프로젝트

일반

사용자정보

통계
| 개정판:

hytos / HYTOS / HYTOS / Ball.py @ 08955797

이력 | 보기 | 이력해설 | 다운로드 (16.3 KB)

1
# -*- coding: utf-8 -*-
2

    
3
# Form implementation generated from reading ui file 'ProjectDialog.ui'
4
#
5
# Created by: PyQt5 UI code generator 5.6
6
#
7
# WARNING! All changes made in this file will be lost!
8

    
9
from PyQt5 import QtCore, QtGui, QtWidgets
10
from PyQt5.QtWidgets import *
11
import os
12
from AppDocData import AppDocData
13
import Ball_UI
14
import math
15

    
16

    
17
def is_float(s):
18
    try:
19
        if s:
20
            float(s)
21
            return True
22
        else:
23
            return False
24
    except ValueError:
25
        return False
26

    
27

    
28
def is_blank(s):
29
    return not (s and s.strip())
30

    
31

    
32
def is_not_blank(s):
33
    return bool(s and s.strip())
34

    
35

    
36
def convert_to_fixed_point(value):
37
    if is_float(str(value)):
38
        tokens = f"{float(value):.10f}".split('.')
39
        if len(tokens) == 2:
40
            # 소수점 아래가 있을 경우 소수점 아래의 trailing zero를 제거한다.
41
            if is_blank(tokens[1].rstrip('0')):
42
                return tokens[0]
43
            else:
44
                tokens[1] = tokens[1].rstrip('0')
45
                return '.'.join(tokens)
46
        else:
47
            return tokens[0]
48
    else:
49
        return value
50

    
51

    
52
class QBall(QDialog):
53
    def __init__(self):
54
        QDialog.__init__(self)
55

    
56
        self.ui = Ball_UI.Ui_BallDialog()
57
        self.ui.setupUi(self)
58
        self._item = None
59

    
60
        self.ui.lineEdit_N1_Pressure.setValidator(QtGui.QDoubleValidator(self.ui.lineEdit_N1_Pressure))
61
        self.ui.lineEdit_N2_Pressure.setValidator(QtGui.QDoubleValidator(self.ui.lineEdit_N2_Pressure))
62
        self.ui.lineEdit_N3_Pressure.setValidator(QtGui.QDoubleValidator(self.ui.lineEdit_N3_Pressure))
63
        self.ui.lineEdit_N4_Pressure.setValidator(QtGui.QDoubleValidator(self.ui.lineEdit_N4_Pressure))
64
        self.ui.lineEdit_N5_Pressure.setValidator(QtGui.QDoubleValidator(self.ui.lineEdit_N5_Pressure))
65
        self.ui.lineEdit_N6_Pressure.setValidator(QtGui.QDoubleValidator(self.ui.lineEdit_N6_Pressure))
66
        self.ui.lineEdit_N7_Pressure.setValidator(QtGui.QDoubleValidator(self.ui.lineEdit_N7_Pressure))
67
        self.ui.lineEdit_N8_Pressure.setValidator(QtGui.QDoubleValidator(self.ui.lineEdit_N8_Pressure))
68

    
69
        self.ui.lineEdit_N1_Elevation.setValidator(QtGui.QDoubleValidator(self.ui.lineEdit_N1_Elevation))
70
        self.ui.lineEdit_N2_Elevation.setValidator(QtGui.QDoubleValidator(self.ui.lineEdit_N2_Elevation))
71
        self.ui.lineEdit_N3_Elevation.setValidator(QtGui.QDoubleValidator(self.ui.lineEdit_N3_Elevation))
72
        self.ui.lineEdit_N4_Elevation.setValidator(QtGui.QDoubleValidator(self.ui.lineEdit_N4_Elevation))
73
        self.ui.lineEdit_N5_Elevation.setValidator(QtGui.QDoubleValidator(self.ui.lineEdit_N5_Elevation))
74
        self.ui.lineEdit_N6_Elevation.setValidator(QtGui.QDoubleValidator(self.ui.lineEdit_N6_Elevation))
75
        self.ui.lineEdit_N7_Elevation.setValidator(QtGui.QDoubleValidator(self.ui.lineEdit_N7_Elevation))
76
        self.ui.lineEdit_N8_Elevation.setValidator(QtGui.QDoubleValidator(self.ui.lineEdit_N8_Elevation))
77

    
78
        self.initialize()
79

    
80
    def show_dialog(self, item):
81
        self.setWindowFlags(self.windowFlags() & ~QtCore.Qt.WindowContextHelpButtonHint)
82
        self._item = item
83

    
84
        self.ui.lineEdit_TagNo.setFocus()
85
        self.set_controls()
86
        self.load_data()
87

    
88
        return self.exec_()
89

    
90
    def initialize(self):
91
        self.ui.label_Img_N1.setVisible(False)
92
        self.ui.label_Img_N2.setVisible(False)
93
        self.ui.label_Img_N3.setVisible(False)
94
        self.ui.label_Img_N4.setVisible(False)
95
        self.ui.label_Img_N5.setVisible(False)
96
        self.ui.label_Img_N6.setVisible(False)
97
        self.ui.label_Img_N7.setVisible(False)
98
        self.ui.label_Img_N8.setVisible(False)
99

    
100
        self.ui.label_N1.setVisible(False)
101
        self.ui.lineEdit_N1_Pressure.setEnabled(False)
102
        self.ui.lineEdit_N1_Elevation.setEnabled(False)
103

    
104
        self.ui.label_N2.setVisible(False)
105
        self.ui.lineEdit_N2_Pressure.setEnabled(False)
106
        self.ui.lineEdit_N2_Elevation.setEnabled(False)
107

    
108
        self.ui.label_N3.setVisible(False)
109
        self.ui.lineEdit_N3_Pressure.setEnabled(False)
110
        self.ui.lineEdit_N3_Elevation.setEnabled(False)
111

    
112
        self.ui.label_N4.setVisible(False)
113
        self.ui.lineEdit_N4_Pressure.setEnabled(False)
114
        self.ui.lineEdit_N4_Elevation.setEnabled(False)
115

    
116
        self.ui.label_N5.setVisible(False)
117
        self.ui.lineEdit_N5_Pressure.setEnabled(False)
118
        self.ui.lineEdit_N5_Elevation.setEnabled(False)
119

    
120
        self.ui.label_N6.setVisible(False)
121
        self.ui.lineEdit_N6_Pressure.setEnabled(False)
122
        self.ui.lineEdit_N6_Elevation.setEnabled(False)
123

    
124
        self.ui.label_N7.setVisible(False)
125
        self.ui.lineEdit_N7_Pressure.setEnabled(False)
126
        self.ui.lineEdit_N7_Elevation.setEnabled(False)
127

    
128
        self.ui.label_N8.setVisible(False)
129
        self.ui.lineEdit_N8_Pressure.setEnabled(False)
130
        self.ui.lineEdit_N8_Elevation.setEnabled(False)
131

    
132
    def set_controls(self):
133
        # To do : 이름으로 Control 찾아오기
134
        for connector in self._item.connectors:
135
            index = connector._conn_index
136
            if connector.connectedItem:
137
                if index == 1:
138
                    self.ui.label_Img_N1.setVisible(True)
139
                    self.ui.label_N1.setVisible(True)
140
                    self.ui.lineEdit_N1_Pressure.setEnabled(True)
141
                    self.ui.lineEdit_N1_Elevation.setEnabled(True)
142
                elif index == 2:
143
                    self.ui.label_Img_N2.setVisible(True)
144
                    self.ui.label_N2.setVisible(True)
145
                    self.ui.lineEdit_N2_Pressure.setEnabled(True)
146
                    self.ui.lineEdit_N2_Elevation.setEnabled(True)
147
                elif index == 3:
148
                    self.ui.label_Img_N3.setVisible(True)
149
                    self.ui.label_N3.setVisible(True)
150
                    self.ui.lineEdit_N3_Pressure.setEnabled(True)
151
                    self.ui.lineEdit_N3_Elevation.setEnabled(True)
152
                elif index == 4:
153
                    self.ui.label_Img_N4.setVisible(True)
154
                    self.ui.label_N4.setVisible(True)
155
                    self.ui.lineEdit_N4_Pressure.setEnabled(True)
156
                    self.ui.lineEdit_N4_Elevation.setEnabled(True)
157
                elif index == 5:
158
                    self.ui.label_Img_N5.setVisible(True)
159
                    self.ui.label_N5.setVisible(True)
160
                    self.ui.lineEdit_N5_Pressure.setEnabled(True)
161
                    self.ui.lineEdit_N5_Elevation.setEnabled(True)
162
                elif index == 6:
163
                    self.ui.label_Img_N6.setVisible(True)
164
                    self.ui.label_N6.setVisible(True)
165
                    self.ui.lineEdit_N6_Pressure.setEnabled(True)
166
                    self.ui.lineEdit_N6_Elevation.setEnabled(True)
167
                elif index == 7:
168
                    self.ui.label_Img_N7.setVisible(True)
169
                    self.ui.label_N7.setVisible(True)
170
                    self.ui.lineEdit_N7_Pressure.setEnabled(True)
171
                    self.ui.lineEdit_N7_Elevation.setEnabled(True)
172
                elif index == 8:
173
                    self.ui.label_Img_N8.setVisible(True)
174
                    self.ui.label_N8.setVisible(True)
175
                    self.ui.lineEdit_N8_Pressure.setEnabled(True)
176
                    self.ui.lineEdit_N8_Elevation.setEnabled(True)
177

    
178
    def load_data(self):
179
        """ load tag no and nozzle data """
180
        tag_no = self._item.tag_no
181
        if tag_no != 'None' and is_not_blank(tag_no):
182
            self.ui.lineEdit_TagNo.setText(tag_no)
183

    
184
        app_doc_data = AppDocData.instance()
185
        drawing = app_doc_data.activeDrawing
186
        if drawing:
187
            for attr in drawing.attrs:
188
                if attr[0] == 'Units':
189
                    self.ui.label_PressureUnit.setText('{}(g)'.format(attr[1]['Pressure']))
190
                    self.ui.label_ElevationUnit.setText(attr[1]['Length'])
191

    
192
        for connector in self._item.connectors:
193
            index = connector._conn_index
194
            if connector.data:
195
                pressure = connector.data.pressure
196
                if pressure is not None:
197
                    if index == 1:
198
                        self.ui.lineEdit_N1_Pressure.setText(str(convert_to_fixed_point(pressure)))
199
                    elif index == 2:
200
                        self.ui.lineEdit_N2_Pressure.setText(str(convert_to_fixed_point(pressure)))
201
                    elif index == 3:
202
                        self.ui.lineEdit_N3_Pressure.setText(str(convert_to_fixed_point(pressure)))
203
                    elif index == 4:
204
                        self.ui.lineEdit_N4_Pressure.setText(str(convert_to_fixed_point(pressure)))
205
                    elif index == 5:
206
                        self.ui.lineEdit_N5_Pressure.setText(str(convert_to_fixed_point(pressure)))
207
                    elif index == 6:
208
                        self.ui.lineEdit_N6_Pressure.setText(str(convert_to_fixed_point(pressure)))
209
                    elif index == 7:
210
                        self.ui.lineEdit_N7_Pressure.setText(str(convert_to_fixed_point(pressure)))
211
                    elif index == 8:
212
                        self.ui.lineEdit_N8_Pressure.setText(str(convert_to_fixed_point(pressure)))
213

    
214
                elevation = connector.data.elevation
215
                if elevation is not None:
216
                    if index == 1:
217
                        self.ui.lineEdit_N1_Elevation.setText(str(convert_to_fixed_point(elevation)))
218
                    elif index == 2:
219
                        self.ui.lineEdit_N2_Elevation.setText(str(convert_to_fixed_point(elevation)))
220
                    elif index == 3:
221
                        self.ui.lineEdit_N3_Elevation.setText(str(convert_to_fixed_point(elevation)))
222
                    elif index == 4:
223
                        self.ui.lineEdit_N4_Elevation.setText(str(convert_to_fixed_point(elevation)))
224
                    elif index == 5:
225
                        self.ui.lineEdit_N5_Elevation.setText(str(convert_to_fixed_point(elevation)))
226
                    elif index == 6:
227
                        self.ui.lineEdit_N6_Elevation.setText(str(convert_to_fixed_point(elevation)))
228
                    elif index == 7:
229
                        self.ui.lineEdit_N7_Elevation.setText(str(convert_to_fixed_point(elevation)))
230
                    elif index == 8:
231
                        self.ui.lineEdit_N8_Elevation.setText(str(convert_to_fixed_point(elevation)))
232

    
233
    def accept(self):
234
        """ set tag no and nozzle data """
235
        from EngineeringConnectorItem import NozzleData
236
        tag_no = self.ui.lineEdit_TagNo.text()
237

    
238
        if is_not_blank(tag_no):
239
            self._item.tag_no = tag_no
240
            for connector in self._item.connectors:
241
                index = connector._conn_index
242
                if not connector.data:
243
                    connector.data = NozzleData()
244

    
245
                if index == 1:
246
                    if self.ui.lineEdit_N1_Pressure.isEnabled():
247
                        pressure = self.ui.lineEdit_N1_Pressure.text()
248
                        if pressure:
249
                            connector.data.pressure = float(pressure)
250
                        else:
251
                            connector.data.pressure = 0
252

    
253
                    if self.ui.lineEdit_N1_Elevation.isEnabled():
254
                        elevation = self.ui.lineEdit_N1_Elevation.text()
255
                        if elevation:
256
                            connector.data.elevation = float(elevation)
257
                        else:
258
                            connector.data.elevation = 0
259
                elif index == 2:
260
                    if self.ui.lineEdit_N2_Pressure.isEnabled():
261
                        pressure = self.ui.lineEdit_N2_Pressure.text()
262
                        if pressure:
263
                            connector.data.pressure = float(pressure)
264
                        else:
265
                            connector.data.pressure = 0
266

    
267
                    if self.ui.lineEdit_N2_Elevation.isEnabled():
268
                        elevation = self.ui.lineEdit_N2_Elevation.text()
269
                        if elevation:
270
                            connector.data.elevation = float(elevation)
271
                        else:
272
                            connector.data.elevation = 0
273
                elif index == 3:
274
                    if self.ui.lineEdit_N3_Pressure.isEnabled():
275
                        pressure = self.ui.lineEdit_N3_Pressure.text()
276
                        if pressure:
277
                            connector.data.pressure = float(pressure)
278
                        else:
279
                            connector.data.pressure = 0
280

    
281
                    if self.ui.lineEdit_N3_Elevation.isEnabled():
282
                        elevation = self.ui.lineEdit_N3_Elevation.text()
283
                        if elevation:
284
                            connector.data.elevation = float(elevation)
285
                        else:
286
                            connector.data.elevation = 0
287
                elif index == 4:
288
                    if self.ui.lineEdit_N4_Pressure.isEnabled():
289
                        pressure = self.ui.lineEdit_N4_Pressure.text()
290
                        if pressure:
291
                            connector.data.pressure = float(pressure)
292
                        else:
293
                            connector.data.pressure = 0
294

    
295
                    if self.ui.lineEdit_N4_Elevation.isEnabled():
296
                        elevation = self.ui.lineEdit_N4_Elevation.text()
297
                        if elevation:
298
                            connector.data.elevation = float(elevation)
299
                        else:
300
                            connector.data.elevation = 0
301
                elif index == 5:
302
                    if self.ui.lineEdit_N5_Pressure.isEnabled():
303
                        pressure = self.ui.lineEdit_N5_Pressure.text()
304
                        if pressure:
305
                            connector.data.pressure = float(pressure)
306
                        else:
307
                            connector.data.pressure = 0
308

    
309
                    if self.ui.lineEdit_N5_Elevation.isEnabled():
310
                        elevation = self.ui.lineEdit_N5_Elevation.text()
311
                        if elevation:
312
                            connector.data.elevation = float(elevation)
313
                        else:
314
                            connector.data.elevation = 0
315
                elif index == 6:
316
                    if self.ui.lineEdit_N6_Pressure.isEnabled():
317
                        pressure = self.ui.lineEdit_N6_Pressure.text()
318
                        if pressure:
319
                            connector.data.pressure = float(pressure)
320
                        else:
321
                            connector.data.pressure = 0
322

    
323
                    if self.ui.lineEdit_N6_Elevation.isEnabled():
324
                        elevation = self.ui.lineEdit_N6_Elevation.text()
325
                        if elevation:
326
                            connector.data.elevation = float(elevation)
327
                        else:
328
                            connector.data.elevation = 0
329
                elif index == 7:
330
                    if self.ui.lineEdit_N7_Pressure.isEnabled():
331
                        pressure = self.ui.lineEdit_N7_Pressure.text()
332
                        if pressure:
333
                            connector.data.pressure = float(pressure)
334
                        else:
335
                            connector.data.pressure = 0
336

    
337
                    if self.ui.lineEdit_N7_Elevation.isEnabled():
338
                        elevation = self.ui.lineEdit_N7_Elevation.text()
339
                        if elevation:
340
                            connector.data.elevation = float(elevation)
341
                        else:
342
                            connector.data.elevation = 0
343
                elif index == 8:
344
                    if self.ui.lineEdit_N8_Pressure.isEnabled():
345
                        pressure = self.ui.lineEdit_N8_Pressure.text()
346
                        if pressure:
347
                            connector.data.pressure = float(pressure)
348
                        else:
349
                            connector.data.pressure = 0
350

    
351
                    if self.ui.lineEdit_N8_Elevation.isEnabled():
352
                        elevation = self.ui.lineEdit_N8_Elevation.text()
353
                        if elevation:
354
                            connector.data.elevation = float(elevation)
355
                        else:
356
                            connector.data.elevation = 0
357

    
358
            QDialog.accept(self)
359
        else:
360
            QMessageBox.information(self, self.tr('Information'), self.tr('Please Input [Tag No.]'))
361

    
362
    def reject(self):
363
        QDialog.reject(self)
클립보드 이미지 추가 (최대 크기: 500 MB)