프로젝트

일반

사용자정보

개정판 6795de66

ID6795de668e79a3acc87f3d8fd6b169d9d04900cf
상위 fe6060ea
하위 ad06449c

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

issue #563: spec break manual

Change-Id: I186766d68567b05d900704a6b8852f6ff866255f

차이점 보기:

DTI_PID/DTI_PID/Commands/SelectAttributeBatchCommand.py
1
import sys
2
import os.path
3
import AbstractCommand
4
from AppDocData import AppDocData
5
from CodeTables import CodeTable
6

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

  
18
'''
19
    QtImageViewer Select Attribute batch Command
20
'''
21
class SelectAttributeBatchCommand(AbstractCommand.AbstractCommand):
22
    onSuccess = pyqtSignal()
23

  
24
    def __init__(self, item, imageViewer):
25
        super(SelectAttributeBatchCommand, self).__init__(imageViewer)
26
        self.name = 'SelectAttributeBatch'
27
        self.imageViewer.setCursor(QCursor(Qt.ArrowCursor))
28

  
29
        #self.imageViewer.scene().clearSelection()
30
        self.selection_order = [item]
31
    
32
    def execute(self, param):
33
        from SymbolSvgItem import SymbolSvgItem
34
        from EngineeringSpecBreakItem import QEngineeringSpecBreakItem
35
        from EngineeringLineItem import QEngineeringLineItem
36
        from EngineeringTextItem import QEngineeringTextItem
37

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

  
41
        try:
42
            self.isTreated = False
43
            if 'mouseReleaseEvent' == param[0] and event.button() == Qt.LeftButton and event.modifiers() == Qt.ControlModifier:
44
                items = [item for item in self.imageViewer.scene().items(scenePos) \
45
                        if issubclass(type(item), SymbolSvgItem) or issubclass(type(item), QEngineeringTextItem) or type(item) is QEngineeringLineItem]
46
                if not items:
47
                    return
48
                else:
49
                    item = items[0]
50

  
51
                selected_items = self.imageViewer.scene().selectedItems()
52
                selected_items.append(item)
53

  
54
                if len(selected_items) == len(self.selection_order) + 1:
55
                    self.selection_order.append([item for item in selected_items if item not in self.selection_order][0])
56

  
57
            elif 'mouseReleaseEvent' == param[0]:
58
                self.isTreated = True
59
            elif ('keyPressEvent' == param[0] and Qt.Key_Return == event.key()):
60
                self.isTreated = True
61

  
62
                app_doc_data = AppDocData.instance()
63
                
64
                item = self.selection_order.pop(0)
65
                stream = [item for item in self.selection_order if issubclass(type(item), SymbolSvgItem) or type(item) is QEngineeringLineItem]
66
                values = [item for item in self.selection_order if issubclass(type(item), QEngineeringTextItem)]
67
                if len(stream) != 2 or len(values) % 2 !=0:
68
                    return
69

  
70
                spec = [stream[0], stream[1]]
71

  
72
                specBreakAttrsFull = [attr for attr in app_doc_data.getSymbolAttribute('Segment Breaks') if \
73
                            attr.Target == 'ALL' and (attr.AttributeType == 'Spec' or attr.AttributeType == 'String')]
74

  
75
                for attr in specBreakAttrsFull:
76
                    if attr.AttributeType != 'Spec':
77
                        continue
78

  
79
                    table = CodeTable.instance(attr.Attribute)
80
                    for index in range(0, len(values), 2):
81
                        up_value = table.find_match_exactly(values[index].text())
82
                        down_value = table.find_match_exactly(values[index + 1].text())
83
                        if up_value and down_value:
84
                            values[index].setPlainText(up_value)
85
                            values[index + 1].setPlainText(down_value)
86
                            spec.append([attr.Attribute, up_value, down_value])
87
                            break
88

  
89
                if len(spec) < 3:
90
                    return
91

  
92
                attrs = item.getAttributes()
93
                for key in attrs.keys():
94
                    if key.Attribute == 'UpStream':
95
                        attrs[key] = str(spec[0])
96
                        item.add_assoc_item(spec[0], key.AttrAt, force=True)
97
                        key.AssocItem = spec[0]
98
                    elif key.Attribute == 'DownStream':
99
                        attrs[key] = str(spec[1])
100
                        item.add_assoc_item(spec[1], key.AttrAt, force=True)
101
                        key.AssocItem = spec[1]
102

  
103
                for attr, value, value2 in spec[2:]:
104
                    for full in specBreakAttrsFull:
105
                        if full.Attribute == attr:
106
                            attrs[full] = [value, value2]
107

  
108
                self.onSuccess.emit()
109
                            
110
        except Exception as ex:
111
            from App import App 
112
            from AppDocData import MessageType
113

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

  
117
    def undo(self):
118
        pass
119

  
120
    def redo(self):
121
        pass

내보내기 Unified diff

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