프로젝트

일반

사용자정보

통계
| 개정판:

hytos / DTI_PID / DTI_PID / Shapes / EngineeringSpecBreakItem.py @ fceaf69c

이력 | 보기 | 이력해설 | 다운로드 (9.3 KB)

1
# coding: utf-8
2

    
3
import sys
4
import os
5
import math
6
from PyQt5.QtGui import *
7
from PyQt5.QtCore import *
8
from PyQt5.QtSvg import *
9
from PyQt5.QtWidgets import QApplication, QGraphicsItem, QGraphicsTextItem
10

    
11
from SymbolSvgItem import SymbolSvgItem
12
from SymbolAttr import SymbolAttr
13
#from UserInputAttribute import UserInputAttribute
14
from EngineeringConnectorItem import QEngineeringConnectorItem
15
from AppDocData import AppDocData
16

    
17
from EngineeringFromMarkItem import EngineeringFromMarkItem
18
from EngineeringToMarkItem import EngineeringToMarkItem
19

    
20
class QEngineeringSpecBreakItem(SymbolSvgItem):
21
    """ This is engineering specbreak item class """
22

    
23
    ZVALUE = 20
24
    clicked = pyqtSignal(QGraphicsSvgItem)
25

    
26
    '''
27
    '''
28
    def __init__(self, path, uid=None, flip=0):
29
        from SymbolAttr import SymbolProp        
30
        SymbolSvgItem.__init__(self, None, path, uid, flip=flip)
31

    
32
        '''
33
        attr = SymbolAttr()
34
        attr.Attribute = 'UpStream'
35
        attr.AttributeType = 'Comp Item'
36
        self.attrs[attr] = None
37
        attr = SymbolAttr()
38
        attr.Attribute = 'DownStream'
39
        attr.AttributeType = 'Comp Item'
40
        self.attrs[attr] = None
41
        '''
42
        '''
43
        specBreakAttrs = AppDocData.instance().getSymbolAttribute('Segment Breaks')
44
        self.attrs[[up for up in specBreakAttrs if up.Attribute == 'UpStream'][0]] = None
45
        self.attrs[[down for down in specBreakAttrs if down.Attribute == 'DownStream'][0]] = None
46
        '''
47

    
48
        self._properties = \
49
            {\
50
                SymbolProp(None, 'Freeze', 'Boolean'):False,
51
                SymbolProp(None, 'Show', 'Boolean'):False
52
            }
53

    
54
    def is_connected(self, item):
55
        """ check if given item is connected to spec break """
56
        import uuid
57

    
58
        matches = [(attr,value) for attr,value in self.attrs.items() if (attr.Attribute == 'UpStream' or attr.Attribute == 'DownStream')]
59
        for match in matches:
60
            if (type(match[1]) is uuid.UUID) and (match[1] == item.uid):
61
                return True
62
            elif not (type(match[1]) is uuid.UUID) and (match[1] == item):
63
                return True
64

    
65
        return False
66

    
67
    def hoverEnterEvent(self, event):
68
        super().hoverEnterEvent(event)
69

    
70
        try:
71
            # display Up / Down indicator
72
            add_doc_data = AppDocData.instance()
73
            attrs = self.getAttributes()
74
            up = [attr.AssocItem for attr in attrs if attr.Attribute == 'UpStream' and attr.AssocItem]
75
            down = [attr.AssocItem for attr in attrs if attr.Attribute == 'DownStream' and attr.AssocItem]
76
            if not add_doc_data.SpecBreakUpDownIndicator or len(add_doc_data.SpecBreakUpDownIndicator) < 2:
77
                if up and down:
78
                    for item in [up[0], down[0]]:
79
                        _label = EngineeringFromMarkItem(10) \
80
                            if not add_doc_data.SpecBreakUpDownIndicator else EngineeringToMarkItem(10)
81
                        _label.setZValue(500)
82
                        self.scene().addItem(_label)
83
                        _label.setPos(QPointF(item.origin[0] - 25, item.origin[1] - 25))
84
                        add_doc_data.SpecBreakUpDownIndicator.append(_label)
85
            elif add_doc_data.SpecBreakUpDownIndicator:
86
                if up and down:
87
                    add_doc_data.SpecBreakUpDownIndicator[0].setPos(QPointF(up[0].origin[0] - 25, up[0].origin[1] - 25))
88
                    add_doc_data.SpecBreakUpDownIndicator[0].setVisible(True)
89
                    add_doc_data.SpecBreakUpDownIndicator[1].setPos(QPointF(down[0].origin[0] - 25, down[0].origin[1] - 25))
90
                    add_doc_data.SpecBreakUpDownIndicator[1].setVisible(True)
91
            # up to here
92
        except Exception as ex:
93
            from App import App
94
            from AppDocData import MessageType
95

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

    
100
    def hoverLeaveEvent(self, event):
101
        super().hoverLeaveEvent(event)
102

    
103
        try:
104
            add_doc_data = AppDocData.instance()
105
            if add_doc_data.SpecBreakUpDownIndicator:
106
                for _label in add_doc_data.SpecBreakUpDownIndicator:
107
                    _label.setVisible(False)
108
        except Exception as ex:
109
            from App import App
110
            from AppDocData import MessageType
111

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

    
116
    '''
117
        @brief      get attribute
118
        @author     humkyung
119
        @date       2018.06.14
120
        @history    kyouho  2018.07.18  Add only attr QEngineeringTextItem
121
                    euisung 2019.01.15  return self.attrs
122
    def getAttributes(self):
123
        """ attributes MUST have UpStream, DownStream attribute """
124
        from AppDocData import AppDocData
125
        if not len(self.attrs):
126
            specBreakAttrs = AppDocData.instance().getSymbolAttribute('Segment Breaks')
127
            self.attrs[[up for up in specBreakAttrs if up.Attribute == 'UpStream'][0]] = None
128
            self.attrs[[down for down in specBreakAttrs if down.Attribute == 'DownStream'][0]] = None
129

130
        for attr, value in self.attrs.items():
131
            if attr.AttributeType != 'Spec' and attr.AssocItem:
132
                self.attrs[attr] = str(attr.AssocItem)
133
        return self.attrs
134
    '''
135

    
136
    @property
137
    def up_stream(self):
138
        """ return up stream attribute """
139
        matches = [self.attrs[attr] for attr in self.attrs if attr.Attribute == 'UpStream']
140
        return matches[0] if matches else None
141

    
142
    @property
143
    def down_stream(self):
144
        """ return down stream attribute """
145
        matches = [self.attrs[attr] for attr in self.attrs if attr.Attribute == 'DownStream']
146
        return matches[0] if matches else None
147

    
148
    def validate(self, rules):
149
        """ validate specbreak item """
150
        from AppDocData import AppDocData
151
        from EngineeringAbstractItem import QEngineeringAbstractItem
152
        from SymbolSvgItem import SymbolSvgItem
153
        from ValidateCommand import SymbolValidation
154

    
155
        errors = []
156

    
157
        app_doc_data = AppDocData.instance()
158
        dataPath = app_doc_data.getErrorItemSvgPath()
159
        # UpStream and DownStream must be connected
160
        if not (self.up_stream and self.down_stream):
161
            if SymbolValidation.UpStreamOrDownStreamIsDisconnected in rules:
162
                error = SymbolSvgItem.createItem('Error', None, dataPath)
163
                error.parent = self
164
                error.msg = self.tr('UpStream or DownStream is disconnected')
165
                error.setToolTip(error.msg)
166
                error.area = 'Drawing'
167
                error.name = 'Error'
168
                errors.append(error)
169
        elif self.up_stream and self.down_stream:
170
            up_stream_item = [x for x in self.scene().items() if hasattr(x, 'uid') and str(x.uid) == str(self.up_stream)]
171
            down_stream_item = [x for x in self.scene().items() if hasattr(x, 'uid') and str(x.uid) == str(self.down_stream)]
172
            if not (up_stream_item and down_stream_item):
173
                if SymbolValidation.UpStreamOrDownStreamIsNone in rules:
174
                    error = SymbolSvgItem.createItem('Error', None, dataPath)
175
                    error.parent = self
176
                    error.msg = self.tr('UpStream or DownStream is None')
177
                    error.setToolTip(error.msg)
178
                    error.area = 'Drawing'
179
                    error.name = 'Error'
180
                    errors.append(error)
181
            else:
182
                if SymbolValidation.UpStreamAndDownStreamIsMisconnected in rules:
183
                    connected = [False, False]
184
                    for connector in up_stream_item[0].connectors:
185
                        if connector.connectedItem == down_stream_item[0]:
186
                            connected[0] = True
187
                            if connector._connected_at == QEngineeringAbstractItem.CONNECTED_AT_BODY:
188
                                connected[1] = True
189

    
190
                    if connected[1] == False:
191
                        for connector in down_stream_item[0].connectors:
192
                            if connector.connectedItem == up_stream_item[0]:
193
                                connected[1] = True
194
                                if connector._connected_at == QEngineeringAbstractItem.CONNECTED_AT_BODY:
195
                                    connected[0] = True
196

    
197
                    if not (connected[0] and connected[1]):
198
                        error = SymbolSvgItem.createItem('Error', None, dataPath)
199
                        error.parent = self
200
                        error.msg = self.tr('UpStream and DownStream is misconnected')
201
                        error.setToolTip(error.msg)
202
                        error.area = 'Drawing'
203
                        error.name = 'Error'
204
                        error.items = [ up_stream_item[0], down_stream_item[0] ]
205
                        errors.append(error)
206

    
207
        # set error position
208
        for error in errors:
209
            error.setPosition([self.sceneBoundingRect().center().x(), self.sceneBoundingRect().center().y()])
210

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