compas-cadwork 0.7.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- compas_cadwork/__init__.py +36 -0
- compas_cadwork/conversions/__init__.py +12 -0
- compas_cadwork/conversions/primitives.py +71 -0
- compas_cadwork/datamodel/__init__.py +18 -0
- compas_cadwork/datamodel/dimension.py +144 -0
- compas_cadwork/datamodel/element.py +389 -0
- compas_cadwork/scene/__init__.py +40 -0
- compas_cadwork/scene/camera.py +243 -0
- compas_cadwork/scene/instructionobject.py +137 -0
- compas_cadwork/scene/scene.py +37 -0
- compas_cadwork/storage.py +132 -0
- compas_cadwork/utilities/__init__.py +445 -0
- compas_cadwork/utilities/dimensions.py +68 -0
- compas_cadwork/utilities/events.py +61 -0
- compas_cadwork/utilities/ifc_export.py +99 -0
- compas_cadwork-0.7.0.dist-info/LICENSE +21 -0
- compas_cadwork-0.7.0.dist-info/METADATA +101 -0
- compas_cadwork-0.7.0.dist-info/RECORD +20 -0
- compas_cadwork-0.7.0.dist-info/WHEEL +5 -0
- compas_cadwork-0.7.0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
from __future__ import print_function
|
|
2
|
+
import os
|
|
3
|
+
from datetime import datetime
|
|
4
|
+
|
|
5
|
+
__title__ = "compas_cadwork"
|
|
6
|
+
__description__ = "COMPAS package for integrating with cadwork"
|
|
7
|
+
__url__ = "https://github.com/gramaziokohler/compas_cadwork"
|
|
8
|
+
__version__ = "0.7.0"
|
|
9
|
+
__author__ = "Gramazio Kohler Research"
|
|
10
|
+
__author_email__ = "gramaziokohler@arch.ethz.ch"
|
|
11
|
+
__license__ = "MIT license"
|
|
12
|
+
__copyright__ = "Copyright {} Gramazio Kohler Research".format(datetime.today().year)
|
|
13
|
+
|
|
14
|
+
HERE = os.path.dirname(__file__)
|
|
15
|
+
HOME = os.path.abspath(os.path.join(HERE, "../../"))
|
|
16
|
+
DATA = os.path.abspath(os.path.join(HOME, "data"))
|
|
17
|
+
DOCS = os.path.abspath(os.path.join(HOME, "docs"))
|
|
18
|
+
TEMP = os.path.abspath(os.path.join(HOME, "temp"))
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
__all__ = [
|
|
22
|
+
"HOME",
|
|
23
|
+
"DATA",
|
|
24
|
+
"DOCS",
|
|
25
|
+
"TEMP",
|
|
26
|
+
"__author__",
|
|
27
|
+
"__author_email__",
|
|
28
|
+
"__copyright__",
|
|
29
|
+
"__description__",
|
|
30
|
+
"__license__",
|
|
31
|
+
"__title__",
|
|
32
|
+
"__url__",
|
|
33
|
+
"__version__",
|
|
34
|
+
]
|
|
35
|
+
|
|
36
|
+
__all_plugins__ = ["compas_cadwork.scene"]
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
from .primitives import point_to_cadwork
|
|
2
|
+
from .primitives import vector_to_cadwork
|
|
3
|
+
from .primitives import point_to_compas
|
|
4
|
+
from .primitives import vector_to_compas
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
__all__ = [
|
|
8
|
+
"point_to_cadwork",
|
|
9
|
+
"vector_to_cadwork",
|
|
10
|
+
"point_to_compas",
|
|
11
|
+
"vector_to_compas",
|
|
12
|
+
]
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
try:
|
|
2
|
+
from cadwork import point_3d
|
|
3
|
+
except ImportError:
|
|
4
|
+
pass
|
|
5
|
+
|
|
6
|
+
from compas.geometry import Point
|
|
7
|
+
from compas.geometry import Vector
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
def point_to_cadwork(point: Point):
|
|
11
|
+
"""Convert a :class:`compas.geometry.Point` to a cadwork point_3d object.
|
|
12
|
+
|
|
13
|
+
Parameters
|
|
14
|
+
----------
|
|
15
|
+
point : :class:`~compas.geometry.Point`
|
|
16
|
+
The point to convert
|
|
17
|
+
|
|
18
|
+
Returns
|
|
19
|
+
-------
|
|
20
|
+
:class:`cadwork.point_3d`
|
|
21
|
+
|
|
22
|
+
"""
|
|
23
|
+
return point_3d(point.x, point.y, point.z)
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
def vector_to_cadwork(vector: Vector):
|
|
27
|
+
"""Convert a :class:`compas.geometry.Vector` to a cadwork point_3d object.
|
|
28
|
+
|
|
29
|
+
Parameters
|
|
30
|
+
----------
|
|
31
|
+
vector : :class:`~compas.geometry.Vector`
|
|
32
|
+
The vector to convert
|
|
33
|
+
|
|
34
|
+
Returns
|
|
35
|
+
-------
|
|
36
|
+
:class:`cadwork.point_3d`
|
|
37
|
+
|
|
38
|
+
"""
|
|
39
|
+
return point_3d(vector.x, vector.y, vector.z)
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
def point_to_compas(point):
|
|
43
|
+
"""Convert a cadwork point_3d to a :class:`compas.geometry.Point` object.
|
|
44
|
+
|
|
45
|
+
Parameters
|
|
46
|
+
----------
|
|
47
|
+
point : :class:`cadwork.point_3d`
|
|
48
|
+
The point to convert
|
|
49
|
+
|
|
50
|
+
Returns
|
|
51
|
+
-------
|
|
52
|
+
:class:`~compas.geometry.Point`
|
|
53
|
+
|
|
54
|
+
"""
|
|
55
|
+
return Point(point.x, point.y, point.z)
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
def vector_to_compas(vector):
|
|
59
|
+
"""Convert a cadwork point_3d to a :class:`compas.geometry.Point` obhect.
|
|
60
|
+
|
|
61
|
+
Parameters
|
|
62
|
+
----------
|
|
63
|
+
point : :class:`~compas.geometry.Point`
|
|
64
|
+
The point to convert
|
|
65
|
+
|
|
66
|
+
Returns
|
|
67
|
+
-------
|
|
68
|
+
:class:`cadwork.point_3d`
|
|
69
|
+
|
|
70
|
+
"""
|
|
71
|
+
return Vector(*point_to_compas(vector))
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
from .element import Element
|
|
2
|
+
from .element import ElementType
|
|
3
|
+
from .element import ElementGroup
|
|
4
|
+
from .element import ElementGroupingType
|
|
5
|
+
from .element import ATTR_INSTRUCTION_ID
|
|
6
|
+
from .dimension import Dimension
|
|
7
|
+
from .dimension import AnchorPoint
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
__all__ = [
|
|
11
|
+
"Element",
|
|
12
|
+
"ElementType",
|
|
13
|
+
"ElementGroup",
|
|
14
|
+
"ElementGroupingType",
|
|
15
|
+
"ATTR_INSTRUCTION_ID",
|
|
16
|
+
"AnchorPoint",
|
|
17
|
+
"Dimension",
|
|
18
|
+
]
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from dataclasses import dataclass
|
|
4
|
+
|
|
5
|
+
import dimension_controller as dc
|
|
6
|
+
from compas.geometry import Frame
|
|
7
|
+
from compas.geometry import Point
|
|
8
|
+
from compas.geometry import Vector
|
|
9
|
+
from compas.tolerance import Tolerance
|
|
10
|
+
|
|
11
|
+
from compas_cadwork.conversions import point_to_compas
|
|
12
|
+
from compas_cadwork.conversions import vector_to_compas
|
|
13
|
+
|
|
14
|
+
from .element import Element
|
|
15
|
+
from .element import ElementType
|
|
16
|
+
|
|
17
|
+
TOL = Tolerance(unit="MM", absolute=1e-3, relative=1e-3)
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
@dataclass
|
|
21
|
+
class AnchorPoint:
|
|
22
|
+
"""Anchor point of a cadwork measurement. There may me 2 or more anchor points in a measurement.
|
|
23
|
+
|
|
24
|
+
Attributes
|
|
25
|
+
----------
|
|
26
|
+
location : Point
|
|
27
|
+
The location of the anchor point in 3d space.
|
|
28
|
+
distance : float
|
|
29
|
+
The distance of the anchor point from the measurement line.
|
|
30
|
+
direction : Vector
|
|
31
|
+
The direction of the anchor point from the measurement line.
|
|
32
|
+
|
|
33
|
+
"""
|
|
34
|
+
|
|
35
|
+
location: Point
|
|
36
|
+
distance: float
|
|
37
|
+
direction: Vector
|
|
38
|
+
|
|
39
|
+
def __eq__(self, other: AnchorPoint) -> bool:
|
|
40
|
+
if not isinstance(other, AnchorPoint):
|
|
41
|
+
return False
|
|
42
|
+
|
|
43
|
+
if not TOL.is_allclose([*self.location], [*other.location]):
|
|
44
|
+
return False
|
|
45
|
+
|
|
46
|
+
if not TOL.is_allclose([*self.direction], [*other.direction]):
|
|
47
|
+
return False
|
|
48
|
+
|
|
49
|
+
return TOL.is_close(self.distance, other.distance)
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
class Dimension(Element):
|
|
53
|
+
"""Represents a cadwork dimension"""
|
|
54
|
+
|
|
55
|
+
def __init__(self, id):
|
|
56
|
+
super().__init__(id, ElementType.DIMENSION)
|
|
57
|
+
self._frame = None
|
|
58
|
+
# not lazy-instantiating this so that it can be used to compare the modified instances of the same dimension
|
|
59
|
+
# otherwise, the anchors values that are compared depend on the time `anchors` was first accessed
|
|
60
|
+
self.anchors = self._init_anchors()
|
|
61
|
+
|
|
62
|
+
def __str__(self) -> str:
|
|
63
|
+
return f"Dimension id:{self.id} length:{self.length:.0f} anchors:{len(self.anchors)}"
|
|
64
|
+
|
|
65
|
+
def __hash__(self):
|
|
66
|
+
return hash(self.cadwork_guid)
|
|
67
|
+
|
|
68
|
+
def __eq__(self, other: Dimension):
|
|
69
|
+
if not isinstance(other, Dimension):
|
|
70
|
+
return False
|
|
71
|
+
|
|
72
|
+
if self.cadwork_guid != other.cadwork_guid:
|
|
73
|
+
return False
|
|
74
|
+
|
|
75
|
+
if len(self.anchors) != len(other.anchors):
|
|
76
|
+
return False
|
|
77
|
+
|
|
78
|
+
for point_self, point_other in zip(self.anchors, other.anchors):
|
|
79
|
+
if point_self != point_other:
|
|
80
|
+
return False
|
|
81
|
+
return True
|
|
82
|
+
|
|
83
|
+
@property
|
|
84
|
+
def frame(self):
|
|
85
|
+
if not self._frame:
|
|
86
|
+
zaxis = -self.text_normal
|
|
87
|
+
xaxis = vector_to_compas(dc.get_plane_xl(self.id))
|
|
88
|
+
yaxis = xaxis.cross(zaxis).unitized()
|
|
89
|
+
self._frame = Frame(self.anchors[0].location, xaxis, yaxis)
|
|
90
|
+
return self._frame
|
|
91
|
+
|
|
92
|
+
@property
|
|
93
|
+
def text_normal(self):
|
|
94
|
+
return vector_to_compas(dc.get_plane_normal(self.id))
|
|
95
|
+
|
|
96
|
+
@property
|
|
97
|
+
def length(self):
|
|
98
|
+
start: Point = self.anchors[0].location
|
|
99
|
+
end: Point = self.anchors[-1].location
|
|
100
|
+
return start.distance_to_point(end)
|
|
101
|
+
|
|
102
|
+
def _init_anchors(self):
|
|
103
|
+
anchors = []
|
|
104
|
+
for index, point in enumerate(dc.get_dimension_points(self.id)):
|
|
105
|
+
distance = dc.get_segment_distance(self.id, index)
|
|
106
|
+
direction = dc.get_segment_direction(self.id, index)
|
|
107
|
+
anchors.append(AnchorPoint(point_to_compas(point), distance, vector_to_compas(direction)))
|
|
108
|
+
return tuple(anchors)
|
|
109
|
+
|
|
110
|
+
@classmethod
|
|
111
|
+
def from_id(cls, element_id: int) -> Dimension:
|
|
112
|
+
"""Creates a dimension object from an element id.
|
|
113
|
+
|
|
114
|
+
This is an override of :func:`Element.from_id`.
|
|
115
|
+
|
|
116
|
+
Parameters
|
|
117
|
+
----------
|
|
118
|
+
element_id : int
|
|
119
|
+
The id of the element to create the dimension from.
|
|
120
|
+
|
|
121
|
+
Returns
|
|
122
|
+
-------
|
|
123
|
+
:class:`Dimension`
|
|
124
|
+
The dimension object created from the element id.
|
|
125
|
+
|
|
126
|
+
"""
|
|
127
|
+
return cls(id=element_id)
|
|
128
|
+
|
|
129
|
+
@classmethod
|
|
130
|
+
def from_element(cls, element: Element) -> Dimension:
|
|
131
|
+
"""Creates a dimension object from an element.
|
|
132
|
+
|
|
133
|
+
Parameters
|
|
134
|
+
----------
|
|
135
|
+
element : :class:`Element`
|
|
136
|
+
The element to create the dimension from.
|
|
137
|
+
|
|
138
|
+
Returns
|
|
139
|
+
-------
|
|
140
|
+
:class:`Dimension`
|
|
141
|
+
The dimension object created from the element.
|
|
142
|
+
|
|
143
|
+
"""
|
|
144
|
+
return cls(id=element.id)
|
|
@@ -0,0 +1,389 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from dataclasses import dataclass
|
|
4
|
+
from enum import Enum
|
|
5
|
+
from enum import IntEnum
|
|
6
|
+
from enum import auto
|
|
7
|
+
from typing import Generator
|
|
8
|
+
from typing import List
|
|
9
|
+
from typing import Optional
|
|
10
|
+
|
|
11
|
+
import attribute_controller as ac
|
|
12
|
+
import bim_controller as bc
|
|
13
|
+
import cadwork # noqa: F401
|
|
14
|
+
import element_controller as ec
|
|
15
|
+
import geometry_controller as gc
|
|
16
|
+
import utility_controller as uc
|
|
17
|
+
from compas.geometry import Frame
|
|
18
|
+
from compas.geometry import Line
|
|
19
|
+
from compas.geometry import Point
|
|
20
|
+
from compas.geometry import Vector
|
|
21
|
+
|
|
22
|
+
from compas_cadwork.conversions import point_to_compas
|
|
23
|
+
from compas_cadwork.conversions import vector_to_cadwork
|
|
24
|
+
|
|
25
|
+
# These are used to identify instruction elements which were added to the cadwork file by compas_cadwork.
|
|
26
|
+
ATTR_INSTRUCTION_ID = 666
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
class ElementGroupingType(IntEnum):
|
|
30
|
+
"""CADWork Element Grouping Type
|
|
31
|
+
|
|
32
|
+
Attributes
|
|
33
|
+
----------
|
|
34
|
+
GROUP
|
|
35
|
+
Elements are grouped using group as the main grouping type.
|
|
36
|
+
SUBGROUP
|
|
37
|
+
Elements are grouped using subgroup as the main grouping type.
|
|
38
|
+
NONE
|
|
39
|
+
Not setting is available.
|
|
40
|
+
|
|
41
|
+
"""
|
|
42
|
+
|
|
43
|
+
GROUP = 1
|
|
44
|
+
SUBGROUP = 2
|
|
45
|
+
NONE = 3
|
|
46
|
+
|
|
47
|
+
def to_cadwork(self):
|
|
48
|
+
"""Converts the ElementGroupingType to a cadwork compatible value.
|
|
49
|
+
|
|
50
|
+
Returns
|
|
51
|
+
-------
|
|
52
|
+
int
|
|
53
|
+
The cadwork compatible value of the ElementGroupingType
|
|
54
|
+
"""
|
|
55
|
+
return cadwork.element_grouping_type(self.value)
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
class ElementType(str, Enum):
|
|
59
|
+
"""CADWork Element type"""
|
|
60
|
+
|
|
61
|
+
BEAM = auto() # Stab
|
|
62
|
+
PLATE = auto() # Platte
|
|
63
|
+
SURFACE = auto()
|
|
64
|
+
SHAFT = auto()
|
|
65
|
+
LINE = auto()
|
|
66
|
+
INSTALLATION_ROUND = auto()
|
|
67
|
+
INSTALLATION_STRAIGHT = auto()
|
|
68
|
+
DIMENSION = auto()
|
|
69
|
+
OTHER = auto()
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
ELEMENT_TYPE_MAP = {
|
|
73
|
+
"de": {
|
|
74
|
+
"Stab": ElementType.BEAM,
|
|
75
|
+
"Platte": ElementType.PLATE,
|
|
76
|
+
"Achse": ElementType.SHAFT,
|
|
77
|
+
"Linie": ElementType.LINE,
|
|
78
|
+
"Installation rechteckig": ElementType.INSTALLATION_STRAIGHT,
|
|
79
|
+
"Fläche": ElementType.SURFACE,
|
|
80
|
+
"Installation rund": ElementType.INSTALLATION_ROUND,
|
|
81
|
+
"Measurement": ElementType.DIMENSION,
|
|
82
|
+
},
|
|
83
|
+
"en": {
|
|
84
|
+
"Beam": ElementType.BEAM,
|
|
85
|
+
"Plate": ElementType.PLATE,
|
|
86
|
+
"Bemassung": ElementType.DIMENSION,
|
|
87
|
+
},
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
# TODO: get rid of this whole thing
|
|
91
|
+
try:
|
|
92
|
+
LOCAL_TYPE_MAP = ELEMENT_TYPE_MAP[uc.get_language()]
|
|
93
|
+
except AttributeError:
|
|
94
|
+
pass
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
@dataclass
|
|
98
|
+
class ElementGroup:
|
|
99
|
+
"""Represents a cadwork Element Group
|
|
100
|
+
|
|
101
|
+
Parameters
|
|
102
|
+
----------
|
|
103
|
+
name : str
|
|
104
|
+
The name of the Element Group
|
|
105
|
+
elements : list
|
|
106
|
+
A list of Elements belonging to the Element Group
|
|
107
|
+
|
|
108
|
+
Attributes
|
|
109
|
+
----------
|
|
110
|
+
name : str
|
|
111
|
+
The name of the Element Group
|
|
112
|
+
elements : list
|
|
113
|
+
A list of Elements belonging to the Element Group
|
|
114
|
+
wall_frame_element : Element, optional
|
|
115
|
+
The containing Element (often a wall element) which contains all other elements in the group. If any.
|
|
116
|
+
ifc_guid : str
|
|
117
|
+
The IFC GUID of the container element, often used to represent the whole group. See also: ifc_base64_guid
|
|
118
|
+
|
|
119
|
+
"""
|
|
120
|
+
|
|
121
|
+
name: str
|
|
122
|
+
elements: list = None
|
|
123
|
+
wall_frame_element: Element = None
|
|
124
|
+
|
|
125
|
+
def add_element(self, element: Element) -> None:
|
|
126
|
+
"""Adds an Element to the Element Group
|
|
127
|
+
|
|
128
|
+
Parameters
|
|
129
|
+
----------
|
|
130
|
+
element : Element
|
|
131
|
+
The Element to add to the Element Group
|
|
132
|
+
|
|
133
|
+
"""
|
|
134
|
+
if self.elements is None:
|
|
135
|
+
self.elements = []
|
|
136
|
+
self.elements.append(element)
|
|
137
|
+
if element.is_wall or element.is_roof or element.is_floor:
|
|
138
|
+
self.wall_frame_element = element
|
|
139
|
+
|
|
140
|
+
@property
|
|
141
|
+
def ifc_guid(self) -> str:
|
|
142
|
+
if self.wall_frame_element is None:
|
|
143
|
+
return None
|
|
144
|
+
return self.wall_frame_element.ifc_base64_guid
|
|
145
|
+
|
|
146
|
+
|
|
147
|
+
@dataclass
|
|
148
|
+
class Element:
|
|
149
|
+
"""Represents a cadwork Element
|
|
150
|
+
|
|
151
|
+
Parameters
|
|
152
|
+
----------
|
|
153
|
+
id : int
|
|
154
|
+
The ID of the Element
|
|
155
|
+
type : ElementType
|
|
156
|
+
The type of the Element
|
|
157
|
+
|
|
158
|
+
|
|
159
|
+
Attributes
|
|
160
|
+
----------
|
|
161
|
+
name : str
|
|
162
|
+
The name of the Element
|
|
163
|
+
frame : Frame
|
|
164
|
+
The local coordinate system of the Element
|
|
165
|
+
width : float
|
|
166
|
+
The width of the Element
|
|
167
|
+
height : float
|
|
168
|
+
The height of the Element
|
|
169
|
+
length : float
|
|
170
|
+
The length of the Element
|
|
171
|
+
group : str
|
|
172
|
+
The group the Element belongs to. Either group or subgroup depending on the current grouping type.
|
|
173
|
+
ifc_base64_guid : str
|
|
174
|
+
The base64 IFC GUID of the Element
|
|
175
|
+
cadwork_guid : str
|
|
176
|
+
The cadwork GUID of the Element
|
|
177
|
+
centerline : Line
|
|
178
|
+
The centerline of the Element.
|
|
179
|
+
midpoint : Point
|
|
180
|
+
The midpoint of the Element's centerline.
|
|
181
|
+
ifc_guid : str
|
|
182
|
+
The IFC GUID of the Element. See also: ifc_base64_guid.
|
|
183
|
+
is_wall : bool
|
|
184
|
+
Whether the Element is a framed wall i.e. container for all other elements in the building group.
|
|
185
|
+
is_drilling : bool
|
|
186
|
+
Whether the Element is a drilling hole
|
|
187
|
+
is_roof : bool
|
|
188
|
+
Whether the Element is a framed roof i.e. container for all other elements in the building group.
|
|
189
|
+
is_floor : bool
|
|
190
|
+
Whether the Element is a framed floor i.e. container for all other elements in the building group.
|
|
191
|
+
|
|
192
|
+
"""
|
|
193
|
+
|
|
194
|
+
id: int
|
|
195
|
+
type: ElementType
|
|
196
|
+
|
|
197
|
+
@property
|
|
198
|
+
def name(self) -> str:
|
|
199
|
+
return ac.get_name(self.id)
|
|
200
|
+
|
|
201
|
+
@property
|
|
202
|
+
def frame(self) -> Frame:
|
|
203
|
+
try:
|
|
204
|
+
p1 = Point(*gc.get_p1(self.id))
|
|
205
|
+
x_axis = Vector(*gc.get_xl(self.id))
|
|
206
|
+
y_axis = Vector(*gc.get_yl(self.id))
|
|
207
|
+
return Frame(p1, x_axis, y_axis)
|
|
208
|
+
except ZeroDivisionError:
|
|
209
|
+
# TODO: get to the bottom of this:
|
|
210
|
+
# sometimes one of the axes comes back as [0,0,0] in the meantime just don't crash
|
|
211
|
+
return Frame.worldXY()
|
|
212
|
+
|
|
213
|
+
@property
|
|
214
|
+
def width(self) -> float:
|
|
215
|
+
return gc.get_width(self.id)
|
|
216
|
+
|
|
217
|
+
@property
|
|
218
|
+
def height(self) -> float:
|
|
219
|
+
return gc.get_height(self.id)
|
|
220
|
+
|
|
221
|
+
@property
|
|
222
|
+
def length(self) -> float:
|
|
223
|
+
return gc.get_length(self.id)
|
|
224
|
+
|
|
225
|
+
@property
|
|
226
|
+
def group(self) -> str:
|
|
227
|
+
if ac.get_element_grouping_type() == cadwork.element_grouping_type.subgroup:
|
|
228
|
+
return ac.get_subgroup(self.id)
|
|
229
|
+
else:
|
|
230
|
+
return ac.get_group(self.id)
|
|
231
|
+
|
|
232
|
+
@property
|
|
233
|
+
def ifc_base64_guid(self) -> str:
|
|
234
|
+
return bc.get_ifc_base64_guid(self.id)
|
|
235
|
+
|
|
236
|
+
@property
|
|
237
|
+
def cadwork_guid(self) -> str:
|
|
238
|
+
return ec.get_element_cadwork_guid(self.id)
|
|
239
|
+
|
|
240
|
+
@property
|
|
241
|
+
def centerline(self) -> Line:
|
|
242
|
+
p1 = point_to_compas(gc.get_p1(self.id))
|
|
243
|
+
p2 = point_to_compas(gc.get_p2(self.id))
|
|
244
|
+
return Line(p1, p2)
|
|
245
|
+
|
|
246
|
+
@property
|
|
247
|
+
def midpoint(self) -> Point:
|
|
248
|
+
return self.centerline.midpoint
|
|
249
|
+
|
|
250
|
+
@property
|
|
251
|
+
def ifc_guid(self) -> str:
|
|
252
|
+
return bc.get_ifc_guid(self.id)
|
|
253
|
+
|
|
254
|
+
@property
|
|
255
|
+
def is_wall(self) -> bool:
|
|
256
|
+
return ac.is_framed_wall(self.id)
|
|
257
|
+
|
|
258
|
+
@property
|
|
259
|
+
def is_roof(self) -> bool:
|
|
260
|
+
return ac.is_framed_roof(self.id)
|
|
261
|
+
|
|
262
|
+
@property
|
|
263
|
+
def is_floor(self) -> bool:
|
|
264
|
+
return ac.is_framed_floor(self.id)
|
|
265
|
+
|
|
266
|
+
@property
|
|
267
|
+
def is_linear_dimension(self) -> bool:
|
|
268
|
+
type_ = ac.get_element_type(self.id)
|
|
269
|
+
return type_.is_dimension()
|
|
270
|
+
|
|
271
|
+
@property
|
|
272
|
+
def is_drilling(self) -> bool:
|
|
273
|
+
return ac.is_drilling(self.id)
|
|
274
|
+
|
|
275
|
+
@property
|
|
276
|
+
def is_instruction(self) -> bool:
|
|
277
|
+
return ac.get_user_attribute(self.id, ATTR_INSTRUCTION_ID) != ""
|
|
278
|
+
|
|
279
|
+
def is_beam(self) -> bool:
|
|
280
|
+
type_ = ac.get_element_type(self.id)
|
|
281
|
+
return type_.is_rectangular_beam()
|
|
282
|
+
|
|
283
|
+
@classmethod
|
|
284
|
+
def from_id(cls, element_id: int) -> Element:
|
|
285
|
+
"""Returns an Element object for the cadwork Element with the given ID
|
|
286
|
+
|
|
287
|
+
Parameters
|
|
288
|
+
----------
|
|
289
|
+
element_id : int
|
|
290
|
+
The ID of the Element
|
|
291
|
+
|
|
292
|
+
Returns
|
|
293
|
+
-------
|
|
294
|
+
Element
|
|
295
|
+
The Element object for the given ID
|
|
296
|
+
|
|
297
|
+
"""
|
|
298
|
+
type_description = ec.get_element_type_description(element_id)
|
|
299
|
+
try:
|
|
300
|
+
type_ = LOCAL_TYPE_MAP[type_description]
|
|
301
|
+
except KeyError:
|
|
302
|
+
type_ = ElementType.OTHER
|
|
303
|
+
return Element(element_id, type_)
|
|
304
|
+
|
|
305
|
+
@classmethod
|
|
306
|
+
def from_selection(cls) -> Generator[Element]:
|
|
307
|
+
"""Returns a generator containing Element objects for all currently activated Elements
|
|
308
|
+
|
|
309
|
+
Returns
|
|
310
|
+
-------
|
|
311
|
+
Generator[Element]
|
|
312
|
+
A generator containing Element objects for all currently activated Elements
|
|
313
|
+
|
|
314
|
+
"""
|
|
315
|
+
return (Element.from_id(e_id) for e_id in ec.get_active_identifiable_element_ids())
|
|
316
|
+
|
|
317
|
+
def set_attribute(self, name, value):
|
|
318
|
+
"""Sets an attribute on the Element
|
|
319
|
+
|
|
320
|
+
Parameters
|
|
321
|
+
----------
|
|
322
|
+
name : str
|
|
323
|
+
The name of the attribute
|
|
324
|
+
value : str
|
|
325
|
+
The value of the attribute
|
|
326
|
+
|
|
327
|
+
"""
|
|
328
|
+
ac.set_user_attribute([self.id], name, value)
|
|
329
|
+
|
|
330
|
+
def remove_attribute(self, name):
|
|
331
|
+
"""Removes an attribute from the Element
|
|
332
|
+
|
|
333
|
+
Parameters
|
|
334
|
+
----------
|
|
335
|
+
name : str
|
|
336
|
+
The name of the attribute
|
|
337
|
+
|
|
338
|
+
"""
|
|
339
|
+
ac.delete_user_attribute([self.id], name)
|
|
340
|
+
|
|
341
|
+
def set_is_instruction(self, value: bool, instruction_id: Optional[str] = None):
|
|
342
|
+
"""Sets the is_instruction attribute on the Element
|
|
343
|
+
|
|
344
|
+
Parameters
|
|
345
|
+
----------
|
|
346
|
+
value : bool
|
|
347
|
+
If True, this Element will be flagged as an instruction element by setting the appropriate attribute.
|
|
348
|
+
If False, the attribute will be removed.
|
|
349
|
+
instruction_id : str
|
|
350
|
+
The ID of the instruction. This is required when setting is_instruction to True.
|
|
351
|
+
|
|
352
|
+
"""
|
|
353
|
+
if value and instruction_id is None:
|
|
354
|
+
raise ValueError("Instruction ID must be provided when setting is_instruction to True")
|
|
355
|
+
|
|
356
|
+
if value:
|
|
357
|
+
self.set_attribute(ATTR_INSTRUCTION_ID, instruction_id)
|
|
358
|
+
else:
|
|
359
|
+
self.remove_attribute(ATTR_INSTRUCTION_ID)
|
|
360
|
+
|
|
361
|
+
def get_instruction_id(self) -> Optional[str]:
|
|
362
|
+
"""Returns the instruction ID of the Element
|
|
363
|
+
|
|
364
|
+
Returns
|
|
365
|
+
-------
|
|
366
|
+
str, optional
|
|
367
|
+
The instruction ID of the Element
|
|
368
|
+
|
|
369
|
+
"""
|
|
370
|
+
return ac.get_user_attribute(self.id, ATTR_INSTRUCTION_ID)
|
|
371
|
+
|
|
372
|
+
def get_elements_in_contact(self) -> List[Element]:
|
|
373
|
+
"""Returns a list of elements in contact with the current element"""
|
|
374
|
+
return [Element.from_id(e_id) for e_id in ec.get_elements_in_contact(self.id)]
|
|
375
|
+
|
|
376
|
+
def remove(self):
|
|
377
|
+
"""Removes the Element from the cadwork file"""
|
|
378
|
+
ec.delete_elements([self.id])
|
|
379
|
+
|
|
380
|
+
def translate(self, vector: Vector) -> None:
|
|
381
|
+
"""Translates the Element by the given vector.
|
|
382
|
+
|
|
383
|
+
Parameters
|
|
384
|
+
----------
|
|
385
|
+
vector : Vector
|
|
386
|
+
The vector by which to translate the Element
|
|
387
|
+
|
|
388
|
+
"""
|
|
389
|
+
ec.move_element([self.id], vector_to_cadwork(vector))
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
from compas.plugins import plugin
|
|
2
|
+
from compas.scene import register
|
|
3
|
+
|
|
4
|
+
from .camera import Camera
|
|
5
|
+
from .scene import CadworkSceneObject
|
|
6
|
+
from .instructionobject import Text3dSceneObject
|
|
7
|
+
from .instructionobject import LinearDimensionSceneObject
|
|
8
|
+
|
|
9
|
+
__all__ = [
|
|
10
|
+
"Camera",
|
|
11
|
+
"CadworkSceneObject",
|
|
12
|
+
"Text3dSceneObject",
|
|
13
|
+
"LinearDimensionSceneObject",
|
|
14
|
+
]
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
CONTEXT = "cadwork"
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
@plugin(category="drawing-utils", requires=[CONTEXT])
|
|
21
|
+
def clear(*args, **kwargs):
|
|
22
|
+
CadworkSceneObject.clear()
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
@plugin(category="drawing-utils", requires=[CONTEXT])
|
|
26
|
+
def after_draw(*args, **kwargs):
|
|
27
|
+
CadworkSceneObject.refresh()
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
@plugin(category="factories", requires=[CONTEXT])
|
|
31
|
+
def register_scene_objects():
|
|
32
|
+
try:
|
|
33
|
+
from compas_monosashi.sequencer import Text3d
|
|
34
|
+
from compas_monosashi.sequencer import LinearDimension
|
|
35
|
+
|
|
36
|
+
# These should move to monosashi probably
|
|
37
|
+
register(Text3d, Text3dSceneObject, context=CONTEXT)
|
|
38
|
+
register(LinearDimension, LinearDimensionSceneObject, context=CONTEXT)
|
|
39
|
+
except Exception:
|
|
40
|
+
pass
|