개정판 2f0e18ee
issue #505: improve zoom window function with control key(revised)
Change-Id: I722d24acf8d8b217831d35674a37d1308d028dbb
DTI_PID/DTI_PID/Commands/AreaZoomCommand.py | ||
---|---|---|
1 | 1 |
import os.path |
2 | 2 |
import AbstractCommand |
3 |
|
|
3 | 4 |
try: |
4 | 5 |
from PyQt5.QtCore import * |
5 | 6 |
from PyQt5.QtGui import * |
... | ... | |
13 | 14 |
|
14 | 15 |
from GraphicsBoundingBoxItem import QGraphicsBoundingBoxItem |
15 | 16 |
|
17 |
|
|
16 | 18 |
class AreaZoomCommand(AbstractCommand.AbstractCommand): |
17 | 19 |
onRejected = pyqtSignal(AbstractCommand.AbstractCommand) |
18 | 20 |
|
19 | 21 |
''' |
20 | 22 |
@history 2018.06.27 Jeongwoo Add variables [startPoint, endPoint] |
21 | 23 |
''' |
24 |
|
|
22 | 25 |
def __init__(self, imageViewer): |
23 | 26 |
super(AreaZoomCommand, self).__init__(imageViewer) |
24 |
self.name = 'AreaZoom'
|
|
27 |
self.name = 'AreaZoom' |
|
25 | 28 |
self.imageViewer.setCursor(QCursor(Qt.CrossCursor)) |
26 | 29 |
|
27 | 30 |
self._rubberBand = QRubberBand(QRubberBand.Rectangle, self.imageViewer) |
28 | 31 |
self._origin = QPoint() |
29 | 32 |
self.isLeftClicked = False |
30 |
|
|
33 |
|
|
31 | 34 |
''' |
32 | 35 |
@brief pan image by left click and drag |
33 | 36 |
@history 2018.06.27 Jeongwoo Add if-statement for panning after zoom in / Add variable [startPoint, endPoint] |
34 | 37 |
humkyung 2018.08.29 use rubberband to select area |
35 | 38 |
''' |
39 |
|
|
36 | 40 |
def execute(self, param): |
37 | 41 |
event = param[1] |
38 | 42 |
scenePos = param[2] |
39 |
|
|
43 |
|
|
40 | 44 |
self.isTreated = False |
41 | 45 |
if 'mousePressEvent' == param[0]: |
42 | 46 |
if event.button() == Qt.LeftButton: |
... | ... | |
45 | 49 |
self._origin = event.pos() |
46 | 50 |
self._rubberBand.setGeometry(QRect(self._origin, QSize())) |
47 | 51 |
self._rubberBand.show() |
48 |
|
|
52 |
|
|
49 | 53 |
self.imageViewer.leftMouseButtonPressed.emit(scenePos.x(), scenePos.y()) |
50 | 54 |
elif 'mouseMoveEvent' == param[0] and event.buttons() == Qt.LeftButton: |
51 | 55 |
if self._rubberBand.isVisible(): |
... | ... | |
58 | 62 |
self._rubberBand.hide() |
59 | 63 |
topLeft = self.imageViewer.mapToScene(self._rubberBand.geometry().topLeft()) |
60 | 64 |
bottomRight = self.imageViewer.mapToScene(self._rubberBand.geometry().bottomRight()) |
61 |
self.imageViewer.zoomStack.append(QRectF(topLeft.x(), topLeft.y(), bottomRight.x() - topLeft.x(), bottomRight.y() - topLeft.y())) |
|
62 |
self.imageViewer.updateViewer() |
|
63 |
elif event.button() == Qt.RightButton: |
|
64 |
if self.isLeftClicked == False: |
|
65 |
rect = QRectF(topLeft.x(), topLeft.y(), |
|
66 |
bottomRight.x() - topLeft.x(), bottomRight.y() - topLeft.y()) |
|
67 |
self.imageViewer.updateViewer(rect) |
|
68 |
elif Qt.RightButton == event.button(): |
|
69 |
if not self.isLeftClicked: |
|
65 | 70 |
self.onRejected.emit(self) |
66 | 71 |
finally: |
67 | 72 |
pass |
... | ... | |
73 | 78 |
|
74 | 79 |
def redo(self): |
75 | 80 |
pass |
76 |
|
|
77 |
def zoomImageInit(self): |
|
78 |
if self.imageViewer.hasImage(): |
|
79 |
self.imageViewer.zoomStack = [] |
|
80 |
self.imageViewer.updateViewer() |
|
81 |
|
|
82 |
def zoomImage(self, isZoomIn, pos): |
|
83 |
""" Zoom in & out |
|
84 |
""" |
|
85 |
scenePos1 = self.imageViewer.mapToScene(pos.x() - 300, pos.y() - 300) |
|
86 |
scenePos2 = self.imageViewer.mapToScene(pos.x() + 300, pos.y() + 300) |
|
87 |
if isZoomIn: |
|
88 |
zoomArea = QRectF(QPointF(scenePos1.x(), scenePos1.y()), QPointF(scenePos2.x(), scenePos2.y())) |
|
89 |
viewBBox = self.imageViewer.zoomStack[-1] if len(self.imageViewer.zoomStack) else self.imageViewer.sceneRect() |
|
90 |
selectionBBox = zoomArea.intersected(viewBBox) |
|
91 |
self.imageViewer.scene.setSelectionArea(QPainterPath()) # Clear current selection area. |
|
92 |
if selectionBBox.isValid() and (selectionBBox != viewBBox): |
|
93 |
self.imageViewer.zoomStack.append(selectionBBox) |
|
94 |
self.imageViewer.updateViewer() |
|
95 |
else: |
|
96 |
self.imageViewer.scene.setSelectionArea(QPainterPath()) # Clear current selection area. |
|
97 |
if len(self.imageViewer.zoomStack): |
|
98 |
self.imageViewer.zoomStack.pop() |
|
99 |
self.imageViewer.updateViewer() |
DTI_PID/DTI_PID/Commands/HighlightCommand.py | ||
---|---|---|
1 | 1 |
import os.path |
2 | 2 |
import AbstractCommand |
3 |
|
|
3 | 4 |
try: |
4 | 5 |
from PyQt5.QtCore import * |
5 | 6 |
from PyQt5.QtGui import * |
... | ... | |
13 | 14 |
|
14 | 15 |
from GraphicsBoundingBoxItem import QGraphicsBoundingBoxItem |
15 | 16 |
|
17 |
|
|
16 | 18 |
class HighlightCommand(AbstractCommand.AbstractCommand): |
17 | 19 |
onSuccess = pyqtSignal(float, float, float, float) |
18 | 20 |
|
19 | 21 |
def __init__(self, imageViewer): |
20 | 22 |
super(HighlightCommand, self).__init__(imageViewer) |
21 |
self.name = 'Highlight'
|
|
22 |
|
|
23 |
self.name = 'Highlight' |
|
24 |
|
|
23 | 25 |
''' |
24 | 26 |
@brief highlight items selected by user |
25 | 27 |
''' |
28 |
|
|
26 | 29 |
def execute(self, param): |
27 | 30 |
from EngineeringRunItem import QEngineeringRunItem |
28 | 31 |
from SymbolSvgItem import SymbolSvgItem |
... | ... | |
30 | 33 |
from EngineeringLineNoTextItem import QEngineeringLineNoTextItem |
31 | 34 |
|
32 | 35 |
self.isTreated = False |
33 |
|
|
36 |
FIT_WINDOW_SIZE = 300 |
|
37 |
|
|
34 | 38 |
if param is not None: |
35 | 39 |
if type(param) is QEngineeringRunItem: |
36 | 40 |
rect = None |
... | ... | |
40 | 44 |
|
41 | 45 |
if rect is not None: |
42 | 46 |
self.imageViewer.centerOn(rect.center()) |
43 |
## Send new event to imageViewer's zoomImage Method |
|
44 |
self.imageViewer.zoomImage(True, QMouseEvent(QEvent.MouseButtonPress, self.imageViewer.mapFromScene(QPointF(rect.left(), rect.top())), Qt.LeftButton, Qt.LeftButton, Qt.NoModifier), 3) |
|
47 |
|
|
48 |
rect.translate(-FIT_WINDOW_SIZE, -FIT_WINDOW_SIZE) |
|
49 |
rect.setWidth(rect.width() + FIT_WINDOW_SIZE * 2) |
|
50 |
rect.setHeight(rect.height() + FIT_WINDOW_SIZE * 2) |
|
51 |
topLeft = rect.topLeft() |
|
52 |
bottomRight = rect.bottomRight() |
|
53 |
self.imageViewer.scene.clearSelection() |
|
54 |
self.imageViewer.updateViewer(QRectF(topLeft.x(), topLeft.y(), bottomRight.x() - topLeft.x(), |
|
55 |
bottomRight.y() - topLeft.y())) |
|
45 | 56 |
|
46 | 57 |
for item in param.items: |
47 | 58 |
item.setSelected(True) |
... | ... | |
54 | 65 |
|
55 | 66 |
if rect is not None: |
56 | 67 |
self.imageViewer.centerOn(rect.center()) |
57 |
## Send new event to imageViewer's zoomImage Method |
|
58 |
self.imageViewer.zoomImage(True, QMouseEvent(QEvent.MouseButtonPress, self.imageViewer.mapFromScene(QPointF(rect.left(), rect.top())), Qt.LeftButton, Qt.LeftButton, Qt.NoModifier), 3) |
|
59 |
if len(param) > 1: self.imageViewer.fitInView(rect, Qt.KeepAspectRatio) |
|
68 |
|
|
69 |
rect.translate(-FIT_WINDOW_SIZE, -FIT_WINDOW_SIZE) |
|
70 |
rect.setWidth(rect.width() + FIT_WINDOW_SIZE * 2) |
|
71 |
rect.setHeight(rect.height() + FIT_WINDOW_SIZE * 2) |
|
72 |
topLeft = rect.topLeft() |
|
73 |
bottomRight = rect.bottomRight() |
|
74 |
self.imageViewer.scene.clearSelection() |
|
75 |
self.imageViewer.updateViewer(QRectF(topLeft.x(), topLeft.y(), bottomRight.x() - topLeft.x(), |
|
76 |
bottomRight.y() - topLeft.y())) |
|
60 | 77 |
|
61 | 78 |
for item in param: |
62 | 79 |
if item.symbol: |
... | ... | |
68 | 85 |
else: |
69 | 86 |
rect = param.sceneBoundingRect() |
70 | 87 |
self.imageViewer.centerOn(rect.center()) |
71 |
## Send new event to imageViewer's zoomImage Method |
|
72 |
#self.imageViewer.fitInView(rect, Qt.KeepAspectRatio) |
|
73 |
self.imageViewer.zoomImage(True, QMouseEvent(QEvent.MouseButtonPress, self.imageViewer.mapFromScene(QPointF(rect.left(), rect.top())), Qt.LeftButton, Qt.LeftButton, Qt.NoModifier), 3) |
|
88 |
|
|
89 |
rect.translate(-FIT_WINDOW_SIZE, -FIT_WINDOW_SIZE) |
|
90 |
rect.setWidth(rect.width() + FIT_WINDOW_SIZE*2) |
|
91 |
rect.setHeight(rect.height() + FIT_WINDOW_SIZE*2) |
|
92 |
topLeft = rect.topLeft() |
|
93 |
bottomRight = rect.bottomRight() |
|
94 |
self.imageViewer.scene.clearSelection() |
|
95 |
self.imageViewer.updateViewer(QRectF(topLeft.x(), topLeft.y(), bottomRight.x() - topLeft.x(), |
|
96 |
bottomRight.y() - topLeft.y())) |
|
74 | 97 |
|
75 | 98 |
param.setSelected(True) |
76 | 99 |
param.update() |
77 |
|
|
100 |
|
|
78 | 101 |
if type(param) is QEngineeringLineNoTextItem: |
79 | 102 |
for run in param.runs: |
80 | 103 |
for item in run.items: |
... | ... | |
85 | 108 |
pass |
86 | 109 |
|
87 | 110 |
def redo(self): |
88 |
pass |
|
111 |
pass |
DTI_PID/DTI_PID/ItemTreeWidget.py | ||
---|---|---|
31 | 31 |
from AppDocData import AppDocData |
32 | 32 |
from Drawing import Drawing |
33 | 33 |
|
34 |
|
|
34 | 35 |
class CustomTreeWidgetItem(QTreeWidgetItem): |
35 | 36 |
def __init__(self, *args, **kwargs): |
36 | 37 |
super(CustomTreeWidgetItem, self).__init__(*args, **kwargs) |
... | ... | |
45 | 46 |
|
46 | 47 |
super(CustomTreeWidgetItem, self).setData(column, role, value) |
47 | 48 |
|
49 |
|
|
48 | 50 |
class QItemTreeWidget(QTreeWidget): |
49 | 51 |
""" This is item tree widget """ |
50 | 52 |
TREE_DATA_ROLE = Qt.UserRole |
51 | 53 |
|
52 |
#Add Signal |
|
54 |
# Add Signal
|
|
53 | 55 |
singleClicked = pyqtSignal(SymbolSvgItem) |
54 | 56 |
noteNoSingleClicked = pyqtSignal(str, dict) |
55 | 57 |
lineNoSingleClicked = pyqtSignal(QEngineeringAbstractItem) |
... | ... | |
59 | 61 |
''' |
60 | 62 |
@history 2018.05.11 Jeongwoo Add Context Menu settings |
61 | 63 |
''' |
64 |
|
|
62 | 65 |
def __init__(self, imageViewer): |
63 | 66 |
QTreeWidget.__init__(self) |
64 | 67 |
|
... | ... | |
76 | 79 |
@author humkyung |
77 | 80 |
@date 2018.07.20 |
78 | 81 |
''' |
82 |
|
|
79 | 83 |
def keyPressEvent(self, event): |
80 | 84 |
try: |
81 | 85 |
if event.key() == Qt.Key_Delete: |
... | ... | |
84 | 88 |
data = item.data(0, self.TREE_DATA_ROLE) |
85 | 89 |
if data is not None: |
86 | 90 |
data.transfer.onRemoved.emit(data) |
87 |
#self.imageViewer.scene.removeItem(data) |
|
91 |
# self.imageViewer.scene.removeItem(data)
|
|
88 | 92 |
|
89 |
#if type(data) is QEngineeringLineNoTextItem: |
|
93 |
# if type(data) is QEngineeringLineNoTextItem:
|
|
90 | 94 |
# self.imageViewer.mainWindow.removedItems['LINE'].append(str(data.uid)) |
91 |
#elif type(data) is QEngineeringInstrumentItem: |
|
95 |
# elif type(data) is QEngineeringInstrumentItem:
|
|
92 | 96 |
# self.imageViewer.mainWindow.removedItems['INST'].append(str(data.uid)) |
93 |
#elif type(data) is QEngineeringEquipmentItem: |
|
97 |
# elif type(data) is QEngineeringEquipmentItem:
|
|
94 | 98 |
# self.imageViewer.mainWindow.removedItems['EQUIP'].append(str(data.uid)) |
95 |
#elif type(data) is QEngineeringNoteItem: |
|
99 |
# elif type(data) is QEngineeringNoteItem:
|
|
96 | 100 |
# self.imageViewer.mainWindow.removedItems['NOTE'].append(str(data.uid)) |
97 | 101 |
|
98 |
#item.parent().removeChild(item) |
|
102 |
# item.parent().removeChild(item)
|
|
99 | 103 |
event.accept() |
100 | 104 |
elif event.key() == Qt.Key_Up: |
101 | 105 |
if self.selectedItems(): |
... | ... | |
118 | 122 |
else: |
119 | 123 |
event.ignore() |
120 | 124 |
except Exception as ex: |
121 |
print('error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno)) |
|
122 |
|
|
125 |
print('error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, |
|
126 |
sys.exc_info()[-1].tb_lineno)) |
|
127 |
|
|
123 | 128 |
''' |
124 | 129 |
@brief Show Context Menu |
125 | 130 |
@author Jeongwoo |
... | ... | |
127 | 132 |
@history 18.06.14 Jeongwoo Add item None check |
128 | 133 |
humkyung 2018.06.27 add menu of run item for selecting line type |
129 | 134 |
''' |
135 |
|
|
130 | 136 |
def openContextMenu(self, position): |
131 | 137 |
from EngineeringRunItem import QEngineeringRunItem |
132 | 138 |
|
... | ... | |
137 | 143 |
if item is self.LineNoTreeItem: |
138 | 144 |
menu = QMenu() |
139 | 145 |
explode_action = QAction(self.tr("Explode")) |
140 |
explode_action.triggered.connect(lambda : self.explode_all_line_nos(item))
|
|
146 |
explode_action.triggered.connect(lambda: self.explode_all_line_nos(item)) |
|
141 | 147 |
menu.addAction(explode_action) |
142 | 148 |
explodeKeepFromTo_action = QAction(self.tr("Explode (keep from, to)")) |
143 |
explodeKeepFromTo_action.triggered.connect(lambda : self.explode_all_line_nos(item, True))
|
|
149 |
explodeKeepFromTo_action.triggered.connect(lambda: self.explode_all_line_nos(item, True)) |
|
144 | 150 |
menu.addAction(explodeKeepFromTo_action) |
145 | 151 |
menu.exec_(self.viewport().mapToGlobal(position)) |
146 | 152 |
else: |
... | ... | |
148 | 154 |
if len(indexes) > 0 and data is not None and issubclass(type(data), QEngineeringLineNoTextItem): |
149 | 155 |
menu = QMenu() |
150 | 156 |
pickColorAction = QAction(self.tr("Select Line Color")) |
151 |
pickColorAction.triggered.connect(lambda : self.pickColorClickEvent(item))
|
|
157 |
pickColorAction.triggered.connect(lambda: self.pickColorClickEvent(item)) |
|
152 | 158 |
menu.addAction(pickColorAction) |
153 | 159 |
explode_action = QAction(self.tr("Explode")) |
154 | 160 |
freeze = data.prop('Freeze') |
155 | 161 |
explode_action.setEnabled(not freeze) |
156 |
explode_action.triggered.connect(lambda : self.explode_line_no(item))
|
|
162 |
explode_action.triggered.connect(lambda: self.explode_line_no(item)) |
|
157 | 163 |
menu.addAction(explode_action) |
158 | 164 |
if type(data) is QEngineeringLineNoTextItem: |
159 | 165 |
explodeKeepFromTo_action = QAction(self.tr("Explode (keep from, to)")) |
160 | 166 |
explodeKeepFromTo_action.setEnabled(not freeze) |
161 |
explodeKeepFromTo_action.triggered.connect(lambda : self.explode_line_no(item, True))
|
|
167 |
explodeKeepFromTo_action.triggered.connect(lambda: self.explode_line_no(item, True)) |
|
162 | 168 |
menu.addAction(explodeKeepFromTo_action) |
163 | 169 |
reverse_flow_action = QAction(self.tr("Reverse Flow")) |
164 |
reverse_flow_action.triggered.connect(lambda : self.reverse_line_flow(item))
|
|
170 |
reverse_flow_action.triggered.connect(lambda: self.reverse_line_flow(item)) |
|
165 | 171 |
menu.addAction(reverse_flow_action) |
166 | 172 |
menu.exec_(self.viewport().mapToGlobal(position)) |
167 | 173 |
elif len(indexes) > 0 and data is not None and issubclass(type(data), QEngineeringRunItem): |
168 | 174 |
menu = QMenu() |
169 | 175 |
lineTypeAction = QAction(self.tr("Select Line Type")) |
170 |
lineTypeAction.triggered.connect(lambda : self.lineTypeClickEvent(item))
|
|
176 |
lineTypeAction.triggered.connect(lambda: self.lineTypeClickEvent(item)) |
|
171 | 177 |
menu.addAction(lineTypeAction) |
172 | 178 |
line_no = item.parent().data(0, self.TREE_DATA_ROLE) |
173 | 179 |
freeze = line_no.prop('Freeze') |
174 | 180 |
explode_action = QAction(self.tr("Explode")) |
175 | 181 |
explode_action.setEnabled(not freeze) |
176 |
explode_action.triggered.connect(lambda : self.explode_line_run(item))
|
|
182 |
explode_action.triggered.connect(lambda: self.explode_line_run(item)) |
|
177 | 183 |
menu.addAction(explode_action) |
178 | 184 |
reverse_flow_action = QAction(self.tr("Reverse Flow")) |
179 |
reverse_flow_action.triggered.connect(lambda : self.reverse_line_flow(item))
|
|
185 |
reverse_flow_action.triggered.connect(lambda: self.reverse_line_flow(item)) |
|
180 | 186 |
menu.addAction(reverse_flow_action) |
181 | 187 |
menu.exec_(self.viewport().mapToGlobal(position)) |
182 | 188 |
|
183 | 189 |
self.SymbolsTreeItem.sortChildren(0, Qt.AscendingOrder) |
184 |
self.EqpTreeItem.sortChildren(0, Qt.AscendingOrder)
|
|
190 |
self.EqpTreeItem.sortChildren(0, Qt.AscendingOrder) |
|
185 | 191 |
|
186 | 192 |
''' |
187 | 193 |
@brief Pick Color for Line No |
... | ... | |
189 | 195 |
@date 18.05.11 |
190 | 196 |
@history 18.05.14 Jeongwoo Change method to change color by changeTreeWidgetItemColorRecursively() |
191 | 197 |
''' |
198 |
|
|
192 | 199 |
def pickColorClickEvent(self, lineNoTreeWidgetItem): |
193 |
color = QColorDialog.getColor() # Dialog returns QColor |
|
194 |
|
|
200 |
color = QColorDialog.getColor() # Dialog returns QColor
|
|
201 |
|
|
195 | 202 |
if color is not None: |
196 | 203 |
lineNoTreeWidgetItem.setForeground(0, QBrush(color)) |
197 | 204 |
lineNoTreeWidgetItem.setFont(0, lineNoTreeWidgetItem.font(0)) |
... | ... | |
227 | 234 |
from EngineeringLineNoTextItem import QEngineeringLineNoTextItem |
228 | 235 |
|
229 | 236 |
for i in reversed(range(self.LineNoTreeItem.childCount())): |
230 |
if not self.LineNoTreeItem.child(i).data(0, self.TREE_DATA_ROLE).prop('Freeze'): |
|
231 |
self.explode_line_no(self.LineNoTreeItem.child(i), remainFromTo) |
|
237 |
if not self.LineNoTreeItem.child(i).data(0, self.TREE_DATA_ROLE).prop('Freeze'): |
|
238 |
self.explode_line_no(self.LineNoTreeItem.child(i), remainFromTo) |
|
239 |
|
|
240 |
# for item in [item for item in self.scene.items() if hasattr(item, 'owner') |
|
232 | 241 |
|
233 |
#for item in [item for item in self.scene.items() if hasattr(item, 'owner') |
|
234 |
|
|
235 | 242 |
def reverse_line_flow(self, lineTreeWidgetItem): |
236 | 243 |
""" reverse line flow """ |
237 | 244 |
|
... | ... | |
264 | 271 |
@author humkyung |
265 | 272 |
@date 2018.06.27 |
266 | 273 |
''' |
274 |
|
|
267 | 275 |
def lineTypeClickEvent(self, item): |
268 | 276 |
pass |
269 | 277 |
|
... | ... | |
272 | 280 |
@author Jeongwoo |
273 | 281 |
@date 18.05.14 |
274 | 282 |
''' |
283 |
|
|
275 | 284 |
def changeTreeWidgetItemColorRecursively(self, item, color): |
276 | 285 |
for index in range(item.childCount()): |
277 | 286 |
child = item.child(index) |
... | ... | |
287 | 296 |
2018.05.09 Jeongwoo Change method to add default tree items |
288 | 297 |
humkyung 2018.06.10 add tree item for Line No and Unknown Item |
289 | 298 |
''' |
299 |
|
|
290 | 300 |
def setCurrentPID(self, drawingName): |
291 | 301 |
appDocData = AppDocData.instance() |
292 | 302 |
|
... | ... | |
317 | 327 |
@date 2018.05.15 |
318 | 328 |
@history 2018.05.17 Jeongwoo Change run item color with parent(LineNo Item) color |
319 | 329 |
''' |
330 |
|
|
320 | 331 |
def addPipeRunTreeItemIfNeed(self, lineNoTreeItem, pipeRun): |
321 | 332 |
for index in range(lineNoTreeItem.childCount()): |
322 | 333 |
treeItem = lineNoTreeItem.child(index) |
... | ... | |
324 | 335 |
if itemData is not None and itemData == pipeRun: |
325 | 336 |
return treeItem |
326 | 337 |
|
327 |
runItem = QTreeWidgetItem(['RUNS {}'.format(lineNoTreeItem.childCount()+1)])
|
|
338 |
runItem = QTreeWidgetItem(['RUNS {}'.format(lineNoTreeItem.childCount() + 1)])
|
|
328 | 339 |
runItem.setData(0, self.TREE_DATA_ROLE, pipeRun) |
329 | 340 |
|
330 | 341 |
brush = lineNoTreeItem.foreground(0) |
... | ... | |
349 | 360 |
humkyung 2018.06.12 add unknown item |
350 | 361 |
humkyung 2018.07.20 append nozzle to equipment |
351 | 362 |
''' |
363 |
|
|
352 | 364 |
def addTreeItem(self, parent, child): |
353 | 365 |
item = None |
354 | 366 |
appDocData = AppDocData.instance() |
... | ... | |
360 | 372 |
if isEquipmentType: |
361 | 373 |
item = QTreeWidgetItem(self.EqpTreeItem, [child.name]) |
362 | 374 |
item.setData(0, self.TREE_DATA_ROLE, child) |
363 |
#elif child.type == 'Nozzles':
|
|
364 |
# for i in range(self.EqpTreeItem.childCount()): |
|
365 |
# eqpTreeItem = eqpRootTreeItem[0].child(i) |
|
366 |
# eqpSymbol = eqpTreeItem.data(0, self.TREE_DATA_ROLE) |
|
367 |
# if child.owner is eqpSymbol: |
|
368 |
# item = QTreeWidgetItem(eqpTreeItem, [child.name]) |
|
369 |
# item.setData(0, self.TREE_DATA_ROLE, child) |
|
370 |
# break |
|
371 |
|
|
375 |
# elif child.type == 'Nozzles':
|
|
376 |
# for i in range(self.EqpTreeItem.childCount()):
|
|
377 |
# eqpTreeItem = eqpRootTreeItem[0].child(i)
|
|
378 |
# eqpSymbol = eqpTreeItem.data(0, self.TREE_DATA_ROLE)
|
|
379 |
# if child.owner is eqpSymbol:
|
|
380 |
# item = QTreeWidgetItem(eqpTreeItem, [child.name])
|
|
381 |
# item.setData(0, self.TREE_DATA_ROLE, child)
|
|
382 |
# break
|
|
383 |
|
|
372 | 384 |
if item is None: |
373 | 385 |
item = QTreeWidgetItem(self.SymbolsTreeItem, [child.name]) |
374 | 386 |
elif child.type == 'Notes': |
... | ... | |
376 | 388 |
return item |
377 | 389 |
else: |
378 | 390 |
item = QTreeWidgetItem(self.SymbolsTreeItem, [child.name]) |
379 |
|
|
391 |
|
|
380 | 392 |
if item is not None: |
381 |
iconPath = os.path.join(AppDocData.instance().getCurrentProject().getSvgFilePath(), child.type , child.name + ".svg") |
|
393 |
iconPath = os.path.join(AppDocData.instance().getCurrentProject().getSvgFilePath(), child.type, |
|
394 |
child.name + ".svg") |
|
382 | 395 |
item.setIcon(0, QIcon(iconPath)) |
383 | 396 |
item.setData(0, self.TREE_DATA_ROLE, child) |
384 | 397 |
brush = QBrush() |
... | ... | |
394 | 407 |
self.SymbolsTreeItem.sortChildren(0, Qt.AscendingOrder) # sort childrens |
395 | 408 |
elif type(child) is QEngineeringLineNoTextItem: |
396 | 409 |
for index in range(self.LineNoTreeItem.childCount()): |
397 |
if child.text() == self.LineNoTreeItem.child(0).text(index) and self.LineNoTreeItem.child(0).childCount() is 0: |
|
410 |
if child.text() == self.LineNoTreeItem.child(0).text(index) and self.LineNoTreeItem.child( |
|
411 |
0).childCount() is 0: |
|
398 | 412 |
self.LineNoTreeItem.takeChild(index) |
399 | 413 |
break |
400 | 414 |
item = CustomTreeWidgetItem([child.text().replace('\n', '')]) |
... | ... | |
440 | 454 |
|
441 | 455 |
# show note icon if note icon is setted |
442 | 456 |
if child.symbol: |
443 |
iconPath = os.path.join(appDocData.getCurrentProject().getSvgFilePath(), 'Notes' , child.symbol.name + '.svg') |
|
457 |
iconPath = os.path.join(appDocData.getCurrentProject().getSvgFilePath(), 'Notes', |
|
458 |
child.symbol.name + '.svg') |
|
444 | 459 |
item.setIcon(0, QIcon(iconPath)) |
445 | 460 |
elif (type(child) is QEngineeringUnknownItem): |
446 | 461 |
item = QTreeWidgetItem(['Unknown']) |
... | ... | |
450 | 465 |
if child.lineIndicator == 'Match': |
451 | 466 |
item.setHidden(True) |
452 | 467 |
elif issubclass(type(child), SymbolSvgItem): # change item's parent |
453 |
foundItems = self.findItems(child.name, Qt.MatchExactly|Qt.MatchRecursive, 0)
|
|
468 |
foundItems = self.findItems(child.name, Qt.MatchExactly | Qt.MatchRecursive, 0)
|
|
454 | 469 |
if foundItems is not None: |
455 | 470 |
for item in foundItems: |
456 | 471 |
data = item.data(0, self.TREE_DATA_ROLE) |
... | ... | |
460 | 475 |
for index in range(len(parentData.runs)): |
461 | 476 |
runGroup = parentData.runs[index] |
462 | 477 |
if data in runGroup.items: |
463 |
item.parent().removeChild(item) # remove item from original parent |
|
464 |
runItem = self.addPipeRunTreeItemIfNeed(parent, runGroup) #parent.child(index)
|
|
478 |
item.parent().removeChild(item) # remove item from original parent
|
|
479 |
runItem = self.addPipeRunTreeItemIfNeed(parent, runGroup) # parent.child(index)
|
|
465 | 480 |
brush = QBrush() |
466 | 481 |
brush.setColor(QColor(item.data(0, self.TREE_DATA_ROLE).getColor())) |
467 | 482 |
item.setForeground(0, brush) |
468 |
#item.data(0, self.TREE_DATA_ROLE).setColor(brush.color().name()) |
|
483 |
# item.data(0, self.TREE_DATA_ROLE).setColor(brush.color().name())
|
|
469 | 484 |
item.setFont(0, item.font(0)) |
470 | 485 |
runItem.addChild(item) |
471 | 486 |
break |
472 | 487 |
else: |
473 | 488 |
pass |
474 | 489 |
elif parent is not None: |
475 |
item.parent().removeChild(item) # remove item from original parent |
|
490 |
item.parent().removeChild(item) # remove item from original parent
|
|
476 | 491 |
parent.addChild(item) |
477 | 492 |
break |
478 | 493 |
elif type(child) is QEngineeringLineNoTextItem: |
479 |
foundItems = self.findItems(child.text(), Qt.MatchExactly|Qt.MatchRecursive, 0)
|
|
494 |
foundItems = self.findItems(child.text(), Qt.MatchExactly | Qt.MatchRecursive, 0)
|
|
480 | 495 |
if foundItems is not None: |
481 | 496 |
for item in foundItems: |
482 | 497 |
data = item.data(0, self.TREE_DATA_ROLE) |
... | ... | |
490 | 505 |
from App import App |
491 | 506 |
from AppDocData import MessageType |
492 | 507 |
|
493 |
message = 'error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno) |
|
508 |
message = 'error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, |
|
509 |
sys.exc_info()[-1].tb_lineno) |
|
494 | 510 |
App.mainWnd().addMessage.emit(MessageType.Error, message) |
495 | 511 |
|
496 | 512 |
return item |
... | ... | |
504 | 520 |
humkyung 2018.07.20 put items which's owner is None before item which's owner is not None |
505 | 521 |
''' |
506 | 522 |
lastSceneItems = None |
523 |
|
|
507 | 524 |
def sceneChanged(self, sceneItems): |
508 | 525 |
try: |
509 |
changedSceneItems = [item for item in sceneItems if ((issubclass(type(item), SymbolSvgItem) and type(item) is not QEngineeringErrorItem and type(item) is not QEngineeringEndBreakItem and type(item) is not QEngineeringFlowMarkItem) or (type(item) is QEngineeringNoteItem) or (type(item) is QEngineeringLineNoTextItem) |
|
510 |
or (type(item) is QEngineeringUnknownItem)) and (not hasattr(item, 'treeItem') or item.treeItem is None)] # Sublist includes SymbolSvgItem |
|
526 |
changedSceneItems = [item for item in sceneItems if ((issubclass(type(item), SymbolSvgItem) and type( |
|
527 |
item) is not QEngineeringErrorItem and type(item) is not QEngineeringEndBreakItem and type( |
|
528 |
item) is not QEngineeringFlowMarkItem) or (type(item) is QEngineeringNoteItem) or ( |
|
529 |
type(item) is QEngineeringLineNoTextItem) |
|
530 |
or (type(item) is QEngineeringUnknownItem)) and ( |
|
531 |
not hasattr(item, |
|
532 |
'treeItem') or item.treeItem is None)] # Sublist includes SymbolSvgItem |
|
511 | 533 |
first = [item for item in changedSceneItems if item.owner is None] |
512 | 534 |
second = [item for item in changedSceneItems if item.owner is not None] |
513 | 535 |
if first + second: self.initResultTreeWidget(first + second) |
... | ... | |
524 | 546 |
2018.04.25 Jeongwoo Add QEngineeringNoteItem Child |
525 | 547 |
2018.04.26 Jeongwoo Change method to insert child |
526 | 548 |
''' |
549 |
|
|
527 | 550 |
def initResultTreeWidget(self, items): |
528 | 551 |
for item in items: |
529 | 552 |
if (type(item) is QEngineeringNoteItem): |
530 | 553 |
self.addTreeItem(self.NotesTreeItem, item) |
531 | 554 |
else: |
532 | 555 |
self.addTreeItem(self.root, item) |
533 |
|
|
556 |
|
|
534 | 557 |
if self.NotesTreeItem is not None: |
535 | 558 |
self.NotesTreeItem.sortChildren(0, Qt.AscendingOrder) |
536 | 559 |
|
537 | 560 |
self.expandAll() |
538 |
|
|
561 |
|
|
539 | 562 |
def itemCheckBoxToggled(self, item, checkState): |
540 | 563 |
""" |
541 | 564 |
set visible of invisible of item |
542 | 565 |
""" |
543 | 566 |
try: |
544 |
itemData = item.data(0, self.TREE_DATA_ROLE)
|
|
567 |
itemData = item.data(0, self.TREE_DATA_ROLE) |
|
545 | 568 |
if (type(itemData) is QEngineeringLineNoTextItem) or (type(itemData) is QEngineeringTrimLineNoTextItem): |
546 | 569 |
itemData.setVisible(checkState == Qt.CheckState.Checked) |
547 | 570 |
except Exception as ex: |
548 | 571 |
from App import App |
549 | 572 |
from AppDocData import MessageType |
550 | 573 |
|
551 |
message = 'error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno) |
|
574 |
message = 'error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, |
|
575 |
sys.exc_info()[-1].tb_lineno) |
|
552 | 576 |
App.mainWnd().addMessage.emit(MessageType.Error, message) |
553 | 577 |
finally: |
554 | 578 |
pass |
... | ... | |
567 | 591 |
18.05.10 Jeongwoo Add lineNoSingleClicked emit |
568 | 592 |
humkyung 2018.07.07 emit singleClicked signal when user click drawing name |
569 | 593 |
''' |
570 |
def itemClickEvent(self, item, columnNo, isSvgClick = False): |
|
594 |
|
|
595 |
def itemClickEvent(self, item, columnNo, isSvgClick=False): |
|
571 | 596 |
from Drawing import Drawing |
572 | 597 |
from EngineeringRunItem import QEngineeringRunItem |
573 | 598 |
from HighlightCommand import HighlightCommand |
... | ... | |
575 | 600 |
hilightColor = QColor(255, 0, 0, 127) |
576 | 601 |
|
577 | 602 |
itemData = item.data(0, self.TREE_DATA_ROLE) |
578 |
|
|
579 |
if itemData is not None: ## Not PID Name |
|
603 |
|
|
604 |
if itemData is not None: ## Not PID Name
|
|
580 | 605 |
if issubclass(type(itemData), SymbolSvgItem): |
581 | 606 |
HighlightCommand(self.imageViewer).execute(itemData) |
582 | 607 |
## Draw rectangle on selected symbol |
583 |
#rect = itemData.sceneBoundingRect() |
|
584 |
#if isSvgClick == False: |
|
608 |
# rect = itemData.sceneBoundingRect()
|
|
609 |
# if isSvgClick == False:
|
|
585 | 610 |
# self.imageViewer.centerOn(rect.center()) |
586 | 611 |
## Send new event to imageViewer's zoomImage Method |
587 |
#self.imageViewer.zoomImage(True, QMouseEvent(QEvent.MouseButtonPress, self.imageViewer.mapFromScene(QPointF(rect.left(), rect.top())), Qt.LeftButton, Qt.LeftButton, Qt.NoModifier), 3) |
|
612 |
# self.imageViewer.zoomImage(True, QMouseEvent(QEvent.MouseButtonPress, self.imageViewer.mapFromScene(QPointF(rect.left(), rect.top())), Qt.LeftButton, Qt.LeftButton, Qt.NoModifier), 3)
|
|
588 | 613 |
|
589 |
#self.singleClicked.emit(itemData) |
|
614 |
# self.singleClicked.emit(itemData)
|
|
590 | 615 |
elif type(itemData) is QEngineeringRunItem: |
591 | 616 |
HighlightCommand(self.imageViewer).execute(itemData) |
592 | 617 |
self.lineNoSingleClicked.emit(itemData) |
... | ... | |
594 | 619 |
item.child(child).setSelected(True) |
595 | 620 |
elif type(itemData) is QEngineeringLineNoTextItem: |
596 | 621 |
HighlightCommand(self.imageViewer).execute(itemData) |
597 |
#self.lineNoSingleClicked.emit(itemData) |
|
622 |
# self.lineNoSingleClicked.emit(itemData)
|
|
598 | 623 |
itemData.setSelected(True) |
599 |
#for child in range(item.childCount()): |
|
624 |
# for child in range(item.childCount()):
|
|
600 | 625 |
# for cchild in range(item.child(child).childCount()): |
601 | 626 |
# item.child(child).child(cchild).setSelected(True) |
602 | 627 |
elif type(itemData) is list and type(itemData[0]) is QEngineeringNoteItem: |
... | ... | |
615 | 640 |
HighlightCommand(self.imageViewer).execute(itemData) |
616 | 641 |
elif type(itemData) is Drawing: |
617 | 642 |
self.drawingClicked.emit(itemData) |
618 |
|
|
643 |
|
|
619 | 644 |
''' |
620 | 645 |
if issubclass(type(itemData), QGraphicsItem): |
621 | 646 |
itemData.setSelected(True) |
... | ... | |
629 | 654 |
@history 2018.06.18 Jeongwoo Add if-statement for QEngineeringUnknownItem |
630 | 655 |
@history 2018.11.22 euisung add delete note |
631 | 656 |
''' |
657 |
|
|
632 | 658 |
def findItemByData(self, item): |
633 | 659 |
if issubclass(type(item), SymbolSvgItem): |
634 |
foundItems = self.findItems(item.name, Qt.MatchExactly|Qt.MatchRecursive, 0)
|
|
660 |
foundItems = self.findItems(item.name, Qt.MatchExactly | Qt.MatchRecursive, 0)
|
|
635 | 661 |
for foundItem in foundItems: |
636 | 662 |
data = foundItem.data(0, self.TREE_DATA_ROLE) |
637 | 663 |
if data is not None and data is item: |
638 | 664 |
return foundItem |
639 | 665 |
elif type(item) is QEngineeringLineNoTextItem: |
640 |
foundItems = self.findItems(item.text().replace('\n', '') , Qt.MatchExactly|Qt.MatchRecursive, 0)
|
|
666 |
foundItems = self.findItems(item.text().replace('\n', ''), Qt.MatchExactly | Qt.MatchRecursive, 0)
|
|
641 | 667 |
for foundItem in foundItems: |
642 | 668 |
data = foundItem.data(0, self.TREE_DATA_ROLE) |
643 | 669 |
if data is not None and data is item: |
644 | 670 |
return foundItem |
645 | 671 |
elif type(item) is QEngineeringUnknownItem: |
646 |
foundItems = self.findItems('Unknown' , Qt.MatchExactly|Qt.MatchRecursive, 0)
|
|
672 |
foundItems = self.findItems('Unknown', Qt.MatchExactly | Qt.MatchRecursive, 0)
|
|
647 | 673 |
for foundItem in foundItems: |
648 | 674 |
data = foundItem.data(0, self.TREE_DATA_ROLE) |
649 | 675 |
if data is not None and data is item: |
650 | 676 |
return foundItem |
651 | 677 |
elif type(item) is QEngineeringNoteItem: |
652 |
foundItems = self.findItems(item.text() , Qt.MatchExactly|Qt.MatchRecursive, 0)
|
|
678 |
foundItems = self.findItems(item.text(), Qt.MatchExactly | Qt.MatchRecursive, 0)
|
|
653 | 679 |
for foundItem in foundItems: |
654 | 680 |
data = foundItem.data(0, self.TREE_DATA_ROLE) |
655 | 681 |
if data is not None and data is item: |
656 | 682 |
return foundItem |
657 | 683 |
elif type(item) is QEngineeringTrimLineNoTextItem: |
658 |
foundItems = self.findItems('Unknown Line', Qt.MatchExactly|Qt.MatchRecursive, 0)
|
|
684 |
foundItems = self.findItems('Unknown Line', Qt.MatchExactly | Qt.MatchRecursive, 0)
|
|
659 | 685 |
for foundItem in foundItems: |
660 | 686 |
data = foundItem.data(0, self.TREE_DATA_ROLE) |
661 | 687 |
if data is not None and data is item: |
662 | 688 |
return foundItem |
663 |
|
|
689 |
|
|
664 | 690 |
return None |
665 | 691 |
|
666 | 692 |
''' |
... | ... | |
668 | 694 |
@author kyouho |
669 | 695 |
@date 2018.09.17 |
670 | 696 |
''' |
697 |
|
|
671 | 698 |
def InitLineNoItems(self): |
672 |
try:
|
|
699 |
try: |
|
673 | 700 |
removeLineItem = [] |
674 | 701 |
for lineIndex in range(self.LineNoTreeItem.childCount()): |
675 | 702 |
## LineNoItem, TrimLine Item |
... | ... | |
706 | 733 |
from App import App |
707 | 734 |
from AppDocData import MessageType |
708 | 735 |
|
709 |
message = 'error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno) |
|
736 |
message = 'error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, |
|
737 |
sys.exc_info()[-1].tb_lineno) |
|
710 | 738 |
App.mainWnd().addMessage.emit(MessageType.Error, message) |
711 | 739 |
|
712 | 740 |
''' |
... | ... | |
717 | 745 |
Declare self.TREE_DATA_ROLE for QTreeWidgetItem.data(column, role) |
718 | 746 |
@history 2018.11.22 euisung add note, unknown |
719 | 747 |
''' |
748 |
|
|
720 | 749 |
@pyqtSlot(SymbolSvgItem) |
721 | 750 |
def findItem(self, item): |
722 | 751 |
if issubclass(type(item), SymbolSvgItem): |
723 |
foundItems = self.findItems(item.name, Qt.MatchExactly|Qt.MatchRecursive, 0)
|
|
752 |
foundItems = self.findItems(item.name, Qt.MatchExactly | Qt.MatchRecursive, 0)
|
|
724 | 753 |
if foundItems is not None: |
725 | 754 |
for fItem in foundItems: |
726 | 755 |
data = fItem.data(0, self.TREE_DATA_ROLE) |
... | ... | |
728 | 757 |
self.setCurrentItem(fItem) |
729 | 758 |
return |
730 | 759 |
elif type(item) is QEngineeringLineNoTextItem: |
731 |
foundItems = self.findItems(item.text(), Qt.MatchExactly|Qt.MatchRecursive, 0)
|
|
760 |
foundItems = self.findItems(item.text(), Qt.MatchExactly | Qt.MatchRecursive, 0)
|
|
732 | 761 |
if foundItems is not None: |
733 | 762 |
for fItem in foundItems: |
734 | 763 |
data = fItem.data(0, self.TREE_DATA_ROLE) |
... | ... | |
745 | 774 |
self.setCurrentItem(child) |
746 | 775 |
return |
747 | 776 |
elif type(item) is QEngineeringUnknownItem: |
748 |
foundItems = self.findItems('Unknown', Qt.MatchExactly|Qt.MatchRecursive, 0)
|
|
777 |
foundItems = self.findItems('Unknown', Qt.MatchExactly | Qt.MatchRecursive, 0)
|
|
749 | 778 |
if foundItems is not None: |
750 | 779 |
for fItem in foundItems: |
751 | 780 |
data = fItem.data(0, self.TREE_DATA_ROLE) |
... | ... | |
753 | 782 |
self.setCurrentItem(fItem) |
754 | 783 |
return |
755 | 784 |
elif type(item) is QEngineeringTrimLineNoTextItem: |
756 |
foundItems = self.findItems('Unknown Line', Qt.MatchExactly|Qt.MatchRecursive, 0)
|
|
785 |
foundItems = self.findItems('Unknown Line', Qt.MatchExactly | Qt.MatchRecursive, 0)
|
|
757 | 786 |
if foundItems is not None: |
758 | 787 |
for fItem in foundItems: |
759 | 788 |
data = fItem.data(0, self.TREE_DATA_ROLE) |
... | ... | |
762 | 791 |
return |
763 | 792 |
|
764 | 793 |
## Not found |
765 |
#QMessageBox.warning(self, self.tr('Error'), self.tr('Can not find data for the selected symbol.')) |
|
766 |
|
|
794 |
# QMessageBox.warning(self, self.tr('Error'), self.tr('Can not find data for the selected symbol.'))
|
|
795 |
|
|
767 | 796 |
''' |
768 | 797 |
@brief remove given item |
769 | 798 |
@author humkyung |
... | ... | |
771 | 800 |
@history Jeongwoo 2018.05.25 Remove Highlighting when item removed |
772 | 801 |
humkyung 2018.07.22 removed code to Remove highlighting |
773 | 802 |
''' |
803 |
|
|
774 | 804 |
@pyqtSlot(QGraphicsItem) |
775 | 805 |
def itemRemoved(self, item): |
776 | 806 |
try: |
... | ... | |
793 | 823 |
if hasattr(self, 'NotesTreeItem'): |
794 | 824 |
self.NotesTreeItem.setText(0, 'NOTES({})'.format(self.NotesTreeItem.childCount())) |
795 | 825 |
if hasattr(self, 'UnknownTreeItem'): |
796 |
self.UnknownTreeItem.setText(0, 'UNKNOWN({})'.format(self.UnknownTreeItem.childCount())) |
|
826 |
self.UnknownTreeItem.setText(0, 'UNKNOWN({})'.format(self.UnknownTreeItem.childCount())) |
DTI_PID/DTI_PID/MainWindow.py | ||
---|---|---|
1284 | 1284 |
self.onCommandRejected() |
1285 | 1285 |
dialog = QTextDataListDialog(self) |
1286 | 1286 |
dialog.show() |
1287 |
dialog.exec_() |
|
1288 | 1287 |
except Exception as ex: |
1289 | 1288 |
message = 'error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, |
1290 | 1289 |
sys.exc_info()[-1].tb_lineno) |
DTI_PID/DTI_PID/QtImageViewer.py | ||
---|---|---|
257 | 257 |
''' |
258 | 258 |
|
259 | 259 |
def updateViewer(self, zoomNewRect=None): |
260 |
""" Show current zoom (if showing entire image, apply current aspect ratio mode). |
|
261 |
""" |
|
260 |
"""Show current zoom (if showing entire image, apply current aspect ratio mode).""" |
|
262 | 261 |
if not self.hasImage(): |
263 | 262 |
return |
264 |
if len(self.zoomStack): # and self.sceneRect().contains(self.zoomStack[-1]): |
|
265 |
if zoomNewRect is None: |
|
266 |
self.fitInView(self.zoomStack[-1], Qt.KeepAspectRatio) # Show zoomed rect (ignore aspect ratio). |
|
267 |
else: |
|
268 |
self.fitInView(zoomNewRect, Qt.KeepAspectRatio) |
|
263 |
|
|
264 |
if zoomNewRect: |
|
265 |
self.fitInView(zoomNewRect, Qt.KeepAspectRatio) |
|
269 | 266 |
else: |
270 |
self.zoomStack = [] # Clear the zoom stack (in case we got here because of an invalid zoom). |
|
271 |
self.fitInView(self.sceneRect(), self.aspectRatioMode) # Show entire image (use current aspect ratio mode). |
|
267 |
if self.zoomStack: |
|
268 |
if zoomNewRect is None: |
|
269 |
self.fitInView(self.zoomStack[-1], Qt.KeepAspectRatio) # Show zoomed rect (ignore aspect ratio). |
|
270 |
else: |
|
271 |
self.zoomStack = [] # Clear the zoom stack (in case we got here because of an invalid zoom). |
|
272 |
self.fitInView(self.sceneRect(), self.aspectRatioMode) # Show entire image (use current aspect ratio mode). |
|
272 | 273 |
|
273 | 274 |
def zoomImageInit(self): |
274 | 275 |
if self.hasImage(): |
... | ... | |
287 | 288 |
"""Zoom in & out """ |
288 | 289 |
|
289 | 290 |
HALF_SIZE = 300 |
290 |
clickPos = event.pos() |
|
291 |
scenePos1 = self.mapToScene(clickPos.x() - HALF_SIZE // adjust, clickPos.y() - HALF_SIZE // adjust) |
|
292 |
scenePos2 = self.mapToScene(clickPos.x() + HALF_SIZE // adjust, clickPos.y() + HALF_SIZE // adjust) |
|
293 | 291 |
if isZoomIn: |
294 |
zoomArea = QRectF( |
|
295 |
QPointF(scenePos1.x() if scenePos1.x() > 0 else 0, scenePos1.y() if scenePos1.y() > 0 else 0), |
|
296 |
QPointF(scenePos2.x(), scenePos2.y())) |
|
297 |
# self.fitInView(zoomArea, Qt.KeepAspectRatioByExpanding) |
|
298 |
viewBBox = self.zoomStack[-1] if len(self.zoomStack) else self.sceneRect() |
|
299 |
selectionBBox = zoomArea.intersected(viewBBox) |
|
292 |
clickPos = event.pos() |
|
293 |
left_top = self.mapToScene(clickPos.x() - HALF_SIZE // adjust, clickPos.y() - HALF_SIZE // adjust) |
|
294 |
right_bottom = self.mapToScene(clickPos.x() + HALF_SIZE // adjust, clickPos.y() + HALF_SIZE // adjust) |
|
295 |
|
|
296 |
zoomArea = QRectF(left_top, right_bottom) |
|
300 | 297 |
self.scene.setSelectionArea(QPainterPath()) # Clear current selection area. |
301 |
if selectionBBox.width() > HALF_SIZE * 2 and selectionBBox.height() > HALF_SIZE * 2: |
|
302 |
if selectionBBox.isValid() and (selectionBBox != viewBBox): |
|
303 |
self.zoomStack.append(selectionBBox) |
|
304 |
self.updateViewer() |
|
298 |
if zoomArea.isValid(): |
|
299 |
self.zoomStack.append(zoomArea) |
|
300 |
self.updateViewer(zoomArea) |
|
305 | 301 |
else: |
306 | 302 |
zoomNewRect = None |
307 |
self.scene.setSelectionArea(QPainterPath()) # Clear current selection area. |
|
308 |
if len(self.zoomStack): |
|
309 |
self.zoomStack.pop() |
|
310 |
if len(self.zoomStack): |
|
311 |
newScenePos = self.mapToScene(clickPos.x(), clickPos.y()) |
|
312 |
newPosX1 = newScenePos.x() - self.zoomStack[-1].width() / 2 |
|
313 |
newPosY1 = newScenePos.y() - self.zoomStack[-1].height() / 2 |
|
314 |
zoomNewPos1 = QPointF(newPosX1 if newPosX1 > 0 else 0, newPosY1 if newPosY1 > 0 else 0) |
|
315 |
newPosX2 = newScenePos.x() + self.zoomStack[-1].width() / 2 |
|
316 |
newPosY2 = newScenePos.y() + self.zoomStack[-1].width() / 2 |
|
317 |
zoomNewPos2 = QPointF(newPosX2, newPosY2) |
|
318 |
zoomNewRect = QRectF(zoomNewPos1, zoomNewPos2) |
|
303 |
self.scene.clearSelection() |
|
304 |
if self.zoomStack: |
|
305 |
zoomNewRect = self.zoomStack.pop() |
|
319 | 306 |
self.updateViewer(zoomNewRect) |
320 | 307 |
|
321 |
def resizeEvent(self, event): |
|
322 |
"""Maintain current zoom on resize""" |
|
323 |
self.updateViewer() |
|
324 |
|
|
325 | 308 |
''' |
326 | 309 |
@brief mouse move event |
327 | 310 |
''' |
DTI_PID/DTI_PID/RecognitionDialog.py | ||
---|---|---|
99 | 99 |
from AppDocData import MessageType |
100 | 100 |
|
101 | 101 |
message = 'error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, |
102 |
sys.exc_info()[-1].tb_lineno) |
|
102 |
sys.exc_info()[-1].tb_lineno)
|
|
103 | 103 |
App.mainWnd().addMessage.emit(MessageType.Error, message) |
104 | 104 |
self.displayLog.emit(MessageType.Error, message) |
105 | 105 |
except: |
... | ... | |
137 | 137 |
from App import App |
138 | 138 |
|
139 | 139 |
message = 'error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, |
140 |
sys.exc_info()[-1].tb_lineno) |
|
140 |
sys.exc_info()[-1].tb_lineno)
|
|
141 | 141 |
App.mainWnd().addMessage.emit(MessageType.Error, message) |
142 | 142 |
|
143 | 143 |
return contourImage |
... | ... | |
195 | 195 |
from App import App |
196 | 196 |
|
197 | 197 |
message = 'error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, |
198 |
sys.exc_info()[-1].tb_lineno) |
|
198 |
sys.exc_info()[-1].tb_lineno)
|
|
199 | 199 |
App.mainWnd().addMessage.emit(MessageType.Error, message) |
200 | 200 |
|
201 | 201 |
@staticmethod |
... | ... | |
237 | 237 |
# remove already existing symbol and text |
238 | 238 |
if not batch: |
239 | 239 |
items = [item for item in worker.graphicsView.scene.items() if |
240 |
type(item) is QEngineeringUnknownItem or type(item) is QEngineeringEndBreakItem or type(
|
|
241 |
item) is QEngineeringErrorItem]
|
|
240 |
type(item) is QEngineeringUnknownItem or type(item) is QEngineeringEndBreakItem or |
|
241 |
type(item) is QEngineeringErrorItem]
|
|
242 | 242 |
if worker.isSymbolChecked: |
243 | 243 |
items.extend( |
244 | 244 |
[item for item in worker.graphicsView.scene.items() if issubclass(type(item), SymbolSvgItem)]) |
... | ... | |
251 | 251 |
for item in [item for item in worker.graphicsView.scene.items() if |
252 | 252 |
type(item) is QGraphicsBoundingBoxItem]: |
253 | 253 |
item.transfer.onRemoved.emit(item) |
254 |
|
|
255 | 254 |
# up to here |
256 | 255 |
|
257 | 256 |
srcList = path |
... | ... | |
330 | 329 |
if worker.isSymbolChecked: |
331 | 330 |
worker.displayTitle.emit(worker.tr('Detecting symbols...')) |
332 | 331 |
|
332 |
""" |
|
333 |
contours, _ = cv1.findContours(image, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE) |
|
334 |
for contour in contours: |
|
335 |
area = cv1.contourArea(contour, False) |
|
336 |
if min_area < area < max_area: |
|
337 |
epsilon = cv1.arcLength(contour, True) * 0.001 |
|
338 |
approx = cv1.approxPolyDP(contour, epsilon, True) |
|
339 |
approx = [pt[-1] for pt in approx] |
|
340 |
self.graphics_view.scene.contours.append(approx) |
|
341 |
""" |
|
342 |
|
|
333 | 343 |
# detect equipments |
334 | 344 |
pool = futures.ThreadPoolExecutor(max_workers=THREAD_MAX_WORKER) |
335 | 345 |
for symbol in targetSymbolList[0]: |
... | ... | |
369 | 379 |
continue |
370 | 380 |
pool.submit(Worker.remove_detected_symbol_image, sym, app_doc_data.imgSrc) |
371 | 381 |
pool.shutdown(wait=True) |
372 |
# print(searchedSymbolList[0].getOcrOption()) |
|
373 | 382 |
else: |
374 |
# if symbol is excluded from recognition, keep it |
|
375 | 383 |
''' |
376 | 384 |
import math |
377 | 385 |
|
... | ... | |
463 | 471 |
otherTextInfoList = textDetector.otherTextInfoList.copy() if textDetector.otherTextInfoList is not None else None |
464 | 472 |
titleBlockTextInfoList = textDetector.titleBlockTextInfoList.copy() if textDetector.titleBlockTextInfoList is not None else None |
465 | 473 |
|
466 |
app_doc_data.activeDrawing.width, app_doc_data.activeDrawing.height = app_doc_data.imgSrc.shape[::-1] |
|
474 |
app_doc_data.activeDrawing.width, app_doc_data.activeDrawing.height = app_doc_data.imgSrc.shape[ |
|
475 |
::-1] |
|
467 | 476 |
|
468 | 477 |
app_doc_data.imgName = os.path.splitext(os.path.basename(mainRes))[0] |
469 | 478 |
else: |
... | ... | |
482 | 491 |
lineNoTextItem.explode() |
483 | 492 |
|
484 | 493 |
for textItem in textItems: |
485 |
textInfoList.append(TextInfo(textItem.text(), textItem.loc[0], textItem.loc[1], textItem.size[0], textItem.size[1], \ |
|
486 |
round(math.degrees(textItem.angle)))) |
|
494 |
textInfoList.append( |
|
495 |
TextInfo(textItem.text(), textItem.loc[0], textItem.loc[1], textItem.size[0], |
|
496 |
textItem.size[1], \ |
|
497 |
round(math.degrees(textItem.angle)))) |
|
487 | 498 |
|
488 | 499 |
textItem.owner = None |
489 | 500 |
worker.graphicsView.scene.removeItem(textItem) |
... | ... | |
501 | 512 |
valid = 0 |
502 | 513 |
for text_info in textInfoList: |
503 | 514 |
info_center = text_info.center |
504 |
if info_center[0] > sym_xmin and info_center[0] < sym_xmax and info_center[1] > sym_ymin and info_center[1] < sym_ymax: |
|
515 |
if info_center[0] > sym_xmin and info_center[0] < sym_xmax and info_center[1] > sym_ymin and \ |
|
516 |
info_center[1] < sym_ymax: |
|
505 | 517 |
valid += 1 |
506 | 518 |
if valid >= valid_count: |
507 | 519 |
valid_sym.append(searchedTextSymList[index]) |
... | ... | |
530 | 542 |
if area is not None: |
531 | 543 |
area.img = app_doc_data.imgSrc[round(area.y + 1):round(area.y + area.height), |
532 | 544 |
round(area.x + 1):round(area.x + area.width)] |
533 |
cv2.imwrite(os.path.join(project.getTempPath(), "RECT_" + os.path.basename(mainRes)), app_doc_data.imgSrc) |
|
545 |
cv2.imwrite(os.path.join(project.getTempPath(), "RECT_" + os.path.basename(mainRes)), |
|
546 |
app_doc_data.imgSrc) |
|
534 | 547 |
|
535 | 548 |
listWidget.addItem("Recognized symbol count : " + str(len(searchedSymbolList))) |
536 | 549 |
|
... | ... | |
564 | 577 |
configs = app_doc_data.getConfigs('Line Detector', 'Length to connect line') |
565 | 578 |
toler = int(configs[0].value) if configs else 20 |
566 | 579 |
for symbol in app_doc_data.symbols: |
567 |
matches = [it for it in app_doc_data.symbols if it is not symbol and symbol.is_connectable(it, toler=toler)] |
|
580 |
matches = [it for it in app_doc_data.symbols if |
|
581 |
it is not symbol and symbol.is_connectable(it, toler=toler)] |
|
568 | 582 |
# print(str(symbol)) |
569 | 583 |
# print(matches) |
570 | 584 |
for match in matches: |
571 | 585 |
symbol.connect_if_possible(match) |
572 | 586 |
except Exception as ex: |
573 | 587 |
message = 'error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, |
574 |
sys.exc_info()[-1].tb_lineno) |
|
588 |
sys.exc_info()[-1].tb_lineno)
|
|
575 | 589 |
worker.displayLog.emit(MessageType.Error, message) |
576 | 590 |
# up to here |
577 | 591 |
|
... | ... | |
621 | 635 |
worker.updateBatchProgress.emit(len(srcList), 1) |
622 | 636 |
except Exception as ex: |
623 | 637 |
message = 'error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, |
624 |
sys.exc_info()[-1].tb_lineno) |
|
638 |
sys.exc_info()[-1].tb_lineno)
|
|
625 | 639 |
worker.displayLog.emit(MessageType.Error, message) |
626 | 640 |
finally: |
627 | 641 |
pass |
... | ... | |
630 | 644 |
def changeConnectedLineType(line, lineType): |
631 | 645 |
line.lineType = lineType |
632 | 646 |
if type(line.connectors[0].connectedItem) is QEngineeringLineItem and \ |
633 |
(line.connectors[0].connectedItem.connectors[0].connectedItem is line or line.connectors[0].connectedItem.connectors[1].connectedItem is line) and \ |
|
647 |
(line.connectors[0].connectedItem.connectors[0].connectedItem is line or |
|
648 |
line.connectors[0].connectedItem.connectors[1].connectedItem is line) and \ |
|
634 | 649 |
line.connectors[0].connectedItem.lineType is not lineType: |
635 | 650 |
Worker.changeConnectedLineType(line.connectors[0].connectedItem, lineType) |
636 | 651 |
if type(line.connectors[1].connectedItem) is QEngineeringLineItem and \ |
637 |
(line.connectors[1].connectedItem.connectors[0].connectedItem is line or line.connectors[1].connectedItem.connectors[1].connectedItem is line) and \ |
|
652 |
(line.connectors[1].connectedItem.connectors[0].connectedItem is line or |
|
653 |
line.connectors[1].connectedItem.connectors[1].connectedItem is line) and \ |
|
638 | 654 |
line.connectors[1].connectedItem.lineType is not lineType: |
639 | 655 |
Worker.changeConnectedLineType(line.connectors[1].connectedItem, lineType) |
640 | 656 |
|
... | ... | |
709 | 725 |
app_doc_data.allItems.append(line) |
710 | 726 |
except Exception as ex: |
711 | 727 |
message = 'error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, |
712 |
sys.exc_info()[-1].tb_lineno) |
|
728 |
sys.exc_info()[-1].tb_lineno)
|
|
713 | 729 |
worker.displayLog.emit(MessageType.Error, message) |
714 | 730 |
finally: |
715 | 731 |
listWidget.addItem('Finishing line recognition') |
... | ... | |
761 | 777 |
# up to here |
762 | 778 |
except Exception as ex: |
763 | 779 |
message = 'error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, |
764 |
sys.exc_info()[-1].tb_lineno) |
|
780 |
sys.exc_info()[-1].tb_lineno)
|
|
765 | 781 |
worker.displayLog(MessageType.Error, message) |
766 | 782 |
|
767 | 783 |
''' |
... | ... | |
786 | 802 |
try: |
787 | 803 |
forTraining = worker.isTrainingChecked |
788 | 804 |
symbolName = targetSymbol.getName() |
789 |
# threadLock.acquire() |
|
790 |
# print(symbolName) |
|
791 |
# threadLock.release() |
|
792 | 805 |
symbolType = targetSymbol.getType() |
793 | 806 |
symbolPath = targetSymbol.getPath() |
794 | 807 |
symbolThreshold = targetSymbol.getThreshold() # if not forTraining else targetSymbol.getThreshold() / 3 * 2 |
... | ... | |
832 | 845 |
sow, soh = symGray.shape[::-1] # symbol original w, h |
833 | 846 |
|
834 | 847 |
offsetDrawingArea = [] |
835 |
appDocData = AppDocData.instance()
|
|
836 |
area = appDocData.getArea('Drawing')
|
|
848 |
app_doc_data = AppDocData.instance()
|
|
849 |
area = app_doc_data.getArea('Drawing')
|
|
837 | 850 |
if area is not None: |
838 |
copiedBasePid = area.img.copy() |
|
851 |
roiItem = area.img |
|
852 |
# roiItem = area.img.copy() |
|
839 | 853 |
offsetDrawingArea.append(area.x) |
840 | 854 |
offsetDrawingArea.append(area.y) |
841 | 855 |
else: |
842 | 856 |
offsetDrawingArea.append(0) |
843 | 857 |
offsetDrawingArea.append(0) |
844 | 858 |
if isDetectOnOrigin == 1: |
845 |
copiedBasePid = appDocData.imgSrc.copy()
|
|
859 |
roiItem = app_doc_data.imgSrc
|
|
846 | 860 |
else: |
847 |
copiedBasePid = ocrCompletedSrc.copy()
|
|
848 |
srcWidth, srcHeight = copiedBasePid.shape[::-1]
|
|
861 |
roiItem = ocrCompletedSrc
|
|
862 |
srcWidth, srcHeight = roiItem.shape[::-1]
|
|
849 | 863 |
|
850 | 864 |
roiItemSp = (0, 0) |
851 | 865 |
roiItemEp = (srcWidth, srcHeight) |
852 |
roiItem = copiedBasePid |
|
866 |
|
|
867 |
""" |
|
868 |
cv2.imwrite('c:\\Temp\\contour.png', roiItem) |
|
869 |
# remove objects smaller than symbol |
|
870 |
selected_contours = [] |
|
871 |
roiItem = cv2.bitwise_not(roiItem) |
|
872 |
cv2.imwrite('c:\\Temp\\not_contour.png', roiItem) |
|
873 |
contours, hierarchy = cv2.findContours(roiItem, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE) |
|
874 |
index = 0 |
|
875 |
for contour in contours: |
|
876 |
child, parent = hierarchy[0][index][2], hierarchy[0][index][3] |
|
877 |
if child == -1 and parent != -1: |
|
878 |
[x, y, w, h] = cv2.boundingRect(contour) |
|
879 |
if w * h < sow * soh * 0.9: |
|
880 |
selected_contours.append(contour) |
|
881 |
index += 1 |
|
882 |
# up to here |
|
883 |
|
|
884 |
# draw contour with white color |
|
885 |
roiItem = cv2.drawContours(roiItem, selected_contours, -1, (255, 255, 255), -1) |
|
886 |
|
|
887 |
inverted_contours = [] |
|
888 |
contours, hierarchy = cv2.findContours(roiItem, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE) |
|
889 |
index = 0 |
|
890 |
for contour in contours: |
|
891 |
child, parent = hierarchy[0][index][2], hierarchy[0][index][3] |
|
892 |
if child == -1 and parent != -1: |
|
893 |
[x, y, w, h] = cv2.boundingRect(contour) |
|
894 |
if w * h < sow * soh * 0.9: |
|
895 |
inverted_contours.append(contour) |
|
896 |
index += 1 |
|
897 |
|
|
898 |
roiItem = cv2.bitwise_not(roiItem) |
|
899 |
roiItem = cv2.drawContours(roiItem, inverted_contours, -1, (255, 255, 255), -1) |
|
900 |
|
|
901 |
cv2.imwrite('c:\\Temp\\contour1.png', roiItem) |
|
902 |
""" |
|
853 | 903 |
|
854 | 904 |
for index in range(2): |
855 | 905 |
if index is 0: |
... | ... | |
898 | 948 |
# print(symbolOriginalPoint) |
899 | 949 |
# print(symbolConnectionPoint) |
900 | 950 |
symbolRotatedAngle = 0 |
901 |
for rc in range(symbolRotateCount + 1): ## Rotation Count를 사용자 기준으로 받아서 1을 더한 후 사용
|
|
951 |
for rc in range(symbolRotateCount + 1): # Rotation Count를 사용자 기준으로 받아서 1을 더한 후 사용 |
|
902 | 952 |
sw, sh = symGray.shape[::-1] |
903 | 953 |
roiw = (roiItemEp[0] - roiItemSp[0]) |
904 | 954 |
roih = (roiItemEp[1] - roiItemSp[1]) |
905 | 955 |
|
906 |
## Case : Bigger Symbol than Split ROI
|
|
956 |
# Case : Bigger Symbol than Split ROI |
|
907 | 957 |
if roiw < sw or roih < sh: |
908 | 958 |
symGray = cv2.rotate(symGray, cv2.ROTATE_90_COUNTERCLOCKWISE) |
909 | 959 |
symbolRotatedAngle = symbolRotatedAngle + 90 |
... | ... | |
912 | 962 |
additionalSymbol = Worker.getRotatedChildInfo(additionalSymbol) |
913 | 963 |
continue |
914 | 964 |
|
915 |
## get Rotated Original Point
|
|
965 |
# get Rotated Original Point |
|
916 | 966 |
originalPoint = Worker.getCalculatedOriginalPoint(additionalSymbol, symbolOriginalPoint, |
917 | 967 |
symbolRotatedAngle, sw, sh, sow, soh) |
918 | 968 |
connectionPoint = Worker.getCalculatedConnectionPoint(symbolConnectionPoint, symbolRotatedAngle, sw, |
... | ... | |
960 | 1010 |
|
961 | 1011 |
hitRate = tmRes[pt[1], pt[0]] |
962 | 1012 |
|
963 |
## 겹치는 영역이 기준값보다 작을 경우
|
|
1013 |
# 겹치는 영역이 기준값보다 작을 경우 |
|
964 | 1014 |
if overlapArea <= ACCEPT_OVERLAY_AREA: |
965 | 1015 |
threadLock.acquire() |
966 | 1016 |
foundSymbolCount = foundSymbolCount + 1 |
... | ... | |
970 | 1020 |
isDetectOnOrigin, symbolRotateCount, symbolOcrOption, |
971 | 1021 |
isContainChild, |
972 | 1022 |
originalPoint, connectionPoint, baseSymbol, additionalSymbol, |
973 |
isExceptDetect, detectFlip=1 if index is 1 else 0, hasInstrumentLabel=hasInstrumentLabel) |
|
1023 |
isExceptDetect, detectFlip=1 if index is 1 else 0, |
|
1024 |
hasInstrumentLabel=hasInstrumentLabel) |
|
974 | 1025 |
threadLock.release() |
975 |
else: ## 겹치는 영역이 기준값보다 클 경우
|
|
1026 |
else: # 겹치는 영역이 기준값보다 클 경우 |
|
976 | 1027 |
if symbolIndex != -1 and symbolIndex < len(searchedSymbolList): |
977 | 1028 |
searchedSymbol = searchedSymbolList[symbolIndex] |
978 |
## 현재 심볼과 검출된 심볼이 같을 경우 Match Point가 더 높은 정보로 교체
|
|
1029 |
# 현재 심볼과 검출된 심볼이 같을 경우 Match Point가 더 높은 정보로 교체 |
|
979 | 1030 |
if symbolName == searchedSymbol.getName(): |
980 | 1031 |
symbolHitRate = searchedSymbol.getHitRate() |
981 | 1032 |
if symbolHitRate - searchedSymbol.getThreshold() < hitRate - symbolThreshold: |
... | ... | |
1001 | 1052 |
detectFlip=1 if index is 1 else 0, |
1002 | 1053 |
hasInstrumentLabel=hasInstrumentLabel) |
1003 | 1054 |
threadLock.release() |
1004 |
## 현재 심볼과 검출된 심볼이 같지 않을 경우 (포함)
|
|
1005 |
elif appDocData.isEquipmentType(searchedSymbol.getType()):
|
|
1055 |
# 현재 심볼과 검출된 심볼이 같지 않을 경우 (포함) |
|
1056 |
elif app_doc_data.isEquipmentType(searchedSymbol.getType()):
|
|
1006 | 1057 |
if searchedSymbol.area > sw * sh * 10: # searched equipment area is greather than 10 times of symbol's area |
1007 | 1058 |
threadLock.acquire() |
1008 | 1059 |
foundSymbolCount = foundSymbolCount + 1 |
... | ... | |
1013 | 1064 |
isContainChild, |
1014 | 1065 |
originalPoint, connectionPoint, baseSymbol, |
1015 | 1066 |
additionalSymbol, isExceptDetect, |
1016 |
detectFlip=1 if index is 1 else 0, hasInstrumentLabel=hasInstrumentLabel) |
|
1067 |
detectFlip=1 if index is 1 else 0, |
|
1068 |
hasInstrumentLabel=hasInstrumentLabel) |
|
1017 | 1069 |
threadLock.release() |
1018 |
## 현재 심볼과 검출된 심볼이 같지 않을 경우 (교체)
|
|
1070 |
# 현재 심볼과 검출된 심볼이 같지 않을 경우 (교체) |
|
1019 | 1071 |
elif not forTraining: |
1020 | 1072 |
searchedSymbol = searchedSymbolList[symbolIndex] |
1021 | 1073 |
symbolHitRate = searchedSymbol.getHitRate() |
... | ... | |
1038 | 1090 |
connectionPoint), |
1039 | 1091 |
baseSymbol, additionalSymbol, |
1040 | 1092 |
isExceptDetect, |
1041 |
detectFlip=1 if index is 1 else 0, hasInstrumentLabel=hasInstrumentLabel) |
|
1093 |
detectFlip=1 if index is 1 else 0, |
|
1094 |
hasInstrumentLabel=hasInstrumentLabel) |
|
1042 | 1095 |
threadLock.release() |
1043 | 1096 |
# 학습용 데이터 생성을 위해 교체하지 않고 추가함 |
1044 | 1097 |
elif forTraining: |
... | ... | |
1051 | 1104 |
isContainChild, |
1052 | 1105 |
originalPoint, connectionPoint, baseSymbol, |
1053 | 1106 |
additionalSymbol, isExceptDetect, |
1054 |
detectFlip=1 if index is 1 else 0, hasInstrumentLabel=hasInstrumentLabel) |
|
1107 |
detectFlip=1 if index is 1 else 0, |
|
1108 |
hasInstrumentLabel=hasInstrumentLabel) |
|
1055 | 1109 |
threadLock.release() |
1056 | 1110 |
|
1057 |
## Rotate Symbol
|
|
1111 |
# Rotate Symbol |
|
1058 | 1112 |
symGray = cv2.rotate(symGray, cv2.ROTATE_90_COUNTERCLOCKWISE) |
1059 | 1113 |
symbolRotatedAngle = symbolRotatedAngle + 90 |
1060 | 1114 |
|
... | ... | |
1066 | 1120 |
foundSymbolCount) + ')') |
1067 | 1121 |
threadLock.release() |
1068 | 1122 |
|
1123 |
""" |
|
1124 |
# restore objects smaller than symbol |
|
1125 |
roiItem = cv2.drawContours(roiItem, inverted_contours, -1, (0, 0, 0), -1) |
|
1126 |
roiItem = cv2.drawContours(roiItem, selected_contours, -1, (255, 255, 255), -1) |
|
1127 |
# up to here |
|
1128 |
cv2.imwrite('c:\\Temp\\contour2.png', roiItem) |
|
1129 |
""" |
|
1130 |
|
|
1069 | 1131 |
worker.updateProgress.emit(maxProgressValue, symbolPath) |
1070 | 1132 |
|
1071 | 1133 |
return [symbol for symbol in searchedSymbolList if symbol.getName() == symbolName] |
1072 | 1134 |
except Exception as ex: |
1073 | 1135 |
message = 'error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, |
1074 |
sys.exc_info()[-1].tb_lineno) |
|
1136 |
sys.exc_info()[-1].tb_lineno)
|
|
1075 | 1137 |
worker.displayLog.emit(MessageType.Error, message) |
1076 | 1138 |
|
1077 | 1139 |
return [] |
... | ... | |
1283 | 1345 |
return [symbol for symbol in searchedSymbolList if symbol.getName() == symbolName] |
1284 | 1346 |
except Exception as ex: |
1285 | 1347 |
message = 'error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, |
1286 |
sys.exc_info()[-1].tb_lineno) |
|
1348 |
sys.exc_info()[-1].tb_lineno)
|
|
1287 | 1349 |
worker.displayLog(MessageType.Error, message) |
1288 | 1350 |
|
1289 | 1351 |
return [] |
... | ... | |
1407 | 1469 |
def addSearchedSymbol(sName, sType |
1408 | 1470 |
, sp, w, h, threshold, minMatchCount, hitRate, rotatedAngle |
1409 | 1471 |
, isDetectOnOrigin, rotateCount, ocrOption, isContainChild |
1410 |
, originalPoint, connectionPoint, baseSymbol, additionalSymbol, isExceptDetect, detectFlip, hasInstrumentLabel): |
|
1472 |
, originalPoint, connectionPoint, baseSymbol, additionalSymbol, isExceptDetect, detectFlip, |
|
1473 |
hasInstrumentLabel): |
|
1411 | 1474 |
global searchedSymbolList |
1412 | 1475 |
|
1413 | 1476 |
newSym = None |
... | ... | |
1418 | 1481 |
','.join(str(x) for x in originalPoint), |
1419 | 1482 |
'/'.join('{},{},{},{}'.format(param[0], param[1], param[2], param[3]) for param in |
1420 | 1483 |
connectionPoint), |
1421 |
baseSymbol, additionalSymbol, isExceptDetect, detectFlip=detectFlip, hasInstrumentLabel=hasInstrumentLabel) |
|
1484 |
baseSymbol, additionalSymbol, isExceptDetect, detectFlip=detectFlip, |
|
1485 |
hasInstrumentLabel=hasInstrumentLabel) |
|
1422 | 1486 |
|
1423 | 1487 |
searchedSymbolList.append(newSym) |
1424 | 1488 |
except Exception as ex: |
1425 | 1489 |
from App import App |
1426 | 1490 |
|
1427 | 1491 |
message = 'error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, |
1428 |
sys.exc_info()[-1].tb_lineno) |
|
1492 |
sys.exc_info()[-1].tb_lineno)
|
|
1429 | 1493 |
App.mainWnd().addMessage.emit(MessageType.Error, message) |
1430 | 1494 |
|
1431 | 1495 |
return newSym |
... | ... | |
1500 | 1564 |
from App import App |
1501 | 1565 |
|
1502 | 1566 |
message = 'error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, |
1503 |
sys.exc_info()[-1].tb_lineno) |
|
1567 |
sys.exc_info()[-1].tb_lineno)
|
|
1504 | 1568 |
App.mainWnd().addMessage.emit(MessageType.Error, message) |
1505 | 1569 |
|
1506 | 1570 |
return matchCount |
... | ... | |
1595 | 1659 |
from App import App |
1596 | 1660 |
|
1597 | 1661 |
message = 'error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, |
1598 |
sys.exc_info()[-1].tb_lineno) |
|
1662 |
sys.exc_info()[-1].tb_lineno)
|
|
1599 | 1663 |
App.mainWnd().addMessage.emit(MessageType.Error, message) |
1600 | 1664 |
|
1601 | 1665 |
''' |
... | ... | |
1732 | 1796 |
from App import App |
1733 | 1797 |
|
1734 | 1798 |
message = 'error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, |
1735 |
sys.exc_info()[-1].tb_lineno) |
|
1799 |
sys.exc_info()[-1].tb_lineno)
|
|
1736 | 1800 |
App.mainWnd().addMessage.emit(MessageType.Error, message) |
1737 | 1801 |
|
1738 | 1802 |
|
... | ... | |
1895 | 1959 |
''' |
1896 | 1960 |
self.ui.progressBarBatch.setMaximum(maxValue * 5) |
1897 | 1961 |
value = self.ui.progressBarBatch.value() + weight |
1898 |
self.ui.progressBarBatch.setValue(value)
|
|
1962 |
self.ui.progressBarBatch.setValue(value) |
|
1899 | 1963 |
self.ui.progressBarBatch.setFormat('{}/{}'.format(str(int(value / 5)), str(maxValue))) |
1900 | 1964 |
|
1901 | 1965 |
''' |
... | ... | |
1984 | 2048 |
from App import App |
1985 | 2049 |
|
1986 | 2050 |
message = 'error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, |
1987 |
sys.exc_info()[-1].tb_lineno) |
|
2051 |
sys.exc_info()[-1].tb_lineno)
|
|
1988 | 2052 |
App.mainWnd().addMessage.emit(MessageType.Error, message) |
1989 | 2053 |
finally: |
1990 | 2054 |
self.tmStop = timeit.default_timer() |
DTI_PID/DTI_PID/TextDataListDialog.py | ||
---|---|---|
6 | 6 |
import TextDataList_UI |
7 | 7 |
from EngineeringTextItem import QEngineeringTextItem |
8 | 8 |
|
9 |
|
|
9 | 10 |
class forDoubleClicked(): |
10 | 11 |
def buttons(self): |
11 | 12 |
return Qt.LeftButton |
12 | 13 |
|
14 |
|
|
13 | 15 |
class QTextDataListDialog(QDialog): |
14 | 16 |
""" |
15 | 17 |
This is text image data list dialog class |
... | ... | |
26 | 28 |
self.setWindowFlag(Qt.WindowMinMaxButtonsHint) |
27 | 29 |
|
28 | 30 |
# for List |
29 |
self.ui.tableWidget.setSelectionMode(QAbstractItemView.SingleSelection)
|
|
31 |
self.ui.tableWidget.setSelectionMode(QAbstractItemView.SingleSelection) |
|
30 | 32 |
self.ui.tableWidget.setColumnCount(2) |
31 | 33 |
self.ui.tableWidget.setSortingEnabled(True) |
32 | 34 |
|
... | ... | |
52 | 54 |
allowed_error = 0.001 |
53 | 55 |
for textItem in self.textItems: |
54 | 56 |
imageWidget = QTableWidgetItem() |
55 |
#textImage = AppDocData.instance().getCurrentPidSource().getQImageOnRect(QRect(textItem.loc[0] - 3, textItem.loc[1] - 3, textItem.size[0] + 6, textItem.size[1] + 6)) |
|
56 |
textImage = self.graphicsView.image().copy(textItem.loc[0] - 3, textItem.loc[1] - 3, textItem.size[0] + 6, textItem.size[1] + 6) |
|
57 |
# textImage = AppDocData.instance().getCurrentPidSource().getQImageOnRect(QRect(textItem.loc[0] - 3, textItem.loc[1] - 3, textItem.size[0] + 6, textItem.size[1] + 6)) |
|
58 |
textImage = self.graphicsView.image().copy(textItem.loc[0] - 3, textItem.loc[1] - 3, textItem.size[0] + 6, |
|
59 |
textItem.size[1] + 6) |
|
57 | 60 |
if abs(textItem.angle - 0) <= allowed_error: |
58 | 61 |
pass |
59 | 62 |
elif abs(textItem.angle - 1.57) <= allowed_error: |
... | ... | |
95 | 98 |
except Exception as ex: |
96 | 99 |
from App import App |
97 | 100 |
from AppDocData import MessageType |
98 |
message = 'error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno) |
|
101 |
message = 'error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, |
|
102 |
sys.exc_info()[-1].tb_lineno) |
|
99 | 103 |
print(message) |
100 | 104 |
App.mainWnd().addMessage.emit(MessageType.Error, message) |
101 | 105 |
|
... | ... | |
116 | 120 |
|
117 | 121 |
if not force and textItem.scene() is not None: |
118 | 122 |
try: |
119 |
reply = QMessageBox.question(self, self.tr('Continue?'), self.tr('Are you sure you want to delete text item? '), QMessageBox.Yes, QMessageBox.Cancel) |
|
123 |
reply = QMessageBox.question(self, self.tr('Continue?'), |
|
124 |
self.tr('Are you sure you want to delete text item? '), QMessageBox.Yes, |
|
125 |
QMessageBox.Cancel) |
|
120 | 126 |
if reply == QMessageBox.Yes: |
121 | 127 |
textItem.transfer.onRemoved.emit(textItem) |
122 | 128 |
self.ui.tableWidget.removeRow(row) |
123 | 129 |
except Exception as ex: |
124 | 130 |
from App import App |
125 | 131 |
from AppDocData import MessageType |
126 |
message = 'error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno) |
|
132 |
message = 'error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, |
|
133 |
sys.exc_info()[-1].tb_lineno) |
|
127 | 134 |
App.mainWnd().addMessage.emit(MessageType.Error, message) |
128 | 135 |
else: |
129 | 136 |
# item already was deleted from scene |
130 | 137 |
QMessageBox.warning(self, 'Notice', 'The item does not exist in the scene.') |
131 | 138 |
self.ui.tableWidget.removeRow(row) |
132 |
|
|
139 |
|
|
133 | 140 |
def listCellClicked(self, row, col): |
134 | 141 |
from HighlightCommand import HighlightCommand |
135 | 142 |
|
... | ... | |
149 | 156 |
row -= 1 |
150 | 157 |
HighlightCommand(self.graphicsView).execute(self.ui.tableWidget.item(row, 1).tag) |
151 | 158 |
self.ui.tableWidget.setCurrentItem(self.ui.tableWidget.item(row, col)) |
152 |
self.ui.tableWidget.scrollToItem(self.ui.tableWidget.item(row, col), QAbstractItemView.EnsureVisible) |
|
159 |
self.ui.tableWidget.scrollToItem(self.ui.tableWidget.item(row, col), |
|
160 |
QAbstractItemView.EnsureVisible) |
|
153 | 161 |
elif event.key() == Qt.Key_Down: |
154 | 162 |
if row is not self.ui.tableWidget.rowCount() - 1: |
155 |
row +=1 |
|
163 |
row += 1
|
|
156 | 164 |
HighlightCommand(self.graphicsView).execute(self.ui.tableWidget.item(row, 1).tag) |
157 | 165 |
self.ui.tableWidget.setCurrentItem(self.ui.tableWidget.item(row, col)) |
158 |
self.ui.tableWidget.scrollToItem(self.ui.tableWidget.item(row, col), QAbstractItemView.EnsureVisible) |
|
166 |
self.ui.tableWidget.scrollToItem(self.ui.tableWidget.item(row, col), |
|
167 |
QAbstractItemView.EnsureVisible) |
|
159 | 168 |
except Exception as ex: |
160 | 169 |
pass |
161 | 170 |
|
162 |
#QDialog.keyPressEvent(self, event) |
|
171 |
# QDialog.keyPressEvent(self, event)
|
|
163 | 172 |
|
164 | 173 |
except Exception as ex: |
165 | 174 |
from App import App |
166 | 175 |
from AppDocData import MessageType |
167 |
message = 'error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno) |
|
168 |
App.mainWnd().addMessage.emit(MessageType.Error, message) |
|
176 |
message = 'error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, |
|
177 |
sys.exc_info()[-1].tb_lineno) |
|
178 |
App.mainWnd().addMessage.emit(MessageType.Error, message) |
내보내기 Unified diff