프로젝트

일반

사용자정보

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

hytos / HYTOS / HYTOS / StreamDataDialog.py @ 5a4be5ff

이력 | 보기 | 이력해설 | 다운로드 (83.9 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 is_float(s):
21
    try:
22
        if s:
23
            float(s)
24
            return True
25
        else:
26
            return False
27
    except ValueError:
28
        return False
29

    
30

    
31
def set_item_properties(name, alignment, color=None):
32
    item = QTableWidgetItem(str(name))
33
    item.setTextAlignment(alignment)
34
    if color:
35
        item.setBackground(color)
36

    
37
    return item
38

    
39

    
40
def is_blank(s):
41
    return not (s and s.strip())
42

    
43

    
44
def is_not_blank(s):
45
    return bool(s and s.strip())
46

    
47

    
48
def convert_to_fixed_point(value):
49
    if is_float(str(value)):
50
        tokens = f"{float(value):.10f}".split('.')
51
        if len(tokens) == 2:
52
            # 소수점 아래가 있을 경우 소수점 아래의 trailing zero를 제거한다.
53
            if is_blank(tokens[1].rstrip('0')):
54
                return tokens[0]
55
            else:
56
                tokens[1] = tokens[1].rstrip('0')
57
                return '.'.join(tokens)
58
        else:
59
            return tokens[0]
60
    else:
61
        return value
62

    
63

    
64
class QStreamDataDialog(QDialog):
65
    def __init__(self):
66
        QDialog.__init__(self)
67

    
68
        self.ui = StreamData_UI.Ui_Dialog()
69
        self.ui.setupUi(self)
70
        self.item = None
71
        self.result = False
72
        self.liquid_drop_method = None
73
        self.ui.label_current_tab_index.setVisible(False)
74

    
75
        self.ui.lineEdit_Flowrate_Mass_Liquid.setValidator(
76
            QtGui.QDoubleValidator(self.ui.lineEdit_Flowrate_Mass_Liquid))
77
        self.ui.lineEdit_Flowrate_Volume.setValidator(QtGui.QDoubleValidator(self.ui.lineEdit_Flowrate_Volume))
78
        self.ui.lineEdit_Density.setValidator(QtGui.QDoubleValidator(self.ui.lineEdit_Density))
79
        self.ui.lineEdit_Viscosity_Liquid.setValidator(QtGui.QDoubleValidator(self.ui.lineEdit_Viscosity_Liquid))
80
        self.ui.lineEdit_Limitation_Velocity.setValidator(QtGui.QDoubleValidator(self.ui.lineEdit_Limitation_Velocity))
81
        self.ui.lineEdit_Limitation_Pressure_Drop.setValidator(
82
            QtGui.QDoubleValidator(self.ui.lineEdit_Limitation_Pressure_Drop))
83
        self.ui.lineEdit_Inside_Pipe_Size.setValidator(QtGui.QDoubleValidator(self.ui.lineEdit_Inside_Pipe_Size))
84
        self.ui.lineEdit_Roughness.setValidator(QtGui.QDoubleValidator(self.ui.lineEdit_Roughness))
85
        self.ui.lineEdit_Straight_Length.setValidator(QtGui.QDoubleValidator(self.ui.lineEdit_Straight_Length))
86
        self.ui.lineEdit_Equivalent_Length_Input.setValidator(
87
            QtGui.QDoubleValidator(self.ui.lineEdit_Equivalent_Length_Input))
88
        self.ui.lineEdit_Equivalent_Length_Cal.setValidator(
89
            QtGui.QDoubleValidator(self.ui.lineEdit_Equivalent_Length_Cal))
90
        self.ui.lineEdit_Viscosity_Vapor.setValidator(QtGui.QDoubleValidator(self.ui.lineEdit_Viscosity_Vapor))
91
        self.ui.lineEdit_Specific_Heat_Ratio.setValidator(QtGui.QDoubleValidator(self.ui.lineEdit_Specific_Heat_Ratio))
92
        self.ui.lineEdit_Molecular_Weight.setValidator(QtGui.QDoubleValidator(self.ui.lineEdit_Molecular_Weight))
93
        self.ui.lineEdit_Temperature.setValidator(QtGui.QDoubleValidator(self.ui.lineEdit_Temperature))
94
        self.ui.lineEdit_Compress_Factor.setValidator(QtGui.QDoubleValidator(self.ui.lineEdit_Compress_Factor))
95

    
96
        self.ui.lineEdit_Mixed_Flowrate_Mass_Vapor.setValidator(
97
            QtGui.QDoubleValidator(self.ui.lineEdit_Mixed_Flowrate_Mass_Vapor))
98
        self.ui.lineEdit_Mixed_Density_Vapor.setValidator(QtGui.QDoubleValidator(self.ui.lineEdit_Mixed_Density_Vapor))
99
        self.ui.lineEdit_Mixed_Viscosity_Vapor.setValidator(
100
            QtGui.QDoubleValidator(self.ui.lineEdit_Mixed_Viscosity_Vapor))
101
        self.ui.lineEdit_Mixed_Pressure_Vapor.setValidator(
102
            QtGui.QDoubleValidator(self.ui.lineEdit_Mixed_Pressure_Vapor))
103
        self.ui.lineEdit_Mixed_Temperature_Vapor.setValidator(
104
            QtGui.QDoubleValidator(self.ui.lineEdit_Mixed_Temperature_Vapor))
105
        self.ui.lineEdit_Mixed_Molecular_Weight_Vapor.setValidator(
106
            QtGui.QDoubleValidator(self.ui.lineEdit_Mixed_Molecular_Weight_Vapor))
107
        self.ui.lineEdit_Mixed_Compress_Factor_Vapor.setValidator(
108
            QtGui.QDoubleValidator(self.ui.lineEdit_Mixed_Compress_Factor_Vapor))
109
        self.ui.lineEdit_Mixed_Flowrate_Mass_Liquid.setValidator(
110
            QtGui.QDoubleValidator(self.ui.lineEdit_Mixed_Flowrate_Mass_Liquid))
111
        self.ui.lineEdit_Mixed_Density_Liquid.setValidator(
112
            QtGui.QDoubleValidator(self.ui.lineEdit_Mixed_Density_Liquid))
113
        self.ui.lineEdit_Mixed_Viscosity_Liquid.setValidator(
114
            QtGui.QDoubleValidator(self.ui.lineEdit_Mixed_Viscosity_Liquid))
115
        self.ui.pushButton_Roughness.clicked.connect(self.roughness_clicked_event)
116
        self.ui.pushButton_Fitting.clicked.connect(self.show_fitting_dialog)
117
        self.ui.comboBox_Nominal_Pipe_Size.currentIndexChanged.connect(self.getInsideDiameter)
118
        self.ui.comboBox_Schedule_No.currentIndexChanged.connect(self.getInsideDiameter)
119
        self.ui.comboBox_PhaseType.currentIndexChanged.connect(self.on_change_phase_type)
120
        self.ui.pushButton_Line_Sizing.clicked.connect(self.show_line_sizing_dialog)
121
        self.ui.pushButton_Diameter_Estimation.clicked.connect(self.show_diameter_estimation_dialog)
122
        self.ui.pushButton_Add_GeometryData_Mixed.clicked.connect(self.show_geometry_data_dialog)
123
        self.ui.pushButton_Copy_Stream.clicked.connect(self.show_copy_stream_dialog)
124
        self.ui.pushButton_Calculation.clicked.connect(self.mixed_type_calculation)
125
        self.ui.pushButton_view.clicked.connect(self.show_result_dialog)
126
        self.ui.lineEdit_Equivalent_Length_Input.textChanged.connect(self.equivalent_length_change_event)
127
        self.ui.lineEdit_Flowrate_Mass_Liquid.textChanged.connect(self.flowrate_change_event)
128
        self.ui.lineEdit_Flowrate_Volume.textChanged.connect(self.flowrate_change_event)
129
        self.ui.lineEdit_Mixed_Density_Vapor.textChanged.connect(self.mixed_density_vapor_change_event)
130

    
131
        self.ui.tableWidget_GeometryData_Mixed.setContextMenuPolicy(Qt.CustomContextMenu)
132
        self.ui.tableWidget_GeometryData_Mixed.customContextMenuRequested.connect(self.context_menu_geometry_data)
133
        self.ui.tableWidget_GeometryData_Mixed.cellDoubleClicked.connect(self.cell_double_clicked)
134

    
135
        self.initialize()
136
        self.init_liquid_drop_method()
137
        self.init_phase_type()
138
        self.init_units()
139
        self.init_nominal_diameter()
140
        self.init_schedule()
141

    
142
    def delete_geometry_data_click_event(self):
143
        try:
144
            row = self.ui.tableWidget_GeometryData_Mixed.currentRow()
145
            self.ui.tableWidget_GeometryData_Mixed.removeRow(row)
146
        except Exception as ex:
147
            from App import App
148
            from AppDocData import MessageType
149

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

    
154
    def get_data(self, row):
155
        element = self.ui.tableWidget_GeometryData_Mixed.item(row, 0).text()
156
        nominal_pipe_size = self.ui.tableWidget_GeometryData_Mixed.item(row, 1).text()
157
        schedule_no = self.ui.tableWidget_GeometryData_Mixed.item(row, 2).text()
158
        inside_pipe_size = self.ui.tableWidget_GeometryData_Mixed.item(row, 3).text()
159
        roughness = self.ui.tableWidget_GeometryData_Mixed.item(row, 4).text()
160
        length = self.ui.tableWidget_GeometryData_Mixed.item(row, 5).text()
161
        angle = self.ui.tableWidget_GeometryData_Mixed.item(row, 6).text()
162
        rpd = self.ui.tableWidget_GeometryData_Mixed.item(row, 7).text()
163
        d1_d2 = self.ui.tableWidget_GeometryData_Mixed.item(row, 8).text()
164
        k = self.ui.tableWidget_GeometryData_Mixed.item(row, 9).text()
165

    
166
        return element, nominal_pipe_size, schedule_no, inside_pipe_size, roughness, length, angle, rpd, d1_d2, k
167

    
168
    def cell_double_clicked(self, row):
169
        from GeometryData_MixedDialog import QGeometryData_MixedDialog
170
        try:
171
            if row > -1:
172
                data = self.get_data(row)
173

    
174
                row_count = self.ui.tableWidget_GeometryData_Mixed.rowCount() - 1
175
                dialog = QGeometryData_MixedDialog(self)
176
                (
177
                    isAccepted, element, nominal_pipe_size, schedule_no, inside_pipe_size, roughness, length, angle,
178
                    rpd,
179
                    d1_d2,
180
                    k) = dialog.show_dialog(row_count, data)
181

    
182
                if isAccepted:
183
                    self.ui.tableWidget_GeometryData_Mixed.setItem(row, 0,
184
                                                                   set_item_properties(element,
185
                                                                                       Qt.AlignLeft | Qt.AlignVCenter))
186

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

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

    
195
                    self.ui.tableWidget_GeometryData_Mixed.setItem(row, 3,
196
                                                                   set_item_properties(inside_pipe_size,
197
                                                                                       Qt.AlignRight | Qt.AlignVCenter))
198

    
199
                    self.ui.tableWidget_GeometryData_Mixed.setItem(row, 4,
200
                                                                   set_item_properties(roughness,
201
                                                                                       Qt.AlignRight | Qt.AlignVCenter))
202

    
203
                    self.ui.tableWidget_GeometryData_Mixed.setItem(row, 5,
204
                                                                   set_item_properties(length,
205
                                                                                       Qt.AlignRight | Qt.AlignVCenter))
206

    
207
                    self.ui.tableWidget_GeometryData_Mixed.setItem(row, 6,
208
                                                                   set_item_properties(angle,
209
                                                                                       Qt.AlignRight | Qt.AlignVCenter))
210

    
211
                    self.ui.tableWidget_GeometryData_Mixed.setItem(row, 7,
212
                                                                   set_item_properties(rpd,
213
                                                                                       Qt.AlignRight | Qt.AlignVCenter))
214

    
215
                    self.ui.tableWidget_GeometryData_Mixed.setItem(row, 8,
216
                                                                   set_item_properties(d1_d2,
217
                                                                                       Qt.AlignRight | Qt.AlignVCenter))
218

    
219
                    self.ui.tableWidget_GeometryData_Mixed.setItem(row, 9,
220
                                                                   set_item_properties(k,
221
                                                                                       Qt.AlignRight | Qt.AlignVCenter))
222

    
223
                    self.ui.tableWidget_GeometryData_Mixed.resizeColumnsToContents()
224
                    self.ui.tableWidget_GeometryData_Mixed.resizeRowsToContents()
225

    
226
        except Exception as ex:
227
            from App import App
228
            from AppDocData import MessageType
229

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

    
234
    def edit_geometry_data_click_event(self):
235
        from GeometryData_MixedDialog import QGeometryData_MixedDialog
236
        try:
237
            row = self.ui.tableWidget_GeometryData_Mixed.currentRow()
238
            if row > -1:
239
                data = self.get_data(row)
240

    
241
                row_count = self.ui.tableWidget_GeometryData_Mixed.rowCount() - 1
242
                dialog = QGeometryData_MixedDialog(self)
243
                (
244
                    isAccepted, element, nominal_pipe_size, schedule_no, inside_pipe_size, roughness, length, angle,
245
                    rpd,
246
                    d1_d2,
247
                    k) = dialog.show_dialog(row_count, data)
248

    
249
                if isAccepted:
250
                    self.ui.tableWidget_GeometryData_Mixed.setItem(row, 0,
251
                                                                   set_item_properties(element,
252
                                                                                       Qt.AlignLeft | Qt.AlignVCenter))
253

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

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

    
262
                    self.ui.tableWidget_GeometryData_Mixed.setItem(row, 3,
263
                                                                   set_item_properties(inside_pipe_size,
264
                                                                                       Qt.AlignRight | Qt.AlignVCenter))
265

    
266
                    self.ui.tableWidget_GeometryData_Mixed.setItem(row, 4,
267
                                                                   set_item_properties(roughness,
268
                                                                                       Qt.AlignRight | Qt.AlignVCenter))
269

    
270
                    self.ui.tableWidget_GeometryData_Mixed.setItem(row, 5,
271
                                                                   set_item_properties(length,
272
                                                                                       Qt.AlignRight | Qt.AlignVCenter))
273

    
274
                    self.ui.tableWidget_GeometryData_Mixed.setItem(row, 6,
275
                                                                   set_item_properties(angle,
276
                                                                                       Qt.AlignRight | Qt.AlignVCenter))
277

    
278
                    self.ui.tableWidget_GeometryData_Mixed.setItem(row, 7,
279
                                                                   set_item_properties(rpd,
280
                                                                                       Qt.AlignRight | Qt.AlignVCenter))
281

    
282
                    self.ui.tableWidget_GeometryData_Mixed.setItem(row, 8,
283
                                                                   set_item_properties(d1_d2,
284
                                                                                       Qt.AlignRight | Qt.AlignVCenter))
285

    
286
                    self.ui.tableWidget_GeometryData_Mixed.setItem(row, 9,
287
                                                                   set_item_properties(k,
288
                                                                                       Qt.AlignRight | Qt.AlignVCenter))
289

    
290
                    self.ui.tableWidget_GeometryData_Mixed.resizeColumnsToContents()
291
                    self.ui.tableWidget_GeometryData_Mixed.resizeRowsToContents()
292

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

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

    
301
    def keyPressEvent(self, QKeyEvent):
302
        if QKeyEvent.key() == QtCore.Qt.Key_Delete:
303
            if self.ui.tableWidget_GeometryData_Mixed.hasFocus():
304
                row = self.ui.tableWidget_GeometryData_Mixed.currentRow()
305
                self.ui.tableWidget_GeometryData_Mixed.removeRow(row)
306

    
307
    def context_menu_geometry_data(self, position):
308
        try:
309
            menu = QMenu()
310

    
311
            edit_geometry_data = menu.addAction(self.tr('Edit'))
312
            edit_geometry_data.triggered.connect(lambda: self.edit_geometry_data_click_event())
313
            menu.addAction(edit_geometry_data)
314

    
315
            delete_geometry_data = menu.addAction(self.tr('Delete'))
316
            delete_geometry_data.triggered.connect(lambda: self.delete_geometry_data_click_event())
317
            menu.addAction(delete_geometry_data)
318

    
319
            if self.ui.tableWidget_GeometryData_Mixed.rowCount() > 0:
320
                menu.exec_(self.ui.tableWidget_GeometryData_Mixed.viewport().mapToGlobal(position))
321

    
322
        except Exception as ex:
323
            from App import App
324
            from AppDocData import MessageType
325

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

    
330
    def mixed_density_vapor_change_event(self, text):
331
        if is_not_blank(text):
332
            self.ui.lineEdit_Mixed_Temperature_Vapor.setText('-')
333
            self.ui.lineEdit_Mixed_Temperature_Vapor.setEnabled(False)
334
            self.ui.lineEdit_Mixed_Molecular_Weight_Vapor.setText('-')
335
            self.ui.lineEdit_Mixed_Molecular_Weight_Vapor.setEnabled(False)
336
            self.ui.lineEdit_Mixed_Compress_Factor_Vapor.setText('-')
337
            self.ui.lineEdit_Mixed_Compress_Factor_Vapor.setEnabled(False)
338
        else:
339
            self.ui.lineEdit_Mixed_Temperature_Vapor.clear()
340
            self.ui.lineEdit_Mixed_Temperature_Vapor.setEnabled(True)
341
            self.ui.lineEdit_Mixed_Molecular_Weight_Vapor.clear()
342
            self.ui.lineEdit_Mixed_Molecular_Weight_Vapor.setEnabled(True)
343
            self.ui.lineEdit_Mixed_Compress_Factor_Vapor.clear()
344
            self.ui.lineEdit_Mixed_Compress_Factor_Vapor.setEnabled(True)
345

    
346
    def equivalent_length_change_event(self, text):
347
        if is_not_blank(text):
348
            # Equivalent Length Cal Clear
349
            self.ui.lineEdit_Fitting_Length.clear()
350
            self.ui.lineEdit_Fitting_Length.setStyleSheet('QLineEdit {background-color: rgb(237,237,237);}')
351
            self.ui.lineEdit_Fitting_K.clear()
352
            self.ui.lineEdit_Fitting_K.setStyleSheet('QLineEdit {background-color: rgb(237,237,237);}')
353
            self.ui.lineEdit_Equivalent_Length_Cal.clear()
354
            self.ui.lineEdit_Equivalent_Length_Cal.setStyleSheet('QLineEdit {background-color: rgb(237,237,237);}')
355
        else:
356
            self.ui.lineEdit_Equivalent_Length_Input.setStyleSheet('QLineEdit {background-color: white;}')
357

    
358
    def flowrate_change_event(self, text):
359
        if self.sender() == self.ui.lineEdit_Flowrate_Mass_Liquid:
360
            if is_not_blank(text):
361
                self.ui.lineEdit_Flowrate_Volume.clear()
362
                self.ui.lineEdit_Flowrate_Volume.setStyleSheet('QLineEdit {background-color: rgb(237,237,237);}')
363
                self.ui.lineEdit_Flowrate_Mass_Liquid.setStyleSheet('QLineEdit {background-color: white;}')
364
        else:
365
            if is_not_blank(text):
366
                self.ui.lineEdit_Flowrate_Mass_Liquid.clear()
367
                self.ui.lineEdit_Flowrate_Mass_Liquid.setStyleSheet('QLineEdit {background-color: rgb(237,237,237);}')
368
                self.ui.lineEdit_Flowrate_Volume.setStyleSheet('QLineEdit {background-color: white;}')
369

    
370
    def initialize(self):
371

    
372
        self.ui.tableWidget_GeometryData_Mixed.setColumnCount(10)
373
        self.ui.tableWidget_GeometryData_Mixed.horizontalHeader().setStretchLastSection(True)
374
        col_names = ['Element', 'ND', 'Sch.', 'ID', 'Roughness', 'Length', 'Angle', 'r/D', 'D1/D2', 'K']
375
        self.ui.tableWidget_GeometryData_Mixed.setHorizontalHeaderLabels(col_names)
376

    
377
        self.ui.tableWidget_GeometryData_Mixed.setEditTriggers(QAbstractItemView.NoEditTriggers)
378
        self.ui.tableWidget_GeometryData_Mixed.verticalHeader().setVisible(False)
379
        self.ui.tableWidget_GeometryData_Mixed.resizeColumnsToContents()
380
        self.ui.tableWidget_GeometryData_Mixed.resizeRowsToContents()
381

    
382
    def init_liquid_drop_method(self):
383
        app_doc_data = AppDocData.instance()
384

    
385
        liquid_dp_method = app_doc_data.getConfigs('Calculation', 'Liquid_Drop_Method')
386
        if len(liquid_dp_method) == 1:
387
            self.liquid_drop_method = liquid_dp_method[0].value
388
        else:
389
            self.liquid_drop_method = 'darcy'
390

    
391
    def roughness_clicked_event(self):
392
        from RoughnessDialog import QRoughnessDialog
393
        from Roughness_HagenDialog import QRoughness_HagenDialog
394

    
395
        phase_type = self.ui.comboBox_PhaseType.currentData()
396

    
397
        if phase_type == 'Liquid' and self.liquid_drop_method == 'hagen':
398
            dialog = QRoughness_HagenDialog()
399
        else:
400
            dialog = QRoughnessDialog()
401

    
402
        isAccepted, roughness = dialog.show_dialog()
403
        if isAccepted == True:
404
            self.ui.lineEdit_Roughness.setText(str(roughness))
405

    
406
    def validation_check_vapor(self):
407
        message = None
408

    
409
        # Nominal Diameter
410
        nominal_diameter_uid = self.ui.comboBox_Nominal_Pipe_Size.currentData()
411
        flowrate_mass = self.ui.lineEdit_Flowrate_Mass_Vapor.text()
412
        viscosity = self.ui.lineEdit_Viscosity_Vapor.text()
413
        molecular_weight = self.ui.lineEdit_Molecular_Weight.text()
414
        temperature = self.ui.lineEdit_Temperature.text()
415
        compress_factor = self.ui.lineEdit_Compress_Factor.text()
416
        inside_diameter = self.ui.lineEdit_Inside_Pipe_Size.text()
417

    
418
        if nominal_diameter_uid is None:
419
            message = 'Select Nominal Diameter'
420
        elif flowrate_mass is None or flowrate_mass == '':
421
            message = 'Input Flowrate'
422
        elif viscosity is None or viscosity == '':
423
            message = 'Input Viscosity'
424
        elif molecular_weight is None or molecular_weight == '':
425
            message = 'Input Molecular Weight'
426
        elif temperature is None or temperature == '':
427
            message = 'Input Temperature'
428
        elif compress_factor is None or compress_factor == '':
429
            message = 'Input Z factor'
430
        elif inside_diameter is None or inside_diameter == '':
431
            message = 'Select Schedule No.'
432

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

    
444
    def validation_check_liquid(self):
445
        message = None
446

    
447
        nominal_diameter_uid = self.ui.comboBox_Nominal_Pipe_Size.currentData()
448
        flowrate_mass = self.ui.lineEdit_Flowrate_Mass_Liquid.text()
449
        flowrate_volume = self.ui.lineEdit_Flowrate_Volume.text()
450
        density = self.ui.lineEdit_Density.text()
451
        viscosity = self.ui.lineEdit_Viscosity_Liquid.text()
452
        inside_diameter = self.ui.lineEdit_Inside_Pipe_Size.text()
453

    
454
        if nominal_diameter_uid is None:
455
            message = 'Select Nominal Diameter'
456
        elif (flowrate_mass is None or flowrate_mass == '') and (flowrate_volume is None or flowrate_volume == ''):
457
            message = 'Input Flowrate'
458
        elif density is None or density == '':
459
            message = 'Input Density'
460
        elif viscosity is None or viscosity == '':
461
            message = 'Input Viscosity'
462
        elif inside_diameter is None or inside_diameter == '':
463
            message = 'Select Schedule No.'
464

    
465
        if message:
466
            msg = QMessageBox(self)
467
            msg.setIcon(QMessageBox.Information)
468
            msg.setText(self.tr(message))
469
            msg.setWindowTitle(self.tr("Information"))
470
            msg.setStandardButtons(QMessageBox.Ok)
471
            msg.exec_()
472
            return False
473
        else:
474
            return True
475

    
476
    def load_mixed_result(self, result):
477

    
478
        table = self.ui.tableWidget_Mixed_DB
479
        for row in result:
480
            row_count = table.rowCount()
481

    
482
            table.setRowCount(row_count + 1)
483

    
484
            table.setItem(row_count, 0,
485
                          set_item_properties(row[0], Qt.AlignHCenter | Qt.AlignVCenter))  # No
486
            table.setItem(row_count, 1,
487
                          set_item_properties(row[1], Qt.AlignLeft | Qt.AlignVCenter))  # Element
488
            table.setItem(row_count, 2,
489
                          set_item_properties(row[2], Qt.AlignRight | Qt.AlignVCenter))  # Inside Diameter
490
            table.setItem(row_count, 3,
491
                          set_item_properties(row[3], Qt.AlignRight | Qt.AlignVCenter))  # Length
492
            table.setItem(row_count, 4,
493
                          set_item_properties(row[4], Qt.AlignRight | Qt.AlignVCenter))  # Angle
494
            table.setItem(row_count, 5, set_item_properties(row[5], Qt.AlignRight | Qt.AlignVCenter))  # K
495
            table.setItem(row_count, 6,
496
                          set_item_properties(row[6], Qt.AlignRight | Qt.AlignVCenter))  # Pressure
497
            table.setItem(row_count, 7,
498
                          set_item_properties(row[7], Qt.AlignRight | Qt.AlignVCenter))  # Void
499
            table.setItem(row_count, 8,
500
                          set_item_properties(row[8], Qt.AlignRight | Qt.AlignVCenter))  # Quality
501
            table.setItem(row_count, 9,
502
                          set_item_properties(row[9], Qt.AlignRight | Qt.AlignVCenter))  # Density
503
            table.setItem(row_count, 10,
504
                          set_item_properties(row[10], Qt.AlignRight | Qt.AlignVCenter))  # V.Den
505
            table.setItem(row_count, 11,
506
                          set_item_properties(row[11], Qt.AlignRight | Qt.AlignVCenter))  # Mean Vel
507
            table.setItem(row_count, 12,
508
                          set_item_properties(row[12], Qt.AlignRight | Qt.AlignVCenter))  # Max Vel
509
            table.setItem(row_count, 13,
510
                          set_item_properties(row[13], Qt.AlignRight | Qt.AlignVCenter))  # Ero Vel
511
            table.setItem(row_count, 14,
512
                          set_item_properties(row[14], Qt.AlignRight | Qt.AlignVCenter))  # X
513
            table.setItem(row_count, 15,
514
                          set_item_properties(row[15], Qt.AlignRight | Qt.AlignVCenter))  # Y
515
            table.setItem(row_count, 16,
516
                          set_item_properties(row[16], Qt.AlignLeft | Qt.AlignVCenter))  # Regime
517
            table.setItem(row_count, 17,
518
                          set_item_properties(row[17], Qt.AlignRight | Qt.AlignVCenter))  # Friction
519
            table.setItem(row_count, 18,
520
                          set_item_properties(row[18], Qt.AlignRight | Qt.AlignVCenter))  # Gravity
521
            table.setItem(row_count, 19,
522
                          set_item_properties(row[19], Qt.AlignRight | Qt.AlignVCenter))  # Momentum
523
            table.setItem(row_count, 20,
524
                          set_item_properties(row[20], Qt.AlignRight | Qt.AlignVCenter))  # Total
525

    
526
        table.resizeColumnsToContents()
527
        table.resizeRowsToContents()
528

    
529
    def show_result_dialog(self):
530
        from PressureVariation import QPressureVariation
531

    
532
        if self.item.pressure_variation:
533
            dlg = QPressureVariation()
534
            dlg.show_dialog(self.item)
535
        else:
536
            QMessageBox.information(self, self.tr("Information"), self.tr("Calculate this line !"))
537

    
538
    def show_copy_stream_dialog(self):
539
        from CopyStreamData import QCopyStreamData
540

    
541
        dlg = QCopyStreamData()
542
        (isAccepted, components_uid) = dlg.show_dialog(self.item)
543
        if isAccepted == True:
544
            self.load_hmb(components_uid)
545

    
546
    def mixed_type_calculation(self):
547
        from Calculation import Calculation_Mixed
548
        try:
549
            self.update_mixed_hmb()
550
            self.update_mixed_geometry()
551

    
552
            process = {}
553

    
554
            process['l_flowrate'] = self.ui.lineEdit_Mixed_Flowrate_Mass_Liquid.text()
555
            process['v_flowrate'] = self.ui.lineEdit_Mixed_Flowrate_Mass_Vapor.text()
556
            process['l_density'] = self.ui.lineEdit_Mixed_Density_Liquid.text()
557
            process['v_density'] = self.ui.lineEdit_Mixed_Density_Vapor.text()
558
            process['l_viscosity'] = self.ui.lineEdit_Mixed_Viscosity_Liquid.text()
559
            process['v_viscosity'] = self.ui.lineEdit_Mixed_Viscosity_Vapor.text()
560
            process['tp_pressure'] = self.ui.lineEdit_Mixed_Pressure_Vapor.text()
561
            process['v_temp'] = self.ui.lineEdit_Mixed_Temperature_Vapor.text()
562
            process['v_mw'] = self.ui.lineEdit_Mixed_Molecular_Weight_Vapor.text()
563
            process['v_z'] = self.ui.lineEdit_Mixed_Compress_Factor_Vapor.text()
564

    
565
            if self.ui.tableWidget_GeometryData_Mixed.rowCount() == 0:
566
                QMessageBox.information(self, self.tr("Information"), self.tr("Please input [Geometry Data] !"))
567
            elif is_not_blank(process['l_flowrate']) or is_not_blank(process['v_flowrate']) or is_not_blank(
568
                    process['l_density']) or is_not_blank(process['l_viscosity']) or is_not_blank(
569
                process['v_viscosity']):
570
                if is_not_blank(process['v_density']):
571
                    if is_not_blank(process['tp_pressure']):
572
                        res = Calculation_Mixed(self.item, process, self.ui.tableWidget_GeometryData_Mixed)
573
                        self.item.pressure_variation = res.pressure_variation
574
                        QMessageBox.information(self, self.tr("Information"),
575
                                                self.tr("Calculation completed successfully."))
576
                    else:
577
                        QMessageBox.information(self, self.tr("Information"),
578
                                                self.tr("Please input the [Start pressure] !"))
579
                        return
580
                else:
581
                    if is_not_blank(process['tp_pressure']) and is_not_blank(process['v_temp']) and is_not_blank(
582
                            process['v_mw']) and is_not_blank(process['v_z']):
583
                        res = Calculation_Mixed(self.item, process, self.ui.tableWidget_GeometryData_Mixed)
584
                        self.item.pressure_variation = res.pressure_variation
585
                        QMessageBox.information(self, self.tr("Information"),
586
                                                self.tr("Calculation completed successfully."))
587
                    else:
588
                        QMessageBox.information(self, self.tr("Information"),
589
                                                self.tr("Please input [Vapor property] !"))
590
                        return
591
            else:
592
                QMessageBox.information(self, self.tr("Information"), self.tr("Please input all property !"))
593
        except Exception as ex:
594
            from App import App
595
            from AppDocData import MessageType
596

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

    
601
    def show_geometry_data_dialog(self):
602
        """pop up geometry data dialog"""
603
        from GeometryData_MixedDialog import QGeometryData_MixedDialog
604

    
605
        try:
606
            row_count = self.ui.tableWidget_GeometryData_Mixed.rowCount()
607

    
608
            data = self.get_data(row_count - 1) if row_count > 0 else None
609

    
610
            dialog = QGeometryData_MixedDialog(self)
611
            (
612
                isAccepted, element, nominal_pipe_size, schedule_no, inside_pipe_size, roughness, length, angle, rpd,
613
                d1_d2,
614
                k) = dialog.show_dialog(row_count, data)
615

    
616
            if isAccepted:
617
                self.ui.tableWidget_GeometryData_Mixed.setRowCount(row_count + 1)
618

    
619
                self.ui.tableWidget_GeometryData_Mixed.setItem(row_count, 0, set_item_properties(element,
620
                                                                                                 Qt.AlignLeft | Qt.AlignVCenter))
621

    
622
                self.ui.tableWidget_GeometryData_Mixed.setItem(row_count, 1,
623
                                                               set_item_properties(nominal_pipe_size,
624
                                                                                   Qt.AlignRight | Qt.AlignVCenter))
625

    
626
                self.ui.tableWidget_GeometryData_Mixed.setItem(row_count, 2,
627
                                                               set_item_properties(schedule_no,
628
                                                                                   Qt.AlignRight | Qt.AlignVCenter))
629

    
630
                self.ui.tableWidget_GeometryData_Mixed.setItem(row_count, 3,
631
                                                               set_item_properties(inside_pipe_size,
632
                                                                                   Qt.AlignRight | Qt.AlignVCenter))
633

    
634
                self.ui.tableWidget_GeometryData_Mixed.setItem(row_count, 4,
635
                                                               set_item_properties(roughness,
636
                                                                                   Qt.AlignRight | Qt.AlignVCenter))
637

    
638
                self.ui.tableWidget_GeometryData_Mixed.setItem(row_count, 5,
639
                                                               set_item_properties(length,
640
                                                                                   Qt.AlignRight | Qt.AlignVCenter))
641

    
642
                self.ui.tableWidget_GeometryData_Mixed.setItem(row_count, 6,
643
                                                               set_item_properties(angle,
644
                                                                                   Qt.AlignRight | Qt.AlignVCenter))
645

    
646
                self.ui.tableWidget_GeometryData_Mixed.setItem(row_count, 7,
647
                                                               set_item_properties(rpd,
648
                                                                                   Qt.AlignRight | Qt.AlignVCenter))
649

    
650
                self.ui.tableWidget_GeometryData_Mixed.setItem(row_count, 8,
651
                                                               set_item_properties(d1_d2,
652
                                                                                   Qt.AlignRight | Qt.AlignVCenter))
653

    
654
                self.ui.tableWidget_GeometryData_Mixed.setItem(row_count, 9,
655
                                                               set_item_properties(k,
656
                                                                                   Qt.AlignRight | Qt.AlignVCenter))
657

    
658
                self.ui.tableWidget_GeometryData_Mixed.resizeColumnsToContents()
659
                self.ui.tableWidget_GeometryData_Mixed.resizeRowsToContents()
660

    
661
        except Exception as ex:
662
            from App import App
663
            from AppDocData import MessageType
664

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

    
669
    def show_diameter_estimation_dialog(self):
670
        from DiameterEstimation_Liquid import QDiameterEstimation_Liquid
671
        from DiameterEstimation_Vapor import QDiameterEstimation_Vapor
672

    
673
        try:
674
            phase_type = self.ui.comboBox_PhaseType.currentData()
675

    
676
            velocity = self.ui.lineEdit_Limitation_Velocity.text()
677
            pressure_drop = self.ui.lineEdit_Limitation_Pressure_Drop.text()
678
            roughness = self.ui.lineEdit_Roughness.text()
679

    
680
            process_data = {}
681
            if phase_type == 'Liquid':
682
                # Validation Check
683
                density = self.ui.lineEdit_Density.text()
684
                viscosity = self.ui.lineEdit_Viscosity_Liquid.text()
685
                flowrate_mass = self.ui.lineEdit_Flowrate_Mass_Liquid.text()
686
                flowrate_volume = self.ui.lineEdit_Flowrate_Volume.text()
687

    
688
                if is_blank(velocity) and is_blank(pressure_drop):
689
                    QMessageBox.information(self, self.tr('Information'), self.tr('Please input the stream criteria !'))
690
                    return
691
                elif is_blank(density) or is_blank(viscosity):
692
                    QMessageBox.information(self, self.tr('Information'), self.tr('Please input the stream property !'))
693
                    return
694
                elif is_blank(flowrate_mass) and is_blank(flowrate_volume):
695
                    QMessageBox.information(self, self.tr('Information'), self.tr('Please input the flowrate !'))
696
                    return
697
                elif is_blank(roughness):
698
                    QMessageBox.information(self, self.tr('Information'), self.tr('Please input the pipe roughness !'))
699
                    return
700

    
701
                process_data['Flowrate_Mass'] = self.ui.lineEdit_Flowrate_Mass_Liquid.text()
702
                process_data['Flowrate_Volume'] = self.ui.lineEdit_Flowrate_Volume.text()
703
                process_data['Density'] = self.ui.lineEdit_Density.text()
704
                process_data['Viscosity'] = self.ui.lineEdit_Viscosity_Liquid.text()
705
                process_data['Roughness'] = self.ui.lineEdit_Roughness.text()
706

    
707
                dialog = QDiameterEstimation_Liquid()
708
            elif phase_type == 'Vapor':
709
                # Validation Check
710
                heat_ratio = self.ui.lineEdit_Specific_Heat_Ratio.text()
711
                viscosity = self.ui.lineEdit_Viscosity_Vapor.text()
712
                compress_factor = self.ui.lineEdit_Compress_Factor.text()
713
                temperature = self.ui.lineEdit_Temperature.text()
714
                flowrate_mass = self.ui.lineEdit_Flowrate_Mass_Vapor.text()
715

    
716
                if is_blank(velocity) and is_blank(pressure_drop):
717
                    QMessageBox.information(self, self.tr('Information'), self.tr('Please input the stream criteria !'))
718
                    return
719
                elif is_blank(heat_ratio) or is_blank(viscosity) or is_blank(compress_factor) or is_blank(temperature):
720
                    QMessageBox.information(self, self.tr('Information'), self.tr('Please input the stream property !'))
721
                    return
722
                elif is_blank(flowrate_mass):
723
                    QMessageBox.information(self, self.tr('Information'), self.tr('Please input the flowrate !'))
724
                    return
725
                elif is_blank(roughness):
726
                    QMessageBox.information(self, self.tr('Information'), self.tr('Please input the pipe roughness !'))
727
                    return
728

    
729
                process_data['Flowrate_Mass'] = self.ui.lineEdit_Flowrate_Mass_Vapor.text()
730
                process_data['Molecular_Weight'] = self.ui.lineEdit_Molecular_Weight.text()
731
                process_data['Temperature'] = self.ui.lineEdit_Temperature.text()
732
                process_data['Compress_Factor'] = self.ui.lineEdit_Compress_Factor.text()
733
                process_data['Viscosity'] = self.ui.lineEdit_Viscosity_Liquid.text()
734
                process_data['Roughness'] = self.ui.lineEdit_Roughness.text()
735

    
736
                dialog = QDiameterEstimation_Vapor()
737

    
738
            isAccepted, nominal_pipe_size = dialog.show_dialog(velocity, pressure_drop, process_data)
739
            if isAccepted:
740
                self.ui.comboBox_Nominal_Pipe_Size.setCurrentText(nominal_pipe_size)
741
                self.ui.comboBox_Schedule_No.setCurrentText('Std')
742

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

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

    
751
    def show_line_sizing_dialog(self):
752
        from LineSizingCriteria import QLineSizingCriteria
753
        try:
754
            phase_type = self.ui.comboBox_PhaseType.currentData()
755

    
756
            dialog = QLineSizingCriteria()
757
            (isAccepted, velocity, pressure_drop) = dialog.show_dialog(phase_type)
758

    
759
            if isAccepted:
760
                self.ui.lineEdit_Limitation_Velocity.setText(velocity)
761
                self.ui.lineEdit_Limitation_Pressure_Drop.setText(pressure_drop)
762
        except Exception as ex:
763
            from App import App
764
            from AppDocData import MessageType
765

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

    
770
        '''
771
        from Line_Sizing_LiquidDialog import QLine_Sizing_LiquidDialog
772
        from Line_Sizing_VaporDialog import QLine_Sizing_VaporDialog
773
        try:
774
            phase_type = self.ui.comboBox_PhaseType.currentData()
775
            if phase_type == 'Vapor':
776
                dialog = QLine_Sizing_VaporDialog()
777
                (isAccepted, velocity, pressure_drop) = dialog.show_dialog()
778
            elif phase_type == 'Liquid':
779
                dialog = QLine_Sizing_LiquidDialog()
780
                (isAccepted, velocity, pressure_drop) = dialog.show_dialog()
781

782
            if isAccepted:
783
                self.ui.lineEdit_Limitation_Velocity.setText(velocity)
784
                self.ui.lineEdit_Limitation_Pressure_Drop.setText(pressure_drop)
785

786
        except Exception as ex:
787
            from App import App
788
            from AppDocData import MessageType
789

790
            message = 'error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename,
791
                                                           sys.exc_info()[-1].tb_lineno)
792
            App.mainWnd().addMessage.emit(MessageType.Error, message)
793
        '''
794

    
795
    def show_fitting_dialog(self):
796
        from FittingsDialog import QFittingsDialog
797

    
798
        try:
799
            phase_type = self.ui.comboBox_PhaseType.currentData()
800
            if phase_type == 'Vapor':
801
                if not self.validation_check_vapor():
802
                    return
803
            elif phase_type == 'Liquid':
804
                if not self.validation_check_liquid():
805
                    return
806
            current_tab_index = self.ui.label_current_tab_index.text() if self.ui.label_current_tab_index else None
807
            nominal_diameter_uid = self.ui.comboBox_Nominal_Pipe_Size.currentData()
808
            dialog = QFittingsDialog(self.item)
809
            (isAccepted, fittings_length, total_k, current_tab_index) = dialog.show_dialog(nominal_diameter_uid,
810
                                                                                           current_tab_index)
811
            if isAccepted:
812
                self.ui.label_current_tab_index.setText(str(current_tab_index))
813
                self.ui.lineEdit_Equivalent_Length_Input.clear()
814
                self.ui.lineEdit_Equivalent_Length_Input.setStyleSheet(
815
                    'QLineEdit {background-color: rgb(237,237,237);}')
816
                self.ui.lineEdit_Fitting_Length.clear()
817
                self.ui.lineEdit_Fitting_Length.setStyleSheet('QLineEdit {background-color: white;}')
818
                self.ui.lineEdit_Fitting_K.clear()
819
                self.ui.lineEdit_Fitting_K.setStyleSheet('QLineEdit {background-color: white;}')
820
                self.ui.lineEdit_Equivalent_Length_Cal.clear()
821
                self.ui.lineEdit_Equivalent_Length_Cal.setStyleSheet('QLineEdit {background-color: white;}')
822

    
823
                if fittings_length > 0:
824
                    # Equivalent Length Method
825
                    self.ui.lineEdit_Fitting_Length.setText(str(fittings_length))
826
                    self.ui.lineEdit_Fitting_K.setText(str(total_k))
827

    
828
                    straight_length = 0
829
                    if self.ui.lineEdit_Straight_Length.text():
830
                        straight_length = float(self.ui.lineEdit_Straight_Length.text())
831

    
832
                    equivalent_length_cal = fittings_length + straight_length
833
                    self.ui.lineEdit_Equivalent_Length_Cal.setText(str(equivalent_length_cal))
834
                elif total_k > 0:
835
                    # CraneK Method or 2-K Method
836
                    if phase_type == 'Vapor':
837
                        fittings_length = self.get_equivalent_length_vapor(total_k)
838
                    elif phase_type == 'Liquid':
839
                        fittings_length = self.get_equivalent_length_liquid(total_k)
840

    
841
                    self.ui.lineEdit_Fitting_Length.setText(str(fittings_length))
842
                    self.ui.lineEdit_Fitting_K.setText(str(total_k))
843

    
844
                    straight_length = 0
845
                    if self.ui.lineEdit_Straight_Length.text():
846
                        straight_length = float(self.ui.lineEdit_Straight_Length.text())
847

    
848
                    equivalent_length_cal = fittings_length + straight_length
849
                    self.ui.lineEdit_Equivalent_Length_Cal.setText(str(equivalent_length_cal))
850
        except Exception as ex:
851
            from App import App
852
            from AppDocData import MessageType
853

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

    
858
    # 마찰계수 산출
859
    def get_friction_coefficient_vapor(self):
860
        # '**********************************************************************************
861
        # '참고사항 :
862
        # '유닛의 기준 : 유량 (kg/h, m3/h), 밀도 (kg/m3), 지름 (m), 점도 (kg/m/s), 속도 (m/s), 압력 (kg/cm2(a))
863
        # ' mw (g/mol), temperature (kalvin)
864

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

    
870
        # '       현재 이것은 없어져 있는 상태임. from 김상도
871
        # '**********************************************************************************
872

    
873
        temperature = self.ui.lineEdit_Temperature.text()
874
        compress_factor = self.ui.lineEdit_Compress_Factor.text()
875
        flowrate_mass = self.ui.lineEdit_Flowrate_Mass_Vapor.text()
876
        viscosity = self.ui.lineEdit_Viscosity_Vapor.text()
877
        roughness = self.ui.lineEdit_Roughness.text()
878
        inside_pipe_size = self.ui.lineEdit_Inside_Pipe_Size.text()
879

    
880
        # 'molecular weight
881
        mw = float(self.ui.lineEdit_Molecular_Weight.text())
882

    
883
        # 'temperature
884
        temperature_unit = self.ui.label_Temperature_Unit.text()
885
        if temperature_unit == '':
886
            temp = float(temperature) + 273.15
887
        elif temperature_unit == '':
888
            temp = (float(temperature) - 32) / 1.8 + 273.15
889

    
890
        # 'compressibility
891
        z = float(compress_factor)
892

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

    
896
        density_unit = self.ui.label_Density_Unit.text()
897
        if density_unit == 'kg/m3':
898
            density = density
899
        elif density_unit == 'lb/ft3':
900
            density = density * 0.062428
901

    
902
        # '************************* 2. volume flowrate *************************
903
        # 'mass gain
904
        flowrate_mass_unit = self.ui.label_Flowrate_Mass_Unit_Vapor.text()
905
        if flowrate_mass_unit == 'kg/h':
906
            mass = float(flowrate_mass)
907
        elif flowrate_mass_unit == 'g/min':
908
            mass = float(flowrate_mass) * 60 / 1000
909
        elif flowrate_mass_unit == 'lb/h':
910
            mass = float(flowrate_mass) * 0.453592
911
        elif flowrate_mass_unit == 't/h':
912
            mass = float(flowrate_mass) * 1000
913

    
914
        # 'volume calculation (m3/h)
915
        volume = mass / density
916

    
917
        # ' ********** 2. viscosity 구하기 ***********
918
        viscosity_unit = self.ui.label_Viscosity_Unit_Vapor.text()
919
        if viscosity_unit == 'kg/m.sec':
920
            viscosity = float(viscosity)
921
        elif viscosity_unit == 'cP':
922
            viscosity = float(viscosity) * 0.001
923
        elif viscosity_unit == 'kg/m.h':
924
            viscosity = float(viscosity) / 3600
925
        elif viscosity_unit == 'lb/ft.s':
926
            viscosity = float(viscosity) * 1.48816
927

    
928
        # ' ********** 3. ND, 속도, 구함 **********
929

    
930
        # '조도 구함 (m)
931
        roughness_unit = self.ui.label_Roughness_Unit.text()
932
        if roughness_unit == 'm':
933
            rough = float(roughness)
934
        elif roughness_unit == 'ft':
935
            rough = float(roughness) * 0.3048
936
        elif roughness_unit == 'in':
937
            rough = float(roughness) * 0.0254
938
        elif roughness_unit == 'mm':
939
            rough = float(roughness) * 0.001
940

    
941
        # 'ND 구함 (in)
942
        nominal_pipe_size_unit = self.ui.label_Nominal_Pipe_Size_Unit.text()
943
        if nominal_pipe_size_unit == 'in':
944
            nd = float(inside_pipe_size)
945
        elif nominal_pipe_size_unit == 'mm':
946
            nd = float(inside_pipe_size) / 25
947

    
948
        # ' 속도 구함
949
        velocity = 4 * volume / 3.1415 / ((nd * 0.0254) ** 2) / 3600
950

    
951
        # ' 레이놀즈 넘버 구함
952
        reynolds = (nd * 0.0254) * velocity * density / viscosity
953

    
954
        # '마찰계수 산출
955
        if reynolds < 2100:
956
            f = 4 * 16 / reynolds
957
        else:
958
            a = math.log(rough / (nd * 0.0254) / 3.7 + (6.7 / reynolds) ** 0.9) / math.log(10)
959
            f = (-2 * (math.log(rough / 3.7 / (nd * 0.0254) - 5.02 / reynolds * a) / math.log(10))) ** (-2)
960

    
961
        return f
962

    
963
    # 마찰계수 산출
964
    def get_friction_coefficient_liquid(self):
965
        # '**********************************************************************************
966
        # '참고사항 :
967
        # '유닛의 기준 : 유량 (kg/h, m3/h), 밀도 (kg/m3), 지름 (m), 점도 (kg/m/s), 속도 (m/s), 압력강하 (kg/cm2/100m)
968
        # '**********************************************************************************
969

    
970
        flowrate_mass = self.ui.lineEdit_Flowrate_Mass_Liquid.text()
971
        flowrate_volume = self.ui.lineEdit_Flowrate_Volume.text()
972
        viscosity = self.ui.lineEdit_Viscosity_Liquid.text()
973
        roughness = self.ui.lineEdit_Roughness.text()
974
        inside_pipe_size = self.ui.lineEdit_Inside_Pipe_Size.text()
975

    
976
        # ' ********** 1. volume flowrate 구하기 ***********
977
        # '(1) 질량이 적혀있는 경우
978
        if flowrate_mass:
979
            density = float(self.ui.lineEdit_Density.text())
980

    
981
            # '질량 유량을 kg/h로 변환
982
            flowrate_mass_unit = self.ui.label_Flowrate_Mass_Unit_Liquid.text()
983
            if flowrate_mass_unit == 'kg/h':
984
                mass = float(flowrate_mass)
985
            elif flowrate_mass_unit == 'g/min':
986
                mass = float(flowrate_mass) * 60 / 1000
987
            elif flowrate_mass_unit == 'lb/h':
988
                mass = float(flowrate_mass) * 0.453592
989
            elif flowrate_mass_unit == 't/h':
990
                mass = float(flowrate_mass) * 1000
991

    
992
            # '밀도에 맞춰서 부피 유량 산출 (m3/h)
993
            density_unit = self.ui.label_Density_Unit.text()
994
            if density_unit == 'kg/m3':
995
                volume = mass / density
996
            elif density_unit == 'lb/ft3':
997
                volume = mass / (density * 16.0185)
998
        # (2)부피가 적혀있는경우
999
        elif flowrate_volume:
1000
            density = float(self.ui.lineEdit_Density.text())
1001

    
1002
            # '부피유량을 m3/h로 변환.
1003
            flowrate_volume_unit = self.ui.label_Flowrate_Volume_Unit.text()
1004
            if flowrate_volume_unit == 'm3/h':
1005
                volume = float(flowrate_volume)
1006
            elif flowrate_volume_unit == 'l/min':
1007
                volume = float(flowrate_volume) * 60 / 1000
1008
            elif flowrate_volume_unit == 'ft3/h':
1009
                volume = float(flowrate_volume) / 35.3147
1010
            elif flowrate_volume_unit == 'USgpm':
1011
                volume = float(flowrate_volume) / 4.40287
1012
            elif flowrate_volume_unit == 'BPSD':
1013
                volume = float(flowrate_volume) / 150.955
1014

    
1015
        # ' ********** 2. viscosity 구하기 ***********
1016
        viscosity_unit = self.ui.label_Viscosity_Unit_Liquid.text()
1017
        if viscosity_unit == 'kg/m.sec':
1018
            viscosity = float(viscosity)
1019
        elif viscosity_unit == 'cP':
1020
            viscosity = float(viscosity) * 0.001
1021
        elif viscosity_unit == 'kg/m.h':
1022
            viscosity = float(viscosity) / 3600
1023
        elif viscosity_unit == 'lb/ft.s':
1024
            viscosity = float(viscosity) * 1.48816
1025

    
1026
        # '조도 구함 (m)
1027
        roughness_unit = self.ui.label_Roughness_Unit.text()
1028
        if roughness_unit == 'm':
1029
            rough = float(roughness)
1030
        elif roughness_unit == 'ft':
1031
            rough = float(roughness) * 0.3048
1032
        elif roughness_unit == 'in':
1033
            rough = float(roughness) * 0.0254
1034
        elif roughness_unit == 'mm':
1035
            rough = float(roughness) * 0.001
1036

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

    
1039
        # 'ID 구함 (in)
1040
        nominal_pipe_size_unit = self.ui.label_Nominal_Pipe_Size_Unit.text()
1041
        if nominal_pipe_size_unit == 'in':
1042
            nd = float(inside_pipe_size)
1043
        elif nominal_pipe_size_unit == 'mm':
1044
            nd = float(inside_pipe_size) / 25
1045

    
1046
        # ' 속도 구함
1047
        velocity = 4 * volume / 3.1415 / ((nd * 0.0254) ** 2) / 3600
1048

    
1049
        # ' 레이놀즈 넘버 구함
1050
        reynolds = (nd * 0.0254) * velocity * density / viscosity
1051

    
1052
        # '마찰계수 산출
1053
        if reynolds < 2100:
1054
            f = 4 * 16 / reynolds
1055
        else:
1056
            a = math.log(rough / (nd * 0.0254) / 3.7 + (6.7 / reynolds) ** 0.9) / math.log(10)
1057
            f = (-2 * (math.log(rough / 3.7 / (nd * 0.0254) - 5.02 / reynolds * a) / math.log(10))) ** (-2)
1058

    
1059
        return f
1060

    
1061
    def get_equivalent_length_liquid(self, total_k):
1062
        # 마찰계수
1063
        friction_coefficient = self.get_friction_coefficient_liquid()
1064

    
1065
        pipe_unit = self.ui.label_Inside_Pipe_Size_Unit.text()
1066
        pipe_id = float(self.ui.lineEdit_Inside_Pipe_Size.text())
1067
        if pipe_unit == 'in':
1068
            return round(pipe_id * total_k / friction_coefficient * 0.0254, 3)
1069
        elif pipe_unit == 'mm':
1070
            return round(pipe_id * total_k / friction_coefficient / 1000, 3)
1071

    
1072
    def get_equivalent_length_vapor(self, total_k):
1073
        # 마찰계수
1074
        friction_coefficient = self.get_friction_coefficient_vapor()
1075

    
1076
        pipe_unit = self.ui.label_Inside_Pipe_Size_Unit.text()
1077
        pipe_id = float(self.ui.lineEdit_Inside_Pipe_Size.text())
1078
        if pipe_unit == 'in':
1079
            return round(pipe_id * total_k / total_k * 0.0254, 3)
1080
        elif pipe_unit == 'mm':
1081
            return round(pipe_id * total_k / total_k / 1000, 3)
1082

    
1083
    def init_phase_type(self):
1084
        self.ui.comboBox_PhaseType.clear()
1085

    
1086
        self.ui.comboBox_PhaseType.addItem('Vapor (Compressible)', 'Vapor')
1087
        self.ui.comboBox_PhaseType.addItem('Liquid (Incompressible)', 'Liquid')
1088
        self.ui.comboBox_PhaseType.addItem('Mixed (Vapor + Liquid)', 'Mixed')
1089

    
1090
        self.ui.comboBox_PhaseType.setCurrentIndex(1)
1091

    
1092
    def init_units(self):
1093
        app_doc_data = AppDocData.instance()
1094
        active_drawing = app_doc_data.activeDrawing
1095

    
1096
        for attr in active_drawing.attrs:
1097
            if attr[0] == 'Units':
1098
                self.ui.label_Flowrate_Mass_Unit_Liquid.setText(attr[1]['Flowrate_Mass'])
1099
                self.ui.label_Flowrate_Mass_Unit_Vapor.setText(attr[1]['Flowrate_Mass'])
1100
                self.ui.label_Flowrate_Mass_Unit_Mixed.setText(attr[1]['Flowrate_Mass'])
1101
                self.ui.label_Flowrate_Volume_Unit.setText(attr[1]['Flowrate_Volume'])
1102
                self.ui.label_Density_Unit.setText(attr[1]['Density'])
1103
                self.ui.label_Density_Unit_Mixed.setText(attr[1]['Density'])
1104
                self.ui.label_Viscosity_Unit_Liquid.setText(attr[1]['Viscosity'])
1105
                self.ui.label_Viscosity_Unit_Vapor.setText(attr[1]['Viscosity'])
1106
                self.ui.label_Viscosity_Unit_Mixed.setText(attr[1]['Viscosity'])
1107
                self.ui.label_Velocity_Unit.setText(attr[1]['Velocity'])
1108
                self.ui.label_DropPressure_Unit.setText('{}/100{}'.format(attr[1]['Pressure'], attr[1]['Length']))
1109
                self.ui.label_Nominal_Pipe_Size_Unit.setText(attr[1]['Pipe_Diameter'])
1110
                self.ui.label_Inside_Pipe_Size_Unit.setText(attr[1]['Pipe_Diameter'])
1111
                if self.liquid_drop_method == 'darcy':
1112
                    self.ui.label_Roughness_Unit.setText(attr[1]['Roughness'])
1113
                else:
1114
                    self.ui.label_Roughness_Unit.setText('')
1115
                self.ui.label_Straight_Lengh_Unit.setText(attr[1]['Length'])
1116
                self.ui.label_Equivalent_Lenght_Input_Unit.setText(attr[1]['Length'])
1117
                self.ui.label_Fitting_Length_Unit.setText(attr[1]['Length'])
1118
                self.ui.label_Equivalent_Lenght_Cal_Unit.setText(attr[1]['Length'])
1119
                self.ui.label_Temperature_Unit.setText(attr[1]['Temperature'])
1120
                self.ui.label_Temperature_Unit_Mixed.setText(attr[1]['Temperature'])
1121
                self.ui.label_Pressure_Unit_Mixed.setText('{}(g)'.format(attr[1]['Pressure']))
1122

    
1123
    def on_change_phase_type(self):
1124
        phase_type = self.ui.comboBox_PhaseType.currentData()
1125

    
1126
        if phase_type == 'Vapor':
1127
            self.ui.groupBox_ProcessData_Vapor.setVisible(True)
1128
            self.ui.groupBox_Line_Sizing_Data.setVisible(True)
1129
            self.ui.groupBox_GeometryData.setVisible(True)
1130
            self.ui.pushButton_Line_Sizing.setVisible(True)
1131
            self.ui.pushButton_Diameter_Estimation.setVisible(True)
1132
            self.ui.pushButton_Copy_Stream.setVisible(True)
1133
            self.ui.groupBox_ProcessData_Liquid.setVisible(False)
1134

    
1135
            self.ui.groupBox_ProcessData_Mixed.setVisible(False)
1136
            self.ui.groupBox_GeometryData_Mixed.setVisible(False)
1137
            self.ui.pushButton_Add_GeometryData_Mixed.setVisible(False)
1138
            self.ui.pushButton_Calculation.setVisible(False)
1139
            self.ui.pushButton_view.setVisible(False)
1140
        elif phase_type == 'Liquid':
1141
            self.ui.groupBox_ProcessData_Liquid.setVisible(True)
1142
            self.ui.groupBox_Line_Sizing_Data.setVisible(True)
1143
            self.ui.groupBox_GeometryData.setVisible(True)
1144
            self.ui.pushButton_Line_Sizing.setVisible(True)
1145
            self.ui.pushButton_Diameter_Estimation.setVisible(True)
1146
            self.ui.pushButton_Copy_Stream.setVisible(True)
1147
            self.ui.groupBox_ProcessData_Vapor.setVisible(False)
1148

    
1149
            self.ui.groupBox_ProcessData_Mixed.setVisible(False)
1150
            self.ui.groupBox_GeometryData_Mixed.setVisible(False)
1151
            self.ui.pushButton_Add_GeometryData_Mixed.setVisible(False)
1152
            self.ui.pushButton_Calculation.setVisible(False)
1153
            self.ui.pushButton_view.setVisible(False)
1154
        elif phase_type == 'Mixed':
1155
            self.ui.groupBox_ProcessData_Mixed.setVisible(True)
1156
            self.ui.groupBox_GeometryData_Mixed.setVisible(True)
1157
            self.ui.pushButton_Add_GeometryData_Mixed.setVisible(True)
1158
            self.ui.pushButton_Calculation.setVisible(True)
1159
            self.ui.pushButton_view.setVisible(True)
1160

    
1161
            self.ui.groupBox_ProcessData_Vapor.setVisible(False)
1162
            self.ui.groupBox_ProcessData_Liquid.setVisible(False)
1163
            self.ui.groupBox_Line_Sizing_Data.setVisible(False)
1164
            self.ui.groupBox_GeometryData.setVisible(False)
1165
            self.ui.pushButton_Line_Sizing.setVisible(False)
1166
            self.ui.pushButton_Diameter_Estimation.setVisible(False)
1167
            self.ui.pushButton_Copy_Stream.setVisible(False)
1168

    
1169
    def getInsideDiameter(self):
1170
        from AppDocData import AppDocData
1171

    
1172
        self.ui.lineEdit_Inside_Pipe_Size.clear()
1173

    
1174
        nominal_diameter_uid = self.ui.comboBox_Nominal_Pipe_Size.currentData()
1175
        schedule_uid = self.ui.comboBox_Schedule_No.currentData()
1176
        schedule_no = self.ui.comboBox_Schedule_No.currentText()
1177

    
1178
        if schedule_no == 'User Sch.':
1179
            self.ui.lineEdit_Inside_Pipe_Size.setReadOnly(False)
1180
        else:
1181
            self.ui.lineEdit_Inside_Pipe_Size.setReadOnly(True)
1182
            if nominal_diameter_uid and schedule_uid:
1183
                inside_diameter = AppDocData.instance().getInsideDiameter(nominal_diameter_uid, schedule_uid)
1184
                if len(inside_diameter) > 0:
1185
                    if self.ui.label_Inside_Pipe_Size_Unit.text() == 'mm':
1186
                        if inside_diameter[0][1]:
1187
                            self.ui.lineEdit_Inside_Pipe_Size.setText(str(inside_diameter[0][1]))
1188
                    else:
1189
                        if inside_diameter[0][2]:
1190
                            self.ui.lineEdit_Inside_Pipe_Size.setText(str(inside_diameter[0][2]))
1191

    
1192
    def init_nominal_diameter(self):
1193
        from AppDocData import AppDocData
1194

    
1195
        self.ui.comboBox_Nominal_Pipe_Size.clear()
1196

    
1197
        nominal_diameter_list = AppDocData.instance().getNominalDiameter()
1198
        for nominalDiameter in nominal_diameter_list:
1199
            if self.ui.label_Nominal_Pipe_Size_Unit.text() == 'mm':
1200
                self.ui.comboBox_Nominal_Pipe_Size.addItem(str(convert_to_fixed_point(nominalDiameter[1])),
1201
                                                           nominalDiameter[0])
1202
            else:
1203
                self.ui.comboBox_Nominal_Pipe_Size.addItem(str(convert_to_fixed_point(nominalDiameter[2])),
1204
                                                           nominalDiameter[0])
1205
        self.ui.comboBox_Nominal_Pipe_Size.setCurrentIndex(-1)
1206

    
1207
    def init_schedule(self):
1208
        from AppDocData import AppDocData
1209

    
1210
        self.ui.comboBox_Schedule_No.clear()
1211

    
1212
        schedule_list = AppDocData.instance().getSchedule()
1213
        for schedule in schedule_list:
1214
            self.ui.comboBox_Schedule_No.addItem(str(schedule[1]), schedule[0])
1215

    
1216
        self.ui.comboBox_Schedule_No.setCurrentIndex(-1)
1217

    
1218
    def showDialog(self, item):
1219
        self.item = item
1220
        self.setWindowFlags(self.windowFlags() & ~QtCore.Qt.WindowContextHelpButtonHint)
1221
        self.ui.lineEdit_StreamNo.setText(str(item.stream_no))
1222
        self.load_hmb(item.uid)
1223
        self.load_geometry()
1224
        self.exec_()
1225

    
1226
        return self.result
1227

    
1228
    def load_geometry(self):
1229
        from AppDocData import AppDocData
1230
        try:
1231
            geometry = self.item.mixed_geometry
1232
            if geometry:
1233
                for row in geometry:
1234
                    row_count = self.ui.tableWidget_GeometryData_Mixed.rowCount()
1235

    
1236
                    self.ui.tableWidget_GeometryData_Mixed.setRowCount(row_count + 1)
1237

    
1238
                    self.ui.tableWidget_GeometryData_Mixed.setItem(row_count, 0,
1239
                                                                   set_item_properties(row[0],
1240
                                                                                       Qt.AlignLeft | Qt.AlignVCenter))
1241

    
1242
                    self.ui.tableWidget_GeometryData_Mixed.setItem(row_count, 1,
1243
                                                                   set_item_properties(convert_to_fixed_point(row[1]),
1244
                                                                                       Qt.AlignRight | Qt.AlignVCenter))
1245

    
1246
                    self.ui.tableWidget_GeometryData_Mixed.setItem(row_count, 2,
1247
                                                                   set_item_properties(convert_to_fixed_point(row[2]),
1248
                                                                                       Qt.AlignRight | Qt.AlignVCenter))
1249

    
1250
                    self.ui.tableWidget_GeometryData_Mixed.setItem(row_count, 3,
1251
                                                                   set_item_properties(convert_to_fixed_point(row[3]),
1252
                                                                                       Qt.AlignRight | Qt.AlignVCenter))
1253

    
1254
                    self.ui.tableWidget_GeometryData_Mixed.setItem(row_count, 4,
1255
                                                                   set_item_properties(convert_to_fixed_point(row[4]),
1256
                                                                                       Qt.AlignRight | Qt.AlignVCenter))
1257

    
1258
                    self.ui.tableWidget_GeometryData_Mixed.setItem(row_count, 5,
1259
                                                                   set_item_properties(convert_to_fixed_point(row[5]),
1260
                                                                                       Qt.AlignRight | Qt.AlignVCenter))
1261

    
1262
                    self.ui.tableWidget_GeometryData_Mixed.setItem(row_count, 6,
1263
                                                                   set_item_properties(convert_to_fixed_point(row[6]),
1264
                                                                                       Qt.AlignRight | Qt.AlignVCenter))
1265

    
1266
                    self.ui.tableWidget_GeometryData_Mixed.setItem(row_count, 7,
1267
                                                                   set_item_properties(convert_to_fixed_point(row[7]),
1268
                                                                                       Qt.AlignRight | Qt.AlignVCenter))
1269

    
1270
                    self.ui.tableWidget_GeometryData_Mixed.setItem(row_count, 8,
1271
                                                                   set_item_properties(convert_to_fixed_point(row[8]),
1272
                                                                                       Qt.AlignRight | Qt.AlignVCenter))
1273

    
1274
                    self.ui.tableWidget_GeometryData_Mixed.setItem(row_count, 9,
1275
                                                                   set_item_properties(convert_to_fixed_point(row[9]),
1276
                                                                                       Qt.AlignRight | Qt.AlignVCenter))
1277

    
1278
                self.ui.tableWidget_GeometryData_Mixed.resizeColumnsToContents()
1279
                self.ui.tableWidget_GeometryData_Mixed.resizeRowsToContents()
1280

    
1281
        except Exception as ex:
1282
            from App import App
1283
            from AppDocData import MessageType
1284

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

    
1289
    def load_hmb(self, components_uid):
1290
        from AppDocData import AppDocData
1291
        try:
1292

    
1293
            drawing = AppDocData.instance().activeDrawing
1294
            if drawing:
1295
                matches = [hmb for hmb in drawing.hmbTable._hmbs if str(hmb.components_uid) == str(components_uid)]
1296
                if matches:
1297

    
1298
                    if matches[0].phase_type:
1299
                        index = self.ui.comboBox_PhaseType.findData(matches[0].phase_type)
1300
                        if index > -1:
1301
                            self.ui.comboBox_PhaseType.setCurrentIndex(index)
1302
                    if matches[0].flowrate_mass:
1303
                        self.ui.lineEdit_Flowrate_Mass_Liquid.setText(str(
1304
                            convert_to_fixed_point(matches[0].flowrate_mass)))
1305
                        self.ui.lineEdit_Flowrate_Mass_Vapor.setText(str(
1306
                            convert_to_fixed_point(matches[0].flowrate_mass)))
1307
                    if matches[0].flowrate_volume:
1308
                        self.ui.lineEdit_Flowrate_Volume.setText(str(
1309
                            convert_to_fixed_point(matches[0].flowrate_volume)))
1310
                    if matches[0].viscosity:
1311
                        self.ui.lineEdit_Viscosity_Liquid.setText(str(convert_to_fixed_point(matches[0].viscosity)))
1312
                        self.ui.lineEdit_Viscosity_Vapor.setText(str(convert_to_fixed_point(matches[0].viscosity)))
1313

    
1314
                    if matches[0].specific_heat_ratio:
1315
                        self.ui.lineEdit_Specific_Heat_Ratio.setText(str(
1316
                            convert_to_fixed_point(matches[0].specific_heat_ratio)))
1317
                    if matches[0].molecular_weight:
1318
                        self.ui.lineEdit_Molecular_Weight.setText(str(
1319
                            convert_to_fixed_point(matches[0].molecular_weight)))
1320
                    if matches[0].temperature:
1321
                        self.ui.lineEdit_Temperature.setText(str(convert_to_fixed_point(matches[0].temperature)))
1322
                    if matches[0].compress_factor:
1323
                        self.ui.lineEdit_Compress_Factor.setText(str(
1324
                            convert_to_fixed_point(matches[0].compress_factor)))
1325

    
1326
                    if matches[0].density:
1327
                        self.ui.lineEdit_Density.setText(str(convert_to_fixed_point(matches[0].density)))
1328
                    if matches[0].limitation_velocity:
1329
                        self.ui.lineEdit_Limitation_Velocity.setText(str(
1330
                            convert_to_fixed_point(matches[0].limitation_velocity)))
1331
                    if matches[0].limitation_pressure_drop:
1332
                        self.ui.lineEdit_Limitation_Pressure_Drop.setText(str(
1333
                            convert_to_fixed_point(matches[0].limitation_pressure_drop)))
1334
                    if matches[0].nominal_pipe_size:
1335
                        self.ui.comboBox_Nominal_Pipe_Size.setCurrentText(str(
1336
                            convert_to_fixed_point(matches[0].nominal_pipe_size)))
1337
                    if matches[0].schedule_no:
1338
                        self.ui.comboBox_Schedule_No.setCurrentText(str(convert_to_fixed_point(matches[0].schedule_no)))
1339
                    if matches[0].roughness:
1340
                        self.ui.lineEdit_Roughness.setText(str(convert_to_fixed_point(matches[0].roughness)))
1341
                    if matches[0].straight_length:
1342
                        self.ui.lineEdit_Straight_Length.setText(str(
1343
                            convert_to_fixed_point(matches[0].straight_length)))
1344
                    if matches[0].equivalent_length_input:
1345
                        self.ui.lineEdit_Equivalent_Length_Input.setText(str(
1346
                            convert_to_fixed_point(matches[0].equivalent_length_input)))
1347
                    if matches[0].fitting_length:
1348
                        self.ui.lineEdit_Fitting_Length.setText(str(convert_to_fixed_point(matches[0].fitting_length)))
1349
                    if matches[0].fitting_K:
1350
                        self.ui.lineEdit_Fitting_K.setText(str(convert_to_fixed_point(matches[0].fitting_K)))
1351
                    if matches[0].equivalent_length_cal:
1352
                        self.ui.lineEdit_Equivalent_Length_Cal.setText(str(
1353
                            convert_to_fixed_point(matches[0].equivalent_length_cal)))
1354
                    if matches[0].vapor_flowrate_mass:
1355
                        self.ui.lineEdit_Mixed_Flowrate_Mass_Vapor.setText(str(
1356
                            convert_to_fixed_point(matches[0].vapor_flowrate_mass)))
1357
                    if matches[0].vapor_density:
1358
                        self.ui.lineEdit_Mixed_Density_Vapor.setText(str(
1359
                            convert_to_fixed_point(matches[0].vapor_density)))
1360
                    if matches[0].vapor_viscosity:
1361
                        self.ui.lineEdit_Mixed_Viscosity_Vapor.setText(str(
1362
                            convert_to_fixed_point(matches[0].vapor_viscosity)))
1363
                    if matches[0].vapor_pressure:
1364
                        self.ui.lineEdit_Mixed_Pressure_Vapor.setText(str(
1365
                            convert_to_fixed_point(matches[0].vapor_pressure)))
1366
                    if matches[0].vapor_temperature:
1367
                        self.ui.lineEdit_Mixed_Temperature_Vapor.setText(str(
1368
                            convert_to_fixed_point(matches[0].vapor_temperature)))
1369
                    if matches[0].vapor_molecular_weight:
1370
                        self.ui.lineEdit_Mixed_Molecular_Weight_Vapor.setText(str(
1371
                            convert_to_fixed_point(matches[0].vapor_molecular_weight)))
1372
                    if matches[0].vapor_compress_factor:
1373
                        self.ui.lineEdit_Mixed_Compress_Factor_Vapor.setText(str(
1374
                            convert_to_fixed_point(matches[0].vapor_compress_factor)))
1375
                    if matches[0].liquid_flowrate_mass:
1376
                        self.ui.lineEdit_Mixed_Flowrate_Mass_Liquid.setText(str(
1377
                            convert_to_fixed_point(matches[0].liquid_flowrate_mass)))
1378
                    if matches[0].liquid_density:
1379
                        self.ui.lineEdit_Mixed_Density_Liquid.setText(str(
1380
                            convert_to_fixed_point(matches[0].liquid_density)))
1381
                    if matches[0].liquid_viscosity:
1382
                        self.ui.lineEdit_Mixed_Viscosity_Liquid.setText(str(
1383
                            convert_to_fixed_point(matches[0].liquid_viscosity)))
1384

    
1385
        except Exception as ex:
1386
            from App import App
1387
            from AppDocData import MessageType
1388

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

    
1393
    def getIndexByText(self, control, text):
1394
        return control.findText(text)
1395

    
1396
        # return control.findData(value)
1397

    
1398
    def update_mixed_hmb(self):
1399
        from AppDocData import AppDocData
1400

    
1401
        try:
1402
            drawing = AppDocData.instance().activeDrawing
1403
            if drawing:
1404
                values = {}
1405

    
1406
                phase_type = self.ui.comboBox_PhaseType.currentData()
1407
                if phase_type == 'Mixed':
1408
                    values['Phase_Type'] = 'Mixed'
1409
                    values['Vapor_Flowrate_Mass'] = self.ui.lineEdit_Mixed_Flowrate_Mass_Vapor.text()
1410
                    values['Vapor_Density'] = self.ui.lineEdit_Mixed_Density_Vapor.text()
1411
                    values['Vapor_Viscosity'] = self.ui.lineEdit_Mixed_Viscosity_Vapor.text()
1412
                    values['Vapor_Pressure'] = self.ui.lineEdit_Mixed_Pressure_Vapor.text()
1413
                    values['Vapor_Temperature'] = self.ui.lineEdit_Mixed_Temperature_Vapor.text()
1414
                    values['Vapor_Molecular_Weight'] = self.ui.lineEdit_Mixed_Molecular_Weight_Vapor.text()
1415
                    values['Vapor_Compress_Factor'] = self.ui.lineEdit_Mixed_Compress_Factor_Vapor.text()
1416
                    values['Liquid_Flowrate_Mass'] = self.ui.lineEdit_Mixed_Flowrate_Mass_Liquid.text()
1417
                    values['Liquid_Density'] = self.ui.lineEdit_Mixed_Density_Liquid.text()
1418
                    values['Liquid_Viscosity'] = self.ui.lineEdit_Mixed_Viscosity_Liquid.text()
1419
                    l_flowrate = float(self.ui.lineEdit_Mixed_Flowrate_Mass_Liquid.text()) if is_not_blank(
1420
                        self.ui.lineEdit_Mixed_Flowrate_Mass_Liquid.text()) else 0
1421
                    v_flowrate = float(self.ui.lineEdit_Mixed_Flowrate_Mass_Vapor.text()) if is_not_blank(
1422
                        self.ui.lineEdit_Mixed_Flowrate_Mass_Vapor.text()) else 0
1423
                    values['Flowrate_Mass'] = l_flowrate + v_flowrate
1424
                    values['Viscosity'] = 'Mixed'
1425
                    values['Temperature'] = self.ui.lineEdit_Mixed_Temperature_Vapor.text()
1426
                    values['Molecular_Weight'] = self.ui.lineEdit_Mixed_Molecular_Weight_Vapor.text()
1427
                    values['Specific_Heat_Ratio'] = 'Mixed'
1428
                    values['Compress_Factor'] = self.ui.lineEdit_Mixed_Compress_Factor_Vapor.text()
1429
                    values['Limitation_Velocity'] = 'Mixed'
1430
                    values['Limitation_Pressure_Drop'] = 'Mixed'
1431
                    values['Reynolds'] = 'Mixed'
1432
                    values['Friction_Factor'] = 'Mixed'
1433
                    values['Pressure_Drop'] = 'Mixed'
1434
                    values['Straight_Length'] = 'Mixed'
1435
                    if self.ui.tableWidget_GeometryData_Mixed.rowCount() > 0:
1436
                        values['Nominal_Pipe_Size'] = self.ui.tableWidget_GeometryData_Mixed.item(0, 1).text()
1437
                        values['Schedule_No'] = self.ui.tableWidget_GeometryData_Mixed.item(0, 2).text()
1438
                        values['Inside_Pipe_Size'] = self.ui.tableWidget_GeometryData_Mixed.item(0, 3).text()
1439
                        values['Roughness'] = self.ui.tableWidget_GeometryData_Mixed.item(0, 4).text()
1440

    
1441
                        equivalent_length = self.get_mixed_equivalent_length()
1442
                        values['Equivalent_Length'] = equivalent_length
1443
                        values['Equivalent_Length_Cal'] = equivalent_length
1444

    
1445
                drawing.hmbTable.updateByUID(self.item.uid, values)
1446

    
1447
        except Exception as ex:
1448
            from App import App
1449
            from AppDocData import MessageType
1450

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

    
1455
    def update_hmb(self):
1456
        from AppDocData import AppDocData
1457

    
1458
        try:
1459
            drawing = AppDocData.instance().activeDrawing
1460
            if drawing:
1461
                values = {}
1462

    
1463
                phase_type = self.ui.comboBox_PhaseType.currentData()
1464
                values['Phase_Type'] = phase_type
1465
                if phase_type == 'Vapor':
1466
                    values['Flowrate_Mass'] = self.ui.lineEdit_Flowrate_Mass_Vapor.text()
1467
                    values['Viscosity'] = self.ui.lineEdit_Viscosity_Vapor.text()
1468
                    values['Specific_Heat_Ratio'] = self.ui.lineEdit_Specific_Heat_Ratio.text()
1469
                    values['Molecular_Weight'] = self.ui.lineEdit_Molecular_Weight.text()
1470
                    values['Temperature'] = self.ui.lineEdit_Temperature.text()
1471
                    values['Compress_Factor'] = self.ui.lineEdit_Compress_Factor.text()
1472
                    values['Limitation_Velocity'] = self.ui.lineEdit_Limitation_Velocity.text()
1473
                    values['Limitation_Pressure_Drop'] = self.ui.lineEdit_Limitation_Pressure_Drop.text()
1474
                    values['Nominal_Pipe_Size'] = self.ui.comboBox_Nominal_Pipe_Size.currentText()
1475
                    values['Inside_Pipe_Size'] = self.ui.lineEdit_Inside_Pipe_Size.text()
1476
                    values['Schedule_No'] = self.ui.comboBox_Schedule_No.currentText()
1477
                    values['Roughness'] = self.ui.lineEdit_Roughness.text()
1478
                    values['Straight_Length'] = self.ui.lineEdit_Straight_Length.text()
1479
                    values['Equivalent_Length'] = self.get_equivalent_length()
1480
                    values['Equivalent_Length_Input'] = self.ui.lineEdit_Equivalent_Length_Input.text()
1481
                    values['Fitting_Length'] = self.ui.lineEdit_Fitting_Length.text()
1482
                    values['Fitting_K'] = self.ui.lineEdit_Fitting_K.text()
1483
                    values['Equivalent_Length_Cal'] = self.ui.lineEdit_Equivalent_Length_Cal.text()
1484
                    values['Flowrate_Volume'] = None
1485
                    values['Density'] = None
1486
                elif phase_type == 'Liquid':
1487
                    values['Flowrate_Mass'] = self.ui.lineEdit_Flowrate_Mass_Liquid.text()
1488
                    values['Flowrate_Volume'] = self.ui.lineEdit_Flowrate_Volume.text()
1489
                    values['Density'] = self.ui.lineEdit_Density.text()
1490
                    values['Viscosity'] = self.ui.lineEdit_Viscosity_Liquid.text()
1491
                    values['Limitation_Velocity'] = self.ui.lineEdit_Limitation_Velocity.text()
1492
                    values['Limitation_Pressure_Drop'] = self.ui.lineEdit_Limitation_Pressure_Drop.text()
1493
                    values['Nominal_Pipe_Size'] = self.ui.comboBox_Nominal_Pipe_Size.currentText()
1494
                    values['Inside_Pipe_Size'] = self.ui.lineEdit_Inside_Pipe_Size.text()
1495
                    values['Schedule_No'] = self.ui.comboBox_Schedule_No.currentText()
1496
                    values['Roughness'] = self.ui.lineEdit_Roughness.text()
1497
                    values['Straight_Length'] = self.ui.lineEdit_Straight_Length.text()
1498
                    values['Equivalent_Length'] = self.get_equivalent_length()
1499
                    values['Equivalent_Length_Input'] = self.ui.lineEdit_Equivalent_Length_Input.text()
1500
                    values['Fitting_Length'] = self.ui.lineEdit_Fitting_Length.text()
1501
                    values['Fitting_K'] = self.ui.lineEdit_Fitting_K.text()
1502
                    values['Equivalent_Length_Cal'] = self.ui.lineEdit_Equivalent_Length_Cal.text()
1503
                    values['Specific_Heat_Ratio'] = None
1504
                    values['Molecular_Weight'] = None
1505
                    values['Temperature'] = None
1506
                    values['Compress_Factor'] = None
1507

    
1508
                drawing.hmbTable.updateByUID(self.item.uid, values)
1509

    
1510
        except Exception as ex:
1511
            from App import App
1512
            from AppDocData import MessageType
1513

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

    
1518
    def get_mixed_equivalent_length(self):
1519
        equivalent_length = 0
1520

    
1521
        for row in range(self.ui.tableWidget_GeometryData_Mixed.rowCount()):
1522
            if is_not_blank(self.ui.tableWidget_GeometryData_Mixed.item(row, 5).text()):
1523
                length = float(self.ui.tableWidget_GeometryData_Mixed.item(row, 5).text())
1524
                if length:
1525
                    equivalent_length += length
1526

    
1527
        return equivalent_length
1528

    
1529
    def get_equivalent_length(self):
1530
        if self.ui.lineEdit_Equivalent_Length_Input.text():
1531
            self.ui.lineEdit_Fitting_Length.clear()
1532
            self.ui.lineEdit_Fitting_K.clear()
1533
            self.ui.lineEdit_Equivalent_Length_Cal.clear()
1534
            return self.ui.lineEdit_Equivalent_Length_Input.text()
1535
        else:
1536
            self.ui.lineEdit_Equivalent_Length_Input.clear()
1537
            return self.ui.lineEdit_Equivalent_Length_Cal.text()
1538

    
1539
    def update_mixed_geometry(self):
1540
        geometry = []
1541

    
1542
        if self.ui.tableWidget_GeometryData_Mixed.rowCount() > 0:
1543
            for row in range(self.ui.tableWidget_GeometryData_Mixed.rowCount()):
1544
                element = self.ui.tableWidget_GeometryData_Mixed.item(row, 0).text()
1545
                nominal_pipe_size = self.ui.tableWidget_GeometryData_Mixed.item(row, 1).text()
1546
                schedule_no = self.ui.tableWidget_GeometryData_Mixed.item(row, 2).text()
1547
                inside_pipe_size = self.ui.tableWidget_GeometryData_Mixed.item(row, 3).text()
1548
                roughness = self.ui.tableWidget_GeometryData_Mixed.item(row, 4).text()
1549
                length = self.ui.tableWidget_GeometryData_Mixed.item(row, 5).text()
1550
                angle = self.ui.tableWidget_GeometryData_Mixed.item(row, 6).text()
1551
                rpd = self.ui.tableWidget_GeometryData_Mixed.item(row, 7).text()
1552
                d1_d2 = self.ui.tableWidget_GeometryData_Mixed.item(row, 8).text()
1553
                k = self.ui.tableWidget_GeometryData_Mixed.item(row, 9).text()
1554

    
1555
                geometry.append(
1556
                    (
1557
                        element, nominal_pipe_size, schedule_no, inside_pipe_size, roughness, length, angle, rpd, d1_d2,
1558
                        k))
1559

    
1560
        self.item.mixed_geometry = geometry
1561

    
1562
    def accept(self):
1563
        # Mixed Type Check
1564
        phase_type = self.ui.comboBox_PhaseType.currentData()
1565
        if phase_type == 'Mixed':
1566
            if self.item.pressure_variation is None:
1567
                QMessageBox.information(self, self.tr("Information"), self.tr("Calculate this line !"))
1568
                return
1569

    
1570
        self.update_hmb()
1571
        self.result = True
1572

    
1573
        QDialog.accept(self)
1574

    
1575
    def reject(self):
1576
        self.result = False
1577

    
1578
        QDialog.reject(self)
1579

    
1580
    if __name__ == '__main__':
1581
        from StreamDataDialog import QStreamDataDialog
1582
        from App import App
1583

    
1584
        app = App(sys.argv)
1585

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