개정판 10a61578
issue #000: add 2-way symbol adding assistant
Change-Id: I012d623cf7a9c5ddd831fd06c40108588975bf0f
DTI_PID/DTI_PID/QtImageViewer.py | ||
---|---|---|
594 | 594 |
''' |
595 | 595 |
def matchSymbolToLine(self, svg, scenePos): |
596 | 596 |
from EngineeringConnectorItem import QEngineeringConnectorItem |
597 |
from EngineeringLineItem import QEngineeringLineItem |
|
598 |
from SymbolSvgItem import SymbolSvgItem |
|
597 | 599 |
|
598 |
items = [item for item in self.scene.items(scenePos) if type(item) is not QGraphicsPixmapItem] |
|
600 |
items = [item for item in self.scene.items(scenePos) if type(item) is not QGraphicsPixmapItem and type(item) is not QGraphicsTextItem] |
|
601 |
connectors = [] |
|
599 | 602 |
if len(items) > 0 and type(items[0]) is QEngineeringConnectorItem: |
600 | 603 |
scenePos = QPointF(items[0].center()[0], items[0].center()[1]) |
604 |
connectors = [sym for sym in items if issubclass(type(sym.parentItem()), SymbolSvgItem)] |
|
601 | 605 |
|
602 | 606 |
matches = [item for item in self.scene.items() if (type(item) is QEngineeringLineItem) and (item.distanceTo((scenePos.x(), scenePos.y())) < 20)] |
603 | 607 |
if False:#len(matches) == 1: |
604 |
pass |
|
605 |
#matches[0].insertSymbol(svg, scenePos) |
|
608 |
matches[0].insertSymbol(svg, scenePos) |
|
609 |
elif len(connectors) == 1 and len(svg.connectors) == 2 and len(connectors[0].parentItem().connectors) and (connectors[0].parentItem().angle == 0 or connectors[0].parentItem().angle == 1.57 or connectors[0].parentItem().angle == 3.14 or connectors[0].parentItem().angle == 4.71): |
|
610 |
# 0, 90, 180, 270 2-way to 2-way item assistant with line connection |
|
611 |
ddx = ((connectors[0].sceneBoundingRect().center().x() - connectors[0].parentItem().sceneBoundingRect().center().x()) / abs(connectors[0].sceneBoundingRect().center().x() - connectors[0].parentItem().sceneBoundingRect().center().x())) if abs(connectors[0].sceneBoundingRect().center().x() - connectors[0].parentItem().sceneBoundingRect().center().x()) > 0.000001 else 1 |
|
612 |
ddy = ((connectors[0].sceneBoundingRect().center().y() - connectors[0].parentItem().sceneBoundingRect().center().y()) / abs(connectors[0].sceneBoundingRect().center().y() - connectors[0].parentItem().sceneBoundingRect().center().y())) if abs(connectors[0].sceneBoundingRect().center().y() - connectors[0].parentItem().sceneBoundingRect().center().y()) > 0.000001 else 1 |
|
613 |
dx, dy = abs(svg.connectors[0].connectPoint[0] - svg.symbolOrigin[0]), abs(svg.connectors[0].connectPoint[1] - svg.symbolOrigin[1]) |
|
614 |
if connectors[0].parentItem().angle == 1.57 or connectors[0].parentItem().angle == 4.71: |
|
615 |
dx, dy = ddx * dy, ddy * dx |
|
616 |
else: |
|
617 |
dx, dy = ddx * dx, ddy * dy |
|
618 |
svg.angle = connectors[0].parentItem().angle |
|
619 |
x, y = connectors[0].sceneBoundingRect().center().x() + dx, connectors[0].sceneBoundingRect().center().y() + dy |
|
620 |
svg.loc = [x - svg.symbolOrigin[0], y - svg.symbolOrigin[1]] |
|
621 |
svg.origin = [x, y] |
|
622 |
svg.addSvgItemToScene(self.scene) |
|
623 |
|
|
624 |
items = [item for item in self.scene.items(scenePos) if type(item) is not QGraphicsPixmapItem and type(item) is not QGraphicsTextItem] |
|
625 |
items = [item for item in items if item.parentItem() is svg] |
|
626 |
if items and connectors[0].connectedItem and type(connectors[0].connectedItem) is QEngineeringLineItem: |
|
627 |
items[0].connectedItem = connectors[0].parentItem() |
|
628 |
anotherConns = [conn for conn in svg.connectors if conn is not items[0]] |
|
629 |
anotherConns[0].connectedItem = connectors[0].connectedItem |
|
630 |
for lineConn in connectors[0].connectedItem.connectors: |
|
631 |
if lineConn.connectedItem is connectors[0].parentItem(): |
|
632 |
lineConn.connectedItem = svg |
|
633 |
lineConn.setPos(anotherConns[0].center()) |
|
634 |
break |
|
635 |
connectors[0].connectedItem = svg |
|
636 |
lineConn.transfer.onPosChanged.emit(lineConn) |
|
637 |
elif items: |
|
638 |
items[0].connectedItem = connectors[0].parentItem() |
|
639 |
if connectors[0].connectedItem: |
|
640 |
for conn in connectors[0].connectedItem.connectors: |
|
641 |
if lineConn.connectedItem is connectors[0].parentItem(): |
|
642 |
lineConn.connectedItem = None |
|
643 |
break |
|
644 |
connectors[0].connectedItem = svg |
|
606 | 645 |
else: |
607 | 646 |
transform = QTransform() |
608 | 647 |
transform.translate(scenePos.x() - svg.symbolOrigin[0], scenePos.y() - svg.symbolOrigin[1]) |
DTI_PID/DTI_PID/Shapes/SymbolSvgItem.py | ||
---|---|---|
1488 | 1488 |
self.angle = 0 |
1489 | 1489 |
else: |
1490 | 1490 |
self.angle = 0 |
1491 |
|
|
1492 |
self.size[0], self.size[1] = self.size[1], self.size[0] |
|
1493 | 1491 |
else: |
1494 | 1492 |
self.angle = angle |
1495 | 1493 |
|
... | ... | |
1529 | 1527 |
line.reDrawLine(self, connector.center()) |
1530 | 1528 |
line.update_arrow() |
1531 | 1529 |
|
1530 |
self.size[0], self.size[1] = round(self.sceneBoundingRect().width()), round(self.sceneBoundingRect().height()) |
|
1531 |
|
|
1532 | 1532 |
''' |
1533 | 1533 |
@brief change Conn point |
1534 | 1534 |
@author kyouho |
내보내기 Unified diff