17 |
17 |
'''
|
18 |
18 |
def __init__(self, symbols, lines, lineNos):
|
19 |
19 |
try:
|
20 |
|
self.symbols = symbols
|
21 |
|
self.lines = lines
|
22 |
|
self.lineNos = lineNos
|
|
20 |
self._symbols = symbols
|
|
21 |
for symbol in self._symbols: symbol.owner = None
|
|
22 |
self._lines = lines
|
|
23 |
for line in self._lines: line.owner = None
|
|
24 |
self._lineNos = lineNos
|
23 |
25 |
except Exception as ex:
|
24 |
26 |
print('error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno))
|
25 |
27 |
|
... | ... | |
42 |
44 |
configs = docData.getConfigs('Line No', 'Configuration')
|
43 |
45 |
|
44 |
46 |
docData.lineNos.clear()
|
45 |
|
for lineNo in self.lineNos: lineNo.conns.clear()
|
46 |
|
docData.lineNos = self.lineNos
|
|
47 |
for lineNo in self._lineNos: lineNo.conns.clear()
|
|
48 |
docData.lineNos = self._lineNos
|
47 |
49 |
for lineno in docData.lineNos:
|
48 |
50 |
minDist = None
|
49 |
51 |
startLine = None
|
50 |
|
for line in self.lines:
|
|
52 |
for line in self._lines:
|
51 |
53 |
dist = line.distanceTo((lineno.center().x(), lineno.center().y()))
|
52 |
54 |
if (minDist is None) or (dist < minDist):
|
53 |
55 |
minDist = dist
|
... | ... | |
55 |
57 |
if (startLine is not None) and (minDist < toler):
|
56 |
58 |
lineno.conns.append(startLine)
|
57 |
59 |
|
|
60 |
# find primary lines
|
58 |
61 |
for lineno in docData.lineNos:
|
59 |
62 |
if 1 == len(lineno.conns):
|
60 |
63 |
self.findConnectedObjects(lineno.conns[0], toler=10)
|
61 |
64 |
connectedItems = lineno.getConnectedItems()
|
|
65 |
for item in connectedItems: item.owner = lineno # set item's owner
|
|
66 |
|
|
67 |
connectedLines = [item for item in connectedItems if type(item) is QEngineeringLineItem]
|
|
68 |
|
|
69 |
maxLength = None
|
|
70 |
maxLengthItem = None
|
|
71 |
for line in connectedLines:
|
|
72 |
length = line.length()
|
|
73 |
if maxLength is None or maxLength < length:
|
|
74 |
maxLength = length
|
|
75 |
maxLengthItem = line
|
|
76 |
|
|
77 |
if maxLengthItem is not None: maxLengthItem.addFlowArrow() # TODO: check error scene() returns None
|
|
78 |
|
|
79 |
# find secondary lines
|
|
80 |
for line in self._lines:
|
|
81 |
if line.owner is not None: continue
|
|
82 |
|
|
83 |
matches = [x for x in self._lines if x.owner is not None and x.isConnectable(line)]
|
|
84 |
if matches:
|
|
85 |
connectedItems = self.findConnectedObjects(line, toler=10)
|
|
86 |
for item in connectedItems: item.owner = matches[0]
|
|
87 |
|
62 |
88 |
connectedLines = [item for item in connectedItems if type(item) is QEngineeringLineItem]
|
63 |
89 |
|
64 |
90 |
maxLength = None
|
... | ... | |
86 |
112 |
pool = []
|
87 |
113 |
pool.append(startLine)
|
88 |
114 |
|
89 |
|
visited = []
|
|
115 |
visited = [startLine]
|
90 |
116 |
while len(pool) > 0:
|
91 |
117 |
obj = pool.pop()
|
92 |
118 |
if type(obj) is QEngineeringLineItem:
|
93 |
|
matches = [x for x in self.symbols if (x not in visited) and len(obj.connectIfPossible(x, toler)) > 0]
|
|
119 |
matches = [x for x in self._symbols if (x.owner is None) and (x not in visited) and len(obj.connectIfPossible(x, toler)) > 0]
|
94 |
120 |
if not matches:
|
95 |
|
matches = [x for x in self.lines if (x is not obj) and (x not in visited) and (len(obj.connectIfPossible(x, toler)) > 0)]
|
|
121 |
matches = [x for x in self._lines if (x.owner is None) and (x is not obj) and (x not in visited) and (len(obj.connectIfPossible(x, toler)) > 0)]
|
96 |
122 |
elif issubclass(type(obj), SymbolSvgItem):
|
97 |
|
matches = [x for x in self.lines if (x not in visited) and len(obj.connectIfPossible(x, toler)) > 0]
|
|
123 |
matches = [x for x in self._lines if (x.owner is None) and (x not in visited) and len(obj.connectIfPossible(x, toler)) > 0]
|
98 |
124 |
if not matches:
|
99 |
|
matches = [x for x in self.symbols if (x is not obj) and (x not in visited) and (len(obj.connectIfPossible(x, toler)) > 0)]
|
|
125 |
matches = [x for x in self._symbols if (x.owner is None) and (x is not obj) and (x not in visited) and (len(obj.connectIfPossible(x, toler)) > 0)]
|
100 |
126 |
|
101 |
127 |
for match in matches:
|
102 |
128 |
pool.append(match)
|
103 |
129 |
visited.append(match)
|
|
130 |
|
|
131 |
return visited
|