hytos / DTI_PID / DTI_PID / Shapes / EngineeringEquipmentItem.py @ 472a7ca7
이력 | 보기 | 이력해설 | 다운로드 (6.57 KB)
1 |
# coding: utf-8
|
---|---|
2 |
""" This is engineering equipment item module """
|
3 |
|
4 |
import sys |
5 |
import os |
6 |
import math |
7 |
from PyQt5.QtGui import * |
8 |
from PyQt5.QtCore import * |
9 |
from PyQt5.QtSvg import * |
10 |
from PyQt5.QtWidgets import (QApplication, QGraphicsItem) |
11 |
|
12 |
from SymbolSvgItem import SymbolSvgItem |
13 |
from EngineeringAbstractItem import QEngineeringAbstractItem |
14 |
#from UserInputAttribute import UserInputAttribute
|
15 |
|
16 |
|
17 |
class QEngineeringEquipmentItem(SymbolSvgItem): |
18 |
""" This is engineering equipment item class """
|
19 |
|
20 |
clicked = pyqtSignal(QGraphicsSvgItem) |
21 |
ZVALUE = 10
|
22 |
EQUIP_COLUMN_LIST = None
|
23 |
EQUIP_COLOR = None
|
24 |
|
25 |
def __init__(self, path, uid=None, flip=0): |
26 |
from SymbolAttr import SymbolProp |
27 |
|
28 |
SymbolSvgItem.__init__(self, None, path, uid, flip=flip) |
29 |
self.setZValue(QEngineeringEquipmentItem.ZVALUE)
|
30 |
|
31 |
self._properties = \
|
32 |
{ \ |
33 |
#SymbolProp(None, 'Desc', 'String', Expression="self.desc"): None
|
34 |
#SymbolProp(None, 'Name Tag', 'Tag No', Expression='self.EvaluatedName'): None
|
35 |
} |
36 |
|
37 |
'''
|
38 |
if QEngineeringEquipmentItem.EQUIP_COLUMN_LIST is None:
|
39 |
from AppDocData import AppDocData
|
40 |
|
41 |
appDocData = AppDocData.instance()
|
42 |
QEngineeringEquipmentItem.EQUIP_COLUMN_LIST = appDocData.getColNames('EQUIPMENT_DATA_LIST')
|
43 |
'''
|
44 |
|
45 |
def texts(self): |
46 |
""" return text type of labels """
|
47 |
from AppDocData import AppDocData |
48 |
from EngineeringTextItem import QEngineeringTextItem |
49 |
|
50 |
configs = AppDocData.instance().getConfigs('Symbol', 'EQ Setting') |
51 |
if configs and int(configs[0].value) != 1: |
52 |
return super().texts() |
53 |
else:
|
54 |
return sorted([x for x in self.associations() if issubclass(type(x), QEngineeringTextItem)], |
55 |
key=lambda attr: attr.loc[1]) |
56 |
|
57 |
@property
|
58 |
def tag_no(self): |
59 |
""" getter of tag_no """
|
60 |
from QEngineeringTagNoTextItem import QEngineeringTagNoTextItem |
61 |
|
62 |
matches = [assoc for assoc in self.associations() if type(assoc) is QEngineeringTagNoTextItem] |
63 |
return matches[0].text() if matches else None |
64 |
|
65 |
@property
|
66 |
def desc(self): |
67 |
""" getter of desc """
|
68 |
from CodeTables import CodeTable |
69 |
|
70 |
try:
|
71 |
if self.tag_no: |
72 |
matches = [value for value in CodeTable.instance('EqpTagNames').values if value[1] == self.tag_no] |
73 |
if matches: return matches[0][2] |
74 |
except Exception as ex: |
75 |
from App import App |
76 |
from AppDocData import MessageType |
77 |
|
78 |
message = 'error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, |
79 |
sys.exc_info()[-1].tb_lineno)
|
80 |
App.mainWnd().addMessage.emit(MessageType.Error, message) |
81 |
|
82 |
return '' |
83 |
|
84 |
'''
|
85 |
@brief connect attribute
|
86 |
@author humkyung
|
87 |
@date 2018.05.03
|
88 |
'''
|
89 |
|
90 |
def connectAttribute(self, attributes, clear=True): |
91 |
from QEngineeringTagNoTextItem import QEngineeringTagNoTextItem |
92 |
|
93 |
if clear:
|
94 |
self.clear_attr_and_assoc_item()
|
95 |
|
96 |
# tag no text item will find owner itself
|
97 |
'''
|
98 |
try:
|
99 |
rect = self.sceneBoundingRect()
|
100 |
attrs = [attr for attr in attributes if type(attr) is QEngineeringTagNoTextItem]
|
101 |
for attr in attrs:
|
102 |
if rect.contains(attr.center()):
|
103 |
self.add_assoc_item(attr)
|
104 |
attr.onwer = self
|
105 |
|
106 |
# not have equipment name which is located inside equipment
|
107 |
if not 'Tag No' in self._associations or not self._associations['Tag No']:
|
108 |
minDist = None
|
109 |
selected = None
|
110 |
# get nearest text from equipment
|
111 |
for attr in attrs:
|
112 |
dx = attr.center().x() - rect.center().x()
|
113 |
dy = attr.center().y() - rect.center().y()
|
114 |
dist = math.sqrt(dx*dx + dy*dy)
|
115 |
if (minDist is None) or (dist < minDist):
|
116 |
minDist = dist
|
117 |
selected = attr
|
118 |
|
119 |
if selected is not None:
|
120 |
self.add_assoc_item(selected)
|
121 |
selected.onwer = self
|
122 |
except Exception as ex:
|
123 |
from App import App
|
124 |
from AppDocData import MessageType
|
125 |
|
126 |
message = 'error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno)
|
127 |
App.mainWnd().addMessage.emit(MessageType.Error, message)
|
128 |
'''
|
129 |
|
130 |
'''
|
131 |
def highlight(self, flag):
|
132 |
""" highlight/unhighlight the equpment """
|
133 |
|
134 |
try:
|
135 |
self.hover = flag
|
136 |
self.update()
|
137 |
|
138 |
for assoc in self.associations():
|
139 |
assoc.highlight(flag)
|
140 |
|
141 |
for connector in self.connectors:
|
142 |
connector.highlight(flag)
|
143 |
except Exception as ex:
|
144 |
from App import App
|
145 |
from AppDocData import MessageType
|
146 |
|
147 |
message = 'error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename,
|
148 |
sys.exc_info()[-1].tb_lineno)
|
149 |
App.mainWnd().addMessage.emit(MessageType.Error, message)
|
150 |
'''
|
151 |
|
152 |
@property
|
153 |
def NameText(self): |
154 |
#from EngineeringTextItem import QEngineeringTextItem
|
155 |
from QEngineeringTagNoTextItem import QEngineeringTagNoTextItem |
156 |
|
157 |
if self.associations(): |
158 |
matches = [assoc for assoc in self.associations() if type(assoc) is QEngineeringTagNoTextItem] |
159 |
if matches:
|
160 |
return matches[0].text() |
161 |
else:
|
162 |
matches = [prop for prop, _ in self._properties.items() if prop.Attribute == 'Name'] |
163 |
if matches: return self._properties[matches[0]] |
164 |
|
165 |
return None |
166 |
|
167 |
@property
|
168 |
def EvaluatedName(self): |
169 |
return self.NameText |
170 |
|
171 |
'''
|
172 |
@brief generate xml code for equipment
|
173 |
@author humkyung
|
174 |
@date 2018.05.09
|
175 |
'''
|
176 |
def toXml(self): |
177 |
from xml.etree.ElementTree import Element, SubElement, dump, ElementTree |
178 |
|
179 |
try:
|
180 |
node = SymbolSvgItem.toXml(self)
|
181 |
except Exception as ex: |
182 |
from App import App |
183 |
from AppDocData import MessageType |
184 |
|
185 |
message = 'error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, |
186 |
sys.exc_info()[-1].tb_lineno)
|
187 |
App.mainWnd().addMessage.emit(MessageType.Error, message) |
188 |
|
189 |
return None |
190 |
|
191 |
return node
|