개정판 0e1cee66
issue #000: symbol adding assist now apply every degrees
Change-Id: I92aaa60cac610752d39ea311e1a2bef17d852d93
DTI_PID/DTI_PID/QtImageViewer.py | ||
---|---|---|
601 | 601 |
from EngineeringConnectorItem import QEngineeringConnectorItem |
602 | 602 |
from EngineeringLineItem import QEngineeringLineItem |
603 | 603 |
from SymbolSvgItem import SymbolSvgItem |
604 |
import math |
|
604 | 605 |
|
605 | 606 |
svg.transfer.onRemoved.connect(self.mainWindow.itemRemoved) |
606 | 607 |
|
... | ... | |
613 | 614 |
matches = [item for item in self.scene.items() if (type(item) is QEngineeringLineItem) and (item.distanceTo((scenePos.x(), scenePos.y())) < 20)] |
614 | 615 |
if False:#len(matches) == 1: |
615 | 616 |
matches[0].insertSymbol(svg, scenePos) |
616 |
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): |
|
617 |
# 0, 90, 180, 270 2-way to 2-way item assistant with line connection |
|
618 |
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 |
|
619 |
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 |
|
617 |
elif len(connectors) == 1 and len(svg.connectors) == 2 and len(connectors[0].parentItem().connectors): |
|
618 |
# 2-way to 2-way item assistant with line connection |
|
619 |
xl = connectors[0].parentItem().symbolOrigin[0] - connectors[0].connectPoint[0] |
|
620 |
yl = connectors[0].parentItem().symbolOrigin[1] - connectors[0].connectPoint[1] |
|
621 |
length = math.sqrt(xl * xl + yl * yl) |
|
622 |
ddx = (connectors[0].sceneBoundingRect().center().x() - connectors[0].parentItem().origin[0]) / length |
|
623 |
ddy = (connectors[0].sceneBoundingRect().center().y() - connectors[0].parentItem().origin[1]) / length |
|
620 | 624 |
dx, dy = abs(svg.connectors[0].connectPoint[0] - svg.symbolOrigin[0]), abs(svg.connectors[0].connectPoint[1] - svg.symbolOrigin[1]) |
621 |
if connectors[0].parentItem().angle == 1.57 or connectors[0].parentItem().angle == 4.71: |
|
622 |
dx, dy = ddx * dy, ddy * dx |
|
623 |
else: |
|
624 |
dx, dy = ddx * dx, ddy * dy |
|
625 |
length = math.sqrt(dx * dx + dy * dy) |
|
626 |
dx, dy = length * ddx, length * ddy |
|
627 |
|
|
628 |
allowed_error = 0.01 |
|
629 |
#if abs(connectors[0].parentItem().angle - math.pi / 2) < allowed_error or abs(connectors[0].parentItem().angle - math.pi / 2 * 3) < allowed_error: |
|
630 |
# dx, dy = ddx * dy, ddy * dx |
|
631 |
#else: |
|
632 |
# dx, dy = ddx * dx, ddy * dy |
|
625 | 633 |
|
634 |
flip = connectors[0].parentItem().flip |
|
635 |
angle = connectors[0].parentItem().angle |
|
626 | 636 |
if connectors[0].parentItem().connectors.index(connectors[0]) == 0: |
627 |
svg.angle = connectors[0].parentItem().angle |
|
637 |
if flip == 0: |
|
638 |
svg.angle = angle |
|
639 |
else: |
|
640 |
if angle == 0: |
|
641 |
svg.angle = 3.14 |
|
642 |
elif angle == 3.14: |
|
643 |
svg.angle = 0.0 |
|
644 |
elif angle == 1.57: |
|
645 |
svg.angle = 4.71 |
|
646 |
elif angle == 4.71: |
|
647 |
svg.angle = 1.57 |
|
648 |
else: |
|
649 |
svg.angle = angle + math.pi if angle + math.pi < 2 * math.pi - allowed_error else angle - math.pi |
|
628 | 650 |
else: |
629 |
if connectors[0].parentItem().angle == 0:
|
|
651 |
if (angle == 0 and flip == 0) or (angle == 3.14 and flip == 1):
|
|
630 | 652 |
svg.angle = 3.14 |
631 |
elif connectors[0].parentItem().angle == 3.14:
|
|
653 |
elif (angle == 3.14 and flip == 0) or (angle == 0 and flip == 1):
|
|
632 | 654 |
svg.angle = 0.0 |
633 |
elif connectors[0].parentItem().angle == 1.57:
|
|
655 |
elif (angle == 1.57 and flip == 0) or (angle == 4.71 and flip == 1):
|
|
634 | 656 |
svg.angle = 4.71 |
635 |
elif connectors[0].parentItem().angle == 4.71:
|
|
657 |
elif (angle == 4.71 and flip == 0) or (angle == 1.57 and flip == 1):
|
|
636 | 658 |
svg.angle = 1.57 |
659 |
elif flip == 0: |
|
660 |
svg.angle = angle + math.pi if angle + math.pi < 2 * math.pi - allowed_error else angle - math.pi |
|
661 |
else: |
|
662 |
svg.angle = angle |
|
637 | 663 |
|
638 | 664 |
x, y = connectors[0].sceneBoundingRect().center().x() + dx, connectors[0].sceneBoundingRect().center().y() + dy |
639 | 665 |
svg.loc = [x - svg.symbolOrigin[0], y - svg.symbolOrigin[1]] |
내보내기 Unified diff