hytos / DTI_PID / DTI_PID / Shapes / QEngineeringInstrumentItem.py @ ba0bca12
이력 | 보기 | 이력해설 | 다운로드 (6.86 KB)
1 |
# coding: utf-8
|
---|---|
2 |
|
3 |
import sys |
4 |
import os |
5 |
import math |
6 |
from PyQt5.QtGui import * |
7 |
from PyQt5.QtCore import * |
8 |
from PyQt5.QtSvg import * |
9 |
from PyQt5.QtWidgets import (QApplication, QGraphicsItem) |
10 |
|
11 |
from SymbolSvgItem import SymbolSvgItem |
12 |
from QEngineeringConnectorItem import QEngineeringConnectorItem |
13 |
|
14 |
class QEngineeringInstrumentItem(SymbolSvgItem): |
15 |
clicked = pyqtSignal(QGraphicsSvgItem) |
16 |
removed = pyqtSignal(QGraphicsItem) |
17 |
|
18 |
'''
|
19 |
'''
|
20 |
def __init__(self, path): |
21 |
import uuid |
22 |
|
23 |
SymbolSvgItem.__init__(self, path)
|
24 |
|
25 |
'''
|
26 |
@brief getter of measured variable code
|
27 |
@author humkyung
|
28 |
@date 2018.05.06
|
29 |
'''
|
30 |
@property
|
31 |
def measuredVariableCode(self): |
32 |
return self._measuredVairableCode |
33 |
|
34 |
'''
|
35 |
@brief setter of measured variable code
|
36 |
@author humkyung
|
37 |
@date 2018.05.06
|
38 |
'''
|
39 |
@measuredVariableCode.setter
|
40 |
def measuredVariableCode(self, value): |
41 |
self._measuredVairableCode = value
|
42 |
|
43 |
'''
|
44 |
@brief getter of type modifier
|
45 |
@author humkyung
|
46 |
@date 2018.05.06
|
47 |
'''
|
48 |
@property
|
49 |
def typeModifier(self): |
50 |
return self._typeModifier |
51 |
|
52 |
'''
|
53 |
@brief setter of type modifier
|
54 |
@author humkyung
|
55 |
@date 2018.05.06
|
56 |
'''
|
57 |
@typeModifier.setter
|
58 |
def typeModifier(self, value): |
59 |
self._typeModifier = value
|
60 |
|
61 |
'''
|
62 |
@brief getter of tag seq no
|
63 |
@author humkyung
|
64 |
@date 2018.05.06
|
65 |
'''
|
66 |
@property
|
67 |
def tagSeqNo(self): |
68 |
return self._tagSeqNo |
69 |
|
70 |
'''
|
71 |
@brief setter of tag seq no
|
72 |
@author humkyung
|
73 |
@date 2018.05.06
|
74 |
'''
|
75 |
@tagSeqNo.setter
|
76 |
def tagSeqNo(self, value): |
77 |
self._tagSeqNo = value
|
78 |
|
79 |
'''
|
80 |
@brief getter of tag suffix
|
81 |
@author humkyung
|
82 |
@date 2018.05.06
|
83 |
'''
|
84 |
@property
|
85 |
def tagSuffix(self): |
86 |
return self._tagSuffix |
87 |
|
88 |
'''
|
89 |
@brief setter of tag suffix
|
90 |
@author humkyung
|
91 |
@date 2018.05.06
|
92 |
'''
|
93 |
@tagSuffix.setter
|
94 |
def tagSuffix(self, value): |
95 |
self._tagSuffix = value
|
96 |
|
97 |
'''
|
98 |
@brief connect attribute
|
99 |
@author humkyung
|
100 |
@date 2018.05.06
|
101 |
'''
|
102 |
def connectAttribute(self, attributes): |
103 |
from AppDocData import AppDocData |
104 |
|
105 |
self.attrs.clear()
|
106 |
|
107 |
rect = self.sceneBoundingRect()
|
108 |
for attr in attributes: |
109 |
if rect.contains(attr.center()):
|
110 |
self.attrs.append(attr)
|
111 |
|
112 |
self.attrs = sorted(self.attrs, key=lambda attr: attr.loc[1]) # sort by y coordinate |
113 |
attrs = [attr.text() for attr in self.attrs] # will be used in eval function's parameter |
114 |
|
115 |
docData = AppDocData.instance() |
116 |
try:
|
117 |
self.measuredVariableCode = '' |
118 |
configs = docData.getConfigs('Instrument Tag No Rule', 'Measured Variable Code') |
119 |
self.measuredVariableCode = eval(configs[0].value) if configs else '' |
120 |
except Exception as ex: |
121 |
print('error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno)) |
122 |
|
123 |
try:
|
124 |
self.typeModifier = '' |
125 |
configs = docData.getConfigs('Instrument Tag No Rule', 'Type Modifier') |
126 |
self.typeModifier = eval(configs[0].value) if configs else '' |
127 |
except Exception as ex: |
128 |
print('error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno)) |
129 |
|
130 |
try:
|
131 |
self.tagSeqNo = '' |
132 |
configs = docData.getConfigs('Instrument Tag No Rule', 'Tag Seq No') |
133 |
self.tagSeqNo = eval(configs[0].value) if configs else '' |
134 |
except Exception as ex: |
135 |
print('error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno)) |
136 |
|
137 |
try:
|
138 |
self.tagSuffix = '' |
139 |
configs = docData.getConfigs('Instrument Tag No Rule', 'Tag Suffix') |
140 |
self.tagSuffix = eval(configs[0].value) if configs else '' |
141 |
except Exception as ex: |
142 |
print('error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno)) |
143 |
|
144 |
'''
|
145 |
@brief generate xml code for attribute
|
146 |
@author humkyung
|
147 |
@date 2018.05.06
|
148 |
'''
|
149 |
def toXmlAsAttribute(self, parentNode): |
150 |
from xml.etree.ElementTree import Element, SubElement, dump, ElementTree |
151 |
|
152 |
try:
|
153 |
attrNode = Element('ATTRIBUTE')
|
154 |
|
155 |
uidNode = Element('UID')
|
156 |
uidNode.text = str(self.uid) |
157 |
attrNode.append(uidNode) |
158 |
|
159 |
nameNode = Element('NAME')
|
160 |
nameNode.text = 'Measured Variable Code'
|
161 |
attrNode.append(nameNode) |
162 |
|
163 |
valueNode = Element('VALUE')
|
164 |
valueNode.text = self.measuredVariableCode
|
165 |
attrNode.append(valueNode) |
166 |
|
167 |
parentNode.append(attrNode) |
168 |
except Exception as ex: |
169 |
print('error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno)) |
170 |
|
171 |
try:
|
172 |
attrNode = Element('ATTRIBUTE')
|
173 |
|
174 |
uidNode = Element('UID')
|
175 |
uidNode.text = str(self.uid) |
176 |
attrNode.append(uidNode) |
177 |
|
178 |
nameNode = Element('NAME')
|
179 |
nameNode.text = 'Type Modifier'
|
180 |
attrNode.append(nameNode) |
181 |
|
182 |
valueNode = Element('VALUE')
|
183 |
valueNode.text = self.typeModifier
|
184 |
attrNode.append(valueNode) |
185 |
|
186 |
parentNode.append(attrNode) |
187 |
except Exception as ex: |
188 |
print('error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno)) |
189 |
|
190 |
try:
|
191 |
attrNode = Element('ATTRIBUTE')
|
192 |
|
193 |
uidNode = Element('UID')
|
194 |
uidNode.text = str(self.uid) |
195 |
attrNode.append(uidNode) |
196 |
|
197 |
nameNode = Element('NAME')
|
198 |
nameNode.text = 'Tag Seq No'
|
199 |
attrNode.append(nameNode) |
200 |
|
201 |
valueNode = Element('VALUE')
|
202 |
valueNode.text = self.tagSeqNo
|
203 |
attrNode.append(valueNode) |
204 |
|
205 |
parentNode.append(attrNode) |
206 |
except Exception as ex: |
207 |
print('error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno)) |
208 |
|
209 |
try:
|
210 |
attrNode = Element('ATTRIBUTE')
|
211 |
|
212 |
uidNode = Element('UID')
|
213 |
uidNode.text = str(self.uid) |
214 |
attrNode.append(uidNode) |
215 |
|
216 |
nameNode = Element('NAME')
|
217 |
nameNode.text = 'Tag Suffix'
|
218 |
attrNode.append(nameNode) |
219 |
|
220 |
valueNode = Element('VALUE')
|
221 |
valueNode.text = self.tagSuffix
|
222 |
attrNode.append(valueNode) |
223 |
|
224 |
parentNode.append(attrNode) |
225 |
except Exception as ex: |
226 |
print('error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno)) |