|
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 QConnectorItem import QConnectorItem
|
|
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 |
sorted(self.attrs, key=lambda attr: attr.loc[1]) # sort by y coordinate
|
|
113 |
|
|
114 |
docData = AppDocData.instance()
|
|
115 |
try:
|
|
116 |
self.measuredVariableCode = ''
|
|
117 |
configs = docData.getConfigs('Instrument Tag No Rule', 'Measured Variable Code')
|
|
118 |
self.measuredVariableCode = eval(configs[0].value) if configs else ''
|
|
119 |
except Exception as ex:
|
|
120 |
print('error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno))
|
|
121 |
|
|
122 |
try:
|
|
123 |
self.typeModifier = ''
|
|
124 |
configs = docData.getConfigs('Instrument Tag No Rule', 'Type Modifier')
|
|
125 |
self.typeModifier = eval(configs[0].value) if configs else ''
|
|
126 |
except Exception as ex:
|
|
127 |
print('error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno))
|
|
128 |
|
|
129 |
try:
|
|
130 |
self.tagSeqNo = ''
|
|
131 |
configs = docData.getConfigs('Instrument Tag No Rule', 'Tag Seq No')
|
|
132 |
self.tagSeqNo = eval(configs[0].value) if configs else ''
|
|
133 |
except Exception as ex:
|
|
134 |
print('error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno))
|
|
135 |
|
|
136 |
try:
|
|
137 |
self.tagSuffix = ''
|
|
138 |
configs = docData.getConfigs('Instrument Tag No Rule', 'Tag Suffix')
|
|
139 |
self.tagSuffix = eval(configs[0].value) if configs else ''
|
|
140 |
except Exception as ex:
|
|
141 |
print('error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno))
|
|
142 |
|
|
143 |
'''
|
|
144 |
@brief generate xml code for attribute
|
|
145 |
@author humkyung
|
|
146 |
@date 2018.05.06
|
|
147 |
'''
|
|
148 |
def toXmlAsAttribute(self, owner):
|
|
149 |
from xml.etree.ElementTree import Element, SubElement, dump, ElementTree
|
|
150 |
|
|
151 |
try:
|
|
152 |
attrNode = Element('ATTRIBUTE')
|
|
153 |
|
|
154 |
uidNode = Element('UID')
|
|
155 |
uidNode.text = str(owner.uid)
|
|
156 |
attrNode.append(uidNode)
|
|
157 |
|
|
158 |
nameNode = Element('NAME')
|
|
159 |
nameNode.text = 'Measured Variable Code'
|
|
160 |
attrNode.append(nameNode)
|
|
161 |
|
|
162 |
valueNode = Element('VALUE')
|
|
163 |
valueNode.text = self.measuredVariableCode
|
|
164 |
attrNode.append(valueNode)
|
|
165 |
|
|
166 |
owner.append(attrNode)
|
|
167 |
except Exception as ex:
|
|
168 |
print('error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno))
|
|
169 |
|
|
170 |
try:
|
|
171 |
attrNode = Element('ATTRIBUTE')
|
|
172 |
|
|
173 |
uidNode = Element('UID')
|
|
174 |
uidNode.text = str(owner.uid)
|
|
175 |
attrNode.append(uidNode)
|
|
176 |
|
|
177 |
nameNode = Element('NAME')
|
|
178 |
nameNode.text = 'Type Modifier'
|
|
179 |
attrNode.append(nameNode)
|
|
180 |
|
|
181 |
valueNode = Element('VALUE')
|
|
182 |
valueNode.text = self.typeModifier
|
|
183 |
attrNode.append(valueNode)
|
|
184 |
|
|
185 |
owner.append(attrNode)
|
|
186 |
except Exception as ex:
|
|
187 |
print('error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno))
|
|
188 |
|
|
189 |
try:
|
|
190 |
attrNode = Element('ATTRIBUTE')
|
|
191 |
|
|
192 |
uidNode = Element('UID')
|
|
193 |
uidNode.text = str(owner.uid)
|
|
194 |
attrNode.append(uidNode)
|
|
195 |
|
|
196 |
nameNode = Element('NAME')
|
|
197 |
nameNode.text = 'Tag Seq No'
|
|
198 |
attrNode.append(nameNode)
|
|
199 |
|
|
200 |
valueNode = Element('VALUE')
|
|
201 |
valueNode.text = self.tagSeqNo
|
|
202 |
attrNode.append(valueNode)
|
|
203 |
|
|
204 |
owner.append(attrNode)
|
|
205 |
except Exception as ex:
|
|
206 |
print('error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno))
|
|
207 |
|
|
208 |
try:
|
|
209 |
attrNode = Element('ATTRIBUTE')
|
|
210 |
|
|
211 |
uidNode = Element('UID')
|
|
212 |
uidNode.text = str(owner.uid)
|
|
213 |
attrNode.append(uidNode)
|
|
214 |
|
|
215 |
nameNode = Element('NAME')
|
|
216 |
nameNode.text = 'Tag Suffix'
|
|
217 |
attrNode.append(nameNode)
|
|
218 |
|
|
219 |
valueNode = Element('VALUE')
|
|
220 |
valueNode.text = self.tagSuffix
|
|
221 |
attrNode.append(valueNode)
|
|
222 |
|
|
223 |
owner.append(attrNode)
|
|
224 |
except Exception as ex:
|
|
225 |
print('error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno))
|