프로젝트

일반

사용자정보

개정판 959aa14a

ID959aa14a05ac75cd8e0f07e14d5bf19bc97f3235
상위 f5e25e07
하위 f6352950

함의성이(가) 약 4년 전에 추가함

issue #1462: stream tracing on going, method and detail remain

Change-Id: Ibe9199268f4ae8fd7c8fa6de12ddce65c338b221

차이점 보기:

DTI_PID/DTI_PID/AppDocData.py
2525 2525
                App.mainWnd().addMessage.emit(MessageType.Error, message)
2526 2526

  
2527 2527
    @staticmethod
2528
    def get_hmb_data_from(file_path: str):
2528
    def get_hmb_data(file_path: str):
2529 2529
        """get hmb data from pap database if file_path is given otherwise get hmb data from id2 database"""
2530 2530

  
2531 2531
        from HMBTable import HMBData
......
2714 2714
                          f"{sys.exc_info()[-1].tb_lineno}"
2715 2715
                App.mainWnd().addMessage.emit(MessageType.Error, message)
2716 2716

  
2717
    def get_stream_lines(self, hmb_uid: str) -> list:
2717
    def get_stream_from_to(self, hmb_uid: str = None, drawing_uid: str = None) -> list:
2718 2718
        """get stream lines related to hmb"""
2719 2719

  
2720 2720
        with self.project.database.connect() as conn:
......
2722 2722
                # Get a cursor object
2723 2723
                cursor = conn.cursor()
2724 2724

  
2725
                sql = f"select h.Drawing_UID, h.From_Component_UID, h.To_Component_UID, d.Name from HMB_From_To h " \
2726
                      f"inner join Drawings d on d.UID=h.Drawing_UID " \
2727
                      f"where Stream_No_UID = ?"
2725
                if hmb_uid:
2726
                    sql = f"select h.Drawing_UID, h.From_Component_UID, h.To_Component_UID, d.Name from HMB_From_To h " \
2727
                          f"inner join Drawings d on d.UID=h.Drawing_UID " \
2728
                          f"where Stream_No_UID = ?"
2729
                    params = (hmb_uid,)
2730
                else:
2731
                    sql = f"select h.From_Component_UID, h.To_Component_UID, s.Stream_No from HMB_From_To h " \
2732
                          f"inner join Stream_No s on s.UID=h.Stream_No_UID " \
2733
                          f"where Drawing_UID = ?"
2734
                    params = (drawing_uid,)
2728 2735
                sql = self.project.database.to_sql(sql)
2729
                params = (hmb_uid,)
2730 2736
                cursor.execute(sql, params)
2731 2737
                return cursor.fetchall()
2732 2738
            # Catch the exception
DTI_PID/DTI_PID/Commands/ReplaceInsertCommand.py
40 40
        """replace or insert symbol"""
41 41

  
42 42
        from App import App
43
        from AppDocData import AppDocData
44 43
        from AppDocData import MessageType
45 44

  
46 45
        app_doc_data = AppDocData.instance()
DTI_PID/DTI_PID/Commands/SetStreamNoCommand.py
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}:" \
DTI_PID/DTI_PID/HMBDialog.py
44 44
        """load hmb data and fill table view"""
45 45
        import uuid
46 46

  
47
        hmbs = AppDocData.get_hmb_data_from(file_path)
47
        hmbs = AppDocData.get_hmb_data(file_path)
48 48
        if not hmbs:
49 49
            return
50 50

  
DTI_PID/DTI_PID/HMBTable.py
204 204
            if self._hmbs is None:
205 205
                self._hmbs = []
206 206

  
207
                rows = AppDocData.get_hmb_data_from(None)
207
                rows = AppDocData.get_hmb_data(None)
208 208
                for row in rows:
209 209
                    hmb = HMBData.from_row(row)
210 210
                    self._hmbs.append(hmb)
DTI_PID/DTI_PID/RecognitionDialog.py
4082 4082

  
4083 4083
        try:
4084 4084
            for item in items:
4085
                #item.transfer.onRemoved.emit(item)
4086 4085
                App.mainWnd().itemRemoved(item)
4087
            '''
4088
            from ReplaceInsertCommand import ReplaceInsertCommand
4089

  
4090
            cmd = ReplaceInsertCommand()
4091
            cmd.display_message.connect(App.mainWnd().onAddMessage)
4092
            cmd.item_remove(items)
4093
            '''
4094 4086

  
4095 4087
        except Exception as ex:
4096 4088
            message = 'error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename,
DTI_PID/DTI_PID/StreamlineDialog.py
74 74
        """load hmb data and fill table view"""
75 75
        import uuid
76 76

  
77
        hmbs = AppDocData.get_hmb_data_from(None)
77
        hmbs = AppDocData.get_hmb_data(None)
78 78
        if not hmbs:
79 79
            return
80 80

  
......
115 115
            model.clear()
116 116

  
117 117
            app_doc_data = AppDocData.instance()
118
            rows = app_doc_data.get_stream_lines(uid)
118
            rows = app_doc_data.get_stream_from_to(hmb_uid=uid)
119 119
            if rows:
120 120
                for row_ in rows:
121 121
                    from_ = row_['From_Component_UID']

내보내기 Unified diff

클립보드 이미지 추가 (최대 크기: 500 MB)