Skip to content

Commit 7c296c5

Browse files
committed
Refactor type hints and improve documentation in machine controller
Signed-off-by: Michael Brunner <brunner@cadwork.swiss>
1 parent dfc4c71 commit 7c296c5

File tree

4 files changed

+230
-39
lines changed

4 files changed

+230
-39
lines changed

src/bim_controller/__init__.pyi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,12 @@ def get_ifc2x3_element_type(element_id: int) -> ifc_2x3_element_type:
4242
"""
4343

4444

45-
def set_ifc2x3_element_type(element_i_ds: List[int], element_type: element_type) -> None:
45+
def set_ifc2x3_element_type(element_i_ds: List[int], ifc_type: ifc_2x3_element_type) -> None:
4646
"""set ifc2x3 element type
4747
4848
Parameters:
4949
element_i_ds: element_i_ds
50-
element_type: element_type
50+
ifc_type: element_type
5151
5252
Returns:
5353
None

src/cadwork/point_3d.pyi

Lines changed: 112 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -8,61 +8,146 @@ class point_3d:
88
y (float): The y-coordinate of the point.
99
z (float): The z-coordinate of the point.
1010
"""
11-
self.x = x
12-
self.y = y
13-
self.z = z
1411

15-
def dot(self, p: 'point_3d') -> float:
16-
"""dot
12+
def __add__(self, other: 'point_3d') -> 'point_3d':
13+
"""
14+
Add two points component-wise.
1715
18-
Parameters:
19-
p: p
16+
Returns:
17+
point_3d: The sum of two points.
18+
"""
19+
20+
def __sub__(self, other: 'point_3d') -> 'point_3d':
21+
"""
22+
Subtract two points component-wise.
2023
2124
Returns:
22-
float
25+
point_3d: The difference of two points.
2326
"""
2427

25-
def cross(self, p: 'point_3d') -> 'point_3d':
26-
"""cross
28+
def __mul__(self, other: float) -> 'point_3d':
29+
"""
30+
Multiply point by a scalar.
2731
28-
Parameters:
29-
p: p
32+
Returns:
33+
point_3d: The scaled point.
34+
"""
35+
36+
def __rmul__(self, other: float) -> 'point_3d':
37+
"""
38+
Multiply point by a scalar (right-hand side).
3039
3140
Returns:
32-
'point_3d'
41+
point_3d: The scaled point.
3342
"""
3443

35-
def magnitude(self) -> float:
36-
"""magnitude
44+
def __truediv__(self, other: float) -> 'point_3d':
45+
"""
46+
Divide point by a scalar.
3747
3848
Returns:
39-
float
49+
point_3d: The scaled point.
4050
"""
4151

42-
def normalized(self) -> 'point_3d':
43-
"""normalized
52+
def __iadd__(self, other: 'point_3d') -> 'point_3d':
53+
"""
54+
In-place addition of another point.
4455
4556
Returns:
46-
'point_3d'
57+
point_3d: The updated point.
4758
"""
4859

49-
def distance(self, p: 'point_3d') -> float:
50-
"""distance
60+
def __isub__(self, other: 'point_3d') -> 'point_3d':
61+
"""
62+
In-place subtraction of another point.
5163
52-
Parameters:
53-
p: p
64+
Returns:
65+
point_3d: The updated point.
66+
"""
67+
68+
def __imul__(self, other: float) -> 'point_3d':
69+
"""
70+
In-place multiplication by a scalar.
5471
5572
Returns:
56-
float
73+
point_3d: The updated point.
5774
"""
5875

59-
def invert(self) -> 'point_3d':
60-
"""invert
76+
def __itruediv__(self, other: float) -> 'point_3d':
77+
"""
78+
In-place division by a scalar.
6179
6280
Returns:
63-
'point_3d'
81+
point_3d: The updated point.
82+
"""
83+
84+
def __neg__(self) -> 'point_3d':
6485
"""
86+
Negate the point (component-wise).
6587
88+
Returns:
89+
point_3d: The negated point.
90+
"""
91+
92+
def __eq__(self, other: object) -> bool:
93+
"""
94+
Check if two points are equal.
95+
96+
Returns:
97+
bool: True if equal, False otherwise.
98+
"""
99+
100+
def __ne__(self, other: object) -> bool:
101+
"""
102+
Check if two points are not equal.
103+
104+
Returns:
105+
bool: True if not equal, False otherwise.
106+
"""
107+
108+
def __getitem__(self, index: int) -> float:
109+
"""
110+
Get coordinate by index (0: x, 1: y, 2: z).
111+
112+
Returns:
113+
float: The coordinate value.
114+
Raises:
115+
IndexError: If index is out of range.
116+
"""
117+
118+
def __setitem__(self, index: int, value: float) -> None:
119+
"""
120+
Set coordinate by index (0: x, 1: y, 2: z).
121+
122+
Raises:
123+
IndexError: If index is out of range.
124+
"""
125+
126+
def __repr__(self) -> str:
127+
"""
128+
Return the string representation of the point.
129+
130+
Returns:
131+
str: The string representation.
132+
"""
133+
134+
def dot(self, p: 'point_3d') -> float:
135+
"""Dot product with another point."""
136+
137+
def cross(self, p: 'point_3d') -> 'point_3d':
138+
"""Cross product with another point."""
139+
140+
def magnitude(self) -> float:
141+
"""Return the magnitude of the point vector."""
142+
143+
def normalized(self) -> 'point_3d':
144+
"""Return the normalized (unit) vector."""
145+
146+
def distance(self, p: 'point_3d') -> float:
147+
"""Euclidean distance to another point."""
148+
149+
def invert(self) -> 'point_3d':
150+
"""Return the inverted point (negated coordinates)."""
66151
def __sub__(self, other: 'point_3d') -> 'point_3d':
67152
"""sub
68153

src/element_controller/__init__.pyi

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2131,7 +2131,7 @@ def map_elements(elements: List[int], map_query: element_map_query) -> Dict[str,
21312131
elements: elements
21322132
map_query: map_query
21332133
2134-
Example:
2134+
Examples:
21352135
>>> import cadwork
21362136
>>> import element_controller as ec
21372137
>>> your_map_query = cadwork.element_map_query()
@@ -2153,9 +2153,9 @@ def cast_ray_and_get_element_intersections(elements: List[int], ray_start_positi
21532153
ray_end_position: ray_end_position
21542154
radius: radius
21552155
2156-
Example:
2157-
>>> from cadwork import point_3d
2156+
Examples:
21582157
>>> import element_controller as ec
2158+
>>> from cadwork import point_3d
21592159
>>> ray_start = point_3d(0, 0, 0)
21602160
>>> ray_end = point_3d(1000, 0, 0)
21612161
>>> hit_result = ec.cast_ray_and_get_element_intersections(ec.get_active_identifiable_element_ids(), ray_start, ray_end, 40.0)

src/machine_controller/__init__.pyi

Lines changed: 113 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
from typing import List
2+
from cadwork import vertex_list
3+
24

35
def get_last_error(error_code: int) -> str:
46
"""Gets the last error
@@ -41,13 +43,6 @@ def export_hundegger(hundeggertype: int) -> None:
4143
None
4244
"""
4345

44-
def clear_errors() -> None:
45-
"""clear errors
46-
47-
Returns:
48-
None
49-
"""
50-
5146
def export_hundegger_with_file_path(hundeggertype: int, file_path: str) -> None:
5247
"""Exports a Hundegger file
5348
@@ -139,3 +134,114 @@ def export_hundegger_with_file_path_and_presetting_silent(hundeggertype: int, fi
139134
None
140135
"""
141136

137+
138+
def get_element_hundegger_processings(element_id: int, hundeggertype: int) -> List[int]:
139+
"""Get Hundegger processing IDs for an element.
140+
141+
Parameters:
142+
element_id: The element ID.
143+
hundeggertype: The Hundegger type.
144+
145+
Returns:
146+
List of processing IDs.
147+
"""
148+
149+
150+
def get_element_btl_processings(element_id: int, btl_version: int) -> List[int]:
151+
"""Get BTL processing IDs for an element.
152+
153+
Parameters:
154+
element_id: The element ID.
155+
btl_version: The BTL version.
156+
157+
Returns:
158+
List of processing IDs.
159+
"""
160+
161+
162+
def get_processing_name(reference_element_id: int, processing_id: int) -> str:
163+
"""Get the name of a processing.
164+
165+
Parameters:
166+
reference_element_id: The reference element ID.
167+
processing_id: The processing ID.
168+
169+
Examples:
170+
>>> import cadwork
171+
>>> import element_controller as ec
172+
>>> import machine_controller as mc
173+
174+
>>> element: int = 123456789
175+
>>> processings = mc.get_element_btl_processings(element, cadwork.btl_version.btlx_2_1.value)
176+
>>> for processing in processings:
177+
>>> name = mc.get_processing_name(element, processing)
178+
179+
Returns:
180+
The processing name.
181+
"""
182+
183+
184+
def get_processing_code(reference_element_id: int, processing_id: int) -> str:
185+
"""Get the code of a processing.
186+
187+
Parameters:
188+
reference_element_id: The reference element ID.
189+
processing_id: The processing ID.
190+
191+
Examples:
192+
>>> import cadwork
193+
>>> import element_controller as ec
194+
>>> import machine_controller as mc
195+
196+
>>> element: int = 123456789
197+
>>> processings = mc.get_element_btl_processings(element, cadwork.btl_version.btlx_2_1.value)
198+
>>> for processing in processings:
199+
>>> code = mc.get_processing_code(element, processing)
200+
201+
Returns:
202+
The processing code.
203+
"""
204+
205+
206+
def get_processing_points(reference_element_id: int, processing_id: int) -> vertex_list:
207+
"""Get the points of a processing.
208+
209+
Parameters:
210+
reference_element_id: The reference element ID.
211+
processing_id: The processing ID.
212+
213+
Examples:
214+
>>> import cadwork
215+
>>> import element_controller as ec
216+
>>> import machine_controller as mc
217+
218+
>>> element: int = 123456789
219+
>>> processings = mc.get_element_btl_processings(element, cadwork.btl_version.btlx_2_1.value)
220+
>>> for processing in processings:
221+
>>> points = mc.get_processing_points(element, processing)
222+
223+
Returns:
224+
A vertex_list of points.
225+
"""
226+
227+
228+
def get_processing_btl_parameter_set(reference_element_id: int, processing_id: int) -> List[str]:
229+
"""Get the BTL parameter set for a processing.
230+
231+
Parameters:
232+
reference_element_id: The reference element ID.
233+
processing_id: The processing ID.
234+
235+
Examples:
236+
>>> import cadwork
237+
>>> import element_controller as ec
238+
>>> import machine_controller as mc
239+
240+
>>> element: int = 123456789
241+
>>> processings = mc.get_element_btl_processings(element, cadwork.btl_version.btlx_2_1.value)
242+
>>> for processing in processings:
243+
>>> parameters = mc.get_processing_btl_parameter_set(element, processing)
244+
245+
Returns:
246+
List of BTL parameter strings.
247+
"""

0 commit comments

Comments
 (0)