개정판 cfe9e60c
issue #000 : Connector와 Connector 직접 연결시 on_symbol_pos_changed 이벤트 추가
Change-Id: I911b96db85aa99429631246d9aeeb3b950a9fcbb
HYTOS/HYTOS/Shapes/EngineeringConnectorItem.py | ||
---|---|---|
284 | 284 |
try: |
285 | 285 |
if self.parentItem() is not None and self._savedPos is not None: |
286 | 286 |
items = [item for item in self.scene().items(event.scenePos()) if item is not self and item is not self.parentItem() and \ |
287 |
(issubclass(type(item), SymbolSvgItem) or issubclass(type(item), QEngineeringTextItem) or issubclass(type(item), QEngineeringLineItem) or type(item) is QEngineeringConnectorItem)]
|
|
287 |
(issubclass(type(item), SymbolSvgItem) or issubclass(type(item), QEngineeringTextItem) or type(item) is QEngineeringConnectorItem)] |
|
288 | 288 |
|
289 | 289 |
if items and type(items[0]) is QEngineeringConnectorItem: |
290 | 290 |
self.setPos(items[0].center()) |
... | ... | |
321 | 321 |
self._underItem.highlight(False) |
322 | 322 |
## up to here |
323 | 323 |
|
324 |
for symbol in [self.parentItem() for self in items if type(self.parentItem()) is SymbolSvgItem]: |
|
325 |
symbol.transfer.on_pos_changed.connect(self.on_symbol_pos_changed) |
|
326 |
|
|
324 | 327 |
if self.parentItem() is not None: |
325 | 328 |
self._savedPos = None |
326 | 329 |
self._savedConnectedItem = None |
327 |
self.transfer.onPosChanged.emit(self) |
|
330 |
self.transfer.onPosChanged.emit(self)
|
|
328 | 331 |
finally: |
329 | 332 |
#self.ungrabKeyboard() |
330 | 333 |
pass |
331 | 334 |
|
332 | 335 |
QGraphicsEllipseItem.mouseReleaseEvent(self, event) |
333 | 336 |
|
337 |
def on_symbol_pos_changed(self, symbol): |
|
338 |
""" rebuild stream line because symbol position is changed """ |
|
339 |
stremline = self.parent |
|
340 |
|
|
341 |
if stremline.connectors[0].connectedItem is not None : stremline.connectors[0].setPos(stremline.connectors[0].connectedItem.center()) |
|
342 |
if stremline.connectors[-1].connectedItem is not None : stremline.connectors[-1].setPos(stremline.connectors[-1].connectedItem.center()) |
|
343 |
self.on_connector_pos_changed(None) |
|
344 |
|
|
345 |
def on_connector_pos_changed(self, connector): |
|
346 |
""" rebuild stream line """ |
|
347 |
stremline = self.parent |
|
348 |
|
|
349 |
stremline._vertices = [] |
|
350 |
|
|
351 |
stremline._vertices.append(stremline.connectors[0].center()) |
|
352 |
dx = stremline.connectors[-1].center()[0] - stremline._vertices[0][0] |
|
353 |
dy = stremline.connectors[-1].center()[1] - stremline._vertices[0][1] |
|
354 |
stremline._vertices.append((stremline._vertices[0][0] + dx*0.5, stremline._vertices[0][1])) |
|
355 |
stremline._vertices.append((stremline._vertices[-1][0], stremline._vertices[-1][1] + dy)) |
|
356 |
stremline._vertices.append(stremline.connectors[-1].center()) |
|
357 |
stremline.buildItem() |
|
358 |
stremline.update_arrow() |
|
359 |
stremline.update() |
|
334 | 360 |
''' |
335 | 361 |
@brief move connector's position while mouse drag |
336 | 362 |
@author humkyung |
... | ... | |
346 | 372 |
if self.parentItem() is not None and self._savedPos is not None: |
347 | 373 |
if event.buttons() == Qt.LeftButton: |
348 | 374 |
items = [item for item in self.scene().items(event.scenePos()) if item is not self and item is not self.parent and \ |
349 |
(issubclass(type(item), SymbolSvgItem) or issubclass(type(item), QEngineeringTextItem) or issubclass(type(item), QEngineeringLineItem) or type(item) is QEngineeringConnectorItem)]
|
|
375 |
(issubclass(type(item), SymbolSvgItem) or issubclass(type(item), QEngineeringTextItem) or type(item) is QEngineeringConnectorItem)] |
|
350 | 376 |
## highlight underitem |
351 | 377 |
if len(items) > 0: |
352 | 378 |
if not hasattr(self, '_underItem') or self._underItem is not items[0]: |
... | ... | |
360 | 386 |
self._underItem = None |
361 | 387 |
## up to here |
362 | 388 |
|
363 |
if items and self.parent not in items and type(items[0]) is QEngineeringLineItem: |
|
364 |
length = items[0].length()*0.5 |
|
365 |
dir = items[0].perpendicular() |
|
366 |
if self.parent.isHorizontal(): |
|
367 |
start = [event.scenePos().x() - dir[0]*length, self.parent.startPoint()[1] - dir[1]*length] |
|
368 |
end = [event.scenePos().x() + dir[0]*length, self.parent.startPoint()[1] + dir[1]*length] |
|
369 |
else: |
|
370 |
start = [self.parent.startPoint()[0] - dir[0]*length, event.scenePos().y() - dir[1]*length] |
|
371 |
end = [self.parent.startPoint()[0] + dir[0]*length, event.scenePos().y() + dir[1]*length] |
|
372 |
|
|
373 |
pt = items[0].intersection([start, end]) |
|
374 |
if (pt is not None) and (type(pt) == shapely.geometry.point.Point): |
|
375 |
self.setPos((pt.x, pt.y)) |
|
376 |
elif items and type(items[0]) is QEngineeringConnectorItem: |
|
389 |
if items and type(items[0]) is QEngineeringConnectorItem: |
|
377 | 390 |
self.setPos(items[0].center()) |
378 | 391 |
else: |
379 | 392 |
pt = [event.scenePos().x(), event.scenePos().y()] |
내보내기 Unified diff