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