프로젝트

일반

사용자정보

개정판 24219f3d

ID24219f3d466c1c7643e35775921ea60b3e1d8504
상위 93128b71
하위 b24ce137

김정우 이(가) 약 7년 전에 추가함

SG_DbHelper 에 있던 메소드를 AppDocData 에 이동

차이점 보기:

DTI_PID/DTI_PID/AppDocData.py
100 100
        return self.currentPidSource
101 101

  
102 102
    '''
103
        @brief      Check if Exist data or not, Moved from SG_DbHelper
104
        @author     Jeongwoo
105
        @date       2018.05.03
106
    '''
107
    def isExistData(self, fieldName, data):
108
        rows = None
109
        try:
110
            dbPath = self.getCurrentProject().getDbFilePath() + "/ITI_PID.db"
111

  
112
            conn = sqlite3.connect(dbPath)
113
            cursor = conn.cursor()
114
            sql = ""
115
            if isinstance(data, str):
116
                sql = "SELECT * FROM Symbol WHERE " + fieldName + " = '"+ data +"'"
117
            else:
118
                sql = "SELECT * FROM Symbol WHERE " + fieldName + " = "+ str(data) +""
119
            cursor.execute(sql)
120
            rows = cursor.fetchall()
121
        except Error as e:
122
            print(e)
123
        finally:
124
            conn.close()
125
            if rows is not None and len(rows) > 0:
126
                return True
127
            else:
128
                return False
129

  
130
    '''
131
        @brief      Check if exist file name or not, Moved from SG_DbHelper
132
        @author     Jeongwoo
133
        @date       2018.05.03
134
    '''
135
    def isExistFileName(self, name):
136
        rows = None
137
        try:
138
            dbPath = self.getCurrentProject().getDbFilePath() + "/ITI_PID.db"
139
            conn = sqlite3.connect(dbPath)
140
            cursor = conn.cursor()
141
            sql = "SELECT * FROM Symbol WHERE name = '"+ name +"'"
142
            cursor.execute(sql)
143
            rows = cursor.fetchall()
144
        except Error as e:
145
            print(e)
146
        finally:
147
            conn.close()
148
            if rows is not None and len(rows) > 0:
149
                return True
150
            else:
151
                return False
152

  
153
    '''
154
        @brief      Insert new symbol into Symbol Table, Moved from SG_DbHelper
155
        @author     Jeongwoo
156
        @date       2018.05.03
157
    '''
158
    def insertSymbol(self, symbol):
159
        isAdded = False
160
        try:
161
            dbPath = self.getCurrentProject().getDbFilePath() + "/ITI_PID.db"
162
            conn = sqlite3.connect(dbPath)
163
            
164
            INSERT_SYMBOL_SQL = '''
165
                INSERT INTO Symbol(symId, name, type, threshold, minMatchPoint, isDetectOrigin, rotationCount, ocrOption, isContainChild, originalPoint, connectionPoint, baseSymbol, additionalSymbol, isExceptDetect) 
166
                VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);
167
            '''
168

  
169
            cursor = conn.cursor()
170
            query = (symbol.getId(), symbol.getName(), symbol.getType(), symbol.getThreshold()
171
                           , symbol.getMinMatchCount(), symbol.getIsDetectOnOrigin(), symbol.getRotationCount()
172
                           , symbol.getOcrOption(), symbol.getIsContainChild()
173
                           , symbol.getOriginalPoint(), symbol.getConnectionPoint()
174
                           , symbol.getBaseSymbol(), symbol.getAdditionalSymbol(), symbol.getIsExceptDetect())
175
            cursor.execute(INSERT_SYMBOL_SQL, query)
176
            conn.commit()
177
            isAdded = True
178
        except Error as e:
179
            print(e)
180
        finally:
181
            conn.close()
182
            return (isAdded, symbol.getType(), symbol.getName(), symbol.getPath())
183

  
184
    '''
185
        @brief      Update symbol in Symbol Table, Moved from SG_DbHelper
186
        @author     Jeongwoo
187
        @date       2018.05.03
188
    '''
189
    def updateSymbol(self, symbol):
190
        isUpdated = False
191
        try:
192
            dbPath = self.getCurrentProject().getDbFilePath() + "/ITI_PID.db"
193
            conn = sqlite3.connect(dbPath)
194
            
195
            UPDATE_SYMBOL_SQL = '''
196
                UPDATE Symbol
197
                SET
198
                    symId = ?, name = ?, type = ?, threshold = ?, minMatchPoint = ?, isDetectOrigin = ?,
199
                    rotationCount = ?, ocrOption = ?, isContainChild = ?, originalPoint = ?, connectionPoint = ?,
200
                    baseSymbol = ?, additionalSymbol = ?, isExceptDetect = ?
201
                WHERE uid = ?
202
            '''
203
            
204
            cursor = conn.cursor()
205
            query = (symbol.getId(), symbol.getName(), symbol.getType(), symbol.getThreshold()
206
                           , symbol.getMinMatchCount(), symbol.getIsDetectOnOrigin(), symbol.getRotationCount()
207
                           , symbol.getOcrOption(), symbol.getIsContainChild()
208
                           , symbol.getOriginalPoint(), symbol.getConnectionPoint()
209
                           , symbol.getBaseSymbol(), symbol.getAdditionalSymbol(), symbol.getIsExceptDetect(), symbol.getUid())
210
            cursor.execute(UPDATE_SYMBOL_SQL, query)
211
            conn.commit()
212
            isUpdated = True
213
        except Error as e:
214
            print(e)
215
        finally:
216
            conn.close()
217
            return (isUpdated, symbol.getType(), symbol.getName(), symbol.getPath())
218

  
219
    '''
103 220
        @brief      Get Detecting Target Symbol List (Field 'isExceptDetect' == False(0))
104 221
        @author     Jeongwoo
105 222
        @date       18.04.24
DTI_PID/DTI_PID/QSymbolEditorDialog.py
7 7
import os
8 8
import sqlite3
9 9
import sys
10
import SG_DbHelper
11 10
import symbol, SymbolBase
12 11
import potrace
13 12

  
......
25 24
    '''
26 25
        @history    2018.05.02  Jeongwoo    Add variables (self.offsetX, self.offsetY, self.newSym)
27 26
                    2018.05.03  Jeongwoo    Remove parameter in SG_DbHelper()
27
                                            Remove self.dbHelper variable
28 28
    '''
29 29
    def __init__(self, parent, image, project, selectedSymbol = None):
30 30
        QDialog.__init__(self, parent)
......
41 41
        self.offsetX = 0
42 42
        self.offsetY = 0
43 43
        self.newSym = None
44
        self.dbHelper = SG_DbHelper.SG_DbHelper()
45 44

  
46 45
    '''
47 46
        @brief  Set up QtImageViewer and QImage
......
222 221
                If the [Name] exists, add number like [FILE_NAME(1), FILE_NAME(2), ...]
223 222
                Recursive function
224 223
        @history    2018.05.02  Jeongwoo    Change isExistFileName's parameter (Dir → newName)
224
                    2018.05.03  Jeongwoo    Change self.dbHelper to AppDocData
225 225
    '''
226 226
    def makeFileName(self, type, originName, newName):
227 227
        imageFolderDir = self.project.getImageFilePath()
228 228
        imageDir = imageFolderDir + "/" + type + "/" + newName + ".png"
229 229
        svgFolderDir = self.project.getSvgFilePath()
230 230
        svgDir = svgFolderDir + "/" + type + "/" + newName + ".svg"
231
        if (os.path.exists(imageDir)) or (self.dbHelper.isExistFileName(newName) or (os.path.exists(svgDir))):
231
        if (os.path.exists(imageDir)) or (AppDocData.instance().isExistFileName(newName) or (os.path.exists(svgDir))):
232 232
            self.FILE_NUMBER = self.FILE_NUMBER + 1
233 233
            imgName = originName + "({})".format(self.FILE_NUMBER)
234 234
            return self.makeFileName(originName, imgName)
......
315 315
        @brief  Called when Save Button Clicked
316 316
                Validation Check → Make Symbol Data → Insert Symbol Data into DB → Save png and svg files
317 317
        @history    2018.05.03  Jeongwoo    Change parameters on method 'deleteImageAndSvg'
318
                                            Change self.dbHelper to AppDocData
318 319
    '''
319 320
    def accept(self):
320 321
        print("save")
......
324 325
            print("valid symbol info")
325 326

  
326 327
            if self.selectedSymbol is None:
327
                isSuccess, fileType, fileName, imagePath = self.dbHelper.insertSymbol(self.makeSymbolData())
328
                isSuccess, fileType, fileName, imagePath = AppDocData.instance().insertSymbol(self.makeSymbolData())
328 329
            else:
329
                isSuccess, fileType, fileName, imagePath = self.dbHelper.updateSymbol(self.makeSymbolData())
330
                isSuccess, fileType, fileName, imagePath = AppDocData.instance().updateSymbol(self.makeSymbolData())
330 331

  
331 332
            if isSuccess:
332 333
                try:
......
388 389

  
389 390
    '''
390 391
        @history    2018.05.03  Jeongwoo    Change Parameters
392
                                            Change self.dbHelper to AppDocData
391 393
    '''
392 394
    def resetUpdateSymbol(self, imagePath, svgPath):
393 395
        self.deleteImageAndSvg(imagePath, svgPath)
394 396

  
395
        SG_DbHelper.SG_DbHelper().updateSymbol(self.selectedSymbol)
397
        AppDocData.instance().updateSymbol(self.selectedSymbol)
396 398

  
397 399
    def keyPressEvent(self, event):
398 400
        if event.key() == QtCore.Qt.Key_Delete:
......
594 596
    '''
595 597
        @brief  Validation Check
596 598
        @return (isValid, errorMsg)
599
        @history    2018.05.03  Jeongwoo    Change self.dbHelper to AppDocData
597 600
    '''
598 601
    def isValidSymbolInfo(self):
599 602
        print("isValid")
......
610 613
        lastId = -1
611 614
        if self.selectedSymbol is not None:
612 615
            lastId = self.selectedSymbol.getId()
613
        if lastId != id and self.dbHelper.isExistData('symId', id):
616
        if lastId != id and AppDocData.instance().isExistData('symId', id):
614 617
            infoTitle = self.ui.idLabel.text()
615 618
            return (False, EXCEPTION_MSG_DUPLICATED_FORMAT.format(infoTitle))
616 619

  
DTI_PID/DTI_PID/SG_DbHelper.py
6 6
from sqlite3 import Error
7 7
from AppDocData import AppDocData
8 8

  
9

  
10
#############################################################
11
#           NOT USED
12
#############################################################
13

  
14

  
9 15
class SG_DbHelper():
10 16
    ROOT_DIR = ""
11 17
    DB_PATH = "db"

내보내기 Unified diff

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