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