hytos / DTI_PID / DTI_PID / LineNoTracer.py @ 9a7fcd80
이력 | 보기 | 이력해설 | 다운로드 (28.2 KB)
1 |
# coding: utf-8
|
---|---|
2 |
""" This is line no tracer module """
|
3 |
|
4 |
import sys |
5 |
import math |
6 |
import shapely |
7 |
from AppDocData import AppDocData, MessageType |
8 |
from EngineeringLineItem import QEngineeringLineItem |
9 |
from EngineeringLineNoTextItem import QEngineeringLineNoTextItem |
10 |
from QEngineeringFlowArrowItem import QEngineeringFlowArrowItem |
11 |
from SymbolSvgItem import SymbolSvgItem |
12 |
from EngineeringTextItem import QEngineeringTextItem |
13 |
from EngineeringUnknownItem import QEngineeringUnknownItem |
14 |
try:
|
15 |
from PyQt5.QtCore import * |
16 |
from PyQt5.QtGui import * |
17 |
from PyQt5.QtWidgets import * |
18 |
except ImportError: |
19 |
try:
|
20 |
from PyQt4.QtCore import * |
21 |
from PyQt4.QtGui import * |
22 |
except ImportError: |
23 |
raise ImportError("ImageViewerQt: Requires PyQt5 or PyQt4.") |
24 |
|
25 |
class LineNoTracer: |
26 |
'''
|
27 |
@history 2018.04.26 Jeongwoo Variable name changed (texts → lineNos)
|
28 |
'''
|
29 |
def __init__(self, symbols, lines, lineNos, specBreak, lineIndicator, vendor): |
30 |
try:
|
31 |
self._symbols = symbols
|
32 |
self._lines = lines
|
33 |
self._lineNos = lineNos
|
34 |
self._spec_breaks = specBreak
|
35 |
self._lineIndicator = lineIndicator
|
36 |
|
37 |
"""
|
38 |
for spec in self._specBreak:
|
39 |
for attr in spec.attrs:
|
40 |
if type(attr) is tuple and attr[1] != '':
|
41 |
self._specBreakUID.append(attr[1])
|
42 |
"""
|
43 |
except Exception as ex: |
44 |
from App import App |
45 |
|
46 |
message = 'error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno) |
47 |
App.mainWnd().addMessage.emit(MessageType.Error, message) |
48 |
|
49 |
'''
|
50 |
@brief find primary lines connected to given line no
|
51 |
@author humkyung
|
52 |
'''
|
53 |
def find_primary_lines(self, lineno): |
54 |
from EngineeringLineItem import QEngineeringLineItem |
55 |
from EngineeringRunItem import QEngineeringRunItem |
56 |
|
57 |
connected_items = [] |
58 |
|
59 |
_from = lineno.prop('From')
|
60 |
_to = lineno.prop('To')
|
61 |
if _from and _to and lineno.empty(): |
62 |
connected_items = self.find_connected_objects(_from, to=_to)
|
63 |
if _from in connected_items and _to in connected_items: |
64 |
start = connected_items.index(_from) |
65 |
end = connected_items.index(_to) |
66 |
if start < end:
|
67 |
connected_items = connected_items[start:end+1]
|
68 |
else:
|
69 |
connected_items = connected_items[end:start+1]
|
70 |
connected_items.reverse() |
71 |
elif (not _from or not _to) and (1 == len(lineno.conns)): |
72 |
connected_items = self.find_connected_objects(lineno.conns[0]) |
73 |
|
74 |
#print(connected_items)
|
75 |
if connected_items:
|
76 |
for item in connected_items: |
77 |
item.owner = lineno # set item's owner
|
78 |
|
79 |
line_run = QEngineeringRunItem() |
80 |
line_run.items = connected_items |
81 |
line_run.arrange_flow_direction() |
82 |
line_run.owner = lineno |
83 |
lineno.runs.append(line_run) |
84 |
|
85 |
lineno.set_property('From', connected_items[0]) |
86 |
lineno.set_property('To', connected_items[-1]) |
87 |
|
88 |
if _to is not None and connected_items and connected_items[-1] is not _to: |
89 |
_to.owner = None
|
90 |
|
91 |
return connected_items
|
92 |
|
93 |
'''
|
94 |
@brief find secondary lines
|
95 |
@author humkyung
|
96 |
'''
|
97 |
def find_secondary_lines(self, lines): |
98 |
from EngineeringAbstractItem import QEngineeringAbstractItem |
99 |
from EngineeringLineItem import QEngineeringLineItem |
100 |
from EngineeringRunItem import QEngineeringRunItem |
101 |
|
102 |
try:
|
103 |
foundCount = 1
|
104 |
while foundCount:
|
105 |
foundCount = 0
|
106 |
notMatches = [] |
107 |
for line in lines: |
108 |
if line.owner is not None: continue |
109 |
|
110 |
line_matches = [x for x in self._lines if x.owner and line.is_connected(x, QEngineeringAbstractItem.CONNECTED_AT_BODY)] |
111 |
symbol_matches = [x for x in self._symbols if x.owner and line.is_connected(x)] |
112 |
if line_matches or symbol_matches: |
113 |
foundCount += 1
|
114 |
connected_items = self.find_connected_objects(line)
|
115 |
|
116 |
owner = line_matches[0].owner if line_matches else symbol_matches[0].owner |
117 |
for item in connected_items: |
118 |
item.owner = owner # set item's owner
|
119 |
|
120 |
line_run = QEngineeringRunItem() |
121 |
line_run.items = connected_items |
122 |
line_run.arrange_flow_direction() |
123 |
if line_run.items is not None and len(line_run.items) > 0: |
124 |
line_run.owner = owner |
125 |
owner.runs.append(line_run) |
126 |
else:
|
127 |
notMatches.append(line) |
128 |
lines = notMatches |
129 |
except Exception as ex: |
130 |
from App import App |
131 |
|
132 |
message = 'error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno) |
133 |
App.mainWnd().addMessage.emit(MessageType.Error, message) |
134 |
|
135 |
'''
|
136 |
@brief trace line no
|
137 |
@author humkyung
|
138 |
@date 2018.04.16
|
139 |
@history 2018.04.26 Jeongwoo docDatalineNos = self.lineNos, Not For loop
|
140 |
humkyung 2018.05.08 add flow arrow
|
141 |
Jeongwoo 2018.05.14 Add [runs] on Primary/Secondary Line - Need to modify Secondary Line
|
142 |
Jeongwoo 2018.05.15 Make Comments [lineno.conns[0].owner = lineno]
|
143 |
Jeongwoo 2018.05.17 Modify find secondary lines with 'while'
|
144 |
Modify find secondary lines with 'while' used sublist for unconnected line
|
145 |
humkyung 2018.05.18 set start line's owner before tracing
|
146 |
'''
|
147 |
def execute(self, displayMessage, updateProgress, toler=50): |
148 |
from EngineeringLineItem import QEngineeringLineItem |
149 |
from SymbolSvgItem import SymbolSvgItem |
150 |
from EngineeringRunItem import QEngineeringRunItem |
151 |
from QEngineeringTrimLineNoTextItem import QEngineeringTrimLineNoTextItem |
152 |
|
153 |
try:
|
154 |
docData = AppDocData.instance() |
155 |
|
156 |
configs = docData.getConfigs('Line No', 'Delimiter') |
157 |
if 1 == len(configs): |
158 |
configs = docData.getConfigs('Line No', 'Configuration') |
159 |
|
160 |
for lineno in self._lineNos: |
161 |
_from = lineno.prop('From')
|
162 |
_to = lineno.prop('To')
|
163 |
#if type(_from) is str or type(_to) is str:
|
164 |
# print(str(lineno.uid))
|
165 |
if _from and _to and (type(_from) is QEngineeringLineItem or issubclass(type(_from), SymbolSvgItem)) and (type(_to) is QEngineeringLineItem or issubclass(type(_to), SymbolSvgItem)): |
166 |
_from.owner = lineno |
167 |
_to.owner = lineno |
168 |
continue
|
169 |
else:
|
170 |
lineno.set_property('From', None) |
171 |
lineno.set_property('To', None) |
172 |
|
173 |
lineno.conns.clear() |
174 |
minDist = None
|
175 |
startLine = None
|
176 |
for line in self._lines: |
177 |
dist = line.distanceTo((lineno.center().x(), lineno.center().y())) |
178 |
if (minDist is None) or (dist < minDist): |
179 |
minDist = dist |
180 |
startLine = line |
181 |
if (startLine is not None) and (minDist < toler): |
182 |
lineno.conns.append(startLine) |
183 |
startLine.owner = lineno |
184 |
|
185 |
"""
|
186 |
## lineIndicator
|
187 |
extendPixel = 30
|
188 |
for lineIndicator in self._lineIndicator:
|
189 |
maxOverLap = 0
|
190 |
matchLineNo = None
|
191 |
liInRect = [round(lineIndicator.boundingRect().x()), round(lineIndicator.boundingRect().y()), round(lineIndicator.boundingRect().x() + lineIndicator.boundingRect().width()), round(lineIndicator.boundingRect().y() + lineIndicator.boundingRect().height())]
|
192 |
for remainLineNo in remainLineNos:
|
193 |
xOverlap = False
|
194 |
yOverlap = False
|
195 |
extendDx = remainLineNo.size[0] if lineIndicator.isVH == 'V' else remainLineNo.size[1]
|
196 |
reNoRect = [round(remainLineNo.loc[0] - extendDx), round(remainLineNo.loc[1] - extendDx), round(remainLineNo.loc[0] + remainLineNo.size[0] + extendDx), round(remainLineNo.loc[1] + remainLineNo.size[1] + extendDx)]
|
197 |
w, h = 0, 0
|
198 |
for x1 in range(reNoRect[0], reNoRect[2] + 1):
|
199 |
for x2 in range(liInRect[0], liInRect[2] + 1):
|
200 |
if x1 - x2 is 0:
|
201 |
xOverlap = True
|
202 |
w += 1
|
203 |
if not xOverlap:
|
204 |
continue
|
205 |
for y1 in range(reNoRect[1], reNoRect[3] + 1):
|
206 |
for y2 in range(liInRect[1], liInRect[3] + 1):
|
207 |
if y1 - y2 is 0:
|
208 |
yOverlap = True
|
209 |
h += 1
|
210 |
|
211 |
if not xOverlap or not yOverlap:
|
212 |
continue
|
213 |
overLapRate = (w / lineIndicator.boundingRect().width() * 100) if lineIndicator.boundingRect().width() > lineIndicator.boundingRect().height() else (h / lineIndicator.boundingRect().height() * 100)
|
214 |
#print(overLapRate)
|
215 |
if maxOverLap < overLapRate:
|
216 |
maxOverLap = overLapRate
|
217 |
matchLineNo = remainLineNo
|
218 |
#lineIndicator.setBrush(QBrush(QColor(255, 0, 0, 127)))
|
219 |
|
220 |
if matchLineNo is not None:
|
221 |
#print(matchLineNo.text() + ' indicator : ' + str(lineIndicator.boundingRect().x()) + ', ' + str(lineIndicator.boundingRect().y()))
|
222 |
matchLine = None
|
223 |
x1, y1, x2, y2 = int(lineIndicator.boundingRect().x() + lineIndicator.otherLine[0]), int(lineIndicator.boundingRect().y() + lineIndicator.otherLine[1]), int(lineIndicator.boundingRect().x() + lineIndicator.otherLine[2]), int(lineIndicator.boundingRect().y() + lineIndicator.otherLine[3])
|
224 |
#print([type(x1), type(y1), type(x2), type(y2)])
|
225 |
startXorY = (min(liInRect[0], liInRect[2]) - extendPixel) if lineIndicator.isVH == 'V' else (min(liInRect[1], liInRect[3]) - extendPixel)
|
226 |
endXorY = (max(liInRect[0], liInRect[2]) + extendPixel) if lineIndicator.isVH == 'V' else (max(liInRect[1], liInRect[3]) + extendPixel)
|
227 |
fXorY = []
|
228 |
for dXOrdY in range(startXorY, endXorY + 1): # if horizontal -> Y, if vertical -> X
|
229 |
if lineIndicator.isVH == 'V':
|
230 |
fXorY.append(round(((y2-y1)/(x2-x1))*dXOrdY + y1 - ((y2-y1)/(x2-x1))*x1)) # f(x)
|
231 |
else:
|
232 |
fXorY.append(round(((x2-x1)/(y2-y1))*dXOrdY + x1 - ((x2-x1)/(y2-y1))*y1)) # f(y)
|
233 |
|
234 |
#print(self._lines)
|
235 |
for line in self._lines:
|
236 |
axis1Overlap = False
|
237 |
axis2Overlap = False
|
238 |
lX1, lY1, lX2, lY2 = int(line.startPoint()[0]), int(line.startPoint()[1]), int(line.endPoint()[0]), int(line.endPoint()[1])
|
239 |
#print([lX1, lY1, lX2, lY2])
|
240 |
|
241 |
if lineIndicator.isVH == 'V':
|
242 |
range11 = range(startXorY, endXorY + 1)
|
243 |
range12 = range(min(lX1, lX2), max(lX1, lX2)+ 1)
|
244 |
range21 = fXorY
|
245 |
range22 = range(min(lY1, lY2), max(lY1, lY2) + 1)
|
246 |
else:
|
247 |
range11 = range(startXorY, endXorY + 1)
|
248 |
range12 = range(min(lY1, lY2), max(lY1, lY2) + 1)
|
249 |
range21 = fXorY
|
250 |
range22 = range(min(lX1, lX2), max(lX1, lX2) + 1)
|
251 |
#print(fXorY)
|
252 |
#print(type(fXorY[0]))
|
253 |
#print([range11[0],range11[-1], range12[0],range12[-1], range21[0],range21[-1], range22[0],range22[-1]])
|
254 |
|
255 |
for axis11 in range11:
|
256 |
for axis12 in range12:
|
257 |
if axis11 - axis12 is 0:
|
258 |
axis1Overlap = True
|
259 |
break
|
260 |
if axis1Overlap: break
|
261 |
if not axis1Overlap:
|
262 |
continue
|
263 |
for axis21 in range21:
|
264 |
for axis22 in range22:
|
265 |
if axis21 - axis22 is 0:
|
266 |
axis2Overlap = True
|
267 |
break
|
268 |
if axis2Overlap: break
|
269 |
|
270 |
if axis1Overlap and axis2Overlap:
|
271 |
matchLine = line
|
272 |
break
|
273 |
if matchLine is not None:
|
274 |
matchLineNo.conns.append(matchLine)
|
275 |
lineIndicator.lineIndicator = 'Match'
|
276 |
lineIndicator.setBrush(QBrush(QColor(0, 0, 255, 127)))
|
277 |
#print('connected ' + matchLineNo.text() + ' and ' + matchLine.uid)
|
278 |
## up to here
|
279 |
"""
|
280 |
|
281 |
maxValue = len(self._lineNos) + 1 ## line no's count + secondary line |
282 |
|
283 |
# find primary lines
|
284 |
# sort line no with from,to value
|
285 |
self._lineNos.sort(key=lambda line_no:(1 if line_no.prop('From') else 0)+(1 if line_no.prop('To') else 0),reverse=True) |
286 |
for lineno in self._lineNos: |
287 |
if displayMessage: displayMessage.emit('{} {}'.format(lineno.text(), 'Topology Construction')) |
288 |
self.find_primary_lines(lineno)
|
289 |
if updateProgress: updateProgress.emit(maxValue)
|
290 |
|
291 |
# find secondary lines
|
292 |
lines = self._lines
|
293 |
self.find_secondary_lines(lines)
|
294 |
if updateProgress: updateProgress.emit(maxValue)
|
295 |
|
296 |
### make trim lines
|
297 |
"""
|
298 |
updateProgress.emit(-1) # reset progressbar
|
299 |
displayMessage.emit('Unknown line Topology Construction')
|
300 |
orphanLines = [line for line in self._lines if line.owner is None]
|
301 |
if orphanLines:
|
302 |
maxValue = len(orphanLines)
|
303 |
orphanLines = sorted(orphanLines, key=lambda param:param.length(), reverse=True)
|
304 |
while len(orphanLines) > 0:
|
305 |
trimLineNo = QEngineeringTrimLineNoTextItem()
|
306 |
trimLineNo.conns.append(orphanLines[0])
|
307 |
orphanLines[0].owner = trimLineNo
|
308 |
orphanLines[0].linkedItem = trimLineNo
|
309 |
|
310 |
connectedItems = self.findPrimaryLines(trimLineNo)
|
311 |
for item in connectedItems:
|
312 |
if item in orphanLines:
|
313 |
orphanLines.remove(item)
|
314 |
updateProgress.emit(maxValue)
|
315 |
|
316 |
self.findSecondaryLines(orphanLines)
|
317 |
for item in orphanLines[:]:
|
318 |
if item.owner is not None:
|
319 |
orphanLines.remove(item)
|
320 |
updateProgress.emit(maxValue)
|
321 |
|
322 |
docData.tracerLineNos.append(trimLineNo)
|
323 |
"""
|
324 |
if updateProgress: updateProgress.emit(maxValue)
|
325 |
except Exception as ex: |
326 |
from App import App |
327 |
|
328 |
message = 'error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno) |
329 |
App.mainWnd().addMessage.emit(MessageType.Error, message) |
330 |
|
331 |
'''
|
332 |
@brief find objects connected to given line while loop
|
333 |
@author humkyung
|
334 |
@date 2018.04.16
|
335 |
@history humkyung 2018.05.08 find symbol or line connected to given object
|
336 |
humkyung 2018.05.10 set found object's owner
|
337 |
humkyung 2018.05.17 try to connect both symbol and line
|
338 |
humkyung 2018.06.22 order connected objects
|
339 |
'''
|
340 |
def find_connected_objects(self, start, to=None): |
341 |
from EngineeringLineItem import QEngineeringLineItem |
342 |
from EngineeringEquipmentItem import QEngineeringEquipmentItem |
343 |
from SymbolSvgItem import SymbolSvgItem |
344 |
|
345 |
visited = [start] |
346 |
|
347 |
try:
|
348 |
pool = [] |
349 |
pool.append((0, start))
|
350 |
|
351 |
while len(pool) > 0: |
352 |
sign, obj = pool.pop() |
353 |
print(type(obj))
|
354 |
|
355 |
""" check obj is upstream or downstream of spec break """
|
356 |
matches = [spec_break for spec_break in self._spec_breaks if spec_break.is_connected(obj)] |
357 |
if matches or issubclass(type(obj), QEngineeringEquipmentItem): continue |
358 |
""" end loop if obj is to """
|
359 |
if to is not None and str(obj.uid) == str(to.uid): break |
360 |
|
361 |
if type(obj) is QEngineeringLineItem: |
362 |
symbolMatches = [x for x in self._symbols if (x.owner is None or x.owner == start.owner) and (x not in visited) and obj.is_connected(x)] |
363 |
lineMatches = [x for x in self._lines if (x.owner is None or x.owner == start.owner) and (x is not obj) and (x not in visited) and obj.is_connected(x)] |
364 |
|
365 |
elif issubclass(type(obj), SymbolSvgItem): |
366 |
lineMatches = [x for x in self._lines if (x.owner is None or x.owner == start.owner) and (x not in visited) and obj.is_connected(x)] |
367 |
|
368 |
if len(lineMatches) > 1: # choose one if connected lines are more than 2 |
369 |
matches = [x for x in [visited[0], visited[-1]] if obj.is_connected(x)] |
370 |
if matches:
|
371 |
next_connected = [x for x in lineMatches if obj.next_connected(x, matches[0])] |
372 |
if next_connected: lineMatches = next_connected
|
373 |
|
374 |
symbolMatches = [x for x in self._symbols if (x.owner is None or x.owner == start.owner) and (x is not obj) and (x not in visited) and obj.is_connected(x, None)] |
375 |
#print(visited)
|
376 |
#for s in self._symbols:
|
377 |
# print(s)
|
378 |
# print(s.owner)
|
379 |
#print(symbolMatches)
|
380 |
|
381 |
# order connected objects
|
382 |
matches = [] |
383 |
matches.extend(symbolMatches) |
384 |
matches.extend(lineMatches) |
385 |
|
386 |
if sign == 0 and len(matches) > 1: |
387 |
mid = int(len(matches)*0.5) |
388 |
lhs = matches[0:mid]
|
389 |
rhs = matches[mid:] |
390 |
elif sign == -1: |
391 |
lhs = matches |
392 |
rhs = [] |
393 |
else:
|
394 |
lhs = [] |
395 |
rhs = matches |
396 |
|
397 |
for match in lhs: |
398 |
pool.append((-1, match))
|
399 |
visited.insert(0, match)
|
400 |
|
401 |
for match in rhs: |
402 |
pool.append((1, match))
|
403 |
visited.append(match) |
404 |
# up to here
|
405 |
|
406 |
except Exception as ex: |
407 |
from App import App |
408 |
|
409 |
message = 'error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno) |
410 |
App.mainWnd().addMessage.emit(MessageType.Error, message) |
411 |
|
412 |
return visited
|
413 |
|
414 |
'''
|
415 |
@brief connect attributes
|
416 |
@author humkyung
|
417 |
@date 2018.06.17
|
418 |
@history humkyung 2018.06.21 paste connect attributes codes from recognizeLine function
|
419 |
kyouho 2018.09.14 clear Item's owner
|
420 |
'''
|
421 |
def connectAttrImpl(worker, update_line_type): |
422 |
import os |
423 |
from App import App |
424 |
from LineNoTracer import LineNoTracer |
425 |
from AppDocData import AppDocData |
426 |
from EngineeringSpecBreakItem import QEngineeringSpecBreakItem |
427 |
from EngineeringInstrumentItem import QEngineeringInstrumentItem |
428 |
from EngineeringReducerItem import QEngineeringReducerItem |
429 |
from EngineeringEquipmentItem import QEngineeringEquipmentItem |
430 |
from QEngineeringOPCItem import QEngineeringOPCItem |
431 |
from EngineeringSpecBreakItem import QEngineeringSpecBreakItem |
432 |
from EngineeringVendorItem import QEngineeringVendorItem |
433 |
from EngineeringEndBreakItem import QEngineeringEndBreakItem |
434 |
from EngineeringReservedWordTextItem import QEngineeringReservedWordTextItem |
435 |
|
436 |
try:
|
437 |
symbols = [] |
438 |
lines = [] |
439 |
lineNos = [] |
440 |
specBreak = [] |
441 |
lineIndicator = [] |
442 |
vendor_packages = [item for item in worker.graphicsView.scene.items() if type(item) is QEngineeringVendorItem] |
443 |
end_breaks = [item for item in worker.graphicsView.scene.items() if type(item) is QEngineeringEndBreakItem] |
444 |
for end_break in end_breaks: |
445 |
worker.graphicsView.scene.removeItem(end_break) |
446 |
|
447 |
configs = AppDocData.instance().getConfigs('Supplied by Tag Rule', 'by Vendor') |
448 |
vendorTag = configs[0].value if configs else 'By Vendor' |
449 |
for item in worker.graphicsView.scene.items(): |
450 |
if type(item) is QEngineeringSpecBreakItem: |
451 |
specBreak.append(item) |
452 |
elif issubclass(type(item), SymbolSvgItem) and not type(item) is QEngineeringUnknownItem: |
453 |
matches = [vendor_package for vendor_package in vendor_packages if vendor_package.includes(item)] |
454 |
if matches:
|
455 |
item.set_property('Supplied By', vendorTag)
|
456 |
else:
|
457 |
item.set_property('Supplied By', '') |
458 |
symbols.append(item) |
459 |
elif type(item) is QEngineeringLineNoTextItem: |
460 |
lineNos.append(item) |
461 |
elif type(item) is QEngineeringLineItem: |
462 |
#matches = [vendor_package for vendor_package in vendor_packages if vendor_package.includes(item)]
|
463 |
#if not matches: lines.append(item)
|
464 |
lines.append(item) |
465 |
elif type(item) is QEngineeringUnknownItem and item.lineIndicator != 'False': |
466 |
lineIndicator.append(item) |
467 |
elif issubclass(type(item), QEngineeringTextItem): |
468 |
item.owner = None
|
469 |
|
470 |
# trace line no
|
471 |
tracer = LineNoTracer(symbols, lines, lineNos, specBreak, lineIndicator, vendor_packages) |
472 |
tracer.execute(worker.displayMessage, worker.updateProgress) |
473 |
# up to here
|
474 |
|
475 |
# connect attribute
|
476 |
texts = [item for item in worker.graphicsView.scene.items() if issubclass(type(item), QEngineeringTextItem)] |
477 |
for symbol in symbols: |
478 |
try:
|
479 |
symbol.connectAttribute(texts) |
480 |
except Exception as ex: |
481 |
from App import App |
482 |
message = 'error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno) |
483 |
App.mainWnd().addMessage.emit(MessageType.Error, message) |
484 |
|
485 |
""" try to connect label to valve """
|
486 |
labels = [symbol for symbol in symbols if type(symbol) is QEngineeringInstrumentItem and not symbol.is_connected] |
487 |
valves = [symbol for symbol in symbols if type(symbol) is not QEngineeringInstrumentItem and type(symbol) is not QEngineeringReducerItem and type(symbol) is not QEngineeringEquipmentItem \ |
488 |
and type(symbol) is not QEngineeringOPCItem and type(symbol) is not QEngineeringSpecBreakItem] |
489 |
for valve in valves: |
490 |
valve.connectAttribute(labels, clear=False)
|
491 |
|
492 |
""" try to find reserved word's owner """
|
493 |
texts = [item for item in worker.graphicsView.scene.items() if type(item) is QEngineeringReservedWordTextItem] |
494 |
for reservedWord in texts: |
495 |
reservedWord.findOwner(lines) |
496 |
|
497 |
""" update line type """
|
498 |
if update_line_type == True: |
499 |
#lines = [line for line in worker.graphicsView.scene.items() if type(line) is QEngineeringLineItem]
|
500 |
#for line in lines: line.lineType = 'Primary'
|
501 |
for line in lines: line.update_line_type() |
502 |
|
503 |
"""make end break"""
|
504 |
docdata = AppDocData.instance() |
505 |
|
506 |
end_break_names = docdata.getSymbolListByType('type', 'End Break') |
507 |
if len(end_break_names) is not 0: |
508 |
|
509 |
svgFileName = end_break_names[0].sName
|
510 |
symbol = AppDocData.instance().getSymbolByQuery('name', svgFileName)
|
511 |
svgFilePath = os.path.join(AppDocData.instance().getCurrentProject().getSvgFilePath(), symbol.getType(), svgFileName+'.svg')
|
512 |
|
513 |
end_breaks = [] |
514 |
lineNo_froms = [] |
515 |
lineNo_tos = [] |
516 |
|
517 |
for lineNo in lineNos: |
518 |
lineNo_froms.append(lineNo.prop('From')) if lineNo.prop('From') is not None else None |
519 |
lineNo_tos.append(lineNo.prop('To')) if lineNo.prop('To') is not None else None |
520 |
#end_breaks.extend(lineNo.end_break())
|
521 |
|
522 |
for line_end in lineNo_froms + lineNo_tos: |
523 |
#print(type(line_end))
|
524 |
for connector in line_end.connectors: |
525 |
if connector.connectedItem is not None and connector.connectedItem.owner is not line_end.owner: |
526 |
end_break = SymbolSvgItem.createItem(symbol.getType(), svgFilePath) |
527 |
pt = [connector.center()[0] - float(symbol.getOriginalPoint().split(',')[0]), connector.center()[1] - float(symbol.getOriginalPoint().split(',')[1])] |
528 |
origin = [0,0] |
529 |
if 2 == len(symbol.getOriginalPoint().split(',')): |
530 |
tokens = symbol.getOriginalPoint().split(',')
|
531 |
origin = [pt[0] + float(tokens[0]), pt[1] + float(tokens[1])] |
532 |
end_break.buildItem(svgFileName, symbol.getType(), 5.7, pt, [end_break.boundingRect().width(), end_break.boundingRect().height()], origin, [], symbol.getBaseSymbol(), symbol.getAdditionalSymbol(), symbol.getHasInstrumentLabel())
|
533 |
|
534 |
end_break.set_property('Connected Item', connector.connectedItem)
|
535 |
end_break.setToolTip('owner : ' + str(line_end)) |
536 |
end_break.area = 'Drawing'
|
537 |
end_break.owner = line_end |
538 |
end_breaks.append(end_break) |
539 |
|
540 |
if end_breaks:
|
541 |
# check dulplication
|
542 |
dupl = set()
|
543 |
for i in range(len(end_breaks)): |
544 |
for j in range(len(end_breaks)): |
545 |
if i == j: continue |
546 |
else:
|
547 |
setI = set([end_breaks[i].owner, end_breaks[i].prop('Connected Item')]) |
548 |
setJ = set([end_breaks[j].owner, end_breaks[j].prop('Connected Item')]) |
549 |
if not (setI - setJ): |
550 |
index = [i, j] |
551 |
index.sort() |
552 |
index = tuple(index)
|
553 |
dupl.add(index) |
554 |
#print(dupl)
|
555 |
dupl = list(set([indexSet[1] for indexSet in list(dupl)])) |
556 |
dupl.sort(reverse=True)
|
557 |
#print(dupl)
|
558 |
for index in dupl: |
559 |
end_breaks.pop(index) |
560 |
|
561 |
for end_break in end_breaks: |
562 |
end_break.transfer.onRemoved.connect(App.mainWnd().itemRemoved) |
563 |
end_break.addSvgItemToScene(worker.graphicsView.scene) |
564 |
|
565 |
except Exception as ex: |
566 |
from App import App |
567 |
message = 'error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno) |
568 |
App.mainWnd().addMessage.emit(MessageType.Error, message) |
569 |
finally:
|
570 |
worker.finished.emit() |
571 |
|