hytos / HYTOS / HYTOS / AirFinCooler.py @ cac163a4
이력 | 보기 | 이력해설 | 다운로드 (5.19 KB)
1 |
# -*- coding: utf-8 -*-
|
---|---|
2 |
"""This is AirFinCooler module"""
|
3 | |
4 |
from PyQt5 import QtCore, QtGui, QtWidgets |
5 |
from PyQt5.QtWidgets import * |
6 |
import os |
7 |
from AppDocData import AppDocData |
8 |
import AirFinCooler_UI |
9 |
import math |
10 | |
11 | |
12 |
def is_float(s): |
13 |
try:
|
14 |
if s:
|
15 |
float(s)
|
16 |
return True |
17 |
else:
|
18 |
return False |
19 |
except ValueError: |
20 |
return False |
21 | |
22 | |
23 |
def is_blank(s): |
24 |
return not (s and s.strip()) |
25 | |
26 | |
27 |
def is_not_blank(s): |
28 |
return bool(s and s.strip()) |
29 | |
30 | |
31 |
def convert_to_fixed_point(value): |
32 |
if is_float(str(value)): |
33 |
tokens = f"{float(value):.10f}".split('.') |
34 |
if len(tokens) == 2: |
35 |
# 소수점 아래가 있을 경우 소수점 아래의 trailing zero를 제거한다.
|
36 |
if is_blank(tokens[1].rstrip('0')): |
37 |
return tokens[0] |
38 |
else:
|
39 |
tokens[1] = tokens[1].rstrip('0') |
40 |
return '.'.join(tokens) |
41 |
else:
|
42 |
return tokens[0] |
43 |
else:
|
44 |
return value
|
45 | |
46 | |
47 |
class QAirFinCooler(QDialog): |
48 |
def __init__(self): |
49 |
QDialog.__init__(self)
|
50 | |
51 |
self.ui = AirFinCooler_UI.Ui_AirFinCoolerDialog()
|
52 |
self.ui.setupUi(self) |
53 |
self.ui.buttonBox.button(QDialogButtonBox.Ok).setIcon(QtGui.QIcon(':/images/OK.svg')) |
54 |
self.ui.buttonBox.button(QDialogButtonBox.Cancel).setIcon(QtGui.QIcon(':/images/Cancel.svg')) |
55 | |
56 |
self._item = None |
57 |
self._modified = False |
58 | |
59 |
self.ui.lineEdit_Pressure_Drop.setValidator(QtGui.QDoubleValidator(self.ui.lineEdit_Pressure_Drop)) |
60 |
self.ui.lineEdit_Elevation.setValidator(QtGui.QDoubleValidator(self.ui.lineEdit_Elevation)) |
61 |
self.initialize()
|
62 | |
63 |
def show_dialog(self, item): |
64 |
self.setWindowFlags(self.windowFlags() & ~QtCore.Qt.WindowContextHelpButtonHint) |
65 |
self._item = item
|
66 | |
67 |
self.ui.lineEdit_TagNo.setFocus()
|
68 |
self.set_controls()
|
69 |
self.load_data()
|
70 |
self.exec_()
|
71 | |
72 |
return self._modified |
73 | |
74 |
def initialize(self): |
75 |
self.ui.label_Img.setVisible(False) |
76 | |
77 |
def set_controls(self): |
78 |
self.ui.label_Img.setVisible(True) |
79 | |
80 |
def is_modified(self): |
81 |
""" Tag No 도 Output Explorer에 사용되기에 Modified 적용"""
|
82 |
old_tag_no = self.ui.lineEdit_TagNo.placeholderText()
|
83 |
new_tag_no = self.ui.lineEdit_TagNo.text()
|
84 |
if old_tag_no != new_tag_no:
|
85 |
self._modified = True |
86 |
return
|
87 | |
88 |
old_pressure_drop = self.ui.lineEdit_Pressure_Drop.placeholderText()
|
89 |
new_pressure_drop = self.ui.lineEdit_Pressure_Drop.text()
|
90 |
if old_pressure_drop != new_pressure_drop:
|
91 |
self._modified = True |
92 |
return
|
93 | |
94 |
old_elevation = self.ui.lineEdit_Elevation.placeholderText()
|
95 |
new_elevation = self.ui.lineEdit_Elevation.text()
|
96 |
if old_elevation != new_elevation:
|
97 |
self._modified = True |
98 |
return
|
99 | |
100 |
def load_data(self): |
101 |
""" load tag no and nozzle data """
|
102 |
tag_no = self._item.tag_no
|
103 |
if tag_no != 'None' and is_not_blank(tag_no): |
104 |
self.ui.lineEdit_TagNo.setText(tag_no)
|
105 |
self.ui.lineEdit_TagNo.setPlaceholderText(tag_no)
|
106 | |
107 |
app_doc_data = AppDocData.instance() |
108 |
drawing = app_doc_data.activeDrawing |
109 |
if drawing:
|
110 |
for attr in drawing.attrs: |
111 |
if attr[0] == 'Units': |
112 |
self.ui.label_PressureUnit.setText(attr[1]['Pressure']) |
113 |
self.ui.label_ElevationUnit.setText(attr[1]['Length']) |
114 | |
115 |
matches = [connector.data for connector in self._item.connectors if connector.data] |
116 |
if matches:
|
117 |
pressure_drop = matches[0].pressure_drop
|
118 |
if pressure_drop is not None: |
119 |
self.ui.lineEdit_Pressure_Drop.setText(str(convert_to_fixed_point(pressure_drop))) |
120 |
self.ui.lineEdit_Pressure_Drop.setPlaceholderText(str(convert_to_fixed_point(pressure_drop))) |
121 | |
122 |
elevation = matches[0].elevation
|
123 |
if elevation is not None: |
124 |
self.ui.lineEdit_Elevation.setText(str(convert_to_fixed_point(elevation))) |
125 |
self.ui.lineEdit_Elevation.setPlaceholderText(str(convert_to_fixed_point(elevation))) |
126 | |
127 |
def accept(self): |
128 |
""" check changed value """
|
129 |
self.is_modified()
|
130 | |
131 |
""" set tag no and nozzle data """
|
132 |
from EngineeringConnectorItem import NozzleData |
133 |
tag_no = self.ui.lineEdit_TagNo.text()
|
134 | |
135 |
if is_not_blank(tag_no):
|
136 |
self._item.tag_no = tag_no
|
137 |
for connector in self._item.connectors: |
138 |
if not connector.data: |
139 |
connector.data = NozzleData() |
140 | |
141 |
pressure_drop = self.ui.lineEdit_Pressure_Drop.text()
|
142 |
if pressure_drop:
|
143 |
connector.data.pressure_drop = float(pressure_drop)
|
144 |
else:
|
145 |
connector.data.pressure_drop = 0
|
146 | |
147 |
elevation = self.ui.lineEdit_Elevation.text()
|
148 |
if elevation:
|
149 |
connector.data.elevation = float(elevation)
|
150 |
else:
|
151 |
connector.data.elevation = 0
|
152 | |
153 |
QDialog.accept(self)
|
154 |
else:
|
155 |
QMessageBox.information(self, self.tr('Information'), self.tr('Please Input [Tag No.]')) |
156 | |
157 |
def reject(self): |
158 |
QDialog.reject(self)
|