개정판 419fcc77
issue #1051: fixed an error that fail to connect stream line to compressor
Change-Id: I94f6f792108994241882303015070e4d9cd6eca9
HYTOS/HYTOS/Commands/PlaceStreamlineCommand.py | ||
---|---|---|
2 | 2 |
""" This is place stream line module """ |
3 | 3 |
|
4 | 4 |
import os.path |
5 |
import sys |
|
5 | 6 |
import AbstractCommand |
6 | 7 |
|
7 | 8 |
try: |
... | ... | |
57 | 58 |
|
58 | 59 |
self.isTreated = False |
59 | 60 |
|
60 |
event = param[1] |
|
61 |
if 'mousePressEvent' == param[0] and event.button() == Qt.LeftButton: |
|
62 |
selected = self.imageViewer.scene.itemAt(param[2], QTransform()) |
|
63 |
|
|
64 |
if self._streamline is None: |
|
65 |
if selected is not None and (type(selected) is QEngineeringConnectorItem or type( |
|
66 |
selected.parentItem()) is QEngineeringConnectorItem): |
|
67 |
if selected.hasConnectedItem() == False: |
|
68 |
self._streamline = QEngineeringStreamlineItem() |
|
69 |
self._streamline._vertices.append(selected.center() if type( |
|
70 |
selected) is QEngineeringConnectorItem else selected.parentItem().center()) |
|
71 |
self.imageViewer.scene.addItem(self._streamline) |
|
72 |
self.imageViewer.scene.setFocusItem(self._streamline) |
|
73 |
|
|
74 |
self.connectorItems.append( |
|
75 |
selected if type(selected) is QEngineeringConnectorItem else selected.parentItem()) |
|
76 |
else: |
|
77 |
try: |
|
61 |
try: |
|
62 |
event = param[1] |
|
63 |
if 'mousePressEvent' == param[0] and event.button() == Qt.LeftButton: |
|
64 |
selected = self.imageViewer.scene.itemAt(param[2], QTransform()) |
|
65 |
|
|
66 |
if self._streamline is None: |
|
78 | 67 |
if selected is not None and (type(selected) is QEngineeringConnectorItem or type( |
79 | 68 |
selected.parentItem()) is QEngineeringConnectorItem): |
80 | 69 |
if selected.hasConnectedItem() == False: |
70 |
self._streamline = QEngineeringStreamlineItem() |
|
71 |
self._streamline._vertices.append(selected.center() if type( |
|
72 |
selected) is QEngineeringConnectorItem else selected.parentItem().center()) |
|
73 |
self.imageViewer.scene.addItem(self._streamline) |
|
74 |
self.imageViewer.scene.setFocusItem(self._streamline) |
|
75 |
|
|
81 | 76 |
self.connectorItems.append( |
82 | 77 |
selected if type(selected) is QEngineeringConnectorItem else selected.parentItem()) |
83 |
self._streamline._vertices[-1] = selected.center() if type( |
|
84 |
selected) is QEngineeringConnectorItem else selected.parentItem().center() |
|
85 |
else: |
|
86 |
return |
|
87 |
|
|
88 |
# QGraphicsView.mouseReleaseEvent(self.imageViewer, event) |
|
89 |
connectorItems = [conn.uid for conn in self.connectorItems] |
|
90 |
self._streamline.build_connectors(connectorItems) |
|
91 |
|
|
92 |
# self._streamline.build_connectors(self.connectorItems) |
|
93 |
self._streamline.update() |
|
94 |
self.onSuccess.emit() |
|
95 |
self.connectorItems.clear() |
|
96 |
finally: |
|
97 |
pass |
|
98 |
elif 'mouseReleaseEvent' == param[0] and event.button() == Qt.RightButton: |
|
99 |
self.onRejected.emit(self) |
|
100 |
elif 'mouseMoveEvent' == param[0] and self._streamline is not None: |
|
101 |
self._streamline.onMouseMoved(event, param[2]) |
|
102 |
elif 'keyPressEvent' == param[0]: |
|
103 |
if event.key() == Qt.Key_Escape: |
|
78 |
else: |
|
79 |
try: |
|
80 |
if selected is not None and (type(selected) is QEngineeringConnectorItem or type( |
|
81 |
selected.parentItem()) is QEngineeringConnectorItem): |
|
82 |
if selected.hasConnectedItem() == False: |
|
83 |
self.connectorItems.append( |
|
84 |
selected if type(selected) is QEngineeringConnectorItem else selected.parentItem()) |
|
85 |
self._streamline._vertices[-1] = selected.center() if type( |
|
86 |
selected) is QEngineeringConnectorItem else selected.parentItem().center() |
|
87 |
else: |
|
88 |
return |
|
89 |
|
|
90 |
# QGraphicsView.mouseReleaseEvent(self.imageViewer, event) |
|
91 |
connectorItems = [conn.uid for conn in self.connectorItems] |
|
92 |
self._streamline.build_connectors(connectorItems) |
|
93 |
|
|
94 |
# self._streamline.build_connectors(self.connectorItems) |
|
95 |
self._streamline.update() |
|
96 |
self.onSuccess.emit() |
|
97 |
self.connectorItems.clear() |
|
98 |
finally: |
|
99 |
pass |
|
100 |
elif 'mouseReleaseEvent' == param[0] and event.button() == Qt.RightButton: |
|
104 | 101 |
self.onRejected.emit(self) |
105 |
self.isTreated = False |
|
102 |
elif 'mouseMoveEvent' == param[0] and self._streamline is not None: |
|
103 |
self._streamline.onMouseMoved(event, param[2]) |
|
104 |
elif 'keyPressEvent' == param[0]: |
|
105 |
if event.key() == Qt.Key_Escape: |
|
106 |
self.onRejected.emit(self) |
|
107 |
self.isTreated = False |
|
108 |
except Exception as ex: |
|
109 |
from App import App |
|
110 |
from AppDocData import MessageType |
|
111 |
|
|
112 |
message = 'error occurred({}) in {}:{}'.format(repr(ex), sys.exc_info()[-1].tb_frame.f_code.co_filename, |
|
113 |
sys.exc_info()[-1].tb_lineno) |
|
114 |
App.mainWnd().addMessage.emit(MessageType.Error, message) |
|
106 | 115 |
|
107 | 116 |
def undo(self): |
108 | 117 |
pass |
HYTOS/HYTOS/QtImageViewer.py | ||
---|---|---|
518 | 518 |
|
519 | 519 |
if len(self.scene.items()) is 0: |
520 | 520 |
return |
521 |
if hasattr(self, '_underItem') and self._underItem is not None: |
|
522 |
self._underItem.hoverLeaveEvent(event) |
|
523 |
self._underItem = None |
|
524 | 521 |
|
525 | 522 |
scenePos = self.mapToScene(event.pos()) |
526 | 523 |
uid = event.mimeData().text() |
HYTOS/HYTOS/Shapes/EngineeringConnectorItem.py | ||
---|---|---|
195 | 195 |
|
196 | 196 |
res = [] |
197 | 197 |
|
198 |
parent = self.parentItem() |
|
199 |
if type(parent) is SymbolSvgItem: |
|
200 |
if parent.category == 'Equipment - [ Pressurized ]': |
|
201 |
if self.connectedItem and \ |
|
202 |
(self.data is None or (self.data.pressure is None or self.data.elevation is None)): |
|
203 |
res.extend([self, 'pressure or elevation is invalid']) |
|
204 |
elif parent.category == 'Equipment - [ Pressure Drop ]' or parent.type == 'Flowmeter': |
|
205 |
if self.connectedItem and \ |
|
206 |
(self.data is None or (self.data.pressure_drop is None or self.data.elevation is None)): |
|
207 |
res.extend([self, 'pressure drop or elevation is invalid']) |
|
208 |
elif parent.category == 'Equipment - [ Rotating ]': |
|
209 |
if self.connectedItem and parent.name.upper() in ['L_KOMP', 'R_KOMP', 'R_PUMP', 'L_PUMP', 'V_PUMP']: |
|
198 |
try: |
|
199 |
parent = self.parentItem() |
|
200 |
if type(parent) is SymbolSvgItem: |
|
201 |
if parent.category == 'Equipment - [ Pressurized ]': |
|
202 |
if self.connectedItem and \ |
|
203 |
(self.data is None or (self.data.pressure is None or self.data.elevation is None)): |
|
204 |
res.extend([self, 'pressure or elevation is invalid']) |
|
205 |
elif parent.category == 'Equipment - [ Pressure Drop ]' or parent.type == 'Flowmeter': |
|
206 |
if self.connectedItem and \ |
|
207 |
(self.data is None or (self.data.pressure_drop is None or self.data.elevation is None)): |
|
208 |
res.extend([self, 'pressure drop or elevation is invalid']) |
|
209 |
elif parent.category == 'Equipment - [ Rotating ]': |
|
210 |
if self.connectedItem and parent.name.upper() in ['L_KOMP', 'R_KOMP', 'R_PUMP', 'L_PUMP', 'V_PUMP']: |
|
211 |
if self.data is None or self.data.elevation is None: |
|
212 |
res.extend([self, 'need to check elevation']) |
|
213 |
elif self.connectedItem and parent.name.upper() in ['L_COMP', 'R_COMP']: |
|
214 |
if self.data is None or self.data.pressure is None: |
|
215 |
res.extend([self, 'need to check pressure']) |
|
216 |
elif self.data is None or self.data.elevation is None: |
|
217 |
res.extend([self, 'need to check elevation']) |
|
218 |
elif self.connectedItem and (self.data.pressure_drop is None or self.data.elevation is None): |
|
219 |
res.extend([self, 'need to check pressure drop and elevation']) |
|
220 |
elif self.connectedItem and parent.name in ['CV_H', 'CV_V']: |
|
210 | 221 |
if self.data is None or self.data.elevation is None: |
211 | 222 |
res.extend([self, 'need to check elevation']) |
212 |
elif self.connectedItem and parent.name.upper() in ['L_COMP', 'R_COMP']:
|
|
213 |
if self.data.pressure is None:
|
|
214 |
res.extend([self, 'need to check pressure'])
|
|
215 |
elif self.data.elevation is None:
|
|
216 |
res.extend([self, 'need to check elevation'])
|
|
217 |
elif self.connectedItem and (self.data.pressure_drop is None or self.data.elevation is None):
|
|
218 |
res.extend([self, 'need to check pressure drop and elevation'])
|
|
219 |
elif self.connectedItem and parent.name in ['CV_H', 'CV_V']:
|
|
220 |
if self.data is None or self.data.elevation is None: |
|
221 |
res.extend([self, 'need to check elevation'])
|
|
222 |
elif parent.name == 'Line Splitter': # set default value for line splitter
|
|
223 |
if self.connectedItem:
|
|
224 |
if self.data.pressure_drop is None:
|
|
225 |
self.data.pressure_drop = 0
|
|
226 |
if self.data.elevation is None:
|
|
227 |
self.data.elevation = 0
|
|
228 |
elif type(parent) is QEngineeringStreamlineItem:
|
|
229 |
pass
|
|
223 |
elif parent.name == 'Line Splitter': # set default value for line splitter
|
|
224 |
if self.connectedItem:
|
|
225 |
if self.data.pressure_drop is None:
|
|
226 |
self.data.pressure_drop = 0
|
|
227 |
if self.data.elevation is None:
|
|
228 |
self.data.elevation = 0
|
|
229 |
elif type(parent) is QEngineeringStreamlineItem:
|
|
230 |
pass
|
|
231 |
|
|
232 |
# update connector's color
|
|
233 |
if self.connectedItem and type(self.parentItem()) is SymbolSvgItem:
|
|
234 |
self.setBrush(Qt.red) if res else self.setBrush(Qt.yellow)
|
|
235 |
else:
|
|
236 |
self.setBrush(Qt.yellow) if self.connectedItem else self.setBrush(Qt.blue)
|
|
237 |
# up to here
|
|
238 |
except Exception as ex:
|
|
239 |
from App import App
|
|
240 |
from AppDocData import MessageType
|
|
230 | 241 |
|
231 |
# update connector's color |
|
232 |
if self.connectedItem and type(self.parentItem()) is SymbolSvgItem: |
|
233 |
self.setBrush(Qt.red) if res else self.setBrush(Qt.yellow) |
|
234 |
else: |
|
235 |
self.setBrush(Qt.yellow) if self.connectedItem else self.setBrush(Qt.blue) |
|
236 |
# up to here |
|
242 |
message = 'error occurred({}) in {}:{}'.format(repr(ex), sys.exc_info()[-1].tb_frame.f_code.co_filename, |
|
243 |
sys.exc_info()[-1].tb_lineno) |
|
244 |
App.mainWnd().addMessage.emit(MessageType.Error, message) |
|
237 | 245 |
|
238 | 246 |
return res |
239 | 247 |
|
HYTOS/HYTOS/Shapes/EngineeringReservedWordTextItem.py | ||
---|---|---|
27 | 27 |
def __init__(self, uid=None, parent=None): |
28 | 28 |
QEngineeringTextItem.__init__(self, uid, parent) |
29 | 29 |
self.type = 'Reserved Word' |
30 |
|
|
31 |
def findOwner(self, lines): |
|
32 |
import sys |
|
33 |
|
|
34 |
try: |
|
35 |
# find line onwer parallel |
|
36 |
self.onwer = None |
|
37 |
dist = min(self.sceneBoundingRect().height(), self.sceneBoundingRect().width()) * 2 |
|
38 |
center = self.sceneBoundingRect().center() |
|
39 |
|
|
40 |
maxOverlap = 0 |
|
41 |
minDist = sys.maxsize |
|
42 |
selected = None |
|
43 |
hLines = [] |
|
44 |
vLines = [] |
|
45 |
for line in lines: |
|
46 |
if line.sceneBoundingRect().height() > line.sceneBoundingRect().width(): |
|
47 |
vLines.append(line) |
|
48 |
else: |
|
49 |
hLines.append(line) |
|
50 |
|
|
51 |
if self.sceneBoundingRect().height() > self.sceneBoundingRect().width(): |
|
52 |
lines = vLines |
|
53 |
else: |
|
54 |
lines = hLines |
|
55 |
|
|
56 |
axisText = range(round(self.sceneBoundingRect().x()), round( |
|
57 |
self.sceneBoundingRect().x() + self.sceneBoundingRect().width())) if lines is hLines else range( |
|
58 |
round(self.sceneBoundingRect().y()), |
|
59 |
round(self.sceneBoundingRect().y() + self.sceneBoundingRect().height())) |
|
60 |
# print(axisText) |
|
61 |
for line in lines: |
|
62 |
intercept = line.sceneBoundingRect().center().y() if lines is hLines else line.sceneBoundingRect().center().x() |
|
63 |
length = abs(intercept - center.y()) if lines is hLines else abs(intercept - center.x()) |
|
64 |
if (length < dist): |
|
65 |
overlap = 0 |
|
66 |
axisLine = range(round(line.sceneBoundingRect().x()), round( |
|
67 |
line.sceneBoundingRect().x() + line.sceneBoundingRect().width())) if lines is hLines else range( |
|
68 |
round(line.sceneBoundingRect().y()), |
|
69 |
round(line.sceneBoundingRect().y() + line.sceneBoundingRect().height())) |
|
70 |
# print(axisLine) |
|
71 |
for onLine in axisLine: |
|
72 |
for onText in axisText: |
|
73 |
if onLine - onText is 0: |
|
74 |
overlap += 1 |
|
75 |
# print(overlap) |
|
76 |
if overlap == maxOverlap and length < minDist: |
|
77 |
selected = line |
|
78 |
maxOverlap = overlap |
|
79 |
minDist = length |
|
80 |
elif overlap > maxOverlap: |
|
81 |
selected = line |
|
82 |
maxOverlap = overlap |
|
83 |
minDist = length |
|
84 |
|
|
85 |
if selected is not None: |
|
86 |
self.owner = selected |
|
87 |
return |
|
88 |
# print(self.owner) |
|
89 |
## up to here |
|
90 |
|
|
91 |
# fine line owner orthogonal |
|
92 |
if self.sceneBoundingRect().height() < self.sceneBoundingRect().width(): |
|
93 |
lines = vLines |
|
94 |
else: |
|
95 |
lines = hLines |
|
96 |
|
|
97 |
minDist = 30 |
|
98 |
for line in lines: |
|
99 |
if line.connectors[1].connectedItem is not None: continue |
|
100 |
|
|
101 |
dl = min(self.sceneBoundingRect().height(), self.sceneBoundingRect().width()) / 10 |
|
102 |
dx = dl if (line.connectors[0].sceneConnectPoint[0] - line.connectors[1].sceneConnectPoint[ |
|
103 |
0]) > 0 else -dl |
|
104 |
dy = -dl if (line.connectors[0].sceneConnectPoint[1] - line.connectors[1].sceneConnectPoint[ |
|
105 |
1]) > 0 else dl |
|
106 |
|
|
107 |
startPoint = line.endPoint() |
|
108 |
for index in range(30): |
|
109 |
point = (startPoint[0] + index * dx, startPoint[1] + index * dy) |
|
110 |
if self.sceneBoundingRect().contains(point[0], point[1]): |
|
111 |
if index < minDist: |
|
112 |
minDist = index |
|
113 |
selected = line |
|
114 |
break |
|
115 |
|
|
116 |
if selected is not None: |
|
117 |
self.owner = selected |
|
118 |
|
|
119 |
except Exception as ex: |
|
120 |
from App import App |
|
121 |
message = 'error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno) |
|
122 |
App.mainWnd().addMessage.emit(MessageType.Error, message) |
HYTOS/HYTOS/Shapes/EngineeringStreamNoTextItem.py | ||
---|---|---|
49 | 49 |
def paint(self, painter, option, widget): |
50 | 50 |
""" override paint method """ |
51 | 51 |
|
52 |
painter.drawPolygon(self.create_poly(4, 7, 0)) |
|
52 |
rect = self.boundingRect() |
|
53 |
r = rect.width()*0.5 if rect.width() > rect.height() else rect.height()*0.5 |
|
54 |
painter.drawPolygon(self.create_poly(4, r, 0)) |
|
53 | 55 |
QGraphicsTextItem.paint(self, painter, option, widget) |
54 | 56 |
|
55 | 57 |
def create_poly(self, n, r, s): |
HYTOS/HYTOS/Shapes/EngineeringStreamlineItem.py | ||
---|---|---|
183 | 183 |
if not self._vertices: |
184 | 184 |
return |
185 | 185 |
|
186 |
targets = [] |
|
187 |
index = 0 |
|
188 |
for vertex in [self._vertices[0], self._vertices[-1]]: |
|
189 |
if pointsUids: |
|
190 |
connector = QEngineeringConnectorItem(pointsUids[index], parent=self, index=index + 1) |
|
191 |
else: |
|
192 |
connector = QEngineeringConnectorItem(uid=None, parent=self, index=index + 1) |
|
193 |
|
|
194 |
connector.setPos(vertex) |
|
195 |
connector.connectPoint = vertex |
|
196 |
connector.sceneConnectPoint = vertex |
|
197 |
|
|
198 |
# add connector move ables |
|
199 |
connector.setFlags(QGraphicsItem.ItemIsSelectable | QGraphicsItem.ItemIsFocusable) |
|
200 |
connector.setAcceptTouchEvents(True) |
|
201 |
connector.transfer.onPosChanged.connect(self.on_connector_pos_changed) |
|
202 |
|
|
203 |
#connector.setZValue(self.zValue() + 1) |
|
204 |
self.connectors.append(connector) |
|
205 |
if len(connected) > index: |
|
206 |
connected_item_uid = connected[index] |
|
207 |
if connected_item_uid: |
|
208 |
target = QEngineeringConnectorItem.find_connector(connected_item_uid) |
|
209 |
connector.connect(target) |
|
210 |
if target: |
|
211 |
target.connect(connector) |
|
212 |
targets.append(target) |
|
213 |
|
|
214 |
index = index + 1 |
|
215 |
|
|
216 |
""" connect symbol's on_pos_changed signal """ |
|
217 |
for symbol in [conn.parentItem() for conn in targets if type(conn.parentItem()) is SymbolSvgItem]: |
|
218 |
symbol.transfer.on_pos_changed.connect(self.on_symbol_pos_changed) |
|
219 |
symbol.transfer.on_size_changed.connect(self.on_symbol_pos_changed) |
|
186 |
try: |
|
187 |
targets = [] |
|
188 |
index = 0 |
|
189 |
for vertex in [self._vertices[0], self._vertices[-1]]: |
|
190 |
if pointsUids: |
|
191 |
connector = QEngineeringConnectorItem(pointsUids[index], parent=self, index=index + 1) |
|
192 |
else: |
|
193 |
connector = QEngineeringConnectorItem(uid=None, parent=self, index=index + 1) |
|
194 |
|
|
195 |
connector.setPos(vertex) |
|
196 |
connector.connectPoint = vertex |
|
197 |
|
|
198 |
# add connector move ables |
|
199 |
connector.setFlags(QGraphicsItem.ItemIsSelectable | QGraphicsItem.ItemIsFocusable) |
|
200 |
connector.setAcceptTouchEvents(True) |
|
201 |
connector.transfer.onPosChanged.connect(self.on_connector_pos_changed) |
|
202 |
|
|
203 |
#connector.setZValue(self.zValue() + 1) |
|
204 |
self.connectors.append(connector) |
|
205 |
if len(connected) > index: |
|
206 |
connected_item_uid = connected[index] |
|
207 |
if connected_item_uid: |
|
208 |
target = QEngineeringConnectorItem.find_connector(connected_item_uid) |
|
209 |
connector.connect(target) |
|
210 |
if target: |
|
211 |
target.connect(connector) |
|
212 |
targets.append(target) |
|
213 |
|
|
214 |
index = index + 1 |
|
215 |
|
|
216 |
""" connect symbol's on_pos_changed signal """ |
|
217 |
for symbol in [conn.parentItem() for conn in targets if type(conn.parentItem()) is SymbolSvgItem]: |
|
218 |
symbol.transfer.on_pos_changed.connect(self.on_symbol_pos_changed) |
|
219 |
symbol.transfer.on_size_changed.connect(self.on_symbol_pos_changed) |
|
220 |
|
|
221 |
except Exception as ex: |
|
222 |
from App import App |
|
223 |
from AppDocData import MessageType |
|
224 |
|
|
225 |
message = 'error occurred({}) in {}:{}'.format(repr(ex), sys.exc_info()[-1].tb_frame.f_code.co_filename, |
|
226 |
sys.exc_info()[-1].tb_lineno) |
|
227 |
App.mainWnd().addMessage.emit(MessageType.Error, message) |
|
220 | 228 |
|
221 | 229 |
def update_arrow(self): |
222 | 230 |
""" update flow arrow """ |
... | ... | |
786 | 794 |
from SymbolSvgItem import SymbolSvgItem |
787 | 795 |
from EngineeringConnectorItem import QEngineeringConnectorItem |
788 | 796 |
|
789 |
# get connection point near by mouse point |
|
790 |
pt = (scenePos.x(), scenePos.y()) |
|
791 |
item = self.scene().itemAt(scenePos, QTransform()) |
|
792 |
if (item is not None) and (type(item) is SymbolSvgItem): |
|
793 |
connPt = item.getConnectionPointCloseTo(pt, 5) |
|
794 |
if connPt is not None: pt = connPt |
|
795 |
elif (item is not None) and (type(item) is QEngineeringConnectorItem): |
|
796 |
pt = item.center() |
|
797 |
# up to here |
|
798 |
|
|
799 |
del self._vertices[1:] |
|
800 |
dx = pt[0] - self._vertices[0][0] |
|
801 |
dy = pt[1] - self._vertices[0][1] |
|
802 |
self._vertices.append((self._vertices[0][0] + dx * 0.5, self._vertices[0][1])) |
|
803 |
self._vertices.append((self._vertices[-1][0], self._vertices[-1][1] + dy)) |
|
804 |
self._vertices.append(pt) |
|
797 |
try: |
|
798 |
# get connection point near by mouse point |
|
799 |
pt = (scenePos.x(), scenePos.y()) |
|
800 |
item = self.scene().itemAt(scenePos, QTransform()) |
|
801 |
if (item is not None) and (type(item) is SymbolSvgItem): |
|
802 |
connPt = item.getConnectionPointCloseTo(pt, 5) |
|
803 |
if connPt is not None: pt = connPt |
|
804 |
elif (item is not None) and (type(item) is QEngineeringConnectorItem): |
|
805 |
pt = item.center() |
|
806 |
# up to here |
|
807 |
|
|
808 |
del self._vertices[1:] |
|
809 |
dx = pt[0] - self._vertices[0][0] |
|
810 |
dy = pt[1] - self._vertices[0][1] |
|
811 |
self._vertices.append((self._vertices[0][0] + dx * 0.5, self._vertices[0][1])) |
|
812 |
self._vertices.append((self._vertices[-1][0], self._vertices[-1][1] + dy)) |
|
813 |
self._vertices.append(pt) |
|
805 | 814 |
|
806 |
self.build_path() |
|
807 |
self.update() |
|
815 |
self.build_path() |
|
816 |
self.update() |
|
817 |
except Exception as ex: |
|
818 |
from App import App |
|
819 |
from AppDocData import MessageType |
|
820 |
|
|
821 |
message = 'error occurred({}) in {}:{}'.format(repr(ex), sys.exc_info()[-1].tb_frame.f_code.co_filename, |
|
822 |
sys.exc_info()[-1].tb_lineno) |
|
823 |
App.mainWnd().addMessage.emit(MessageType.Error, message) |
|
808 | 824 |
|
809 | 825 |
def hoverEnterEvent(self, event): |
810 | 826 |
""" hilight item and it's children """ |
HYTOS/HYTOS/Shapes/SymbolSvgItem.py | ||
---|---|---|
1233 | 1233 |
(connector.connectedItem == item and (connector._connected_at == at if at else True))] |
1234 | 1234 |
return len(_connectors) > 0 |
1235 | 1235 |
|
1236 |
''' |
|
1237 |
@brief connect line and symbol is able to be connected and return line |
|
1238 |
@author humkyung |
|
1239 |
@date 2018.04.16 |
|
1240 |
@history humkyung 2018.05.08 check if symbol is possible to be connected |
|
1241 |
Jeongwoo 2018.05.15 Connect each symbol and line |
|
1242 |
''' |
|
1243 |
|
|
1244 |
def connect_if_possible(self, obj, toler=10): |
|
1245 |
from shapely.geometry import Point |
|
1246 |
from EngineeringLineItem import QEngineeringLineItem |
|
1247 |
|
|
1248 |
res = [] |
|
1249 |
try: |
|
1250 |
if type(obj) is QEngineeringLineItem: |
|
1251 |
startPt = obj.startPoint() |
|
1252 |
endPt = obj.endPoint() |
|
1253 |
for i in range(len(self.connectors)): |
|
1254 |
if (Point(startPt[0], startPt[1]).distance(Point(self.connectors[i].sceneConnectPoint[0], |
|
1255 |
self.connectors[i].sceneConnectPoint[1])) < toler): |
|
1256 |
if self.connectors[i].connectedItem is None: |
|
1257 |
self.connectors[i].connect(obj) |
|
1258 |
if obj.connectors[0].connectedItem is None: |
|
1259 |
obj.connectors[0].connect(self) |
|
1260 |
|
|
1261 |
res.append(obj) |
|
1262 |
if (Point(endPt[0], endPt[1]).distance(Point(self.connectors[i].sceneConnectPoint[0], |
|
1263 |
self.connectors[i].sceneConnectPoint[1])) < toler): |
|
1264 |
if self.connectors[i].connectedItem is None: |
|
1265 |
self.connectors[i].connect(obj) |
|
1266 |
if obj.connectors[1].connectedItem is None: |
|
1267 |
obj.connectors[1].connect(self) |
|
1268 |
|
|
1269 |
res.append(obj) |
|
1270 |
elif issubclass(type(obj), SymbolSvgItem): |
|
1271 |
for i in range(len(self.connectors)): |
|
1272 |
for j in range(len(obj.connectors)): |
|
1273 |
_pt = Point(obj.connectors[j].sceneConnectPoint[0], obj.connectors[j].sceneConnectPoint[1]) |
|
1274 |
if (_pt.distance(Point(self.connectors[i].sceneConnectPoint[0], |
|
1275 |
self.connectors[i].sceneConnectPoint[1])) < toler): |
|
1276 |
if self.connectors[i].connectedItem is None: |
|
1277 |
self.connectors[i].connect(obj) |
|
1278 |
if obj.connectors[j].connectedItem is None: |
|
1279 |
obj.connectors[j].connect(self) |
|
1280 |
|
|
1281 |
res.append(obj) |
|
1282 |
except Exception as ex: |
|
1283 |
from App import App |
|
1284 |
message = 'error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, |
|
1285 |
sys.exc_info()[-1].tb_lineno) |
|
1286 |
App.mainWnd().addMessage.emit(MessageType.Error, message) |
|
1287 |
|
|
1288 |
return res |
|
1289 |
|
|
1290 |
''' |
|
1291 |
@brief get connection point close to given point in tolerance |
|
1292 |
@author humkyung |
|
1293 |
@dat |
|
1294 |
''' |
|
1295 |
|
|
1296 | 1236 |
def getConnectionPointCloseTo(self, pt, toler=10): |
1237 |
"""get connection point close to given point in tolerance""" |
|
1297 | 1238 |
import math |
1298 | 1239 |
|
1299 | 1240 |
for connector in self.connectors: |
1300 |
dx = connector.sceneConnectPoint[0] - pt[0] |
|
1301 |
dy = connector.sceneConnectPoint[1] - pt[1] |
|
1302 |
if math.sqrt(dx * dx + dy * dy) < toler: return connPt |
|
1241 |
center = connector.center() |
|
1242 |
|
|
1243 |
dx = center[0] - pt[0] |
|
1244 |
dy = center[1] - pt[1] |
|
1245 |
|
|
1246 |
if math.sqrt(dx * dx + dy * dy) < toler: |
|
1247 |
return center |
|
1303 | 1248 |
|
1304 | 1249 |
return None |
1305 | 1250 |
|
... | ... | |
2061 | 2006 |
return rect |
2062 | 2007 |
|
2063 | 2008 |
''' |
2064 |
@brief rotate Symbol |
|
2065 |
@author kyouho |
|
2066 |
@date 2018.07.24 |
|
2067 |
''' |
|
2068 |
|
|
2069 |
def rotateSymbol(self, angle=None): |
|
2070 |
if angle is None: |
|
2071 |
# degree 0 |
|
2072 |
if 0 == self.angle: |
|
2073 |
self.angle = 1.57 |
|
2074 |
# degree 90 |
|
2075 |
elif 1.57 == self.angle: |
|
2076 |
self.angle = 3.14 |
|
2077 |
# degree 180 |
|
2078 |
elif 3.14 == self.angle: |
|
2079 |
self.angle = 4.71 |
|
2080 |
# degree 270 |
|
2081 |
elif 4.71 == self.angle: |
|
2082 |
self.angle = 0 |
|
2083 |
else: |
|
2084 |
self.angle = 0 |
|
2085 |
|
|
2086 |
self.size[0], self.size[1] = self.size[1], self.size[0] |
|
2087 |
else: |
|
2088 |
self.angle = angle |
|
2089 |
|
|
2090 |
# scene = self.scene() |
|
2091 |
# self.scene().removeItem(self) |
|
2092 |
# self.addSvgItemToScene(scene) |
|
2093 |
currentPoint = self.getCurrentPoint() |
|
2094 |
self.reSettingSymbol(currentPoint, self.angle) |
|
2095 |
|
|
2096 |
''' |
|
2097 |
@brief resetting rotate Symbol |
|
2098 |
@author kyouho |
|
2099 |
@date 2018.07.24 |
|
2100 |
''' |
|
2101 |
|
|
2102 |
def reSettingSymbol(self, standardPoint, angle): |
|
2103 |
transform = QTransform() |
|
2104 |
|
|
2105 |
transform.translate(self.loc[0] + self.symbolOrigin[0], self.loc[1] + self.symbolOrigin[1]) |
|
2106 |
transform.rotateRadians(-angle) |
|
2107 |
transform.translate(-standardPoint[0], -standardPoint[1]) |
|
2108 |
|
|
2109 |
if self.flip is 1: |
|
2110 |
transform.scale(-1.0, 1.0) |
|
2111 |
transform.translate(-self.size[0], 0) |
|
2112 |
|
|
2113 |
self.setTransform(transform) |
|
2114 |
self.reSettingConnetors() |
|
2115 |
|
|
2116 |
def reSettingConnetors(self): |
|
2117 |
for conn in self.connectors: |
|
2118 |
conn.sceneConnectPoint = (conn.sceneBoundingRect().center().x(), conn.sceneBoundingRect().center().y()) |
|
2119 |
|
|
2120 |
from EngineeringLineItem import QEngineeringLineItem |
|
2121 |
for connector in self.connectors: |
|
2122 |
if connector.connectedItem is not None and type(connector.connectedItem) == QEngineeringLineItem: |
|
2123 |
line = connector.connectedItem |
|
2124 |
line.reDrawLine(self, connector.center()) |
|
2125 |
line.update_arrow() |
|
2126 |
|
|
2127 |
''' |
|
2128 |
@brief change Conn point |
|
2129 |
@author kyouho |
|
2130 |
@date 2018.07.25 |
|
2131 |
''' |
|
2132 |
|
|
2133 |
def changeConnPoint(self): |
|
2134 |
if len(self.connectors) == 2: |
|
2135 |
conn1Item = self.connectors[0].connectedItem |
|
2136 |
conn2Item = self.connectors[1].connectedItem |
|
2137 |
self.connectors[0].connectedItem = conn2Item |
|
2138 |
self.connectors[1].connectedItem = conn1Item |
|
2139 |
|
|
2140 |
currentPoint = self.getCurrentPoint() |
|
2141 |
self.reSettingSymbol(currentPoint, self.angle) |
|
2142 |
|
|
2143 |
''' |
|
2144 |
@brief change standard point |
|
2145 |
@author kyouho |
|
2146 |
@date 2018.07.24 |
|
2147 |
''' |
|
2148 |
|
|
2149 |
def changeStandardPoint(self): |
|
2150 |
connPtsCount = len(self.connectors) |
|
2151 |
|
|
2152 |
if self.currentPointModeIndex < connPtsCount: |
|
2153 |
self.currentPointModeIndex += 1 |
|
2154 |
else: |
|
2155 |
self.currentPointModeIndex = 0 |
|
2156 |
|
|
2157 |
currentPoint = self.getCurrentPoint() |
|
2158 |
self.reSettingSymbol(currentPoint, self.angle) |
|
2159 |
|
|
2160 |
''' |
|
2161 | 2009 |
@brief get standard point |
2162 | 2010 |
@author kyouho |
2163 | 2011 |
@date 2018.07.25 |
내보내기 Unified diff