개정판 17cbda7d
issue #503: vendorPackage 설정 기능 개선(추가, 삭제 기능 추가)
Change-Id: I08b01ae0d81bb448e5d53328aef3b1abfb9f216f
DTI_PID/DTI_PID/Commands/PlaceLineCommand.py | ||
---|---|---|
4 | 4 |
""" |
5 | 5 |
|
6 | 6 |
import os.path |
7 |
import sys |
|
7 | 8 |
import AbstractCommand |
9 |
|
|
8 | 10 |
try: |
9 | 11 |
from PyQt5.QtCore import * |
10 | 12 |
from PyQt5.QtGui import * |
... | ... | |
16 | 18 |
except ImportError: |
17 | 19 |
raise ImportError("ImageViewerQt: Requires PyQt5 or PyQt4.") |
18 | 20 |
|
21 |
|
|
19 | 22 |
class PlaceLineCommand(AbstractCommand.AbstractCommand): |
20 |
""" |
|
21 |
This is place line class |
|
22 |
""" |
|
23 |
"""This is place line class""" |
|
23 | 24 |
|
24 | 25 |
onSuccess = pyqtSignal() |
25 | 26 |
onRejected = pyqtSignal(AbstractCommand.AbstractCommand) |
26 | 27 |
|
27 | 28 |
def __init__(self, imageViewer): |
28 | 29 |
super(PlaceLineCommand, self).__init__(imageViewer) |
29 |
self.name = 'PlaceLine'
|
|
30 |
self.name = 'PlaceLine' |
|
30 | 31 |
self.imageViewer.setCursor(QCursor(Qt.CrossCursor)) |
31 | 32 |
|
32 | 33 |
self._polyline = None |
33 |
|
|
34 |
|
|
34 | 35 |
''' |
35 | 36 |
@brief reset command status |
36 | 37 |
@author humkyung |
37 | 38 |
@date 2018.07.23 |
38 | 39 |
''' |
40 |
|
|
39 | 41 |
def reset(self): |
40 | 42 |
self._polyline = None |
41 | 43 |
|
... | ... | |
44 | 46 |
@author humkyung |
45 | 47 |
@date 2018.07.23 |
46 | 48 |
''' |
49 |
|
|
47 | 50 |
def execute(self, param): |
48 | 51 |
import shapely |
49 | 52 |
from EngineeringConnectorItem import QEngineeringConnectorItem |
... | ... | |
54 | 57 |
self.isTreated = False |
55 | 58 |
|
56 | 59 |
event = param[1] |
57 |
if 'mousePressEvent' == param[0] and event.button() == Qt.LeftButton: |
|
58 |
if self._polyline is None: |
|
59 |
selected = [conn for conn in self.imageViewer.scene.items(param[2]) if type(conn) is not QGraphicsTextItem][0] |
|
60 |
if selected is not None and type(selected) is QEngineeringConnectorItem: |
|
61 |
self._polyline = QEngineeringPolylineItem() |
|
62 |
self._polyline._vertices.append(selected.center()) |
|
63 |
self.imageViewer.scene.addItem(self._polyline) |
|
64 |
self.imageViewer.scene.setFocusItem(self._polyline) |
|
65 |
elif selected is not None and type(selected) is QEngineeringLineItem: |
|
66 |
length = selected.length()*0.5 |
|
67 |
dir = selected.perpendicular() |
|
68 |
start = [param[2].x() - dir[0]*length, param[2].y() - dir[1]*length] |
|
69 |
end = [param[2].x() + dir[0]*length, param[2].y() + dir[1]*length] |
|
70 |
pt = selected.intersection([start, end]) |
|
71 |
if (pt is not None) and (type(pt) == shapely.geometry.point.Point): |
|
60 |
try: |
|
61 |
if 'mousePressEvent' == param[0] and event.button() == Qt.LeftButton: |
|
62 |
if self._polyline is None: |
|
63 |
selected = \ |
|
64 |
[conn for conn in self.imageViewer.scene.items(param[2]) if type(conn) is not QGraphicsTextItem][0] |
|
65 |
if selected is not None and type(selected) is QEngineeringConnectorItem: |
|
72 | 66 |
self._polyline = QEngineeringPolylineItem() |
73 |
self._polyline._vertices.append([pt.x, pt.y])
|
|
67 |
self._polyline._vertices.append(selected.center())
|
|
74 | 68 |
self.imageViewer.scene.addItem(self._polyline) |
75 | 69 |
self.imageViewer.scene.setFocusItem(self._polyline) |
76 |
else: |
|
77 |
try: |
|
78 |
QGraphicsView.mouseReleaseEvent(self.imageViewer, event) |
|
79 |
self._polyline._vertices.append(self._polyline._pt) |
|
80 |
self._polyline.update() |
|
81 |
finally: |
|
82 |
pass |
|
83 |
elif 'mouseReleaseEvent' == param[0] and event.button() == Qt.RightButton and self._polyline is not None: |
|
84 |
self.onSuccess.emit() |
|
85 |
elif 'mouseReleaseEvent' == param[0] and event.button() == Qt.RightButton and self._polyline is None: |
|
86 |
self.onRejected.emit(self) |
|
87 |
elif 'mouseMoveEvent' == param[0] and self._polyline is not None: |
|
88 |
self._polyline.onMouseMoved(event, param[2]) |
|
89 |
elif 'keyPressEvent' == param[0]: |
|
90 |
if event.key() == Qt.Key_Escape: |
|
70 |
elif selected is not None and type(selected) is QEngineeringLineItem: |
|
71 |
length = selected.length() * 0.5 |
|
72 |
dir = selected.perpendicular() |
|
73 |
start = [param[2].x() - dir[0] * length, param[2].y() - dir[1] * length] |
|
74 |
end = [param[2].x() + dir[0] * length, param[2].y() + dir[1] * length] |
|
75 |
pt = selected.intersection([start, end]) |
|
76 |
if (pt is not None) and (type(pt) == shapely.geometry.point.Point): |
|
77 |
self._polyline = QEngineeringPolylineItem() |
|
78 |
self._polyline._vertices.append([pt.x, pt.y]) |
|
79 |
self.imageViewer.scene.addItem(self._polyline) |
|
80 |
self.imageViewer.scene.setFocusItem(self._polyline) |
|
81 |
else: |
|
82 |
try: |
|
83 |
QGraphicsView.mouseReleaseEvent(self.imageViewer, event) |
|
84 |
self._polyline._vertices.append(self._polyline._pt) |
|
85 |
self._polyline.update() |
|
86 |
finally: |
|
87 |
pass |
|
88 |
elif 'mouseReleaseEvent' == param[0] and event.button() == Qt.RightButton and self._polyline is not None: |
|
89 |
self.onSuccess.emit() |
|
90 |
elif 'mouseReleaseEvent' == param[0] and event.button() == Qt.RightButton and self._polyline is None: |
|
91 | 91 |
self.onRejected.emit(self) |
92 |
self.isTreated = False |
|
93 |
elif event.key() == Qt.Key_A: # axis lock mode |
|
94 |
self._polyline.drawing_mode = QEngineeringPolylineItem.AXIS_MODE |
|
95 |
elif event.key() == Qt.Key_F: # free drawing mode |
|
96 |
self._polyline.drawing_mode = QEngineeringPolylineItem.FREE_MODE |
|
92 |
elif 'mouseMoveEvent' == param[0] and self._polyline is not None: |
|
93 |
self._polyline.onMouseMoved(event, param[2]) |
|
94 |
elif 'keyPressEvent' == param[0]: |
|
95 |
if event.key() == Qt.Key_Escape: |
|
96 |
self.onRejected.emit(self) |
|
97 |
self.isTreated = False |
|
98 |
elif event.key() == Qt.Key_A: # axis lock mode |
|
99 |
self._polyline.drawing_mode = QEngineeringPolylineItem.AXIS_MODE |
|
100 |
elif event.key() == Qt.Key_F: # free drawing mode |
|
101 |
self._polyline.drawing_mode = QEngineeringPolylineItem.FREE_MODE |
|
102 |
except Exception as ex: |
|
103 |
from App import App |
|
104 |
from AppDocData import MessageType |
|
105 |
|
|
106 |
message = 'error occurred({}) in {}:{}'.format(repr(ex), sys.exc_info()[-1].tb_frame.f_code.co_filename, |
|
107 |
sys.exc_info()[-1].tb_lineno) |
|
108 |
App.mainWnd().addMessage.emit(MessageType.Error, message) |
|
97 | 109 |
|
98 | 110 |
def undo(self): |
99 | 111 |
pass |
100 | 112 |
|
101 | 113 |
def redo(self): |
102 |
pass |
|
114 |
pass |
내보내기 Unified diff