개정판 5a3ae911
issue #1445: ShapeCatalogue 형상을 참조하도록 수정
Change-Id: I4aec964128de69860b21d7d9f1f2138cf469634c
DTI_PID/DTI_PID/DEXPI/Equipment.py | ||
---|---|---|
7 | 7 |
from PyQt5.QtCore import * |
8 | 8 |
from .Extent import Extent |
9 | 9 |
from .Presentation import Presentation |
10 |
from .Shape import Point, Line as DEXPI_Line, ConnectionPoints, GenericAttributes, BsplineCurve |
|
10 |
from .Shape import Point, ZAxis, Reference, Line as DEXPI_Line, ConnectionPoints, GenericAttributes, BsplineCurve
|
|
11 | 11 |
from .Transform import Transform |
12 | 12 |
from .Text import Text |
13 | 13 |
|
... | ... | |
30 | 30 |
node.attrib['ID'] = f"XME_{Equipment.ITEMS}" |
31 | 31 |
Equipment.ITEMS += 1 |
32 | 32 |
node.attrib['TagName'] = item.tag_no if item.tag_no else '' |
33 |
node.attrib['ComponentClass'] = ''
|
|
34 |
node.attrib['ComponentName'] = ''
|
|
33 |
node.attrib['ComponentClass'] = f"{item.type}/{item.name}"
|
|
34 |
node.attrib['ComponentName'] = item.name
|
|
35 | 35 |
node.attrib['ComponentType'] = 'Explicit' |
36 | 36 |
node.attrib['Status'] = 'Current' |
37 | 37 |
|
... | ... | |
39 | 39 |
Extent.to_xml(node, item=item) |
40 | 40 |
|
41 | 41 |
_node = SubElement(node, 'Position') |
42 |
pt = item.pos()
|
|
43 |
_node.append(Point.to_xml('Location', pt.x(), pt.y())) |
|
44 |
_node.append(Point.to_xml('Axis', 0, 0, 1))
|
|
45 |
_node.append(Point.to_xml('Reference', 1, 0, 0))
|
|
42 |
pt, rect = item.pos(), item.scene().sceneRect()
|
|
43 |
_node.append(Point.to_xml('Location', pt.x(), rect.height() - pt.y()))
|
|
44 |
ZAxis.to_xml(_node)
|
|
45 |
Reference.to_xml(_node, item)
|
|
46 | 46 |
|
47 | 47 |
node.append(Point.to_xml('Scale', 1, 1, 1)) |
48 | 48 |
|
... | ... | |
53 | 53 |
for text in texts: |
54 | 54 |
Text.to_xml(node, text, item) |
55 | 55 |
|
56 |
svg = item.to_svg(parent=None) |
|
57 |
matrix_trans = None |
|
58 |
if 'transform' in svg[0].attrib: |
|
59 |
matrix_trans = Transform.to_transform(svg[0].attrib['transform']) |
|
60 |
|
|
61 |
paths = svg[0].findall('path') |
|
62 |
for path in paths: |
|
63 |
_trans = Transform.to_transform(path.attrib['transform']) |
|
64 |
trans = _trans * matrix_trans |
|
65 |
path_ele = parse_path(path.attrib['d']) |
|
66 |
for idx, ele in enumerate(path_ele): |
|
67 |
if type(ele) is Move: |
|
68 |
continue |
|
69 |
elif type(ele) is Line: |
|
70 |
line = DEXPI_Line(Transform.apply_transform(trans, ele.start), |
|
71 |
Transform.apply_transform(trans, ele.end)) |
|
72 |
node.append(line.to_xml(item.scene().sceneRect())) |
|
73 |
elif type(ele) is Arc: |
|
74 |
continue |
|
75 |
elif type(ele) is CubicBezier: |
|
76 |
_node = DEXPI_Line(Transform.apply_transform(trans, ele.start), |
|
77 |
Transform.apply_transform(trans, ele.control1)) |
|
78 |
node.append(_node.to_xml(item.scene().sceneRect())) |
|
79 |
|
|
80 |
_node = DEXPI_Line(Transform.apply_transform(trans, ele.control1), |
|
81 |
Transform.apply_transform(trans, ele.control2)) |
|
82 |
node.append(_node.to_xml(item.scene().sceneRect())) |
|
83 |
|
|
84 |
_node = DEXPI_Line(Transform.apply_transform(trans, ele.control2), |
|
85 |
Transform.apply_transform(trans, ele.end)) |
|
86 |
node.append(_node.to_xml(item.scene().sceneRect())) |
|
87 |
""" |
|
88 |
bspline_curve_node = BsplineCurve.to_xml(controls=[Equipment.apply_transform(trans, ele.start), |
|
89 |
Equipment.apply_transform(trans, ele.control1), |
|
90 |
Equipment.apply_transform(trans, ele.control2), |
|
91 |
Equipment.apply_transform(trans, ele.end)], |
|
92 |
_type='BsplineCurve', knots=[]) |
|
93 |
node.append(bspline_curve_node) |
|
94 |
""" |
|
95 |
elif type(ele) is QuadraticBezier: |
|
96 |
continue |
|
97 |
else: |
|
98 |
continue |
|
99 |
|
|
100 | 56 |
generic_attributes = GenericAttributes(item) |
101 | 57 |
_attr_node = generic_attributes.to_xml() |
102 | 58 |
if _attr_node: |
103 | 59 |
node.append(_attr_node) |
104 | 60 |
|
105 |
connection_points_node = ConnectionPoints(item.connectors)
|
|
106 |
_conn_node = connection_points_node.to_xml()
|
|
61 |
origin = item.mapToScene(item.transformOriginPoint())
|
|
62 |
_conn_node = ConnectionPoints.to_xml([origin.x(), origin.y()], item.connectors)
|
|
107 | 63 |
if _conn_node: |
108 | 64 |
node.append(_conn_node) |
109 | 65 |
|
DTI_PID/DTI_PID/DEXPI/PipingComponent.py | ||
---|---|---|
7 | 7 |
from PyQt5.QtCore import * |
8 | 8 |
from .Extent import Extent |
9 | 9 |
from .Presentation import Presentation |
10 |
from .Shape import Point, Line as DEXPI_Line, ConnectionPoints, GenericAttributes, BsplineCurve |
|
10 |
from .Shape import Point, ZAxis, Reference, Line as DEXPI_Line, ConnectionPoints, GenericAttributes, BsplineCurve
|
|
11 | 11 |
from .Transform import Transform |
12 | 12 |
from .Text import Text |
13 | 13 |
|
... | ... | |
22 | 22 |
def to_xml(texts: list, item) -> Element: |
23 | 23 |
"""return element for equipment""" |
24 | 24 |
import sys |
25 |
import math |
|
25 | 26 |
from svg.path import Path, Line, Arc, CubicBezier, QuadraticBezier, parse_path |
26 | 27 |
from svg.path.path import Move |
27 | 28 |
|
... | ... | |
29 | 30 |
node = Element('PipingComponent') |
30 | 31 |
node.attrib['ID'] = f"XPC_{PipingComponent.ITEMS}" |
31 | 32 |
PipingComponent.ITEMS += 1 |
32 |
node.attrib['ComponentClass'] = ''
|
|
33 |
node.attrib['ComponentName'] = ''
|
|
33 |
node.attrib['ComponentClass'] = f"{item.type}/{item.name}"
|
|
34 |
node.attrib['ComponentName'] = item.name
|
|
34 | 35 |
node.attrib['ComponentType'] = 'Explicit' |
35 | 36 |
node.attrib['Status'] = 'Current' |
36 | 37 |
|
... | ... | |
41 | 42 |
Text.to_xml(node, text, item) |
42 | 43 |
|
43 | 44 |
_node = SubElement(node, 'Position') |
44 |
pt = item.pos() |
|
45 |
_node.append(Point.to_xml('Location', pt.x(), pt.y())) |
|
46 |
_node.append(Point.to_xml('Axis', 0, 0, 1)) |
|
47 |
_node.append(Point.to_xml('Reference', 1, 0, 0)) |
|
45 |
origin = item.mapToScene(item.transformOriginPoint()) |
|
46 |
pt, rect = item.pos(), item.scene().sceneRect() |
|
47 |
trans = QTransform() |
|
48 |
trans.rotateRadians(item.angle) |
|
49 |
offset_x, offset_y = trans.map(item.symbolOrigin[0], item.symbolOrigin[1]) |
|
50 |
_node.append(Point.to_xml('Location', origin.x() - offset_x, rect.height() - origin.y() + offset_y)) |
|
51 |
ZAxis.to_xml(_node) |
|
52 |
Reference.to_xml(_node, item) |
|
48 | 53 |
|
49 | 54 |
node.append(Point.to_xml('Scale', 1, 1, 1)) |
50 | 55 |
|
... | ... | |
52 | 57 |
_node.attrib['Identifier'] = str(item.uid) |
53 | 58 |
_node.attrib['Context'] = 'ID2' |
54 | 59 |
|
55 |
svg = item.to_svg(parent=None) |
|
56 |
matrix_trans = None |
|
57 |
if 'transform' in svg[0].attrib: |
|
58 |
matrix_trans = Transform.to_transform(svg[0].attrib['transform']) |
|
59 |
|
|
60 |
paths = svg[0].findall('path') |
|
61 |
for path in paths: |
|
62 |
_trans = Transform.to_transform(path.attrib['transform']) |
|
63 |
trans = _trans * matrix_trans |
|
64 |
path_ele = parse_path(path.attrib['d']) |
|
65 |
for idx, ele in enumerate(path_ele): |
|
66 |
if type(ele) is Move: |
|
67 |
continue |
|
68 |
elif type(ele) is Line: |
|
69 |
line = DEXPI_Line(Transform.apply_transform(trans, ele.start), |
|
70 |
Transform.apply_transform(trans, ele.end)) |
|
71 |
node.append(line.to_xml(item.scene().sceneRect())) |
|
72 |
elif type(ele) is Arc: |
|
73 |
continue |
|
74 |
elif type(ele) is CubicBezier: |
|
75 |
_node = DEXPI_Line(Transform.apply_transform(trans, ele.start), |
|
76 |
Transform.apply_transform(trans, ele.control1)) |
|
77 |
node.append(_node.to_xml(item.scene().sceneRect())) |
|
78 |
|
|
79 |
_node = DEXPI_Line(Transform.apply_transform(trans, ele.control1), |
|
80 |
Transform.apply_transform(trans, ele.control2)) |
|
81 |
node.append(_node.to_xml(item.scene().sceneRect())) |
|
82 |
|
|
83 |
_node = DEXPI_Line(Transform.apply_transform(trans, ele.control2), |
|
84 |
Transform.apply_transform(trans, ele.end)) |
|
85 |
node.append(_node.to_xml(item.scene().sceneRect())) |
|
86 |
|
|
87 |
""" |
|
88 |
bspline_curve_node = BsplineCurve.to_xml(controls=[PipingComponent.apply_transform(trans, ele.start), |
|
89 |
PipingComponent.apply_transform(trans, ele.control1), |
|
90 |
PipingComponent.apply_transform(trans, ele.control2), |
|
91 |
PipingComponent.apply_transform(trans, ele.end)], |
|
92 |
_type='BsplineCurve', knots=[]) |
|
93 |
node.append(bspline_curve_node) |
|
94 |
""" |
|
95 |
elif type(ele) is QuadraticBezier: |
|
96 |
continue |
|
97 |
else: |
|
98 |
continue |
|
99 |
|
|
100 | 60 |
generic_attributes = GenericAttributes(item) |
101 | 61 |
_attr_node = generic_attributes.to_xml() |
102 | 62 |
if _attr_node: |
103 | 63 |
node.append(_attr_node) |
104 | 64 |
|
105 |
connection_points_node = ConnectionPoints(item.connectors) |
|
106 |
_conn_node = connection_points_node.to_xml() |
|
65 |
_conn_node = ConnectionPoints.to_xml([origin.x(), origin.y()], item.connectors) |
|
107 | 66 |
if _conn_node: |
108 | 67 |
node.append(_conn_node) |
109 | 68 |
|
DTI_PID/DTI_PID/DEXPI/PipingNetworkSegment.py | ||
---|---|---|
7 | 7 |
from PyQt5.QtCore import * |
8 | 8 |
from EngineeringTextItem import QEngineeringTextItem |
9 | 9 |
from .Extent import Extent |
10 |
from .Shape import Point, Line as DEXPI_Line |
|
10 |
from .Shape import Point, CenterLine, Line as DEXPI_Line
|
|
11 | 11 |
from .Presentation import Presentation |
12 | 12 |
from .PipingComponent import PipingComponent |
13 | 13 |
from .Transform import Transform |
... | ... | |
35 | 35 |
|
36 | 36 |
for item in run.items: |
37 | 37 |
if type(item) is QEngineeringLineItem: |
38 |
line = DEXPI_Line(Transform.apply_transform(QTransform(), |
|
39 |
complex(item.start_point()[0], item.start_point()[1])), |
|
40 |
Transform.apply_transform(QTransform(), |
|
41 |
complex(item.end_point()[0], item.end_point()[1]))) |
|
42 |
node.append(line.to_xml(scene.sceneRect())) |
|
38 |
CenterLine.to_xml(node, item) |
|
43 | 39 |
elif issubclass(type(item), SymbolSvgItem): |
44 | 40 |
texts = [child for child in scene.items() if type(child) is QEngineeringTextItem and |
45 | 41 |
str(child.owner) == str(item.uid)] |
... | ... | |
50 | 46 |
|
51 | 47 |
return node |
52 | 48 |
|
53 |
@staticmethod |
|
54 |
def line_to_xml(parent: Element, line) -> Element: |
|
55 |
"""return element for CenterLine""" |
|
56 |
|
|
57 |
node = SubElement(parent, 'CenterLine') |
|
58 |
node.attrib['NumPoints'] = '2' |
|
59 |
|
|
60 |
Presentation.to_xml(node, layer='20', color='0', line_type='1', line_weight=0.5, r=0, g=0, b=0) |
|
61 |
|
|
62 |
Extent.to_xml(node, line) |
|
63 |
x, y = line.start_point()[0], line.start_point()[1] |
|
64 |
node.append(Point.to_xml('Coordinate', x=x, y=y)) |
|
65 |
x, y = line.end_point()[0], line.end_point()[1] |
|
66 |
node.append(Point.to_xml('Coordinate', x=x, y=y)) |
|
67 |
|
|
68 |
return node |
DTI_PID/DTI_PID/DEXPI/Shape.py | ||
---|---|---|
4 | 4 |
from xml.etree.ElementTree import Element, SubElement, dump, ElementTree, parse, tostring |
5 | 5 |
from PyQt5.QtCore import * |
6 | 6 |
from .Presentation import Presentation |
7 |
from .Extent import Extent |
|
7 | 8 |
|
8 | 9 |
|
9 | 10 |
class Point: |
10 |
def __init__(self): |
|
11 |
pass |
|
12 |
|
|
13 | 11 |
@staticmethod |
14 | 12 |
def to_xml(name: str, x: float, y: float, z: float = 0) -> Element: |
15 | 13 |
"""return element for control point""" |
... | ... | |
22 | 20 |
return node |
23 | 21 |
|
24 | 22 |
|
23 |
class ZAxis: |
|
24 |
@staticmethod |
|
25 |
def to_xml(parent: Element) -> Element: |
|
26 |
"""return element for control point""" |
|
27 |
|
|
28 |
node = SubElement(parent, 'Axis') |
|
29 |
node.attrib['X'] = '0' |
|
30 |
node.attrib['Y'] = '0' |
|
31 |
node.attrib['Z'] = '1' |
|
32 |
|
|
33 |
return node |
|
34 |
|
|
35 |
|
|
36 |
class Reference: |
|
37 |
@staticmethod |
|
38 |
def to_xml(parent: Element, item) -> Element: |
|
39 |
"""return element for reference""" |
|
40 |
import math |
|
41 |
|
|
42 |
node = SubElement(parent, 'Reference') |
|
43 |
node.attrib['X'] = str(round(math.cos(item.angle), 1)) |
|
44 |
node.attrib['Y'] = str(round(math.sin(item.angle), 1)) |
|
45 |
node.attrib['Z'] = "0" |
|
46 |
|
|
47 |
return node |
|
48 |
|
|
49 |
|
|
25 | 50 |
class Line: |
26 | 51 |
def __init__(self, start: complex, end: complex): |
27 | 52 |
self.start = start |
28 | 53 |
self.end = end |
29 | 54 |
|
30 |
def to_xml(self, rect: QRectF): |
|
31 |
node = Element('Line') |
|
55 |
def extent(self): |
|
56 |
"""return extent""" |
|
57 |
|
|
58 |
min_x = min(self.start.real, self.end.real) |
|
59 |
min_y = min(self.start.imag, self.end.imag) |
|
60 |
max_x = max(self.start.real, self.end.real) |
|
61 |
max_y = max(self.start.imag, self.end.imag) |
|
62 |
|
|
63 |
return min_x, min_y, max_x, max_y |
|
64 |
|
|
65 |
def to_xml(self, name: str, rect: QRectF) -> Element: |
|
66 |
"""write line to element""" |
|
67 |
|
|
68 |
node = Element(name) |
|
32 | 69 |
Presentation.to_xml(node, layer='125', color='0', line_type='1', line_weight=0.35, r=0, g=0, b=0) |
33 | 70 |
extent_node = SubElement(node, 'Extent') |
34 | 71 |
min_node = SubElement(extent_node, 'Min') |
35 |
min_node.attrib['X'] = str(min(self.start.real, self.end.real)) |
|
36 |
min_node.attrib['Y'] = str(min(self.start.imag, self.end.imag)) |
|
72 |
|
|
73 |
start_x, start_y = self.start.real, rect.height() - self.start.imag if rect else self.start.imag |
|
74 |
end_x, end_y = self.end.real, rect.height() - self.end.imag if rect else self.end.imag |
|
75 |
|
|
76 |
min_node.attrib['X'] = str(min(start_x, end_x)) |
|
77 |
min_node.attrib['Y'] = str(min(start_y, end_y)) |
|
37 | 78 |
min_node.attrib['Z'] = '0' |
38 | 79 |
max_node = SubElement(extent_node, 'Max') |
39 |
max_node.attrib['X'] = str(max(self.start.real, self.end.real))
|
|
40 |
max_node.attrib['Y'] = str(max(self.start.imag, self.end.imag))
|
|
80 |
max_node.attrib['X'] = str(max(start_x, end_x))
|
|
81 |
max_node.attrib['Y'] = str(max(start_y, end_y))
|
|
41 | 82 |
max_node.attrib['Z'] = '0' |
42 | 83 |
coordinate_node = SubElement(node, 'Coordinate') |
43 |
coordinate_node.attrib['X'] = str(self.start.real)
|
|
44 |
coordinate_node.attrib['Y'] = str(rect.height() - self.start.imag)
|
|
84 |
coordinate_node.attrib['X'] = str(start_x)
|
|
85 |
coordinate_node.attrib['Y'] = str(start_y)
|
|
45 | 86 |
coordinate_node.attrib['Z'] = '0' |
46 | 87 |
coordinate_node = SubElement(node, 'Coordinate') |
47 |
coordinate_node.attrib['X'] = str(self.end.real)
|
|
48 |
coordinate_node.attrib['Y'] = str(rect.height() - self.end.imag)
|
|
88 |
coordinate_node.attrib['X'] = str(end_x)
|
|
89 |
coordinate_node.attrib['Y'] = str(end_y)
|
|
49 | 90 |
coordinate_node.attrib['Z'] = '0' |
50 | 91 |
|
51 | 92 |
return node |
52 | 93 |
|
53 | 94 |
|
95 |
class CenterLine: |
|
96 |
@staticmethod |
|
97 |
def to_xml(parent: Element, line) -> Element: |
|
98 |
"""return element for CenterLine""" |
|
99 |
|
|
100 |
node = SubElement(parent, 'CenterLine') |
|
101 |
node.attrib['NumPoints'] = '2' |
|
102 |
|
|
103 |
Presentation.to_xml(node, layer='20', color='0', line_type='1', line_weight=0.5, r=0, g=0, b=0) |
|
104 |
|
|
105 |
Extent.to_xml(node, line) |
|
106 |
rect = line.scene().sceneRect() |
|
107 |
x, y = line.start_point()[0], rect.height() - line.start_point()[1] |
|
108 |
node.append(Point.to_xml('Coordinate', x=x, y=y)) |
|
109 |
x, y = line.end_point()[0], rect.height() - line.end_point()[1] |
|
110 |
node.append(Point.to_xml('Coordinate', x=x, y=y)) |
|
111 |
|
|
112 |
return node |
|
113 |
|
|
114 |
|
|
54 | 115 |
class BsplineCurve: |
55 | 116 |
def __init__(self): |
56 | 117 |
pass |
... | ... | |
126 | 187 |
class ConnectionPoints: |
127 | 188 |
NODES = 0 |
128 | 189 |
|
129 |
def __init__(self, connectors): |
|
130 |
self.connectors = connectors |
|
131 |
|
|
132 |
def to_xml(self): |
|
133 |
if self.connectors: |
|
134 |
xml = Element('ConnectionPoints') |
|
135 |
xml.attrib['NumPoints'] = str(len(self.connectors)) |
|
136 |
|
|
137 |
min_x, min_y = None, None |
|
138 |
max_x, max_y = None, None |
|
139 |
for conn in self.connectors: |
|
140 |
center = conn.center() |
|
141 |
min_x = center[0] if min_x is None or min_x > center[0] else min_x |
|
142 |
max_x = center[0] if max_x is None or max_x < center[0] else max_x |
|
143 |
min_y = center[1] if min_y is None or min_y > center[1] else min_y |
|
144 |
max_y = center[1] if max_y is None or max_y < center[1] else max_y |
|
145 |
|
|
146 |
extent_node = SubElement(xml, 'Extent') |
|
147 |
min_node = SubElement(extent_node, 'Min') |
|
148 |
min_node.attrib['X'] = str(min_x) |
|
149 |
min_node.attrib['Y'] = str(min_y) |
|
150 |
min_node.attrib['Z'] = '0' |
|
151 |
max_node = SubElement(extent_node, 'Max') |
|
152 |
max_node.attrib['X'] = str(max_x) |
|
153 |
max_node.attrib['Y'] = str(max_y) |
|
154 |
max_node.attrib['Z'] = '0' |
|
155 |
|
|
156 |
for idx, conn in enumerate(self.connectors): |
|
157 |
node = SubElement(xml, 'Node') |
|
158 |
node.attrib['ID'] = f"XMP_{ConnectionPoints.NODES}" |
|
159 |
node.attrib['Name'] = f"conn{idx}" |
|
160 |
position_node = SubElement(node, 'Position') |
|
161 |
location_node = Point.to_xml('Location', x=conn.center()[0], y=conn.center()[1], z=0) |
|
162 |
position_node.append(location_node) |
|
163 |
axis_node = Point.to_xml('Axis', x=0, y=0, z=1) |
|
164 |
position_node.append(axis_node) |
|
165 |
reference_node = Point.to_xml('Reference', x=1, y=0, z=0) |
|
166 |
position_node.append(reference_node) |
|
167 |
|
|
168 |
ConnectionPoints.NODES += 1 |
|
169 |
|
|
170 |
generic_attributes_node = SubElement(xml, 'GenericAttributes') |
|
171 |
generic_attributes_node.attrib['Number'] = str(len(self.connectors)) |
|
172 |
for idx in range(len(self.connectors)): |
|
173 |
generic_attribute_node = SubElement(generic_attributes_node, 'GenericAttribute') |
|
174 |
generic_attribute_node.attrib['Name'] = f"NodeName{idx}" |
|
175 |
generic_attribute_node.attrib['Value'] = f"conn{idx}" |
|
176 |
generic_attribute_node.attrib['Format'] = 'string' |
|
177 |
|
|
178 |
return xml |
|
190 |
@staticmethod |
|
191 |
def to_xml(origin, connectors) -> Element: |
|
192 |
xml = Element('ConnectionPoints') |
|
193 |
xml.attrib['NumPoints'] = str(len(connectors) + 1) |
|
194 |
""" |
|
195 |
xml.attrib['FlowIn'] = '' |
|
196 |
xml.attrib['FlowOut'] = '' |
|
197 |
""" |
|
198 |
|
|
199 |
min_x, min_y = origin[0], origin[1] |
|
200 |
max_x, max_y = origin[0], origin[1] |
|
201 |
for conn in connectors: |
|
202 |
center = conn.center() |
|
203 |
min_x = center[0] if min_x is None or min_x > center[0] else min_x |
|
204 |
max_x = center[0] if max_x is None or max_x < center[0] else max_x |
|
205 |
min_y = center[1] if min_y is None or min_y > center[1] else min_y |
|
206 |
max_y = center[1] if max_y is None or max_y < center[1] else max_y |
|
207 |
|
|
208 |
extent_node = SubElement(xml, 'Extent') |
|
209 |
min_node = SubElement(extent_node, 'Min') |
|
210 |
min_node.attrib['X'] = str(min_x) |
|
211 |
min_node.attrib['Y'] = str(min_y) |
|
212 |
min_node.attrib['Z'] = '0' |
|
213 |
max_node = SubElement(extent_node, 'Max') |
|
214 |
max_node.attrib['X'] = str(max_x) |
|
215 |
max_node.attrib['Y'] = str(max_y) |
|
216 |
max_node.attrib['Z'] = '0' |
|
179 | 217 |
|
180 |
return None |
|
218 |
"""origin node""" |
|
219 |
origin_node = SubElement(xml, 'Node') |
|
220 |
origin_node.attrib['ID'] = f"XMP_{ConnectionPoints.NODES}" |
|
221 |
origin_node.attrib['Name'] = 'conn0' |
|
222 |
position_node = SubElement(origin_node, 'Position') |
|
223 |
location_node = Point.to_xml('Location', x=origin[0], y=origin[1], z=0) |
|
224 |
position_node.append(location_node) |
|
225 |
ZAxis.to_xml(position_node) |
|
226 |
reference_node = Point.to_xml('Reference', x=1, y=0, z=0) |
|
227 |
position_node.append(reference_node) |
|
228 |
"""up to here""" |
|
229 |
|
|
230 |
ConnectionPoints.NODES += 1 |
|
231 |
|
|
232 |
for idx, conn in enumerate(connectors): |
|
233 |
node = SubElement(xml, 'Node') |
|
234 |
node.attrib['ID'] = f"XMP_{ConnectionPoints.NODES}" |
|
235 |
node.attrib['Name'] = f"conn{idx + 1}" |
|
236 |
position_node = SubElement(node, 'Position') |
|
237 |
location_node = Point.to_xml('Location', x=conn.center()[0], y=conn.center()[1], z=0) |
|
238 |
position_node.append(location_node) |
|
239 |
ZAxis.to_xml(position_node) |
|
240 |
reference_node = Point.to_xml('Reference', x=1, y=0, z=0) |
|
241 |
position_node.append(reference_node) |
|
242 |
|
|
243 |
ConnectionPoints.NODES += 1 |
|
244 |
|
|
245 |
generic_attributes_node = SubElement(xml, 'GenericAttributes') |
|
246 |
generic_attributes_node.attrib['Number'] = str(len(connectors)) |
|
247 |
for idx in range(len(connectors)): |
|
248 |
generic_attribute_node = SubElement(generic_attributes_node, 'GenericAttribute') |
|
249 |
generic_attribute_node.attrib['Name'] = f"NodeName{idx + 1}" |
|
250 |
generic_attribute_node.attrib['Value'] = f"conn{idx + 1}" |
|
251 |
generic_attribute_node.attrib['Format'] = 'string' |
|
252 |
|
|
253 |
return xml |
DTI_PID/DTI_PID/DEXPI/ShapeCatalogue.py | ||
---|---|---|
3 | 3 |
|
4 | 4 |
from xml.etree.ElementTree import Element, SubElement, dump, ElementTree, parse, tostring |
5 | 5 |
from PyQt5.QtWidgets import * |
6 |
from PyQt5.QtGui import * |
|
6 | 7 |
from .Extent import Extent |
7 | 8 |
from .Presentation import Presentation |
9 |
from .Transform import Transform |
|
10 |
from .Shape import Point |
|
8 | 11 |
|
9 | 12 |
|
10 | 13 |
class ShapeCatalogue: |
... | ... | |
32 | 35 |
if type_str not in catalogue: |
33 | 36 |
shape_node = SubElement(node, 'Nozzle' if item.type == 'Nozzles' else 'Equipment') |
34 | 37 |
shape_node.attrib['ID'] = f"XMC_{ShapeCatalogue.ITEMS}" |
35 |
shape_node.attrib['ComponentClass'] = item.type
|
|
38 |
shape_node.attrib['ComponentClass'] = type_str
|
|
36 | 39 |
shape_node.attrib['ComponentName'] = item.name |
37 | 40 |
shape_node.attrib['Status'] = 'Current' |
38 | 41 |
Presentation.to_xml(shape_node, layer='0', color='0', line_type='0', line_weight=0.1, r=0, g=0, b=0) |
42 |
|
|
43 |
position_node = SubElement(shape_node, 'Position') |
|
44 |
position_node.append(Point.to_xml('Location', x=item.symbolOrigin[0], y=item.symbolOrigin[1], z=0)) |
|
45 |
position_node.append(Point.to_xml('Axis', x=0, y=0, z=1)) |
|
46 |
position_node.append(Point.to_xml('Reference', x=1, y=0, z=0)) |
|
47 |
|
|
39 | 48 |
generic_attributes = GenericAttributes(item) |
40 | 49 |
_attr_node = generic_attributes.to_xml() |
41 | 50 |
if _attr_node: |
42 | 51 |
shape_node.append(_attr_node) |
43 | 52 |
|
44 |
""" |
|
53 |
extent = None |
|
54 |
|
|
55 |
scale_trans = QTransform() |
|
56 |
scale_trans.scale(1, -1) |
|
57 |
|
|
45 | 58 |
svg = item.to_svg(parent=None) |
46 | 59 |
paths = svg[0].findall('path') |
47 | 60 |
for path in paths: |
61 |
trans = Transform.to_transform(path.attrib['transform']) * scale_trans |
|
48 | 62 |
path_ele = parse_path(path.attrib['d']) |
49 | 63 |
for idx, ele in enumerate(path_ele): |
50 | 64 |
if type(ele) is Move: |
51 | 65 |
continue |
52 | 66 |
elif type(ele) is Line: |
53 |
line = DEXPI_Line(ele.start, ele.end) |
|
54 |
shape_node.append(line.to_xml()) |
|
67 |
line = DEXPI_Line(Transform.apply_transform(trans, ele.start), |
|
68 |
Transform.apply_transform(trans, ele.end)) |
|
69 |
extent = ShapeCatalogue.merge_extent(extent, line.extent()) |
|
70 |
shape_node.append(line.to_xml('Line', None)) |
|
55 | 71 |
elif type(ele) is Arc: |
56 | 72 |
continue |
57 | 73 |
elif type(ele) is CubicBezier: |
74 |
line = DEXPI_Line(Transform.apply_transform(trans, ele.start), |
|
75 |
Transform.apply_transform(trans, ele.control1)) |
|
76 |
extent = ShapeCatalogue.merge_extent(extent, line.extent()) |
|
77 |
shape_node.append(line.to_xml('Line', None)) |
|
78 |
|
|
79 |
line = DEXPI_Line(Transform.apply_transform(trans, ele.control1), |
|
80 |
Transform.apply_transform(trans, ele.control2)) |
|
81 |
extent = ShapeCatalogue.merge_extent(extent, line.extent()) |
|
82 |
shape_node.append(line.to_xml('Line', None)) |
|
83 |
|
|
84 |
line = DEXPI_Line(Transform.apply_transform(trans, ele.control2), |
|
85 |
Transform.apply_transform(trans, ele.end)) |
|
86 |
extent = ShapeCatalogue.merge_extent(extent, line.extent()) |
|
87 |
shape_node.append(line.to_xml('Line', None)) |
|
88 |
""" |
|
58 | 89 |
bspline_curve_node = BsplineCurve.to_xml(controls=[ele.start, ele.control1, |
59 | 90 |
ele.control2, ele.end], |
60 | 91 |
_type='BsplineCurve', knots=[]) |
61 | 92 |
shape_node.append(bspline_curve_node) |
93 |
""" |
|
62 | 94 |
elif type(ele) is QuadraticBezier: |
63 | 95 |
continue |
64 | 96 |
else: |
65 | 97 |
continue |
66 |
""" |
|
98 |
|
|
99 |
extent_node = SubElement(shape_node, 'Extent') |
|
100 |
extent_node.append(Point.to_xml('Min', x=extent[0], y=extent[1], z=0)) |
|
101 |
extent_node.append(Point.to_xml('Max', x=extent[2], y=extent[2], z=0)) |
|
67 | 102 |
|
68 | 103 |
ShapeCatalogue.ITEMS += 1 |
69 | 104 |
|
70 |
connection_points_node = ConnectionPoints(item.connectors) |
|
71 |
_conn_node = connection_points_node.to_xml() |
|
105 |
_conn_node = ConnectionPoints.to_xml(item.symbolOrigin, item.connectors) |
|
72 | 106 |
if _conn_node: |
73 | 107 |
shape_node.append(_conn_node) |
74 | 108 |
|
75 | 109 |
catalogue.add(type_str) |
76 | 110 |
|
77 | 111 |
return node |
112 |
|
|
113 |
@staticmethod |
|
114 |
def merge_extent(lhs, rhs): |
|
115 |
if lhs and rhs: |
|
116 |
min_x = min(lhs[0], rhs[0]) |
|
117 |
min_y = min(lhs[1], rhs[1]) |
|
118 |
max_x = max(lhs[2], rhs[2]) |
|
119 |
max_y = max(lhs[3], rhs[3]) |
|
120 |
elif lhs: |
|
121 |
min_x, min_y, max_x, max_y = lhs[0], lhs[1], lhs[2], lhs[3] |
|
122 |
elif rhs: |
|
123 |
min_x, min_y, max_x, max_y = rhs[0], rhs[1], rhs[2], rhs[3] |
|
124 |
else: |
|
125 |
raise ValueError('lhs and rhs is None') |
|
126 |
|
|
127 |
return min_x, min_y, max_x, max_y |
DTI_PID/DTI_PID/DEXPI/Text.py | ||
---|---|---|
7 | 7 |
from PyQt5.QtCore import * |
8 | 8 |
from .Extent import Extent |
9 | 9 |
from .Presentation import Presentation |
10 |
from .Shape import Point, Line as DEXPI_Line, ConnectionPoints, GenericAttributes, BsplineCurve |
|
10 |
from .Shape import Point, ZAxis, Line as DEXPI_Line, ConnectionPoints, GenericAttributes, BsplineCurve
|
|
11 | 11 |
from .Transform import Transform |
12 | 12 |
|
13 | 13 |
|
... | ... | |
40 | 40 |
Extent.to_xml(node, item=item) |
41 | 41 |
|
42 | 42 |
_node = SubElement(node, 'Position') |
43 |
_node.append(Point.to_xml('Location', item.loc[0], item.scene().sceneRect().height() - item.loc[1] - |
|
43 |
rect = item.scene().sceneRect() |
|
44 |
_node.append(Point.to_xml('Location', item.loc[0], rect.height() - item.loc[1] - |
|
44 | 45 |
float(node.attrib['Height']))) |
45 |
_node.append(Point.to_xml('Axis', 0, 0, 1))
|
|
46 |
ZAxis.to_xml(_node)
|
|
46 | 47 |
_node.append(Point.to_xml('Reference', 1, 0, 0)) |
47 | 48 |
except Exception as ex: |
48 | 49 |
message = f"error occurred({repr(ex)}) in {sys.exc_info()[-1].tb_frame.f_code.co_filename}:" \ |
내보내기 Unified diff