hytos / DTI_PID / DTI_PID / SymbolEditorDialog.py @ 0df8e0bc
이력 | 보기 | 이력해설 | 다운로드 (56.3 KB)
1 |
# coding: utf-8
|
---|---|
2 |
|
3 |
from PyQt5 import QtCore, QtGui, QtWidgets |
4 |
from PyQt5.QtCore import pyqtSlot, QRectF |
5 |
from PyQt5.QtWidgets import * |
6 |
from PyQt5.QtGui import * |
7 |
from QtImageViewer import QtImageViewer |
8 |
import os |
9 |
import sqlite3 |
10 |
import sys |
11 |
import symbol, SymbolBase |
12 |
import potrace |
13 |
import numpy as np |
14 |
import cv2 |
15 |
|
16 |
import SymbolEditor_UI |
17 |
from AppDocData import * |
18 |
from LineTypeConditions import LineTypeConditions |
19 |
|
20 |
sys.path.insert(0, os.path.dirname(os.path.realpath(__file__)) + '\\Commands') |
21 |
import CropCommand, HandCommand, ZoomCommand, PenCommand, EraserCommand, AreaEraserCommand, OriginalPointCommand, \ |
22 |
ConnectionPointCommand, AreaZoomCommand, FitImageCommand, RemoveTextCommand, RotateImageCommand, FlipImageCommand, \ |
23 |
FenceCommand
|
24 |
from GraphicsBoundingBoxItem import QGraphicsBoundingBoxItem |
25 |
from Area import Area |
26 |
|
27 |
|
28 |
class QSymbolEditorDialog(QDialog): |
29 |
""" This is symbol editor dialog """
|
30 |
|
31 |
FILE_NUMBER = 0
|
32 |
|
33 |
'''
|
34 |
@history 2018.05.02 Jeongwoo Add variables (self.offsetX, self.offsetY, self.newSym)
|
35 |
2018.05.03 Jeongwoo Remove parameter in SG_DbHelper()
|
36 |
Remove self.dbHelper variable
|
37 |
2018.07.03 Yecheol Rename File, Is Instrument Label added
|
38 |
'''
|
39 |
|
40 |
def __init__(self, parent, image, project, selectedSymbol=None, display=False): |
41 |
QDialog.__init__(self, parent)
|
42 |
|
43 |
try:
|
44 |
self.setWindowFlag(Qt.WindowMinMaxButtonsHint)
|
45 |
self.image = image
|
46 |
self.display = display
|
47 |
|
48 |
self.selectedSymbol = selectedSymbol
|
49 |
self.project = project
|
50 |
self.ui = SymbolEditor_UI.Ui_Dialog()
|
51 |
self.ui.setupUi(self) |
52 |
self.ui.tableWidgetConnList.setColumnCount(6) |
53 |
self.ui.tableWidgetConnList.setHorizontalHeaderLabels(
|
54 |
[self.tr('Position'), self.tr('Direction'), self.tr('Symbol'), self.tr('In_out'), self.tr('Break'), |
55 |
self.tr('Type')]) |
56 |
self.ui.tableWidgetConnList.horizontalHeader().setStretchLastSection(True) |
57 |
self.ui.tableWidgetConnList.itemPressed.connect(self.onConnPtPressed) |
58 |
|
59 |
self.ui.textAreaTableWidget.setColumnCount(1) |
60 |
self.ui.textAreaTableWidget.setHorizontalHeaderLabels(['Area']) |
61 |
self.ui.textAreaTableWidget.horizontalHeader().setStretchLastSection(True) |
62 |
|
63 |
self.conn_index = 1 |
64 |
|
65 |
self.setupImageViewer()
|
66 |
self.setupTools()
|
67 |
self.initForms()
|
68 |
self.initContents()
|
69 |
self.isAccepted = False |
70 |
self.offsetX = 0 |
71 |
self.offsetY = 0 |
72 |
self.newSym = None |
73 |
|
74 |
self.ui.addTextAreaButton.clicked.connect(self.onSelectTextArea) |
75 |
self.ui.delTextAreaButton.clicked.connect(self.onDeleteTextArea) |
76 |
|
77 |
# for display image
|
78 |
if display:
|
79 |
self.ui.nameLineEdit.setEnabled(False) |
80 |
self.ui.spinBoxThreshold.setEnabled(False) |
81 |
self.ui.rotationCountSpinBox.setEnabled(False) |
82 |
self.ui.treeViewSymbolCategory.setEnabled(False) |
83 |
self.ui.spinBoxParent.setEnabled(False) |
84 |
self.ui.defaultSymbolDirectionComboBox.setEnabled(False) |
85 |
self.ui.additionalSymbolComboBox.setEnabled(False) |
86 |
self.ui.addAdditionalSymbolButton.setEnabled(False) |
87 |
self.ui.additionalSymbolListWidget.setEnabled(False) |
88 |
self.ui.originalPointLineEdit.setEnabled(False) |
89 |
self.ui.addOriginalPointButton.setEnabled(False) |
90 |
self.ui.connectionPointLineEdit.setEnabled(False) |
91 |
self.ui.addConnectionPointButton.setEnabled(False) |
92 |
self.ui.pushButtonDelConnPt.setEnabled(False) |
93 |
self.ui.tableWidgetConnList.setEnabled(False) |
94 |
self.ui.isExceptDetectCheckBox.setEnabled(False) |
95 |
self.ui.makeFlipCheckBox.setEnabled(False) |
96 |
self.ui.cropButton.setEnabled(False) |
97 |
self.ui.fitImageButton.setEnabled(False) |
98 |
self.ui.rotateLeftButton.setEnabled(False) |
99 |
self.ui.rotateRightButton.setEnabled(False) |
100 |
self.ui.flipHorizontalButton.setEnabled(False) |
101 |
self.ui.flipVerticalButton.setEnabled(False) |
102 |
self.ui.spinBoxhasInstrumentLabel.setEnabled(False) |
103 |
self.ui.textAreaTableWidget.setEnabled(False) |
104 |
self.ui.textAreaLineEdit.setEnabled(False) |
105 |
self.ui.addTextAreaButton.setEnabled(False) |
106 |
self.ui.delTextAreaButton.setEnabled(False) |
107 |
|
108 |
# unused function
|
109 |
self.ui.isContainChildLabel.setHidden(True) |
110 |
self.ui.isContainChildCheckBox.setHidden(True) |
111 |
self.ui.immediateInsertLabel.setHidden(True) |
112 |
self.ui.immediateInsertCheckBox.setHidden(True) |
113 |
|
114 |
self.ui.label_3.setHidden(True) |
115 |
self.ui.label_4.setHidden(True) |
116 |
self.ui.checkBoxChange.setHidden(True) |
117 |
self.ui.pushButtonChange.setHidden(True) |
118 |
except Exception as ex: |
119 |
from App import App |
120 |
|
121 |
message = 'error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, |
122 |
sys.exc_info()[-1].tb_lineno)
|
123 |
App.mainWnd().addMessage.emit(MessageType.Error, message) |
124 |
|
125 |
def onAreaCreated(self, x, y, width, height): |
126 |
import uuid |
127 |
THICKNESS = 1
|
128 |
|
129 |
x, y = round(x), round(y) |
130 |
width, height = round(width), round(height) |
131 |
|
132 |
boundingBox = QGraphicsBoundingBoxItem(x, y, width, height) |
133 |
boundingBox.transfer.onSizeChanged.connect(self.onBoundingBoxChanged)
|
134 |
boundingBox.transfer.onRemoved.connect(self.itemRemoved)
|
135 |
boundingBox.setPen(QPen(Qt.darkGray, THICKNESS, Qt.SolidLine)) |
136 |
self.ui.imageView.scene().addItem(boundingBox)
|
137 |
|
138 |
strArea = '({},{}),({},{})'.format(x, y, width, height)
|
139 |
self.ui.textAreaLineEdit.setText(strArea)
|
140 |
|
141 |
# add item to table widget
|
142 |
row = self.ui.textAreaTableWidget.rowCount()
|
143 |
self.ui.textAreaTableWidget.setRowCount(row + 1) |
144 |
item = QTableWidgetItem(strArea) |
145 |
item.setFlags(Qt.ItemIsEnabled) |
146 |
item.tag = boundingBox |
147 |
self.ui.textAreaTableWidget.setItem(row, 0, item) |
148 |
# up to here
|
149 |
|
150 |
self.ui.imageView.command = None |
151 |
|
152 |
def onBoundingBoxChanged(self, boundingBox): |
153 |
x = boundingBox.rect().left() |
154 |
y = boundingBox.rect().top() |
155 |
width = boundingBox.rect().width() |
156 |
height = boundingBox.rect().height() |
157 |
|
158 |
for row in range(self.ui.textAreaTableWidget.rowCount()): |
159 |
item = self.ui.textAreaTableWidget.item(row, 0) |
160 |
if boundingBox == item.tag:
|
161 |
strArea = '({},{}),({},{})'.format(round(x), round(y), round(width), round(height)) |
162 |
item.setText(strArea) |
163 |
break
|
164 |
|
165 |
def onSelectTextArea(self): |
166 |
cmd = FenceCommand.FenceCommand(self.ui.imageView)
|
167 |
cmd.onSuccess.connect(self.onAreaCreated)
|
168 |
cmd.tag = self.ui.textAreaLineEdit
|
169 |
self.ui.imageView.command = cmd
|
170 |
|
171 |
def onDeleteTextArea(self): |
172 |
try:
|
173 |
row = self.ui.textAreaTableWidget.currentRow()
|
174 |
if row is -1: |
175 |
return
|
176 |
self.removeArea(self.ui.textAreaTableWidget.item(row, 0).tag) |
177 |
self.ui.textAreaTableWidget.removeRow(row)
|
178 |
except Exception as ex: |
179 |
from App import App |
180 |
from AppDocData import MessageType |
181 |
|
182 |
message = 'error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, |
183 |
sys.exc_info()[-1].tb_lineno)
|
184 |
App.mainWnd().addMessage.emit(MessageType.Error, message) |
185 |
|
186 |
def itemRemoved(self, item): |
187 |
for row in range(self.ui.textAreaTableWidget.rowCount()): |
188 |
boundingBox = self.ui.textAreaTableWidget.item(row, 0) |
189 |
if item == boundingBox.tag:
|
190 |
self.ui.textAreaTableWidget.removeRow(row)
|
191 |
break
|
192 |
|
193 |
def removeArea(self, box): |
194 |
try:
|
195 |
self.ui.imageView.scene().removeItem(box)
|
196 |
except Exception as ex: |
197 |
from App import App |
198 |
from AppDocData import MessageType |
199 |
|
200 |
message = 'error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, |
201 |
sys.exc_info()[-1].tb_lineno)
|
202 |
App.mainWnd().addMessage.emit(MessageType.Error, message) |
203 |
|
204 |
def changeSymbolInfo(self): |
205 |
'''
|
206 |
@brief change base and additional symbol info for already created on drawing
|
207 |
@author euisung
|
208 |
@date 2019.04.23
|
209 |
'''
|
210 |
from App import App |
211 |
from SymbolSvgItem import SymbolSvgItem |
212 |
|
213 |
mainScene = App.mainWnd().graphicsView |
214 |
if not mainScene.hasImage(): |
215 |
return
|
216 |
symbols = [item for item in mainScene.items() if |
217 |
issubclass(type(item), SymbolSvgItem) and item.name == self.selectedSymbol.getName()] |
218 |
newBase = self.ui.baseSymbolComboBox.currentText()
|
219 |
newAddition = self.makeAdditionalSymbolListString()
|
220 |
newType = self.ui.typeComboBox.currentText()
|
221 |
for symbol in symbols: |
222 |
symbol.type = newType |
223 |
symbol.parentSymbol = newBase |
224 |
symbol.childSymbol = newAddition |
225 |
|
226 |
'''
|
227 |
@brief hilight pressed connector item
|
228 |
@author humkyung
|
229 |
@date 2018.08.31
|
230 |
'''
|
231 |
|
232 |
def onConnPtPressed(self, item): |
233 |
data = item.data(Qt.UserRole) |
234 |
if data is not None: |
235 |
for row in range(self.ui.tableWidgetConnList.rowCount()): |
236 |
item = self.ui.tableWidgetConnList.item(row, 0) |
237 |
item.data(Qt.UserRole).hoverLeaveEvent(None)
|
238 |
|
239 |
data.hoverEnterEvent(None)
|
240 |
|
241 |
def convertQImageToMat(self, incomingImage): |
242 |
''' Converts a QImage into an opencv MAT format '''
|
243 |
|
244 |
try:
|
245 |
incomingImage = incomingImage.convertToFormat(QImage.Format_RGBA8888) |
246 |
|
247 |
width = incomingImage.width() |
248 |
height = incomingImage.height() |
249 |
|
250 |
ptr = incomingImage.bits() |
251 |
ptr.setsize(incomingImage.byteCount()) |
252 |
arr = np.array(ptr).reshape(height, width, 4) # Copies the data |
253 |
return arr
|
254 |
except Exception as ex: |
255 |
from App import App |
256 |
|
257 |
message = 'error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, |
258 |
sys.exc_info()[-1].tb_lineno)
|
259 |
App.mainWnd().addMessage.emit(MessageType.Error, message) |
260 |
|
261 |
'''
|
262 |
@brief Set up QtImageViewer and QImage
|
263 |
@history 2018.05.02 Jeongwoo Connect imageviewer and QSymbolEditorDialog
|
264 |
'''
|
265 |
|
266 |
def setupImageViewer(self): |
267 |
from QtImageViewerScene import QtImageViewerScene |
268 |
|
269 |
x = self.ui.imageViewContainer.x()
|
270 |
y = self.ui.imageViewContainer.y()
|
271 |
width = self.ui.imageViewContainer.frameGeometry().width()
|
272 |
height = self.ui.imageViewContainer.frameGeometry().height()
|
273 |
self.ui.imageView = QtImageViewer(self) |
274 |
self.ui.imageView.setScene(QtImageViewerScene(self)) |
275 |
self.ui.imageView.scene().guidesEnabled = True |
276 |
self.ui.imageView.setGeometry(QtCore.QRect(0, y, height, height)) |
277 |
self.ui.imageView.aspectRatioMode = QtCore.Qt.KeepAspectRatio
|
278 |
self.ui.imageView.setHorizontalScrollBarPolicy(QtCore.Qt.ScrollBarAsNeeded)
|
279 |
self.ui.imageView.setVerticalScrollBarPolicy(QtCore.Qt.ScrollBarAsNeeded)
|
280 |
self.ui.imageView.canZoom = True |
281 |
self.ui.imageView.canPan = True |
282 |
image = self.image.copy()
|
283 |
self.imgW = image.width()
|
284 |
self.imgH = image.height()
|
285 |
image = image.scaled(self.imgW, self.imgH) |
286 |
self.ui.imageView.setImage(image)
|
287 |
self.ui.imageViewerContainerLayout.addWidget(self.ui.imageView) |
288 |
self.ui.imageView.startPointChanged.connect(self.offsetChanged) |
289 |
|
290 |
'''
|
291 |
@brief Set up Hand, Crop, ETC Tools
|
292 |
@history 2018.05.03 Jeongwoo Add connection for removeTextButton
|
293 |
2018.06.11 Jeongwoo Add connection for rotation and flip
|
294 |
'''
|
295 |
|
296 |
def setupTools(self): |
297 |
self.ui.handButton.clicked.connect(self.handToolClickEvent) |
298 |
self.ui.cropButton.clicked.connect(self.cropToolClickEvent) |
299 |
self.ui.penButton.clicked.connect(self.penToolClickEvent) |
300 |
self.ui.penWidthSpinBox.valueChanged.connect(self.penWidthChangedEvent) |
301 |
self.ui.eraserButton.clicked.connect(self.eraserToolClickEvent) |
302 |
self.ui.eraserSpinBox.valueChanged.connect(self.eraserWidthChangedEvent) |
303 |
self.ui.areaEraserButton.clicked.connect(self.areaEraserToolClickEvent) |
304 |
self.ui.fitImageButton.clicked.connect(self.fitImageToolClickEvent) |
305 |
self.ui.zoomButton.clicked.connect(self.zoomToolClickEvent) |
306 |
self.ui.areaZoomButton.clicked.connect(self.areaZoomToolClickEvent) |
307 |
self.ui.initZoomButton.clicked.connect(self.zoomInitToolClickEvent) |
308 |
self.ui.guidelineCheckbox.stateChanged.connect(self.guidelineStateChangedEvent) |
309 |
self.ui.removeTextButton.clicked.connect(self.removeTextClickEvent) |
310 |
self.ui.rotateLeftButton.clicked.connect(self.rotateLeftClickEvent) |
311 |
self.ui.rotateRightButton.clicked.connect(self.rotateRightClickEvent) |
312 |
self.ui.flipHorizontalButton.clicked.connect(self.flipHorizontalClickEvent) |
313 |
self.ui.flipVerticalButton.clicked.connect(self.flipVerticalClickEvent) |
314 |
self.ui.pushButtonDelConnPt.clicked.connect(self.onDeleteConnPt) |
315 |
self.ui.pushButtonChange.clicked.connect(self.changeSymbolInfo) |
316 |
|
317 |
'''
|
318 |
@brief Init Forms with type and default values
|
319 |
'''
|
320 |
|
321 |
def initForms(self): |
322 |
self.ui.minMatchPointLineEdit.setValidator(QRegExpValidator(QtCore.QRegExp("^[0-9]\d+$"))) |
323 |
self.initDefaultSymbolDirectionComboBoxItems()
|
324 |
self.ui.addAdditionalSymbolButton.clicked.connect(self.addAdditionalSymbolEvent) |
325 |
self.ui.addOriginalPointButton.clicked.connect(self.addOriginalPoint) |
326 |
self.ui.addConnectionPointButton.clicked.connect(self.addConnectionPoint) |
327 |
self.initSymbolTypeComboBoxItems()
|
328 |
# self.initBaseSymbolComboBoxItems(None)
|
329 |
self.initAdditionalSymbolComboBoxItems()
|
330 |
self.ui.guidelineCheckbox.setChecked(True) |
331 |
|
332 |
''' add symbol gradients to combobox '''
|
333 |
configs = AppDocData.instance().getConfigs('Symbol Gradients')
|
334 |
if configs is not None: |
335 |
for config in configs: |
336 |
self.ui.comboBoxNormalColor.addItem(config.key, config.value)
|
337 |
self.ui.comboBoxHoverColor.addItem(config.key, config.value)
|
338 |
|
339 |
nomalIndex = self.ui.comboBoxNormalColor.findText('Blue', Qt.MatchExactly) |
340 |
if nomalIndex is not -1: |
341 |
self.ui.comboBoxNormalColor.setCurrentIndex(nomalIndex)
|
342 |
hoberIndex = self.ui.comboBoxNormalColor.findText('Red', Qt.MatchExactly) |
343 |
if hoberIndex is not -1: |
344 |
self.ui.comboBoxHoverColor.setCurrentIndex(hoberIndex)
|
345 |
|
346 |
'''
|
347 |
@brief Init Symbol Type ComboBox Items
|
348 |
@author Jeongwoo
|
349 |
@date 2018.04.06
|
350 |
'''
|
351 |
|
352 |
def initSymbolTypeComboBoxItems(self): |
353 |
app_doc_data = AppDocData.instance() |
354 |
|
355 |
model = QStandardItemModel() |
356 |
row = 0
|
357 |
for category in app_doc_data.getSymbolTypeComboBoxItems(): |
358 |
item = QStandardItem(category[2])
|
359 |
item.setSelectable(False)
|
360 |
|
361 |
for _type in app_doc_data.getBaseSymbolComboBoxItems(category[2]): |
362 |
child = QStandardItem(_type) |
363 |
item.appendRow(child) |
364 |
|
365 |
model.setItem(row, 0, item)
|
366 |
row += 1
|
367 |
|
368 |
model.setHeaderData(0, Qt.Horizontal, 'Category', Qt.DisplayRole) |
369 |
|
370 |
"""
|
371 |
view = QTreeView(self)
|
372 |
view.setEditTriggers(view.NoEditTriggers)
|
373 |
view.setAlternatingRowColors(True)
|
374 |
view.setSelectionBehavior(view.SelectRows)
|
375 |
view.setWordWrap(True)
|
376 |
view.setAllColumnsShowFocus(True)
|
377 |
self.ui.typeComboBox.setModel(model)
|
378 |
self.ui.typeComboBox.setView(view)
|
379 |
view.expandAll()
|
380 |
"""
|
381 |
|
382 |
self.ui.treeViewSymbolCategory.setModel(model)
|
383 |
|
384 |
"""
|
385 |
for row in range(model.rowCount()):
|
386 |
for col in range(model.columnCount()):
|
387 |
item = model.item(row, col)
|
388 |
item.child(0, 0)
|
389 |
if item.text() == 'BL Line':
|
390 |
index = model.indexFromItem(item)
|
391 |
self.ui.treeViewSymbolCategory.expand(index)
|
392 |
self.ui.treeViewSymbolCategory.selectionModel().select(index, QItemSelectionModel.Rows | QItemSelectionModel.Select)
|
393 |
"""
|
394 |
|
395 |
"""
|
396 |
for item in AppDocData.instance().getSymbolTypeComboBoxItems():
|
397 |
self.ui.typeComboBox.addItem(item[2])
|
398 |
self.ui.typeComboBox.currentTextChanged.connect(self.symbolTypeTextChagedEvent)
|
399 |
"""
|
400 |
|
401 |
'''
|
402 |
@brief Set data on forms, For modifying symbol
|
403 |
@history 2018.05.02 Jeongwoo When modifying symbol, Make immediateInsertCheckBox disable
|
404 |
2018.07.04 Yecheol Remove is Symbol ID(idLineEdit)
|
405 |
'''
|
406 |
|
407 |
def initContents(self): |
408 |
try:
|
409 |
if self.selectedSymbol is not None: |
410 |
self.ui.immediateInsertCheckBox.setDisabled(True) |
411 |
|
412 |
self.ui.nameLineEdit.setText(self.selectedSymbol.getName()) |
413 |
self.ui.spinBoxThreshold.setValue(round(self.selectedSymbol.getThreshold() * 100)) |
414 |
self.ui.minMatchPointLineEdit.setText(str(self.selectedSymbol.getMinMatchCount())) |
415 |
self.ui.rotationCountSpinBox.setValue(self.selectedSymbol.getRotationCount() * 90) |
416 |
self.ui.isContainChildCheckBox.setChecked(True if self.selectedSymbol.getIsContainChild() else False) |
417 |
|
418 |
category = self.ui.treeViewSymbolCategory.model().findItems(self.selectedSymbol.getType(), |
419 |
Qt.MatchExactly) |
420 |
if category:
|
421 |
index = self.ui.treeViewSymbolCategory.model().indexFromItem(category[0]) |
422 |
self.ui.treeViewSymbolCategory.expand(index)
|
423 |
for row in range(category[0].rowCount()): |
424 |
child = category[0].child(row)
|
425 |
if child.text() == self.selectedSymbol.getBaseSymbol(): |
426 |
index = self.ui.treeViewSymbolCategory.model().indexFromItem(child)
|
427 |
self.ui.treeViewSymbolCategory.setCurrentIndex(index)
|
428 |
|
429 |
"""
|
430 |
self.ui.typeComboBox.setCurrentIndex(self.ui.typeComboBox.findText(self.selectedSymbol.getType()))
|
431 |
self.ui.baseSymbolComboBox.setCurrentIndex(
|
432 |
self.ui.baseSymbolComboBox.findText(self.selectedSymbol.getBaseSymbol()))
|
433 |
"""
|
434 |
|
435 |
self.ui.isExceptDetectCheckBox.setChecked(True if self.selectedSymbol.getIsExceptDetect() else False) |
436 |
self.ui.makeFlipCheckBox.setChecked(True if self.selectedSymbol.getDetectFlip() else False) |
437 |
|
438 |
self.ui.spinBoxhasInstrumentLabel.setValue(self.selectedSymbol.getHasInstrumentLabel()) |
439 |
|
440 |
additionalSymbol = self.selectedSymbol.getAdditionalSymbol()
|
441 |
if additionalSymbol is not None and len(additionalSymbol) > 0: |
442 |
splitAdditionalSymbolList = additionalSymbol.split("/")
|
443 |
i = 1
|
444 |
for symString in splitAdditionalSymbolList: |
445 |
splitSymString = symString.split(",")
|
446 |
if len(splitSymString) is 2: |
447 |
self.addAdditionalSymbol(i, splitSymString[0], splitSymString[1]) |
448 |
i = i + 1
|
449 |
else:
|
450 |
self.addAdditionalSymbol(splitSymString[0], splitSymString[1], splitSymString[2]) |
451 |
|
452 |
if self.selectedSymbol.getText_area(): |
453 |
for area in self.selectedSymbol.getText_area(): |
454 |
self.onAreaCreated(area.x, area.y, area.width, area.height)
|
455 |
|
456 |
originalPoint = self.selectedSymbol.getOriginalPoint()
|
457 |
self.ui.originalPointLineEdit.setText(originalPoint)
|
458 |
OriginalPointCommand.OriginalPointCommand.drawCircle(self.ui.imageView, originalPoint.split(",")[0], |
459 |
originalPoint.split(",")[1]) |
460 |
self.ui.imageView.isOriginalPointSelected = True |
461 |
|
462 |
connectionPoint = self.selectedSymbol.getConnectionPoint()
|
463 |
if connectionPoint is not None and len(connectionPoint) > 0: |
464 |
splitConnectionPointList = connectionPoint.split("/")
|
465 |
symbol_indecies = [str(idx) for idx in range(self.ui.additionalSymbolListWidget.count() + 1)] |
466 |
|
467 |
self.ui.tableWidgetConnList.setRowCount(len(splitConnectionPointList)) |
468 |
row = 0
|
469 |
for conString in splitConnectionPointList: # conString : x,y |
470 |
direction = 'AUTO'
|
471 |
symbol_idx = '0'
|
472 |
in_out = 'None'
|
473 |
break_or_not = 'X'
|
474 |
configs = AppDocData.instance().getConfigs('Line', 'Default Type') |
475 |
conn_type = configs[0].value if 1 == len(configs) else 'Secondary' |
476 |
tokens = conString.split(',')
|
477 |
if len(tokens) == 2: |
478 |
x = float(tokens[0]) |
479 |
y = float(tokens[1]) |
480 |
elif len(tokens) >= 3: |
481 |
direction = tokens[0]
|
482 |
x = float(tokens[1]) |
483 |
y = float(tokens[2]) |
484 |
if len(tokens) >= 4: |
485 |
symbol_idx = tokens[3]
|
486 |
if len(tokens) >= 6: |
487 |
in_out = tokens[4]
|
488 |
break_or_not = tokens[5]
|
489 |
if len(tokens) >= 7: |
490 |
conn_type = tokens[6]
|
491 |
|
492 |
conn = ConnectionPointCommand.ConnectionPointCommand.drawCircle(self.ui.imageView, x, y,
|
493 |
self.conn_index)
|
494 |
self.conn_index += 1 |
495 |
|
496 |
item = QTableWidgetItem('{},{}'.format(x, y))
|
497 |
item.setFlags(Qt.ItemIsEnabled) |
498 |
item.setData(Qt.UserRole, conn) |
499 |
self.ui.tableWidgetConnList.setItem(row, 0, item) |
500 |
|
501 |
directionComboBox = QComboBox(self.ui.tableWidgetConnList)
|
502 |
directionComboBox.addItems(['AUTO', 'LEFT', 'RIGHT', 'UP', 'DOWN']) |
503 |
directionComboBox.setCurrentText(direction) |
504 |
self.ui.tableWidgetConnList.setCellWidget(row, 1, directionComboBox) |
505 |
|
506 |
# add symbol index combobox - 2019.01.04 added by humkyung
|
507 |
symbol_idx_combobox = QComboBox(self.ui.tableWidgetConnList)
|
508 |
symbol_idx_combobox.addItems(symbol_indecies) |
509 |
if symbol_idx in symbol_indecies: |
510 |
symbol_idx_combobox.setCurrentText(symbol_idx) |
511 |
else:
|
512 |
symbol_idx_combobox.setCurrentText('0')
|
513 |
self.ui.tableWidgetConnList.setCellWidget(row, 2, symbol_idx_combobox) |
514 |
# up to here
|
515 |
|
516 |
in_out_combobox = QComboBox(self.ui.tableWidgetConnList)
|
517 |
in_out_combobox.addItems(['None', 'In', 'Out']) |
518 |
in_out_combobox.setCurrentText(in_out) |
519 |
self.ui.tableWidgetConnList.setCellWidget(row, 3, in_out_combobox) |
520 |
|
521 |
break_ComboBox = QComboBox(self.ui.tableWidgetConnList)
|
522 |
break_ComboBox.addItems(['O', 'X']) |
523 |
break_ComboBox.setCurrentText(break_or_not) |
524 |
self.ui.tableWidgetConnList.setCellWidget(row, 4, break_ComboBox) |
525 |
|
526 |
conn_type_combobox = QComboBox(self.ui.tableWidgetConnList)
|
527 |
conn_type_combobox.addItems([lineType.name for lineType in LineTypeConditions.items()]) |
528 |
conn_type_combobox.setCurrentText(conn_type) |
529 |
self.ui.tableWidgetConnList.setCellWidget(row, 5, conn_type_combobox) |
530 |
|
531 |
row = row + 1
|
532 |
|
533 |
self.ui.tableWidgetConnList.resizeColumnsToContents()
|
534 |
else:
|
535 |
self.ui.minMatchPointLineEdit.setText('0') |
536 |
except Exception as ex: |
537 |
from App import App |
538 |
|
539 |
message = 'error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, |
540 |
sys.exc_info()[-1].tb_lineno)
|
541 |
App.mainWnd().addMessage.emit(MessageType.Error, message) |
542 |
|
543 |
'''
|
544 |
@brief Init ComboBox Items For Direction of DB Field [additionalSymbol]
|
545 |
'''
|
546 |
|
547 |
def initDefaultSymbolDirectionComboBoxItems(self): |
548 |
for item in AppDocData.instance().getDefaultSymbolDirectionComboBoxItems(): |
549 |
self.ui.defaultSymbolDirectionComboBox.addItem(item[0], item[1]) # 0 : text / 1 : data(integer) |
550 |
|
551 |
'''
|
552 |
@brief Init ComboBox Items For DB Field [baseSymbol]
|
553 |
'''
|
554 |
|
555 |
"""
|
556 |
def initBaseSymbolComboBoxItems(self, type):
|
557 |
self.ui.baseSymbolComboBox.clear()
|
558 |
for item in AppDocData.instance().getBaseSymbolComboBoxItems(type):
|
559 |
self.ui.baseSymbolComboBox.addItem(item)
|
560 |
"""
|
561 |
|
562 |
'''
|
563 |
@brief Init ComboBox Items For symbolName of DB Field [additionalSymbol]
|
564 |
'''
|
565 |
|
566 |
def initAdditionalSymbolComboBoxItems(self): |
567 |
for name in AppDocData.instance().getAdditionalSymbolComboBoxItems(): |
568 |
self.ui.additionalSymbolComboBox.addItem(name)
|
569 |
|
570 |
'''
|
571 |
@brief remove ConnectionPoint Circles (Using for loop)
|
572 |
'''
|
573 |
|
574 |
def removeConnectionPointCircles(self, circlePointList): |
575 |
for circlePoint in circlePointList: |
576 |
self.removeConnectionPointCircle(circlePoint)
|
577 |
|
578 |
'''
|
579 |
@brief remove each ConnectionPoint Circle
|
580 |
@history 2018.06.12 Jeongwoo Add conditions for selecting ellipse item
|
581 |
'''
|
582 |
|
583 |
def removeConnectionPointCircle(self, circlePoint): |
584 |
from EngineeringConnectorItem import QEngineeringConnectorItem |
585 |
|
586 |
imageWidth = self.ui.imageView.image().width()
|
587 |
imageHeight = self.ui.imageView.image().height()
|
588 |
items = [item for item in |
589 |
self.ui.imageView.scene().items(QRectF(float(circlePoint.x()) - 0.5, float(circlePoint.y()) - 0.5, 1, 1)) \ |
590 |
if type(item) is QEngineeringConnectorItem] |
591 |
for item in items: |
592 |
self.ui.imageView.scene().removeItem(item)
|
593 |
|
594 |
'''^
|
595 |
@brief Display this QDialog
|
596 |
@history 2018.05.02 Jeongwoo Change return value (Single variable → Tuple)
|
597 |
'''
|
598 |
|
599 |
def showDialog(self): |
600 |
self.setWindowFlags(self.windowFlags() & ~QtCore.Qt.WindowContextHelpButtonHint) |
601 |
self.exec_()
|
602 |
return (self.isAccepted, self.ui.immediateInsertCheckBox.isChecked(), self.offsetX, self.offsetY, self.newSym) |
603 |
|
604 |
'''
|
605 |
@brief Using input [Name], make file name
|
606 |
If the [Name] exists, add number like [FILE_NAME(1), FILE_NAME(2), ...]
|
607 |
Recursive function
|
608 |
@history 2018.05.02 Jeongwoo Change isExistFileName's parameter (Dir → newName)
|
609 |
2018.05.03 Jeongwoo Change self.dbHelper to AppDocData
|
610 |
'''
|
611 |
|
612 |
def makeFileName(self, type, originName, newName): |
613 |
imageFolderDir = self.project.getImageFilePath()
|
614 |
imageDir = os.path.join(imageFolderDir, type, newName + '.png') |
615 |
svgFolderDir = self.project.getSvgFilePath()
|
616 |
svgDir = os.path.join(svgFolderDir, type, newName + '.svg') |
617 |
if (os.path.exists(imageDir)) or (AppDocData.instance().isExistFileName(newName) or (os.path.exists(svgDir))): |
618 |
self.FILE_NUMBER = self.FILE_NUMBER + 1 |
619 |
imgName = originName + "({})".format(self.FILE_NUMBER) |
620 |
return self.makeFileName(type, originName, imgName) |
621 |
else:
|
622 |
return newName
|
623 |
|
624 |
def make_symbol_data(self, width, height): |
625 |
"""make a symbol object to save to database"""
|
626 |
|
627 |
uid = -1
|
628 |
if self.selectedSymbol is not None: |
629 |
uid = self.selectedSymbol.getUid()
|
630 |
# symId = self.ui.idLineEdit.text()
|
631 |
name = self.ui.nameLineEdit.text()
|
632 |
|
633 |
index = self.ui.treeViewSymbolCategory.currentIndex()
|
634 |
item = self.ui.treeViewSymbolCategory.model().itemFromIndex(index)
|
635 |
if item:
|
636 |
category = item.parent().text() |
637 |
self.FILE_NUMBER = 0 |
638 |
lastName = ""
|
639 |
if self.selectedSymbol is not None: |
640 |
lastName = self.selectedSymbol.getName()
|
641 |
fileName = ""
|
642 |
if name == lastName:
|
643 |
fileName = name |
644 |
else:
|
645 |
fileName = self.makeFileName(category, name, name)
|
646 |
threshold = str(self.ui.spinBoxThreshold.value()) |
647 |
minMatchPoint = self.ui.minMatchPointLineEdit.text()
|
648 |
rotationCount = int(self.ui.rotationCountSpinBox.value() / 90) |
649 |
ocrOption = 0
|
650 |
isContainChild = 1 if self.ui.isContainChildCheckBox.isChecked() else 0 |
651 |
originalPoint = self.ui.originalPointLineEdit.text()
|
652 |
connectionPoint = self.makeConnectionPointListString()
|
653 |
baseSymbol = item.text() # self.ui.baseSymbolComboBox.currentText()
|
654 |
additionalSymbol = self.makeAdditionalSymbolListString()
|
655 |
isExceptDetect = 1 if self.ui.isExceptDetectCheckBox.isChecked() else 0 |
656 |
|
657 |
hasInstrumentLabel = self.ui.spinBoxhasInstrumentLabel.value()
|
658 |
|
659 |
detectFlip = 1 if self.ui.makeFlipCheckBox.isChecked() else 0 |
660 |
|
661 |
convertedThreshold = int(threshold) / 100.0 |
662 |
|
663 |
imageWidth = width |
664 |
iamgeHeight = height |
665 |
|
666 |
text_areas = [] |
667 |
for row in range(self.ui.textAreaTableWidget.rowCount()): |
668 |
area = Area('Text Area')
|
669 |
area.parse(self.ui.textAreaTableWidget.item(row, 0).text()) |
670 |
text_areas.append(area) |
671 |
|
672 |
self.newSym = symbol.SymbolBase(fileName, category, convertedThreshold, int(minMatchPoint), True, |
673 |
rotationCount, ocrOption, isContainChild, originalPoint, connectionPoint, |
674 |
baseSymbol, additionalSymbol, isExceptDetect, hasInstrumentLabel, uid, |
675 |
imageWidth, iamgeHeight, detectFlip=detectFlip, text_area=text_areas) |
676 |
|
677 |
return self.newSym |
678 |
else:
|
679 |
QMessageBox.warning(self, self.tr('Warning'), self.tr('Please select symbol category')) |
680 |
return None |
681 |
|
682 |
'''
|
683 |
@brief Make AdditionalSymbol String
|
684 |
[AdditionalSymbolString = DIRECTION,SYMBOL_NAME/DIRECTION,SYMBOL_NAME/...]
|
685 |
'''
|
686 |
|
687 |
def makeAdditionalSymbolListString(self): |
688 |
ret = ""
|
689 |
listItems = [] |
690 |
for index in range(self.ui.additionalSymbolListWidget.count()): |
691 |
listItems.append(self.ui.additionalSymbolListWidget.item(index))
|
692 |
if listItems is not None: |
693 |
for index in range(len(listItems)): |
694 |
item = listItems[index] |
695 |
text = item.text() |
696 |
if index != 0: |
697 |
ret = ret + "/"
|
698 |
ret = ret + text |
699 |
|
700 |
return ret
|
701 |
|
702 |
'''
|
703 |
@brief Make ConnectionPoint String
|
704 |
[ConnectionPointString = U,x1,y1/D,x2,y2/...]
|
705 |
'''
|
706 |
|
707 |
def makeConnectionPointListString(self): |
708 |
res = ""
|
709 |
|
710 |
connPtStringList = [] |
711 |
for row in range(self.ui.tableWidgetConnList.rowCount()): |
712 |
direction = self.ui.tableWidgetConnList.cellWidget(row, 1).currentText() |
713 |
symbol_idx = self.ui.tableWidgetConnList.cellWidget(row, 2).currentText() |
714 |
in_out = self.ui.tableWidgetConnList.cellWidget(row, 3).currentText() |
715 |
break_or_not = self.ui.tableWidgetConnList.cellWidget(row, 4).currentText() |
716 |
conn_type = self.ui.tableWidgetConnList.cellWidget(row, 5).currentText() |
717 |
|
718 |
connPtString = '{},{},{},{},{},{}'.format(direction, self.ui.tableWidgetConnList.item(row, 0).text(), |
719 |
symbol_idx, in_out, break_or_not, conn_type) |
720 |
connPtStringList.append(connPtString) |
721 |
|
722 |
res = '/'.join(connPtStringList)
|
723 |
|
724 |
return res
|
725 |
|
726 |
'''
|
727 |
@brief Called when Save Button Clicked
|
728 |
Validation Check → Make Symbol Data → Insert Symbol Data into DB → Save png and svg files
|
729 |
@history 2018.05.03 Jeongwoo Change parameters on method 'deleteImageAndSvg'
|
730 |
Change self.dbHelper to AppDocData
|
731 |
'''
|
732 |
|
733 |
def accept(self): |
734 |
from SymbolSvgItem import SymbolSvgItem |
735 |
|
736 |
valid, exceptionMsg = self.isValidSymbolInfo()
|
737 |
app_doc_data = AppDocData.instance() |
738 |
if valid:
|
739 |
symbol_data = self.make_symbol_data(self.ui.imageView.image().width(), self.ui.imageView.image().height()) |
740 |
if not symbol_data: |
741 |
return
|
742 |
|
743 |
if self.selectedSymbol is None: |
744 |
isSuccess, fileType, SymName, image_file_path = app_doc_data.insertSymbol(symbol_data) |
745 |
else:
|
746 |
isSuccess, fileType, SymName, image_file_path = app_doc_data.updateSymbol(symbol_data) |
747 |
|
748 |
if isSuccess and not self.display: |
749 |
try:
|
750 |
image = self.ui.imageView.image()
|
751 |
if image is not None: |
752 |
if self.selectedSymbol is not None: |
753 |
self.deleteImageAndSvg(self.selectedSymbol.getImageFileFullPath(), |
754 |
self.selectedSymbol.getSvgFileFullPath())
|
755 |
imageLocation = os.path.join(self.project.getImageFilePath(), fileType)
|
756 |
if not os.path.exists(imageLocation): |
757 |
os.makedirs(imageLocation) |
758 |
|
759 |
image.save(image_file_path, 'PNG')
|
760 |
|
761 |
svgLocation = os.path.join(self.project.getSvgFilePath(), fileType)
|
762 |
if not os.path.exists(svgLocation): |
763 |
os.makedirs(svgLocation) |
764 |
|
765 |
normal_color = self.ui.comboBoxNormalColor.itemData(self.ui.comboBoxNormalColor.currentIndex()) |
766 |
hover_color = self.ui.comboBoxHoverColor.itemData(self.ui.comboBoxHoverColor.currentIndex()) |
767 |
svg_file_path = os.path.join(svgLocation, SymName + ".svg")
|
768 |
potrace.convertImageToSvg(image_file_path, svg_file_path, normalColor=normal_color, |
769 |
hoverColor=hover_color) |
770 |
|
771 |
# del document for symbol
|
772 |
if svg_file_path in SymbolSvgItem.DOCUMENTS: |
773 |
del SymbolSvgItem.DOCUMENTS[svg_file_path]
|
774 |
# up to here
|
775 |
|
776 |
app_doc_data.update_symbol_shape(SymName, image_file_path, svg_file_path, None)
|
777 |
self.isAccepted = True |
778 |
if self.ui.checkBoxChange.isChecked(): |
779 |
self.changeSymbolInfo()
|
780 |
QDialog.accept(self)
|
781 |
except Exception as ex: |
782 |
if self.selectedSymbol is None: |
783 |
self.resetInsertSymbol(image_file_path, SymName)
|
784 |
else:
|
785 |
self.resetUpdateSymbol(image_file_path, SymName) # update roll back 으로 변경해야함 |
786 |
self.isAccepted = False |
787 |
QMessageBox.about(self.ui.buttonBox, self.tr('Error'), |
788 |
self.tr('Error occurs during saving symbol, please check data.')) |
789 |
elif self.display: |
790 |
try:
|
791 |
image = self.ui.imageView.image()
|
792 |
if image is not None: |
793 |
self.deleteImageAndSvg(self.selectedSymbol.getImageFileFullPath(), |
794 |
self.selectedSymbol.getSvgFileFullPath(), self.display) |
795 |
imageLocation = os.path.join(self.project.getImageFilePath(), fileType)
|
796 |
|
797 |
path = os.path.splitext(image_file_path) |
798 |
path = path[0] + '_display' + path[1] |
799 |
image.save(path, 'PNG')
|
800 |
|
801 |
svgLocation = os.path.join(self.project.getSvgFilePath(), fileType)
|
802 |
if not os.path.exists(svgLocation): |
803 |
os.makedirs(svgLocation) |
804 |
|
805 |
normal_color = self.ui.comboBoxNormalColor.itemData(self.ui.comboBoxNormalColor.currentIndex()) |
806 |
hover_color = self.ui.comboBoxHoverColor.itemData(self.ui.comboBoxHoverColor.currentIndex()) |
807 |
svg_file_path = os.path.join(svgLocation, SymName + ".svg")
|
808 |
potrace.convertImageToSvg(path, svg_file_path, normalColor=normal_color, hoverColor=hover_color) |
809 |
|
810 |
app_doc_data.update_symbol_shape(SymName, None, svg_file_path, path)
|
811 |
QDialog.accept(self)
|
812 |
except Exception as ex: |
813 |
self.resetUpdateSymbol(image_file_path, SymName, self.display) # update roll back 으로 변경해야함 |
814 |
self.isAccepted = False |
815 |
QMessageBox.about(self.ui.buttonBox, self.tr('Error'), |
816 |
self.tr('Error occurs during saving symbol, please check data.')) |
817 |
|
818 |
else:
|
819 |
QMessageBox.about(self.ui.buttonBox, self.tr('Error'), |
820 |
self.tr('Error occurs during saving symbol, please check data.')) |
821 |
else:
|
822 |
QMessageBox.about(self.ui.buttonBox, self.tr('Notice'), exceptionMsg) |
823 |
|
824 |
'''
|
825 |
@brief Called When Close Button Clicked
|
826 |
'''
|
827 |
|
828 |
def reject(self): |
829 |
self.isAccepted = False |
830 |
QDialog.reject(self)
|
831 |
|
832 |
'''
|
833 |
@history 2018.05.03 Jeongwoo Change Parameters (imagePath, type, name → imagePath, svgPath)
|
834 |
'''
|
835 |
|
836 |
def deleteImageAndSvg(self, imagePath, svgPath, display=False): |
837 |
if not display and os.path.exists(imagePath): |
838 |
os.remove(imagePath) |
839 |
|
840 |
path = os.path.splitext(imagePath) |
841 |
path = path[0] + '_display' + path[1] |
842 |
if os.path.exists(path):
|
843 |
os.remove(path) |
844 |
|
845 |
if os.path.exists(svgPath):
|
846 |
os.remove(svgPath) |
847 |
|
848 |
'''
|
849 |
@brief Called When error occurred while saving png and svg files
|
850 |
Delete png, svg files and record from DB
|
851 |
@history 2018.05.03 Jeongwoo Change Parameters and fileName variable
|
852 |
'''
|
853 |
|
854 |
def resetInsertSymbol(self, imagePath, svgPath): |
855 |
self.deleteImageAndSvg(imagePath, svgPath)
|
856 |
|
857 |
fileName = os.path.basename(imagePath.replace('.png', '')) |
858 |
AppDocData.instance().deleteSymbol(fileName) |
859 |
|
860 |
'''
|
861 |
@history 2018.05.03 Jeongwoo Change Parameters
|
862 |
Change self.dbHelper to AppDocData
|
863 |
'''
|
864 |
|
865 |
def resetUpdateSymbol(self, imagePath, svgPath, display=False): |
866 |
self.deleteImageAndSvg(imagePath, svgPath, display)
|
867 |
|
868 |
AppDocData.instance().updateSymbol(self.selectedSymbol)
|
869 |
|
870 |
'''
|
871 |
@history 2018.06.12 Jeongwoo coords type changed (int → float)
|
872 |
'''
|
873 |
|
874 |
def keyPressEvent(self, event): |
875 |
if event.key() == QtCore.Qt.Key_Delete:
|
876 |
if self.ui.tableWidgetConnList.hasFocus(): |
877 |
self.ui.imageView.command = None |
878 |
model = self.ui.tableWidgetConnList.model()
|
879 |
|
880 |
item = self.ui.tableWidgetConnList.currentItem()
|
881 |
if item is not None: |
882 |
item = self.ui.tableWidgetConnList.item(item.row(), 0) |
883 |
data = item.data(Qt.UserRole) |
884 |
if data is not None: |
885 |
self.ui.imageView.scene().removeItem(data)
|
886 |
model.removeRow(item.row()) |
887 |
self.conn_index -= 1 |
888 |
|
889 |
for index in range(self.ui.tableWidgetConnList.rowCount()): |
890 |
item = self.ui.tableWidgetConnList.item(index, 0) |
891 |
data = item.data(Qt.UserRole) |
892 |
if data is not None: |
893 |
data.label = str(index + 1) |
894 |
elif self.ui.additionalSymbolListWidget.hasFocus(): |
895 |
selectedItems = self.ui.additionalSymbolListWidget.selectedItems()
|
896 |
if selectedItems is not None: |
897 |
for item in selectedItems: |
898 |
self.ui.additionalSymbolListWidget.takeItem(self.ui.additionalSymbolListWidget.row(item)) |
899 |
elif event.key() == Qt.Key_Escape:
|
900 |
self.reject()
|
901 |
|
902 |
'''
|
903 |
@brief Hand Tool Button Clicked
|
904 |
'''
|
905 |
|
906 |
def handToolClickEvent(self, event): |
907 |
self.ui.imageView.command = HandCommand.HandCommand(self.ui.imageView) |
908 |
|
909 |
'''
|
910 |
@brief Crop Tool Button Clicked
|
911 |
@history 2018.06.11 Jeongwoo init original/connection points and guide line refresh
|
912 |
'''
|
913 |
|
914 |
def cropToolClickEvent(self, event): |
915 |
self.initOriginalAndConnectionPoint()
|
916 |
self.ui.imageView.command = CropCommand.CropCommand(self.ui.imageView) |
917 |
self.guidelineStateChangedEvent(None) |
918 |
|
919 |
'''
|
920 |
@brief Zoom Init Tool Button Clicked
|
921 |
'''
|
922 |
|
923 |
def zoomInitToolClickEvent(self, event): |
924 |
self.ui.imageView.command = None |
925 |
self.ui.imageView.zoomImageInit()
|
926 |
|
927 |
'''
|
928 |
@brief Area Zoom Tool Button Clicked
|
929 |
'''
|
930 |
|
931 |
def areaZoomToolClickEvent(self, event): |
932 |
self.ui.imageView.command = AreaZoomCommand.AreaZoomCommand(self.ui.imageView) |
933 |
|
934 |
'''
|
935 |
@brief Zoom Tool Button Clicked
|
936 |
'''
|
937 |
|
938 |
def zoomToolClickEvent(self, event): |
939 |
self.ui.imageView.command = ZoomCommand.ZoomCommand(self.ui.imageView) |
940 |
|
941 |
'''
|
942 |
@brief Pen Tool Button Clicked
|
943 |
'''
|
944 |
|
945 |
def penToolClickEvent(self, event): |
946 |
width = self.ui.toolWidget.findChild(QSpinBox, 'penWidthSpinBox').value() |
947 |
self.ui.imageView.command = PenCommand.PenCommand(self.ui.imageView) |
948 |
self.ui.imageView.command.width = width
|
949 |
|
950 |
'''
|
951 |
@brief Pen Width Value Changed
|
952 |
'''
|
953 |
|
954 |
def penWidthChangedEvent(self, value): |
955 |
if self.ui.imageView.command is not None and type(self.ui.imageView.command) is PenCommand.PenCommand: |
956 |
self.ui.imageView.command.width = value
|
957 |
|
958 |
'''
|
959 |
@brief Eraser Tool Button Clicked
|
960 |
'''
|
961 |
|
962 |
def eraserToolClickEvent(self, event): |
963 |
width = self.ui.toolWidget.findChild(QSpinBox, 'eraserSpinBox').value() |
964 |
self.ui.imageView.command = EraserCommand.EraserCommand(self.ui.imageView) |
965 |
self.ui.imageView.command.width = width
|
966 |
|
967 |
'''
|
968 |
@brief Eraser Width Value Changed
|
969 |
'''
|
970 |
|
971 |
def eraserWidthChangedEvent(self, value): |
972 |
if self.ui.imageView.command is not None and type(self.ui.imageView.command) is EraserCommand.EraserCommand: |
973 |
self.ui.imageView.command.width = value
|
974 |
|
975 |
'''
|
976 |
@brief Area Eraser Tool Button Clicked
|
977 |
'''
|
978 |
|
979 |
def areaEraserToolClickEvent(self, event): |
980 |
self.ui.imageView.command = AreaEraserCommand.AreaEraserCommand(self.ui.imageView) |
981 |
|
982 |
'''
|
983 |
@brief Fit Image Tool Button Clicked
|
984 |
@history 2018.05.02 Jeongwoo Method name changed(getAdjust → getOffset)
|
985 |
Emit offsets to startPointChanged
|
986 |
2018.06.11 Jeongwoo init original/connection points
|
987 |
'''
|
988 |
|
989 |
def fitImageToolClickEvent(self, event): |
990 |
self.initOriginalAndConnectionPoint()
|
991 |
self.ui.imageView.command = FitImageCommand.FitImageCommand(self.ui.imageView) |
992 |
adjustX, adjustY = self.ui.imageView.command.getOffset()
|
993 |
self.ui.imageView.startPointChanged.emit(adjustX, adjustY)
|
994 |
|
995 |
'''
|
996 |
@brief Guideline Check State Changed
|
997 |
'''
|
998 |
|
999 |
def guidelineStateChangedEvent(self, value): |
1000 |
if self.ui.guidelineCheckbox.isChecked(): |
1001 |
self.ui.imageView.showGuideline(None, True) |
1002 |
else:
|
1003 |
self.ui.imageView.showGuideline(None, False) |
1004 |
|
1005 |
'''
|
1006 |
@brief Add AdditionalSymbol String on ListWidget Listener
|
1007 |
'''
|
1008 |
|
1009 |
def addAdditionalSymbolEvent(self, event): |
1010 |
additionalSymbolIndex = self.ui.additionalSymbolComboBox.currentIndex()
|
1011 |
if additionalSymbolIndex != 0: |
1012 |
parent_index = self.ui.spinBoxParent.value()
|
1013 |
direction = self.ui.defaultSymbolDirectionComboBox.currentText()
|
1014 |
symbolName = self.ui.additionalSymbolComboBox.currentText()
|
1015 |
self.addAdditionalSymbol(parent_index, direction, symbolName)
|
1016 |
|
1017 |
'''
|
1018 |
@brief Add AdditionalSymbol String on ListWidget
|
1019 |
'''
|
1020 |
|
1021 |
def addAdditionalSymbol(self, parent_index, direction, symbolName): |
1022 |
text = "{},{},{}".format(parent_index, direction, symbolName)
|
1023 |
|
1024 |
if self.isAlreadyAdded(text): |
1025 |
QMessageBox.about(self.ui.buttonBox, self.tr('Notice'), self.tr('Already add item')) |
1026 |
else:
|
1027 |
self.ui.additionalSymbolListWidget.addItem(text)
|
1028 |
|
1029 |
'''
|
1030 |
@brief Check the text is already added
|
1031 |
'''
|
1032 |
|
1033 |
def isAlreadyAdded(self, text): |
1034 |
for index in range(self.ui.additionalSymbolListWidget.count()): |
1035 |
item = self.ui.additionalSymbolListWidget.item(index)
|
1036 |
if item.text() == text:
|
1037 |
return True |
1038 |
return False |
1039 |
|
1040 |
'''
|
1041 |
@brief update scene when command is success
|
1042 |
@author humkyung
|
1043 |
@date 2018.08.28
|
1044 |
'''
|
1045 |
|
1046 |
def onCommandSuccess(self, pt): |
1047 |
from EngineeringConnectorItem import QEngineeringConnectorItem |
1048 |
|
1049 |
self.ui.imageView.scene().invalidate()
|
1050 |
if type(pt) is QEngineeringConnectorItem: |
1051 |
rows = self.ui.tableWidgetConnList.rowCount()
|
1052 |
self.ui.tableWidgetConnList.setRowCount(rows + 1) |
1053 |
|
1054 |
item = QTableWidgetItem('{},{}'.format(pt.center()[0], pt.center()[1])) |
1055 |
item.setData(Qt.UserRole, pt) |
1056 |
item.setFlags(Qt.ItemIsEnabled) |
1057 |
self.ui.tableWidgetConnList.setItem(rows, 0, item) |
1058 |
|
1059 |
directionComboBox = QComboBox(self.ui.tableWidgetConnList)
|
1060 |
directionComboBox.addItems(['AUTO', 'LEFT', 'RIGHT', 'UP', 'DOWN']) |
1061 |
directionComboBox.setCurrentText('AUTO')
|
1062 |
self.ui.tableWidgetConnList.setCellWidget(rows, 1, directionComboBox) |
1063 |
|
1064 |
# add symbol index combobox - 2019.01.07 added by humkyung
|
1065 |
symbol_indecies = [str(idx) for idx in range(self.ui.additionalSymbolListWidget.count() + 1)] |
1066 |
symbol_idx_combobox = QComboBox(self.ui.tableWidgetConnList)
|
1067 |
symbol_idx_combobox.addItems(symbol_indecies) |
1068 |
symbol_idx_combobox.setCurrentText('0')
|
1069 |
self.ui.tableWidgetConnList.setCellWidget(rows, 2, symbol_idx_combobox) |
1070 |
# up to here
|
1071 |
|
1072 |
in_out_combobox = QComboBox(self.ui.tableWidgetConnList)
|
1073 |
in_out_combobox.addItems(['None', 'In', 'Out']) |
1074 |
in_out_combobox.setCurrentText('None')
|
1075 |
self.ui.tableWidgetConnList.setCellWidget(rows, 3, in_out_combobox) |
1076 |
|
1077 |
break_ComboBox = QComboBox(self.ui.tableWidgetConnList)
|
1078 |
break_ComboBox.addItems(['O', 'X']) |
1079 |
break_ComboBox.setCurrentText('X')
|
1080 |
self.ui.tableWidgetConnList.setCellWidget(rows, 4, break_ComboBox) |
1081 |
|
1082 |
configs = AppDocData.instance().getConfigs('Line', 'Default Type') |
1083 |
conn_type = configs[0].value if 1 == len(configs) else 'Secondary' |
1084 |
|
1085 |
conn_type_combobox = QComboBox(self.ui.tableWidgetConnList)
|
1086 |
conn_type_combobox.addItems([lineType.name for lineType in LineTypeConditions.items()]) |
1087 |
conn_type_combobox.setCurrentText(conn_type) |
1088 |
self.ui.tableWidgetConnList.setCellWidget(rows, 5, conn_type_combobox) |
1089 |
|
1090 |
self.conn_index += 1 |
1091 |
|
1092 |
self.ui.tableWidgetConnList.resizeColumnsToContents()
|
1093 |
|
1094 |
'''
|
1095 |
@brief Original Point Tool Button Clicked
|
1096 |
'''
|
1097 |
|
1098 |
def addOriginalPoint(self, event): |
1099 |
cmd = OriginalPointCommand.OriginalPointCommand(self.ui.imageView, self.ui.originalPointLineEdit) |
1100 |
cmd.onSuccess.connect(self.onCommandSuccess)
|
1101 |
self.ui.imageView.command = cmd
|
1102 |
|
1103 |
'''
|
1104 |
@brief Connection Point Tool Button Clicked
|
1105 |
'''
|
1106 |
|
1107 |
def addConnectionPoint(self, event): |
1108 |
cmd = ConnectionPointCommand.ConnectionPointCommand(self.ui.imageView, self.ui.connectionPointLineEdit, |
1109 |
self.conn_index)
|
1110 |
cmd.onSuccess.connect(self.onCommandSuccess)
|
1111 |
self.ui.imageView.command = cmd
|
1112 |
|
1113 |
'''
|
1114 |
@brief delete current item from tableWidgetConnList
|
1115 |
@author humkyung
|
1116 |
@date 2018.08.31
|
1117 |
'''
|
1118 |
|
1119 |
def onDeleteConnPt(self): |
1120 |
try:
|
1121 |
self.ui.imageView.command = None |
1122 |
model = self.ui.tableWidgetConnList.model()
|
1123 |
|
1124 |
item = self.ui.tableWidgetConnList.currentItem()
|
1125 |
if item is not None: |
1126 |
item = self.ui.tableWidgetConnList.item(item.row(), 0) |
1127 |
data = item.data(Qt.UserRole) |
1128 |
if data is not None: |
1129 |
self.ui.imageView.scene().removeItem(data)
|
1130 |
model.removeRow(item.row()) |
1131 |
self.conn_index -= 1 |
1132 |
|
1133 |
for index in range(self.ui.tableWidgetConnList.rowCount()): |
1134 |
item = self.ui.tableWidgetConnList.item(index, 0) |
1135 |
data = item.data(Qt.UserRole) |
1136 |
if data is not None: |
1137 |
data.label = str(index + 1) |
1138 |
except Exception as ex: |
1139 |
from App import App |
1140 |
from AppDocData import MessageType |
1141 |
|
1142 |
message = 'error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, |
1143 |
sys.exc_info()[-1].tb_lineno)
|
1144 |
App.mainWnd().addMessage.emit(MessageType.Error, message) |
1145 |
|
1146 |
'''
|
1147 |
@brief Remove Text Tool Button Clicked
|
1148 |
@author Jeongwoo
|
1149 |
@date 2018.05.03
|
1150 |
@history 2018.05.09 Jeongwoo Remove comment and activate RemoveTextCommand
|
1151 |
'''
|
1152 |
|
1153 |
def removeTextClickEvent(self, event): |
1154 |
self.ui.imageView.command = RemoveTextCommand.RemoveTextCommand(self.ui.imageView) |
1155 |
|
1156 |
'''
|
1157 |
@brief Init Original/Connection points
|
1158 |
@author Jeongwoo
|
1159 |
@date 2018.06.11
|
1160 |
'''
|
1161 |
|
1162 |
def initOriginalAndConnectionPoint(self): |
1163 |
self.ui.originalPointLineEdit.setText('') |
1164 |
self.ui.tableWidgetConnList.setRowCount(0) |
1165 |
# self.ui.connectionPointList.clear()
|
1166 |
|
1167 |
'''
|
1168 |
@brief Rotate image clockwise
|
1169 |
@author Jeongwoo
|
1170 |
@date 2018.06.11
|
1171 |
'''
|
1172 |
|
1173 |
def rotateLeftClickEvent(self, event): |
1174 |
self.initOriginalAndConnectionPoint()
|
1175 |
self.ui.imageView.command = RotateImageCommand.RotateImageCommand(self.ui.imageView, True) |
1176 |
self.guidelineStateChangedEvent(None) |
1177 |
|
1178 |
'''
|
1179 |
@brief Rotate image counter-clockwise
|
1180 |
@author Jeongwoo
|
1181 |
@date 2018.06.11
|
1182 |
'''
|
1183 |
|
1184 |
def rotateRightClickEvent(self, event): |
1185 |
self.initOriginalAndConnectionPoint()
|
1186 |
self.ui.imageView.command = RotateImageCommand.RotateImageCommand(self.ui.imageView) |
1187 |
self.guidelineStateChangedEvent(None) |
1188 |
|
1189 |
'''
|
1190 |
@brief Flip image left and right
|
1191 |
@author Jeongwoo
|
1192 |
@date 2018.06.11
|
1193 |
'''
|
1194 |
|
1195 |
def flipHorizontalClickEvent(self, event): |
1196 |
self.initOriginalAndConnectionPoint()
|
1197 |
self.ui.imageView.command = FlipImageCommand.FlipImageCommand(self.ui.imageView, horizontal=True, |
1198 |
vertical=False)
|
1199 |
self.guidelineStateChangedEvent(None) |
1200 |
|
1201 |
'''
|
1202 |
@brief Flip image up and down
|
1203 |
@author Jeongwoo
|
1204 |
@date 2018.06.11
|
1205 |
'''
|
1206 |
|
1207 |
def flipVerticalClickEvent(self, event): |
1208 |
self.initOriginalAndConnectionPoint()
|
1209 |
self.ui.imageView.command = FlipImageCommand.FlipImageCommand(self.ui.imageView, horizontal=False, |
1210 |
vertical=True)
|
1211 |
self.guidelineStateChangedEvent(None) |
1212 |
|
1213 |
'''
|
1214 |
def adjustOriginalPoint(self, adjustX, adjustY):
|
1215 |
originalPoint = self.ui.originalPointLineEdit.text()
|
1216 |
if originalPoint and self.ui.imageView.isOriginalPointSelected:
|
1217 |
x = float(originalPoint.split(",")[0])
|
1218 |
y = float(originalPoint.split(",")[1])
|
1219 |
OriginalPointCommand.OriginalPointCommand.removeCircle(self.ui.imageView, x, y)
|
1220 |
x = x - adjustX
|
1221 |
y = y - adjustY
|
1222 |
self.ui.originalPointLineEdit.setText(str(x)+","+str(y))
|
1223 |
OriginalPointCommand.OriginalPointCommand.drawCircle(self.ui.imageView, x, y)
|
1224 |
'''
|
1225 |
'''
|
1226 |
def adjustConnectionPoint(self, adjustX, adjustY):
|
1227 |
itemCount = self.ui.connectionPointList.count()
|
1228 |
for index in range(itemCount):
|
1229 |
item = self.ui.connectionPointList.item(index)
|
1230 |
text = item.text()
|
1231 |
x = float(text.split(",")[0])
|
1232 |
y = float(text.split(",")[1])
|
1233 |
self.removeConnectionPointCircle(QtCore.QPointF(x, y))
|
1234 |
x = x - adjustX
|
1235 |
y = y - adjustY
|
1236 |
item.setText(str(x)+","+str(y))
|
1237 |
ConnectionPointCommand.ConnectionPointCommand.drawCircle(self.ui.imageView, x, y, self.conn_index)
|
1238 |
self.conn_index += 1
|
1239 |
'''
|
1240 |
|
1241 |
'''
|
1242 |
@brief Validation Check
|
1243 |
@return (isValid, errorMsg)
|
1244 |
@history 2018.05.03 Jeongwoo Change self.dbHelper to AppDocData
|
1245 |
'''
|
1246 |
|
1247 |
def isValidSymbolInfo(self): |
1248 |
EXCEPTION_MSG_FORMAT = self.tr('{} Please check input data.') |
1249 |
EXCEPTION_MSG_DUPLICATED_FORMAT = self.tr('Already exist data {}.') |
1250 |
infoTitle = ""
|
1251 |
|
1252 |
if not self.ui.nameLineEdit.text() or self.ui.nameLineEdit.text().find('/') is not -1: |
1253 |
infoTitle = self.ui.nameLabel.text()
|
1254 |
return (False, EXCEPTION_MSG_FORMAT.format(infoTitle)) |
1255 |
|
1256 |
thresholdText = str(self.ui.spinBoxThreshold.value()) |
1257 |
threshold = float(thresholdText) if thresholdText else -1 |
1258 |
if not (0 <= threshold <= 100): |
1259 |
infoTitle = self.ui.thresholdLabel.text()
|
1260 |
return (False, EXCEPTION_MSG_FORMAT.format(infoTitle)) |
1261 |
|
1262 |
minMatchPointText = self.ui.minMatchPointLineEdit.text()
|
1263 |
minMatchPoint = float(minMatchPointText) if minMatchPointText else -1 |
1264 |
if not (minMatchPoint >= 0): |
1265 |
infoTitle = self.ui.minMatchPointLabel.text()
|
1266 |
return (False, EXCEPTION_MSG_FORMAT.format(infoTitle)) |
1267 |
|
1268 |
index = self.ui.treeViewSymbolCategory.currentIndex()
|
1269 |
if index == -1: |
1270 |
return (False, EXCEPTION_MSG_FORMAT.format('Symbol Type')) |
1271 |
|
1272 |
"""
|
1273 |
if self.ui.typeComboBox.currentIndex() == 0:
|
1274 |
infoTitle = self.ui.typeLabel.text()
|
1275 |
return (False, EXCEPTION_MSG_FORMAT.format(infoTitle))
|
1276 |
|
1277 |
if self.ui.baseSymbolComboBox.currentIndex() == 0: # default value(None) index
|
1278 |
infoTitle = self.ui.baseSymbolLabel.text()
|
1279 |
return (False, EXCEPTION_MSG_FORMAT.format(infoTitle))
|
1280 |
"""
|
1281 |
|
1282 |
# Additional Symbol is Nullable
|
1283 |
|
1284 |
if not self.ui.originalPointLineEdit.text() or self.ui.imageView.isOriginalPointSelected == False: |
1285 |
infoTitle = self.ui.originalPointLabel.text()
|
1286 |
return (False, EXCEPTION_MSG_FORMAT.format(infoTitle)) |
1287 |
|
1288 |
if self.ui.tableWidgetConnList.rowCount() > 1: |
1289 |
infoTitle = self.ui.connectionPointLabel.text()
|
1290 |
in_conn = False
|
1291 |
out_conn = False
|
1292 |
for index in range(self.ui.tableWidgetConnList.rowCount()): |
1293 |
if self.ui.tableWidgetConnList.cellWidget(index, 3).currentText() == 'In': |
1294 |
in_conn = True
|
1295 |
elif self.ui.tableWidgetConnList.cellWidget(index, 3).currentText() == 'Out': |
1296 |
out_conn = True
|
1297 |
if in_conn != out_conn:
|
1298 |
return (False, EXCEPTION_MSG_FORMAT.format(infoTitle)) |
1299 |
|
1300 |
return True, None |
1301 |
|
1302 |
'''
|
1303 |
@brief Slot for change offsets
|
1304 |
@author Jeongwoo
|
1305 |
@date 2018.05.02
|
1306 |
@history 2018.06.11 Jeongwoo Add refresh guideline
|
1307 |
'''
|
1308 |
|
1309 |
@pyqtSlot(float, float) |
1310 |
def offsetChanged(self, oX, oY): |
1311 |
# print('offsetX : ' + str(self.offsetX) + '->' + str(self.offsetX+oX))
|
1312 |
# print('offsetY : ' + str(self.offsetY) + '->' + str(self.offsetY+oY))
|
1313 |
self.offsetX = self.offsetX + oX |
1314 |
self.offsetY = self.offsetY + oY |
1315 |
self.guidelineStateChangedEvent(None) |