프로젝트

일반

사용자정보

통계
| 개정판:

hytos / DTI_PID / DTI_PID / Shapes / EngineeringInstrumentItem.py @ 6d011c3c

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

1
# coding: utf-8
2
"""
3
This is Engineering Instrument Item module
4
"""
5

    
6
import sys
7
import os
8
import math
9
from PyQt5.QtGui import *
10
from PyQt5.QtCore import *
11
from PyQt5.QtSvg import *
12
from PyQt5.QtWidgets import (QApplication, QGraphicsItem)
13

    
14
from SymbolSvgItem import SymbolSvgItem
15
from EngineeringAbstractItem import QEngineeringAbstractItem
16
from EngineeringConnectorItem import QEngineeringConnectorItem
17
from EngineeringTextItem import QEngineeringTextItem
18
from UserInputAttribute import UserInputAttribute
19

    
20

    
21
class QEngineeringInstrumentItem(SymbolSvgItem):
22
    """ This is Engineering Instrument Item class """
23
    clicked = pyqtSignal(QGraphicsSvgItem)
24
    INST_COLUMN_LIST = None
25
    INST_COLOR = None
26

    
27
    '''
28
    '''
29

    
30
    def __init__(self, path, uid=None, flip=0):
31
        SymbolSvgItem.__init__(self, None, path, uid, flip=flip)
32

    
33
        self._measuredVairableCode = None
34
        self._typeModifier = None
35
        self._tagSeqNo = None
36
        self._tagSuffix = None
37

    
38
        '''
39
        if QEngineeringInstrumentItem.INST_COLUMN_LIST is None:
40
            from AppDocData import AppDocData
41

42
            appDocData = AppDocData.instance()
43
            QEngineeringInstrumentItem.INST_COLUMN_LIST = appDocData.getColNames('INSTRUMENT_DATA_LIST')
44
        '''
45

    
46
    '''
47
        @brief  getter of measured variable code
48
        @author humkyung
49
        @date   2018.05.06
50
    '''
51

    
52
    @property
53
    def measuredVariableCode(self):
54
        return self._measuredVairableCode
55

    
56
    '''
57
        @brief  setter of measured variable code
58
        @author humkyung
59
        @date   2018.05.06
60
    '''
61

    
62
    @measuredVariableCode.setter
63
    def measuredVariableCode(self, value):
64
        self._measuredVairableCode = value
65

    
66
    '''
67
        @brief  getter of type modifier
68
        @author humkyung
69
        @date   2018.05.06
70
    '''
71

    
72
    @property
73
    def typeModifier(self):
74
        return self._typeModifier
75

    
76
    '''
77
        @brief  setter of type modifier
78
        @author humkyung
79
        @date   2018.05.06
80
    '''
81

    
82
    @typeModifier.setter
83
    def typeModifier(self, value):
84
        self._typeModifier = value
85

    
86
    '''
87
        @brief  getter of tag seq no
88
        @author humkyung
89
        @date   2018.05.06
90
    '''
91

    
92
    @property
93
    def tagSeqNo(self):
94
        return self._tagSeqNo
95

    
96
    '''
97
        @brief  setter of tag seq no
98
        @author humkyung
99
        @date   2018.05.06
100
    '''
101

    
102
    @tagSeqNo.setter
103
    def tagSeqNo(self, value):
104
        self._tagSeqNo = value
105

    
106
    '''
107
        @brief  getter of tag suffix
108
        @author humkyung
109
        @date   2018.05.06
110
    '''
111

    
112
    @property
113
    def tagSuffix(self):
114
        return self._tagSuffix
115

    
116
    '''
117
        @brief  setter of tag suffix
118
        @author humkyung
119
        @date   2018.05.06
120
    '''
121

    
122
    @tagSuffix.setter
123
    def tagSuffix(self, value):
124
        self._tagSuffix = value
125

    
126
    def highlight(self, flag):
127
        """ highlight/unhighlight the instrument """
128

    
129
        try:
130
            self.hover = flag
131
            self.update()
132

    
133
            for assoc in self.associations():
134
                assoc.highlight(flag)
135

    
136
            for connector in self.connectors:
137
                connector.highlight(flag)
138
        except Exception as ex:
139
            from App import App
140
            from AppDocData import MessageType
141

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

    
146
    def getColor(self):
147
        """ return instrument's color 2019.04.24 adde by humkyung """
148
        from AppDocData import AppDocData
149
        from DisplayColors import DisplayColors
150
        from DisplayColors import DisplayOptions
151
        from EngineeringAbstractItem import QEngineeringAbstractItem
152
        from EngineeringLineItem import QEngineeringLineItem
153

    
154
        if DisplayOptions.DisplayByLineType == DisplayColors.instance().option:
155
            if self.hover:
156
                return SymbolSvgItem.HOVER_COLOR
157
            elif not QEngineeringInstrumentItem.INST_COLOR:
158
                app_doc_data = AppDocData.instance()
159
                configs = app_doc_data.getConfigs('Instrument', 'Color')
160
                QEngineeringInstrumentItem.INST_COLOR = configs[
161
                    0].value if configs else QEngineeringAbstractItem.DEFAULT_COLOR
162

    
163
            return QEngineeringInstrumentItem.INST_COLOR
164
        else:
165
            return SymbolSvgItem.getColor(self)
166

    
167
    '''
168
        @brief  connect attribute
169
        @author humkyung
170
        @date   2018.05.06
171
    '''
172

    
173
    def connectAttribute(self, attributes, clear=True):
174
        from AppDocData import AppDocData
175

    
176
        try:
177
            if clear:
178
                if not self.clear_attr_and_assoc_item():
179
                    return
180

    
181
            rect = self.sceneBoundingRect()
182

    
183
            minDist = None
184
            selected = None
185

    
186
            configs = AppDocData.instance().getConfigs('Range', 'Detection Ratio')
187
            ratio = float(configs[0].value) if 1 == len(configs) else 1.5
188

    
189
            dist = (self.sceneBoundingRect().height() + self.sceneBoundingRect().width()) * ratio / 2
190
            center = [self.origin[0], self.origin[1]]
191

    
192
            for attr in attributes:
193
                if issubclass(type(attr), QEngineeringTextItem):
194
                    if rect.contains(attr.center()):
195
                        if self.add_assoc_item(attr):
196
                            attr.owner = self  # set owner of text
197

    
198
                elif issubclass(type(attr), SymbolSvgItem) and attr is not self:
199
                    dx = attr.origin[0] - center[0]
200
                    dy = attr.origin[1] - center[1]
201

    
202
                    length = math.sqrt(dx * dx + dy * dy)
203

    
204
                    if (length < dist) and (minDist is None or length < minDist):
205
                        minDist = length
206
                        selected = attr
207

    
208
            if selected is not None:
209
                self.add_assoc_item(selected)
210

    
211
        except Exception as ex:
212
            from App import App
213
            from AppDocData import MessageType
214

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

    
219
    '''
220
        @brief  generate xml code for attribute
221
        @author humkyung
222
        @date   2018.05.06
223
    '''
224

    
225
    def toXmlAsAttribute(self, parentNode):
226
        from xml.etree.ElementTree import Element, SubElement, dump, ElementTree
227

    
228
        try:
229
            attrNode = Element('ATTRIBUTE')
230

    
231
            uidNode = Element('UID')
232
            uidNode.text = str(self.uid)
233
            attrNode.append(uidNode)
234

    
235
            nameNode = Element('NAME')
236
            nameNode.text = 'Measured Variable Code'
237
            attrNode.append(nameNode)
238

    
239
            valueNode = Element('VALUE')
240
            valueNode.text = self.measuredVariableCode
241
            attrNode.append(valueNode)
242

    
243
            parentNode.append(attrNode)
244
        except Exception as ex:
245
            print('error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename,
246
                                                      sys.exc_info()[-1].tb_lineno))
247

    
248
        try:
249
            attrNode = Element('ATTRIBUTE')
250

    
251
            uidNode = Element('UID')
252
            uidNode.text = str(self.uid)
253
            attrNode.append(uidNode)
254

    
255
            nameNode = Element('NAME')
256
            nameNode.text = 'Type Modifier'
257
            attrNode.append(nameNode)
258

    
259
            valueNode = Element('VALUE')
260
            valueNode.text = self.typeModifier
261
            attrNode.append(valueNode)
262

    
263
            parentNode.append(attrNode)
264
        except Exception as ex:
265
            print('error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename,
266
                                                      sys.exc_info()[-1].tb_lineno))
267

    
268
        try:
269
            attrNode = Element('ATTRIBUTE')
270

    
271
            uidNode = Element('UID')
272
            uidNode.text = str(self.uid)
273
            attrNode.append(uidNode)
274

    
275
            nameNode = Element('NAME')
276
            nameNode.text = 'Tag Seq No'
277
            attrNode.append(nameNode)
278

    
279
            valueNode = Element('VALUE')
280
            valueNode.text = self.tagSeqNo
281
            attrNode.append(valueNode)
282

    
283
            parentNode.append(attrNode)
284
        except Exception as ex:
285
            print('error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename,
286
                                                      sys.exc_info()[-1].tb_lineno))
287

    
288
        try:
289
            attrNode = Element('ATTRIBUTE')
290

    
291
            uidNode = Element('UID')
292
            uidNode.text = str(self.uid)
293
            attrNode.append(uidNode)
294

    
295
            nameNode = Element('NAME')
296
            nameNode.text = 'Tag Suffix'
297
            attrNode.append(nameNode)
298

    
299
            valueNode = Element('VALUE')
300
            valueNode.text = self.tagSuffix
301
            attrNode.append(valueNode)
302

    
303
            parentNode.append(attrNode)
304
        except Exception as ex:
305
            print('error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename,
306
                                                      sys.exc_info()[-1].tb_lineno))
307

    
308
    '''
309
        @brief      return inst Data List
310
        @author     kyouho
311
        @date       2018.08.14
312
    '''
313

    
314
    def getInstrumentDataList(self):
315
        dataList = []
316
        try:
317
            from AppDocData import AppDocData
318

    
319
            docData = AppDocData.instance()
320
            attrs = self.getAttributes()
321

    
322
            for index in range(len(QEngineeringInstrumentItem.INST_COLUMN_LIST)):
323
                dataList.append('')
324

    
325
            dataList[0] = str(self.uid)
326
            dataList[13] = docData.imgName
327

    
328
            for key in attrs.keys():
329
                attrInfo = docData.getSymbolAttributeByUID(key.UID)
330
                attrName = attrInfo.Attribute
331
                if attrName in QEngineeringInstrumentItem.INST_COLUMN_LIST:
332
                    colIndex = QEngineeringInstrumentItem.INST_COLUMN_LIST.index(attrName)
333
                    dataList[colIndex] = attrs[key]
334
        except Exception as ex:
335
            from App import App
336
            from AppDocData import MessageType
337

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

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