프로젝트

일반

사용자정보

통계
| 브랜치(Branch): | 개정판:

hytos / DTI_PID / DTI_PID / Shapes / QEngineeringLineNoTextItem.py @ c0e67dd5

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

1
# coding: utf-8
2
import os.path
3
import sys
4
import copy
5
try:
6
    from PyQt5.QtCore import Qt, QPointF, QRectF, pyqtSignal, QT_VERSION_STR, QRect
7
    from PyQt5.QtGui import QImage, QPixmap, QPainterPath, QBrush, QPen, QTransform, QFont
8
    from PyQt5.QtWidgets import QGraphicsView, QGraphicsScene, QFileDialog, QGraphicsItem, QAbstractGraphicsShapeItem, QGraphicsTextItem
9
except ImportError:
10
    try:
11
        from PyQt4.QtCore import Qt, QRectF, pyqtSignal, QT_VERSION_STR, QRect
12
        from PyQt4.QtGui import QGraphicsView, QGraphicsScene, QImage, QPixmap, QPainterPath, QFileDialog, QFont
13
    except ImportError:
14
        raise ImportError("ImageViewerQt: Requires PyQt5 or PyQt4.")
15

    
16
from EngineeringPolylineItem import QEngineeringPolylineItem
17
from GraphicsBoundingBoxItem import QGraphicsBoundingBoxItem
18
from UserInputAttribute import UserInputAttribute
19
from OcrResultDialog import QOcrResultDialog
20
from AppDocData import AppDocData
21
from EngineeringTextItem import QEngineeringTextItem
22

    
23
lineColumnList = ['UID', 'LINE_SIZE', 'LINE_SYMBOL', 'LINE_NO', 'LINE_CLASS', 'LINE_ROUTING_FROM', 'LINE_ROUTING_TO', 'SERVICE_FLUID', 'SERVICE_DENSITY', 'SERVICE_STATE', 'OPERATION_CONDITION_TEMP', 'OPERATION_CONDITION_PRESS', 'DESIGN_CONDITION_TEMP', 'DESIGN_CONDITION_PRESS', 'TEST_CONDITION_TEMP', 'TEST_CONDITION_PRESS', 'INSUL_CODE', 'PAINT_CODE', 'NDE_CODE', 'PWHT', 'PNID_NO']
24

    
25
class QEngineeringLineNoTextItem(QEngineeringTextItem):
26

    
27
    '''
28
        @history    18.05.14    Jeongwoo    Add variable self.runs
29
                    humkyung 2018.07.09 add stream no
30
    '''
31
    def __init__(self, parent=None):
32
        QEngineeringTextItem.__init__(self, parent)
33
        
34
        self._runs = []
35

    
36
        appDocData = AppDocData.instance()
37
        attributes = appDocData.getSymbolAttribute('Line No Label')
38
        self._attrs = [[attr, None] for attr in attributes]
39
        
40
    '''
41
        @brief  getter of runs
42
        @author humkyung
43
        @date   2018.05.11
44
    '''
45
    @property
46
    def runs(self):
47
        return self._runs
48

    
49
    '''
50
        @brief  setter of runs
51
        @author humkyung
52
        @date   2018.05.11
53
    '''
54
    @runs.setter
55
    def runs(self, value):
56
        self._runs = value
57
    
58
    def getLongestTwoPoints(self, pts):
59
        import math
60
        res = [None, None]
61

    
62
        maxDistance = None
63
        for i in range(len(pts)):
64
            for j in range(i+1, len(pts)):
65
                dx = pts[i][0] - pts[j][0]
66
                dy = pts[i][1] - pts[j][1]
67
                dist = math.sqrt(dx*dx + dy*dy)
68
                if (maxDistance is None) or (maxDistance < dist):
69
                    maxDistance = dist
70
                    res[0] = pts[i]
71
                    res[1] = pts[j]
72
        
73
        return res
74
    
75
    '''
76
        @brief      set attribute
77
        @author     humkyung
78
        @date       2018.07.20
79
    '''
80
    def setAttribute(self, name, value):
81
        matches = [attr for attr in self._attrs if attr[0] == name]
82
        if len(matches) == 1:
83
            matches[0][1] = value
84

    
85
    '''
86
        @brief      get line no attributes
87
        @author     humkyung
88
        @date       2018.04.24
89
        @history    humkyung 2018.05.09 evaluate string for Tag Seq No
90
                    kyouho 2018.07.06 add using TextItemFactory.isLineNo method
91
    '''
92
    def getLineNoAttributes(self, getLineNo = False):
93
        res = []
94

    
95
        try:
96
            docData = AppDocData.instance()
97
            lineNoconfigs = docData.getConfigs('Line No', 'Configuration')
98

    
99
            from TextItemFactory import TextItemFactory
100
            item = TextItemFactory.instance().isLineNo(self.text())
101
            # Line No 부분
102
            if item[0]:
103
                result = item[1]
104
                configs = lineNoconfigs[0].value.split(self.delimiter)
105
                lineAttrs = docData.getLineProperties()
106
                for lineAttr in lineAttrs:
107
                    if lineAttr[3] == 'String':
108
                        find = False
109
                        for attr in self._attrs:
110
                            if type(attr) is UserInputAttribute and attr.attribute == lineAttr[0]:
111
                                find = True
112
                                res.append(attr)
113
                                break;
114
                        if not find:
115
                            newAttr = UserInputAttribute(lineAttr[0], '')
116
                            self._attrs.append(newAttr)
117
                            res.append(newAttr)
118
                    else:
119
                        for i in range(len(configs)):
120
                            if lineAttr[0] == configs[i]:
121
                                res.append((lineAttr[0], result[i]))
122
                                break
123

    
124
            if getLineNo:
125
                res.append(('Line No', self.uid))
126
        except Exception as ex:
127
            print('error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno))
128
        
129
        return res
130

    
131
    '''
132
        @brief      generate xml code
133
        @author     humkyung
134
        @date       2018.04.23
135
        @history    humkyung 2018.05.02 write symbol's attribute
136
                    humkyung 2018.05.16 write run information to xml
137
    '''
138
    def toXml(self):
139
        from xml.etree.ElementTree import Element, SubElement, dump, ElementTree
140
        from EngineeringLineItem import QEngineeringLineItem
141
        from SymbolSvgItem import SymbolSvgItem
142

    
143
        try:
144
            docData = AppDocData.instance()
145
            configs = docData.getConfigs('Line No', 'Delimiter')
146
            delimiter = configs[0].value if 1 == len(configs) else '-'
147
            lineNoconfigs = docData.getConfigs('Line No', 'Configuration')
148

    
149
            node = Element('LINE_NO')
150
            uidNode = Element('UID')
151
            uidNode.text = str(self.uid)
152
            node.append(uidNode)
153

    
154
            textNode = Element('TEXT')
155
            textNode.text = self.text() 
156
            node.append(textNode)
157

    
158
            rect = self.sceneBoundingRect()
159
            locNode = Element('LOCATION')
160
            locNode.text = '{},{}'.format(rect.left(), rect.top())
161
            node.append(locNode)
162

    
163
            widthNode = Element('WIDTH')
164
            widthNode.text = str(rect.width())
165
            node.append(widthNode)
166

    
167
            heightNode = Element('HEIGHT')
168
            heightNode.text = str(rect.height())
169
            node.append(heightNode)
170

    
171
            angleNode = Element('ANGLE')
172
            angleNode.text = str(self.angle)
173
            node.append(angleNode)
174

    
175
            for run in self.runs:
176
                node.append(run.toXml())
177

    
178
            attrs = self.getLineNoAttributes()
179
            for attr in attrs:
180
                if type(attr) is not UserInputAttribute:
181
                    attrNode = Element('ATTRIBUTE')
182

    
183
                    uidNode = Element('UID')
184
                    uidNode.text = str(self.uid)
185
                    attrNode.append(uidNode)
186

    
187
                    nameNode = Element('NAME')
188
                    nameNode.text = str(attr[0])
189
                    attrNode.append(nameNode)
190

    
191
                    valueNode = Element('VALUE')
192
                    valueNode.text = str(attr[1])
193
                    attrNode.append(valueNode)
194

    
195
                    node.append(attrNode) 
196
                else:
197
                    node.append(attr.toXml())
198
        except Exception as ex:
199
            return str(self.uid)
200
            print('error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno))
201

    
202
        return node 
203

    
204
    '''
205
        @Override (QEngineeringTextItem)
206
        @brief  get connected items
207
        @author Jeongwoo
208
        @date   2018.05.15
209
    '''
210
    def getConnectedItems(self):
211
        visited = []
212

    
213
        try:
214
            if self.runs is not None:
215
                for run in self.runs:
216
                    items = run.items
217
                    if items is not None:
218
                        for item in items:
219
                            pool = []
220
                            pool.append(item)
221
                            while len(pool) > 0:
222
                                it = pool.pop()
223
                                visited.append(it)
224
                                for connector in it.connectors:
225
                                    if (connector.connectedItem is not None) and (connector.connectedItem not in visited): pool.append(connector.connectedItem)
226
        except Exception as ex:
227
            print('error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno))
228

    
229
        return visited
230

    
231
    '''
232
        @brief      save Line Data
233
        @author     kyouho
234
        @date       2018.08.14
235
    '''
236
    def saveLineData(self):
237
        try:
238
            docData = AppDocData.instance()
239
            docData.setLineDataList([self.getLineDataList()])
240
        except Exception as ex:
241
            return str(self.uid)
242
            print('error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno))
243

    
244
    '''
245
        @brief      return Line Data List
246
        @author     kyouho
247
        @date       2018.08.14
248
    '''
249
    def getLineDataList(self):
250
        dataList = []
251
        try:
252
            import uuid
253
            global lineColumnList
254

    
255
            docData = AppDocData.instance()
256
            attrs = self.getLineNoAttributes(True)
257

    
258
            for index in range(len(lineColumnList)):
259
                dataList.append('')
260

    
261
            dataList[20] = docData.imgName
262

    
263
            for attr in attrs:
264
                if type(attr) is not UserInputAttribute:
265
                    lineProp = docData.getLinePropertiesByUID(attr[0])
266
                    if lineProp:
267
                        attrName = lineProp[0][1].upper().replace(' ','')
268
                    else:
269
                        attrName = attr[0].upper().replace(' ','')
270
                    data = attr[1] if attr[1] is not None else ''
271
                    if attrName == 'NOMINALDIAMETER':
272
                        dataList[1] = data
273
                    elif attrName == 'FLUIDCODE':
274
                        dataList[2] = data
275
                        dataList[7] = data
276
                    elif attrName == 'TAGSEQNO':
277
                        pass
278
                    elif attrName == 'INSULATIONPURPOSE':
279
                        dataList[16] = data
280
                    elif attrName == 'STREAMNO':
281
                        pass
282
                    elif attrName == 'LINENO':
283
                        dataList[3] = data
284
                    elif attrName == 'PNIDNUMBER':
285
                        pass
286
                    elif attrName == 'PIPINGMATERIALSCLASS':
287
                        dataList[4] = data
288
                    elif attrName == '':
289
                        pass
290
                else:
291
                    typeUID = attr.attribute
292
                    value = attr.text
293
                    lineAttr = docData.getLinePropertiesByUID(typeUID)
294

    
295
                    for index in range(len(lineColumnList)):
296
                        if lineColumnList[index] == lineAttr[0][1]:
297
                            dataList[index] = value
298

    
299
            
300
        except Exception as ex:
301
            print('error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno))
302

    
303
        return dataList