개정판 315bbbd4
issue #663: fix auto connection
Change-Id: If8e1ebc883adcee1308b690ef3f2f28edf5aff11
DTI_PID/DTI_PID/LineDetector.py | ||
---|---|---|
345 | 345 |
else: |
346 | 346 |
endPt[0] += dx |
347 | 347 |
|
348 |
if line.connect_if_possible(symbol, toler): |
|
349 |
line.set_line([[distStart[0][1][0],distStart[0][1][1]], endPt]) |
|
348 |
res = line.connect_if_possible(symbol, toler) |
|
349 |
if res: |
|
350 |
line.set_line([res[1], endPt]) |
|
350 | 351 |
else: |
351 | 352 |
dx = distEnd[0][1][0] - endPt[0] |
352 | 353 |
dy = distEnd[0][1][1] - endPt[1] |
... | ... | |
356 | 357 |
else: |
357 | 358 |
startPt[0] += dx |
358 | 359 |
|
359 |
if line.connect_if_possible(symbol, toler):
|
|
360 |
line.set_line([startPt, [distEnd[0][1][0],distEnd[0][1][1]]])
|
|
361 |
|
|
360 |
res = line.connect_if_possible(symbol, toler)
|
|
361 |
if res:
|
|
362 |
line.set_line([startPt, res[1]]) |
|
362 | 363 |
''' |
363 | 364 |
@brief extend line to intersection point |
364 | 365 |
@author humkyung |
DTI_PID/DTI_PID/RecognitionDialog.py | ||
---|---|---|
535 | 535 |
configs = app_doc_data.getConfigs('Line Detector', 'Length to connect line') |
536 | 536 |
toler = int(configs[0].value) if configs else 20 |
537 | 537 |
if app_doc_data.lines: |
538 |
# connect line to line
|
|
538 |
# connect line to symbol
|
|
539 | 539 |
try: |
540 | 540 |
for line in app_doc_data.lines: |
541 |
matches = [it for it in app_doc_data.lines if |
|
542 |
(it is not line) and (not line.isParallel(it))] |
|
543 |
|
|
544 |
for match in matches: |
|
545 |
detector.connectLineToLine(match, line, toler) |
|
541 |
matches = [symbol for symbol in symbols if symbol.is_connectable(line, toler=toler)] |
|
542 |
for symbol in matches: |
|
543 |
detector.connectLineToSymbol(line, symbol, toler=toler) |
|
546 | 544 |
except Exception as ex: |
547 | 545 |
message = 'error occurred({}) in {}:{}'.format(ex, sys.exc_info()[ |
548 | 546 |
-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno) |
549 | 547 |
worker.displayLog.emit(MessageType.Error, message) |
550 | 548 |
# up to here |
551 | 549 |
|
552 |
# connect line to symbol
|
|
550 |
# connect line to line
|
|
553 | 551 |
try: |
554 | 552 |
for line in app_doc_data.lines: |
555 |
matches = [symbol for symbol in symbols if symbol.is_connectable(line, toler=toler)] |
|
556 |
for symbol in matches: |
|
557 |
detector.connectLineToSymbol(line, symbol, toler=toler) |
|
553 |
matches = [it for it in app_doc_data.lines if |
|
554 |
(it is not line) and (not line.isParallel(it))] |
|
555 |
|
|
556 |
for match in matches: |
|
557 |
detector.connectLineToLine(match, line, toler) |
|
558 | 558 |
|
559 | 559 |
# change line type using symbol connection type(info) |
560 | 560 |
for sym in symbols: |
DTI_PID/DTI_PID/Shapes/EngineeringConnectorItem.py | ||
---|---|---|
410 | 410 |
self.setPos(self._savedPos) |
411 | 411 |
self.connectedItem = self._savedConnectedItem |
412 | 412 |
self._savedPos = None |
413 |
self.update() |
|
414 |
elif event.key() == Qt.Key_A: |
|
415 |
self._drawing_mode = QEngineeringConnectorItem.AXIS_MODE |
|
413 |
self.update() |
|
416 | 414 |
elif event.key() == Qt.Key_F: |
417 |
self._drawing_mode = QEngineeringConnectorItem.FREE_MODE |
|
415 |
if self._drawing_mode == QEngineeringConnectorItem.AXIS_MODE: |
|
416 |
self._drawing_mode = QEngineeringConnectorItem.FREE_MODE |
|
417 |
else: |
|
418 |
self._drawing_mode = QEngineeringConnectorItem.AXIS_MODE |
|
418 | 419 |
|
419 | 420 |
QGraphicsEllipseItem.keyPressEvent(self, event) |
420 | 421 |
|
DTI_PID/DTI_PID/Shapes/EngineeringLineItem.py | ||
---|---|---|
610 | 610 |
''' |
611 | 611 |
def connect_if_possible(self, obj, toler=20): |
612 | 612 |
""" connect line or symbol is able to be connected and return symbol or line connected to connectors """ |
613 |
""" this method not update item's position """ |
|
613 | 614 |
|
614 | 615 |
from shapely.geometry import Point |
615 | 616 |
from SymbolSvgItem import SymbolSvgItem |
... | ... | |
629 | 630 |
self.connectors[0].connect(obj) |
630 | 631 |
obj.connectors[i].connect(self) |
631 | 632 |
res.append(obj) |
633 |
res.append(obj.connectors[i].sceneConnectPoint) |
|
632 | 634 |
elif (Point(endPt[0], endPt[1]).distance(Point(pt[0], pt[1])) < toler): |
633 | 635 |
if self.connectors[1].connectedItem is None and obj.connectors[i].connectedItem is None: |
634 | 636 |
self.connectors[1].connect(obj) |
635 | 637 |
obj.connectors[i].connect(self) |
636 | 638 |
res.append(obj) |
639 |
res.append(obj.connectors[i].sceneConnectPoint) |
|
637 | 640 |
elif type(obj) is QEngineeringLineItem: |
638 | 641 |
_startPt = obj.startPoint() |
639 | 642 |
_endPt = obj.endPoint() |
DTI_PID/DTI_PID/Shapes/SymbolSvgItem.py | ||
---|---|---|
730 | 730 |
''' |
731 | 731 |
|
732 | 732 |
def connect_if_possible(self, obj, toler=10): |
733 |
""" this method not update item's position """ |
|
734 |
|
|
733 | 735 |
from shapely.geometry import Point |
734 | 736 |
from EngineeringLineItem import QEngineeringLineItem |
735 | 737 |
|
... | ... | |
741 | 743 |
for i in range(len(self.connectors)): |
742 | 744 |
if (Point(startPt[0], startPt[1]).distance(Point(self.connectors[i].sceneConnectPoint[0], |
743 | 745 |
self.connectors[i].sceneConnectPoint[1])) < toler): |
744 |
if self.connectors[i].connectedItem is None: |
|
746 |
if self.connectors[i].connectedItem is None and obj.connectors[0].connectedItem is None:
|
|
745 | 747 |
self.connectors[i].connect(obj) |
746 |
if obj.connectors[0].connectedItem is None: |
|
747 | 748 |
obj.connectors[0].connect(self) |
748 |
|
|
749 |
res.append(obj)
|
|
749 |
res.append(obj) |
|
750 |
res.append(self.connectors[i].sceneConnectPoint)
|
|
750 | 751 |
if (Point(endPt[0], endPt[1]).distance(Point(self.connectors[i].sceneConnectPoint[0], |
751 | 752 |
self.connectors[i].sceneConnectPoint[1])) < toler): |
752 |
if self.connectors[i].connectedItem is None: |
|
753 |
if self.connectors[i].connectedItem is None and obj.connectors[1].connectedItem is None:
|
|
753 | 754 |
self.connectors[i].connect(obj) |
754 |
if obj.connectors[1].connectedItem is None: |
|
755 | 755 |
obj.connectors[1].connect(self) |
756 |
|
|
757 |
res.append(obj)
|
|
756 |
res.append(obj) |
|
757 |
res.append(self.connectors[i].sceneConnectPoint)
|
|
758 | 758 |
elif issubclass(type(obj), SymbolSvgItem): |
759 | 759 |
for i in range(len(self.connectors)): |
760 | 760 |
if i > 3: break |
내보내기 Unified diff