hytos / DTI_PID / DTI_PID / Shapes / EngineeringEndBreakItem.py @ 7b02722f
이력 | 보기 | 이력해설 | 다운로드 (4.69 KB)
1 |
# coding: utf-8
|
---|---|
2 |
"""
|
3 |
This is Engineering Error 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 * |
13 |
|
14 |
from SymbolSvgItem import SymbolSvgItem |
15 |
from SymbolAttr import SymbolAttr |
16 |
|
17 |
class QEngineeringEndBreakItem(SymbolSvgItem): |
18 |
"""
|
19 |
This is Engineering Error Item class
|
20 |
"""
|
21 |
clicked = pyqtSignal(QGraphicsSvgItem) |
22 |
|
23 |
'''
|
24 |
'''
|
25 |
ZVALUE = 8
|
26 |
def __init__(self, path, uid=None, flip=0): |
27 |
from SymbolAttr import SymbolProp |
28 |
from EngineeringFreezeItem import QEngineeringFreezeItem |
29 |
|
30 |
SymbolSvgItem.__init__(self, path, uid, flip=flip)
|
31 |
self.setZValue(QEngineeringEndBreakItem.ZVALUE)
|
32 |
#self.connected_lines = []
|
33 |
#attr = SymbolAttr()
|
34 |
#attr.Attribute = 'Connected Line'
|
35 |
#attr.AttributeType = 'Comp Item'
|
36 |
#self.attrs[attr] = None
|
37 |
|
38 |
self._properties = \
|
39 |
{\ |
40 |
SymbolProp(None, 'Connected Item', 'Comp Item'):None, SymbolProp(None, 'Freeze', 'Boolean'):False |
41 |
} |
42 |
|
43 |
""" create freeze control """
|
44 |
#self.freeze_item = QEngineeringFreezeItem(-QEngineeringFreezeItem.FREEZE_SIZE*0.5, -QEngineeringFreezeItem.FREEZE_SIZE*0.5, QEngineeringFreezeItem.FREEZE_SIZE, QEngineeringFreezeItem.FREEZE_SIZE)
|
45 |
#self.freeze_item.setParentItem(self)
|
46 |
#self.freeze_item.setZValue(self.zValue() + 1)
|
47 |
#self.freeze_item.setPen(Qt.black)
|
48 |
|
49 |
|
50 |
'''
|
51 |
def setPosition(self, loc, origin):
|
52 |
transform = QTransform()
|
53 |
transform.translate(loc[0] - origin[0], loc[1] - origin[1])
|
54 |
self.origin = origin
|
55 |
self.loc = loc
|
56 |
self.setTransform(transform)
|
57 |
|
58 |
def getAttributes(self):
|
59 |
"""
|
60 |
attributes MUST have Connected Line attribute
|
61 |
"""
|
62 |
return self.attrs
|
63 |
|
64 |
def keyPressEvent(self, event):
|
65 |
if self.isSelected() and event.key() == Qt.Key_Delete:
|
66 |
self.scene().removeItem(self)
|
67 |
'''
|
68 |
|
69 |
'''
|
70 |
@staticmethod
|
71 |
def fromXml(node):
|
72 |
import uuid
|
73 |
from AppDocData import AppDocData
|
74 |
|
75 |
end_break = None
|
76 |
|
77 |
try:
|
78 |
docdata = AppDocData.instance()
|
79 |
dataPath = docdata.getErrorItemSvgPath()
|
80 |
|
81 |
uidNode = node.find('UID')
|
82 |
uid = uidNode.text if uidNode is not None else uuid.uuid4() # generate UUID
|
83 |
|
84 |
pt = [float(x) for x in node.find('LOCATION').text.split(',')]
|
85 |
name = node.find('NAME').text
|
86 |
origin = [float(x) for x in node.find('ORIGINALPOINT').text.split(',')]
|
87 |
areaNode = node.find('AREA').text
|
88 |
connectedLineNode = [uid for uid in node.find('CONNECTED_LINE').text.split(',')]
|
89 |
|
90 |
end_break = SymbolSvgItem.createItem('End Break', dataPath)
|
91 |
end_break.setPosition(pt, origin)
|
92 |
end_break.connected_lines = [connectedLineNode[0], connectedLineNode[1]]
|
93 |
end_break.setToolTip(str(end_break.connected_lines))
|
94 |
end_break.area = areaNode
|
95 |
end_break.name = name
|
96 |
except Exception as ex:
|
97 |
from App import App
|
98 |
from AppDocData import MessageType
|
99 |
|
100 |
message = 'error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno)
|
101 |
App.mainWnd().addMessage.emit(MessageType.Error, message)
|
102 |
|
103 |
return end_break
|
104 |
|
105 |
|
106 |
def toXml(self):
|
107 |
from xml.etree.ElementTree import Element, SubElement, dump, ElementTree
|
108 |
|
109 |
try:
|
110 |
node = Element('END_BREAK')
|
111 |
uidNode = Element('UID')
|
112 |
uidNode.text = str(self.uid)
|
113 |
node.append(uidNode)
|
114 |
|
115 |
nameNode = Element('NAME')
|
116 |
nameNode.text = self.name
|
117 |
node.append(nameNode)
|
118 |
|
119 |
areaNode = Element('AREA')
|
120 |
areaNode.text = self.area
|
121 |
node.append(areaNode)
|
122 |
|
123 |
locNode = Element('LOCATION')
|
124 |
locNode.text = '{},{}'.format(self.loc[0], self.loc[1])
|
125 |
node.append(locNode)
|
126 |
|
127 |
originNode = Element('ORIGINALPOINT')
|
128 |
originNode.text = '{},{}'.format(self.origin[0], self.origin[1])
|
129 |
node.append(originNode)
|
130 |
|
131 |
connectedLineNode = Element('CONNECTED_LINE')
|
132 |
connectedLineNode.text = '{},{}'.format(self.connected_lines[0], self.connected_lines[1])
|
133 |
node.append(connectedLineNode)
|
134 |
|
135 |
except Exception as ex:
|
136 |
from App import App
|
137 |
from AppDocData import MessageType
|
138 |
|
139 |
message = 'error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno)
|
140 |
App.mainWnd().addMessage.emit(MessageType.Error, message)
|
141 |
|
142 |
return None
|
143 |
|
144 |
return node
|
145 |
'''
|