개정판 f21800ed
issue #563: 심볼 및 라인 속성 연계
Change-Id: Ie01b570a1fad788060393fb7dc40cf7e3d9cb5b6
DTI_PID/DTI_PID/Commands/SelectAttributeCommand.py | ||
---|---|---|
52 | 52 |
from EngineeringLineItem import QEngineeringLineItem |
53 | 53 |
from EngineeringSpecBreakItem import QEngineeringSpecBreakItem |
54 | 54 |
from EngineeringValveOperCodeTextItem import QEngineeringValveOperCodeTextItem |
55 |
from EngineeringConnectorItem import QEngineeringConnectorItem |
|
55 | 56 |
|
56 | 57 |
if self._attr is not None: |
57 | 58 |
item = self.imageViewer.scene.itemAt(scenePos, QTransform()) |
... | ... | |
61 | 62 |
|
62 | 63 |
self.onSuccess.emit() |
63 | 64 |
elif item is not None and self._attr.AttributeType == 'Conn' and (issubclass(type(item), QEngineeringLineItem) or issubclass(type(item), SymbolSvgItem)): |
64 |
self._item.connectors[self._attr.ConnNum - 1].connectedItem = item |
|
65 |
|
|
65 |
self._item.connectors[self._attr.ConnNum - 1].connect(item, QEngineeringAbstractItem.CONNECTED_AT_BODY) |
|
66 |
self.onSuccess.emit() |
|
67 |
elif item is not None and self._attr.AttributeType == 'Conn' and (type(item) is QEngineeringConnectorItem): |
|
68 |
self._item.connectors[self._attr.ConnNum - 1].connect(item.parent, QEngineeringAbstractItem.CONNECTED_AT_PT) |
|
66 | 69 |
self.onSuccess.emit() |
67 | 70 |
elif item is not None and issubclass(type(self._item), QEngineeringSpecBreakItem) and self._attr.AttributeType == 'Comp Item': |
68 | 71 |
self._item.attrs[self._attr] = str(item.uid) |
DTI_PID/DTI_PID/ItemPropertyTableWidget.py | ||
---|---|---|
310 | 310 |
self.setItem(2, 1, QTableWidgetItem(self.symData.type)) |
311 | 311 |
self.setItem(3, 1, QTableWidgetItem(str(round(math.degrees(self.symData.angle))))) |
312 | 312 |
self.setItem(4, 1, QTableWidgetItem(str(self.symData.origin))) |
313 |
owner_item = QTableWidgetItem('{}'.format('None' if self.symData.owner is None else item.owner.uid))
|
|
313 |
owner_item = QTableWidgetItem('{}'.format('None' if self.symData.owner is None else self.symData.owner.uid))
|
|
314 | 314 |
icon = QtGui.QIcon() |
315 | 315 |
icon.addPixmap(QtGui.QPixmap(":/newPrefix/doubleclick.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off) |
316 | 316 |
owner_item.setIcon(icon) |
DTI_PID/DTI_PID/LineDetector.py | ||
---|---|---|
66 | 66 |
qy = origin[1] + math.sin(angle) * dx + math.cos(angle) * dy |
67 | 67 |
return [qx, qy] |
68 | 68 |
|
69 |
""" |
|
70 |
@brief 두 직선이 평행한지 판별한다. |
|
71 |
@author humkyung |
|
72 |
@date 2018.??.?? |
|
73 |
""" |
|
74 |
def isParallel(self, lhs, rhs): |
|
75 |
try: |
|
76 |
vectors = [(lhs[1][0]-lhs[0][0], lhs[1][1]-lhs[0][1]), (rhs[1][0]-rhs[0][0], rhs[1][1]-rhs[0][1])] |
|
77 |
angle = self.getAngle(vectors[0], vectors[1]) |
|
78 |
if (angle == 0) or (angle == math.pi): return True |
|
79 |
except ZeroDivisionError: |
|
80 |
return True |
|
81 |
|
|
82 |
return False |
|
83 |
|
|
84 | 69 |
''' |
85 | 70 |
@brief check if given two lines are connected |
86 | 71 |
@author humkyung |
... | ... | |
330 | 315 |
connectedLines.append(mergedLine) |
331 | 316 |
for match in matches: connectedLines.remove(match) |
332 | 317 |
except Exception as ex: |
333 |
print('error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno)) |
|
318 |
from App import App |
|
319 |
from AppDocData import MessageType |
|
320 |
|
|
321 |
message = 'error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno) |
|
322 |
App.mainWnd().addMessage.emit(MessageType.Error, message) |
|
334 | 323 |
|
335 | 324 |
''' |
336 | 325 |
@brief connect line to nearest connection point of symbol |
337 | 326 |
@author humkyung |
338 | 327 |
@date 2018.04.13 |
339 | 328 |
''' |
340 |
def connectLineToSymbol(self, line, offset, symbol): |
|
341 |
#print(line) |
|
342 |
startPt = line[0] |
|
343 |
distStart = [(self.distanceTo(startPt, (connector.sceneConnectPoint[0]-offset[0], connector.sceneConnectPoint[1]-offset[1])), (connector.sceneConnectPoint[0]-offset[0], connector.sceneConnectPoint[1]-offset[1])) for connector in symbol.connectors] |
|
329 |
def connectLineToSymbol(self, line, symbol, toler): |
|
330 |
startPt = list(line.startPoint()) |
|
331 |
distStart = [(self.distanceTo(startPt, (connector.sceneConnectPoint[0], connector.sceneConnectPoint[1])), (connector.sceneConnectPoint[0], connector.sceneConnectPoint[1])) for connector in symbol.connectors] |
|
344 | 332 |
distStart.sort() |
345 | 333 |
|
346 |
endPt = line[1]
|
|
347 |
distEnd = [(self.distanceTo(endPt, (connector.sceneConnectPoint[0]-offset[0], connector.sceneConnectPoint[1]-offset[1])), (connector.sceneConnectPoint[0]-offset[0], connector.sceneConnectPoint[1]-offset[1])) for connector in symbol.connectors]
|
|
334 |
endPt = list(line.endPoint())
|
|
335 |
distEnd = [(self.distanceTo(endPt, (connector.sceneConnectPoint[0], connector.sceneConnectPoint[1])), (connector.sceneConnectPoint[0], connector.sceneConnectPoint[1])) for connector in symbol.connectors]
|
|
348 | 336 |
distEnd.sort() |
349 | 337 |
|
350 | 338 |
if distStart[0][0] < distEnd[0][0]: |
351 | 339 |
dx = distStart[0][1][0] - startPt[0] |
352 | 340 |
dy = distStart[0][1][1] - startPt[1] |
353 |
dir = (line[1][0] - line[0][0], line[1][1] - line[0][1])
|
|
341 |
dir = (endPt[0] - startPt[0], endPt[1] - startPt[1])
|
|
354 | 342 |
if abs(dir[0]) > abs(dir[1]): |
355 |
for i in range(1, len(line)-1): |
|
356 |
line[i][1] += dy |
|
343 |
endPt[1] += dy |
|
357 | 344 |
else: |
358 |
for i in range(1, len(line)-1):
|
|
359 |
line[i][0] += dx |
|
360 |
line[0][0] = distStart[0][1][0]
|
|
361 |
line[0][1] = distStart[0][1][1]
|
|
345 |
endPt[0] += dx
|
|
346 |
|
|
347 |
line.set_line([[distStart[0][1][0],distStart[0][1][1]], endPt])
|
|
348 |
line.connect_if_possible(symbol, toler)
|
|
362 | 349 |
else: |
363 | 350 |
dx = distEnd[0][1][0] - endPt[0] |
364 | 351 |
dy = distEnd[0][1][1] - endPt[1] |
365 |
dir = (line[1][0] - line[0][0], line[1][1] - line[0][1])
|
|
352 |
dir = (endPt[0] - startPt[0], endPt[1] - startPt[1])
|
|
366 | 353 |
if abs(dir[0]) > abs(dir[1]): |
367 |
for i in range(0, len(line)-2): |
|
368 |
line[i][1] += dy |
|
354 |
startPt[1] += dy |
|
369 | 355 |
else: |
370 |
for i in range(0, len(line)-2):
|
|
371 |
line[i][0] += dx |
|
372 |
line[1][0] = distEnd[0][1][0]
|
|
373 |
line[1][1] = distEnd[0][1][1]
|
|
356 |
startPt[0] += dx
|
|
357 |
|
|
358 |
line.set_line([startPt, [distEnd[0][1][0],distEnd[0][1][1]]])
|
|
359 |
line.connect_if_possible(symbol, toler)
|
|
374 | 360 |
|
375 | 361 |
''' |
376 | 362 |
@brief extend line to intersection point |
... | ... | |
379 | 365 |
''' |
380 | 366 |
def connectLineToLine(self, lhs, rhs, toler=20): |
381 | 367 |
try: |
382 |
dx = rhs[1][0] - rhs[0][0] |
|
383 |
dy = rhs[1][1] - rhs[0][1] |
|
368 |
lhs_start = list(lhs.startPoint()) |
|
369 |
lhs_end = list(lhs.endPoint()) |
|
370 |
rhs_start = list(rhs.startPoint()) |
|
371 |
rhs_end = list(rhs.endPoint()) |
|
372 |
|
|
373 |
dx = rhs_end[0] - rhs_start[0] |
|
374 |
dy = rhs_end[1] - rhs_start[1] |
|
384 | 375 |
length = math.sqrt(dx*dx + dy*dy) |
385 | 376 |
if length == 0: return |
386 | 377 |
dx /= length |
387 | 378 |
dy /= length |
388 |
rightLine = [(rhs[0][0]-dx*toler, rhs[0][1]-dy*toler), (rhs[1][0]+dx*toler, rhs[1][1]+dy*toler)]
|
|
379 |
rightLine = [(rhs_start[0]-dx*toler, rhs_start[1]-dy*toler), (rhs_end[0]+dx*toler, rhs_end[1]+dy*toler)]
|
|
389 | 380 |
shapelyRightLine = shapely.geometry.LineString(rightLine) |
390 | 381 |
|
391 |
dx = lhs[1][0] - lhs[0][0]
|
|
392 |
dy = lhs[1][1] - lhs[0][1]
|
|
382 |
dx = lhs_end[0] - lhs_start[0]
|
|
383 |
dy = lhs_end[1] - lhs_start[1]
|
|
393 | 384 |
length = math.sqrt(dx*dx + dy*dy) |
394 | 385 |
if length == 0: return |
395 | 386 |
dx /= length |
396 | 387 |
dy /= length |
397 |
line = [(lhs[0][0]-dx*toler, lhs[0][1]-dy*toler), (lhs[1][0]+dx*toler, lhs[1][1]+dy*toler)]
|
|
388 |
line = [(lhs_start[0]-dx*toler, lhs_start[1]-dy*toler), (lhs_end[0]+dx*toler, lhs_end[1]+dy*toler)]
|
|
398 | 389 |
shapelyLine = shapely.geometry.LineString(line) |
399 | 390 |
|
400 | 391 |
pt = shapelyRightLine.intersection(shapelyLine) |
401 | 392 |
if (pt is not None) and (type(pt) == shapely.geometry.point.Point): |
402 |
if self.isExternalPoint(lhs, pt):
|
|
403 |
if self.distanceTo(lhs[0], (pt.x, pt.y)) < self.distanceTo(lhs[1], (pt.x, pt.y)):
|
|
404 |
lhs[0][0] = pt.x
|
|
405 |
lhs[0][1] = pt.y
|
|
393 |
if lhs.is_external_point(pt):
|
|
394 |
if self.distanceTo(lhs_start, (pt.x, pt.y)) < self.distanceTo(lhs_end, (pt.x, pt.y)):
|
|
395 |
lhs_start[0] = pt.x
|
|
396 |
lhs_start[1] = pt.y
|
|
406 | 397 |
else: |
407 |
lhs[1][0] = pt.x |
|
408 |
lhs[1][1] = pt.y |
|
409 |
|
|
410 |
if self.isExternalPoint(rhs, pt): |
|
411 |
if self.distanceTo(rhs[0], (pt.x, pt.y)) < self.distanceTo(rhs[1], (pt.x, pt.y)): |
|
412 |
rhs[0][0] = pt.x |
|
413 |
rhs[0][1] = pt.y |
|
398 |
lhs_end[0] = pt.x |
|
399 |
lhs_end[1] = pt.y |
|
400 |
|
|
401 |
lhs.set_line([lhs_start, lhs_end]) |
|
402 |
else: |
|
403 |
if self.distanceTo(lhs_start, (pt.x, pt.y)) < toler: |
|
404 |
lhs_start[0] = pt.x |
|
405 |
lhs_start[1] = pt.y |
|
406 |
elif self.distanceTo(lhs_end, (pt.x, pt.y)) < toler: |
|
407 |
lhs_end[0] = pt.x |
|
408 |
lhs_end[1] = pt.y |
|
409 |
|
|
410 |
lhs.set_line([lhs_start, lhs_end]) |
|
411 |
|
|
412 |
if rhs.is_external_point(pt): |
|
413 |
if self.distanceTo(rhs_start, (pt.x, pt.y)) < self.distanceTo(rhs_end, (pt.x, pt.y)): |
|
414 |
rhs_start[0] = pt.x |
|
415 |
rhs_start[1] = pt.y |
|
414 | 416 |
else: |
415 |
rhs[1][0] = pt.x |
|
416 |
rhs[1][1] = pt.y |
|
417 |
except Exception as ex: |
|
418 |
from App import App |
|
419 |
from AppDocData import MessageType |
|
417 |
rhs_end[0] = pt.x |
|
418 |
rhs_end[1] = pt.y |
|
420 | 419 |
|
421 |
message = 'error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno) |
|
422 |
App.mainWnd().addMessage.emit(MessageType.Error, message) |
|
420 |
rhs.set_line([rhs_start, rhs_end]) |
|
423 | 421 |
|
424 |
def isExternalPoint(self, line, pt): |
|
425 |
""" check given pt is located outside of line """ |
|
426 |
try: |
|
427 |
dx = line[1][0] - line[0][0] |
|
428 |
dy = line[1][1] - line[0][1] |
|
429 |
lineLength = math.sqrt(dx * dx + dy * dy) |
|
430 |
|
|
431 |
dx = pt.x - line[0][0] |
|
432 |
dy = pt.y - line[0][1] |
|
433 |
length = math.sqrt(dx * dx + dy * dy) |
|
434 |
if length > lineLength: |
|
435 |
return True |
|
436 |
|
|
437 |
dx = pt.x - line[1][0] |
|
438 |
dy = pt.y - line[1][1] |
|
439 |
length = math.sqrt(dx * dx + dy * dy) |
|
440 |
if length > lineLength: |
|
441 |
return True |
|
442 |
|
|
443 |
return False |
|
422 |
else: |
|
423 |
if self.distanceTo(rhs_start, (pt.x, pt.y)) < toler: |
|
424 |
rhs_start[0] = pt.x |
|
425 |
rhs_start[1] = pt.y |
|
426 |
elif self.distanceTo(rhs_end, (pt.x, pt.y)) < toler: |
|
427 |
rhs_end[0] = pt.x |
|
428 |
rhs_end[1] = pt.y |
|
429 |
|
|
430 |
rhs.set_line([rhs_start, rhs_end]) |
|
431 |
|
|
432 |
lhs.connect_if_possible(rhs, toler=1) |
|
444 | 433 |
except Exception as ex: |
445 | 434 |
from App import App |
446 | 435 |
from AppDocData import MessageType |
447 | 436 |
|
448 | 437 |
message = 'error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno) |
449 | 438 |
App.mainWnd().addMessage.emit(MessageType.Error, message) |
450 |
|
|
439 |
|
|
451 | 440 |
''' |
452 | 441 |
@brief detech line thickness |
453 | 442 |
@author humkyung |
... | ... | |
580 | 569 |
img = area.img |
581 | 570 |
|
582 | 571 |
if True: |
583 |
imgNot = np.ones(img.shape, np.uint8)
|
|
584 |
cv2.bitwise_not(img, imgNot)
|
|
585 |
imgNot = cv2.dilate(imgNot, np.ones((8,8), np.uint8))
|
|
572 |
imgNot = np.ones(self._image.shape, np.uint8)*255
|
|
573 |
imgNot = cv2.bitwise_xor(self._image, imgNot)
|
|
574 |
imgNot = cv2.erode(imgNot, np.ones((2,2), np.uint8))
|
|
586 | 575 |
|
587 | 576 |
image, contours, hierarchy = cv2.findContours(imgNot, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE) |
588 | 577 |
if len(contours) is 0: |
DTI_PID/DTI_PID/LineNoTracer.py | ||
---|---|---|
82 | 82 |
foundCount = 0 |
83 | 83 |
notMatches = [] |
84 | 84 |
for line in lines: |
85 |
if line.linkedItem is not None: continue
|
|
85 |
if line.owner is not None: continue
|
|
86 | 86 |
|
87 |
matches = [x for x in self._lines if x.linkedItem is not None and x.isConnectable(line)]
|
|
87 |
matches = [x for x in self._lines if x.owner is not None and x.is_connectable(line)]
|
|
88 | 88 |
if matches: |
89 | 89 |
foundCount += 1 |
90 | 90 |
connectedItems = self.findConnectedObjects(line, toler=10) |
... | ... | |
275 | 275 |
|
276 | 276 |
### make trim lines |
277 | 277 |
updateProgress.emit(-1) # reset progressbar |
278 |
displayMessage.emit('TrimLine Topology Construction')
|
|
279 |
orphanLines = [line for line in self._lines if line.linkedItem is None]
|
|
278 |
displayMessage.emit('Unknown line Topology Construction')
|
|
279 |
orphanLines = [line for line in self._lines if line.owner is None]
|
|
280 | 280 |
if orphanLines: |
281 | 281 |
maxValue = len(orphanLines) |
282 | 282 |
orphanLines = sorted(orphanLines, key=lambda param:param.length(), reverse=True) |
... | ... | |
294 | 294 |
|
295 | 295 |
self.findSecondaryLines(orphanLines) |
296 | 296 |
for item in orphanLines[:]: |
297 |
if item.linkedItem is not None:
|
|
297 |
if item.owner is not None:
|
|
298 | 298 |
orphanLines.remove(item) |
299 | 299 |
updateProgress.emit(maxValue) |
300 | 300 |
|
... | ... | |
302 | 302 |
|
303 | 303 |
updateProgress.emit(maxValue) |
304 | 304 |
except Exception as ex: |
305 |
print('error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno)) |
|
305 |
from App import App |
|
306 |
|
|
307 |
message = 'error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno) |
|
308 |
App.mainWnd().addMessage.emit(MessageType.Error, message) |
|
306 | 309 |
|
307 | 310 |
''' |
308 | 311 |
@brief find objects connected to given line while loop |
... | ... | |
327 | 330 |
while len(pool) > 0: |
328 | 331 |
sign, obj = pool.pop() |
329 | 332 |
if type(obj) is QEngineeringLineItem: |
330 |
symbolMatches = [x for x in self._symbols if (x.linkedItem is None) and (x not in visited) and len(obj.connectIfPossible(x, toler)) > 0]
|
|
331 |
lineMatches = [x for x in self._lines if (x.linkedItem is None) and (x is not obj) and (x not in visited) and (len(obj.connectIfPossible(x, toler)) > 0)]
|
|
333 |
symbolMatches = [x for x in self._symbols if (x.owner is None) and (x not in visited) and obj.is_connected(x)]
|
|
334 |
lineMatches = [x for x in self._lines if (x.owner is None) and (x is not obj) and (x not in visited) and obj.is_connected(x)]
|
|
332 | 335 |
|
333 | 336 |
elif issubclass(type(obj), SymbolSvgItem): |
334 |
lineMatches = [x for x in self._lines if (x.linkedItem is None) and (x not in visited) and len(obj.connectIfPossible(x, toler)) > 0]
|
|
335 |
symbolMatches = [x for x in self._symbols if (x.linkedItem is None) and (x is not obj) and (x not in visited) and (len(obj.connectIfPossible(x, toler)) > 0)]
|
|
337 |
lineMatches = [x for x in self._lines if (x.owner is None) and (x not in visited) and obj.is_connected(x)]
|
|
338 |
symbolMatches = [x for x in self._symbols if (x.owner is None) and (x is not obj) and (x not in visited) and obj.is_connected(x)]
|
|
336 | 339 |
|
337 | 340 |
# order connected objects |
338 | 341 |
matches = [] |
... | ... | |
392 | 395 |
# up to here |
393 | 396 |
|
394 | 397 |
except Exception as ex: |
395 |
print('error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno)) |
|
398 |
from App import App |
|
399 |
|
|
400 |
message = 'error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno) |
|
401 |
App.mainWnd().addMessage.emit(MessageType.Error, message) |
|
396 | 402 |
|
397 | 403 |
return visited |
398 | 404 |
|
... | ... | |
423 | 429 |
if type(item) is QEngineeringSpecBreakItem: |
424 | 430 |
specBreak.append(item) |
425 | 431 |
elif issubclass(type(item), SymbolSvgItem): |
426 |
#item.owner = None |
|
427 |
item.linkedItem = None |
|
432 |
item.owner = None |
|
428 | 433 |
symbols.append(item) |
429 | 434 |
elif type(item) is QEngineeringLineNoTextItem: |
430 |
#item.owner = None |
|
431 |
item.linkedItem = None |
|
435 |
item.owner = None |
|
432 | 436 |
item.runs.clear() |
433 | 437 |
lineNos.append(item) |
434 | 438 |
elif type(item) is QEngineeringLineItem: |
435 |
#item.owner = None |
|
436 |
item.linkedItem = None |
|
439 |
item.owner = None |
|
437 | 440 |
lines.append(item) |
438 | 441 |
elif type(item) is QEngineeringUnknownItem and item.lineIndicator != 'False': |
439 | 442 |
lineIndicator.append(item) |
DTI_PID/DTI_PID/MainWindow.py | ||
---|---|---|
1301 | 1301 |
lineItem.transfer.onRemoved.connect(self.itemRemoved) |
1302 | 1302 |
lineItem.lineType = lineType |
1303 | 1303 |
if items: |
1304 |
lineItem.connectIfPossible(items[-1], 5)
|
|
1304 |
lineItem.connect_if_possible(items[-1], 5)
|
|
1305 | 1305 |
else: |
1306 | 1306 |
pt = lineItem.startPoint() |
1307 | 1307 |
selected = [item for item in self.graphicsView.scene.items(QPointF(pt[0], pt[1])) if type(item) is QEngineeringConnectorItem or type(item) is QEngineeringLineItem] |
1308 | 1308 |
if selected: |
1309 |
lineItem.connectIfPossible(selected[0].parent if type(selected[0]) is QEngineeringConnectorItem else selected[0], 5)
|
|
1309 |
lineItem.connect_if_possible(selected[0].parent if type(selected[0]) is QEngineeringConnectorItem else selected[0], 5)
|
|
1310 | 1310 |
|
1311 | 1311 |
items.append(lineItem) |
1312 | 1312 |
self.graphicsView.scene.addItem(lineItem) |
... | ... | |
1314 | 1314 |
pt = items[-1].endPoint() |
1315 | 1315 |
selected = [item for item in self.graphicsView.scene.items(QPointF(pt[0], pt[1])) if type(item) is QEngineeringConnectorItem and item.parent is not items[-1]] |
1316 | 1316 |
if selected: |
1317 |
items[-1].connectIfPossible(selected[0].parent, 5)
|
|
1317 |
items[-1].connect_if_possible(selected[0].parent, 5)
|
|
1318 | 1318 |
finally: |
1319 | 1319 |
self.graphicsView.scene.removeItem(self.actionLine.tag._polyline) |
1320 | 1320 |
self.actionLine.tag.reset() |
DTI_PID/DTI_PID/RecognitionDialog.py | ||
---|---|---|
135 | 135 |
while len(pool) > 0: |
136 | 136 |
line = pool.pop() |
137 | 137 |
print('{} - ({})'.format(line, len(pool))) |
138 |
rhs = [item for item in lines if item not in visited and item.isJointed(line)]
|
|
138 |
rhs = [item for item in lines if item not in visited and item.is_connected(line)]
|
|
139 | 139 |
if rhs: |
140 | 140 |
pool.extend(rhs) |
141 | 141 |
visited.extend(rhs) |
... | ... | |
143 | 143 |
item.arrangeVertexOrder(line) |
144 | 144 |
|
145 | 145 |
# skip jointed symbols |
146 |
symbolPool = [item for item in symbols if item not in visited and item.isJointed(line)]
|
|
146 |
symbolPool = [item for item in symbols if item not in visited and item.is_connected(line)]
|
|
147 | 147 |
if symbolPool: |
148 | 148 |
selected = [] |
149 | 149 |
visited.extend(symbolPool) |
150 | 150 |
while len(symbolPool) > 0: |
151 | 151 |
symbol = symbolPool.pop() |
152 | 152 |
|
153 |
rhs = [item for item in symbols if item not in visited and item.isJointed(symbol)]
|
|
153 |
rhs = [item for item in symbols if item not in visited and item.is_connected(symbol)]
|
|
154 | 154 |
if rhs: |
155 | 155 |
symbolPool.extend(rhs) |
156 | 156 |
visited.extend(rhs) |
... | ... | |
160 | 160 |
|
161 | 161 |
# find lines which are connected last symbol |
162 | 162 |
for symbol in selected: |
163 |
rhs = [item for item in lines if item not in visited and item.isJointed(symbol)]
|
|
163 |
rhs = [item for item in lines if item not in visited and item.is_connected(symbol)]
|
|
164 | 164 |
if rhs: |
165 | 165 |
pool.extend(rhs) |
166 | 166 |
visited.extend(rhs) |
... | ... | |
364 | 364 |
|
365 | 365 |
listWidget.addItem(worker.tr('Creating detected infos...')) |
366 | 366 |
worker.displayTitle.emit(worker.tr('Creating detected infos...')) |
367 |
#print(searchedSymbolList[0].getDetectFlip()) |
|
368 |
#print(searchedSymbolList[1].getDetectFlip()) |
|
369 | 367 |
createDetectedItems(searchedSymbolList, textInfoList, otherTextInfoList if otherTextInfoList is not None else [], titleBlockTextInfoList if titleBlockTextInfoList is not None else []) |
370 | 368 |
|
371 | 369 |
if isLineChecked: |
... | ... | |
427 | 425 |
connectedLines.extend(res) |
428 | 426 |
|
429 | 427 |
# line detection without symbol connection point info |
430 |
remainLines = detector.detectLineWithoutSymbol(area)#path, round(area.x), round(area.y))
|
|
428 |
remainLines = detector.detectLineWithoutSymbol(area) |
|
431 | 429 |
windowSize = appDocData.getSlidingWindowSize() |
432 | 430 |
thickness = int(windowSize[1]) |
433 | 431 |
for line in remainLines: |
434 | 432 |
line.append(thickness) |
435 | 433 |
connectedLines.extend(remainLines) |
436 |
#connectedLines.extend([[[line[0][0]-round(area.x),line[0][1]-round(area.y)],[line[1][0]-round(area.x),line[1][1]-round(area.y)],10] for line in remainLines]) |
|
437 | 434 |
|
438 |
listWidget.addItem('Connecting lines') |
|
439 |
if len(connectedLines) > 1: |
|
440 |
configs = appDocData.getConfigs('Line Detector', 'Length to connect line') |
|
441 |
toler = int(configs[0].value) if configs else 20 |
|
435 |
configs = appDocData.getConfigs('Line Detector', 'Length to connect line') |
|
436 |
toler = int(configs[0].value) if configs else 20 |
|
437 |
detector.mergeLines(connectedLines, toler=toler) |
|
438 |
|
|
439 |
for pts in connectedLines: |
|
440 |
processLine = QEngineeringLineItem(vertices=[(area.x + param[0], area.y + param[1]) for param in pts[:-1]], thickness=pts[2]) |
|
441 |
processLine.area = 'Drawing' |
|
442 | 442 |
|
443 |
#detector.mergeLines(connectedLines, toler=5) |
|
443 |
appDocData.lines.append(processLine) |
|
444 |
appDocData.allItems.append(processLine) |
|
445 |
|
|
446 |
if processLine.length() > 100: # TODO: check critical length |
|
447 |
processLine.addFlowArrow() |
|
448 |
|
|
449 |
listWidget.addItem('Connecting lines') |
|
450 |
if appDocData.lines: |
|
444 | 451 |
# connect line to symbol |
445 | 452 |
try: |
446 |
for line in connectedLines:
|
|
447 |
matches = [symbol for symbol in symbols if symbol.isConnectable(line, (round(area.x), round(area.y)), toler=toler)]
|
|
453 |
for line in appDocData.lines:
|
|
454 |
matches = [symbol for symbol in symbols if symbol.is_connectable(line, toler=toler)]
|
|
448 | 455 |
for symbol in matches: |
449 |
detector.connectLineToSymbol(line, (round(area.x), round(area.y)), symbol)
|
|
456 |
detector.connectLineToSymbol(line, symbol, toler=5)
|
|
450 | 457 |
except Exception as ex: |
451 | 458 |
message = 'error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno) |
452 | 459 |
worker.displayLog.emit(MessageType.Error, message) |
... | ... | |
456 | 463 |
configs = appDocData.getConfigs('Line Detector', 'Length to connect line') |
457 | 464 |
toler = int(configs[0].value) if configs else 20 |
458 | 465 |
try: |
459 |
for line in connectedLines: |
|
460 |
#matches = [it for it in connectedLines if (it is not line) and (not detector.isParallel(line, it))] |
|
461 |
matches = [it for it in connectedLines if (it is not line)] |
|
466 |
for line in appDocData.lines: |
|
467 |
matches = [it for it in appDocData.lines if (it is not line) and (not line.isParallel(it))] |
|
462 | 468 |
|
463 | 469 |
# get closest line |
464 |
""" |
|
465 | 470 |
selected = [] |
466 |
shapelyLine = LineString(line[:-1]) |
|
467 | 471 |
for match in matches: |
468 |
dist = [shapelyLine.distance(Point(match[0][0], match[0][1])),shapelyLine.distance(Point(match[1][0], match[1][1]))]
|
|
472 |
dist = [line.distanceTo(match.startPoint()), line.distanceTo(match.endPoint())]
|
|
469 | 473 |
if dist[0] < toler or dist[1] < toler: |
470 | 474 |
selected.append(match) |
471 |
""" |
|
472 | 475 |
# up to here |
473 | 476 |
|
474 | 477 |
for match in matches: |
... | ... | |
480 | 483 |
|
481 | 484 |
listWidget.addItem(worker.tr('Creating lines...')) |
482 | 485 |
|
486 |
""" |
|
483 | 487 |
for pts in connectedLines: |
484 | 488 |
processLine = QEngineeringLineItem(vertices=[(area.x + param[0], area.y + param[1]) for param in pts[:-1]], thickness=pts[2]) |
485 | 489 |
processLine.area = 'Drawing' |
... | ... | |
489 | 493 |
|
490 | 494 |
if processLine.length() > 100: # TODO: check critical length |
491 | 495 |
processLine.addFlowArrow() |
492 |
|
|
496 |
""" |
|
493 | 497 |
except Exception as ex: |
494 | 498 |
message = 'error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno) |
495 | 499 |
worker.displayLog.emit(MessageType.Error, message) |
DTI_PID/DTI_PID/Shapes/EngineeringAbstractItem.py | ||
---|---|---|
11 | 11 |
DEFAULT_COLOR = '#0000FF' |
12 | 12 |
HOVER_COLOR = '#BC4438' |
13 | 13 |
|
14 |
CONNECTED_AT_PT = 0 |
|
15 |
CONNECTED_AT_BODY = 1 |
|
16 |
|
|
14 | 17 |
def __init__(self, parent=None): |
15 | 18 |
self._color = self.DEFAULT_COLOR # default color |
16 | 19 |
self._owner = None |
DTI_PID/DTI_PID/Shapes/EngineeringConnectorItem.py | ||
---|---|---|
16 | 16 |
except ImportError: |
17 | 17 |
raise ImportError("ImageViewerQt: Requires PyQt5 or PyQt4.") |
18 | 18 |
|
19 |
from EngineeringAbstractItem import QEngineeringAbstractItem |
|
19 | 20 |
from EngineeringLineItem import QEngineeringLineItem |
20 | 21 |
|
21 | 22 |
""" |
... | ... | |
52 | 53 |
self._spec_break = None |
53 | 54 |
self.highlight = False |
54 | 55 |
self.connectedItem = None |
56 |
self._connected_at = QEngineeringAbstractItem.CONNECTED_AT_PT # default value is connected at pt |
|
55 | 57 |
self.sceneConnectPoint = None |
56 | 58 |
self.connectPoint = None |
57 | 59 |
self._hoverItem = None |
... | ... | |
156 | 158 |
self.setRect(self._loc[0] - round(self.SMALL_SIZE*0.5), self._loc[1] - round(self.SMALL_SIZE*0.5), self.SMALL_SIZE, self.SMALL_SIZE) |
157 | 159 |
self.update() |
158 | 160 |
|
161 |
def connect(self, item, at=QEngineeringAbstractItem.CONNECTED_AT_PT): |
|
162 |
""" connect to given item where given position """ |
|
163 |
self.connectedItem = item |
|
164 |
self._connected_at = at |
|
165 |
|
|
159 | 166 |
''' |
160 | 167 |
@brief highlight connector |
161 | 168 |
@authro humkyung |
... | ... | |
244 | 251 |
pt = items[0].intersection([start, end]) |
245 | 252 |
if (pt is not None) and (type(pt) == shapely.geometry.point.Point): |
246 | 253 |
self.setPos((pt.x, pt.y)) |
247 |
self.connectedItem = items[0]
|
|
254 |
self.connect(items[0], QEngineeringAbstractItem.CONNECTED_AT_BODY)
|
|
248 | 255 |
elif items and type(items[0]) is QEngineeringConnectorItem: |
249 | 256 |
self.setPos(items[0].center()) |
250 | 257 |
|
... | ... | |
253 | 260 |
if connect.connectedItem == self.parent: |
254 | 261 |
connect.connectedItem = None |
255 | 262 |
|
256 |
self.connectedItem = items[0].parent
|
|
257 |
items[0].connectedItem = self.parent
|
|
263 |
self.connect(items[0].parent)
|
|
264 |
items[0].connect(self.parent)
|
|
258 | 265 |
else: |
259 | 266 |
pt = [event.scenePos().x(), event.scenePos().y()] |
260 | 267 |
if self._drawing_mode == QEngineeringConnectorItem.AXIS_MODE: |
... | ... | |
388 | 395 |
else: |
389 | 396 |
return False |
390 | 397 |
|
398 |
def parse_xml(self, node): |
|
399 |
""" parse given node """ |
|
400 |
if 'CONNECTED_AT' in node.attrib: |
|
401 |
self._connected_at = QEngineeringAbstractItem.CONNECTED_AT_PT if node.attrib['CONNECTED_AT'] == '0' else QEngineeringAbstractItem.CONNECTED_AT_BODY |
|
402 |
else: |
|
403 |
self._connected_at = QEngineeringAbstractItem.CONNECTED_AT_PT |
|
404 |
|
|
405 |
connectedItemStr = node.find('CONNECTEDITEM').text |
|
406 |
connectPointStr = node.find('CONNECTPOINT').text.split(',') |
|
407 |
sceneConnectPointStr = node.find('SCENECONNECTPOINT').text.split(',') |
|
408 |
|
|
409 |
self.connectedItem = connectedItemStr if connectedItemStr != 'None' else None |
|
410 |
self.connectPoint = (float(connectPointStr[0]), float(connectPointStr[1])) |
|
411 |
self.sceneConnectPoint = (float(sceneConnectPointStr[0]), float(sceneConnectPointStr[1])) |
|
412 |
|
|
391 | 413 |
@staticmethod |
392 | 414 |
def fromXml(node): |
393 | 415 |
""" |
... | ... | |
405 | 427 |
from xml.etree.ElementTree import Element, SubElement, dump, ElementTree |
406 | 428 |
|
407 | 429 |
node = Element('CONNECTOR') |
430 |
node.attrib['CONNECTED_AT'] = str(self._connected_at) |
|
431 |
connectedItemNode = Element('CONNECTEDITEM') |
|
432 |
connectedItemNode.text = str(self.connectedItem.uid) if self.connectedItem is not None else 'None' |
|
433 |
connectPointNode = Element('CONNECTPOINT') |
|
434 |
connectPointNode.text = str(self.connectPoint[0]) + ',' + str(self.connectPoint[1]) |
|
435 |
sceneConnectPointNode = Element('SCENECONNECTPOINT') |
|
436 |
sceneConnectPointNode.text = str(self.sceneConnectPoint[0]) + ',' + str(self.sceneConnectPoint[1]) |
|
437 |
|
|
438 |
node.append(connectedItemNode) |
|
439 |
node.append(connectPointNode) |
|
440 |
node.append(sceneConnectPointNode) |
|
408 | 441 |
|
409 | 442 |
return node |
410 | 443 |
|
DTI_PID/DTI_PID/Shapes/EngineeringLineItem.py | ||
---|---|---|
167 | 167 |
|
168 | 168 |
return clone |
169 | 169 |
|
170 |
def set_line(self, line): |
|
171 |
""" set line """ |
|
172 |
self.setLine(line[0][0], line[0][1], line[1][0], line[1][1]) |
|
173 |
self.connectors[0].setPos(line[0]) |
|
174 |
self.connectors[1].setPos(line[1]) |
|
175 |
|
|
170 | 176 |
''' |
171 | 177 |
@brief return start point |
172 | 178 |
@author humkyung |
... | ... | |
309 | 315 |
rhs = LineString(line) |
310 | 316 |
return lhs.intersection(rhs) |
311 | 317 |
|
318 |
def getAngle(self, rhs): |
|
319 |
""" get angle between self and given line """ |
|
320 |
import math |
|
321 |
|
|
322 |
try: |
|
323 |
return math.acos(self.dotProduct(self, rhs) / (self.length() * rhs.length())) |
|
324 |
except Exception as ex: |
|
325 |
return sys.float_info.max |
|
326 |
|
|
327 |
def isParallel(self, rhs): |
|
328 |
""" check if two lines are parallel """ |
|
329 |
import math |
|
330 |
|
|
331 |
try: |
|
332 |
vectors = [(self.endPoint()[0]-self.startPoint()[0], self.endPoint()[1]-self.startPoint()[1]), (rhs.endPoint()[0]-rhs.startPoint()[0], rhs.endPoint()[1]-rhs.startPoint()[1])] |
|
333 |
angle = self.getAngle(rhs) |
|
334 |
if (angle == 0) or (angle == math.pi): return True |
|
335 |
except ZeroDivisionError: |
|
336 |
return True |
|
337 |
|
|
338 |
return False |
|
339 |
|
|
312 | 340 |
''' |
313 | 341 |
@brief check if two lines are connectable |
314 | 342 |
@author humkyung |
... | ... | |
316 | 344 |
@history Jeongwoo 18.05.15 Add check pt's type |
317 | 345 |
Jeongwoo 18.05.16 Add length == 0 check |
318 | 346 |
''' |
319 |
def isConnectable(self, line, toler=20):
|
|
347 |
def is_connectable(self, line, toler=20):
|
|
320 | 348 |
import math |
321 | 349 |
|
322 | 350 |
startPt = line.startPoint() |
... | ... | |
335 | 363 |
return (pt is not None) and (type(pt) == shapely.geometry.point.Point) |
336 | 364 |
|
337 | 365 |
''' |
338 |
@brief check if line and given item is jointable |
|
339 | 366 |
@author humkyung |
340 | 367 |
@date 2018.06.26 |
341 | 368 |
@history humkyung 2018.07.03 allow item to be line or symbol |
342 | 369 |
''' |
343 |
def isJointed(self, item, toler=5): |
|
344 |
import math |
|
345 |
from SymbolSvgItem import SymbolSvgItem |
|
346 |
|
|
347 |
lhs = [self.startPoint(), self.endPoint()] |
|
348 |
if type(item) is QEngineeringLineItem: |
|
349 |
rhs = [item.startPoint(), item.endPoint()] |
|
350 |
elif issubclass(type(item), SymbolSvgItem): |
|
351 |
rhs = [] |
|
352 |
for connector in item.connectors: |
|
353 |
rhs.append(connector.sceneConnectPoint) |
|
354 |
else: |
|
355 |
rhs = [] |
|
356 |
|
|
357 |
for pt in lhs: |
|
358 |
for _pt in rhs: |
|
359 |
dx = _pt[0] - pt[0] |
|
360 |
dy = _pt[1] - pt[1] |
|
361 |
if math.sqrt(dx*dx + dy*dy) < toler: |
|
362 |
return True |
|
370 |
def is_connected(self, item, at=QEngineeringAbstractItem.CONNECTED_AT_PT): |
|
371 |
""" check if given item is connected to self """ |
|
363 | 372 |
|
364 |
return False |
|
373 |
_connectors = [connector for connector in self.connectors if (connector.connectedItem == item and connector._connected_at == at)] |
|
374 |
return len(_connectors) > 0 |
|
365 | 375 |
|
366 | 376 |
''' |
367 | 377 |
@brief join line to symbol |
... | ... | |
454 | 464 |
|
455 | 465 |
return False |
456 | 466 |
|
467 |
def is_external_point(self, pt): |
|
468 |
""" check given pt is located outside of line """ |
|
469 |
import math |
|
470 |
|
|
471 |
try: |
|
472 |
dx = self.endPoint()[0] - self.startPoint()[0] |
|
473 |
dy = self.endPoint()[1] - self.startPoint()[1] |
|
474 |
lineLength = math.sqrt(dx * dx + dy * dy) |
|
475 |
|
|
476 |
dx = pt.x - self.startPoint()[0] |
|
477 |
dy = pt.y - self.startPoint()[1] |
|
478 |
length = math.sqrt(dx * dx + dy * dy) |
|
479 |
if length > lineLength: |
|
480 |
return True |
|
481 |
|
|
482 |
dx = pt.x - self.endPoint()[0] |
|
483 |
dy = pt.y - self.endPoint()[1] |
|
484 |
length = math.sqrt(dx * dx + dy * dy) |
|
485 |
if length > lineLength: |
|
486 |
return True |
|
487 |
|
|
488 |
return False |
|
489 |
except Exception as ex: |
|
490 |
from App import App |
|
491 |
from AppDocData import MessageType |
|
492 |
|
|
493 |
message = 'error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno) |
|
494 |
App.mainWnd().addMessage.emit(MessageType.Error, message) |
|
495 |
|
|
457 | 496 |
''' |
458 |
@brief connect line and symbol is able to be connected and return symbol |
|
459 | 497 |
@author humkyung |
460 | 498 |
@date 2018.04.16 |
461 | 499 |
@history humkyung 2018.05.08 check if line is possible to be connected |
462 | 500 |
Jeongwoo 2018.05.15 Split if-statement and Connect each symbol and line |
463 | 501 |
''' |
464 |
def connectIfPossible(self, obj, toler): |
|
502 |
def connect_if_possible(self, obj, toler): |
|
503 |
""" connect line or symbol is able to be connected and return symbol or line connected to connectors """ |
|
504 |
|
|
465 | 505 |
from shapely.geometry import Point |
466 | 506 |
from SymbolSvgItem import SymbolSvgItem |
507 |
from EngineeringConnectorItem import QEngineeringConnectorItem |
|
508 |
|
|
467 | 509 |
res = [] |
468 | 510 |
|
469 | 511 |
startPt = self.startPoint() |
... | ... | |
476 | 518 |
|
477 | 519 |
if (Point(startPt[0], startPt[1]).distance(Point(pt[0], pt[1])) < toler): |
478 | 520 |
if self.connectors[0].connectedItem is None: |
479 |
self.connectors[0].connectedItem = obj
|
|
521 |
self.connectors[0].connect(obj)
|
|
480 | 522 |
if obj.connectors[i].connectedItem is None: |
481 |
obj.connectors[i].connectedItem = self
|
|
523 |
obj.connectors[i].connect(self)
|
|
482 | 524 |
|
483 | 525 |
res.append(obj) |
484 | 526 |
if (Point(endPt[0], endPt[1]).distance(Point(pt[0], pt[1])) < toler): |
485 | 527 |
if self.connectors[1].connectedItem is None: |
486 |
self.connectors[1].connectedItem = obj
|
|
528 |
self.connectors[1].connect(obj)
|
|
487 | 529 |
if obj.connectors[i].connectedItem is None: |
488 |
obj.connectors[i].connectedItem = self
|
|
530 |
obj.connectors[i].connect(self)
|
|
489 | 531 |
|
490 | 532 |
res.append(obj) |
491 | 533 |
elif type(obj) is QEngineeringLineItem: |
492 | 534 |
_startPt = obj.startPoint() |
493 | 535 |
_endPt = obj.endPoint() |
494 |
if((Point(startPt[0], startPt[1]).distance(Point(_startPt[0], _startPt[1])) < toler)): |
|
495 |
self.connectors[0].connectedItem = obj |
|
496 |
obj.connectors[0].connectedItem = self |
|
497 |
res.append(obj) |
|
498 |
if ((Point(startPt[0], startPt[1]).distance(Point(_endPt[0], _endPt[1])) < toler)): |
|
499 |
self.connectors[0].connectedItem = obj |
|
500 |
obj.connectors[1].connectedItem = self |
|
501 |
res.append(obj) |
|
502 |
|
|
503 |
if((Point(endPt[0], endPt[1]).distance(Point(_startPt[0], _startPt[1])) < toler)): |
|
504 |
self.connectors[1].connectedItem = obj |
|
505 |
obj.connectors[0].connectedItem = self |
|
506 |
res.append(obj) |
|
507 |
|
|
508 |
if ((Point(endPt[0], endPt[1]).distance(Point(_endPt[0], _endPt[1])) < toler)): |
|
509 |
self.connectors[1].connectedItem = obj |
|
510 |
obj.connectors[1].connectedItem = self |
|
511 |
res.append(obj) |
|
536 |
if self.distanceTo(_startPt) < toler: |
|
537 |
if((Point(startPt[0], startPt[1]).distance(Point(_startPt[0], _startPt[1])) < toler)): |
|
538 |
self.connectors[0].connect(obj) |
|
539 |
obj.connectors[0].connect(self) |
|
540 |
res.append(obj) |
|
541 |
elif((Point(endPt[0], endPt[1]).distance(Point(_startPt[0], _startPt[1])) < toler)): |
|
542 |
self.connectors[1].connect(obj) |
|
543 |
obj.connectors[0].connect(self) |
|
544 |
res.append(obj) |
|
545 |
else: |
|
546 |
obj.connectors[0].connect(self, at=QEngineeringAbstractItem.CONNECTED_AT_BODY) |
|
547 |
|
|
548 |
if self.distanceTo(_endPt) < toler: |
|
549 |
if ((Point(startPt[0], startPt[1]).distance(Point(_endPt[0], _endPt[1])) < toler)): |
|
550 |
self.connectors[0].connect(obj) |
|
551 |
obj.connectors[1].connect(self) |
|
552 |
res.append(obj) |
|
553 |
elif ((Point(endPt[0], endPt[1]).distance(Point(_endPt[0], _endPt[1])) < toler)): |
|
554 |
self.connectors[1].connect(obj) |
|
555 |
obj.connectors[1].connect(self) |
|
556 |
res.append(obj) |
|
557 |
else: |
|
558 |
obj.connectors[1].connect(self, at=QEngineeringAbstractItem.CONNECTED_AT_BODY) |
|
512 | 559 |
except Exception as ex: |
513 | 560 |
from App import App |
514 | 561 |
from AppDocData import MessageType |
... | ... | |
1044 | 1091 |
if connectors is not None: |
1045 | 1092 |
iterIndex = 0 |
1046 | 1093 |
for connector in connectors.iter('CONNECTOR'): |
1047 |
connectedItemStr = connector.find('CONNECTEDITEM').text |
|
1048 |
connectPointStr = connector.find('CONNECTPOINT').text.split(',') |
|
1049 |
sceneConnectPointStr = connector.find('SCENECONNECTPOINT').text.split(',') |
|
1050 |
|
|
1051 |
item.connectors[iterIndex].connectedItem = connectedItemStr if connectedItemStr != 'None' else None |
|
1052 |
item.connectors[iterIndex].connectPoint = (float(connectPointStr[0]), float(connectPointStr[1])) |
|
1053 |
item.connectors[iterIndex].sceneConnectPoint = (float(sceneConnectPointStr[0]), float(sceneConnectPointStr[1])) |
|
1054 |
|
|
1094 |
item.connectors[iterIndex].parse_xml(connector) |
|
1055 | 1095 |
iterIndex += 1 |
1056 | 1096 |
except Exception as ex: |
1057 | 1097 |
from App import App |
... | ... | |
1099 | 1139 |
|
1100 | 1140 |
connectorsNode = Element('CONNECTORS') |
1101 | 1141 |
for connector in self.connectors: |
1102 |
connectorNode = Element('CONNECTOR') |
|
1103 |
connectedItemNode = Element('CONNECTEDITEM') |
|
1104 |
connectedItemNode.text = str(connector.connectedItem.uid) if connector.connectedItem is not None else 'None' |
|
1105 |
connectPointNode = Element('CONNECTPOINT') |
|
1106 |
connectPointNode.text = str(connector.connectPoint[0]) + ',' + str(connector.connectPoint[1]) |
|
1107 |
sceneConnectPointNode = Element('SCENECONNECTPOINT') |
|
1108 |
sceneConnectPointNode.text = str(connector.sceneConnectPoint[0]) + ',' + str(connector.sceneConnectPoint[1]) |
|
1109 |
|
|
1110 |
connectorNode.append(connectedItemNode) |
|
1111 |
connectorNode.append(connectPointNode) |
|
1112 |
connectorNode.append(sceneConnectPointNode) |
|
1113 |
connectorsNode.append(connectorNode) |
|
1142 |
connectorsNode.append(connector.toXml()) |
|
1114 | 1143 |
node.append(connectorsNode) |
1115 | 1144 |
|
1116 | 1145 |
# up to here |
DTI_PID/DTI_PID/Shapes/SymbolSvgItem.py | ||
---|---|---|
13 | 13 |
from AppDocData import * |
14 | 14 |
from EngineeringConnectorItem import QEngineeringConnectorItem |
15 | 15 |
from EngineeringAbstractItem import QEngineeringAbstractItem |
16 |
from EngineeringConnectorItem import QEngineeringConnectorItem |
|
16 | 17 |
from UserInputAttribute import UserInputAttribute |
17 | 18 |
import SelectAttributeCommand |
18 | 19 |
|
... | ... | |
314 | 315 |
@author humkyung |
315 | 316 |
@date 2018.04.13 |
316 | 317 |
''' |
317 |
def isConnectable(self, line, offset, toler=10): |
|
318 |
#print(line) |
|
318 |
def is_connectable(self, line, toler=10): |
|
319 |
start_pt = line.startPoint() |
|
320 |
end_pt = line.endPoint() |
|
319 | 321 |
for connector in self.connectors: |
320 |
dx = connector.sceneConnectPoint[0] - (line[0][0] + offset[0])
|
|
321 |
dy = connector.sceneConnectPoint[1] - (line[0][1] + offset[1])
|
|
322 |
dx = connector.sceneConnectPoint[0] - (start_pt[0])
|
|
323 |
dy = connector.sceneConnectPoint[1] - (start_pt[1])
|
|
322 | 324 |
if (math.sqrt(dx*dx + dy*dy) < toler): return True |
323 |
dx = connector.sceneConnectPoint[0] - (line[1][0] + offset[0])
|
|
324 |
dy = connector.sceneConnectPoint[1] - (line[1][1] + offset[1])
|
|
325 |
dx = connector.sceneConnectPoint[0] - (end_pt[0])
|
|
326 |
dy = connector.sceneConnectPoint[1] - (end_pt[1])
|
|
325 | 327 |
if (math.sqrt(dx*dx + dy*dy) < toler): return True |
326 | 328 |
|
327 | 329 |
return False |
328 | 330 |
|
329 | 331 |
''' |
330 |
@brief check if symbol and given item is jointed |
|
331 | 332 |
@author humkyung |
332 | 333 |
@date 2018.07.03 |
333 | 334 |
''' |
334 |
def isJointed(self, item, toler=5): |
|
335 |
import math |
|
336 |
from EngineeringLineItem import QEngineeringLineItem |
|
335 |
def is_connected(self, item, at=QEngineeringAbstractItem.CONNECTED_AT_PT): |
|
336 |
""" check if given item is connected to self """ |
|
337 | 337 |
|
338 |
lhs = [] |
|
339 |
for connector in self.connectors: |
|
340 |
lhs.append(connector.sceneConnectPoint) |
|
341 |
|
|
342 |
if type(item) is QEngineeringLineItem: |
|
343 |
rhs = [item.startPoint(), item.endPoint()] |
|
344 |
elif issubclass(type(item), SymbolSvgItem): |
|
345 |
rhs = [] |
|
346 |
for connector in item.connectors: |
|
347 |
rhs.append(connector.sceneConnectPoint) |
|
348 |
else: |
|
349 |
rhs = [] |
|
350 |
|
|
351 |
for pt in lhs: |
|
352 |
for _pt in rhs: |
|
353 |
dx = _pt[0] - pt[0] |
|
354 |
dy = _pt[1] - pt[1] |
|
355 |
if math.sqrt(dx*dx + dy*dy) < toler: |
|
356 |
return True |
|
338 |
_connectors = [connector for connector in self.connectors if (connector.connectedItem == item and connector._connected_at == at)] |
|
339 |
return len(_connectors) > 0 |
|
357 | 340 |
|
358 |
return False |
|
359 |
|
|
360 | 341 |
''' |
361 | 342 |
@brief connect line and symbol is able to be connected and return line |
362 | 343 |
@author humkyung |
... | ... | |
364 | 345 |
@history humkyung 2018.05.08 check if symbol is possible to be connected |
365 | 346 |
Jeongwoo 2018.05.15 Connect each symbol and line |
366 | 347 |
''' |
367 |
def connectIfPossible(self, obj, toler=10):
|
|
348 |
def connect_if_possible(self, obj, toler=10):
|
|
368 | 349 |
from shapely.geometry import Point |
369 | 350 |
from EngineeringLineItem import QEngineeringLineItem |
351 |
|
|
370 | 352 |
res = [] |
371 | 353 |
try: |
372 | 354 |
if type(obj) is QEngineeringLineItem: |
... | ... | |
375 | 357 |
for i in range(len(self.connectors)): |
376 | 358 |
if (Point(startPt[0], startPt[1]).distance(Point(self.connectors[i].sceneConnectPoint[0], self.connectors[i].sceneConnectPoint[1])) < toler): |
377 | 359 |
if self.connectors[i].connectedItem is None: |
378 |
self.connectors[i].connectedItem = obj
|
|
360 |
self.connectors[i].connect(obj)
|
|
379 | 361 |
if obj.connectors[0].connectedItem is None: |
380 |
obj.connectors[0].connectedItem = self
|
|
362 |
obj.connectors[0].connect(self)
|
|
381 | 363 |
|
382 | 364 |
res.append(obj) |
383 | 365 |
if (Point(endPt[0], endPt[1]).distance(Point(self.connectors[i].sceneConnectPoint[0], self.connectors[i].sceneConnectPoint[1])) < toler): |
384 | 366 |
if self.connectors[i].connectedItem is None: |
385 |
self.connectors[i].connectedItem = obj
|
|
367 |
self.connectors[i].connect(obj)
|
|
386 | 368 |
if obj.connectors[1].connectedItem is None: |
387 |
obj.connectors[1].connectedItem = self
|
|
369 |
obj.connectors[1].connect(self)
|
|
388 | 370 |
|
389 | 371 |
res.append(obj) |
390 | 372 |
elif issubclass(type(obj), SymbolSvgItem): |
... | ... | |
393 | 375 |
_pt = Point(obj.connectors[j].sceneConnectPoint[0], obj.connectors[j].sceneConnectPoint[1]) |
394 | 376 |
if (_pt.distance(Point(self.connectors[i].sceneConnectPoint[0], self.connectors[i].sceneConnectPoint[1])) < toler): |
395 | 377 |
if self.connectors[i].connectedItem is None: |
396 |
self.connectors[i].connectedItem = obj
|
|
397 |
if obj.connectors[j].connectedItem is None :
|
|
398 |
obj.connectors[j].connectedItem = self
|
|
378 |
self.connectors[i].connect(obj)
|
|
379 |
if obj.connectors[j].connectedItem is None: |
|
380 |
obj.connectors[j].connect(self)
|
|
399 | 381 |
|
400 | 382 |
res.append(obj) |
401 | 383 |
except Exception as ex: |
402 |
print('error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno)) |
|
384 |
from App import App |
|
385 |
message = 'error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno) |
|
386 |
App.mainWnd().addMessage.emit(MessageType.Error, message) |
|
403 | 387 |
|
404 | 388 |
return res |
405 | 389 |
|
... | ... | |
771 | 755 |
|
772 | 756 |
connectorsNode = Element('CONNECTORS') |
773 | 757 |
for connector in self.connectors: |
774 |
connectorNode = Element('CONNECTOR') |
|
775 |
connectedItemNode = Element('CONNECTEDITEM') |
|
776 |
connectedItemNode.text = str(connector.connectedItem.uid) if connector.connectedItem is not None else 'None' |
|
777 |
connectPointNode = Element('CONNECTPOINT') |
|
778 |
connectPointNode.text = str(connector.connectPoint[0]) + ',' + str(connector.connectPoint[1]) |
|
779 |
sceneConnectPointNode = Element('SCENECONNECTPOINT') |
|
780 |
sceneConnectPointNode.text = str(connector.sceneConnectPoint[0]) + ',' + str(connector.sceneConnectPoint[1]) |
|
781 |
|
|
782 |
connectorNode.append(connectedItemNode) |
|
783 |
connectorNode.append(connectPointNode) |
|
784 |
connectorNode.append(sceneConnectPointNode) |
|
785 |
connectorsNode.append(connectorNode) |
|
758 |
connectorsNode.append(connector.toXml()) |
|
786 | 759 |
node.append(connectorsNode) |
787 | 760 |
|
788 | 761 |
connectionNode = Element('CONNECTIONPOINT') |
... | ... | |
926 | 899 |
if connectors is not None: |
927 | 900 |
iterIndex = 0 |
928 | 901 |
for connector in connectors.iter('CONNECTOR'): |
929 |
connectedItemStr = connector.find('CONNECTEDITEM').text |
|
930 |
connectPointStr = connector.find('CONNECTPOINT').text.split(',') |
|
931 |
sceneConnectPointStr = connector.find('SCENECONNECTPOINT').text.split(',') |
|
932 |
|
|
933 |
item[0].connectors[iterIndex].connectedItem = connectedItemStr if connectedItemStr != 'None' else None |
|
934 |
item[0].connectors[iterIndex].connectPoint = (float(connectPointStr[0]), float(connectPointStr[1])) |
|
935 |
item[0].connectors[iterIndex].sceneConnectPoint = (float(sceneConnectPointStr[0]), float(sceneConnectPointStr[1])) |
|
936 |
|
|
902 |
item[0].connectors[iterIndex].parse_xml(connector) |
|
937 | 903 |
iterIndex += 1 |
938 | 904 |
|
939 | 905 |
# get associations |
DTI_PID/DTI_PID/TextDetector.py | ||
---|---|---|
338 | 338 |
|
339 | 339 |
path = os.path.join(project.getTempPath(), 'OCR_{}.png'.format(appDocData.imgName)) |
340 | 340 |
if os.path.isfile(path): |
341 |
imgOCR = cv2.imread(path, 1)
|
|
341 |
imgOCR = cv2.imread(path) |
|
342 | 342 |
imgOCR = cv2.threshold(cv2.cvtColor(imgOCR, cv2.COLOR_BGR2GRAY), 127, 255, cv2.THRESH_BINARY+cv2.THRESH_OTSU)[1] |
343 | 343 |
|
344 | 344 |
# remove recognized text from image |
... | ... | |
362 | 362 |
|
363 | 363 |
temp = img[y:y+height, x:x+width] |
364 | 364 |
imgOCR = cv2.erode(imgOCR, np.ones((3,3), np.uint8)) |
365 |
mask = cv2.bitwise_or(temp, cv2.bitwise_not(imgOCR))
|
|
365 |
mask = cv2.bitwise_or(temp, imgOCR)
|
|
366 | 366 |
imgXOR = cv2.bitwise_xor(temp, mask) |
367 | 367 |
img[y:y+height, x:x+width] = cv2.bitwise_not(imgXOR) |
368 | 368 |
|
내보내기 Unified diff