hytos / DTI_PID / DTI_PID / Commands / ConnectionPointCommand.py @ 0df8e0bc
이력 | 보기 | 이력해설 | 다운로드 (4.5 KB)
1 |
import os.path |
---|---|
2 |
import AbstractCommand |
3 |
|
4 |
try:
|
5 |
from PyQt5.QtCore import * |
6 |
from PyQt5.QtGui import * |
7 |
from PyQt5.QtWidgets import * |
8 |
except ImportError: |
9 |
try:
|
10 |
from PyQt4.QtCore import Qt, QPoint, QPointF, QRectF, pyqtSignal, QT_VERSION_STR, QMimeData |
11 |
from PyQt4.QtGui import QGraphicsView, QGraphicsScene, QImage, QPixmap, QPainterPath, QFileDialog, QColor, QPen, \ |
12 |
QBrush, QCursor |
13 |
except ImportError: |
14 |
raise ImportError("ImageViewerQt: Requires PyQt5 or PyQt4.") |
15 |
|
16 |
|
17 |
class ConnectionPointCommand(AbstractCommand.AbstractCommand): |
18 |
"""
|
19 |
ConnectionPointCommand class
|
20 |
"""
|
21 |
|
22 |
onSuccess = pyqtSignal(QGraphicsItem) |
23 |
|
24 |
def __init__(self, imageViewer, connectionPointLineEdit, index=-1): |
25 |
super(ConnectionPointCommand, self).__init__(imageViewer) |
26 |
self.name = 'ConnectionPoint' |
27 |
self.connectionPointLineEdit = connectionPointLineEdit
|
28 |
self.imageViewer.setCursor(QCursor(Qt.CrossCursor))
|
29 |
self.imageWidth = self.imageViewer.image().width() |
30 |
self.imageHeight = self.imageViewer.image().height() |
31 |
self.initMinPoint = QPointF(self.imageWidth * -1, self.imageHeight * -1) |
32 |
self.connectionPointLineEdit.setText("") |
33 |
self.index = index
|
34 |
|
35 |
'''
|
36 |
@brief pan image by left click and drag
|
37 |
@history 2016.06.12 Jeongwoo Make new point (newScenePos)
|
38 |
'''
|
39 |
|
40 |
def execute(self, param): |
41 |
from EngineeringOriginItem import QEngineeringOriginItem |
42 |
from EngineeringGuidelineItem import QEngineeringGuidelineItem |
43 |
|
44 |
event = param[1]
|
45 |
scenePos = param[2]
|
46 |
|
47 |
newScenePos = QPointF(round(scenePos.x()), round(scenePos.y())) |
48 |
items = [item for item in self.imageViewer.scene().items(scenePos) \ |
49 |
if type(item) is QEngineeringOriginItem or type(item) is QEngineeringGuidelineItem] |
50 |
|
51 |
originItem = None
|
52 |
if items and type(items[0]) is QEngineeringGuidelineItem: |
53 |
originItem = items[0].parentItem()
|
54 |
elif items and type(items[0]) is QEngineeringOriginItem: |
55 |
originItem = items[0]
|
56 |
|
57 |
if originItem is not None: |
58 |
center = originItem.rect().center() |
59 |
dx = scenePos.x() - center.x() |
60 |
dy = scenePos.y() - center.y() |
61 |
if abs(dx) < 1: |
62 |
newScenePos.setX(center.x()) |
63 |
if abs(dy) < 1: |
64 |
newScenePos.setY(center.y()) |
65 |
|
66 |
if 'mousePressEvent' == param[0]: |
67 |
if event.button() == Qt.LeftButton:
|
68 |
if self.isOnImage(newScenePos.x(), newScenePos.y()): |
69 |
## drawCircle Method is static
|
70 |
conn = ConnectionPointCommand.drawCircle(self.imageViewer, newScenePos.x(), newScenePos.y(),
|
71 |
self.index)
|
72 |
text = "{},{}".format(newScenePos.x(), newScenePos.y())
|
73 |
self.connectionPointLineEdit.setText(text)
|
74 |
self.index += 1 |
75 |
self.onSuccess.emit(conn)
|
76 |
else:
|
77 |
QMessageBox.about(self.imageViewer, self.tr('Notice'), |
78 |
self.tr('Please select inside of the symbol.')) |
79 |
|
80 |
QGraphicsView.mousePressEvent(self.imageViewer, event)
|
81 |
elif 'mouseMoveEvent' == param[0]: |
82 |
if self.isOnImage(newScenePos.x(), newScenePos.y()): |
83 |
self.connectionPointLineEdit.setText("{},{}".format(newScenePos.x(), newScenePos.y())) |
84 |
else:
|
85 |
self.connectionPointLineEdit.setText("") |
86 |
pass
|
87 |
self.isTreated = False |
88 |
|
89 |
'''
|
90 |
@history 2018.06.11 Jeongwoo Shorten method to add Ellipse
|
91 |
2018.06.12 Jeongwoo Modify RectF's coords
|
92 |
humkyung 2018.08.28 add connector item instead of QGraphicsEllipse
|
93 |
'''
|
94 |
|
95 |
@staticmethod
|
96 |
def drawCircle(imageViewer, x, y, index=-1): |
97 |
from EngineeringConnectorItem import QEngineeringConnectorItem |
98 |
|
99 |
connector = QEngineeringConnectorItem(index=index) |
100 |
connector.setPos((float(x), float(y))) |
101 |
imageViewer.scene().addItem(connector) |
102 |
|
103 |
return connector
|
104 |
|
105 |
'''
|
106 |
@history 2018.06.11 Jeongwoo Make area bigger (width/height 1px)
|
107 |
2018.06.12 Jeongwoo Make area smaller (width/height 1px)
|
108 |
'''
|
109 |
|
110 |
def isOnImage(self, x, y): |
111 |
if (x >= 0 and x <= self.imageWidth) and (y >= 0 and y <= self.imageHeight): |
112 |
return True |
113 |
else:
|
114 |
return False |
115 |
|
116 |
def undo(self): |
117 |
pass
|
118 |
|
119 |
def redo(self): |
120 |
pass
|