프로젝트

일반

사용자정보

통계
| 브랜치(Branch): | 개정판:

hytos / HYTOS / HYTOS / StreamDataDialog.py @ 4211450a

이력 | 보기 | 이력해설 | 다운로드 (79 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
from PyQt5.QtCore import *
12
from PyQt5 import QtCore, QtGui, QtWidgets
13
import sys
14
import os
15
from AppDocData import AppDocData
16
import StreamData_UI
17
import math
18

    
19

    
20
def set_item_properties(name, alignment, color=None):
21
    item = QTableWidgetItem(str(name))
22
    item.setTextAlignment(alignment)
23
    if color:
24
        item.setBackground(color)
25

    
26
    return item
27

    
28

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

    
32

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

    
36

    
37
class QStreamDataDialog(QDialog):
38
    def __init__(self):
39
        QDialog.__init__(self)
40

    
41
        self.ui = StreamData_UI.Ui_Dialog()
42
        self.ui.setupUi(self)
43
        self.item = None
44
        self.result = False
45
        self.liquid_drop_method = None
46
        self.ui.label_current_tab_index.setVisible(False)
47

    
48
        self.ui.lineEdit_Flowrate_Mass_Liquid.setValidator(
49
            QtGui.QDoubleValidator(self.ui.lineEdit_Flowrate_Mass_Liquid))
50
        self.ui.lineEdit_Flowrate_Volume.setValidator(QtGui.QDoubleValidator(self.ui.lineEdit_Flowrate_Volume))
51
        self.ui.lineEdit_Density.setValidator(QtGui.QDoubleValidator(self.ui.lineEdit_Density))
52
        self.ui.lineEdit_Viscosity_Liquid.setValidator(QtGui.QDoubleValidator(self.ui.lineEdit_Viscosity_Liquid))
53
        self.ui.lineEdit_Limitation_Velocity.setValidator(QtGui.QDoubleValidator(self.ui.lineEdit_Limitation_Velocity))
54
        self.ui.lineEdit_Limitation_Pressure_Drop.setValidator(
55
            QtGui.QDoubleValidator(self.ui.lineEdit_Limitation_Pressure_Drop))
56
        self.ui.lineEdit_Inside_Pipe_Size.setValidator(QtGui.QDoubleValidator(self.ui.lineEdit_Inside_Pipe_Size))
57
        self.ui.lineEdit_Roughness.setValidator(QtGui.QDoubleValidator(self.ui.lineEdit_Roughness))
58
        self.ui.lineEdit_Straight_Length.setValidator(QtGui.QDoubleValidator(self.ui.lineEdit_Straight_Length))
59
        self.ui.lineEdit_Equivalent_Length_Input.setValidator(
60
            QtGui.QDoubleValidator(self.ui.lineEdit_Equivalent_Length_Input))
61
        self.ui.lineEdit_Equivalent_Length_Cal.setValidator(
62
            QtGui.QDoubleValidator(self.ui.lineEdit_Equivalent_Length_Cal))
63
        self.ui.lineEdit_Viscosity_Vapor.setValidator(QtGui.QDoubleValidator(self.ui.lineEdit_Viscosity_Vapor))
64
        self.ui.lineEdit_Specific_Heat_Ratio.setValidator(QtGui.QDoubleValidator(self.ui.lineEdit_Specific_Heat_Ratio))
65
        self.ui.lineEdit_Molecular_Weight.setValidator(QtGui.QDoubleValidator(self.ui.lineEdit_Molecular_Weight))
66
        self.ui.lineEdit_Temperature.setValidator(QtGui.QDoubleValidator(self.ui.lineEdit_Temperature))
67
        self.ui.lineEdit_Compress_Factor.setValidator(QtGui.QDoubleValidator(self.ui.lineEdit_Compress_Factor))
68

    
69
        self.ui.lineEdit_Mixed_Flowrate_Mass_Vapor.setValidator(
70
            QtGui.QDoubleValidator(self.ui.lineEdit_Mixed_Flowrate_Mass_Vapor))
71
        self.ui.lineEdit_Mixed_Density_Vapor.setValidator(QtGui.QDoubleValidator(self.ui.lineEdit_Mixed_Density_Vapor))
72
        self.ui.lineEdit_Mixed_Viscosity_Vapor.setValidator(
73
            QtGui.QDoubleValidator(self.ui.lineEdit_Mixed_Viscosity_Vapor))
74
        self.ui.lineEdit_Mixed_Pressure_Vapor.setValidator(
75
            QtGui.QDoubleValidator(self.ui.lineEdit_Mixed_Pressure_Vapor))
76
        self.ui.lineEdit_Mixed_Temperature_Vapor.setValidator(
77
            QtGui.QDoubleValidator(self.ui.lineEdit_Mixed_Temperature_Vapor))
78
        self.ui.lineEdit_Mixed_Molecular_Weight_Vapor.setValidator(
79
            QtGui.QDoubleValidator(self.ui.lineEdit_Mixed_Molecular_Weight_Vapor))
80
        self.ui.lineEdit_Mixed_Compress_Factor_Vapor.setValidator(
81
            QtGui.QDoubleValidator(self.ui.lineEdit_Mixed_Compress_Factor_Vapor))
82
        self.ui.lineEdit_Mixed_Flowrate_Mass_Liquid.setValidator(
83
            QtGui.QDoubleValidator(self.ui.lineEdit_Mixed_Flowrate_Mass_Liquid))
84
        self.ui.lineEdit_Mixed_Density_Liquid.setValidator(
85
            QtGui.QDoubleValidator(self.ui.lineEdit_Mixed_Density_Liquid))
86
        self.ui.lineEdit_Mixed_Viscosity_Liquid.setValidator(
87
            QtGui.QDoubleValidator(self.ui.lineEdit_Mixed_Viscosity_Liquid))
88
        self.ui.pushButton_Roughness.clicked.connect(self.roughness_clicked_event)
89
        self.ui.pushButton_Fitting.clicked.connect(self.show_fitting_dialog)
90
        self.ui.comboBox_Nominal_Pipe_Size.currentIndexChanged.connect(self.getInsideDiameter)
91
        self.ui.comboBox_Schedule_No.currentIndexChanged.connect(self.getInsideDiameter)
92
        self.ui.comboBox_PhaseType.currentIndexChanged.connect(self.on_change_phase_type)
93
        self.ui.pushButton_Line_Sizing.clicked.connect(self.show_line_sizing_dialog)
94
        self.ui.pushButton_Diameter_Estimation.clicked.connect(self.show_diameter_estimation_dialog)
95
        self.ui.pushButton_Add_GeometryData_Mixed.clicked.connect(self.show_geometry_data_dialog)
96
        self.ui.pushButton_Copy_Stream.clicked.connect(self.show_copy_stream_dialog)
97
        self.ui.pushButton_Calculation.clicked.connect(self.mixed_type_calculation)
98
        self.ui.lineEdit_Equivalent_Length_Input.textChanged.connect(self.equivalent_length_change_event)
99
        self.ui.lineEdit_Flowrate_Mass_Liquid.textChanged.connect(self.flowrate_change_event)
100
        self.ui.lineEdit_Flowrate_Volume.textChanged.connect(self.flowrate_change_event)
101
        self.ui.lineEdit_Mixed_Density_Vapor.textChanged.connect(self.mixed_density_vapor_change_event)
102

    
103
        self.ui.tableWidget_GeometryData_Mixed.setContextMenuPolicy(Qt.CustomContextMenu)
104
        self.ui.tableWidget_GeometryData_Mixed.customContextMenuRequested.connect(self.context_menu_geometry_data)
105
        self.ui.tableWidget_GeometryData_Mixed.cellDoubleClicked.connect(self.cell_double_clicked)
106

    
107
        self.initialize()
108
        self.init_liquid_drop_method()
109
        self.init_phase_type()
110
        self.init_units()
111
        self.init_nominal_diameter()
112
        self.init_schedule()
113

    
114
    def delete_geometry_data_click_event(self):
115
        try:
116
            row = self.ui.tableWidget_GeometryData_Mixed.currentRow()
117
            self.ui.tableWidget_GeometryData_Mixed.removeRow(row)
118
        except Exception as ex:
119
            from App import App
120
            from AppDocData import MessageType
121

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

    
126
    def get_data(self, row):
127
        element = self.ui.tableWidget_GeometryData_Mixed.item(row, 0).text()
128
        nominal_pipe_size = self.ui.tableWidget_GeometryData_Mixed.item(row, 1).text()
129
        schedule_no = self.ui.tableWidget_GeometryData_Mixed.item(row, 2).text()
130
        inside_pipe_size = self.ui.tableWidget_GeometryData_Mixed.item(row, 3).text()
131
        roughness = self.ui.tableWidget_GeometryData_Mixed.item(row, 4).text()
132
        length = self.ui.tableWidget_GeometryData_Mixed.item(row, 5).text()
133
        angle = self.ui.tableWidget_GeometryData_Mixed.item(row, 6).text()
134
        rpd = self.ui.tableWidget_GeometryData_Mixed.item(row, 7).text()
135
        d1_d2 = self.ui.tableWidget_GeometryData_Mixed.item(row, 8).text()
136
        k = self.ui.tableWidget_GeometryData_Mixed.item(row, 9).text()
137

    
138
        return element, nominal_pipe_size, schedule_no, inside_pipe_size, roughness, length, angle, rpd, d1_d2, k
139

    
140
    def cell_double_clicked(self, row):
141
        from GeometryData_MixedDialog import QGeometryData_MixedDialog
142
        try:
143
            if row > -1:
144
                data = self.get_data(row)
145

    
146
                row_count = self.ui.tableWidget_GeometryData_Mixed.rowCount() - 1
147
                dialog = QGeometryData_MixedDialog()
148
                (
149
                    isAccepted, element, nominal_pipe_size, schedule_no, inside_pipe_size, roughness, length, angle,
150
                    rpd,
151
                    d1_d2,
152
                    k) = dialog.show_dialog(row_count, data)
153

    
154
                if isAccepted:
155
                    self.ui.tableWidget_GeometryData_Mixed.setItem(row, 0,
156
                                                                   set_item_properties(element,
157
                                                                                       Qt.AlignLeft | Qt.AlignVCenter))
158

    
159
                    self.ui.tableWidget_GeometryData_Mixed.setItem(row, 1,
160
                                                                   set_item_properties(nominal_pipe_size,
161
                                                                                       Qt.AlignRight | Qt.AlignVCenter))
162

    
163
                    self.ui.tableWidget_GeometryData_Mixed.setItem(row, 2,
164
                                                                   set_item_properties(schedule_no,
165
                                                                                       Qt.AlignRight | Qt.AlignVCenter))
166

    
167
                    self.ui.tableWidget_GeometryData_Mixed.setItem(row, 3,
168
                                                                   set_item_properties(inside_pipe_size,
169
                                                                                       Qt.AlignRight | Qt.AlignVCenter))
170

    
171
                    self.ui.tableWidget_GeometryData_Mixed.setItem(row, 4,
172
                                                                   set_item_properties(roughness,
173
                                                                                       Qt.AlignRight | Qt.AlignVCenter))
174

    
175
                    self.ui.tableWidget_GeometryData_Mixed.setItem(row, 5,
176
                                                                   set_item_properties(length,
177
                                                                                       Qt.AlignRight | Qt.AlignVCenter))
178

    
179
                    self.ui.tableWidget_GeometryData_Mixed.setItem(row, 6,
180
                                                                   set_item_properties(angle,
181
                                                                                       Qt.AlignRight | Qt.AlignVCenter))
182

    
183
                    self.ui.tableWidget_GeometryData_Mixed.setItem(row, 7,
184
                                                                   set_item_properties(rpd,
185
                                                                                       Qt.AlignRight | Qt.AlignVCenter))
186

    
187
                    self.ui.tableWidget_GeometryData_Mixed.setItem(row, 8,
188
                                                                   set_item_properties(d1_d2,
189
                                                                                       Qt.AlignRight | Qt.AlignVCenter))
190

    
191
                    self.ui.tableWidget_GeometryData_Mixed.setItem(row, 9,
192
                                                                   set_item_properties(k,
193
                                                                                       Qt.AlignRight | Qt.AlignVCenter))
194

    
195
                    self.ui.tableWidget_GeometryData_Mixed.resizeColumnsToContents()
196
                    self.ui.tableWidget_GeometryData_Mixed.resizeRowsToContents()
197

    
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 edit_geometry_data_click_event(self):
207
        from GeometryData_MixedDialog import QGeometryData_MixedDialog
208
        try:
209
            row = self.ui.tableWidget_GeometryData_Mixed.currentRow()
210
            if row > -1:
211
                data = self.get_data(row)
212

    
213
                row_count = self.ui.tableWidget_GeometryData_Mixed.rowCount() - 1
214
                dialog = QGeometryData_MixedDialog()
215
                (
216
                    isAccepted, element, nominal_pipe_size, schedule_no, inside_pipe_size, roughness, length, angle,
217
                    rpd,
218
                    d1_d2,
219
                    k) = dialog.show_dialog(row_count, data)
220

    
221
                if isAccepted:
222
                    self.ui.tableWidget_GeometryData_Mixed.setItem(row, 0,
223
                                                                   set_item_properties(element,
224
                                                                                       Qt.AlignLeft | Qt.AlignVCenter))
225

    
226
                    self.ui.tableWidget_GeometryData_Mixed.setItem(row, 1,
227
                                                                   set_item_properties(nominal_pipe_size,
228
                                                                                       Qt.AlignRight | Qt.AlignVCenter))
229

    
230
                    self.ui.tableWidget_GeometryData_Mixed.setItem(row, 2,
231
                                                                   set_item_properties(schedule_no,
232
                                                                                       Qt.AlignRight | Qt.AlignVCenter))
233

    
234
                    self.ui.tableWidget_GeometryData_Mixed.setItem(row, 3,
235
                                                                   set_item_properties(inside_pipe_size,
236
                                                                                       Qt.AlignRight | Qt.AlignVCenter))
237

    
238
                    self.ui.tableWidget_GeometryData_Mixed.setItem(row, 4,
239
                                                                   set_item_properties(roughness,
240
                                                                                       Qt.AlignRight | Qt.AlignVCenter))
241

    
242
                    self.ui.tableWidget_GeometryData_Mixed.setItem(row, 5,
243
                                                                   set_item_properties(length,
244
                                                                                       Qt.AlignRight | Qt.AlignVCenter))
245

    
246
                    self.ui.tableWidget_GeometryData_Mixed.setItem(row, 6,
247
                                                                   set_item_properties(angle,
248
                                                                                       Qt.AlignRight | Qt.AlignVCenter))
249

    
250
                    self.ui.tableWidget_GeometryData_Mixed.setItem(row, 7,
251
                                                                   set_item_properties(rpd,
252
                                                                                       Qt.AlignRight | Qt.AlignVCenter))
253

    
254
                    self.ui.tableWidget_GeometryData_Mixed.setItem(row, 8,
255
                                                                   set_item_properties(d1_d2,
256
                                                                                       Qt.AlignRight | Qt.AlignVCenter))
257

    
258
                    self.ui.tableWidget_GeometryData_Mixed.setItem(row, 9,
259
                                                                   set_item_properties(k,
260
                                                                                       Qt.AlignRight | Qt.AlignVCenter))
261

    
262
                    self.ui.tableWidget_GeometryData_Mixed.resizeColumnsToContents()
263
                    self.ui.tableWidget_GeometryData_Mixed.resizeRowsToContents()
264

    
265
        except Exception as ex:
266
            from App import App
267
            from AppDocData import MessageType
268

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

    
273
    def keyPressEvent(self, QKeyEvent):
274
        if QKeyEvent.key() == QtCore.Qt.Key_Delete:
275
            if self.ui.tableWidget_GeometryData_Mixed.hasFocus():
276
                row = self.ui.tableWidget_GeometryData_Mixed.currentRow()
277
                self.ui.tableWidget_GeometryData_Mixed.removeRow(row)
278

    
279
    def context_menu_geometry_data(self, position):
280
        try:
281
            menu = QMenu()
282

    
283
            edit_geometry_data = menu.addAction(self.tr('Edit'))
284
            edit_geometry_data.triggered.connect(lambda: self.edit_geometry_data_click_event())
285
            menu.addAction(edit_geometry_data)
286

    
287
            delete_geometry_data = menu.addAction(self.tr('Delete'))
288
            delete_geometry_data.triggered.connect(lambda: self.delete_geometry_data_click_event())
289
            menu.addAction(delete_geometry_data)
290

    
291
            if self.ui.tableWidget_GeometryData_Mixed.rowCount() > 0:
292
                menu.exec_(self.ui.tableWidget_GeometryData_Mixed.viewport().mapToGlobal(position))
293

    
294
        except Exception as ex:
295
            from App import App
296
            from AppDocData import MessageType
297

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

    
302
    def mixed_density_vapor_change_event(self, text):
303
        if is_not_blank(text):
304
            self.ui.lineEdit_Mixed_Temperature_Vapor.setText('-')
305
            self.ui.lineEdit_Mixed_Temperature_Vapor.setEnabled(False)
306
            self.ui.lineEdit_Mixed_Molecular_Weight_Vapor.setText('-')
307
            self.ui.lineEdit_Mixed_Molecular_Weight_Vapor.setEnabled(False)
308
            self.ui.lineEdit_Mixed_Compress_Factor_Vapor.setText('-')
309
            self.ui.lineEdit_Mixed_Compress_Factor_Vapor.setEnabled(False)
310
        else:
311
            self.ui.lineEdit_Mixed_Temperature_Vapor.clear()
312
            self.ui.lineEdit_Mixed_Temperature_Vapor.setEnabled(True)
313
            self.ui.lineEdit_Mixed_Molecular_Weight_Vapor.clear()
314
            self.ui.lineEdit_Mixed_Molecular_Weight_Vapor.setEnabled(True)
315
            self.ui.lineEdit_Mixed_Compress_Factor_Vapor.clear()
316
            self.ui.lineEdit_Mixed_Compress_Factor_Vapor.setEnabled(True)
317

    
318
    def equivalent_length_change_event(self, text):
319
        if is_not_blank(text):
320
            # Equivalent Length Cal Clear
321
            self.ui.lineEdit_Fitting_Length.clear()
322
            self.ui.lineEdit_Fitting_Length.setStyleSheet('QLineEdit {background-color: rgb(237,237,237);}')
323
            self.ui.lineEdit_Fitting_K.clear()
324
            self.ui.lineEdit_Fitting_K.setStyleSheet('QLineEdit {background-color: rgb(237,237,237);}')
325
            self.ui.lineEdit_Equivalent_Length_Cal.clear()
326
            self.ui.lineEdit_Equivalent_Length_Cal.setStyleSheet('QLineEdit {background-color: rgb(237,237,237);}')
327
        else:
328
            self.ui.lineEdit_Equivalent_Length_Input.setStyleSheet('QLineEdit {background-color: white;}')
329
    def flowrate_change_event(self, text):
330
        if self.sender() == self.ui.lineEdit_Flowrate_Mass_Liquid:
331
            if is_not_blank(text):
332
                self.ui.lineEdit_Flowrate_Volume.clear()
333
                self.ui.lineEdit_Flowrate_Volume.setStyleSheet('QLineEdit {background-color: rgb(237,237,237);}')
334
                self.ui.lineEdit_Flowrate_Mass_Liquid.setStyleSheet('QLineEdit {background-color: white;}')
335
        else:
336
            if is_not_blank(text):
337
                self.ui.lineEdit_Flowrate_Mass_Liquid.clear()
338
                self.ui.lineEdit_Flowrate_Mass_Liquid.setStyleSheet('QLineEdit {background-color: rgb(237,237,237);}')
339
                self.ui.lineEdit_Flowrate_Volume.setStyleSheet('QLineEdit {background-color: white;}')
340

    
341

    
342
    def initialize(self):
343

    
344
        self.ui.tableWidget_GeometryData_Mixed.setColumnCount(10)
345
        self.ui.tableWidget_GeometryData_Mixed.horizontalHeader().setStretchLastSection(True)
346
        col_names = ['Element', 'ND', 'Sch.', 'ID', 'Roughness', 'Length', 'Angle', 'r/D', 'D1/D2', 'K']
347
        self.ui.tableWidget_GeometryData_Mixed.setHorizontalHeaderLabels(col_names)
348

    
349
        self.ui.tableWidget_GeometryData_Mixed.setEditTriggers(QAbstractItemView.NoEditTriggers)
350
        self.ui.tableWidget_GeometryData_Mixed.verticalHeader().setVisible(False)
351
        self.ui.tableWidget_GeometryData_Mixed.resizeColumnsToContents()
352
        self.ui.tableWidget_GeometryData_Mixed.resizeRowsToContents()
353

    
354
    def init_liquid_drop_method(self):
355
        app_doc_data = AppDocData.instance()
356

    
357
        liquid_dp_method = app_doc_data.getConfigs('Calculation', 'Liquid_Drop_Method')
358
        if len(liquid_dp_method) == 1:
359
            self.liquid_drop_method = liquid_dp_method[0].value
360
        else:
361
            self.liquid_drop_method = 'darcy'
362

    
363
    def roughness_clicked_event(self):
364
        from RoughnessDialog import QRoughnessDialog
365
        from Roughness_HagenDialog import QRoughness_HagenDialog
366

    
367
        phase_type = self.ui.comboBox_PhaseType.currentData()
368

    
369
        if phase_type == 'Liquid' and self.liquid_drop_method == 'hagen':
370
            dialog = QRoughness_HagenDialog()
371
        else:
372
            dialog = QRoughnessDialog()
373

    
374
        roughness = dialog.show_dialog()
375
        self.ui.lineEdit_Roughness.setText(str(roughness))
376

    
377
    def validation_check_vapor(self):
378
        message = None
379

    
380
        # Nominal Diameter
381
        nominal_diameter_uid = self.ui.comboBox_Nominal_Pipe_Size.currentData()
382
        flowrate_mass = self.ui.lineEdit_Flowrate_Mass_Vapor.text()
383
        viscosity = self.ui.lineEdit_Viscosity_Vapor.text()
384
        molecular_weight = self.ui.lineEdit_Molecular_Weight.text()
385
        temperature = self.ui.lineEdit_Temperature.text()
386
        compress_factor = self.ui.lineEdit_Compress_Factor.text()
387
        inside_diameter = self.ui.lineEdit_Inside_Pipe_Size.text()
388

    
389
        if nominal_diameter_uid is None:
390
            message = 'Select Nominal Diameter'
391
        elif flowrate_mass is None or flowrate_mass == '':
392
            message = 'Input Flowrate'
393
        elif viscosity is None or viscosity == '':
394
            message = 'Input Viscosity'
395
        elif molecular_weight is None or molecular_weight == '':
396
            message = 'Input Molecular Weight'
397
        elif temperature is None or temperature == '':
398
            message = 'Input Temperature'
399
        elif compress_factor is None or compress_factor == '':
400
            message = 'Input Z factor'
401
        elif inside_diameter is None or inside_diameter == '':
402
            message = 'Select Schedule No.'
403

    
404
        if message:
405
            msg = QMessageBox(self)
406
            msg.setIcon(QMessageBox.Information)
407
            msg.setText(self.tr(message))
408
            msg.setWindowTitle(self.tr("Notice"))
409
            msg.setStandardButtons(QMessageBox.Ok)
410
            msg.exec_()
411
            return False
412
        else:
413
            return True
414

    
415
    def validation_check_liquid(self):
416
        message = None
417

    
418
        nominal_diameter_uid = self.ui.comboBox_Nominal_Pipe_Size.currentData()
419
        flowrate_mass = self.ui.lineEdit_Flowrate_Mass_Liquid.text()
420
        flowrate_volume = self.ui.lineEdit_Flowrate_Volume.text()
421
        density = self.ui.lineEdit_Density.text()
422
        viscosity = self.ui.lineEdit_Viscosity_Liquid.text()
423
        inside_diameter = self.ui.lineEdit_Inside_Pipe_Size.text()
424

    
425
        if nominal_diameter_uid is None:
426
            message = 'Select Nominal Diameter'
427
        elif (flowrate_mass is None or flowrate_mass == '') and (flowrate_volume is None or flowrate_volume == ''):
428
            message = 'Input Flowrate'
429
        elif density is None or density == '':
430
            message = 'Input Density'
431
        elif viscosity is None or viscosity == '':
432
            message = 'Input Viscosity'
433
        elif inside_diameter is None or inside_diameter == '':
434
            message = 'Select Schedule No.'
435

    
436
        if message:
437
            msg = QMessageBox(self)
438
            msg.setIcon(QMessageBox.Information)
439
            msg.setText(self.tr(message))
440
            msg.setWindowTitle(self.tr("Notice"))
441
            msg.setStandardButtons(QMessageBox.Ok)
442
            msg.exec_()
443
            return False
444
        else:
445
            return True
446

    
447
    def load_mixed_result(self, result):
448

    
449
        table = self.ui.tableWidget_Mixed_DB
450
        for row in result:
451
            row_count = table.rowCount()
452

    
453
            table.setRowCount(row_count + 1)
454

    
455
            table.setItem(row_count, 0,
456
                          set_item_properties(row[0], Qt.AlignHCenter | Qt.AlignVCenter))  # No
457
            table.setItem(row_count, 1,
458
                          set_item_properties(row[1], Qt.AlignLeft | Qt.AlignVCenter))  # Element
459
            table.setItem(row_count, 2,
460
                          set_item_properties(row[2], Qt.AlignRight | Qt.AlignVCenter))  # Inside Diameter
461
            table.setItem(row_count, 3,
462
                          set_item_properties(row[3], Qt.AlignRight | Qt.AlignVCenter))  # Length
463
            table.setItem(row_count, 4,
464
                          set_item_properties(row[4], Qt.AlignRight | Qt.AlignVCenter))  # Angle
465
            table.setItem(row_count, 5, set_item_properties(row[5], Qt.AlignRight | Qt.AlignVCenter))  # K
466
            table.setItem(row_count, 6,
467
                          set_item_properties(row[6], Qt.AlignRight | Qt.AlignVCenter))  # Pressure
468
            table.setItem(row_count, 7,
469
                          set_item_properties(row[7], Qt.AlignRight | Qt.AlignVCenter))  # Void
470
            table.setItem(row_count, 8,
471
                          set_item_properties(row[8], Qt.AlignRight | Qt.AlignVCenter))  # Quality
472
            table.setItem(row_count, 9,
473
                          set_item_properties(row[9], Qt.AlignRight | Qt.AlignVCenter))  # Density
474
            table.setItem(row_count, 10,
475
                          set_item_properties(row[10], Qt.AlignRight | Qt.AlignVCenter))  # V.Den
476
            table.setItem(row_count, 11,
477
                          set_item_properties(row[11], Qt.AlignRight | Qt.AlignVCenter))  # Mean Vel
478
            table.setItem(row_count, 12,
479
                          set_item_properties(row[12], Qt.AlignRight | Qt.AlignVCenter))  # Max Vel
480
            table.setItem(row_count, 13,
481
                          set_item_properties(row[13], Qt.AlignRight | Qt.AlignVCenter))  # Ero Vel
482
            table.setItem(row_count, 14,
483
                          set_item_properties(row[14], Qt.AlignRight | Qt.AlignVCenter))  # X
484
            table.setItem(row_count, 15,
485
                          set_item_properties(row[15], Qt.AlignRight | Qt.AlignVCenter))  # Y
486
            table.setItem(row_count, 16,
487
                          set_item_properties(row[16], Qt.AlignLeft | Qt.AlignVCenter))  # Regime
488
            table.setItem(row_count, 17,
489
                          set_item_properties(row[17], Qt.AlignRight | Qt.AlignVCenter))  # Friction
490
            table.setItem(row_count, 18,
491
                          set_item_properties(row[18], Qt.AlignRight | Qt.AlignVCenter))  # Gravity
492
            table.setItem(row_count, 19,
493
                          set_item_properties(row[19], Qt.AlignRight | Qt.AlignVCenter))  # Momentum
494
            table.setItem(row_count, 20,
495
                          set_item_properties(row[20], Qt.AlignRight | Qt.AlignVCenter))  # Total
496

    
497
        table.resizeColumnsToContents()
498
        table.resizeRowsToContents()
499

    
500
    def show_result_dialog(self):
501
        from PressureVariation import QPressureVariation
502

    
503
        dlg = QPressureVariation()
504
        dlg.show_dialog(self.item)
505

    
506
    def show_copy_stream_dialog(self):
507
        from CopyStreamData import QCopyStreamData
508

    
509
        dlg = QCopyStreamData()
510
        (isAccepted, components_uid) = dlg.show_dialog(self.item)
511
        if isAccepted == True:
512
            self.load_hmb(components_uid)
513

    
514
    def mixed_type_calculation(self):
515
        from Calculation import Calculation_2Phase
516
        try:
517
            process = {}
518

    
519
            process['l_flowrate'] = self.ui.lineEdit_Mixed_Flowrate_Mass_Liquid.text()
520
            process['v_flowrate'] = self.ui.lineEdit_Mixed_Flowrate_Mass_Vapor.text()
521
            process['l_density'] = self.ui.lineEdit_Mixed_Density_Liquid.text()
522
            process['v_density'] = self.ui.lineEdit_Mixed_Density_Vapor.text()
523
            process['l_viscosity'] = self.ui.lineEdit_Mixed_Viscosity_Liquid.text()
524
            process['v_viscosity'] = self.ui.lineEdit_Mixed_Viscosity_Vapor.text()
525
            process['tp_pressure'] = self.ui.lineEdit_Mixed_Pressure_Vapor.text()
526
            process['v_temp'] = self.ui.lineEdit_Mixed_Temperature_Vapor.text()
527
            process['v_mw'] = self.ui.lineEdit_Mixed_Molecular_Weight_Vapor.text()
528
            process['v_z'] = self.ui.lineEdit_Mixed_Compress_Factor_Vapor.text()
529

    
530
            if self.ui.tableWidget_GeometryData_Mixed.rowCount() == 0:
531
                QMessageBox.information(self, self.tr("Notice"), self.tr("Please input [Geometry Data] !"))
532
            elif is_not_blank(process['l_flowrate']) or is_not_blank(process['v_flowrate']) or is_not_blank(
533
                    process['l_density']) or is_not_blank(process['l_viscosity']) or is_not_blank(
534
                process['v_viscosity']):
535
                if is_not_blank(process['v_density']):
536
                    if is_not_blank(process['tp_pressure']):
537
                        self.item.mixed_calculation_result = Calculation_2Phase(self.item, process, self.ui.tableWidget_GeometryData_Mixed)
538
                        self.show_result_dialog()
539
                    else:
540
                        QMessageBox.information(self, self.tr("Notice"), self.tr("Please input the [Start pressure] !"))
541
                        return
542
                else:
543
                    if is_not_blank(process['tp_pressure']) and is_not_blank(process['v_temp']) and is_not_blank(
544
                            process['v_mw']) and is_not_blank(process['v_z']):
545
                        self.item.mixed_calculation_result = Calculation_2Phase(self.item, process, self.ui.tableWidget_GeometryData_Mixed)
546
                        self.show_result_dialog()
547
                    else:
548
                        QMessageBox.information(self, self.tr("Notice"), self.tr("Please input [Vapor property] !"))
549
                        return
550
            else:
551
                QMessageBox.information(self, self.tr("Notice"), self.tr("Please input all property !"))
552
        except Exception as ex:
553
            from App import App
554
            from AppDocData import MessageType
555

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

    
560
    def show_geometry_data_dialog(self):
561
        from GeometryData_MixedDialog import QGeometryData_MixedDialog
562

    
563
        try:
564
            row_count = self.ui.tableWidget_GeometryData_Mixed.rowCount()
565

    
566
            data = self.get_data(row_count - 1) if row_count > 0 else None
567

    
568
            dialog = QGeometryData_MixedDialog()
569
            (
570
                isAccepted, element, nominal_pipe_size, schedule_no, inside_pipe_size, roughness, length, angle, rpd,
571
                d1_d2,
572
                k) = dialog.show_dialog(row_count, data)
573

    
574
            if isAccepted:
575
                self.ui.tableWidget_GeometryData_Mixed.setRowCount(row_count + 1)
576

    
577
                self.ui.tableWidget_GeometryData_Mixed.setItem(row_count, 0, set_item_properties(element,
578
                                                                                                 Qt.AlignLeft | Qt.AlignVCenter))
579

    
580
                self.ui.tableWidget_GeometryData_Mixed.setItem(row_count, 1,
581
                                                               set_item_properties(nominal_pipe_size,
582
                                                                                   Qt.AlignRight | Qt.AlignVCenter))
583

    
584
                self.ui.tableWidget_GeometryData_Mixed.setItem(row_count, 2,
585
                                                               set_item_properties(schedule_no,
586
                                                                                   Qt.AlignRight | Qt.AlignVCenter))
587

    
588
                self.ui.tableWidget_GeometryData_Mixed.setItem(row_count, 3,
589
                                                               set_item_properties(inside_pipe_size,
590
                                                                                   Qt.AlignRight | Qt.AlignVCenter))
591

    
592
                self.ui.tableWidget_GeometryData_Mixed.setItem(row_count, 4,
593
                                                               set_item_properties(roughness,
594
                                                                                   Qt.AlignRight | Qt.AlignVCenter))
595

    
596
                self.ui.tableWidget_GeometryData_Mixed.setItem(row_count, 5,
597
                                                               set_item_properties(length,
598
                                                                                   Qt.AlignRight | Qt.AlignVCenter))
599

    
600
                self.ui.tableWidget_GeometryData_Mixed.setItem(row_count, 6,
601
                                                               set_item_properties(angle,
602
                                                                                   Qt.AlignRight | Qt.AlignVCenter))
603

    
604
                self.ui.tableWidget_GeometryData_Mixed.setItem(row_count, 7,
605
                                                               set_item_properties(rpd,
606
                                                                                   Qt.AlignRight | Qt.AlignVCenter))
607

    
608
                self.ui.tableWidget_GeometryData_Mixed.setItem(row_count, 8,
609
                                                               set_item_properties(d1_d2,
610
                                                                                   Qt.AlignRight | Qt.AlignVCenter))
611

    
612
                self.ui.tableWidget_GeometryData_Mixed.setItem(row_count, 9,
613
                                                               set_item_properties(k,
614
                                                                                   Qt.AlignRight | Qt.AlignVCenter))
615

    
616
                self.ui.tableWidget_GeometryData_Mixed.resizeColumnsToContents()
617
                self.ui.tableWidget_GeometryData_Mixed.resizeRowsToContents()
618

    
619
        except Exception as ex:
620
            from App import App
621
            from AppDocData import MessageType
622

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

    
627
    def show_diameter_estimation_dialog(self):
628
        from DiameterEstimation_Liquid import QDiameterEstimation_Liquid
629
        from DiameterEstimation_Vapor import QDiameterEstimation_Vapor
630

    
631
        try:
632
            phase_type = self.ui.comboBox_PhaseType.currentData()
633

    
634
            velocity = self.ui.lineEdit_Limitation_Velocity.text()
635
            pressure_drop = self.ui.lineEdit_Limitation_Pressure_Drop.text()
636
            roughness = self.ui.lineEdit_Roughness.text()
637

    
638
            process_data = {}
639
            if phase_type == 'Liquid':
640
                # Validation Check
641
                density = self.ui.lineEdit_Density.text()
642
                viscosity = self.ui.lineEdit_Viscosity_Liquid.text()
643
                flowrate_mass = self.ui.lineEdit_Flowrate_Mass_Liquid.text()
644
                flowrate_volume = self.ui.lineEdit_Flowrate_Volume.text()
645

    
646
                if is_blank(velocity) and is_blank(pressure_drop):
647
                    QMessageBox.warning(self, self.tr('Warning'), self.tr('Please input the stream criteria !'))
648
                    return
649
                elif is_blank(density) or is_blank(viscosity):
650
                    QMessageBox.warning(self, self.tr('Warning'), self.tr('Please input the stream property !'))
651
                    return
652
                elif is_blank(flowrate_mass) and is_blank(flowrate_volume):
653
                    QMessageBox.warning(self, self.tr('Warning'), self.tr('Please input the flowrate !'))
654
                    return
655
                elif is_blank(roughness):
656
                    QMessageBox.warning(self, self.tr('Warning'), self.tr('Please input the pipe roughness !'))
657
                    return
658

    
659
                process_data['Flowrate_Mass'] = self.ui.lineEdit_Flowrate_Mass_Liquid.text()
660
                process_data['Flowrate_Volume'] = self.ui.lineEdit_Flowrate_Volume.text()
661
                process_data['Density'] = self.ui.lineEdit_Density.text()
662
                process_data['Viscosity'] = self.ui.lineEdit_Viscosity_Liquid.text()
663
                process_data['Roughness'] = self.ui.lineEdit_Roughness.text()
664

    
665
                dialog = QDiameterEstimation_Liquid()
666
            elif phase_type == 'Vapor':
667
                # Validation Check
668
                heat_ratio = self.ui.lineEdit_Specific_Heat_Ratio.text()
669
                viscosity = self.ui.lineEdit_Viscosity_Vapor.text()
670
                compress_factor = self.ui.lineEdit_Compress_Factor.text()
671
                temperature = self.ui.lineEdit_Temperature.text()
672
                flowrate_mass = self.ui.lineEdit_Flowrate_Mass_Vapor.text()
673

    
674
                if is_blank(velocity) and is_blank(pressure_drop):
675
                    QMessageBox.warning(self, self.tr('Warning'), self.tr('Please input the stream criteria !'))
676
                    return
677
                elif is_blank(heat_ratio) or is_blank(viscosity) or is_blank(compress_factor) or is_blank(temperature):
678
                    QMessageBox.warning(self, self.tr('Warning'), self.tr('Please input the stream property !'))
679
                    return
680
                elif is_blank(flowrate_mass):
681
                    QMessageBox.warning(self, self.tr('Warning'), self.tr('Please input the flowrate !'))
682
                    return
683
                elif is_blank(roughness):
684
                    QMessageBox.warning(self, self.tr('Warning'), self.tr('Please input the pipe roughness !'))
685
                    return
686

    
687
                process_data['Flowrate_Mass'] = self.ui.lineEdit_Flowrate_Mass_Vapor.text()
688
                process_data['Molecular_Weight'] = self.ui.lineEdit_Molecular_Weight.text()
689
                process_data['Temperature'] = self.ui.lineEdit_Temperature.text()
690
                process_data['Compress_Factor'] = self.ui.lineEdit_Compress_Factor.text()
691
                process_data['Viscosity'] = self.ui.lineEdit_Viscosity_Liquid.text()
692
                process_data['Roughness'] = self.ui.lineEdit_Roughness.text()
693

    
694
                dialog = QDiameterEstimation_Vapor()
695

    
696
            isAccepted, nominal_pipe_size = dialog.show_dialog(velocity, pressure_drop, process_data)
697
            if isAccepted:
698
                self.ui.comboBox_Nominal_Pipe_Size.setCurrentText(nominal_pipe_size)
699
                self.ui.comboBox_Schedule_No.setCurrentText('Std')
700

    
701
        except Exception as ex:
702
            from App import App
703
            from AppDocData import MessageType
704

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

    
709
    def show_line_sizing_dialog(self):
710
        from LineSizingCriteria import QLineSizingCriteria
711
        try:
712
            phase_type = self.ui.comboBox_PhaseType.currentData()
713

    
714
            dialog = QLineSizingCriteria()
715
            (isAccepted, velocity, pressure_drop) = dialog.show_dialog(phase_type)
716

    
717
            if isAccepted:
718
                self.ui.lineEdit_Limitation_Velocity.setText(velocity)
719
                self.ui.lineEdit_Limitation_Pressure_Drop.setText(pressure_drop)
720
        except Exception as ex:
721
            from App import App
722
            from AppDocData import MessageType
723

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

    
728
        '''
729
        from Line_Sizing_LiquidDialog import QLine_Sizing_LiquidDialog
730
        from Line_Sizing_VaporDialog import QLine_Sizing_VaporDialog
731
        try:
732
            phase_type = self.ui.comboBox_PhaseType.currentData()
733
            if phase_type == 'Vapor':
734
                dialog = QLine_Sizing_VaporDialog()
735
                (isAccepted, velocity, pressure_drop) = dialog.show_dialog()
736
            elif phase_type == 'Liquid':
737
                dialog = QLine_Sizing_LiquidDialog()
738
                (isAccepted, velocity, pressure_drop) = dialog.show_dialog()
739

740
            if isAccepted:
741
                self.ui.lineEdit_Limitation_Velocity.setText(velocity)
742
                self.ui.lineEdit_Limitation_Pressure_Drop.setText(pressure_drop)
743

744
        except Exception as ex:
745
            from App import App
746
            from AppDocData import MessageType
747

748
            message = 'error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename,
749
                                                           sys.exc_info()[-1].tb_lineno)
750
            App.mainWnd().addMessage.emit(MessageType.Error, message)
751
        '''
752

    
753
    def show_fitting_dialog(self):
754
        from FittingsDialog import QFittingsDialog
755

    
756
        try:
757
            phase_type = self.ui.comboBox_PhaseType.currentData()
758
            if phase_type == 'Vapor':
759
                if not self.validation_check_vapor():
760
                    return
761
            elif phase_type == 'Liquid':
762
                if not self.validation_check_liquid():
763
                    return
764
            current_tab_index = self.ui.label_current_tab_index.text() if self.ui.label_current_tab_index else None
765
            nominal_diameter_uid = self.ui.comboBox_Nominal_Pipe_Size.currentData()
766
            dialog = QFittingsDialog(self.item)
767
            (isAccepted, fittings_length, total_k, current_tab_index) = dialog.show_dialog(nominal_diameter_uid,
768
                                                                                           current_tab_index)
769
            if isAccepted:
770
                self.ui.label_current_tab_index.setText(str(current_tab_index))
771
                self.ui.lineEdit_Equivalent_Length_Input.clear()
772
                self.ui.lineEdit_Equivalent_Length_Input.setStyleSheet('QLineEdit {background-color: rgb(237,237,237);}')
773
                self.ui.lineEdit_Fitting_Length.clear()
774
                self.ui.lineEdit_Fitting_Length.setStyleSheet('QLineEdit {background-color: white;}')
775
                self.ui.lineEdit_Fitting_K.clear()
776
                self.ui.lineEdit_Fitting_K.setStyleSheet('QLineEdit {background-color: white;}')
777
                self.ui.lineEdit_Equivalent_Length_Cal.clear()
778
                self.ui.lineEdit_Equivalent_Length_Cal.setStyleSheet('QLineEdit {background-color: white;}')
779

    
780
                if fittings_length > 0:
781
                    # Equivalent Length Method
782
                    self.ui.lineEdit_Fitting_Length.setText(str(fittings_length))
783
                    self.ui.lineEdit_Fitting_K.setText(str(total_k))
784

    
785
                    straight_length = 0
786
                    if self.ui.lineEdit_Straight_Length.text():
787
                        straight_length = float(self.ui.lineEdit_Straight_Length.text())
788

    
789
                    equivalent_length_cal = fittings_length + straight_length
790
                    self.ui.lineEdit_Equivalent_Length_Cal.setText(str(equivalent_length_cal))
791
                elif total_k > 0:
792
                    # CraneK Method or 2-K Method
793
                    if phase_type == 'Vapor':
794
                        fittings_length = self.get_equivalent_length_vapor(total_k)
795
                    elif phase_type == 'Liquid':
796
                        fittings_length = self.get_equivalent_length_liquid(total_k)
797

    
798
                    self.ui.lineEdit_Fitting_Length.setText(str(fittings_length))
799
                    self.ui.lineEdit_Fitting_K.setText(str(total_k))
800

    
801
                    straight_length = 0
802
                    if self.ui.lineEdit_Straight_Length.text():
803
                        straight_length = float(self.ui.lineEdit_Straight_Length.text())
804

    
805
                    equivalent_length_cal = fittings_length + straight_length
806
                    self.ui.lineEdit_Equivalent_Length_Cal.setText(str(equivalent_length_cal))
807
        except Exception as ex:
808
            from App import App
809
            from AppDocData import MessageType
810

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

    
815
    # 마찰계수 산출
816
    def get_friction_coefficient_vapor(self):
817
        # '**********************************************************************************
818
        # '참고사항 :
819
        # '유닛의 기준 : 유량 (kg/h, m3/h), 밀도 (kg/m3), 지름 (m), 점도 (kg/m/s), 속도 (m/s), 압력 (kg/cm2(a))
820
        # ' mw (g/mol), temperature (kalvin)
821

    
822
        # '주의 : 레이놀즈 넘버와 마찰계수를 구하는 과정에서 액체의 모듈을 따와서 작업을 했는데
823
        # '       그렇게 한 결과 어차피 레이놀즈는 결국 질량 유속과 점도, 파이프 지름만의 함수가 되기때문에
824
        # '       밀도를 구하고 이를 적용하는 과정은 생략해버림.
825
        # '       이것은 아래 density calculation 부분에서 * Val(frm_K_2K.Label49)  이었음
826

    
827
        # '       현재 이것은 없어져 있는 상태임. from 김상도
828
        # '**********************************************************************************
829

    
830
        temperature = self.ui.lineEdit_Temperature.text()
831
        compress_factor = self.ui.lineEdit_Compress_Factor.text()
832
        flowrate_mass = self.ui.lineEdit_Flowrate_Mass_Vapor.text()
833
        viscosity = self.ui.lineEdit_Viscosity_Vapor.text()
834
        roughness = self.ui.lineEdit_Roughness.text()
835
        inside_pipe_size = self.ui.lineEdit_Inside_Pipe_Size.text()
836

    
837
        # 'molecular weight
838
        mw = float(self.ui.lineEdit_Molecular_Weight.text())
839

    
840
        # 'temperature
841
        temperature_unit = self.ui.label_Temperature_Unit.text()
842
        if temperature_unit == '':
843
            temp = float(temperature) + 273.15
844
        elif temperature_unit == '':
845
            temp = (float(temperature) - 32) / 1.8 + 273.15
846

    
847
        # 'compressibility
848
        z = float(compress_factor)
849

    
850
        # ' density calculation
851
        density = mw / 0.08206 / temp / z / 1.033  # * Val(frm_K_2K.Label49)         <--  이 부분은 받은 압력을 계산하는 부분이었으나, 이제는 그럴 필요가 없어졌으므로 삭제함
852

    
853
        density_unit = self.ui.label_Density_Unit.text()
854
        if density_unit == 'kg/m3':
855
            density = density
856
        elif density_unit == 'lb/ft3':
857
            density = density * 0.062428
858

    
859
        # '************************* 2. volume flowrate *************************
860
        # 'mass gain
861
        flowrate_mass_unit = self.ui.label_Flowrate_Mass_Unit_Vapor.text()
862
        if flowrate_mass_unit == 'kg/h':
863
            mass = float(flowrate_mass)
864
        elif flowrate_mass_unit == 'g/min':
865
            mass = float(flowrate_mass) * 60 / 1000
866
        elif flowrate_mass_unit == 'lb/h':
867
            mass = float(flowrate_mass) * 0.453592
868
        elif flowrate_mass_unit == 't/h':
869
            mass = float(flowrate_mass) * 1000
870

    
871
        # 'volume calculation (m3/h)
872
        volume = mass / density
873

    
874
        # ' ********** 2. viscosity 구하기 ***********
875
        viscosity_unit = self.ui.label_Viscosity_Unit_Vapor.text()
876
        if viscosity_unit == 'kg/m.sec':
877
            viscosity = float(viscosity)
878
        elif viscosity_unit == 'cP':
879
            viscosity = float(viscosity) * 0.001
880
        elif viscosity_unit == 'kg/m.h':
881
            viscosity = float(viscosity) / 3600
882
        elif viscosity_unit == 'lb/ft.s':
883
            viscosity = float(viscosity) * 1.48816
884

    
885
        # ' ********** 3. ND, 속도, 구함 **********
886

    
887
        # '조도 구함 (m)
888
        roughness_unit = self.ui.label_Roughness_Unit.text()
889
        if roughness_unit == 'm':
890
            rough = float(roughness)
891
        elif roughness_unit == 'ft':
892
            rough = float(roughness) * 0.3048
893
        elif roughness_unit == 'in':
894
            rough = float(roughness) * 0.0254
895
        elif roughness_unit == 'mm':
896
            rough = float(roughness) * 0.001
897

    
898
        # 'ND 구함 (in)
899
        nominal_pipe_size_unit = self.ui.label_Nominal_Pipe_Size_Unit.text()
900
        if nominal_pipe_size_unit == 'in':
901
            nd = float(inside_pipe_size)
902
        elif nominal_pipe_size_unit == 'mm':
903
            nd = float(inside_pipe_size) / 25
904

    
905
        # ' 속도 구함
906
        velocity = 4 * volume / 3.1415 / ((nd * 0.0254) ** 2) / 3600
907

    
908
        # ' 레이놀즈 넘버 구함
909
        reynolds = (nd * 0.0254) * velocity * density / viscosity
910

    
911
        # '마찰계수 산출
912
        if reynolds < 2100:
913
            f = 4 * 16 / reynolds
914
        else:
915
            a = math.log(rough / (nd * 0.0254) / 3.7 + (6.7 / reynolds) ** 0.9) / math.log(10)
916
            f = (-2 * (math.log(rough / 3.7 / (nd * 0.0254) - 5.02 / reynolds * a) / math.log(10))) ** (-2)
917

    
918
        return f
919

    
920
    # 마찰계수 산출
921
    def get_friction_coefficient_liquid(self):
922
        # '**********************************************************************************
923
        # '참고사항 :
924
        # '유닛의 기준 : 유량 (kg/h, m3/h), 밀도 (kg/m3), 지름 (m), 점도 (kg/m/s), 속도 (m/s), 압력강하 (kg/cm2/100m)
925
        # '**********************************************************************************
926

    
927
        flowrate_mass = self.ui.lineEdit_Flowrate_Mass_Liquid.text()
928
        flowrate_volume = self.ui.lineEdit_Flowrate_Volume.text()
929
        viscosity = self.ui.lineEdit_Viscosity_Liquid.text()
930
        roughness = self.ui.lineEdit_Roughness.text()
931
        inside_pipe_size = self.ui.lineEdit_Inside_Pipe_Size.text()
932

    
933
        # ' ********** 1. volume flowrate 구하기 ***********
934
        # '(1) 질량이 적혀있는 경우
935
        if flowrate_mass:
936
            density = float(self.ui.lineEdit_Density.text())
937

    
938
            # '질량 유량을 kg/h로 변환
939
            flowrate_mass_unit = self.ui.label_Flowrate_Mass_Unit_Liquid.text()
940
            if flowrate_mass_unit == 'kg/h':
941
                mass = float(flowrate_mass)
942
            elif flowrate_mass_unit == 'g/min':
943
                mass = float(flowrate_mass) * 60 / 1000
944
            elif flowrate_mass_unit == 'lb/h':
945
                mass = float(flowrate_mass) * 0.453592
946
            elif flowrate_mass_unit == 't/h':
947
                mass = float(flowrate_mass) * 1000
948

    
949
            # '밀도에 맞춰서 부피 유량 산출 (m3/h)
950
            density_unit = self.ui.label_Density_Unit.text()
951
            if density_unit == 'kg/m3':
952
                volume = mass / density
953
            elif density_unit == 'lb/ft3':
954
                volume = mass / (density * 16.0185)
955
        # (2)부피가 적혀있는경우
956
        elif flowrate_volume:
957
            density = float(self.ui.lineEdit_Density.text())
958

    
959
            # '부피유량을 m3/h로 변환.
960
            flowrate_volume_unit = self.ui.label_Flowrate_Volume_Unit.text()
961
            if flowrate_volume_unit == 'm3/h':
962
                volume = float(flowrate_volume)
963
            elif flowrate_volume_unit == 'l/min':
964
                volume = float(flowrate_volume) * 60 / 1000
965
            elif flowrate_volume_unit == 'ft3/h':
966
                volume = float(flowrate_volume) / 35.3147
967
            elif flowrate_volume_unit == 'USgpm':
968
                volume = float(flowrate_volume) / 4.40287
969
            elif flowrate_volume_unit == 'BPSD':
970
                volume = float(flowrate_volume) / 150.955
971

    
972
        # ' ********** 2. viscosity 구하기 ***********
973
        viscosity_unit = self.ui.label_Viscosity_Unit_Liquid.text()
974
        if viscosity_unit == 'kg/m.sec':
975
            viscosity = float(viscosity)
976
        elif viscosity_unit == 'cP':
977
            viscosity = float(viscosity) * 0.001
978
        elif viscosity_unit == 'kg/m.h':
979
            viscosity = float(viscosity) / 3600
980
        elif viscosity_unit == 'lb/ft.s':
981
            viscosity = float(viscosity) * 1.48816
982

    
983
        # '조도 구함 (m)
984
        roughness_unit = self.ui.label_Roughness_Unit.text()
985
        if roughness_unit == 'm':
986
            rough = float(roughness)
987
        elif roughness_unit == 'ft':
988
            rough = float(roughness) * 0.3048
989
        elif roughness_unit == 'in':
990
            rough = float(roughness) * 0.0254
991
        elif roughness_unit == 'mm':
992
            rough = float(roughness) * 0.001
993

    
994
        # '여기까지 mod_calc_pde부분을 그대로 따온 것임
995

    
996
        # 'ID 구함 (in)
997
        nominal_pipe_size_unit = self.ui.label_Nominal_Pipe_Size_Unit.text()
998
        if nominal_pipe_size_unit == 'in':
999
            nd = float(inside_pipe_size)
1000
        elif nominal_pipe_size_unit == 'mm':
1001
            nd = float(inside_pipe_size) / 25
1002

    
1003
        # ' 속도 구함
1004
        velocity = 4 * volume / 3.1415 / ((nd * 0.0254) ** 2) / 3600
1005

    
1006
        # ' 레이놀즈 넘버 구함
1007
        reynolds = (nd * 0.0254) * velocity * density / viscosity
1008

    
1009
        # '마찰계수 산출
1010
        if reynolds < 2100:
1011
            f = 4 * 16 / reynolds
1012
        else:
1013
            a = math.log(rough / (nd * 0.0254) / 3.7 + (6.7 / reynolds) ** 0.9) / math.log(10)
1014
            f = (-2 * (math.log(rough / 3.7 / (nd * 0.0254) - 5.02 / reynolds * a) / math.log(10))) ** (-2)
1015

    
1016
        return f
1017

    
1018
    def get_equivalent_length_liquid(self, total_k):
1019
        # 마찰계수
1020
        friction_coefficient = self.get_friction_coefficient_liquid()
1021

    
1022
        pipe_unit = self.ui.label_Inside_Pipe_Size_Unit.text()
1023
        pipe_id = float(self.ui.lineEdit_Inside_Pipe_Size.text())
1024
        if pipe_unit == 'in':
1025
            return round(pipe_id * total_k / friction_coefficient * 0.0254, 3)
1026
        elif pipe_unit == 'mm':
1027
            return round(pipe_id * total_k / friction_coefficient / 1000, 3)
1028

    
1029
    def get_equivalent_length_vapor(self, total_k):
1030
        # 마찰계수
1031
        friction_coefficient = self.get_friction_coefficient_vapor()
1032

    
1033
        pipe_unit = self.ui.label_Inside_Pipe_Size_Unit.text()
1034
        pipe_id = float(self.ui.lineEdit_Inside_Pipe_Size.text())
1035
        if pipe_unit == 'in':
1036
            return round(pipe_id * total_k / total_k * 0.0254, 3)
1037
        elif pipe_unit == 'mm':
1038
            return round(pipe_id * total_k / total_k / 1000, 3)
1039

    
1040
    def init_phase_type(self):
1041
        self.ui.comboBox_PhaseType.clear()
1042

    
1043
        self.ui.comboBox_PhaseType.addItem('Vapor (Compressible)', 'Vapor')
1044
        self.ui.comboBox_PhaseType.addItem('Liquid (Incompressible)', 'Liquid')
1045
        self.ui.comboBox_PhaseType.addItem('Mixed (Vapor + Liquid)', 'Mixed')
1046

    
1047
        self.ui.comboBox_PhaseType.setCurrentIndex(0)
1048

    
1049
    def init_units(self):
1050
        app_doc_data = AppDocData.instance()
1051
        active_drawing = app_doc_data.activeDrawing
1052

    
1053
        for attr in active_drawing.attrs:
1054
            if attr[0] == 'Units':
1055
                self.ui.label_Flowrate_Mass_Unit_Liquid.setText(attr[1]['Flowrate_Mass'])
1056
                self.ui.label_Flowrate_Mass_Unit_Vapor.setText(attr[1]['Flowrate_Mass'])
1057
                self.ui.label_Flowrate_Mass_Unit_Mixed.setText(attr[1]['Flowrate_Mass'])
1058
                self.ui.label_Flowrate_Volume_Unit.setText(attr[1]['Flowrate_Volume'])
1059
                self.ui.label_Density_Unit.setText(attr[1]['Density'])
1060
                self.ui.label_Density_Unit_Mixed.setText(attr[1]['Density'])
1061
                self.ui.label_Viscosity_Unit_Liquid.setText(attr[1]['Viscosity'])
1062
                self.ui.label_Viscosity_Unit_Vapor.setText(attr[1]['Viscosity'])
1063
                self.ui.label_Viscosity_Unit_Mixed.setText(attr[1]['Viscosity'])
1064
                self.ui.label_Velocity_Unit.setText(attr[1]['Velocity'])
1065
                self.ui.label_DropPressure_Unit.setText('{}/100{}'.format(attr[1]['Pressure'], attr[1]['Length']))
1066
                self.ui.label_Nominal_Pipe_Size_Unit.setText(attr[1]['Pipe_Diameter'])
1067
                self.ui.label_Inside_Pipe_Size_Unit.setText(attr[1]['Pipe_Diameter'])
1068
                if self.liquid_drop_method == 'darcy':
1069
                    self.ui.label_Roughness_Unit.setText(attr[1]['Roughness'])
1070
                else:
1071
                    self.ui.label_Roughness_Unit.setText('')
1072
                self.ui.label_Straight_Lengh_Unit.setText(attr[1]['Length'])
1073
                self.ui.label_Equivalent_Lenght_Input_Unit.setText(attr[1]['Length'])
1074
                self.ui.label_Fitting_Length_Unit.setText(attr[1]['Length'])
1075
                self.ui.label_Equivalent_Lenght_Cal_Unit.setText(attr[1]['Length'])
1076
                self.ui.label_Temperature_Unit.setText(attr[1]['Temperature'])
1077
                self.ui.label_Temperature_Unit_Mixed.setText(attr[1]['Temperature'])
1078
                self.ui.label_Pressure_Unit_Mixed.setText('{}(g)'.format(attr[1]['Pressure']))
1079

    
1080
    def on_change_phase_type(self):
1081
        phase_type = self.ui.comboBox_PhaseType.currentData()
1082

    
1083
        if phase_type == 'Vapor':
1084
            self.ui.groupBox_ProcessData_Vapor.setVisible(True)
1085
            self.ui.groupBox_Line_Sizing_Data.setVisible(True)
1086
            self.ui.groupBox_GeometryData.setVisible(True)
1087
            self.ui.pushButton_Line_Sizing.setVisible(True)
1088
            self.ui.pushButton_Diameter_Estimation.setVisible(True)
1089
            self.ui.pushButton_Copy_Stream.setVisible(True)
1090
            self.ui.groupBox_ProcessData_Liquid.setVisible(False)
1091

    
1092
            self.ui.groupBox_ProcessData_Mixed.setVisible(False)
1093
            self.ui.groupBox_GeometryData_Mixed.setVisible(False)
1094
            self.ui.pushButton_Add_GeometryData_Mixed.setVisible(False)
1095
            self.ui.pushButton_Calculation.setVisible(False)
1096
        elif phase_type == 'Liquid':
1097
            self.ui.groupBox_ProcessData_Liquid.setVisible(True)
1098
            self.ui.groupBox_Line_Sizing_Data.setVisible(True)
1099
            self.ui.groupBox_GeometryData.setVisible(True)
1100
            self.ui.pushButton_Line_Sizing.setVisible(True)
1101
            self.ui.pushButton_Diameter_Estimation.setVisible(True)
1102
            self.ui.pushButton_Copy_Stream.setVisible(True)
1103
            self.ui.groupBox_ProcessData_Vapor.setVisible(False)
1104

    
1105
            self.ui.groupBox_ProcessData_Mixed.setVisible(False)
1106
            self.ui.groupBox_GeometryData_Mixed.setVisible(False)
1107
            self.ui.pushButton_Add_GeometryData_Mixed.setVisible(False)
1108
            self.ui.pushButton_Calculation.setVisible(False)
1109
        elif phase_type == 'Mixed':
1110
            self.ui.groupBox_ProcessData_Mixed.setVisible(True)
1111
            self.ui.groupBox_GeometryData_Mixed.setVisible(True)
1112
            self.ui.pushButton_Add_GeometryData_Mixed.setVisible(True)
1113
            self.ui.pushButton_Calculation.setVisible(True)
1114

    
1115
            self.ui.groupBox_ProcessData_Vapor.setVisible(False)
1116
            self.ui.groupBox_ProcessData_Liquid.setVisible(False)
1117
            self.ui.groupBox_Line_Sizing_Data.setVisible(False)
1118
            self.ui.groupBox_GeometryData.setVisible(False)
1119
            self.ui.pushButton_Line_Sizing.setVisible(False)
1120
            self.ui.pushButton_Diameter_Estimation.setVisible(False)
1121
            self.ui.pushButton_Copy_Stream.setVisible(False)
1122

    
1123
    def getInsideDiameter(self):
1124
        from AppDocData import AppDocData
1125

    
1126
        self.ui.lineEdit_Inside_Pipe_Size.clear()
1127

    
1128
        nominal_diameter_uid = self.ui.comboBox_Nominal_Pipe_Size.currentData()
1129
        schedule_uid = self.ui.comboBox_Schedule_No.currentData()
1130

    
1131
        if nominal_diameter_uid and schedule_uid:
1132
            inside_diameter = AppDocData.instance().getInsideDiameter(nominal_diameter_uid, schedule_uid)
1133
            if len(inside_diameter) > 0:
1134
                if self.ui.label_Inside_Pipe_Size_Unit.text() == 'mm':
1135
                    if inside_diameter[0][1]:
1136
                        self.ui.lineEdit_Inside_Pipe_Size.setText(str(inside_diameter[0][1]))
1137
                else:
1138
                    if inside_diameter[0][2]:
1139
                        self.ui.lineEdit_Inside_Pipe_Size.setText(str(inside_diameter[0][2]))
1140

    
1141
    def init_nominal_diameter(self):
1142
        from AppDocData import AppDocData
1143

    
1144
        self.ui.comboBox_Nominal_Pipe_Size.clear()
1145

    
1146
        nominal_diameter_list = AppDocData.instance().getNominalDiameter()
1147
        for nominalDiameter in nominal_diameter_list:
1148
            if self.ui.label_Nominal_Pipe_Size_Unit.text() == 'mm':
1149
                self.ui.comboBox_Nominal_Pipe_Size.addItem(str(nominalDiameter[1]), nominalDiameter[0])
1150
            else:
1151
                self.ui.comboBox_Nominal_Pipe_Size.addItem(str(nominalDiameter[2]), nominalDiameter[0])
1152
        self.ui.comboBox_Nominal_Pipe_Size.setCurrentIndex(-1)
1153

    
1154
    def init_schedule(self):
1155
        from AppDocData import AppDocData
1156

    
1157
        self.ui.comboBox_Schedule_No.clear()
1158

    
1159
        schedule_list = AppDocData.instance().getSchedule()
1160
        for schedule in schedule_list:
1161
            self.ui.comboBox_Schedule_No.addItem(schedule[1], schedule[0])
1162

    
1163
        self.ui.comboBox_Schedule_No.setCurrentIndex(-1)
1164

    
1165
    def showDialog(self, item):
1166
        self.item = item
1167
        self.setWindowFlags(self.windowFlags() & ~QtCore.Qt.WindowContextHelpButtonHint)
1168
        self.ui.lineEdit_StreamNo.setText(str(item.stream_no))
1169
        self.load_hmb(item.uid)
1170
        self.load_geometry()
1171
        self.exec_()
1172

    
1173
        return self.result
1174

    
1175
    def load_geometry(self):
1176
        from AppDocData import AppDocData
1177
        try:
1178
            geometry = self.item.mixed_geometry
1179
            if geometry:
1180
                for row in geometry:
1181
                    row_count = self.ui.tableWidget_GeometryData_Mixed.rowCount()
1182

    
1183
                    self.ui.tableWidget_GeometryData_Mixed.setRowCount(row_count + 1)
1184

    
1185
                    self.ui.tableWidget_GeometryData_Mixed.setItem(row_count, 0,
1186
                                                                   set_item_properties(row[0],
1187
                                                                                       Qt.AlignLeft | Qt.AlignVCenter))
1188

    
1189
                    self.ui.tableWidget_GeometryData_Mixed.setItem(row_count, 1,
1190
                                                                   set_item_properties(row[1],
1191
                                                                                       Qt.AlignRight | Qt.AlignVCenter))
1192

    
1193
                    self.ui.tableWidget_GeometryData_Mixed.setItem(row_count, 2,
1194
                                                                   set_item_properties(row[2],
1195
                                                                                       Qt.AlignRight | Qt.AlignVCenter))
1196

    
1197
                    self.ui.tableWidget_GeometryData_Mixed.setItem(row_count, 3,
1198
                                                                   set_item_properties(row[3],
1199
                                                                                       Qt.AlignRight | Qt.AlignVCenter))
1200

    
1201
                    self.ui.tableWidget_GeometryData_Mixed.setItem(row_count, 4,
1202
                                                                   set_item_properties(row[4],
1203
                                                                                       Qt.AlignRight | Qt.AlignVCenter))
1204

    
1205
                    self.ui.tableWidget_GeometryData_Mixed.setItem(row_count, 5,
1206
                                                                   set_item_properties(row[5],
1207
                                                                                       Qt.AlignRight | Qt.AlignVCenter))
1208

    
1209
                    self.ui.tableWidget_GeometryData_Mixed.setItem(row_count, 6,
1210
                                                                   set_item_properties(row[6],
1211
                                                                                       Qt.AlignRight | Qt.AlignVCenter))
1212

    
1213
                    self.ui.tableWidget_GeometryData_Mixed.setItem(row_count, 7,
1214
                                                                   set_item_properties(row[7],
1215
                                                                                       Qt.AlignRight | Qt.AlignVCenter))
1216

    
1217
                    self.ui.tableWidget_GeometryData_Mixed.setItem(row_count, 8,
1218
                                                                   set_item_properties(row[8],
1219
                                                                                       Qt.AlignRight | Qt.AlignVCenter))
1220

    
1221
                    self.ui.tableWidget_GeometryData_Mixed.setItem(row_count, 9,
1222
                                                                   set_item_properties(row[9],
1223
                                                                                       Qt.AlignRight | Qt.AlignVCenter))
1224

    
1225
                self.ui.tableWidget_GeometryData_Mixed.resizeColumnsToContents()
1226
                self.ui.tableWidget_GeometryData_Mixed.resizeRowsToContents()
1227

    
1228
        except Exception as ex:
1229
            from App import App
1230
            from AppDocData import MessageType
1231

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

    
1236
    def load_hmb(self, components_uid):
1237
        from AppDocData import AppDocData
1238
        try:
1239

    
1240
            drawing = AppDocData.instance().activeDrawing
1241
            if drawing:
1242
                matches = [hmb for hmb in drawing.hmbTable._hmbs if hmb.components_uid == components_uid]
1243
                if matches:
1244

    
1245
                    if matches[0].phase_type:
1246
                        index = self.ui.comboBox_PhaseType.findData(matches[0].phase_type)
1247
                        if index > -1:
1248
                            self.ui.comboBox_PhaseType.setCurrentIndex(index)
1249
                    if matches[0].flowrate_mass:
1250
                        self.ui.lineEdit_Flowrate_Mass_Liquid.setText(str(matches[0].flowrate_mass))
1251
                        self.ui.lineEdit_Flowrate_Mass_Vapor.setText(str(matches[0].flowrate_mass))
1252
                    if matches[0].flowrate_volume:
1253
                        self.ui.lineEdit_Flowrate_Volume.setText(str(matches[0].flowrate_volume))
1254
                    if matches[0].viscosity:
1255
                        self.ui.lineEdit_Viscosity_Liquid.setText(str(matches[0].viscosity))
1256
                        self.ui.lineEdit_Viscosity_Vapor.setText(str(matches[0].viscosity))
1257

    
1258
                    if matches[0].specific_heat_ratio:
1259
                        self.ui.lineEdit_Specific_Heat_Ratio.setText(str(matches[0].specific_heat_ratio))
1260
                    if matches[0].molecular_weight:
1261
                        self.ui.lineEdit_Molecular_Weight.setText(str(matches[0].molecular_weight))
1262
                    if matches[0].temperature:
1263
                        self.ui.lineEdit_Temperature.setText(str(matches[0].temperature))
1264
                    if matches[0].compress_factor:
1265
                        self.ui.lineEdit_Compress_Factor.setText(str(matches[0].compress_factor))
1266

    
1267
                    if matches[0].density:
1268
                        self.ui.lineEdit_Density.setText(str(matches[0].density))
1269
                    if matches[0].limitation_velocity:
1270
                        self.ui.lineEdit_Limitation_Velocity.setText(str(matches[0].limitation_velocity))
1271
                    if matches[0].limitation_pressure_drop:
1272
                        self.ui.lineEdit_Limitation_Pressure_Drop.setText(str(matches[0].limitation_pressure_drop))
1273
                    if matches[0].nominal_pipe_size:
1274
                        self.ui.comboBox_Nominal_Pipe_Size.setCurrentText(str(matches[0].nominal_pipe_size))
1275
                    if matches[0].schedule_no:
1276
                        self.ui.comboBox_Schedule_No.setCurrentText(str(matches[0].schedule_no))
1277
                    if matches[0].roughness:
1278
                        self.ui.lineEdit_Roughness.setText(str(matches[0].roughness))
1279
                    if matches[0].straight_length:
1280
                        self.ui.lineEdit_Straight_Length.setText(str(matches[0].straight_length))
1281
                    if matches[0].equivalent_length_input:
1282
                        self.ui.lineEdit_Equivalent_Length_Input.setText(str(matches[0].equivalent_length_input))
1283
                    if matches[0].fitting_length:
1284
                        self.ui.lineEdit_Fitting_Length.setText(str(matches[0].fitting_length))
1285
                    if matches[0].fitting_K:
1286
                        self.ui.lineEdit_Fitting_K.setText(str(matches[0].fitting_K))
1287
                    if matches[0].equivalent_length_cal:
1288
                        self.ui.lineEdit_Equivalent_Length_Cal.setText(str(matches[0].equivalent_length_cal))
1289
                    if matches[0].vapor_flowrate_mass:
1290
                        self.ui.lineEdit_Mixed_Flowrate_Mass_Vapor.setText(str(matches[0].vapor_flowrate_mass))
1291
                    if matches[0].vapor_density:
1292
                        self.ui.lineEdit_Mixed_Density_Vapor.setText(str(matches[0].vapor_density))
1293
                    if matches[0].vapor_viscosity:
1294
                        self.ui.lineEdit_Mixed_Viscosity_Vapor.setText(str(matches[0].vapor_viscosity))
1295
                    if matches[0].vapor_pressure:
1296
                        self.ui.lineEdit_Mixed_Pressure_Vapor.setText(str(matches[0].vapor_pressure))
1297
                    if matches[0].vapor_temperature:
1298
                        self.ui.lineEdit_Mixed_Temperature_Vapor.setText(str(matches[0].vapor_temperature))
1299
                    if matches[0].vapor_molecular_weight:
1300
                        self.ui.lineEdit_Mixed_Molecular_Weight_Vapor.setText(str(matches[0].vapor_molecular_weight))
1301
                    if matches[0].vapor_compress_factor:
1302
                        self.ui.lineEdit_Mixed_Compress_Factor_Vapor.setText(str(matches[0].vapor_compress_factor))
1303
                    if matches[0].liquid_flowrate_mass:
1304
                        self.ui.lineEdit_Mixed_Flowrate_Mass_Liquid.setText(str(matches[0].liquid_flowrate_mass))
1305
                    if matches[0].liquid_density:
1306
                        self.ui.lineEdit_Mixed_Density_Liquid.setText(str(matches[0].liquid_density))
1307
                    if matches[0].liquid_viscosity:
1308
                        self.ui.lineEdit_Mixed_Viscosity_Liquid.setText(str(matches[0].liquid_viscosity))
1309

    
1310
        except Exception as ex:
1311
            from App import App
1312
            from AppDocData import MessageType
1313

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

    
1318
    def update_HMB(self):
1319
        from AppDocData import AppDocData
1320

    
1321
        try:
1322
            drawing = AppDocData.instance().activeDrawing
1323
            if drawing:
1324
                values = {}
1325

    
1326
                phase_type = self.ui.comboBox_PhaseType.currentData()
1327
                values['Phase_Type'] = phase_type
1328
                if phase_type == 'Vapor':
1329
                    values['Flowrate_Mass'] = self.ui.lineEdit_Flowrate_Mass_Vapor.text()
1330
                    values['Viscosity'] = self.ui.lineEdit_Viscosity_Vapor.text()
1331
                    values['Specific_Heat_Ratio'] = self.ui.lineEdit_Specific_Heat_Ratio.text()
1332
                    values['Molecular_Weight'] = self.ui.lineEdit_Molecular_Weight.text()
1333
                    values['Temperature'] = self.ui.lineEdit_Temperature.text()
1334
                    values['Compress_Factor'] = self.ui.lineEdit_Compress_Factor.text()
1335
                    values['Limitation_Velocity'] = self.ui.lineEdit_Limitation_Velocity.text()
1336
                    values['Limitation_Pressure_Drop'] = self.ui.lineEdit_Limitation_Pressure_Drop.text()
1337
                    values['Nominal_Pipe_Size'] = self.ui.comboBox_Nominal_Pipe_Size.currentText()
1338
                    values['Inside_Pipe_Size'] = self.ui.lineEdit_Inside_Pipe_Size.text()
1339
                    values['Schedule_No'] = self.ui.comboBox_Schedule_No.currentText()
1340
                    values['Roughness'] = self.ui.lineEdit_Roughness.text()
1341
                    values['Straight_Length'] = self.ui.lineEdit_Straight_Length.text()
1342
                    values['Equivalent_Length'] = self.get_equivalent_length()
1343
                    values['Equivalent_Length_Input'] = self.ui.lineEdit_Equivalent_Length_Input.text()
1344
                    values['Fitting_Length'] = self.ui.lineEdit_Fitting_Length.text()
1345
                    values['Fitting_K'] = self.ui.lineEdit_Fitting_K.text()
1346
                    values['Equivalent_Length_Cal'] = self.ui.lineEdit_Equivalent_Length_Cal.text()
1347
                    values['Flowrate_Volume'] = None
1348
                    values['Density'] = None
1349
                elif phase_type == 'Liquid':
1350
                    values['Flowrate_Mass'] = self.ui.lineEdit_Flowrate_Mass_Liquid.text()
1351
                    values['Flowrate_Volume'] = self.ui.lineEdit_Flowrate_Volume.text()
1352
                    values['Density'] = self.ui.lineEdit_Density.text()
1353
                    values['Viscosity'] = self.ui.lineEdit_Viscosity_Liquid.text()
1354
                    values['Limitation_Velocity'] = self.ui.lineEdit_Limitation_Velocity.text()
1355
                    values['Limitation_Pressure_Drop'] = self.ui.lineEdit_Limitation_Pressure_Drop.text()
1356
                    values['Nominal_Pipe_Size'] = self.ui.comboBox_Nominal_Pipe_Size.currentText()
1357
                    values['Inside_Pipe_Size'] = self.ui.lineEdit_Inside_Pipe_Size.text()
1358
                    values['Schedule_No'] = self.ui.comboBox_Schedule_No.currentText()
1359
                    values['Roughness'] = self.ui.lineEdit_Roughness.text()
1360
                    values['Straight_Length'] = self.ui.lineEdit_Straight_Length.text()
1361
                    values['Equivalent_Length'] = self.get_equivalent_length()
1362
                    values['Equivalent_Length_Input'] = self.ui.lineEdit_Equivalent_Length_Input.text()
1363
                    values['Fitting_Length'] = self.ui.lineEdit_Fitting_Length.text()
1364
                    values['Fitting_K'] = self.ui.lineEdit_Fitting_K.text()
1365
                    values['Equivalent_Length_Cal'] = self.ui.lineEdit_Equivalent_Length_Cal.text()
1366
                    values['Specific_Heat_Ratio'] = None
1367
                    values['Molecular_Weight'] = None
1368
                    values['Temperature'] = None
1369
                    values['Compress_Factor'] = None
1370
                elif phase_type == 'Mixed':
1371
                    values['Vapor_Flowrate_Mass'] = self.ui.lineEdit_Mixed_Flowrate_Mass_Vapor.text()
1372
                    values['Vapor_Density'] = self.ui.lineEdit_Mixed_Density_Vapor.text()
1373
                    values['Vapor_Viscosity'] = self.ui.lineEdit_Mixed_Viscosity_Vapor.text()
1374
                    values['Vapor_Pressure'] = self.ui.lineEdit_Mixed_Pressure_Vapor.text()
1375
                    values['Vapor_Temperature'] = self.ui.lineEdit_Mixed_Temperature_Vapor.text()
1376
                    values['Vapor_Molecular_Weight'] = self.ui.lineEdit_Mixed_Molecular_Weight_Vapor.text()
1377
                    values['Vapor_Compress_Factor'] = self.ui.lineEdit_Mixed_Compress_Factor_Vapor.text()
1378
                    values['Liquid_Flowrate_Mass'] = self.ui.lineEdit_Mixed_Flowrate_Mass_Liquid.text()
1379
                    values['Liquid_Density'] = self.ui.lineEdit_Mixed_Density_Liquid.text()
1380
                    values['Liquid_Viscosity'] = self.ui.lineEdit_Mixed_Viscosity_Liquid.text()
1381
                    l_flowrate = float(self.ui.lineEdit_Mixed_Flowrate_Mass_Liquid.text()) if is_not_blank(
1382
                        self.ui.lineEdit_Mixed_Flowrate_Mass_Liquid.text()) else 0
1383
                    v_flowrate = float(self.ui.lineEdit_Mixed_Flowrate_Mass_Vapor.text()) if is_not_blank(
1384
                        self.ui.lineEdit_Mixed_Flowrate_Mass_Vapor.text()) else 0
1385
                    values['Flowrate_Mass'] = l_flowrate + v_flowrate
1386
                    values['Viscosity'] = 'Mixed'
1387
                    values['Temperature'] = self.ui.lineEdit_Mixed_Temperature_Vapor.text()
1388
                    values['Molecular_Weight'] = self.ui.lineEdit_Mixed_Molecular_Weight_Vapor.text()
1389
                    values['Specific_Heat_Ratio'] = 'Mixed'
1390
                    values['Compress_Factor'] = self.ui.lineEdit_Mixed_Compress_Factor_Vapor.text()
1391
                    values['Limitation_Velocity'] = 'Mixed'
1392
                    values['Limitation_Pressure_Drop'] = 'Mixed'
1393
                    values['Reynolds'] = 'Mixed'
1394
                    values['Friction_Factor'] = 'Mixed'
1395
                    values['Pressure_Drop'] = 'Mixed'
1396
                    values['Straight_Length'] = 'Mixed'
1397
                    if self.ui.tableWidget_GeometryData_Mixed.rowCount() > 0:
1398
                        values['Nominal_Pipe_Size'] = self.ui.tableWidget_GeometryData_Mixed.item(0, 1).text()
1399
                        values['Schedule_No'] = self.ui.tableWidget_GeometryData_Mixed.item(0, 2).text()
1400
                        values['Inside_Pipe_Size'] = self.ui.tableWidget_GeometryData_Mixed.item(0, 3).text()
1401
                        values['Roughness'] = self.ui.tableWidget_GeometryData_Mixed.item(0, 4).text()
1402

    
1403
                        equivalent_length = self.get_mixed_equivalent_length()
1404
                        values['Equivalent_Length'] = equivalent_length
1405
                        values['Equivalent_Length_Cal'] = equivalent_length
1406

    
1407
                drawing.hmbTable.updateByUID(self.item.uid, values)
1408

    
1409
        except Exception as ex:
1410
            from App import App
1411
            from AppDocData import MessageType
1412

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

    
1417
    def get_mixed_equivalent_length(self):
1418
        equivalent_length = 0
1419

    
1420
        for row in range(self.ui.tableWidget_GeometryData_Mixed.rowCount()):
1421
            if is_not_blank(self.ui.tableWidget_GeometryData_Mixed.item(row, 5).text()):
1422
                length = float(self.ui.tableWidget_GeometryData_Mixed.item(row, 5).text())
1423
                if length:
1424
                    equivalent_length += length
1425

    
1426
        return equivalent_length
1427

    
1428
    def get_equivalent_length(self):
1429
        if self.ui.lineEdit_Equivalent_Length_Input.text():
1430
            self.ui.lineEdit_Fitting_Length.clear()
1431
            self.ui.lineEdit_Fitting_K.clear()
1432
            self.ui.lineEdit_Equivalent_Length_Cal.clear()
1433
            return self.ui.lineEdit_Equivalent_Length_Input.text()
1434
        else:
1435
            self.ui.lineEdit_Equivalent_Length_Input.clear()
1436
            return self.ui.lineEdit_Equivalent_Length_Cal.text()
1437

    
1438
    def set_geometry(self):
1439
        geometry = []
1440

    
1441
        if self.ui.tableWidget_GeometryData_Mixed.rowCount() > 0:
1442
            for row in range(self.ui.tableWidget_GeometryData_Mixed.rowCount()):
1443
                element = self.ui.tableWidget_GeometryData_Mixed.item(row, 0).text()
1444
                nominal_pipe_size = self.ui.tableWidget_GeometryData_Mixed.item(row, 1).text()
1445
                schedule_no = self.ui.tableWidget_GeometryData_Mixed.item(row, 2).text()
1446
                inside_pipe_size = self.ui.tableWidget_GeometryData_Mixed.item(row, 3).text()
1447
                roughness = self.ui.tableWidget_GeometryData_Mixed.item(row, 4).text()
1448
                length = self.ui.tableWidget_GeometryData_Mixed.item(row, 5).text()
1449
                angle = self.ui.tableWidget_GeometryData_Mixed.item(row, 6).text()
1450
                rpd = self.ui.tableWidget_GeometryData_Mixed.item(row, 7).text()
1451
                d1_d2 = self.ui.tableWidget_GeometryData_Mixed.item(row, 8).text()
1452
                k = self.ui.tableWidget_GeometryData_Mixed.item(row, 9).text()
1453

    
1454
                geometry.append(
1455
                    (
1456
                        element, nominal_pipe_size, schedule_no, inside_pipe_size, roughness, length, angle, rpd, d1_d2,
1457
                        k))
1458

    
1459
        self.item.mixed_geometry = geometry
1460

    
1461
    def accept(self):
1462
        self.update_HMB()
1463
        self.set_geometry()
1464
        self.result = True
1465

    
1466
        QDialog.accept(self)
1467

    
1468
    def reject(self):
1469
        self.result = False
1470

    
1471
        QDialog.reject(self)
1472

    
1473
    if __name__ == '__main__':
1474
        from StreamDataDialog import QStreamDataDialog
1475
        from App import App
1476

    
1477
        app = App(sys.argv)
1478

    
1479
        if True:
1480
            dlg = QStreamDataDialog()
1481
            dlg.exec_()
클립보드 이미지 추가 (최대 크기: 500 MB)