hytos / HYTOS / HYTOS / Valve_Control.py @ d694c9e8
이력 | 보기 | 이력해설 | 다운로드 (8.88 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 Valve_Control_UI |
14 |
import math |
15 |
|
16 |
|
17 |
def is_blank(s): |
18 |
return not (s and s.strip()) |
19 |
|
20 |
def is_not_blank(s): |
21 |
return bool(s and s.strip()) |
22 |
|
23 |
class QValve_Control(QDialog): |
24 |
def __init__(self): |
25 |
QDialog.__init__(self)
|
26 |
|
27 |
self.ui = Valve_Control_UI.Ui_Valve_ControlDialog()
|
28 |
self.ui.setupUi(self) |
29 |
self._item = None |
30 |
|
31 |
self.ui.lineEdit_Pressure_Drop.setValidator(QtGui.QDoubleValidator(self.ui.lineEdit_Pressure_Drop)) |
32 |
self.ui.lineEdit_Elevation.setValidator(QtGui.QDoubleValidator(self.ui.lineEdit_Elevation)) |
33 |
self.ui.lineEdit_Overdesign.setValidator(QtGui.QDoubleValidator(self.ui.lineEdit_Overdesign)) |
34 |
|
35 |
self.ui.lineEdit_Rangerability.setValidator(QtGui.QDoubleValidator(self.ui.lineEdit_Rangerability)) |
36 |
self.ui.lineEdit_Calculated_Cv.setValidator(QtGui.QDoubleValidator(self.ui.lineEdit_Calculated_Cv)) |
37 |
|
38 |
self.ui.comboBox_Valve_Type.currentIndexChanged.connect(self.valve_type_change) |
39 |
self.ui.pushButton_Opening_Calculation.clicked.connect(self.opening_calculation) |
40 |
self.ui.pushButton_Opening.clicked.connect(self.opening) |
41 |
|
42 |
self.initialize()
|
43 |
|
44 |
def opening(self): |
45 |
# Validation Check
|
46 |
if not self.ui.radioButton_Linear.isChecked() and not self.ui.radioButton_Equal_Percentage.isChecked(): |
47 |
QMessageBox.information(self, self.tr('Information'), self.tr('Select Flow Character !\nLinear or Equal Percentage')) |
48 |
return
|
49 |
rangerability = self.ui.lineEdit_Rangerability.text()
|
50 |
calculated_cv = self.ui.lineEdit_Calculated_Cv.text()
|
51 |
rated_cv = self.ui.lineEdit_Rated_Cv.text()
|
52 |
|
53 |
if is_blank(rangerability):
|
54 |
QMessageBox.information(self, self.tr("Information"), self.tr("Please input [Rangerability Data] !")) |
55 |
return
|
56 |
elif is_blank(calculated_cv):
|
57 |
QMessageBox.information(self, self.tr("Information"), self.tr("Please input [Calculated Cv Data] !")) |
58 |
return
|
59 |
elif is_blank(rated_cv):
|
60 |
QMessageBox.information(self, self.tr("Information"), self.tr("Please input [Calculated Cv Data] !")) |
61 |
return
|
62 |
|
63 |
if rangerability == '1': |
64 |
QMessageBox.warning(self, self.tr('Notice'), self.tr("""Don't input 1 !\nIt's not actual\nRangerability will changed to 50.""")) |
65 |
self.ui.lineEdit_Rangerability.setText(str(50)) |
66 |
rangerability = 50
|
67 |
|
68 |
if self.ui.radioButton_Linear.isChecked(): |
69 |
a = math.log(float(rangerability))
|
70 |
c = math.log(float(calculated_cv) / float(rated_cv)) |
71 |
opening = 100 / a * c + 100 |
72 |
elif self.ui.radioButton_Equal_Percentage.isChecked(): |
73 |
a = float(rangerability) * float(calculated_cv) - float(rated_cv) |
74 |
b = float(rangerability) - 1 |
75 |
opening = a / (float(rated_cv) * b) * 100 |
76 |
|
77 |
self.ui.lineEdit_Opening.setText(str(round(opening, 4))) |
78 |
|
79 |
def opening_calculation(self): |
80 |
cur_text = self.ui.pushButton_Opening_Calculation.text()
|
81 |
if cur_text == 'Opening % Calculation': |
82 |
self.ui.pushButton_Opening_Calculation.setText('Completed') |
83 |
self.resize(446, 530) |
84 |
else:
|
85 |
self.ui.pushButton_Opening_Calculation.setText('Opening % Calculation') |
86 |
self.resize(446, 270) |
87 |
|
88 |
def valve_type_change(self, index): |
89 |
if index == -1: |
90 |
self.ui.lineEdit_Rangerability.clear()
|
91 |
self.dsiplay_image(None) |
92 |
return
|
93 |
|
94 |
valve_type = self.ui.comboBox_Valve_Type.itemText(index)
|
95 |
if valve_type == '--User Input--': |
96 |
self.ui.lineEdit_Rangerability.clear()
|
97 |
self.ui.lineEdit_Rangerability.setReadOnly(False) |
98 |
self.ui.lineEdit_Rangerability.setStyleSheet('QLineEdit {background-color: white;}') |
99 |
self.dsiplay_image(None) |
100 |
else:
|
101 |
data = self.ui.comboBox_Valve_Type.itemData(index)
|
102 |
rangerability = data[0]
|
103 |
image = data[1]
|
104 |
self.ui.lineEdit_Rangerability.setText(str(rangerability)) |
105 |
self.ui.lineEdit_Rangerability.setReadOnly(True) |
106 |
self.ui.lineEdit_Rangerability.setStyleSheet('QLineEdit {background-color: rgb(237,237,237);}') |
107 |
self.dsiplay_image(image)
|
108 |
|
109 |
def dsiplay_image(self, image): |
110 |
picture = QtGui.QPixmap(':/images/{}'.format(image))
|
111 |
w = 130 # self.ui.label_Valve_Img.height() |
112 |
h = 100 # self.ui.label_Valve_Img.width() |
113 |
self.ui.label_Valve_Img.setPixmap(
|
114 |
picture.scaled(w, h, QtCore.Qt.KeepAspectRatio, QtCore.Qt.FastTransformation)) |
115 |
|
116 |
def show_dialog(self, item): |
117 |
self.setWindowFlags(self.windowFlags() & ~QtCore.Qt.WindowContextHelpButtonHint) |
118 |
self._item = item
|
119 |
|
120 |
self.ui.lineEdit_TagNo.setFocus()
|
121 |
self.set_controls()
|
122 |
self.load_data()
|
123 |
|
124 |
return self.exec_() |
125 |
|
126 |
def initialize(self): |
127 |
self.ui.label_Img.setVisible(False) |
128 |
|
129 |
self.ui.comboBox_Valve_Type.addItem('Globe, Single Port', [50, 'globe_single_port.png']) |
130 |
self.ui.comboBox_Valve_Type.addItem('Globe, Double Port', [50, 'globe_double_port.png']) |
131 |
self.ui.comboBox_Valve_Type.addItem('Globe, Pressure balanced cage', [50, 'globe_pressure_balanced_cage_linear.png']) |
132 |
self.ui.comboBox_Valve_Type.addItem('Rotating Disc', [100, 'rotating_disc.png']) |
133 |
self.ui.comboBox_Valve_Type.addItem('Spilt Body', [30, None]) |
134 |
self.ui.comboBox_Valve_Type.addItem('Angle', [30, 'angle_cage_type.png']) |
135 |
self.ui.comboBox_Valve_Type.addItem('Diaphragm', [5, None]) |
136 |
self.ui.comboBox_Valve_Type.addItem('Butterfly, 60˚', [15, None]) |
137 |
self.ui.comboBox_Valve_Type.addItem('Butterfly, 60˚(Throttling)', [20, 'bf_thro.png']) |
138 |
self.ui.comboBox_Valve_Type.addItem('Butterfly, 60˚(Eccentric Disc)', [25, 'bf.png']) |
139 |
self.ui.comboBox_Valve_Type.addItem('Butterfly, 90˚', [100, None]) |
140 |
self.ui.comboBox_Valve_Type.addItem('Pinch', [5, None]) |
141 |
self.ui.comboBox_Valve_Type.addItem('Vee-Ball', [30, None]) |
142 |
self.ui.comboBox_Valve_Type.addItem('Full Ball', [100, None]) |
143 |
self.ui.comboBox_Valve_Type.addItem('--User Input--', [0, None]) |
144 |
|
145 |
self.ui.comboBox_Valve_Type.setCurrentIndex(-1) |
146 |
|
147 |
def set_controls(self): |
148 |
self.ui.label_Img.setVisible(True) |
149 |
|
150 |
def load_data(self): |
151 |
""" load tag no and nozzle data """
|
152 |
tag_no = self._item.tag_no
|
153 |
if tag_no != 'None' and is_not_blank(tag_no): |
154 |
self.ui.lineEdit_TagNo.setText(tag_no)
|
155 |
|
156 |
app_doc_data = AppDocData.instance() |
157 |
drawing = app_doc_data.activeDrawing |
158 |
if drawing:
|
159 |
for attr in drawing.attrs: |
160 |
if attr[0] == 'Units': |
161 |
self.ui.label_PressureUnit.setText(attr[1]['Pressure']) |
162 |
self.ui.label_ElevationUnit.setText(attr[1]['Length']) |
163 |
|
164 |
matches = [connector.data for connector in self._item.connectors if connector.data] |
165 |
if matches:
|
166 |
pressure_drop = matches[0].pressure_drop
|
167 |
if pressure_drop is not None: |
168 |
self.ui.lineEdit_Pressure_Drop.setText(str(pressure_drop)) |
169 |
|
170 |
elevation = matches[0].elevation
|
171 |
if elevation is not None: |
172 |
self.ui.lineEdit_Elevation.setText(str(elevation)) |
173 |
|
174 |
over_design_cv = matches[0].over_design_cv
|
175 |
if over_design_cv is not None: |
176 |
self.ui.lineEdit_Overdesign.setText(str(over_design_cv)) |
177 |
|
178 |
def accept(self): |
179 |
|
180 |
""" set tag no and nozzle data """
|
181 |
from EngineeringConnectorItem import NozzleData |
182 |
tag_no = self.ui.lineEdit_TagNo.text()
|
183 |
|
184 |
if is_not_blank(tag_no):
|
185 |
self._item.tag_no = tag_no
|
186 |
for connector in self._item.connectors: |
187 |
if not connector.data: |
188 |
connector.data = NozzleData() |
189 |
|
190 |
pressure_drop = self.ui.lineEdit_Pressure_Drop.text()
|
191 |
if pressure_drop:
|
192 |
connector.data.pressure_drop = float(pressure_drop)
|
193 |
else:
|
194 |
connector.data.pressure_drop = None
|
195 |
|
196 |
elevation = self.ui.lineEdit_Elevation.text()
|
197 |
if elevation:
|
198 |
connector.data.elevation = float(elevation)
|
199 |
else:
|
200 |
connector.data.elevation = None
|
201 |
|
202 |
over_design_cv = self.ui.lineEdit_Overdesign.text()
|
203 |
if over_design_cv:
|
204 |
connector.data.over_design_cv = float(over_design_cv)
|
205 |
else:
|
206 |
connector.data.over_design_cv = None
|
207 |
|
208 |
QDialog.accept(self)
|
209 |
else:
|
210 |
QMessageBox.warning(self, self.tr('Notice'), self.tr('Please Input [Tag No.]')) |
211 |
|
212 |
def reject(self): |
213 |
QDialog.reject(self)
|