hytos / DTI_PID / DTI_PID / Shapes / EngineeringLineNoTextItem.py @ 3aeaaa66
이력 | 보기 | 이력해설 | 다운로드 (29.7 KB)
1 |
# coding: utf-8
|
---|---|
2 |
""" This is engineering line no text item module """
|
3 |
|
4 |
import os.path |
5 |
import sys |
6 |
import copy |
7 |
try:
|
8 |
from PyQt5.QtCore import Qt, QPointF, QRectF, pyqtSignal, QT_VERSION_STR, QRect |
9 |
from PyQt5.QtGui import QImage, QPixmap, QPainterPath, QBrush, QPen, QTransform, QFont |
10 |
from PyQt5.QtWidgets import QGraphicsView, QGraphicsScene, QFileDialog, QGraphicsItem, QAbstractGraphicsShapeItem, QGraphicsTextItem |
11 |
except ImportError: |
12 |
try:
|
13 |
from PyQt4.QtCore import Qt, QRectF, pyqtSignal, QT_VERSION_STR, QRect |
14 |
from PyQt4.QtGui import QGraphicsView, QGraphicsScene, QImage, QPixmap, QPainterPath, QFileDialog, QFont |
15 |
except ImportError: |
16 |
raise ImportError("ImageViewerQt: Requires PyQt5 or PyQt4.") |
17 |
|
18 |
from EngineeringPolylineItem import QEngineeringPolylineItem |
19 |
from GraphicsBoundingBoxItem import QGraphicsBoundingBoxItem |
20 |
from UserInputAttribute import UserInputAttribute |
21 |
from OcrResultDialog import QOcrResultDialog |
22 |
from AppDocData import AppDocData |
23 |
from EngineeringTextItem import QEngineeringTextItem |
24 |
from TextInfo import TextInfo |
25 |
|
26 |
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'] |
27 |
|
28 |
class QEngineeringLineNoTextItem(QEngineeringTextItem): |
29 |
'''
|
30 |
@history 18.05.14 Jeongwoo Add variable self.runs
|
31 |
humkyung 2018.07.09 add stream no
|
32 |
'''
|
33 |
def __init__(self, uid=None, parent=None): |
34 |
from SymbolAttr import SymbolProp |
35 |
from EngineeringFreezeItem import QEngineeringFreezeItem |
36 |
|
37 |
QEngineeringTextItem.__init__(self, uid, parent)
|
38 |
|
39 |
self._properties = {SymbolProp(None, 'From', 'Comp Item'):None, SymbolProp(None, 'To', 'Comp Item'):None}#, SymbolProp(None, 'Freeze', 'Boolean'):False} |
40 |
self._runs = []
|
41 |
|
42 |
""" create freeze control """
|
43 |
#self.freeze_item = QEngineeringFreezeItem(-QEngineeringFreezeItem.FREEZE_SIZE*0.5, -QEngineeringFreezeItem.FREEZE_SIZE*0.5, QEngineeringFreezeItem.FREEZE_SIZE, QEngineeringFreezeItem.FREEZE_SIZE)
|
44 |
#self.freeze_item.setParentItem(self)
|
45 |
#self.freeze_item.setZValue(self.zValue() + 1)
|
46 |
#self.freeze_item.setPen(Qt.black)
|
47 |
|
48 |
@property
|
49 |
def Size(self): |
50 |
""" return line no's size """
|
51 |
attrs = self.getAttributes()
|
52 |
matches = [value for attr,value in attrs.items() if attr.Attribute.upper() == 'NOMINALDIAMETER'] |
53 |
return matches[0] if matches else None |
54 |
|
55 |
def empty(self): |
56 |
""" return True if run is empty else return False """
|
57 |
return False if self._runs else True |
58 |
|
59 |
def setVisible(self, visible): |
60 |
""" override visible value """
|
61 |
super(QEngineeringTextItem, self).setVisible(visible) |
62 |
for run in self.runs: |
63 |
run.visible = visible |
64 |
|
65 |
'''
|
66 |
@brief getter of runs
|
67 |
@author humkyung
|
68 |
@date 2018.05.11
|
69 |
'''
|
70 |
@property
|
71 |
def runs(self): |
72 |
return self._runs |
73 |
|
74 |
'''
|
75 |
@brief setter of runs
|
76 |
@author humkyung
|
77 |
@date 2018.05.11
|
78 |
'''
|
79 |
@runs.setter
|
80 |
def runs(self, value): |
81 |
self._runs = value
|
82 |
|
83 |
def hoverEnterEvent(self, event): |
84 |
""" highlight line no text and run's item """
|
85 |
self.hover = True |
86 |
self.update()
|
87 |
|
88 |
for run in self.runs: |
89 |
for item in run.items: |
90 |
item.hoverEnterEvent(event) |
91 |
|
92 |
def hoverLeaveEvent(self, event): |
93 |
""" unhighlight line no text and run's item """
|
94 |
self.hover = False |
95 |
self.update()
|
96 |
|
97 |
for run in self.runs: |
98 |
for item in run.items: |
99 |
item.hoverLeaveEvent(event) |
100 |
|
101 |
def keyPressEvent(self, event): |
102 |
""" reverse line routine when user press 'C' key """
|
103 |
if event.key() == Qt.Key_C:
|
104 |
self.reverse()
|
105 |
|
106 |
QEngineeringTextItem.keyPressEvent(self, event)
|
107 |
|
108 |
def update_flow_mark(self, position, minLength): |
109 |
""" update line flow mark """
|
110 |
import math |
111 |
from EngineeringLineItem import QEngineeringLineItem |
112 |
|
113 |
allowed_error_radian = 0.09
|
114 |
|
115 |
try:
|
116 |
for run in self.runs: |
117 |
pre = None
|
118 |
preRadian = None
|
119 |
for item in run.items: |
120 |
if pre is None and type(item) is QEngineeringLineItem and (item._lineType == 'Primary' or item._lineType == 'Secondary') and item.length() > minLength: |
121 |
pre = item |
122 |
start = item.line().p1() |
123 |
end = item.line().p2() |
124 |
_dir = [(end.x() - start.x())/item.length(), (end.y() - start.y())/item.length()] |
125 |
radian = math.atan2(_dir[1], _dir[0]) - math.pi / 2 |
126 |
preRadian = radian if radian >= 0 else radian + 2 * math.pi |
127 |
preRadian = abs(preRadian - math.pi)
|
128 |
|
129 |
elif pre and type(pre) is QEngineeringLineItem and type(item) is QEngineeringLineItem and (item._lineType == 'Primary' or item._lineType == 'Secondary'): |
130 |
start = item.line().p1() |
131 |
end = item.line().p2() |
132 |
_dir = [(end.x() - start.x())/item.length(), (end.y() - start.y())/item.length()] |
133 |
radian = math.atan2(_dir[1], _dir[0]) - math.pi / 2 |
134 |
currRadian = radian if radian >= 0 else radian + 2 * math.pi |
135 |
currRadian = abs(currRadian - math.pi)
|
136 |
if abs(currRadian - preRadian) > allowed_error_radian: |
137 |
# insert flow mark at pre line
|
138 |
if pre.length() > minLength:
|
139 |
#if str(pre.uid) == '62edfbe5-29fd-49af-840b-6dce051e04d1':
|
140 |
#print(math.atan2(preDir[0], preDir[1]) - math.pi / 2)
|
141 |
#print(currRadian)
|
142 |
#print(preRadian)
|
143 |
pre.flowMark = position |
144 |
pre.update_arrow() |
145 |
|
146 |
pre = item |
147 |
preRadian = currRadian |
148 |
|
149 |
if pre and type(item) is QEngineeringLineItem and (item._lineType == 'Primary' or item._lineType == 'Secondary') and item.length() > minLength: |
150 |
pre.flowMark = position |
151 |
pre.update_arrow() |
152 |
|
153 |
except Exception as ex: |
154 |
from App import App |
155 |
from AppDocData import MessageType |
156 |
|
157 |
message = 'error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno) |
158 |
App.mainWnd().addMessage.emit(MessageType.Error, message) |
159 |
|
160 |
"""
|
161 |
def paint(self, painter, options=None, widget=None):
|
162 |
QEngineeringTextItem.paint(self, painter, options, widget)
|
163 |
if self.freeze_item is None:
|
164 |
from EngineeringFreezeItem import QEngineeringFreezeItem
|
165 |
|
166 |
self.freeze_item = QEngineeringFreezeItem(0, 0, QEngineeringFreezeItem.FREEZE_SIZE, QEngineeringFreezeItem.FREEZE_SIZE)
|
167 |
self.freeze_item.setParentItem(self)
|
168 |
self.freeze_item.setZValue(self.zValue() + 1)
|
169 |
self.freeze_item.setPen(Qt.black)
|
170 |
"""
|
171 |
|
172 |
def reverse(self): |
173 |
""" reverse line routine """
|
174 |
|
175 |
if self.runs: |
176 |
self.runs[0].reverse() |
177 |
_from = self.prop('From') |
178 |
_to = self.prop('To') |
179 |
self.set_property('From', _to) |
180 |
self.set_property('To', _from) |
181 |
|
182 |
def getLongestTwoPoints(self, pts): |
183 |
import math |
184 |
res = [None, None] |
185 |
|
186 |
maxDistance = None
|
187 |
for i in range(len(pts)): |
188 |
for j in range(i+1, len(pts)): |
189 |
dx = pts[i][0] - pts[j][0] |
190 |
dy = pts[i][1] - pts[j][1] |
191 |
dist = math.sqrt(dx*dx + dy*dy) |
192 |
if (maxDistance is None) or (maxDistance < dist): |
193 |
maxDistance = dist |
194 |
res[0] = pts[i]
|
195 |
res[1] = pts[j]
|
196 |
|
197 |
return res
|
198 |
|
199 |
'''
|
200 |
@brief set attribute
|
201 |
@author humkyung
|
202 |
@date 2018.07.20
|
203 |
'''
|
204 |
def set_attrib(self, attrib, value): |
205 |
matches = [attr for attr in self.attrs if attr.UID == attrib.UID] |
206 |
if len(matches) == 1: |
207 |
self.attrs[matches[0]] = value |
208 |
else:
|
209 |
self.attrs[attrib] = value
|
210 |
|
211 |
def removeSelfAttr(self, attributeName): |
212 |
pass
|
213 |
|
214 |
'''
|
215 |
@brief get attribute
|
216 |
@author kyouho
|
217 |
@date 2018.09.06
|
218 |
'''
|
219 |
def getLineNoAttributes(self, _attrs=None): |
220 |
from SymbolAttr import SymbolAttr |
221 |
from Configs import LineNoConfig |
222 |
|
223 |
if _attrs is None: |
224 |
_attrs = {} |
225 |
|
226 |
try:
|
227 |
docData = AppDocData.instance() |
228 |
|
229 |
line_no_configs = LineNoConfig.instance() |
230 |
config = None
|
231 |
if line_no_configs:
|
232 |
for line_no_config in line_no_configs: |
233 |
item = line_no_config.parse(self.text())
|
234 |
if item[0]: |
235 |
config = line_no_config |
236 |
break
|
237 |
else:
|
238 |
item = (False,)
|
239 |
|
240 |
# Line No 부분
|
241 |
if item[0]: |
242 |
attr = SymbolAttr() |
243 |
attr.Attribute = 'LINE NO'
|
244 |
attr.DisplayAttribute = 'Line No'
|
245 |
attr.AttributeType = 'String'
|
246 |
attr.IsProp = 5
|
247 |
_attrs[attr] = self.text()
|
248 |
|
249 |
result = item[1]
|
250 |
configs = config.value.split(self.delimiter)
|
251 |
props = docData.getLineProperties() |
252 |
for prop in props: |
253 |
if prop.UID in configs: |
254 |
for i in range(len(configs)): |
255 |
if prop.UID == configs[i]:
|
256 |
_attrs[prop] = result[i] |
257 |
break
|
258 |
else:
|
259 |
matches = [attr for attr in self.attrs if attr.UID == prop.UID] |
260 |
if len(matches) == 1: |
261 |
_attrs[matches[0]] = self.attrs[matches[0]] |
262 |
#else:
|
263 |
# _attrs[prop] = ''
|
264 |
except Exception as ex: |
265 |
from App import App |
266 |
from AppDocData import MessageType |
267 |
|
268 |
message = 'error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno) |
269 |
App.mainWnd().addMessage.emit(MessageType.Error, message) |
270 |
|
271 |
return _attrs
|
272 |
|
273 |
@staticmethod
|
274 |
def from_database(component): |
275 |
""" get line no item from database """
|
276 |
import uuid |
277 |
from AppDocData import AppDocData |
278 |
from TextItemFactory import TextItemFactory |
279 |
from SymbolAttr import SymbolAttr |
280 |
|
281 |
item = None
|
282 |
|
283 |
try:
|
284 |
x = float(component['X']) |
285 |
y = float(component['Y']) |
286 |
width = float(component['Width']) if component['Width'] is not None else 0 |
287 |
height = float(component['Height']) if component['Height'] is not None else 0 |
288 |
angle = float(component['Rotation']) if component['Rotation'] is not None else 0 |
289 |
text = component['Value']
|
290 |
textInfo = TextInfo(text, x, y, width, height, angle) |
291 |
connline = component['Connected'] if component['Connected'] is not None else None |
292 |
|
293 |
item = TextItemFactory.instance().createTextItem(textInfo) |
294 |
if item is not None: |
295 |
item.setVisible(False)
|
296 |
for key in item._properties.keys(): |
297 |
item._properties[key] = key.parse_value(component[key.Attribute]) |
298 |
|
299 |
app_doc_data = AppDocData.instance() |
300 |
|
301 |
# get associations
|
302 |
associations = app_doc_data.get_component_associations(component['UID'])
|
303 |
if associations:
|
304 |
for assoc in associations: |
305 |
_attrType = assoc['Type']
|
306 |
if not _attrType in item._associations: |
307 |
item._associations[_attrType] = [] |
308 |
item._associations[_attrType].append( |
309 |
uuid.UUID(assoc['Association']) if assoc['Association'] != 'None' else None) |
310 |
# up to here
|
311 |
|
312 |
attrs = app_doc_data.get_component_attributes(component['UID'])
|
313 |
for _attr in attrs: |
314 |
attr = SymbolAttr.from_record(_attr) |
315 |
item.attrs[attr] = _attr['Value']
|
316 |
|
317 |
item.uid = uuid.UUID(component['UID'])
|
318 |
item.loc = [x, y] |
319 |
item.size = (width, height) |
320 |
item.angle = angle |
321 |
item.setToolTip('<b>{}</b><br>LINE NO={}'.format(str(item.uid), text)) |
322 |
|
323 |
""" apply freeze value """
|
324 |
#item.freeze_item.update_freeze(item.prop('Freeze'))
|
325 |
|
326 |
if connline is not None: |
327 |
item.conns.append(connline) |
328 |
except Exception as ex: |
329 |
from App import App |
330 |
from AppDocData import MessageType |
331 |
|
332 |
message = 'error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno) |
333 |
App.mainWnd().addMessage.emit(MessageType.Error, message) |
334 |
return None |
335 |
|
336 |
return item
|
337 |
|
338 |
@staticmethod
|
339 |
def fromXml(node): |
340 |
""" generate EngineeringLineNoTextItem from xml node """
|
341 |
import uuid |
342 |
from TextItemFactory import TextItemFactory |
343 |
from SymbolAttr import SymbolAttr |
344 |
|
345 |
item = None
|
346 |
|
347 |
try:
|
348 |
location = node.find('LOCATION').text if node.find('LOCATION') is not None else '0,0' |
349 |
x = float(location.split(',')[0]) |
350 |
y = float(location.split(',')[1]) |
351 |
width = float(node.find('WIDTH').text) if node.find('WIDTH') is not None else 0 |
352 |
height = float(node.find('HEIGHT').text) if node.find('HEIGHT') is not None else 0 |
353 |
angle = float(node.find('ANGLE').text) if node.find('ANGLE') is not None else 0 |
354 |
text = node.find('TEXT').text
|
355 |
textInfo = TextInfo(text, x, y, width, height, angle) |
356 |
connline = node.find('CONNLINE').text if node.find('CONNLINE') is not None else None |
357 |
|
358 |
item = TextItemFactory.instance().createTextItem(textInfo) |
359 |
if item is not None: |
360 |
for prop_node in node.iter('PROPERTY'): |
361 |
matches = [prop for prop in item._properties.keys() if prop.Attribute == prop_node.attrib['Attribute']] |
362 |
if matches:
|
363 |
item._properties[matches[0]] = matches[0].parse_value(prop_node.text) |
364 |
|
365 |
for attr_node in node.iter('ATTRIBUTE'): |
366 |
attr = SymbolAttr.fromXml(attr_node) |
367 |
item.attrs[attr] = attr_node.text |
368 |
|
369 |
item.uid = uuid.UUID(node.find('UID').text)
|
370 |
item.loc = [x, y] |
371 |
item.size = (width, height) |
372 |
item.angle = angle |
373 |
item.setToolTip('<b>{}</b><br>LINE NO={}'.format(str(item.uid), text)) |
374 |
|
375 |
""" apply freeze value """
|
376 |
#item.freeze_item.update_freeze(item.prop('Freeze'))
|
377 |
|
378 |
if connline is not None: |
379 |
item.conns.append(connline) |
380 |
except Exception as ex: |
381 |
from App import App |
382 |
from AppDocData import MessageType |
383 |
|
384 |
message = 'error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno) |
385 |
App.mainWnd().addMessage.emit(MessageType.Error, message) |
386 |
return None |
387 |
|
388 |
return item
|
389 |
|
390 |
'''
|
391 |
@brief generate xml code
|
392 |
@author humkyung
|
393 |
@date 2018.04.23
|
394 |
@history humkyung 2018.05.02 write symbol's attribute
|
395 |
humkyung 2018.05.16 write run information to xml
|
396 |
'''
|
397 |
def toXml(self): |
398 |
from xml.etree.ElementTree import Element, SubElement, dump, ElementTree |
399 |
from EngineeringLineItem import QEngineeringLineItem |
400 |
from SymbolSvgItem import SymbolSvgItem |
401 |
|
402 |
try:
|
403 |
docData = AppDocData.instance() |
404 |
configs = docData.getConfigs('Line No', 'Delimiter') |
405 |
delimiter = configs[0].value if 1 == len(configs) else '-' |
406 |
lineNoconfigs = docData.getConfigs('Line No', 'Configuration') |
407 |
|
408 |
node = Element('LINE_NO')
|
409 |
uidNode = Element('UID')
|
410 |
uidNode.text = str(self.uid) |
411 |
node.append(uidNode) |
412 |
|
413 |
textNode = Element('TEXT')
|
414 |
textNode.text = self.text()
|
415 |
node.append(textNode) |
416 |
|
417 |
locNode = Element('LOCATION')
|
418 |
locNode.text = '{},{}'.format(self.loc[0], self.loc[1]) |
419 |
node.append(locNode) |
420 |
|
421 |
widthNode = Element('WIDTH')
|
422 |
widthNode.text = str(self.size[0]) |
423 |
node.append(widthNode) |
424 |
|
425 |
heightNode = Element('HEIGHT')
|
426 |
heightNode.text = str(self.size[1]) |
427 |
node.append(heightNode) |
428 |
|
429 |
angleNode = Element('ANGLE')
|
430 |
angleNode.text = str(self.angle) |
431 |
node.append(angleNode) |
432 |
|
433 |
areaNode = Element('AREA')
|
434 |
areaNode.text = self.area
|
435 |
node.append(areaNode) |
436 |
|
437 |
for run in self.runs: |
438 |
node.append(run.toXml()) |
439 |
|
440 |
properties_node = Element('PROPERTIES')
|
441 |
for prop,value in self.properties.items(): |
442 |
prop_node = prop.toXml() |
443 |
prop_node.text = str(value) if value else '' |
444 |
properties_node.append(prop_node) |
445 |
node.append(properties_node) |
446 |
|
447 |
_attrs = self.getAttributes()
|
448 |
for key in _attrs.keys(): |
449 |
if key.UID is not None: |
450 |
attrNode = key.toXml() |
451 |
attrNode.text = str(_attrs[key])
|
452 |
node.append(attrNode) |
453 |
|
454 |
if self.conns: |
455 |
connNode = Element('CONNLINE')
|
456 |
connNode.text = str(self.conns[0].uid) if hasattr(self.conns[0], 'uid') else str(self.conns[0]) |
457 |
node.append(connNode) |
458 |
|
459 |
sceneNode = Element('SCENE')
|
460 |
sceneNode.text = str(self.sceneBoundingRect()).replace('PyQt5.QtCore.QRectF(', '').replace(' ', '').replace(')', '') |
461 |
node.append(sceneNode) |
462 |
|
463 |
except Exception as ex: |
464 |
from App import App |
465 |
from AppDocData import MessageType |
466 |
|
467 |
message = 'error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno) |
468 |
App.mainWnd().addMessage.emit(MessageType.Error, message) |
469 |
|
470 |
return None |
471 |
|
472 |
return node
|
473 |
|
474 |
def end_break(self): |
475 |
'''
|
476 |
@brief end break check
|
477 |
@author euisung
|
478 |
@date 2019.05.07
|
479 |
@history 2019.05.19 euisung can cover at both end that contact other line's middle
|
480 |
2019.05.19 euisung no more used integrated with linetracer
|
481 |
'''
|
482 |
from EngineeringLineItem import QEngineeringLineItem |
483 |
from SymbolSvgItem import SymbolSvgItem |
484 |
from AppDocData import AppDocData |
485 |
end_breaks = [] |
486 |
|
487 |
try:
|
488 |
docdata = AppDocData.instance() |
489 |
|
490 |
line_from = self.prop('From') |
491 |
line_to = self.prop('To') |
492 |
|
493 |
end_break_names = docdata.getSymbolListByType('type', 'End Break') |
494 |
if len(end_break_names) is 0: |
495 |
return end_breaks
|
496 |
|
497 |
svgFileName = end_break_names[0].sName
|
498 |
symbol = AppDocData.instance().getSymbolByQuery('name', svgFileName)
|
499 |
svgFilePath = os.path.join(AppDocData.instance().getCurrentProject().getSvgFilePath(), symbol.getType(), svgFileName+'.svg')
|
500 |
|
501 |
for line_end in [line_from, line_to]: |
502 |
for connector in line_end.connectors: |
503 |
if connector.connectedItem is not None and connector.connectedItem.owner is not self: |
504 |
end_break = SymbolSvgItem.createItem(symbol.getType(), None, svgFilePath)
|
505 |
pt = [connector.center()[0] - float(symbol.getOriginalPoint().split(',')[0]), connector.center()[1] - float(symbol.getOriginalPoint().split(',')[1])] |
506 |
origin = [0,0] |
507 |
if 2 == len(symbol.getOriginalPoint().split(',')): |
508 |
tokens = symbol.getOriginalPoint().split(',')
|
509 |
origin = [pt[0] + float(tokens[0]), pt[1] + float(tokens[1])] |
510 |
end_break.buildItem(svgFileName, symbol.getType(), 5.7, pt, [end_break.boundingRect().width(), end_break.boundingRect().height()], origin, [], symbol.getBaseSymbol(), symbol.getAdditionalSymbol(), symbol.getHasInstrumentLabel())
|
511 |
|
512 |
end_break.set_property('Connected Item', connector.connectedItem)
|
513 |
end_break.setToolTip('owner : ' + str(line_end)) |
514 |
end_break.area = 'Drawing'
|
515 |
end_break.owner = line_end |
516 |
end_breaks.append(end_break) |
517 |
except Exception as ex: |
518 |
from App import App |
519 |
from AppDocData import MessageType |
520 |
|
521 |
message = 'error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno) |
522 |
App.mainWnd().addMessage.emit(MessageType.Error, message) |
523 |
|
524 |
return end_breaks
|
525 |
|
526 |
'''
|
527 |
@Override (QEngineeringTextItem)
|
528 |
@brief get connected items
|
529 |
@author Jeongwoo
|
530 |
@date 2018.05.15
|
531 |
'''
|
532 |
def getConnectedItems(self): |
533 |
visited = [] |
534 |
|
535 |
try:
|
536 |
for run in self.runs: |
537 |
visited.extend(run.items) |
538 |
except Exception as ex: |
539 |
from App import App |
540 |
from AppDocData import MessageType |
541 |
|
542 |
message = 'error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno) |
543 |
App.mainWnd().addMessage.emit(MessageType.Error, message) |
544 |
|
545 |
return visited
|
546 |
|
547 |
def explode(self, remainFromTo=False): |
548 |
""" explode line no """
|
549 |
|
550 |
#if False == self.prop('Freeze'):
|
551 |
try:
|
552 |
for index in reversed(range(len(self.runs))): |
553 |
self.runs[index].explode()
|
554 |
finally:
|
555 |
self.runs.clear()
|
556 |
if not remainFromTo: |
557 |
self.set_property('From', None) |
558 |
self.set_property('To', None) |
559 |
|
560 |
'''
|
561 |
@brief generate sql phrase to save to database(Notice: Line No's symbol is is 1)
|
562 |
@author humkyung
|
563 |
@date 2018.08.14
|
564 |
'''
|
565 |
def toSql_return_separately(self): |
566 |
import uuid |
567 |
from EngineeringAbstractItem import QEngineeringAbstractItem |
568 |
|
569 |
res = [] |
570 |
resLater = [] |
571 |
|
572 |
app_doc_data = AppDocData.instance() |
573 |
cols = ['UID', 'Drawings_UID', 'Symbol_UID', 'X', 'Y', 'Width', 'Height', 'Rotation', 'Value', 'Connected', '[From]', '[To]'] |
574 |
if type(self) is QEngineeringLineNoTextItem: |
575 |
values = ['?', '?', "(select UID from Symbol where Name='Line NO' and SymbolType_UID=-1)", '?', '?', '?', '?', '?', '?', '?', '?', '?'] |
576 |
else:
|
577 |
values = ['?', '?', "(select UID from Symbol where Name='Trim Line NO' and SymbolType_UID=-1)", '?', '?', '?', '?', '?', '?', '?', '?', '?'] |
578 |
params = [(str(self.uid), str(app_doc_data.activeDrawing.UID), self.loc[0], self.loc[1], self.size[0], self.size[1], str(self.angle),\ |
579 |
self.text(), str(self.conns[0]) if self.conns else None, str(self.prop('From')), str(self.prop('To')))] |
580 |
sql = 'insert into Components({}) values({})'.format(','.join(cols), ','.join(values)) |
581 |
res.append((sql, tuple(params)))
|
582 |
|
583 |
cols = ['UID', 'Components_UID', 'LineProperties_UID', 'Value'] |
584 |
values = ['?', '?', '?', '?'] |
585 |
params = [] |
586 |
attrs = self.getAttributes()
|
587 |
for key,value in attrs.items(): |
588 |
if key.Attribute == 'LINE NO':# or key.IsProp != 5: |
589 |
continue
|
590 |
params.append((str(uuid.uuid4()), str(self.uid), str(key.UID), str(value))) |
591 |
sql = 'insert into LineNoAttributes({}) values({})'.format(','.join(cols), ','.join(values)) |
592 |
resLater.append((sql, tuple(params)))
|
593 |
|
594 |
# insert line no's Attributes
|
595 |
cols = ['UID', 'Components_UID', 'SymbolAttribute_UID', 'Value', 'Association_UID', 'Freeze'] |
596 |
values = ['?', '?', '?', '?', '?', '?'] |
597 |
params = [] |
598 |
for key in attrs.keys(): |
599 |
if key.IsProp != 5: |
600 |
params.append((str(uuid.uuid4()), str(self.uid), str(key.UID), str(attrs[key]), str(key.AssocItem), |
601 |
str(key.Freeze)))
|
602 |
sql = 'insert into Attributes({}) values({})'.format(','.join(cols), ','.join(values)) |
603 |
res.append((sql, tuple(params)))
|
604 |
|
605 |
if self.associations(): |
606 |
cols = ['UID', '[Type]', 'Components_UID', 'Association'] |
607 |
values = ['?', '?', '?', '?'] |
608 |
params = [] |
609 |
for assoc in self.associations(): |
610 |
params.append( |
611 |
(str(uuid.uuid4()), QEngineeringAbstractItem.assoc_type(assoc), str(self.uid), str(assoc.uid))) |
612 |
sql = 'insert into Associations({}) values({})'.format(','.join(cols), ','.join(values)) |
613 |
resLater.append((sql, tuple(params)))
|
614 |
|
615 |
_index = 0
|
616 |
for run in self.runs: |
617 |
resLater.extend(run.to_sql(_index, self))
|
618 |
_index += 1
|
619 |
|
620 |
return res, resLater
|
621 |
|
622 |
'''
|
623 |
@brief return Line Data List
|
624 |
@author kyouho
|
625 |
@date 2018.08.14
|
626 |
'''
|
627 |
def getLineDataList(self): |
628 |
dataList = [] |
629 |
try:
|
630 |
import uuid |
631 |
global lineColumnList
|
632 |
|
633 |
docData = AppDocData.instance() |
634 |
attrs = self.getAttributes()
|
635 |
for index in range(len(lineColumnList)): |
636 |
dataList.append('')
|
637 |
|
638 |
dataList[20] = docData.imgName
|
639 |
|
640 |
for key in attrs.keys(): |
641 |
if type(key) is not UserInputAttribute: |
642 |
lineProp = docData.getLinePropertiesByUID(key.UID) |
643 |
if lineProp:
|
644 |
attrName = lineProp[0].Attribute.upper().replace(' ','') |
645 |
else:
|
646 |
attrName = key.Attribute.upper().replace(' ','') |
647 |
|
648 |
data = attrs[key] |
649 |
if attrName == 'NOMINALDIAMETER': |
650 |
dataList[1] = data
|
651 |
elif attrName == 'FLUIDCODE': |
652 |
dataList[2] = data
|
653 |
dataList[7] = data
|
654 |
elif attrName == 'TAGSEQNO': |
655 |
pass
|
656 |
elif attrName == 'INSULATIONPURPOSE': |
657 |
dataList[16] = data
|
658 |
elif attrName == 'STREAMNO': |
659 |
pass
|
660 |
elif attrName == 'LINENO' or attrName == 'LINE NO': |
661 |
dataList[3] = data
|
662 |
elif attrName == 'PNIDNUMBER': |
663 |
pass
|
664 |
elif attrName == 'PIPINGMATERIALSCLASS': |
665 |
dataList[4] = data
|
666 |
elif attrName == '': |
667 |
pass
|
668 |
else:
|
669 |
typeUID = key.Attribute |
670 |
value = key.text |
671 |
lineAttr = docData.getLinePropertiesByUID(key.UD) |
672 |
|
673 |
for index in range(len(lineColumnList)): |
674 |
if lineColumnList[index] == lineAttr[0].Attribute: |
675 |
dataList[index] = value |
676 |
except Exception as ex: |
677 |
from App import App |
678 |
from AppDocData import MessageType |
679 |
|
680 |
message = 'error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno) |
681 |
App.mainWnd().addMessage.emit(MessageType.Error, message) |
682 |
|
683 |
if dataList[0] == '': |
684 |
dataList[0] = str(uuid.uuid4()) |
685 |
|
686 |
return dataList
|
687 |
|
688 |
def EvaluatedEQ(self): |
689 |
''' evaluate line no's From / To equipment '''
|
690 |
|
691 |
from EngineeringNozzleItem import QEngineeringNozzleItem |
692 |
from EngineeringVendorItem import QEngineeringVendorItem |
693 |
from EngineeringEquipmentItem import QEngineeringEquipmentItem |
694 |
|
695 |
if self.runs and self.runs[0]: |
696 |
items = self.runs[0].items |
697 |
if len(items) > 2: |
698 |
_attrs = self.getAttributes()
|
699 |
if type(items[0]) is QEngineeringNozzleItem: |
700 |
for connector in items[0].connectors: |
701 |
# From
|
702 |
if (type(connector.connectedItem) is QEngineeringVendorItem or type(connector.connectedItem) is QEngineeringEquipmentItem) and \ |
703 |
connector.connectedItem not in items: |
704 |
for _attr in _attrs: |
705 |
if _attr.Attribute == 'From_eq' and self.add_assoc_item(connector.connectedItem, at=_attr.AttrAt): |
706 |
_attr.AssocItem = connector.connectedItem |
707 |
break
|
708 |
break
|
709 |
|
710 |
if type(items[-1]) is QEngineeringNozzleItem: |
711 |
for connector in items[0].connectors: |
712 |
# To
|
713 |
if (type(connector.connectedItem) is QEngineeringVendorItem or type(connector.connectedItem) is QEngineeringEquipmentItem) and \ |
714 |
connector.connectedItem not in items: |
715 |
for _attr in _attrs: |
716 |
if _attr.Attribute == 'To_eq' and self.add_assoc_item(connector.connectedItem, at=_attr.AttrAt): |
717 |
_attr.AssocItem = connector.connectedItem |
718 |
break
|
719 |
break
|
720 |
|