프로젝트

일반

사용자정보

개정판 2b9f1680

ID2b9f1680bafefc24a7561b1d990cd065fe350e40
상위 a6a2273e
하위 16c4b23c

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

issue #1197: 작업한 도면 데이타를 저장한다

Change-Id: I136c93f0465c9672e40e4146b9be99721995cc5a

차이점 보기:

HYTOS/HYTOS/App.py
16 16
sys.path.insert(0, os.path.dirname(os.path.realpath(__file__)))
17 17

  
18 18
class App(QApplication):
19
    """
20
    This is App class inherits from QApplication
21
    """
19
    """ This is App class inherits from QApplication """
22 20

  
23 21
    NAME = 'HYTOS'  ### program name
24 22

  
......
112 110
    sys._excepthook = sys.excepthook
113 111
    sys.excepthook = exceptionHandler.handler
114 112

  
115
    """
116
    try:
117
        import qtmodern.styles
118
    except ImportError:
119
        pass
120
    else:
121
        qtmodern.styles.darkorange(app)
122
    """
123 113
    if True:
124
        dlg = Ui_Dialog()
125
        selectedProject = dlg.showDialog()
126
        if selectedProject is not None:
127
            AppDocData.instance().setCurrentProject(selectedProject)
128
            AppDocData.instance().ex = exceptionHandler
129
            app._mainWnd = MainWindow.instance()
130
            app._mainWnd.show()
131
            sys.exit(app.exec_())
114
        AppDocData.instance().ex = exceptionHandler
115
        app._mainWnd = MainWindow.instance()
116
        app._mainWnd.show()
117
        sys.exit(app.exec_())
HYTOS/HYTOS/AppDocData.py
545 545

  
546 546
        return styles
547 547

  
548
    '''
549
        @brief  Set current Project
550
        @history    2018.06.27  Jeongwoo    If DB file is not, copy DB file from ProgramData
551
    '''
552
    def setCurrentProject(self, project):
553
        self.project = project
554
        try:
555
            # Creates or opens a file called mydb with a SQLite3 DB
556
            dbPath = os.path.join(self.getCurrentProject().getDbFilePath() , App.NAME + '.db')
557
            
558
            if not os.path.isfile(dbPath):
559
                templatePath = self.getTemplateDbPath()
560
                templateFile = QFile(templatePath)
561
                templateFile.copy(dbPath)
562
            else:
563
                try:
564
                    conn = sqlite3.connect(dbPath)
565
                    # Get a cursor object
566
                    cursor = conn.cursor()
567

  
568
                    fileNames = os.listdir(os.path.join(os.path.dirname(os.path.realpath(__file__)), 'Scripts'))
569
                    for fileName in fileNames:
570
                        if fileName.endswith(".sql") and (1 == len(os.path.splitext(fileName)[0].split('.'))):
571
                            try:
572
                                file = QFile(os.path.join(os.path.dirname(os.path.realpath(__file__)), 'Scripts', fileName))
573
                                file.open(QFile.ReadOnly)
574
                                sql = file.readAll()
575
                                sql = str(sql, encoding='utf8')
576
                                cursor.executescript(sql)
577
                            finally:
578
                                file.close()
579
                    conn.commit()
580
                except Exception as ex:
581
                    print('error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno))
582
                finally:
583
                    conn.close()
584
        # Catch the exception
585
        except Exception as ex:
586
            # Roll back any change if something goes wrong
587
            print('error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno))
588
        finally:
589
            pass
590

  
591

  
592 548
    @property
593 549
    def border_file_path(self):
594 550
        """ return border file path """
......
829 785

  
830 786
    def getRoughness(self):
831 787
        res = []
832
        try:
833
            # Creates or opens a file called mydb with a SQLite3 DB
834
            dbPath = os.path.join(self.getCurrentProject().getDbFilePath(), AppDocData.DATABASE)
835
            db = sqlite3.connect(dbPath)
836
            db.row_factory = sqlite3.Row
837
            # Get a cursor object
838
            cursor = db.cursor()
839 788

  
840
            sql = "select UID, Material, Meter, Inch, Feet, Milimeter from Roughness" 
841
            cursor.execute(sql)
842
            rows = cursor.fetchall()
843
            for row in rows:                
844
                res.append((row[0], row[1], row[2], row[3], row[4], row[5]))
845
        # Catch the exception
846
        except Exception as ex:
847
            # Roll back any change if something goes wrong
848
            db.rollback()
849
            print('error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno))
850
        finally:
851
            # Close the db connection
852
            db.close()
789
        conn = sqlite3.connect(self.activeDrawing.path)
790
        with conn:
791
            try:
792
                conn.row_factory = sqlite3.Row
793
                # Get a cursor object
794
                cursor = conn.cursor()
795

  
796
                sql = "select UID, Material, Meter, Inch, Feet, Milimeter from Roughness" 
797
                cursor.execute(sql)
798
                rows = cursor.fetchall()
799
                for row in rows:                
800
                    res.append((row[0], row[1], row[2], row[3], row[4], row[5]))
801
            # Catch the exception
802
            except Exception as ex:
803
                # Roll back any change if something goes wrong
804
                conn.rollback()
805
                print('error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno))
853 806

  
854 807
        return res
855 808

  
......
887 840

  
888 841
    def getSchedule(self):
889 842
        res = []
890
        try:
891
            # Creates or opens a file called mydb with a SQLite3 DB
892
            dbPath = os.path.join(self.getCurrentProject().getDbFilePath(), AppDocData.DATABASE)
893
            db = sqlite3.connect(dbPath)
894
            # Get a cursor object
895
            cursor = db.cursor()
896

  
897
            sql = "select UID, No from Schedule" 
898
            cursor.execute(sql)
899
            rows = cursor.fetchall()
900
            for row in rows:                
901
                res.append((row[0], row[1]))
902
        # Catch the exception
903
        except Exception as ex:
904
            # Roll back any change if something goes wrong
905
            db.rollback()
906
            print('error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno))
907
        finally:
908
            # Close the db connection
909
            db.close()
910 843

  
911
        return res
844
        conn = sqlite3.connect(self.activeDrawing.path)
845
        with conn:
846
            try:
847
                # Get a cursor object
848
                cursor = conn.cursor()
912 849

  
850
                sql = "select UID, No from Schedule" 
851
                cursor.execute(sql)
852
                rows = cursor.fetchall()
853
                for row in rows:                
854
                    res.append((row[0], row[1]))
855
            # Catch the exception
856
            except Exception as ex:
857
                # Roll back any change if something goes wrong
858
                conn.rollback()
859
                print('error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno))
913 860

  
861
        return res
914 862

  
915 863
    def getNominalDiameter(self):
916 864
        
917 865
        res = []
918
        try:
919
            # Creates or opens a file called mydb with a SQLite3 DB
920
            dbPath = os.path.join(self.getCurrentProject().getDbFilePath(), AppDocData.DATABASE)
921
            db = sqlite3.connect(dbPath)
922
            # Get a cursor object
923
            cursor = db.cursor()
924 866

  
925
            sql = "select UID, Milimeter, Inch from NominalDiameter" 
926
            cursor.execute(sql)
927
            rows = cursor.fetchall()
928
            for row in rows:                
929
                res.append((row[0], row[1], row[2]))
930
        # Catch the exception
931
        except Exception as ex:
932
            # Roll back any change if something goes wrong
933
            db.rollback()
934
            print('error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno))
935
        finally:
936
            # Close the db connection
937
            db.close()
867
        # Creates or opens a file called mydb with a SQLite3 DB
868
        conn = sqlite3.connect(self.activeDrawing.path)
869
        with conn:
870
            try:
871
                # Get a cursor object
872
                cursor = conn.cursor()
873

  
874
                sql = "select UID, Milimeter, Inch from NominalDiameter" 
875
                cursor.execute(sql)
876
                rows = cursor.fetchall()
877
                for row in rows:                
878
                    res.append((row[0], row[1], row[2]))
879
            # Catch the exception
880
            except Exception as ex:
881
                # Roll back any change if something goes wrong
882
                conn.rollback()
883
                print('error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno))
938 884

  
939 885
        return res
940 886

  
......
1604 1550
    def getSymbolByQuery(self, fieldName, param):
1605 1551
        ret = None
1606 1552

  
1607
        try:
1608
            dbPath = os.path.join(self.getCurrentProject().getDbFilePath(), AppDocData.DATABASE)
1609
            conn = sqlite3.connect(dbPath)
1553
        conn = sqlite3.connect(self.activeDrawing.path)
1554
        with conn:
1610 1555
            cursor = conn.cursor()
1611 1556

  
1612 1557
            sql = """select s.UID
1613
                          , s.Name
1614
                          , t.Category
1615
                          , t.Type
1616
                          , s.OriginalPoint
1617
                          , s.ConnectionPoint
1618
                       from Symbols s
1619
                      inner join SymbolType t
1620
                         on s.SymbolType_UID = t.UID 
1621
                      where """ + "s." + fieldName + '=?'
1558
                            , s.Name
1559
                            , t.Category
1560
                            , t.Type
1561
                            , s.OriginalPoint
1562
                            , s.ConnectionPoint
1563
                        from Symbols s
1564
                        inner join SymbolType t
1565
                            on s.SymbolType_UID = t.UID 
1566
                        where """ + "s." + fieldName + '=?'
1622 1567

  
1623 1568
            try:
1624 1569
                cursor.execute(sql, (param,))
......
1628 1573
                    ret = symbol.SymbolBase(symbolTuple[0], symbolTuple[1], symbolTuple[2], symbolTuple[3], symbolTuple[4], symbolTuple[5]) 
1629 1574
            except Exception as ex:
1630 1575
                print('error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno))
1631
        finally:
1632
            conn.close()
1633 1576

  
1634 1577
        return ret
1635 1578

  
1636

  
1637 1579
    def getSymbolListByUID(self, uid):
1580
        """ get symbol list by given uid """
1638 1581
        ret = []
1639 1582

  
1640
        try:
1641
            dbPath = os.path.join(self.getCurrentProject().getDbFilePath(), AppDocData.DATABASE)
1642
            conn = sqlite3.connect(dbPath)
1583
        conn = sqlite3.connect(self.getTemplateDbPath())
1584
        with conn:
1643 1585
            cursor = conn.cursor()
1644 1586
            
1645 1587
            sql = """select s.UID
1646
                          , s.Name
1647
                          , t.Category
1648
                          , t.Type
1649
                          , s.OriginalPoint
1650
                          , s.ConnectionPoint
1651
                       from Symbols s
1652
                      inner join SymbolType t
1653
                         on s.SymbolType_UID = t.uid 
1654
                      where s.SymbolType_UID = ?"""
1655
           
1588
                            , s.Name
1589
                            , t.Category
1590
                            , t.Type
1591
                            , s.OriginalPoint
1592
                            , s.ConnectionPoint
1593
                        from Symbols s
1594
                        inner join SymbolType t
1595
                            on s.SymbolType_UID = t.uid 
1596
                        where s.SymbolType_UID = ?"""
1597
            
1656 1598
            try:
1657 1599
                cursor.execute(sql, (uid,))
1658 1600
                rows = cursor.fetchall()
......
1663 1605
                        ret.append(sym)
1664 1606
            except Exception as ex:
1665 1607
                print('error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno))
1666
        finally:
1667
            conn.close()
1668 1608

  
1669 1609
        return ret
1670 1610

  
......
3035 2975
    def getSymbolCategoryList(self):
3036 2976
        SymbolCategoryList = []
3037 2977

  
3038
        try:
3039
            dbPath = os.path.join(self.getCurrentProject().getDbFilePath(), AppDocData.DATABASE)
3040

  
3041
            conn = sqlite3.connect(dbPath)
2978
        conn = sqlite3.connect(self.getTemplateDbPath())
2979
        with conn:
3042 2980
            cursor = conn.cursor()
3043 2981
            sql = 'SELECT DISTINCT CATEGORY FROM SymbolType ORDER BY type ASC'
3044 2982
            try:
......
3051 2989

  
3052 2990
                message = 'error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno)
3053 2991
                App.mainWnd().addMessage.emit(MessageType.Error, message)
3054
        finally:
3055
            conn.close()
3056 2992

  
3057 2993
        return SymbolCategoryList
3058 2994

  
......
3112 3048
        from EngineeringConnectorItem import NozzleData
3113 3049

  
3114 3050
        res = None
3115
        db_path = os.path.join(self.getCurrentProject().getDbFilePath(), AppDocData.DATABASE)
3116
        conn = sqlite3.connect(db_path)
3051
        conn = sqlite3.connect(self.activeDrawing.path)
3117 3052
        with conn:
3118 3053
            conn.row_factory = sqlite3.Row
3119 3054
            cursor = conn.cursor()
......
3133 3068
                    res.over_design_cv = float(rows[0]['Over_Design_CV'])
3134 3069
        return res
3135 3070

  
3136
    def getDrawingsUnitsByDrawingUID(self, uid):
3071
    def getDrawingsUnitsByDrawingUID(self, drawing):
3072
        """ get units of drawing """
3137 3073
        unitsList = []
3138 3074

  
3139
        try:
3140
            dbPath = os.path.join(self.getCurrentProject().getDbFilePath(), AppDocData.DATABASE)
3141

  
3142
            conn = sqlite3.connect(dbPath)
3075
        conn = sqlite3.connect(drawing.path)
3076
        with conn:
3143 3077
            cursor = conn.cursor()
3144
            #sql = 'select UID from Components where Drawings_UID = ? order by x desc'
3145 3078

  
3146
            sql = """select du.Units
3147
                          , u.Value
3148
                       from DrawingsUnits du 
3149
                       left join units u 
3150
                         on du.Units_UID = u.uid
3151
                      where du.drawings_uid = ?"""
3079
            sql = 'select du.Units, u.Value from DrawingsUnits du \
3080
                                                 left join units u on du.Units_UID = u.uid'
3152 3081
            try:
3153
                param = (uid, )
3154
                cursor.execute(sql, param)
3082
                cursor.execute(sql)
3155 3083
                rows = cursor.fetchall()
3156 3084
                for row in rows:
3157 3085
                    unitsList.append((row[0], row[1])) 
......
3160 3088

  
3161 3089
                message = 'error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno)
3162 3090
                App.mainWnd().addMessage.emit(MessageType.Error, message)
3163
        finally:
3164
            conn.close()
3165 3091

  
3166 3092
        return unitsList
3167 3093

  
......
3200 3126
    def getSymbolTypeListByCategory(self, category):
3201 3127
        symbolTypeList = []
3202 3128

  
3203
        try:
3204
            dbPath = os.path.join(self.getCurrentProject().getDbFilePath(), AppDocData.DATABASE)
3205

  
3206
            conn = sqlite3.connect(dbPath)
3129
        conn = sqlite3.connect(self.getTemplateDbPath())
3130
        with conn:
3207 3131
            cursor = conn.cursor()
3208 3132
            sql = 'SELECT UID, Category, Type FROM SymbolType WHERE Category = "' + category + '"'
3209 3133
            try:
......
3216 3140

  
3217 3141
                message = 'error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno)
3218 3142
                App.mainWnd().addMessage.emit(MessageType.Error, message)
3219
        finally:
3220
            conn.close()
3221 3143

  
3222 3144
        return symbolTypeList
3223 3145

  
......
3286 3208
    def getHMBDisplayNameAndUnitsExpression(self):
3287 3209
        res = []
3288 3210

  
3289
        try:
3290
            dbPath = os.path.join(self.getCurrentProject().getDbFilePath(), AppDocData.DATABASE)
3291

  
3292
            conn = sqlite3.connect(dbPath)
3293
            cursor = conn.cursor()
3294
            sql = """SELECT dn.DISPLAY_NAME
3295
                          , hu.Units_Expression
3296
                       FROM DisplayNames dn
3297
                       left join HMBUnits hu
3298
                         on dn.COLUMN_NAME = Hu.Column_Name
3299
                      where dn.Table_Name = 'HMB'
3300
                      order by dn.[Order]"""    
3301
            try:
3302
                cursor.execute(sql)  
3303
                rows = cursor.fetchall()
3304
                for row in rows:
3305
                    res.append((row[0], row[1])) 
3306
            except Exception as ex:
3307
                from App import App
3211
        if self.activeDrawing:
3212
            conn = sqlite3.connect(self.activeDrawing.path)
3213
            with conn:
3214
                cursor = conn.cursor()
3215
                sql = """SELECT dn.DISPLAY_NAME
3216
                                , hu.Units_Expression
3217
                            FROM DisplayNames dn
3218
                            left join HMBUnits hu
3219
                                on dn.COLUMN_NAME = Hu.Column_Name
3220
                            where dn.Table_Name = 'HMB'
3221
                            order by dn.[Order]"""    
3222
                try:
3223
                    cursor.execute(sql)  
3224
                    rows = cursor.fetchall()
3225
                    for row in rows:
3226
                        res.append((row[0], row[1])) 
3227
                except Exception as ex:
3228
                    from App import App
3308 3229

  
3309
                message = 'error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno)
3310
                App.mainWnd().addMessage.emit(MessageType.Error, message)
3311
        finally:
3312
            conn.close()
3230
                    message = 'error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno)
3231
                    App.mainWnd().addMessage.emit(MessageType.Error, message)
3313 3232

  
3314 3233
        return res
3315 3234

  
......
3389 3308
    '''
3390 3309
    def getSymbolCategoryByType(self, type):
3391 3310
        category = None
3392
        try:
3393
            dbPath = os.path.join(self.getCurrentProject().getDbFilePath(), AppDocData.DATABASE)
3394
            
3395
            conn = sqlite3.connect(dbPath)
3396
            cursor = conn.cursor()
3397
            sql = 'SELECT Category FROM SymbolType WHERE type = "' + type + '"'
3398
            cursor.execute(sql)
3399
            rows = cursor.fetchall()
3400
            if rows is not None and len(rows) > 0:
3401
                category = rows[0][0]
3402
        except Exception as ex:
3403
            print('error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno))
3404
        finally:
3405
            conn.close()
3311

  
3312
        conn = sqlite3.connect(self.activeDrawing.path)
3313
        with conn:
3314
            try:
3315
                cursor = conn.cursor()
3316
                sql = 'SELECT Category FROM SymbolType WHERE type = "' + type + '"'
3317
                cursor.execute(sql)
3318
                rows = cursor.fetchall()
3319
                if rows is not None and len(rows) > 0:
3320
                    category = rows[0][0]
3321
            except Exception as ex:
3322
                print('error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno))
3406 3323

  
3407 3324
        return category
3408 3325

  
HYTOS/HYTOS/Drawing.py
30 30
    def setUnits(self, uid):
31 31
        value = {}
32 32

  
33
        unitsList = AppDocData.instance().getDrawingsUnitsByDrawingUID(uid)
33
        unitsList = AppDocData.instance().getDrawingsUnitsByDrawingUID(self)
34 34
        for units in unitsList:            
35 35
            value[units[0]] = units[1]
36 36

  
......
79 79

  
80 80
        if self._hmbTable is None:
81 81
            self._hmbTable = HMBTable()
82
            self._hmbTable.loadDataByDrawingUID(self.UID)
82
            self._hmbTable.load_data_by_drawing(self)
83 83
        
84 84
        return self._hmbTable
85 85

  
HYTOS/HYTOS/HMBTable.py
103 103

  
104 104
    @flowrate_mass.setter
105 105
    def flowrate_mass(self, value):
106
        self._flowrate_mass = float(value)
106
        self._flowrate_mass = float(value) if value else None
107 107

  
108 108
    @property
109 109
    def flowrate_volume(self):
......
111 111

  
112 112
    @flowrate_volume.setter
113 113
    def flowrate_volume(self, value):
114
        self._flowrate_volume = float(value)
114
        self._flowrate_volume = float(value) if value else None
115 115

  
116 116
    @property
117 117
    def density(self):
......
119 119

  
120 120
    @density.setter
121 121
    def density(self, value):
122
        self._density = float(value)
122
        self._density = float(value) if value else None
123 123

  
124 124
    @property
125 125
    def viscosity(self):
......
127 127

  
128 128
    @viscosity.setter
129 129
    def viscosity(self, value):
130
        self._viscosity = float(value)
130
        self._viscosity = float(value) if value else None
131 131

  
132 132
    @property
133 133
    def temperature(self):
......
135 135

  
136 136
    @temperature.setter
137 137
    def temperature(self, value):
138
        self._temperature = float(value)
138
        self._temperature = float(value) if value else None
139 139

  
140 140
    @property
141 141
    def molecular_weight(self):
......
143 143

  
144 144
    @molecular_weight.setter
145 145
    def molecular_weight(self, value):
146
        self._molecular_weight = float(value)
146
        self._molecular_weight = float(value) if value else None
147 147

  
148 148
    @property
149 149
    def specific_heat_ratio(self):
......
151 151

  
152 152
    @specific_heat_ratio.setter
153 153
    def specific_heat_ratio(self, value):
154
        self._specific_heat_ratio = float(value)
154
        self._specific_heat_ratio = float(value) if value else None
155 155

  
156 156
    @property
157 157
    def compress_factor(self):
......
159 159

  
160 160
    @compress_factor.setter
161 161
    def compress_factor(self, value):
162
        self._compress_factor = float(value)
162
        self._compress_factor = float(value) if value else None
163 163

  
164 164
    @property
165 165
    def nominal_pipe_size(self):
......
167 167

  
168 168
    @nominal_pipe_size.setter
169 169
    def nominal_pipe_size(self, value):
170
        self._nominal_pipe_size = float(value)
170
        self._nominal_pipe_size = float(value) if value else None
171 171

  
172 172
    @property
173 173
    def inside_pipe_size(self):
......
175 175

  
176 176
    @inside_pipe_size.setter
177 177
    def inside_pipe_size(self, value):
178
        self._inside_pipe_size = float(value)
178
        self._inside_pipe_size = float(value) if value else None
179 179

  
180 180
    @property
181 181
    def schedule_no(self):
......
191 191

  
192 192
    @straight_length.setter
193 193
    def straight_length(self, value):
194
        self._straight_length = float(value)
194
        self._straight_length = float(value) if value else None
195 195

  
196 196
    @property
197 197
    def equivalent_length(self):
......
199 199

  
200 200
    @equivalent_length.setter
201 201
    def equivalent_length(self, value):
202
        self._equivalent_length = float(value)
202
        self._equivalent_length = float(value) if value else None
203 203

  
204 204
    @property
205 205
    def roughness(self):
......
207 207

  
208 208
    @roughness.setter
209 209
    def roughness(self, value):
210
        self._roughness = float(value)
210
        self._roughness = float(value) if value else None
211 211

  
212 212
    @property
213 213
    def limitation_velocity(self):
......
215 215

  
216 216
    @limitation_velocity.setter
217 217
    def limitation_velocity(self, value):
218
        self._limitation_velocity = float(value)
218
        self._limitation_velocity = float(value) if value else None
219 219

  
220 220
    @property
221 221
    def limitation_pressure_drop(self):
......
223 223

  
224 224
    @limitation_pressure_drop.setter
225 225
    def limitation_pressure_drop(self, value):
226
        self._limitation_pressure_drop = float(value)
226
        self._limitation_pressure_drop = float(value) if value else None
227 227

  
228 228
    @property
229 229
    def velocity(self):
......
231 231

  
232 232
    @velocity.setter
233 233
    def velocity(self, value):
234
        self._velocity = float(value)
234
        self._velocity = float(value) if value else None
235 235

  
236 236
    @property
237 237
    def reynolds(self):
......
239 239

  
240 240
    @reynolds.setter
241 241
    def reynolds(self, value):
242
        self._reynolds = float(value)
242
        self._reynolds = float(value) if value else None
243 243

  
244 244
    @property
245 245
    def friction_factor(self):
......
247 247

  
248 248
    @friction_factor.setter
249 249
    def friction_factor(self, value):
250
        self._friction_factor = float(value)
250
        self._friction_factor = float(value) if value else None
251 251

  
252 252
    @property
253 253
    def pressure_drop(self):
......
255 255

  
256 256
    @pressure_drop.setter
257 257
    def pressure_drop(self, value):
258
        self._pressure_drop = float(value)
258
        self._pressure_drop = float(value) if value else None
259 259

  
260 260
    @property
261 261
    def pressure_drop_friction(self):
......
263 263

  
264 264
    @pressure_drop_friction.setter
265 265
    def pressure_drop_friction(self, value):
266
        self._pressure_drop_friction = float(value)
266
        self._pressure_drop_friction = float(value) if value else None
267 267

  
268 268
    @property
269 269
    def pressure_drop_static(self):
......
271 271

  
272 272
    @pressure_drop_static.setter
273 273
    def pressure_drop_static(self, value):
274
        self._pressure_drop_static = float(value)
274
        self._pressure_drop_static = float(value) if value else None
275 275

  
276 276
    @property
277 277
    def pressure_pipe_end_point(self):
......
279 279

  
280 280
    @pressure_pipe_end_point.setter
281 281
    def pressure_pipe_end_point(self, value):
282
        self._pressure_pipe_end_point = float(value)
282
        self._pressure_pipe_end_point = float(value) if value else None
283 283

  
284 284
    @property
285 285
    def power(self):
......
287 287

  
288 288
    @power.setter
289 289
    def power(self, value):
290
        self._power = float(value)
291

  
290
        self._power = float(value) if value else None
292 291

  
293 292
    def fromRow(row):
294 293
        hmb = HMBData()
......
321 320
        hmb._pressure_pipe_end_point = row[26]
322 321
        hmb._power = row[27]
323 322

  
324

  
325

  
326

  
327

  
328

  
329

  
330 323
        return hmb
331 324
class HMBTable:
332 325
    '''
......
433 426
        @author     humkyung
434 427
        @date       2018.07.12
435 428
    '''
436
    def loadDataByDrawingUID(self, uid):
429
    def load_data_by_drawing(self, drawing):
437 430
        from App import App
438 431
        from AppDocData import AppDocData
439 432

  
440
        try:
441
            if self._hmbs is None:
442
                self._hmbs = []
443

  
444
                appDocData = AppDocData.instance()
445

  
446
                dbPath = os.path.join(appDocData.getCurrentProject().getDbFilePath() , App.NAME + '.db')
433
        if self._hmbs is None:
434
            self._hmbs = []
447 435

  
448
                conn = sqlite3.connect(dbPath)
449
                cursor = conn.cursor()
450
                sql = """select h.UID
451
                              , h.Components_UID
452
                              , h.Stream_No
453
                              , h.Phase_Type
454
                              , h.Flowrate_Mass
455
                              , h.Flowrate_Volume
456
                              , h.Density
457
                              , h.Viscosity
458
                              , h.Temperature
459
                              , h.Molecular_Weight
460
                              , h.Specific_Heat_Ratio
461
                              , h.Compress_Factor
462
                              , h.Nominal_Pipe_Size
463
                              , h.Inside_Pipe_Size
464
                              , h.Schedule_No
465
                              , h.Straight_Length
466
                              , h.Equivalent_Length
467
                              , h.Roughness
468
                              , h.Limitation_Velocity
469
                              , h.Limitation_Pressure_Drop
470
                              , h.Velocity
471
                              , h.Reynolds
472
                              , h.Friction_Factor
473
                              , h.Pressure_Drop
474
                              , h.Pressure_Drop_Friction
475
                              , h.Pressure_Drop_Static
476
                              , h.Pressure_Pipe_End_Point
477
                              , h.Power
478
                           from HMB h
479
                           left join Components c
480
                             on h.Components_UID = c.UID
481
                          where c.Drawings_UID = ?
482
                          order by h.Stream_No"""
483

  
484
                param = (uid, )           
485
                cursor.execute(sql, param)
486
                rows = cursor.fetchall()
487
                for row in rows:
488
                    hmb = HMBData.fromRow(row)
489
                    self._hmbs.append(hmb)
490
        # Catch the exception
491
        except Exception as ex:
492
            # Roll back any change if something goes wrong
493
            conn.rollback()
494
            print('error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno))
495
        finally:
496
            conn.close()
436
            conn = sqlite3.connect(drawing.path)
437
            with conn:
438
                try:
439
                    cursor = conn.cursor()
440
                    sql = """select h.UID
441
                                , h.Components_UID
442
                                , h.Stream_No
443
                                , h.Phase_Type
444
                                , h.Flowrate_Mass
445
                                , h.Flowrate_Volume
446
                                , h.Density
447
                                , h.Viscosity
448
                                , h.Temperature
449
                                , h.Molecular_Weight
450
                                , h.Specific_Heat_Ratio
451
                                , h.Compress_Factor
452
                                , h.Nominal_Pipe_Size
453
                                , h.Inside_Pipe_Size
454
                                , h.Schedule_No
455
                                , h.Straight_Length
456
                                , h.Equivalent_Length
457
                                , h.Roughness
458
                                , h.Limitation_Velocity
459
                                , h.Limitation_Pressure_Drop
460
                                , h.Velocity
461
                                , h.Reynolds
462
                                , h.Friction_Factor
463
                                , h.Pressure_Drop
464
                                , h.Pressure_Drop_Friction
465
                                , h.Pressure_Drop_Static
466
                                , h.Pressure_Pipe_End_Point
467
                                , h.Power
468
                            from HMB h
469
                            left join Components c
470
                                on h.Components_UID = c.UID
471
                            order by h.Stream_No"""
472

  
473
                    cursor.execute(sql)
474
                    rows = cursor.fetchall()
475
                    for row in rows:
476
                        hmb = HMBData.fromRow(row)
477
                        self._hmbs.append(hmb)
478
                # Catch the exception
479
                except Exception as ex:
480
                    # Roll back any change if something goes wrong
481
                    conn.rollback()
482
                    print('error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno))
497 483

  
498 484
        return self._hmbs
499 485
        
HYTOS/HYTOS/ItemPropertyTableWidget.py
1
# coding: utf-8
2

  
3
try:
4
    from PyQt5.QtCore import *
5
    from PyQt5.QtGui import *
6
    from PyQt5.QtWidgets import *
7
except ImportError:
8
    try:
9
        from PyQt4.QtCore import *
10
        from PyQt4.QtGui import *
11
    except ImportError:
12
        raise ImportError("ImageViewerQt: Requires PyQt5 or PyQt4.")
13

  
14
import os
15
import sys
16
import math
17
import re
18

  
19
from EngineeringAbstractItem import QEngineeringAbstractItem
20
from SymbolSvgItem import SymbolSvgItem
21
from EngineeringLineNoTextItem import QEngineeringLineNoTextItem
22
from EngineeringNoteItem import QEngineeringNoteItem
23
from EngineeringTextItem import QEngineeringTextItem
24
from UserInputAttribute import UserInputAttribute
25
from EngineeringSpecBreakItem import QEngineeringSpecBreakItem
26
from EngineeringErrorItem import QEngineeringErrorItem
27
from SymbolAttr import SymbolAttr
28
from AppDocData import *
29
from Drawing import Drawing
30
from enum import Enum
31

  
32
'''
33
    @brief      ItemType
34
    @author     Jeongwoo
35
    @date       2018.04.27
36
    @history    2018.05.10  Jeongwoo    Add LINE_NO
37
'''
38
class ItemType(Enum):
39
    SYMBOL = 1
40
    NOTE = 2
41
    LINE_NO = 3
42

  
43
class QCustomCheckBox(QCheckBox):
44
    def __init__(self, table, row, col):
45
        QCheckBox.__init__(self)
46
        self.table = table
47
        self.row = row
48
        self.col = col
49

  
50
    def state_changed(self, state):
51
        """ check box state is changed """
52
        if self.col == 0:
53
            '''
54
            for index in range(self.table.rowCount()):
55
                data = self.table.item(index, 1).data(Qt.UserRole) if self.table.item(index, 1) is not None else None
56
                if data and type(data) is SymbolAttr:
57
                    widget = self.table.cellWidget(index, 3)
58
                    if widget:
59
                        widget.setEnabled(False) if state else widget.setEnabled(True)
60
                    data.Freeze = self.isChecked()
61

  
62
                    item = self.table.item(index, 3)
63
                    if item:
64
                        item.setFlags(Qt.ItemIsEnabled) if state else item.setFlags(Qt.ItemIsEnabled|Qt.ItemIsEditable|Qt.ItemIsSelectable)
65
                        item.setBackground(Qt.lightGray) if state else item.setBackground(Qt.white)
66
            '''
67

  
68
            widget = self.table.cellWidget(self.row, 3)
69
            if widget:
70
                widget.setEnabled(False) if state else widget.setEnabled(True)
71

  
72
            data = self.table.item(self.row, 1).data(Qt.UserRole)
73
            if data: data.Freeze = self.isChecked()
74

  
75
            item = self.table.item(self.row, 3)
76
            if item:
77
                item.setFlags(Qt.ItemIsEnabled) if state else item.setFlags(Qt.ItemIsEnabled|Qt.ItemIsEditable|Qt.ItemIsSelectable)
78
                item.setBackground(Qt.lightGray) if state else item.setBackground(Qt.white)
79
        elif self.col == 3:
80
            cell = self.table.item(self.row, 1)
81
            if cell:
82
                data = cell.data(Qt.UserRole)
83
                if data is not None:
84
                    if self.table._item: self.table._item.set_property(data.Attribute, self.isChecked())
85

  
86
class QItemPropertyTableWidget(QTableWidget):
87
    def __init__(self, mainWindow):
88
        QTableWidget.__init__(self)
89
        self._item = None
90
        self.mainWindow = mainWindow
91

  
92
        self.cellChanged.connect(self.cellChangedEvent)
93
        self.cellDoubleClicked.connect(self.cellDoubleClickedEvent)
94

  
95
    '''
96
        @brief      Initialize TableWidget
97
        @author     Jeongwoo
98
        @date       18.04.13
99
        @history    humkyung 2018.07.08 show column header
100
    '''
101
    def initItemPropertyTableWidget(self, item=None):
102

  
103
        if item is None:
104
            self.horizontalHeader().hide()
105
            return
106

  
107
        self.horizontalHeader().show()
108

  
109
        category = item.category
110

  
111
        if category == 'Equipment - [ Pressure Drop ]':
112
            self.setColumnCount(2)
113
            self.setHorizontalHeaderLabels(['P. Drop', 'Elevation'])
114
            self.setColumnWidth(0, 80)
115
            self.setColumnWidth(1, 80)
116
        elif category == 'Equipment - [ Pressurized ]':
117
            self.setColumnCount(3)
118
            self.setHorizontalHeaderLabels(['Index', 'P. Drop', 'Elevation'])
119
            self.setColumnWidth(0, 70)
120
            self.setColumnWidth(1, 70)
121
            self.setColumnWidth(2, 10)
122
        elif category == 'Equipment - [ Rotating ]':
123
            self.setColumnCount(2)
124
            self.setHorizontalHeaderLabels(['P. Drop', 'Elevation'])
125
            self.setColumnWidth(0, 80)
126
            self.setColumnWidth(1, 80)
127
        elif category == 'Instrument':
128
            self.setColumnCount(2)
129
            self.setHorizontalHeaderLabels(['P. Drop', 'Elevation'])
130
            self.setColumnWidth(0, 80)
131
            self.setColumnWidth(1, 80)
132

  
133
        self.verticalHeader().hide()
134
        self.horizontalHeader().setStretchLastSection(True)
135
        #self.verticallHeader().setDefaultSectionSize(50)
136

  
137
    '''
138
        @brief  show item's property
139
        @author humkyung
140
        @date   2018.07.03
141
        @history    euisung  2019.01.15     add icon image to line item
142
    '''
143
    def show_item_property(self, item):
144
        try:
145
            from PyQt5 import QtGui
146
            from SymbolAttr import SymbolAttr
147
            from EngineeringStreamlineItem import QEngineeringStreamlineItem
148

  
149
            self._item = item
150

  
151
            self.blockSignals(True)
152

  
153
            if type(item) is QEngineeringStreamlineItem:
154
                self.initItemPropertyTableWidget()
155
                self.initTitleCell(item)
156
                self.initContentsCell()
157
            elif issubclass(type(item), SymbolSvgItem):                
158
                self.onSymbolClicked(item)
159
            elif type(item) is QEngineeringLineNoTextItem:
160
                self.onLineNoClicked(item)
161
            elif type(item) is QEngineeringNoteItem:
162
                noteContentsList = item.findNoteContents(item.text())
163
                self.onNoteClicked(item.text(), noteContentsList)
164
            elif issubclass(type(item), QEngineeringTextItem):
165
                self.onTextClicked(item)            
166
            elif item is None:
167
                self.setRowCount(0)
168
        except Exception as ex:
169
            from App import App 
170

  
171
            message = 'error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno)
172
            App.mainWnd().addMessage.emit(MessageType.Error, message)
173
        finally:
174
            self.blockSignals(False)
175

  
176
    
177
        
178
    '''
179
        @brief      Slot to accept item click event
180
        @author     Jeongwoo
181
        @date       18.04.13
182
        @history    humkyung 2018.04.17 check if given symbol type is SymbolSvgItem
183
    '''
184
    @pyqtSlot(SymbolSvgItem)
185
    def onSymbolClicked(self, symbol):
186
        try:
187
            self.blockSignals(True)
188
            if issubclass(type(symbol), SymbolSvgItem):
189
                self._item = symbol
190
                self.symbolChanged(symbol)
191
            elif type(symbol) is QEngineeringLineNoTextItem:
192
                self.lineNoChanged(symbol)
193
        finally:
194
            self.blockSignals(True)
195

  
196
    '''
197
        @brief      show drawing' attributes
198
        @author     humkyung 
199
        @date       2018.07.07
200
    '''
201
    @pyqtSlot(Drawing)
202
    def onDrawingClicked(self, drawing):
203
        try:
204
            self.blockSignals(True)
205
            self.setRowCount(len(drawing.attrs))
206

  
207
            row = 0
208
            for attr in drawing.attrs:
209
                name = attr[0]
210
                item = QTableWidgetItem(name)
211
                item.setFlags(Qt.ItemIsEnabled)
212
                item.setBackground(Qt.lightGray)
213
                self.setItem(row, 0, item)
214

  
215
                value = attr[1]
216
                item = QTableWidgetItem(value)
217
                item.setFlags(Qt.ItemIsEnabled)
218
                self.setItem(row, 1, item)
219

  
220
                row = row + 1
221
        finally:
222
            self.blockSignals(False)
223

  
224
    def onVendorClicked(self, item):
225
        from SymbolAttr import SymbolAttr
226

  
227
        try:
228
            self.blockSignals(True)
229
            self.initTitleCell(item)
230

  
231
            self.setItem(0, 3, QTableWidgetItem(str(self._item.uid)))
232

  
233
            self.show_item_properties(item)
234
        finally:
235
            self.blockSignals(False)
236

  
237
    def onTextClicked(self, item):
238
        from SymbolAttr import SymbolAttr
239

  
240
        try:
241
            self.blockSignals(True)
242
            self.initTitleCell(item)
243

  
244
            self.setItem(0, 3, QTableWidgetItem(str(self._item.uid)))
245

  
246
            owner_item = QTableWidgetItem('{}'.format('None' if self._item.owner is None else str(self._item.owner)))
247
            owner_item.setFlags(Qt.ItemIsEnabled|Qt.ItemIsSelectable)
248
            self.setItem(1, 3, owner_item)
249

  
250
            """ show icon item """
251
            attr = SymbolAttr()
252
            attr.AttributeType = "OWNER"
253
            self.show_icon_item(1, 2, attr)
254
            self.item(1, 1).setData(Qt.UserRole, attr)
255

  
256
            self.setItem(2, 3, QTableWidgetItem(self._item.type))
257
            self.setItem(3, 3, QTableWidgetItem(self._item.text()))
258
        finally:
259
            self.blockSignals(False)
260

  
261
    '''
262
        @brief      Slot to accept Note item click event
263
        @author     Jeongwoo
264
        @date       18.04.27
265
        @history    humkyung 2018.07.08 change method name to onNoteClicked
266
    '''
267
    @pyqtSlot(str, dict)
268
    def onNoteClicked(self, noteNoStr, noteContentsList):
269
        try:
270
            self.blockSignals(True)
271
            self.noteChanged(noteNoStr, noteContentsList)
272
        finally:
273
            self.blockSignals(False)
274

  
275
    '''
276
        @brief      Slot to accept Line No Item Click event
277
        @author     Jeongwoo
278
        @date       18.05.10
279
        @hisotry    humkyung 2018.07.08 change method name to onLineNoClicked
280
    '''
281
    @pyqtSlot(QEngineeringAbstractItem)
282
    def onLineNoClicked(self, item):
283
        try:
284
            self.blockSignals(True)
285
            self.lineNoChanged(item)
286
        finally:
287
            self.blockSignals(False)
288
        
289
    '''
290
        @brief      Reset table with new SymbolSvgItem
291
        @author     Jeongwoo
292
        @date       18.04.13
293
        @history    .
294
    '''
295
    def symbolChanged(self, item):
296
        self.initItemPropertyTableWidget(item)
297
        #self.initTitleCell(item)
298
        self.initContentsCell()
299

  
300
    '''
301
        @brief      Reset table with note info
302
        @author     Jeongwoo
303
        @date       18.04.27
304
    '''
305
    def noteChanged(self, noteNoStr, noteContentsList):
306
        self.initNoteCell(noteNoStr, noteContentsList)
307

  
308
    '''
309
        @brief      Reset table with line no item
310
        @author     Jeongwoo
311
        @date       18.05.10
312
    '''
313
    def lineNoChanged(self, item):
314
        from EngineeringRunItem import QEngineeringRunItem
315

  
316
        if type(item) is QEngineeringLineNoTextItem:
317
            self.initTitleCell(item)
318
            self.initLineNoCell(item)
319
        elif type(item) is QEngineeringRunItem:
320
            self.initLineRunCell(item)
321

  
322
        """ show tooltip """
323
        for index in range(self.rowCount()):
324
            item = self.item(index, 1)
325
            if item is not None:
326
                item.setToolTip(item.text())
327

  
328
    '''
329
        @brief      Initialize Title Cell
330
        @author     Jeongwoos
331
        @date       18.04.13
332
        @history    Jeongwoo 2018.04.27 Add if-statement by ItemType
333
                    Jeongwoo 2018.05.10 Add if-statement LINE_NO ItemType
334
                    humkyung 2018.08.15 add combobox for line type
335
    '''
336
    def initTitleCell(self, item):
337
        from LineTypeConditions import LineTypeConditions
338
        from EngineeringStreamlineItem import QEngineeringStreamlineItem
339

  
340
        try:
341

  
342
            #self.clear()
343
            #self.setHorizontalHeaderLabels(['', self.tr('Name'), '', self.tr('Value')])
344
            #self.setColumnWidth(0, 20)
345
            #self.setColumnWidth(1, 80)
346
            #self.setColumnWidth(2, 20)
347
            if type(item) is QEngineeringStreamlineItem:
348
                self.setRowCount(7)
349
                self.setItem(0, 1, QTableWidgetItem(self.tr("UID")))
350
                self.setItem(1, 1, QTableWidgetItem(self.tr("Name")))
351
                self.setItem(2, 1, QTableWidgetItem(self.tr("Type")))
352
                self.setItem(3, 1, QTableWidgetItem(self.tr("Angle")))
353
                self.setItem(4, 1, QTableWidgetItem(self.tr("Origin")))
354
                self.setItem(5, 1, QTableWidgetItem(self.tr("OWNER")))
355
                self.setItem(6, 1, QTableWidgetItem(self.tr("Set Specs")))
356
            elif type(item) is QEngineeringErrorItem:
357
                self.setRowCount(7)
358
                self.setItem(0, 1, QTableWidgetItem(self.tr("UID")))
359
                self.setItem(1, 1, QTableWidgetItem(self.tr("Name")))
360
                self.setItem(2, 1, QTableWidgetItem(self.tr("Type")))
361
                self.setItem(3, 1, QTableWidgetItem(self.tr("Angle")))
362
                self.setItem(4, 1, QTableWidgetItem(self.tr("Origin")))
363
                self.setItem(5, 1, QTableWidgetItem(self.tr("OWNER")))
364
                self.setItem(6, 1, QTableWidgetItem(self.tr("Message")))
365
            elif issubclass(type(item), SymbolSvgItem):
366
                self.setRowCount(6)
367
                self.setItem(0, 1, QTableWidgetItem(self.tr("UID")))
368
                self.setItem(1, 1, QTableWidgetItem(self.tr("Name")))
369
                self.setItem(2, 1, QTableWidgetItem(self.tr("Type")))
370
                self.setItem(3, 1, QTableWidgetItem(self.tr("Angle")))
371
                self.setItem(4, 1, QTableWidgetItem(self.tr("Origin")))
372
                self.setItem(5, 1, QTableWidgetItem(self.tr("OWNER")))
373
            elif type(item) is QEngineeringNoteItem:
374
                self.setRowCount(2)
375
                self.setItem(0, 1, QTableWidgetItem(self.tr("Note No")))
376
                self.setItem(1, 1, QTableWidgetItem(self.tr("Desc.")))
377
            elif type(item) is QEngineeringLineNoTextItem:
378
                self.setRowCount(1)
379
                self.setItem(0, 1, QTableWidgetItem(self.tr("UID")))
380
            elif type(item) is QEngineeringLineItem:
381
                self.setRowCount(5)
382
                self.setItem(0, 1, QTableWidgetItem(self.tr('UID')))
383
                self.setItem(1, 1, QTableWidgetItem(self.tr('OWNER')))
384
                widgetItem = QTableWidgetItem(self.tr("Type"))
385
                widgetItem.setData(Qt.UserRole, item)
386
                self.setItem(2, 1, widgetItem)
387
                self._lineTypeComboBox = QComboBox(self)
388
                self._lineTypeComboBox.tag = widgetItem
389
                for lineType in LineTypeConditions.items():
390
                    self._lineTypeComboBox.addItem(lineType.name)
391
                self.setCellWidget(2, 3, self._lineTypeComboBox)
392
                self._lineTypeComboBox.setCurrentText(item.lineType)
393
                self._lineTypeComboBox.currentIndexChanged.connect(self.onLineTypeChanged)           
394
            #else:
395
            #    self.setRowCount(4)
396
            #    self.setItem(0, 1, QTableWidgetItem(self.tr("UID")))
397
            #    self.setItem(1, 1, QTableWidgetItem(self.tr("OWNER")))
398
            #    self.setItem(2, 1, QTableWidgetItem(self.tr("Type")))
399
            #    self.setItem(3, 1, QTableWidgetItem(self.tr("Text")))
400

  
401
            for index in range(self.rowCount()):
402
                item = self.item(index, 1)
403
                if item is not None:
404
                    item.setFlags(Qt.ItemIsEnabled)
405
                    item.setBackground(Qt.lightGray)
406
        except Exception as ex:
407
            from App import App 
408

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

  
412
    '''
413
        @brief  change selected lines' type by selected line type
414
        @author humkyung
415
        @date   2018.08.15
416
    '''
417
    def onLineTypeChanged(self, param):
418
        lineType = self._lineTypeComboBox.itemText(param)
419
        data = self._lineTypeComboBox.tag.data(Qt.UserRole)
420
        if type(data) is QEngineeringLineItem:
421
            self.changeConnectedLineType(data, lineType)
422

  
423
    def changeConnectedLineType(self, line, lineType):
424
        line.lineType = lineType
425
        if type(line.connectors[0].connectedItem) is QEngineeringLineItem and \
426
                (line.connectors[0].connectedItem.connectors[0].connectedItem is line or line.connectors[0].connectedItem.connectors[1].connectedItem is line) and \
427
                line.connectors[0].connectedItem.lineType is not lineType:
428
            self.changeConnectedLineType(line.connectors[0].connectedItem, lineType)
429
        if type(line.connectors[1].connectedItem) is QEngineeringLineItem and \
430
                (line.connectors[1].connectedItem.connectors[0].connectedItem is line or line.connectors[1].connectedItem.connectors[1].connectedItem is line) and \
431
                line.connectors[1].connectedItem.lineType is not lineType:
432
            self.changeConnectedLineType(line.connectors[1].connectedItem, lineType)
433

  
434
    def show_icon_item(self, row, col, prop):
435
        """ show icon item on grid """
436
        from PyQt5 import QtGui
437

  
438
        if prop.is_selectable or prop.AttributeType == 'OWNER' or prop.AttributeType == 'CONN':
439
            icon = QtGui.QIcon()
440
            icon.addPixmap(QtGui.QPixmap(":/newPrefix/doubleclick.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
441
            icon_item = QTableWidgetItem('')
442
            icon_item.setFlags(Qt.ItemIsEnabled)
443
            icon_item.setIcon(icon)
444
            self.setItem(row, col, icon_item)
445
        elif prop.AttributeType == "String":
446
            icon = QtGui.QIcon()
447
            icon.addPixmap(QtGui.QPixmap(":/newPrefix/type.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
448
            icon_item = QTableWidgetItem()
449
            icon_item.setIcon(icon)
450
            self.setItem(row, col, icon_item)
451
        else:
452
            item = QTableWidgetItem()
453
            item.setFlags(Qt.ItemIsEditable)
454
            self.setItem(row, col, item)
455

  
456
    def show_item_properties(self, item):
457
        """ show item properties on grid """
458
        from PyQt5 import QtGui
459

  
460
        row = self.rowCount()
461
        if hasattr(item, '_properties'):
462
            self.setRowCount(row + len(item.properties))
463

  
464
            for prop,value in item.properties.items():
465
                try:
466
                    """ show freeze state """
467
                    checkbox = QCustomCheckBox(self, row, 0)
468
                    checkbox.setChecked(prop.Freeze)
469
                    checkbox.stateChanged.connect(checkbox.state_changed)
470
                    self.setCellWidget(row, 0, checkbox)
471

  
472
                    """ show property name """
473
                    key_item = QTableWidgetItem(prop.DisplayAttribute if prop.DisplayAttribute else prop.Attribute)
474
                    key_item.setFlags(Qt.ItemIsEnabled)
475
                    key_item.setBackground(Qt.lightGray)
476
                    key_item.setData(Qt.UserRole, prop)
477
                    self.setItem(row, 1, key_item)
478

  
479
                    """ show icon item """
480
                    self.show_icon_item(row, 2, prop)
481

  
482
                    """ show property value """
483
                    if prop.is_selectable:
484
                        value_item = QTableWidgetItem(str(value.uid) if hasattr(value, 'uid') else value)
485
                        value_item.setFlags(Qt.ItemIsEnabled|Qt.ItemIsSelectable)
486
                        self.setItem(row, 3, value_item)
487
                    else:
488
                        if prop.AttributeType == 'Boolean':
489
                            self.checkbox_cell = QCustomCheckBox(self, row, 3)
490
                            self.checkbox_cell.setChecked(True if value and str(value) == 'True' else False)
491
                            self.checkbox_cell.stateChanged.connect(self.checkbox_cell.state_changed)
492
                            #if prop.Attribute == 'Freeze': self.checkbox_cell.stateChanged.connect(item.freeze_item.update_freeze)
493
                            self.setCellWidget(row, 3, self.checkbox_cell)
494
                        else:
495
                            value_item = QTableWidgetItem(value if value else '')
496
                            value_item.setFlags(Qt.ItemIsEnabled|Qt.ItemIsSelectable|Qt.ItemIsEditable)
497
                            self.setItem(row, 3, value_item)
498

  
499
                    checkbox.state_changed(checkbox.isChecked())
500
                    
501
                    row = row + 1
502
                except Exception as ex:
503
                    from App import App 
504

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

  
508
    def show_item_attributes(self, item):
509
        """ show item's attributes on grid """
510
        from PyQt5 import QtGui
511

  
512
        row = self.rowCount()
513
        attrs = item.getAttributes()
514

  
515
        # display attributes of symbol
516
        if attrs is not None:
517
            self.setRowCount(row + len(attrs))
518

  
519
            for key,value in attrs.items():
520
                try:
521
                    """ show freeze state """
522
                    checkbox = QCustomCheckBox(self, row, 0)
523
                    checkbox.setChecked(key.Freeze)
524
                    checkbox.stateChanged.connect(checkbox.state_changed)
525
                    self.setCellWidget(row, 0, checkbox)
526

  
527
                    """ show property name """
528
                    key_item = QTableWidgetItem(key.DisplayAttribute if key.DisplayAttribute else key.Attribute)
529
                    key_item.setBackground(Qt.lightGray)
530
                    key_item.setData(Qt.UserRole, key)
531
                    self.setItem(row, 1, key_item)
532

  
533
                    """ show icon item """
534
                    self.show_icon_item(row, 2, key)
535

  
536
                    value_item = QTableWidgetItem(str(value))
537
                    value_item.setFlags(Qt.ItemIsEnabled|Qt.ItemIsSelectable|Qt.ItemIsEditable)
538

  
539
                    if type(item) is QEngineeringSpecBreakItem:
540
                        if key.Attribute == 'UpStream' or key.Attribute == 'DownStream':
541
                            UpDownItem = QTableWidgetItem('{}'.format('None' if value is None else value))
542
                            self.setItem(row, 3, UpDownItem)
543
                        elif key.AttributeType == 'Spec':
544
                            self.setItem(row, 3, QTableWidgetItem(key.Attribute))
545
                    else:
546
                        self.setItem(row, 3, value_item)
547

  
548
                    checkbox.state_changed(checkbox.isChecked())
549

  
550
                    row = row + 1
551
                except Exception as ex:
552
                        from App import App 
553

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

  
557
    def show_item_connectors(self, item):
558
        """ show items' connectors on grid """
559
        from PyQt5 import QtGui
560
        from SymbolAttr import SymbolAttr
561

  
562
        row = 0 #self.rowCount()
563
        self.setRowCount(row + len(item.connectors))
564
        
565
        count = 1
566
        for connector in item.connectors:
567
            connector_item = QTableWidgetItem('{}'.format(count))
568
            connector_item.setFlags(Qt.ItemIsEnabled)
569
            connector_item.setBackground(Qt.lightGray)
570
            connector_item.setTextAlignment(Qt.AlignHCenter | Qt.AlignVCenter)
571
            self.setItem(row, 0, connector_item)
572

  
573
            #attr = SymbolAttr()
574
            #attr.AttributeType = "CONN"
575
            #attr.AttrAt = count
576
            #connector_item.setData(Qt.UserRole, attr)
577

  
578
            """ show icon item """
579
            #self.show_icon_item(row, 2, attr)
580

  
581
            #connector_item = QTableWidgetItem('{}'.format('None' if connector.connectedItem is None else str(connector.connectedItem)))
582
            #connector_item.setFlags(Qt.ItemIsEnabled|Qt.ItemIsSelectable)
583
            #self.setItem(row, 3, connector_item)
584
            
585
            row = row + 1
586
            count = count + 1
587

  
588
    '''
589
        @brief      Initialize Contents Cell
590
        @author     Jeongwoo
591
        @date       18.04.13
592
        @history    humkyung 2018.06.14 display symbol attributes 
593
                    humkyung 2018.07.05 display connectivity
594
                    euisung  2019.01.15 edit specbreak
595
    '''
596
    def initContentsCell(self):
597
        from PyQt5 import QtGui
598
        from SymbolAttr import SymbolAttr
599

  
600
        try:
601
            if self._item is not None and issubclass(type(self._item), SymbolSvgItem):
602
                docData = AppDocData.instance()
603

  
604
                '''
605
                self.setItem(0, 3, QTableWidgetItem(str(self._item.uid)))
606
                self.setItem(1, 3, QTableWidgetItem(self._item.name))
607
                self.setItem(2, 3, QTableWidgetItem(self._item.type))
608
                self.setItem(3, 3, QTableWidgetItem(str(round(math.degrees(self._item.angle)))))
609
                self.setItem(4, 3, QTableWidgetItem(str(self._item.origin)))
610
                owner_item = QTableWidgetItem('{}'.format('None' if self._item.owner is None else str(self._item.owner)))
611
                self.setItem(5, 3, owner_item)
612

  
613
                for index in range(self.rowCount()):
614
                    item = self.item(index, 3)
615
                    if item is not None:
616
                        item.setFlags(Qt.ItemIsEnabled|Qt.ItemIsSelectable)
617

  
618
                """ show icon item """
619
                attr = SymbolAttr()
620
                attr.AttributeType = "OWNER"
621
                self.show_icon_item(5, 2, attr)
622
                self.item(5, 1).setData(Qt.UserRole, attr)
623

  
624
                #if type(self._item) is not QEngineeringSpecBreakItem and type(self._item) is not QEngineeringErrorItem:
625
                    #self.show_item_properties(self._item)
... 이 차이점은 표시할 수 있는 최대 줄수를 초과해서 이 차이점은 잘렸습니다.

내보내기 Unified diff

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