개정판 4b4d954c
issue #622:
- late bind for symbol and text item while loading
DTI_PID/DTI_PID/MainWindow.py | ||
---|---|---|
1906 | 1906 |
# 처음에는 UID가 connectedItem에 String으로 들어가있기 때문에 |
1907 | 1907 |
connector.connectedItem = self.graphicsView.findItemByUid(connector.connectedItem) |
1908 | 1908 |
|
1909 |
""" |
|
1909 | 1910 |
symbols = [item for item in self.graphicsView.scene.items() if issubclass(type(item), SymbolSvgItem) and len(item.attrs) > 0] |
1910 | 1911 |
for symbol in symbols: |
1911 | 1912 |
# 처음에는 attrs의 uid가 connectedItem에 String으로 들어가있기 때문에 |
1912 | 1913 |
for index in range(len(symbol.attrs)): |
1913 | 1914 |
if type(symbol.attrs[index]) is not UserInputAttribute and type(symbol.attrs[index]) is not tuple: |
1914 | 1915 |
symbol.attrs[index] = self.graphicsView.findItemByUid(symbol.attrs[index]) |
1916 |
""" |
|
1915 | 1917 |
|
1916 | 1918 |
# Update Scene |
1917 | 1919 |
self.graphicsView.scene.update(self.graphicsView.sceneRect()) |
... | ... | |
2029 | 2031 |
removeAttrList.append(attr) |
2030 | 2032 |
continue |
2031 | 2033 |
|
2032 |
attrInfo = docData.getSymbolAttributeByUID(attr.attribute)
|
|
2034 |
attrInfo = docData.getSymbolAttributeByUID(attr.UID)
|
|
2033 | 2035 |
if attrInfo is None: |
2034 | 2036 |
removeAttrList.append(attr) |
2035 | 2037 |
# 해당 attribute가 맞는지 확인 |
2036 | 2038 |
else: |
2037 |
attrType = attrInfo[2] |
|
2038 | 2039 |
_type = type(attr) |
2039 |
if attrType == 'Symbol Item': |
|
2040 |
if attrInfo.AttributeType == 'Symbol Item':
|
|
2040 | 2041 |
if not issubclass(_type, SymbolSvgItem): |
2041 | 2042 |
removeAttrList.append(attr) |
2042 |
elif attrType == 'Text Item': |
|
2043 |
elif attrInfo.AttributeType == 'Text Item':
|
|
2043 | 2044 |
if _type is not QEngineeringTextItem: |
2044 | 2045 |
removeAttrList.append(attr) |
2045 |
elif attrType == 'Int': |
|
2046 |
elif attrInfo.AttributeType == 'Int':
|
|
2046 | 2047 |
if _type is not UserInputAttribute and self.isNumber(attr.text): |
2047 | 2048 |
removeAttrList.append(attr) |
2048 |
elif attrType == 'String': |
|
2049 |
elif attrInfo.AttributeType == 'String':
|
|
2049 | 2050 |
if _type is not UserInputAttribute: |
2050 | 2051 |
removeAttrList.append(attr) |
2051 | 2052 |
|
2052 | 2053 |
for attr in removeAttrList: |
2053 |
attrs.remove(attr)
|
|
2054 |
del attrs[attr]
|
|
2054 | 2055 |
|
2055 | 2056 |
# Line No Text Item의 경우 |
2056 | 2057 |
items = [item for item in self.graphicsView.scene.items() if issubclass(type(item), QEngineeringLineNoTextItem)] |
... | ... | |
2060 | 2061 |
removeAttrList = [] |
2061 | 2062 |
for attr in attrs: |
2062 | 2063 |
if type(attr) is UserInputAttribute: |
2063 |
attrInfo = docData.getLinePropertiesByUID(attr.attribute)
|
|
2064 |
attrInfo = docData.getLinePropertiesByUID(attr.UID)
|
|
2064 | 2065 |
if attrInfo is None: |
2065 | 2066 |
removeAttrList.append(attr) |
2066 | 2067 |
|
2067 | 2068 |
for attr in removeAttrList: |
2068 |
attrs.remove(attr)
|
|
2069 |
del attrs[attr]
|
|
2069 | 2070 |
|
2070 | 2071 |
except Exception as ex: |
2071 |
message = 'error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno) |
|
2072 |
self.addMessage.emit(MessageType.Error, message) |
|
2072 |
message = 'error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno) |
|
2073 |
self.addMessage.emit(MessageType.Error, message) |
|
2074 |
|
|
2073 | 2075 |
''' |
2074 | 2076 |
@brief Check Number |
2075 | 2077 |
@author kyouho |
DTI_PID/DTI_PID/Shapes/EngineeringInstrumentItem.py | ||
---|---|---|
40 | 40 |
appDocData = AppDocData.instance() |
41 | 41 |
QEngineeringInstrumentItem.INST_COLUMN_LIST = appDocData.getColNames('INSTRUMENT_DATA_LIST') |
42 | 42 |
|
43 |
def texts(self): |
|
44 |
""" |
|
45 |
return text type of labels |
|
46 |
""" |
|
47 |
from EngineeringTextItem import QEngineeringTextItem |
|
48 |
|
|
49 |
if self.labels(): |
|
50 |
return sorted([x for x in self.labels() if issubclass(type(x), QEngineeringTextItem)], key=lambda attr: attr.loc[1]) |
|
51 |
|
|
52 |
return [] |
|
53 |
|
|
43 | 54 |
''' |
44 | 55 |
@brief getter of measured variable code |
45 | 56 |
@author humkyung |
... | ... | |
127 | 138 |
if rect.contains(attr.center()): |
128 | 139 |
if issubclass(type(attr), QEngineeringTextItem): |
129 | 140 |
attr.owner = self # set owner of text |
130 |
self._texts.append(attr)
|
|
141 |
self._labels.append(attr)
|
|
131 | 142 |
elif issubclass(type(attr), SymbolSvgItem): |
132 | 143 |
attr._owner = self.uid # set owner of symbol |
133 |
self._symbols.append(attr)
|
|
144 |
self._labels.append(attr)
|
|
134 | 145 |
|
135 |
self._texts = sorted(self._texts, key=lambda attr: attr.loc[1]) # sort by y coordinate |
|
146 |
#self._texts = sorted(self._texts, key=lambda attr: attr.loc[1]) # sort by y coordinate
|
|
136 | 147 |
except Exception as ex: |
137 | 148 |
from App import App |
138 | 149 |
from AppDocData import MessageType |
... | ... | |
154 | 165 |
# 해당 Type의 attribute setting |
155 | 166 |
docData = AppDocData.instance() |
156 | 167 |
symbolAttrs = docData.getSymbolAttribute(self.type) |
168 |
_texts = self.texts() |
|
169 |
_symbols = self.symbols() |
|
157 | 170 |
for attr in symbolAttrs: |
158 | 171 |
if attr.AttributeType == 'Text Item': |
159 | 172 |
at = int(attr.AttrAt) |
160 |
if len(self._texts) > at:
|
|
161 |
item = self._texts[at]
|
|
173 |
if len(_texts) > at: |
|
174 |
item = _texts[at] |
|
162 | 175 |
_attrs[attr] = eval(attr.Expression) if attr.Expression else '' |
163 | 176 |
else: |
164 | 177 |
_attrs[attr] = '' |
165 | 178 |
elif attr.AttributeType == 'Symbol Item': |
166 | 179 |
at = int(attr.AttrAt) |
167 |
if len(self._symbols) > at:
|
|
168 |
item = self._symbols[at]
|
|
180 |
if len(_symbols) > at: |
|
181 |
item = _symbols[at] |
|
169 | 182 |
_attrs[attr] = eval(attr.Expression) if attr.Expression else '' |
170 | 183 |
else: |
171 | 184 |
_attrs[attr] = '' |
DTI_PID/DTI_PID/Shapes/EngineeringTextItem.py | ||
---|---|---|
60 | 60 |
|
61 | 61 |
# find owner with uid |
62 | 62 |
if self._owner is not None and type(self._owner) is uuid.UUID: |
63 |
matches = [x for x in self.scene.items() if hasattr(x, 'uid') and x.uid == self._owner] |
|
64 |
return matches[0] |
|
63 |
matches = [x for x in self.scene().items() if hasattr(x, 'uid') and x.uid == self._owner]
|
|
64 |
return matches[0] if matches else None
|
|
65 | 65 |
# up to here |
66 | 66 |
|
67 | 67 |
return self._owner |
DTI_PID/DTI_PID/Shapes/SymbolSvgItem.py | ||
---|---|---|
50 | 50 |
# attributeType uid |
51 | 51 |
self.attribute = '' |
52 | 52 |
|
53 |
self._labels = [] |
|
53 | 54 |
self._texts = [] # contains text items |
54 | 55 |
self._symbols = [] # contains symbol items |
55 | 56 |
|
... | ... | |
101 | 102 |
self._color = self.DEFAULT_COLOR |
102 | 103 |
self.setColor(self._color) |
103 | 104 |
|
105 |
def labels(self): |
|
106 |
""" |
|
107 |
return label instance |
|
108 |
""" |
|
109 |
import uuid |
|
110 |
|
|
111 |
res = [] |
|
112 |
for label in self._labels: |
|
113 |
# find owner with uid |
|
114 |
if label and type(label) is uuid.UUID: |
|
115 |
matches = [x for x in self.scene().items() if hasattr(x, 'uid') and x.uid == label] |
|
116 |
if matches: res.append(matches[0]) |
|
117 |
# up to here |
|
118 |
elif label: |
|
119 |
res.append(label) |
|
120 |
|
|
121 |
return res |
|
122 |
|
|
123 |
def texts(self): |
|
124 |
""" |
|
125 |
return text type of labels |
|
126 |
""" |
|
127 |
from EngineeringTextItem import QEngineeringTextItem |
|
128 |
|
|
129 |
return [x for x in self.labels() if issubclass(type(x), QEngineeringTextItem)] |
|
130 |
|
|
131 |
def symbols(self): |
|
132 |
""" |
|
133 |
return symbol type of labels |
|
134 |
""" |
|
135 |
return [x for x in self.labels() if issubclass(type(x), SymbolSvgItem)] |
|
136 |
|
|
104 | 137 |
def toSql(self): |
105 | 138 |
""" |
106 | 139 |
convert valve data to sql query |
... | ... | |
508 | 541 |
from QEngineeringSizeTextItem import QEngineeringSizeTextItem |
509 | 542 |
|
510 | 543 |
self.attrs.clear() |
544 |
self._labels.clear() |
|
511 | 545 |
|
512 | 546 |
try: |
513 | 547 |
dist = max(self.sceneBoundingRect().height(), self.sceneBoundingRect().width()) |
... | ... | |
525 | 559 |
selected = attr |
526 | 560 |
|
527 | 561 |
if selected is not None: |
528 |
self._texts.append(selected) |
|
562 |
self._labels.append(selected) |
|
563 |
#self._texts.append(selected) |
|
529 | 564 |
except Exception as ex: |
530 | 565 |
from App import App |
531 | 566 |
message = 'error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno) |
... | ... | |
630 | 665 |
nameNode.text = self.name |
631 | 666 |
node.append(nameNode) |
632 | 667 |
|
633 |
attributeValueNode = Element('ATTRIBUTEVALUE') |
|
634 |
attributeValueNode.text = self.attribute |
|
668 |
attributeValueNode = Element('LABELS') |
|
669 |
for label in self.labels: |
|
670 |
labelNode = Element('LABEL') |
|
671 |
labelNode.text = str(label.uid) |
|
672 |
attributeValueNode.append(labelNode) |
|
635 | 673 |
node.append(attributeValueNode) |
636 | 674 |
|
637 | 675 |
typeNode = Element('TYPE') |
... | ... | |
805 | 843 |
|
806 | 844 |
iterIndex += 1 |
807 | 845 |
|
808 |
attributeValue = node.find('ATTRIBUTEVALUE') |
|
846 |
# get labels |
|
847 |
attributeValue = node.find('LABELS') |
|
809 | 848 |
if attributeValue is not None: |
810 |
item[0].attribute = attributeValue.text |
|
849 |
for label in attributeValue.iter('LABEL'): |
|
850 |
item[0]._labels.append(uuid.UUID(label.text)) |
|
851 |
# up to here |
|
811 | 852 |
|
812 | 853 |
attributes = node.find('SYMBOLATTRIBUTES') |
813 | 854 |
if attributes is not None: |
내보내기 Unified diff