18 |
18 |
from EngineeringEquipmentItem import QEngineeringEquipmentItem
|
19 |
19 |
from EngineeringInstrumentItem import QEngineeringInstrumentItem
|
20 |
20 |
from EngineeringVendorItem import QEngineeringVendorItem
|
|
21 |
from EngineeringSpecBreakItem import QEngineeringSpecBreakItem
|
|
22 |
from EngineeringErrorItem import QEngineeringErrorItem
|
|
23 |
from EngineeringEndBreakItem import QEngineeringEndBreakItem
|
|
24 |
from EngineeringUnknownItem import QEngineeringUnknownItem
|
|
25 |
from EngineeringRunItem import QEngineeringRunItem
|
21 |
26 |
|
22 |
27 |
|
23 |
28 |
class SetStreamCommand(AbstractCommand):
|
... | ... | |
26 |
31 |
def __init__(self):
|
27 |
32 |
super(SetStreamCommand, self).__init__(None)
|
28 |
33 |
|
|
34 |
def find_item(scene, uid):
|
|
35 |
items = [item for item in scene.items() if hasattr(item, 'uid') and str(item.uid) == str(uid)]
|
|
36 |
return items[0] if items else None
|
|
37 |
|
|
38 |
def set_stream_no(lineno, include_signal=True):
|
|
39 |
""" modified from find_primary_lines at LineNoTracer"""
|
|
40 |
|
|
41 |
connected_items = []
|
|
42 |
|
|
43 |
_from = lineno.prop('From')
|
|
44 |
_to = lineno.prop('To')
|
|
45 |
if _from and _to and lineno.empty():
|
|
46 |
connected_items = SetStreamCommand.find_connected_objects(_from, to=_to, primary=True, include_signal=include_signal)
|
|
47 |
if _from in connected_items and _to in connected_items:
|
|
48 |
start = connected_items.index(_from)
|
|
49 |
end = connected_items.index(_to)
|
|
50 |
if start < end:
|
|
51 |
connected_items = connected_items[start:end + 1]
|
|
52 |
else:
|
|
53 |
connected_items = connected_items[end:start + 1]
|
|
54 |
connected_items.reverse()
|
|
55 |
|
|
56 |
if connected_items:
|
|
57 |
for item in connected_items:
|
|
58 |
# set stream no -> on going
|
|
59 |
pass
|
|
60 |
|
|
61 |
return connected_items
|
|
62 |
|
|
63 |
def find_connected_objects(start, to=None, primary=False, include_signal=True):
|
|
64 |
visited = [start]
|
|
65 |
break_at_first = None
|
|
66 |
|
|
67 |
try:
|
|
68 |
pool = []
|
|
69 |
pool.append((0, start))
|
|
70 |
|
|
71 |
while len(pool) > 0:
|
|
72 |
sign, obj = pool.pop()
|
|
73 |
match = False
|
|
74 |
if not primary:
|
|
75 |
# check stream no is already setted
|
|
76 |
pass
|
|
77 |
|
|
78 |
if issubclass(type(obj), QEngineeringEquipmentItem):
|
|
79 |
visited.pop(visited.index(obj))
|
|
80 |
continue
|
|
81 |
elif match:
|
|
82 |
continue
|
|
83 |
|
|
84 |
""" end loop if obj is to """
|
|
85 |
if to is not None and str(obj.uid) == str(to.uid): break
|
|
86 |
|
|
87 |
# nextmatches list always has one item
|
|
88 |
if type(obj) is QEngineeringLineItem:
|
|
89 |
symbolMatches = [x for x in self._symbols if (x.owner is None or x.owner == start.owner) and (
|
|
90 |
x not in visited) and obj.is_connected(x)]
|
|
91 |
if include_signal:
|
|
92 |
lineMatches = [x for x in self._lines if
|
|
93 |
(x.owner is None or x.owner == start.owner) and (x is not obj) and (
|
|
94 |
x not in visited) and obj.is_connected(x)]
|
|
95 |
else:
|
|
96 |
lineMatches = [x for x in self._lines if
|
|
97 |
x.is_piping() and (x.owner is None or x.owner == start.owner) and (
|
|
98 |
x is not obj) and (x not in visited) and obj.is_connected(x)]
|
|
99 |
nextMatches = symbolMatches + lineMatches
|
|
100 |
|
|
101 |
elif issubclass(type(obj), SymbolSvgItem):
|
|
102 |
# symbol can be connected with line and another symbol at the same time
|
|
103 |
if include_signal:
|
|
104 |
lineMatches = [x for x in self._lines if (x.owner is None or x.owner == start.owner) and (
|
|
105 |
x not in visited) and obj.is_connected(x)]
|
|
106 |
else:
|
|
107 |
lineMatches = [x for x in self._lines if
|
|
108 |
x.is_piping() and (x.owner is None or x.owner == start.owner) and (
|
|
109 |
x not in visited) and obj.is_connected(x)]
|
|
110 |
symbolMatches = [x for x in self._symbols if
|
|
111 |
(x.owner is None or x.owner == start.owner) and (x is not obj) and (
|
|
112 |
x not in visited) and obj.is_connected(x, None)]
|
|
113 |
nextMatches = symbolMatches + lineMatches
|
|
114 |
|
|
115 |
if len(nextMatches) > 1: # choose one if connected items are more than 2
|
|
116 |
matches = [x for x in visited if obj.is_connected(x)]
|
|
117 |
if matches:
|
|
118 |
next_connected = [x for x in nextMatches if obj.next_connected(x, matches[0])]
|
|
119 |
|
|
120 |
if next_connected:
|
|
121 |
nextMatches = next_connected
|
|
122 |
else:
|
|
123 |
nextMatches = []
|
|
124 |
|
|
125 |
# if obj symbol has break connector and nextMatch connected that connector than break line group
|
|
126 |
if nextMatches and obj.break_connector and [index for index in obj.break_connector if
|
|
127 |
obj.connectors[index].connectedItem is nextMatches[0]]:
|
|
128 |
match = True
|
|
129 |
break
|
|
130 |
|
|
131 |
# if obj item connected symbol that has break connector then break line group
|
|
132 |
if nextMatches:
|
|
133 |
pop_index = []
|
|
134 |
index = 0
|
|
135 |
for nextMatch in nextMatches:
|
|
136 |
if hasattr(nextMatch, 'break_connector'):
|
|
137 |
if [index for index in nextMatch.break_connector if
|
|
138 |
nextMatch.connectors[index].connectedItem is obj]:
|
|
139 |
pop_index.append(index)
|
|
140 |
index += 1
|
|
141 |
|
|
142 |
for index in reversed(pop_index):
|
|
143 |
nextMatches.pop(index)
|
|
144 |
|
|
145 |
# order connected objects
|
|
146 |
matches = []
|
|
147 |
matches.extend(nextMatches)
|
|
148 |
|
|
149 |
if sign == 0 and len(matches) > 1:
|
|
150 |
mid = int(len(matches) * 0.5)
|
|
151 |
lhs = matches[0:mid]
|
|
152 |
rhs = matches[mid:]
|
|
153 |
elif sign == -1:
|
|
154 |
lhs = matches
|
|
155 |
rhs = []
|
|
156 |
else:
|
|
157 |
lhs = []
|
|
158 |
rhs = matches
|
|
159 |
|
|
160 |
for match in lhs:
|
|
161 |
# print(match)
|
|
162 |
pool.append((-1, match))
|
|
163 |
visited.insert(0, match)
|
|
164 |
|
|
165 |
for match in rhs:
|
|
166 |
# print(match)
|
|
167 |
pool.append((1, match))
|
|
168 |
visited.append(match)
|
|
169 |
# up to here
|
|
170 |
|
|
171 |
except Exception as ex:
|
|
172 |
from App import App
|
|
173 |
|
|
174 |
message = 'error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename,
|
|
175 |
sys.exc_info()[-1].tb_lineno)
|
|
176 |
App.mainWnd().addMessage.emit(MessageType.Error, message)
|
|
177 |
|
|
178 |
# print(visited)
|
|
179 |
return visited
|
|
180 |
|
29 |
181 |
def execute(self, scene):
|
30 |
182 |
"""set stream no"""
|
31 |
183 |
|
... | ... | |
34 |
186 |
|
35 |
187 |
app_doc_data = AppDocData.instance()
|
36 |
188 |
try:
|
|
189 |
symbols = []
|
|
190 |
lines = [item for item in scene.items() if type(item) is QEngineeringLineItem]
|
|
191 |
lineNos = []
|
|
192 |
spec_breaks = []
|
|
193 |
end_breaks = []
|
|
194 |
|
|
195 |
for end_break in [item for item in scene.items() if type(item) is QEngineeringEndBreakItem]:
|
|
196 |
end_breaks.append(end_break)
|
|
197 |
|
|
198 |
for item in scene.items():
|
|
199 |
if type(item) is QEngineeringSpecBreakItem:
|
|
200 |
spec_breaks.append(item)
|
|
201 |
elif issubclass(type(item), SymbolSvgItem) and not (type(item) is QEngineeringErrorItem) and not (
|
|
202 |
type(item) is QEngineeringUnknownItem) and item.type != 'Notes' and not (
|
|
203 |
type(item) is QEngineeringEndBreakItem):
|
|
204 |
symbols.append(item)
|
|
205 |
elif type(item) is QEngineeringLineNoTextItem:
|
|
206 |
lineNos.append(item)
|
|
207 |
|
|
208 |
rows = app_doc_data.get_stream_from_to(drawing_uid = app_doc_data.activeDrawing.UID)
|
|
209 |
stream_nos = []
|
37 |
210 |
|
|
211 |
for row in rows:
|
|
212 |
stream_no = QEngineeringLineNoTextItem()
|
|
213 |
stream_no.setPlainText(row['Stream_No'])
|
|
214 |
|
|
215 |
from_item = SetStreamCommand.find_item(scene, row['From_Component_UID'])
|
|
216 |
to_item = SetStreamCommand.find_item(scene, row['To_Component_UID'])
|
|
217 |
if not from_item or not to_item:
|
|
218 |
continue
|
|
219 |
|
|
220 |
stream_no.set_property('From', from_item)
|
|
221 |
stream_no.set_property('To', to_item)
|
|
222 |
|
|
223 |
|
38 |
224 |
|
39 |
225 |
except Exception as ex:
|
40 |
226 |
message = f"error occurred({repr(ex)}) in {sys.exc_info()[-1].tb_frame.f_code.co_filename}:" \
|