hytos / DTI_PID / DTI_PID / Shapes / EngineeringInstrumentItem.py @ ef4495fd
이력 | 보기 | 이력해설 | 다운로드 (10.3 KB)
1 | 90739b5c | humkyung | # coding: utf-8
|
---|---|---|---|
2 | 9100a182 | humkyung | """
|
3 | This is Engineering Instrument Item module
|
||
4 | """
|
||
5 | 90739b5c | humkyung | |
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 | 57ab567c | humkyung | from EngineeringConnectorItem import QEngineeringConnectorItem |
16 | eb71581d | gaqhf | from EngineeringTextItem import QEngineeringTextItem |
17 | 357646b0 | gaqhf | from UserInputAttribute import UserInputAttribute |
18 | 90739b5c | humkyung | |
19 | class QEngineeringInstrumentItem(SymbolSvgItem): |
||
20 | 9100a182 | humkyung | """
|
21 | This is Engineering Instrument Item class
|
||
22 | """
|
||
23 | 90739b5c | humkyung | clicked = pyqtSignal(QGraphicsSvgItem) |
24 | 820ed509 | humkyung | INST_COLUMN_LIST = None
|
25 | 90739b5c | humkyung | |
26 | '''
|
||
27 | '''
|
||
28 | cf1f887b | humkyung | def __init__(self, path, uid=None): |
29 | SymbolSvgItem.__init__(self, path, uid)
|
||
30 | 90739b5c | humkyung | |
31 | 1430097d | humkyung | self._measuredVairableCode = None |
32 | self._typeModifier = None |
||
33 | self._tagSeqNo = None |
||
34 | self._tagSuffix = None |
||
35 | |||
36 | d77477f8 | humkyung | 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 | 4b4d954c | humkyung | def texts(self): |
43 | """
|
||
44 | return text type of labels
|
||
45 | """
|
||
46 | from EngineeringTextItem import QEngineeringTextItem |
||
47 | |||
48 | 820ed509 | humkyung | return sorted([x for x in self.associations() if issubclass(type(x), QEngineeringTextItem)], key=lambda attr: attr.loc[1]) |
49 | 4b4d954c | humkyung | |
50 | 90739b5c | humkyung | '''
|
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 | 820ed509 | humkyung | self._associations.clear()
|
129 | 90739b5c | humkyung | |
130 | be3e0c2d | humkyung | try:
|
131 | rect = self.sceneBoundingRect()
|
||
132 | for attr in attributes: |
||
133 | if rect.contains(attr.center()):
|
||
134 | if issubclass(type(attr), QEngineeringTextItem): |
||
135 | 85a460a6 | humkyung | attr.owner = self # set owner of text |
136 | 820ed509 | humkyung | self.add_assoc_item(attr)
|
137 | be3e0c2d | humkyung | elif issubclass(type(attr), SymbolSvgItem): |
138 | 85a460a6 | humkyung | attr._owner = self.uid # set owner of symbol |
139 | 820ed509 | humkyung | self.add_assoc_item(attr)
|
140 | be3e0c2d | humkyung | 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 | 90739b5c | humkyung | |
147 | 18f21a9a | humkyung | '''
|
148 | @brief get attributes
|
||
149 | @author humkyung
|
||
150 | @date 2018.06.14
|
||
151 | '''
|
||
152 | def getAttributes(self): |
||
153 | 9100a182 | humkyung | _attrs = {} |
154 | 18f21a9a | humkyung | try:
|
155 | 95bd7003 | gaqhf | 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 | 4b4d954c | humkyung | _texts = self.texts()
|
162 | _symbols = self.symbols()
|
||
163 | 95bd7003 | gaqhf | for attr in symbolAttrs: |
164 | 9100a182 | humkyung | if attr.AttributeType == 'Text Item': |
165 | at = int(attr.AttrAt)
|
||
166 | 4b4d954c | humkyung | if len(_texts) > at: |
167 | item = _texts[at] |
||
168 | 9100a182 | humkyung | _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 | 4b4d954c | humkyung | if len(_symbols) > at: |
174 | item = _symbols[at] |
||
175 | 9100a182 | humkyung | _attrs[attr] = eval(attr.Expression) if attr.Expression else '' |
176 | else:
|
||
177 | _attrs[attr] = ''
|
||
178 | else:
|
||
179 | ef4495fd | humkyung | 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 | 18f21a9a | humkyung | except Exception as ex: |
185 | b8d39c65 | humkyung | 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 | 18f21a9a | humkyung | |
191 | 9100a182 | humkyung | return _attrs
|
192 | 90739b5c | humkyung | |
193 | '''
|
||
194 | @brief generate xml code for attribute
|
||
195 | @author humkyung
|
||
196 | @date 2018.05.06
|
||
197 | '''
|
||
198 | 5fbc4298 | humkyung | def toXmlAsAttribute(self, parentNode): |
199 | 90739b5c | humkyung | from xml.etree.ElementTree import Element, SubElement, dump, ElementTree |
200 | |||
201 | try:
|
||
202 | attrNode = Element('ATTRIBUTE')
|
||
203 | |||
204 | uidNode = Element('UID')
|
||
205 | 5fbc4298 | humkyung | uidNode.text = str(self.uid) |
206 | 90739b5c | humkyung | 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 | 5fbc4298 | humkyung | parentNode.append(attrNode) |
217 | 90739b5c | humkyung | 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 | 5fbc4298 | humkyung | uidNode.text = str(self.uid) |
225 | 90739b5c | humkyung | 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 | 5fbc4298 | humkyung | parentNode.append(attrNode) |
236 | 90739b5c | humkyung | 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 | 5fbc4298 | humkyung | uidNode.text = str(self.uid) |
244 | 90739b5c | humkyung | 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 | 5fbc4298 | humkyung | parentNode.append(attrNode) |
255 | 90739b5c | humkyung | 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 | 5fbc4298 | humkyung | uidNode.text = str(self.uid) |
263 | 90739b5c | humkyung | 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 | 5fbc4298 | humkyung | parentNode.append(attrNode) |
274 | 90739b5c | humkyung | except Exception as ex: |
275 | d1576bff | 김정우 | print('error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno)) |
276 | 8804d0d9 | gaqhf | |
277 | 1df9adbf | humkyung | def toSql(self): |
278 | """
|
||
279 | convert instrument data to sql query
|
||
280 | """
|
||
281 | from AppDocData import AppDocData |
||
282 | |||
283 | 51a72882 | esham21 | appDocData = AppDocData.instance() |
284 | 1df9adbf | humkyung | |
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 | d1a02244 | gaqhf | '''
|
298 | @brief return inst Data List
|
||
299 | 8804d0d9 | gaqhf | @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 | 06e5d695 | esham21 | attrs = self.getAttributes()
|
309 | 8804d0d9 | gaqhf | |
310 | d77477f8 | humkyung | for index in range(len(QEngineeringInstrumentItem.INST_COLUMN_LIST)): |
311 | 8804d0d9 | gaqhf | dataList.append('')
|
312 | |||
313 | d1a02244 | gaqhf | dataList[0] = str(self.uid) |
314 | 8804d0d9 | gaqhf | dataList[13] = docData.imgName
|
315 | |||
316 | d77477f8 | humkyung | 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 | 8804d0d9 | gaqhf | except Exception as ex: |
323 | d77477f8 | humkyung | from App import App |
324 | from AppDocData import MessageType |
||
325 | 8804d0d9 | gaqhf | |
326 | d77477f8 | humkyung | 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 | d1a02244 | gaqhf | |
329 | d77477f8 | humkyung | return dataList |