개정판 7ea4d64d
add end break binding func
Change-Id: Ib8f3535f2e874427ee931576f77a9db549ba269d
DTI_PID/DTI_PID/Shapes/SymbolSvgItem.py | ||
---|---|---|
998 | 998 |
@author kyouho |
999 | 999 |
@date 18.07.17 |
1000 | 1000 |
''' |
1001 |
|
|
1002 | 1001 |
def isOverlapItemAndPoint(self, item, point): |
1003 | 1002 |
x = point.x() |
1004 | 1003 |
y = point.y() |
... | ... | |
1009 | 1008 |
return True |
1010 | 1009 |
else: |
1011 | 1010 |
return False |
1011 |
|
|
1012 |
def bind_end_break(self): |
|
1013 |
from shapely.geometry import Point |
|
1014 |
from EngineeringEndBreakItem import QEngineeringEndBreakItem |
|
1015 |
from EngineeringSpecBreakItem import QEngineeringSpecBreakItem |
|
1016 |
from EngineeringAbstractItem import QEngineeringAbstractItem |
|
1017 |
from EngineeringLineItem import QEngineeringLineItem |
|
1018 |
from AppDocData import AppDocData |
|
1019 |
|
|
1020 |
if self.prop('Freeze') or self.owner or self.prop('Connected Item'): |
|
1021 |
return |
|
1022 |
|
|
1023 |
app_doc_data = AppDocData.instance() |
|
1024 |
configs = app_doc_data.getConfigs('Line Detector', 'Length to connect line') |
|
1025 |
toler = int(configs[0].value) if configs else 20 |
|
1026 |
|
|
1027 |
lines = sorted([item for item in self.scene().items() if type(item) is QEngineeringLineItem], key=lambda param: param.length(), reverse=True) |
|
1028 |
symbols = [item for item in self.scene().items() if issubclass(type(item), SymbolSvgItem) and type(item) is not QEngineeringEndBreakItem and type(item) is not QEngineeringSpecBreakItem] |
|
1029 |
end_breaks = [item for item in self.scene().items() if type(item) is QEngineeringEndBreakItem] |
|
1030 |
|
|
1031 |
usedItemPairs = [] |
|
1032 |
for end_break in end_breaks: |
|
1033 |
if end_break.prop('Freeze') or end_break.owner or end_break.prop('Connected Item'): |
|
1034 |
usedItemPairs.append([end_break.owner, end_break.prop('Connected Item')]) |
|
1035 |
|
|
1036 |
originPoint = Point(self.origin[0], self.origin[1]) |
|
1037 |
minD = sys.maxsize |
|
1038 |
ownerItem = None |
|
1039 |
connectedItem = None |
|
1040 |
|
|
1041 |
for symbol in symbols: |
|
1042 |
for conn in symbol.connectors: |
|
1043 |
dist = originPoint.distance(Point(conn.sceneConnectPoint[0], conn.sceneConnectPoint[1])) |
|
1044 |
if not conn.connectedItem or not issubclass(type(conn.connectedItem), QEngineeringAbstractItem) or \ |
|
1045 |
[pair for pair in usedItemPairs if symbol in pair and conn.connectedItem in pair] or dist > 3 * toler or dist > minD: |
|
1046 |
continue |
|
1047 |
|
|
1048 |
minD = dist |
|
1049 |
ownerItem = symbol |
|
1050 |
connectedItem = conn.connectedItem |
|
1051 |
|
|
1052 |
for line in lines: |
|
1053 |
for conn in line.connectors: |
|
1054 |
dist = originPoint.distance(Point(conn.sceneConnectPoint[0], conn.sceneConnectPoint[1])) |
|
1055 |
if not conn.connectedItem or not issubclass(type(conn.connectedItem), QEngineeringAbstractItem) or \ |
|
1056 |
conn._connected_at != QEngineeringAbstractItem.CONNECTED_AT_BODY or \ |
|
1057 |
[pair for pair in usedItemPairs if line in pair and conn.connectedItem in pair] or dist > 3 * toler or dist > minD: |
|
1058 |
continue |
|
1059 |
|
|
1060 |
minD = dist |
|
1061 |
ownerItem = line |
|
1062 |
connectedItem = conn.connectedItem |
|
1063 |
|
|
1064 |
if ownerItem and connectedItem: |
|
1065 |
self.set_property('Connected Item', connectedItem) |
|
1066 |
self.setToolTip('owner : ' + str(ownerItem)) |
|
1067 |
self.owner = ownerItem |
|
1068 |
self.set_property('Freeze', True) |
|
1012 | 1069 |
|
1013 | 1070 |
''' |
1014 | 1071 |
@brief remove item when user press delete key |
... | ... | |
1020 | 1077 |
def keyPressEvent(self, event): |
1021 | 1078 |
from EngineeringErrorItem import QEngineeringErrorItem |
1022 | 1079 |
from RotateSymbolDialog import QRotateSymbolDialog |
1080 |
from EngineeringEndBreakItem import QEngineeringEndBreakItem |
|
1023 | 1081 |
from RotateCommand import RotateCommand |
1024 | 1082 |
|
1025 | 1083 |
if not self.isSelected(): |
1026 | 1084 |
return |
1027 | 1085 |
elif event.key() == Qt.Key_B: |
1028 |
self.bind_close_items() |
|
1029 |
elif event.key() == Qt.Key_O and type(self) is not QEngineeringErrorItem: |
|
1030 |
pass |
|
1031 |
elif event.key() == Qt.Key_C and type(self) is not QEngineeringErrorItem: |
|
1032 |
self.changeConnPoint() |
|
1086 |
if type(self) is not QEngineeringEndBreakItem: |
|
1087 |
self.bind_close_items() |
|
1088 |
else: |
|
1089 |
self.bind_end_break() |
|
1090 |
#elif event.key() == Qt.Key_O and type(self) is not QEngineeringErrorItem: |
|
1091 |
# pass |
|
1092 |
#elif event.key() == Qt.Key_C and type(self) is not QEngineeringErrorItem: |
|
1093 |
# self.changeConnPoint() |
|
1033 | 1094 |
elif event.key() == Qt.Key_Return: |
1034 | 1095 |
dlg = QRotateSymbolDialog(None, self.rotation(), self.origin, self.zValue()) |
1035 | 1096 |
if QDialog.Accepted == dlg.showDialog(): |
내보내기 Unified diff