프로젝트

일반

사용자정보

개정판 969629b3

ID969629b3f2c51090c17d71da47848fbcceca756a
상위 23cf656c
하위 3372da8c, ff8cba33

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

issue #1465: line list test

Change-Id: Idd4b9e63972e4a27f964cc8ac6b4e77a6b034ec8

차이점 보기:

DTI_PID/DTI_PID/LineListDialog.py
1
# coding: utf-8
2
"""
3
    This is area configuration module
4
"""
5
import os
6
import sys
7
from PyQt5.QtCore import *
8
from PyQt5.QtGui import *
9
from PyQt5.QtWidgets import *
10
from AppDocData import AppDocData, MessageType
11
from App import App
12

  
13
from EngineeringAbstractItem import QEngineeringAbstractItem
14
from EngineeringLineItem import QEngineeringLineItem
15
from EngineeringLineNoTextItem import QEngineeringLineNoTextItem
16
from SymbolSvgItem import SymbolSvgItem
17
from EngineeringEquipmentItem import QEngineeringEquipmentItem
18
from EngineeringInstrumentItem import QEngineeringInstrumentItem
19
from EngineeringVendorItem import QEngineeringVendorItem
20
from EngineeringSpecBreakItem import QEngineeringSpecBreakItem
21
from EngineeringErrorItem import QEngineeringErrorItem
22
from EngineeringEndBreakItem import QEngineeringEndBreakItem
23
from EngineeringUnknownItem import QEngineeringUnknownItem
24
from EngineeringRunItem import QEngineeringRunItem
25
from QEngineeringOPCItem import QEngineeringOPCItem
26

  
27
import LineNoList_UI
28

  
29
class LineListDialog(QDialog):
30
    def __init__(self, parent):
31
        QDialog.__init__(self, parent)
32
        
33
        self.ui = LineNoList_UI.Ui_LineListTable()
34
        self.ui.setupUi(self)
35

  
36
        self.ui.tableViewLineList.setSortingEnabled(True)
37

  
38
        self.isAccepted = False
39
        self.code_data = None
40

  
41
        # load drawing list
42
        # skip
43

  
44
        datas = self.make_line_list_data()
45
        self.fill_data(datas)
46

  
47
        #self.ui.buttonBox.accepted.connect(self.accept)
48
        self.ui.buttonBox.button(QDialogButtonBox.Close).clicked.connect(self.reject)
49

  
50
        #self.settingTable(Table_Name, attribute_uid=attribute_uid, tableDatas=tableDatas)
51
    
52
    def get_from_name(self, run, item):
53

  
54
        return item.name + '(' + str(item.uid) + ')' if issubclass(type(item), SymbolSvgItem) else 'Line' + '(' + str(item.uid) + ')'
55

  
56
    def get_to_name(self, run, item):
57

  
58
        return item.name + '(' + str(item.uid) + ')' if issubclass(type(item), SymbolSvgItem) else 'Line' + '(' + str(item.uid) + ')'
59

  
60
    def fill_data(self, datas):
61
        model = QStandardItemModel()
62
        header = ['Line No', 'From', 'To', 'Stream No']
63

  
64
        row_datas = []
65
        for data in datas:
66
            row_datas.extend(data)
67

  
68
        for row_data in row_datas:
69
            line_no = row_data[0].owner.text()
70
            from_ = self.get_from_name(row_data[0], row_data[1])
71
            to_ = self.get_to_name(row_data[0], row_data[2])
72
            stream_no = row_data[1].stream_no
73
            items = [QStandardItem(line_no), QStandardItem(from_), QStandardItem(to_), QStandardItem(stream_no)]
74

  
75
            model.appendRow(items)
76

  
77
        model.setHorizontalHeaderLabels(header)
78

  
79
        self.ui.tableViewLineList.setModel(model)
80
        self.ui.tableViewLineList.resizeColumnsToContents()
81
        self.ui.tableViewLineList.setEditTriggers(QAbstractItemView.NoEditTriggers)
82

  
83
    def make_line_list_data(self):
84

  
85
        app_doc_data = AppDocData.instance()
86
        try:
87
            scene = self.get_scene()
88

  
89
            self._symbols = []
90
            self._lines = [item for item in scene.items() if type(item) is QEngineeringLineItem]
91

  
92
            lineNos = []
93
            start_line_runs = []
94

  
95
            spec_breaks = []
96
            break_items_pair = []
97

  
98
            end_breaks = []
99

  
100
            for end_break in [item for item in scene.items() if type(item) is QEngineeringEndBreakItem]:
101
                end_breaks.append(end_break)
102

  
103
            for item in scene.items():
104
                # for data binding
105
                if issubclass(type(item), QEngineeringAbstractItem):
106
                    item.getAttributes()
107

  
108
                if type(item) is QEngineeringSpecBreakItem:
109
                    spec_breaks.append(item)
110
                elif issubclass(type(item), SymbolSvgItem) and not (type(item) is QEngineeringErrorItem) and not (
111
                        type(item) is QEngineeringUnknownItem) and item.type != 'Notes' and not (
112
                        type(item) is QEngineeringEndBreakItem):
113
                    self._symbols.append(item)
114
                elif type(item) is QEngineeringLineNoTextItem:
115
                    lineNos.append(item)
116

  
117
                    if item.runs:
118
                        for run in item.runs:
119
                            start = [run.items[0]]
120
                            end = [run.items[-1]] if run.items[0] is not run.items[-1] else []
121
                            
122
                            if type(start[0]) is QEngineeringOPCItem:
123
                                start_line_runs.insert(0, run)
124
                            else:
125
                                start_line_runs.append(run)
126

  
127
            for spec_break in spec_breaks:
128
                up_item = spec_break.up_stream
129
                down_item = spec_break.down_stream
130
                if issubclass(type(up_item), QEngineeringAbstractItem) and issubclass(type(down_item), QEngineeringAbstractItem) and \
131
                    up_item.owner is down_item.owner:
132
                    break_items_pair.append((up_item, down_item))
133

  
134
            line_list_row_datass = [] # [[[run, from item, to item], [run, from item, to item], ...], [[run, from item, to item], [run, from item, to item], ...], ...]
135
            while True:
136
                if len(start_line_runs) == 0:
137
                    break
138

  
139
                line_list_row_datas = [] # [[run, from item, to item], [run, from item, to item], ...]
140
                run = start_line_runs.pop(0)
141
                
142
                # row split if spec change in same run
143
                break_run_item_pairs = []
144
                for pair in break_items_pair:
145
                    if pair[0] in run.items and pair[1] in run.items:
146
                        break_run_item_pairs.append(pair)
147

  
148
                if break_run_item_pairs:
149
                    save_index = 0
150
                    for index in range(len(run.items)):
151
                        if index >= len(run.items) - 2:
152
                            break
153

  
154
                        for break_items in break_run_item_pairs:
155
                            if run.items[index] in break_items and run.items[index + 1] in break_items:
156
                                line_list_row_datas.append([run, run.items[save_index], run.items[index]])
157
                                save_index = index + 1
158

  
159
                    line_list_row_datas.append([run, run.items[save_index], run.items[index]])
160
                else:
161
                    line_list_row_datas.append([run, run.items[0], run.items[-1]])
162

  
163
                # for list row sequence, connected pipe list in a row
164
                for index in range(len(start_line_runs)):
165
                    if start_line_runs[index].items[0].is_connected(run.items[-1]):
166
                        connected_run = start_line_runs.pop(index)
167
                        start_line_runs.insert(0, connected_run)
168
                        break
169

  
170
                # row split if stream no change
171
                new_row_datas_index_infos = []
172
                for line_list_row_data_index in range(len(line_list_row_datas)):
173
                    new_row_datas = []
174

  
175
                    line_list_row_data = line_list_row_datas[line_list_row_data_index]
176
                    run = line_list_row_data[0]
177
                    start_index = run.items.index(line_list_row_data[1])
178
                    end_index = run.items.index(line_list_row_data[2])
179

  
180
                    pre_stream_no = line_list_row_data[1].stream_no
181
                    pre_index  = start_index
182
                    for index in range(start_index, end_index + 1):
183
                        if pre_stream_no != run.items[index].stream_no:
184
                            new_row_datas.append([run, run.items[pre_index], run.items[index - 1]])
185
                            pre_index = index
186
                            pre_stream_no = run.items[index].stream_no
187

  
188
                    if start_index != pre_index:
189
                        new_row_datas.append([run, run.items[pre_index], run.items[end_index]])
190

  
191
                    if new_row_datas:
192
                        new_row_datas_index_infos.append([line_list_row_data_index, new_row_datas])
193

  
194
                new_row_datas_index_infos.reverse()
195
                for new_row_datas_index_info in new_row_datas_index_infos:
196
                    line_list_row_datas.pop(new_row_datas_index_info[0])
197
                    new_row_datas_index_info[1].reverse()
198
                    for new_row_data in new_row_datas_index_info[1]:
199
                        line_list_row_datas.insert(new_row_datas_index_info[0], new_row_data)
200

  
201
                if line_list_row_datas:
202
                    line_list_row_datass.append(line_list_row_datas)
203

  
204
            return line_list_row_datass            
205
            
206
        except Exception as ex:
207
            message = f"error occurred({repr(ex)}) in {sys.exc_info()[-1].tb_frame.f_code.co_filename}:" \
208
                      f"{sys.exc_info()[-1].tb_lineno}"
209
            self.display_message.emit(MessageType.Error, message)
210

  
211
    def get_scene(self):
212
        # get scene for load data
213
        # now return mainwindow scene
214
        return self.parent().graphicsView.scene()
215
        
216
    '''
217
        @brief  accept dialog
218
    '''
219
    '''
220
    def accept(self):
221
        import uuid
222

  
223
        try:
224
            self.code_data = []
225
            self.isAccepted = False
226

  
227
            tabText = self.getTabText()    
228
            table = self.findTableWidget(tabText)
229

  
230
            for row in range(table.rowCount()):
231
                if table.isRowHidden(row):
232
                    continue
233
                else:
234
                    if not self.inst:
235
                        uid = table.item(row, 0).text() if table.item(row, 0).text() else str(uuid.uuid4())
236
                        code = table.item(row, 1).text() if table.item(row, 1) else ''
237
                        description = table.item(row, 2).text() if table.item(row, 2) is not None else ''
238
                        allowables = table.item(row, 3).text().split(',') if table.item(row, 3) is not None else []
239

  
240
                        if code:
241
                            self.code_data.append((uid, code, description, allowables))
242
                    else:
243
                        uid = table.item(row, 0).text() if table.item(row, 0).text() else str(uuid.uuid4())
244
                        code = table.item(row, 1).text().split(',') if table.item(row, 1) is not None else []
245
                        symbols = table.item(row, 2).text().split(',') if table.item(row, 3) is not None else []
246
                        attrs = table.item(row, 3).text().split(',') if table.item(row, 3) is not None else []
247
                        newCode = table.item(row, 4).text() if table.item(row, 1) else ''
248
                        expression = table.item(row, 5).text() if table.item(row, 1) else ''
249
                        priority = table.item(row, 6).text() if table.item(row, 1) else ''
250

  
251
                        texts = [[table.item(row, 1).text(), table.item(row, 2).text(), table.item(row, 3).text()], \
252
                                    [table.item(row, 4).text(), table.item(row, 5).text()]]
253
                        if True if len([text for text in texts[0] if text == '']) <= 2 and len([text for text in texts[1] if text == '']) <= 1 else False:
254
                            self.code_data.append((uid, code, symbols, attrs, newCode, expression, priority))
255

  
256
            self.isAccepted = True
257
            QDialog.accept(self)
258

  
259
        except Exception as ex:
260
            from App import App
261
            from AppDocData import MessageType
262

  
263
            message = 'error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno)
264
            App.mainWnd().addMessage.emit(MessageType.Error, message)
265
    '''
266
        
267
    def reject(self):
268
        try:
269
            self.isAccepted = False
270
            QDialog.reject(self)
271

  
272
        except Exception as ex:
273
            from App import App
274
            from AppDocData import MessageType
275

  
276
            message = 'error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno)
277
            App.mainWnd().addMessage.emit(MessageType.Error, message)
278

  
279
    def showDialog(self):
280
        self.show()
281
        self.exec_()

내보내기 Unified diff

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