프로젝트

일반

사용자정보

통계
| 개정판:

hytos / DTI_PID / DTI_PID / QSymbolEditorDialog.py @ 80696a97

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

1
# coding: utf-8
2
from PyQt5 import QtCore, QtGui, QtWidgets
3
from PyQt5.QtWidgets import *
4
from PyQt5.QtGui import *
5
from QtImageViewer import QtImageViewer
6
import os
7
import sqlite3
8
import sys
9
import SG_DbHelper
10
import symbol, SymbolBase
11
import potrace
12

    
13
import UI_SymbolEditor
14
from AppDocData import AppDocData
15

    
16

    
17
sys.path.insert(0, os.path.dirname(os.path.realpath(__file__)) + '\\Commands')
18
import CropCommand, HandCommand, ZoomCommand, PenCommand, EraserCommand, AreaEraserCommand, OriginalPointCommand, ConnectionPointCommand, AreaZoomCommand, FitImageCommand
19

    
20

    
21
class QSymbolEditorDialog(QDialog):
22
    FILE_NUMBER = 0
23

    
24
    def __init__(self, parent, image, project, selectedSymbol = None):
25
        QDialog.__init__(self, parent)
26
        self.image = image
27
        self.selectedSymbol = selectedSymbol
28
        self.project = project
29
        self.ui = UI_SymbolEditor.Ui_Dialog()
30
        self.ui.setupUi(self)
31
        self.setupImageViewer()
32
        self.setupTools()
33
        self.initForms()
34
        self.initContents()
35
        self.isAccepted = False
36
        self.dbHelper = SG_DbHelper.SG_DbHelper(self.project.getPath())
37

    
38
    '''
39
        @brief  Set up QtImageViewer and QImage
40
    '''
41
    def setupImageViewer(self):
42
        x = self.ui.imageViewContainer.x()
43
        y = self.ui.imageViewContainer.y()
44
        width = self.ui.imageViewContainer.frameGeometry().width()
45
        height = self.ui.imageViewContainer.frameGeometry().height()
46
        self.ui.imageView = QtImageViewer()
47
        self.ui.imageView.setGeometry(QtCore.QRect(0, y, height, height))
48
        self.ui.imageView.aspectRatioMode = QtCore.Qt.KeepAspectRatio
49
        self.ui.imageView.setHorizontalScrollBarPolicy(QtCore.Qt.ScrollBarAsNeeded)
50
        self.ui.imageView.setVerticalScrollBarPolicy(QtCore.Qt.ScrollBarAsNeeded)
51
        self.ui.imageView.canZoom = True
52
        self.ui.imageView.canPan = True
53
        image = self.image.copy()
54
        self.imgW = image.width()
55
        self.imgH = image.height()
56
        image = image.scaled(self.imgW, self.imgH)
57
        self.ui.imageView.setImage(image)
58
        self.ui.imageViewerContainerLayout.addWidget(self.ui.imageView)
59

    
60
    '''
61
        @brief  Set up Hand, Crop, ETC Tools
62
    '''
63
    def setupTools(self):
64
        self.ui.handButton.clicked.connect(self.handToolClickEvent)
65
        self.ui.cropButton.clicked.connect(self.cropToolClickEvent)
66
        self.ui.penButton.clicked.connect(self.penToolClickEvent)
67
        self.ui.penWidthSpinBox.valueChanged.connect(self.penWidthChangedEvent)
68
        self.ui.eraserButton.clicked.connect(self.eraserToolClickEvent)
69
        self.ui.eraserSpinBox.valueChanged.connect(self.eraserWidthChangedEvent)
70
        self.ui.areaEraserButton.clicked.connect(self.areaEraserToolClickEvent)
71
        self.ui.fitImageButton.clicked.connect(self.fitImageToolClickEvent)
72
        self.ui.zoomButton.clicked.connect(self.zoomToolClickEvent)
73
        self.ui.areaZoomButton.clicked.connect(self.areaZoomToolClickEvent)
74
        self.ui.initZoomButton.clicked.connect(self.zoomInitToolClickEvent)
75
        self.ui.guidelineCheckbox.stateChanged.connect(self.guidelineStateChangedEvent)
76
        #self.ui.additionalSymbolListWidget.keyPressEvent.connect(self.additionalSymbolListKeyPressEvent)
77
        #self.ui.connectionPointList.keyPressEvent.connect(self.additionalSymbolListKeyPressEvent)
78

    
79
    '''
80
        @brief  Init Forms with type and default values
81
    '''
82
    def initForms(self):
83
        self.ui.idLineEdit.setValidator(QRegExpValidator(QtCore.QRegExp("^[1-9]\d+$")))
84
        self.ui.thresholdLineEdit.setValidator(QRegExpValidator(QtCore.QRegExp("^[0-9]\d+$"))) # ([0-1]{1}[.])?[0-9]+
85
        self.ui.minMatchPointLineEdit.setValidator(QRegExpValidator(QtCore.QRegExp("^[0-9]\d+$")))
86
        self.initIsOriginDetectComboBoxItems()
87
        self.initOcrOptionComboBoxItems()
88
        self.initDefaultSymbolDirectionComboBoxItems()
89
        self.ui.addAdditionalSymbolButton.clicked.connect(self.addAdditionalSymbolEvent)
90
        self.ui.addOriginalPointButton.clicked.connect(self.addOriginalPoint)
91
        self.ui.addConnectionPointButton.clicked.connect(self.addConnectionPoint)
92
        self.initBaseSymbolComboBoxItems()
93
        self.initAdditionalSymbolComboBoxItems()
94
        
95
    '''
96
        @brief  Set data on forms, For modifying symbol
97
    '''
98
    def initContents(self):
99
        self.ui.targetDBLineEdit.setText(self.project.getPath()+'/db/ITI_PID.db')
100
        if self.selectedSymbol is not None:
101
            self.ui.idLineEdit.setText(str(self.selectedSymbol.getId()))
102
            self.ui.nameLineEdit.setText(self.selectedSymbol.getName())
103
            self.ui.thresholdLineEdit.setText(str(int(self.selectedSymbol.getThreshold() * 100)))
104
            self.ui.minMatchPointLineEdit.setText(str(self.selectedSymbol.getMinMatchCount()))
105
            self.ui.ocrOptionComboBox.setCurrentIndex(self.ui.ocrOptionComboBox.findData(self.selectedSymbol.getOcrOption()))
106
            self.ui.rotationCountSpinBox.setValue(self.selectedSymbol.getRotationCount())
107
            self.ui.isContainChildCheckBox.setChecked(True if self.selectedSymbol.getIsContainChild() else False)
108
            self.ui.baseSymbolComboBox.setCurrentIndex(self.ui.baseSymbolComboBox.findText(self.selectedSymbol.getBaseSymbol()))
109

    
110
            additionalSymbol = self.selectedSymbol.getAdditionalSymbol()
111
            if additionalSymbol is not None and len(additionalSymbol) > 0:
112
                splitAdditionalSymbolList = additionalSymbol.split("/")
113
                for symString in splitAdditionalSymbolList:
114
                    splitSymString = symString.split(",")
115
                    self.addAdditionalSymbol(splitSymString[0], splitSymString[1])
116

    
117
            originalPoint = self.selectedSymbol.getOriginalPoint()
118
            self.ui.originalPointLineEdit.setText(originalPoint)
119
            OriginalPointCommand.OriginalPointCommand.drawCircle(self.ui.imageView, originalPoint.split(",")[0], originalPoint.split(",")[1])
120
            self.ui.imageView.isOriginalPointSelected = True
121

    
122
            connectionPoint = self.selectedSymbol.getConnectionPoint()
123
            if connectionPoint is not None and len(connectionPoint) > 0:
124
                splitConnectionPointList = connectionPoint.split("/")
125
                for conString in splitConnectionPointList: # conString : x,y
126
                    self.ui.connectionPointList.addItem(conString)
127
                    ConnectionPointCommand.ConnectionPointCommand.drawCircle(self.ui.imageView, conString.split(",")[0], conString.split(",")[1])
128

    
129
    '''
130
        @brief  Init ComboBox Items For DB Field [IsDetectOrigin]
131
    '''
132
    def initIsOriginDetectComboBoxItems(self):
133
        for item in AppDocData.instance().getIsOriginDetectComboBoxItems():
134
            self.ui.isOriginDetectComboBox.addItem(item[0], item[1]) # 0 : text / 1 : data(integer)
135

    
136
    '''
137
        @brief  Init ComboBox Items For DB Field [OcrOption]
138
    '''
139
    def initOcrOptionComboBoxItems(self):
140
        for item in AppDocData.instance().getOcrOptionComboBoxItems():
141
            self.ui.ocrOptionComboBox.addItem(item[0], item[1]) # 0 : text / 1 : data(integer)
142
        
143
    '''
144
        @brief  Init ComboBox Items For Direction of DB Field [additionalSymbol]
145
    '''
146
    def initDefaultSymbolDirectionComboBoxItems(self):
147
        for item in AppDocData.instance().getDefaultSymbolDirectionComboBoxItems():
148
            self.ui.defaultSymbolDirectionComboBox.addItem(item[0], item[1]) # 0 : text / 1 : data(integer)
149
        
150
    '''
151
        @brief  Init ComboBox Items For DB Field [baseSymbol]
152
    '''
153
    def initBaseSymbolComboBoxItems(self):
154
        for name in AppDocData.instance().getBaseSymbolComboBoxItems():
155
            self.ui.baseSymbolComboBox.addItem(name)
156
            
157
    '''
158
        @brief  Init ComboBox Items For symbolName of DB Field [additionalSymbol]
159
    '''
160
    def initAdditionalSymbolComboBoxItems(self):
161
        for name in AppDocData.instance().getAdditionalSymbolComboBoxItems():
162
            self.ui.additionalSymbolComboBox.addItem(name)
163
    
164
    '''
165
        @brief  remove ConnectionPoint Circles (Using for loop)
166
    '''
167
    def removeConnectionPointCircles(self, circlePointList):
168
        for circlePoint in circlePointList:
169
            self.removeConnectionPointCircle(circlePoint)
170
            
171
    '''
172
        @brief  remove each ConnectionPoint Circle
173
    '''
174
    def removeConnectionPointCircle(self, circlePoint):
175
        self.ui.imageView.scene.removeItem(self.ui.imageView.scene.itemAt(QtCore.QPointF(int(circlePoint.x()), int(circlePoint.y())), QTransform()))
176
        
177
    '''
178
        @brief  Display this QDialog
179
    '''
180
    def showDialog(self):
181
        self.setWindowFlags(self.windowFlags() & ~QtCore.Qt.WindowContextHelpButtonHint)
182
        #self.show()
183
        self.exec_()
184
        return self.isAccepted
185
    
186
    '''
187
        @brief  Using input [Name], make file name
188
                If the [Name] exists, add number like [FILE_NAME(1), FILE_NAME(2), ...]
189
                Recursive function
190
    '''
191
    def makeFileName(self, originName, newName):
192
        imageFolderDir = self.project.getPath() + "/image"
193
        imageDir = imageFolderDir + "/" + newName + ".png"
194
        svgFolderDir = self.project.getPath() + "/svg"
195
        svgDir = svgFolderDir + "/" + newName + ".svg"
196
        if (os.path.exists(imageDir)) or (self.dbHelper.isExistFileName(imageDir) or (os.path.exists(svgDir))):
197
            self.FILE_NUMBER = self.FILE_NUMBER + 1
198
            imgName = originName + "({})".format(self.FILE_NUMBER)
199
            return self.makeFileName(originName, imgName)
200
        else:
201
            return newName
202
        
203
    '''
204
        @brief  Make symbol object for saving on DB
205
    '''
206
    def makeSymbolData(self):
207
        uid = -1
208
        if self.selectedSymbol is not None:
209
            uid = self.selectedSymbol.getUid()
210
        symId = self.ui.idLineEdit.text()
211
        name = self.ui.nameLineEdit.text()
212
        type = '' #Empty
213
        self.FILE_NUMBER = 0
214
        lastName = ""
215
        if self.selectedSymbol is not None:
216
            lastName = self.selectedSymbol.getName()
217
        fileName = ""
218
        if name == lastName:
219
            fileName = name
220
        else:
221
            fileName = self.makeFileName(name, name)
222
        path = self.project.getPath() + "/image/" + fileName + ".png"
223
        threshold = self.ui.thresholdLineEdit.text()
224
        minMatchPoint = self.ui.minMatchPointLineEdit.text()
225
        isDetectOnOrigin = self.ui.isOriginDetectComboBox.currentData()
226
        rotationCount = self.ui.rotationCountSpinBox.value()
227
        ocrOption = self.ui.ocrOptionComboBox.currentData()
228
        isContainChild = 1 if self.ui.isContainChildCheckBox.isChecked() else 0
229
        originalPoint = self.ui.originalPointLineEdit.text()
230
        connectionPoint = self.makeConnectionPointListString()
231
        baseSymbol = self.ui.baseSymbolComboBox.currentText()
232
        additionalSymbol = self.makeAdditionalSymbolListString()
233

    
234
        convertedThreshold = int(threshold) / 100.0
235

    
236
        newSym = symbol.SymbolBase(int(symId), fileName, type, path, convertedThreshold, int(minMatchPoint), isDetectOnOrigin
237
                                   , rotationCount, ocrOption, isContainChild, originalPoint, connectionPoint, baseSymbol, additionalSymbol, uid)
238

    
239
        return newSym
240
    
241
    '''
242
        @brief  Make AdditionalSymbol String
243
                [AdditionalSymbolString = DIRECTION,SYMBOL_NAME/DIRECTION,SYMBOL_NAME/...]
244
    '''
245
    def makeAdditionalSymbolListString(self):
246
        ret = ""
247
        listItems = []
248
        for index in range(self.ui.additionalSymbolListWidget.count()):
249
            listItems.append(self.ui.additionalSymbolListWidget.item(index))
250
        if listItems is not None:
251
            for index in range(len(listItems)):
252
                item = listItems[index]
253
                text = item.text()
254
                if index != 0:
255
                    ret = ret + "/"
256
                ret = ret + text
257
        return ret
258
    
259
    '''
260
        @brief  Make ConnectionPoint String
261
                [ConnectionPointString = x1,y1/x2,y2/...]
262
    '''
263
    def makeConnectionPointListString(self):
264
        ret = ""
265
        listItems = []
266
        for index in range(self.ui.connectionPointList.count()):
267
            listItems.append(self.ui.connectionPointList.item(index))
268
        if listItems is not None:
269
            for index in range(len(listItems)):
270
                item = listItems[index]
271
                text = item.text()
272
                if index != 0:
273
                    ret = ret + "/"
274
                ret = ret + text
275
        return ret
276
    
277
    '''
278
        @brief  Called when Save Button Clicked
279
                Validation Check → Make Symbol Data → Insert Symbol Data into DB → Save png and svg files
280
    '''
281
    def accept(self):
282
        print("save")
283

    
284
        isValid, exceptionMsg = self.isValidSymbolInfo()
285
        if isValid:
286
            print("valid symbol info")
287

    
288
            if self.selectedSymbol is None:
289
                isSuccess, fileName, imagePath = self.dbHelper.insertSymbol(self.makeSymbolData())
290
            else:
291
                isSuccess, fileName, imagePath = self.dbHelper.updateSymbol(self.makeSymbolData())
292

    
293
            if isSuccess:
294
                try:
295
                    image = self.ui.imageView.image()
296
                    if image is not None:
297
                        if self.selectedSymbol is not None:
298
                            self.deleteImageAndSvg(self.selectedSymbol.getPath(), self.selectedSymbol.getName())
299
                        image.save(imagePath, 'PNG')
300
                        potrace.convertImageToSvg(imagePath, self.project.getPath()+"/svg/" + fileName + ".svg")
301
                        self.isAccepted = True
302
                        QDialog.accept(self)
303
                except:
304
                    if self.selectedSymbol is None:
305
                        self.resetInsertSymbol(imagePath, fileName)
306
                    else:
307
                        self.resetUpdateSymbol(imagePath, fileName) ### update roll back 으로 변경해야함
308
                    self.isAccepted = False
309
                    QMessageBox.about(self.ui.buttonBox, "알림", "심볼 저장 과정 중 문제가 발생했습니다.")
310
            else:
311
                QMessageBox.about(self.ui.buttonBox, "알림", "심볼 저장 과정 중 문제가 발생했습니다.")
312
        else:
313
            print("invalid symbol info")
314
            QMessageBox.about(self.ui.buttonBox, "알림", exceptionMsg)
315
            
316
    '''
317
        @brief  Called When Cancel Button Clicked
318
    '''
319
    def cancel(self):
320
        print("cancel")
321
        self.isAccepted = Flase
322
        QDialog.cancel(self)
323

    
324
    def deleteImageAndSvg(self, imagePath, fileName):
325
        if os.path.exists(imagePath):
326
            os.remove(imagePath)
327

    
328
        svgPath = self.project.getPath() + "/svg/" + fileName + ".svg"
329
        if os.path.exists(svgPath):
330
            os.remove(svgPath)
331
        
332
    '''
333
        @brief  Called When error occured while saving png and svg files
334
                Delete png, svg files and record from DB
335
    '''
336
    def resetInsertSymbol(self, imagePath, fileName):
337
        self.deleteImageAndSvg(imagePath, fileName)
338

    
339
        AppDocData.instance().deleteSymbol(imagePath)
340

    
341
    def resetUpdateSymbol(self, imagePath, fileName):
342
        self.deleteImageAndSvg(imagePath, fileName)
343

    
344
        SG_DbHelper.SG_DbHelper().updateSymbol(self.selectedSymbol)
345

    
346
    def keyPressEvent(self, event):
347
        if event.key() == QtCore.Qt.Key_Delete:
348
            if self.ui.connectionPointList.hasFocus():
349
                selectedItems = self.ui.connectionPointList.selectedItems()
350
                if selectedItems is not None:
351
                    for item in selectedItems:
352
                        text = item.text()
353
                        x = int(text.split(",")[0])
354
                        y = int(text.split(",")[1])
355
                        self.removeConnectionPointCircle(QtCore.QPointF(x, y))
356
                        self.ui.connectionPointList.takeItem(self.ui.connectionPointList.row(item))
357
            elif self.ui.additionalSymbolListWidget.hasFocus():
358
                selectedItems = self.ui.additionalSymbolListWidget.selectedItems()
359
                if selectedItems is not None:
360
                    for item in selectedItems:
361
                        self.ui.additionalSymbolListWidget.takeItem(self.ui.additionalSymbolListWidget.row(item))
362
                        
363
    '''
364
        @brief  Hand Tool Button Clicked
365
    '''
366
    def handToolClickEvent(self, event):
367
        print("hand tool clicked")
368
        self.ui.imageView.command = HandCommand.HandCommand(self.ui.imageView)
369
        
370
    '''
371
        @brief  Crop Tool Button Clicked
372
    '''
373
    def cropToolClickEvent(self, event):
374
        print("crop tool clicked")
375
        self.ui.imageView.command = CropCommand.CropCommand(self.ui.imageView)
376
                         
377
    '''
378
        @brief  Zoom Init Tool Button Clicked
379
    '''
380
    def zoomInitToolClickEvent(self, event):
381
        print("zoom init tool clicked")
382
        self.ui.imageView.command = None
383
        self.ui.imageView.zoomImageInit()
384

    
385
    '''
386
        @brief  Area Zoom Tool Button Clicked
387
    '''
388
    def areaZoomToolClickEvent(self, event):
389
        print("area zoom tool clicked")
390
        self.ui.imageView.command = AreaZoomCommand.AreaZoomCommand(self.ui.imageView)
391
                         
392
    '''
393
        @brief  Zoom Tool Button Clicked
394
    '''
395
    def zoomToolClickEvent(self, event):
396
        print("zoom tool clicked")
397
        self.ui.imageView.command = ZoomCommand.ZoomCommand(self.ui.imageView)
398
                         
399
    '''
400
        @brief  Pen Tool Button Clicked
401
    '''
402
    def penToolClickEvent(self, event):
403
        print("Pen")
404
        width = self.ui.toolWidget.findChild(QSpinBox, 'penWidthSpinBox').value()
405
        self.ui.imageView.command = PenCommand.PenCommand(self.ui.imageView)
406
        self.ui.imageView.command.width = width
407
                         
408
    '''
409
        @brief  Pen Width Value Changed
410
    '''
411
    def penWidthChangedEvent(self, value):
412
        print("Pen Width " + str(value))
413
        if self.ui.imageView.command is not None and type(self.ui.imageView.command) is PenCommand.PenCommand:
414
            self.ui.imageView.command.width = value
415
                 
416
    '''
417
        @brief  Eraser Tool Button Clicked
418
    '''
419
    def eraserToolClickEvent(self, event):
420
        print("eraser")
421
        width = self.ui.toolWidget.findChild(QSpinBox, 'eraserSpinBox').value()
422
        self.ui.imageView.command = EraserCommand.EraserCommand(self.ui.imageView)
423
        self.ui.imageView.command.width = width
424
                         
425
    '''
426
        @brief  Eraser Width Value Changed
427
    '''
428
    def eraserWidthChangedEvent(self, value):
429
        print("eraser " + str(value))
430
        if self.ui.imageView.command is not None and type(self.ui.imageView.command) is EraserCommand.EraserCommand:
431
            self.ui.imageView.command.width = value
432
                             
433
    '''
434
        @brief  Area Eraser Tool Button Clicked
435
    '''
436
    def areaEraserToolClickEvent(self, event):
437
        print("area eraser")
438
        self.ui.imageView.command = AreaEraserCommand.AreaEraserCommand(self.ui.imageView)
439
                             
440
    '''
441
        @brief  Fit Image Tool Button Clicked
442
    '''
443
    def fitImageToolClickEvent(self, event):
444
        print("Fit Image")
445
        self.ui.imageView.command = FitImageCommand.FitImageCommand(self.ui.imageView)
446
        adjustX, adjustY = self.ui.imageView.command.getAdjust()
447
        self.adjustOriginalPoint(adjustX, adjustY)
448
        self.adjustConnectionPoint(adjustX, adjustY)
449
                         
450
    '''
451
        @brief  Guideline Check State Changed
452
    '''
453
    def guidelineStateChangedEvent(self, value):
454
        if self.ui.guidelineCheckbox.isChecked():
455
            self.ui.imageView.showGuideline(True)
456
        else:
457
            self.ui.imageView.showGuideline(False)
458
                             
459
    '''
460
        @brief  Add AdditionalSymbol String on ListWidget Listener
461
    '''
462
    def addAdditionalSymbolEvent(self, event):
463
        print("addAdditionalSymbolEvent")
464
        additionalSymbolIndex = self.ui.additionalSymbolComboBox.currentIndex()
465
        if additionalSymbolIndex != 0:
466
            print("Symbol Selected")
467
            direction = self.ui.defaultSymbolDirectionComboBox.currentText()
468
            symbolName = self.ui.additionalSymbolComboBox.currentText()
469
            self.addAdditionalSymbol(direction, symbolName)
470
                    
471
    '''
472
        @brief  Add AdditionalSymbol String on ListWidget
473
    '''
474
    def addAdditionalSymbol(self, direction, symbolName):
475
        text = "{},{}".format(direction, symbolName)
476

    
477
        if self.isAlreadyAdded(text):
478
            QMessageBox.about(self.ui.buttonBox, "알림", "이미 추가된 아이템입니다.")
479
        else:
480
            self.ui.additionalSymbolListWidget.addItem(text)
481
                                 
482
    '''
483
        @brief  Check the text is already added
484
    '''
485
    def isAlreadyAdded(self, text):
486
        for index in range(self.ui.additionalSymbolListWidget.count()):
487
            item = self.ui.additionalSymbolListWidget.item(index)
488
            if item.text() == text:
489
                return True
490
        return False
491
                     
492
    '''
493
        @brief  Original Point Tool Button Clicked
494
    '''
495
    def addOriginalPoint(self, event):
496
        print("addOriginalPoint")
497
        self.ui.imageView.command = OriginalPointCommand.OriginalPointCommand(self.ui.imageView, self.ui.originalPointLineEdit)
498
                         
499
    '''
500
        @brief  Connection Point Tool Button Clicked
501
    '''
502
    def addConnectionPoint(self, event):
503
        print("addConnectionPoint")
504
        self.ui.imageView.command = ConnectionPointCommand.ConnectionPointCommand(self.ui.imageView, self.ui.connectionPointLineEdit, self.ui.connectionPointList)
505

    
506
    def adjustOriginalPoint(self, adjustX, adjustY):
507
        originalPoint = self.ui.originalPointLineEdit.text()
508
        if originalPoint and self.ui.imageView.isOriginalPointSelected:
509
            x = int(originalPoint.split(",")[0])
510
            y = int(originalPoint.split(",")[1])
511
            OriginalPointCommand.OriginalPointCommand.removeCircle(self.ui.imageView, x, y)
512
            x = x - adjustX
513
            y = y - adjustY
514
            self.ui.originalPointLineEdit.setText(str(x)+","+str(y))
515
            OriginalPointCommand.OriginalPointCommand.drawCircle(self.ui.imageView, x, y)
516

    
517
    def adjustConnectionPoint(self, adjustX, adjustY):
518
        itemCount = self.ui.connectionPointList.count()
519
        for index in range(itemCount):
520
            item = self.ui.connectionPointList.item(index)
521
            text = item.text()
522
            x = int(text.split(",")[0])
523
            y = int(text.split(",")[1])
524
            self.removeConnectionPointCircle(QtCore.QPointF(x, y))
525
            x = x - adjustX
526
            y = y - adjustY
527
            item.setText(str(x)+","+str(y))
528
            ConnectionPointCommand.ConnectionPointCommand.drawCircle(self.ui.imageView, x, y)
529
                         
530
    '''
531
        @brief  Validation Check
532
        @return (isValid, errorMsg)
533
    '''
534
    def isValidSymbolInfo(self):
535
        print("isValid")
536
        EXCEPTION_MSG_FORMAT = "{} 입력을 확인해주세요."
537
        EXCEPTION_MSG_DUPLICATED_FORMAT = "이미 저장된 {} 값입니다."
538
        infoTitle = ""
539

    
540
        idText = self.ui.idLineEdit.text()
541
        id = int(idText) if idText else -1
542
        if (id == -1 or id < 100):
543
            infoTitle = self.ui.idLabel.text()
544
            return (False, EXCEPTION_MSG_FORMAT.format(infoTitle))
545

    
546
        lastId = -1
547
        if self.selectedSymbol is not None:
548
            lastId = self.selectedSymbol.getId()
549
        if lastId != id and self.dbHelper.isExistData('symId', id):
550
            infoTitle = self.ui.idLabel.text()
551
            return (False, EXCEPTION_MSG_DUPLICATED_FORMAT.format(infoTitle))
552

    
553
        if not self.ui.nameLineEdit.text():
554
            infoTitle = self.ui.nameLabel.text()
555
            return (False, EXCEPTION_MSG_FORMAT.format(infoTitle))
556

    
557
        thresholdText = self.ui.thresholdLineEdit.text()
558
        threshold = float(thresholdText) if thresholdText else -1
559
        if not(threshold >= 0 and threshold <= 100):
560
            infoTitle = self.ui.thresholdLabel.text()
561
            return (False, EXCEPTION_MSG_FORMAT.format(infoTitle))
562
            
563
        minMatchPointText = self.ui.minMatchPointLineEdit.text()
564
        minMatchPoint = float(minMatchPointText) if minMatchPointText else -1
565
        if not(minMatchPoint >= 0):
566
            infoTitle = self.ui.minMatchPointLabel.text()
567
            return (False, EXCEPTION_MSG_FORMAT.format(infoTitle))
568

    
569
        if self.ui.baseSymbolComboBox.currentIndex() == 0: #default value(None) index
570
            infoTitle = self.ui.baseSymbolLabel.text()
571
            return (False, EXCEPTION_MSG_FORMAT.format(infoTitle))
572

    
573
        #Additional Symbol is Nullable
574

    
575
        if not self.ui.originalPointLineEdit.text() or self.ui.imageView.isOriginalPointSelected == False:
576
            infoTitle = self.ui.originalPointLabel.text()
577
            return (False, EXCEPTION_MSG_FORMAT.format(infoTitle))
578

    
579
        if not (self.ui.connectionPointList.count() > 0):
580
            infoTitle = self.ui.connectionPointLabel.text()
581
            return (False, EXCEPTION_MSG_FORMAT.format(infoTitle))
582
            
583
        return True, None
클립보드 이미지 추가 (최대 크기: 500 MB)