프로젝트

일반

사용자정보

개정판 4d27dd9c

ID4d27dd9c8c7f06e93bbe9083e2585782f98c4d10
상위 e9adcbe7
하위 ad1cd883

백흠경이(가) 5년 이상 전에 추가함

issue #1202: calculate press drop(40%)

Change-Id: I62fd5842606709d055672c5239f2cc8b1e6ba6d8

차이점 보기:

HYTOS/HYTOS/AppDocData.py
1055 1055

  
1056 1056
        return category
1057 1057

  
1058
    
1059

  
1060 1058
    '''
1061 1059
        @brief  getter of activeDrawing
1062 1060
        @author humkyung
HYTOS/HYTOS/HMBTable.py
582 582

  
583 583
        self._hmbs = None
584 584

  
585
    def get_hmb_data(self, stream_no):
585
    def get_hmb_data(self, component_uid):
586 586
        """ get hmb data has given stream no """
587 587

  
588
        matches = [data for data in self._hmbs if data.stream_no == stream_no]
588
        matches = [data for data in self._hmbs if data._components_uid == component_uid]
589 589
        return matches[0] if matches else None
HYTOS/HYTOS/MainWindow.py
294 294
        count = len(columnInfos)
295 295
        self.tableWidgetHMB.setRowCount(count)
296 296
        self.tableWidgetHMB.setColumnCount(2)
297
        self.tableWidgetHMB.hideRow(0)
298
        self.tableWidgetHMB.hideRow(1)        
297
        self.tableWidgetHMB.hideRow(0) # uid
298
        self.tableWidgetHMB.hideRow(1) # components_uid 
299
        self.tableWidgetHMB.hideRow(2) # stream no
299 300
        self.tableWidgetHMB.setEditTriggers(QAbstractItemView.NoEditTriggers)
300
        self.tableWidgetHMB.horizontalHeader().setVisible(False)
301 301
        self.tableWidgetHMB.verticalHeader().setVisible(False)
302 302

  
303 303
        rowIndex = 0
......
550 550
                        self.tableWidgetHMB.selectRow(index)
551 551
                        break
552 552
        
553

  
554
        
555 553
    '''
556 554
        @brief      Initialize scene and itemTreeWidget
557 555
        @author     Jeongwoo
......
695 693
                    item.setTextAlignment(Qt.AlignHCenter | Qt.AlignVCenter)
696 694
                    self.tableWidgetLoop.setItem(row, col*4, item)
697 695

  
696
                # display calcuation values
698 697
                for row in range(len(loops[col].items)):
699
                    if loops[col].items[row] in loops[col].press_drops:
700
                        item = QTableWidgetItem(str(loops[col].press_drops[loops[col].items[row]]))
698
                    if loops[col].items[row] in loops[col].pressures:
699
                        item = QTableWidgetItem(str(loops[col].pressures[loops[col].items[row]]))
700
                        if not loops[col].pressures[loops[col].items[row]]: item.setBackground(Qt.red)
701 701
                        self.tableWidgetLoop.setItem(row, col*4 + 1, item)
702 702

  
703
                    if loops[col].items[row] in loops[col].pressure_drops:
704
                        item = QTableWidgetItem(str(loops[col].pressure_drops[loops[col].items[row]]))
705
                        if not loops[col].pressure_drops[loops[col].items[row]]: item.setBackground(Qt.red)
706
                        self.tableWidgetLoop.setItem(row, col*4 + 2, item)
707

  
708
                    if loops[col].items[row] in loops[col].density_elevations:
709
                        item = QTableWidgetItem(str(loops[col].density_elevations[loops[col].items[row]]))
710
                        if not loops[col].density_elevations[loops[col].items[row]]: item.setBackground(Qt.red)
711
                        self.tableWidgetLoop.setItem(row, col*4 + 3, item)
712

  
703 713
    '''
704 714
        @brief  configuration
705 715
    '''
......
1019 1029
        try:
1020 1030
            count = len(self.actionLine.tag.streamline._vertices)
1021 1031
            if count > 1:                            
1022
                self.add_HMB()
1032
                self.add_hmb_data(self.actionLine.tag.streamline)
1033
                self.actionLine.tag.streamline.transfer.onRemoved.connect(self.on_stream_line_deleted)
1023 1034
                self.load_HMB()
1024

  
1025 1035
        finally:
1026 1036
            self.actionLine.tag.reset()
1027 1037

  
1028
    def add_HMB(self):
1038
    def on_stream_line_deleted(self, stream_line):
1039
        """ callback after stream line is deleted """
1040
        app_doc_data = AppDocData.instance()
1041
        activeDrawing = app_doc_data.activeDrawing
1042
        if activeDrawing:
1043
            activeDrawing.hmbTable.deleteByUID(stream_line.uid)
1044

  
1045
        self.load_HMB()
1046

  
1047
    def add_hmb_data(self, stream_line):
1048
        """ add a new hmb data associated with given stream line """
1029 1049
        from HMBTable import HMBTable
1030 1050
        import uuid
1031 1051

  
1032
        drawing = AppDocData.instance().activeDrawing
1033
        if drawing:
1034
            components_uid = self.actionLine.tag.streamline.uid
1035
            stream_no = self.getNextStreamNo(drawing)
1036

  
1037
            drawing.hmbTable.add(components_uid, stream_no)
1052
        try:
1053
            drawing = AppDocData.instance().activeDrawing
1054
            if drawing:
1055
                components_uid = stream_line.uid
1056
                stream_no = self.getNextStreamNo(drawing)
1057
                stream_line.stream_no = stream_no
1058
                drawing.hmbTable.add(components_uid, stream_no)
1059
        except Exception as ex:
1060
            message = 'error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno)
1061
            self.addMessage.emit(MessageType.Error, message)
1038 1062

  
1039 1063
    def getNextStreamNo(self, drawing):
1040 1064

  
......
1057 1081
        if hmbs is not None:            
1058 1082
            self.tableWidgetHMB.setColumnCount(2)
1059 1083

  
1060
            for hmb in hmbs:                  
1061
                columnCount = self.tableWidgetHMB.columnCount()                      
1084
            col_names = ['Stream No.', '']
1085
            for hmb in hmbs:
1086
                columnCount = self.tableWidgetHMB.columnCount() 
1062 1087
                self.tableWidgetHMB.setColumnCount(columnCount + 1)
1088
                col_names.append(str(hmb.stream_no))
1063 1089

  
1064 1090
                self.tableWidgetHMB.setItem(0, columnCount, self.setTableWidgetItemProperties(hmb.uid, Qt.AlignHCenter | Qt.AlignVCenter))
1065 1091
                self.tableWidgetHMB.setItem(1, columnCount, self.setTableWidgetItemProperties(hmb.components_uid, Qt.AlignHCenter | Qt.AlignVCenter))
......
1090 1116
                self.tableWidgetHMB.setItem(26, columnCount, self.setTableWidgetItemProperties(hmb.pressure_pipe_end_point, Qt.AlignHCenter | Qt.AlignVCenter))
1091 1117
                self.tableWidgetHMB.setItem(27, columnCount, self.setTableWidgetItemProperties(hmb.power, Qt.AlignHCenter | Qt.AlignVCenter))
1092 1118

  
1119
                if hmb.isDeleted: self.tableWidgetHMB.hideColumn(columnCount)
1120

  
1121
            self.tableWidgetHMB.setHorizontalHeaderLabels(col_names)
1122

  
1093 1123
            self.tableWidgetHMB.resizeColumnsToContents()
1094 1124
            self.tableWidgetHMB.resizeRowsToContents()
1125

  
1095 1126
    '''
1096 1127
        @brief      refresh scene
1097 1128
        @author     humkyung
......
1213 1244
                    category = componentInfos[0][3] # Category@SymbolType
1214 1245

  
1215 1246
                    if category == 'Stream Line':
1216
                        item = QEngineeringStreamlineItem.fromDatabase(componentInfos)     
1247
                        item = QEngineeringStreamlineItem.fromDatabase(componentInfos) 
1217 1248
                        if item is not None:
1218 1249
                            item.transfer.onRemoved.connect(self.itemRemoved)
1219 1250
                            self.graphicsView.scene.addItem(item)                   
HYTOS/HYTOS/MainWindow_UI.py
113 113
        self.tableWidgetLoop.setObjectName("tableWidgetLoop")
114 114
        self.tableWidgetLoop.setColumnCount(0)
115 115
        self.tableWidgetLoop.setRowCount(0)
116
        self.tableWidgetLoop.horizontalHeader().setVisible(False)
117
        self.tableWidgetLoop.verticalHeader().setVisible(False)
118 116
        self.gridLayout_6.addWidget(self.tableWidgetLoop, 0, 0, 1, 1)
119 117
        self.tabWidget.addTab(self.tabLoop, "")
120 118
        self.tabLogs = QtWidgets.QWidget()
HYTOS/HYTOS/QtImageViewer.py
300 300
            message = 'error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno)
301 301
            App.mainWnd().addMessage.emit(MessageType.Error, message)
302 302

  
303
        if self.guidesEnabled:
304
            self.coords = self.mapToScene(event.pos())
305
            self.scene.invalidate()
306

  
307 303
        QGraphicsView.mouseMoveEvent(self, event)
308 304

  
309 305
    '''
HYTOS/HYTOS/Shapes/EngineeringLoopItem.py
28 28
        self._UID = None
29 29
        self._name = None
30 30
        self.items = _items
31
        self.press_drops = {}
31

  
32
        self.pressures = {}
33
        self.pressure_drops = {}
34
        self.density_elevations = {}
35
        self.extras = {}
32 36
 
33 37
    def __repr__(self):
34 38
        """ return string represent loop item """
......
44 48

  
45 49
    def calculate(self):
46 50
        """ calculate Pressure Drop (Static), Pressure @ Pipe end point of stream line """
51
        from AppDocData import AppDocData
47 52

  
48 53
        try:
49
            for i in range(len(self.items) - 2, 0, -3):
50
                density2 = self.items[i].density
51
                el1 = self.items[i - 1].elevation
52
                el2 = self.items[i + 1].elevation
54
            #(1) 기기들의 del.p, p, el을 넣음
55
            self.p_eq_input()
56

  
57
            #(3) 계산 시작
58
            self.discharge_cal()
59
            if not self.items[1] in self.pressures or not self.pressures[self.items[1]]: self.suction_cal()
60
        except Exception as ex:
61
            from App import App 
62
            message = 'error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno)
63
            App.mainWnd().addMessage.emit(MessageType.Error, message)
64

  
65
    def discharge_cal(self):
66
        try:
67
            for i in range(len(self.items) - 2, 0, -3): # backward
68
                self.discharge_den(i)           #(1) density 입력
69
                self.discharge_static_cal(i)    #(2) static P를 계산
70

  
71
                #(3) pressure drop 계산
72
                #liquid 인 경우 stream 시트로부터 del.P를 입력해줌.
73
                #vapor인 경우 압력강하를 계산해주고 넣어주는 모듈
74
                if self.items[i].data.phase_type == 'Liquid' or self.items[i].data.phase_type == 'Mixed':
75
                    self.pressure_drops[self.items[i]] = self.items[i].press_drop
76
                    asd = self.discharge_p_cal(i)
77
                    if asd == 0: break
78
                elif self.items[i].phase_type == 'Vapor':
79
                    pass #TODO: 
80
        except Exception as ex:
81
            from App import App 
82
            message = 'error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno)
83
            App.mainWnd().addMessage.emit(MessageType.Error, message)
84

  
85
    def suction_cal(self):
86
        try:
87
            for i in range(1, len(self.items) - 1, 3):
88
                self.suction_find_line(i)
89
                self.suction_static_cal(i) #static P를 계산해줌
90

  
91
                #라인이 liqiud 인지 vapor인지 판별
92
                if self.items[i].data.phase_type == 'Liquid' or self.items[i].data.phase_type == 'Mixed':
93
                    #liquid 인 경우 stream 데이타로부터 del.P를 입력해줌.
94
                    self.pressure_drops[self.items[i]] = self.items[i].data.pressure_drop_friction
95
                    res = self.suction_p_cal(i)
96
                    if res == 0: break
97
                elif self.items[i].data.phase_type == 'Vapor':
98
                    pass #TODO:
99
        except Exception as ex:
100
            from App import App 
101
            message = 'error occured({}) in {}:{}'.format(repr(ex), sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno)
102
            App.mainWnd().addMessage.emit(MessageType.Error, message)
103

  
104
    def suction_find_line(self, i):
105
        if self.items[i].data.phase_type == 'Liquid' or self.items[i].data.phase_type == 'Mixed':
106
            self.density_elevations[self.items[i]] = self.items[i].data.density
107
        elif self.items[i].data.phase_type == 'Vapor':
108
            self.suction_vapor_density(i)
109
        else:
110
            raise ValueError('You have to input the properties of stream <{}>\nCalculation will be terminated !'.format(self.items[i].data.stream_no))
111

  
112
    def suction_vapor_density(self, i):
113
        pass
114

  
115
    def suction_static_cal(self, i):
116
        try:
117
            if self.items[i].data.phase_type == 'Mixed':
118
                pass    #TODO:
119
            else:
120
                app_doc_data = AppDocData.instance()
121
                units = [attr[1] for attr in app_doc_data.activeDrawing.attrs if attr[0] == 'Units'][0]
122
                if units['Density'] == 'kg/m3':
123
                    density2 = self.density_elevations[self.items[i]]
124
                else:
125
                    density2 = self.density_elevations[self.items[i]] * 16.0185 #lb/ft3
126

  
127
                #2 elevation 받음
128
                if units['Length'] == 'm':
129
                    el1 = self.density_elevations[self.items[i-1]]
130
                    el2 = self.density_elevations[self.items[i+1]]
131
                elif units['Length'] == 'in':
132
                    el1 = self.density_elevations[self.items[i-1]] * 0.0254
133
                    el2 = self.density_elevations[self.items[i+1]] * 0.0254
134
                elif units['Length'] == 'ft':
135
                    el1 = self.density_elevations[self.items[i-1]] * 0.3048 
136
                    el2 = self.density_elevations[self.items[i+1]] * 0.3048
137
                elif units['Length'] == 'yd':
138
                    el1 = self.density_elevations[self.items[i-1]] * 0.9144
139
                    el2 = self.density_elevations[self.items[i+1]] * 0.9144
140
                elif units['Length'] == 'mm':
141
                    el1 = self.density_elevations[self.items[i-1]] * 0.001
142
                    el2 = self.density_elevations[self.items[i+1]] * 0.001
143
                else:    #mile
144
                    el1 = self.density_elevations[self.items[i-1]] * 1609.34
145
                    el2 = self.density_elevations[self.items[i+1]] * 1609.34
146

  
147
                #3. static head 계산
53 148
                stat_dp = (el2 - el1) * density2 / 1000 * 9.80665 / 101.325 #atm으로 계산된 dp
54
                self.press_drops[self.items[i - 1]] = stat_dp * 1.033
55 149

  
56
                self.press_drops[self.items[i]] = self.items[i].press_drop
150
                #4. 압력 유닛에 맞춰 뿌리기
151
                if units['Pressure'] == 'kg/cm2':
152
                    self.pressure_drops[self.items[i - 1]] = stat_dp * 1.033
153
                elif units['Pressure'] == 'psi':
154
                    self.pressure_drops[self.items[i - 1]] = stat_dp * 14.7
155
                elif units['Pressure'] == 'atm':
156
                    self.pressure_drops[self.items[i - 1]] = stat_dp
157
                elif units['Pressure'] == 'bar':
158
                    self.pressure_drops[self.items[i - 1]] = stat_dp * 1.013
159
                elif units['Pressure'] == 'mmHg':
160
                    self.pressure_drops[self.items[i - 1]] = stat_dp * 760
161
                elif units['Pressure'] == 'kPa':
162
                    self.pressure_drops[self.items[i - 1]] = stat_dp * 101.325
163
                elif units['Pressure'] == 'MPa':
164
                    self.pressure_drops[self.items[i - 1]] = stat_dp * 0.101325
165
        except Exception as ex:
166
            from App import App 
167
            message = 'error occured({}) in {}:{}'.format(repr(ex), sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno)
168
            App.mainWnd().addMessage.emit(MessageType.Error, message)
169

  
170
    def p_eq_input(self):
171
        try:
172
            # 시작, 끝 기기의 pressure와 elevation을 구한다
173
            self.pressures[self.items[0]] = self.items[0].data.pressure
174
            self.density_elevations[self.items[0]] = self.items[0].data.elevation
175
            self.pressures[self.items[-1]] = self.items[-1].data.pressure
176
            self.density_elevations[self.items[-1]] = self.items[-1].data.elevation
177

  
178
            for i in range(2, len(self.items) - 2, 3):
179
                dp_eq = str(self.items[i])[:3]
180
                if dp_eq == 'HEX' or dp_eq == 'M_D' or dp_eq == 'M_R': dp_eq = str(self.items[i])[:3]
181

  
182
                #pressure drop
183
                self.pressure_drops[self.items[i]] = self.items[i].data.pressure_drop
184
                if not self.items[i].data.pressure_drop:
185
                    pass
186

  
187
                #elevation
188
                if dp_eq[:3] == 'M_R':
189
                    self.density_elevations[self.items[i]] = self.items[i].data.elevation
190
                    self.density_elevations[self.items[i+1]] = self.items[i+1].data.elevation
191
                else:
192
                    self.density_elevations[self.items[i]] = self.items[i].data.elevation
193
                    self.density_elevations[self.items[i+1]] = self.items[i+1].data.elevation
194

  
195
                if dp_eq[:3] == 'L_P' or dp_eq[:3] == 'R_P' or dp_eq[:3] == 'V_P' or dp_eq[:3] == 'R_K':
196
                    self.extras[self.items[i]] = self.items[i].data.over_design_cv
197
                elif dp_eq[:3] == 'CV_':
198
                    self.extras[self.items[i]] = self.items[i].data.over_design_cv
199
                    self.extras[self.items[i+1]] = None #TODO:
200
        except Exception as ex:
201
            from App import App 
202
            message = 'error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno)
203
            App.mainWnd().addMessage.emit(MessageType.Error, message)
204

  
205
    def discharge_den(self, i):
206
        try:
207
            app_doc_data = AppDocData.instance()
208
            units = [attr[1] for attr in app_doc_data.activeDrawing.attrs if attr[0] == 'Units'][0]
209

  
210
            #1. density 받음
211
            if self.items[i].data.phase_type == 'Liquid' or self.items[i].data.phase_type == 'Mixed':
212
                self.density_elevations[self.items[i]] = self.items[i].density
213
            elif self.items[i].data.phase_type == 'Vapor':
214
                self.discharge_vapor_density(i)
57 215
        except Exception as ex:
58
            from App import App
59
            from AppDocData import MessageType
60
            
216
            from App import App 
61 217
            message = 'error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno)
62 218
            App.mainWnd().addMessage.emit(MessageType.Error, message)
63 219

  
220
    def discharge_vapor_density(self, i):
221
        pass
222

  
223
    def discharge_static_cal(self, i):
224
        """ (2) static P를 계산 """
225

  
226
        try:
227
            app_doc_data = AppDocData.instance()
228
            units = [attr[1] for attr in app_doc_data.activeDrawing.attrs if attr[0] == 'Units'][0]
229

  
230
            #1. density 받음
231
            if self.items[i].data.phase_type == 'Mixed':
232
                pass    #TODO: 
233
            else:
234
                if units['Density'] == 'kg/m3':
235
                    density2 = self.density_elevations[self.items[i]]
236
                else:
237
                    density2 = self.density_elevations[self.items[i]] * 16.0185 #lb/ft3
238

  
239
            #2 elevation 받음
240
            if units['Length'] == 'm':
241
                el1 = self.density_elevations[self.items[i-1]]
242
                el2 = self.density_elevations[self.items[i+1]]
243
            elif units['Length'] == 'in':
244
                el1 = self.density_elevations[self.items[i-1]] * 0.0254
245
                el2 = self.density_elevations[self.items[i+1]] * 0.0254
246
            elif units['Length'] == 'ft':
247
                el1 = self.density_elevations[self.items[i-1]] * 0.3048 
248
                el2 = self.density_elevations[self.items[i+1]] * 0.3048
249
            elif units['Length'] == 'yd':
250
                el1 = self.density_elevations[self.items[i-1]] * 0.9144
251
                el2 = self.density_elevations[self.items[i+1]] * 0.9144
252
            elif units['Length'] == 'mm':
253
                el1 = self.density_elevations[self.items[i-1]] * 0.001
254
                el2 = self.density_elevations[self.items[i+1]] * 0.001
255
            else:    #mile
256
                el1 = self.density_elevations[self.items[i-1]] * 1609.34
257
                el2 = self.density_elevations[self.items[i+1]] * 1609.34
258

  
259
            #3. static head 계산
260
            stat_dp = (el2 - el1) * density2 / 1000 * 9.80665 / 101.325 #atm으로 계산된 dp
261

  
262
            #4. 압력 유닛에 맞춰 뿌리기
263
            if units['Pressure'] == 'kg/cm2':
264
                self.pressure_drops[self.items[i - 1]] = stat_dp * 1.033
265
            elif units['Pressure'] == 'psi':
266
                self.pressure_drops[self.items[i - 1]] = stat_dp * 14.7
267
            elif units['Pressure'] == 'atm':
268
                self.pressure_drops[self.items[i - 1]] = stat_dp
269
            elif units['Pressure'] == 'bar':
270
                self.pressure_drops[self.items[i - 1]] = stat_dp * 1.013
271
            elif units['Pressure'] == 'mmHg':
272
                self.pressure_drops[self.items[i - 1]] = stat_dp * 760
273
            elif units['Pressure'] == 'kPa':
274
                self.pressure_drops[self.items[i - 1]] = stat_dp * 101.325
275
            elif units['Pressure'] == 'MPa':
276
                self.pressure_drops[self.items[i - 1]] = stat_dp * 0.101325
277
        except Exception as ex:
278
            from App import App 
279
            message = 'error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno)
280
            App.mainWnd().addMessage.emit(MessageType.Error, message)
281

  
282
    def suction_p_cal(self, i):
283
        res = 1
284

  
285
        try:
286
            app_doc_data = AppDocData.instance()
287
            units = [attr[1] for attr in app_doc_data.activeDrawing.attrs if attr[0] == 'Units'][0]
288

  
289
            self.pressures[self.items[i]] = self.pressures[self.items[i - 1]] - self.pressure_drops[self.items[i - 1]]
290

  
291
            pressure_unit = units['Pressure']
292
            if pressure_unit == 'kg/cm2':
293
                pabsolute = self.pressures[self.items[i]] + 1.033
294
            elif pressure_unit == 'psi':
295
                pabsolute = self.pressures[self.items[i]] + 14.7
296
            elif pressure_unit == 'atm':
297
                pabsolute = self.pressures[self.items[i]] + 1
298
            elif pressure_unit == 'bar':
299
                pabsolute = self.pressures[self.items[i]] + 1.013
300
            elif pressure_unit == 'mmHg':
301
                pabsolute = self.pressures[self.items[i]] + 760
302
            elif pressure_unit == 'kPa':
303
                pabsolute = self.pressures[self.items[i]] + 101.325
304
            elif pressure_unit == 'MPa':
305
                pabsolute = self.pressures[self.items[i]] + 0.101325
306

  
307
            if pabsolute < 0:
308
                raise ValueError('The absolute pressure of {} is below 0.'.format(self.items[i]))
309

  
310
            if i < len(self.items) - 2:
311
                self.pressures[self.items[i + 1]] = self.pressures[self.items[i]] - self.pressure_drops[self.items[i]]
312
                if self.pressures[self.items[i + 1]] < 0:
313
                    if pressure_unit == 'kg/cm2':
314
                        pabsolute = self.pressures[self.items[i + 1]] + 1.033
315
                    elif pressure_unit == 'psi':
316
                        pabsolute = self.pressures[self.items[i + 1]] + 14.7
317
                    elif pressure_unit == 'atm':
318
                        pabsolute = self.pressures[self.items[i + 1]] + 1
319
                    elif pressure_unit == 'bar':
320
                        pabsolute = self.pressures[self.items[i + 1]] + 1.013
321
                    elif pressure_unit == 'mmHg':
322
                        pabsolute = self.pressures[self.items[i + 1]] + 760
323
                    elif pressure_unit == 'kPa':
324
                        pabsolute = self.pressures[self.items[i + 1]] + 101.325
325
                    elif pressure_unit == 'MPa':
326
                        pabsolute = self.pressures[self.items[i + 1]] + 0.101325
327

  
328
                    if pabsolute < 0:
329
                        raise ValueError('The absolute pressure of {} is below 0.'.format(self.items[i + 1]))
330

  
331
                name = str(self.items[i + 1])[:3]
332
                if not self.pressure_drops[self.items[i + 1]]:
333
                    res = 0
334
                elif name == 'L_P' or name == 'R_P' or name == 'V_P' or name == 'R_K' or name == 'L_K':
335
                    self.pressures[self.items[i + 2]] = self.pressures[self.items[i + 1]] + self.pressure_drops[self.items[i + 1]]
336
                else:
337
                    self.pressures[self.items[i + 2]] = self.pressures[self.items[i + 1]] - self.pressure_drops[self.items[i + 1]]
338
        except Exception as ex:
339
            from App import App 
340
            message = 'error occured({}) in {}:{}'.format(repr(ex), sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno)
341
            App.mainWnd().addMessage.emit(MessageType.Error, message)
342

  
343
        return res
344

  
345
    def discharge_p_cal(self, i):
346
        res = 1
347

  
348
        try:
349
            self.pressures[self.items[i]] = self.pressures[self.items[i + 1]] + self.pressure_drops[self.items[i]]
350
            index = str(self.items[i - 2])[:3]
351
            if i > 0:
352
                self.pressures[self.items[i - 1]] = self.pressures[self.items[i]] + self.pressure_drops[self.items[i - 1]]
353

  
354
                if self.pressure_drops[self.items[i - 2]]:
355
                    if index == 'L_P' or index == 'R_P' or index == 'V_P' or index == 'R_K' or index == 'L_K':
356
                        self.pressures[self.items[i - 2]] = self.pressures[self.items[i - 1]] + self.pressure_drops[self.items[i - 2]]
357
                    else:
358
                        self.pressures[self.items[i - 2]] = self.pressures[self.items[i - 1]] + self.pressure_drops[self.items[i - 2]]
359
                else:
360
                    #여기에 그 루프는 그만 하는 로직을 넣어줘야함
361
                    res = 0
362
        except Exception as ex:
363
            from App import App 
364
            message = 'error occured({}) in {}:{}'.format(repr(ex), sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno)
365
            App.mainWnd().addMessage.emit(MessageType.Error, message)
366

  
367
        return res
368

  
64 369
class Transfer(QObject):
65 370
    onRemoved = pyqtSignal(QGraphicsItem)
66 371

  
67 372
    def __init__(self, parent = None):
68
        QObject.__init__(self, parent)
373
        QObject.__init__(self, parent)
HYTOS/HYTOS/Shapes/EngineeringStreamlineItem.py
49 49
            self.setPen(QPen(Qt.blue, 1, Qt.SolidLine)) # set default pen
50 50
            
51 51
            self._stream_no = 0
52

  
53
            self._stream_no_text = QEngineeringStreamNoTextItem('<{}>'.format(self._stream_no), self)
52
            self._stream_no_text = None
54 53

  
55 54
            self.transfer = Transfer()
56
            self.transfer.onRemoved.connect(self.on_item_removed)
57 55
            self.setZValue(QEngineeringStreamlineItem.ZVALUE)
58 56
        except Exception as ex:
59 57
            from App import App
......
67 65
        return 'Line_{}'.format(self._stream_no)
68 66

  
69 67
    @property
68
    def stream_no(self):
69
        """ return stream no """
70
        return self._stream_no
71

  
72
    @stream_no.setter
73
    def stream_no(self, value):
74
        """ set stream no with given value """
75
        from EngineeringStreamNoTextItem import QEngineeringStreamNoTextItem
76

  
77
        self._stream_no = value
78
        self._stream_no_text = QEngineeringStreamNoTextItem('<{}>'.format(self._stream_no), self)
79
        
80
    @property
81
    def data(self):
82
        """ return hmb data"""
83
        from AppDocData import AppDocData
84

  
85
        app_doc_data = AppDocData.instance()
86
        return app_doc_data.activeDrawing.hmbTable.get_hmb_data(self.uid)
87

  
88
    @property
70 89
    def density(self):
71 90
        """ return density """
72 91
        from AppDocData import AppDocData
73 92

  
93
        res = 0
74 94
        app_doc_data = AppDocData.instance()
75
        hmb_data = app_doc_data.activeDrawing.hmbTable.get_hmb_data(self._stream_no)
76
        
77
        return hmb_data.density if hmb_data else 1
95
        hmb_data = app_doc_data.activeDrawing.hmbTable.get_hmb_data(self.uid)
96
        if hmb_data: res = hmb_data.density
97

  
98
        return res
78 99

  
79 100
    @property
80 101
    def press_drop(self):
......
82 103
        from AppDocData import AppDocData
83 104

  
84 105
        app_doc_data = AppDocData.instance()
85
        hmb_data = app_doc_data.activeDrawing.hmbTable.get_hmb_data(self._stream_no)
106
        hmb_data = app_doc_data.activeDrawing.hmbTable.get_hmb_data(self.uid)
86 107

  
87
        return hmb_data.press_drop if hmb_data else 0
108
        return hmb_data.pressure_drop if hmb_data else 0
88 109

  
89 110
    def build_connectors(self, connected, pointsUids=None):
90 111
        """ build connectors for stream line
......
218 239
        self.setPath(path)
219 240
        self.isCreated = True
220 241

  
221
        if max_length_line[0] is not None and max_length_line[1] is not None:
222
            x = (max_length_line[0][0] + max_length_line[1][0] - self._stream_no_text.textWidth())*0.5
223
            y = (max_length_line[0][1] + max_length_line[1][1])*0.5
224
            self._stream_no_text.setPos(QPointF(x, y))
225
            dx = max_length_line[0][0] - max_length_line[1][0]
226
            dy = max_length_line[0][1] - max_length_line[1][1]
227
            self._stream_no_text.setRotation(90) if abs(dy) > abs(dx) else self._stream_no_text.setRotation(0)
242
        if self._stream_no_text:
243
            if max_length_line[0] is not None and max_length_line[1] is not None:
244
                x = (max_length_line[0][0] + max_length_line[1][0] - self._stream_no_text.textWidth())*0.5
245
                y = (max_length_line[0][1] + max_length_line[1][1])*0.5
246
                self._stream_no_text.setPos(QPointF(x, y))
247
                dx = max_length_line[0][0] - max_length_line[1][0]
248
                dy = max_length_line[0][1] - max_length_line[1][1]
249
                self._stream_no_text.setRotation(90) if abs(dy) > abs(dx) else self._stream_no_text.setRotation(0)
228 250

  
229 251
    '''
230 252
        @brief      return bouding rectangle of polyline
......
399 421
        from AppDocData import AppDocData
400 422
        if not self.isSelected(): return
401 423

  
402
        if event.key() == Qt.Key_Delete:            
403
            self.deleteStreamlineItemFromScene()
404

  
405
            appDocData = AppDocData.instance()
406
            activeDrawing = appDocData.activeDrawing
407
            if activeDrawing:
408
                activeDrawing.hmbTable.deleteByUID(self.uid)
409

  
410
            App.mainWnd().load_HMB()
424
        if event.key() == Qt.Key_Delete: 
425
            self.transfer.onRemoved.emit(self)
426
            self.on_item_removed(self)
411 427
        elif event.key() == Qt.Key_QuoteLeft:
412 428
            self.mouseDoubleClickEvent(event)    
413 429
           
414
    def deleteStreamlineItemFromScene(self):
415
        """ remove self from scene """
416
        try:
417
            for conn in self.connectors:
418
                if conn.connectedItem is not None:
419
                    conn.connectedItem.connect(None)
420
        except Exception as ex:
421
            from App import App
422
            from AppDocData import MessageType
423

  
424
            message = 'error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno)
425
            App.mainWnd().addMessage.emit(MessageType.Error, message)
426

  
427
        self.transfer.onRemoved.emit(self)
428

  
429

  
430

  
431 430
    def toSql(self):
432 431
        """ convert valve data to sql query """
433 432
        import uuid
......
440 439
        dbUid = symbolInfo.uid
441 440
        uid = self.uid
442 441

  
443
        cols = ['UID', 'Symbols_UID']
444
        values = ['?','?']
445
        param = [str(uid), str(dbUid)]
442
        cols = ['UID', 'Symbols_UID', 'Name']
443
        values = ['?','?', '?']
444
        param = [str(uid), str(dbUid), str(self.stream_no)]
446 445
        sql = 'insert or replace into Components({}) values({})'.format(','.join(cols), ','.join(values))
447 446
        res.append((sql, tuple(param)))
448 447

  
......
475 474
    @staticmethod 
476 475
    def fromDatabase(componentInfos):
477 476
        from EngineeringConnectorItem import QEngineeringConnectorItem
477
        from AppDocData import AppDocData
478 478

  
479 479
        item = None
480 480
        try:
481
            app_doc_data = AppDocData.instance()
482

  
481 483
            uid = componentInfos[0][0]              #uid@Components
482 484

  
483 485
            item = QEngineeringStreamlineItem(uid)
486
            hmb_data = app_doc_data.activeDrawing.hmbTable.get_hmb_data(uid)
487
            item.stream_no = int(hmb_data.stream_no) if hmb_data else 1 # stream no
484 488

  
485 489
            pointsUids = []
486 490
            for componentInfo in componentInfos:     

내보내기 Unified diff

클립보드 이미지 추가 (최대 크기: 500 MB)