hytos / DTI_PID / DTI_PID / MainWindow.py @ 0de8c1ca
이력 | 보기 | 이력해설 | 다운로드 (140 KB)
1 | e4b3e191 | humkyung | # coding: utf-8
|
---|---|---|---|
2 | 7552be56 | humkyung | """ This is MainWindow module """
|
3 | e4b3e191 | humkyung | |
4 | import sys |
||
5 | import os |
||
6 | 7e1a8685 | esham21 | import subprocess |
7 | dbc1b32f | humkyung | from functools import partial |
8 | a4707ffe | humkyung | |
9 | sys.path.insert(0, os.path.dirname(os.path.realpath(__file__)))
|
||
10 | 9264500e | humkyung | sys.path.insert(0, os.path.dirname(os.path.realpath(__file__)) + '\\Commands') |
11 | import CreateCommand |
||
12 | import CropCommand |
||
13 | import AreaOcrCommand |
||
14 | import CreateSymbolCommand |
||
15 | import AreaZoomCommand |
||
16 | import FenceCommand |
||
17 | import PlaceLineCommand |
||
18 | 00f34471 | esham21 | import PlacePolygonCommand |
19 | 9264500e | humkyung | |
20 | e4b3e191 | humkyung | import cv2 |
21 | ccb42e9b | humkyung | import numpy as np |
22 | e4b3e191 | humkyung | |
23 | from PyQt5.QtCore import * |
||
24 | from PyQt5.QtGui import * |
||
25 | from PyQt5.QtWidgets import * |
||
26 | from PyQt5.QtSvg import * |
||
27 | |||
28 | 7b2a4455 | 김정우 | from PIL import Image |
29 | |||
30 | 25e0cacb | Gyusu | import MainWindow_UI |
31 | e4b3e191 | humkyung | import QtImageViewer |
32 | 6229e3e2 | humkyung | from SingletonInstance import SingletonInstane |
33 | e4b3e191 | humkyung | |
34 | sys.path.insert(0, os.path.dirname(os.path.realpath(__file__)) + '\\Shapes') |
||
35 | 746c8f97 | esham21 | from EngineeringAbstractItem import QEngineeringAbstractItem |
36 | 25e0cacb | Gyusu | from EngineeringPolylineItem import QEngineeringPolylineItem |
37 | from EngineeringLineItem import QEngineeringLineItem |
||
38 | 0a748a0d | humkyung | from SymbolSvgItem import SymbolSvgItem |
39 | 8fd1d96f | humkyung | from GraphicsBoundingBoxItem import QGraphicsBoundingBoxItem |
40 | c80d49e6 | humkyung | from EngineeringTextItem import QEngineeringTextItem |
41 | baf331db | humkyung | from EngineeringLineNoTextItem import QEngineeringLineNoTextItem |
42 | afabd84e | humkyung | from EngineeringNoteItem import QEngineeringNoteItem |
43 | 24015dc6 | humkyung | from QEngineeringSizeTextItem import QEngineeringSizeTextItem |
44 | dc05dcb9 | humkyung | from EngineeringUnknownItem import QEngineeringUnknownItem |
45 | afabd84e | humkyung | from EngineeringEquipmentItem import QEngineeringEquipmentItem |
46 | 9100a182 | humkyung | from EngineeringInstrumentItem import QEngineeringInstrumentItem |
47 | 550cedb9 | gaqhf | from EngineeringSpecBreakItem import QEngineeringSpecBreakItem |
48 | 2605a8f9 | esham21 | from EngineeringErrorItem import QEngineeringErrorItem |
49 | 42318ecb | esham21 | from EngineeringVendorItem import QEngineeringVendorItem |
50 | 5ed7b446 | esham21 | from EngineeringEndBreakItem import QEngineeringEndBreakItem |
51 | 18e758c8 | esham21 | from EngineeringReducerItem import QEngineeringReducerItem |
52 | d28da625 | esham21 | from EngineeringFlowMarkItem import QEngineeringFlowMarkItem |
53 | 746c8f97 | esham21 | from QEngineeringTrimLineNoTextItem import QEngineeringTrimLineNoTextItem |
54 | 0a9e44a7 | humkyung | from AppDocData import * |
55 | 6a2a7457 | humkyung | import SymbolTreeWidget, SymbolPropertyTableWidget |
56 | dc05dcb9 | humkyung | import SymbolEditorDialog |
57 | 0a9e44a7 | humkyung | import ItemTreeWidget |
58 | import ItemPropertyTableWidget |
||
59 | 357646b0 | gaqhf | from UserInputAttribute import UserInputAttribute |
60 | aa1b6842 | 김정우 | from TextItemFactory import TextItemFactory |
61 | 93827f59 | humkyung | from TrainingImageListDialog import QTrainingImageListDialog |
62 | 35eb686f | esham21 | from TrainingSymbolImageListDialog import QTrainingSymbolImageListDialog |
63 | d35a6081 | esham21 | from TextDataListDialog import QTextDataListDialog |
64 | a3aa5583 | esham21 | from ImportTextFromCADDialog import QImportTextFromCADDialog |
65 | 01fc42a0 | esham21 | from SymbolThicknessDialog import QSymbolThicknessDialog |
66 | 7e77874e | humkyung | from DisplayColors import DisplayColors |
67 | from DisplayColors import DisplayOptions |
||
68 | 38dbda17 | esham21 | import uuid |
69 | 853df487 | humkyung | from openpyxl import * |
70 | from openpyxl.styles import * |
||
71 | |||
72 | e4b3e191 | humkyung | |
73 | 25e0cacb | Gyusu | class MainWindow(QMainWindow, MainWindow_UI.Ui_MainWindow, SingletonInstane): |
74 | 52e28a3a | humkyung | """ This is MainWindow class """
|
75 | e65b0bf8 | humkyung | addMessage = pyqtSignal(Enum, str)
|
76 | |||
77 | d8ddd93d | humkyung | '''
|
78 | @brief initialize
|
||
79 | @author
|
||
80 | @date
|
||
81 | @history humkyung 2018.04.12 add splitter widget
|
||
82 | 12fa11d3 | 김정우 | Jeongwoo 2018.04.27 Add Signal/Slot Connection 'noteNoSingleClicked'
|
83 | 65cdeb69 | 김정우 | Jeongwoo 2018.05.09 Initialize Action group
|
84 | 360faad5 | 김정우 | Jeongwoo 2018.05.10 Add Signal/Slot Connection 'lineNoSingleClicked'
|
85 | 1f45633d | 김정우 | Add QActionGroup for managing checkable action
|
86 | 594bbd9c | 김정우 | Jeongwoo 2018.06.27 Add Action [Zoom, Fit Window] and Add new actions into ActionGroup
|
87 | 59643c3f | humkyung | humkyung 2018.08.23 add labelStatus to statusbar
|
88 | 1669b150 | esham21 | Euisung 2018.09.27 add OCR Training , Signal/Slot Connection 'oCRTrainingClicked'
|
89 | 6518bfbe | esham21 | Euisung 2018.10.05 add OCR Editor , Signal/Slot Connection 'oCRTrainingEdidorClicked'
|
90 | ff768aea | esham21 | Euisung 2018.10.22 delete Signal/Slot Connection 'oCRTrainingEdidorClicked'
|
91 | d8ddd93d | humkyung | '''
|
92 | 853df487 | humkyung | |
93 | e4b3e191 | humkyung | def __init__(self): |
94 | 54eedb38 | humkyung | from App import App |
95 | 3a9d8155 | humkyung | from LineTypeConditions import LineTypeConditions |
96 | |||
97 | e4b3e191 | humkyung | super(self.__class__, self).__init__() |
98 | self.setupUi(self) |
||
99 | 436a3d81 | humkyung | self.progress_bar = QProgressBar()
|
100 | 2829806b | humkyung | self._label_mouse = QLabel(self.statusbar) |
101 | 853df487 | humkyung | self._label_mouse.setText(self.tr('mouse pos : ({},{})'.format(0, 0))) |
102 | 59643c3f | humkyung | self.labelStatus = QLabel(self.statusbar) |
103 | f5709716 | humkyung | self.labelStatus.setText(self.tr('Unrecognition : ')) |
104 | f7ada1c1 | humkyung | self.labelSymbolStatus = QLabel(self.statusbar) |
105 | f5709716 | humkyung | self.labelSymbolStatus.setText(self.tr('Symbol : ')) |
106 | f7ada1c1 | humkyung | self.labelLineStatus = QLabel(self.statusbar) |
107 | f5709716 | humkyung | self.labelLineStatus.setText(self.tr('Line : ')) |
108 | f7ada1c1 | humkyung | self.labelTextStatus = QLabel(self.statusbar) |
109 | f5709716 | humkyung | self.labelTextStatus.setText(self.tr('Text : ')) |
110 | 436a3d81 | humkyung | |
111 | 2829806b | humkyung | self.statusbar.addWidget(self._label_mouse) |
112 | 436a3d81 | humkyung | self.statusbar.addPermanentWidget(self.progress_bar, 1) |
113 | f7ada1c1 | humkyung | self.statusbar.addPermanentWidget(self.labelSymbolStatus) |
114 | self.statusbar.addPermanentWidget(self.labelLineStatus) |
||
115 | self.statusbar.addPermanentWidget(self.labelTextStatus) |
||
116 | 853df487 | humkyung | self.statusbar.addPermanentWidget(self.labelStatus) |
117 | 1f45633d | 김정우 | |
118 | 0ea718ad | humkyung | docData = AppDocData.instance() |
119 | 77616eee | esham21 | docData.clear() |
120 | 0ea718ad | humkyung | project = docData.getCurrentProject() |
121 | a6581e45 | humkyung | _translate = QCoreApplication.translate |
122 | ad66ff0a | humkyung | version = QCoreApplication.applicationVersion() |
123 | f3178bb6 | esham21 | # set title
|
124 | 54eedb38 | humkyung | self.setWindowTitle(_translate(f"{App.NAME}({version}) - {project.name}", |
125 | f"{App.NAME}({version}) - {project.name}"))
|
||
126 | a6581e45 | humkyung | |
127 | e4b3e191 | humkyung | self.lineComboBox = QComboBox(self.toolBar) |
128 | 3a9d8155 | humkyung | for condition in LineTypeConditions.items(): |
129 | self.lineComboBox.addItem(condition.name)
|
||
130 | e4003ced | esham21 | |
131 | configs = docData.getConfigs('Line', 'Default Type') |
||
132 | value = configs[0].value if 1 == len(configs) else '' |
||
133 | if value:
|
||
134 | at = self.lineComboBox.findText(value)
|
||
135 | self.lineComboBox.setCurrentIndex(at)
|
||
136 | else:
|
||
137 | at = self.lineComboBox.findText('Secondary') |
||
138 | self.lineComboBox.setCurrentIndex(at)
|
||
139 | #self.lineComboBox.currentIndexChanged.connect(self.onLineTypeChanged)
|
||
140 | 0ea718ad | humkyung | |
141 | d05d80dc | humkyung | self.toolBar.insertWidget(self.actionOCR, self.lineComboBox) |
142 | self.toolBar.insertSeparator(self.actionOCR) |
||
143 | 853df487 | humkyung | |
144 | 7e77874e | humkyung | self.graphicsView = QtImageViewer.QtImageViewer(self) |
145 | self.graphicsView.setParent(self.centralwidget) |
||
146 | 853df487 | humkyung | self.graphicsView.useDefaultCommand() # USE DEFAULT COMMAND |
147 | 7e77874e | humkyung | self.graphicsView.setMouseTracking(True) |
148 | self.graphicsView.viewport().installEventFilter(self) |
||
149 | |||
150 | 835465ff | humkyung | self._display_widget = QWidget()
|
151 | layout = QVBoxLayout() |
||
152 | self._by_line_no = QRadioButton()
|
||
153 | self._by_line_no.setChecked(True) |
||
154 | 43f6ca32 | esham21 | self._by_line_no.setText('By Group') |
155 | 2829806b | humkyung | self._by_line_no.toggled.connect(self.display_colors) |
156 | 835465ff | humkyung | layout.addWidget(self._by_line_no)
|
157 | self._by_line_type = QRadioButton()
|
||
158 | f28d5e17 | esham21 | self._by_line_type.setText('By Type') |
159 | 835465ff | humkyung | layout.addWidget(self._by_line_type)
|
160 | self._display_widget.setLayout(layout)
|
||
161 | 2829806b | humkyung | self.EditToolbar.insertWidget(None, self._display_widget) |
162 | 853df487 | humkyung | self._by_line_no.setChecked(
|
163 | True) if DisplayColors.instance().option == DisplayOptions.DisplayByLineNo else self._by_line_type.setChecked( |
||
164 | True)
|
||
165 | b192a44e | humkyung | |
166 | e4b3e191 | humkyung | self.verticalLayout.addWidget(self.graphicsView) |
167 | |||
168 | d52b3462 | 김정우 | # Add Custom TreeWidget
|
169 | b929957d | humkyung | self.dirTreeWidget = SymbolTreeWidget.QSymbolTreeWidget()
|
170 | 936111d1 | 김정우 | self.dirTreeWidget.header().hide()
|
171 | self.symbolTabVerticalLayout.addWidget(self.dirTreeWidget) |
||
172 | d52b3462 | 김정우 | |
173 | 936111d1 | 김정우 | # Add Custom Property TableWidget
|
174 | 6a2a7457 | humkyung | self.propertyTableWidget = SymbolPropertyTableWidget.QSymbolPropertyTableWidget()
|
175 | 936111d1 | 김정우 | self.symbolTabVerticalLayout.addWidget(self.propertyTableWidget) |
176 | self.dirTreeWidget.singleClicked.connect(self.propertyTableWidget.getClickedSymbol) |
||
177 | d8ddd93d | humkyung | # add splitter widget
|
178 | splitter = QSplitter(Qt.Vertical) |
||
179 | splitter.addWidget(self.dirTreeWidget)
|
||
180 | splitter.addWidget(self.propertyTableWidget)
|
||
181 | self.symbolTabVerticalLayout.addWidget(splitter)
|
||
182 | # up to here
|
||
183 | d52b3462 | 김정우 | |
184 | 0bcf00da | 김정우 | # Add Custom Result Tree Widget (Symbol Explorer)
|
185 | cac8d64c | humkyung | self.itemTreeWidget = ItemTreeWidget.QItemTreeWidget(self.graphicsView) |
186 | self.itemTreeWidget.header().hide()
|
||
187 | self.symbolExplorerVerticalLayout.addWidget(self.itemTreeWidget) |
||
188 | 0bcf00da | 김정우 | |
189 | # Add Empty Widget
|
||
190 | 0a9e44a7 | humkyung | self.resultPropertyTableWidget = ItemPropertyTableWidget.QItemPropertyTableWidget(self) |
191 | bddd799c | 김정우 | self.symbolExplorerVerticalLayout.addWidget(self.resultPropertyTableWidget) |
192 | cac8d64c | humkyung | self.itemTreeWidget.singleClicked.connect(self.resultPropertyTableWidget.onSymbolClicked) |
193 | self.itemTreeWidget.noteNoSingleClicked.connect(self.resultPropertyTableWidget.onNoteClicked) |
||
194 | self.itemTreeWidget.lineNoSingleClicked.connect(self.resultPropertyTableWidget.onLineNoClicked) |
||
195 | self.itemTreeWidget.drawingClicked.connect(self.resultPropertyTableWidget.onDrawingClicked) |
||
196 | d8ddd93d | humkyung | # add splitter widget
|
197 | splitter = QSplitter(Qt.Vertical) |
||
198 | cac8d64c | humkyung | splitter.addWidget(self.itemTreeWidget)
|
199 | bddd799c | 김정우 | splitter.addWidget(self.resultPropertyTableWidget)
|
200 | d8ddd93d | humkyung | self.symbolExplorerVerticalLayout.addWidget(splitter)
|
201 | # up to here
|
||
202 | 0bcf00da | 김정우 | |
203 | 65cdeb69 | 김정우 | # Initialize Action group
|
204 | d538864c | humkyung | self.actionGroup = QActionGroup(self) |
205 | self.actionGroup.addAction(self.actionRecognition) |
||
206 | self.actionGroup.addAction(self.actionLineRecognition) |
||
207 | self.actionGroup.addAction(self.actionLine) |
||
208 | self.actionGroup.addAction(self.actionGenerateOutput) |
||
209 | self.actionGroup.addAction(self.actionOCR) |
||
210 | self.actionGroup.addAction(self.actionZoom) |
||
211 | self.actionGroup.addAction(self.actionFitWindow) |
||
212 | self.actionGroup.addAction(self.actionSave) |
||
213 | 2605a8f9 | esham21 | self.actionGroup.addAction(self.actionValidate) |
214 | 00f34471 | esham21 | self.actionGroup.addAction(self.actionVendor) |
215 | d538864c | humkyung | self.actionGroup.triggered.connect(self.actionGroupTriggered) |
216 | 65cdeb69 | 김정우 | |
217 | e4b3e191 | humkyung | # connect signals and slots
|
218 | self.actionClose.triggered.connect(self.close) |
||
219 | 25e0cacb | Gyusu | self.actionOpen.triggered.connect(self.onOpenImageDrawing) |
220 | self.actionLine.triggered.connect(self.onPlaceLine) |
||
221 | e4b3e191 | humkyung | self.actionRecognition.triggered.connect(self.recognize) |
222 | b25fca04 | esham21 | self.pushButtonBatchRecognition.clicked.connect(self.recognizeBatch) |
223 | 7da8145f | humkyung | self.pushButtonRefreshDrawings.clicked.connect(self.load_drawing_list) |
224 | df4661c5 | humkyung | self.actionLineRecognition.triggered.connect(self.connect_attributes) |
225 | 4c612af8 | humkyung | self.actionArea.triggered.connect(self.areaConfiguration) |
226 | e4b3e191 | humkyung | self.actionConfiguration.triggered.connect(self.configuration) |
227 | 42e5fdf3 | humkyung | self.actionOCR.triggered.connect(self.onAreaOcr) |
228 | 68ce37ea | humkyung | self.actionGenerateOutput.triggered.connect(self.generateOutput) |
229 | ec750c78 | humkyung | self.pushButtonCreateSymbol.clicked.connect(self.onCreateSymbolClicked) |
230 | 0a9e44a7 | humkyung | self.pushButtonClearLog.clicked.connect(self.onClearLog) |
231 | 25e0cacb | Gyusu | self.actionHMB_DATA.triggered.connect(self.onHMBData) |
232 | eb71581d | gaqhf | self.actionItem_Data_List.triggered.connect(self.showItemDataList) |
233 | d35a6081 | esham21 | self.actionText_Data_List.triggered.connect(self.showTextDataList) |
234 | 853df487 | humkyung | self.actionSpecialItemTypes.triggered.connect(self.on_show_special_item_types) # show special item types dialog |
235 | self.actionDataTransfer.triggered.connect(self.on_show_data_transfer) # show data transfer dialog |
||
236 | 7fb00532 | humkyung | self.actionDataExport.triggered.connect(self.on_show_data_export) |
237 | eea44d8f | humkyung | self.actionExportEqpDatasheet.triggered.connect(
|
238 | self.on_show_eqp_datasheet_export) # show eqp datasheet export dialog |
||
239 | 853df487 | humkyung | self.actionOPCRelation.triggered.connect(self.on_show_opc_relation) # show OPC Relation dialog |
240 | 25e0cacb | Gyusu | self.actionCodeTable.triggered.connect(self.onShowCodeTable) |
241 | 081b7311 | humkyung | self.actionImage_Drawing.triggered.connect(self.onViewImageDrawing) |
242 | 2e2b4a3f | esham21 | self.actionDrawing_Only.triggered.connect(self.onViewDrawingOnly) |
243 | 2605a8f9 | esham21 | self.actionValidate.triggered.connect(self.onValidation) |
244 | 081b7311 | humkyung | self.actionViewText.triggered.connect(self.onViewText) |
245 | self.actionViewSymbol.triggered.connect(self.onViewSymbol) |
||
246 | self.actionViewLine.triggered.connect(self.onViewLine) |
||
247 | self.actionViewUnknown.triggered.connect(self.onViewUnknown) |
||
248 | ac91a3d7 | esham21 | self.actionViewInconsistency.triggered.connect(self.onViewInconsistency) |
249 | 35bbca8a | esham21 | self.actionViewVendor_Area.triggered.connect(self.onViewVendorArea) |
250 | d05d80dc | humkyung | self.actionRotate.triggered.connect(self.onRotate) |
251 | 42e5fdf3 | humkyung | self.actionZoom.triggered.connect(self.onAreaZoom) |
252 | 00f34471 | esham21 | self.actionVendor.triggered.connect(self.onVendor) |
253 | 594bbd9c | 김정우 | self.actionFitWindow.triggered.connect(self.fitWindow) |
254 | 25e0cacb | Gyusu | self.actionpdf_to_image.triggered.connect(self.onConvertPDFToImage) |
255 | a3aa5583 | esham21 | self.actionImport_Text_From_CAD.triggered.connect(self.onImportTextFromCAD) |
256 | 01fc42a0 | esham21 | self.actionSymbol_Thickness_Reinforcement.triggered.connect(self.onSymbolThickness) |
257 | bbcf500e | humkyung | self.actionHelp.triggered.connect(self.on_help) |
258 | 0ea718ad | humkyung | self.graphicsView.scene.selectionChanged.connect(self.onSelectionChanged) |
259 | 18e32014 | humkyung | self.actionInitialize.triggered.connect(self.onInitializeScene) |
260 | 0daf070c | gaqhf | self.actionSave.triggered.connect(self.actionSaveCliked) |
261 | e65b0bf8 | humkyung | self.addMessage.connect(self.onAddMessage) |
262 | afeab967 | gaqhf | self.actionFindReplaceText.triggered.connect(self.findReplaceTextClicked) |
263 | 7c8eb42b | gaqhf | self.pushButtonDetectSymbol.clicked.connect(self.onShowDetectSymbol) |
264 | 0de8c1ca | esham21 | #self.graphicsView.scene.contents_changed.connect(self.scene_changed)
|
265 | 8dd11a1f | humkyung | |
266 | configs = docData.getAppConfigs('app', 'mode') |
||
267 | if configs and 1 == len(configs) and 'advanced' == configs[0].value: |
||
268 | self.actionOCR_Training.triggered.connect(self.oCRTrainingClicked) |
||
269 | 35eb686f | esham21 | self.actionSymbol_Training.triggered.connect(self.symbolTrainingClicked) |
270 | 8dd11a1f | humkyung | else:
|
271 | self.actionOCR_Training.setVisible(False) |
||
272 | 35eb686f | esham21 | self.actionSymbol_Training.setVisible(False) |
273 | 5c89a091 | esham21 | self.pushButtonBatchRecognition.setVisible(False) |
274 | eda9685a | esham21 | self.pushButtonCreateSymbol.setVisible(False) |
275 | self.pushButtonDetectSymbol.setVisible(False) |
||
276 | 7c8eb42b | gaqhf | |
277 | 269a15c8 | gaqhf | self.delimiter = '"' |
278 | 853df487 | humkyung | |
279 | 27ffc4ac | gaqhf | self.resizeDocks({self.dockWidget}, {self.dockWidgetObjectExplorer.sizeHint().width()}, Qt.Horizontal) |
280 | 269a15c8 | gaqhf | |
281 | daa1b7d0 | humkyung | self.treeWidgetDrawingList.setHeaderHidden(False) |
282 | self.treeWidgetDrawingList.header().setStretchLastSection(False) |
||
283 | f5709716 | humkyung | self.treeWidgetDrawingList.setHeaderLabels([self.tr('Name'), self.tr('DateTime')]) |
284 | c28d2e4c | esham21 | self.treeWidgetDrawingList.header().setSectionResizeMode(0, QHeaderView.ResizeToContents) |
285 | self.treeWidgetDrawingList.header().setSectionResizeMode(1, QHeaderView.ResizeToContents) |
||
286 | 21fc8683 | humkyung | self.treeWidgetDrawingList.itemDoubleClicked.connect(self.open_selected_drawing) |
287 | self.load_drawing_list()
|
||
288 | |||
289 | dbc1b32f | humkyung | # load stylesheet file list
|
290 | 4af2f2de | humkyung | stylesheet_name = QtWidgets.qApp.stylesheet_name |
291 | 853df487 | humkyung | files = [os.path.splitext(file)[0] for file in os.listdir(os.path.dirname(os.path.realpath(__file__))) if |
292 | os.path.splitext(file)[1] == '.qss'] |
||
293 | dbc1b32f | humkyung | for file in files: |
294 | action = self.menuTheme.addAction(file) |
||
295 | 4af2f2de | humkyung | action.setCheckable(True)
|
296 | action.setChecked(True) if stylesheet_name == file else action.setChecked(False) |
||
297 | dbc1b32f | humkyung | action.triggered.connect(partial(self.load_stylesheet, file)) |
298 | # up to here
|
||
299 | |||
300 | 02b1bbcb | humkyung | # load language files
|
301 | language_name = QtWidgets.qApp.language_name |
||
302 | 853df487 | humkyung | files = ['en_us'] # englisgh is default language |
303 | files.extend([os.path.splitext(file)[0] for file in |
||
304 | os.listdir(os.path.join(os.path.dirname(os.path.realpath(__file__)), 'translate')) if |
||
305 | os.path.splitext(file)[1] == '.qm']) |
||
306 | 02b1bbcb | humkyung | for file in files: |
307 | action = self.menuLanguage.addAction(file) |
||
308 | action.setCheckable(True)
|
||
309 | action.setChecked(True) if language_name.lower() == file.lower() else action.setChecked(False) |
||
310 | action.triggered.connect(partial(self.load_language, file)) |
||
311 | # up to here
|
||
312 | |||
313 | 41484c18 | esham21 | # inconsistency table
|
314 | e72e864f | humkyung | self.tableWidgetInconsistency.setColumnCount(3) |
315 | self.tableWidgetInconsistency.setHorizontalHeaderLabels(['Owner', 'Type', 'Message']) |
||
316 | c2a5bd1f | esham21 | self.tableWidgetInconsistency.setEditTriggers(QAbstractItemView.NoEditTriggers)
|
317 | 41484c18 | esham21 | self.tableWidgetInconsistency.itemClicked.connect(self.inconsistencyItemClickEvent) |
318 | c2a5bd1f | esham21 | self.tableWidgetInconsistency.keyPressEvent = self.inconsistencyTableKeyPressEvent |
319 | d3b7de6d | esham21 | self.tableWidgetInconsistency.setSortingEnabled(True) |
320 | 41484c18 | esham21 | |
321 | 2829806b | humkyung | def eventFilter(self, source, event): |
322 | 54eedb38 | humkyung | """display mouse position of graphics view"""
|
323 | 2829806b | humkyung | if (event.type() == QEvent.MouseMove):
|
324 | pos = self.graphicsView.mapToScene(event.pos())
|
||
325 | self._label_mouse.setText('mouse pos : ({},{})'.format(round(pos.x()), round(pos.y()))) |
||
326 | |||
327 | return QWidget.eventFilter(self, source, event) |
||
328 | |||
329 | 77616eee | esham21 | def closeEvent(self, event): |
330 | 54eedb38 | humkyung | """ask user to save drawing which is modified"""
|
331 | |||
332 | self.save_drawing_if_necessary()
|
||
333 | 77616eee | esham21 | AppDocData.instance().clear() |
334 | 54eedb38 | humkyung | event.accept() |
335 | 77616eee | esham21 | |
336 | 4077103a | esham21 | def inconsistencyTableKeyPressEvent(self, event): |
337 | try:
|
||
338 | c2a5bd1f | esham21 | row = self.tableWidgetInconsistency.selectedIndexes()[0].row() |
339 | col = self.tableWidgetInconsistency.selectedIndexes()[0].column() |
||
340 | from HighlightCommand import HighlightCommand |
||
341 | if event.key() == Qt.Key_Up:
|
||
342 | if row is not 0: |
||
343 | errorItem = self.tableWidgetInconsistency.item(row - 1, 1).tag |
||
344 | HighlightCommand(self.graphicsView).execute(errorItem)
|
||
345 | elif event.key() == Qt.Key_Down:
|
||
346 | if row is not self.tableWidgetInconsistency.rowCount() - 1: |
||
347 | errorItem = self.tableWidgetInconsistency.item(row + 1, 1).tag |
||
348 | HighlightCommand(self.graphicsView).execute(errorItem)
|
||
349 | e72e864f | humkyung | elif event.key() == Qt.Key_Delete:
|
350 | item = self.tableWidgetInconsistency.item(row, 0).tag |
||
351 | if item and item.scene(): item.scene().removeItem(item) |
||
352 | self.tableWidgetInconsistency.removeRow(row)
|
||
353 | c2a5bd1f | esham21 | except Exception as ex: |
354 | e57134bc | esham21 | message = 'error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, |
355 | 853df487 | humkyung | sys.exc_info()[-1].tb_lineno)
|
356 | e72e864f | humkyung | self.addMessage.emit(MessageType.Error, message)
|
357 | 853df487 | humkyung | # finally:
|
358 | 0c8812bd | esham21 | # return QTableView.keyPressEvent(self.tableWidgetInconsistency, event)
|
359 | 4077103a | esham21 | |
360 | 2605a8f9 | esham21 | def onValidation(self): |
361 | """
|
||
362 | @brief validation check
|
||
363 | @author euisung
|
||
364 | @date 2019.04.01
|
||
365 | """
|
||
366 | e72e864f | humkyung | from ValidateCommand import ValidateCommand |
367 | |||
368 | 2605a8f9 | esham21 | if not self.graphicsView.hasImage(): |
369 | self.showImageSelectionMessageBox()
|
||
370 | return
|
||
371 | |||
372 | 5ed3c39a | humkyung | try:
|
373 | e72e864f | humkyung | # remove error items
|
374 | 5ed3c39a | humkyung | for item in self.graphicsView.scene.items(): |
375 | if type(item) is QEngineeringErrorItem: |
||
376 | item.transfer.onRemoved.emit(item) |
||
377 | e72e864f | humkyung | # up to here
|
378 | 5ed3c39a | humkyung | |
379 | e72e864f | humkyung | cmd = ValidateCommand(self.graphicsView)
|
380 | errors = cmd.execute(self.graphicsView.scene.items())
|
||
381 | 5ed3c39a | humkyung | for error in errors: |
382 | error.transfer.onRemoved.connect(self.itemRemoved)
|
||
383 | self.graphicsView.scene.addItem(error)
|
||
384 | |||
385 | self.tableWidgetInconsistency.clearContents()
|
||
386 | self.tableWidgetInconsistency.setRowCount(len(errors)) |
||
387 | for index in range(len(errors)): |
||
388 | e72e864f | humkyung | self.makeInconsistencyTableRow(index, errors[index])
|
389 | 5ed3c39a | humkyung | except Exception as ex: |
390 | e57134bc | esham21 | message = 'error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, |
391 | 853df487 | humkyung | sys.exc_info()[-1].tb_lineno)
|
392 | 5ed3c39a | humkyung | self.addMessage.emit(MessageType.Error, message)
|
393 | 41484c18 | esham21 | |
394 | e72e864f | humkyung | def makeInconsistencyTableRow(self, row, errorItem): |
395 | 379f603c | esham21 | '''
|
396 | @brief make row data for inconsistency widget
|
||
397 | @author euisung
|
||
398 | @date 2019.04.16
|
||
399 | '''
|
||
400 | e72e864f | humkyung | |
401 | item = QTableWidgetItem(str(errorItem.parent))
|
||
402 | 379f603c | esham21 | item.tag = errorItem |
403 | e72e864f | humkyung | self.tableWidgetInconsistency.setItem(row, 0, item) |
404 | 379f603c | esham21 | |
405 | e72e864f | humkyung | item = QTableWidgetItem(str(type(errorItem.parent))) |
406 | 379f603c | esham21 | item.tag = errorItem |
407 | e72e864f | humkyung | self.tableWidgetInconsistency.setItem(row, 1, item) |
408 | 379f603c | esham21 | |
409 | e72e864f | humkyung | item = QTableWidgetItem(errorItem.msg) |
410 | item.tag = errorItem |
||
411 | self.tableWidgetInconsistency.setItem(row, 2, item) |
||
412 | 379f603c | esham21 | |
413 | 41484c18 | esham21 | def inconsistencyItemClickEvent(self, item): |
414 | """
|
||
415 | @brief inconsistency table item clicked
|
||
416 | @author euisung
|
||
417 | @date 2019.04.02
|
||
418 | """
|
||
419 | from HighlightCommand import HighlightCommand |
||
420 | |||
421 | HighlightCommand(self.graphicsView).execute(item.tag)
|
||
422 | 2605a8f9 | esham21 | |
423 | dbc1b32f | humkyung | def load_stylesheet(self, file): |
424 | """
|
||
425 | @brief load stylesheets
|
||
426 | @author humkyung
|
||
427 | @date 2018.10.29
|
||
428 | """
|
||
429 | |||
430 | QtWidgets.qApp.loadStyleSheet(os.path.join(os.path.dirname(os.path.realpath(__file__)), file))
|
||
431 | |||
432 | 4af2f2de | humkyung | app_doc_data = AppDocData.instance() |
433 | configs = [Config('app', 'stylesheet', file)] |
||
434 | app_doc_data.saveAppConfigs(configs) |
||
435 | 853df487 | humkyung | |
436 | 4af2f2de | humkyung | for action in self.menuTheme.actions(): |
437 | if action.text() == file: continue |
||
438 | action.setChecked(False)
|
||
439 | |||
440 | 02b1bbcb | humkyung | def load_language(self, file): |
441 | """
|
||
442 | load language file and then apply selected language
|
||
443 | """
|
||
444 | try:
|
||
445 | qm_file = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'translate', '{0}.qm'.format(file)) |
||
446 | QtWidgets.qApp.load_language(qm_file) |
||
447 | |||
448 | app_doc_data = AppDocData.instance() |
||
449 | configs = [Config('app', 'language', file)] |
||
450 | app_doc_data.saveAppConfigs(configs) |
||
451 | 853df487 | humkyung | |
452 | 02b1bbcb | humkyung | for action in self.menuLanguage.actions(): |
453 | if action.text().lower() == file.lower(): continue |
||
454 | action.setChecked(False)
|
||
455 | finally:
|
||
456 | self.retranslateUi(self) |
||
457 | self.propertyTableWidget.retranslateUi()
|
||
458 | |||
459 | 21fc8683 | humkyung | '''
|
460 | @brief Clear TreeWidget and Set Current PID
|
||
461 | @author Jeongwoo
|
||
462 | @date 18.04.11
|
||
463 | @history 2018.04.26 Jeongwoo Add Child [SYMBOLS, NOTES] into root item
|
||
464 | 2018.05.09 Jeongwoo Change method to add default tree items
|
||
465 | humkyung 2018.06.10 add tree item for Line No and Unknown Item
|
||
466 | '''
|
||
467 | 853df487 | humkyung | |
468 | 21fc8683 | humkyung | def load_drawing_list(self): |
469 | 436a3d81 | humkyung | """load p&id drawing list"""
|
470 | 34b1790c | esham21 | from Drawing import Drawing |
471 | 21fc8683 | humkyung | |
472 | daa1b7d0 | humkyung | try:
|
473 | 436a3d81 | humkyung | app_doc_data = AppDocData.instance() |
474 | drawings = app_doc_data.getDrawings() |
||
475 | daa1b7d0 | humkyung | |
476 | self.treeWidgetDrawingList.clear()
|
||
477 | 853df487 | humkyung | self.treeWidgetDrawingList.root = QTreeWidgetItem(self.treeWidgetDrawingList, |
478 | [self.tr('P&ID Drawings'), '']) |
||
479 | self.treeWidgetDrawingList.root.setFlags(
|
||
480 | self.treeWidgetDrawingList.root.flags() | Qt.ItemIsTristate | Qt.ItemIsUserCheckable)
|
||
481 | 2e91029b | esham21 | self.treeWidgetDrawingList.root.setCheckState(0, Qt.Unchecked) |
482 | 436a3d81 | humkyung | files = app_doc_data.getDrawingFileList() |
483 | daa1b7d0 | humkyung | for file in files: |
484 | c2b9f64e | gaqhf | drawing = [drawing for drawing in drawings if drawing.name == file] |
485 | if not drawing or not drawing[0].UID: |
||
486 | drawings.append(Drawing(None, file, None)) |
||
487 | daa1b7d0 | humkyung | |
488 | 853df487 | humkyung | item = QTreeWidgetItem(self.treeWidgetDrawingList.root,
|
489 | [file, drawing[0].datetime if drawing else None]) |
||
490 | daa1b7d0 | humkyung | item.setIcon(0, QIcon(':newPrefix/image.png')) |
491 | 82e5790e | esham21 | item.setFlags(item.flags() | Qt.ItemIsUserCheckable) |
492 | item.setCheckState(0, Qt.Unchecked)
|
||
493 | 853df487 | humkyung | |
494 | self.treeWidgetDrawingList.root.setText(0, self.tr('P&ID Drawings') + '({})'.format( |
||
495 | self.treeWidgetDrawingList.root.childCount()))
|
||
496 | daa1b7d0 | humkyung | self.treeWidgetDrawingList.expandItem(self.treeWidgetDrawingList.root) |
497 | self.treeWidgetDrawingList.root.sortChildren(0, Qt.AscendingOrder) |
||
498 | self.treeWidgetDrawingList.resizeColumnToContents(0) |
||
499 | 21fc8683 | humkyung | |
500 | 436a3d81 | humkyung | app_doc_data.saveDrawings(drawings) |
501 | daa1b7d0 | humkyung | except Exception as ex: |
502 | eea44d8f | humkyung | message = 'error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, |
503 | 853df487 | humkyung | sys.exc_info()[-1].tb_lineno)
|
504 | daa1b7d0 | humkyung | self.addMessage.emit(MessageType.Error, message)
|
505 | 21fc8683 | humkyung | |
506 | def open_selected_drawing(self, item, column): |
||
507 | """
|
||
508 | @brief open selected p&id drawing
|
||
509 | @author humkyung
|
||
510 | @date 18.11.02
|
||
511 | """
|
||
512 | appDocData = AppDocData.instance() |
||
513 | f1632ad7 | esham21 | drawing = os.path.join(appDocData.getCurrentProject().getDrawingFilePath(), item.text(0))
|
514 | 21fc8683 | humkyung | self.onOpenImageDrawing(drawing)
|
515 | |||
516 | 7c8eb42b | gaqhf | def onShowDetectSymbol(self): |
517 | from DetectSymbolDialog import QDetectSymbolDialog |
||
518 | |||
519 | 100c12cd | gaqhf | dlgDetectSymbol = QDetectSymbolDialog(self)
|
520 | 7c8eb42b | gaqhf | dlgDetectSymbol.show() |
521 | dlgDetectSymbol.exec_() |
||
522 | 853df487 | humkyung | |
523 | 6518bfbe | esham21 | '''
|
524 | @brief OCR Editor
|
||
525 | @author euisung
|
||
526 | @date 2018.10.05
|
||
527 | ff768aea | esham21 | @history 2018.10.16 euisung no more used, Integrated with oCRTrainingClicked
|
528 | 6518bfbe | esham21 | '''
|
529 | 853df487 | humkyung | |
530 | 6518bfbe | esham21 | def oCRTrainingEdidorClicked(self): |
531 | from TrainingEditorDialog import QTrainingEditorDialog |
||
532 | |||
533 | try:
|
||
534 | dialog = QTrainingEditorDialog(self)
|
||
535 | dialog.exec_() |
||
536 | except Exception as ex: |
||
537 | e57134bc | esham21 | message = 'error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, |
538 | 853df487 | humkyung | sys.exc_info()[-1].tb_lineno)
|
539 | 25959e37 | humkyung | self.addMessage.emit(MessageType.Error, message)
|
540 | 853df487 | humkyung | |
541 | 6518bfbe | esham21 | return
|
542 | 7c8eb42b | gaqhf | |
543 | 3be6727a | gaqhf | '''
|
544 | 1669b150 | esham21 | @brief OCR Training
|
545 | @author euisung
|
||
546 | @date 2018.09.27
|
||
547 | @history euisung 2018.10.16 TrainingListDialog -> TrainingImageListDialog
|
||
548 | '''
|
||
549 | 853df487 | humkyung | |
550 | 1669b150 | esham21 | def oCRTrainingClicked(self): |
551 | try:
|
||
552 | dialog = QTrainingImageListDialog(self)
|
||
553 | dialog.exec_() |
||
554 | except Exception as ex: |
||
555 | e57134bc | esham21 | message = 'error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, |
556 | 853df487 | humkyung | sys.exc_info()[-1].tb_lineno)
|
557 | 25959e37 | humkyung | self.addMessage.emit(MessageType.Error, message)
|
558 | 1669b150 | esham21 | |
559 | 35eb686f | esham21 | |
560 | def symbolTrainingClicked(self): |
||
561 | try:
|
||
562 | dialog = QTrainingSymbolImageListDialog(self)
|
||
563 | dialog.exec_() |
||
564 | except Exception as ex: |
||
565 | message = 'error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, |
||
566 | sys.exc_info()[-1].tb_lineno)
|
||
567 | self.addMessage.emit(MessageType.Error, message)
|
||
568 | |||
569 | 1669b150 | esham21 | '''
|
570 | 59643c3f | humkyung | @brief show unknownitem's count
|
571 | 6929ebfb | gaqhf | @author kyouho
|
572 | @date 2018.08.27
|
||
573 | '''
|
||
574 | 853df487 | humkyung | |
575 | afeab967 | gaqhf | def findReplaceTextClicked(self): |
576 | 8fd45efa | gaqhf | if not self.graphicsView.hasImage(): |
577 | self.showImageSelectionMessageBox()
|
||
578 | return
|
||
579 | |||
580 | from TextItemEditDialog import QTextItemEditDialog |
||
581 | |||
582 | self.dlgTextItemEdit = QTextItemEditDialog(self) |
||
583 | self.dlgTextItemEdit.show()
|
||
584 | self.dlgTextItemEdit.exec_()
|
||
585 | 6929ebfb | gaqhf | |
586 | db336ebd | humkyung | def display_number_of_items(self): |
587 | """display count of symbol, line, text"""
|
||
588 | 853df487 | humkyung | |
589 | 59643c3f | humkyung | items = [item for item in self.graphicsView.scene.items() if type(item) is QEngineeringUnknownItem] |
590 | if len(items) > 0: |
||
591 | 853df487 | humkyung | self.labelStatus.setText(
|
592 | "<font color='red'>" + self.tr('Unrecognition') + " : {}</font>".format(len(items))) |
||
593 | 59643c3f | humkyung | else:
|
594 | 853df487 | humkyung | self.labelStatus.setText(
|
595 | "<font color='black'>" + self.tr('Unrecognition') + " : {}</font>".format(len(items))) |
||
596 | 59643c3f | humkyung | |
597 | 853df487 | humkyung | items = [item for item in self.graphicsView.scene.items() if |
598 | issubclass(type(item), SymbolSvgItem) and type(item) is not QEngineeringErrorItem] |
||
599 | f5709716 | humkyung | self.labelSymbolStatus.setText("<font color='blue'>" + self.tr('Symbol') + " : {}</font>".format(len(items))) |
600 | f7ada1c1 | humkyung | |
601 | items = [item for item in self.graphicsView.scene.items() if type(item) is QEngineeringLineItem] |
||
602 | f5709716 | humkyung | self.labelLineStatus.setText("<font color='blue'>" + self.tr('Line') + " : {}</font>".format(len(items))) |
603 | f7ada1c1 | humkyung | |
604 | items = [item for item in self.graphicsView.scene.items() if issubclass(type(item), QEngineeringTextItem)] |
||
605 | f5709716 | humkyung | self.labelTextStatus.setText("<font color='blue'>" + self.tr('Text') + " : {}</font>".format(len(items))) |
606 | f7ada1c1 | humkyung | |
607 | cac8d64c | humkyung | self.itemTreeWidget.sceneChanged(self.graphicsView.scene.items()) |
608 | 6ee64d77 | humkyung | |
609 | 478c2510 | esham21 | def dbUpdate(self): |
610 | '''
|
||
611 | @brief db update when save or recognition
|
||
612 | @author euisung
|
||
613 | @date 2018.11.12
|
||
614 | fadd4d82 | esham21 | @history 2018.11.02 euisung remove scene dependency
|
615 | 478c2510 | esham21 | '''
|
616 | 29fa6d45 | humkyung | try:
|
617 | appDocData = AppDocData.instance() |
||
618 | 478c2510 | esham21 | |
619 | 29fa6d45 | humkyung | titleBlockProps = appDocData.getTitleBlockProperties() |
620 | 853df487 | humkyung | # items = self.graphicsView.scene.items()
|
621 | 29fa6d45 | humkyung | items = appDocData.allItems |
622 | titleBlockItems = [] |
||
623 | for item in items: |
||
624 | 853df487 | humkyung | # if type(item) is QEngineeringLineNoTextItem:
|
625 | 1f8d3435 | esham21 | # item.saveLineData()
|
626 | if type(item) is QEngineeringTextItem: |
||
627 | 29fa6d45 | humkyung | for titleBlockProp in titleBlockProps: |
628 | if item.area == titleBlockProp[0]: |
||
629 | titleBlockItems.append(item) |
||
630 | |||
631 | 6f0d136d | esham21 | # unknown item is not saved now for performance
|
632 | db_items = [item for item in items if issubclass(type(item), QEngineeringAbstractItem) and type(item) is not QGraphicsBoundingBoxItem and type(item) is not QEngineeringErrorItem and type(item) is not QEngineeringLineNoTextItem and type(item) is not QEngineeringUnknownItem] |
||
633 | 746c8f97 | esham21 | db_items.extend([item for item in items if type(item) is QEngineeringLineNoTextItem]) |
634 | db_items.extend([line for line in appDocData.tracerLineNos if type(line) is QEngineeringTrimLineNoTextItem]) |
||
635 | db_items.extend(titleBlockItems) |
||
636 | 02d50c2c | esham21 | configs = appDocData.getConfigs('Data Load', 'Xml First') |
637 | if configs and int(configs[0].value) is 1: |
||
638 | db_items.extend([item for item in items if type(item) is QEngineeringUnknownItem]) |
||
639 | |||
640 | 746c8f97 | esham21 | '''
|
641 | 853df487 | humkyung | dbItems = [item for item in items if
|
642 | type(item) is QEngineeringInstrumentItem or type(item) is QEngineeringEquipmentItem or type(
|
||
643 | item) is QEngineeringReducerItem or \
|
||
644 | type(item) is QEngineeringNoteItem or type(item) is SymbolSvgItem or type(
|
||
645 | item) is QEngineeringLineNoTextItem or type(
|
||
646 | item) is QEngineeringVendorItem] + titleBlockItems
|
||
647 | 746c8f97 | esham21 | '''
|
648 | appDocData.saveToDatabase(db_items) |
||
649 | 29fa6d45 | humkyung | except Exception as ex: |
650 | e57134bc | esham21 | message = 'error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, |
651 | 853df487 | humkyung | sys.exc_info()[-1].tb_lineno)
|
652 | 29fa6d45 | humkyung | self.addMessage.emit(MessageType.Error, message)
|
653 | 478c2510 | esham21 | |
654 | 54eedb38 | humkyung | def save_drawing_if_necessary(self): |
655 | """ask to user to save drawing or not when drawing is modified"""
|
||
656 | |||
657 | app_doc_data = AppDocData.instance() |
||
658 | if app_doc_data.activeDrawing and app_doc_data.activeDrawing.modified: |
||
659 | if QMessageBox.Yes == QMessageBox.question(self, self.tr("Question"), |
||
660 | self.tr("Do you want to save drawing?"), |
||
661 | QMessageBox.Yes | QMessageBox.No): |
||
662 | self.actionSaveCliked()
|
||
663 | |||
664 | 59643c3f | humkyung | '''
|
665 | 0daf070c | gaqhf | @brief action save click event
|
666 | @author kyouho
|
||
667 | @date 2018.08.09
|
||
668 | c2230d59 | esham21 | @history 2018.11.02 euisung add line data list db update
|
669 | daa1b7d0 | humkyung | humkyung save saved time to database
|
670 | c2230d59 | esham21 | 2018.11.05 euisung add note data list db update
|
671 | 2018.11.05 euisung add db delete process before save
|
||
672 | 478c2510 | esham21 | 2018.11.12 euisung db part move new method to dbUpdate
|
673 | 0daf070c | gaqhf | '''
|
674 | 853df487 | humkyung | |
675 | 0daf070c | gaqhf | def actionSaveCliked(self): |
676 | 16cf1212 | humkyung | from EngineeringAbstractItem import QEngineeringAbstractItem |
677 | 853df487 | humkyung | from SaveWorkCommand import SaveWorkCommand |
678 | daa1b7d0 | humkyung | |
679 | 3ec1874a | humkyung | try:
|
680 | 54eedb38 | humkyung | app_doc_data = AppDocData.instance() |
681 | if app_doc_data.imgName is None: |
||
682 | 3ec1874a | humkyung | self.showImageSelectionMessageBox()
|
683 | return
|
||
684 | daa1b7d0 | humkyung | |
685 | 54eedb38 | humkyung | app_doc_data.clearItemList(False)
|
686 | e060a623 | esham21 | |
687 | 3ec1874a | humkyung | items = self.graphicsView.scene.items()
|
688 | for item in items: |
||
689 | 16cf1212 | humkyung | if issubclass(type(item), QEngineeringAbstractItem): |
690 | 54eedb38 | humkyung | app_doc_data.allItems.append(item) |
691 | 3ec1874a | humkyung | if issubclass(type(item), QEngineeringTextItem): |
692 | 54eedb38 | humkyung | app_doc_data.texts.append(item) |
693 | 52e28a3a | humkyung | |
694 | 3ec1874a | humkyung | itemTypes = [] |
695 | for item in items: |
||
696 | typeExist = False
|
||
697 | for itemType in itemTypes: |
||
698 | if type(item) is itemType: |
||
699 | typeExist = True
|
||
700 | break
|
||
701 | if not typeExist: |
||
702 | itemTypes.append(type(item))
|
||
703 | |||
704 | 52e28a3a | humkyung | self._save_work_cmd = SaveWorkCommand()
|
705 | 436a3d81 | humkyung | self._save_work_cmd.show_progress.connect(self.progress_bar.setValue) |
706 | 52e28a3a | humkyung | self._save_work_cmd.display_message.connect(self.onAddMessage) |
707 | self._save_work_cmd.finished.connect(self.save_finished) |
||
708 | 3ec1874a | humkyung | |
709 | 52e28a3a | humkyung | self._save_work_cmd.start()
|
710 | c82b5644 | humkyung | except Exception as ex: |
711 | 54eedb38 | humkyung | message = 'error occurred({}) in {}:{}'.format(repr(ex), sys.exc_info()[-1].tb_frame.f_code.co_filename, |
712 | 853df487 | humkyung | sys.exc_info()[-1].tb_lineno)
|
713 | c82b5644 | humkyung | self.addMessage.emit(MessageType.Error, message)
|
714 | 3be6727a | gaqhf | |
715 | 52e28a3a | humkyung | def save_finished(self): |
716 | 436a3d81 | humkyung | """reload drawing list"""
|
717 | 54eedb38 | humkyung | |
718 | 7108869f | esham21 | self._save_work_cmd.show_progress.emit(100) |
719 | 436a3d81 | humkyung | QMessageBox.about(self.graphicsView, self.tr('Information'), self._save_work_cmd.resultStr) |
720 | 0a4292cc | esham21 | self.load_drawing_list()
|
721 | 52e28a3a | humkyung | |
722 | 54eedb38 | humkyung | app_doc_data = AppDocData.instance() |
723 | app_doc_data.activeDrawing.modified = False
|
||
724 | title = self.windowTitle()
|
||
725 | self.setWindowTitle(title[:-1] if title[-1] == '*' else title) |
||
726 | |||
727 | 25e0cacb | Gyusu | '''
|
728 | @brief refresh resultPropertyTableWidget
|
||
729 | @author kyouho
|
||
730 | @date 2018.07.19
|
||
731 | '''
|
||
732 | 853df487 | humkyung | |
733 | 25e0cacb | Gyusu | def refreshResultPropertyTableWidget(self): |
734 | items = self.graphicsView.scene.selectedItems()
|
||
735 | if len(items) == 1: |
||
736 | a208ed03 | humkyung | self.resultPropertyTableWidget.show_item_property(items[0]) |
737 | 853df487 | humkyung | |
738 | de640a0d | gaqhf | '''
|
739 | 0a9e44a7 | humkyung | @brief add message listwidget
|
740 | @author humkyung
|
||
741 | @date 2018.07.31
|
||
742 | '''
|
||
743 | 853df487 | humkyung | |
744 | e65b0bf8 | humkyung | def onAddMessage(self, messageType, message): |
745 | 0a9e44a7 | humkyung | from AppDocData import MessageType |
746 | |||
747 | try:
|
||
748 | current = QDateTime.currentDateTime() |
||
749 | |||
750 | item = QListWidgetItem('{}: {}'.format(current.toString('hh:mm:ss'), message)) |
||
751 | 29392b1a | esham21 | item.setFlags(item.flags() | Qt.ItemIsEditable) |
752 | 0a9e44a7 | humkyung | if messageType == MessageType.Error:
|
753 | item.setBackground(Qt.red) |
||
754 | |||
755 | self.listWidgetLog.insertItem(0, item) |
||
756 | except Exception as ex: |
||
757 | e57134bc | esham21 | print('error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, |
758 | 853df487 | humkyung | sys.exc_info()[-1].tb_lineno))
|
759 | 0a9e44a7 | humkyung | |
760 | '''
|
||
761 | @brief clear log
|
||
762 | @author humkyung
|
||
763 | @date 2018.08.01
|
||
764 | '''
|
||
765 | 853df487 | humkyung | |
766 | 0a9e44a7 | humkyung | def onClearLog(self): |
767 | self.listWidgetLog.clear()
|
||
768 | |||
769 | a63f247e | 김정우 | '''
|
770 | d05d80dc | humkyung | @brief rotate selected symbol
|
771 | @author humkyung
|
||
772 | @date 2018.08.15
|
||
773 | '''
|
||
774 | 853df487 | humkyung | |
775 | d05d80dc | humkyung | def onRotate(self, action): |
776 | selected = [item for item in self.graphicsView.scene.selectedItems() if issubclass(type(item), SymbolSvgItem)] |
||
777 | if len(selected) == 1: |
||
778 | selected[0].rotateSymbol()
|
||
779 | |||
780 | '''
|
||
781 | 594bbd9c | 김정우 | @brief Area Zoom
|
782 | @author Jeongwoo
|
||
783 | @date 2018.06.27
|
||
784 | 42e5fdf3 | humkyung | @history connect command's rejected signal
|
785 | 594bbd9c | 김정우 | '''
|
786 | 853df487 | humkyung | |
787 | 42e5fdf3 | humkyung | def onAreaZoom(self, action): |
788 | 594bbd9c | 김정우 | if self.actionZoom.isChecked(): |
789 | 42e5fdf3 | humkyung | cmd = AreaZoomCommand.AreaZoomCommand(self.graphicsView)
|
790 | cmd.onRejected.connect(self.onCommandRejected)
|
||
791 | self.graphicsView.command = cmd
|
||
792 | 594bbd9c | 김정우 | |
793 | 00f34471 | esham21 | def onVendor(self, action): |
794 | '''
|
||
795 | @brief make vendor package area
|
||
796 | @author euisung
|
||
797 | @date 2019.04.29
|
||
798 | '''
|
||
799 | if not self.graphicsView.hasImage(): |
||
800 | self.actionVendor.setChecked(False) |
||
801 | self.showImageSelectionMessageBox()
|
||
802 | return
|
||
803 | |||
804 | self.actionVendor.setChecked(True) |
||
805 | if not hasattr(self.actionVendor, 'tag'): |
||
806 | self.actionVendor.tag = PlacePolygonCommand.PlacePolygonCommand(self.graphicsView) |
||
807 | self.actionVendor.tag.onSuccess.connect(self.onVendorCreated) |
||
808 | self.actionVendor.tag.onRejected.connect(self.onCommandRejected) |
||
809 | |||
810 | self.graphicsView.command = self.actionVendor.tag |
||
811 | |||
812 | def onVendorCreated(self): |
||
813 | '''
|
||
814 | @brief add created vendor polygon area to scene
|
||
815 | @author euisung
|
||
816 | @date 2019.04.29
|
||
817 | '''
|
||
818 | try:
|
||
819 | 42318ecb | esham21 | count = len(self.actionVendor.tag._polyline._vertices) |
820 | if count > 2: |
||
821 | 35bbca8a | esham21 | qPoints = [] |
822 | 42318ecb | esham21 | points = [] |
823 | for point in self.actionVendor.tag._polyline._vertices: |
||
824 | 35bbca8a | esham21 | points.append([round(point[0]), round(point[1])]) |
825 | qPoints.append(QPoint(round(point[0]), round(point[1]))) |
||
826 | vendorArea = QPolygonF(qPoints) |
||
827 | vendorItem = QEngineeringVendorItem(vendorArea, points) |
||
828 | f15587ee | esham21 | vendorItem.area = 'Drawing'
|
829 | 35bbca8a | esham21 | vendorItem.transfer.onRemoved.connect(self.itemRemoved)
|
830 | 42318ecb | esham21 | self.graphicsView.scene.addItem(vendorItem)
|
831 | 00f34471 | esham21 | finally:
|
832 | self.graphicsView.scene.removeItem(self.actionVendor.tag._polyline) |
||
833 | self.actionVendor.tag.reset()
|
||
834 | |||
835 | 594bbd9c | 김정우 | '''
|
836 | @brief Fit Window
|
||
837 | @author Jeongwoo
|
||
838 | @date 2018.06.27
|
||
839 | d367d959 | 김정우 | @history 2018.06.27 Jeongwoo Chnage method to initialize command [Set None → DefaultCommand]
|
840 | 594bbd9c | 김정우 | '''
|
841 | 853df487 | humkyung | |
842 | 594bbd9c | 김정우 | def fitWindow(self, action): |
843 | d367d959 | 김정우 | self.graphicsView.useDefaultCommand()
|
844 | 594bbd9c | 김정우 | self.graphicsView.zoomImageInit()
|
845 | |||
846 | 54eedb38 | humkyung | def scene_changed(self): |
847 | """update modified flag"""
|
||
848 | |||
849 | db336ebd | humkyung | self.display_number_of_items()
|
850 | |||
851 | 54eedb38 | humkyung | app_doc_data = AppDocData.instance() |
852 | app_doc_data.activeDrawing.modified = True
|
||
853 | title = self.windowTitle()
|
||
854 | self.setWindowTitle(title if title[-1] == '*' else title + '*') |
||
855 | |||
856 | 62dc9ffa | humkyung | def onConvertPDFToImage(self): |
857 | """
|
||
858 | 25e0cacb | Gyusu | @brief convert to selected pdf to image
|
859 | @author humkyung
|
||
860 | @date 2018.07.09
|
||
861 | 59560085 | humkyung | @history Euisung 2018.10.11 hide shell
|
862 | 62dc9ffa | humkyung | """
|
863 | 853df487 | humkyung | try:
|
864 | filePath = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'bin64', 'PDF_TO_IMAGE.exe') |
||
865 | subprocess.call(filePath, shell=False)
|
||
866 | 25e0cacb | Gyusu | except Exception as ex: |
867 | e57134bc | esham21 | message = 'error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, |
868 | 853df487 | humkyung | sys.exc_info()[-1].tb_lineno)
|
869 | a3aa5583 | esham21 | self.addMessage.emit(MessageType.Error, message)
|
870 | |||
871 | def onImportTextFromCAD(self): |
||
872 | 01fc42a0 | esham21 | """ import text from cad """
|
873 | a3aa5583 | esham21 | try:
|
874 | self.onCommandRejected()
|
||
875 | dialog = QImportTextFromCADDialog(self)
|
||
876 | 27479ed9 | esham21 | dialog.show() |
877 | a3aa5583 | esham21 | dialog.exec_() |
878 | except Exception as ex: |
||
879 | e57134bc | esham21 | message = 'error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, |
880 | 853df487 | humkyung | sys.exc_info()[-1].tb_lineno)
|
881 | a3aa5583 | esham21 | self.addMessage.emit(MessageType.Error, message)
|
882 | 853df487 | humkyung | |
883 | 01fc42a0 | esham21 | def onSymbolThickness(self): |
884 | """ symbol thickness reinforcement by using configuration filter drawing dilate size """
|
||
885 | try:
|
||
886 | self.onCommandRejected()
|
||
887 | dialog = QSymbolThicknessDialog(self)
|
||
888 | dialog.exec_() |
||
889 | except Exception as ex: |
||
890 | e57134bc | esham21 | message = 'error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, |
891 | eea44d8f | humkyung | sys.exc_info()[-1].tb_lineno)
|
892 | 01fc42a0 | esham21 | self.addMessage.emit(MessageType.Error, message)
|
893 | eea44d8f | humkyung | |
894 | bbcf500e | humkyung | def on_help(self): |
895 | """ open help file """
|
||
896 | import os |
||
897 | |||
898 | 853df487 | humkyung | try:
|
899 | help_file_path = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'ID2 User Manual.pdf')
|
||
900 | bbcf500e | humkyung | os.system('"{}"'.format(help_file_path))
|
901 | except Exception as ex: |
||
902 | e57134bc | esham21 | message = 'error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, |
903 | 853df487 | humkyung | sys.exc_info()[-1].tb_lineno)
|
904 | bbcf500e | humkyung | self.addMessage.emit(MessageType.Error, message)
|
905 | 25e0cacb | Gyusu | |
906 | '''
|
||
907 | 0ea718ad | humkyung | @brief selection changed
|
908 | @author humkyung
|
||
909 | @date 2018.06.27
|
||
910 | 6d6ad72f | humkyung | @history humkung 2018.07.08 call tree widget's findItem
|
911 | 0ea718ad | humkyung | '''
|
912 | 853df487 | humkyung | |
913 | 0ea718ad | humkyung | def onSelectionChanged(self): |
914 | 5a5c16e6 | humkyung | items = [item for item in self.graphicsView.scene.selectedItems() if issubclass(type(item), SymbolSvgItem) or \ |
915 | 853df487 | humkyung | type(item) is QEngineeringLineItem or issubclass(type(item), QEngineeringTextItem) or type( |
916 | item) is QEngineeringUnknownItem or type(item) is QEngineeringVendorItem] |
||
917 | 5a5c16e6 | humkyung | if items:
|
918 | item = items[-1]
|
||
919 | cac8d64c | humkyung | self.itemTreeWidget.findItem(item)
|
920 | db9b4d89 | humkyung | self.resultPropertyTableWidget.show_item_property(item)
|
921 | ccb722a4 | esham21 | if type(item) is QEngineeringErrorItem: |
922 | for index in range(self.tableWidgetInconsistency.rowCount()): |
||
923 | if self.tableWidgetInconsistency.item(index, 1).tag is item: |
||
924 | self.tableWidgetInconsistency.selectRow(index)
|
||
925 | break
|
||
926 | 5a5c16e6 | humkyung | else:
|
927 | a208ed03 | humkyung | self.resultPropertyTableWidget.show_item_property(None) |
928 | 853df487 | humkyung | |
929 | 0ea718ad | humkyung | '''
|
930 | cac8d64c | humkyung | @brief Initialize scene and itemTreeWidget
|
931 | a63f247e | 김정우 | @author Jeongwoo
|
932 | @date 2018.06.14
|
||
933 | 18e32014 | humkyung | @history humkyung 2018.08.16 ask to delete recognized items before remove
|
934 | a63f247e | 김정우 | '''
|
935 | 853df487 | humkyung | |
936 | 18e32014 | humkyung | def onInitializeScene(self, action): |
937 | a63f247e | 김정우 | if not self.graphicsView.hasImage(): |
938 | self.actionEquipment.setChecked(False) |
||
939 | self.showImageSelectionMessageBox()
|
||
940 | d1a02244 | gaqhf | |
941 | a63f247e | 김정우 | return
|
942 | |||
943 | 03a684dd | esham21 | try:
|
944 | msg = QMessageBox() |
||
945 | msg.setIcon(QMessageBox.Critical) |
||
946 | msg.setText(self.tr('Do you want to remove all items?\nThis work cannot be recovered.')) |
||
947 | msg.setWindowTitle(self.tr("Initialize")) |
||
948 | 853df487 | humkyung | msg.setStandardButtons(QMessageBox.Ok | QMessageBox.Cancel) |
949 | 03a684dd | esham21 | if QMessageBox.Ok == msg.exec_():
|
950 | |||
951 | appDocData = AppDocData.instance() |
||
952 | appDocData.clearItemList(True)
|
||
953 | 853df487 | humkyung | |
954 | 03a684dd | esham21 | items = self.graphicsView.scene.items()
|
955 | for item in items: |
||
956 | if type(item) is not QGraphicsPixmapItem and item.scene() is not None: |
||
957 | 853df487 | humkyung | # if hasattr(item, 'tranfer'):
|
958 | 03a684dd | esham21 | # item.tranfer.onRemoved.emit(item)
|
959 | 853df487 | humkyung | # else:
|
960 | 03a684dd | esham21 | # self.graphicsView.scene.removeItem(item)
|
961 | self.graphicsView.scene.removeItem(item)
|
||
962 | |||
963 | '''
|
||
964 | if type(item) is QEngineeringLineNoTextItem:
|
||
965 | self.removedItems['LINE'].append(str(item.uid))
|
||
966 | elif type(item) is QEngineeringInstrumentItem:
|
||
967 | self.removedItems['INST'].append(str(item.uid))
|
||
968 | elif type(item) is QEngineeringEquipmentItem:
|
||
969 | self.removedItems['EQUIP'].append(str(item.uid))
|
||
970 | elif type(item) is QEngineeringNoteItem:
|
||
971 | self.removedItems['NOTE'].append(str(item.uid))
|
||
972 | '''
|
||
973 | 853df487 | humkyung | |
974 | 03a684dd | esham21 | if self.path is not None: |
975 | baseName = os.path.basename(self.path)
|
||
976 | self.itemTreeWidget.setCurrentPID(baseName)
|
||
977 | |||
978 | except Exception as ex: |
||
979 | e57134bc | esham21 | message = 'error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, |
980 | 853df487 | humkyung | sys.exc_info()[-1].tb_lineno)
|
981 | 03a684dd | esham21 | self.addMessage.emit(MessageType.Error, message)
|
982 | 2240f7db | 김정우 | |
983 | '''
|
||
984 | 1f45633d | 김정우 | @brief Manage Checkable Action statement
|
985 | @author Jeongwoo
|
||
986 | @date 2018.05.10
|
||
987 | d367d959 | 김정우 | @history 2018.06.27 Jeongwoo Chnage method to initialize command [Set None → DefaultCommand]
|
988 | 1f45633d | 김정우 | '''
|
989 | 853df487 | humkyung | |
990 | 1f45633d | 김정우 | def actionGroupTriggered(self, action): |
991 | eb2d256e | esham21 | if hasattr(self.actionLine, 'tag'): |
992 | self.actionLine.tag.onRejected.emit(None) |
||
993 | |||
994 | if hasattr(self.actionVendor, 'tag'): |
||
995 | self.actionVendor.tag.onRejected.emit(None) |
||
996 | |||
997 | 594bbd9c | 김정우 | if self.graphicsView.command is not None: |
998 | d367d959 | 김정우 | self.graphicsView.useDefaultCommand()
|
999 | 59643c3f | humkyung | |
1000 | for _action in self.actionGroup.actions(): |
||
1001 | _action.setChecked(False)
|
||
1002 | |||
1003 | action.setChecked(True)
|
||
1004 | ad8a4791 | 김정우 | |
1005 | 2240f7db | 김정우 | '''
|
1006 | ce604b29 | 김정우 | @brief Create Equipment
|
1007 | @author Jeongwoo
|
||
1008 | @date 18.05.03
|
||
1009 | ff3d1c7a | 김정우 | @history 2018.05.04 Jeongwoo Add Parameter on CreateSymbolCommand
|
1010 | ce604b29 | 김정우 | '''
|
1011 | 853df487 | humkyung | |
1012 | ce604b29 | 김정우 | def createEquipment(self): |
1013 | if not self.graphicsView.hasImage(): |
||
1014 | ad8a4791 | 김정우 | self.actionEquipment.setChecked(False) |
1015 | ce604b29 | 김정우 | self.showImageSelectionMessageBox()
|
1016 | return
|
||
1017 | if self.actionEquipment.isChecked(): |
||
1018 | 853df487 | humkyung | self.graphicsView.command = CreateSymbolCommand.CreateSymbolCommand(self.graphicsView, self.itemTreeWidget, |
1019 | self.dirTreeWidget)
|
||
1020 | ce604b29 | 김정우 | else:
|
1021 | self.graphicsView.useDefaultCommand()
|
||
1022 | |||
1023 | '''
|
||
1024 | @brief Create Nozzle
|
||
1025 | @author Jeongwoo
|
||
1026 | ff3d1c7a | 김정우 | @date 2018.05.03
|
1027 | @history 2018.05.04 Jeongwoo Add Parameter on CreateSymbolCommand
|
||
1028 | ce604b29 | 김정우 | '''
|
1029 | 853df487 | humkyung | |
1030 | ce604b29 | 김정우 | def createNozzle(self): |
1031 | if not self.graphicsView.hasImage(): |
||
1032 | ad8a4791 | 김정우 | self.actionNozzle.setChecked(False) |
1033 | ce604b29 | 김정우 | self.showImageSelectionMessageBox()
|
1034 | return
|
||
1035 | if self.actionNozzle.isChecked(): |
||
1036 | 853df487 | humkyung | self.graphicsView.command = CreateSymbolCommand.CreateSymbolCommand(self.graphicsView, self.itemTreeWidget, |
1037 | self.dirTreeWidget)
|
||
1038 | ce604b29 | 김정우 | else:
|
1039 | self.graphicsView.useDefaultCommand()
|
||
1040 | |||
1041 | '''
|
||
1042 | 2240f7db | 김정우 | @brief Area OCR
|
1043 | @author Jeongwoo
|
||
1044 | @date 18.04.18
|
||
1045 | b8c5dceb | 김정우 | @history 2018.05.02 Jeongwoo Change graphicsView.command by actionOCR checked state
|
1046 | 98b01134 | 김정우 | Show MessageBox when imageviewer doesn't have image
|
1047 | 2240f7db | 김정우 | '''
|
1048 | 853df487 | humkyung | |
1049 | 42e5fdf3 | humkyung | def onAreaOcr(self): |
1050 | 98b01134 | 김정우 | if not self.graphicsView.hasImage(): |
1051 | ad8a4791 | 김정우 | self.actionOCR.setChecked(False) |
1052 | 98b01134 | 김정우 | self.showImageSelectionMessageBox()
|
1053 | return
|
||
1054 | |||
1055 | b8c5dceb | 김정우 | if self.actionOCR.isChecked(): |
1056 | d6d16d45 | humkyung | cmd = AreaOcrCommand.AreaOcrCommand(self.graphicsView)
|
1057 | cmd.onSuccess.connect(self.onRecognizeText)
|
||
1058 | 42e5fdf3 | humkyung | cmd.onRejected.connect(self.onCommandRejected)
|
1059 | d6d16d45 | humkyung | self.graphicsView.command = cmd
|
1060 | b8c5dceb | 김정우 | else:
|
1061 | self.graphicsView.useDefaultCommand()
|
||
1062 | 853df487 | humkyung | |
1063 | e4b3e191 | humkyung | '''
|
1064 | d6d16d45 | humkyung | @brief show text recognition dialog
|
1065 | @author humkyung
|
||
1066 | @date 2018.08.08
|
||
1067 | '''
|
||
1068 | 853df487 | humkyung | |
1069 | d6d16d45 | humkyung | def onRecognizeText(self, x, y, width, height): |
1070 | from OcrResultDialog import QOcrResultDialog |
||
1071 | |||
1072 | try:
|
||
1073 | image = self.graphicsView.image().copy(x, y, width, height)
|
||
1074 | dialog = QOcrResultDialog(self.graphicsView, image, QRectF(x, y, width, height))
|
||
1075 | (isAccept, textInfoList) = dialog.showDialog() |
||
1076 | if isAccept:
|
||
1077 | if textInfoList is not None and len(textInfoList) > 0: |
||
1078 | docData = AppDocData.instance() |
||
1079 | for textInfo in textInfoList: |
||
1080 | x = textInfo.getX() |
||
1081 | y = textInfo.getY() |
||
1082 | angle = textInfo.getAngle() |
||
1083 | text = textInfo.getText() |
||
1084 | width = textInfo.getW() |
||
1085 | height = textInfo.getH() |
||
1086 | cc747b58 | esham21 | item = TextItemFactory.instance().createTextItem(textInfo) |
1087 | e65b0bf8 | humkyung | if item is not None: |
1088 | 14608af0 | esham21 | item.loc = [x, y] |
1089 | e65b0bf8 | humkyung | item.size = (width, height) |
1090 | item.angle = angle |
||
1091 | item.setDefaultTextColor(Qt.blue) |
||
1092 | item.addTextItemToScene(self.graphicsView.scene)
|
||
1093 | 071ff4b4 | gaqhf | item.transfer.onRemoved.connect(self.itemRemoved)
|
1094 | e65b0bf8 | humkyung | else:
|
1095 | e57134bc | esham21 | message = 'error occurred({}) in {}:{}'.format('텍스트 생성에 실패했습니다.', sys.exc_info()[ |
1096 | 853df487 | humkyung | -1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno) |
1097 | e65b0bf8 | humkyung | self.addMessage.emit(MessageType.Normal, message)
|
1098 | d6d16d45 | humkyung | else:
|
1099 | f5709716 | humkyung | QMessageBox.about(self.graphicsView, self.tr("Notice"), self.tr("Fail to recognize text")) |
1100 | d6d16d45 | humkyung | except Exception as ex: |
1101 | e57134bc | esham21 | message = 'error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, |
1102 | 853df487 | humkyung | sys.exc_info()[-1].tb_lineno)
|
1103 | e65b0bf8 | humkyung | self.addMessage.emit(MessageType.Error, message)
|
1104 | d6d16d45 | humkyung | |
1105 | '''
|
||
1106 | 4c612af8 | humkyung | @brief area configuration
|
1107 | '''
|
||
1108 | 853df487 | humkyung | |
1109 | 4c612af8 | humkyung | def areaConfiguration(self): |
1110 | 47604221 | humkyung | from ConfigurationAreaDialog import QConfigurationAreaDialog |
1111 | 31958dce | esham21 | if not self.graphicsView.hasImage(): |
1112 | self.showImageSelectionMessageBox()
|
||
1113 | return
|
||
1114 | 9b514625 | esham21 | self.onCommandRejected()
|
1115 | 47604221 | humkyung | self.dlgConfigurationArea = QConfigurationAreaDialog(self) |
1116 | self.dlgConfigurationArea.show()
|
||
1117 | self.dlgConfigurationArea.exec_()
|
||
1118 | 4c612af8 | humkyung | |
1119 | '''
|
||
1120 | e4b3e191 | humkyung | @brief configuration
|
1121 | '''
|
||
1122 | 853df487 | humkyung | |
1123 | e4b3e191 | humkyung | def configuration(self): |
1124 | a3b64994 | humkyung | from ConfigurationDialog import QConfigurationDialog |
1125 | e4b3e191 | humkyung | |
1126 | self.dlgConfiguration = QConfigurationDialog(self) |
||
1127 | 853df487 | humkyung | # self.dlgConfiguration.show()
|
1128 | ee195020 | humkyung | if QDialog.Accepted == self.dlgConfiguration.exec_(): |
1129 | QEngineeringLineItem.LINE_TYPE_COLORS.clear() |
||
1130 | QEngineeringInstrumentItem.INST_COLOR = None
|
||
1131 | 98b01134 | 김정우 | |
1132 | '''
|
||
1133 | b5749a77 | humkyung | @brief show special item types dialog
|
1134 | @author humkyung
|
||
1135 | @date 2019.08.10
|
||
1136 | '''
|
||
1137 | 853df487 | humkyung | |
1138 | b5749a77 | humkyung | def on_show_special_item_types(self): |
1139 | from SpecialItemTypesDialog import QSpecialItemTypesDialog |
||
1140 | |||
1141 | dlg = QSpecialItemTypesDialog(self)
|
||
1142 | dlg.exec_() |
||
1143 | |||
1144 | 9f428148 | humkyung | def on_show_data_transfer(self): |
1145 | """ show data transfer dialog """
|
||
1146 | from DataTransferDialog import QDataTransferDialog |
||
1147 | |||
1148 | dlg = QDataTransferDialog(self)
|
||
1149 | dlg.exec_() |
||
1150 | |||
1151 | 7fb00532 | humkyung | def on_show_data_export(self): |
1152 | """ show data export dialog """
|
||
1153 | from DataExportDialog import QDataExportDialog |
||
1154 | |||
1155 | dlg = QDataExportDialog(self)
|
||
1156 | dlg.exec_() |
||
1157 | |||
1158 | 853df487 | humkyung | def on_show_eqp_datasheet_export(self): |
1159 | """ show eqp datasheet export dialog """
|
||
1160 | from EqpDatasheetExportDialog import QEqpDatasheetExportDialog |
||
1161 | |||
1162 | dlg = QEqpDatasheetExportDialog(self)
|
||
1163 | dlg.exec_() |
||
1164 | |||
1165 | 9f428148 | humkyung | def on_show_opc_relation(self): |
1166 | """ show opc relation dialog """
|
||
1167 | from OPCRelationDialog import QOPCRelationDialog |
||
1168 | |||
1169 | dlg = QOPCRelationDialog(self)
|
||
1170 | dlg.exec_() |
||
1171 | |||
1172 | b5749a77 | humkyung | '''
|
1173 | 25e0cacb | Gyusu | @brief show nominal diameter dialog
|
1174 | 081b7311 | humkyung | @author humkyung
|
1175 | @date 2018.06.28
|
||
1176 | '''
|
||
1177 | 853df487 | humkyung | |
1178 | 25e0cacb | Gyusu | def onShowCodeTable(self): |
1179 | from CodeTableDialog import QCodeTableDialog |
||
1180 | 081b7311 | humkyung | |
1181 | 25e0cacb | Gyusu | dlg = QCodeTableDialog(self)
|
1182 | b3bd19f3 | esham21 | dlg.show() |
1183 | 081b7311 | humkyung | dlg.exec_() |
1184 | b3bd19f3 | esham21 | if dlg.code_area:
|
1185 | if dlg.code_area.scene():
|
||
1186 | self.graphicsView.scene.removeItem(dlg.code_area)
|
||
1187 | if dlg.desc_area:
|
||
1188 | if dlg.desc_area.scene():
|
||
1189 | self.graphicsView.scene.removeItem(dlg.desc_area)
|
||
1190 | self.graphicsView.useDefaultCommand()
|
||
1191 | 081b7311 | humkyung | |
1192 | '''
|
||
1193 | 25e0cacb | Gyusu | @brief show HMB data
|
1194 | d23501a0 | humkyung | @author humkyung
|
1195 | 25e0cacb | Gyusu | @date 2018.07.11
|
1196 | d23501a0 | humkyung | '''
|
1197 | 853df487 | humkyung | |
1198 | 25e0cacb | Gyusu | def onHMBData(self): |
1199 | from HMBDialog import QHMBDialog |
||
1200 | d23501a0 | humkyung | |
1201 | 25e0cacb | Gyusu | dlg = QHMBDialog(self)
|
1202 | dlg.show() |
||
1203 | d23501a0 | humkyung | dlg.exec_() |
1204 | |||
1205 | '''
|
||
1206 | 5afca25c | humkyung | @brief show line data list
|
1207 | @author humkyung
|
||
1208 | @date 2018.05.03
|
||
1209 | '''
|
||
1210 | 853df487 | humkyung | |
1211 | eb71581d | gaqhf | def showItemDataList(self): |
1212 | bfba2652 | gaqhf | from ItemDataExportDialog import QItemDataExportDialog |
1213 | 5afca25c | humkyung | |
1214 | bfba2652 | gaqhf | self.dlgLineDataList = QItemDataExportDialog(self) |
1215 | 5afca25c | humkyung | self.dlgLineDataList.exec_()
|
1216 | |||
1217 | d35a6081 | esham21 | def showTextDataList(self): |
1218 | '''
|
||
1219 | @brief show all text item in scene
|
||
1220 | @author euisung
|
||
1221 | @date 2019.04.18
|
||
1222 | '''
|
||
1223 | try:
|
||
1224 | if not self.graphicsView.hasImage(): |
||
1225 | self.showImageSelectionMessageBox()
|
||
1226 | return
|
||
1227 | |||
1228 | 9b514625 | esham21 | self.onCommandRejected()
|
1229 | d35a6081 | esham21 | dialog = QTextDataListDialog(self)
|
1230 | c4ae884a | esham21 | dialog.show() |
1231 | d35a6081 | esham21 | dialog.exec_() |
1232 | except Exception as ex: |
||
1233 | e57134bc | esham21 | message = 'error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, |
1234 | 853df487 | humkyung | sys.exc_info()[-1].tb_lineno)
|
1235 | d35a6081 | esham21 | self.addMessage.emit(MessageType.Error, message)
|
1236 | |||
1237 | 5afca25c | humkyung | '''
|
1238 | 98b01134 | 김정우 | @brief Show Image Selection Guide MessageBox
|
1239 | @author Jeongwoo
|
||
1240 | @date 2018.05.02
|
||
1241 | '''
|
||
1242 | 853df487 | humkyung | |
1243 | 98b01134 | 김정우 | def showImageSelectionMessageBox(self): |
1244 | f5709716 | humkyung | QMessageBox.about(self.graphicsView, self.tr("Notice"), self.tr("First select image drawing")) |
1245 | 853df487 | humkyung | |
1246 | e4b3e191 | humkyung | '''
|
1247 | 0ea718ad | humkyung | @brief change selected lines' type by selected line type
|
1248 | @author humkyung
|
||
1249 | @date 2018.06.27
|
||
1250 | '''
|
||
1251 | 853df487 | humkyung | |
1252 | 0ea718ad | humkyung | def onLineTypeChanged(self, param): |
1253 | lineType = self.lineComboBox.itemText(param)
|
||
1254 | selected = [item for item in self.graphicsView.scene.selectedItems() if type(item) is QEngineeringLineItem] |
||
1255 | if selected:
|
||
1256 | for item in selected: |
||
1257 | item.lineType = lineType |
||
1258 | |||
1259 | 2829806b | humkyung | def display_colors(self, value): |
1260 | 7e77874e | humkyung | """ display colors """
|
1261 | from DisplayColors import DisplayColors |
||
1262 | from DisplayColors import DisplayOptions |
||
1263 | |||
1264 | DisplayColors.instance().option = DisplayOptions.DisplayByLineNo if value == True else DisplayOptions.DisplayByLineType |
||
1265 | if hasattr(self, 'graphicsView'): |
||
1266 | ee195020 | humkyung | self.graphicsView.scene.update(self.graphicsView.sceneRect()) |
1267 | 7e77874e | humkyung | DisplayColors.instance().save_data() |
1268 | 2829806b | humkyung | |
1269 | 0ea718ad | humkyung | '''
|
1270 | 018867e0 | humkyung | @brief Open image drawing file and then display it
|
1271 | @author humkyung
|
||
1272 | @date 2018.??.??
|
||
1273 | @history 18.04.23 Jeongwoo Add AppDocData.instance().setCurrentPidSource
|
||
1274 | 18.04.23 Jeongwoo Add Store Set Current Pid Image on AppDocData
|
||
1275 | 18.05.02 Jeongwoo Add useDefaultCommand()
|
||
1276 | humkyung 2018.05.24 load recognition result file if exists
|
||
1277 | 7ac6b06b | 김정우 | Jeongwoo 2018.05.29 load data on xml if xml file exist
|
1278 | 88d604d7 | humkyung | humkyung 2018.08.22 clear scene before loading xml file
|
1279 | e4b3e191 | humkyung | '''
|
1280 | 853df487 | humkyung | |
1281 | 21fc8683 | humkyung | def onOpenImageDrawing(self, path=None): |
1282 | 714bab5a | humkyung | from Drawing import Drawing |
1283 | 988b20a2 | humkyung | |
1284 | a6581e45 | humkyung | try:
|
1285 | 54eedb38 | humkyung | self.save_drawing_if_necessary()
|
1286 | if hasattr(self, '_save_work_cmd'): |
||
1287 | self._save_work_cmd.wait()
|
||
1288 | |||
1289 | eea44d8f | humkyung | app_doc_data = AppDocData.instance() |
1290 | 54eedb38 | humkyung | |
1291 | eea44d8f | humkyung | project = app_doc_data.getCurrentProject() |
1292 | 853df487 | humkyung | |
1293 | self.path = self.graphicsView.loadImageFromFile(project.getDrawingFilePath(), |
||
1294 | path if type(path) is str else '') |
||
1295 | bd0d156a | humkyung | if os.path.isfile(self.path): |
1296 | 9b514625 | esham21 | self.onCommandRejected()
|
1297 | eea44d8f | humkyung | app_doc_data.clear() |
1298 | 5afca25c | humkyung | |
1299 | eea44d8f | humkyung | app_doc_data.setImgFilePath(self.path)
|
1300 | app_doc_data.activeDrawing = Drawing(None, app_doc_data.imgName, None) |
||
1301 | if not app_doc_data.set_occupying_drawing(app_doc_data.activeDrawing.UID): |
||
1302 | 853df487 | humkyung | QMessageBox.about(self.graphicsView, self.tr("Notice"), |
1303 | self.tr("The drawing is locked for editing by another user")) |
||
1304 | 77616eee | esham21 | return
|
1305 | eea44d8f | humkyung | app_doc_data.activeDrawing.set_pid_source(Image.open(self.path))
|
1306 | self.itemTreeWidget.setCurrentPID(app_doc_data.activeDrawing.name)
|
||
1307 | bd0d156a | humkyung | |
1308 | 82e5790e | esham21 | drawingList = self.treeWidgetDrawingList.topLevelItem(0) |
1309 | for childIdex in range(drawingList.childCount()): |
||
1310 | drawingList.child(childIdex).setCheckState(0, Qt.Unchecked)
|
||
1311 | for childIdex in range(drawingList.childCount()): |
||
1312 | child = drawingList.child(childIdex) |
||
1313 | eea44d8f | humkyung | if child.text(0).replace('.png', '') == app_doc_data.activeDrawing.name: |
1314 | 82e5790e | esham21 | child.setCheckState(0, Qt.Checked)
|
1315 | break
|
||
1316 | |||
1317 | 2796938f | humkyung | try:
|
1318 | 708824e3 | esham21 | self.show_Progress_bar()
|
1319 | 54eedb38 | humkyung | |
1320 | # disconnect scene changed if signal is connected
|
||
1321 | if self.graphicsView.scene.receivers(self.graphicsView.scene.contents_changed) > 0: |
||
1322 | self.graphicsView.scene.contents_changed.disconnect()
|
||
1323 | |||
1324 | eea44d8f | humkyung | # Load data
|
1325 | path = os.path.join(app_doc_data.getCurrentProject().getTempPath(), app_doc_data.imgName + '.xml')
|
||
1326 | configs = app_doc_data.getConfigs('Data Load', 'Xml First') |
||
1327 | 725a0a82 | esham21 | if configs and int(configs[0].value) is 1 and os.path.isfile(path): |
1328 | 9b0bec95 | humkyung | self.loadRecognitionResultFromXml(path)
|
1329 | 2796938f | humkyung | else:
|
1330 | eea44d8f | humkyung | self.load_drawing(app_doc_data.activeDrawing)
|
1331 | 54eedb38 | humkyung | |
1332 | db336ebd | humkyung | self.display_number_of_items()
|
1333 | 54eedb38 | humkyung | # connect scene changed signal
|
1334 | self.graphicsView.scene.contents_changed.connect(self.scene_changed) |
||
1335 | 2796938f | humkyung | finally:
|
1336 | 708824e3 | esham21 | if hasattr(self, 'progress'): |
1337 | self.progress.setValue(self.progress.maximum()) |
||
1338 | 853df487 | humkyung | # self.progress.hide()
|
1339 | 2796938f | humkyung | |
1340 | 4b0f4698 | esham21 | self.changeViewCheckedState(True) |
1341 | a6581e45 | humkyung | except Exception as ex: |
1342 | eea44d8f | humkyung | message = 'error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, |
1343 | sys.exc_info()[-1].tb_lineno)
|
||
1344 | e65b0bf8 | humkyung | self.addMessage.emit(MessageType.Error, message)
|
1345 | e4b3e191 | humkyung | |
1346 | return self.path |
||
1347 | a6581e45 | humkyung | |
1348 | 708824e3 | esham21 | def show_Progress_bar(self): |
1349 | """ show progress bar """
|
||
1350 | 853df487 | humkyung | self.progress = QProgressDialog(self.tr("Please wait for a while"), self.tr("Cancel"), 0, 100, |
1351 | self) if not hasattr(self, 'progress') else self.progress |
||
1352 | 708824e3 | esham21 | self.progress.setWindowModality(Qt.WindowModal)
|
1353 | self.progress.setAutoReset(True) |
||
1354 | self.progress.setAutoClose(True) |
||
1355 | self.progress.setMinimum(0) |
||
1356 | self.progress.setMaximum(100) |
||
1357 | 853df487 | humkyung | self.progress.resize(600, 100) |
1358 | 708824e3 | esham21 | self.progress.setWindowTitle(self.tr("Reading file...")) |
1359 | self.progress.show()
|
||
1360 | |||
1361 | 2e2b4a3f | esham21 | def changeViewCheckedState(self, checked, clear=True): |
1362 | 4b0f4698 | esham21 | '''
|
1363 | @brief change view checked state
|
||
1364 | @author euisung
|
||
1365 | @date 2019.03.06
|
||
1366 | '''
|
||
1367 | 853df487 | humkyung | # self.actionImage_Drawing.setChecked(checked)
|
1368 | 4b0f4698 | esham21 | self.actionViewText.setChecked(checked)
|
1369 | self.actionViewSymbol.setChecked(checked)
|
||
1370 | self.actionViewLine.setChecked(checked)
|
||
1371 | self.actionViewUnknown.setChecked(checked)
|
||
1372 | ac91a3d7 | esham21 | self.actionViewInconsistency.setChecked(checked)
|
1373 | 35bbca8a | esham21 | self.actionViewVendor_Area.setChecked(not checked) |
1374 | 2e2b4a3f | esham21 | self.actionDrawing_Only.setChecked(not checked) |
1375 | if clear:
|
||
1376 | self.tableWidgetInconsistency.clearContents()
|
||
1377 | self.tableWidgetInconsistency.setRowCount(0) |
||
1378 | |||
1379 | def onViewDrawingOnly(self, isChecked): |
||
1380 | '''
|
||
1381 | @brief visible/invisible except image drawing
|
||
1382 | @author euisung
|
||
1383 | @date 2019.04.22
|
||
1384 | '''
|
||
1385 | self.changeViewCheckedState(not isChecked, False) |
||
1386 | for item in self.graphicsView.scene.items(): |
||
1387 | if type(item) is not QGraphicsPixmapItem: |
||
1388 | item.setVisible(not isChecked)
|
||
1389 | 4b0f4698 | esham21 | |
1390 | a6581e45 | humkyung | '''
|
1391 | 6319193b | humkyung | @brief visible/invisible image drawing
|
1392 | @author humkyung
|
||
1393 | @date 2018.06.25
|
||
1394 | '''
|
||
1395 | 853df487 | humkyung | |
1396 | 081b7311 | humkyung | def onViewImageDrawing(self, isChecked): |
1397 | 6319193b | humkyung | for item in self.graphicsView.scene.items(): |
1398 | if type(item) is QGraphicsPixmapItem: |
||
1399 | item.setVisible(isChecked) |
||
1400 | break
|
||
1401 | |||
1402 | '''
|
||
1403 | 081b7311 | humkyung | @brief visible/invisible Text
|
1404 | @author humkyung
|
||
1405 | @date 2018.06.28
|
||
1406 | '''
|
||
1407 | 853df487 | humkyung | |
1408 | 081b7311 | humkyung | def onViewText(self, isChecked): |
1409 | selected = [item for item in self.graphicsView.scene.items() if issubclass(type(item), QEngineeringTextItem)] |
||
1410 | for item in selected: |
||
1411 | item.setVisible(isChecked) |
||
1412 | |||
1413 | '''
|
||
1414 | @brief visible/invisible Symbol
|
||
1415 | @author humkyung
|
||
1416 | @date 2018.06.28
|
||
1417 | '''
|
||
1418 | 853df487 | humkyung | |
1419 | 081b7311 | humkyung | def onViewSymbol(self, isChecked): |
1420 | 853df487 | humkyung | selected = [item for item in self.graphicsView.scene.items() if |
1421 | (issubclass(type(item), SymbolSvgItem) and type(item) is not QEngineeringErrorItem)] |
||
1422 | 081b7311 | humkyung | for item in selected: |
1423 | item.setVisible(isChecked) |
||
1424 | |||
1425 | '''
|
||
1426 | @brief visible/invisible Line
|
||
1427 | @author humkyung
|
||
1428 | @date 2018.06.28
|
||
1429 | '''
|
||
1430 | 853df487 | humkyung | |
1431 | 081b7311 | humkyung | def onViewLine(self, isChecked): |
1432 | selected = [item for item in self.graphicsView.scene.items() if type(item) is QEngineeringLineItem] |
||
1433 | for item in selected: |
||
1434 | item.setVisible(isChecked) |
||
1435 | |||
1436 | ac91a3d7 | esham21 | def onViewInconsistency(self, isChecked): |
1437 | '''
|
||
1438 | 35bbca8a | esham21 | @brief visible/invisible Inconsistency
|
1439 | @author euisung
|
||
1440 | @date 2019.04.03
|
||
1441 | ac91a3d7 | esham21 | '''
|
1442 | selected = [item for item in self.graphicsView.scene.items() if type(item) is QEngineeringErrorItem] |
||
1443 | for item in selected: |
||
1444 | item.setVisible(isChecked) |
||
1445 | |||
1446 | 081b7311 | humkyung | '''
|
1447 | @brief visible/invisible Unknown
|
||
1448 | @author humkyung
|
||
1449 | @date 2018.06.28
|
||
1450 | '''
|
||
1451 | 853df487 | humkyung | |
1452 | 081b7311 | humkyung | def onViewUnknown(self, isChecked): |
1453 | selected = [item for item in self.graphicsView.scene.items() if type(item) is QEngineeringUnknownItem] |
||
1454 | for item in selected: |
||
1455 | item.setVisible(isChecked) |
||
1456 | |||
1457 | 35bbca8a | esham21 | def onViewVendorArea(self, isChecked): |
1458 | '''
|
||
1459 | @brief visible/invisible Vendor Area
|
||
1460 | @author euisung
|
||
1461 | @date 2019.04.29
|
||
1462 | '''
|
||
1463 | selected = [item for item in self.graphicsView.scene.items() if type(item) is QEngineeringVendorItem] |
||
1464 | for item in selected: |
||
1465 | item.setVisible(isChecked) |
||
1466 | |||
1467 | 081b7311 | humkyung | '''
|
1468 | bae576b7 | humkyung | @brief create a symbol
|
1469 | 3828d206 | 김정우 | @history 2018.05.02 Jeongwoo Change return value of QSymbolEditorDialog (Single variable → Tuple)
|
1470 | Add SymbolSvgItem
|
||
1471 | a67b3200 | 김정우 | 2018.05.03 Jeongwoo Change method to draw Svg Item on Scene (svg.addSvgItemToScene)
|
1472 | d9cbc4d3 | 김정우 | Change method to make svg and image path
|
1473 | 59384c70 | 김정우 | 2018.06.08 Jeongwoo Add Paramter on SymbolSvgItem.buildItem()
|
1474 | bae576b7 | humkyung | '''
|
1475 | 853df487 | humkyung | |
1476 | ec750c78 | humkyung | def onCreateSymbolClicked(self): |
1477 | 25e0cacb | Gyusu | cmd = FenceCommand.FenceCommand(self.graphicsView)
|
1478 | cmd.onSuccess.connect(self.onAreaSelected)
|
||
1479 | self.graphicsView.command = cmd
|
||
1480 | QApplication.setOverrideCursor(Qt.CrossCursor) |
||
1481 | e4b3e191 | humkyung | |
1482 | '''
|
||
1483 | 25e0cacb | Gyusu | @brief show SymbolEditorDialog with image selected by user
|
1484 | @author humkyung
|
||
1485 | @date 2018.07.20
|
||
1486 | '''
|
||
1487 | 853df487 | humkyung | |
1488 | 25e0cacb | Gyusu | def onAreaSelected(self, x, y, width, height): |
1489 | try:
|
||
1490 | image = self.graphicsView.image()
|
||
1491 | if image is not None: |
||
1492 | 853df487 | humkyung | symbolEditorDialog = SymbolEditorDialog.QSymbolEditorDialog(self, image.copy(x, y, width, height),
|
1493 | AppDocData.instance().getCurrentProject()) |
||
1494 | 25e0cacb | Gyusu | (isAccepted, isImmediateInsert, offsetX, offsetY, newSym) = symbolEditorDialog.showDialog() |
1495 | self.dirTreeWidget.initDirTreeWidget()
|
||
1496 | if isAccepted:
|
||
1497 | if isImmediateInsert:
|
||
1498 | svgPath = newSym.getSvgFileFullPath() |
||
1499 | img = cv2.imread(newSym.getImageFileFullPath(), 1)
|
||
1500 | w, h = (0, 0) |
||
1501 | if len(img.shape[::-1]) == 2: |
||
1502 | w, h = img.shape[::-1]
|
||
1503 | else:
|
||
1504 | _chan, w, h = img.shape[::-1]
|
||
1505 | svg = SymbolSvgItem(svgPath) |
||
1506 | 853df487 | humkyung | svg.buildItem(newSym.getName(), newSym.getType(), 0, [offsetX, offsetY], [w, h],
|
1507 | [float(x) for x in newSym.getOriginalPoint().split(',')], |
||
1508 | [(float(x.split(',')[0]), float(x.split(',')[1])) for x in |
||
1509 | newSym.getConnectionPoint().split('/')], newSym.getBaseSymbol(),
|
||
1510 | newSym.getAdditionalSymbol(), newSym.getHasInstrumentLabel) |
||
1511 | 25e0cacb | Gyusu | |
1512 | cac8d64c | humkyung | svg.transfer.onRemoved.connect(self.itemTreeWidget.itemRemoved)
|
1513 | 25e0cacb | Gyusu | svg.addSvgItemToScene(self.graphicsView.scene)
|
1514 | for connector in svg.connectors: |
||
1515 | self.graphicsView.scene.addItem(connector)
|
||
1516 | finally:
|
||
1517 | 9b514625 | esham21 | self.onCommandRejected()
|
1518 | 25e0cacb | Gyusu | QApplication.restoreOverrideCursor() |
1519 | 853df487 | humkyung | |
1520 | 25e0cacb | Gyusu | '''
|
1521 | @brief create a line
|
||
1522 | @author humkyung
|
||
1523 | @history Jeongwoo 2018.05.10 Change method for Checkable action
|
||
1524 | e4b3e191 | humkyung | '''
|
1525 | 853df487 | humkyung | |
1526 | def onPlaceLine(self): |
||
1527 | 1f45633d | 김정우 | if not self.graphicsView.hasImage(): |
1528 | self.actionLine.setChecked(False) |
||
1529 | self.showImageSelectionMessageBox()
|
||
1530 | return
|
||
1531 | e4b3e191 | humkyung | |
1532 | 25e0cacb | Gyusu | self.actionLine.setChecked(True) |
1533 | if not hasattr(self.actionLine, 'tag'): |
||
1534 | self.actionLine.tag = PlaceLineCommand.PlaceLineCommand(self.graphicsView) |
||
1535 | self.actionLine.tag.onSuccess.connect(self.onLineCreated) |
||
1536 | self.actionLine.tag.onRejected.connect(self.onCommandRejected) |
||
1537 | |||
1538 | self.graphicsView.command = self.actionLine.tag |
||
1539 | |||
1540 | '''
|
||
1541 | @brief add created lines to scene
|
||
1542 | @author humkyung
|
||
1543 | @date 2018.07.23
|
||
1544 | '''
|
||
1545 | 853df487 | humkyung | |
1546 | 25e0cacb | Gyusu | def onLineCreated(self): |
1547 | from EngineeringConnectorItem import QEngineeringConnectorItem |
||
1548 | |||
1549 | try:
|
||
1550 | count = len(self.actionLine.tag._polyline._vertices) |
||
1551 | if count > 1: |
||
1552 | items = [] |
||
1553 | |||
1554 | lineType = self.lineComboBox.currentText()
|
||
1555 | for index in range(count - 1): |
||
1556 | start = self.actionLine.tag._polyline._vertices[index]
|
||
1557 | 853df487 | humkyung | end = self.actionLine.tag._polyline._vertices[index + 1] |
1558 | |||
1559 | 25e0cacb | Gyusu | lineItem = QEngineeringLineItem(vertices=[start, end]) |
1560 | lineItem.transfer.onRemoved.connect(self.itemRemoved)
|
||
1561 | lineItem.lineType = lineType |
||
1562 | if items:
|
||
1563 | f21800ed | humkyung | lineItem.connect_if_possible(items[-1], 5) |
1564 | 25e0cacb | Gyusu | else:
|
1565 | pt = lineItem.startPoint() |
||
1566 | 853df487 | humkyung | selected = [item for item in self.graphicsView.scene.items(QPointF(pt[0], pt[1])) if |
1567 | type(item) is QEngineeringConnectorItem or type(item) is QEngineeringLineItem] |
||
1568 | 7f7cdbd5 | humkyung | if selected:
|
1569 | 853df487 | humkyung | lineItem.connect_if_possible( |
1570 | selected[0].parent if type(selected[0]) is QEngineeringConnectorItem else selected[0], |
||
1571 | 5)
|
||
1572 | |||
1573 | 25e0cacb | Gyusu | items.append(lineItem) |
1574 | self.graphicsView.scene.addItem(lineItem)
|
||
1575 | |||
1576 | pt = items[-1].endPoint()
|
||
1577 | 853df487 | humkyung | selected = [item for item in self.graphicsView.scene.items(QPointF(pt[0], pt[1])) if |
1578 | type(item) is QEngineeringConnectorItem and item.parent is not items[-1]] |
||
1579 | 7f7cdbd5 | humkyung | if selected:
|
1580 | f21800ed | humkyung | items[-1].connect_if_possible(selected[0].parent, 5) |
1581 | 45af4300 | esham21 | |
1582 | 25e0cacb | Gyusu | finally:
|
1583 | self.graphicsView.scene.removeItem(self.actionLine.tag._polyline) |
||
1584 | self.actionLine.tag.reset()
|
||
1585 | |||
1586 | '''
|
||
1587 | @brief refresh scene
|
||
1588 | @author humkyung
|
||
1589 | @date 2018.07.23
|
||
1590 | '''
|
||
1591 | 853df487 | humkyung | |
1592 | 9b514625 | esham21 | def onCommandRejected(self, cmd=None): |
1593 | 25e0cacb | Gyusu | try:
|
1594 | 42e5fdf3 | humkyung | if type(cmd) is PlaceLineCommand.PlaceLineCommand: |
1595 | 45af4300 | esham21 | if self.actionLine.tag._polyline: |
1596 | self.graphicsView.scene.removeItem(self.actionLine.tag._polyline) |
||
1597 | 25e0cacb | Gyusu | self.graphicsView.scene.update()
|
1598 | self.actionLine.tag.reset()
|
||
1599 | |||
1600 | self.actionLine.setChecked(False) |
||
1601 | 42e5fdf3 | humkyung | elif type(cmd) is AreaZoomCommand.AreaZoomCommand: |
1602 | self.actionZoom.setChecked(False) |
||
1603 | elif type(cmd) is AreaOcrCommand.AreaOcrCommand: |
||
1604 | self.actionOCR.setChecked(False) |
||
1605 | 00f34471 | esham21 | elif type(cmd) is PlacePolygonCommand.PlacePolygonCommand: |
1606 | self.actionVendor.setChecked(False) |
||
1607 | 9b514625 | esham21 | else:
|
1608 | if hasattr(self.actionLine, 'tag') and self.actionLine.tag._polyline: |
||
1609 | self.graphicsView.scene.removeItem(self.actionLine.tag._polyline) |
||
1610 | self.graphicsView.scene.update()
|
||
1611 | self.actionLine.tag.reset()
|
||
1612 | eb2d256e | esham21 | if hasattr(self.actionVendor, 'tag') and self.actionVendor.tag._polyline: |
1613 | self.graphicsView.scene.removeItem(self.actionVendor.tag._polyline) |
||
1614 | self.graphicsView.scene.update()
|
||
1615 | self.actionVendor.tag.reset()
|
||
1616 | 9b514625 | esham21 | self.actionLine.setChecked(False) |
1617 | self.actionZoom.setChecked(False) |
||
1618 | self.actionOCR.setChecked(False) |
||
1619 | self.actionVendor.setChecked(False) |
||
1620 | 25e0cacb | Gyusu | finally:
|
1621 | self.graphicsView.useDefaultCommand()
|
||
1622 | 853df487 | humkyung | |
1623 | d538864c | humkyung | '''
|
1624 | @brief restore to default command when user press Escape key
|
||
1625 | @author humkyung
|
||
1626 | @date 2018.08.09
|
||
1627 | 2e2b4a3f | esham21 |
|
1628 | d538864c | humkyung | '''
|
1629 | 853df487 | humkyung | |
1630 | d538864c | humkyung | def keyPressEvent(self, event): |
1631 | try:
|
||
1632 | if event.key() == Qt.Key_Escape:
|
||
1633 | 9b514625 | esham21 | # already catched in command
|
1634 | pass
|
||
1635 | 853df487 | humkyung | # checked = self.actionGroup.checkedAction()
|
1636 | # if checked:
|
||
1637 | 9b514625 | esham21 | # checked.setChecked(False)
|
1638 | # self.graphicsView.useDefaultCommand()
|
||
1639 | 64e4303a | esham21 | elif event.key() == Qt.Key_1:
|
1640 | if self.actionImage_Drawing.isChecked(): |
||
1641 | self.onViewImageDrawing(False) |
||
1642 | self.actionImage_Drawing.setChecked(False) |
||
1643 | else:
|
||
1644 | self.onViewImageDrawing(True) |
||
1645 | self.actionImage_Drawing.setChecked(True) |
||
1646 | elif event.key() == Qt.Key_2:
|
||
1647 | if self.actionViewText.isChecked(): |
||
1648 | self.onViewText(False) |
||
1649 | self.actionViewText.setChecked(False) |
||
1650 | else:
|
||
1651 | self.onViewText(True) |
||
1652 | self.actionViewText.setChecked(True) |
||
1653 | elif event.key() == Qt.Key_3:
|
||
1654 | if self.actionViewSymbol.isChecked(): |
||
1655 | self.onViewSymbol(False) |
||
1656 | self.actionViewSymbol.setChecked(False) |
||
1657 | else:
|
||
1658 | self.onViewSymbol(True) |
||
1659 | self.actionViewSymbol.setChecked(True) |
||
1660 | elif event.key() == Qt.Key_4:
|
||
1661 | if self.actionViewLine.isChecked(): |
||
1662 | self.onViewLine(False) |
||
1663 | self.actionViewLine.setChecked(False) |
||
1664 | else:
|
||
1665 | self.onViewLine(True) |
||
1666 | self.actionViewLine.setChecked(True) |
||
1667 | elif event.key() == Qt.Key_5:
|
||
1668 | if self.actionViewUnknown.isChecked(): |
||
1669 | self.onViewUnknown(False) |
||
1670 | self.actionViewUnknown.setChecked(False) |
||
1671 | else:
|
||
1672 | self.onViewUnknown(True) |
||
1673 | self.actionViewUnknown.setChecked(True) |
||
1674 | elif event.key() == Qt.Key_6:
|
||
1675 | if self.actionViewInconsistency.isChecked(): |
||
1676 | self.onViewInconsistency(False) |
||
1677 | self.actionViewInconsistency.setChecked(False) |
||
1678 | else:
|
||
1679 | self.onViewInconsistency(True) |
||
1680 | self.actionViewInconsistency.setChecked(True) |
||
1681 | 35bbca8a | esham21 | elif event.key() == Qt.Key_7:
|
1682 | if self.actionViewVendor_Area.isChecked(): |
||
1683 | self.onViewVendorArea(False) |
||
1684 | self.actionViewVendor_Area.setChecked(False) |
||
1685 | else:
|
||
1686 | self.onViewVendorArea(True) |
||
1687 | self.actionViewVendor_Area.setChecked(True) |
||
1688 | 853df487 | humkyung | elif event.key() == 96: # '`' key |
1689 | 2e2b4a3f | esham21 | if self.actionDrawing_Only.isChecked(): |
1690 | self.onViewDrawingOnly(False) |
||
1691 | self.actionDrawing_Only.setChecked(False) |
||
1692 | else:
|
||
1693 | self.onViewDrawingOnly(True) |
||
1694 | self.actionDrawing_Only.setChecked(True) |
||
1695 | 853df487 | humkyung | elif event.key() == Qt.Key_M: # merge text as vertical |
1696 | d91bc271 | esham21 | from TextInfo import TextInfo |
1697 | |||
1698 | 853df487 | humkyung | textItems = [text for text in self.graphicsView.scene.selectedItems() if |
1699 | 478a2bb1 | esham21 | type(text) is QEngineeringTextItem] |
1700 | if not textItems or len(textItems) is 1: |
||
1701 | return
|
||
1702 | |||
1703 | angle = None
|
||
1704 | for item in textItems: |
||
1705 | if angle is None: |
||
1706 | angle = item.angle |
||
1707 | else:
|
||
1708 | if angle != item.angle:
|
||
1709 | return
|
||
1710 | |||
1711 | textItems = sorted(textItems, key=lambda text: text.loc[1]) if textItems[0].angle == 0 else ( \ |
||
1712 | sorted(textItems, key=lambda text: text.loc[0]) if textItems[0].angle == 1.57 else ( \ |
||
1713 | sorted(textItems, key=lambda text: text.loc[1], reverse=True) if textItems[0].angle == 4.71 else \ |
||
1714 | sorted(textItems, key=lambda text: text.loc[0], reverse=True))) |
||
1715 | d91bc271 | esham21 | minX = sys.maxsize |
1716 | minY = sys.maxsize |
||
1717 | maxX = 0
|
||
1718 | maxY = 0
|
||
1719 | newText = ''
|
||
1720 | for text in textItems: |
||
1721 | if text.loc[0] < minX: minX = text.loc[0] |
||
1722 | if text.loc[1] < minY: minY = text.loc[1] |
||
1723 | if text.loc[0] + text.size[0] > maxX: maxX = text.loc[0] + text.size[0] |
||
1724 | if text.loc[1] + text.size[1] > maxY: maxY = text.loc[1] + text.size[1] |
||
1725 | newText = newText + text.text() + "\n"
|
||
1726 | text.transfer.onRemoved.emit(text) |
||
1727 | newText = newText[:-1]
|
||
1728 | 853df487 | humkyung | |
1729 | 478a2bb1 | esham21 | textInfo = TextInfo(newText, minX, minY, maxX - minX, maxY - minY, textItems[0].angle)
|
1730 | d91bc271 | esham21 | x = textInfo.getX() |
1731 | y = textInfo.getY() |
||
1732 | angle = textInfo.getAngle() |
||
1733 | text = textInfo.getText() |
||
1734 | width = textInfo.getW() |
||
1735 | height = textInfo.getH() |
||
1736 | item = TextItemFactory.instance().createTextItem(textInfo) |
||
1737 | if item is not None: |
||
1738 | 14608af0 | esham21 | item.loc = [x, y] |
1739 | d91bc271 | esham21 | item.size = (width, height) |
1740 | item.angle = angle |
||
1741 | item.setDefaultTextColor(Qt.blue) |
||
1742 | item.addTextItemToScene(self.graphicsView.scene)
|
||
1743 | item.transfer.onRemoved.connect(self.itemRemoved)
|
||
1744 | 853df487 | humkyung | |
1745 | d538864c | humkyung | QMainWindow.keyPressEvent(self, event)
|
1746 | except Exception as ex: |
||
1747 | e57134bc | esham21 | message = 'error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, |
1748 | 853df487 | humkyung | sys.exc_info()[-1].tb_lineno)
|
1749 | d538864c | humkyung | self.addMessage.emit(MessageType.Error, message)
|
1750 | 853df487 | humkyung | |
1751 | 84efcaa7 | esham21 | def recognizeBatch(self, MainWindow): |
1752 | '''
|
||
1753 | b25fca04 | esham21 | @brief batch recognize symbol, text and line
|
1754 | 84efcaa7 | esham21 | @author euisung
|
1755 | @date 2018.11.23
|
||
1756 |
|
||
1757 | '''
|
||
1758 | from datetime import datetime |
||
1759 | b25fca04 | esham21 | from RecognitionDialog import QRecognitionDialog |
1760 | 84efcaa7 | esham21 | |
1761 | appDocData = AppDocData.instance() |
||
1762 | project = appDocData.getCurrentProject() |
||
1763 | 132ebe3b | esham21 | appDocData.needReOpening = None
|
1764 | currentPid = None
|
||
1765 | 853df487 | humkyung | |
1766 | 208a26e7 | esham21 | if self.graphicsView.hasImage(): |
1767 | c28d2e4c | esham21 | currentPid = appDocData.activeDrawing.name |
1768 | 208a26e7 | esham21 | |
1769 | 84efcaa7 | esham21 | drawingTop = self.treeWidgetDrawingList.topLevelItem(0) |
1770 | drawingCount = drawingTop.childCount() |
||
1771 | 4148416a | esham21 | checkedTreeItems = [] |
1772 | 84efcaa7 | esham21 | checkedDrawingPath = [] |
1773 | for drawing in range(drawingCount): |
||
1774 | drawingChild = drawingTop.child(drawing) |
||
1775 | if drawingChild.checkState(0) == 2: |
||
1776 | 4148416a | esham21 | checkedTreeItems.append(drawingChild) |
1777 | 84efcaa7 | esham21 | checkedDrawingPath.append(os.path.join(project.getDrawingFilePath(), drawingChild.data(0, 0))) |
1778 | c28d2e4c | esham21 | if currentPid is not None and drawingChild.data(0, 0).find(currentPid) is 0: |
1779 | 853df487 | humkyung | appDocData.needReOpening = False # later check need reopening at drawUnknownItems() |
1780 | 2c891173 | esham21 | currentPid = drawingChild.data(0, 0) |
1781 | 84efcaa7 | esham21 | |
1782 | if len(checkedDrawingPath) == 0: |
||
1783 | self.showImageSelectionMessageBox()
|
||
1784 | return
|
||
1785 | |||
1786 | try:
|
||
1787 | self.onClearLog()
|
||
1788 | b25fca04 | esham21 | self.dlg = QRecognitionDialog(self, checkedDrawingPath, True) |
1789 | 84efcaa7 | esham21 | self.dlg.exec_()
|
1790 | if self.dlg.isAccepted == True: |
||
1791 | 4148416a | esham21 | pass
|
1792 | |||
1793 | if appDocData.needReOpening == True: |
||
1794 | drawing = os.path.join(appDocData.getCurrentProject().getDrawingFilePath(), currentPid) |
||
1795 | self.onOpenImageDrawing(drawing)
|
||
1796 | 132ebe3b | esham21 | |
1797 | 84efcaa7 | esham21 | # save working date-time
|
1798 | drawings = appDocData.getDrawings() |
||
1799 | 4148416a | esham21 | checkedDrawings = [] |
1800 | for checkedTreeItem in checkedTreeItems: |
||
1801 | for drawing in drawings: |
||
1802 | 6a9e5ae7 | esham21 | if checkedTreeItem.data(0, 0) == drawing.name: |
1803 | if drawing:
|
||
1804 | drawing.datetime = datetime.now().strftime('%Y-%m-%d %H:%M:%S')
|
||
1805 | 4148416a | esham21 | checkedDrawings.append(drawing) |
1806 | checkedTreeItem.setText(1, datetime.now().strftime('%Y-%m-%d %H:%M:%S')) |
||
1807 | appDocData.saveDrawings(checkedDrawings) |
||
1808 | ac91a3d7 | esham21 | self.changeViewCheckedState(True) |
1809 | 84efcaa7 | esham21 | # up to here
|
1810 | except Exception as ex: |
||
1811 | e57134bc | esham21 | message = 'error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, |
1812 | 853df487 | humkyung | sys.exc_info()[-1].tb_lineno)
|
1813 | 84efcaa7 | esham21 | self.addMessage.emit(MessageType.Error, message)
|
1814 | |||
1815 | e4b3e191 | humkyung | '''
|
1816 | 8c5431cc | humkyung | @brief recognize symbol and text
|
1817 | @author humkyung
|
||
1818 | @date 2018.04.??
|
||
1819 | 120d1104 | 김정우 | @history 2018.04.16 humkyung execute line no tracing
|
1820 | 2018.05.02 Jeongwoo Show MessageBox when imageviewer doesn't have image
|
||
1821 | 93ed7203 | 김정우 | 2018.05.25 Jeongwoo Add parameter on QRecognitionDialog.__init__() and Move thread to QRecognitionDialog
|
1822 | 47bd6b4e | 김정우 | Remove codes below if self.dlg.isAccepted == True
|
1823 | 7ac6b06b | 김정우 | 2018.05.29 Jeongwoo Remove connects and comments
|
1824 | 02643b52 | humkyung | humkyung 2018.11.05 save working date-time
|
1825 | e4b3e191 | humkyung | '''
|
1826 | 853df487 | humkyung | |
1827 | e4b3e191 | humkyung | def recognize(self, MainWindow): |
1828 | 02643b52 | humkyung | from datetime import datetime |
1829 | 41ef00bd | humkyung | from RecognitionDialog import QRecognitionDialog |
1830 | e4b3e191 | humkyung | |
1831 | 120d1104 | 김정우 | if not self.graphicsView.hasImage(): |
1832 | 98b01134 | 김정우 | self.showImageSelectionMessageBox()
|
1833 | 120d1104 | 김정우 | return
|
1834 | |||
1835 | e4b3e191 | humkyung | try:
|
1836 | ec750c78 | humkyung | appDocData = AppDocData.instance() |
1837 | |||
1838 | 0a9e44a7 | humkyung | self.onClearLog()
|
1839 | 610b9a60 | esham21 | appDocData.needReOpening = False
|
1840 | ff08270e | esham21 | drawingList = [] |
1841 | drawingList.append(self.path)
|
||
1842 | b25fca04 | esham21 | self.dlg = QRecognitionDialog(self, drawingList, False) |
1843 | e4b3e191 | humkyung | self.dlg.exec_()
|
1844 | 4148416a | esham21 | |
1845 | 1a5cf07e | esham21 | if appDocData.needReOpening == True: |
1846 | 8aeb7076 | esham21 | self.itemTreeWidget.setCurrentPID(appDocData.activeDrawing.name)
|
1847 | self.drawDetectedItemsToScene()
|
||
1848 | 853df487 | humkyung | |
1849 | 1a5cf07e | esham21 | # save working date-time
|
1850 | drawings = appDocData.getDrawings() |
||
1851 | afee1544 | humkyung | drawing = [drawing for drawing in drawings if appDocData.imgName == os.path.splitext(drawing.name)[0]] |
1852 | 1a5cf07e | esham21 | if drawing[0]: |
1853 | afee1544 | humkyung | drawing[0].datetime = datetime.now().strftime('%Y-%m-%d %H:%M:%S') |
1854 | 1a5cf07e | esham21 | appDocData.saveDrawings(drawing) |
1855 | 4148416a | esham21 | |
1856 | 1a5cf07e | esham21 | currentPid = appDocData.activeDrawing.name |
1857 | 610b9a60 | esham21 | |
1858 | 1a5cf07e | esham21 | drawingTop = self.treeWidgetDrawingList.topLevelItem(0) |
1859 | drawingCount = drawingTop.childCount() |
||
1860 | 853df487 | humkyung | |
1861 | 610b9a60 | esham21 | for drawing in range(drawingCount): |
1862 | drawingChild = drawingTop.child(drawing) |
||
1863 | if drawingChild.data(0, 0).find(currentPid) is 0: |
||
1864 | drawingChild.setText(1, datetime.now().strftime('%Y-%m-%d %H:%M:%S')) |
||
1865 | 4b0f4698 | esham21 | self.changeViewCheckedState(True) |
1866 | 8aeb7076 | esham21 | # up to here
|
1867 | 80f6becd | humkyung | except Exception as ex: |
1868 | e57134bc | esham21 | message = 'error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, |
1869 | 853df487 | humkyung | sys.exc_info()[-1].tb_lineno)
|
1870 | e65b0bf8 | humkyung | self.addMessage.emit(MessageType.Error, message)
|
1871 | e4b3e191 | humkyung | |
1872 | 80f6becd | humkyung | '''
|
1873 | 90bc60db | humkyung | @brief remove item from tree widget and then remove from scene
|
1874 | 47bd6b4e | 김정우 | @date 2018.05.25
|
1875 | @author Jeongwoo
|
||
1876 | c12ca4e3 | humkyung | '''
|
1877 | 853df487 | humkyung | |
1878 | 47bd6b4e | 김정우 | def itemRemoved(self, item): |
1879 | 25e0cacb | Gyusu | try:
|
1880 | cac8d64c | humkyung | self.itemTreeWidget.itemRemoved(item)
|
1881 | d1a02244 | gaqhf | |
1882 | 853df487 | humkyung | matches = [_item for _item in self.graphicsView.scene.items() if |
1883 | hasattr(_item, 'connectors') and [connector for connector in _item.connectors if |
||
1884 | connector.connectedItem is item]]
|
||
1885 | bcc95349 | esham21 | for match in matches: |
1886 | for connector in match.connectors: |
||
1887 | 373230bc | esham21 | if connector.connectedItem is item: |
1888 | connector.connectedItem = None
|
||
1889 | connector.highlight(False)
|
||
1890 | 62762fec | humkyung | |
1891 | 853df487 | humkyung | # matches = [_item for _item in self.graphicsView.scene.items() if hasattr(_item, 'remove_assoc_item')]
|
1892 | # for _item in matches:
|
||
1893 | d5be9c7f | esham21 | # _item.remove_assoc_item(item)
|
1894 | 827cf144 | esham21 | |
1895 | bcc95349 | esham21 | matches = [_item for _item in self.graphicsView.scene.items() if type(_item) is QEngineeringLineNoTextItem] |
1896 | 4c2f20d2 | esham21 | matches.extend([lineNo for lineNo in AppDocData.instance().tracerLineNos if type(lineNo) is QEngineeringTrimLineNoTextItem]) |
1897 | bcc95349 | esham21 | for match in matches: |
1898 | if item is match.prop('From'): |
||
1899 | match.set_property('From', None) |
||
1900 | elif item is match.prop('To'): |
||
1901 | match.set_property('To', None) |
||
1902 | 62762fec | humkyung | |
1903 | d9257e5d | esham21 | for run in match.runs: |
1904 | if item in run.items: |
||
1905 | index = run.items.index(item) |
||
1906 | run.items.pop(index) |
||
1907 | e4003ced | esham21 | if not run.items: |
1908 | run.explode() |
||
1909 | break
|
||
1910 | db796047 | esham21 | |
1911 | 11a98615 | esham21 | matches = [_item for _item in self.graphicsView.scene.items() if hasattr(_item, 'owner')] |
1912 | for match in matches: |
||
1913 | if match.owner is item: |
||
1914 | match.owner = None
|
||
1915 | |||
1916 | 0b9c35fe | esham21 | matches = [_item for _item in self.graphicsView.scene.items() if hasattr(_item, 'attrs')] |
1917 | 853df487 | humkyung | # done = False
|
1918 | 0b9c35fe | esham21 | for match in matches: |
1919 | for assoc in match.associations(): |
||
1920 | if item is assoc: |
||
1921 | for attr in match.attrs.keys(): |
||
1922 | 78c75ee8 | esham21 | if attr.AssocItem and str(item.uid) == str(attr.AssocItem.uid): |
1923 | 0b9c35fe | esham21 | attr.AssocItem = None
|
1924 | match.attrs[attr] = ''
|
||
1925 | 853df487 | humkyung | # done = True
|
1926 | f232adfd | esham21 | match.remove_assoc_item(item) |
1927 | 0b9c35fe | esham21 | break
|
1928 | 853df487 | humkyung | # if done: break
|
1929 | 0b9c35fe | esham21 | |
1930 | e72e864f | humkyung | # remove error item from inconsistency list
|
1931 | if type(item) is QEngineeringErrorItem: |
||
1932 | for row in range(self.tableWidgetInconsistency.rowCount()): |
||
1933 | if item is self.tableWidgetInconsistency.item(row, 0).tag: |
||
1934 | self.tableWidgetInconsistency.removeRow(row)
|
||
1935 | break
|
||
1936 | d28da625 | esham21 | |
1937 | 25e0cacb | Gyusu | if item.scene() is not None: item.scene().removeItem(item) |
1938 | except Exception as ex: |
||
1939 | e57134bc | esham21 | message = 'error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, |
1940 | 853df487 | humkyung | sys.exc_info()[-1].tb_lineno)
|
1941 | 90bc60db | humkyung | self.addMessage.emit(MessageType.Error, message)
|
1942 | 25e0cacb | Gyusu | |
1943 | c12ca4e3 | humkyung | '''
|
1944 | 80f6becd | humkyung | @brief recognize line
|
1945 | @author humkyung
|
||
1946 | @date 2018.04.19
|
||
1947 | 5fbc4298 | humkyung | @history Jeongwoo 2018.04.26 Variable name changed (texts → lineNos)
|
1948 | aa1b6842 | 김정우 | TextItem type changed (QEngineeringTextItem → QEngineeringLineNoTextItem)
|
1949 | 5fbc4298 | humkyung | humkyung 2018.04.26 remove small objects before recognizing line
|
1950 | Jeongwoo 2018.05.02 Show MessageBox when imageviewer doesn't have image
|
||
1951 | 47bd6b4e | 김정우 | Jeongwoo 2018.05.25 Move codes about LineDetector
|
1952 | e6b6b13d | humkyung | humkyung 2018.06.17 show progress dialog
|
1953 | 80f6becd | humkyung | '''
|
1954 | 853df487 | humkyung | |
1955 | df4661c5 | humkyung | def connect_attributes(self, MainWindow): |
1956 | 80f6becd | humkyung | from LineNoTracer import LineNoTracer |
1957 | 18e32014 | humkyung | from ConnectAttrDialog import QConnectAttrDialog |
1958 | 44ba0518 | humkyung | |
1959 | 98b01134 | 김정우 | if not self.graphicsView.hasImage(): |
1960 | self.showImageSelectionMessageBox()
|
||
1961 | return
|
||
1962 | |||
1963 | 80f6becd | humkyung | try:
|
1964 | e6b6b13d | humkyung | self.dlgConnectAttr = QConnectAttrDialog(self, self.graphicsView) |
1965 | bda81ed4 | esham21 | self.dlgConnectAttr.exec_()
|
1966 | if self.dlgConnectAttr.isRunned: |
||
1967 | b89eca62 | humkyung | self.itemTreeWidget.InitLineNoItems()
|
1968 | |||
1969 | # construct line no item
|
||
1970 | 4b03b7f7 | esham21 | line_nos = AppDocData.instance().tracerLineNos |
1971 | b89eca62 | humkyung | for line_no in line_nos: |
1972 | item = self.itemTreeWidget.addTreeItem(self.itemTreeWidget.root, line_no) |
||
1973 | connectedItems = line_no.getConnectedItems() |
||
1974 | for connectedItem in connectedItems: |
||
1975 | 853df487 | humkyung | if issubclass(type(connectedItem), SymbolSvgItem): |
1976 | b89eca62 | humkyung | self.itemTreeWidget.addTreeItem(item, connectedItem)
|
1977 | # up to here
|
||
1978 | |||
1979 | bda81ed4 | esham21 | self.tableWidgetInconsistency.clearContents()
|
1980 | if self.dlgConnectAttr.ui.checkBoxValidation.isChecked(): |
||
1981 | self.onValidation()
|
||
1982 | |||
1983 | 5a4d5665 | humkyung | self.graphicsView.invalidateScene()
|
1984 | e4b3e191 | humkyung | except Exception as ex: |
1985 | e57134bc | esham21 | message = 'error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, |
1986 | 853df487 | humkyung | sys.exc_info()[-1].tb_lineno)
|
1987 | e65b0bf8 | humkyung | self.addMessage.emit(MessageType.Error, message)
|
1988 | e4b3e191 | humkyung | |
1989 | '''
|
||
1990 | 7ac6b06b | 김정우 | @history 2018.05.25 Jeongwoo Moved from MainWindow
|
1991 | SvgItem and TextItem Connect with method in this class
|
||
1992 | Change method to add GraphicsItem
|
||
1993 | 2018.05.28 Jeongwoo Make QGraphicsItem by symbol, text object. Not xml
|
||
1994 | 2018.05.29 Jeongwoo Change method name and Moved from QRecognitionDialog
|
||
1995 | 34f2b549 | 김정우 | 2018.05.30 Jeongwoo Add parameters on SymbolSvgItem.__init__() (parentSymbol, childSymbol)
|
1996 | f09eb8ff | 김정우 | Change Method name and seperate each item
|
1997 | 1423a37c | humkyung | humkyung 2018.06.11 display difference between original and recognized image
|
1998 | Jeongwoo 2018.06.18 Update Scene after all item added
|
||
1999 | e060a623 | esham21 | 2018.11.05 euisung add save note item because of dependency
|
2000 | c2230d59 | esham21 | 2018.11.05 euisung add db delete process before save
|
2001 | 783c7845 | esham21 | 2018.11.12 euisung add title block properties
|
2002 | 478c2510 | esham21 | 2018.11.12 euisung db part move new method to dbUpdate
|
2003 | c6e0fc86 | esham21 | 2018.11.26 euisung isolate scene adding part -> drawDetectedItemsToScene()
|
2004 | 4148416a | esham21 | 2018.11.29 euisung change name drawDetectedItems() -> createDetectedItems
|
2005 | 7ac6b06b | 김정우 | '''
|
2006 | 853df487 | humkyung | |
2007 | 4148416a | esham21 | def createDetectedItems(self, symbolList, textInfoList, otherTextInfoList, titleBlockTextInfoList): |
2008 | afabd84e | humkyung | try:
|
2009 | appDocData = AppDocData.instance() |
||
2010 | |||
2011 | QApplication.processEvents() |
||
2012 | 4148416a | esham21 | self.createDetectedSymbolItem(symbolList)
|
2013 | afabd84e | humkyung | QApplication.processEvents() |
2014 | 4148416a | esham21 | self.createDetectedTextItem(textInfoList)
|
2015 | afabd84e | humkyung | QApplication.processEvents() |
2016 | 4148416a | esham21 | self.createDetectedOtherTextItem(otherTextInfoList)
|
2017 | 478c2510 | esham21 | QApplication.processEvents() |
2018 | 4148416a | esham21 | self.createDetectedTitleBlockTextItem(titleBlockTextInfoList)
|
2019 | afabd84e | humkyung | |
2020 | # update scene
|
||
2021 | 853df487 | humkyung | # self.graphicsView.scene.update(self.graphicsView.sceneRect())
|
2022 | afabd84e | humkyung | except Exception as ex: |
2023 | e57134bc | esham21 | message = 'error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, |
2024 | 853df487 | humkyung | sys.exc_info()[-1].tb_lineno)
|
2025 | afabd84e | humkyung | self.addMessage.emit(MessageType.Error, message)
|
2026 | 89b66b97 | 김정우 | |
2027 | c6e0fc86 | esham21 | def drawDetectedItemsToScene(self): |
2028 | 936bbf2b | esham21 | '''
|
2029 | @brief add detected items to scene
|
||
2030 | @author euisung
|
||
2031 | @date 2018.11.26
|
||
2032 | '''
|
||
2033 | appDocData = AppDocData.instance() |
||
2034 | |||
2035 | 1e145fc0 | humkyung | try:
|
2036 | for symbol in appDocData.symbols: |
||
2037 | if issubclass(type(symbol), SymbolSvgItem): |
||
2038 | self.addSvgItemToScene(symbol)
|
||
2039 | else:
|
||
2040 | self.graphicsView.scene.addItem(symbol)
|
||
2041 | 936bbf2b | esham21 | |
2042 | 1e145fc0 | humkyung | for text in appDocData.texts: |
2043 | self.addTextItemToScene(text)
|
||
2044 | 936bbf2b | esham21 | |
2045 | e519d74b | esham21 | for lineNo in appDocData.tracerLineNos: |
2046 | self.addTextItemToScene(lineNo)
|
||
2047 | |||
2048 | 1e145fc0 | humkyung | for line in appDocData.lines: |
2049 | self.graphicsView.scene.addItem(line)
|
||
2050 | 6a87bac1 | esham21 | line.transfer.onRemoved.connect(self.itemRemoved)
|
2051 | 09841ec5 | esham21 | for conn in line.connectors: |
2052 | conn.transfer.onPosChanged.connect(line.onConnectorPosChaned) |
||
2053 | 6e953094 | esham21 | |
2054 | e19c7264 | esham21 | for unknown in appDocData.unknowns + appDocData.lineIndicators: |
2055 | 5a4d5665 | humkyung | self.graphicsView.scene.addItem(unknown)
|
2056 | 1e145fc0 | humkyung | finally:
|
2057 | # update scene
|
||
2058 | self.graphicsView.scene.update(self.graphicsView.sceneRect()) |
||
2059 | 6e953094 | esham21 | |
2060 | b9bdf471 | esham21 | def postDetectLineProcess(self): |
2061 | '''
|
||
2062 | @brief check allowables among undetected items
|
||
2063 | @author euisung
|
||
2064 | @date 2018.11.15
|
||
2065 | 0e95388f | esham21 | @history 2018.11.15 euisung no more used, moved to TextItemFactoy isLineNo()
|
2066 | b9bdf471 | esham21 | '''
|
2067 | from TextItemFactory import TextItemFactory |
||
2068 | |||
2069 | appDocData = AppDocData.instance() |
||
2070 | |||
2071 | tableNames = ["Fluid Code", "Insulation Purpose", "PnID Number", "Piping Materials Class", "Unit Number"] |
||
2072 | tableDatas = [] |
||
2073 | for tableName in tableNames: |
||
2074 | 853df487 | humkyung | tableNameFormat = tableName.replace(' ', '').replace('&&', 'n') |
2075 | b9bdf471 | esham21 | tableDatas.append(appDocData.getCodeTable(tableNameFormat)) |
2076 | |||
2077 | items = self.graphicsView.scene.items()
|
||
2078 | for item in items: |
||
2079 | if type(item) is not QEngineeringTextItem: |
||
2080 | continue
|
||
2081 | text = item.text() |
||
2082 | for tableData in tableDatas: |
||
2083 | for data in tableData: |
||
2084 | if data[3] == '': |
||
2085 | continue
|
||
2086 | else:
|
||
2087 | f5e3c912 | esham21 | allows = data[3].split(',') |
2088 | for allow in allows: |
||
2089 | text = text.replace(allow, data[1])
|
||
2090 | |||
2091 | b9bdf471 | esham21 | lineItem = TextItemFactory.instance().createTextItem(text) |
2092 | if type(lineItem) is QEngineeringLineNoTextItem: |
||
2093 | f5e3c912 | esham21 | lineItem.loc = item.loc |
2094 | lineItem.size = item.size |
||
2095 | lineItem.angle = item.angle |
||
2096 | lineItem.area = item.area |
||
2097 | 853df487 | humkyung | # lineItem.addTextItemToScene(self.graphicsView.scene)
|
2098 | f5e3c912 | esham21 | lineItem.transfer.onRemoved.connect(self.itemRemoved)
|
2099 | item.transfer.onRemoved.emit(item) |
||
2100 | 208a26e7 | esham21 | appDocData.lineNos.append(lineItem) |
2101 | 853df487 | humkyung | |
2102 | 4148416a | esham21 | def createDetectedTitleBlockTextItem(self, textInfoList): |
2103 | 783c7845 | esham21 | '''
|
2104 | @brief draw title block
|
||
2105 | @author euisung
|
||
2106 | @date 2018.11.12
|
||
2107 | 4148416a | esham21 | @history 2018.11.26 euisung remove scene dependency
|
2108 | 2018.11.29 euisung change name drawDetectedTitleBlockTextItem() -> createDetectedTitleBlockTextItem
|
||
2109 | 783c7845 | esham21 | '''
|
2110 | from TextItemFactory import TextItemFactory |
||
2111 | import math |
||
2112 | |||
2113 | try:
|
||
2114 | appDocData = AppDocData.instance() |
||
2115 | |||
2116 | # parse texts
|
||
2117 | for textInfo in textInfoList: |
||
2118 | 1dc16162 | esham21 | if len(textInfo[1]) is 0: |
2119 | continue
|
||
2120 | 478c2510 | esham21 | x = textInfo[1][0].getX() |
2121 | y = textInfo[1][0].getY() |
||
2122 | width = textInfo[1][0].getW() |
||
2123 | height = textInfo[1][0].getH() |
||
2124 | angle = round(math.radians(textInfo[1][0].getAngle()), 2) |
||
2125 | text = textInfo[1][0].getText() |
||
2126 | cc747b58 | esham21 | item = TextItemFactory.instance().createTextItem(textInfo) |
2127 | 783c7845 | esham21 | |
2128 | if item is not None: |
||
2129 | 14608af0 | esham21 | item.loc = [x, y] |
2130 | 783c7845 | esham21 | item.size = (width, height) |
2131 | item.angle = angle |
||
2132 | 478c2510 | esham21 | item.area = textInfo[0]
|
2133 | 853df487 | humkyung | # self.addTextItemToScene(item)
|
2134 | # appDocData.texts.append(item)
|
||
2135 | c61eefbf | esham21 | appDocData.allItems.append(item) |
2136 | 783c7845 | esham21 | except Exception as ex: |
2137 | e57134bc | esham21 | message = 'error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, |
2138 | 853df487 | humkyung | sys.exc_info()[-1].tb_lineno)
|
2139 | 783c7845 | esham21 | self.addMessage.emit(MessageType.Error, message)
|
2140 | |||
2141 | 15e26d1c | humkyung | '''
|
2142 | 1423a37c | humkyung | @brief
|
2143 | @author humkyung
|
||
2144 | @date 2018.08.23
|
||
2145 | 6e953094 | esham21 | @history 2018.11.26 euisung remove scene dependency
|
2146 | c6e0fc86 | esham21 | 2018.11.26 euisung isolate scene adding part -> drawDetectedItemsToScene()
|
2147 | 6a6e8be6 | esham21 | 2018.11. euisung no more used
|
2148 | 4148416a | esham21 | 2018.11.29 euisung change name drawDetectedLines() -> createDetectedLines
|
2149 | 1423a37c | humkyung | '''
|
2150 | 853df487 | humkyung | |
2151 | 4148416a | esham21 | def createDetectedLines(self, lineList, worker): |
2152 | 6e953094 | esham21 | appDocData = AppDocData.instance() |
2153 | area = appDocData.getArea('Drawing')
|
||
2154 | 1423a37c | humkyung | |
2155 | for pts in lineList: |
||
2156 | processLine = QEngineeringLineItem(vertices=[(area.x + param[0], area.y + param[1]) for param in pts]) |
||
2157 | baf331db | humkyung | processLine.area = 'Drawing'
|
2158 | 853df487 | humkyung | # self.graphicsView.scene.addItem(processLine)
|
2159 | 6e953094 | esham21 | appDocData.lines.append(processLine) |
2160 | c61eefbf | esham21 | appDocData.allItems.append(processLine) |
2161 | 1423a37c | humkyung | |
2162 | 853df487 | humkyung | # if processLine.length() > 100: # TODO: check critical length
|
2163 | 4a99d0e8 | esham21 | # processLine.addFlowArrow()
|
2164 | 853df487 | humkyung | |
2165 | 1423a37c | humkyung | # re-order process line's start,end according to flow mark
|
2166 | 853df487 | humkyung | # worker.arrangeLinePosition(lines, symbols, listWidget)
|
2167 | 1423a37c | humkyung | # up to here
|
2168 | |||
2169 | '''
|
||
2170 | e060a623 | esham21 | history 2018.06.09 humkyung check length of original and connection point is 2 while parsing
|
2171 | 6e953094 | esham21 | 2018.11.26 euisung remove scene dependency
|
2172 | 4148416a | esham21 | 2018.11.29 euisung change name drawDetectedSymbolItem() -> createDetectedSymbolItem
|
2173 | 15e26d1c | humkyung | '''
|
2174 | 853df487 | humkyung | |
2175 | 4148416a | esham21 | def createDetectedSymbolItem(self, symbolList): |
2176 | 8fd1d96f | humkyung | from GraphicsBoundingBoxItem import QGraphicsBoundingBoxItem |
2177 | 7ac6b06b | 김정우 | from SymbolSvgItem import SymbolSvgItem |
2178 | import math |
||
2179 | |||
2180 | try:
|
||
2181 | 936bbf2b | esham21 | appDocData = AppDocData.instance() |
2182 | project = appDocData.getCurrentProject() |
||
2183 | 7ac6b06b | 김정우 | |
2184 | 25e0cacb | Gyusu | searchedMap = [] |
2185 | 7ac6b06b | 김정우 | for symbol in symbolList: |
2186 | pt = [float(x) for x in symbol.getSp()] |
||
2187 | size = [symbol.getWidth(), symbol.getHeight()] |
||
2188 | name = symbol.getName() |
||
2189 | angle = round(math.radians(symbol.getRotatedAngle()), 2) |
||
2190 | d1a02244 | gaqhf | _type = symbol.getType() |
2191 | 9aaebab3 | esham21 | flip = symbol.getDetectFlip() |
2192 | 853df487 | humkyung | origin = [0, 0] |
2193 | 15e26d1c | humkyung | if 2 == len(symbol.getOriginalPoint().split(',')): |
2194 | tokens = symbol.getOriginalPoint().split(',')
|
||
2195 | origin = [pt[0] + float(tokens[0]), pt[1] + float(tokens[1])] |
||
2196 | 7ac6b06b | 김정우 | connPts = [] |
2197 | bf1b20fb | esham21 | if symbol.getConnectionPoint() is not None and symbol.getConnectionPoint() != '': |
2198 | 4edbb659 | humkyung | for param in symbol.getConnectionPoint().split('/'): |
2199 | tokens = param.split(',')
|
||
2200 | 853df487 | humkyung | connPts.append( |
2201 | ('AUTO', pt[0] + float(tokens[0]), pt[1] + float(tokens[1]), '0') if len(tokens) == 2 else \ |
||
2202 | (tokens[0], pt[0] + float(tokens[1]), pt[1] + float(tokens[2]), '0') if len( |
||
2203 | tokens) == 3 else \ |
||
2204 | (tokens[0], pt[0] + float(tokens[1]), pt[1] + float(tokens[2]), tokens[3]) if len( |
||
2205 | tokens) == 4 else None) |
||
2206 | 4edbb659 | humkyung | |
2207 | 34f2b549 | 김정우 | parentSymbol = symbol.getBaseSymbol() |
2208 | childSymbol = symbol.getAdditionalSymbol() |
||
2209 | 25e0cacb | Gyusu | hasInstrumentLabel = symbol.getHasInstrumentLabel() |
2210 | |||
2211 | d1a02244 | gaqhf | svgFilePath = os.path.join(project.getSvgFilePath(), _type, name + '.svg')
|
2212 | 7ac6b06b | 김정우 | if os.path.isfile(svgFilePath):
|
2213 | f0e763e8 | esham21 | svg = SymbolSvgItem.createItem(_type, svgFilePath, owner=None, flip=flip)
|
2214 | 853df487 | humkyung | # print(pt)
|
2215 | # print(origin)
|
||
2216 | svg.buildItem(name, _type, angle, pt, size, origin, connPts, parentSymbol, childSymbol, |
||
2217 | hasInstrumentLabel) |
||
2218 | dda5aa49 | gaqhf | svg.reCalculationRotatedItem() |
2219 | baf331db | humkyung | svg.area = 'Drawing'
|
2220 | 7ac6b06b | 김정우 | |
2221 | 25e0cacb | Gyusu | # set owner - 2018.07.20 added by humkyung
|
2222 | matches = [searched for searched in searchedMap if searched[0] == symbol.owner] |
||
2223 | if len(matches) == 1: |
||
2224 | svg.owner = matches[0][1] |
||
2225 | searchedMap.append((symbol, svg)) |
||
2226 | # up to here
|
||
2227 | |||
2228 | svg.transfer.onRemoved.connect(self.itemRemoved)
|
||
2229 | 853df487 | humkyung | # self.addSvgItemToScene(svg)
|
2230 | 936bbf2b | esham21 | appDocData.symbols.append(svg) |
2231 | c61eefbf | esham21 | appDocData.allItems.append(svg) |
2232 | 7ac6b06b | 김정우 | else:
|
2233 | item = QGraphicsBoundingBoxItem(pt[0], pt[1], size[0], size[1]) |
||
2234 | item.isSymbol = True
|
||
2235 | item.angle = angle |
||
2236 | 25e0cacb | Gyusu | item.setPen(QPen(Qt.red, 5, Qt.SolidLine))
|
2237 | 853df487 | humkyung | # self.graphicsView.scene.addItem(item)
|
2238 | # appDocData.symbols.append(item)
|
||
2239 | c61eefbf | esham21 | appDocData.allItems.append(item) |
2240 | f09eb8ff | 김정우 | # up to here
|
2241 | except Exception as ex: |
||
2242 | e57134bc | esham21 | message = 'error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, |
2243 | 853df487 | humkyung | sys.exc_info()[-1].tb_lineno)
|
2244 | e65b0bf8 | humkyung | self.addMessage.emit(MessageType.Error, message)
|
2245 | 7ac6b06b | 김정우 | |
2246 | 59384c70 | 김정우 | '''
|
2247 | @history 2018.06.08 Jeongwoo Add parameter on round method
|
||
2248 | 6e953094 | esham21 | @history 2018.11.02 euisung Add save note text item
|
2249 | @history 2018.11.05 euisung delete save note text item and move to drawDetectedItems()
|
||
2250 | 2018.11.26 euisung remove scene dependency
|
||
2251 | 4148416a | esham21 | 2018.11.29 euisung change name drawDetectedTextItem() -> createDetectedTextItem
|
2252 | 59384c70 | 김정우 | '''
|
2253 | 853df487 | humkyung | |
2254 | 4148416a | esham21 | def createDetectedTextItem(self, textInfoList): |
2255 | f09eb8ff | 김정우 | from TextItemFactory import TextItemFactory |
2256 | import math |
||
2257 | baf331db | humkyung | |
2258 | f09eb8ff | 김정우 | try:
|
2259 | baf331db | humkyung | appDocData = AppDocData.instance() |
2260 | |||
2261 | 7ac6b06b | 김정우 | # parse texts
|
2262 | f09eb8ff | 김정우 | for textInfo in textInfoList: |
2263 | x = textInfo.getX() |
||
2264 | y = textInfo.getY() |
||
2265 | width = textInfo.getW() |
||
2266 | height = textInfo.getH() |
||
2267 | 59384c70 | 김정우 | angle = round(math.radians(textInfo.getAngle()), 2) |
2268 | f09eb8ff | 김정우 | text = textInfo.getText() |
2269 | 1e145fc0 | humkyung | if not text: continue |
2270 | b7a0aff7 | gaqhf | |
2271 | cc747b58 | esham21 | item = TextItemFactory.instance().createTextItem(textInfo) |
2272 | 7ac6b06b | 김정우 | if item is not None: |
2273 | 14608af0 | esham21 | item.loc = [x, y] |
2274 | 7ac6b06b | 김정우 | item.size = (width, height) |
2275 | item.angle = angle |
||
2276 | baf331db | humkyung | item.area = 'Drawing'
|
2277 | 25e0cacb | Gyusu | item.transfer.onRemoved.connect(self.itemRemoved)
|
2278 | 853df487 | humkyung | # self.addTextItemToScene(item)
|
2279 | # appDocData.texts.append(item)
|
||
2280 | c61eefbf | esham21 | appDocData.allItems.append(item) |
2281 | f09eb8ff | 김정우 | except Exception as ex: |
2282 | e57134bc | esham21 | message = 'error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, |
2283 | 853df487 | humkyung | sys.exc_info()[-1].tb_lineno)
|
2284 | e65b0bf8 | humkyung | self.addMessage.emit(MessageType.Error, message)
|
2285 | 7ac6b06b | 김정우 | |
2286 | baf331db | humkyung | '''
|
2287 | @brief draw detected texts except which in drawing area
|
||
2288 | 4148416a | esham21 | @history 2018.11.29 euisung change name drawDetectedOtherTextItem() -> createDetectedOtherTextItem
|
2289 | baf331db | humkyung | '''
|
2290 | 853df487 | humkyung | |
2291 | 4148416a | esham21 | def createDetectedOtherTextItem(self, otherTextInfoList): |
2292 | f09eb8ff | 김정우 | from TextItemFactory import TextItemFactory |
2293 | import math |
||
2294 | baf331db | humkyung | |
2295 | f09eb8ff | 김정우 | try:
|
2296 | baf331db | humkyung | appDocData = AppDocData.instance() |
2297 | |||
2298 | 7ac6b06b | 김정우 | # parse notes
|
2299 | baf331db | humkyung | for textInfoMap in otherTextInfoList: |
2300 | 853df487 | humkyung | if textInfoMap[0] == 'Note' or textInfoMap[1] is None: |
2301 | abf4f001 | gaqhf | pass
|
2302 | |||
2303 | baf331db | humkyung | for textInfo in textInfoMap[1]: |
2304 | x = textInfo.getX() |
||
2305 | y = textInfo.getY() |
||
2306 | width = textInfo.getW() |
||
2307 | height = textInfo.getH() |
||
2308 | angle = round(math.radians(textInfo.getAngle()))
|
||
2309 | text = textInfo.getText() |
||
2310 | abf4f001 | gaqhf | |
2311 | cc747b58 | esham21 | item = TextItemFactory.instance().createTextItem(textInfo) |
2312 | abf4f001 | gaqhf | |
2313 | 14608af0 | esham21 | item.loc = [x, y] |
2314 | baf331db | humkyung | item.size = (width, height) |
2315 | item.angle = angle |
||
2316 | item.area = textInfoMap[0]
|
||
2317 | 94c4cd85 | humkyung | item.transfer.onRemoved.connect(self.itemRemoved)
|
2318 | 853df487 | humkyung | # appDocData.texts.append(item)
|
2319 | c61eefbf | esham21 | appDocData.allItems.append(item) |
2320 | 7ac6b06b | 김정우 | except Exception as ex: |
2321 | e57134bc | esham21 | message = 'error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, |
2322 | 853df487 | humkyung | sys.exc_info()[-1].tb_lineno)
|
2323 | e65b0bf8 | humkyung | self.addMessage.emit(MessageType.Error, message)
|
2324 | 7ac6b06b | 김정우 | |
2325 | '''
|
||
2326 | ccb42e9b | humkyung | @brief draw unknown items
|
2327 | @author humkyung
|
||
2328 | @date 2018.06.12
|
||
2329 | f74877aa | 김정우 | @history 2018.06.14 Jeongwoo Change method to add unknown item
|
2330 | 89b66b97 | 김정우 | 2018.06.18 Jeongwoo Add connect on unknown item
|
2331 | f44c85ee | 김정우 | Add [transfer] for using pyqtSignal
|
2332 | 6e953094 | esham21 | 2018.11.26 euisung remove scene dependency
|
2333 | c6e0fc86 | esham21 | 2018.11.26 euisung isolate scene adding part -> drawDetectedItemsToScene()
|
2334 | 93cfc465 | esham21 | 2018.11.27 euisung add save to xml
|
2335 | 4148416a | esham21 | 2018.11.29 euisung change name drawUnknownItems() -> createUnknownItems
|
2336 | ccb42e9b | humkyung | '''
|
2337 | 853df487 | humkyung | |
2338 | 4148416a | esham21 | def createUnknownItems(self, path): |
2339 | 853df487 | humkyung | from QEngineeringFlowArrowItem import QEngineeringFlowArrowItem |
2340 | 25e0cacb | Gyusu | from EngineeringLineItem import QEngineeringLineItem |
2341 | dc05dcb9 | humkyung | from EngineeringUnknownItem import QEngineeringUnknownItem |
2342 | 52e28a3a | humkyung | from SaveWorkCommand import SaveWorkCommand |
2343 | ccb42e9b | humkyung | |
2344 | try:
|
||
2345 | docData = AppDocData.instance() |
||
2346 | project = docData.getCurrentProject() |
||
2347 | windowSize = docData.getSlidingWindowSize() |
||
2348 | 4077103a | esham21 | |
2349 | ccb42e9b | humkyung | thickness = int(windowSize[1]) |
2350 | |||
2351 | 132ebe3b | esham21 | if docData.needReOpening is not None: |
2352 | docData.needReOpening = True
|
||
2353 | |||
2354 | 93cfc465 | esham21 | diffFilePath = os.path.join(project.getTempPath(), "DIFF_" + os.path.basename(path))
|
2355 | 12ee48dc | humkyung | if os.path.isfile(diffFilePath):
|
2356 | 853df487 | humkyung | imgDiff = cv2.threshold(cv2.cvtColor(cv2.imread(diffFilePath, 1), cv2.COLOR_BGR2GRAY), 127, 255, |
2357 | cv2.THRESH_BINARY)[1]
|
||
2358 | 12ee48dc | humkyung | |
2359 | 1423a37c | humkyung | ## remove line
|
2360 | 6e953094 | esham21 | lines = docData.lines |
2361 | 12ee48dc | humkyung | for line in lines: |
2362 | 853df487 | humkyung | line.drawToImage(imgDiff, 255, thickness) if line.thickness is None else line.drawToImage(imgDiff, |
2363 | 255,
|
||
2364 | line.thickness) |
||
2365 | 12ee48dc | humkyung | cv2.imwrite(diffFilePath, imgDiff) |
2366 | 1423a37c | humkyung | ## up to here
|
2367 | 12ee48dc | humkyung | |
2368 | imgNot = np.ones(imgDiff.shape, np.uint8) |
||
2369 | cv2.bitwise_not(imgDiff, imgNot) |
||
2370 | 87ad2c1a | esham21 | configs = docData.getConfigs('Filter', 'ErodeSize') |
2371 | kernel = int(configs[0].value) if 1 == len(configs) else 3 |
||
2372 | imgNot = cv2.erode(imgNot, np.ones((kernel, kernel), np.uint8)) |
||
2373 | imgNot = cv2.dilate(imgNot, np.ones((8 + kernel, 8 + kernel), np.uint8)) |
||
2374 | 12ee48dc | humkyung | |
2375 | deb37242 | humkyung | contours, hierarchy = cv2.findContours(imgNot, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE) |
2376 | 422da6c8 | esham21 | |
2377 | ##
|
||
2378 | ade0521c | esham21 | idx = 0
|
2379 | 422da6c8 | esham21 | ##
|
2380 | df052b57 | esham21 | smallContours = [] |
2381 | 6830e470 | esham21 | minimumSize = docData.getConfigs('Filter', 'MinimumSize') |
2382 | 12ee48dc | humkyung | for contour in contours: |
2383 | [x, y, w, h] = cv2.boundingRect(contour) |
||
2384 | |||
2385 | # remove too small one
|
||
2386 | 0bd1436f | esham21 | if len(minimumSize) is 1: |
2387 | if (w * h < int(minimumSize[0].value) * int(minimumSize[0].value)): |
||
2388 | df052b57 | esham21 | smallContours.append(contour) |
2389 | 0bd1436f | esham21 | idx += 1
|
2390 | continue
|
||
2391 | 12ee48dc | humkyung | |
2392 | 1423a37c | humkyung | '''
|
2393 | rect = QRectF(x, y, w, h)
|
||
2394 | items = [item for item in diffItems if item.boundingRect().contains(rect)]
|
||
2395 | if len(items) > 0: continue
|
||
2396 |
|
||
2397 | items = [item for item in diffItems if rect.contains(item.boundingRect())]
|
||
2398 | for item in items:
|
||
2399 | diffItems.remove(item)
|
||
2400 | '''
|
||
2401 | e19c7264 | esham21 | |
2402 | # create unknown item
|
||
2403 | 853df487 | humkyung | epsilon = cv2.arcLength(contour, True) * 0.001 |
2404 | e19c7264 | esham21 | approx = cv2.approxPolyDP(contour, epsilon, True)
|
2405 | approx = [pt[0] for pt in approx] |
||
2406 | 661c5a80 | esham21 | resultStr, resultList = self.determineRemainObject(idx, contours, imgNot)
|
2407 | df052b57 | esham21 | if resultStr == 'LineIndicator': |
2408 | 0a5f5fa3 | esham21 | item = QEngineeringUnknownItem(approx, 'True', resultList[0], resultList[1]) |
2409 | e19c7264 | esham21 | docData.lineIndicators.append(item) |
2410 | 0a5f5fa3 | esham21 | elif resultStr == 'MissingLine': |
2411 | pass
|
||
2412 | elif resultStr == 'Unknown': |
||
2413 | df052b57 | esham21 | item = QEngineeringUnknownItem(approx, 'False')
|
2414 | e19c7264 | esham21 | docData.unknowns.append(item) |
2415 | item.area = 'Drawing'
|
||
2416 | c61eefbf | esham21 | docData.allItems.append(item) |
2417 | e19c7264 | esham21 | item.transfer.onRemoved.connect(self.itemRemoved)
|
2418 | idx += 1
|
||
2419 | # up to here
|
||
2420 | 12ee48dc | humkyung | |
2421 | df052b57 | esham21 | imgNotRemoveSmall = cv2.drawContours(imgNot, smallContours, -1, 0, -1) |
2422 | 93cfc465 | esham21 | notFilePath = os.path.join(project.getTempPath(), "NOT_" + os.path.basename(path))
|
2423 | df052b57 | esham21 | cv2.imwrite(notFilePath, imgNotRemoveSmall) |
2424 | 12ee48dc | humkyung | else:
|
2425 | message = 'can\'t found {}'.format(diffFilePath)
|
||
2426 | e65b0bf8 | humkyung | self.addMessage.emit(MessageType.Normal, message)
|
2427 | 93cfc465 | esham21 | |
2428 | 746c8f97 | esham21 | self.dbUpdate()
|
2429 | 52e28a3a | humkyung | SaveWorkCommand.save_to_xml() |
2430 | ccb42e9b | humkyung | except Exception as ex: |
2431 | e57134bc | esham21 | message = 'error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, |
2432 | 853df487 | humkyung | sys.exc_info()[-1].tb_lineno)
|
2433 | e65b0bf8 | humkyung | self.addMessage.emit(MessageType.Error, message)
|
2434 | ccb42e9b | humkyung | |
2435 | 661c5a80 | esham21 | def determineRemainObject(self, idx, contours, imgNot): |
2436 | 7a6c7db7 | esham21 | '''
|
2437 | d0949b1e | esham21 | @brief determine remain objects -> line no indicator or unknown
|
2438 | 7a6c7db7 | esham21 | @author euisung
|
2439 | @date 2018.12.26
|
||
2440 | df052b57 | esham21 | @history 2019.03.25 euisung Change name isLineNoIndicator -> determineRemainObject
|
2441 | 7a6c7db7 | esham21 | '''
|
2442 | 1fa8e5e5 | esham21 | import math |
2443 | [x, y, w, h] = cv2.boundingRect(contours[idx]) |
||
2444 | 853df487 | humkyung | |
2445 | 15782c16 | esham21 | if (w < 250 and h < 250): |
2446 | return ('Unknown', []) |
||
2447 | 853df487 | humkyung | |
2448 | 7a6c7db7 | esham21 | fLines = [] |
2449 | 27b83026 | esham21 | maxDifAngle = 3
|
2450 | 7a6c7db7 | esham21 | mask = np.zeros_like(imgNot) |
2451 | 853df487 | humkyung | cv2.drawContours(mask, contours, idx, 123, -1) # Draw filled contour in mask |
2452 | out = np.zeros_like(imgNot) # Extract out the object and place into output image
|
||
2453 | 1fa8e5e5 | esham21 | out[mask == 123] = imgNot[mask == 123] |
2454 | 7a6c7db7 | esham21 | |
2455 | # Now crop
|
||
2456 | ##print(out)
|
||
2457 | (x, y) = np.where(mask == 123)
|
||
2458 | (topx, topy) = (np.min(x), np.min(y)) |
||
2459 | (bottomx, bottomy) = (np.max(x), np.max(y)) |
||
2460 | 853df487 | humkyung | out = out[topx:bottomx + 1, topy:bottomy + 1] |
2461 | 7a6c7db7 | esham21 | h, w = out.shape[0], out.shape[1] |
2462 | 853df487 | humkyung | maxDifH, maxDifW = math.ceil(math.tan(4 * math.pi / 180) / 2 * w), math.ceil( |
2463 | math.tan(4 * math.pi / 180) / 2 * h) |
||
2464 | 7a6c7db7 | esham21 | |
2465 | 0a5f5fa3 | esham21 | # detection lines
|
2466 | 7a6c7db7 | esham21 | edged2 = cv2.Canny(out, 100, 200) |
2467 | 853df487 | humkyung | lines = cv2.HoughLinesP(image=edged2, rho=1, theta=np.pi / 180, threshold=25, minLineLength=30, maxLineGap=25) |
2468 | # lines = cv2.HoughLines(edged2, 1, np.pi/180, 60)
|
||
2469 | 7a6c7db7 | esham21 | if lines is None: |
2470 | 0a5f5fa3 | esham21 | return ('Unknown', []) |
2471 | 7a6c7db7 | esham21 | for line in lines: |
2472 | 853df487 | humkyung | # r, theta = line[0]
|
2473 | # a, b = np.cos(theta), np.sin(theta)
|
||
2474 | # x0, y0 = a * r, b * r
|
||
2475 | # x1, y1 = int(x0 + 1000 * (-b)), int(y0 + 1000 * a)
|
||
2476 | # x2, y2 = int(x0 - 1000 * (-b)), int(y0 - 1000 * a)
|
||
2477 | # cv2.line(out, (x1, y1), (x2, y2), (0, 255, 0), 3)
|
||
2478 | 15782c16 | esham21 | x1, y1, x2, y2 = line[0]
|
2479 | 7a6c7db7 | esham21 | degree = math.atan2(y2 - y1, x2 - x1) * 180 / math.pi
|
2480 | fLine = [x1, y1, x2, y2, degree] |
||
2481 | 853df487 | humkyung | # print(fLine)
|
2482 | 7a6c7db7 | esham21 | fLines.append(fLine) |
2483 | 853df487 | humkyung | |
2484 | 7a6c7db7 | esham21 | horLines = [] |
2485 | verLines = [] |
||
2486 | otherLines = [] |
||
2487 | 428b08a3 | esham21 | isVH = None
|
2488 | 7a6c7db7 | esham21 | for fLine in fLines: |
2489 | degree = math.fabs(fLine[4])
|
||
2490 | 27b83026 | esham21 | if degree >= 90 - maxDifAngle: |
2491 | 7a6c7db7 | esham21 | verLines.append(fLine) |
2492 | 27b83026 | esham21 | elif degree <= maxDifAngle:
|
2493 | 7a6c7db7 | esham21 | horLines.append(fLine) |
2494 | else:
|
||
2495 | otherLines.append(fLine) |
||
2496 | 0a5f5fa3 | esham21 | |
2497 | c573a3b0 | esham21 | baseLines = [] |
2498 | baseDifV = 0
|
||
2499 | if len(horLines): |
||
2500 | x, y = w / 2, 0 |
||
2501 | baseDifV = maxDifH |
||
2502 | for horLine in horLines: |
||
2503 | x1, y1, x2, y2 = horLine[0], horLine[1], horLine[2], horLine[3] |
||
2504 | 853df487 | humkyung | y = ((y2 - y1) / (x2 - x1)) * x + y1 - ((y2 - y1) / (x2 - x1)) * x1 |
2505 | c573a3b0 | esham21 | horLine.append(y) |
2506 | baseLines = horLines |
||
2507 | isVH = 'H'
|
||
2508 | if len(verLines): |
||
2509 | x, y = 0, h / 2 |
||
2510 | baseDifV = maxDifW |
||
2511 | for verLine in verLines: |
||
2512 | x1, y1, x2, y2 = verLine[0], verLine[1], verLine[2], verLine[3] |
||
2513 | 853df487 | humkyung | x = ((x2 - x1) / (y2 - y1)) * y + x1 - ((x2 - x1) / (y2 - y1)) * y1 |
2514 | c573a3b0 | esham21 | verLine.append(x) |
2515 | baseLines = verLines |
||
2516 | isVH = 'V'
|
||
2517 | |||
2518 | for otherLine in otherLines: |
||
2519 | x, y = w / 2, 0 |
||
2520 | x1, y1, x2, y2 = otherLine[0], otherLine[1], otherLine[2], otherLine[3] |
||
2521 | 853df487 | humkyung | y = ((y2 - y1) / (x2 - x1)) * x + y1 - ((y2 - y1) / (x2 - x1)) * x1 |
2522 | c573a3b0 | esham21 | otherLine.append(y) |
2523 | |||
2524 | # determine line no indicator
|
||
2525 | 853df487 | humkyung | if not ((len(horLines) > 0 and len(verLines) > 0) or len(otherLines) is 0 or ( |
2526 | len(horLines) == 0 and len(verLines) == 0)): |
||
2527 | c573a3b0 | esham21 | result, mergedOtherLine = self.isLineNoIndicator(w, h, maxDifAngle, baseDifV, baseLines, otherLines)
|
2528 | if result:
|
||
2529 | 853df487 | humkyung | # print(fLines)
|
2530 | c573a3b0 | esham21 | return ('LineIndicator', [isVH, mergedOtherLine]) |
2531 | 0a5f5fa3 | esham21 | |
2532 | return ('Unknown', []) |
||
2533 | |||
2534 | c573a3b0 | esham21 | def isLineNoIndicator(self, w, h, maxDifAngle, baseDifV, baseLines, otherLines): |
2535 | 0a5f5fa3 | esham21 | '''
|
2536 | 6830e470 | esham21 | @brief determine line no indicator
|
2537 | 0a5f5fa3 | esham21 | @author euisung
|
2538 | @date 2019.03.25
|
||
2539 | '''
|
||
2540 | import math |
||
2541 | |||
2542 | if (w < 250 and h < 250): |
||
2543 | c573a3b0 | esham21 | return (False, None) |
2544 | 7a6c7db7 | esham21 | |
2545 | isSameLine = True
|
||
2546 | i = 0
|
||
2547 | for baseLine in baseLines: |
||
2548 | if not isSameLine: break |
||
2549 | j = 0
|
||
2550 | for baseLinee in baseLines: |
||
2551 | if i == j:
|
||
2552 | j += 1
|
||
2553 | continue
|
||
2554 | difV = math.fabs(baseLine[5] - baseLinee[5]) |
||
2555 | if difV > baseDifV:
|
||
2556 | 853df487 | humkyung | isSameLine = False
|
2557 | break
|
||
2558 | 7a6c7db7 | esham21 | j += 1
|
2559 | i += 1
|
||
2560 | if not isSameLine: |
||
2561 | c573a3b0 | esham21 | return (False, None) |
2562 | 7a6c7db7 | esham21 | |
2563 | isSameLine = True
|
||
2564 | i = 0
|
||
2565 | maxY = 0
|
||
2566 | for otherLine in otherLines: |
||
2567 | c573a3b0 | esham21 | y = otherLine[5]
|
2568 | 7a6c7db7 | esham21 | if math.fabs(y) > maxY:
|
2569 | maxY = math.fabs(y) |
||
2570 | if not isSameLine: break |
||
2571 | j = 0
|
||
2572 | for otherLinee in otherLines: |
||
2573 | if i == j:
|
||
2574 | j += 1
|
||
2575 | continue
|
||
2576 | difV = math.fabs(otherLine[4] - otherLinee[4]) |
||
2577 | 27b83026 | esham21 | if difV > maxDifAngle:
|
2578 | 853df487 | humkyung | isSameLine = False
|
2579 | break
|
||
2580 | 7a6c7db7 | esham21 | j += 1
|
2581 | i += 1
|
||
2582 | if not isSameLine: |
||
2583 | c573a3b0 | esham21 | return (False, None) |
2584 | 853df487 | humkyung | |
2585 | 7a6c7db7 | esham21 | isSameLine = True
|
2586 | 428b08a3 | esham21 | mergedOtherLine = [0, 0, 0, 0] |
2587 | 7a6c7db7 | esham21 | i = 0
|
2588 | maxDif = math.ceil(math.tan(4 * math.pi / 180) * maxY) |
||
2589 | for otherLine in otherLines: |
||
2590 | if not isSameLine: break |
||
2591 | j = 0
|
||
2592 | for otherLinee in otherLines: |
||
2593 | if i == j:
|
||
2594 | j += 1
|
||
2595 | continue
|
||
2596 | angle = math.fabs(otherLine[4] + otherLinee[4]) / 2 |
||
2597 | difV = math.fabs(otherLine[5] - otherLinee[5]) |
||
2598 | 853df487 | humkyung | dist = math.sin((90 - angle) * math.pi / 180) * difV |
2599 | 7a6c7db7 | esham21 | if dist > maxDif:
|
2600 | 853df487 | humkyung | isSameLine = False
|
2601 | break
|
||
2602 | 7a6c7db7 | esham21 | j += 1
|
2603 | i += 1
|
||
2604 | 428b08a3 | esham21 | mergedOtherLine[0] += otherLine[0] |
2605 | mergedOtherLine[1] += otherLine[1] |
||
2606 | mergedOtherLine[2] += otherLine[2] |
||
2607 | mergedOtherLine[3] += otherLine[3] |
||
2608 | 7a6c7db7 | esham21 | if not isSameLine: |
2609 | c573a3b0 | esham21 | (False, None) |
2610 | 853df487 | humkyung | |
2611 | 7a6c7db7 | esham21 | # Show the output image
|
2612 | 853df487 | humkyung | # print('line no indicator')
|
2613 | 27b83026 | esham21 | mergedOtherLine[0] = round(mergedOtherLine[0] / len(otherLines)) |
2614 | mergedOtherLine[1] = round(mergedOtherLine[1] / len(otherLines)) |
||
2615 | mergedOtherLine[2] = round(mergedOtherLine[2] / len(otherLines)) |
||
2616 | mergedOtherLine[3] = round(mergedOtherLine[3] / len(otherLines)) |
||
2617 | 853df487 | humkyung | # cv2.line(out, (mergedOtherLine[0], mergedOtherLine[1]), (mergedOtherLine[2], mergedOtherLine[3]), (255, 255, 255), 3)
|
2618 | # cv2.imshow('Output', out)
|
||
2619 | # cv2.waitKey(0)
|
||
2620 | # cv2.destroyAllWindows()
|
||
2621 | c573a3b0 | esham21 | return (True, mergedOtherLine) |
2622 | 7a6c7db7 | esham21 | |
2623 | 0de8c1ca | esham21 | def init_add_tree_item(self, line_no_tree_item, run_item): |
2624 | """ insert symbol item and find line no as owner """
|
||
2625 | # insert
|
||
2626 | self.itemTreeWidget.addTreeItem(line_no_tree_item, run_item)
|
||
2627 | # find
|
||
2628 | self.itemTreeWidget.addTreeItem(line_no_tree_item, run_item)
|
||
2629 | |||
2630 | 2796938f | humkyung | def load_drawing(self, drawing): |
2631 | """ load drawing """
|
||
2632 | 60f50aee | humkyung | from EngineeringRunItem import QEngineeringRunItem |
2633 | from QEngineeringTrimLineNoTextItem import QEngineeringTrimLineNoTextItem |
||
2634 | |||
2635 | 2796938f | humkyung | app_doc_data = AppDocData.instance() |
2636 | 60f50aee | humkyung | try:
|
2637 | symbols = [] |
||
2638 | lines = [] |
||
2639 | |||
2640 | 2796938f | humkyung | components = app_doc_data.get_components(drawing.UID) |
2641 | 60f50aee | humkyung | maxValue = len(components)
|
2642 | 708824e3 | esham21 | self.progress.setMaximum(maxValue) if maxValue > 0 else None |
2643 | 60f50aee | humkyung | |
2644 | """ parsing all symbols """
|
||
2645 | 11ed99c3 | esham21 | for symbol in [component for component in components if int(component['SymbolType_UID']) != -1]: |
2646 | 2796938f | humkyung | item = SymbolSvgItem.from_database(symbol) |
2647 | 60f50aee | humkyung | if item is not None: |
2648 | item.transfer.onRemoved.connect(self.itemRemoved)
|
||
2649 | symbols.append(item) |
||
2650 | app_doc_data.symbols.append(item) |
||
2651 | self.addSvgItemToScene(item)
|
||
2652 | else:
|
||
2653 | pt = [float(symbol['X']), float(symbol['Y'])] |
||
2654 | size = [float(symbol['Width']), float(symbol['Height'])] |
||
2655 | angle = float(symbol['Rotation']) |
||
2656 | item = QGraphicsBoundingBoxItem(pt[0], pt[1], size[0], size[1]) |
||
2657 | item.isSymbol = True
|
||
2658 | item.angle = angle |
||
2659 | item.setPen(QPen(Qt.red, 5, Qt.SolidLine))
|
||
2660 | self.graphicsView.scene.addItem(item)
|
||
2661 | item.transfer.onRemoved.connect(self.itemRemoved)
|
||
2662 | |||
2663 | self.progress.setValue(self.progress.value() + 1) |
||
2664 | 853df487 | humkyung | |
2665 | 60f50aee | humkyung | QApplication.processEvents() |
2666 | |||
2667 | # parse texts
|
||
2668 | 853df487 | humkyung | for text in [component for component in components if |
2669 | component['Name'] == 'Text' and component['SymbolType_UID'] == -1]: |
||
2670 | 60f50aee | humkyung | item = QEngineeringTextItem.from_database(text) |
2671 | if item is not None: |
||
2672 | item.uid = text['UID']
|
||
2673 | item.attribute = text['Value']
|
||
2674 | name = text['Name']
|
||
2675 | item.transfer.onRemoved.connect(self.itemRemoved)
|
||
2676 | self.addTextItemToScene(item)
|
||
2677 | |||
2678 | self.progress.setValue(self.progress.value() + 1) |
||
2679 | 853df487 | humkyung | |
2680 | 60f50aee | humkyung | QApplication.processEvents() |
2681 | |||
2682 | # note
|
||
2683 | 853df487 | humkyung | for note in [component for component in components if |
2684 | component['Name'] == 'Note' and component['SymbolType_UID'] == -1]: |
||
2685 | 60f50aee | humkyung | item = QEngineeringTextItem.from_database(note) |
2686 | if item is not None: |
||
2687 | item.uid = note['UID']
|
||
2688 | attributeValue = note['Value']
|
||
2689 | name = note['Name']
|
||
2690 | item.transfer.onRemoved.connect(self.itemRemoved)
|
||
2691 | self.addTextItemToScene(item)
|
||
2692 | |||
2693 | self.progress.setValue(self.progress.value() + 1) |
||
2694 | 853df487 | humkyung | |
2695 | 60f50aee | humkyung | QApplication.processEvents() |
2696 | |||
2697 | 853df487 | humkyung | for line in [component for component in components if |
2698 | component['Name'] == 'Line' and component['SymbolType_UID'] == -1]: |
||
2699 | 60f50aee | humkyung | item = QEngineeringLineItem.from_database(line) |
2700 | if item:
|
||
2701 | item.transfer.onRemoved.connect(self.itemRemoved)
|
||
2702 | self.graphicsView.scene.addItem(item)
|
||
2703 | lines.append(item) |
||
2704 | |||
2705 | self.progress.setValue(self.progress.value() + 1) |
||
2706 | 853df487 | humkyung | |
2707 | 60f50aee | humkyung | QApplication.processEvents() |
2708 | |||
2709 | 853df487 | humkyung | for unknown in [component for component in components if |
2710 | component['Name'] == 'Unknown' and component['SymbolType_UID'] == -1]: |
||
2711 | 60f50aee | humkyung | item = QEngineeringUnknownItem.from_database(unknown) |
2712 | item.transfer.onRemoved.connect(self.itemRemoved)
|
||
2713 | if item is not None: |
||
2714 | item.transfer.onRemoved.connect(self.itemRemoved)
|
||
2715 | self.graphicsView.scene.addItem(item)
|
||
2716 | |||
2717 | self.progress.setValue(self.progress.value() + 1) |
||
2718 | 853df487 | humkyung | |
2719 | 60f50aee | humkyung | QApplication.processEvents() |
2720 | |||
2721 | 853df487 | humkyung | for component in [component for component in components if |
2722 | component['Name'] == 'Line NO' and component['SymbolType_UID'] == -1]: |
||
2723 | 60f50aee | humkyung | line_no = QEngineeringLineNoTextItem.from_database(component) |
2724 | 228fd9b3 | humkyung | if type(line_no) is QEngineeringLineNoTextItem: |
2725 | line_no.transfer.onRemoved.connect(self.itemRemoved)
|
||
2726 | self.addTextItemToScene(line_no)
|
||
2727 | line_no_tree_item = self.itemTreeWidget.addTreeItem(self.itemTreeWidget.root, line_no) |
||
2728 | |||
2729 | runs = app_doc_data.get_pipe_runs(str(line_no.uid))
|
||
2730 | if not runs: continue |
||
2731 | for run in runs: |
||
2732 | line_run = QEngineeringRunItem() |
||
2733 | run_items = app_doc_data.get_pipe_run_items(run['UID'])
|
||
2734 | for record in run_items: |
||
2735 | uid = record['Components_UID']
|
||
2736 | run_item = self.graphicsView.findItemByUid(uid)
|
||
2737 | if run_item is not None: |
||
2738 | run_item._owner = line_no |
||
2739 | line_run.items.append(run_item) |
||
2740 | line_run.owner = line_no |
||
2741 | line_no.runs.append(line_run) |
||
2742 | |||
2743 | for run_item in line_run.items: |
||
2744 | 0de8c1ca | esham21 | if issubclass(type(run_item), SymbolSvgItem): |
2745 | self.init_add_tree_item(line_no_tree_item, run_item)
|
||
2746 | 60f50aee | humkyung | |
2747 | self.progress.setValue(self.progress.value() + 1) |
||
2748 | QApplication.processEvents() |
||
2749 | |||
2750 | 853df487 | humkyung | for component in [component for component in components if |
2751 | component['Name'] == 'Trim Line NO' and component['SymbolType_UID'] == -1]: |
||
2752 | 60f50aee | humkyung | line_no = QEngineeringTrimLineNoTextItem() |
2753 | e5e77709 | esham21 | line_no.uid = uuid.UUID(component['UID'])
|
2754 | 60f50aee | humkyung | |
2755 | runs = app_doc_data.get_pipe_runs(str(line_no.uid))
|
||
2756 | if not runs: continue |
||
2757 | for run in runs: |
||
2758 | line_run = QEngineeringRunItem() |
||
2759 | run_items = app_doc_data.get_pipe_run_items(run['UID'])
|
||
2760 | for record in run_items: |
||
2761 | uid = record['Components_UID']
|
||
2762 | run_item = self.graphicsView.findItemByUid(uid)
|
||
2763 | if run_item is not None: |
||
2764 | run_item.owner = line_no |
||
2765 | line_run.items.append(run_item) |
||
2766 | line_no.runs.append(line_run) |
||
2767 | line_no_tree_item = self.itemTreeWidget.addTreeItem(self.itemTreeWidget.root, line_no) |
||
2768 | 853df487 | humkyung | |
2769 | 60f50aee | humkyung | for run_item in line_run.items: |
2770 | 0de8c1ca | esham21 | if issubclass(type(run_item), SymbolSvgItem): |
2771 | self.init_add_tree_item(line_no_tree_item, run_item)
|
||
2772 | 60f50aee | humkyung | |
2773 | 2796938f | humkyung | app_doc_data.tracerLineNos.append(line_no) |
2774 | 60f50aee | humkyung | |
2775 | self.progress.setValue(self.progress.value() + 1) |
||
2776 | |||
2777 | 853df487 | humkyung | for component in [component for component in components if |
2778 | component['Name'] == 'VendorPackage' and component['SymbolType_UID'] == -1]: |
||
2779 | 60f50aee | humkyung | item = QEngineeringVendorItem.from_database(component) |
2780 | 8329204f | esham21 | if item is not None: |
2781 | item.transfer.onRemoved.connect(self.itemRemoved)
|
||
2782 | self.graphicsView.scene.addItem(item)
|
||
2783 | 60f50aee | humkyung | |
2784 | # connect flow item to line
|
||
2785 | for line in lines: |
||
2786 | line.update_arrow() |
||
2787 | 853df487 | humkyung | # for flowMark in [item for item in symbols if type(item) is QEngineeringFlowMarkItem]:
|
2788 | 60f50aee | humkyung | # for line in lines:
|
2789 | # if flowMark.owner is line:
|
||
2790 | # line._flowMark.append(flowMark)
|
||
2791 | # flowMark.setParentItem(line)
|
||
2792 | # up to here
|
||
2793 | |||
2794 | """ update scene """
|
||
2795 | self.graphicsView.scene.update(self.graphicsView.sceneRect()) |
||
2796 | for item in self.graphicsView.scene.items(): |
||
2797 | item.setVisible(True)
|
||
2798 | 853df487 | humkyung | |
2799 | 60f50aee | humkyung | # binding items
|
2800 | if hasattr(item, 'owner'): |
||
2801 | item.owner |
||
2802 | if hasattr(item, 'connectors'): |
||
2803 | for connector in item.connectors: |
||
2804 | connector.connectedItem |
||
2805 | |||
2806 | except Exception as ex: |
||
2807 | e57134bc | esham21 | message = 'error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, |
2808 | 853df487 | humkyung | sys.exc_info()[-1].tb_lineno)
|
2809 | 60f50aee | humkyung | self.addMessage.emit(MessageType.Error, message)
|
2810 | finally:
|
||
2811 | c5410c70 | esham21 | app_doc_data.clearTempDBData |
2812 | 853df487 | humkyung | # self.graphicsView.scene.blockSignals(False)
|
2813 | 60f50aee | humkyung | |
2814 | ccb42e9b | humkyung | '''
|
2815 | d8ddd93d | humkyung | @brief load recognition result
|
2816 | @author humkyung
|
||
2817 | @date 2018.04.??
|
||
2818 | @history humkyung 2018.01.12 parse originalpoint and connectionpoint
|
||
2819 | d86f328a | 김정우 | Jeongwoo 2018.04.17 add QGraphicItem with Rotated text
|
2820 | 7b2a4455 | 김정우 | Jeongwoo 2018.04.23 Change to Draw texts on QEngineeringTextItem
|
2821 | 68ce37ea | humkyung | humkyung 2018.04.23 connect item remove slot to result tree
|
2822 | b9440d40 | 김정우 | Jeongwoo 2018.04.25 Add if state with QEngineeringNoteItem
|
2823 | aa1b6842 | 김정우 | Jeongwoo 2018.04.26 Change method to create TextItem object with TextItemFactory
|
2824 | a67b3200 | 김정우 | Jeongwoo 2018.05.03 Change method to draw Svg Item on Scene (svg.addSvgItemToScene)
|
2825 | 7ac6b06b | 김정우 | Jeongwoo 2018.05.29 Change method name / Change method to add item / Add Line item
|
2826 | f09eb8ff | 김정우 | Jeongwoo 2018.05.30 Add parameters on SymbolSvgItem.__init__() (parentSymbol, childSymbol) / Change method name / Change XML NODE NAMES
|
2827 | f4130ef7 | 김정우 | Jeongwoo 2018.06.12 Add LineNoTextItem from LINE_NO
|
2828 | f74877aa | 김정우 | Jeongwoo 2018.06.14 Add UnknownItem from UNKNOWN
|
2829 | 89b66b97 | 김정우 | Jeongwoo 2018.06.18 Update Scene after all item added
|
2830 | f44c85ee | 김정우 | Add connect on unknown item
|
2831 | Add [transfer] for using pyqtSignal
|
||
2832 | 25e0cacb | Gyusu | kyouho 2018.07.12 Add line property logic
|
2833 | 77a35abf | humkyung | humkyung 2018.08.22 show progress while loading xml file
|
2834 | 55003315 | esham21 | 2018.11.22 euisung fix note road
|
2835 | e4b3e191 | humkyung | '''
|
2836 | 853df487 | humkyung | |
2837 | f09eb8ff | 김정우 | def loadRecognitionResultFromXml(self, xmlPath): |
2838 | 87497674 | gaqhf | docData = AppDocData.instance() |
2839 | e4b3e191 | humkyung | from xml.etree.ElementTree import Element, SubElement, dump, ElementTree, parse |
2840 | 87497674 | gaqhf | from EngineeringRunItem import QEngineeringRunItem |
2841 | from QEngineeringTrimLineNoTextItem import QEngineeringTrimLineNoTextItem |
||
2842 | e4b3e191 | humkyung | |
2843 | try:
|
||
2844 | 853df487 | humkyung | # self.graphicsView.scene.blockSignals(True)
|
2845 | 990644d9 | humkyung | |
2846 | 25e0cacb | Gyusu | symbols = [] |
2847 | d28da625 | esham21 | lines = [] |
2848 | 0a748a0d | humkyung | |
2849 | e4b3e191 | humkyung | xml = parse(xmlPath) |
2850 | 7ac6b06b | 김정우 | root = xml.getroot() |
2851 | 853df487 | humkyung | |
2852 | 77a35abf | humkyung | maxValue = 0
|
2853 | 853df487 | humkyung | maxValue = maxValue + len(list(root.iter('SYMBOL'))) - len( |
2854 | list(root.iterfind('LINENOS/LINE_NO/RUN/SYMBOL'))) - len( |
||
2855 | list(root.iterfind('TRIMLINENOS/TRIM_LINE_NO/RUN/SYMBOL'))) |
||
2856 | d061e6ee | humkyung | maxValue = maxValue + len(list(root.iterfind('TEXTINFOS/ATTRIBUTE'))) |
2857 | maxValue = maxValue + len(list(root.iterfind('NOTES/ATTRIBUTE'))) |
||
2858 | 77a35abf | humkyung | maxValue = maxValue + len(list(root.iter('LINE_NO'))) |
2859 | 853df487 | humkyung | maxValue = maxValue + len(list(root.iter('LINE'))) - len( |
2860 | list(root.iterfind('LINENOS/LINE_NO/RUN/LINE'))) - len( |
||
2861 | list(root.iterfind('TRIMLINENOS/TRIM_LINE_NO/RUN/LINE'))) |
||
2862 | 77a35abf | humkyung | maxValue = maxValue + len(list(root.iter('UNKNOWN'))) |
2863 | 853df487 | humkyung | # maxValue = maxValue + len(list(root.iter('SIZETEXT')))
|
2864 | f15587ee | esham21 | maxValue = maxValue + len(list(root.iter('TRIM_LINE_NO'))) |
2865 | 708824e3 | esham21 | self.progress.setMaximum(maxValue) if maxValue > 0 else None |
2866 | 77a35abf | humkyung | |
2867 | 990644d9 | humkyung | """ parsing all symbols """
|
2868 | 87497674 | gaqhf | for symbol in root.find('SYMBOLS').iter('SYMBOL'): |
2869 | 25e0cacb | Gyusu | item = SymbolSvgItem.fromXml(symbol) |
2870 | 5a4d5665 | humkyung | if item is not None: |
2871 | item.transfer.onRemoved.connect(self.itemRemoved)
|
||
2872 | 8b1a59d5 | esham21 | symbols.append(item) |
2873 | a56a12dd | esham21 | docData.symbols.append(item) |
2874 | self.addSvgItemToScene(item)
|
||
2875 | 02ed19e4 | humkyung | else:
|
2876 | 25e0cacb | Gyusu | pt = [float(x) for x in symbol.find('LOCATION').text.split(',')] |
2877 | size = [float(x) for x in symbol.find('SIZE').text.split(',')] |
||
2878 | angle = float(symbol.find('ANGLE').text) |
||
2879 | 02ed19e4 | humkyung | item = QGraphicsBoundingBoxItem(pt[0], pt[1], size[0], size[1]) |
2880 | item.isSymbol = True
|
||
2881 | item.angle = angle |
||
2882 | 25e0cacb | Gyusu | item.setPen(QPen(Qt.red, 5, Qt.SolidLine))
|
2883 | 02ed19e4 | humkyung | self.graphicsView.scene.addItem(item)
|
2884 | fe0bc5d7 | esham21 | item.transfer.onRemoved.connect(self.itemRemoved)
|
2885 | 46e67073 | humkyung | |
2886 | 77a35abf | humkyung | self.progress.setValue(self.progress.value() + 1) |
2887 | 853df487 | humkyung | |
2888 | 77a35abf | humkyung | QApplication.processEvents() |
2889 | |||
2890 | 46e67073 | humkyung | # parse texts
|
2891 | 763f6ba0 | humkyung | for text in root.find('TEXTINFOS').iter('ATTRIBUTE'): |
2892 | baf331db | humkyung | item = QEngineeringTextItem.fromXml(text) |
2893 | if item is not None: |
||
2894 | uid = text.find('UID')
|
||
2895 | attributeValue = text.find('ATTRIBUTEVALUE')
|
||
2896 | name = text.find('NAME').text
|
||
2897 | item.transfer.onRemoved.connect(self.itemRemoved)
|
||
2898 | self.addTextItemToScene(item)
|
||
2899 | 853df487 | humkyung | # docData.texts.append(item)
|
2900 | baf331db | humkyung | |
2901 | if name == 'TEXT': |
||
2902 | 16ca5a01 | gaqhf | if uid is not None and attributeValue is not None: |
2903 | item.uid = uid.text |
||
2904 | item.attribute = attributeValue.text |
||
2905 | 388e1ee8 | esham21 | |
2906 | self.progress.setValue(self.progress.value() + 1) |
||
2907 | 853df487 | humkyung | |
2908 | 388e1ee8 | esham21 | QApplication.processEvents() |
2909 | |||
2910 | # note
|
||
2911 | for text in root.find('NOTES').iter('ATTRIBUTE'): |
||
2912 | item = QEngineeringTextItem.fromXml(text) |
||
2913 | if item is not None: |
||
2914 | uid = text.find('UID')
|
||
2915 | attributeValue = text.find('ATTRIBUTEVALUE')
|
||
2916 | name = text.find('NAME').text
|
||
2917 | item.transfer.onRemoved.connect(self.itemRemoved)
|
||
2918 | self.addTextItemToScene(item)
|
||
2919 | |||
2920 | if name == 'NOTE': |
||
2921 | 16ca5a01 | gaqhf | if uid is not None: |
2922 | item.uid = uid.text |
||
2923 | 77a35abf | humkyung | |
2924 | self.progress.setValue(self.progress.value() + 1) |
||
2925 | 853df487 | humkyung | |
2926 | 735aac62 | gaqhf | QApplication.processEvents() |
2927 | 25e0cacb | Gyusu | |
2928 | 87497674 | gaqhf | for line in root.find('LINEINFOS').iter('LINE'): |
2929 | item = QEngineeringLineItem.fromXml(line) |
||
2930 | df4661c5 | humkyung | if item:
|
2931 | d28da625 | esham21 | item.transfer.onRemoved.connect(self.itemRemoved)
|
2932 | df4661c5 | humkyung | self.graphicsView.scene.addItem(item)
|
2933 | d28da625 | esham21 | lines.append(item) |
2934 | 87497674 | gaqhf | |
2935 | self.progress.setValue(self.progress.value() + 1) |
||
2936 | 853df487 | humkyung | |
2937 | 87497674 | gaqhf | QApplication.processEvents() |
2938 | |||
2939 | for unknown in root.iter('UNKNOWN'): |
||
2940 | item = QEngineeringUnknownItem.fromXml(unknown) |
||
2941 | if item is not None: |
||
2942 | item.transfer.onRemoved.connect(self.itemRemoved)
|
||
2943 | 5a4d5665 | humkyung | self.graphicsView.scene.addItem(item)
|
2944 | 87497674 | gaqhf | |
2945 | self.progress.setValue(self.progress.value() + 1) |
||
2946 | 853df487 | humkyung | |
2947 | 87497674 | gaqhf | QApplication.processEvents() |
2948 | |||
2949 | 853df487 | humkyung | # """ add tree widget """
|
2950 | # for item in symbols:
|
||
2951 | a56a12dd | esham21 | # docData.symbols.append(item)
|
2952 | # self.addSvgItemToScene(item)
|
||
2953 | # self.itemTreeWidget.addTreeItem(self.itemTreeWidget.root, item)
|
||
2954 | 5a4d5665 | humkyung | |
2955 | 990644d9 | humkyung | for line_no_node in root.find('LINENOS').iter('LINE_NO'): |
2956 | line_no = QEngineeringLineNoTextItem.fromXml(line_no_node) |
||
2957 | 5a4d5665 | humkyung | if line_no is None: continue |
2958 | line_no.transfer.onRemoved.connect(self.itemRemoved)
|
||
2959 | self.addTextItemToScene(line_no)
|
||
2960 | line_no_tree_item = self.itemTreeWidget.addTreeItem(self.itemTreeWidget.root, line_no) |
||
2961 | 48cabe25 | humkyung | if type(line_no) is not QEngineeringLineNoTextItem: continue |
2962 | 1dbb865c | gaqhf | |
2963 | 990644d9 | humkyung | runs_node = line_no_node.findall('RUN')
|
2964 | 5a4d5665 | humkyung | if runs_node is None: continue |
2965 | |||
2966 | for run_node in runs_node: |
||
2967 | line_run = QEngineeringRunItem() |
||
2968 | for child_node in run_node: |
||
2969 | uidElement = child_node.find('UID')
|
||
2970 | if uidElement is not None: |
||
2971 | uid = uidElement.text |
||
2972 | run_item = self.graphicsView.findItemByUid(uid)
|
||
2973 | if run_item is not None: |
||
2974 | 8138f238 | humkyung | run_item._owner = line_no |
2975 | 5a4d5665 | humkyung | line_run.items.append(run_item) |
2976 | line_run.owner = line_no |
||
2977 | line_no.runs.append(line_run) |
||
2978 | |||
2979 | for run_item in line_run.items: |
||
2980 | 0de8c1ca | esham21 | if issubclass(type(run_item), SymbolSvgItem): |
2981 | self.init_add_tree_item(line_no_tree_item, run_item)
|
||
2982 | 5a4d5665 | humkyung | |
2983 | 853df487 | humkyung | # docData.tracerLineNos.append(line_no)
|
2984 | f74877aa | 김정우 | |
2985 | 77a35abf | humkyung | self.progress.setValue(self.progress.value() + 1) |
2986 | QApplication.processEvents() |
||
2987 | |||
2988 | 87497674 | gaqhf | for trimLineNo in root.iter('TRIM_LINE_NO'): |
2989 | 5a4d5665 | humkyung | line_no = QEngineeringTrimLineNoTextItem() |
2990 | e5e77709 | esham21 | line_no.uid = uuid.UUID(trimLineNo.find('UID').text)
|
2991 | 87497674 | gaqhf | |
2992 | run = trimLineNo.find('RUN')
|
||
2993 | if run is not None: |
||
2994 | 5a4d5665 | humkyung | line_run = QEngineeringRunItem() |
2995 | 87497674 | gaqhf | for child in run: |
2996 | uidElement = child.find('UID')
|
||
2997 | if uidElement is not None: |
||
2998 | uid = uidElement.text |
||
2999 | 5a4d5665 | humkyung | run_item = self.graphicsView.findItemByUid(uid)
|
3000 | if run_item is not None: |
||
3001 | 38dbda17 | esham21 | run_item.owner = line_no |
3002 | 5a4d5665 | humkyung | line_run.items.append(run_item) |
3003 | line_no.runs.append(line_run) |
||
3004 | line_no_tree_item = self.itemTreeWidget.addTreeItem(self.itemTreeWidget.root, line_no) |
||
3005 | 853df487 | humkyung | |
3006 | 5a4d5665 | humkyung | for run_item in line_run.items: |
3007 | 0de8c1ca | esham21 | if issubclass(type(run_item), SymbolSvgItem): |
3008 | self.init_add_tree_item(line_no_tree_item, run_item)
|
||
3009 | 38dbda17 | esham21 | |
3010 | 5a4d5665 | humkyung | docData.tracerLineNos.append(line_no) |
3011 | f15587ee | esham21 | |
3012 | self.progress.setValue(self.progress.value() + 1) |
||
3013 | 7a3315ea | esham21 | QApplication.processEvents() |
3014 | f15587ee | esham21 | |
3015 | ff096d3a | esham21 | if root.find('VENDORS') is not None: |
3016 | for vendor in root.find('VENDORS').iter('VENDOR'): |
||
3017 | item = QEngineeringVendorItem.fromXml(vendor) |
||
3018 | item.transfer.onRemoved.connect(self.itemRemoved)
|
||
3019 | self.graphicsView.scene.addItem(item)
|
||
3020 | d28da625 | esham21 | |
3021 | 229cfccb | esham21 | # connect flow item to line
|
3022 | 0de0c0c4 | esham21 | for line in lines: |
3023 | line.update_arrow() |
||
3024 | 853df487 | humkyung | # for flowMark in [item for item in symbols if type(item) is QEngineeringFlowMarkItem]:
|
3025 | a21d65cb | esham21 | # for line in lines:
|
3026 | # if flowMark.owner is line:
|
||
3027 | # line._flowMark.append(flowMark)
|
||
3028 | # flowMark.setParentItem(line)
|
||
3029 | 77a35abf | humkyung | # up to here
|
3030 | 7aa3c8e5 | gaqhf | |
3031 | 990644d9 | humkyung | """ update scene """
|
3032 | 89b66b97 | 김정우 | self.graphicsView.scene.update(self.graphicsView.sceneRect()) |
3033 | 7765b508 | humkyung | for item in self.graphicsView.scene.items(): |
3034 | item.setVisible(True)
|
||
3035 | 853df487 | humkyung | |
3036 | 94302d85 | esham21 | # binding items
|
3037 | if hasattr(item, 'owner'): |
||
3038 | item.owner |
||
3039 | if hasattr(item, 'connectors'): |
||
3040 | for connector in item.connectors: |
||
3041 | connector.connectedItem |
||
3042 | d28da625 | esham21 | |
3043 | e4b3e191 | humkyung | except Exception as ex: |
3044 | e57134bc | esham21 | message = 'error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, |
3045 | 853df487 | humkyung | sys.exc_info()[-1].tb_lineno)
|
3046 | e65b0bf8 | humkyung | self.addMessage.emit(MessageType.Error, message)
|
3047 | 990644d9 | humkyung | finally:
|
3048 | 7552be56 | humkyung | pass
|
3049 | 853df487 | humkyung | # self.graphicsView.scene.blockSignals(False)
|
3050 | e4b3e191 | humkyung | |
3051 | '''
|
||
3052 | 7ac6b06b | 김정우 | @brief Remove added item on same place and Add GraphicsItem
|
3053 | @author Jeongwoo
|
||
3054 | @date 2018.05.25
|
||
3055 | @history 2018.05.29 Jeongwoo Moved from QRecognitionDialog
|
||
3056 | 89b66b97 | 김정우 | 2018.06.18 Jeongwoo Set Z-index
|
3057 | 7ac6b06b | 김정우 | '''
|
3058 | 853df487 | humkyung | |
3059 | 7ac6b06b | 김정우 | def addSvgItemToScene(self, svgItem): |
3060 | svgItem.addSvgItemToScene(self.graphicsView.scene)
|
||
3061 | 853df487 | humkyung | |
3062 | 7ac6b06b | 김정우 | '''
|
3063 | @brief Remove added item on same place and Add GraphicsItem
|
||
3064 | @author Jeongwoo
|
||
3065 | @date 2018.05.25
|
||
3066 | @history 2018.05.29 Jeongwoo Moved from QRecognitionDialog
|
||
3067 | 2e71e478 | 김정우 | 2018.06.05 Jeongwoo Remove Size condition
|
3068 | 89b66b97 | 김정우 | 2018.06.18 Jeongwoo Set Z-index
|
3069 | 7ac6b06b | 김정우 | '''
|
3070 | 853df487 | humkyung | |
3071 | 7ac6b06b | 김정우 | def addTextItemToScene(self, textItem): |
3072 | textItem.addTextItemToScene(self.graphicsView.scene)
|
||
3073 | 853df487 | humkyung | |
3074 | 7ac6b06b | 김정우 | '''
|
3075 | @brief Remove added item on same place and Add GraphicsItem
|
||
3076 | @author Jeongwoo
|
||
3077 | @date 2018.05.29
|
||
3078 | 89b66b97 | 김정우 | @history 2018.06.18 Jeongwoo Set Z-index
|
3079 | 7ac6b06b | 김정우 | '''
|
3080 | 853df487 | humkyung | |
3081 | 7ac6b06b | 김정우 | def addLineItemToScene(self, lineItem): |
3082 | 7765b508 | humkyung | self.graphicsView.scene.addItem(lineItem)
|
3083 | 7ac6b06b | 김정우 | |
3084 | '''
|
||
3085 | 5fbc4298 | humkyung | @brief generate output xml file
|
3086 | @author humkyung
|
||
3087 | @date 2018.04.23
|
||
3088 | 98b01134 | 김정우 | @history 2018.05.02 Jeongwoo Show MessageBox when imageviewer doesn't have image
|
3089 | 68ce37ea | humkyung | '''
|
3090 | 853df487 | humkyung | |
3091 | 68ce37ea | humkyung | def generateOutput(self): |
3092 | import XmlGenerator as xg |
||
3093 | |||
3094 | 98b01134 | 김정우 | if not self.graphicsView.hasImage(): |
3095 | self.showImageSelectionMessageBox()
|
||
3096 | return
|
||
3097 | |||
3098 | 68ce37ea | humkyung | try:
|
3099 | baf331db | humkyung | appDocData = AppDocData.instance() |
3100 | 79a8001e | humkyung | |
3101 | baf331db | humkyung | ## collect items
|
3102 | appDocData.lines.clear() |
||
3103 | 853df487 | humkyung | appDocData.lines = [item for item in self.graphicsView.scene.items() if |
3104 | type(item) is QEngineeringLineItem and item.owner is None] |
||
3105 | 5fbc4298 | humkyung | |
3106 | baf331db | humkyung | appDocData.symbols.clear() |
3107 | 853df487 | humkyung | appDocData.symbols = [item for item in self.graphicsView.scene.items() if |
3108 | issubclass(type(item), SymbolSvgItem) and item.owner is None] |
||
3109 | 5fbc4298 | humkyung | |
3110 | baf331db | humkyung | appDocData.equipments.clear() |
3111 | f21ec5b3 | humkyung | for item in self.graphicsView.scene.items(): |
3112 | 1312f1fb | humkyung | if type(item) is QEngineeringEquipmentItem: |
3113 | baf331db | humkyung | appDocData.equipments.append(item) |
3114 | f21ec5b3 | humkyung | |
3115 | baf331db | humkyung | appDocData.texts.clear() |
3116 | 853df487 | humkyung | appDocData.texts = [item for item in self.graphicsView.scene.items() if |
3117 | issubclass(type(item), QEngineeringTextItem) and type( |
||
3118 | item) is not QEngineeringLineNoTextItem] |
||
3119 | baf331db | humkyung | ## up to here
|
3120 | f21ec5b3 | humkyung | |
3121 | 853df487 | humkyung | appDocData.imgOutput = np.ones((appDocData.activeDrawing.height, appDocData.activeDrawing.width), |
3122 | np.uint8) * 255
|
||
3123 | xg.writeOutputXml(appDocData.imgName, appDocData.activeDrawing.width, |
||
3124 | appDocData.activeDrawing.height) # TODO: check
|
||
3125 | aef56f4a | humkyung | project = appDocData.getCurrentProject() |
3126 | 853df487 | humkyung | cv2.imwrite(os.path.join(project.getTempPath(), 'OUTPUT.png'), appDocData.imgOutput)
|
3127 | 68ce37ea | humkyung | except Exception as ex: |
3128 | e57134bc | esham21 | message = 'error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, |
3129 | 853df487 | humkyung | sys.exc_info()[-1].tb_lineno)
|
3130 | e65b0bf8 | humkyung | self.addMessage.emit(MessageType.Error, message)
|
3131 | abcf2c52 | gaqhf | |
3132 | '''
|
||
3133 | @brief resetting attribute at secne
|
||
3134 | @author kyoyho
|
||
3135 | @date 2018.08.21
|
||
3136 | '''
|
||
3137 | 7552be56 | humkyung | """
|
3138 | abcf2c52 | gaqhf | def checkAttribute(self):
|
3139 | 6a187649 | gaqhf | try:
|
3140 | abcf2c52 | gaqhf |
|
3141 | 6a187649 | gaqhf | docData = AppDocData.instance()
|
3142 | if not self.graphicsView.hasImage():
|
||
3143 | return
|
||
3144 |
|
||
3145 | # symbol 경우
|
||
3146 | 12e3f87c | esham21 | items = [item for item in self.graphicsView.scene.items() if issubclass(type(item), SymbolSvgItem) and type(item) is not QEngineeringSpecBreakItem and type(item) is not QEngineeringEndBreakItem]
|
3147 | 6a187649 | gaqhf | for item in items:
|
3148 | attrs = item.attrs
|
||
3149 |
|
||
3150 | removeAttrList = []
|
||
3151 | for attr in attrs:
|
||
3152 | if type(attr) is tuple:
|
||
3153 | continue
|
||
3154 | abcf2c52 | gaqhf |
|
3155 | 6a187649 | gaqhf | if attr is None:
|
3156 | removeAttrList.append(attr)
|
||
3157 | continue
|
||
3158 | abcf2c52 | gaqhf |
|
3159 | 820ed509 | humkyung | attrInfo = docData.getSymbolAttributeByUID(attr.UID)
|
3160 | 269a15c8 | gaqhf | if attrInfo is None:
|
3161 | removeAttrList.append(attr)
|
||
3162 | 6a187649 | gaqhf | # 해당 attribute가 맞는지 확인
|
3163 | else:
|
||
3164 | 820ed509 | humkyung | attrType = attrInfo.AttributeType
|
3165 | 6a187649 | gaqhf | _type = type(attr)
|
3166 | 8958cadd | esham21 | if attrType == 'Symbol Item':
|
3167 | 6a187649 | gaqhf | if not issubclass(_type, SymbolSvgItem):
|
3168 | removeAttrList.append(attr)
|
||
3169 | 8958cadd | esham21 | elif attrType == 'Text Item':
|
3170 | 6a187649 | gaqhf | if _type is not QEngineeringTextItem:
|
3171 | removeAttrList.append(attr)
|
||
3172 | 8958cadd | esham21 | elif attrType == 'Int':
|
3173 | 6a187649 | gaqhf | if _type is not UserInputAttribute and self.isNumber(attr.text):
|
3174 | removeAttrList.append(attr)
|
||
3175 | 8958cadd | esham21 | elif attrType == 'String':
|
3176 | 6a187649 | gaqhf | if _type is not UserInputAttribute:
|
3177 | removeAttrList.append(attr)
|
||
3178 |
|
||
3179 | for attr in removeAttrList:
|
||
3180 | 820ed509 | humkyung | del attrs[attr]
|
3181 | 6a187649 | gaqhf |
|
3182 | # Line No Text Item의 경우
|
||
3183 | items = [item for item in self.graphicsView.scene.items() if issubclass(type(item), QEngineeringLineNoTextItem)]
|
||
3184 | for item in items:
|
||
3185 | 866112c6 | humkyung | attrs = item.attrs
|
3186 | 6a187649 | gaqhf |
|
3187 | removeAttrList = []
|
||
3188 | for attr in attrs:
|
||
3189 | if type(attr) is UserInputAttribute:
|
||
3190 | 8958cadd | esham21 | attrInfo = docData.getLinePropertiesByUID(attr.attribute)
|
3191 | 6a187649 | gaqhf | if attrInfo is None:
|
3192 | removeAttrList.append(attr)
|
||
3193 | 269a15c8 | gaqhf |
|
3194 | 6a187649 | gaqhf | for attr in removeAttrList:
|
3195 | 820ed509 | humkyung | del attrs[attr]
|
3196 | abcf2c52 | gaqhf |
|
3197 | 6a187649 | gaqhf | except Exception as ex:
|
3198 | e57134bc | esham21 | message = 'error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno)
|
3199 | 8958cadd | esham21 | self.addMessage.emit(MessageType.Error, message)
|
3200 | 7552be56 | humkyung | """
|
3201 | abcf2c52 | gaqhf | '''
|
3202 | @brief Check Number
|
||
3203 | @author kyouho
|
||
3204 | @date 2018.08.20
|
||
3205 | '''
|
||
3206 | 853df487 | humkyung | |
3207 | abcf2c52 | gaqhf | def isNumber(self, num): |
3208 | p = re.compile('(^[0-9]+$)')
|
||
3209 | result = p.match(num) |
||
3210 | |||
3211 | if result:
|
||
3212 | return True |
||
3213 | else:
|
||
3214 | return False |
||
3215 | |||
3216 | f457910a | gaqhf | '''
|
3217 | 6a187649 | gaqhf | @brief find overlap Connector
|
3218 | @author kyouho
|
||
3219 | @date 2018.08.28
|
||
3220 | f457910a | gaqhf | '''
|
3221 | 853df487 | humkyung | |
3222 | 6a187649 | gaqhf | def findOverlapConnector(self, connectorItem): |
3223 | from shapely.geometry import Point |
||
3224 | from EngineeringConnectorItem import QEngineeringConnectorItem |
||
3225 | itemList = [] |
||
3226 | 853df487 | humkyung | |
3227 | 6a187649 | gaqhf | x = connectorItem.center()[0]
|
3228 | y = connectorItem.center()[1]
|
||
3229 | |||
3230 | 853df487 | humkyung | connectors = [item for item in self.graphicsView.scene.items() if |
3231 | type(item) is QEngineeringConnectorItem and item != connectorItem] |
||
3232 | 6a187649 | gaqhf | for connector in connectors: |
3233 | if Point(x, y).distance(Point(connector.center()[0], connector.center()[1])) < 5: |
||
3234 | itemList.append(connector.parent) |
||
3235 | |||
3236 | return itemList
|
||
3237 | f457910a | gaqhf | |
3238 | 853df487 | humkyung | |
3239 | e4b3e191 | humkyung | if __name__ == '__main__': |
3240 | f5709716 | humkyung | import locale |
3241 | 87833d61 | humkyung | from PyQt5.QtCore import QTranslator |
3242 | ae19dabd | humkyung | from License import QLicenseDialog |
3243 | e4b3e191 | humkyung | from ProjectDialog import Ui_Dialog |
3244 | 853df487 | humkyung | from App import App |
3245 | e4b3e191 | humkyung | |
3246 | 02294b59 | humkyung | app = App(sys.argv) |
3247 | e4b3e191 | humkyung | try:
|
3248 | ae19dabd | humkyung | if True == QLicenseDialog.check_license_key(): |
3249 | dlg = Ui_Dialog() |
||
3250 | selectedProject = dlg.showDialog() |
||
3251 | if selectedProject is not None: |
||
3252 | AppDocData.instance().setCurrentProject(selectedProject) |
||
3253 | app._mainWnd = MainWindow.instance() |
||
3254 | app._mainWnd.show() |
||
3255 | sys.exit(app.exec_()) |
||
3256 | e4b3e191 | humkyung | except Exception as ex: |
3257 | e57134bc | esham21 | print('error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, |
3258 | 853df487 | humkyung | sys.exc_info()[-1].tb_lineno))
|
3259 | a4707ffe | humkyung | finally:
|
3260 | 5a4d5665 | humkyung | pass |