개정판 565ec74a
issue #1445: PipingComponent 추가
Change-Id: I65a5300a686bcdaf1dc1ca5966f8a22ff8384ad2
DTI_PID/DTI_PID/DEXPI/PipingComponent.py | ||
---|---|---|
1 |
# coding: utf-8 |
|
2 |
""" This is Equipment module """ |
|
3 |
|
|
4 |
from xml.etree.ElementTree import Element, SubElement, dump, ElementTree, parse, tostring |
|
5 |
from PyQt5.QtWidgets import * |
|
6 |
from PyQt5.QtGui import * |
|
7 |
from PyQt5.QtCore import * |
|
8 |
from .Extent import Extent |
|
9 |
from .Presentation import Presentation |
|
10 |
from .Shape import Point, Line as DEXPI_Line, ConnectionPoints, GenericAttributes, BsplineCurve |
|
11 |
|
|
12 |
|
|
13 |
class PipingComponent: |
|
14 |
ITEMS = 0 |
|
15 |
|
|
16 |
def __init__(self): |
|
17 |
pass |
|
18 |
|
|
19 |
@staticmethod |
|
20 |
def to_transform(matrix: str) -> QTransform: |
|
21 |
"""convert given value to transform""" |
|
22 |
import sys |
|
23 |
import re |
|
24 |
|
|
25 |
res = None |
|
26 |
try: |
|
27 |
if 'matrix' in matrix: |
|
28 |
_str = matrix[len('matrix('):-1] |
|
29 |
tokens = _str.split(',') |
|
30 |
|
|
31 |
res = QTransform(float(tokens[0]), float(tokens[1]), |
|
32 |
float(tokens[2]), float(tokens[3]), |
|
33 |
float(tokens[4]), float(tokens[5])) |
|
34 |
else: |
|
35 |
float_re = '[+-]?(\d+(\.\d*)?|\.\d+)([eE][+-]?\d+)?' |
|
36 |
|
|
37 |
translate_trans = None |
|
38 |
if 'translate' in matrix: |
|
39 |
match = re.search(f"translate\({float_re},{float_re}\)", matrix) |
|
40 |
if match: |
|
41 |
_str = match.group()[len('translate('):-1] |
|
42 |
tokens = _str.split(',') |
|
43 |
|
|
44 |
translate_trans = QTransform() |
|
45 |
translate_trans.translate(float(tokens[0]), float(tokens[1])) |
|
46 |
|
|
47 |
scale_trans = None |
|
48 |
if 'scale' in matrix: |
|
49 |
match = re.search(f"scale\({float_re},{float_re}\)", matrix) |
|
50 |
if match: |
|
51 |
_str = match.group()[len('scale('):-1] |
|
52 |
tokens = _str.split(',') |
|
53 |
|
|
54 |
scale_trans = QTransform() |
|
55 |
scale_trans.scale(float(tokens[0]), float(tokens[1])) |
|
56 |
|
|
57 |
if translate_trans and scale_trans: |
|
58 |
res = scale_trans * translate_trans |
|
59 |
elif translate_trans: |
|
60 |
res = translate_trans |
|
61 |
elif scale_trans: |
|
62 |
res = scale_trans |
|
63 |
except Exception as ex: |
|
64 |
message = f"error occurred({repr(ex)}) in {sys.exc_info()[-1].tb_frame.f_code.co_filename}:" \ |
|
65 |
f"{sys.exc_info()[-1].tb_lineno}" |
|
66 |
print(message) |
|
67 |
|
|
68 |
return res |
|
69 |
|
|
70 |
@staticmethod |
|
71 |
def apply_transform(trans: QTransform, pos: complex) -> complex: |
|
72 |
"""transform given pos and then return the result""" |
|
73 |
res = trans.map(QPointF(pos.real, pos.imag)) |
|
74 |
return complex(res.x(), res.y()) |
|
75 |
|
|
76 |
@staticmethod |
|
77 |
def to_xml(item) -> Element: |
|
78 |
"""return element for equipment""" |
|
79 |
import sys |
|
80 |
from svg.path import Path, Line, Arc, CubicBezier, QuadraticBezier, parse_path |
|
81 |
from svg.path.path import Move |
|
82 |
|
|
83 |
try: |
|
84 |
node = Element('PipingComponent') |
|
85 |
node.attrib['ID'] = f"XPC_{PipingComponent.ITEMS}" |
|
86 |
PipingComponent.ITEMS += 1 |
|
87 |
node.attrib['ComponentClass'] = '' |
|
88 |
node.attrib['ComponentName'] = '' |
|
89 |
node.attrib['ComponentType'] = 'Explicit' |
|
90 |
node.attrib['Status'] = 'Current' |
|
91 |
|
|
92 |
Presentation.to_xml(node, layer='0', color='0', line_type='0', line_weight=1, r=0, g=0, b=0) |
|
93 |
Extent.to_xml(node, item=item) |
|
94 |
|
|
95 |
_node = SubElement(node, 'Position') |
|
96 |
pt = item.pos() |
|
97 |
_node.append(Point.to_xml('Location', pt.x(), pt.y())) |
|
98 |
_node.append(Point.to_xml('Axis', 0, 0, 1)) |
|
99 |
_node.append(Point.to_xml('Reference', 1, 0, 0)) |
|
100 |
|
|
101 |
node.append(Point.to_xml('Scale', 1, 1, 1)) |
|
102 |
|
|
103 |
_node = SubElement(node, 'PersistentID') |
|
104 |
_node.attrib['Identifier'] = str(item.uid) |
|
105 |
_node.attrib['Context'] = 'ID2' |
|
106 |
|
|
107 |
svg = item.to_svg(parent=None) |
|
108 |
matrix_trans = None |
|
109 |
if 'transform' in svg[0].attrib: |
|
110 |
matrix_trans = PipingComponent.to_transform(svg[0].attrib['transform']) |
|
111 |
|
|
112 |
paths = svg[0].findall('path') |
|
113 |
for path in paths: |
|
114 |
_trans = PipingComponent.to_transform(path.attrib['transform']) |
|
115 |
trans = _trans * matrix_trans |
|
116 |
path_ele = parse_path(path.attrib['d']) |
|
117 |
for idx, ele in enumerate(path_ele): |
|
118 |
if type(ele) is Move: |
|
119 |
continue |
|
120 |
elif type(ele) is Line: |
|
121 |
line = DEXPI_Line(PipingComponent.apply_transform(trans, ele.start), |
|
122 |
PipingComponent.apply_transform(trans, ele.end)) |
|
123 |
node.append(line.to_xml()) |
|
124 |
elif type(ele) is Arc: |
|
125 |
continue |
|
126 |
elif type(ele) is CubicBezier: |
|
127 |
bspline_curve_node = BsplineCurve.to_xml(controls=[PipingComponent.apply_transform(trans, ele.start), |
|
128 |
PipingComponent.apply_transform(trans, ele.control1), |
|
129 |
PipingComponent.apply_transform(trans, ele.control2), |
|
130 |
PipingComponent.apply_transform(trans, ele.end)], |
|
131 |
_type='BsplineCurve', knots=[]) |
|
132 |
node.append(bspline_curve_node) |
|
133 |
elif type(ele) is QuadraticBezier: |
|
134 |
continue |
|
135 |
else: |
|
136 |
continue |
|
137 |
|
|
138 |
generic_attributes = GenericAttributes(item) |
|
139 |
_attr_node = generic_attributes.to_xml() |
|
140 |
if _attr_node: |
|
141 |
node.append(_attr_node) |
|
142 |
|
|
143 |
connection_points_node = ConnectionPoints(item.connectors) |
|
144 |
_conn_node = connection_points_node.to_xml() |
|
145 |
if _conn_node: |
|
146 |
node.append(_conn_node) |
|
147 |
|
|
148 |
return node |
|
149 |
except Exception as ex: |
|
150 |
message = f"error occurred({repr(ex)}) in {sys.exc_info()[-1].tb_frame.f_code.co_filename}:" \ |
|
151 |
f"{sys.exc_info()[-1].tb_lineno}" |
|
152 |
print(message) |
|
153 |
|
|
154 |
|
|
155 |
class Nozzle: |
|
156 |
def __init__(self): |
|
157 |
pass |
|
158 |
|
|
159 |
@staticmethod |
|
160 |
def to_xml(item) -> Element: |
|
161 |
"""return element for nozzle""" |
|
162 |
|
|
163 |
node = Element('Nozzle') |
|
164 |
node.attrib['ID'] = '' |
|
165 |
node.attrib['TagName'] = '' |
|
166 |
node.attrib['ComponentClass'] = 'Nozzle' |
|
167 |
node.attrib['ComponentName'] = '' |
|
168 |
node.attrib['ComponentType'] = 'Explicit' |
|
169 |
node.attrib['Status'] = 'Current' |
|
170 |
|
|
171 |
Presentation.to_xml(node, layer='30', color='0', line_type='0', line_weight=0.1, r=0, g=0, b=0) |
|
172 |
|
|
173 |
return node |
DTI_PID/DTI_PID/DEXPI/PipingNetworkSegment.py | ||
---|---|---|
6 | 6 |
from .Extent import Extent |
7 | 7 |
from .Shape import Point |
8 | 8 |
from .Presentation import Presentation |
9 |
from .PipingComponent import PipingComponent |
|
9 | 10 |
|
10 | 11 |
|
11 | 12 |
class PipingNetworkSegment: |
... | ... | |
19 | 20 |
"""return element for PipingNetworkSegment""" |
20 | 21 |
|
21 | 22 |
from EngineeringLineItem import QEngineeringLineItem |
23 |
from SymbolSvgItem import SymbolSvgItem |
|
22 | 24 |
|
23 | 25 |
node = SubElement(parent, 'PipingNetworkSegment') |
24 | 26 |
node.attrib['ID'] = f"XNG_{PipingNetworkSegment.ITEMS}" |
... | ... | |
30 | 32 |
for item in run.items: |
31 | 33 |
if type(item) is QEngineeringLineItem: |
32 | 34 |
PipingNetworkSegment.line_to_xml(node, item) |
35 |
elif issubclass(type(item), SymbolSvgItem): |
|
36 |
comp_node = PipingComponent.to_xml(item) |
|
37 |
if comp_node: |
|
38 |
node.append(comp_node) |
|
33 | 39 |
|
34 | 40 |
return node |
35 | 41 |
|
내보내기 Unified diff