66 |
66 |
self.lineComboBox = QComboBox(self.toolBar)
|
67 |
67 |
self.lineComboBox.addItem('Primary Line')
|
68 |
68 |
self.lineComboBox.addItem('Secondary Line')
|
69 |
|
self.lineComboBox.addItem('Utility Line')
|
|
69 |
#self.lineComboBox.addItem('Utility Line')
|
70 |
70 |
self.toolBar.insertWidget(self.actionValidate, self.lineComboBox)
|
71 |
71 |
self.toolBar.insertSeparator(self.actionValidate)
|
72 |
72 |
self.graphicsView = QtImageViewer.QtImageViewer()
|
... | ... | |
106 |
106 |
self.symbolExplorerVerticalLayout.addWidget(splitter)
|
107 |
107 |
# up to here
|
108 |
108 |
|
109 |
|
self.loadStyleSheet(os.path.dirname(os.path.realpath(__file__)) + '\\coffee')
|
110 |
|
|
111 |
109 |
# connect signals and slots
|
112 |
110 |
self.actionClose.triggered.connect(self.close)
|
113 |
111 |
self.actionOpen.triggered.connect(self.openImageDrawing)
|
... | ... | |
120 |
118 |
self.graphicsView.scene.changed.connect(lambda: self.resultTreeWidget.sceneChanged(self.graphicsView.scene.items()))
|
121 |
119 |
|
122 |
120 |
'''
|
123 |
|
@brief load application style sheet
|
124 |
|
@author humkyung
|
125 |
|
@date 2018.04.07
|
126 |
|
'''
|
127 |
|
def loadStyleSheet(self, sheetName):
|
128 |
|
file = QFile('%s.qss' % sheetName.lower())
|
129 |
|
file.open(QFile.ReadOnly)
|
130 |
|
|
131 |
|
styleSheet = file.readAll()
|
132 |
|
styleSheet = str(styleSheet, encoding='utf8')
|
133 |
|
|
134 |
|
QApplication.instance().setStyleSheet(styleSheet)
|
135 |
|
|
136 |
|
'''
|
137 |
121 |
@brief area configuration
|
138 |
122 |
'''
|
139 |
123 |
def areaConfiguration(self):
|
... | ... | |
165 |
149 |
self.graphicsView.clearImage()
|
166 |
150 |
self.graphicsView.scene.clear()
|
167 |
151 |
self.path = self.graphicsView.loadImageFromFile()
|
168 |
|
baseName = os.path.basename(self.path)
|
169 |
|
self.resultTreeWidget.setCurrentPID(baseName)
|
170 |
|
|
171 |
|
# DEBUG
|
172 |
|
'''
|
173 |
|
if __debug__:
|
174 |
|
from LineDetector import LineDetector
|
175 |
|
from LineNoTracer import LineNoTracer
|
176 |
|
self.loadRecognitionResult('d:/Projects/DTIPID/DTI_PID/DTI_PID/SG_TEST/output/UY1-K-2005G_P1_300dpi_black.xml')
|
177 |
|
|
178 |
|
# detect line
|
179 |
|
connectedLines = []
|
180 |
|
|
181 |
|
img = cv2.cvtColor(cv2.imread(self.path), cv2.COLOR_BGR2GRAY)
|
182 |
|
detector = LineDetector(img)
|
183 |
|
symbols = []
|
184 |
|
for item in self.graphicsView.scene.items():
|
185 |
|
if type(item) is SymbolSvgItem:
|
186 |
|
symbols.append(item)
|
187 |
|
color = QColor(random.randrange(0,255), random.randrange(0,255), random.randrange(0,255))
|
188 |
|
res = detector.detectConnectedLine(item, 0, 0)
|
189 |
|
if res is not None:
|
190 |
|
for line in res: connectedLines.append(line)
|
191 |
|
|
192 |
|
texts = []
|
193 |
|
for item in self.graphicsView.scene.items():
|
194 |
|
if (type(item) is QEngineeringTextItem): texts.append(item)
|
195 |
|
|
196 |
|
if len(connectedLines) > 1:
|
197 |
|
detector.mergeLines(connectedLines, toler=20)
|
198 |
|
# connect line to symbol
|
199 |
|
try:
|
200 |
|
for line in connectedLines:
|
201 |
|
matches = [symbol for symbol in symbols if symbol.isConnectable(line, (0,0), toler=40)]
|
202 |
|
for symbol in matches:
|
203 |
|
detector.connectLineToSymbol(line, (0,0), symbol)
|
204 |
|
except Exception as ex:
|
205 |
|
print('error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno))
|
|
152 |
if os.path.isfile(self.path):
|
|
153 |
baseName = os.path.basename(self.path)
|
|
154 |
self.resultTreeWidget.setCurrentPID(baseName)
|
|
155 |
|
|
156 |
# DEBUG
|
|
157 |
if __debug__:
|
|
158 |
from LineDetector import LineDetector
|
|
159 |
from LineNoTracer import LineNoTracer
|
|
160 |
self.loadRecognitionResult('d:/Projects/DTIPID/DTI_PID/DTI_PID/SG_TEST/output/UY1-K-2005G_P1_300dpi_black.xml')
|
|
161 |
|
|
162 |
# detect line
|
|
163 |
connectedLines = []
|
|
164 |
|
|
165 |
img = cv2.cvtColor(cv2.imread(self.path), cv2.COLOR_BGR2GRAY)
|
|
166 |
detector = LineDetector(img)
|
|
167 |
symbols = []
|
|
168 |
for item in self.graphicsView.scene.items():
|
|
169 |
if type(item) is SymbolSvgItem:
|
|
170 |
symbols.append(item)
|
|
171 |
color = QColor(random.randrange(0,255), random.randrange(0,255), random.randrange(0,255))
|
|
172 |
res = detector.detectConnectedLine(item, 0, 0)
|
|
173 |
if res is not None:
|
|
174 |
for line in res: connectedLines.append(line)
|
|
175 |
|
|
176 |
texts = []
|
|
177 |
for item in self.graphicsView.scene.items():
|
|
178 |
if (type(item) is QEngineeringTextItem): texts.append(item)
|
|
179 |
|
|
180 |
if len(connectedLines) > 1:
|
|
181 |
detector.mergeLines(connectedLines, toler=20)
|
|
182 |
# connect line to symbol
|
|
183 |
try:
|
|
184 |
for line in connectedLines:
|
|
185 |
matches = [symbol for symbol in symbols if symbol.isConnectable(line, (0,0), toler=40)]
|
|
186 |
for symbol in matches:
|
|
187 |
detector.connectLineToSymbol(line, (0,0), symbol)
|
|
188 |
except Exception as ex:
|
|
189 |
print('error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno))
|
|
190 |
# up to here
|
|
191 |
|
|
192 |
# connect line to line
|
|
193 |
try:
|
|
194 |
for line in connectedLines[:]:
|
|
195 |
matches = [it for it in connectedLines if (line != it) and (not detector.isParallel(line, it))]
|
|
196 |
for match in matches:
|
|
197 |
detector.connectLineToLine(match, line)
|
|
198 |
except Exception as ex:
|
|
199 |
print('error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno))
|
|
200 |
# up to here
|
|
201 |
|
|
202 |
lines = []
|
|
203 |
for pts in connectedLines:
|
|
204 |
processLine = QEngineeringLineItem()
|
|
205 |
lines.append(processLine)
|
|
206 |
for pt in pts:
|
|
207 |
processLine._pol.append(QPointF(pt[0], pt[1]))
|
|
208 |
processLine._path.addPolygon(processLine._pol)
|
|
209 |
processLine.setPath(processLine._path)
|
|
210 |
processLine.setPen(QPen(color, 5, Qt.SolidLine))
|
|
211 |
self.graphicsView.scene.addItem(processLine)
|
|
212 |
detector.saveImage()
|
|
213 |
|
|
214 |
# trace line no
|
|
215 |
tracer = LineNoTracer(symbols, lines, texts)
|
|
216 |
tracer.execute()
|
206 |
217 |
# up to here
|
207 |
218 |
|
208 |
|
# connect line to line
|
209 |
|
try:
|
210 |
|
for line in connectedLines[:]:
|
211 |
|
matches = [it for it in connectedLines if (line != it) and (not detector.isParallel(line, it))]
|
212 |
|
for match in matches:
|
213 |
|
detector.connectLineToLine(match, line)
|
214 |
|
except Exception as ex:
|
215 |
|
print('error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno))
|
|
219 |
# construct line no item
|
|
220 |
docData = AppDocData.instance()
|
|
221 |
for text in docData.lineNos:
|
|
222 |
item = self.resultTreeWidget.addTreeItem(self.resultTreeWidget.root, text)
|
|
223 |
|
|
224 |
# iterate connected items
|
|
225 |
pool = []
|
|
226 |
visited = []
|
|
227 |
pool.append(text.conns[0])
|
|
228 |
while len(pool) > 0:
|
|
229 |
it = pool.pop()
|
|
230 |
if type(it) is SymbolSvgItem: self.resultTreeWidget.addTreeItem(item, it)
|
|
231 |
visited.append(it)
|
|
232 |
for conn in it.conns:
|
|
233 |
if (conn is not None) and (conn not in visited): pool.append(conn)
|
|
234 |
# up to here
|
|
235 |
|
216 |
236 |
# up to here
|
217 |
|
|
218 |
|
lines = []
|
219 |
|
for pts in connectedLines:
|
220 |
|
processLine = QEngineeringLineItem()
|
221 |
|
lines.append(processLine)
|
222 |
|
for pt in pts:
|
223 |
|
processLine._pol.append(QPointF(pt[0], pt[1]))
|
224 |
|
processLine._path.addPolygon(processLine._pol)
|
225 |
|
processLine.setPath(processLine._path)
|
226 |
|
processLine.setPen(QPen(color, 5, Qt.SolidLine))
|
227 |
|
self.graphicsView.scene.addItem(processLine)
|
228 |
|
detector.saveImage()
|
229 |
|
|
230 |
|
# trace line no
|
231 |
|
tracer = LineNoTracer(symbols, lines, texts)
|
232 |
|
tracer.execute()
|
233 |
|
# up to here
|
234 |
|
|
235 |
|
# construct line no item
|
236 |
|
docData = AppDocData.instance()
|
237 |
|
for text in docData.lineNos:
|
238 |
|
item = self.resultTreeWidget.addTreeItem(self.resultTreeWidget.root, text)
|
239 |
|
|
240 |
|
# iterate connected items
|
241 |
|
pool = []
|
242 |
|
visited = []
|
243 |
|
pool.append(text.conns[0])
|
244 |
|
while len(pool) > 0:
|
245 |
|
it = pool.pop()
|
246 |
|
if type(it) is SymbolSvgItem: self.resultTreeWidget.addTreeItem(item, it)
|
247 |
|
visited.append(it)
|
248 |
|
for conn in it.conns:
|
249 |
|
if (conn is not None) and (conn not in visited): pool.append(conn)
|
250 |
|
# up to here
|
251 |
|
|
252 |
237 |
# up to here
|
253 |
|
# up to here
|
254 |
|
'''
|
255 |
238 |
except Exception as ex:
|
256 |
239 |
print('error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno))
|
257 |
240 |
|
... | ... | |
520 |
503 |
self.xmlPath = self.obj.xmlPath
|
521 |
504 |
self.dlg.ui.buttonBox.setEnabled(True)
|
522 |
505 |
|
|
506 |
'''
|
|
507 |
@brief load application style sheet
|
|
508 |
@author humkyung
|
|
509 |
@date 2018.04.07
|
|
510 |
'''
|
|
511 |
def loadStyleSheet(sheetName):
|
|
512 |
file = QFile('%s.qss' % sheetName.lower())
|
|
513 |
file.open(QFile.ReadOnly)
|
|
514 |
|
|
515 |
styleSheet = file.readAll()
|
|
516 |
styleSheet = str(styleSheet, encoding='utf8')
|
|
517 |
|
|
518 |
QApplication.instance().setStyleSheet(styleSheet)
|
|
519 |
|
523 |
520 |
if __name__ == '__main__':
|
524 |
521 |
import DTI_PID_UI
|
525 |
522 |
from ProjectDialog import Ui_Dialog
|
526 |
523 |
|
527 |
524 |
app = QApplication(sys.argv)
|
528 |
525 |
app.setStyle('Fusion')
|
529 |
|
'''
|
530 |
|
palette = QPalette()
|
531 |
|
palette.setColor(QPalette.Window, QColor(53,53,53))
|
532 |
|
palette.setColor(QPalette.WindowText, Qt.white)
|
533 |
|
palette.setColor(QPalette.Base, QColor(15,15,15))
|
534 |
|
palette.setColor(QPalette.AlternateBase, QColor(53,53,53))
|
535 |
|
palette.setColor(QPalette.ToolTipBase, Qt.white)
|
536 |
|
palette.setColor(QPalette.ToolTipText, Qt.white)
|
537 |
|
palette.setColor(QPalette.Text, Qt.white)
|
538 |
|
palette.setColor(QPalette.Button, QColor(53,53,53))
|
539 |
|
palette.setColor(QPalette.ButtonText, Qt.white)
|
540 |
|
palette.setColor(QPalette.BrightText, Qt.red)
|
541 |
|
palette.setColor(QPalette.Highlight, QColor(142,45,197).lighter())
|
542 |
|
palette.setColor(QPalette.HighlightedText, Qt.black)
|
543 |
|
app.setPalette(palette)
|
544 |
|
'''
|
|
526 |
loadStyleSheet(os.path.dirname(os.path.realpath(__file__)) + '\\coffee')
|
545 |
527 |
|
546 |
528 |
try:
|
547 |
529 |
dlg = Ui_Dialog()
|