프로젝트

일반

사용자정보

통계
| 개정판:

hytos / HYTOS / HYTOS / GeometryData_MixedDialog.py @ a25e9bcd

이력 | 보기 | 이력해설 | 다운로드 (16.1 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 sys
12
import os
13
from AppDocData import AppDocData
14
import GeometryData_Mixed_UI
15
import math
16

    
17

    
18
def is_blank(s):
19
    return not (s and s.strip())
20

    
21

    
22
class QGeometryData_MixedDialog(QDialog):
23
    def __init__(self):
24
        QDialog.__init__(self)
25

    
26
        self.ui = GeometryData_Mixed_UI.Ui_Dialog()
27
        self.ui.setupUi(self)
28

    
29
        self.units = {}
30
        self.isAccepted = False
31
        self.row_count = 0
32

    
33
        self.ui.lineEdit_Length.setValidator(QtGui.QDoubleValidator(self.ui.lineEdit_Length))
34
        self.ui.lineEdit_Angle.setValidator(QtGui.QDoubleValidator(self.ui.lineEdit_Angle))
35
        self.ui.lineEdit_rpd.setValidator(QtGui.QDoubleValidator(self.ui.lineEdit_rpd))
36
        self.ui.lineEdit_d1_d2.setValidator(QtGui.QDoubleValidator(self.ui.lineEdit_d1_d2))
37
        self.ui.lineEdit_k.setValidator(QtGui.QDoubleValidator(self.ui.lineEdit_k))
38

    
39
        self.ui.pushButton_Roughness.clicked.connect(self.roughness_clicked_event)
40
        self.ui.pushButton_Angle.clicked.connect(self.angle_clicked_event)
41
        self.ui.comboBox_Nominal_Pipe_Size.currentIndexChanged.connect(self.getInsideDiameter)
42
        self.ui.comboBox_Schedule_No.currentIndexChanged.connect(self.getInsideDiameter)
43

    
44
        self.ui.pushButton_Angle_Help.clicked.connect(self.show_help_dialog)
45
        self.ui.pushButton_d1_d2_Help.clicked.connect(self.show_help_dialog)
46
        self.ui.pushButton_rpd_Help.clicked.connect(self.show_help_dialog)
47
        self.ui.pushButton_K_Help.clicked.connect(self.show_help_dialog)
48

    
49
        self.ui.comboBox_Element.currentIndexChanged.connect(self.element_change_event)
50
        self.ui.comboBox_Nominal_Pipe_Size.currentIndexChanged.connect(self.nominal_pipe_size_change_event)
51

    
52
        self.init_units()
53
        self.init_nominal_diameter()
54
        self.init_schedule()
55

    
56
    def angle_input_reducer(self):
57
        nominal_pipe_size = self.ui.comboBox_Nominal_Pipe_Size.currentText()
58
        if nominal_pipe_size:
59
            nominal_pipe_size = float(nominal_pipe_size)
60
            if nominal_pipe_size == 0.5:
61
                self.ui.lineEdit_Angle.setText(str(5.1))
62
            elif nominal_pipe_size == 0.75:
63
                self.ui.lineEdit_Angle.setText(str(4.7))
64
            elif nominal_pipe_size == 1:
65
                self.ui.lineEdit_Angle.setText(str(8.1))
66
            elif nominal_pipe_size == 1.5:
67
                self.ui.lineEdit_Angle.setText(str(6.3))
68
            elif nominal_pipe_size == 2:
69
                self.ui.lineEdit_Angle.setText(str(18.9))
70
            elif nominal_pipe_size == 3:
71
                self.ui.lineEdit_Angle.setText(str(16.2))
72
            elif nominal_pipe_size == 4:
73
                self.ui.lineEdit_Angle.setText(str(28))
74
            elif nominal_pipe_size == 6:
75
                self.ui.lineEdit_Angle.setText(str(20.7))
76
            elif nominal_pipe_size == 8:
77
                self.ui.lineEdit_Angle.setText(str(18.9))
78
            elif nominal_pipe_size == 10:
79
                self.ui.lineEdit_Angle.setText(str(16.2))
80
            elif nominal_pipe_size == 12:
81
                self.ui.lineEdit_Angle.setText(str(14.2))
82
            elif nominal_pipe_size == 14:
83
                self.ui.lineEdit_Angle.setText(str(8.8))
84
            elif nominal_pipe_size == 16:
85
                self.ui.lineEdit_Angle.setText(str(8.1))
86
            elif nominal_pipe_size == 18:
87
                self.ui.lineEdit_Angle.setText(str(7.6))
88
            elif nominal_pipe_size == 20:
89
                self.ui.lineEdit_Angle.setText(str(5.7))
90
            elif nominal_pipe_size == 22:
91
                self.ui.lineEdit_Angle.setText(str(5.7))
92
            elif nominal_pipe_size == 24:
93
                self.ui.lineEdit_Angle.setText(str(5.7))
94
            elif nominal_pipe_size == 26:
95
                self.ui.lineEdit_Angle.setText(str(4.7))
96
            elif nominal_pipe_size == 28:
97
                self.ui.lineEdit_Angle.setText(str(4.7))
98
            elif nominal_pipe_size == 30:
99
                self.ui.lineEdit_Angle.setText(str(4.7))
100
            elif nominal_pipe_size == 32:
101
                self.ui.lineEdit_Angle.setText(str(4.7))
102
            elif nominal_pipe_size == 34:
103
                self.ui.lineEdit_Angle.setText(str(4.7))
104
            elif nominal_pipe_size == 36:
105
                self.ui.lineEdit_Angle.setText(str(4.7))
106
            else:
107
                self.ui.lineEdit_Angle.clear()
108

    
109
    def nominal_pipe_size_change_event(self, index):
110

    
111
        element = self.ui.comboBox_Element.currentText()
112
        if element:
113
            if index > -1:
114
                if element == 'Reducer' or element == 'Expander':
115
                    self.angle_input_reducer()
116

    
117
    def element_change_event(self, index):
118
        try:
119
            self.ui.comboBox_Nominal_Pipe_Size.setCurrentIndex(-1)
120
            self.ui.comboBox_Schedule_No.setCurrentIndex(-1)
121
            self.ui.lineEdit_Inside_Pipe_Size.setEnabled(True)
122
            self.ui.lineEdit_Inside_Pipe_Size.clear()
123
            self.ui.lineEdit_Roughness.clear()
124
            self.ui.lineEdit_Length.setEnabled(True)
125
            self.ui.lineEdit_Length.clear()
126
            self.ui.pushButton_Angle.setEnabled(True)
127
            self.ui.lineEdit_Angle.setEnabled(True)
128
            self.ui.lineEdit_Angle.clear()
129
            self.ui.lineEdit_rpd.setEnabled(True)
130
            self.ui.lineEdit_rpd.clear()
131
            self.ui.lineEdit_d1_d2.setEnabled(True)
132
            self.ui.lineEdit_d1_d2.clear()
133
            self.ui.lineEdit_k.setEnabled(True)
134
            self.ui.lineEdit_k.clear()
135

    
136
            if index > -1:
137
                element = self.ui.comboBox_Element.itemText(index)
138

    
139
                if element == 'Pipe':
140
                    self.ui.lineEdit_Angle.setText('0')
141
                    self.ui.lineEdit_rpd.setEnabled(False)
142
                    self.ui.lineEdit_d1_d2.setEnabled(False)
143
                    self.ui.lineEdit_k.setEnabled(False)
144
                elif element == 'Bend':
145
                    self.ui.lineEdit_Angle.setText('90')
146
                    self.ui.lineEdit_rpd.setText('1.5')
147
                    self.ui.lineEdit_Length.setEnabled(False)
148
                    self.ui.lineEdit_d1_d2.setEnabled(False)
149
                elif element == 'Reducer' or element == 'Expander':
150
                    self.ui.lineEdit_Length.setEnabled(False)
151
                    self.ui.lineEdit_rpd.setEnabled(False)
152
                else:
153
                    self.ui.pushButton_Angle.setEnabled(False)
154
                    self.ui.lineEdit_Length.setEnabled(False)
155
                    self.ui.lineEdit_Angle.setEnabled(False)
156
                    self.ui.lineEdit_rpd.setEnabled(False)
157
                    self.ui.lineEdit_d1_d2.setEnabled(False)
158
        except Exception as ex:
159
            from App import App
160
            from AppDocData import MessageType
161

    
162
            message = 'error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno)
163
            App.mainWnd().addMessage.emit(MessageType.Error, message)
164

    
165
    def show_dialog(self, row_count, data=None):
166
        self.setWindowFlags(self.windowFlags() & ~QtCore.Qt.WindowContextHelpButtonHint)
167
        self.row_count = row_count
168
        self.init_element()
169
        if data:
170
            self.load_data(data)
171
        self.exec_()
172

    
173
        return self.isAccepted, self.ui.comboBox_Element.currentText(), self.ui.comboBox_Nominal_Pipe_Size.currentText(), \
174
               self.ui.comboBox_Schedule_No.currentText(), self.ui.lineEdit_Inside_Pipe_Size.text(), self.ui.lineEdit_Roughness.text(), \
175
               self.ui.lineEdit_Length.text(), self.ui.lineEdit_Angle.text(), self.ui.lineEdit_rpd.text(), self.ui.lineEdit_d1_d2.text(), self.ui.lineEdit_k.text()
176

    
177
    def load_data(self, data):
178
        try:
179
            index = self.ui.comboBox_Element.findText(data[0])
180
            if index > -1:
181
                self.ui.comboBox_Element.setCurrentIndex(index)
182

    
183
            index = self.ui.comboBox_Nominal_Pipe_Size.findText(data[1])
184
            if index > -1:
185
                self.ui.comboBox_Nominal_Pipe_Size.setCurrentIndex(index)
186

    
187
            index = self.ui.comboBox_Schedule_No.findText(data[2])
188
            if index > -1:
189
                self.ui.comboBox_Schedule_No.setCurrentIndex(index)
190

    
191
            self.ui.lineEdit_Inside_Pipe_Size.setText(str(data[3]))
192
            self.ui.lineEdit_Roughness.setText(str(data[4]))
193
            self.ui.lineEdit_Length.setText(str(data[5]))
194
            self.ui.lineEdit_Angle.setText(str(data[6]))
195
            self.ui.lineEdit_rpd.setText(str(data[7]))
196
            self.ui.lineEdit_d1_d2.setText(str(data[8]))
197
            self.ui.lineEdit_k.setText(str(data[9]))
198
        except Exception as ex:
199
            from App import App
200
            from AppDocData import MessageType
201

    
202
            message = 'error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename,
203
                                                           sys.exc_info()[-1].tb_lineno)
204
            App.mainWnd().addMessage.emit(MessageType.Error, message)
205

    
206
    def init_element(self):
207
        self.ui.comboBox_Element.clear()
208

    
209
        if self.row_count > 0:
210
            self.ui.comboBox_Element.addItem('Pipe')
211
            self.ui.comboBox_Element.addItem('Bend')
212
            self.ui.comboBox_Element.addItem('Nozzle In')
213
            self.ui.comboBox_Element.addItem('Nozzle Out')
214
            self.ui.comboBox_Element.addItem('Check Valve')
215
            self.ui.comboBox_Element.addItem('Ball Valve')
216
            self.ui.comboBox_Element.addItem('Gate Valve')
217
            self.ui.comboBox_Element.addItem('Globe Valve')
218
            self.ui.comboBox_Element.addItem('Butterfly Valve')
219
            self.ui.comboBox_Element.addItem('Reducer')
220
            self.ui.comboBox_Element.addItem('Expander')
221
        else:
222
            self.ui.comboBox_Element.addItem('Pipe')
223
            self.ui.comboBox_Element.addItem('Nozzle Out')
224

    
225
        self.ui.comboBox_Element.setCurrentIndex(-1)
226

    
227
    def show_help_dialog(self):
228

    
229
        if self.sender() == self.ui.pushButton_Angle_Help:
230
            name = 'angle'
231
        elif self.sender() == self.ui.pushButton_d1_d2_Help:
232
            name = 'd1_d2'
233
        elif self.sender() == self.ui.pushButton_rpd_Help:
234
            name = 'rpd'
235
        elif self.sender() == self.ui.pushButton_K_Help:
236
            name = 'k'
237

    
238
        from GeometryData_HelpDialog import QGeometryData_HelpDialog
239

    
240
        dialog = QGeometryData_HelpDialog()
241
        dialog.show_dialog(name)
242

    
243
    def init_nominal_diameter(self):
244
        from AppDocData import AppDocData
245

    
246
        self.ui.comboBox_Nominal_Pipe_Size.clear()
247

    
248
        nominal_diameter_list = AppDocData.instance().getNominalDiameter()
249
        for nominalDiameter in nominal_diameter_list:
250
            if self.ui.label_Nominal_Pipe_Size_Unit.text() == 'mm':
251
                self.ui.comboBox_Nominal_Pipe_Size.addItem(str(nominalDiameter[1]), nominalDiameter[0])
252
            else:
253
                self.ui.comboBox_Nominal_Pipe_Size.addItem(str(nominalDiameter[2]), nominalDiameter[0])
254
        self.ui.comboBox_Nominal_Pipe_Size.setCurrentIndex(-1)
255

    
256
    def init_schedule(self):
257
        from AppDocData import AppDocData
258

    
259
        self.ui.comboBox_Schedule_No.clear()
260

    
261
        schedule_list = AppDocData.instance().getSchedule()
262
        for schedule in schedule_list:
263
            self.ui.comboBox_Schedule_No.addItem(schedule[1], schedule[0])
264

    
265
        self.ui.comboBox_Schedule_No.setCurrentIndex(-1)
266

    
267
    def angle_clicked_event(self):
268
        from GeometryData_AngleDialog import QGeometryData_AngleDialog
269

    
270
        dialog = QGeometryData_AngleDialog()
271
        angle = dialog.show_dialog()
272

    
273
        self.ui.lineEdit_Angle.setText(str(angle))
274

    
275
    def roughness_clicked_event(self):
276
        from RoughnessDialog import QRoughnessDialog
277

    
278
        dialog = QRoughnessDialog()
279
        roughness = dialog.show_dialog('Mixed')
280

    
281
        self.ui.lineEdit_Roughness.setText(str(roughness))
282

    
283
    def getInsideDiameter(self):
284
        from AppDocData import AppDocData
285

    
286
        self.ui.lineEdit_Inside_Pipe_Size.clear()
287

    
288
        nominal_diameter_uid = self.ui.comboBox_Nominal_Pipe_Size.currentData()
289
        schedule_uid = self.ui.comboBox_Schedule_No.currentData()
290

    
291
        if nominal_diameter_uid and schedule_uid:
292
            inside_diameter = AppDocData.instance().getInsideDiameter(nominal_diameter_uid, schedule_uid)
293
            if len(inside_diameter) > 0:
294
                if self.ui.label_Inside_Pipe_Size_Unit.text() == 'mm':
295
                    if inside_diameter[0][1]:
296
                        self.ui.lineEdit_Inside_Pipe_Size.setText(str(inside_diameter[0][1]))
297
                else:
298
                    if inside_diameter[0][2]:
299
                        self.ui.lineEdit_Inside_Pipe_Size.setText(str(inside_diameter[0][2]))
300

    
301
    def init_units(self):
302
        app_doc_data = AppDocData.instance()
303
        active_drawing = app_doc_data.activeDrawing
304

    
305
        for attr in active_drawing.attrs:
306
            if attr[0] == 'Units':
307
                self.units = attr[1]
308

    
309
        self.ui.label_Nominal_Pipe_Size_Unit.setText(self.units['Pipe_Diameter'])
310
        self.ui.label_Inside_Pipe_Size_Unit.setText(self.units['Pipe_Diameter'])
311
        self.ui.label_Roughness_Unit.setText(self.units['Roughness'])
312
        self.ui.label_Lengh_Unit.setText(self.units['Length'])
313

    
314
    def initialize(self):
315
        try:
316
            dev = 1
317
        except Exception as ex:
318
            from App import App
319
            from AppDocData import MessageType
320

    
321
            message = 'error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename,
322
                                                           sys.exc_info()[-1].tb_lineno)
323
            App.mainWnd().addMessage.emit(MessageType.Error, message)
324

    
325
    def validation_check(self):
326
        message = None
327

    
328
        element = self.ui.comboBox_Element.currentText()
329
        if is_blank(element):
330
            message = '- Element'
331
        else:
332
            nominal_pipe_size = self.ui.comboBox_Nominal_Pipe_Size.currentText()
333
            schedule_no = self.ui.comboBox_Schedule_No.currentText()
334
            inside_pipe_size = self.ui.lineEdit_Inside_Pipe_Size.text()
335
            roughness = self.ui.lineEdit_Roughness.text()
336
            length = self.ui.lineEdit_Length.text()
337
            angle = self.ui.lineEdit_Angle.text()
338
            rpd = self.ui.lineEdit_rpd.text()
339
            d1_d2 = self.ui.lineEdit_d1_d2.text()
340
            k = self.ui.lineEdit_k.text()
341

    
342
            if element == 'Pipe':
343
                if is_blank(inside_pipe_size):
344
                    message = '- Inner Diameter'
345
                elif is_blank(roughness):
346
                    message = '- Roughness'
347
                elif is_blank(length):
348
                    message = '- Length'
349
            elif element == 'Bend':
350
                if is_blank(inside_pipe_size):
351
                    message = '- Inner Diameter'
352
                elif is_blank(roughness):
353
                    message = '- Roughness'
354
                elif is_blank(angle):
355
                    message = '- Angle'
356
                elif is_blank(rpd):
357
                    message = '- r/D'
358
            elif element == 'Reducer' or element == 'Expander':
359
                if is_blank(inside_pipe_size):
360
                    message = '- Inner Diameter'
361
                elif is_blank(roughness):
362
                    message = '- Roughness'
363
                elif is_blank(angle):
364
                    message = '- Angle'
365
                elif is_blank(d1_d2):
366
                    message = '- D1/D2'
367
            else:
368
                if is_blank(inside_pipe_size):
369
                    message = '- Inner Diameter'
370
                elif is_blank(roughness):
371
                    message = '- Roughness'
372

    
373
        if message:
374
            msg = QMessageBox(self)
375
            msg.setIcon(QMessageBox.Information)
376
            msg.setText(self.tr(message))
377
            msg.setWindowTitle(self.tr("Notice"))
378
            msg.setStandardButtons(QMessageBox.Ok)
379
            msg.exec_()
380
            return False
381
        else:
382
            return True
383

    
384
    def accept(self):
385
        if self.validation_check():
386
            self.isAccepted = True
387
            QDialog.accept(self)
388

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