프로젝트

일반

사용자정보

개정판 2b9f1680

ID2b9f1680bafefc24a7561b1d990cd065fe350e40
상위 a6a2273e
하위 16c4b23c

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

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

Change-Id: I136c93f0465c9672e40e4146b9be99721995cc5a

차이점 보기:

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

  

내보내기 Unified diff

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