프로젝트

일반

사용자정보

개정판 3025092f

ID3025092f1773367e1a0e84da6777ee5b79ce50ca
상위 eeb05bb2
하위 f823003e

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

dev issue #538: symbol copy and paste

차이점 보기:

DTI_PID/DTI_PID/Commands/CopySymbolCommand.py
1
import sys
1 2
import os.path
2 3
import AbstractCommand
3 4
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
5
    from PyQt5.QtCore import Qt, QRectF, pyqtSignal, QT_VERSION_STR, QEvent
6
    from PyQt5.QtGui import QImage, QPixmap, QPainterPath, QCursor, QMouseEvent, QTransform
6 7
    from PyQt5.QtWidgets import QGraphicsView, QGraphicsScene, QFileDialog, QApplication
7 8
except ImportError:
8 9
    try:
......
11 12
    except ImportError:
12 13
        raise ImportError("ImageViewerQt: Requires PyQt5 or PyQt4.")
13 14

  
15
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.realpath(__file__))) + '\\Shapes')
16
from SymbolSvgItem import SymbolSvgItem
17
from AppDocData import AppDocData
18
import symbol
14 19
'''
15 20
    @brief      QtImageViewer Copy Symbol Command
16 21
    @author     kyouho
......
21 26
    def __init__(self, imageViewer):
22 27
        super(CopySymbolCommand, self).__init__(imageViewer)
23 28
        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)
29
        QApplication.instance().setOverrideCursor(QCursor(Qt.DragCopyCursor))
30
        
31
        # create symbol
32
        svgFileName = self.imageViewer.copySymbol.name
33
        self.symbol = self.imageViewer.createSymbolObject(svgFileName)
34
        self.imageViewer.scene.addItem(self.symbol)
35
        
32 36
    '''
33
        @brief      Copy Symbol
37
        @brief      Select Attribuew
34 38
        @author     kyouho
35
        @date       18.07.27
39
        @date       18.07.19
36 40
    '''
37 41
    def execute(self, param):
38 42
        event = param[1]
39 43
        scenePos = param[2]
40 44

  
41

  
42 45
        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)
46
            transform = QTransform()
47
            transform.translate(scenePos.x(), scenePos.y())
48
            self.symbol.setTransform(transform)
53 49

  
54
            #강제 이벤트 발생 보류
55
            #drop = QDropEvent(event.pos(), Qt.CopyAction, mime, event.button(), Qt.NoModifier)
56
            #QCoreApplication.sendEvent(self.imageViewer, drop)
57
            #QCoreApplication.processEvents()
50
            self.imageViewer.scene.removeItem(self.symbol)
51
            self.imageViewer.matchSymbolToLine(self.symbol, scenePos)
52
        elif 'mouseMoveEvent' == param[0]:
53
            transform = QTransform()
54
            transform.translate(scenePos.x() - self.symbol.symbolOrigin[0], scenePos.y() - self.symbol.symbolOrigin[1])
55
            self.symbol.setTransform(transform)
58 56

  
59 57
        self.isTreated = True
60 58

  
DTI_PID/DTI_PID/QtImageViewer.py
356 356
                    self.command.execute(['keyPressEvent', event])
357 357
            elif event.key() == Qt.Key_C and self.isPressCtrl:
358 358
                selectedItems = self.scene.selectedItems()
359
                if len(selectedItems) == 1 and type(selectedItems[0]) is SymbolSvgItem:
359
                if len(selectedItems) == 1 and issubclass(type(selectedItems[0]), SymbolSvgItem):
360 360
                    self.copySymbol = selectedItems[0]
361 361
            elif event.key() == Qt.Key_V and self.isPressCtrl:
362 362
                if self.copySymbol is not None:
......
493 493
        
494 494
        scenePos = self.mapToScene(event.pos())
495 495
        svgFileName = event.mimeData().text()
496
        self.createSymbolAtPoint(scenePos, svgFileName)
496
        svg = self.createSymbolObject(svgFileName)
497
        self.matchSymbolToLine(svg, scenePos)
497 498
        event.acceptProposedAction()
498 499

  
499 500
    '''
......
501 502
        @author kyouho
502 503
        @date   2018.07.27
503 504
    '''
504
    def createSymbolAtPoint(self, scenePos, svgFileName):
505
    def createSymbolObject(self, svgFileName):
505 506
        from AppDocData import AppDocData
506 507
        import symbol
507 508
        
......
514 515
            connPts = [(float(x.split(',')[0]), float(x.split(',')[1])) for x in strConnPts.split('/')]
515 516

  
516 517
        svg.buildItem(svgFileName, symbol.getType(), 0, None, None, [float(x) for x in symbol.getOriginalPoint().split(',')], connPts, symbol.getBaseSymbol(), symbol.getAdditionalSymbol(), symbol.getHasInstrumentLabel())
517

  
518
        
519
        return svg
520
        
521
    '''
522
        @brief  match symbol to line
523
        @author kyouho
524
        @date   2018.07.27
525
    '''
526
    def matchSymbolToLine(self, svg, scenePos):
518 527
        matches = [item for item in self.scene.items() if (type(item) is QEngineeringLineItem) and (item.distanceTo((scenePos.x(), scenePos.y())) < 20)]
519 528
        if len(matches) == 1:
520 529
            matches[0].insertSymbol(svg, scenePos)

내보내기 Unified diff

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