개정판 6de19f63
issue #563: opc attr auto insertion improve
Change-Id: Iee4cef470d1868acd820e8794a44ec9032593df3
DTI_PID/DTI_PID/Shapes/QEngineeringOPCItem.py | ||
---|---|---|
95 | 95 |
if not self.clear_attr_and_assoc_item(): |
96 | 96 |
return |
97 | 97 | |
98 |
app_doc_data = AppDocData.instance() |
|
98 |
#app_doc_data = AppDocData.instance() |
|
99 |
allowed_error = 0.01 |
|
99 | 100 | |
100 | 101 |
''' |
101 | 102 |
matches = [connector.connectedItem for connector in self.connectors if connector is not None and type(connector.connectedItem) is QEngineeringLineItem] |
... | ... | |
114 | 115 |
attr.owner = self |
115 | 116 |
''' |
116 | 117 | |
117 |
attrs = self.getAttributes()
|
|
118 |
attrs = sorted(list(self.getAttributes().keys()), key=lambda param: int(param.AttrAt))
|
|
118 | 119 |
attr_num = len(attrs) |
119 | 120 | |
120 | 121 |
configs = AppDocData.instance().getConfigs('Range', 'Detection Ratio') |
... | ... | |
138 | 139 |
minDists = sorted(minDists, key=lambda minDist: minDist[0]) |
139 | 140 | |
140 | 141 |
minDists.pop(attr_num) |
141 |
for attr in minDists: |
|
142 |
if attr[1]: |
|
143 |
if self.add_assoc_item(attr[1]): |
|
144 |
attr[1].owner = self |
|
142 |
items = [attr for attr in minDists if attr[1]] |
|
143 |
if len(items) != 1 or attr_num == 1: |
|
144 |
for attr in minDists: |
|
145 |
if attr[1]: |
|
146 |
if self.add_assoc_item(attr[1]): |
|
147 |
attr[1].owner = self |
|
148 |
else: |
|
149 |
item = items[0][1] |
|
150 |
if abs(1.57 - self.angle) < allowed_error or abs(4.71 - self.angle) < allowed_error: |
|
151 |
if item.sceneBoundingRect().center().x() < self.sceneBoundingRect().center().x(): |
|
152 |
if self.add_assoc_item(item, 0): |
|
153 |
attrs[0].AssocItem = item |
|
154 |
item.owner = self |
|
155 |
else: |
|
156 |
if self.add_assoc_item(item, 1): |
|
157 |
attrs[1].AssocItem = item |
|
158 |
item.owner = self |
|
159 |
else: |
|
160 |
if item.sceneBoundingRect().center().y() < self.sceneBoundingRect().center().y(): |
|
161 |
if self.add_assoc_item(item, 0): |
|
162 |
attrs[0].AssocItem = item |
|
163 |
item.owner = self |
|
164 |
else: |
|
165 |
if self.add_assoc_item(item, 1): |
|
166 |
attrs[1].AssocItem = item |
|
167 |
item.owner = self |
|
145 | 168 | |
146 | 169 |
#self.associations() # to binding object from scene |
147 | 170 | |
... | ... | |
168 | 191 |
else: |
169 | 192 |
return sorted([x for x in self.associations() if issubclass(type(x), QEngineeringTextItem)], key=lambda attr: attr.loc[1]) # sort by y coordinate |
170 | 193 |
''' |
171 |
if abs(0 - self.angle) < allowed_error or abs(3.14 - self.angle) < allowed_error: |
|
172 |
return sorted([x for x in self.associations() if issubclass(type(x), QEngineeringTextItem)], key=lambda attr: attr.loc[1]) |
|
173 |
elif abs(1.57 - self.angle) < allowed_error or abs(4.71 - self.angle) < allowed_error: |
|
174 |
return sorted([x for x in self.associations() if issubclass(type(x), QEngineeringTextItem)], key=lambda attr: attr.loc[0]) |
|
194 |
''' |
|
195 |
texts = [x for x in self.associations() if issubclass(type(x), QEngineeringTextItem)] |
|
196 |
if len(texts) != 1: |
|
197 |
if abs(1.57 - self.angle) < allowed_error or abs(4.71 - self.angle) < allowed_error: |
|
198 |
return sorted(texts, key=lambda attr: attr.loc[0]) |
|
199 |
else: |
|
200 |
return sorted(texts, key=lambda attr: attr.loc[1]) |
|
201 |
else: |
|
202 |
text = texts[0] |
|
203 |
if abs(1.57 - self.angle) < allowed_error or abs(4.71 - self.angle) < allowed_error: |
|
204 |
if text.sceneBoundingRect().center().x() < self.sceneBoundingRect().center().x(): |
|
205 |
return [text] |
|
206 |
else: |
|
207 |
return [None, text] |
|
208 |
else: |
|
209 |
if text.sceneBoundingRect().center().y() < self.sceneBoundingRect().center().y(): |
|
210 |
return [text] |
|
211 |
else: |
|
212 |
return [None, text] |
|
213 |
''' |
|
214 |
texts = [x for x in self.associations() if issubclass(type(x), QEngineeringTextItem)] |
|
215 |
if abs(1.57 - self.angle) < allowed_error or abs(4.71 - self.angle) < allowed_error: |
|
216 |
return sorted(texts, key=lambda attr: attr.loc[0]) |
|
175 | 217 |
else: |
176 |
return sorted([x for x in self.associations() if issubclass(type(x), QEngineeringTextItem)], key=lambda attr: attr.loc[1])
|
|
218 |
return sorted(texts, key=lambda attr: attr.loc[1])
|
|
177 | 219 | |
178 | 220 |
''' |
179 | 221 |
@brief generate xml code for attribute |
내보내기 Unified diff