프로젝트

일반

사용자정보

통계
| 개정판:

hytos / DTI_PID / DTI_PID / Commands / ConnectionPointCommand.py @ d11be98f

이력 | 보기 | 이력해설 | 다운로드 (4.92 KB)

1
import os.path
2
import AbstractCommand
3
try:
4
    from PyQt5.QtCore import Qt, QPoint, QPointF, QRectF, pyqtSignal, QT_VERSION_STR, QMimeData
5
    from PyQt5.QtGui import QImage, QPixmap, QPainterPath, QColor, QPen, QBrush, QTransform, QCursor
6
    from PyQt5.QtWidgets import QGraphicsView, QGraphicsScene, QFileDialog, QMessageBox
7
except ImportError:
8
    try:
9
        from PyQt4.QtCore import Qt, QPoint, QPointF, QRectF, pyqtSignal, QT_VERSION_STR, QMimeData
10
        from PyQt4.QtGui import QGraphicsView, QGraphicsScene, QImage, QPixmap, QPainterPath, QFileDialog, QColor, QPen, QBrush, QCursor
11
    except ImportError:
12
        raise ImportError("ImageViewerQt: Requires PyQt5 or PyQt4.")
13

    
14
class ConnectionPointCommand(AbstractCommand.AbstractCommand):
15
    onSuccess = pyqtSignal()
16

    
17
    def __init__(self, imageViewer, connectionPointLineEdit, connectionPointListWidget):
18
        super(ConnectionPointCommand, self).__init__(imageViewer)
19
        self.name = 'ConnectionPoint' 
20
        self.connectionPointLineEdit = connectionPointLineEdit
21
        self.connectionPointListWidget = connectionPointListWidget
22
        self.listItems = self.connectionPointListWidget.items(QMimeData())
23
        self.imageViewer.setCursor(QCursor(Qt.CrossCursor))
24
        self.imageWidth = self.imageViewer.image().width()
25
        self.imageHeight = self.imageViewer.image().height()
26
        self.initMinPoint = QPointF(self.imageWidth * -1, self.imageHeight * -1)
27
        #self.showGuideline(self.initMinPoint)
28
        self.connectionPointLineEdit.setText("")
29
    
30
    '''
31
        @brief      pan image by left click and drag
32
        @history    2016.06.12  Jeongwoo    Make new point (newScenePos)
33
    '''
34
    def execute(self, param):
35
        from EngineeringOriginItem import QEngineeringOriginItem
36
        from EngineeringGuidelineItem import QEngineeringGuidelineItem
37

    
38
        event = param[1]
39
        scenePos = param[2]
40

    
41
        newScenePos = QPointF(round(scenePos.x()), round(scenePos.y()))
42
        items = [item for item in self.imageViewer.scene.items(scenePos) \
43
            if type(item) is QEngineeringOriginItem or type(item) is QEngineeringGuidelineItem]
44

    
45
        originItem = None
46
        if items and type(items[0]) is QEngineeringGuidelineItem:
47
            originItem = items[0].parentItem()
48
        elif items[0] and type(items[0]) is QEngineeringOriginItem:
49
            originItem = items[0]
50

    
51
        if originItem is not None:
52
            center = originItem.rect().center() 
53
            dx = scenePos.x() - center.x()
54
            dy = scenePos.y() - center.y()
55
            if abs(dx) < 1:
56
                newScenePos.setX(center.x())
57
            if abs(dy) < 1:
58
                newScenePos.setY(center.y())
59

    
60
        if 'mousePressEvent' == param[0]:
61
            if event.button() == Qt.LeftButton:
62
                if self.isOnImage(newScenePos.x(), newScenePos.y()):
63
                    ## drawCircle Method is static
64
                    ConnectionPointCommand.drawCircle(self.imageViewer, newScenePos.x(), newScenePos.y())
65
                    text = "{},{}".format(newScenePos.x(), newScenePos.y())
66
                    self.connectionPointLineEdit.setText(text)
67
                    self.connectionPointListWidget.addItem(text)
68
                    self.onSuccess.emit()
69
                else:
70
                    QMessageBox.about(self.imageViewer, "알림", "심볼 내부를 선택해주세요.")
71

    
72
                QGraphicsView.mousePressEvent(self.imageViewer, event)
73
        elif 'mouseMoveEvent' == param[0]:
74
            if self.isOnImage(newScenePos.x(), newScenePos.y()):
75
                #self.showGuideline(newScenePos)
76
                self.connectionPointLineEdit.setText("{},{}".format(newScenePos.x(), newScenePos.y()))
77
            else:
78
                #self.showGuideline(self.initMinPoint)
79
                self.connectionPointLineEdit.setText("")
80
            pass
81
        self.isTreated = False
82
        
83
    '''
84
        @history    2018.06.11  Jeongwoo    Shorten method to add Ellipse
85
                    2018.06.12  Jeongwoo    Modify RectF's coords
86
                    humkyung 2018.08.28 add connector item instead of QGraphicsEllipse
87
    '''
88
    @staticmethod
89
    def drawCircle(imageViewer, x, y):
90
        from EngineeringConnectorItem import QEngineeringConnectorItem
91

    
92
        connector = QEngineeringConnectorItem()
93
        connector.setPos((float(x), float(y)))
94
        imageViewer.scene.addItem(connector)
95

    
96
    '''
97
        @history    2018.06.11  Jeongwoo    Make area bigger (width/height 1px)
98
                    2018.06.12  Jeongwoo    Make area smaller (width/height 1px)
99
    '''
100
    def isOnImage(self, x, y):
101
        if (x >= 0 and x <= self.imageWidth) and (y >= 0 and y <= self.imageHeight):
102
            return True
103
        else:
104
            return False
105
        
106
    '''
107
    def showGuideline(self, pos):
108
        self.imageViewer.crosshairPos = pos
109
        self.imageViewer.scene.update(QRectF(0, 0, self.imageWidth, self.imageHeight))
110
    '''
111

    
112
    def undo(self):
113
        pass
114

    
115
    def redo(self):
116
        pass
클립보드 이미지 추가 (최대 크기: 500 MB)