개정판 4ff25dbf
issue #1061: revised create connector when creating stream line
Change-Id: Ic4fc96d336598ccf66fe715488c6d84587514a5b
HYTOS/HYTOS/Commands/PlaceStreamlineCommand.py | ||
---|---|---|
59 | 59 |
if 'mousePressEvent' == param[0] and event.button() == Qt.LeftButton: |
60 | 60 |
selected = self.imageViewer.scene.itemAt(param[2], QTransform()) |
61 | 61 |
|
62 |
if self._streamline is None:
|
|
62 |
if self._streamline is None: |
|
63 | 63 |
if selected is not None and type(selected) is QEngineeringConnectorItem: |
64 | 64 |
self._streamline = QEngineeringStreamlineItem() |
65 | 65 |
self._streamline._vertices.append(selected.center()) |
... | ... | |
68 | 68 |
|
69 | 69 |
self.connectorItems.append(selected) |
70 | 70 |
else: |
71 |
try:
|
|
71 |
try: |
|
72 | 72 |
if selected is not None and type(selected) is QEngineeringConnectorItem: |
73 | 73 |
self.connectorItems.append(selected) |
74 |
self._streamline._vertices[-1] = selected.center() |
|
74 | 75 |
|
75 |
#self.buildConnectors(self.connectorItems) |
|
76 |
|
|
77 |
QGraphicsView.mouseReleaseEvent(self.imageViewer, event) |
|
76 |
#QGraphicsView.mouseReleaseEvent(self.imageViewer, event) |
|
77 |
self._streamline.build_connectors(self.connectorItems) |
|
78 | 78 |
self._streamline.update() |
79 |
self.buildConnectors(self.connectorItems) |
|
80 | 79 |
self.onSuccess.emit() |
81 | 80 |
self.connectorItems.clear() |
82 | 81 |
finally: |
... | ... | |
94 | 93 |
pass |
95 | 94 |
|
96 | 95 |
def redo(self): |
97 |
pass |
|
98 |
|
|
99 |
def buildConnectors(self, connectorItems): |
|
100 |
from EngineeringConnectorItem import QEngineeringConnectorItem |
|
101 |
|
|
102 |
index = 0 |
|
103 |
for vertex in [self._streamline._vertices[0],self._streamline._vertices[-1]]: |
|
104 |
connector = QEngineeringConnectorItem(parent=self._streamline, index=index+1) |
|
105 |
connector.setPos(vertex) |
|
106 |
connector.setParentItem(self._streamline) |
|
107 |
# connector의 connectPoint, sceneConnectPoint를 vertex로 함 추후 좀 알아봐서 수정 필요 |
|
108 |
connector.connectPoint = vertex |
|
109 |
connector.sceneConnectPoint = vertex |
|
110 |
|
|
111 |
# add connector move ables |
|
112 |
connector.setFlags(QGraphicsItem.ItemIsSelectable|QGraphicsItem.ItemIsFocusable) |
|
113 |
connector.setAcceptTouchEvents(True) |
|
114 |
#connector.transfer.onPosChanged.connect(self.onConnectorPosChaned) |
|
115 |
|
|
116 |
connector.setZValue(self._streamline.zValue() + 1) |
|
117 |
self._streamline.connectors.append(connector) |
|
118 |
if len(connectorItems) > index: |
|
119 |
connector.connectedItem = connectorItems[index] |
|
120 |
|
|
121 |
index = index + 1 |
|
122 |
|
|
123 |
if len(connectorItems) > 1: |
|
124 |
connectorItems[0].connectedItem = self._streamline.connectors[0] |
|
125 |
connectorItems[1].connectedItem = self._streamline.connectors[1] |
|
126 |
else: |
|
127 |
connectorItems[0].connectedItem = self._streamline.connectors[0] |
|
96 |
pass |
HYTOS/HYTOS/Shapes/EngineeringConnectorItem.py | ||
---|---|---|
204 | 204 |
try: |
205 | 205 |
self.highlight(True) |
206 | 206 |
finally: |
207 |
if self.parentItem() is not None: self.parentItem().highlight(True) |
|
208 | 207 |
QApplication.setOverrideCursor(Qt.CrossCursor) |
209 | 208 |
|
210 | 209 |
''' |
... | ... | |
216 | 215 |
try: |
217 | 216 |
self.highlight(False) |
218 | 217 |
finally: |
219 |
if self.parentItem() is not None: self.parentItem().highlight(False) |
|
220 | 218 |
QApplication.restoreOverrideCursor() |
221 | 219 |
|
222 | 220 |
def highlight(self, flag): |
... | ... | |
240 | 238 |
if self.parentItem(): self.setZValue(self.parentItem().zValue() + 1) |
241 | 239 |
if self.scene() and self.scene().sceneRect().contains(self.sceneBoundingRect()): |
242 | 240 |
self.update() |
243 |
else: |
|
244 | 241 |
if self.scene(): self.scene().update() |
245 | 242 |
|
246 | 243 |
''' |
... | ... | |
253 | 250 |
if event.buttons() == Qt.LeftButton: |
254 | 251 |
self._savedPos = self._loc |
255 | 252 |
self._savedConnectedItem = self.connectedItem |
256 |
#self.grabKeyboard() |
|
257 | 253 |
|
258 | 254 |
QGraphicsEllipseItem.mousePressEvent(self, event) |
259 | 255 |
|
... | ... | |
274 | 270 |
items = [item for item in self.scene().items(event.scenePos()) if item is not self and item is not self.parentItem() and \ |
275 | 271 |
(issubclass(type(item), SymbolSvgItem) or issubclass(type(item), QEngineeringTextItem) or issubclass(type(item), QEngineeringLineItem) or type(item) is QEngineeringConnectorItem)] |
276 | 272 |
|
277 |
if items and type(items[0]) is QEngineeringLineItem: |
|
278 |
length = items[0].length()*0.5 |
|
279 |
dir = items[0].perpendicular() |
|
280 |
if self.parent.isHorizontal(): |
|
281 |
start = [event.scenePos().x() - dir[0]*length, self.parent.startPoint()[1] - dir[1]*length] |
|
282 |
end = [event.scenePos().x() + dir[0]*length, self.parent.startPoint()[1] + dir[1]*length] |
|
283 |
else: |
|
284 |
start = [self.parent.startPoint()[0] - dir[0]*length, event.scenePos().y() - dir[1]*length] |
|
285 |
end = [self.parent.startPoint()[0] + dir[0]*length, event.scenePos().y() + dir[1]*length] |
|
286 |
|
|
287 |
pt = items[0].intersection([start, end]) |
|
288 |
if (pt is not None) and (type(pt) == shapely.geometry.point.Point): |
|
289 |
self.setPos((pt.x, pt.y)) |
|
290 |
self.connect(items[0], QEngineeringAbstractItem.CONNECTED_AT_BODY) |
|
291 |
elif items and type(items[0]) is QEngineeringConnectorItem: |
|
273 |
if items and type(items[0]) is QEngineeringConnectorItem: |
|
292 | 274 |
self.setPos(items[0].center()) |
293 | 275 |
|
276 |
""" disconnect alreay connected item """ |
|
294 | 277 |
if self.connectedItem is not None: |
295 |
pass |
|
296 |
#for connect in self.connectedItem.connectors: |
|
297 |
# if connect.connectedItem == self.parent: |
|
298 |
# connect.connect(None) |
|
278 |
self.connectedItem.connect(None) |
|
299 | 279 |
|
300 |
self.connect(items[0].parent) |
|
301 |
items[0].connect(self.parent) |
|
280 |
""" connect each other """ |
|
281 |
self.connect(items[0]) |
|
282 |
items[0].connect(self) |
|
302 | 283 |
else: |
303 | 284 |
pt = [event.scenePos().x(), event.scenePos().y()] |
304 | 285 |
if self._drawing_mode == QEngineeringConnectorItem.AXIS_MODE: |
... | ... | |
315 | 296 |
|
316 | 297 |
self.setPos(pt) |
317 | 298 |
if self.connectedItem is not None: |
318 |
for connect in self.connectedItem.connectors: |
|
319 |
if connect.connectedItem == self.parent: |
|
320 |
connect.connect(None) |
|
299 |
self.connectedItem.connect(None) |
|
321 | 300 |
|
322 | 301 |
self.connect(None) |
323 | 302 |
|
HYTOS/HYTOS/Shapes/EngineeringStreamlineItem.py | ||
---|---|---|
21 | 21 |
class QEngineeringStreamlineItem(QGraphicsPathItem, QEngineeringAbstractItem): |
22 | 22 |
""" This is EngineeringPolylineItem Class """ |
23 | 23 |
|
24 |
ZVALUE = 100 |
|
24 | 25 |
onRemoved = pyqtSignal(QGraphicsItem) |
25 | 26 |
|
26 | 27 |
''' |
... | ... | |
40 | 41 |
self._vertices = [] |
41 | 42 |
self.isCreated = False |
42 | 43 |
self._pt = None |
43 |
self.setPen(QPen(Qt.blue, 2, Qt.SolidLine)) # set default pen
|
|
44 |
self.setPen(QPen(Qt.blue, 1, Qt.SolidLine)) # set default pen
|
|
44 | 45 |
|
45 | 46 |
self.transfer = Transfer() |
47 |
self.setZValue(QEngineeringStreamlineItem.ZVALUE) |
|
46 | 48 |
except Exception as ex: |
47 | 49 |
print('error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno)) |
48 | 50 |
|
49 |
@property |
|
50 |
def drawing_mode(self): |
|
51 |
return self._drawing_mode |
|
51 |
def build_connectors(self, connected): |
|
52 |
""" build connectors for stream line |
|
53 |
connected is target connector |
|
54 |
""" |
|
52 | 55 |
|
53 |
@drawing_mode.setter |
|
54 |
def drawing_mode(self, value): |
|
55 |
self._drawing_mode = value |
|
56 |
from EngineeringConnectorItem import QEngineeringConnectorItem |
|
57 |
|
|
58 |
index = 0 |
|
59 |
for vertex in [self._vertices[0],self._vertices[-1]]: |
|
60 |
connector = QEngineeringConnectorItem(parent=self, index=index+1) |
|
61 |
connector.setPos(vertex) |
|
62 |
connector.setParentItem(self) |
|
63 |
connector.connectPoint = vertex |
|
64 |
connector.sceneConnectPoint = vertex |
|
65 |
|
|
66 |
# add connector move ables |
|
67 |
connector.setFlags(QGraphicsItem.ItemIsSelectable|QGraphicsItem.ItemIsFocusable) |
|
68 |
connector.setAcceptTouchEvents(True) |
|
69 |
connector.transfer.onPosChanged.connect(self.on_connector_pos_chaned) |
|
70 |
|
|
71 |
connector.setZValue(self.zValue() + 1) |
|
72 |
self.connectors.append(connector) |
|
73 |
if len(connected) > index: |
|
74 |
connector.connect(connected[index]) |
|
75 |
connected[index].connect(connector) |
|
76 |
|
|
77 |
index = index + 1 |
|
56 | 78 |
|
57 | 79 |
''' |
58 | 80 |
@brief construct a polyline |
... | ... | |
85 | 107 |
@author humkyung |
86 | 108 |
@date 2018.04.23 |
87 | 109 |
''' |
88 |
def buildItem(self): |
|
110 |
def __buildItem(self):
|
|
89 | 111 |
path = QPainterPath() |
90 | 112 |
path.moveTo(self._vertices[0][0], self._vertices[0][1]) |
91 | 113 |
for i in range(1, len(self._vertices)): |
... | ... | |
162 | 184 |
self._vertices.append((self._vertices[-1][0], self._vertices[-1][1] + dy)) |
163 | 185 |
self._vertices.append(pt) |
164 | 186 |
|
165 |
self.buildItem() |
|
187 |
self.__buildItem()
|
|
166 | 188 |
self.update() |
167 | 189 |
|
168 | 190 |
''' |
... | ... | |
191 | 213 |
self.setPen(_pen) |
192 | 214 |
self.update() |
193 | 215 |
|
216 |
def on_connector_pos_chaned(self, connector): |
|
217 |
""" rebuild stream line """ |
|
218 |
|
|
219 |
self._vertices = [] |
|
220 |
|
|
221 |
self._vertices.append(self.connectors[0].center()) |
|
222 |
dx = self.connectors[-1].center()[0] - self._vertices[0][0] |
|
223 |
dy = self.connectors[-1].center()[1] - self._vertices[0][1] |
|
224 |
self._vertices.append((self._vertices[0][0] + dx*0.5, self._vertices[0][1])) |
|
225 |
self._vertices.append((self._vertices[-1][0], self._vertices[-1][1] + dy)) |
|
226 |
self._vertices.append(self.connectors[-1].center()) |
|
227 |
self.__buildItem() |
|
228 |
self.update() |
|
229 |
|
|
194 | 230 |
''' |
195 | 231 |
@brief The class transfer pyqtSignal Event. Cause Subclass of QGraphicsRectItem can't use pyqtSignal |
196 | 232 |
@author Jeongwoo |
HYTOS/HYTOS/Shapes/SymbolSvgItem.py | ||
---|---|---|
658 | 658 |
self.setZValue(QEngineeringAbstractItem.HOVER_ZVALUE) if flag else self.setZValue(SymbolSvgItem.ZVALUE) |
659 | 659 |
self.update() |
660 | 660 |
|
661 |
for assoc in self.associations(): |
|
662 |
assoc.highlight(flag) |
|
663 |
|
|
664 |
for connector in self.connectors: |
|
665 |
connector.highlight(flag) |
|
661 |
#for assoc in self.associations(): |
|
662 |
# assoc.highlight(flag) |
|
666 | 663 |
except Exception as ex: |
667 | 664 |
from App import App |
668 | 665 |
message = 'error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno) |
내보내기 Unified diff