프로젝트

일반

사용자정보

통계
| 개정판:

hytos / DTI_PID / DTI_PID / Shapes / EngineeringInstrumentItem.py @ a4806b86

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

1 90739b5c humkyung
# coding: utf-8
2 9100a182 humkyung
"""
3
This is Engineering Instrument Item module
4
"""
5 90739b5c humkyung
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 57ab567c humkyung
from EngineeringConnectorItem import QEngineeringConnectorItem
16 eb71581d gaqhf
from EngineeringTextItem import QEngineeringTextItem
17 357646b0 gaqhf
from UserInputAttribute import UserInputAttribute
18 90739b5c humkyung
19
class QEngineeringInstrumentItem(SymbolSvgItem):
20 9100a182 humkyung
    """
21
    This is Engineering Instrument Item class
22
    """
23 90739b5c humkyung
    clicked = pyqtSignal(QGraphicsSvgItem)
24 820ed509 humkyung
    INST_COLUMN_LIST = None 
25 90739b5c humkyung
26
    '''
27
    '''
28 d5fe6ee9 esham21
    def __init__(self, path, uid=None, flip=None):
29
        SymbolSvgItem.__init__(self, path, uid, flip=flip)
30 90739b5c humkyung
31 1430097d humkyung
        self._measuredVairableCode = None
32
        self._typeModifier = None
33
        self._tagSeqNo = None
34
        self._tagSuffix = None
35
36 d77477f8 humkyung
        if QEngineeringInstrumentItem.INST_COLUMN_LIST is None:
37
            from AppDocData import AppDocData
38
39
            appDocData = AppDocData.instance()
40
            QEngineeringInstrumentItem.INST_COLUMN_LIST = appDocData.getColNames('INSTRUMENT_DATA_LIST')
41
42 4b4d954c humkyung
    def texts(self):
43
        """
44
        return text type of labels
45
        """
46
        from EngineeringTextItem import QEngineeringTextItem
47
48 820ed509 humkyung
        return sorted([x for x in self.associations() if issubclass(type(x), QEngineeringTextItem)], key=lambda attr: attr.loc[1])
49 4b4d954c humkyung
50 90739b5c humkyung
    '''
51
        @brief  getter of measured variable code
52
        @author humkyung
53
        @date   2018.05.06
54
    '''
55
    @property
56
    def measuredVariableCode(self):
57
        return self._measuredVairableCode
58
59
    '''
60
        @brief  setter of measured variable code
61
        @author humkyung
62
        @date   2018.05.06
63
    '''
64
    @measuredVariableCode.setter
65
    def measuredVariableCode(self, value):
66
        self._measuredVairableCode = value
67
68
    '''
69
        @brief  getter of type modifier
70
        @author humkyung
71
        @date   2018.05.06
72
    '''
73
    @property
74
    def typeModifier(self):
75
        return self._typeModifier
76
    
77
    '''
78
        @brief  setter of type modifier
79
        @author humkyung
80
        @date   2018.05.06
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
    @property
92
    def tagSeqNo(self):
93
        return self._tagSeqNo
94
    
95
    '''
96
        @brief  setter of tag seq no
97
        @author humkyung
98
        @date   2018.05.06
99
    '''
100
    @tagSeqNo.setter
101
    def tagSeqNo(self, value):
102
        self._tagSeqNo = value
103
104
    '''
105
        @brief  getter of tag suffix
106
        @author humkyung
107
        @date   2018.05.06
108
    '''
109
    @property
110
    def tagSuffix(self):
111
        return self._tagSuffix
112
113
    '''
114
        @brief  setter of tag suffix
115
        @author humkyung
116
        @date   2018.05.06
117
    '''
118
    @tagSuffix.setter
119
    def tagSuffix(self, value):
120
        self._tagSuffix = value
121
122
    '''
123
        @brief  connect attribute
124
        @author humkyung
125
        @date   2018.05.06
126
    '''
127
    def connectAttribute(self, attributes):
128 820ed509 humkyung
        self._associations.clear()
129 90739b5c humkyung
130 be3e0c2d humkyung
        try:
131
            rect = self.sceneBoundingRect()
132
            for attr in attributes:
133
                if rect.contains(attr.center()):
134
                    if issubclass(type(attr), QEngineeringTextItem):
135 85a460a6 humkyung
                        attr.owner = self  # set owner of text
136 820ed509 humkyung
                        self.add_assoc_item(attr)
137 be3e0c2d humkyung
                    elif issubclass(type(attr), SymbolSvgItem):
138 85a460a6 humkyung
                        attr._owner = self.uid  # set owner of symbol
139 820ed509 humkyung
                        self.add_assoc_item(attr)
140 be3e0c2d humkyung
        except Exception as ex:
141
            from App import App 
142
            from AppDocData import MessageType
143
144
            message = 'error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno)
145
            App.mainWnd().addMessage.emit(MessageType.Error, message)
146 90739b5c humkyung
147 18f21a9a humkyung
    '''
148
        @brief      get attributes
149
        @author     humkyung
150
        @date       2018.06.14
151
    '''
152
    def getAttributes(self):
153 9100a182 humkyung
        _attrs = {}
154 18f21a9a humkyung
        try:
155 95bd7003 gaqhf
            from AppDocData import AppDocData
156
            from EngineeringTextItem import QEngineeringTextItem
157
158
            # 해당 Type의 attribute setting
159
            docData = AppDocData.instance()
160
            symbolAttrs = docData.getSymbolAttribute(self.type)
161 4b4d954c humkyung
            _texts = self.texts()
162
            _symbols = self.symbols()
163 95bd7003 gaqhf
            for attr in symbolAttrs:
164 a4806b86 humkyung
                if attr.AttributeType == 'Size Text Item' or attr.AttributeType == 'Text Item' or attr.AttributeType == 'Valve Oper Code':
165 9100a182 humkyung
                    at = int(attr.AttrAt)
166 a4806b86 humkyung
                    items = [text for text in _texts if self.assoc_type(text) == attr.AttributeType]
167
                    if len(items) > at:
168
                        item = items[at]
169 9100a182 humkyung
                        _attrs[attr] = eval(attr.Expression) if attr.Expression else ''
170
                    else:
171
                        _attrs[attr] = ''
172
                elif attr.AttributeType == 'Symbol Item':
173
                    at = int(attr.AttrAt)
174 4b4d954c humkyung
                    if len(_symbols) > at:
175
                        item = _symbols[at]
176 9100a182 humkyung
                        _attrs[attr] = eval(attr.Expression) if attr.Expression else ''
177
                    else:
178
                        _attrs[attr] = ''
179
                else:
180 ef4495fd humkyung
                    matches = [prop for prop in self.attrs if prop.UID == attr.UID]
181
                    if len(matches) == 1:
182
                        _attrs[matches[0]] = self.attrs[matches[0]]
183
                    else:
184
                        _attrs[attr] = ''
185 18f21a9a humkyung
        except Exception as ex:
186 b8d39c65 humkyung
            from App import App 
187
            from AppDocData import MessageType
188
189
            message = 'error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno)
190
            App.mainWnd().addMessage.emit(MessageType.Error, message)
191 18f21a9a humkyung
        
192 9100a182 humkyung
        return _attrs
193 90739b5c humkyung
194
    '''
195
        @brief  generate xml code for attribute
196
        @author humkyung
197
        @date   2018.05.06
198
    '''
199 5fbc4298 humkyung
    def toXmlAsAttribute(self, parentNode):
200 90739b5c humkyung
        from xml.etree.ElementTree import Element, SubElement, dump, ElementTree
201
202
        try:
203
            attrNode = Element('ATTRIBUTE')
204
205
            uidNode = Element('UID')
206 5fbc4298 humkyung
            uidNode.text = str(self.uid)
207 90739b5c humkyung
            attrNode.append(uidNode)
208
209
            nameNode = Element('NAME')
210
            nameNode.text = 'Measured Variable Code'
211
            attrNode.append(nameNode)
212
213
            valueNode = Element('VALUE')
214
            valueNode.text = self.measuredVariableCode
215
            attrNode.append(valueNode)
216
217 5fbc4298 humkyung
            parentNode.append(attrNode) 
218 90739b5c humkyung
        except Exception as ex:
219
            print('error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno))
220
221
        try:
222
            attrNode = Element('ATTRIBUTE')
223
224
            uidNode = Element('UID')
225 5fbc4298 humkyung
            uidNode.text = str(self.uid)
226 90739b5c humkyung
            attrNode.append(uidNode)
227
228
            nameNode = Element('NAME')
229
            nameNode.text = 'Type Modifier'
230
            attrNode.append(nameNode)
231
232
            valueNode = Element('VALUE')
233
            valueNode.text = self.typeModifier
234
            attrNode.append(valueNode)
235
236 5fbc4298 humkyung
            parentNode.append(attrNode) 
237 90739b5c humkyung
        except Exception as ex:
238
            print('error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno))
239
240
        try:
241
            attrNode = Element('ATTRIBUTE')
242
243
            uidNode = Element('UID')
244 5fbc4298 humkyung
            uidNode.text = str(self.uid)
245 90739b5c humkyung
            attrNode.append(uidNode)
246
247
            nameNode = Element('NAME')
248
            nameNode.text = 'Tag Seq No'
249
            attrNode.append(nameNode)
250
251
            valueNode = Element('VALUE')
252
            valueNode.text = self.tagSeqNo
253
            attrNode.append(valueNode)
254
255 5fbc4298 humkyung
            parentNode.append(attrNode) 
256 90739b5c humkyung
        except Exception as ex:
257
            print('error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno))
258
259
        try:
260
            attrNode = Element('ATTRIBUTE')
261
262
            uidNode = Element('UID')
263 5fbc4298 humkyung
            uidNode.text = str(self.uid)
264 90739b5c humkyung
            attrNode.append(uidNode)
265
266
            nameNode = Element('NAME')
267
            nameNode.text = 'Tag Suffix'
268
            attrNode.append(nameNode)
269
270
            valueNode = Element('VALUE')
271
            valueNode.text = self.tagSuffix
272
            attrNode.append(valueNode)
273
274 5fbc4298 humkyung
            parentNode.append(attrNode) 
275 90739b5c humkyung
        except Exception as ex:
276 d1576bff 김정우
            print('error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno))
277 8804d0d9 gaqhf
278 1df9adbf humkyung
    def toSql(self):
279
        """
280
        convert instrument data to sql query
281
        """
282
        from AppDocData import AppDocData
283
284 51a72882 esham21
        appDocData = AppDocData.instance()
285 1df9adbf humkyung
286
        cols = ['UID', 'PNID_NO']
287
        values = ['?','?']
288
        param = [str(self.uid), appDocData.activeDrawing.name]
289
        _attrs = self.getAttributes()
290
        for key in _attrs.keys():
291
            cols.append(key.Attribute)
292
            values.append('?')
293
            param.append(_attrs[key])
294
295
        sql = 'insert or replace into INSTRUMENT_DATA_LIST({}) values({})'.format(','.join(cols), ','.join(values))
296 673d8cba esham21
297 1df9adbf humkyung
        return (sql, tuple(param))
298
299 d1a02244 gaqhf
    '''
300
        @brief      return inst Data List
301 8804d0d9 gaqhf
        @author     kyouho
302
        @date       2018.08.14
303
    '''
304
    def getInstrumentDataList(self):
305
        dataList = []
306
        try:
307
            from AppDocData import AppDocData
308
309
            docData = AppDocData.instance()
310 06e5d695 esham21
            attrs = self.getAttributes()
311 8804d0d9 gaqhf
312 d77477f8 humkyung
            for index in range(len(QEngineeringInstrumentItem.INST_COLUMN_LIST)):
313 8804d0d9 gaqhf
                dataList.append('')
314
315 d1a02244 gaqhf
            dataList[0] = str(self.uid)
316 8804d0d9 gaqhf
            dataList[13] = docData.imgName
317
318 d77477f8 humkyung
            for key in attrs.keys():
319
                attrInfo = docData.getSymbolAttributeByUID(key.UID)
320
                attrName = attrInfo.Attribute
321
                if attrName in QEngineeringInstrumentItem.INST_COLUMN_LIST:
322
                    colIndex = QEngineeringInstrumentItem.INST_COLUMN_LIST.index(attrName)
323
                    dataList[colIndex] = attrs[key]
324 8804d0d9 gaqhf
        except Exception as ex:
325 d77477f8 humkyung
            from App import App 
326
            from AppDocData import MessageType
327 8804d0d9 gaqhf
328 d77477f8 humkyung
            message = 'error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno)
329
            App.mainWnd().addMessage.emit(MessageType.Error, message)
330 d1a02244 gaqhf
331 d77477f8 humkyung
        return dataList