프로젝트

일반

사용자정보

개정판 aa7ba076

IDaa7ba076a714657dc42b40d0e85859fdb4a1ec6f
상위 f0ff491d
하위 5fdc4fd0, fe5c4e9f

김연진이(가) 약 5년 전에 추가함

issue #1055 : 거칠기 항목 편집 가능 하도록 수정

Change-Id: Ice9e54c155eb2a5e9a0942d453acd8f343c458a4

차이점 보기:

HYTOS/HYTOS/AppDocData.py
506 506

  
507 507
        return res
508 508

  
509

  
510 509
    def getInsideDiameter(self, nominaldiameter_uid, schedule_uid):
511 510
        res = []
512 511
        try:
......
782 781
            # Close the db connection
783 782
            conn.close()
784 783

  
784
    def update_roughness(self, roughness):
785
        try:
786
            # Creates or opens a file called mydb with a SQLite3 DB
787
            conn = sqlite3.connect(self.activeDrawing.path)
788
            conn.execute('PRAGMA foreign_keys = ON')
789
            # Get a cursor object
790
            cursor = conn.cursor()
791

  
792
            for r in roughness:
793
                uid = r[0]
794
                material = r[1]
795
                meter = r[2]
796
                inch = r[3]
797
                feet = r[4]
798
                millimeter = r[5]
799

  
800
                sql = """Update Roughness
801
                            Set Material = ?
802
                              , Meter = ?
803
                              , Inch = ?
804
                              , Feet = ?
805
                              , Milimeter = ? 
806
                          Where UID = ?"""
807
                param = (material, meter, inch, feet, millimeter, uid)
808

  
809
                cursor.execute(sql, param)
810
            conn.commit()
811
        except Exception as ex:
812
            from App import App
813
            # Roll back any change if something goes wrong
814
            conn.rollback()
815

  
816
            message = 'error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename,
817
                                                           sys.exc_info()[-1].tb_lineno)
818
            App.mainWnd().addMessage.emit(MessageType.Error, message)
819
        finally:
820
            # Close the db connection
821
            conn.close()
822

  
823
    def update_fittings(self, fittings):
824
        try:
825
            # Creates or opens a file called mydb with a SQLite3 DB
826
            conn = sqlite3.connect(self.activeDrawing.path)
827
            conn.execute('PRAGMA foreign_keys = ON')
828
            # Get a cursor object
829
            cursor = conn.cursor()
830

  
831
            for fitting in fittings:
832
                uid = fitting[0]
833
                k = fitting[1]
834

  
835
                sql = """Update Fittings
836
                            Set K = ?
837
                          Where UID = ?"""
838
                param = (k, uid)
839

  
840
                cursor.execute(sql, param)
841
            conn.commit()
842
        except Exception as ex:
843
            from App import App
844
            # Roll back any change if something goes wrong
845
            conn.rollback()
846

  
847
            message = 'error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename,
848
                                                           sys.exc_info()[-1].tb_lineno)
849
            App.mainWnd().addMessage.emit(MessageType.Error, message)
850
        finally:
851
            # Close the db connection
852
            conn.close()
853

  
785 854
    def saveConfigs(self, configs):
786 855
        """
787 856
        @brief      save application configurations
HYTOS/HYTOS/RoughnessDialog.py
12 12
from AppDocData import Config
13 13
import Roughness_UI
14 14

  
15
def is_float(s):
16
    try:
17
        if s:
18
            float(s)
19
            return True
20
        else:
21
            return False
22
    except ValueError:
23
        return False
15 24

  
16
def set_item_properties(name, alignment, color=None):
17
    if name is None:
18
        name = ''
25
def is_blank(s):
26
    return not (s and s.strip())
19 27

  
20
    item = None
21
    if type(name) == float:
22
        # fixed format으로 변환 후 .으로 분리
23
        tokens = f"{name:.10f}".split('.')
28

  
29
def is_not_blank(s):
30
    return bool(s and s.strip())
31

  
32
def convert_to_fixed_point(value):
33
    if is_float(str(value)):
34
        tokens = f"{float(value):.10f}".split('.')
24 35
        if len(tokens) == 2:
25 36
            # 소수점 아래가 있을 경우 소수점 아래의 trailing zero를 제거한다.
26
            tokens[1] = tokens[1].rstrip('0')
27
        item = QTableWidgetItem('.'.join(tokens))
37
            if is_blank(tokens[1].rstrip('0')):
38
                return tokens[0]
39
            else:
40
                tokens[1] = tokens[1].rstrip('0')
41
                return '.'.join(tokens)
42
        else:
43
            return tokens[0]
28 44
    else:
29
        item = QTableWidgetItem(str(name))
45
        return value
30 46

  
47
def set_item_properties(name, alignment, color=None):
48
    if name is None:
49
        name = ''
50

  
51
    item = QTableWidgetItem(str(name))
31 52
    item.setTextAlignment(alignment)
32 53
    if color:
33 54
        item.setBackground(color)
34 55

  
35 56
    return item
36 57

  
37

  
38 58
class QRoughnessDialog(QDialog):
39 59

  
40 60
    def __init__(self):
......
44 64
        self.unit = None
45 65
        self.isAccepted = False
46 66

  
67
        self.ui.pushButton_Save.clicked.connect(self.update_roughness)
47 68
        self.ui.tableWidget_Roughness.cellDoubleClicked.connect(self.double_clicked)
48 69

  
70
    def update_roughness(self):
71
        try:
72
            validation = True
73
            data = []
74

  
75
            for row in range(self.ui.tableWidget_Roughness.rowCount()):
76
                uid = self.ui.tableWidget_Roughness.item(row, 0).text()
77
                material = self.ui.tableWidget_Roughness.item(row, 1).text()
78
                meter = self.ui.tableWidget_Roughness.item(row, 2).text()
79
                inch = self.ui.tableWidget_Roughness.item(row, 3).text()
80
                feet = self.ui.tableWidget_Roughness.item(row, 4).text()
81
                millimeter = self.ui.tableWidget_Roughness.item(row, 5).text()
82

  
83
                if is_float(meter) and is_float(inch) and is_float(feet) and is_float(millimeter):
84
                    data.append([uid, material, meter, inch, feet, millimeter])
85
                else:
86
                    validation = False
87
                    break
88

  
89
            if validation == True:
90
                app_doc_data = AppDocData.instance()
91
                app_doc_data.update_roughness(data)
92
                QMessageBox.information(self, self.tr('Information'), self.tr('Save completed successfully.'))
93
            else:
94
                QMessageBox.information(self, self.tr('Information'), self.tr('Roughness is a numeric type.'))
95
        except Exception as ex:
96
            from App import App
97
            from AppDocData import MessageType
98

  
99
            message = 'error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename,
100
                                                           sys.exc_info()[-1].tb_lineno)
101
            App.mainWnd().addMessage.emit(MessageType.Error, message)
102

  
103

  
49 104
    def double_clicked(self, row):
50 105
        self.isAccepted = True
51 106
        QDialog.accept(self)
......
69 124
                self.unit = attr[1]['Roughness']
70 125

  
71 126
    def get_selected_item(self):
72

  
73 127
        if self.unit == 'm':
74 128
            item = self.ui.tableWidget_Roughness.item(self.ui.tableWidget_Roughness.currentRow(), 2).text()
75 129
        elif self.unit == 'in':
......
89 143
        self.ui.tableWidget_Roughness.setHorizontalHeaderLabels(
90 144
            ['UID', 'Material', 'Roughness', 'Roughness', 'Roughness', 'Roughness', 'Unit'])
91 145
        self.ui.tableWidget_Roughness.horizontalHeader().setStretchLastSection(True)
92
        self.ui.tableWidget_Roughness.setEditTriggers(QAbstractItemView.NoEditTriggers)
146
        # self.ui.tableWidget_Roughness.setEditTriggers(QAbstractItemView.NoEditTriggers)
93 147
        self.ui.tableWidget_Roughness.verticalHeader().setVisible(False)
94 148
        self.ui.tableWidget_Roughness.setSelectionMode(QAbstractItemView.SingleSelection)
95 149
        self.ui.tableWidget_Roughness.setSelectionBehavior(QAbstractItemView.SelectRows)
......
124 178
                                                                                    Qt.AlignHCenter | Qt.AlignVCenter))
125 179
            self.ui.tableWidget_Roughness.setItem(row_count, 1, set_item_properties(roughness[1],
126 180
                                                                                    Qt.AlignLeft | Qt.AlignVCenter))
127
            self.ui.tableWidget_Roughness.setItem(row_count, 2, set_item_properties(roughness[2],
181
            self.ui.tableWidget_Roughness.setItem(row_count, 2, set_item_properties(convert_to_fixed_point(roughness[2]),
128 182
                                                                                    Qt.AlignRight | Qt.AlignVCenter))
129
            self.ui.tableWidget_Roughness.setItem(row_count, 3, set_item_properties(roughness[3],
183
            self.ui.tableWidget_Roughness.setItem(row_count, 3, set_item_properties(convert_to_fixed_point(roughness[3]),
130 184
                                                                                    Qt.AlignRight | Qt.AlignVCenter))
131
            self.ui.tableWidget_Roughness.setItem(row_count, 4, set_item_properties(roughness[4],
185
            self.ui.tableWidget_Roughness.setItem(row_count, 4, set_item_properties(convert_to_fixed_point(roughness[4]),
132 186
                                                                                    Qt.AlignRight | Qt.AlignVCenter))
133
            self.ui.tableWidget_Roughness.setItem(row_count, 5, set_item_properties(roughness[5],
187
            self.ui.tableWidget_Roughness.setItem(row_count, 5, set_item_properties(convert_to_fixed_point(roughness[5]),
134 188
                                                                                    Qt.AlignRight | Qt.AlignVCenter))
135 189
            self.ui.tableWidget_Roughness.setItem(row_count, 6, set_item_properties(self.unit,
136 190
                                                                                    Qt.AlignHCenter | Qt.AlignVCenter))
HYTOS/HYTOS/Roughness_UI.py
22 22
        RoughnessDialog.setWindowIcon(icon)
23 23
        self.gridLayout_2 = QtWidgets.QGridLayout(RoughnessDialog)
24 24
        self.gridLayout_2.setObjectName("gridLayout_2")
25
        self.horizontalLayout = QtWidgets.QHBoxLayout()
26
        self.horizontalLayout.setObjectName("horizontalLayout")
27
        self.pushButton_Save = QtWidgets.QPushButton(RoughnessDialog)
28
        self.pushButton_Save.setObjectName("pushButton_Save")
29
        self.horizontalLayout.addWidget(self.pushButton_Save)
30
        self.buttonBox = QtWidgets.QDialogButtonBox(RoughnessDialog)
31
        self.buttonBox.setOrientation(QtCore.Qt.Horizontal)
32
        self.buttonBox.setStandardButtons(QtWidgets.QDialogButtonBox.Cancel|QtWidgets.QDialogButtonBox.Ok)
33
        self.buttonBox.setObjectName("buttonBox")
34
        self.horizontalLayout.addWidget(self.buttonBox)
35
        self.gridLayout_2.addLayout(self.horizontalLayout, 3, 0, 1, 1)
25 36
        self.gridLayout = QtWidgets.QGridLayout()
26 37
        self.gridLayout.setObjectName("gridLayout")
27 38
        self.tableWidget_Roughness = QtWidgets.QTableWidget(RoughnessDialog)
......
32 43
        self.tableWidget_Roughness.setRowCount(0)
33 44
        self.gridLayout.addWidget(self.tableWidget_Roughness, 1, 0, 1, 1)
34 45
        self.gridLayout_2.addLayout(self.gridLayout, 1, 0, 1, 1)
35
        self.buttonBox = QtWidgets.QDialogButtonBox(RoughnessDialog)
36
        self.buttonBox.setOrientation(QtCore.Qt.Horizontal)
37
        self.buttonBox.setStandardButtons(QtWidgets.QDialogButtonBox.Cancel|QtWidgets.QDialogButtonBox.Ok)
38
        self.buttonBox.setObjectName("buttonBox")
39
        self.gridLayout_2.addWidget(self.buttonBox, 2, 0, 1, 1)
40 46

  
41 47
        self.retranslateUi(RoughnessDialog)
42 48
        self.buttonBox.accepted.connect(RoughnessDialog.accept)
......
46 52
    def retranslateUi(self, RoughnessDialog):
47 53
        _translate = QtCore.QCoreApplication.translate
48 54
        RoughnessDialog.setWindowTitle(_translate("RoughnessDialog", "Select Material (General Eq.)"))
55
        self.pushButton_Save.setText(_translate("RoughnessDialog", "Save"))
49 56
import Resource_rc
HYTOS/HYTOS/UI/Roughness.ui
23 23
    <normaloff>:/images/HYTOS.png</normaloff>:/images/HYTOS.png</iconset>
24 24
  </property>
25 25
  <layout class="QGridLayout" name="gridLayout_2">
26
   <item row="3" column="0">
27
    <layout class="QHBoxLayout" name="horizontalLayout">
28
     <item>
29
      <widget class="QPushButton" name="pushButton_Save">
30
       <property name="text">
31
        <string>Save</string>
32
       </property>
33
      </widget>
34
     </item>
35
     <item>
36
      <widget class="QDialogButtonBox" name="buttonBox">
37
       <property name="orientation">
38
        <enum>Qt::Horizontal</enum>
39
       </property>
40
       <property name="standardButtons">
41
        <set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
42
       </property>
43
      </widget>
44
     </item>
45
    </layout>
46
   </item>
26 47
   <item row="1" column="0">
27 48
    <layout class="QGridLayout" name="gridLayout">
28 49
     <item row="1" column="0">
......
37 58
     </item>
38 59
    </layout>
39 60
   </item>
40
   <item row="2" column="0">
41
    <widget class="QDialogButtonBox" name="buttonBox">
42
     <property name="orientation">
43
      <enum>Qt::Horizontal</enum>
44
     </property>
45
     <property name="standardButtons">
46
      <set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
47
     </property>
48
    </widget>
49
   </item>
50 61
  </layout>
51 62
 </widget>
52 63
 <tabstops>

내보내기 Unified diff

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