프로젝트

일반

사용자정보

통계
| 브랜치(Branch): | 개정판:

hytos / HYTOS / HYTOS / FittingsDialog.py @ 4cf3a6c8

이력 | 보기 | 이력해설 | 다운로드 (134 KB)

1
# -*- coding: utf-8 -*-
2
"""This is FittingsDialog module"""
3

    
4
import os
5
import sys
6
# from PyQt5 import QtCore, QtGui, QtWidgets
7
# from PyQt5.QtWidgets import *
8

    
9
from PyQt5.QtCore import *
10
from PyQt5 import QtCore, QtGui, QtWidgets
11
from PyQt5.QtCore import pyqtSlot, QRectF
12
from PyQt5.QtWidgets import *
13
from PyQt5.QtGui import *
14
from QtImageViewer import QtImageViewer
15

    
16
from AppDocData import AppDocData
17
import Fittings_UI
18
import math
19

    
20

    
21
def set_item_properties(name, alignment, color=None):
22
    item = QTableWidgetItem(str(name))
23
    item.setTextAlignment(alignment)
24
    if color:
25
        item.setBackground(color)
26

    
27
    return item
28

    
29

    
30
class ManualKValueDelegate(QStyledItemDelegate):
31
    def createEditor(self, parent, option, index):
32
        editor = None
33
        if index.column() == 9 and parent.parent().item(index.row(), 2).text() == 'Manual':
34
            editor = QLineEdit(parent)
35
            validator = QtGui.QDoubleValidator(parent)
36
            editor.setValidator(validator)
37

    
38
        return editor
39

    
40
    def destroyEditor(self, editor, index):
41
        """apply modified manual K value"""
42
        editor.blockSignals(True)
43
        value = float(editor.text())
44
        name = editor.parent().parent().item(index.row(), 4).text()
45
        count = int(editor.parent().parent().item(index.row(), 5).text())
46
        selected_fitting = f"{name} x {value} = {int(count) * value}"
47
        editor.parent().parent().item(index.row(), 11).setText(selected_fitting)
48
        editor.blockSignals(False)
49

    
50

    
51
class QFittingsDialog(QDialog):
52
    def __init__(self, item):
53
        QDialog.__init__(self)
54

    
55
        self.ui = Fittings_UI.Ui_Dialog()
56
        self.ui.setupUi(self)
57
        self.ui.buttonBox.button(QDialogButtonBox.Ok).setIcon(QIcon(':/images/OK.svg'))
58
        self.ui.buttonBox.button(QDialogButtonBox.Cancel).setIcon(QIcon(':/images/Cancel.svg'))
59

    
60
        self.item = item
61
        self.current_tab_index = None
62
        self.isAccepted = False
63
        self.pipe_diameter_unit = None
64
        self.fittings_length = 0
65
        self.total_k = 0
66
        self.nps = 0
67
        self.selected_dia_in = 0
68
        self.friction_factor = 1
69

    
70
        self.init_units()
71
        self.initialize_equivalent_length()
72
        self.initialize_crane_k()
73
        self.initialize_2_k()
74

    
75
    def init_units(self):
76
        active_drawing = AppDocData.instance().activeDrawing
77

    
78
        for attr in active_drawing.attrs:
79
            if attr[0] == 'Units':
80
                self.pipe_diameter_unit = attr[1]['Pipe_Diameter']
81

    
82
    def initialize_equivalent_length(self):
83
        try:
84
            self.initialize_equivalent_length_selected_fitting()
85

    
86
            self.ui.lineEdit_Equivalent_Length_Gate_Ball_Plug_Count.setValidator(
87
                QtGui.QIntValidator(self.ui.lineEdit_Equivalent_Length_Gate_Ball_Plug_Count))
88
            self.ui.lineEdit_Equivalent_Length_Butterfly_Count.setValidator(
89
                QtGui.QIntValidator(self.ui.lineEdit_Equivalent_Length_Butterfly_Count))
90
            self.ui.lineEdit_Equivalent_Length_90_Elbow_Count.setValidator(
91
                QtGui.QIntValidator(self.ui.lineEdit_Equivalent_Length_90_Elbow_Count))
92
            self.ui.lineEdit_Equivalent_Length_Tee_Branch_Count.setValidator(
93
                QtGui.QIntValidator(self.ui.lineEdit_Equivalent_Length_Tee_Branch_Count))
94
            self.ui.lineEdit_Equivalent_Length_Miter_Count.setValidator(
95
                QtGui.QIntValidator(self.ui.lineEdit_Equivalent_Length_Miter_Count))
96
            self.ui.lineEdit_Equivalent_Length_Globe_Count.setValidator(
97
                QtGui.QIntValidator(self.ui.lineEdit_Equivalent_Length_Globe_Count))
98
            self.ui.lineEdit_Equivalent_Length_Check_Count.setValidator(
99
                QtGui.QIntValidator(self.ui.lineEdit_Equivalent_Length_Check_Count))
100
            self.ui.lineEdit_Equivalent_Length_45_Elbow_Count.setValidator(
101
                QtGui.QIntValidator(self.ui.lineEdit_Equivalent_Length_45_Elbow_Count))
102
            self.ui.lineEdit_Equivalent_Length_Tee_Through_Count.setValidator(
103
                QtGui.QIntValidator(self.ui.lineEdit_Equivalent_Length_Tee_Through_Count))
104

    
105
            self.ui.comboBox_Equivalent_Length_Miter_Degree.clear()
106

    
107
            self.ui.comboBox_Equivalent_Length_Miter_Degree.addItem('0', 0)
108
            self.ui.comboBox_Equivalent_Length_Miter_Degree.addItem('15', 15)
109
            self.ui.comboBox_Equivalent_Length_Miter_Degree.addItem('30', 30)
110
            self.ui.comboBox_Equivalent_Length_Miter_Degree.addItem('45', 45)
111
            self.ui.comboBox_Equivalent_Length_Miter_Degree.addItem('60', 60)
112
            self.ui.comboBox_Equivalent_Length_Miter_Degree.addItem('75', 75)
113
            self.ui.comboBox_Equivalent_Length_Miter_Degree.addItem('90', 90)
114

    
115
            self.ui.comboBox_Equivalent_Length_Miter_Degree.setCurrentIndex(0)
116

    
117
            self.controls_equivalent_length_set_names()
118

    
119
            # Elbow
120
            self.ui.pushButton_Add_Equivalent_Length_90_Elbow.clicked.connect(self.add_equivalent_length)
121
            self.ui.pushButton_Add_Equivalent_Length_45_Elbow.clicked.connect(self.add_equivalent_length)
122
            self.ui.pushButton_Add_Equivalent_Length_Miter.clicked.connect(self.add_equivalent_length)
123
            # Tees
124
            self.ui.pushButton_Add_Equivalent_Length_Tee_Branch.clicked.connect(self.add_equivalent_length)
125
            self.ui.pushButton_Add_Equivalent_Length_Tee_Through.clicked.connect(self.add_equivalent_length)
126
            # Valves
127
            self.ui.pushButton_Add_Equivalent_Length_Gate_Ball_Plug.clicked.connect(self.add_equivalent_length)
128
            self.ui.pushButton_Add_Equivalent_Length_Globe.clicked.connect(self.add_equivalent_length)
129
            self.ui.pushButton_Add_Equivalent_Length_Butterfly.clicked.connect(self.add_equivalent_length)
130
            self.ui.pushButton_Add_Equivalent_Length_Check.clicked.connect(self.add_equivalent_length)
131
            # Nozzles
132
            self.ui.pushButton_Add_Equivalent_Length_Nozzle_In.clicked.connect(self.add_equivalent_length)
133
            self.ui.pushButton_Add_Equivalent_Length_Nozzle_Out.clicked.connect(self.add_equivalent_length)
134

    
135
            self.ui.tableWidget_Equivalent_Length_SelectedFitting.setContextMenuPolicy(Qt.CustomContextMenu)
136
            self.ui.tableWidget_Equivalent_Length_SelectedFitting.customContextMenuRequested.connect(
137
                self.context_menu_del_equivalent_length)
138
        except Exception as ex:
139
            from App import App
140
            from AppDocData import MessageType
141

    
142
            message = 'error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename,
143
                                                           sys.exc_info()[-1].tb_lineno)
144
            App.mainWnd().addMessage.emit(MessageType.Error, message)
145

    
146
    def initialize_crane_k(self):
147
        try:
148
            self.initialize_crane_k_selected_fitting()
149

    
150
            self.ui.label_CraneK_Main_Size_Unit.setText(self.pipe_diameter_unit)
151
            self.ui.label_CraneK_Sub_Size_Unit.setText(self.pipe_diameter_unit)
152

    
153
            self.ui.lineEdit_CraneK_180_Elbow_Standard_Count.setValidator(
154
                QtGui.QIntValidator(self.ui.lineEdit_CraneK_180_Elbow_Standard_Count))
155
            self.ui.lineEdit_CraneK_180_Elbow_Bend_Count.setValidator(
156
                QtGui.QIntValidator(self.ui.lineEdit_CraneK_180_Elbow_Bend_Count))
157
            self.ui.lineEdit_CraneK_180_Elbow_Miter_Count.setValidator(
158
                QtGui.QIntValidator(self.ui.lineEdit_CraneK_180_Elbow_Miter_Count))
159
            self.ui.lineEdit_CraneK_90_Elbow_Standard_Count.setValidator(
160
                QtGui.QIntValidator(self.ui.lineEdit_CraneK_90_Elbow_Standard_Count))
161
            self.ui.lineEdit_CraneK_90_Elbow_Bend_Count.setValidator(
162
                QtGui.QIntValidator(self.ui.lineEdit_CraneK_90_Elbow_Bend_Count))
163
            self.ui.lineEdit_CraneK_90_Elbow_Miter_Count.setValidator(
164
                QtGui.QIntValidator(self.ui.lineEdit_CraneK_90_Elbow_Miter_Count))
165
            self.ui.lineEdit_CraneK_Check_Valves_Swing_Count.setValidator(
166
                QtGui.QIntValidator(self.ui.lineEdit_CraneK_Check_Valves_Swing_Count))
167
            self.ui.lineEdit_CraneK_Check_Valves_Lift_Count.setValidator(
168
                QtGui.QIntValidator(self.ui.lineEdit_CraneK_Check_Valves_Lift_Count))
169
            self.ui.lineEdit_CraneK_Check_Valves_Tilting_Count.setValidator(
170
                QtGui.QIntValidator(self.ui.lineEdit_CraneK_Check_Valves_Tilting_Count))
171
            self.ui.lineEdit_CraneK_Check_Valves_Globe_Stop_Count.setValidator(
172
                QtGui.QIntValidator(self.ui.lineEdit_CraneK_Check_Valves_Globe_Stop_Count))
173
            self.ui.lineEdit_CraneK_Check_Valves_Angle_Stop_Count.setValidator(
174
                QtGui.QIntValidator(self.ui.lineEdit_CraneK_Check_Valves_Angle_Stop_Count))
175
            self.ui.lineEdit_CraneK_Pipe_Entrance_Count.setValidator(
176
                QtGui.QIntValidator(self.ui.lineEdit_CraneK_Pipe_Entrance_Count))
177
            self.ui.lineEdit_CraneK_Pipe_Exit_Count.setValidator(
178
                QtGui.QIntValidator(self.ui.lineEdit_CraneK_Pipe_Exit_Count))
179
            self.ui.lineEdit_CraneK_Tees_Count.setValidator(
180
                QtGui.QIntValidator(self.ui.lineEdit_CraneK_Tees_Count))
181
            self.ui.lineEdit_CraneK_45_Elbow_Standard_Count.setValidator(
182
                QtGui.QIntValidator(self.ui.lineEdit_CraneK_45_Elbow_Standard_Count))
183
            self.ui.lineEdit_CraneK_45_Elbow_Miter_Count.setValidator(
184
                QtGui.QIntValidator(self.ui.lineEdit_CraneK_45_Elbow_Miter_Count))
185
            self.ui.lineEdit_CraneK_Expander_Count.setValidator(
186
                QtGui.QIntValidator(self.ui.lineEdit_CraneK_Expander_Count))
187
            self.ui.lineEdit_CraneK_Reducer_Count.setValidator(
188
                QtGui.QIntValidator(self.ui.lineEdit_CraneK_Reducer_Count))
189
            self.ui.lineEdit_CraneK_Manual_Count.setValidator(
190
                QtGui.QIntValidator(self.ui.lineEdit_CraneK_Manual_Count))
191
            self.ui.lineEdit_CraneK_Valves_Globe_Count.setValidator(
192
                QtGui.QIntValidator(self.ui.lineEdit_CraneK_Valves_Globe_Count))
193
            self.ui.lineEdit_CraneK_Valves_Plug_Count.setValidator(
194
                QtGui.QIntValidator(self.ui.lineEdit_CraneK_Valves_Plug_Count))
195
            self.ui.lineEdit_CraneK_Valves_Foot_Count.setValidator(
196
                QtGui.QIntValidator(self.ui.lineEdit_CraneK_Valves_Foot_Count))
197
            self.ui.lineEdit_CraneK_Valves_Etc_Count.setValidator(
198
                QtGui.QIntValidator(self.ui.lineEdit_CraneK_Valves_Etc_Count))
199
            self.ui.lineEdit_CraneK_Sub_Size.setValidator(QtGui.QDoubleValidator(self.ui.lineEdit_CraneK_Sub_Size))
200
            self.ui.lineEdit_CraneK_Angle.setValidator(QtGui.QDoubleValidator(self.ui.lineEdit_CraneK_Angle))
201

    
202
            self.controls_crane_k_set_names()
203

    
204
            # 90 Elbow
205
            self.ui.pushButton_Add_CraneK_90_Elbow_Standard.clicked.connect(self.add_crane_k)
206
            self.ui.pushButton_View_CraneK_90_Elbow_Standard.clicked.connect(self.show_crane_k_image)
207
            self.ui.pushButton_Add_CraneK_90_Elbow_Bend.clicked.connect(self.add_crane_k)
208
            self.ui.pushButton_View_CraneK_90_Elbow_Bend.clicked.connect(self.show_crane_k_image)
209
            self.ui.pushButton_Add_CraneK_90_Elbow_Miter.clicked.connect(self.add_crane_k)
210
            self.ui.pushButton_View_CraneK_90_Elbow_Miter.clicked.connect(self.show_crane_k_image)
211
            self.ui.comboBox_CraneK_90_Elbow_Standard.currentIndexChanged.connect(self.on_crane_k_index_changed)
212
            self.ui.comboBox_CraneK_90_Elbow_Bend.currentIndexChanged.connect(self.on_crane_k_index_changed)
213
            self.ui.comboBox_CraneK_90_Elbow_Miter.currentIndexChanged.connect(self.on_crane_k_index_changed)
214
            # 45 Elbow
215
            self.ui.pushButton_Add_CraneK_45_Elbow_Standard.clicked.connect(self.add_crane_k)
216
            self.ui.pushButton_View_CraneK_45_Elbow_Standard.clicked.connect(self.show_crane_k_image)
217
            self.ui.pushButton_Add_CraneK_45_Elbow_Miter.clicked.connect(self.add_crane_k)
218
            self.ui.pushButton_View_CraneK_45_Elbow_Miter.clicked.connect(self.show_crane_k_image)
219
            self.ui.comboBox_CraneK_45_Elbow_Standard.currentIndexChanged.connect(self.on_crane_k_index_changed)
220
            self.ui.comboBox_CraneK_45_Elbow_Miter.currentIndexChanged.connect(self.on_crane_k_index_changed)
221
            # 180 Elbow
222
            self.ui.pushButton_Add_CraneK_180_Elbow_Standard.clicked.connect(self.add_crane_k)
223
            self.ui.pushButton_View_CraneK_180_Elbow_Standard.clicked.connect(self.show_crane_k_image)
224
            self.ui.pushButton_Add_CraneK_180_Elbow_Bend.clicked.connect(self.add_crane_k)
225
            self.ui.pushButton_View_CraneK_180_Elbow_Bend.clicked.connect(self.show_crane_k_image)
226
            self.ui.pushButton_Add_CraneK_180_Elbow_Miter.clicked.connect(self.add_crane_k)
227
            self.ui.pushButton_View_CraneK_180_Elbow_Miter.clicked.connect(self.show_crane_k_image)
228
            self.ui.comboBox_CraneK_180_Elbow_Standard.currentIndexChanged.connect(self.on_crane_k_index_changed)
229
            self.ui.comboBox_CraneK_180_Elbow_Bend.currentIndexChanged.connect(self.on_crane_k_index_changed)
230
            self.ui.comboBox_CraneK_180_Elbow_Miter.currentIndexChanged.connect(self.on_crane_k_index_changed)
231
            # Tees
232
            self.ui.pushButton_Add_CraneK_Tees.clicked.connect(self.add_crane_k)
233
            self.ui.pushButton_View_CraneK_Tees.clicked.connect(self.show_crane_k_image)
234
            self.ui.comboBox_CraneK_Tees.currentIndexChanged.connect(self.on_crane_k_index_changed)
235
            # Reducer & Expander
236
            self.ui.pushButton_Add_CraneK_Expander.clicked.connect(self.add_crane_k)
237
            self.ui.pushButton_View_CraneK_Expander.clicked.connect(self.show_crane_k_image)
238
            self.ui.pushButton_Add_CraneK_Reducer.clicked.connect(self.add_crane_k)
239
            self.ui.pushButton_View_CraneK_Reducer.clicked.connect(self.show_crane_k_image)
240
            self.ui.comboBox_CraneK_Expander.currentIndexChanged.connect(self.on_crane_k_index_changed)
241
            self.ui.comboBox_CraneK_Reducer.currentIndexChanged.connect(self.on_crane_k_index_changed)
242
            # Valves
243
            self.ui.pushButton_Add_CraneK_Valves_Globe.clicked.connect(self.add_crane_k)
244
            self.ui.pushButton_View_CraneK_Valves_Globe.clicked.connect(self.show_crane_k_image)
245
            self.ui.pushButton_Add_CraneK_Valves_Plug.clicked.connect(self.add_crane_k)
246
            self.ui.pushButton_View_CraneK_Valves_Plug.clicked.connect(self.show_crane_k_image)
247
            self.ui.pushButton_Add_CraneK_Valves_Foot.clicked.connect(self.add_crane_k)
248
            self.ui.pushButton_View_CraneK_Valves_Foot.clicked.connect(self.show_crane_k_image)
249
            self.ui.pushButton_Add_CraneK_Valves_Etc.clicked.connect(self.add_crane_k)
250
            self.ui.pushButton_View_CraneK_Valves_Etc.clicked.connect(self.show_crane_k_image)
251
            self.ui.comboBox_CraneK_Valves_Globe.currentIndexChanged.connect(self.on_crane_k_index_changed)
252
            self.ui.comboBox_CraneK_Valves_Plug.currentIndexChanged.connect(self.on_crane_k_index_changed)
253
            self.ui.comboBox_CraneK_Valves_Foot.currentIndexChanged.connect(self.on_crane_k_index_changed)
254
            self.ui.comboBox_CraneK_Valves_Etc.currentIndexChanged.connect(self.on_crane_k_index_changed)
255
            # Pipe
256
            self.ui.pushButton_Add_CraneK_Pipe_Entrance.clicked.connect(self.add_crane_k)
257
            self.ui.pushButton_View_CraneK_Pipe_Entrance.clicked.connect(self.show_crane_k_image)
258
            self.ui.pushButton_Add_CraneK_Pipe_Exit.clicked.connect(self.add_crane_k)
259
            self.ui.pushButton_View_CraneK_Pipe_Exit.clicked.connect(self.show_crane_k_image)
260
            self.ui.comboBox_CraneK_Pipe_Entrance.currentIndexChanged.connect(self.on_crane_k_index_changed)
261
            self.ui.comboBox_CraneK_Pipe_Exit.currentIndexChanged.connect(self.on_crane_k_index_changed)
262
            # Check Values
263
            self.ui.pushButton_Add_CraneK_Check_Valves_Swing.clicked.connect(self.add_crane_k)
264
            self.ui.pushButton_View_CraneK_Check_Valves_Swing.clicked.connect(self.show_crane_k_image)
265
            self.ui.pushButton_Add_CraneK_Check_Valves_Lift.clicked.connect(self.add_crane_k)
266
            self.ui.pushButton_View_CraneK_Check_Valves_Lift.clicked.connect(self.show_crane_k_image)
267
            self.ui.pushButton_Add_CraneK_Check_Valves_Tilting.clicked.connect(self.add_crane_k)
268
            self.ui.pushButton_View_CraneK_Check_Valves_Tilting.clicked.connect(self.show_crane_k_image)
269
            self.ui.pushButton_Add_CraneK_Check_Valves_Globe_Stop.clicked.connect(self.add_crane_k)
270
            self.ui.pushButton_View_CraneK_Check_Valves_Globe_Stop.clicked.connect(self.show_crane_k_image)
271
            self.ui.pushButton_Add_CraneK_Check_Valves_Angle_Stop.clicked.connect(self.add_crane_k)
272
            self.ui.pushButton_View_CraneK_Check_Valves_Angle_Stop.clicked.connect(self.show_crane_k_image)
273
            self.ui.comboBox_CraneK_Check_Valves_Swing.currentIndexChanged.connect(self.on_crane_k_index_changed)
274
            self.ui.comboBox_CraneK_Check_Valves_Lift.currentIndexChanged.connect(self.on_crane_k_index_changed)
275
            self.ui.comboBox_CraneK_Check_Valves_Tilting.currentIndexChanged.connect(self.on_crane_k_index_changed)
276
            self.ui.comboBox_CraneK_Check_Valves_Globe_Stop.currentIndexChanged.connect(self.on_crane_k_index_changed)
277
            self.ui.comboBox_CraneK_Check_Valves_Angle_Stop.currentIndexChanged.connect(self.on_crane_k_index_changed)
278
            # Manual K
279
            self.ui.pushButton_Add_CraneK_Manual.clicked.connect(self.add_crane_k)
280
            self.ui.pushButton_View_CraneK_Manual.clicked.connect(self.show_crane_k_image)
281
            self.ui.comboBox_CraneK_Manual.currentIndexChanged.connect(self.on_crane_k_index_changed)
282

    
283
            self.ui.tableWidget_CraneK_SelectedFitting.setContextMenuPolicy(Qt.CustomContextMenu)
284
            self.ui.tableWidget_CraneK_SelectedFitting.customContextMenuRequested.connect(self.context_menu_del_crane_k)
285

    
286
            delegate = ManualKValueDelegate(self.ui.tableWidget_CraneK_SelectedFitting)
287
            self.ui.tableWidget_CraneK_SelectedFitting.setItemDelegate(delegate)
288
        except Exception as ex:
289
            from App import App
290
            from AppDocData import MessageType
291

    
292
            message = 'error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename,
293
                                                           sys.exc_info()[-1].tb_lineno)
294
            App.mainWnd().addMessage.emit(MessageType.Error, message)
295

    
296
    def on_2k_index_changed(self, index):
297
        data = None
298

    
299
        if self.sender() == self.ui.comboBox_2K_90_Elbow_Bend:
300
            data = self.ui.comboBox_2K_90_Elbow_Bend.itemData(index)
301
        elif self.sender() == self.ui.comboBox_2K_90_Elbow_Miter:
302
            data = self.ui.comboBox_2K_90_Elbow_Miter.itemData(index)
303
        elif self.sender() == self.ui.comboBox_2K_45_Elbow_Bend:
304
            data = self.ui.comboBox_2K_45_Elbow_Bend.itemData(index)
305
        elif self.sender() == self.ui.comboBox_2K_45_Elbow_Miter:
306
            data = self.ui.comboBox_2K_45_Elbow_Miter.itemData(index)
307
        elif self.sender() == self.ui.comboBox_2K_180_Elbow_Bend:
308
            data = self.ui.comboBox_2K_180_Elbow_Bend.itemData(index)
309
        elif self.sender() == self.ui.comboBox_2K_Tees_Elbow:
310
            data = self.ui.comboBox_2K_Tees_Elbow.itemData(index)
311
        elif self.sender() == self.ui.comboBox_2K_Tees_Through:
312
            data = self.ui.comboBox_2K_Tees_Through.itemData(index)
313
        elif self.sender() == self.ui.comboBox_2K_Valves_Gate_Ball_Plug:
314
            data = self.ui.comboBox_2K_Valves_Gate_Ball_Plug.itemData(index)
315
        elif self.sender() == self.ui.comboBox_2K_Valves_Globe:
316
            data = self.ui.comboBox_2K_Valves_Globe.itemData(index)
317
        elif self.sender() == self.ui.comboBox_2K_Valves_Others:
318
            data = self.ui.comboBox_2K_Valves_Others.itemData(index)
319
        elif self.sender() == self.ui.comboBox_2K_Pipe:
320
            data = self.ui.comboBox_2K_Pipe.itemData(index)
321
        elif self.sender() == self.ui.comboBox_2K_Check_Valves:
322
            data = self.ui.comboBox_2K_Check_Valves.itemData(index)
323

    
324
        if data:
325
            image = data[6]
326

    
327
            picture = QtGui.QPixmap(':/images/{}'.format(image))
328
            w = 150
329
            h = 150
330
            self.ui.label_2K_Img.setPixmap(
331
                picture.scaled(w, h, QtCore.Qt.KeepAspectRatio, QtCore.Qt.FastTransformation))
332

    
333
    def on_crane_k_index_changed(self, index):
334
        data = None
335

    
336
        if self.sender() == self.ui.comboBox_CraneK_90_Elbow_Standard:
337
            data = self.ui.comboBox_CraneK_90_Elbow_Standard.itemData(index)
338
        elif self.sender() == self.ui.comboBox_CraneK_90_Elbow_Bend:
339
            data = self.ui.comboBox_CraneK_90_Elbow_Bend.itemData(index)
340
        elif self.sender() == self.ui.comboBox_CraneK_90_Elbow_Miter:
341
            data = self.ui.comboBox_CraneK_90_Elbow_Miter.itemData(index)
342
        elif self.sender() == self.ui.comboBox_CraneK_45_Elbow_Standard:
343
            data = self.ui.comboBox_CraneK_45_Elbow_Standard.itemData(index)
344
        elif self.sender() == self.ui.comboBox_CraneK_45_Elbow_Miter:
345
            data = self.ui.comboBox_CraneK_45_Elbow_Miter.itemData(index)
346
        elif self.sender() == self.ui.comboBox_CraneK_180_Elbow_Standard:
347
            data = self.ui.comboBox_CraneK_180_Elbow_Standard.itemData(index)
348
        elif self.sender() == self.ui.comboBox_CraneK_180_Elbow_Bend:
349
            data = self.ui.comboBox_CraneK_180_Elbow_Bend.itemData(index)
350
        elif self.sender() == self.ui.comboBox_CraneK_180_Elbow_Miter:
351
            data = self.ui.comboBox_CraneK_180_Elbow_Miter.itemData(index)
352
        elif self.sender() == self.ui.comboBox_CraneK_Tees:
353
            data = self.ui.comboBox_CraneK_Tees.itemData(index)
354
        elif self.sender() == self.ui.comboBox_CraneK_Expander:
355
            data = self.ui.comboBox_CraneK_Expander.itemData(index)
356
        elif self.sender() == self.ui.comboBox_CraneK_Reducer:
357
            data = self.ui.comboBox_CraneK_Reducer.itemData(index)
358
        elif self.sender() == self.ui.comboBox_CraneK_Valves_Globe:
359
            data = self.ui.comboBox_CraneK_Valves_Globe.itemData(index)
360
        elif self.sender() == self.ui.comboBox_CraneK_Valves_Plug:
361
            data = self.ui.comboBox_CraneK_Valves_Plug.itemData(index)
362
        elif self.sender() == self.ui.comboBox_CraneK_Valves_Foot:
363
            data = self.ui.comboBox_CraneK_Valves_Foot.itemData(index)
364
        elif self.sender() == self.ui.comboBox_CraneK_Valves_Etc:
365
            data = self.ui.comboBox_CraneK_Valves_Etc.itemData(index)
366
        elif self.sender() == self.ui.comboBox_CraneK_Pipe_Entrance:
367
            data = self.ui.comboBox_CraneK_Pipe_Entrance.itemData(index)
368
        elif self.sender() == self.ui.comboBox_CraneK_Pipe_Exit:
369
            data = self.ui.comboBox_CraneK_Pipe_Exit.itemData(index)
370
        elif self.sender() == self.ui.comboBox_CraneK_Check_Valves_Swing:
371
            data = self.ui.comboBox_CraneK_Check_Valves_Swing.itemData(index)
372
        elif self.sender() == self.ui.comboBox_CraneK_Check_Valves_Lift:
373
            data = self.ui.comboBox_CraneK_Check_Valves_Lift.itemData(index)
374
        elif self.sender() == self.ui.comboBox_CraneK_Check_Valves_Tilting:
375
            data = self.ui.comboBox_CraneK_Check_Valves_Tilting.itemData(index)
376
        elif self.sender() == self.ui.comboBox_CraneK_Check_Valves_Globe_Stop:
377
            data = self.ui.comboBox_CraneK_Check_Valves_Globe_Stop.itemData(index)
378
        elif self.sender() == self.ui.comboBox_CraneK_Check_Valves_Angle_Stop:
379
            data = self.ui.comboBox_CraneK_Check_Valves_Angle_Stop.itemData(index)
380
        elif self.sender() == self.ui.comboBox_CraneK_Manual:
381
            data = self.ui.comboBox_CraneK_Manual.itemData(index)
382

    
383
        if data:
384
            image = data[6]
385

    
386
            picture = QtGui.QPixmap(':/images/{}'.format(image))
387
            w = 150
388
            h = 150
389
            self.ui.label_CraneK_Img.setPixmap(
390
                picture.scaled(w, h, QtCore.Qt.KeepAspectRatio, QtCore.Qt.FastTransformation))
391

    
392
    def context_menu_del_2_k(self, position):
393
        try:
394
            menu = QMenu()
395
            delete_2_k = menu.addAction(self.tr("Delete"))
396
            delete_2_k.triggered.connect(lambda: self.delete_2_k_click_event())
397
            menu.addAction(delete_2_k)
398

    
399
            menu.exec_(self.ui.tableWidget_2K_SelectedFitting.viewport().mapToGlobal(position))
400
        except Exception as ex:
401
            from App import App
402
            from AppDocData import MessageType
403

    
404
            message = 'error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename,
405
                                                           sys.exc_info()[-1].tb_lineno)
406
            App.mainWnd().addMessage.emit(MessageType.Error, message)
407

    
408
    def context_menu_del_equivalent_length(self, position):
409
        try:
410
            menu = QMenu()
411
            delete_equivalent_length = menu.addAction(self.tr("Delete"))
412
            delete_equivalent_length.triggered.connect(lambda: self.delete_equivalent_length_click_event())
413
            menu.addAction(delete_equivalent_length)
414

    
415
            menu.exec_(self.ui.tableWidget_Equivalent_Length_SelectedFitting.viewport().mapToGlobal(position))
416
        except Exception as ex:
417
            from App import App
418
            from AppDocData import MessageType
419

    
420
            message = 'error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename,
421
                                                           sys.exc_info()[-1].tb_lineno)
422
            App.mainWnd().addMessage.emit(MessageType.Error, message)
423

    
424
    def context_menu_del_crane_k(self, position):
425
        try:
426
            menu = QMenu()
427
            delete_crane_k = menu.addAction(self.tr("Delete"))
428
            delete_crane_k.triggered.connect(lambda: self.delete_crane_k_click_event())
429
            menu.addAction(delete_crane_k)
430

    
431
            menu.exec_(self.ui.tableWidget_CraneK_SelectedFitting.viewport().mapToGlobal(position))
432
        except Exception as ex:
433
            from App import App
434
            from AppDocData import MessageType
435

    
436
            message = 'error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename,
437
                                                           sys.exc_info()[-1].tb_lineno)
438
            App.mainWnd().addMessage.emit(MessageType.Error, message)
439

    
440
    def delete_2_k_click_event(self):
441
        try:
442
            row = self.ui.tableWidget_2K_SelectedFitting.currentRow()
443
            uid = self.ui.tableWidget_2K_SelectedFitting.item(row, 0).text()
444
            find_row = self.find_2_k_data(uid)
445
            if find_row is not None:
446
                self.del_2_k_data(find_row)
447
        except Exception as ex:
448
            from App import App
449
            from AppDocData import MessageType
450

    
451
            message = 'error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename,
452
                                                           sys.exc_info()[-1].tb_lineno)
453
            App.mainWnd().addMessage.emit(MessageType.Error, message)
454

    
455
    def delete_equivalent_length_click_event(self):
456
        try:
457
            row = self.ui.tableWidget_Equivalent_Length_SelectedFitting.currentRow()
458
            uid = self.ui.tableWidget_Equivalent_Length_SelectedFitting.item(row, 0).text()
459
            find_row = self.find_equivalent_length_data(uid)
460
            if find_row is not None:
461
                self.del_equivalent_length_data(find_row)
462
        except Exception as ex:
463
            from App import App
464
            from AppDocData import MessageType
465

    
466
            message = 'error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename,
467
                                                           sys.exc_info()[-1].tb_lineno)
468
            App.mainWnd().addMessage.emit(MessageType.Error, message)
469

    
470
    def delete_crane_k_click_event(self):
471
        try:
472
            row = self.ui.tableWidget_CraneK_SelectedFitting.currentRow()
473
            uid = self.ui.tableWidget_CraneK_SelectedFitting.item(row, 0).text()
474
            find_row = self.find_crane_k_data(uid)
475
            if find_row is not None:
476
                self.del_crane_k_data(find_row)
477
        except Exception as ex:
478
            from App import App
479
            from AppDocData import MessageType
480

    
481
            message = 'error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename,
482
                                                           sys.exc_info()[-1].tb_lineno)
483
            App.mainWnd().addMessage.emit(MessageType.Error, message)
484

    
485
    def show_2_k_image(self):
486
        try:
487
            data = None
488
            # 90 Elbow
489
            if self.sender() == self.ui.pushButton_View_2K_90_Elbow_Bend:
490
                data = self.ui.comboBox_2K_90_Elbow_Bend.currentData()
491
            elif self.sender() == self.ui.pushButton_View_2K_90_Elbow_Miter:
492
                data = self.ui.comboBox_2K_90_Elbow_Miter.currentData()
493
            # 45 Elbow
494
            elif self.sender() == self.ui.pushButton_View_2K_45_Elbow_Bend:
495
                data = self.ui.comboBox_2K_45_Elbow_Bend.currentData()
496
            elif self.sender() == self.ui.pushButton_View_2K_45_Elbow_Miter:
497
                data = self.ui.comboBox_2K_45_Elbow_Miter.currentData()
498
            # 180 Elbow
499
            elif self.sender() == self.ui.pushButton_View_2K_180_Elbow_Bend:
500
                data = self.ui.comboBox_2K_180_Elbow_Bend.currentData()
501
            # Tees
502
            elif self.sender() == self.ui.pushButton_View_2K_Tees_Elbow:
503
                data = self.ui.comboBox_2K_Tees_Elbow.currentData()
504
            elif self.sender() == self.ui.pushButton_View_2K_Tees_Through:
505
                data = self.ui.comboBox_2K_Tees_Through.currentData()
506
            # Valves
507
            elif self.sender() == self.ui.pushButton_View_2K_Valves_Gate_Ball_Plug:
508
                data = self.ui.comboBox_2K_Valves_Gate_Ball_Plug.currentData()
509
            elif self.sender() == self.ui.pushButton_View_2K_Valves_Globe:
510
                data = self.ui.comboBox_2K_Valves_Globe.currentData()
511
            elif self.sender() == self.ui.pushButton_View_2K_Valves_Others:
512
                data = self.ui.comboBox_2K_Valves_Others.currentData()
513
            # Pipe
514
            elif self.sender() == self.ui.pushButton_View_2K_Pipe:
515
                data = self.ui.comboBox_2K_Pipe.currentData()
516
            # Check Valves
517
            elif self.sender() == self.ui.pushButton_View_2K_Check_Valves:
518
                data = self.ui.comboBox_2K_Check_Valves.currentData()
519

    
520
            if data:
521
                image = data[6]
522

    
523
                picture = QtGui.QPixmap(':/images/{}'.format(image))
524
                w = 150  # self.ui.label_2K_Img.height()
525
                h = 150  # self.ui.label_2K_Img.width()
526
                self.ui.label_2K_Img.setPixmap(
527
                    picture.scaled(w, h, QtCore.Qt.KeepAspectRatio, QtCore.Qt.FastTransformation))
528
        except Exception as ex:
529
            from App import App
530
            from AppDocData import MessageType
531

    
532
            message = 'error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename,
533
                                                           sys.exc_info()[-1].tb_lineno)
534
            App.mainWnd().addMessage.emit(MessageType.Error, message)
535

    
536
    def show_crane_k_image(self):
537
        try:
538
            data = None
539
            # 90 Elbow
540
            if self.sender() == self.ui.pushButton_View_CraneK_90_Elbow_Standard:
541
                data = self.ui.comboBox_CraneK_90_Elbow_Standard.currentData()
542
            elif self.sender() == self.ui.pushButton_View_CraneK_90_Elbow_Bend:
543
                data = self.ui.comboBox_CraneK_90_Elbow_Bend.currentData()
544
            elif self.sender() == self.ui.pushButton_View_CraneK_90_Elbow_Miter:
545
                data = self.ui.comboBox_CraneK_90_Elbow_Miter.currentData()
546
            # 45 Elbow
547
            elif self.sender() == self.ui.pushButton_View_CraneK_45_Elbow_Standard:
548
                data = self.ui.comboBox_CraneK_45_Elbow_Standard.currentData()
549
            elif self.sender() == self.ui.pushButton_View_CraneK_45_Elbow_Miter:
550
                data = self.ui.comboBox_CraneK_45_Elbow_Miter.currentData()
551
            # 180 Elbow
552
            elif self.sender() == self.ui.pushButton_View_CraneK_180_Elbow_Standard:
553
                data = self.ui.comboBox_CraneK_180_Elbow_Standard.currentData()
554
            elif self.sender() == self.ui.pushButton_View_CraneK_180_Elbow_Bend:
555
                data = self.ui.comboBox_CraneK_180_Elbow_Bend.currentData()
556
            elif self.sender() == self.ui.pushButton_View_CraneK_180_Elbow_Miter:
557
                data = self.ui.comboBox_CraneK_180_Elbow_Miter.currentData()
558
            # Tees
559
            elif self.sender() == self.ui.pushButton_View_CraneK_Tees:
560
                data = self.ui.comboBox_CraneK_Tees.currentData()
561
            # Reducer & Expander
562
            elif self.sender() == self.ui.pushButton_View_CraneK_Expander:
563
                data = self.ui.comboBox_CraneK_Expander.currentData()
564
            elif self.sender() == self.ui.pushButton_View_CraneK_Reducer:
565
                data = self.ui.comboBox_CraneK_Reducer.currentData()
566
            # Valves
567
            elif self.sender() == self.ui.pushButton_View_CraneK_Valves_Globe:
568
                data = self.ui.comboBox_CraneK_Valves_Globe.currentData()
569
            elif self.sender() == self.ui.pushButton_View_CraneK_Valves_Plug:
570
                data = self.ui.comboBox_CraneK_Valves_Plug.currentData()
571
            elif self.sender() == self.ui.pushButton_View_CraneK_Valves_Foot:
572
                data = self.ui.comboBox_CraneK_Valves_Foot.currentData()
573
            elif self.sender() == self.ui.pushButton_View_CraneK_Valves_Etc:
574
                data = self.ui.comboBox_CraneK_Valves_Etc.currentData()
575
            # Pipe
576
            elif self.sender() == self.ui.pushButton_View_CraneK_Pipe_Entrance:
577
                data = self.ui.comboBox_CraneK_Pipe_Entrance.currentData()
578
            elif self.sender() == self.ui.pushButton_View_CraneK_Pipe_Exit:
579
                data = self.ui.comboBox_CraneK_Pipe_Exit.currentData()
580
            # Check Valves
581
            elif self.sender() == self.ui.pushButton_View_CraneK_Check_Valves_Swing:
582
                data = self.ui.comboBox_CraneK_Check_Valves_Swing.currentData()
583
            elif self.sender() == self.ui.pushButton_View_CraneK_Check_Valves_Lift:
584
                data = self.ui.comboBox_CraneK_Check_Valves_Lift.currentData()
585
            elif self.sender() == self.ui.pushButton_View_CraneK_Check_Valves_Tilting:
586
                data = self.ui.comboBox_CraneK_Check_Valves_Tilting.currentData()
587
            elif self.sender() == self.ui.pushButton_View_CraneK_Check_Valves_Globe_Stop:
588
                data = self.ui.comboBox_CraneK_Check_Valves_Globe_Stop.currentData()
589
            elif self.sender() == self.ui.pushButton_View_CraneK_Check_Valves_Angle_Stop:
590
                data = self.ui.comboBox_CraneK_Check_Valves_Angle_Stop.currentData()
591
            # Manual K
592
            elif self.sender() == self.ui.pushButton_View_CraneK_Manual:
593
                data = self.ui.comboBox_CraneK_Manual.currentData()
594

    
595
            if data:
596
                image = data[6]
597

    
598
                picture = QtGui.QPixmap(':/images/{}'.format(image))
599
                w = 150  # self.ui.label_CraneK_Img.height()
600
                h = 150  # self.ui.label_CraneK_Img.width()
601
                self.ui.label_CraneK_Img.setPixmap(
602
                    picture.scaled(w, h, QtCore.Qt.KeepAspectRatio, QtCore.Qt.FastTransformation))
603

    
604
        except Exception as ex:
605
            from App import App
606
            from AppDocData import MessageType
607

    
608
            message = 'error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename,
609
                                                           sys.exc_info()[-1].tb_lineno)
610
            App.mainWnd().addMessage.emit(MessageType.Error, message)
611

    
612
    def add_2_k(self):
613
        try:
614
            # 90 Elbow
615
            if self.sender() == self.ui.pushButton_Add_2K_90_Elbow_Bend:
616
                count = self.ui.lineEdit_2K_90_Elbow_Bend_Count.text()
617
                if count.isdigit():
618
                    data = self.ui.comboBox_2K_90_Elbow_Bend.currentData()
619
                    find_row = self.find_2_k_data(data[0])
620
                    if find_row is None:
621
                        row = self.ui.tableWidget_2K_SelectedFitting.rowCount()
622
                        self.ui.tableWidget_2K_SelectedFitting.setRowCount(row + 1)
623
                        self.add_2_k_data(row, data, count)
624
                    else:
625
                        self.update_2_k_data(find_row, data, count)
626
            elif self.sender() == self.ui.pushButton_Add_2K_90_Elbow_Miter:
627
                count = self.ui.lineEdit_2K_90_Elbow_Miter_Count.text()
628
                if count.isdigit():
629
                    data = self.ui.comboBox_2K_90_Elbow_Miter.currentData()
630
                    find_row = self.find_2_k_data(data[0])
631
                    if find_row is None:
632
                        row = self.ui.tableWidget_2K_SelectedFitting.rowCount()
633
                        self.ui.tableWidget_2K_SelectedFitting.setRowCount(row + 1)
634
                        self.add_2_k_data(row, data, count)
635
                    else:
636
                        self.update_2_k_data(find_row, data, count)
637
            # 45 Elbow
638
            elif self.sender() == self.ui.pushButton_Add_2K_45_Elbow_Bend:
639
                count = self.ui.lineEdit_2K_45_Elbow_Bend_Count.text()
640
                if count.isdigit():
641
                    data = self.ui.comboBox_2K_45_Elbow_Bend.currentData()
642
                    find_row = self.find_2_k_data(data[0])
643
                    if find_row is None:
644
                        row = self.ui.tableWidget_2K_SelectedFitting.rowCount()
645
                        self.ui.tableWidget_2K_SelectedFitting.setRowCount(row + 1)
646
                        self.add_2_k_data(row, data, count)
647
                    else:
648
                        self.update_2_k_data(find_row, data, count)
649
            elif self.sender() == self.ui.pushButton_Add_2K_45_Elbow_Miter:
650
                count = self.ui.lineEdit_2K_45_Elbow_Miter_Count.text()
651
                if count.isdigit():
652
                    data = self.ui.comboBox_2K_45_Elbow_Miter.currentData()
653
                    find_row = self.find_2_k_data(data[0])
654
                    if find_row is None:
655
                        row = self.ui.tableWidget_2K_SelectedFitting.rowCount()
656
                        self.ui.tableWidget_2K_SelectedFitting.setRowCount(row + 1)
657
                        self.add_2_k_data(row, data, count)
658
                    else:
659
                        self.update_2_k_data(find_row, data, count)
660
            # 180 Elbow
661
            elif self.sender() == self.ui.pushButton_Add_2K_180_Elbow_Bend:
662
                count = self.ui.lineEdit_2K_180_Elbow_Bend_Count.text()
663
                if count.isdigit():
664
                    data = self.ui.comboBox_2K_180_Elbow_Bend.currentData()
665
                    find_row = self.find_2_k_data(data[0])
666
                    if find_row is None:
667
                        row = self.ui.tableWidget_2K_SelectedFitting.rowCount()
668
                        self.ui.tableWidget_2K_SelectedFitting.setRowCount(row + 1)
669
                        self.add_2_k_data(row, data, count)
670
                    else:
671
                        self.update_2_k_data(find_row, data, count)
672
            # Tees
673
            elif self.sender() == self.ui.pushButton_Add_2K_Tees_Elbow:
674
                count = self.ui.lineEdit_2K_Tees_Elbow_Count.text()
675
                if count.isdigit():
676
                    data = self.ui.comboBox_2K_Tees_Elbow.currentData()
677
                    find_row = self.find_2_k_data(data[0])
678
                    if find_row is None:
679
                        row = self.ui.tableWidget_2K_SelectedFitting.rowCount()
680
                        self.ui.tableWidget_2K_SelectedFitting.setRowCount(row + 1)
681
                        self.add_2_k_data(row, data, count)
682
                    else:
683
                        self.update_2_k_data(find_row, data, count)
684
            elif self.sender() == self.ui.pushButton_Add_2K_Tees_Through:
685
                count = self.ui.lineEdit_2K_Tees_Through_Count.text()
686
                if count.isdigit():
687
                    data = self.ui.comboBox_2K_Tees_Through.currentData()
688
                    find_row = self.find_2_k_data(data[0])
689
                    if find_row is None:
690
                        row = self.ui.tableWidget_2K_SelectedFitting.rowCount()
691
                        self.ui.tableWidget_2K_SelectedFitting.setRowCount(row + 1)
692
                        self.add_2_k_data(row, data, count)
693
                    else:
694
                        self.update_2_k_data(find_row, data, count)
695
            # Valves
696
            elif self.sender() == self.ui.pushButton_Add_2K_Valves_Gate_Ball_Plug:
697
                count = self.ui.lineEdit_2K_Valves_Gate_Ball_Plug_Count.text()
698
                if count.isdigit():
699
                    data = self.ui.comboBox_2K_Valves_Gate_Ball_Plug.currentData()
700
                    find_row = self.find_2_k_data(data[0])
701
                    if find_row is None:
702
                        row = self.ui.tableWidget_2K_SelectedFitting.rowCount()
703
                        self.ui.tableWidget_2K_SelectedFitting.setRowCount(row + 1)
704
                        self.add_2_k_data(row, data, count)
705
                    else:
706
                        self.update_2_k_data(find_row, data, count)
707
            elif self.sender() == self.ui.pushButton_Add_2K_Valves_Globe:
708
                count = self.ui.lineEdit_2K_Valves_Globe_Count.text()
709
                if count.isdigit():
710
                    data = self.ui.comboBox_2K_Valves_Globe.currentData()
711
                    find_row = self.find_2_k_data(data[0])
712
                    if find_row is None:
713
                        row = self.ui.tableWidget_2K_SelectedFitting.rowCount()
714
                        self.ui.tableWidget_2K_SelectedFitting.setRowCount(row + 1)
715
                        self.add_2_k_data(row, data, count)
716
                    else:
717
                        self.update_2_k_data(find_row, data, count)
718
            elif self.sender() == self.ui.pushButton_Add_2K_Valves_Others:
719
                count = self.ui.lineEdit_2K_Valves_Others_Count.text()
720
                if count.isdigit():
721
                    data = self.ui.comboBox_2K_Valves_Others.currentData()
722
                    find_row = self.find_2_k_data(data[0])
723
                    if find_row is None:
724
                        row = self.ui.tableWidget_2K_SelectedFitting.rowCount()
725
                        self.ui.tableWidget_2K_SelectedFitting.setRowCount(row + 1)
726
                        self.add_2_k_data(row, data, count)
727
                    else:
728
                        self.update_2_k_data(find_row, data, count)
729
            # Pipe
730
            elif self.sender() == self.ui.pushButton_Add_2K_Pipe:
731
                count = self.ui.lineEdit_2K_Pipe_Count.text()
732
                if count.isdigit():
733
                    data = self.ui.comboBox_2K_Pipe.currentData()
734
                    find_row = self.find_2_k_data(data[0])
735
                    if find_row is None:
736
                        row = self.ui.tableWidget_2K_SelectedFitting.rowCount()
737
                        self.ui.tableWidget_2K_SelectedFitting.setRowCount(row + 1)
738
                        self.add_2_k_data(row, data, count)
739
                    else:
740
                        self.update_2_k_data(find_row, data, count)
741
            # Check Valves
742
            elif self.sender() == self.ui.pushButton_Add_2K_Check_Valves:
743
                count = self.ui.lineEdit_2K_Check_Valves_Count.text()
744
                if count.isdigit():
745
                    data = self.ui.comboBox_2K_Check_Valves.currentData()
746
                    find_row = self.find_2_k_data(data[0])
747
                    if find_row is None:
748
                        row = self.ui.tableWidget_2K_SelectedFitting.rowCount()
749
                        self.ui.tableWidget_2K_SelectedFitting.setRowCount(row + 1)
750
                        self.add_2_k_data(row, data, count)
751
                    else:
752
                        self.update_2_k_data(find_row, data, count)
753
        except Exception as ex:
754
            from App import App
755
            from AppDocData import MessageType
756

    
757
            message = 'error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename,
758
                                                           sys.exc_info()[-1].tb_lineno)
759
            App.mainWnd().addMessage.emit(MessageType.Error, message)
760

    
761
    def add_equivalent_length(self):
762
        try:
763
            # Elbow
764
            if self.sender() == self.ui.pushButton_Add_Equivalent_Length_90_Elbow:
765
                count = self.ui.lineEdit_Equivalent_Length_90_Elbow_Count.text()
766
                if count.isdigit():
767
                    data = self.ui.comboBox_Equivalent_Length_90_Elbow.currentData()
768
                    find_row = self.find_equivalent_length_data(data[0])
769
                    if find_row is None:
770
                        row = self.ui.tableWidget_Equivalent_Length_SelectedFitting.rowCount()
771
                        self.ui.tableWidget_Equivalent_Length_SelectedFitting.setRowCount(row + 1)
772
                        self.add_equivalent_length_data(row, data, count)
773
                    else:
774
                        self.update_equivalent_length_data(find_row, count)
775
            elif self.sender() == self.ui.pushButton_Add_Equivalent_Length_45_Elbow:
776
                count = self.ui.lineEdit_Equivalent_Length_45_Elbow_Count.text()
777
                if count.isdigit():
778
                    data = self.ui.comboBox_Equivalent_Length_45_Elbow.currentData()
779
                    find_row = self.find_equivalent_length_data(data[0])
780
                    if find_row is None:
781
                        row = self.ui.tableWidget_Equivalent_Length_SelectedFitting.rowCount()
782
                        self.ui.tableWidget_Equivalent_Length_SelectedFitting.setRowCount(row + 1)
783
                        self.add_equivalent_length_data(row, data, count)
784
                    else:
785
                        self.update_equivalent_length_data(find_row, count)
786
            elif self.sender() == self.ui.pushButton_Add_Equivalent_Length_Miter:
787
                count = self.ui.lineEdit_Equivalent_Length_Miter_Count.text()
788
                angle = self.ui.comboBox_Equivalent_Length_Miter_Degree.currentText()
789
                if count.isdigit():
790
                    data = self.ui.comboBox_Equivalent_Length_Miter.currentData()
791
                    find_row = self.find_equivalent_length_data(data[0])
792
                    if find_row is None:
793
                        row = self.ui.tableWidget_Equivalent_Length_SelectedFitting.rowCount()
794
                        self.ui.tableWidget_Equivalent_Length_SelectedFitting.setRowCount(row + 1)
795
                        self.add_equivalent_length_data(row, data, count, angle)
796
                    else:
797
                        self.update_equivalent_length_data(find_row, count, angle)
798
            # Tees
799
            elif self.sender() == self.ui.pushButton_Add_Equivalent_Length_Tee_Branch:
800
                count = self.ui.lineEdit_Equivalent_Length_Tee_Branch_Count.text()
801
                if count.isdigit():
802
                    data = self.ui.comboBox_Equivalent_Length_Tee_Branch.currentData()
803
                    find_row = self.find_equivalent_length_data(data[0])
804
                    if find_row is None:
805
                        row = self.ui.tableWidget_Equivalent_Length_SelectedFitting.rowCount()
806
                        self.ui.tableWidget_Equivalent_Length_SelectedFitting.setRowCount(row + 1)
807
                        self.add_equivalent_length_data(row, data, count)
808
                    else:
809
                        self.update_equivalent_length_data(find_row, count)
810
            elif self.sender() == self.ui.pushButton_Add_Equivalent_Length_Tee_Through:
811
                count = self.ui.lineEdit_Equivalent_Length_Tee_Through_Count.text()
812
                if count.isdigit():
813
                    data = self.ui.comboBox_Equivalent_Length_Tee_Through.currentData()
814
                    find_row = self.find_equivalent_length_data(data[0])
815
                    if find_row is None:
816
                        row = self.ui.tableWidget_Equivalent_Length_SelectedFitting.rowCount()
817
                        self.ui.tableWidget_Equivalent_Length_SelectedFitting.setRowCount(row + 1)
818
                        self.add_equivalent_length_data(row, data, count)
819
                    else:
820
                        self.update_equivalent_length_data(find_row, count)
821
            # Valves
822
            elif self.sender() == self.ui.pushButton_Add_Equivalent_Length_Gate_Ball_Plug:
823
                count = self.ui.lineEdit_Equivalent_Length_Gate_Ball_Plug_Count.text()
824
                if count.isdigit():
825
                    data = self.ui.comboBox_Equivalent_Length_Gate_Ball_Plug.currentData()
826
                    find_row = self.find_equivalent_length_data(data[0])
827
                    if find_row is None:
828
                        row = self.ui.tableWidget_Equivalent_Length_SelectedFitting.rowCount()
829
                        self.ui.tableWidget_Equivalent_Length_SelectedFitting.setRowCount(row + 1)
830
                        self.add_equivalent_length_data(row, data, count)
831
                    else:
832
                        self.update_equivalent_length_data(find_row, count)
833
            elif self.sender() == self.ui.pushButton_Add_Equivalent_Length_Globe:
834
                count = self.ui.lineEdit_Equivalent_Length_Globe_Count.text()
835
                if count.isdigit():
836
                    data = self.ui.comboBox_Equivalent_Length_Globe.currentData()
837
                    find_row = self.find_equivalent_length_data(data[0])
838
                    if find_row is None:
839
                        row = self.ui.tableWidget_Equivalent_Length_SelectedFitting.rowCount()
840
                        self.ui.tableWidget_Equivalent_Length_SelectedFitting.setRowCount(row + 1)
841
                        self.add_equivalent_length_data(row, data, count)
842
                    else:
843
                        self.update_equivalent_length_data(find_row, count)
844
            elif self.sender() == self.ui.pushButton_Add_Equivalent_Length_Butterfly:
845
                count = self.ui.lineEdit_Equivalent_Length_Butterfly_Count.text()
846
                if count.isdigit():
847
                    data = self.ui.comboBox_Equivalent_Length_Butterfly.currentData()
848
                    find_row = self.find_equivalent_length_data(data[0])
849
                    if find_row is None:
850
                        row = self.ui.tableWidget_Equivalent_Length_SelectedFitting.rowCount()
851
                        self.ui.tableWidget_Equivalent_Length_SelectedFitting.setRowCount(row + 1)
852
                        self.add_equivalent_length_data(row, data, count)
853
                    else:
854
                        self.update_equivalent_length_data(find_row, count)
855
            elif self.sender() == self.ui.pushButton_Add_Equivalent_Length_Check:
856
                count = self.ui.lineEdit_Equivalent_Length_Check_Count.text()
857
                if count.isdigit():
858
                    data = self.ui.comboBox_Equivalent_Length_Check.currentData()
859
                    find_row = self.find_equivalent_length_data(data[0])
860
                    if find_row is None:
861
                        row = self.ui.tableWidget_Equivalent_Length_SelectedFitting.rowCount()
862
                        self.ui.tableWidget_Equivalent_Length_SelectedFitting.setRowCount(row + 1)
863
                        self.add_equivalent_length_data(row, data, count)
864
                    else:
865
                        self.update_equivalent_length_data(find_row, count)
866
            # Nozzles
867
            elif self.sender() == self.ui.pushButton_Add_Equivalent_Length_Nozzle_In:
868
                count = self.ui.lineEdit_Equivalent_Length_Nozzle_In_Count.text()
869
                if count.isdigit():
870
                    data = self.ui.comboBox_Equivalent_Length_Nozzle_In.currentData()
871
                    find_row = self.find_equivalent_length_data(data[0])
872
                    if find_row is None:
873
                        row = self.ui.tableWidget_Equivalent_Length_SelectedFitting.rowCount()
874
                        self.ui.tableWidget_Equivalent_Length_SelectedFitting.setRowCount(row + 1)
875
                        self.add_equivalent_length_data(row, data, count)
876
                    else:
877
                        self.update_equivalent_length_data(find_row, count)
878
            elif self.sender() == self.ui.pushButton_Add_Equivalent_Length_Nozzle_Out:
879
                count = self.ui.lineEdit_Equivalent_Length_Nozzle_Out_Count.text()
880
                if count.isdigit():
881
                    data = self.ui.comboBox_Equivalent_Length_Nozzle_Out.currentData()
882
                    find_row = self.find_equivalent_length_data(data[0])
883
                    if find_row is None:
884
                        row = self.ui.tableWidget_Equivalent_Length_SelectedFitting.rowCount()
885
                        self.ui.tableWidget_Equivalent_Length_SelectedFitting.setRowCount(row + 1)
886
                        self.add_equivalent_length_data(row, data, count)
887
                    else:
888
                        self.update_equivalent_length_data(find_row, count)
889
        except Exception as ex:
890
            from App import App
891
            from AppDocData import MessageType
892

    
893
            message = 'error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename,
894
                                                           sys.exc_info()[-1].tb_lineno)
895
            App.mainWnd().addMessage.emit(MessageType.Error, message)
896

    
897
    def add_crane_k(self):
898
        try:
899
            # 90 Elbow
900
            if self.sender() == self.ui.pushButton_Add_CraneK_90_Elbow_Standard:
901
                count = self.ui.lineEdit_CraneK_90_Elbow_Standard_Count.text()
902
                if count.isdigit():
903
                    data = self.ui.comboBox_CraneK_90_Elbow_Standard.currentData()
904
                    find_row = self.find_crane_k_data(data[0])
905
                    if find_row is None:
906
                        row = self.ui.tableWidget_CraneK_SelectedFitting.rowCount()
907
                        self.ui.tableWidget_CraneK_SelectedFitting.setRowCount(row + 1)
908
                        self.add_crane_k_data(row, data, count)
909
                    else:
910
                        self.update_crane_k_data(find_row, data, count)
911
            elif self.sender() == self.ui.pushButton_Add_CraneK_90_Elbow_Bend:
912
                count = self.ui.lineEdit_CraneK_90_Elbow_Bend_Count.text()
913
                if count.isdigit():
914
                    data = self.ui.comboBox_CraneK_90_Elbow_Bend.currentData()
915
                    find_row = self.find_crane_k_data(data[0])
916
                    if find_row is None:
917
                        row = self.ui.tableWidget_CraneK_SelectedFitting.rowCount()
918
                        self.ui.tableWidget_CraneK_SelectedFitting.setRowCount(row + 1)
919
                        self.add_crane_k_data(row, data, count)
920
                    else:
921
                        self.update_crane_k_data(find_row, data, count)
922
            elif self.sender() == self.ui.pushButton_Add_CraneK_90_Elbow_Miter:
923
                count = self.ui.lineEdit_CraneK_90_Elbow_Miter_Count.text()
924
                if count.isdigit():
925
                    data = self.ui.comboBox_CraneK_90_Elbow_Miter.currentData()
926
                    find_row = self.find_crane_k_data(data[0])
927
                    if find_row is None:
928
                        row = self.ui.tableWidget_CraneK_SelectedFitting.rowCount()
929
                        self.ui.tableWidget_CraneK_SelectedFitting.setRowCount(row + 1)
930
                        self.add_crane_k_data(row, data, count)
931
                    else:
932
                        self.update_crane_k_data(find_row, data, count)
933
            # 45 Elbow
934
            elif self.sender() == self.ui.pushButton_Add_CraneK_45_Elbow_Standard:
935
                count = self.ui.lineEdit_CraneK_45_Elbow_Standard_Count.text()
936
                if count.isdigit():
937
                    data = self.ui.comboBox_CraneK_45_Elbow_Standard.currentData()
938
                    find_row = self.find_crane_k_data(data[0])
939
                    if find_row is None:
940
                        row = self.ui.tableWidget_CraneK_SelectedFitting.rowCount()
941
                        self.ui.tableWidget_CraneK_SelectedFitting.setRowCount(row + 1)
942
                        self.add_crane_k_data(row, data, count)
943
                    else:
944
                        self.update_crane_k_data(find_row, data, count)
945
            elif self.sender() == self.ui.pushButton_Add_CraneK_45_Elbow_Miter:
946
                count = self.ui.lineEdit_CraneK_45_Elbow_Miter_Count.text()
947
                if count.isdigit():
948
                    data = self.ui.comboBox_CraneK_45_Elbow_Miter.currentData()
949
                    find_row = self.find_crane_k_data(data[0])
950
                    if find_row is None:
951
                        row = self.ui.tableWidget_CraneK_SelectedFitting.rowCount()
952
                        self.ui.tableWidget_CraneK_SelectedFitting.setRowCount(row + 1)
953
                        self.add_crane_k_data(row, data, count)
954
                    else:
955
                        self.update_crane_k_data(find_row, data, count)
956
            # 180 Elbow
957
            elif self.sender() == self.ui.pushButton_Add_CraneK_180_Elbow_Standard:
958
                count = self.ui.lineEdit_CraneK_180_Elbow_Standard_Count.text()
959
                if count.isdigit():
960
                    data = self.ui.comboBox_CraneK_180_Elbow_Standard.currentData()
961
                    find_row = self.find_crane_k_data(data[0])
962
                    if find_row is None:
963
                        row = self.ui.tableWidget_CraneK_SelectedFitting.rowCount()
964
                        self.ui.tableWidget_CraneK_SelectedFitting.setRowCount(row + 1)
965
                        self.add_crane_k_data(row, data, count)
966
                    else:
967
                        self.update_crane_k_data(find_row, data, count)
968
            elif self.sender() == self.ui.pushButton_Add_CraneK_180_Elbow_Bend:
969
                count = self.ui.lineEdit_CraneK_180_Elbow_Bend_Count.text()
970
                if count.isdigit():
971
                    data = self.ui.comboBox_CraneK_180_Elbow_Bend.currentData()
972
                    find_row = self.find_crane_k_data(data[0])
973
                    if find_row is None:
974
                        row = self.ui.tableWidget_CraneK_SelectedFitting.rowCount()
975
                        self.ui.tableWidget_CraneK_SelectedFitting.setRowCount(row + 1)
976
                        self.add_crane_k_data(row, data, count)
977
                    else:
978
                        self.update_crane_k_data(find_row, data, count)
979
            elif self.sender() == self.ui.pushButton_Add_CraneK_180_Elbow_Miter:
980
                count = self.ui.lineEdit_CraneK_180_Elbow_Miter_Count.text()
981
                if count.isdigit():
982
                    data = self.ui.comboBox_CraneK_180_Elbow_Miter.currentData()
983
                    find_row = self.find_crane_k_data(data[0])
984
                    if find_row is None:
985
                        row = self.ui.tableWidget_CraneK_SelectedFitting.rowCount()
986
                        self.ui.tableWidget_CraneK_SelectedFitting.setRowCount(row + 1)
987
                        self.add_crane_k_data(row, data, count)
988
                    else:
989
                        self.update_crane_k_data(find_row, data, count)
990
            # Tees
991
            elif self.sender() == self.ui.pushButton_Add_CraneK_Tees:
992
                count = self.ui.lineEdit_CraneK_Tees_Count.text()
993
                if count.isdigit():
994
                    data = self.ui.comboBox_CraneK_Tees.currentData()
995
                    find_row = self.find_crane_k_data(data[0])
996
                    if find_row is None:
997
                        row = self.ui.tableWidget_CraneK_SelectedFitting.rowCount()
998
                        self.ui.tableWidget_CraneK_SelectedFitting.setRowCount(row + 1)
999
                        self.add_crane_k_data(row, data, count)
1000
                    else:
1001
                        self.update_crane_k_data(find_row, data, count)
1002
            # Reducer & Expander
1003
            elif self.sender() == self.ui.pushButton_Add_CraneK_Expander:
1004
                count = self.ui.lineEdit_CraneK_Expander_Count.text()
1005
                if count.isdigit():
1006
                    main_size = self.ui.lineEdit_CraneK_Main_Size.text()
1007
                    sub_size = self.ui.lineEdit_CraneK_Sub_Size.text()
1008
                    angle = self.ui.lineEdit_CraneK_Angle.text()
1009
                    if sub_size and angle:
1010
                        if float(main_size) < float(sub_size):
1011
                            data = self.ui.comboBox_CraneK_Expander.currentData()
1012
                            find_row = self.find_crane_k_data(data[0])
1013
                            if find_row is None:
1014
                                row = self.ui.tableWidget_CraneK_SelectedFitting.rowCount()
1015
                                self.ui.tableWidget_CraneK_SelectedFitting.setRowCount(row + 1)
1016
                                self.add_crane_k_data(row, data, count, sub_size, angle)
1017
                            else:
1018
                                self.update_crane_k_data(find_row, data, count, sub_size, angle)
1019
            elif self.sender() == self.ui.pushButton_Add_CraneK_Reducer:
1020
                count = self.ui.lineEdit_CraneK_Reducer_Count.text()
1021
                if count.isdigit():
1022
                    main_size = self.ui.lineEdit_CraneK_Main_Size.text()
1023
                    sub_size = self.ui.lineEdit_CraneK_Sub_Size.text()
1024
                    angle = self.ui.lineEdit_CraneK_Angle.text()
1025
                    if sub_size and angle:
1026
                        if float(main_size) > float(sub_size):
1027
                            data = self.ui.comboBox_CraneK_Reducer.currentData()
1028
                            find_row = self.find_crane_k_data(data[0])
1029
                            if find_row is None:
1030
                                row = self.ui.tableWidget_CraneK_SelectedFitting.rowCount()
1031
                                self.ui.tableWidget_CraneK_SelectedFitting.setRowCount(row + 1)
1032
                                self.add_crane_k_data(row, data, count, sub_size, angle)
1033
                            else:
1034
                                self.update_crane_k_data(find_row, data, count, sub_size, angle)
1035
            # Valves
1036
            elif self.sender() == self.ui.pushButton_Add_CraneK_Valves_Globe:
1037
                count = self.ui.lineEdit_CraneK_Valves_Globe_Count.text()
1038
                if count.isdigit():
1039
                    data = self.ui.comboBox_CraneK_Valves_Globe.currentData()
1040
                    find_row = self.find_crane_k_data(data[0])
1041
                    if find_row is None:
1042
                        row = self.ui.tableWidget_CraneK_SelectedFitting.rowCount()
1043
                        self.ui.tableWidget_CraneK_SelectedFitting.setRowCount(row + 1)
1044
                        self.add_crane_k_data(row, data, count)
1045
                    else:
1046
                        self.update_crane_k_data(find_row, data, count)
1047
            elif self.sender() == self.ui.pushButton_Add_CraneK_Valves_Plug:
1048
                count = self.ui.lineEdit_CraneK_Valves_Plug_Count.text()
1049
                if count.isdigit():
1050
                    data = self.ui.comboBox_CraneK_Valves_Plug.currentData()
1051
                    find_row = self.find_crane_k_data(data[0])
1052
                    if find_row is None:
1053
                        row = self.ui.tableWidget_CraneK_SelectedFitting.rowCount()
1054
                        self.ui.tableWidget_CraneK_SelectedFitting.setRowCount(row + 1)
1055
                        self.add_crane_k_data(row, data, count)
1056
                    else:
1057
                        self.update_crane_k_data(find_row, data, count)
1058
            elif self.sender() == self.ui.pushButton_Add_CraneK_Valves_Foot:
1059
                count = self.ui.lineEdit_CraneK_Valves_Foot_Count.text()
1060
                if count.isdigit():
1061
                    data = self.ui.comboBox_CraneK_Valves_Foot.currentData()
1062
                    find_row = self.find_crane_k_data(data[0])
1063
                    if find_row is None:
1064
                        row = self.ui.tableWidget_CraneK_SelectedFitting.rowCount()
1065
                        self.ui.tableWidget_CraneK_SelectedFitting.setRowCount(row + 1)
1066
                        self.add_crane_k_data(row, data, count)
1067
                    else:
1068
                        self.update_crane_k_data(find_row, data, count)
1069
            elif self.sender() == self.ui.pushButton_Add_CraneK_Valves_Etc:
1070
                count = self.ui.lineEdit_CraneK_Valves_Etc_Count.text()
1071
                if count.isdigit():
1072
                    data = self.ui.comboBox_CraneK_Valves_Etc.currentData()
1073
                    find_row = self.find_crane_k_data(data[0])
1074
                    if find_row is None:
1075
                        row = self.ui.tableWidget_CraneK_SelectedFitting.rowCount()
1076
                        self.ui.tableWidget_CraneK_SelectedFitting.setRowCount(row + 1)
1077
                        self.add_crane_k_data(row, data, count)
1078
                    else:
1079
                        self.update_crane_k_data(find_row, data, count)
1080
            # Pipe
1081
            elif self.sender() == self.ui.pushButton_Add_CraneK_Pipe_Entrance:
1082
                count = self.ui.lineEdit_CraneK_Pipe_Entrance_Count.text()
1083
                if count.isdigit():
1084
                    data = self.ui.comboBox_CraneK_Pipe_Entrance.currentData()
1085
                    find_row = self.find_crane_k_data(data[0])
1086
                    if find_row is None:
1087
                        row = self.ui.tableWidget_CraneK_SelectedFitting.rowCount()
1088
                        self.ui.tableWidget_CraneK_SelectedFitting.setRowCount(row + 1)
1089
                        self.add_crane_k_data(row, data, count)
1090
                    else:
1091
                        self.update_crane_k_data(find_row, data, count)
1092
            elif self.sender() == self.ui.pushButton_Add_CraneK_Pipe_Exit:
1093
                count = self.ui.lineEdit_CraneK_Pipe_Exit_Count.text()
1094
                if count.isdigit():
1095
                    data = self.ui.comboBox_CraneK_Pipe_Exit.currentData()
1096
                    find_row = self.find_crane_k_data(data[0])
1097
                    if find_row is None:
1098
                        row = self.ui.tableWidget_CraneK_SelectedFitting.rowCount()
1099
                        self.ui.tableWidget_CraneK_SelectedFitting.setRowCount(row + 1)
1100
                        self.add_crane_k_data(row, data, count)
1101
                    else:
1102
                        self.update_crane_k_data(find_row, data, count)
1103
            # Check Values
1104
            elif self.sender() == self.ui.pushButton_Add_CraneK_Check_Valves_Swing:
1105
                count = self.ui.lineEdit_CraneK_Check_Valves_Swing_Count.text()
1106
                if count.isdigit():
1107
                    data = self.ui.comboBox_CraneK_Check_Valves_Swing.currentData()
1108
                    find_row = self.find_crane_k_data(data[0])
1109
                    if find_row is None:
1110
                        row = self.ui.tableWidget_CraneK_SelectedFitting.rowCount()
1111
                        self.ui.tableWidget_CraneK_SelectedFitting.setRowCount(row + 1)
1112
                        self.add_crane_k_data(row, data, count)
1113
                    else:
1114
                        self.update_crane_k_data(find_row, data, count)
1115
            elif self.sender() == self.ui.pushButton_Add_CraneK_Check_Valves_Lift:
1116
                count = self.ui.lineEdit_CraneK_Check_Valves_Lift_Count.text()
1117
                if count.isdigit():
1118
                    data = self.ui.comboBox_CraneK_Check_Valves_Lift.currentData()
1119
                    find_row = self.find_crane_k_data(data[0])
1120
                    if find_row is None:
1121
                        row = self.ui.tableWidget_CraneK_SelectedFitting.rowCount()
1122
                        self.ui.tableWidget_CraneK_SelectedFitting.setRowCount(row + 1)
1123
                        self.add_crane_k_data(row, data, count)
1124
                    else:
1125
                        self.update_crane_k_data(find_row, data, count)
1126
            elif self.sender() == self.ui.pushButton_Add_CraneK_Check_Valves_Tilting:
1127
                count = self.ui.lineEdit_CraneK_Check_Valves_Tilting_Count.text()
1128
                if count.isdigit():
1129
                    data = self.ui.comboBox_CraneK_Check_Valves_Tilting.currentData()
1130
                    find_row = self.find_crane_k_data(data[0])
1131
                    if find_row is None:
1132
                        row = self.ui.tableWidget_CraneK_SelectedFitting.rowCount()
1133
                        self.ui.tableWidget_CraneK_SelectedFitting.setRowCount(row + 1)
1134
                        self.add_crane_k_data(row, data, count)
1135
                    else:
1136
                        self.update_crane_k_data(find_row, data, count)
1137
            elif self.sender() == self.ui.pushButton_Add_CraneK_Check_Valves_Globe_Stop:
1138
                count = self.ui.lineEdit_CraneK_Check_Valves_Globe_Stop_Count.text()
1139
                if count.isdigit():
1140
                    data = self.ui.comboBox_CraneK_Check_Valves_Globe_Stop.currentData()
1141
                    find_row = self.find_crane_k_data(data[0])
1142
                    if find_row is None:
1143
                        row = self.ui.tableWidget_CraneK_SelectedFitting.rowCount()
1144
                        self.ui.tableWidget_CraneK_SelectedFitting.setRowCount(row + 1)
1145
                        self.add_crane_k_data(row, data, count)
1146
                    else:
1147
                        self.update_crane_k_data(find_row, data, count)
1148
            elif self.sender() == self.ui.pushButton_Add_CraneK_Check_Valves_Angle_Stop:
1149
                count = self.ui.lineEdit_CraneK_Check_Valves_Angle_Stop_Count.text()
1150
                if count.isdigit():
1151
                    data = self.ui.comboBox_CraneK_Check_Valves_Angle_Stop.currentData()
1152
                    find_row = self.find_crane_k_data(data[0])
1153
                    if find_row is None:
1154
                        row = self.ui.tableWidget_CraneK_SelectedFitting.rowCount()
1155
                        self.ui.tableWidget_CraneK_SelectedFitting.setRowCount(row + 1)
1156
                        self.add_crane_k_data(row, data, count)
1157
                    else:
1158
                        self.update_crane_k_data(find_row, data, count)
1159
            # Manual K
1160
            elif self.sender() == self.ui.pushButton_Add_CraneK_Manual:
1161
                count = self.ui.lineEdit_CraneK_Manual_Count.text()
1162
                if count.isdigit():
1163
                    data = self.ui.comboBox_CraneK_Manual.currentData()
1164
                    find_row = self.find_crane_k_data(data[0])
1165
                    if find_row is None:
1166
                        row = self.ui.tableWidget_CraneK_SelectedFitting.rowCount()
1167
                        self.ui.tableWidget_CraneK_SelectedFitting.setRowCount(row + 1)
1168
                        self.add_crane_k_data(row, data, count)
1169
                    else:
1170
                        self.update_crane_k_data(find_row, data, count)
1171

    
1172
            # self.ui.tableWidget_CraneK_SelectedFitting.resizeColumnsToContents()
1173
            # self.ui.tableWidget_CraneK_SelectedFitting.resizeRowsToContents()
1174
            # self.ui.tableWidget_CraneK_SelectedFitting.horizontalHeader().setStretchLastSection(True)
1175
        except Exception as ex:
1176
            from App import App
1177
            from AppDocData import MessageType
1178

    
1179
            message = 'error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename,
1180
                                                           sys.exc_info()[-1].tb_lineno)
1181
            App.mainWnd().addMessage.emit(MessageType.Error, message)
1182

    
1183
    def find_2_k_data(self, uid):
1184
        find_row = None
1185

    
1186
        row_count = self.ui.tableWidget_2K_SelectedFitting.rowCount()
1187
        for row in range(row_count):
1188
            if self.ui.tableWidget_2K_SelectedFitting.item(row, 0).text() == uid:
1189
                return row
1190

    
1191
        return find_row
1192

    
1193
    def find_equivalent_length_data(self, uid):
1194
        find_row = None
1195

    
1196
        row_count = self.ui.tableWidget_Equivalent_Length_SelectedFitting.rowCount()
1197
        for row in range(row_count):
1198
            if self.ui.tableWidget_Equivalent_Length_SelectedFitting.item(row, 0).text() == uid:
1199
                return row
1200

    
1201
        return find_row
1202

    
1203
    def find_crane_k_data(self, uid):
1204
        find_row = None
1205

    
1206
        row_count = self.ui.tableWidget_CraneK_SelectedFitting.rowCount()
1207
        for row in range(row_count):
1208
            if self.ui.tableWidget_CraneK_SelectedFitting.item(row, 0).text() == uid:
1209
                return row
1210

    
1211
        return find_row
1212

    
1213
    def update_2_k_data(self, row, data, count):
1214
        try:
1215
            self.ui.tableWidget_2K_SelectedFitting.setItem(row, 5, set_item_properties(count,
1216
                                                                                       Qt.AlignHCenter | Qt.AlignVCenter))
1217

    
1218
            selected_fitting = '{} x {} = {}'.format(data[4], count, int(count) * data[5])
1219
            self.ui.tableWidget_2K_SelectedFitting.setItem(row, 8, set_item_properties(selected_fitting,
1220
                                                                                       Qt.AlignLeft | Qt.AlignVCenter))
1221

    
1222
            self.ui.tableWidget_2K_SelectedFitting.resizeRowsToContents()
1223
        except Exception as ex:
1224
            from App import App
1225
            from AppDocData import MessageType
1226

    
1227
            message = 'error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename,
1228
                                                           sys.exc_info()[-1].tb_lineno)
1229
            App.mainWnd().addMessage.emit(MessageType.Error, message)
1230

    
1231
    def update_equivalent_length_data(self, row, count, angle=None):
1232
        try:
1233
            name = self.ui.tableWidget_Equivalent_Length_SelectedFitting.item(row, 4).text()
1234
            self.ui.tableWidget_Equivalent_Length_SelectedFitting.setItem(row, 5,
1235
                                                                          set_item_properties(count,
1236
                                                                                              Qt.AlignHCenter | Qt.AlignVCenter))
1237
            if angle:
1238
                self.ui.tableWidget_Equivalent_Length_SelectedFitting.setItem(row, 6,
1239
                                                                              set_item_properties(angle,
1240
                                                                                                  Qt.AlignHCenter | Qt.AlignVCenter))
1241

    
1242
            selected_fitting = '{} ({}˚) x {}'.format(name, angle, count) if angle else '{} x {}'.format(name, count)
1243

    
1244
            self.ui.tableWidget_Equivalent_Length_SelectedFitting.setItem(row, 7,
1245
                                                                          set_item_properties(
1246
                                                                              selected_fitting,
1247
                                                                              Qt.AlignLeft | Qt.AlignVCenter))
1248

    
1249
            self.ui.tableWidget_Equivalent_Length_SelectedFitting.resizeRowsToContents()
1250
        except Exception as ex:
1251
            from App import App
1252
            from AppDocData import MessageType
1253

    
1254
            message = 'error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename,
1255
                                                           sys.exc_info()[-1].tb_lineno)
1256
            App.mainWnd().addMessage.emit(MessageType.Error, message)
1257

    
1258
    def update_crane_k_data(self, row, data, count, sub_size=None, angle=None):
1259
        try:
1260
            self.ui.tableWidget_CraneK_SelectedFitting.item(row, 5).setText(str(count))
1261
            if sub_size:
1262
                self.ui.tableWidget_CraneK_SelectedFitting.item(row, 7).setText(str(sub_size))
1263
            if angle:
1264
                self.ui.tableWidget_CraneK_SelectedFitting.item(row, 8).setTextx(str(angle))
1265

    
1266
            self.ui.tableWidget_CraneK_SelectedFitting.item(row, 5)
1267

    
1268
            k = self.get_crane_k_resistance_coefficient(data[4], data[5], sub_size, angle)
1269
            cell = set_item_properties(format(k, ".3f"), Qt.AlignRight | Qt.AlignVCenter)
1270
            self.ui.tableWidget_CraneK_SelectedFitting.setItem(row, 9, cell)
1271

    
1272
            selected_fitting = '{} x {} = {}'.format(data[4], count, format(int(count) * k, ".3f"))
1273
            cell = set_item_properties(selected_fitting, Qt.AlignLeft | Qt.AlignVCenter)
1274
            self.ui.tableWidget_CraneK_SelectedFitting.setItem(row, 11, cell)
1275

    
1276
            self.ui.tableWidget_CraneK_SelectedFitting.resizeRowsToContents()
1277
        except Exception as ex:
1278
            from App import App
1279
            from AppDocData import MessageType
1280

    
1281
            message = 'error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename,
1282
                                                           sys.exc_info()[-1].tb_lineno)
1283
            App.mainWnd().addMessage.emit(MessageType.Error, message)
1284

    
1285
    def del_2_k_data(self, row):
1286
        try:
1287
            self.ui.tableWidget_2K_SelectedFitting.removeRow(row)
1288
        except Exception as ex:
1289
            from App import App
1290
            from AppDocData import MessageType
1291

    
1292
            message = 'error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename,
1293
                                                           sys.exc_info()[-1].tb_lineno)
1294
            App.mainWnd().addMessage.emit(MessageType.Error, message)
1295

    
1296
    def del_equivalent_length_data(self, row):
1297
        try:
1298
            self.ui.tableWidget_Equivalent_Length_SelectedFitting.removeRow(row)
1299
        except Exception as ex:
1300
            from App import App
1301
            from AppDocData import MessageType
1302

    
1303
            message = 'error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename,
1304
                                                           sys.exc_info()[-1].tb_lineno)
1305
            App.mainWnd().addMessage.emit(MessageType.Error, message)
1306

    
1307
    def del_crane_k_data(self, row):
1308
        try:
1309
            self.ui.tableWidget_CraneK_SelectedFitting.removeRow(row)
1310
        except Exception as ex:
1311
            from App import App
1312
            from AppDocData import MessageType
1313

    
1314
            message = 'error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename,
1315
                                                           sys.exc_info()[-1].tb_lineno)
1316
            App.mainWnd().addMessage.emit(MessageType.Error, message)
1317

    
1318
    def add_2_k_data(self, row, data, count):
1319
        # data[0] = uid
1320
        # data[1] = method Equivalent_Length, CraneK, 2-K
1321
        # data[2] = category
1322
        # data[3] = type
1323
        # data[4] = name
1324
        # data[5] = k
1325
        # data[6] = image
1326

    
1327
        try:
1328
            self.ui.tableWidget_2K_SelectedFitting.setItem(row, 0, set_item_properties(data[0],
1329
                                                                                       Qt.AlignLeft | Qt.AlignVCenter))
1330
            self.ui.tableWidget_2K_SelectedFitting.setItem(row, 1, set_item_properties(data[1],
1331
                                                                                       Qt.AlignLeft | Qt.AlignVCenter))
1332
            self.ui.tableWidget_2K_SelectedFitting.setItem(row, 2, set_item_properties(data[2],
1333
                                                                                       Qt.AlignLeft | Qt.AlignVCenter))
1334
            self.ui.tableWidget_2K_SelectedFitting.setItem(row, 3, set_item_properties(data[3],
1335
                                                                                       Qt.AlignLeft | Qt.AlignVCenter))
1336
            self.ui.tableWidget_2K_SelectedFitting.setItem(row, 4, set_item_properties(data[4],
1337
                                                                                       Qt.AlignLeft | Qt.AlignVCenter))
1338
            self.ui.tableWidget_2K_SelectedFitting.setItem(row, 5, set_item_properties(count,
1339
                                                                                       Qt.AlignHCenter | Qt.AlignVCenter))
1340
            k = data[5]
1341

    
1342
            self.ui.tableWidget_2K_SelectedFitting.setItem(row, 6, set_item_properties(k,
1343
                                                                                       Qt.AlignRight | Qt.AlignVCenter))
1344

    
1345
            self.ui.tableWidget_2K_SelectedFitting.setItem(row, 7, set_item_properties(data[6],
1346
                                                                                       Qt.AlignLeft | Qt.AlignVCenter))
1347

    
1348
            selected_fitting = '{} x {} = {}'.format(data[4], count, int(count) * k)
1349
            self.ui.tableWidget_2K_SelectedFitting.setItem(row, 8, set_item_properties(selected_fitting,
1350
                                                                                       Qt.AlignLeft | Qt.AlignVCenter))
1351

    
1352
            # total_k = int(count) * k
1353
            # self.ui.tableWidget_2K_SelectedFitting.setItem(row, 8, set_table_widget_item_properties(total_k,
1354
            #                                                                                        Qt.AlignRight | Qt.AlignVCenter))
1355

    
1356
            self.ui.tableWidget_2K_SelectedFitting.resizeRowsToContents()
1357

    
1358
        except Exception as ex:
1359
            from App import App
1360
            from AppDocData import MessageType
1361

    
1362
            message = 'error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename,
1363
                                                           sys.exc_info()[-1].tb_lineno)
1364
            App.mainWnd().addMessage.emit(MessageType.Error, message)
1365

    
1366
    def add_equivalent_length_data(self, row, data, count, angle=None):
1367
        # data[0] = uid
1368
        # data[1] = method Equivalent_Length, CraneK, 2-K
1369
        # data[2] = category
1370
        # data[3] = type
1371
        # data[4] = name
1372

    
1373
        try:
1374
            self.ui.tableWidget_Equivalent_Length_SelectedFitting.setItem(row, 0,
1375
                                                                          set_item_properties(data[0],
1376
                                                                                              Qt.AlignLeft | Qt.AlignVCenter))
1377
            self.ui.tableWidget_Equivalent_Length_SelectedFitting.setItem(row, 1,
1378
                                                                          set_item_properties(data[1],
1379
                                                                                              Qt.AlignLeft | Qt.AlignVCenter))
1380
            self.ui.tableWidget_Equivalent_Length_SelectedFitting.setItem(row, 2,
1381
                                                                          set_item_properties(data[2],
1382
                                                                                              Qt.AlignLeft | Qt.AlignVCenter))
1383
            self.ui.tableWidget_Equivalent_Length_SelectedFitting.setItem(row, 3,
1384
                                                                          set_item_properties(data[3],
1385
                                                                                              Qt.AlignLeft | Qt.AlignVCenter))
1386
            self.ui.tableWidget_Equivalent_Length_SelectedFitting.setItem(row, 4,
1387
                                                                          set_item_properties(data[4],
1388
                                                                                              Qt.AlignLeft | Qt.AlignVCenter))
1389
            self.ui.tableWidget_Equivalent_Length_SelectedFitting.setItem(row, 5,
1390
                                                                          set_item_properties(count,
1391
                                                                                              Qt.AlignHCenter | Qt.AlignVCenter))
1392
            if angle:
1393
                self.ui.tableWidget_Equivalent_Length_SelectedFitting.setItem(row, 6,
1394
                                                                              set_item_properties(angle,
1395
                                                                                                  Qt.AlignHCenter | Qt.AlignVCenter))
1396

    
1397
            selected_fitting = '{} ({}˚) x {}'.format(data[4], angle, count) if angle else '{} x {}'.format(data[4],
1398
                                                                                                            count)
1399

    
1400
            self.ui.tableWidget_Equivalent_Length_SelectedFitting.setItem(row, 7, set_item_properties(
1401
                selected_fitting,
1402
                Qt.AlignLeft | Qt.AlignVCenter))
1403

    
1404
            self.ui.tableWidget_Equivalent_Length_SelectedFitting.resizeRowsToContents()
1405
        except Exception as ex:
1406
            from App import App
1407
            from AppDocData import MessageType
1408

    
1409
            message = 'error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename,
1410
                                                           sys.exc_info()[-1].tb_lineno)
1411
            App.mainWnd().addMessage.emit(MessageType.Error, message)
1412

    
1413
    def add_crane_k_data(self, row, data, count, sub_size=None, angle=None):
1414
        # data[0] = uid
1415
        # data[1] = method Equivalent_Length, CraneK, 2-K
1416
        # data[2] = category
1417
        # data[3] = type
1418
        # data[4] = name
1419
        # data[5] = k
1420
        # data[6] = image
1421
        try:
1422
            self.ui.tableWidget_CraneK_SelectedFitting.setItem(row, 0, set_item_properties(data[0],
1423
                                                                                           Qt.AlignLeft | Qt.AlignVCenter))
1424
            self.ui.tableWidget_CraneK_SelectedFitting.setItem(row, 1, set_item_properties(data[1],
1425
                                                                                           Qt.AlignLeft | Qt.AlignVCenter))
1426
            self.ui.tableWidget_CraneK_SelectedFitting.setItem(row, 2, set_item_properties(data[2],
1427
                                                                                           Qt.AlignLeft | Qt.AlignVCenter))
1428
            self.ui.tableWidget_CraneK_SelectedFitting.setItem(row, 3, set_item_properties(data[3],
1429
                                                                                           Qt.AlignLeft | Qt.AlignVCenter))
1430
            self.ui.tableWidget_CraneK_SelectedFitting.setItem(row, 4, set_item_properties(data[4],
1431
                                                                                           Qt.AlignLeft | Qt.AlignVCenter))
1432
            self.ui.tableWidget_CraneK_SelectedFitting.setItem(row, 5, set_item_properties(count,
1433
                                                                                           Qt.AlignHCenter | Qt.AlignVCenter))
1434
            self.ui.tableWidget_CraneK_SelectedFitting.setItem(row, 6, set_item_properties(self.nps,
1435
                                                                                           Qt.AlignHCenter | Qt.AlignVCenter))
1436
            if sub_size:
1437
                self.ui.tableWidget_CraneK_SelectedFitting.setItem(row, 7,
1438
                                                                   set_item_properties(sub_size,
1439
                                                                                       Qt.AlignHCenter | Qt.AlignVCenter))
1440
            if angle:
1441
                self.ui.tableWidget_CraneK_SelectedFitting.setItem(row, 8, set_item_properties(angle,
1442
                                                                                               Qt.AlignHCenter | Qt.AlignVCenter))
1443
            k = self.get_crane_k_resistance_coefficient(data[4], data[5], sub_size, angle)
1444
            cell = set_item_properties(format(k, ".3f"), Qt.AlignRight | Qt.AlignVCenter)
1445
            self.ui.tableWidget_CraneK_SelectedFitting.setItem(row, 9, cell)
1446

    
1447
            self.ui.tableWidget_CraneK_SelectedFitting.setItem(row, 10, set_item_properties(data[6],
1448
                                                                                            Qt.AlignLeft | Qt.AlignVCenter))
1449

    
1450
            selected_fitting = '{} x {} = {}'.format(data[4], count, format(int(count) * k, ".3f"))
1451
            cell = set_item_properties(selected_fitting, Qt.AlignLeft | Qt.AlignVCenter)
1452
            self.ui.tableWidget_CraneK_SelectedFitting.setItem(row, 11, cell)
1453

    
1454
            self.ui.tableWidget_CraneK_SelectedFitting.resizeRowsToContents()
1455
        except Exception as ex:
1456
            from App import App
1457
            from AppDocData import MessageType
1458

    
1459
            message = 'error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename,
1460
                                                           sys.exc_info()[-1].tb_lineno)
1461
            App.mainWnd().addMessage.emit(MessageType.Error, message)
1462

    
1463
    def get_crane_k_resistance_coefficient(self, name, k, sub_size=None, angle=None):
1464
        if name == 'Butterfly Valve':
1465
            if self.selected_dia_in <= 8:
1466
                return self.friction_factor * 45
1467
            elif 10 <= self.selected_dia_in <= 14:
1468
                return self.friction_factor * 35
1469
            elif 16 <= self.selected_dia_in:
1470
                return self.friction_factor * 25
1471
        elif name == 'Tilting-disk Check Valve (α=5 ˚)':
1472
            if self.selected_dia_in <= 8:
1473
                return self.friction_factor * 40
1474
            elif 10 <= self.selected_dia_in <= 14:
1475
                return self.friction_factor * 30
1476
            elif 16 <= self.selected_dia_in:
1477
                return self.friction_factor * 20
1478
        elif name == 'Tilting-disk Check Valve (α=15 ˚)':
1479
            if self.selected_dia_in <= 8:
1480
                return self.friction_factor * 120
1481
            elif 10 <= self.selected_dia_in <= 14:
1482
                return self.friction_factor * 90
1483
            elif 16 <= self.selected_dia_in:
1484
                return self.friction_factor * 60
1485
        elif name == 'Reducer':
1486
            if float(angle) > 180:
1487
                angle = 180
1488
            # I128 = self.selected_dia_in
1489
            # J128 = self.friction_factor
1490
            # J203 = sub_size
1491
            # K203 = angle
1492
            # =IF(K203 <= 45, 0.8 * SIN(RADIANS(K203 / 2)) * (1 - (J203 / I128) ^ 2) / (J203 / I128) ^ 4,
1493
            #    0.5 * (1 - (J203 / I128) ^ 2) * POWER(SIN(RADIANS(K203 / 2)), 0.5) / (J203 / I128) ^ 4)
1494

    
1495
            if float(angle) <= 45:
1496
                return 0.8 * math.sin(math.radians(float(angle) / 2)) * (
1497
                        1 - (float(sub_size) / self.selected_dia_in) ** 2) / (
1498
                               float(sub_size) / self.selected_dia_in) ** 4
1499
            else:
1500
                return 0.5 * (1 - (float(sub_size) / self.selected_dia_in) ** 2) * math.pow(
1501
                    math.sin(math.radians(float(angle) / 2)), 0.5) / (float(sub_size) / self.selected_dia_in) ** 4
1502
        elif name == 'Expander':
1503
            if float(angle) > 180:
1504
                angle = 180
1505

    
1506
            # I128 = self.selected_dia_in
1507
            # J128 = self.friction_factor
1508
            # J204 = sub_size
1509
            # K204 = angle
1510
            # =IF(K204 <= 45, 2.6 * SIN(RADIANS(K204 / 2)) * (1 - (I128 / J204) ^ 2) ^ 2 / (I128 / J204) ^ 4,
1511
            #    (1 - (I128 / J204) ^ 2) ^ 2 / (I128 / J204) ^ 4)
1512
            if float(angle) <= 45:
1513
                return 2.6 * math.sin(math.radians(float(angle) / 2)) * (
1514
                            1 - (self.selected_dia_in / float(sub_size)) ** 2) ** 2
1515
            else:
1516
                return (1 - (self.selected_dia_in / float(sub_size)) ** 2) ** 2
1517
        elif name[:4] == 'Pipe' or name == 'User Input':
1518
            return k
1519
        else:
1520
            return k * self.friction_factor
1521

    
1522
    def initialize_2_k_selected_fitting(self):
1523
        self.ui.tableWidget_2K_SelectedFitting.setColumnCount(9)
1524
        self.ui.tableWidget_2K_SelectedFitting.hideColumn(0)  # uid
1525
        self.ui.tableWidget_2K_SelectedFitting.hideColumn(1)  # method
1526
        # self.ui.tableWidget_2K_SelectedFitting.hideColumn(2)  # category
1527
        self.ui.tableWidget_2K_SelectedFitting.hideColumn(3)  # type
1528
        self.ui.tableWidget_2K_SelectedFitting.hideColumn(4)  # Name
1529
        self.ui.tableWidget_2K_SelectedFitting.hideColumn(5)  # Count
1530
        # self.ui.tableWidget_2K_SelectedFitting.hideColumn(6)  # K
1531
        self.ui.tableWidget_2K_SelectedFitting.hideColumn(7)  # Image
1532
        # self.ui.tableWidget_2K_SelectedFitting.hideColumn(8)  # Selected Fitting
1533

    
1534
        self.ui.tableWidget_2K_SelectedFitting.setEditTriggers(QAbstractItemView.NoEditTriggers)
1535

    
1536
        col_names = ['UID', 'Method', 'Category', 'Type', 'Name', 'Count', 'K', 'Image', 'Selected Fitting']
1537
        self.ui.tableWidget_2K_SelectedFitting.setHorizontalHeaderLabels(col_names)
1538
        self.ui.tableWidget_2K_SelectedFitting.verticalHeader().setVisible(True)
1539

    
1540
        self.ui.tableWidget_2K_SelectedFitting.horizontalHeader().setStretchLastSection(True)
1541
        self.ui.tableWidget_2K_SelectedFitting.horizontalHeader().setSectionResizeMode(0, QHeaderView.ResizeToContents)
1542
        self.ui.tableWidget_2K_SelectedFitting.horizontalHeader().setSectionResizeMode(1, QHeaderView.ResizeToContents)
1543
        self.ui.tableWidget_2K_SelectedFitting.horizontalHeader().setSectionResizeMode(2, QHeaderView.ResizeToContents)
1544
        self.ui.tableWidget_2K_SelectedFitting.horizontalHeader().setSectionResizeMode(3, QHeaderView.ResizeToContents)
1545
        self.ui.tableWidget_2K_SelectedFitting.horizontalHeader().setSectionResizeMode(4, QHeaderView.ResizeToContents)
1546
        self.ui.tableWidget_2K_SelectedFitting.horizontalHeader().setSectionResizeMode(5, QHeaderView.ResizeToContents)
1547
        self.ui.tableWidget_2K_SelectedFitting.horizontalHeader().setSectionResizeMode(6, QHeaderView.ResizeToContents)
1548
        self.ui.tableWidget_2K_SelectedFitting.horizontalHeader().setSectionResizeMode(7, QHeaderView.ResizeToContents)
1549
        self.ui.tableWidget_2K_SelectedFitting.horizontalHeader().setSectionResizeMode(8, QHeaderView.ResizeToContents)
1550

    
1551
        self.ui.tableWidget_2K_SelectedFitting.currentItemChanged.connect(self.fitting_2_k_item_selection_changed)
1552

    
1553
    def initialize_equivalent_length_selected_fitting(self):
1554

    
1555
        self.ui.tableWidget_Equivalent_Length_SelectedFitting.setColumnCount(8)
1556
        self.ui.tableWidget_Equivalent_Length_SelectedFitting.hideColumn(0)  # uid
1557
        self.ui.tableWidget_Equivalent_Length_SelectedFitting.hideColumn(1)  # method
1558
        self.ui.tableWidget_Equivalent_Length_SelectedFitting.hideColumn(2)  # category
1559
        self.ui.tableWidget_Equivalent_Length_SelectedFitting.hideColumn(3)  # type
1560
        self.ui.tableWidget_Equivalent_Length_SelectedFitting.hideColumn(4)  # Name
1561
        self.ui.tableWidget_Equivalent_Length_SelectedFitting.hideColumn(5)  # Count
1562
        self.ui.tableWidget_Equivalent_Length_SelectedFitting.hideColumn(6)  # Angle
1563
        # self.ui.tableWidget_Equivalent_Length_SelectedFitting.hideColumn(7)  # Selected Fitting
1564

    
1565
        self.ui.tableWidget_Equivalent_Length_SelectedFitting.setEditTriggers(QAbstractItemView.NoEditTriggers)
1566

    
1567
        col_names = ['UID', 'Method', 'Category', 'Type', 'Name', 'Count', 'Angle', 'Selected Fitting']
1568
        self.ui.tableWidget_Equivalent_Length_SelectedFitting.setHorizontalHeaderLabels(col_names)
1569
        self.ui.tableWidget_Equivalent_Length_SelectedFitting.verticalHeader().setVisible(True)
1570

    
1571
        self.ui.tableWidget_Equivalent_Length_SelectedFitting.horizontalHeader().setStretchLastSection(True)
1572

    
1573
        self.ui.tableWidget_Equivalent_Length_SelectedFitting.horizontalHeader().setSectionResizeMode(0,
1574
                                                                                                      QHeaderView.ResizeToContents)
1575
        self.ui.tableWidget_Equivalent_Length_SelectedFitting.horizontalHeader().setSectionResizeMode(1,
1576
                                                                                                      QHeaderView.ResizeToContents)
1577
        self.ui.tableWidget_Equivalent_Length_SelectedFitting.horizontalHeader().setSectionResizeMode(2,
1578
                                                                                                      QHeaderView.ResizeToContents)
1579
        self.ui.tableWidget_Equivalent_Length_SelectedFitting.horizontalHeader().setSectionResizeMode(3,
1580
                                                                                                      QHeaderView.ResizeToContents)
1581
        self.ui.tableWidget_Equivalent_Length_SelectedFitting.horizontalHeader().setSectionResizeMode(4,
1582
                                                                                                      QHeaderView.ResizeToContents)
1583
        self.ui.tableWidget_Equivalent_Length_SelectedFitting.horizontalHeader().setSectionResizeMode(5,
1584
                                                                                                      QHeaderView.ResizeToContents)
1585
        self.ui.tableWidget_Equivalent_Length_SelectedFitting.horizontalHeader().setSectionResizeMode(6,
1586
                                                                                                      QHeaderView.ResizeToContents)
1587
        self.ui.tableWidget_Equivalent_Length_SelectedFitting.horizontalHeader().setSectionResizeMode(7,
1588
                                                                                                      QHeaderView.ResizeToContents)
1589

    
1590
    def initialize_crane_k_selected_fitting(self):
1591
        self.ui.tableWidget_CraneK_SelectedFitting.setColumnCount(12)
1592
        self.ui.tableWidget_CraneK_SelectedFitting.hideColumn(0)  # uid
1593
        self.ui.tableWidget_CraneK_SelectedFitting.hideColumn(1)  # method
1594
        # self.ui.tableWidget_CraneK_SelectedFitting.hideColumn(2)  # category
1595
        self.ui.tableWidget_CraneK_SelectedFitting.hideColumn(3)  # type
1596
        self.ui.tableWidget_CraneK_SelectedFitting.hideColumn(4)  # Name
1597
        self.ui.tableWidget_CraneK_SelectedFitting.hideColumn(5)  # Count
1598
        self.ui.tableWidget_CraneK_SelectedFitting.hideColumn(6)  # Size(M)
1599
        self.ui.tableWidget_CraneK_SelectedFitting.hideColumn(7)  # Size(S)
1600
        self.ui.tableWidget_CraneK_SelectedFitting.hideColumn(8)  # Angle
1601
        # self.ui.tableWidget_CraneK_SelectedFitting.hideColumn(9)  # K
1602
        self.ui.tableWidget_CraneK_SelectedFitting.hideColumn(10)  # Image
1603
        # self.ui.tableWidget_CraneK_SelectedFitting.hideColumn(11)  # Selected Fitting
1604

    
1605
        # self.ui.tableWidget_CraneK_SelectedFitting.setEditTriggers(QAbstractItemView.NoEditTriggers)
1606

    
1607
        col_names = ['UID', 'Method', 'Category', 'Type', 'Name', 'Count', 'Size(M)', 'Size(S)', 'Angle', 'K', 'Image',
1608
                     'Selected Fitting']
1609
        self.ui.tableWidget_CraneK_SelectedFitting.setHorizontalHeaderLabels(col_names)
1610
        self.ui.tableWidget_CraneK_SelectedFitting.verticalHeader().setVisible(True)
1611

    
1612
        self.ui.tableWidget_CraneK_SelectedFitting.horizontalHeader().setStretchLastSection(True)
1613
        self.ui.tableWidget_CraneK_SelectedFitting.horizontalHeader().setSectionResizeMode(0,
1614
                                                                                           QHeaderView.ResizeToContents)
1615
        self.ui.tableWidget_CraneK_SelectedFitting.horizontalHeader().setSectionResizeMode(1,
1616
                                                                                           QHeaderView.ResizeToContents)
1617
        self.ui.tableWidget_CraneK_SelectedFitting.horizontalHeader().setSectionResizeMode(2,
1618
                                                                                           QHeaderView.ResizeToContents)
1619
        self.ui.tableWidget_CraneK_SelectedFitting.horizontalHeader().setSectionResizeMode(3,
1620
                                                                                           QHeaderView.ResizeToContents)
1621
        self.ui.tableWidget_CraneK_SelectedFitting.horizontalHeader().setSectionResizeMode(4,
1622
                                                                                           QHeaderView.ResizeToContents)
1623
        self.ui.tableWidget_CraneK_SelectedFitting.horizontalHeader().setSectionResizeMode(5,
1624
                                                                                           QHeaderView.ResizeToContents)
1625
        self.ui.tableWidget_CraneK_SelectedFitting.horizontalHeader().setSectionResizeMode(6,
1626
                                                                                           QHeaderView.ResizeToContents)
1627
        self.ui.tableWidget_CraneK_SelectedFitting.horizontalHeader().setSectionResizeMode(7,
1628
                                                                                           QHeaderView.ResizeToContents)
1629
        self.ui.tableWidget_CraneK_SelectedFitting.horizontalHeader().setSectionResizeMode(8,
1630
                                                                                           QHeaderView.ResizeToContents)
1631
        self.ui.tableWidget_CraneK_SelectedFitting.horizontalHeader().setSectionResizeMode(9,
1632
                                                                                           QHeaderView.ResizeToContents)
1633
        self.ui.tableWidget_CraneK_SelectedFitting.horizontalHeader().setSectionResizeMode(10,
1634
                                                                                           QHeaderView.ResizeToContents)
1635
        self.ui.tableWidget_CraneK_SelectedFitting.horizontalHeader().setSectionResizeMode(11,
1636
                                                                                           QHeaderView.ResizeToContents)
1637

    
1638
        self.ui.tableWidget_CraneK_SelectedFitting.currentItemChanged.connect(self.crane_k_item_selection_changed)
1639

    
1640
    def fitting_2_k_item_selection_changed(self, item):
1641
        row = self.ui.tableWidget_2K_SelectedFitting.row(item)
1642
        image = self.ui.tableWidget_2K_SelectedFitting.item(row, 7).text()
1643
        picture = QtGui.QPixmap(':/images/{}'.format(image))
1644
        w = 150  # self.ui.label_CraneK_Img.height()
1645
        h = 150  # self.ui.label_CraneK_Img.width()
1646
        self.ui.label_2K_Img.setPixmap(
1647
            picture.scaled(w, h, QtCore.Qt.KeepAspectRatio, QtCore.Qt.FastTransformation))
1648

    
1649
    def crane_k_item_selection_changed(self, item):
1650
        row = self.ui.tableWidget_CraneK_SelectedFitting.row(item)
1651
        image = self.ui.tableWidget_CraneK_SelectedFitting.item(row, 10).text()
1652
        picture = QtGui.QPixmap(':/images/{}'.format(image))
1653
        w = 150  # self.ui.label_CraneK_Img.height()
1654
        h = 150  # self.ui.label_CraneK_Img.width()
1655
        self.ui.label_CraneK_Img.setPixmap(
1656
            picture.scaled(w, h, QtCore.Qt.KeepAspectRatio, QtCore.Qt.FastTransformation))
1657

    
1658
    def controls_equivalent_length_set_names(self):
1659
        from AppDocData import AppDocData
1660

    
1661
        fittings = AppDocData.instance().get_fittings_by_method('Equivalent_Length')
1662
        for fitting in fittings:
1663
            category = fitting[2]
1664
            type = fitting[3]
1665
            name = fitting[4]
1666

    
1667
            if category == 'Valves':
1668
                if type == 'Globe':
1669
                    self.ui.comboBox_Equivalent_Length_Globe.addItem(name, fitting)
1670
                elif type == 'Gate_Ball_Plug':
1671
                    self.ui.comboBox_Equivalent_Length_Gate_Ball_Plug.addItem(name, fitting)
1672
                elif type == 'Check':
1673
                    self.ui.comboBox_Equivalent_Length_Check.addItem(name, fitting)
1674
                elif type == 'Butterfly':
1675
                    self.ui.comboBox_Equivalent_Length_Butterfly.addItem(name, fitting)
1676
            elif category == 'Tees':
1677
                if type == 'Tee through':
1678
                    self.ui.comboBox_Equivalent_Length_Tee_Through.addItem(name, fitting)
1679
                elif type == 'Tee branch':
1680
                    self.ui.comboBox_Equivalent_Length_Tee_Branch.addItem(name, fitting)
1681
            elif category == 'Nozzles':
1682
                if type == 'Nozzle Out':
1683
                    self.ui.comboBox_Equivalent_Length_Nozzle_Out.addItem(name, fitting)
1684
                elif type == 'Nozzle In':
1685
                    self.ui.comboBox_Equivalent_Length_Nozzle_In.addItem(name, fitting)
1686
            elif category == 'Elbow':
1687
                if type == 'Miter':
1688
                    self.ui.comboBox_Equivalent_Length_Miter.addItem(name, fitting)
1689
                elif type == '90 Elbow':
1690
                    self.ui.comboBox_Equivalent_Length_90_Elbow.addItem(name, fitting)
1691
                elif type == '45 Elbow':
1692
                    self.ui.comboBox_Equivalent_Length_45_Elbow.addItem(name, fitting)
1693

    
1694
    def controls_crane_k_set_names(self):
1695
        from AppDocData import AppDocData
1696

    
1697
        fittings = AppDocData.instance().get_fittings_by_method('CraneK')
1698
        for fitting in fittings:
1699
            category = fitting[2]
1700
            type = fitting[3]
1701
            name = fitting[4]
1702

    
1703
            if category == '90 Elbow':
1704
                if type == 'Standard':
1705
                    self.ui.comboBox_CraneK_90_Elbow_Standard.addItem(name, fitting)
1706
                elif type == 'Bend':
1707
                    self.ui.comboBox_CraneK_90_Elbow_Bend.addItem(name, fitting)
1708
                elif type == 'Miter':
1709
                    self.ui.comboBox_CraneK_90_Elbow_Miter.addItem(name, fitting)
1710
            elif category == '45 Elbow':
1711
                if type == 'Standard':
1712
                    self.ui.comboBox_CraneK_45_Elbow_Standard.addItem(name, fitting)
1713
                elif type == 'Miter':
1714
                    self.ui.comboBox_CraneK_45_Elbow_Miter.addItem(name, fitting)
1715
            elif category == '180 Elbow':
1716
                if type == 'Standard':
1717
                    self.ui.comboBox_CraneK_180_Elbow_Standard.addItem(name, fitting)
1718
                elif type == 'Bend':
1719
                    self.ui.comboBox_CraneK_180_Elbow_Bend.addItem(name, fitting)
1720
                elif type == 'Miter':
1721
                    self.ui.comboBox_CraneK_180_Elbow_Miter.addItem(name, fitting)
1722
            elif category == 'Tees':
1723
                if type == 'Standard':
1724
                    self.ui.comboBox_CraneK_Tees.addItem(name, fitting)
1725
            elif category == 'Reducer/Expander':
1726
                if type == 'Reducer':
1727
                    self.ui.comboBox_CraneK_Reducer.addItem(name, fitting)
1728
                elif type == 'Expander':
1729
                    self.ui.comboBox_CraneK_Expander.addItem(name, fitting)
1730
            elif category == 'Etc Valves':
1731
                if type == 'Etc':
1732
                    self.ui.comboBox_CraneK_Valves_Etc.addItem(name, fitting)
1733
            elif category == 'Foot Valves':
1734
                if type == 'Foot':
1735
                    self.ui.comboBox_CraneK_Valves_Foot.addItem(name, fitting)
1736
            elif category == 'Globe Valves':
1737
                if type == 'Globe':
1738
                    self.ui.comboBox_CraneK_Valves_Globe.addItem(name, fitting)
1739
            elif category == 'Manual':
1740
                if type == 'Manual':
1741
                    self.ui.comboBox_CraneK_Manual.addItem(name, fitting)
1742
            elif category == 'Pipe':
1743
                if type == 'Entrance':
1744
                    self.ui.comboBox_CraneK_Pipe_Entrance.addItem(name, fitting)
1745
                elif type == 'Exit':
1746
                    self.ui.comboBox_CraneK_Pipe_Exit.addItem(name, fitting)
1747
            elif category == 'Plug Valves':
1748
                if type == 'Plug':
1749
                    self.ui.comboBox_CraneK_Valves_Plug.addItem(name, fitting)
1750
            elif category == 'Check Valves':
1751
                if type == 'Swing':
1752
                    self.ui.comboBox_CraneK_Check_Valves_Swing.addItem(name, fitting)
1753
                elif type == 'Lift':
1754
                    self.ui.comboBox_CraneK_Check_Valves_Lift.addItem(name, fitting)
1755
                elif type == 'Tilting':
1756
                    self.ui.comboBox_CraneK_Check_Valves_Tilting.addItem(name, fitting)
1757
                elif type == 'Globe Stop':
1758
                    self.ui.comboBox_CraneK_Check_Valves_Globe_Stop.addItem(name, fitting)
1759
                elif type == 'Angled Stop':
1760
                    self.ui.comboBox_CraneK_Check_Valves_Angle_Stop.addItem(name, fitting)
1761

    
1762
    def initialize_2_k(self):
1763
        try:
1764
            self.initialize_2_k_selected_fitting()
1765

    
1766
            self.ui.lineEdit_2K_90_Elbow_Bend_Count.setValidator(
1767
                QtGui.QIntValidator(self.ui.lineEdit_2K_90_Elbow_Bend_Count))
1768
            self.ui.lineEdit_2K_90_Elbow_Miter_Count.setValidator(
1769
                QtGui.QIntValidator(self.ui.lineEdit_2K_90_Elbow_Miter_Count))
1770
            self.ui.lineEdit_2K_45_Elbow_Bend_Count.setValidator(
1771
                QtGui.QIntValidator(self.ui.lineEdit_2K_45_Elbow_Bend_Count))
1772
            self.ui.lineEdit_2K_45_Elbow_Miter_Count.setValidator(
1773
                QtGui.QIntValidator(self.ui.lineEdit_2K_45_Elbow_Miter_Count))
1774
            self.ui.lineEdit_2K_180_Elbow_Bend_Count.setValidator(
1775
                QtGui.QIntValidator(self.ui.lineEdit_2K_180_Elbow_Bend_Count))
1776
            self.ui.lineEdit_2K_Tees_Elbow_Count.setValidator(
1777
                QtGui.QIntValidator(self.ui.lineEdit_2K_Tees_Elbow_Count))
1778
            self.ui.lineEdit_2K_Tees_Through_Count.setValidator(
1779
                QtGui.QIntValidator(self.ui.lineEdit_2K_Tees_Through_Count))
1780
            self.ui.lineEdit_2K_Valves_Gate_Ball_Plug_Count.setValidator(
1781
                QtGui.QIntValidator(self.ui.lineEdit_2K_Valves_Gate_Ball_Plug_Count))
1782
            self.ui.lineEdit_2K_Valves_Globe_Count.setValidator(
1783
                QtGui.QIntValidator(self.ui.lineEdit_2K_Valves_Globe_Count))
1784
            self.ui.lineEdit_2K_Valves_Others_Count.setValidator(
1785
                QtGui.QIntValidator(self.ui.lineEdit_2K_Valves_Others_Count))
1786
            self.ui.lineEdit_2K_Pipe_Count.setValidator(
1787
                QtGui.QIntValidator(self.ui.lineEdit_2K_Pipe_Count))
1788
            self.ui.lineEdit_2K_Check_Valves_Count.setValidator(
1789
                QtGui.QIntValidator(self.ui.lineEdit_2K_Check_Valves_Count))
1790

    
1791
            self.controls_2_k_set_names()
1792

    
1793
            # 90 Elbow
1794
            self.ui.pushButton_Add_2K_90_Elbow_Bend.clicked.connect(self.add_2_k)
1795
            self.ui.pushButton_View_2K_90_Elbow_Bend.clicked.connect(self.show_2_k_image)
1796
            self.ui.pushButton_Add_2K_90_Elbow_Miter.clicked.connect(self.add_2_k)
1797
            self.ui.pushButton_View_2K_90_Elbow_Miter.clicked.connect(self.show_2_k_image)
1798
            self.ui.comboBox_2K_90_Elbow_Bend.currentIndexChanged.connect(self.on_2k_index_changed)
1799
            self.ui.comboBox_2K_90_Elbow_Miter.currentIndexChanged.connect(self.on_2k_index_changed)
1800
            # 45 Elbow
1801
            self.ui.pushButton_Add_2K_45_Elbow_Bend.clicked.connect(self.add_2_k)
1802
            self.ui.pushButton_View_2K_45_Elbow_Bend.clicked.connect(self.show_2_k_image)
1803
            self.ui.pushButton_Add_2K_45_Elbow_Miter.clicked.connect(self.add_2_k)
1804
            self.ui.pushButton_View_2K_45_Elbow_Miter.clicked.connect(self.show_2_k_image)
1805
            self.ui.comboBox_2K_45_Elbow_Bend.currentIndexChanged.connect(self.on_2k_index_changed)
1806
            self.ui.comboBox_2K_45_Elbow_Miter.currentIndexChanged.connect(self.on_2k_index_changed)
1807
            # 180 Elbow
1808
            self.ui.pushButton_Add_2K_180_Elbow_Bend.clicked.connect(self.add_2_k)
1809
            self.ui.pushButton_View_2K_180_Elbow_Bend.clicked.connect(self.show_2_k_image)
1810
            self.ui.comboBox_2K_180_Elbow_Bend.currentIndexChanged.connect(self.on_2k_index_changed)
1811
            # Tees
1812
            self.ui.pushButton_Add_2K_Tees_Elbow.clicked.connect(self.add_2_k)
1813
            self.ui.pushButton_View_2K_Tees_Elbow.clicked.connect(self.show_2_k_image)
1814
            self.ui.pushButton_Add_2K_Tees_Through.clicked.connect(self.add_2_k)
1815
            self.ui.pushButton_View_2K_Tees_Through.clicked.connect(self.show_2_k_image)
1816
            self.ui.comboBox_2K_Tees_Elbow.currentIndexChanged.connect(self.on_2k_index_changed)
1817
            self.ui.comboBox_2K_Tees_Through.currentIndexChanged.connect(self.on_2k_index_changed)
1818
            # Valves
1819
            self.ui.pushButton_Add_2K_Valves_Gate_Ball_Plug.clicked.connect(self.add_2_k)
1820
            self.ui.pushButton_View_2K_Valves_Gate_Ball_Plug.clicked.connect(self.show_2_k_image)
1821
            self.ui.pushButton_Add_2K_Valves_Globe.clicked.connect(self.add_2_k)
1822
            self.ui.pushButton_View_2K_Valves_Globe.clicked.connect(self.show_2_k_image)
1823
            self.ui.pushButton_Add_2K_Valves_Others.clicked.connect(self.add_2_k)
1824
            self.ui.pushButton_View_2K_Valves_Others.clicked.connect(self.show_2_k_image)
1825
            self.ui.comboBox_2K_Valves_Gate_Ball_Plug.currentIndexChanged.connect(self.on_2k_index_changed)
1826
            self.ui.comboBox_2K_Valves_Globe.currentIndexChanged.connect(self.on_2k_index_changed)
1827
            self.ui.comboBox_2K_Valves_Others.currentIndexChanged.connect(self.on_2k_index_changed)
1828
            # Pipe
1829
            self.ui.pushButton_Add_2K_Pipe.clicked.connect(self.add_2_k)
1830
            self.ui.pushButton_View_2K_Pipe.clicked.connect(self.show_2_k_image)
1831
            self.ui.comboBox_2K_Pipe.currentIndexChanged.connect(self.on_2k_index_changed)
1832
            # Check Valves
1833
            self.ui.pushButton_Add_2K_Check_Valves.clicked.connect(self.add_2_k)
1834
            self.ui.pushButton_View_2K_Check_Valves.clicked.connect(self.show_2_k_image)
1835
            self.ui.comboBox_2K_Check_Valves.currentIndexChanged.connect(self.on_2k_index_changed)
1836

    
1837
            self.ui.tableWidget_2K_SelectedFitting.setContextMenuPolicy(Qt.CustomContextMenu)
1838
            self.ui.tableWidget_2K_SelectedFitting.customContextMenuRequested.connect(self.context_menu_del_2_k)
1839

    
1840
        except Exception as ex:
1841
            from App import App
1842
            from AppDocData import MessageType
1843

    
1844
            message = 'error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename,
1845
                                                           sys.exc_info()[-1].tb_lineno)
1846
            App.mainWnd().addMessage.emit(MessageType.Error, message)
1847

    
1848
    def controls_2_k_set_names(self):
1849
        from AppDocData import AppDocData
1850

    
1851
        fittings = AppDocData.instance().get_fittings_by_method('2-K')
1852
        for fitting in fittings:
1853
            category = fitting[2]
1854
            type = fitting[3]
1855
            name = fitting[4]
1856

    
1857
            if category == '90 Elbow':
1858
                if type == 'Bend':
1859
                    self.ui.comboBox_2K_90_Elbow_Bend.addItem(name, fitting)
1860
                elif type == 'Miter':
1861
                    self.ui.comboBox_2K_90_Elbow_Miter.addItem(name, fitting)
1862
            elif category == '45 Elbow':
1863
                if type == 'Bend':
1864
                    self.ui.comboBox_2K_45_Elbow_Bend.addItem(name, fitting)
1865
                elif type == 'Miter':
1866
                    self.ui.comboBox_2K_45_Elbow_Miter.addItem(name, fitting)
1867
            elif category == '180 Elbow':
1868
                if type == 'Bend':
1869
                    self.ui.comboBox_2K_180_Elbow_Bend.addItem(name, fitting)
1870
            elif category == 'Tees':
1871
                if type == 'Tee as Elbow':
1872
                    self.ui.comboBox_2K_Tees_Elbow.addItem(name, fitting)
1873
                elif type == 'Run through':
1874
                    self.ui.comboBox_2K_Tees_Through.addItem(name, fitting)
1875
            elif category == 'Valves':
1876
                if type == 'Gate_Ball_Plug':
1877
                    self.ui.comboBox_2K_Valves_Gate_Ball_Plug.addItem(name, fitting)
1878
                elif type == 'Globe':
1879
                    self.ui.comboBox_2K_Valves_Globe.addItem(name, fitting)
1880
                elif type == 'Others':
1881
                    self.ui.comboBox_2K_Valves_Others.addItem(name, fitting)
1882
            elif category == 'Check Valves':
1883
                # if type == 'Swing':
1884
                self.ui.comboBox_2K_Check_Valves.addItem(name, fitting)
1885
            elif category == 'Pipe':
1886
                if type == 'Standard':
1887
                    self.ui.comboBox_2K_Pipe.addItem(name, fitting)
1888

    
1889
    def show_dialog(self, nominal_diameter, current_tab_index):
1890

    
1891
        self.setWindowFlags(self.windowFlags() & ~QtCore.Qt.WindowContextHelpButtonHint)
1892
        self.set_nominal_diameter_info(nominal_diameter)
1893
        if current_tab_index:
1894
            self.ui.tabWidget.setCurrentIndex(int(current_tab_index))
1895
        self.ui.lineEdit_CraneK_Main_Size.setText(str(self.nps))
1896
        self.load_data()
1897

    
1898
        self.exec_()
1899

    
1900
        return self.isAccepted, self.fittings_length, self.total_k, self.current_tab_index
1901

    
1902
    def set_nominal_diameter_info(self, nominal_diameter):
1903
        try:
1904
            app_doc_data = AppDocData.instance()
1905
            # nominal_diameter_list = app_doc_data.getNominalDiameterByUid(nominal_diameter)
1906
            nominal_diameter_list = app_doc_data.get_nominal_diameter_info(nominal_diameter, self.pipe_diameter_unit)
1907
            if len(nominal_diameter_list) > 0:
1908
                for nominalDiameter in nominal_diameter_list:
1909
                    if self.pipe_diameter_unit == 'mm':
1910
                        self.nps = nominalDiameter[1]
1911
                    else:
1912
                        self.nps = nominalDiameter[2]
1913

    
1914
                    self.selected_dia_in = nominalDiameter[2]
1915
                    self.friction_factor = nominalDiameter[3]
1916
            else:
1917
                # DB에 정의 되어있지 않은 Nominal Diameter인 경우
1918
                if (self.pipe_diameter_unit.upper() == 'MM' and float(nominal_diameter) > 900) or (self.pipe_diameter_unit.upper() == 'IN' and float(nominal_diameter) > 36):
1919
                    # 900mm 보다 큰 값들은 900mm 와 동일하게 friction factor 처리
1920
                    # 36inch 보다 큰 값들은 36inch 와 동일하게 friction factor 처리
1921
                    if self.pipe_diameter_unit == 'mm':
1922
                        self.nps = nominal_diameter
1923
                    else:
1924
                        self.nps = nominal_diameter
1925

    
1926
                    self.selected_dia_in = 36
1927
                    self.friction_factor = 0.012
1928
        except Exception as ex:
1929
            from App import App
1930
            from AppDocData import MessageType
1931

    
1932
            message = 'error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename,
1933
                                                           sys.exc_info()[-1].tb_lineno)
1934
            App.mainWnd().addMessage.emit(MessageType.Error, message)
1935

    
1936
    def get_equivalent_length_item_angle(self, name):
1937
        try:
1938
            count = 0
1939

    
1940
            row_count = self.ui.tableWidget_Equivalent_Length_SelectedFitting.rowCount()
1941
            for row in range(row_count):
1942
                if self.ui.tableWidget_Equivalent_Length_SelectedFitting.item(row, 4).text() == name:
1943
                    return int(self.ui.tableWidget_Equivalent_Length_SelectedFitting.item(row, 6).text())
1944

    
1945
            return count
1946

    
1947
        except Exception as ex:
1948
            from App import App
1949
            from AppDocData import MessageType
1950

    
1951
            message = 'error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename,
1952
                                                           sys.exc_info()[-1].tb_lineno)
1953
            App.mainWnd().addMessage.emit(MessageType.Error, message)
1954

    
1955
    def get_equivalent_length_item_count(self, name):
1956
        try:
1957
            count = 0
1958

    
1959
            row_count = self.ui.tableWidget_Equivalent_Length_SelectedFitting.rowCount()
1960
            for row in range(row_count):
1961
                if self.ui.tableWidget_Equivalent_Length_SelectedFitting.item(row, 4).text() == name:
1962
                    return int(self.ui.tableWidget_Equivalent_Length_SelectedFitting.item(row, 5).text())
1963

    
1964
            return count
1965

    
1966
        except Exception as ex:
1967
            from App import App
1968
            from AppDocData import MessageType
1969

    
1970
            message = 'error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename,
1971
                                                           sys.exc_info()[-1].tb_lineno)
1972
            App.mainWnd().addMessage.emit(MessageType.Error, message)
1973

    
1974
    def get_equivalent_length(self):
1975
        try:
1976
            di = float(self.nps)
1977
            if self.pipe_diameter_unit == 'mm':
1978
                di = di / 25
1979

    
1980
            if di <= 1:
1981
                a = 0.4
1982
                b = 0.7
1983
                c = 11.4
1984
                d = 4.5
1985
                e = 0.5
1986
                f = 2.2
1987
                ni = 1 / 0.023 * di * 0.0254
1988
                no = 0.5 / 0.023 * di * 0.0254
1989
            elif di == 1.5:
1990
                a = 0.6
1991
                b = 1
1992
                c = 16.4
1993
                d = 6.5
1994
                e = 0.8
1995
                f = 3.1
1996
                ni = 1 / 0.021 * di * 0.0254
1997
                no = 0.5 / 0.021 * di * 0.0254
1998
            elif di == 2:
1999
                a = 0.8
2000
                b = 1.2
2001
                c = 20.5
2002
                d = 8.1
2003
                e = 1
2004
                f = 3.9
2005
                ni = 1 / 0.019 * di * 0.0254
2006
                no = 0.5 / 0.019 * di * 0.0254
2007
            elif di == 3:
2008
                a = 1.2
2009
                b = 1.8
2010
                c = 30.2
2011
                d = 12
2012
                e = 1.4
2013
                f = 5.8
2014
                ni = 1 / 0.018 * di * 0.0254
2015
                no = 0.5 / 0.018 * di * 0.0254
2016
            elif di == 4:
2017
                a = 1.5
2018
                b = 2.3
2019
                c = 38.4
2020
                d = 15.4
2021
                e = 1.8
2022
                f = 7.4
2023
                ni = 1 / 0.017 * di * 0.0254
2024
                no = 0.5 / 0.017 * di * 0.0254
2025
            elif di == 6:
2026
                a = 2.2
2027
                b = 3.4
2028
                c = 57.2
2029
                d = 22.7
2030
                e = 2.7
2031
                f = 10.9
2032
                ni = 1 / 0.015 * di * 0.0254
2033
                no = 0.5 / 0.015 * di * 0.0254
2034
            elif di == 8:
2035
                a = 2.8
2036
                b = 4.4
2037
                c = 74.5
2038
                d = 29.6
2039
                e = 3.5
2040
                f = 14.2
2041
                ni = 1 / 0.014 * di * 0.0254
2042
                no = 0.5 / 0.014 * di * 0.0254
2043
            elif di == 10:
2044
                a = 3.5
2045
                b = 5.5
2046
                c = 92.8
2047
                d = 36.9
2048
                e = 4.4
2049
                f = 17.7
2050
                ni = 1 / 0.014 * di * 0.0254
2051
                no = 0.5 / 0.014 * di * 0.0254
2052
            elif di == 12:
2053
                a = 4.2
2054
                b = 6.5
2055
                c = 110.1
2056
                d = 43.7
2057
                e = 5.2
2058
                f = 21.1
2059
                ni = 1 / 0.013 * di * 0.0254
2060
                no = 0.5 / 0.013 * di * 0.0254
2061
            elif di == 14:
2062
                a = 4.6
2063
                b = 7.1
2064
                c = 126.9
2065
                d = 48
2066
                e = 5.7
2067
                f = 23.1
2068
                ni = 1 / 0.013 * di * 0.0254
2069
                no = 0.5 / 0.013 * di * 0.0254
2070
            elif di == 16:
2071
                a = 5.3
2072
                b = 8.1
2073
                c = 138.2
2074
                d = 54.9
2075
                e = 6.5
2076
                f = 26.4
2077
                ni = 1 / 0.013 * di * 0.0254
2078
                no = 0.5 / 0.013 * di * 0.0254
2079
            elif di == 18:
2080
                a = 5.9
2081
                b = 9.1
2082
                c = 155.4
2083
                d = 61.7
2084
                e = 7.3
2085
                f = 29.7
2086
                ni = 1 / 0.012 * di * 0.0254
2087
                no = 0.5 / 0.012 * di * 0.0254
2088
            elif di == 20:
2089
                a = 6.6
2090
                b = 10.2
2091
                c = 172.7
2092
                d = 68.6
2093
                e = 8.1
2094
                f = 33
2095
                ni = 1 / 0.012 * di * 0.0254
2096
                no = 0.5 / 0.012 * di * 0.0254
2097
            elif di == 22:
2098
                a = 6.6
2099
                b = 10.2
2100
                c = 172.7
2101
                d = 68.6
2102
                e = 8.1
2103
                f = 33
2104
                ni = 1 / 0.012 * di * 0.0254
2105
                no = 0.5 / 0.012 * di * 0.0254
2106
            elif di == 24:
2107
                a = 6.6
2108
                b = 10.2
2109
                c = 172.7
2110
                d = 68.6
2111
                e = 8.1
2112
                f = 33
2113
                ni = 1 / 0.012 * di * 0.0254
2114
                no = 0.5 / 0.012 * di * 0.0254
2115
            elif di > 24:
2116
                a = 13 * di * 0.0254
2117
                b = 20 * di * 0.0254
2118
                c = 340 * di * 0.0254
2119
                d = 135 * di * 0.0254
2120
                e = 16 * di * 0.0254
2121
                f = 65 * di * 0.0254
2122
                ni = 1 / 0.012 * di * 0.0254
2123
                no = 0.5 / 0.012 * di * 0.0254
2124

    
2125
            # miter
2126
            degree = self.get_equivalent_length_item_angle('Miter')
2127
            if degree == 0:
2128
                g = 2 * di * 0.0254
2129
            elif degree == 15:
2130
                g = 4 * di * 0.0254
2131
            elif degree == 30:
2132
                g = 8 * di * 0.0254
2133
            elif degree == 45:
2134
                g = 15 * di * 0.0254
2135
            elif degree == 60:
2136
                g = 25 * di * 0.0254
2137
            elif degree == 75:
2138
                g = 40 * di * 0.0254
2139
            elif degree == 90:
2140
                g = 60 * di * 0.0254
2141

    
2142
            # noz
2143
            if self.get_equivalent_length_item_count('Nozzle in') == 0:
2144
                ni = 0
2145
            if self.get_equivalent_length_item_count('Nozzle out') == 0:
2146
                no = 0
2147

    
2148
            gate_ball_plug_count = self.get_equivalent_length_item_count('Gate / Ball / Plug')
2149
            butterfly_count = self.get_equivalent_length_item_count('Butterfly')
2150
            elbow_90_count = self.get_equivalent_length_item_count('90 Elbow')
2151
            tee_branch_count = self.get_equivalent_length_item_count('Tee branch')
2152
            globe_count = self.get_equivalent_length_item_count('Globe')
2153
            check_count = self.get_equivalent_length_item_count('Check')
2154
            elbow_45_count = self.get_equivalent_length_item_count('45 Elbow')
2155
            tee_through_count = self.get_equivalent_length_item_count('Tee through')
2156
            miter_count = self.get_equivalent_length_item_count('Miter')
2157

    
2158
            elength = gate_ball_plug_count * a + (
2159
                    butterfly_count + elbow_90_count + tee_through_count) * b + globe_count * c + check_count * d + elbow_45_count * e + tee_branch_count * f + miter_count * g + ni + no
2160
            elength = round(elength, 3)
2161

    
2162
            return elength
2163

    
2164
        except Exception as ex:
2165
            from App import App
2166
            from AppDocData import MessageType
2167

    
2168
            message = 'error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename,
2169
                                                           sys.exc_info()[-1].tb_lineno)
2170
            App.mainWnd().addMessage.emit(MessageType.Error, message)
2171

    
2172
    def get_crane_k_total_k(self):
2173
        total_k = 0
2174

    
2175
        row_count = self.ui.tableWidget_CraneK_SelectedFitting.rowCount()
2176
        for row in range(row_count):
2177
            count = int(self.ui.tableWidget_CraneK_SelectedFitting.item(row, 5).text())
2178
            k = float(self.ui.tableWidget_CraneK_SelectedFitting.item(row, 9).text())
2179

    
2180
            total_k += count * k
2181

    
2182
        return total_k
2183

    
2184
    def get_2_k_total_k(self):
2185
        total_k = 0
2186

    
2187
        row_count = self.ui.tableWidget_2K_SelectedFitting.rowCount()
2188
        for row in range(row_count):
2189
            count = int(self.ui.tableWidget_2K_SelectedFitting.item(row, 5).text())
2190
            k = float(self.ui.tableWidget_2K_SelectedFitting.item(row, 6).text())
2191

    
2192
            total_k += count * k
2193

    
2194
        return total_k
2195

    
2196
    def keyPressEvent(self, QKeyEvent):
2197
        if QKeyEvent.key() == QtCore.Qt.Key_Delete:
2198
            if self.ui.tableWidget_Equivalent_Length_SelectedFitting.hasFocus():
2199
                selected_items = self.ui.tableWidget_Equivalent_Length_SelectedFitting.selectedItems()
2200
                if selected_items is not None:
2201
                    for item in selected_items:
2202
                        row = self.ui.tableWidget_Equivalent_Length_SelectedFitting.row(item)
2203
                        uid = self.ui.tableWidget_Equivalent_Length_SelectedFitting.item(row, 0).text()
2204
                        find_row = self.find_equivalent_length_data(uid)
2205
                        if find_row is not None:
2206
                            self.del_equivalent_length_data(find_row)
2207

    
2208
            elif self.ui.tableWidget_CraneK_SelectedFitting.hasFocus():
2209
                selected_items = self.ui.tableWidget_CraneK_SelectedFitting.selectedItems()
2210
                if selected_items is not None:
2211
                    for item in selected_items:
2212
                        row = self.ui.tableWidget_CraneK_SelectedFitting.row(item)
2213
                        uid = self.ui.tableWidget_CraneK_SelectedFitting.item(row, 0).text()
2214
                        find_row = self.find_crane_k_data(uid)
2215
                        if find_row is not None:
2216
                            self.del_crane_k_data(find_row)
2217
            elif self.ui.tableWidget_2K_SelectedFitting.hasFocus():
2218
                selected_items = self.ui.tableWidget_2K_SelectedFitting.selectedItems()
2219
                if selected_items is not None:
2220
                    for item in selected_items:
2221
                        row = self.ui.tableWidget_2K_SelectedFitting.row(item)
2222
                        uid = self.ui.tableWidget_2K_SelectedFitting.item(row, 0).text()
2223
                        find_row = self.find_2_k_data(uid)
2224
                        if find_row is not None:
2225
                            self.del_2_k_data(find_row)
2226

    
2227
    def load_data(self):
2228
        from AppDocData import AppDocData
2229
        from Fitting import Fitting
2230
        try:
2231
            fittings = self.item.fittings
2232

    
2233
            if fittings:
2234
                for method in fittings:
2235
                    if method == 'Equivalent_Length':
2236
                        for fitting in fittings[method]:
2237
                            uid = fitting.uid
2238
                            count = fitting.count
2239
                            angle = fitting.angle
2240
                            if angle:
2241
                                index = self.ui.comboBox_Equivalent_Length_Miter_Degree.findData(angle)
2242
                                self.ui.comboBox_Equivalent_Length_Miter_Degree.setCurrentIndex(index)
2243

    
2244
                            data = AppDocData.instance().get_fittings_by_uid(uid)
2245
                            if data:
2246
                                row = self.ui.tableWidget_Equivalent_Length_SelectedFitting.rowCount()
2247
                                self.ui.tableWidget_Equivalent_Length_SelectedFitting.setRowCount(row + 1)
2248
                                self.add_equivalent_length_data(row, data, count, angle)
2249
                    elif method == 'CraneK':
2250
                        for fitting in fittings[method]:
2251
                            uid = fitting.uid
2252
                            sub_size = fitting.sub_size
2253
                            count = fitting.count
2254
                            angle = fitting.angle
2255

    
2256
                            data = AppDocData.instance().get_fittings_by_uid(uid)
2257
                            if data:
2258
                                row = self.ui.tableWidget_CraneK_SelectedFitting.rowCount()
2259
                                self.ui.tableWidget_CraneK_SelectedFitting.setRowCount(row + 1)
2260
                                self.add_crane_k_data(row, data, count, sub_size, angle)
2261
                    elif method == '2-K':
2262
                        for fitting in fittings[method]:
2263
                            uid = fitting.uid
2264
                            sub_size = fitting.sub_size
2265
                            count = fitting.count
2266
                            angle = fitting.angle
2267

    
2268
                            data = AppDocData.instance().get_fittings_by_uid(uid)
2269
                            if data:
2270
                                row = self.ui.tableWidget_2K_SelectedFitting.rowCount()
2271
                                self.ui.tableWidget_2K_SelectedFitting.setRowCount(row + 1)
2272
                                self.add_2_k_data(row, data, count)
2273

    
2274
        except Exception as ex:
2275
            from App import App
2276
            from AppDocData import MessageType
2277

    
2278
            message = 'error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename,
2279
                                                           sys.exc_info()[-1].tb_lineno)
2280
            App.mainWnd().addMessage.emit(MessageType.Error, message)
2281

    
2282
    def add_fittings(self):
2283
        from Fitting import Fitting
2284
        try:
2285
            fittings = {}
2286
            fitting_equivalent_item = []
2287
            fitting_crane_k_item = []
2288
            fitting_2_k_item = []
2289

    
2290
            # Equivalent Length
2291
            row_count = self.ui.tableWidget_Equivalent_Length_SelectedFitting.rowCount()
2292
            for row in range(row_count):
2293
                uid = self.ui.tableWidget_Equivalent_Length_SelectedFitting.item(row, 0).text()
2294
                sub_size = None
2295
                if self.ui.tableWidget_Equivalent_Length_SelectedFitting.item(row, 5):
2296
                    count = self.ui.tableWidget_Equivalent_Length_SelectedFitting.item(row, 5).text()
2297
                else:
2298
                    count = None
2299
                if self.ui.tableWidget_Equivalent_Length_SelectedFitting.item(row, 6):
2300
                    angle = self.ui.tableWidget_Equivalent_Length_SelectedFitting.item(row, 6).text()
2301
                else:
2302
                    angle = None
2303

    
2304
                fitting_equivalent_item.append(Fitting(uid, sub_size, angle, count))
2305
                fittings['Equivalent_Length'] = fitting_equivalent_item
2306
            # Crane K
2307
            row_count = self.ui.tableWidget_CraneK_SelectedFitting.rowCount()
2308
            for row in range(row_count):
2309
                uid = self.ui.tableWidget_CraneK_SelectedFitting.item(row, 0).text()
2310
                if self.ui.tableWidget_CraneK_SelectedFitting.item(row, 7):
2311
                    sub_size = self.ui.tableWidget_CraneK_SelectedFitting.item(row, 7).text()
2312
                else:
2313
                    sub_size = None
2314
                if self.ui.tableWidget_CraneK_SelectedFitting.item(row, 5):
2315
                    count = self.ui.tableWidget_CraneK_SelectedFitting.item(row, 5).text()
2316
                else:
2317
                    count = None
2318
                if self.ui.tableWidget_CraneK_SelectedFitting.item(row, 8):
2319
                    angle = self.ui.tableWidget_CraneK_SelectedFitting.item(row, 8).text()
2320
                else:
2321
                    angle = None
2322

    
2323
                fitting_crane_k_item.append(Fitting(uid, sub_size, angle, count))
2324
                fittings['CraneK'] = fitting_crane_k_item
2325
            # 2-K
2326
            row_count = self.ui.tableWidget_2K_SelectedFitting.rowCount()
2327
            for row in range(row_count):
2328
                uid = self.ui.tableWidget_2K_SelectedFitting.item(row, 0).text()
2329
                sub_size = None
2330
                angle = None
2331
                if self.ui.tableWidget_2K_SelectedFitting.item(row, 5):
2332
                    count = self.ui.tableWidget_2K_SelectedFitting.item(row, 5).text()
2333
                else:
2334
                    count = None
2335

    
2336
                fitting_2_k_item.append(Fitting(uid, sub_size, angle, count))
2337
                fittings['2-K'] = fitting_2_k_item
2338

    
2339
            self.item.fittings = fittings
2340
        except Exception as ex:
2341
            from App import App
2342
            from AppDocData import MessageType
2343

    
2344
            message = 'error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename,
2345
                                                           sys.exc_info()[-1].tb_lineno)
2346
            App.mainWnd().addMessage.emit(MessageType.Error, message)
2347

    
2348
    def accept(self):
2349
        try:
2350
            self.add_fittings()
2351

    
2352
            index = self.ui.tabWidget.currentIndex()
2353
            if index == 0:
2354
                # Equivalent Length
2355
                self.fittings_length = self.get_equivalent_length()
2356
                self.total_k = 0
2357
            elif index == 1:
2358
                # Crane K
2359
                self.fittings_length = 0
2360
                self.total_k = self.get_crane_k_total_k()
2361
            elif index == 2:
2362
                # 2-K
2363
                self.fittings_length = 0
2364
                self.total_k = self.get_2_k_total_k()
2365

    
2366
            self.current_tab_index = index
2367
            self.isAccepted = True
2368
        except Exception as ex:
2369
            from App import App
2370
            from AppDocData import MessageType
2371

    
2372
            message = 'error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename,
2373
                                                           sys.exc_info()[-1].tb_lineno)
2374
            App.mainWnd().addMessage.emit(MessageType.Error, message)
2375

    
2376
        QDialog.accept(self)
2377

    
2378
    def reject(self):
2379
        QDialog.reject(self)
2380

    
2381
    if __name__ == '__main__':
2382
        from FittingsDialog import QFittingsDialog
2383
        from App import App
2384

    
2385
        app = App(sys.argv)
2386

    
2387
        if True:
2388
            dlg = QFittingsDialog()
2389
            dlg.exec_()
클립보드 이미지 추가 (최대 크기: 500 MB)