개정판 f6352950
issue #1462: stream no set test
Change-Id: I3217f3d3fbef4a2c5309e0f88c8ba66d58594ab6
DTI_PID/DTI_PID/Commands/SetStreamNoCommand.py | ||
---|---|---|
7 | 7 |
from PyQt5.QtCore import * |
8 | 8 |
from PyQt5.QtWidgets import * |
9 | 9 |
from PyQt5.QtGui import * |
10 |
from AppDocData import AppDocData |
|
10 |
from AppDocData import AppDocData, MessageType
|
|
11 | 11 |
from AbstractCommand import AbstractCommand |
12 | 12 |
from QtImageViewer import QtImageViewer |
13 | 13 | |
... | ... | |
31 | 31 |
def __init__(self): |
32 | 32 |
super(SetStreamCommand, self).__init__(None) |
33 | 33 | |
34 |
def find_item(scene, uid): |
|
34 |
self._symbols = [] |
|
35 |
self._lines = [] |
|
36 | ||
37 |
def find_item(self, scene, uid): |
|
35 | 38 |
items = [item for item in scene.items() if hasattr(item, 'uid') and str(item.uid) == str(uid)] |
36 | 39 |
return items[0] if items else None |
37 | 40 | |
38 |
def set_stream_no(lineno, include_signal=True):
|
|
41 |
def set_stream_no(self, stream_no, include_signal=True):
|
|
39 | 42 |
""" modified from find_primary_lines at LineNoTracer""" |
40 | 43 | |
41 | 44 |
connected_items = [] |
42 | 45 | |
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) |
|
46 |
_from = stream_no.prop('From') |
|
47 |
_to = stream_no.prop('To') |
|
48 | ||
49 |
# return if from or to item has not stream no attriute |
|
50 |
if not (self.check_stream_no_attribute(_from) != False and self.check_stream_no_attribute(_to) != False): |
|
51 |
return |
|
52 |
else: |
|
53 |
self.set_stream_no_item(_from, stream_no.text()) |
|
54 |
self.set_stream_no_item(_to, stream_no.text()) |
|
55 | ||
56 |
if _from and _to and stream_no.empty(): |
|
57 |
connected_items = self.find_connected_objects(_from, to=_to, primary=True, include_signal=include_signal) |
|
47 | 58 |
if _from in connected_items and _to in connected_items: |
48 | 59 |
start = connected_items.index(_from) |
49 | 60 |
end = connected_items.index(_to) |
... | ... | |
55 | 66 | |
56 | 67 |
if connected_items: |
57 | 68 |
for item in connected_items: |
58 |
# set stream no -> on going |
|
59 |
pass |
|
69 |
self.set_stream_no_item(item, stream_no.text()) |
|
70 | ||
71 |
line_run = QEngineeringRunItem() |
|
72 |
line_run.items = connected_items |
|
73 |
line_run.owner = stream_no |
|
74 |
stream_no.runs.append(line_run) |
|
75 | ||
76 |
stream_no.set_property('From', connected_items[0]) |
|
77 |
stream_no.set_property('To', connected_items[-1]) |
|
60 | 78 | |
61 | 79 |
return connected_items |
62 | 80 | |
63 |
def find_connected_objects(start, to=None, primary=False, include_signal=True): |
|
81 |
def clear_stream_no(self, items): |
|
82 |
for item in items: |
|
83 |
_attrs = item.getAttributes(findOwner=True) |
|
84 |
for key, value in _attrs.items(): |
|
85 |
if key.Attribute == 'Stream No' and not key.Freeze: |
|
86 |
_attrs[key] = '' |
|
87 | ||
88 |
def set_stream_no_item(self, item, stream_no): |
|
89 |
_attrs = item.getAttributes(findOwner=True) |
|
90 |
for key, value in _attrs.items(): |
|
91 |
if key.Attribute == 'Stream No': |
|
92 |
_attrs[key] = stream_no |
|
93 |
return True |
|
94 |
return False |
|
95 | ||
96 |
def check_stream_no_attribute(self, item): |
|
97 |
""" return stream no if item has stream no attribute else return False """ |
|
98 |
_attrs = item.getAttributes(findOwner=True) |
|
99 |
for key, value in _attrs.items(): |
|
100 |
if key.Attribute == 'Stream No': |
|
101 |
if value: |
|
102 |
return value |
|
103 |
elif value == '' or value == None: |
|
104 |
return None |
|
105 |
else: |
|
106 |
return False |
|
107 | ||
108 |
def find_connected_objects(self, start, to=None, primary=False, include_signal=True): |
|
64 | 109 |
visited = [start] |
65 |
break_at_first = None |
|
66 | 110 | |
67 | 111 |
try: |
68 | 112 |
pool = [] |
... | ... | |
72 | 116 |
sign, obj = pool.pop() |
73 | 117 |
match = False |
74 | 118 |
if not primary: |
75 |
# check stream no is already setted |
|
76 | 119 |
pass |
77 | 120 | |
78 | 121 |
if issubclass(type(obj), QEngineeringEquipmentItem): |
... | ... | |
86 | 129 | |
87 | 130 |
# nextmatches list always has one item |
88 | 131 |
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)] |
|
132 |
symbolMatches = [x for x in self._symbols if (self.check_stream_no_attribute(x) is None or \ |
|
133 |
self.check_stream_no_attribute(x) == self.check_stream_no_attribute(start)) and \ |
|
134 |
(x not in visited) and obj.is_connected(x)] |
|
91 | 135 |
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)] |
|
136 |
lineMatches = [x for x in self._lines if (self.check_stream_no_attribute(x) is None or \
|
|
137 |
self.check_stream_no_attribute(x) == self.check_stream_no_attribute(start)) and \
|
|
138 |
(x is not obj) and (x not in visited) and obj.is_connected(x)]
|
|
95 | 139 |
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)] |
|
140 |
lineMatches = [x for x in self._lines if x.is_piping() and (self.check_stream_no_attribute(x) is None or \
|
|
141 |
self.check_stream_no_attribute(x) == self.check_stream_no_attribute(start)) and \
|
|
142 |
(x is not obj) and (x not in visited) and obj.is_connected(x)]
|
|
99 | 143 |
nextMatches = symbolMatches + lineMatches |
100 | 144 | |
101 | 145 |
elif issubclass(type(obj), SymbolSvgItem): |
102 | 146 |
# symbol can be connected with line and another symbol at the same time |
103 | 147 |
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)] |
|
148 |
lineMatches = [x for x in self._lines if (self.check_stream_no_attribute(x) is None or \ |
|
149 |
self.check_stream_no_attribute(x) == self.check_stream_no_attribute(start)) and \ |
|
150 |
(x not in visited) and obj.is_connected(x)] |
|
106 | 151 |
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)] |
|
152 |
lineMatches = [x for x in self._lines if x.is_piping() and (self.check_stream_no_attribute(x) is None or \
|
|
153 |
self.check_stream_no_attribute(x) == self.check_stream_no_attribute(start)) and \
|
|
154 |
(x not in visited) and obj.is_connected(x)]
|
|
155 |
symbolMatches = [x for x in self._symbols if (self.check_stream_no_attribute(x) is None or \
|
|
156 |
self.check_stream_no_attribute(x) == self.check_stream_no_attribute(start)) and \
|
|
157 |
(x is not obj) and (x not in visited) and obj.is_connected(x, None)]
|
|
113 | 158 |
nextMatches = symbolMatches + lineMatches |
114 | 159 | |
115 | 160 |
if len(nextMatches) > 1: # choose one if connected items are more than 2 |
... | ... | |
122 | 167 |
else: |
123 | 168 |
nextMatches = [] |
124 | 169 | |
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 |
|
170 |
# order connected objects |
|
146 | 171 |
matches = [] |
147 | 172 |
matches.extend(nextMatches) |
148 | 173 | |
... | ... | |
158 | 183 |
rhs = matches |
159 | 184 | |
160 | 185 |
for match in lhs: |
161 |
# print(match) |
|
162 | 186 |
pool.append((-1, match)) |
163 | 187 |
visited.insert(0, match) |
164 | 188 | |
165 | 189 |
for match in rhs: |
166 |
# print(match) |
|
167 | 190 |
pool.append((1, match)) |
168 | 191 |
visited.append(match) |
169 | 192 |
# up to here |
... | ... | |
175 | 198 |
sys.exc_info()[-1].tb_lineno) |
176 | 199 |
App.mainWnd().addMessage.emit(MessageType.Error, message) |
177 | 200 | |
178 |
# print(visited) |
|
179 | 201 |
return visited |
180 | 202 | |
181 | 203 |
def execute(self, scene): |
... | ... | |
186 | 208 | |
187 | 209 |
app_doc_data = AppDocData.instance() |
188 | 210 |
try: |
189 |
symbols = [] |
|
190 |
lines = [item for item in scene.items() if type(item) is QEngineeringLineItem] |
|
211 |
self._symbols = []
|
|
212 |
self._lines = [item for item in scene.items() if type(item) is QEngineeringLineItem]
|
|
191 | 213 |
lineNos = [] |
192 | 214 |
spec_breaks = [] |
193 | 215 |
end_breaks = [] |
... | ... | |
201 | 223 |
elif issubclass(type(item), SymbolSvgItem) and not (type(item) is QEngineeringErrorItem) and not ( |
202 | 224 |
type(item) is QEngineeringUnknownItem) and item.type != 'Notes' and not ( |
203 | 225 |
type(item) is QEngineeringEndBreakItem): |
204 |
symbols.append(item) |
|
226 |
self._symbols.append(item)
|
|
205 | 227 |
elif type(item) is QEngineeringLineNoTextItem: |
206 | 228 |
lineNos.append(item) |
207 | 229 | |
230 |
self.clear_stream_no(self._symbols + self._lines) |
|
231 | ||
208 | 232 |
rows = app_doc_data.get_stream_from_to(drawing_uid = app_doc_data.activeDrawing.UID) |
209 | 233 |
stream_nos = [] |
210 | 234 | |
... | ... | |
212 | 236 |
stream_no = QEngineeringLineNoTextItem() |
213 | 237 |
stream_no.setPlainText(row['Stream_No']) |
214 | 238 | |
215 |
from_item = SetStreamCommand.find_item(scene, row['From_Component_UID'])
|
|
216 |
to_item = SetStreamCommand.find_item(scene, row['To_Component_UID'])
|
|
239 |
from_item = self.find_item(scene, row['From_Component_UID'])
|
|
240 |
to_item = self.find_item(scene, row['To_Component_UID'])
|
|
217 | 241 |
if not from_item or not to_item: |
218 | 242 |
continue |
219 | 243 | |
220 | 244 |
stream_no.set_property('From', from_item) |
221 | 245 |
stream_no.set_property('To', to_item) |
246 |
stream_nos.append(stream_no) |
|
222 | 247 | |
223 |
|
|
248 |
for stream_no in stream_nos: |
|
249 |
self.set_stream_no(stream_no, include_signal=False) |
|
224 | 250 |
|
225 | 251 |
except Exception as ex: |
226 | 252 |
message = f"error occurred({repr(ex)}) in {sys.exc_info()[-1].tb_frame.f_code.co_filename}:" \ |
DTI_PID/DTI_PID/ItemPropertyTableWidget.py | ||
---|---|---|
605 | 605 |
else: # elif key.AttributeType == 'Spec': |
606 | 606 |
self.setItem(row, 3, QTableWidgetItem(str(value)[1:-1])) |
607 | 607 |
else: |
608 |
pass |
|
609 |
''' |
|
610 | 608 |
self.setItem(row, 3, value_item) |
609 |
''' |
|
611 | 610 |
if key.Attribute.upper() == 'STREAM NO': |
612 | 611 |
stream_no_combo = QComboBox() |
613 | 612 |
stream_no_combo.tag = key |
DTI_PID/DTI_PID/LineNoTracer.py | ||
---|---|---|
395 | 395 |
for index in reversed(pop_index): |
396 | 396 |
nextMatches.pop(index) |
397 | 397 | |
398 |
# order connected objects
|
|
398 |
# order connected objects |
|
399 | 399 |
matches = [] |
400 | 400 |
matches.extend(nextMatches) |
401 | 401 | |
... | ... | |
702 | 702 |
''' set stream no ''' |
703 | 703 | |
704 | 704 |
from App import App |
705 |
from SetStreamCommand import SetStreamCommand |
|
705 |
from SetStreamNoCommand import SetStreamCommand
|
|
706 | 706 | |
707 | 707 |
cmd = SetStreamCommand() |
708 | 708 |
cmd.display_message.connect(App.mainWnd().onAddMessage) |
내보내기 Unified diff