프로젝트

일반

사용자정보

개정판 eeb05bb2

IDeeb05bb2750d5af9b044d36d5103f0a26384b0f6
상위 6c542a60
하위 3025092f

gaqhf 이(가) 6년 이상 전에 추가함

dev issue #538: add command file

차이점 보기:

DTI_PID/DTI_PID/Commands/CopySymbolCommand.py
1
import os.path
2
import AbstractCommand
3
try:
4
    from PyQt5.QtCore import Qt, QRectF, pyqtSignal, QT_VERSION_STR, QEvent, QMimeData, QCoreApplication, QPoint
5
    from PyQt5.QtGui import QImage, QPixmap, QPainterPath, QCursor, QMouseEvent, QDropEvent, QDrag, QPixmap
6
    from PyQt5.QtWidgets import QGraphicsView, QGraphicsScene, QFileDialog, QApplication
7
except ImportError:
8
    try:
9
        from PyQt4.QtCore import Qt, QRectF, pyqtSignal, QT_VERSION_STR, QEvent
10
        from PyQt4.QtGui import QGraphicsView, QGraphicsScene, QImge, QPixmap, QPainterPath, QFileDialog, QCursor, QMouseEvent
11
    except ImportError:
12
        raise ImportError("ImageViewerQt: Requires PyQt5 or PyQt4.")
13

  
14
'''
15
    @brief      QtImageViewer Copy Symbol Command
16
    @author     kyouho
17
    @date       18.07.27
18
'''
19
class CopySymbolCommand(AbstractCommand.AbstractCommand):
20

  
21
    def __init__(self, imageViewer):
22
        super(CopySymbolCommand, self).__init__(imageViewer)
23
        self.name = 'CopySymbol'
24
        from AppDocData import AppDocData
25
        project = AppDocData.instance().getCurrentProject()
26
        svgFilePath = os.path.join(project.getSvgFilePath(), self.imageViewer.copySymbol.type, self.imageViewer.copySymbol.name + '.svg')
27
        pixmap = QPixmap(svgFilePath)
28
        cursor = QCursor(pixmap)
29

  
30
        QApplication.instance().setOverrideCursor(cursor)
31
        #self.imageViewer.setCursor(cursor)
32
    '''
33
        @brief      Copy Symbol
34
        @author     kyouho
35
        @date       18.07.27
36
    '''
37
    def execute(self, param):
38
        event = param[1]
39
        scenePos = param[2]
40

  
41

  
42
        if 'mouseReleaseEvent' == param[0] and event.button() == Qt.LeftButton:
43
            self.imageViewer.createSymbolAtPoint(scenePos, self.imageViewer.copySymbol.name)
44

  
45
            #mime = QMimeData()
46
            #mime.setText(self.imageViewer.copySymbol.name)
47
            
48
            #drag = QDrag(self)
49
            #drag.setMimeData(mime) 
50
            #originalPoint = self.imageViewer.copySymbol.symbolOrigin
51
            #drag.setHotSpot(QPoint(int(float(originalPoint[0])), int(float(originalPoint[1]))))
52
            #drag.exec(Qt.CopyAction)
53

  
54
            #강제 이벤트 발생 보류
55
            #drop = QDropEvent(event.pos(), Qt.CopyAction, mime, event.button(), Qt.NoModifier)
56
            #QCoreApplication.sendEvent(self.imageViewer, drop)
57
            #QCoreApplication.processEvents()
58

  
59
        self.isTreated = True
60

  
61
    def undo(self):
62
        pass
63

  
64
    def redo(self):
65
        pass
66

  
67
    '''
68
        @brief      Find TextItem contain Point
69
        @author     kyouho
70
        @date       18.07.19
71
    '''
72
    def findTextItemInPoint(self, point):
73
        from QEngineeringTextItem import QEngineeringTextItem
74
        
75
        for item in self.imageViewer.items():
76
            if type(item) is QEngineeringTextItem:
77
                if self.isOverlapItemAndPoint(item, point):
78
                    return (True, item)
79

  
80
        return (False,)
81

  
82
    '''
83
        @brief      Check Overlap
84
        @author     kyouho
85
        @date       18.07.17
86
    '''
87
    def isOverlapItemAndPoint(self, item, point):
88
        x = point.x()
89
        y = point.y()
90
        loc = item.loc
91
        size = item.size
92

  
93
        if loc[0] <= x and loc[0] + size[0] >= x and loc[1] <= y and loc[1] + size[1] >= y:
94
            return True
95
        else:
96
            return False

내보내기 Unified diff

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