hytos / DTI_PID / DTI_PID / Commands / SelectAttributeCommand.py @ ba3513c9
이력 | 보기 | 이력해설 | 다운로드 (7.45 KB)
1 |
# coding: utf-8
|
---|---|
2 |
""" This is select attribute command module """
|
3 |
|
4 |
import os.path |
5 |
import sys |
6 |
import AbstractCommand |
7 |
|
8 |
try:
|
9 |
from PyQt5.QtCore import Qt, QRectF, pyqtSignal, QT_VERSION_STR, QEvent |
10 |
from PyQt5.QtGui import QImage, QPixmap, QPainterPath, QCursor, QMouseEvent, QTransform |
11 |
from PyQt5.QtWidgets import QGraphicsView, QGraphicsScene, QFileDialog, QTableWidgetItem |
12 |
except ImportError: |
13 |
try:
|
14 |
from PyQt4.QtCore import Qt, QRectF, pyqtSignal, QT_VERSION_STR, QEvent |
15 |
from PyQt4.QtGui import QGraphicsView, QGraphicsScene, QImge, QPixmap, QPainterPath, QFileDialog, QCursor, QMouseEvent |
16 |
except ImportError: |
17 |
raise ImportError("ImageViewerQt: Requires PyQt5 or PyQt4.") |
18 |
|
19 |
'''
|
20 |
@brief QtImageViewer Select Attribute Command
|
21 |
@author kyouho
|
22 |
@date 18.04.10
|
23 |
'''
|
24 |
class SelectAttributeCommand(AbstractCommand.AbstractCommand): |
25 |
onSuccess = pyqtSignal() |
26 |
|
27 |
def __init__(self, item, attr, imageViewer): |
28 |
super(SelectAttributeCommand, self).__init__(imageViewer) |
29 |
self.name = 'SelectAttribute' |
30 |
self.imageViewer.setCursor(QCursor(Qt.ArrowCursor))
|
31 |
self._item = item
|
32 |
self._attr = attr
|
33 |
|
34 |
'''
|
35 |
@brief Select Attribuew
|
36 |
@author kyouho
|
37 |
@date 18.07.19
|
38 |
@history euising 2019.01.15 add specbreak
|
39 |
@history add Valve Oper Item 2019.04.15 by humkyung
|
40 |
'''
|
41 |
def execute(self, param): |
42 |
from SymbolAttr import SymbolAttr |
43 |
from SymbolAttr import SymbolProp |
44 |
|
45 |
event = param[1]
|
46 |
scenePos = param[2]
|
47 |
|
48 |
try:
|
49 |
if 'mouseReleaseEvent' == param[0] and event.button() == Qt.LeftButton: |
50 |
from EngineeringAbstractItem import QEngineeringAbstractItem |
51 |
from SymbolSvgItem import SymbolSvgItem |
52 |
from EngineeringTextItem import QEngineeringTextItem |
53 |
from EngineeringLineNoTextItem import QEngineeringLineNoTextItem |
54 |
from EngineeringRunItem import QEngineeringRunItem |
55 |
from QEngineeringTagNoTextItem import QEngineeringTagNoTextItem |
56 |
from EngineeringLineItem import QEngineeringLineItem |
57 |
from EngineeringSpecBreakItem import QEngineeringSpecBreakItem |
58 |
from EngineeringValveOperCodeTextItem import QEngineeringValveOperCodeTextItem |
59 |
from EngineeringConnectorItem import QEngineeringConnectorItem |
60 |
from EngineeringEndBreakItem import QEngineeringEndBreakItem |
61 |
|
62 |
if self._attr is not None and type(self._attr) is SymbolAttr: |
63 |
item = self.imageViewer.scene.itemAt(scenePos, QTransform())
|
64 |
if item is not None and self._attr.AttributeType == 'Line Item' and issubclass(type(item), QEngineeringLineItem): |
65 |
self._item.conns.clear()
|
66 |
self._item.conns.append(item)
|
67 |
self.onSuccess.emit()
|
68 |
elif item is not None and self._attr.AttributeType == 'CONN' and (issubclass(type(item), QEngineeringLineItem) or issubclass(type(item), SymbolSvgItem)): |
69 |
self._item.connectors[self._attr.AttrAt - 1].connect(item, QEngineeringAbstractItem.CONNECTED_AT_BODY) |
70 |
self.onSuccess.emit()
|
71 |
elif item is not None and self._attr.AttributeType == 'CONN' and (type(item) is QEngineeringConnectorItem): |
72 |
self._item.connectors[self._attr.AttrAt - 1].connect(item.parent, QEngineeringAbstractItem.CONNECTED_AT_PT) |
73 |
self.onSuccess.emit()
|
74 |
elif item is not None and issubclass(type(self._item), QEngineeringSpecBreakItem) and self._attr.AttributeType == 'Comp Item': |
75 |
self._item.attrs[self._attr] = str(item.uid) |
76 |
self.onSuccess.emit()
|
77 |
elif item is not None and (type(self._item) is not QEngineeringEndBreakItem) and (type(item) is QEngineeringLineNoTextItem) and self._attr.AttributeType == 'OWNER': |
78 |
if not item.runs: |
79 |
item.runs.append(QEngineeringRunItem()) |
80 |
|
81 |
if 1 == len(item.runs): item.runs[0].items.append(self._item) |
82 |
|
83 |
self._item.owner = item
|
84 |
self.onSuccess.emit()
|
85 |
elif item is not None and (type(self._item) is QEngineeringEndBreakItem) and (type(item) is QEngineeringLineItem) and self._attr.AttributeType == 'OWNER': |
86 |
self._item.owner = item
|
87 |
self.onSuccess.emit()
|
88 |
elif item is not None and (type(self._item) is QEngineeringEndBreakItem) and (type(item) is QEngineeringLineItem) and self._attr.Attribute == 'Connected Line': |
89 |
self._item.attrs[self._attr] = str(item.uid) |
90 |
self.onSuccess.emit()
|
91 |
elif item is not None and self._attr.AttributeType == QEngineeringAbstractItem.assoc_type(item): |
92 |
if self._attr.AttributeType not in self._item._associations: |
93 |
self._item._associations[self._attr.AttributeType] = [] |
94 |
|
95 |
while len(self._item._associations[self._attr.AttributeType]) <= self._attr.AttrAt: |
96 |
self._item._associations[self._attr.AttributeType].append(None) |
97 |
self._item.add_assoc_item(item, self._attr.AttrAt) |
98 |
|
99 |
self.onSuccess.emit()
|
100 |
elif self._attr is not None and type(self._attr) is SymbolProp: |
101 |
item = self.imageViewer.scene.itemAt(scenePos, QTransform())
|
102 |
if item is not None and self._attr.match_type(item): |
103 |
self._item._properties[self._attr] = item |
104 |
self.onSuccess.emit()
|
105 |
except Exception as ex: |
106 |
from App import App |
107 |
from AppDocData import MessageType |
108 |
|
109 |
message = 'error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno) |
110 |
App.mainWnd().addMessage.emit(MessageType.Error, message) |
111 |
|
112 |
self.isTreated = True |
113 |
|
114 |
def undo(self): |
115 |
pass
|
116 |
|
117 |
def redo(self): |
118 |
pass
|
119 |
|
120 |
'''
|
121 |
@brief Find TextItem contain Point
|
122 |
@author kyouho
|
123 |
@date 18.07.19
|
124 |
'''
|
125 |
def findTextItemInPoint(self, point): |
126 |
from EngineeringTextItem import QEngineeringTextItem |
127 |
|
128 |
for item in self.imageViewer.items(): |
129 |
if type(item) is QEngineeringTextItem: |
130 |
if self.isOverlapItemAndPoint(item, point): |
131 |
return (True, item) |
132 |
|
133 |
return (False,) |
134 |
|
135 |
'''
|
136 |
@brief Find Symbol Item contain Point
|
137 |
@author kyouho
|
138 |
@date 18.07.19
|
139 |
'''
|
140 |
def findSymbolItemInPoint(self, point): |
141 |
from SymbolSvgItem import SymbolSvgItem |
142 |
|
143 |
for item in self.imageViewer.items(): |
144 |
if issubclass(type(item), SymbolSvgItem): |
145 |
if self.isOverlapItemAndPoint(item, point): |
146 |
return (True, item) |
147 |
|
148 |
return (False,) |
149 |
|
150 |
'''
|
151 |
@brief Check Overlap
|
152 |
@author kyouho
|
153 |
@date 18.07.17
|
154 |
'''
|
155 |
def isOverlapItemAndPoint(self, item, point): |
156 |
x = point.x() |
157 |
y = point.y() |
158 |
loc = item.loc |
159 |
size = item.size |
160 |
|
161 |
if loc[0] <= x and loc[0] + size[0] >= x and loc[1] <= y and loc[1] + size[1] >= y: |
162 |
return True |
163 |
else:
|
164 |
return False |