개정판 d345d01d
issue #1061: create stream line and update when move equpments
Change-Id: If5044eae3cf6426dab50fb6e17035fd875eb06f3
HYTOS/HYTOS/Commands/PlaceStreamlineCommand.py | ||
---|---|---|
22 | 22 |
|
23 | 23 |
def __init__(self, imageViewer): |
24 | 24 |
super(PlaceStreamlineCommand, self).__init__(imageViewer) |
25 |
self.name = 'PlaceLine'
|
|
25 |
self.name = 'PlaceStreamline'
|
|
26 | 26 |
self.imageViewer.setCursor(QCursor(Qt.CrossCursor)) |
27 | 27 |
|
28 | 28 |
self._streamline = None |
... | ... | |
60 | 60 |
selected = self.imageViewer.scene.itemAt(param[2], QTransform()) |
61 | 61 |
|
62 | 62 |
if self._streamline is None: |
63 |
if selected is not None and type(selected) is QEngineeringConnectorItem:
|
|
63 |
if selected is not None and (type(selected) is QEngineeringConnectorItem or type(selected.parentItem()) is QEngineeringConnectorItem):
|
|
64 | 64 |
self._streamline = QEngineeringStreamlineItem() |
65 |
self._streamline._vertices.append(selected.center()) |
|
65 |
self._streamline._vertices.append(selected.center() if type(selected) is QEngineeringConnectorItem else selected.parentItem().center())
|
|
66 | 66 |
self.imageViewer.scene.addItem(self._streamline) |
67 | 67 |
self.imageViewer.scene.setFocusItem(self._streamline) |
68 | 68 |
|
69 |
self.connectorItems.append(selected) |
|
69 |
self.connectorItems.append(selected if type(selected) is QEngineeringConnectorItem else selected.parentItem())
|
|
70 | 70 |
else: |
71 | 71 |
try: |
72 |
if selected is not None and type(selected) is QEngineeringConnectorItem:
|
|
73 |
self.connectorItems.append(selected) |
|
74 |
self._streamline._vertices[-1] = selected.center() |
|
72 |
if selected is not None and (type(selected) is QEngineeringConnectorItem or type(selected.parentItem()) is QEngineeringConnectorItem):
|
|
73 |
self.connectorItems.append(selected if type(selected) is QEngineeringConnectorItem else selected.parentItem())
|
|
74 |
self._streamline._vertices[-1] = selected.center() if type(selected) is QEngineeringConnectorItem else selected.parentItem().center()
|
|
75 | 75 |
|
76 | 76 |
#QGraphicsView.mouseReleaseEvent(self.imageViewer, event) |
77 | 77 |
self._streamline.build_connectors(self.connectorItems) |
HYTOS/HYTOS/Shapes/EngineeringConnectorItem.py | ||
---|---|---|
40 | 40 |
''' |
41 | 41 |
def __init__(self, uid=None, parent=None, index=-1): |
42 | 42 |
import uuid |
43 |
from SymbolSvgItem import SymbolSvgItem |
|
43 | 44 |
|
44 | 45 |
QGraphicsEllipseItem.__init__(self, parent) |
45 | 46 |
|
... | ... | |
60 | 61 |
|
61 | 62 |
self._drawing_mode = QEngineeringConnectorItem.AXIS_MODE |
62 | 63 |
|
63 |
""" setup label for connector index """ |
|
64 |
self._label = QGraphicsTextItem('{}'.format(index), self) |
|
65 |
self._label.setZValue(0) |
|
66 |
font = QFont('Arial', QEngineeringConnectorItem.SMALL_SIZE) |
|
67 |
font.setPointSizeF(5) |
|
68 |
self._label.setFont(font) |
|
64 |
if type(parent) is SymbolSvgItem: |
|
65 |
""" setup label for connector index """ |
|
66 |
self._label = QGraphicsTextItem('{}'.format(index), self) |
|
67 |
self._label.setAcceptedMouseButtons(Qt.NoButton) |
|
68 |
self._label.setZValue(0) |
|
69 |
font = QFont('Arial', QEngineeringConnectorItem.SMALL_SIZE) |
|
70 |
font.setPointSizeF(5) |
|
71 |
self._label.setFont(font) |
|
69 | 72 |
|
70 | 73 |
@property |
71 | 74 |
def connectedItem(self): |
... | ... | |
181 | 184 |
self.setRect(self._loc[0] - round(self.SMALL_SIZE*0.5), self._loc[1] - round(self.SMALL_SIZE*0.5), self.SMALL_SIZE, self.SMALL_SIZE) |
182 | 185 |
self.update() |
183 | 186 |
|
184 |
""" set label positon at center of connector """ |
|
185 |
self._label.setPos(QPointF(self._loc[0], self._loc[1])) |
|
187 |
if hasattr(self, '_label'): |
|
188 |
""" set label positon at center of connector """ |
|
189 |
self._label.setPos(QPointF(self._loc[0] - self._label.boundingRect().width()*0.5, self._loc[1] - self._label.boundingRect().height()*0.5)) |
|
186 | 190 |
|
187 | 191 |
def connect(self, item, at=QEngineeringAbstractItem.CONNECTED_AT_PT): |
188 | 192 |
""" connect to given item where given position """ |
... | ... | |
224 | 228 |
c.setNamedColor(QEngineeringConnectorItem.HIGHLIGHT) |
225 | 229 |
self.setPen(Qt.red) |
226 | 230 |
self.setBrush(c) |
227 |
font = self._label.font() |
|
228 |
font.setBold(True) |
|
229 |
self._label.setFont(font) |
|
231 |
if hasattr(self, '_label'): |
|
232 |
font = self._label.font() |
|
233 |
font.setBold(True) |
|
234 |
self._label.setFont(font) |
|
230 | 235 |
else: |
231 | 236 |
self.setRect(self._loc[0] - round(self.SMALL_SIZE*0.5), self._loc[1] - round(self.SMALL_SIZE*0.5), self.SMALL_SIZE, self.SMALL_SIZE) |
232 | 237 |
self.setPen(Qt.black) |
233 | 238 |
self.setBrush(Qt.yellow) if self.connectedItem else self.setBrush(Qt.blue) |
234 |
font = self._label.font() |
|
235 |
font.setBold(False) |
|
236 |
self._label.setFont(font) |
|
239 |
if hasattr(self, '_label'): |
|
240 |
font = self._label.font() |
|
241 |
font.setBold(False) |
|
242 |
self._label.setFont(font) |
|
237 | 243 |
|
238 | 244 |
if self.parentItem(): self.setZValue(self.parentItem().zValue() + 1) |
239 | 245 |
if self.scene() and self.scene().sceneRect().contains(self.sceneBoundingRect()): |
... | ... | |
406 | 412 |
def paint(self, painter, options=None, widget=None): |
407 | 413 |
QGraphicsEllipseItem.paint(self, painter, options, widget) |
408 | 414 |
|
409 |
if self.parentItem() is not None: |
|
415 |
if self.parentItem() is not None and hasattr(self, '_label'):
|
|
410 | 416 |
self._label.setDefaultTextColor(Qt.red) if self.parentItem().hover else self._label.setDefaultTextColor(Qt.black) |
411 | 417 |
|
412 | 418 |
''' |
HYTOS/HYTOS/Shapes/EngineeringStreamlineItem.py | ||
---|---|---|
7 | 7 |
import os.path |
8 | 8 |
import copy |
9 | 9 |
try: |
10 |
from PyQt5.QtCore import Qt, QRectF, pyqtSignal, QObject, QT_VERSION_STR
|
|
11 |
from PyQt5.QtGui import QImage, QPixmap, QPainterPath, QBrush, QPen, QPolygonF, QColor, QTransform
|
|
12 |
from PyQt5.QtWidgets import QGraphicsView, QGraphicsScene, QFileDialog, QGraphicsItem, QAbstractGraphicsShapeItem, QGraphicsPathItem
|
|
10 |
from PyQt5.QtCore import *
|
|
11 |
from PyQt5.QtGui import *
|
|
12 |
from PyQt5.QtWidgets import *
|
|
13 | 13 |
except ImportError: |
14 | 14 |
try: |
15 | 15 |
from PyQt4.QtCore import Qt, QRectF, QObject, pyqtSignal, QT_VERSION_STR |
... | ... | |
21 | 21 |
class QEngineeringStreamlineItem(QGraphicsPathItem, QEngineeringAbstractItem): |
22 | 22 |
""" This is EngineeringPolylineItem Class """ |
23 | 23 |
|
24 |
ARROW_SIZE = 10 |
|
24 | 25 |
ZVALUE = 100 |
25 | 26 |
onRemoved = pyqtSignal(QGraphicsItem) |
26 | 27 |
|
... | ... | |
53 | 54 |
connected is target connector |
54 | 55 |
""" |
55 | 56 |
|
57 |
from SymbolSvgItem import SymbolSvgItem |
|
56 | 58 |
from EngineeringConnectorItem import QEngineeringConnectorItem |
57 | 59 |
|
58 | 60 |
index = 0 |
... | ... | |
66 | 68 |
# add connector move ables |
67 | 69 |
connector.setFlags(QGraphicsItem.ItemIsSelectable|QGraphicsItem.ItemIsFocusable) |
68 | 70 |
connector.setAcceptTouchEvents(True) |
69 |
connector.transfer.onPosChanged.connect(self.on_connector_pos_chaned) |
|
71 |
connector.transfer.onPosChanged.connect(self.on_connector_pos_changed)
|
|
70 | 72 |
|
71 | 73 |
connector.setZValue(self.zValue() + 1) |
72 | 74 |
self.connectors.append(connector) |
... | ... | |
76 | 78 |
|
77 | 79 |
index = index + 1 |
78 | 80 |
|
81 |
""" connect symbol's on_pos_changed signal """ |
|
82 |
for symbol in [conn.parentItem() for conn in connected if type(conn.parentItem()) is SymbolSvgItem]: |
|
83 |
symbol.transfer.on_pos_changed.connect(self.on_symbol_pos_changed) |
|
84 |
|
|
85 |
self.update_arrow() |
|
86 |
|
|
87 |
def update_arrow(self): |
|
88 |
""" update flow arrow """ |
|
89 |
import math |
|
90 |
from EngineeringArrowItem import QEngineeringArrowItem |
|
91 |
if len(self._vertices) < 2: return |
|
92 |
|
|
93 |
start = self._vertices[-2] |
|
94 |
end = self._vertices[-1] |
|
95 |
|
|
96 |
dx = end[0] - start[0] |
|
97 |
dy = end[1] - start[1] |
|
98 |
length = math.sqrt(dx*dx + dy*dy) |
|
99 |
if length == 0: return |
|
100 |
|
|
101 |
_dir = [(end[0] - start[0])/length, (end[1] - start[1])/length] |
|
102 |
perpendicular = (-_dir[1], _dir[0]) |
|
103 |
polygon = QPolygonF() |
|
104 |
polygon.append(QPointF(end[0] - _dir[0]*QEngineeringStreamlineItem.ARROW_SIZE + perpendicular[0]*QEngineeringStreamlineItem.ARROW_SIZE*0.25, |
|
105 |
end[1] - _dir[1]*QEngineeringStreamlineItem.ARROW_SIZE + perpendicular[1]*QEngineeringStreamlineItem.ARROW_SIZE*0.25)) |
|
106 |
polygon.append(QPointF(end[0] - _dir[0]*QEngineeringStreamlineItem.ARROW_SIZE - perpendicular[0]*QEngineeringStreamlineItem.ARROW_SIZE*0.25, |
|
107 |
end[1] - _dir[1]*QEngineeringStreamlineItem.ARROW_SIZE - perpendicular[1]*QEngineeringStreamlineItem.ARROW_SIZE*0.25)) |
|
108 |
polygon.append(QPointF(end[0], end[1])) |
|
109 |
polygon.append(polygon[0]) # close polygon |
|
110 |
|
|
111 |
if not hasattr(self, '_arrow'): |
|
112 |
self._arrow = QEngineeringArrowItem(polygon, self) |
|
113 |
else: |
|
114 |
self._arrow.setPolygon(polygon) |
|
115 |
|
|
116 |
self._arrow.setBrush(Qt.blue) |
|
117 |
self._arrow.update() |
|
118 |
|
|
79 | 119 |
''' |
80 | 120 |
@brief construct a polyline |
81 | 121 |
''' |
... | ... | |
213 | 253 |
self.setPen(_pen) |
214 | 254 |
self.update() |
215 | 255 |
|
216 |
def on_connector_pos_chaned(self, connector): |
|
256 |
def on_symbol_pos_changed(self, symbol): |
|
257 |
""" rebuild stream line because symbol position is changed """ |
|
258 |
self.connectors[0].setPos(self.connectors[0].connectedItem.center()) |
|
259 |
self.connectors[-1].setPos(self.connectors[-1].connectedItem.center()) |
|
260 |
self.on_connector_pos_changed(None) |
|
261 |
|
|
262 |
def on_connector_pos_changed(self, connector): |
|
217 | 263 |
""" rebuild stream line """ |
218 | 264 |
|
219 | 265 |
self._vertices = [] |
... | ... | |
225 | 271 |
self._vertices.append((self._vertices[-1][0], self._vertices[-1][1] + dy)) |
226 | 272 |
self._vertices.append(self.connectors[-1].center()) |
227 | 273 |
self.__buildItem() |
274 |
self.update_arrow() |
|
228 | 275 |
self.update() |
229 | 276 |
|
230 | 277 |
''' |
HYTOS/HYTOS/Shapes/SymbolSvgItem.py | ||
---|---|---|
702 | 702 |
self.clicked.emit(self) |
703 | 703 |
|
704 | 704 |
''' |
705 |
@brief Mouse Release Event
|
|
706 |
@author kyouho
|
|
707 |
@date 18.07.17
|
|
705 |
@brief call on_pos_changed signal
|
|
706 |
@author humkyung
|
|
707 |
@date 19.07.17
|
|
708 | 708 |
''' |
709 | 709 |
def mouseReleaseEvent(self, event): |
710 | 710 |
super().mouseReleaseEvent(event) |
711 |
self.transfer.on_pos_changed.emit(self) |
|
711 | 712 |
|
712 | 713 |
def removeSelfAttr(self, attributeName): |
713 | 714 |
target = None |
... | ... | |
1610 | 1611 |
@date 2018.06.18 |
1611 | 1612 |
''' |
1612 | 1613 |
class Transfer(QObject): |
1614 |
on_pos_changed = pyqtSignal(QGraphicsItem) |
|
1613 | 1615 |
onRemoved = pyqtSignal(QGraphicsItem) |
1614 | 1616 |
|
1615 | 1617 |
def __init__(self, parent = None): |
내보내기 Unified diff