프로젝트

일반

사용자정보

개정판 4f696492

ID4f6964927ea54dd23cbb31af0443a5949ca79e30
상위 92eceb0f
하위 188ff83c

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

issue #1061: can resize symbol

Change-Id: I040cddfa0f0e542c71275d3c3250c41acd321ee1

차이점 보기:

HYTOS/HYTOS/MainWindow.py
2664 2664
        finally:
2665 2665
            pass
2666 2666

  
2667
    '''
2668
        @brief      Remove added item on same place and Add GraphicsItem
2669
        @author     Jeongwoo
2670
        @date       2018.05.25
2671
        @history    2018.05.29  Jeongwoo    Moved from QRecognitionDialog
2672
                    2018.06.18  Jeongwoo    Set Z-index
2673
    '''
2674

  
2675 2667
    def addSvgItemToScene(self, svgItem):
2668
        """add symbol item to scene"""
2676 2669
        svgItem.addSvgItemToScene(self.graphicsView.scene)
2677 2670

  
2678 2671
    '''
HYTOS/HYTOS/Shapes/EngineeringCloudItem.py
49 49

  
50 50
            self.setPos(pos)
51 51
            self._selected_idx = None
52
            """
53
            self.resizer = Resizer(parent=self)
54
            self.resizer.setPos(self.boundingRect().bottomRight() - QPointF(5, 5))
55
            self.resizer.resize_signal.connect(self.resize)
56
            """
57 52
        except Exception as ex:
58 53
            from App import App
59 54
            from AppDocData import MessageType
HYTOS/HYTOS/Shapes/EngineeringEqpDescTextItem.py
6 6
import copy
7 7

  
8 8
try:
9
    from PyQt5.QtCore import Qt, QPointF, QRectF, pyqtSignal, QT_VERSION_STR, QRect
9
    from PyQt5.QtCore import Qt, QPointF, QRectF, pyqtSignal, QT_VERSION_STR, QRect, QSizeF
10 10
    from PyQt5.QtGui import QImage, QPixmap, QPainterPath, QBrush, QPen, QTransform, QFont, QColor
11 11
    from PyQt5.QtWidgets import QGraphicsView, QGraphicsScene, QFileDialog, QGraphicsItem, QAbstractGraphicsShapeItem, \
12 12
        QGraphicsTextItem
......
41 41
        self.setFont(font)
42 42
        self.setDefaultTextColor(QColor(font_color))
43 43

  
44
        self.setZValue(100)
45

  
44 46
    def set_font_size(self, size):
45 47
        _font = self.font()
46 48
        _font.setPointSizeF(float(size))
47 49
        self.setFont(_font)
48
        #self.setHtml(self.toPlainText().replace('\n', '<br>'))
50
        # self.setHtml(self.toPlainText().replace('\n', '<br>'))
49 51

  
50 52
    def set_font_color(self, color):
51 53
        self.setDefaultTextColor(QColor(color))
......
79 81
            App.mainWnd().addMessage.emit(MessageType.Error, message)
80 82

  
81 83
        return res
84

  
85
    """
86
    def paint(self, painter, options=None, widget=None):
87
        painter.drawText(QRectF(self.pos(), QSizeF(self.boundingRect().width(), self.boundingRect().height())),
88
                         Qt.AlignLeft | Qt.TextWordWrap, self.toPlainText())
89
    """
90

  
HYTOS/HYTOS/Shapes/EngineeringStreamNoTextItem.py
52 52
        rect = self.boundingRect()
53 53
        r = rect.width()*0.5 if rect.width() > rect.height() else rect.height()*0.5
54 54
        painter.drawPolygon(self.create_poly(4, r, 0))
55
        QGraphicsTextItem.paint(self, painter, option, widget)
55

  
56
        super(QEngineeringStreamNoTextItem, self).paint(painter, option, widget)
56 57

  
57 58
    def create_poly(self, n, r, s):
58 59
        import math
HYTOS/HYTOS/Shapes/QEngineeringTagNoTextItem.py
4 4
import os.path
5 5
import sys
6 6
import copy
7

  
7 8
try:
8 9
    from PyQt5.QtCore import Qt, QPointF, QRectF, pyqtSignal, QT_VERSION_STR, QRect
9 10
    from PyQt5.QtGui import QImage, QPixmap, QPainterPath, QBrush, QPen, QTransform, QFont
10
    from PyQt5.QtWidgets import QGraphicsView, QGraphicsScene, QFileDialog, QGraphicsItem, QAbstractGraphicsShapeItem, QGraphicsTextItem
11
    from PyQt5.QtWidgets import QGraphicsView, QGraphicsScene, QFileDialog, QGraphicsItem, QAbstractGraphicsShapeItem, \
12
        QGraphicsTextItem
11 13
except ImportError:
12 14
    try:
13 15
        from PyQt4.QtCore import Qt, QRectF, pyqtSignal, QT_VERSION_STR, QRect
......
15 17
    except ImportError:
16 18
        raise ImportError("ImageViewerQt: Requires PyQt5 or PyQt4.")
17 19

  
18
from EngineeringPolylineItem import QEngineeringPolylineItem
19
from GraphicsBoundingBoxItem import QGraphicsBoundingBoxItem
20
from AppDocData import AppDocData,MessageType
20
from AppDocData import AppDocData, MessageType
21 21
from EngineeringTextItem import QEngineeringTextItem
22 22

  
23

  
23 24
class QEngineeringTagNoTextItem(QEngineeringTextItem):
24 25
    """ This is engineering tag no text item class """
25 26

  
......
53 54
                    if type(symbol) is QEngineeringEquipmentItem:
54 55
                        dx = symbol.center().x() - center.x()
55 56
                        dy = symbol.center().y() - center.y()
56
                        length = math.sqrt(dx*dx + dy*dy)
57
                        length = math.sqrt(dx * dx + dy * dy)
57 58
                        if (length < dist) and (minDist is None or length < minDist):
58 59
                            minDist = length
59 60
                            selected = symbol
......
63 64
                    self.owner = selected
64 65

  
65 66
        except Exception as ex:
66
            from App import App 
67
            message = 'error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno)
68
            App.mainWnd().addMessage.emit(MessageType.Error, message)
67
            from App import App
68
            message = 'error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename,
69
                                                           sys.exc_info()[-1].tb_lineno)
70
            App.mainWnd().addMessage.emit(MessageType.Error, message)
HYTOS/HYTOS/Shapes/SymbolSvgItem.py
76 76

  
77 77
        self.dbUid = None
78 78
        self.uid = uuid.uuid4() if uid is None else uuid.UUID(uid, version=4)
79
        # self.setElementId(str(self.uid))
80 79
        self.name = ''
81 80
        self.category = ''
82 81
        self.type = ''
......
89 88
        self.parentSymbol = ''
90 89
        self.childSymbol = ''
91 90
        self.hasInstrumentLabel = 0
92
        self.flip = flip
93 91
        # attributeType uid
94 92
        self.attribute = {}
95
        self._properties = {SymbolProp(None, 'Supplied By', 'String'): None}
96 93
        self._tag_no = None
94
        self._selected_idx = None
97 95
        self.setAcceptDrops(True)
98 96
        self.setAcceptHoverEvents(True)
99 97
        self.setAcceptedMouseButtons(Qt.LeftButton)
......
167 165
            self._color = self.DEFAULT_COLOR
168 166
        self.setColor(self._color)
169 167

  
170
    @property
171
    def properties(self):
172
        """ getter of properties """
173
        import uuid
174

  
175
        for prop, value in self._properties.items():
176
            try:
177
                if prop.is_selectable and type(value) is uuid.UUID and self.scene():
178
                    matches = [x for x in self.scene().items() if hasattr(x, 'uid') and str(x.uid) == str(value)]
179
                    if matches: self._properties[prop] = matches[0]
180

  
181
                if prop.Expression:
182
                    item = self._properties[prop]  # assign item
183
                    self._properties[prop] = eval(prop.Expression)
184
            except Exception as ex:
185
                from App import App
186

  
187
                message = 'error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename,
188
                                                               sys.exc_info()[-1].tb_lineno)
189
                App.mainWnd().addMessage.emit(MessageType.Error, message)
190

  
191
        return self._properties
192

  
193
    @properties.setter
194
    def properties(self, value):
195
        """ setter of properties """
196
        self._properties = value
197

  
198
    def set_property(self, property, value):
199
        """ set property with given value """
200
        if issubclass(type(value), QEngineeringAbstractItem): self.add_assoc_item(value, 0)
201
        matches = [prop for prop, _ in self._properties.items() if prop.Attribute == property]
202
        if matches: self._properties[matches[0]] = value
203

  
204
    def prop(self, name):
205
        """ return the value of given property with name """
206
        matches = [(prop, value) for prop, value in self.properties.items() if prop.Attribute == name]
207
        if matches: return matches[0][1]
208

  
209
        return None
210

  
211 168
    def validate(self):
212 169
        """validate symbol data"""
213 170

  
......
220 177

  
221 178
        return res
222 179

  
223
    def includes(self, pt, margin=0):
224
        """ return True if symbol contains given point else return False """
180
    @property
181
    def corners(self):
225 182
        rect = self.sceneBoundingRect()
226
        allowed_error = 0.1
227

  
228
        if abs(rect.x() - 0) <= allowed_error and abs(rect.y() - 0) <= allowed_error:
229
            # when first recognition step, symbols are not in scene(not yet added) therefore cannot use scenebounding rect
230
            minX = self.loc[0] - margin
231
            minY = self.loc[1] - margin
232
            maxX = minX + self.size[0] + margin
233
            maxY = minY + self.size[1] + margin
234
        else:
235
            minX = rect.x() - margin
236
            minY = rect.y() - margin
237
            maxX = minX + rect.width() + margin
238
            maxY = minY + rect.height() + margin
183
        return [rect.topLeft(), rect.bottomLeft(), rect.bottomRight(), rect.topRight()]
184

  
185
    def resize(self, change):
186
        """ resize item """
187
        try:
188
            rect = self.boundingRect()
189
            if rect.isValid():
190
                self.resetTransform()
191
                self.setPos(change.topLeft())
192
                scale = min([change.width() / rect.width(), change.height() / rect.height()])
193
                # scale the item
194
                self.setScale(scale)
195

  
196
                # scale down for label
197
                for conn, label in self.desc_labels.items():
198
                    label.setScale(1/scale)
199
                # up to here
239 200

  
240
        return True if (pt[0] >= minX and pt[0] <= maxX and pt[1] >= minY and pt[1] <= maxY) else False
201
                self.prepareGeometryChange()
202
                self.update()
203
        except Exception as ex:
204
            from App import App
205

  
206
            message = 'error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename,
207
                                                           sys.exc_info()[-1].tb_lineno)
208
            App.mainWnd().addMessage.emit(MessageType.Error, message)
241 209

  
242 210
    def toSql(self):
243 211
        import uuid
......
1282 1250
    def center(self):
1283 1251
        return self.sceneBoundingRect().center()
1284 1252

  
1285
    '''
1286
        @brief      highlight connector and attribute
1287
        @authro     humkyung
1288
        @date       2018.05.02
1289
    '''
1290

  
1291 1253
    def hoverEnterEvent(self, event):
1292
        from Resizer import Resizer
1293

  
1294 1254
        self.highlight(True)
1295 1255

  
1296
        ''' 잠시 주석 처리
1297
        """ create a resizer """
1298
        resizer = Resizer.instance()
1299
        resizer.connected = self
1300
        resizerWidth = resizer.rect.width() / 2
1301
        rect = self.sceneBoundingRect()
1302
        resizerOffset = QPointF(resizerWidth, resizerWidth)
1303
        resizer.setPos(rect.bottomRight() - resizerOffset)
1304
        if resizer.receivers(resizer.resizeSignal) > 0: resizer.resizeSignal.disconnect()
1305
        resizer.resizeSignal.connect(self.resize)
1306
        try:
1307
            self.transfer.on_pos_changed.disconnect(resizer.on_symbol_pos_changed)
1308
        except Exception as ex:
1309
            pass
1310
        self.transfer.on_pos_changed.connect(resizer.on_symbol_pos_changed)
1311
        resizer.setVisible(True)
1312
        if not resizer.scene(): self.scene().addItem(resizer)
1313
        '''
1314

  
1315 1256
    '''
1316 1257
        @brief      unhighlight connector and attribute
1317 1258
        @author     humkyung
......
1364 1305
    def hoverMoveEvent(self, event):
1365 1306
        pass
1366 1307

  
1367
    '''
1368
        @brief      Mouse Press Event
1369
        @author     Jeongwoo
1370
        @date       18.04.11
1371
        @history    kyouho 2018.07.18 add isClick logic
1372
    '''
1373

  
1374 1308
    def mousePressEvent(self, event):
1309
        import math
1310

  
1375 1311
        if event.buttons() == Qt.LeftButton:
1376
            self.clicked.emit(self)
1312
            toler = 10
1313

  
1314
            # try to select corner
1315
            self._selected_idx = None
1316
            pos = event.scenePos()
1317
            for idx, corner in enumerate(self.corners):
1318
                dx = corner.x() - pos.x()
1319
                dy = corner.y() - pos.y()
1320
                if math.sqrt(dx * dx + dy * dy) < toler:
1321
                    self._selected_idx = idx
1322
                    break
1323
            # up to here
1377 1324

  
1378
    '''
1379
        @brief      call on_pos_changed signal
1380
        @author     humkyung
1381
        @date       19.07.17
1382
    '''
1325
            if self._selected_idx is None:
1326
                self.clicked.emit(self)
1327

  
1328
        #super(SymbolSvgItem, self).mousePressEvent(event)
1329

  
1330
    def mouseMoveEvent(self, event):
1331
        """reshape dimension"""
1332

  
1333
        if event.buttons() == Qt.LeftButton and self._selected_idx is not None:
1334
            corners = [event.scenePos(), self.corners[(self._selected_idx + 2) % 4]]
1335
            min_x, min_y = min(corners, key=lambda pt: pt.x()).x(), min(corners, key=lambda pt: pt.y()).y()
1336
            max_x, max_y = max(corners, key=lambda pt: pt.x()).x(), max(corners, key=lambda pt: pt.y()).y()
1337

  
1338
            self.resize(QRectF(min_x, min_y, max_x - min_x, max_y - min_y))
1339
            return
1340

  
1341
        super(SymbolSvgItem, self).mouseMoveEvent(event)
1383 1342

  
1384 1343
    def mouseReleaseEvent(self, event):
1385
        super().mouseReleaseEvent(event)
1344
        self._selected_idx = None
1345
        super(SymbolSvgItem, self).mouseReleaseEvent(event)
1386 1346

  
1387 1347
    def itemChange(self, change, value):
1388 1348
        """ call signals when item's position is changed """
......
2068 2028
        if self.isSelected():
2069 2029
            self.draw_focus_rect(painter)
2070 2030

  
2071
    '''
2072
        @brief      Add Svg Item into ImageViewer's Scene
2073
        @author     Jeongwoo
2074
        @date       2018.05.03
2075
        @history    add connectors which's parent is symbol
2076
                    kyouho  2018.07.30  remove connectors logic
2077
    '''
2078

  
2079 2031
    def addSvgItemToScene(self, scene):
2032
        """add svg item to scene"""
2080 2033
        transform = QTransform()
2081 2034

  
2082 2035
        transform.translate(self.loc[0] + self.symbolOrigin[0], self.loc[1] + self.symbolOrigin[1])
......
2107 2060

  
2108 2061
        # set label
2109 2062
        label = QEngineeringEqpDescTextItem('', self)
2110
        #label.setVisible(False)
2111 2063
        self.desc_labels[connector] = label
2112 2064

  
2113 2065
    def deleteSvgItemFromScene(self):
......
2127 2079
        self.transfer.onRemoved.emit(self)
2128 2080

  
2129 2081
    '''
2130
        @brief      Return real item position
2131
        @author     Jeongwoo
2132
        @date       2018.05.25
2133
    '''
2134

  
2135
    def boundingRectOnScene(self):
2136
        rect = self.boundingRect()
2137
        rect.moveTo(self.loc[0], self.loc[1])
2138
        return rect
2139

  
2140
    '''
2141 2082
        @brief      get standard point
2142 2083
        @author     kyouho
2143 2084
        @date       2018.07.25
......
2173 2114

  
2174 2115
        self.loc = [self.loc[0] + self.origin[0] - goPoint.x(), self.loc[1] + self.origin[1] - goPoint.y()]
2175 2116

  
2176
    def resize(self, change):
2177
        """ resize item """
2178
        # Get the smaller side of the rect
2179
        rect = self.sceneBoundingRect()
2180
        loc = QPointF(rect.x(), rect.y())
2181
        self.resetTransform()
2182
        # self.setScale(1)
2183
        rect = self.sceneBoundingRect()
2184
        scale = [(change.width() - loc.x()) / rect.width(), (change.height() - loc.y()) / rect.height()]
2185
        # scale the item
2186
        if scale[0] > 0 and scale[1] > 0:
2187
            self.setPos(loc)
2188
            # self.setScale(scale[0] if scale[0] < scale[1] else scale[1])
2189
            trans = QTransform()
2190
            trans.scale(scale[0] if scale[0] < scale[1] else scale[1], scale[0] if scale[0] < scale[1] else scale[1])
2191
            self.setTransform(trans)
2192
            self.prepareGeometryChange()
2193
            self.update()
2194

  
2195
            self.transfer.on_size_changed.emit(self)
2196

  
2197 2117
    def moveto(self, to, timeLine=5000, rotation=0):
2198 2118
        """Move the item from one position to one other."""
2199 2119

  

내보내기 Unified diff

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