프로젝트

일반

사용자정보

개정판 759bdc98

ID759bdc98a8d800b49289d57868e3c7451741e7be
상위 565365e1
하위 56332ce8

백흠경이(가) 약 5년 전에 추가함

issue #1362: add a function to place dimension - revised

Change-Id: Icb2605b392572dc1ecbabbdf4458b49818b6a365

차이점 보기:

HYTOS/HYTOS/Commands/PlaceDimensionCommand.py
49 49
        try:
50 50
            event = param[1]
51 51
            if 'mousePressEvent' == param[0] and event.button() == Qt.LeftButton:
52
                selected = self.imageViewer.scene.itemAt(param[2], QTransform())
53

  
54
                if self._dimension is None and not selected:
55
                    self._dimension = PlaceDimensionCommand.create_item(pts=[param[2]])
56
                    if self._dimension:
57
                        self.imageViewer.scene.addItem(self._dimension)
58
                        self.onSuccess.emit()
59
                        self.isTreated = True
52
                if not self._dimension:
53
                    selected = self.imageViewer.scene.itemAt(param[2], QTransform())
54

  
55
                    if self._dimension is None and not selected:
56
                        self._dimension = PlaceDimensionCommand.create_item(pts=[param[2]])
57
                        if self._dimension:
58
                            self.imageViewer.scene.addItem(self._dimension)
59
                else:
60
                    self._dimension.set_pos([self._dimension.pos[0], param[2]])
61
                    self.onSuccess.emit()
62
                    self.isTreated = True
63
            elif 'mouseMoveEvent' == param[0] and self._dimension:
64
                self._dimension.set_pos([self._dimension.pos[0], param[2]])
60 65
            elif 'mouseReleaseEvent' == param[0] and event.button() == Qt.RightButton:
61 66
                self.onRejected.emit(self)
62 67
            elif 'keyPressEvent' == param[0]:
HYTOS/HYTOS/Shapes/EngineeringConnectorItem.py
371 371
    '''
372 372

  
373 373
    def mousePressEvent(self, event):
374
        if self.parentItem() is not None:
374
        if self.parentItem():
375 375
            if event.buttons() == Qt.LeftButton:
376 376
                self._savedPos = self._loc
377 377
                self._savedConnectedItem = self.connectedItem
......
444 444
    def mouseMoveEvent(self, event):
445 445
        import shapely
446 446
        from SymbolSvgItem import SymbolSvgItem
447
        from EngineeringArrowItem import QEngineeringArrowItem
447
        from EngineeringDimensionItem import QEngineeringDimensionItem
448 448
        from EngineeringTextItem import QEngineeringTextItem
449 449

  
450
        if self.parentItem() is not None and self._savedPos is not None:
450
        if self.parentItem() and self._savedPos is not None:
451 451
            if event.buttons() == Qt.LeftButton:
452 452
                items = [item for item in self.scene().items(event.scenePos()) if
453
                         item is not self and item is not self.parent and \
454
                         (issubclass(type(item), SymbolSvgItem) or issubclass(type(item), QEngineeringTextItem) or type(
455
                             item) is QEngineeringConnectorItem)]
456
                ## highlight underitem
453
                         item is not self and item is not self.parentItem() and \
454
                         (issubclass(type(item), SymbolSvgItem) or issubclass(type(item), QEngineeringTextItem) or
455
                          type(item) is QEngineeringConnectorItem)]
456
                # highlight underitem
457 457
                if len(items) > 0:
458 458
                    if not hasattr(self, '_underItem') or self._underItem is not items[0]:
459 459
                        if hasattr(self, '_underItem') and self._underItem is not None:
......
464 464
                elif hasattr(self, '_underItem') and self._underItem is not None:
465 465
                    self._underItem.hoverLeaveEvent(event)
466 466
                    self._underItem = None
467
                ## up to here
467
                # up to here
468 468

  
469 469
                if items and type(items[0]) is QEngineeringConnectorItem:
470 470
                    self.setPos(items[0].center())
471 471
                else:
472
                    pt = [event.scenePos().x(), event.scenePos().y()]
473

  
474
                    self.setPos(pt)
472
                    self.setPos([event.scenePos().x(), event.scenePos().y()])
475 473

  
476 474
                self.update()
477 475

  
HYTOS/HYTOS/Shapes/EngineeringDimensionItem.py
23 23
class QEngineeringDimensionItem(QGraphicsPathItem, QEngineeringAbstractItem):
24 24
    selected_change = pyqtSignal(QGraphicsItem)
25 25

  
26
    ARROW_SIZE = 10
27
    DIMENSION_DEPTH = 30
26 28
    HIGHLIGHT = '#BC4438'
27 29
    ZVALUE = 210
28 30

  
29
    '''
30
        @history    2018.05.17  Jeongwoo    Add self._owner variable
31
    '''
32

  
33 31
    def __init__(self, uid=None, pts=None):
34 32
        import uuid
35 33

  
......
43 41
        self.setAcceptHoverEvents(True)
44 42
        self.setAcceptTouchEvents(True)
45 43

  
46
        self._pts = pts
47
        self.setPath(self.create_path())
44
        self._selected_idx = None
45
        self.setPath(self.create_path(pts))
46
        self.setBrush(Qt.black)
48 47

  
49 48
        self.transfer = Transfer()
50 49
        self.setZValue(QEngineeringDimensionItem.ZVALUE)
......
53 52
        """ return string represent uuid """
54 53
        return str(self.uid)
55 54

  
56
    def create_path(self):
55
    @property
56
    def pos(self):
57
        """return dimension position"""
58
        path = self.mapToScene(self.path())
59
        return [QPointF(path.elementAt(0).x, path.elementAt(0).y), QPointF(path.elementAt(1).x, path.elementAt(1).y)]
60

  
61
    def set_pos(self, pts):
62
        """set dimension positions"""
63

  
64
        if pts and 2 == len(pts):
65
            self.setPath(self.create_path(pts))
66

  
67
    def create_path(self, pts):
57 68
        """create a path"""
58
        path = QPainterPath()
59
        if self._pts:
60
            if 1 == len(self._pts):
61
                self._pts.append(QPointF(self._pts[0].x() + 10, self._pts[0].y() + 10))
69
        import math
70
        from EngineeringConnectorItem import QEngineeringConnectorItem
62 71

  
63
            path.moveTo(self._pts[0])
64
            path.lineTo(self._pts[1])
72
        #self.resetTransform()
73
        path = QPainterPath()
74
        if pts:
75
            if 1 == len(pts):
76
                pts.append(QPointF(pts[0].x() + 10, pts[0].y() + 10))
77

  
78
            path.moveTo(pts[0])
79
            path.lineTo(pts[1])
80

  
81
            dx = pts[1].x() - pts[0].x()
82
            dy = pts[1].y() - pts[0].y()
83
            length = math.sqrt(dx*dx + dy*dy)
84
            if length:
85
                _dir = [dx / length, dy / length]
86

  
87
                arrow_size = QEngineeringDimensionItem.ARROW_SIZE * 0.25
88

  
89
                perpendicular = (-_dir[1], _dir[0])
90
                polygon = QPolygonF()
91
                polygon.append(QPointF(
92
                    pts[1].x() - _dir[0] * QEngineeringDimensionItem.ARROW_SIZE + perpendicular[0] * arrow_size,
93
                    pts[1].y() - _dir[1] * QEngineeringDimensionItem.ARROW_SIZE + perpendicular[1] * arrow_size))
94
                polygon.append(QPointF(
95
                    pts[1].x() - _dir[0] * QEngineeringDimensionItem.ARROW_SIZE - perpendicular[0] * arrow_size,
96
                    pts[1].y() - _dir[1] * QEngineeringDimensionItem.ARROW_SIZE - perpendicular[1] * arrow_size))
97
                polygon.append(pts[1])
98
                polygon.append(polygon[0])
99

  
100
                path.addPolygon(polygon)
101

  
102
                polygon = QPolygonF()
103
                polygon.append(QPointF(
104
                    pts[0].x() + _dir[0] * QEngineeringDimensionItem.ARROW_SIZE + perpendicular[0] * arrow_size,
105
                    pts[0].y() + _dir[1] * QEngineeringDimensionItem.ARROW_SIZE + perpendicular[1] * arrow_size))
106
                polygon.append(QPointF(
107
                    pts[0].x() + _dir[0] * QEngineeringDimensionItem.ARROW_SIZE - perpendicular[0] * arrow_size,
108
                    pts[0].y() + _dir[1] * QEngineeringDimensionItem.ARROW_SIZE - perpendicular[1] * arrow_size))
109
                polygon.append(pts[0])
110
                polygon.append(polygon[0])
111

  
112
                path.moveTo(pts[0].x() - perpendicular[0]*5, pts[0].y() - perpendicular[1]*5)
113
                path.lineTo(pts[0].x() + perpendicular[0]*QEngineeringDimensionItem.DIMENSION_DEPTH,
114
                            pts[0].y() + perpendicular[1]*QEngineeringDimensionItem.DIMENSION_DEPTH)
115

  
116
                path.moveTo(pts[1].x() - perpendicular[0]*5, pts[1].y() - perpendicular[1]*5)
117
                path.lineTo(pts[1].x() + perpendicular[0] * QEngineeringDimensionItem.DIMENSION_DEPTH,
118
                            pts[1].y() + perpendicular[1] * QEngineeringDimensionItem.DIMENSION_DEPTH)
119

  
120
                path.addPolygon(polygon)
121

  
122
                path.addEllipse(pts[0], 4, 4)
123
                path.addEllipse(pts[1], 4, 4)
124

  
125
                """
126
                if not self.connectors:
127
                    conn = QEngineeringConnectorItem(uid=None, parent=self, index=0)
128
                    conn.setFlags(
129
                        QGraphicsItem.ItemIsSelectable | QGraphicsItem.ItemIsFocusable | QGraphicsItem.ItemIsMovable)
130
                    conn.transfer.onPosChanged.connect(self.on_connector_pos_changed)
131
                    self.connectors.append(conn)
132
                    conn = QEngineeringConnectorItem(uid=None, parent=self, index=1)
133
                    conn.setFlags(
134
                        QGraphicsItem.ItemIsSelectable | QGraphicsItem.ItemIsFocusable | QGraphicsItem.ItemIsMovable)
135
                    conn.transfer.onPosChanged.connect(self.on_connector_pos_changed)
136
                    self.connectors.append(conn)
137

  
138
                self.connectors[0].setPos((self._pts[0].x(), self._pts[0].y()))
139
                self.connectors[1].setPos((self._pts[1].x(), self._pts[1].y()))
140
                """
65 141

  
66 142
        return path
67 143

  
144
    """
145
    def on_connector_pos_changed(self, conn):
146
        #rebuild stream line
147
        self._pts[conn._conn_index] = QPointF(conn.center()[0], conn.center()[1])
148
        self.setPath(self.create_path())
149
    """
150

  
68 151
    '''
69 152
        @brief      hover event
70 153
        @authro     humkyung
......
92 175
    def hoverMoveEvent(self, event):
93 176
        pass
94 177

  
178
    def mousePressEvent(self, event):
179
        import math
180

  
181
        if event.buttons() == Qt.LeftButton:
182
            toler = 5
183

  
184
            pos = event.scenePos()
185

  
186
            path = self.mapToScene(self.path())
187
            pts = [QPointF(path.elementAt(0).x, path.elementAt(0).y), QPointF(path.elementAt(1).x, path.elementAt(1).y)]
188

  
189
            dx = pts[0].x() - pos.x()
190
            dy = pts[0].y() - pos.y()
191
            if math.sqrt(dx * dx + dy * dy) < toler:
192
                self._selected_idx = 0
193
                return
194

  
195
            dx = pts[1].x() - pos.x()
196
            dy = pts[1].y() - pos.y()
197
            if math.sqrt(dx * dx + dy * dy) < toler:
198
                self._selected_idx = 1
199
                return
200

  
201
        super(QEngineeringDimensionItem, self).mousePressEvent(event)
202

  
203
    def mouseMoveEvent(self, event):
204
        """reshape dimension"""
205

  
206
        if event.buttons() == Qt.LeftButton and (self._selected_idx == 0 or self._selected_idx == 1):
207
            path = self.mapToScene(self.path())
208
            pts = [QPointF(path.elementAt(0).x, path.elementAt(0).y), QPointF(path.elementAt(1).x, path.elementAt(1).y)]
209
            pts[self._selected_idx] = event.scenePos()
210
            self.setPath(self.create_path(pts))
211
            return
212

  
213
        super(QEngineeringDimensionItem, self).mouseMoveEvent(event)
214

  
215
    def mouseReleaseEvent(self, event: 'QGraphicsSceneMouseEvent') -> None:
216
        self._selected_idx = None
217
        super(QEngineeringDimensionItem, self).mouseReleaseEvent(event)
218

  
95 219
    def itemChange(self, change, value):
96 220
        if change == QGraphicsItem.ItemSelectedChange:
97
            self.selected_change.emit(self)
221
            pass
98 222
        return value
99 223

  
100 224
    def setColor(self, color):

내보내기 Unified diff

클립보드 이미지 추가 (최대 크기: 500 MB)