프로젝트

일반

사용자정보

통계
| 개정판:

hytos / HYTOS / HYTOS / Commands / PlaceStreamlineCommand.py @ 4ff25dbf

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

1
# coding: utf-8
2
""" This is place stream line module """
3

    
4
import os.path
5
import AbstractCommand
6
try:
7
    from PyQt5.QtCore import *
8
    from PyQt5.QtGui import *
9
    from PyQt5.QtWidgets import *
10
except ImportError:
11
    try:
12
        from PyQt4.QtCore import Qt, QRectF, pyqtSignal, QT_VERSION_STR
13
        from PyQt4.QtGui import QGraphicsView, QGraphicsScene, QImage, QPixmap, QPainterPath, QFileDialog, QCursor
14
    except ImportError:
15
        raise ImportError("ImageViewerQt: Requires PyQt5 or PyQt4.")
16

    
17
class PlaceStreamlineCommand(AbstractCommand.AbstractCommand):
18
    """ This is place line class """
19

    
20
    onSuccess = pyqtSignal()
21
    onRejected = pyqtSignal(AbstractCommand.AbstractCommand)
22

    
23
    def __init__(self, imageViewer):
24
        super(PlaceStreamlineCommand, self).__init__(imageViewer)
25
        self.name = 'PlaceLine' 
26
        self.imageViewer.setCursor(QCursor(Qt.CrossCursor))
27

    
28
        self._streamline = None
29
        self.connectorItems = []
30

    
31
    @property
32
    def streamline(self):
33
        """ getter of _streamline """
34
        
35
        return self._streamline
36

    
37
    '''
38
        @brief      reset command status
39
        @author     humkyung
40
        @date       2018.07.23
41
    '''
42
    def reset(self):
43
        self._streamline = None
44

    
45
    '''
46
        @brief      place a line
47
        @author     humkyung
48
        @date       2018.07.23
49
    '''
50
    def execute(self, param):
51
        import shapely
52
        from EngineeringConnectorItem import QEngineeringConnectorItem
53
        from SymbolSvgItem import SymbolSvgItem
54
        from EngineeringStreamlineItem import QEngineeringStreamlineItem
55

    
56
        self.isTreated = False
57

    
58
        event = param[1]
59
        if 'mousePressEvent' == param[0] and event.button() == Qt.LeftButton:
60
            selected = self.imageViewer.scene.itemAt(param[2], QTransform())
61

    
62
            if self._streamline is None: 
63
                if selected is not None and type(selected) is QEngineeringConnectorItem:
64
                    self._streamline = QEngineeringStreamlineItem()
65
                    self._streamline._vertices.append(selected.center())
66
                    self.imageViewer.scene.addItem(self._streamline)
67
                    self.imageViewer.scene.setFocusItem(self._streamline)
68

    
69
                    self.connectorItems.append(selected)
70
            else:
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()
75

    
76
                    #QGraphicsView.mouseReleaseEvent(self.imageViewer, event)
77
                    self._streamline.build_connectors(self.connectorItems)
78
                    self._streamline.update()
79
                    self.onSuccess.emit()
80
                    self.connectorItems.clear()
81
                finally:
82
                    pass
83
        elif 'mouseReleaseEvent' == param[0] and event.button() == Qt.RightButton:
84
            self.onRejected.emit(self)
85
        elif 'mouseMoveEvent' == param[0] and self._streamline is not None:
86
            self._streamline.onMouseMoved(event, param[2])
87
        elif 'keyPressEvent' == param[0]:
88
            if event.key() == Qt.Key_Escape:
89
                self.onRejected.emit(self)
90
                self.isTreated = False
91

    
92
    def undo(self):
93
        pass
94

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