프로젝트

일반

사용자정보

통계
| 개정판:

hytos / HYTOS / HYTOS / Kompressor.py @ 08955797

이력 | 보기 | 이력해설 | 다운로드 (3.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 Kompressor_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 QKompressor(QDialog):
53
    def __init__(self):
54
        QDialog.__init__(self)
55

    
56
        self.ui = Kompressor_UI.Ui_KompressorDialog()
57
        self.ui.setupUi(self)
58
        self._item = None
59

    
60
        self.ui.lineEdit_Diff_Pressure.setValidator(QtGui.QDoubleValidator(self.ui.lineEdit_Diff_Pressure))
61
        self.ui.lineEdit_Elevation.setValidator(QtGui.QDoubleValidator(self.ui.lineEdit_Elevation))
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.load_data()
69

    
70
        return self.exec_()
71

    
72
    def load_data(self):
73
        """ load tag no and nozzle data """
74
        tag_no = self._item.tag_no
75
        if tag_no != 'None' and is_not_blank(tag_no):
76
            self.ui.lineEdit_TagNo.setText(tag_no)
77

    
78
        app_doc_data = AppDocData.instance()
79
        drawing = app_doc_data.activeDrawing
80
        if drawing:
81
            for attr in drawing.attrs:
82
                if attr[0] == 'Units':
83
                    self.ui.label_PressureUnit.setText(attr[1]['Pressure'])
84
                    self.ui.label_ElevationUnit.setText(attr[1]['Length'])
85

    
86
        for connector in self._item.connectors:
87
            index = connector._conn_index
88
            if connector.data:
89
                pressure_drop = connector.data.pressure_drop
90
                if pressure_drop is not None:
91
                    self.ui.lineEdit_Diff_Pressure.setText(str(convert_to_fixed_point(pressure_drop)))
92

    
93
                elevation = connector.data.elevation
94
                if elevation is not None:
95
                    self.ui.lineEdit_Elevation.setText(str(convert_to_fixed_point(elevation)))
96

    
97
    def accept(self):
98
        """ set tag no and nozzle data """
99
        from EngineeringConnectorItem import NozzleData
100
        tag_no = self.ui.lineEdit_TagNo.text()
101

    
102
        if is_not_blank(tag_no):
103
            self._item.tag_no = tag_no
104
            for connector in self._item.connectors:
105
                index = connector._conn_index
106
                if not connector.data:
107
                    connector.data = NozzleData()
108

    
109
                pressure_drop = self.ui.lineEdit_Diff_Pressure.text()
110
                if pressure_drop:
111
                    connector.data.pressure_drop = float(pressure_drop)
112
                else:
113
                    connector.data.pressure_drop = None
114

    
115
                elevation = self.ui.lineEdit_Elevation.text()
116
                if elevation:
117
                    connector.data.elevation = float(elevation)
118
                else:
119
                    connector.data.elevation = 0
120

    
121
            QDialog.accept(self)
122
        else:
123
            QMessageBox.information(self, self.tr('Information'), self.tr('Please Input [Tag No.]'))
124

    
125
    def reject(self):
126
        QDialog.reject(self)
클립보드 이미지 추가 (최대 크기: 500 MB)