hytos / DTI_PID / DTI_PID / Shapes / EngineeringInstrumentItem.py @ 85a460a6
이력 | 보기 | 이력해설 | 다운로드 (10.1 KB)
1 |
# coding: utf-8
|
---|---|
2 |
"""
|
3 |
This is Engineering Instrument Item module
|
4 |
"""
|
5 |
|
6 |
import sys |
7 |
import os |
8 |
import math |
9 |
from PyQt5.QtGui import * |
10 |
from PyQt5.QtCore import * |
11 |
from PyQt5.QtSvg import * |
12 |
from PyQt5.QtWidgets import (QApplication, QGraphicsItem) |
13 |
|
14 |
from SymbolSvgItem import SymbolSvgItem |
15 |
from EngineeringConnectorItem import QEngineeringConnectorItem |
16 |
from EngineeringTextItem import QEngineeringTextItem |
17 |
from UserInputAttribute import UserInputAttribute |
18 |
|
19 |
class QEngineeringInstrumentItem(SymbolSvgItem): |
20 |
"""
|
21 |
This is Engineering Instrument Item class
|
22 |
"""
|
23 |
clicked = pyqtSignal(QGraphicsSvgItem) |
24 |
#removed = pyqtSignal(QGraphicsItem)
|
25 |
INST_COLUMN_LIST = None #['UID', 'ITEM_NO', 'SERVICE', 'FLOW_RATE', 'PRESSURE', 'TEMPERATURE', 'TPYE', 'RANGE', 'NOR_LEVEL_MM', 'NOR_LEVEL_PERCENT', 'DEL_PRESS', 'SHUT_OFF', 'LOCATION', 'PNID_NO', 'REV'] |
26 |
|
27 |
'''
|
28 |
'''
|
29 |
def __init__(self, path, uid=None): |
30 |
SymbolSvgItem.__init__(self, path, uid)
|
31 |
|
32 |
self._measuredVairableCode = None |
33 |
self._typeModifier = None |
34 |
self._tagSeqNo = None |
35 |
self._tagSuffix = None |
36 |
|
37 |
if QEngineeringInstrumentItem.INST_COLUMN_LIST is None: |
38 |
from AppDocData import AppDocData |
39 |
|
40 |
appDocData = AppDocData.instance() |
41 |
QEngineeringInstrumentItem.INST_COLUMN_LIST = appDocData.getColNames('INSTRUMENT_DATA_LIST')
|
42 |
|
43 |
'''
|
44 |
@brief getter of measured variable code
|
45 |
@author humkyung
|
46 |
@date 2018.05.06
|
47 |
'''
|
48 |
@property
|
49 |
def measuredVariableCode(self): |
50 |
return self._measuredVairableCode |
51 |
|
52 |
'''
|
53 |
@brief setter of measured variable code
|
54 |
@author humkyung
|
55 |
@date 2018.05.06
|
56 |
'''
|
57 |
@measuredVariableCode.setter
|
58 |
def measuredVariableCode(self, value): |
59 |
self._measuredVairableCode = value
|
60 |
|
61 |
'''
|
62 |
@brief getter of type modifier
|
63 |
@author humkyung
|
64 |
@date 2018.05.06
|
65 |
'''
|
66 |
@property
|
67 |
def typeModifier(self): |
68 |
return self._typeModifier |
69 |
|
70 |
'''
|
71 |
@brief setter of type modifier
|
72 |
@author humkyung
|
73 |
@date 2018.05.06
|
74 |
'''
|
75 |
@typeModifier.setter
|
76 |
def typeModifier(self, value): |
77 |
self._typeModifier = value
|
78 |
|
79 |
'''
|
80 |
@brief getter of tag seq no
|
81 |
@author humkyung
|
82 |
@date 2018.05.06
|
83 |
'''
|
84 |
@property
|
85 |
def tagSeqNo(self): |
86 |
return self._tagSeqNo |
87 |
|
88 |
'''
|
89 |
@brief setter of tag seq no
|
90 |
@author humkyung
|
91 |
@date 2018.05.06
|
92 |
'''
|
93 |
@tagSeqNo.setter
|
94 |
def tagSeqNo(self, value): |
95 |
self._tagSeqNo = value
|
96 |
|
97 |
'''
|
98 |
@brief getter of tag suffix
|
99 |
@author humkyung
|
100 |
@date 2018.05.06
|
101 |
'''
|
102 |
@property
|
103 |
def tagSuffix(self): |
104 |
return self._tagSuffix |
105 |
|
106 |
'''
|
107 |
@brief setter of tag suffix
|
108 |
@author humkyung
|
109 |
@date 2018.05.06
|
110 |
'''
|
111 |
@tagSuffix.setter
|
112 |
def tagSuffix(self, value): |
113 |
self._tagSuffix = value
|
114 |
|
115 |
'''
|
116 |
@brief connect attribute
|
117 |
@author humkyung
|
118 |
@date 2018.05.06
|
119 |
'''
|
120 |
def connectAttribute(self, attributes): |
121 |
self._texts.clear()
|
122 |
self._symbols.clear()
|
123 |
|
124 |
try:
|
125 |
rect = self.sceneBoundingRect()
|
126 |
for attr in attributes: |
127 |
if rect.contains(attr.center()):
|
128 |
if issubclass(type(attr), QEngineeringTextItem): |
129 |
attr.owner = self # set owner of text |
130 |
self._texts.append(attr)
|
131 |
elif issubclass(type(attr), SymbolSvgItem): |
132 |
attr._owner = self.uid # set owner of symbol |
133 |
self._symbols.append(attr)
|
134 |
|
135 |
self._texts = sorted(self._texts, key=lambda attr: attr.loc[1]) # sort by y coordinate |
136 |
except Exception as ex: |
137 |
from App import App |
138 |
from AppDocData import MessageType |
139 |
|
140 |
message = 'error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno) |
141 |
App.mainWnd().addMessage.emit(MessageType.Error, message) |
142 |
|
143 |
'''
|
144 |
@brief get attributes
|
145 |
@author humkyung
|
146 |
@date 2018.06.14
|
147 |
'''
|
148 |
def getAttributes(self): |
149 |
_attrs = {} |
150 |
try:
|
151 |
from AppDocData import AppDocData |
152 |
from EngineeringTextItem import QEngineeringTextItem |
153 |
|
154 |
# 해당 Type의 attribute setting
|
155 |
docData = AppDocData.instance() |
156 |
symbolAttrs = docData.getSymbolAttribute(self.type)
|
157 |
for attr in symbolAttrs: |
158 |
if attr.AttributeType == 'Text Item': |
159 |
at = int(attr.AttrAt)
|
160 |
if len(self._texts) > at: |
161 |
item = self._texts[at]
|
162 |
_attrs[attr] = eval(attr.Expression) if attr.Expression else '' |
163 |
else:
|
164 |
_attrs[attr] = ''
|
165 |
elif attr.AttributeType == 'Symbol Item': |
166 |
at = int(attr.AttrAt)
|
167 |
if len(self._symbols) > at: |
168 |
item = self._symbols[at]
|
169 |
_attrs[attr] = eval(attr.Expression) if attr.Expression else '' |
170 |
else:
|
171 |
_attrs[attr] = ''
|
172 |
else:
|
173 |
_attrs[attr] = ''#self.attrs[attr[1]] if attr[1] in self.attrs.keys() else '' |
174 |
except Exception as ex: |
175 |
from App import App |
176 |
from AppDocData import MessageType |
177 |
|
178 |
message = 'error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno) |
179 |
App.mainWnd().addMessage.emit(MessageType.Error, message) |
180 |
|
181 |
return _attrs
|
182 |
|
183 |
'''
|
184 |
@brief generate xml code for attribute
|
185 |
@author humkyung
|
186 |
@date 2018.05.06
|
187 |
'''
|
188 |
def toXmlAsAttribute(self, parentNode): |
189 |
from xml.etree.ElementTree import Element, SubElement, dump, ElementTree |
190 |
|
191 |
try:
|
192 |
attrNode = Element('ATTRIBUTE')
|
193 |
|
194 |
uidNode = Element('UID')
|
195 |
uidNode.text = str(self.uid) |
196 |
attrNode.append(uidNode) |
197 |
|
198 |
nameNode = Element('NAME')
|
199 |
nameNode.text = 'Measured Variable Code'
|
200 |
attrNode.append(nameNode) |
201 |
|
202 |
valueNode = Element('VALUE')
|
203 |
valueNode.text = self.measuredVariableCode
|
204 |
attrNode.append(valueNode) |
205 |
|
206 |
parentNode.append(attrNode) |
207 |
except Exception as ex: |
208 |
print('error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno)) |
209 |
|
210 |
try:
|
211 |
attrNode = Element('ATTRIBUTE')
|
212 |
|
213 |
uidNode = Element('UID')
|
214 |
uidNode.text = str(self.uid) |
215 |
attrNode.append(uidNode) |
216 |
|
217 |
nameNode = Element('NAME')
|
218 |
nameNode.text = 'Type Modifier'
|
219 |
attrNode.append(nameNode) |
220 |
|
221 |
valueNode = Element('VALUE')
|
222 |
valueNode.text = self.typeModifier
|
223 |
attrNode.append(valueNode) |
224 |
|
225 |
parentNode.append(attrNode) |
226 |
except Exception as ex: |
227 |
print('error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno)) |
228 |
|
229 |
try:
|
230 |
attrNode = Element('ATTRIBUTE')
|
231 |
|
232 |
uidNode = Element('UID')
|
233 |
uidNode.text = str(self.uid) |
234 |
attrNode.append(uidNode) |
235 |
|
236 |
nameNode = Element('NAME')
|
237 |
nameNode.text = 'Tag Seq No'
|
238 |
attrNode.append(nameNode) |
239 |
|
240 |
valueNode = Element('VALUE')
|
241 |
valueNode.text = self.tagSeqNo
|
242 |
attrNode.append(valueNode) |
243 |
|
244 |
parentNode.append(attrNode) |
245 |
except Exception as ex: |
246 |
print('error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno)) |
247 |
|
248 |
try:
|
249 |
attrNode = Element('ATTRIBUTE')
|
250 |
|
251 |
uidNode = Element('UID')
|
252 |
uidNode.text = str(self.uid) |
253 |
attrNode.append(uidNode) |
254 |
|
255 |
nameNode = Element('NAME')
|
256 |
nameNode.text = 'Tag Suffix'
|
257 |
attrNode.append(nameNode) |
258 |
|
259 |
valueNode = Element('VALUE')
|
260 |
valueNode.text = self.tagSuffix
|
261 |
attrNode.append(valueNode) |
262 |
|
263 |
parentNode.append(attrNode) |
264 |
except Exception as ex: |
265 |
print('error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno)) |
266 |
|
267 |
def toSql(self): |
268 |
"""
|
269 |
convert instrument data to sql query
|
270 |
"""
|
271 |
from AppDocData import AppDocData |
272 |
|
273 |
appDocData = AppDocData.instance() |
274 |
|
275 |
cols = ['UID', 'PNID_NO'] |
276 |
values = ['?','?'] |
277 |
param = [str(self.uid), appDocData.activeDrawing.name] |
278 |
_attrs = self.getAttributes()
|
279 |
for key in _attrs.keys(): |
280 |
cols.append(key.Attribute) |
281 |
values.append('?')
|
282 |
param.append(_attrs[key]) |
283 |
|
284 |
sql = 'insert or replace into INSTRUMENT_DATA_LIST({}) values({})'.format(','.join(cols), ','.join(values)) |
285 |
return (sql, tuple(param)) |
286 |
|
287 |
'''
|
288 |
@brief return inst Data List
|
289 |
@author kyouho
|
290 |
@date 2018.08.14
|
291 |
'''
|
292 |
def getInstrumentDataList(self): |
293 |
dataList = [] |
294 |
try:
|
295 |
from AppDocData import AppDocData |
296 |
|
297 |
docData = AppDocData.instance() |
298 |
attrs = self.getAttributes()
|
299 |
|
300 |
for index in range(len(QEngineeringInstrumentItem.INST_COLUMN_LIST)): |
301 |
dataList.append('')
|
302 |
|
303 |
dataList[0] = str(self.uid) |
304 |
dataList[13] = docData.imgName
|
305 |
|
306 |
for key in attrs.keys(): |
307 |
attrInfo = docData.getSymbolAttributeByUID(key.UID) |
308 |
attrName = attrInfo.Attribute |
309 |
if attrName in QEngineeringInstrumentItem.INST_COLUMN_LIST: |
310 |
colIndex = QEngineeringInstrumentItem.INST_COLUMN_LIST.index(attrName) |
311 |
dataList[colIndex] = attrs[key] |
312 |
except Exception as ex: |
313 |
from App import App |
314 |
from AppDocData import MessageType |
315 |
|
316 |
message = 'error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno) |
317 |
App.mainWnd().addMessage.emit(MessageType.Error, message) |
318 |
|
319 |
return dataList
|