개정판 fb7c4418
issue #000: fix vendor name
Change-Id: Ib13cdcfb638b025bb9162dff18caa809ffad593d
DTI_PID/DTI_PID/Shapes/EngineeringVendorItem.py | ||
---|---|---|
16 | 16 |
|
17 | 17 |
from EngineeringAbstractItem import QEngineeringAbstractItem |
18 | 18 |
from EngineeringConnectorItem import QEngineeringConnectorItem |
19 |
from AppDocData import AppDocData, MessageType |
|
19 | 20 |
|
20 | 21 |
class QEngineeringVendorItem(QGraphicsPolygonItem, QEngineeringAbstractItem): |
21 | 22 |
""" |
... | ... | |
38 | 39 |
self.setColor(self._color) |
39 | 40 |
self._savedColor = None |
40 | 41 |
|
41 |
self._properties = { SymbolProp(None, 'Name', 'String'):None }
|
|
42 |
self._properties = { SymbolProp(None, 'Name', 'Text Item', Expression='self.EvaluatedName'):None }
|
|
42 | 43 |
|
43 | 44 |
self.setFlags(QGraphicsItem.ItemIsSelectable|QGraphicsItem.ItemIsFocusable) |
44 | 45 |
self.setToolTip(str(self.uid)) |
... | ... | |
57 | 58 |
connector.transfer.onPosChanged.connect(self.onConnectorPosChaned) |
58 | 59 |
self.connectors.append(connector) |
59 | 60 |
|
61 |
@property |
|
62 |
def NameText(self): |
|
63 |
from EngineeringTextItem import QEngineeringTextItem |
|
64 |
|
|
65 |
matches = [assoc for assoc in self.associations() if type(assoc) is QEngineeringTextItem] |
|
66 |
if matches: |
|
67 |
return matches[0].text() |
|
68 |
|
|
69 |
return None |
|
70 |
|
|
71 |
@property |
|
72 |
def EvaluatedName(self): |
|
73 |
return self.NameText |
|
74 |
|
|
75 |
|
|
60 | 76 |
def includes(self, item): |
61 | 77 |
rect = item.sceneBoundingRect() |
62 | 78 |
topLeft = QPoint(rect.x(), rect.y()) |
... | ... | |
70 | 86 |
""" |
71 | 87 |
convert vendor package data to sql query |
72 | 88 |
""" |
73 |
from AppDocData import AppDocData |
|
74 | 89 |
res = [] |
75 | 90 |
|
76 | 91 |
appDocData = AppDocData.instance() |
... | ... | |
90 | 105 |
@staticmethod |
91 | 106 |
def fromXml(node): |
92 | 107 |
import uuid |
93 |
from AppDocData import AppDocData |
|
94 | 108 |
|
95 | 109 |
try: |
96 | 110 |
uidNode = node.find('UID') |
... | ... | |
112 | 126 |
if matches: |
113 | 127 |
vendorItem._properties[matches[0]] = matches[0].parse_value(prop_node.text) if prop_node.text else '' |
114 | 128 |
vendorItem.setToolTip(str(vendorItem.uid)) |
129 |
|
|
130 |
attributeValue = node.find('ASSOCIATIONS') |
|
131 |
if attributeValue is not None: |
|
132 |
for assoc in attributeValue.iter('ASSOCIATION'): |
|
133 |
_type = assoc.attrib['TYPE'] |
|
134 |
if not _type in vendorItem._associations: |
|
135 |
vendorItem._associations[_type] = [] |
|
136 |
vendorItem._associations[_type].append(uuid.UUID(assoc.text)) |
|
115 | 137 |
except Exception as ex: |
116 | 138 |
from App import App |
117 | 139 |
from AppDocData import MessageType |
... | ... | |
121 | 143 |
|
122 | 144 |
return vendorItem |
123 | 145 |
|
146 |
def associations(self): |
|
147 |
""" return associated instance """ |
|
148 |
import uuid |
|
149 |
|
|
150 |
res = [] |
|
151 |
for key in self._associations.keys(): |
|
152 |
for assoc in self._associations[key]: |
|
153 |
# find owner with uid |
|
154 |
if assoc and type(assoc) is uuid.UUID: |
|
155 |
matches = [x for x in self.scene().items() if hasattr(x, 'uid') and str(x.uid) == str(assoc)] |
|
156 |
if matches: res.append(matches[0]) # TODO: need to update association with instance |
|
157 |
# up to here |
|
158 |
elif assoc: |
|
159 |
res.append(assoc) |
|
160 |
|
|
161 |
return res |
|
162 |
|
|
124 | 163 |
def toXml(self): |
125 | 164 |
from xml.etree.ElementTree import Element, SubElement, dump, ElementTree |
126 | 165 |
|
... | ... | |
140 | 179 |
pointsNode.text = pointsNode.text + str(point[0]) + ',' + str(point[1]) + QEngineeringVendorItem.DELIMITER |
141 | 180 |
pointsNode.text = pointsNode.text[:-len(QEngineeringVendorItem.DELIMITER)] |
142 | 181 |
node.append(pointsNode) |
182 |
|
|
183 |
attributeValueNode = Element('ASSOCIATIONS') |
|
184 |
for assoc in self.associations(): |
|
185 |
assoc_node = Element('ASSOCIATION') |
|
186 |
assoc_node.attrib['TYPE'] = QEngineeringAbstractItem.assoc_type(assoc) |
|
187 |
assoc_node.text = str(assoc.uid) |
|
188 |
attributeValueNode.append(assoc_node) |
|
189 |
node.append(attributeValueNode) |
|
143 | 190 |
|
144 | 191 |
properties_node = Element('PROPERTIES') |
145 | 192 |
for prop,value in self.properties.items(): |
내보내기 Unified diff