프로젝트

일반

사용자정보

통계
| 개정판:

hytos / DTI_PID / DTI_PID / QSymbolEditorDialog.py @ ff5edf29

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

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

    
14
import UI_SymbolEditor
15
from AppDocData import AppDocData
16

    
17

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

    
21

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

    
25
    '''
26
        @history    2018.05.02  Jeongwoo    Add variables (self.offsetX, self.offsetY, self.newSym)
27
                    2018.05.03  Jeongwoo    Remove parameter in SG_DbHelper()
28
    '''
29
    def __init__(self, parent, image, project, selectedSymbol = None):
30
        QDialog.__init__(self, parent)
31
        self.image = image
32
        self.selectedSymbol = selectedSymbol
33
        self.project = project
34
        self.ui = UI_SymbolEditor.Ui_Dialog()
35
        self.ui.setupUi(self)
36
        self.setupImageViewer()
37
        self.setupTools()
38
        self.initForms()
39
        self.initContents()
40
        self.isAccepted = False
41
        self.offsetX = 0
42
        self.offsetY = 0
43
        self.newSym = None
44
        self.dbHelper = SG_DbHelper.SG_DbHelper()
45

    
46
    '''
47
        @brief  Set up QtImageViewer and QImage
48
        @history    2018.05.02  Jeongwoo    Connect imageviewer and QSymbolEditorDialog
49
    '''
50
    def setupImageViewer(self):
51
        x = self.ui.imageViewContainer.x()
52
        y = self.ui.imageViewContainer.y()
53
        width = self.ui.imageViewContainer.frameGeometry().width()
54
        height = self.ui.imageViewContainer.frameGeometry().height()
55
        self.ui.imageView = QtImageViewer()
56
        self.ui.imageView.setGeometry(QtCore.QRect(0, y, height, height))
57
        self.ui.imageView.aspectRatioMode = QtCore.Qt.KeepAspectRatio
58
        self.ui.imageView.setHorizontalScrollBarPolicy(QtCore.Qt.ScrollBarAsNeeded)
59
        self.ui.imageView.setVerticalScrollBarPolicy(QtCore.Qt.ScrollBarAsNeeded)
60
        self.ui.imageView.canZoom = True
61
        self.ui.imageView.canPan = True
62
        image = self.image.copy()
63
        self.imgW = image.width()
64
        self.imgH = image.height()
65
        image = image.scaled(self.imgW, self.imgH)
66
        self.ui.imageView.setImage(image)
67
        self.ui.imageViewerContainerLayout.addWidget(self.ui.imageView)
68
        self.ui.imageView.startPointChanged.connect(self.offsetChanged)
69

    
70
    '''
71
        @brief  Set up Hand, Crop, ETC Tools
72
        @history    2018.05.03  Jeongwoo    Add connection for removeTextButton
73
    '''
74
    def setupTools(self):
75
        self.ui.handButton.clicked.connect(self.handToolClickEvent)
76
        self.ui.cropButton.clicked.connect(self.cropToolClickEvent)
77
        self.ui.penButton.clicked.connect(self.penToolClickEvent)
78
        self.ui.penWidthSpinBox.valueChanged.connect(self.penWidthChangedEvent)
79
        self.ui.eraserButton.clicked.connect(self.eraserToolClickEvent)
80
        self.ui.eraserSpinBox.valueChanged.connect(self.eraserWidthChangedEvent)
81
        self.ui.areaEraserButton.clicked.connect(self.areaEraserToolClickEvent)
82
        self.ui.fitImageButton.clicked.connect(self.fitImageToolClickEvent)
83
        self.ui.zoomButton.clicked.connect(self.zoomToolClickEvent)
84
        self.ui.areaZoomButton.clicked.connect(self.areaZoomToolClickEvent)
85
        self.ui.initZoomButton.clicked.connect(self.zoomInitToolClickEvent)
86
        self.ui.guidelineCheckbox.stateChanged.connect(self.guidelineStateChangedEvent)
87
        #self.ui.additionalSymbolListWidget.keyPressEvent.connect(self.additionalSymbolListKeyPressEvent)
88
        #self.ui.connectionPointList.keyPressEvent.connect(self.additionalSymbolListKeyPressEvent)
89
        self.ui.removeTextButton.clicked.connect(self.removeTextClickEvent)
90

    
91
    '''
92
        @brief  Init Forms with type and default values
93
    '''
94
    def initForms(self):
95
        self.ui.idLineEdit.setValidator(QRegExpValidator(QtCore.QRegExp("^[1-9]\d+$")))
96
        self.ui.thresholdLineEdit.setValidator(QRegExpValidator(QtCore.QRegExp("^[0-9]\d+$"))) # ([0-1]{1}[.])?[0-9]+
97
        self.ui.minMatchPointLineEdit.setValidator(QRegExpValidator(QtCore.QRegExp("^[0-9]\d+$")))
98
        self.initIsOriginDetectComboBoxItems()
99
        self.initOcrOptionComboBoxItems()
100
        self.initDefaultSymbolDirectionComboBoxItems()
101
        self.ui.addAdditionalSymbolButton.clicked.connect(self.addAdditionalSymbolEvent)
102
        self.ui.addOriginalPointButton.clicked.connect(self.addOriginalPoint)
103
        self.ui.addConnectionPointButton.clicked.connect(self.addConnectionPoint)
104
        self.initSymbolTypeComboBoxItems()
105
        self.initBaseSymbolComboBoxItems(None)
106
        self.initAdditionalSymbolComboBoxItems()
107

    
108
    '''
109
        @brief      Init Symbol Type ComboBox Items
110
        @author     Jeongwoo
111
        @date       2018.04.06
112
        @history    .
113
    '''
114
    def initSymbolTypeComboBoxItems(self):
115
        for item in AppDocData.instance().getSymbolTypeComboBoxItems():
116
            self.ui.typeComboBox.addItem(item)
117
        self.ui.typeComboBox.currentTextChanged.connect(self.symbolTypeTextChagedEvent)
118

    
119
    def symbolTypeTextChagedEvent(self, value):
120
        self.initBaseSymbolComboBoxItems(value)
121
        
122
    '''
123
        @brief  Set data on forms, For modifying symbol
124
        @history    2018.05.02  Jeongwoo    When modifying symbol, Make immediateInsertCheckBox disable
125
    '''
126
    def initContents(self):
127
        self.ui.targetDBLineEdit.setText(self.project.getPath()+'/db/ITI_PID.db')
128
        if self.selectedSymbol is not None:
129
            self.ui.immediateInsertCheckBox.setDisabled(True)
130

    
131
            self.ui.idLineEdit.setText(str(self.selectedSymbol.getId()))
132
            self.ui.nameLineEdit.setText(self.selectedSymbol.getName())
133
            self.ui.thresholdLineEdit.setText(str(int(self.selectedSymbol.getThreshold() * 100)))
134
            self.ui.minMatchPointLineEdit.setText(str(self.selectedSymbol.getMinMatchCount()))
135
            self.ui.ocrOptionComboBox.setCurrentIndex(self.ui.ocrOptionComboBox.findData(self.selectedSymbol.getOcrOption()))
136
            self.ui.rotationCountSpinBox.setValue(self.selectedSymbol.getRotationCount())
137
            self.ui.isContainChildCheckBox.setChecked(True if self.selectedSymbol.getIsContainChild() else False)
138
            self.ui.typeComboBox.setCurrentIndex(self.ui.typeComboBox.findText(self.selectedSymbol.getType()))
139
            self.ui.baseSymbolComboBox.setCurrentIndex(self.ui.baseSymbolComboBox.findText(self.selectedSymbol.getBaseSymbol()))
140
            self.ui.isExceptDetectCheckBox.setChecked(True if self.selectedSymbol.getIsExceptDetect() else False)
141

    
142
            additionalSymbol = self.selectedSymbol.getAdditionalSymbol()
143
            if additionalSymbol is not None and len(additionalSymbol) > 0:
144
                splitAdditionalSymbolList = additionalSymbol.split("/")
145
                for symString in splitAdditionalSymbolList:
146
                    splitSymString = symString.split(",")
147
                    self.addAdditionalSymbol(splitSymString[0], splitSymString[1])
148

    
149
            originalPoint = self.selectedSymbol.getOriginalPoint()
150
            self.ui.originalPointLineEdit.setText(originalPoint)
151
            OriginalPointCommand.OriginalPointCommand.drawCircle(self.ui.imageView, originalPoint.split(",")[0], originalPoint.split(",")[1])
152
            self.ui.imageView.isOriginalPointSelected = True
153

    
154
            connectionPoint = self.selectedSymbol.getConnectionPoint()
155
            if connectionPoint is not None and len(connectionPoint) > 0:
156
                splitConnectionPointList = connectionPoint.split("/")
157
                for conString in splitConnectionPointList: # conString : x,y
158
                    self.ui.connectionPointList.addItem(conString)
159
                    ConnectionPointCommand.ConnectionPointCommand.drawCircle(self.ui.imageView, conString.split(",")[0], conString.split(",")[1])
160

    
161
    '''
162
        @brief  Init ComboBox Items For DB Field [IsDetectOrigin]
163
    '''
164
    def initIsOriginDetectComboBoxItems(self):
165
        for item in AppDocData.instance().getIsOriginDetectComboBoxItems():
166
            self.ui.isOriginDetectComboBox.addItem(item[0], item[1]) # 0 : text / 1 : data(integer)
167

    
168
    '''
169
        @brief  Init ComboBox Items For DB Field [OcrOption]
170
    '''
171
    def initOcrOptionComboBoxItems(self):
172
        for item in AppDocData.instance().getOcrOptionComboBoxItems():
173
            self.ui.ocrOptionComboBox.addItem(item[0], item[1]) # 0 : text / 1 : data(integer)
174
        
175
    '''
176
        @brief  Init ComboBox Items For Direction of DB Field [additionalSymbol]
177
    '''
178
    def initDefaultSymbolDirectionComboBoxItems(self):
179
        for item in AppDocData.instance().getDefaultSymbolDirectionComboBoxItems():
180
            self.ui.defaultSymbolDirectionComboBox.addItem(item[0], item[1]) # 0 : text / 1 : data(integer)
181
        
182
    '''
183
        @brief  Init ComboBox Items For DB Field [baseSymbol]
184
    '''
185
    def initBaseSymbolComboBoxItems(self, type):
186
        self.ui.baseSymbolComboBox.clear()
187
        for item in AppDocData.instance().getBaseSymbolComboBoxItems(type):
188
            self.ui.baseSymbolComboBox.addItem(item)
189
            
190
    '''
191
        @brief  Init ComboBox Items For symbolName of DB Field [additionalSymbol]
192
    '''
193
    def initAdditionalSymbolComboBoxItems(self):
194
        for name in AppDocData.instance().getAdditionalSymbolComboBoxItems():
195
            self.ui.additionalSymbolComboBox.addItem(name)
196
    
197
    '''
198
        @brief  remove ConnectionPoint Circles (Using for loop)
199
    '''
200
    def removeConnectionPointCircles(self, circlePointList):
201
        for circlePoint in circlePointList:
202
            self.removeConnectionPointCircle(circlePoint)
203
            
204
    '''
205
        @brief  remove each ConnectionPoint Circle
206
    '''
207
    def removeConnectionPointCircle(self, circlePoint):
208
        self.ui.imageView.scene.removeItem(self.ui.imageView.scene.itemAt(QtCore.QPointF(int(circlePoint.x()), int(circlePoint.y())), QTransform()))
209
        
210
    '''
211
        @brief  Display this QDialog
212
        @history    2018.05.02  Jeongwoo    Change return value (Single variable → Tuple)
213
    '''
214
    def showDialog(self):
215
        self.setWindowFlags(self.windowFlags() & ~QtCore.Qt.WindowContextHelpButtonHint)
216
        #self.show()
217
        self.exec_()
218
        return (self.isAccepted, self.ui.immediateInsertCheckBox.isChecked(), self.offsetX, self.offsetY, self.newSym)
219
    
220
    '''
221
        @brief  Using input [Name], make file name
222
                If the [Name] exists, add number like [FILE_NAME(1), FILE_NAME(2), ...]
223
                Recursive function
224
        @history    2018.05.02  Jeongwoo    Change isExistFileName's parameter (Dir → newName)
225
    '''
226
    def makeFileName(self, type, originName, newName):
227
        imageFolderDir = self.project.getImageFilePath()
228
        imageDir = imageFolderDir + "/" + type + "/" + newName + ".png"
229
        svgFolderDir = self.project.getSvgFilePath()
230
        svgDir = svgFolderDir + "/" + type + "/" + newName + ".svg"
231
        if (os.path.exists(imageDir)) or (self.dbHelper.isExistFileName(newName) or (os.path.exists(svgDir))):
232
            self.FILE_NUMBER = self.FILE_NUMBER + 1
233
            imgName = originName + "({})".format(self.FILE_NUMBER)
234
            return self.makeFileName(originName, imgName)
235
        else:
236
            return newName
237
        
238
    '''
239
        @brief  Make symbol object for saving on DB
240
        @history    2018.05.02  Jeongwoo    newSym object changed self.newSym
241
    '''
242
    def makeSymbolData(self):
243
        uid = -1
244
        if self.selectedSymbol is not None:
245
            uid = self.selectedSymbol.getUid()
246
        symId = self.ui.idLineEdit.text()
247
        name = self.ui.nameLineEdit.text()
248
        type = self.ui.typeComboBox.currentText() #Empty
249
        self.FILE_NUMBER = 0
250
        lastName = ""
251
        if self.selectedSymbol is not None:
252
            lastName = self.selectedSymbol.getName()
253
        fileName = ""
254
        if name == lastName:
255
            fileName = name
256
        else:
257
            fileName = self.makeFileName(type, name, name)
258
        #path = self.project.getPath() + "/image/" + fileName + ".png"
259
        threshold = self.ui.thresholdLineEdit.text()
260
        minMatchPoint = self.ui.minMatchPointLineEdit.text()
261
        isDetectOnOrigin = self.ui.isOriginDetectComboBox.currentData()
262
        rotationCount = self.ui.rotationCountSpinBox.value()
263
        ocrOption = self.ui.ocrOptionComboBox.currentData()
264
        isContainChild = 1 if self.ui.isContainChildCheckBox.isChecked() else 0
265
        originalPoint = self.ui.originalPointLineEdit.text()
266
        connectionPoint = self.makeConnectionPointListString()
267
        baseSymbol = self.ui.baseSymbolComboBox.currentText()
268
        additionalSymbol = self.makeAdditionalSymbolListString()
269
        isExceptDetect = 1 if self.ui.isExceptDetectCheckBox.isChecked() else 0
270

    
271
        convertedThreshold = int(threshold) / 100.0
272

    
273
        self.newSym = symbol.SymbolBase(int(symId), fileName, type, convertedThreshold, int(minMatchPoint), isDetectOnOrigin
274
                                   , rotationCount, ocrOption, isContainChild, originalPoint, connectionPoint, baseSymbol, additionalSymbol, isExceptDetect, uid)
275

    
276
        return self.newSym
277
    
278
    '''
279
        @brief  Make AdditionalSymbol String
280
                [AdditionalSymbolString = DIRECTION,SYMBOL_NAME/DIRECTION,SYMBOL_NAME/...]
281
    '''
282
    def makeAdditionalSymbolListString(self):
283
        ret = ""
284
        listItems = []
285
        for index in range(self.ui.additionalSymbolListWidget.count()):
286
            listItems.append(self.ui.additionalSymbolListWidget.item(index))
287
        if listItems is not None:
288
            for index in range(len(listItems)):
289
                item = listItems[index]
290
                text = item.text()
291
                if index != 0:
292
                    ret = ret + "/"
293
                ret = ret + text
294
        return ret
295
    
296
    '''
297
        @brief  Make ConnectionPoint String
298
                [ConnectionPointString = x1,y1/x2,y2/...]
299
    '''
300
    def makeConnectionPointListString(self):
301
        ret = ""
302
        listItems = []
303
        for index in range(self.ui.connectionPointList.count()):
304
            listItems.append(self.ui.connectionPointList.item(index))
305
        if listItems is not None:
306
            for index in range(len(listItems)):
307
                item = listItems[index]
308
                text = item.text()
309
                if index != 0:
310
                    ret = ret + "/"
311
                ret = ret + text
312
        return ret
313
    
314
    '''
315
        @brief  Called when Save Button Clicked
316
                Validation Check → Make Symbol Data → Insert Symbol Data into DB → Save png and svg files
317
        @history    2018.05.03  Jeongwoo    Change parameters on method 'deleteImageAndSvg'
318
    '''
319
    def accept(self):
320
        print("save")
321

    
322
        isValid, exceptionMsg = self.isValidSymbolInfo()
323
        if isValid:
324
            print("valid symbol info")
325

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

    
331
            if isSuccess:
332
                try:
333
                    image = self.ui.imageView.image()
334
                    if image is not None:
335
                        if self.selectedSymbol is not None:
336
                            self.deleteImageAndSvg(self.selectedSymbol.getImageFileFullPath(), self.selectedSymbol.getSvgFileFullPath())
337
                        imageLocation = self.project.getImageFilePath() + "/" + fileType
338
                        if not os.path.exists(imageLocation):
339
                            os.makedirs(imageLocation)
340
                        image.save(imagePath, 'PNG')
341
                        svgLocation = self.project.getSvgFilePath() + "/" + fileType
342
                        if not os.path.exists(svgLocation):
343
                            os.makedirs(svgLocation)
344
                        potrace.convertImageToSvg(imagePath, svgLocation + "/" + fileName + ".svg")
345
                        self.isAccepted = True
346
                        QDialog.accept(self)
347
                except:
348
                    if self.selectedSymbol is None:
349
                        self.resetInsertSymbol(imagePath, fileName)
350
                    else:
351
                        self.resetUpdateSymbol(imagePath, fileName) ### update roll back 으로 변경해야함
352
                    self.isAccepted = False
353
                    QMessageBox.about(self.ui.buttonBox, "알림", "심볼 저장 과정 중 문제가 발생했습니다.")
354
            else:
355
                QMessageBox.about(self.ui.buttonBox, "알림", "심볼 저장 과정 중 문제가 발생했습니다.")
356
        else:
357
            print("invalid symbol info")
358
            QMessageBox.about(self.ui.buttonBox, "알림", exceptionMsg)
359
            
360
    '''
361
        @brief  Called When Close Button Clicked
362
    '''
363
    def reject(self):
364
        print("cancel")
365
        self.isAccepted = False
366
        QDialog.reject(self)
367

    
368
    '''
369
        @history    2018.05.03  Jeongwoo    Change Parameters (imagePath, type, name → imagePath, svgPath)
370
    '''
371
    def deleteImageAndSvg(self, imagePath, svgPath):
372
        if os.path.exists(imagePath):
373
            os.remove(imagePath)
374

    
375
        if os.path.exists(svgPath):
376
            os.remove(svgPath)
377
        
378
    '''
379
        @brief  Called When error occured while saving png and svg files
380
                Delete png, svg files and record from DB
381
        @history    2018.05.03  Jeongwoo    Change Parameters and fileName variable
382
    '''
383
    def resetInsertSymbol(self, imagePath, svgPath):
384
        self.deleteImageAndSvg(imagePath, svgPath)
385

    
386
        fileName = os.path.basename(imagePath.replace('.png', ''))
387
        AppDocData.instance().deleteSymbol(fileName)
388

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

    
395
        SG_DbHelper.SG_DbHelper().updateSymbol(self.selectedSymbol)
396

    
397
    def keyPressEvent(self, event):
398
        if event.key() == QtCore.Qt.Key_Delete:
399
            if self.ui.connectionPointList.hasFocus():
400
                selectedItems = self.ui.connectionPointList.selectedItems()
401
                if selectedItems is not None:
402
                    for item in selectedItems:
403
                        text = item.text()
404
                        x = int(text.split(",")[0])
405
                        y = int(text.split(",")[1])
406
                        self.removeConnectionPointCircle(QtCore.QPointF(x, y))
407
                        self.ui.connectionPointList.takeItem(self.ui.connectionPointList.row(item))
408
            elif self.ui.additionalSymbolListWidget.hasFocus():
409
                selectedItems = self.ui.additionalSymbolListWidget.selectedItems()
410
                if selectedItems is not None:
411
                    for item in selectedItems:
412
                        self.ui.additionalSymbolListWidget.takeItem(self.ui.additionalSymbolListWidget.row(item))
413
                        
414
    '''
415
        @brief  Hand Tool Button Clicked
416
    '''
417
    def handToolClickEvent(self, event):
418
        print("hand tool clicked")
419
        self.ui.imageView.command = HandCommand.HandCommand(self.ui.imageView)
420
        
421
    '''
422
        @brief  Crop Tool Button Clicked
423
    '''
424
    def cropToolClickEvent(self, event):
425
        print("crop tool clicked")
426
        self.ui.imageView.command = CropCommand.CropCommand(self.ui.imageView)
427
                         
428
    '''
429
        @brief  Zoom Init Tool Button Clicked
430
    '''
431
    def zoomInitToolClickEvent(self, event):
432
        print("zoom init tool clicked")
433
        self.ui.imageView.command = None
434
        self.ui.imageView.zoomImageInit()
435

    
436
    '''
437
        @brief  Area Zoom Tool Button Clicked
438
    '''
439
    def areaZoomToolClickEvent(self, event):
440
        print("area zoom tool clicked")
441
        self.ui.imageView.command = AreaZoomCommand.AreaZoomCommand(self.ui.imageView)
442
                         
443
    '''
444
        @brief  Zoom Tool Button Clicked
445
    '''
446
    def zoomToolClickEvent(self, event):
447
        print("zoom tool clicked")
448
        self.ui.imageView.command = ZoomCommand.ZoomCommand(self.ui.imageView)
449
                         
450
    '''
451
        @brief  Pen Tool Button Clicked
452
    '''
453
    def penToolClickEvent(self, event):
454
        print("Pen")
455
        width = self.ui.toolWidget.findChild(QSpinBox, 'penWidthSpinBox').value()
456
        self.ui.imageView.command = PenCommand.PenCommand(self.ui.imageView)
457
        self.ui.imageView.command.width = width
458
                         
459
    '''
460
        @brief  Pen Width Value Changed
461
    '''
462
    def penWidthChangedEvent(self, value):
463
        print("Pen Width " + str(value))
464
        if self.ui.imageView.command is not None and type(self.ui.imageView.command) is PenCommand.PenCommand:
465
            self.ui.imageView.command.width = value
466
                 
467
    '''
468
        @brief  Eraser Tool Button Clicked
469
    '''
470
    def eraserToolClickEvent(self, event):
471
        print("eraser")
472
        width = self.ui.toolWidget.findChild(QSpinBox, 'eraserSpinBox').value()
473
        self.ui.imageView.command = EraserCommand.EraserCommand(self.ui.imageView)
474
        self.ui.imageView.command.width = width
475
                         
476
    '''
477
        @brief  Eraser Width Value Changed
478
    '''
479
    def eraserWidthChangedEvent(self, value):
480
        print("eraser " + str(value))
481
        if self.ui.imageView.command is not None and type(self.ui.imageView.command) is EraserCommand.EraserCommand:
482
            self.ui.imageView.command.width = value
483
                             
484
    '''
485
        @brief  Area Eraser Tool Button Clicked
486
    '''
487
    def areaEraserToolClickEvent(self, event):
488
        print("area eraser")
489
        self.ui.imageView.command = AreaEraserCommand.AreaEraserCommand(self.ui.imageView)
490
                             
491
    '''
492
        @brief  Fit Image Tool Button Clicked
493
        @history    2018.05.02  Jeongwoo    Method name changed(getAdjust → getOffset)
494
                                            Emit offsets to startPointChanged
495
    '''
496
    def fitImageToolClickEvent(self, event):
497
        print("Fit Image")
498
        self.ui.imageView.command = FitImageCommand.FitImageCommand(self.ui.imageView)
499
        adjustX, adjustY = self.ui.imageView.command.getOffset()
500
        self.adjustOriginalPoint(adjustX, adjustY)
501
        self.adjustConnectionPoint(adjustX, adjustY)
502
        self.ui.imageView.startPointChanged.emit(adjustX, adjustY)
503
                         
504
    '''
505
        @brief  Guideline Check State Changed
506
    '''
507
    def guidelineStateChangedEvent(self, value):
508
        if self.ui.guidelineCheckbox.isChecked():
509
            self.ui.imageView.showGuideline(True)
510
        else:
511
            self.ui.imageView.showGuideline(False)
512
                             
513
    '''
514
        @brief  Add AdditionalSymbol String on ListWidget Listener
515
    '''
516
    def addAdditionalSymbolEvent(self, event):
517
        print("addAdditionalSymbolEvent")
518
        additionalSymbolIndex = self.ui.additionalSymbolComboBox.currentIndex()
519
        if additionalSymbolIndex != 0:
520
            print("Symbol Selected")
521
            direction = self.ui.defaultSymbolDirectionComboBox.currentText()
522
            symbolName = self.ui.additionalSymbolComboBox.currentText()
523
            self.addAdditionalSymbol(direction, symbolName)
524
                    
525
    '''
526
        @brief  Add AdditionalSymbol String on ListWidget
527
    '''
528
    def addAdditionalSymbol(self, direction, symbolName):
529
        text = "{},{}".format(direction, symbolName)
530

    
531
        if self.isAlreadyAdded(text):
532
            QMessageBox.about(self.ui.buttonBox, "알림", "이미 추가된 아이템입니다.")
533
        else:
534
            self.ui.additionalSymbolListWidget.addItem(text)
535
                                 
536
    '''
537
        @brief  Check the text is already added
538
    '''
539
    def isAlreadyAdded(self, text):
540
        for index in range(self.ui.additionalSymbolListWidget.count()):
541
            item = self.ui.additionalSymbolListWidget.item(index)
542
            if item.text() == text:
543
                return True
544
        return False
545
                     
546
    '''
547
        @brief  Original Point Tool Button Clicked
548
    '''
549
    def addOriginalPoint(self, event):
550
        print("addOriginalPoint")
551
        self.ui.imageView.command = OriginalPointCommand.OriginalPointCommand(self.ui.imageView, self.ui.originalPointLineEdit)
552
                         
553
    '''
554
        @brief  Connection Point Tool Button Clicked
555
    '''
556
    def addConnectionPoint(self, event):
557
        print("addConnectionPoint")
558
        self.ui.imageView.command = ConnectionPointCommand.ConnectionPointCommand(self.ui.imageView, self.ui.connectionPointLineEdit, self.ui.connectionPointList)
559

    
560
    '''
561
        @brief  Remove Text Tool Button Clicked
562
        @author Jeongwoo
563
        @date   2018.05.03
564
    '''
565
    def removeTextClickEvent(self, event):
566
        print("removeText")
567
        QMessageBox.about(self.ui.removeTextButton, "알림", "추후 지원될 예정입니다.")
568
        #self.ui.imageView.command = RemoveTextCommand.RemoveTextCommand(self.ui.imageView)
569

    
570
    def adjustOriginalPoint(self, adjustX, adjustY):
571
        originalPoint = self.ui.originalPointLineEdit.text()
572
        if originalPoint and self.ui.imageView.isOriginalPointSelected:
573
            x = int(originalPoint.split(",")[0])
574
            y = int(originalPoint.split(",")[1])
575
            OriginalPointCommand.OriginalPointCommand.removeCircle(self.ui.imageView, x, y)
576
            x = x - adjustX
577
            y = y - adjustY
578
            self.ui.originalPointLineEdit.setText(str(x)+","+str(y))
579
            OriginalPointCommand.OriginalPointCommand.drawCircle(self.ui.imageView, x, y)
580

    
581
    def adjustConnectionPoint(self, adjustX, adjustY):
582
        itemCount = self.ui.connectionPointList.count()
583
        for index in range(itemCount):
584
            item = self.ui.connectionPointList.item(index)
585
            text = item.text()
586
            x = int(text.split(",")[0])
587
            y = int(text.split(",")[1])
588
            self.removeConnectionPointCircle(QtCore.QPointF(x, y))
589
            x = x - adjustX
590
            y = y - adjustY
591
            item.setText(str(x)+","+str(y))
592
            ConnectionPointCommand.ConnectionPointCommand.drawCircle(self.ui.imageView, x, y)
593
                         
594
    '''
595
        @brief  Validation Check
596
        @return (isValid, errorMsg)
597
    '''
598
    def isValidSymbolInfo(self):
599
        print("isValid")
600
        EXCEPTION_MSG_FORMAT = "{} 입력을 확인해주세요."
601
        EXCEPTION_MSG_DUPLICATED_FORMAT = "이미 저장된 {} 값입니다."
602
        infoTitle = ""
603

    
604
        idText = self.ui.idLineEdit.text()
605
        id = int(idText) if idText else -1
606
        if (id == -1 or id < 100):
607
            infoTitle = self.ui.idLabel.text()
608
            return (False, EXCEPTION_MSG_FORMAT.format(infoTitle))
609

    
610
        lastId = -1
611
        if self.selectedSymbol is not None:
612
            lastId = self.selectedSymbol.getId()
613
        if lastId != id and self.dbHelper.isExistData('symId', id):
614
            infoTitle = self.ui.idLabel.text()
615
            return (False, EXCEPTION_MSG_DUPLICATED_FORMAT.format(infoTitle))
616

    
617
        if not self.ui.nameLineEdit.text():
618
            infoTitle = self.ui.nameLabel.text()
619
            return (False, EXCEPTION_MSG_FORMAT.format(infoTitle))
620

    
621
        thresholdText = self.ui.thresholdLineEdit.text()
622
        threshold = float(thresholdText) if thresholdText else -1
623
        if not(threshold >= 0 and threshold <= 100):
624
            infoTitle = self.ui.thresholdLabel.text()
625
            return (False, EXCEPTION_MSG_FORMAT.format(infoTitle))
626
            
627
        minMatchPointText = self.ui.minMatchPointLineEdit.text()
628
        minMatchPoint = float(minMatchPointText) if minMatchPointText else -1
629
        if not(minMatchPoint >= 0):
630
            infoTitle = self.ui.minMatchPointLabel.text()
631
            return (False, EXCEPTION_MSG_FORMAT.format(infoTitle))
632

    
633
        if self.ui.typeComboBox.currentIndex() == 0:
634
            infoTitle = self.ui.typeLabel.text()
635
            return (False, EXCEPTION_MSG_FORMAT.format(infoTitle))
636

    
637
        if self.ui.baseSymbolComboBox.currentIndex() == 0: #default value(None) index
638
            infoTitle = self.ui.baseSymbolLabel.text()
639
            return (False, EXCEPTION_MSG_FORMAT.format(infoTitle))
640

    
641
        #Additional Symbol is Nullable
642

    
643
        if not self.ui.originalPointLineEdit.text() or self.ui.imageView.isOriginalPointSelected == False:
644
            infoTitle = self.ui.originalPointLabel.text()
645
            return (False, EXCEPTION_MSG_FORMAT.format(infoTitle))
646

    
647
        if not (self.ui.connectionPointList.count() > 0):
648
            infoTitle = self.ui.connectionPointLabel.text()
649
            return (False, EXCEPTION_MSG_FORMAT.format(infoTitle))
650
            
651
        return True, None
652

    
653
    '''
654
        @brief  Slot for change offsets
655
        @author Jeongwoo
656
        @date   2018.05.02
657
    '''
658
    @pyqtSlot(float, float)
659
    def offsetChanged(self, oX, oY):
660
        print('offsetX : ' + str(self.offsetX) + '->' + str(self.offsetX+oX))
661
        print('offsetY : ' + str(self.offsetY) + '->' + str(self.offsetY+oY))
662
        self.offsetX = self.offsetX + oX
663
        self.offsetY = self.offsetY + oY
클립보드 이미지 추가 (최대 크기: 500 MB)