프로젝트

일반

사용자정보

개정판 c09b8d3d

IDc09b8d3d9e67792886482f71fda8b1d86f17f536
상위 033ac5bd
하위 7a6f35ae

백흠경이(가) 4년 이상 전에 추가함

issue #1489: From/To를 선택하는 기능 추가

Change-Id: I6ae75c367c42cbd10245d8bf8e6790d89f2d424a

차이점 보기:

DTI_PID/DTI_PID/AppDocData.py
2665 2665
            try:
2666 2666
                cursor = conn.cursor()
2667 2667
                for stream_line in stream_line_list:
2668
                    sql = f"insert into Streamlines(HMB_UID,[From],[To]) values" \
2669
                          f"((select UID from HMB where StreamNumber=?),?,?)"
2670
                    params = (stream_line[0], stream_line[1], stream_line[2])
2668
                    """delete stream line which has stream number is given data"""
2669
                    sql = "delete from Streamlines where HMB_UID=(select UID from HMB where StreamNumber=?)"
2670
                    params = (stream_line[0],)
2671
                    cursor.execute(sql, params)
2672
                    """up to here"""
2673

  
2674
                    sql = f"insert into Streamlines(HMB_UID,[From_UID],[From],[To_UID],[To]) values" \
2675
                          f"((select UID from HMB where StreamNumber=?),?,?,?,?)"
2676
                    params = (stream_line[0], stream_line[1], stream_line[2], stream_line[3], stream_line[4])
2671 2677
                    affected = cursor.execute(sql, params)
2672 2678
            except Exception as ex:
2673 2679
                # Roll back any change if something goes wrong
DTI_PID/DTI_PID/Commands/SelectAttributeBatchCommand.py
69 69
                    item = self.selection_order.pop(0)
70 70
                    stream = [item for item in self.selection_order if issubclass(type(item), SymbolSvgItem) or type(item) is QEngineeringLineItem]
71 71
                    values = [item for item in self.selection_order if issubclass(type(item), QEngineeringTextItem)]
72
                    if len(stream) != 2 or len(values) % 2 !=0:
72
                    if len(stream) != 2 or len(values) % 2 != 0:
73 73
                        return
74 74

  
75 75
                    spec = [stream[0], stream[1]]
DTI_PID/DTI_PID/Commands/SelectCompCommand.py
1
# coding: utf-8
2
""" This is select component command module """
3

  
4
import os.path
5
import sys
6
import AbstractCommand
7

  
8
try:
9
    from PyQt5.QtCore import *
10
    from PyQt5.QtGui import *
11
    from PyQt5.QtWidgets import *
12
except ImportError:
13
    try:
14
        from PyQt4.QtCore import Qt, QRectF, pyqtSignal, QT_VERSION_STR, QEvent
15
        from PyQt4.QtGui import QGraphicsView, QGraphicsScene, QImge, QPixmap, QPainterPath, QFileDialog, QCursor, QMouseEvent
16
    except ImportError:
17
        raise ImportError("ImageViewerQt: Requires PyQt5 or PyQt4.")
18

  
19

  
20
class SelectCompCommand(AbstractCommand.AbstractCommand):
21
    """select component command"""
22
    onSuccess = pyqtSignal(QGraphicsItem)
23

  
24
    def __init__(self, imageViewer):
25
        super(SelectCompCommand, self).__init__(imageViewer)
26
        self.name = 'SelectComponent'
27
        self.imageViewer.setCursor(QCursor(Qt.ArrowCursor))
28
        self._selected = None
29

  
30
    @property
31
    def selected(self):
32
        return self._selected
33

  
34
    def execute(self, param):
35
        """select a component"""
36
        from SymbolAttr import SymbolAttr
37
        from SymbolAttr import SymbolProp
38

  
39
        event = param[1]
40
        scenePos = param[2]
41

  
42
        try:
43
            if 'mouseReleaseEvent' == param[0] and event.button() == Qt.LeftButton:
44
                from SymbolSvgItem import SymbolSvgItem
45
                from EngineeringLineItem import QEngineeringLineItem
46

  
47
                item = self.imageViewer.scene().itemAt(scenePos, QTransform())
48
                if item and (issubclass(type(item), SymbolSvgItem) or issubclass(type(item), QEngineeringLineItem)):
49
                    self._selected = item
50
                    self.onSuccess.emit(item)
51
                    self.isTreated = True
52
            elif 'keyPressEvent' == param[0]:
53
                if event.key() == Qt.Key_Escape:
54
                    self.onRejected.emit(self)
55
                    self.isTreated = False
56
        except Exception as ex:
57
            from App import App
58
            from AppDocData import MessageType
59

  
60
            message = f"error occurred({repr(ex)}) in {sys.exc_info()[-1].tb_frame.f_code.co_filename}:" \
61
                      f"{sys.exc_info()[-1].tb_lineno}"
62
            App.mainWnd().addMessage.emit(MessageType.Error, message)       
63

  
64
    def undo(self):
65
        pass
66

  
67
    def redo(self):
68
        pass
DTI_PID/DTI_PID/HMBDialog.py
159 159
                hmb.stream_no = stream_no
160 160
                hmb_list.append(hmb)
161 161

  
162
                stream_lines.append((stream_no, from_, to_))
162
                stream_lines.append((stream_no, None, from_, None, to_))
163 163

  
164 164
            app_doc_data = AppDocData.instance()
165 165
            app_doc_data.save_hmb_data(hmb_list)
DTI_PID/DTI_PID/MainWindow_UI.py
1 1
# -*- coding: utf-8 -*-
2 2

  
3
# Form implementation generated from reading ui file './UI/MainWindow.ui'
3
# Form implementation generated from reading ui file '.\UI\MainWindow.ui'
4 4
#
5
# Created by: PyQt5 UI code generator 5.11.3
5
# Created by: PyQt5 UI code generator 5.13.1
6 6
#
7 7
# WARNING! All changes made in this file will be lost!
8 8

  
9

  
9 10
from PyQt5 import QtCore, QtGui, QtWidgets
10 11

  
12

  
11 13
class Ui_MainWindow(object):
12 14
    def setupUi(self, MainWindow):
13 15
        MainWindow.setObjectName("MainWindow")
......
730 732
        self.toolBar.addAction(self.actionOpen)
731 733
        self.toolBar.addAction(self.actionSave)
732 734
        self.toolBar.addAction(self.actionRecognition)
733
        self.toolBar.addAction(self.actionLineRecognition)
734 735
        self.toolBar.addAction(self.actionStreamline)
736
        self.toolBar.addAction(self.actionLineRecognition)
735 737
        self.toolBar.addAction(self.actionInitialize)
736 738
        self.toolBar.addSeparator()
737 739
        self.toolBar.addAction(self.actionUndo)
......
882 884
        self.actionReadme.setText(_translate("MainWindow", "Readme"))
883 885
        self.actionImport_Text_from_CAD_for_Instrument.setText(_translate("MainWindow", "Import Text from PDF for Instrument"))
884 886
        self.actionStreamline.setText(_translate("MainWindow", "Streamline"))
885

  
886 887
import MainWindow_rc
887

  
888
if __name__ == "__main__":
889
    import sys
890
    app = QtWidgets.QApplication(sys.argv)
891
    MainWindow = QtWidgets.QMainWindow()
892
    ui = Ui_MainWindow()
893
    ui.setupUi(MainWindow)
894
    MainWindow.show()
895
    sys.exit(app.exec_())
896

  
DTI_PID/DTI_PID/StreamlineDialog.py
3 3

  
4 4
import os
5 5
import sys
6
from functools import partial
6 7
from PyQt5.QtCore import *
7 8
from PyQt5.QtGui import *
8 9
from PyQt5.QtWidgets import *
......
12 13
from UI.Streamline_UI import Ui_StreamlineDialog
13 14

  
14 15

  
16
class FromToModel(QStandardItemModel):
17
    def __init__(self, parent=None, *args):
18
        QStandardItemModel.__init__(self, parent, *args)
19

  
20
        self._need_to_pick_backcolor = QColor(255, 0, 255)
21

  
22
    def data(self, index, role):
23
        if not index.isValid():
24
            return None
25

  
26
        if role in [Qt.BackgroundRole]:
27
            if index.column() in [1, 2]:
28
                uid = super(FromToModel, self).item(index.row(), index.column()).data(Qt.UserRole)
29
                if not uid:
30
                    return self._need_to_pick_backcolor
31

  
32
        return super(FromToModel, self).data(index, role)
33

  
34

  
15 35
class FromToWidget(QWidget):
16
    def __init__(self, parent, from_to: str = ''):
36
    def __init__(self, parent, column: int, from_to: str = ''):
17 37
        QWidget.__init__(self, parent)
38
        self._column = column
18 39

  
19 40
        layout = QHBoxLayout()
20 41
        layout.setAlignment(Qt.AlignRight)
......
23 44
        pick.setIcon(QIcon(':/newPrefix/OK.svg'))
24 45
        pick.setMaximumHeight(32)
25 46
        pick.setMaximumWidth(32)
47
        pick.clicked.connect(partial(parent.parent().parent().parent().on_select_comp, self._column))
26 48
        layout.addWidget(pick)
27 49
        self.setLayout(layout)
28 50

  
......
32 54

  
33 55
    def __init__(self, parent):
34 56
        QDialog.__init__(self, parent)
57
        self._from_to_widgets = {}
35 58

  
36 59
        self.ui = Ui_StreamlineDialog()
37 60
        self.ui.setupUi(self)
......
145 168
            uid = self.ui.tableViewStreamNo.model().item(row, 0).text()
146 169

  
147 170
            if not self.ui.tableViewFromTo.model():
148
                model = QStandardItemModel()
171
                model = FromToModel()
149 172
                self.ui.tableViewFromTo.setModel(model)
150 173

  
151 174
            model = self.ui.tableViewFromTo.model()
......
171 194
            self.ui.tableViewFromTo.setModel(model)
172 195
            self.ui.tableViewFromTo.resizeColumnsToContents()
173 196

  
197
            self._from_to_widgets.clear()
174 198
            for row in range(self.ui.tableViewFromTo.model().rowCount()):
175 199
                i = self.ui.tableViewFromTo.model().index(row, 1)
176 200
                data = self.ui.tableViewFromTo.model().data(i, Qt.DisplayRole)
177
                from_button = FromToWidget(self.ui.tableViewFromTo, data)
201
                from_button = FromToWidget(self.ui.tableViewFromTo, 1, data)
178 202
                i = self.ui.tableViewFromTo.model().index(row, 1)
179 203
                self.ui.tableViewFromTo.setIndexWidget(i, from_button)
204
                self._from_to_widgets[from_button] = (row, 1)
180 205

  
181 206
                i = self.ui.tableViewFromTo.model().index(row, 2)
182 207
                data = self.ui.tableViewFromTo.model().data(i, Qt.DisplayRole)
183
                to_button = FromToWidget(self.ui.tableViewFromTo, data)
208
                to_button = FromToWidget(self.ui.tableViewFromTo, 2, data)
184 209
                self.ui.tableViewFromTo.setIndexWidget(i, to_button)
210
                self._from_to_widgets[to_button] = (row, 2)
185 211

  
186 212
            """Properties"""
187 213
            if not self.ui.tableViewProperties.model():
......
208 234
        """add a new from/to record"""
209 235
        rows = self.ui.tableViewFromTo.model().rowCount()
210 236
        index = self.ui.tableViewFromTo.model().index(rows, 0)
211
        self.ui.tableViewFromTo.model().insertRow(rows, QStandardItem())
237
        self.ui.tableViewFromTo.model().insertRow(rows, [QStandardItem(), QStandardItem(), QStandardItem()])
212 238
        self.ui.tableViewFromTo.selectionModel().setCurrentIndex(index, QItemSelectionModel.NoUpdate)
213 239

  
214
        from_button = FromToWidget(self.ui.tableViewFromTo)
240
        from_button = FromToWidget(self.ui.tableViewFromTo, 1)
215 241
        i = self.ui.tableViewFromTo.model().index(rows, 1)
216 242
        self.ui.tableViewFromTo.setIndexWidget(i, from_button)
243
        self._from_to_widgets[from_button] = (i.row(), 1)
217 244

  
218
        to_button = FromToWidget(self.ui.tableViewFromTo)
245
        to_button = FromToWidget(self.ui.tableViewFromTo, 2)
219 246
        i = self.ui.tableViewFromTo.model().index(rows, 2)
220 247
        self.ui.tableViewFromTo.setIndexWidget(i, to_button)
248
        self._from_to_widgets[to_button] = (i.row(), 2)
221 249

  
222 250
    def on_del_from_to(self):
223 251
        """delete selected from/to"""
224 252
        current = self.ui.tableViewFromTo.selectionModel().currentIndex()
225 253
        self.ui.tableViewFromTo.model().removeRow(current.row())
226 254

  
255
    def on_select_comp(self, column: int):
256
        """select from or to component"""
257
        from App import App
258
        from Commands.SelectCompCommand import SelectCompCommand
259

  
260
        def on_success_select_comp(selected):
261
            current = self.ui.tableViewFromTo.selectionModel().currentIndex()
262
            row = self.ui.tableViewFromTo.model().item(current.row(), 0)
263
            column = row.data(Qt.UserRole)
264
            item = self.ui.tableViewFromTo.model().item(current.row(), column)
265
            item.setText(str(selected))
266
            item.setData(str(selected.uid), Qt.UserRole)
267
            App.mainWnd().graphicsView.useDefaultCommand()
268

  
269
        # save column index
270
        if self.sender().parent() in self._from_to_widgets:
271
            row, column = self._from_to_widgets[self.sender().parent()]
272
            item = self.ui.tableViewFromTo.model().item(row, 0)
273
            item.setData(column, Qt.UserRole)
274
            self.ui.tableViewFromTo.setCurrentIndex(self.ui.tableViewFromTo.model().index(row, column))
275
        # up to here
276
        cmd = SelectCompCommand(App.mainWnd().graphicsView)
277
        cmd.onSuccess.connect(on_success_select_comp)
278
        App.mainWnd().graphicsView.command = cmd
279

  
227 280
    def on_save_from_to(self):
228
        pass
281
        """save current from/to data"""
282
        row = self.ui.tableViewStreamNo.selectionModel().currentIndex().row()
283
        stream_no = self.ui.tableViewStreamNo.model().item(row, 1).text()
284

  
285
        from_to_data = []
286

  
287
        model = self.ui.tableViewFromTo.model()
288
        for row in range(model.rowCount()):
289
            from_ = model.item(row, 1)
290
            from_uid = from_.data(Qt.UserRole)
291
            to_ = model.item(row, 1)
292
            to_uid = to_.data(Qt.UserRole)
293

  
294
            from_to_data.append((stream_no, from_uid, from_.text(), to_uid, to_.text()))
295

  
296
        AppDocData.save_stream_line_data(from_to_data)
229 297

  
230 298
    def accept(self):
231 299
        QDialog.accept(self)
DTI_PID/DTI_PID/UI/DisplayWidget.ui
6 6
   <rect>
7 7
    <x>0</x>
8 8
    <y>0</y>
9
    <width>94</width>
10
    <height>40</height>
9
    <width>104</width>
10
    <height>62</height>
11 11
   </rect>
12 12
  </property>
13 13
  <property name="windowTitle">
......
42 42
       </property>
43 43
      </widget>
44 44
     </item>
45
     <item row="2" column="0">
46
      <widget class="QRadioButton" name="radioButtonByStreamNo">
47
       <property name="text">
48
        <string>By Stream No</string>
49
       </property>
50
      </widget>
51
     </item>
45 52
    </layout>
46 53
   </item>
47 54
  </layout>
DTI_PID/DTI_PID/UI/MainWindow.ui
206 206
   <addaction name="actionOpen"/>
207 207
   <addaction name="actionSave"/>
208 208
   <addaction name="actionRecognition"/>
209
   <addaction name="actionLineRecognition"/>
210 209
   <addaction name="actionStreamline"/>
210
   <addaction name="actionLineRecognition"/>
211 211
   <addaction name="actionInitialize"/>
212 212
   <addaction name="separator"/>
213 213
   <addaction name="actionUndo"/>

내보내기 Unified diff

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