hytos / DTI_PID / DTI_PID / Shapes / EngineeringSpecBreakItem.py @ 190a20fb
이력 | 보기 | 이력해설 | 다운로드 (6.33 KB)
1 |
# coding: utf-8
|
---|---|
2 | |
3 |
import sys |
4 |
import os |
5 |
import math |
6 |
from PyQt5.QtGui import * |
7 |
from PyQt5.QtCore import * |
8 |
from PyQt5.QtSvg import * |
9 |
from PyQt5.QtWidgets import (QApplication, QGraphicsItem) |
10 | |
11 |
from AppDocData import * |
12 |
from SymbolSvgItem import SymbolSvgItem |
13 |
from SymbolAttr import SymbolAttr |
14 |
from UserInputAttribute import UserInputAttribute |
15 |
from EngineeringConnectorItem import QEngineeringConnectorItem |
16 | |
17 |
class QEngineeringSpecBreakItem(SymbolSvgItem): |
18 |
"""
|
19 |
This is engineering specbreak item class
|
20 |
"""
|
21 | |
22 |
ZVALUE = 20
|
23 |
clicked = pyqtSignal(QGraphicsSvgItem) |
24 | |
25 |
'''
|
26 |
'''
|
27 |
def __init__(self, path, uid=None, flip=None): |
28 |
SymbolSvgItem.__init__(self, path, uid, flip)
|
29 | |
30 |
attr = SymbolAttr() |
31 |
attr.Attribute = 'UpStream'
|
32 |
attr.AttributeType = 'Comp Item'
|
33 |
self.attrs[attr] = None |
34 |
attr = SymbolAttr() |
35 |
attr.Attribute = 'DownStream'
|
36 |
attr.AttributeType = 'Comp Item'
|
37 |
self.attrs[attr] = None |
38 |
#attr = SymbolAttr()
|
39 |
#attr.Attribute = 'SetSpecs'
|
40 |
#attr.AttributeType = 'Link Dialog'
|
41 |
#self.attrs[attr] = 'Double Click'
|
42 |
'''
|
43 |
attr = SymbolAttr()
|
44 |
attr.Attribute = 'Spec'
|
45 |
attr.AttributeType = 'FluidCode'
|
46 |
self.attrs[attr] = ['P', 'OWS']
|
47 |
attr = SymbolAttr()
|
48 |
attr.Attribute = 'Spec'
|
49 |
attr.AttributeType = 'InsulationPurpose'
|
50 |
self.attrs[attr] = ['N', 'Ic']
|
51 |
'''
|
52 | |
53 | |
54 |
'''
|
55 |
@brief get attribute
|
56 |
@author humkyung
|
57 |
@date 2018.06.14
|
58 |
@history kyouho 2018.07.18 Add only attr QEngineeringTextItem
|
59 |
euisung 2019.01.15 return self.attrs
|
60 |
'''
|
61 |
def getAttributes(self): |
62 |
"""
|
63 |
attributes MUST have UpStream, DownStream attribute
|
64 |
"""
|
65 |
return self.attrs |
66 | |
67 |
'''
|
68 |
@brief generate xml code for nozzle
|
69 |
@author humkyung
|
70 |
@date 2018.07.19
|
71 |
'''
|
72 |
def toXml(self): |
73 |
from xml.etree.ElementTree import Element, SubElement, dump, ElementTree |
74 |
from EngineeringTextItem import QEngineeringTextItem |
75 |
from EngineeringSpecBreakItem import QEngineeringSpecBreakItem |
76 |
from SymbolAttr import SymbolAttr |
77 | |
78 |
try:
|
79 |
node = Element('SYMBOL')
|
80 |
uidNode = Element('UID')
|
81 |
uidNode.text = str(self.uid) |
82 |
node.append(uidNode) |
83 | |
84 |
nameNode = Element('NAME')
|
85 |
nameNode.text = self.name
|
86 |
node.append(nameNode) |
87 | |
88 |
typeNode = Element('TYPE')
|
89 |
typeNode.text = self.type
|
90 |
node.append(typeNode) |
91 | |
92 |
# write owner's uid to xml
|
93 |
if self.owner is not None: |
94 |
ownerNode = Element('OWNER')
|
95 |
ownerNode.text = str(self.owner.uid) |
96 |
node.append(ownerNode) |
97 |
# up to here
|
98 | |
99 |
originNode = Element('ORIGINALPOINT')
|
100 |
originNode.text = '{},{}'.format(self.origin[0], self.origin[1]) |
101 |
node.append(originNode) |
102 | |
103 |
connectorsNode = Element('CONNECTORS')
|
104 |
for connector in self.connectors: |
105 |
connectorNode = Element('CONNECTOR')
|
106 |
connectedItemNode = Element('CONNECTEDITEM')
|
107 |
connectedItemNode.text = str(connector.connectedItem.uid) if connector.connectedItem is not None else 'None' |
108 |
connectPointNode = Element('CONNECTPOINT')
|
109 |
connectPointNode.text = str(connector.connectPoint[0]) + ',' + str(connector.connectPoint[1]) |
110 |
sceneConnectPointNode = Element('SCENECONNECTPOINT')
|
111 |
sceneConnectPointNode.text = str(connector.sceneConnectPoint[0]) + ',' + str(connector.sceneConnectPoint[1]) |
112 | |
113 |
connectorNode.append(connectedItemNode) |
114 |
connectorNode.append(connectPointNode) |
115 |
connectorNode.append(sceneConnectPointNode) |
116 |
connectorsNode.append(connectorNode) |
117 |
node.append(connectorsNode) |
118 | |
119 |
connectionNode = Element('CONNECTIONPOINT')
|
120 |
connection_point = [] |
121 |
if self.connectors is not None: |
122 |
for connector in self.connectors: |
123 |
connection_point.append(repr(connector))
|
124 |
connectionNode.text = '/'.join(connection_point)
|
125 |
node.append(connectionNode) |
126 | |
127 |
rect = self.sceneBoundingRect()
|
128 |
locNode = Element('LOCATION')
|
129 |
locNode.text = '{},{}'.format(self.loc[0], self.loc[1]) |
130 |
node.append(locNode) |
131 | |
132 |
sizeNode = Element('SIZE')
|
133 |
sizeNode.text = '{},{}'.format(rect.width(), rect.height())
|
134 |
node.append(sizeNode) |
135 | |
136 |
angleNode = Element('ANGLE')
|
137 |
angleNode.text = str(self.angle) |
138 |
node.append(angleNode) |
139 | |
140 |
parentSymbolNode = Element('PARENT')
|
141 |
parentSymbolNode.text = str(self.parentSymbol) |
142 |
node.append(parentSymbolNode) |
143 | |
144 |
childSymbolNode = Element('CHILD')
|
145 |
childSymbolNode.text = str(self.childSymbol) |
146 |
node.append(childSymbolNode) |
147 | |
148 |
hasInstrumentLabelNode = Element('HASINSTRUMENTLABEL')
|
149 |
hasInstrumentLabelNode.text = str(self.hasInstrumentLabel) |
150 |
node.append(hasInstrumentLabelNode) |
151 | |
152 |
areaNode = Element('AREA')
|
153 |
areaNode.text = self.area
|
154 |
node.append(areaNode) |
155 | |
156 |
attributesNode = Element('SYMBOLATTRIBUTES')
|
157 |
_attrs = list(self.getAttributes()) |
158 |
for attr in _attrs: |
159 |
if type(attr) is SymbolAttr: |
160 |
_node = attr.toXml() |
161 |
if attr.AttributeType != 'Spec': |
162 |
_node.text = self.attrs[attr]
|
163 |
else:
|
164 |
_node.text = str(self.attrs[attr][0]) + ',' + str(self.attrs[attr][1]) |
165 |
attributesNode.append(_node) |
166 |
|
167 |
node.append(attributesNode) |
168 | |
169 |
currentPointModeIndexNode = Element('CURRENTPOINTMODEINDEX')
|
170 |
currentPointModeIndexNode.text = str(self.currentPointModeIndex) |
171 |
node.append(currentPointModeIndexNode) |
172 |
except Exception as ex: |
173 |
from App import App |
174 |
from AppDocData import MessageType |
175 | |
176 |
message = 'error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno) |
177 |
App.mainWnd().addMessage.emit(MessageType.Error, message) |
178 | |
179 |
return node
|