hytos / DTI_PID / DTI_PID / Shapes / EngineeringLineNoTextItem.py @ 866112c6
이력 | 보기 | 이력해설 | 다운로드 (11.2 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 |
self._runs = []
|
34 | |
35 |
'''
|
36 |
@brief getter of runs
|
37 |
@author humkyung
|
38 |
@date 2018.05.11
|
39 |
'''
|
40 |
@property
|
41 |
def runs(self): |
42 |
return self._runs |
43 | |
44 |
'''
|
45 |
@brief setter of runs
|
46 |
@author humkyung
|
47 |
@date 2018.05.11
|
48 |
'''
|
49 |
@runs.setter
|
50 |
def runs(self, value): |
51 |
self._runs = value
|
52 |
|
53 |
def getLongestTwoPoints(self, pts): |
54 |
import math |
55 |
res = [None, None] |
56 | |
57 |
maxDistance = None
|
58 |
for i in range(len(pts)): |
59 |
for j in range(i+1, len(pts)): |
60 |
dx = pts[i][0] - pts[j][0] |
61 |
dy = pts[i][1] - pts[j][1] |
62 |
dist = math.sqrt(dx*dx + dy*dy) |
63 |
if (maxDistance is None) or (maxDistance < dist): |
64 |
maxDistance = dist |
65 |
res[0] = pts[i]
|
66 |
res[1] = pts[j]
|
67 |
|
68 |
return res
|
69 |
|
70 |
'''
|
71 |
@brief set attribute
|
72 |
@author humkyung
|
73 |
@date 2018.07.20
|
74 |
'''
|
75 |
def setAttribute(self, name, value): |
76 |
matches = [attr for attr in self._attrs if attr[0] == name] |
77 |
if len(matches) == 1: |
78 |
matches[0][1] = value |
79 | |
80 |
'''
|
81 |
@brief get attribute
|
82 |
@author kyouho
|
83 |
@date 2018.09.06
|
84 |
'''
|
85 |
def getAttributes(self): |
86 |
attrs = {} |
87 |
attrs['Line No'] = self.uid |
88 |
try:
|
89 |
docData = AppDocData.instance() |
90 |
lineNoconfigs = docData.getConfigs('Line No', 'Configuration') |
91 |
from TextItemFactory import TextItemFactory |
92 |
item = TextItemFactory.instance().isLineNo(self.text())
|
93 |
# Line No 부분
|
94 |
if item[0]: |
95 |
result = item[1]
|
96 |
configs = lineNoconfigs[0].value.split(self.delimiter) |
97 |
lineAttrs = docData.getLineProperties() |
98 |
for lineAttr in lineAttrs: |
99 |
if lineAttr[3] == 'String': |
100 |
find = False
|
101 |
for attr in self.attrs: |
102 |
if type(attr) is UserInputAttribute and attr.attribute == lineAttr[0]: |
103 |
find = True
|
104 |
break;
|
105 |
if not find: |
106 |
newAttr = UserInputAttribute(lineAttr[0], '') |
107 |
self._attrs.append(newAttr)
|
108 | |
109 |
attrs[lineAttr[0]] = '' |
110 |
else:
|
111 |
for i in range(len(configs)): |
112 |
if lineAttr[0] == configs[i]: |
113 |
attrs[lineAttr[0]] = result[i]
|
114 |
break
|
115 | |
116 |
for attr in self._attrs: |
117 |
if type(attr) is UserInputAttribute: |
118 |
attrs[attr.attribute] = attr.text |
119 | |
120 |
attrs['CONN'] = self.conns[0].uid if self.conns else '' |
121 |
except Exception as ex: |
122 |
print('error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno)) |
123 |
|
124 |
return attrs
|
125 | |
126 |
'''
|
127 |
@brief generate xml code
|
128 |
@author humkyung
|
129 |
@date 2018.04.23
|
130 |
@history humkyung 2018.05.02 write symbol's attribute
|
131 |
humkyung 2018.05.16 write run information to xml
|
132 |
'''
|
133 |
def toXml(self): |
134 |
from xml.etree.ElementTree import Element, SubElement, dump, ElementTree |
135 |
from EngineeringLineItem import QEngineeringLineItem |
136 |
from SymbolSvgItem import SymbolSvgItem |
137 | |
138 |
try:
|
139 |
docData = AppDocData.instance() |
140 |
configs = docData.getConfigs('Line No', 'Delimiter') |
141 |
delimiter = configs[0].value if 1 == len(configs) else '-' |
142 |
lineNoconfigs = docData.getConfigs('Line No', 'Configuration') |
143 | |
144 |
node = Element('LINE_NO')
|
145 |
uidNode = Element('UID')
|
146 |
uidNode.text = str(self.uid) |
147 |
node.append(uidNode) |
148 | |
149 |
textNode = Element('TEXT')
|
150 |
textNode.text = self.text()
|
151 |
node.append(textNode) |
152 | |
153 |
rect = self.sceneBoundingRect()
|
154 |
locNode = Element('LOCATION')
|
155 |
locNode.text = '{},{}'.format(rect.left(), rect.top())
|
156 |
node.append(locNode) |
157 | |
158 |
widthNode = Element('WIDTH')
|
159 |
widthNode.text = str(rect.width())
|
160 |
node.append(widthNode) |
161 | |
162 |
heightNode = Element('HEIGHT')
|
163 |
heightNode.text = str(rect.height())
|
164 |
node.append(heightNode) |
165 | |
166 |
angleNode = Element('ANGLE')
|
167 |
angleNode.text = str(self.angle) |
168 |
node.append(angleNode) |
169 | |
170 |
areaNode = Element('AREA')
|
171 |
areaNode.text = self.area
|
172 |
node.append(areaNode) |
173 | |
174 |
for run in self.runs: |
175 |
node.append(run.toXml()) |
176 | |
177 |
for attr in self._attrs: |
178 |
if type(attr) is not UserInputAttribute: |
179 |
attrNode = Element('ATTRIBUTE')
|
180 | |
181 |
uidNode = Element('UID')
|
182 |
uidNode.text = str(self.uid) |
183 |
attrNode.append(uidNode) |
184 | |
185 |
nameNode = Element('NAME')
|
186 |
nameNode.text = str(attr[0]) |
187 |
attrNode.append(nameNode) |
188 | |
189 |
valueNode = Element('VALUE')
|
190 |
valueNode.text = str(attr[1]) |
191 |
attrNode.append(valueNode) |
192 | |
193 |
node.append(attrNode) |
194 |
else:
|
195 |
node.append(attr.toXml()) |
196 |
|
197 |
if self.conns: |
198 |
connNode = Element('CONNLINE')
|
199 |
connNode.text = self.conns[0].uid |
200 |
node.append(connNode) |
201 | |
202 |
except Exception as ex: |
203 |
return str(self.uid) |
204 |
print('error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno)) |
205 | |
206 |
return node
|
207 | |
208 |
'''
|
209 |
@Override (QEngineeringTextItem)
|
210 |
@brief get connected items
|
211 |
@author Jeongwoo
|
212 |
@date 2018.05.15
|
213 |
'''
|
214 |
def getConnectedItems(self): |
215 |
visited = [] |
216 | |
217 |
try:
|
218 |
if self.runs is not None: |
219 |
for run in self.runs: |
220 |
items = run.items |
221 |
if items is not None: |
222 |
for item in items: |
223 |
pool = [] |
224 |
pool.append(item) |
225 |
while len(pool) > 0: |
226 |
it = pool.pop() |
227 |
visited.append(it) |
228 |
for connector in it.connectors: |
229 |
if (connector.connectedItem is not None) and (connector.connectedItem not in visited): pool.append(connector.connectedItem) |
230 |
except Exception as ex: |
231 |
print('error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno)) |
232 | |
233 |
return visited
|
234 | |
235 |
'''
|
236 |
@brief save Line Data
|
237 |
@author kyouho
|
238 |
@date 2018.08.14
|
239 |
'''
|
240 |
def saveLineData(self): |
241 |
try:
|
242 |
docData = AppDocData.instance() |
243 |
docData.setLineDataList([self.getLineDataList()])
|
244 |
except Exception as ex: |
245 |
print('error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno)) |
246 |
return str(self.uid) |
247 | |
248 |
'''
|
249 |
@brief return Line Data List
|
250 |
@author kyouho
|
251 |
@date 2018.08.14
|
252 |
'''
|
253 |
def getLineDataList(self): |
254 |
dataList = [] |
255 |
try:
|
256 |
import uuid |
257 |
global lineColumnList
|
258 | |
259 |
docData = AppDocData.instance() |
260 |
attrs = self.getAttributes()
|
261 |
attrs = attrs.items() |
262 |
for index in range(len(lineColumnList)): |
263 |
dataList.append('')
|
264 | |
265 |
dataList[20] = docData.imgName
|
266 | |
267 |
for attr in attrs: |
268 |
if type(attr) is not UserInputAttribute: |
269 |
lineProp = docData.getLinePropertiesByUID(attr[0])
|
270 |
if lineProp:
|
271 |
attrName = lineProp[0][1].upper().replace(' ','') |
272 |
else:
|
273 |
attrName = attr[0].upper().replace(' ','') |
274 |
data = attr[1] if attr[1] is not None else '' |
275 |
if attrName == 'NOMINALDIAMETER': |
276 |
dataList[1] = data
|
277 |
elif attrName == 'FLUIDCODE': |
278 |
dataList[2] = data
|
279 |
dataList[7] = data
|
280 |
elif attrName == 'TAGSEQNO': |
281 |
pass
|
282 |
elif attrName == 'INSULATIONPURPOSE': |
283 |
dataList[16] = data
|
284 |
elif attrName == 'STREAMNO': |
285 |
pass
|
286 |
elif attrName == 'LINENO': |
287 |
dataList[3] = data
|
288 |
elif attrName == 'PNIDNUMBER': |
289 |
pass
|
290 |
elif attrName == 'PIPINGMATERIALSCLASS': |
291 |
dataList[4] = data
|
292 |
elif attrName == '': |
293 |
pass
|
294 |
else:
|
295 |
typeUID = attr.attribute |
296 |
value = attr.text |
297 |
lineAttr = docData.getLinePropertiesByUID(typeUID) |
298 | |
299 |
for index in range(len(lineColumnList)): |
300 |
if lineColumnList[index] == lineAttr[0][1]: |
301 |
dataList[index] = value |
302 |
except Exception as ex: |
303 |
print('error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno)) |
304 | |
305 |
if dataList[0] == '': |
306 |
dataList[0] = str(uuid.uuid4()) |
307 | |
308 |
return dataList
|