Skip to content

Commit 1c856df

Browse files
jacobrkerstetterpre-commit-ci[bot]pyansys-ci-bot
authored
chore: add unit support (#2340)
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: pyansys-ci-bot <[email protected]>
1 parent 5c82731 commit 1c856df

File tree

7 files changed

+119
-41
lines changed

7 files changed

+119
-41
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Add unit support

src/ansys/geometry/core/_grpc/_services/v0/prepare_tools.py

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525

2626
from ansys.geometry.core.errors import protect_grpc
2727

28+
from ..base.conversions import from_measurement_to_server_length
2829
from ..base.prepare_tools import GRPCPrepareToolsService
2930
from .conversions import build_grpc_id
3031

@@ -115,7 +116,7 @@ def share_topology(self, **kwargs) -> dict: # noqa: D102
115116
# Create the request - assumes all inputs are valid and of the proper type
116117
request = ShareTopologyRequest(
117118
selection=[Body(id=body) for body in kwargs["bodies"]],
118-
tolerance=DoubleValue(value=kwargs["tolerance"]),
119+
tolerance=DoubleValue(value=from_measurement_to_server_length(kwargs["tolerance"])),
119120
preserve_instances=BoolValue(value=kwargs["preserve_instances"]),
120121
)
121122

@@ -136,7 +137,7 @@ def enhanced_share_topology(self, **kwargs) -> dict: # noqa: D102
136137
# Create the request - assumes all inputs are valid and of the proper type
137138
request = ShareTopologyRequest(
138139
selection=[Body(id=body) for body in kwargs["bodies"]],
139-
tolerance=DoubleValue(value=kwargs["tolerance"]),
140+
tolerance=DoubleValue(value=from_measurement_to_server_length(kwargs["tolerance"])),
140141
preserve_instances=BoolValue(value=kwargs["preserve_instances"]),
141142
)
142143

@@ -158,12 +159,24 @@ def find_logos(self, **kwargs) -> dict: # noqa: D102
158159
from ansys.api.geometry.v0.models_pb2 import FindLogoOptions
159160
from ansys.api.geometry.v0.preparetools_pb2 import FindLogosRequest
160161

162+
# Check height objects
163+
min_height = (
164+
from_measurement_to_server_length(kwargs["min_height"])
165+
if kwargs["min_height"] is not None
166+
else None
167+
)
168+
max_height = (
169+
from_measurement_to_server_length(kwargs["max_height"])
170+
if kwargs["max_height"] is not None
171+
else None
172+
)
173+
161174
# Create the request - assumes all inputs are valid and of the proper type
162175
request = FindLogosRequest(
163176
bodies=[build_grpc_id(body) for body in kwargs["bodies"]],
164177
options=FindLogoOptions(
165-
min_height=kwargs["min_height"],
166-
max_height=kwargs["max_height"],
178+
min_height=min_height,
179+
max_height=max_height,
167180
),
168181
)
169182

@@ -181,12 +194,24 @@ def find_and_remove_logos(self, **kwargs) -> dict: # noqa: D102
181194
from ansys.api.geometry.v0.models_pb2 import FindLogoOptions
182195
from ansys.api.geometry.v0.preparetools_pb2 import FindLogosRequest
183196

197+
# Check height objects
198+
min_height = (
199+
from_measurement_to_server_length(kwargs["min_height"])
200+
if kwargs["min_height"] is not None
201+
else None
202+
)
203+
max_height = (
204+
from_measurement_to_server_length(kwargs["max_height"])
205+
if kwargs["max_height"] is not None
206+
else None
207+
)
208+
184209
# Create the request - assumes all inputs are valid and of the proper type
185210
request = FindLogosRequest(
186211
bodies=[build_grpc_id(body) for body in kwargs["bodies"]],
187212
options=FindLogoOptions(
188-
min_height=kwargs["min_height"],
189-
max_height=kwargs["max_height"],
213+
min_height=min_height,
214+
max_height=max_height,
190215
),
191216
)
192217

src/ansys/geometry/core/_grpc/_services/v0/repair_tools.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131

3232
from ansys.geometry.core.errors import protect_grpc
3333

34+
from ..base.conversions import from_measurement_to_server_angle, from_measurement_to_server_length
3435
from ..base.repair_tools import GRPCRepairToolsService
3536
from .conversions import (
3637
serialize_tracker_command_response,
@@ -64,8 +65,10 @@ def find_split_edges(self, **kwargs) -> dict: # noqa: D102
6465
# Create the request - assumes all inputs are valid and of the proper type
6566
request = FindSplitEdgesRequest(
6667
bodies_or_faces=kwargs["bodies_or_faces"],
67-
angle=DoubleValue(value=float(kwargs["angle"])),
68-
distance=DoubleValue(value=float(kwargs["distance"])),
68+
angle=DoubleValue(value=float(from_measurement_to_server_angle(kwargs["angle"]))),
69+
distance=DoubleValue(
70+
value=float(from_measurement_to_server_length(kwargs["distance"]))
71+
),
6972
)
7073

7174
# Call the gRPC service
@@ -132,7 +135,7 @@ def find_short_edges(self, **kwargs) -> dict: # noqa: D102
132135
# Create the request - assumes all inputs are valid and of the proper type
133136
request = FindShortEdgesRequest(
134137
selection=kwargs["selection"],
135-
max_edge_length=DoubleValue(value=kwargs["length"]),
138+
max_edge_length=DoubleValue(value=from_measurement_to_server_length(kwargs["length"])),
136139
)
137140

138141
# Call the gRPC service
@@ -366,7 +369,7 @@ def find_and_fix_short_edges(self, **kwargs): # noqa: D102
366369
# Create the request - assumes all inputs are valid and of the proper type
367370
request = FindShortEdgesRequest(
368371
selection=kwargs["selection"],
369-
max_edge_length=DoubleValue(value=kwargs["length"]),
372+
max_edge_length=DoubleValue(value=from_measurement_to_server_length(kwargs["length"])),
370373
comprehensive=kwargs["comprehensive_result"],
371374
)
372375

@@ -422,8 +425,7 @@ def find_and_fix_split_edges(self, **kwargs) -> dict: # noqa: D102
422425
# Create the request - assumes all inputs are valid and of the proper type
423426
request = FindSplitEdgesRequest(
424427
bodies_or_faces=kwargs["bodies_or_faces"],
425-
angle=DoubleValue(value=float(kwargs["angle"])),
426-
distance=DoubleValue(value=float(kwargs["length"])),
428+
distance=DoubleValue(value=float(from_measurement_to_server_length(kwargs["length"]))),
427429
comprehensive=kwargs["comprehensive_result"],
428430
)
429431

src/ansys/geometry/core/designer/body.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1929,11 +1929,15 @@ def tessellate( # noqa: D102
19291929
)
19301930

19311931
@ensure_design_is_active
1932-
def shell_body(self, offset: Real) -> bool: # noqa: D102
1932+
def shell_body(self, offset: Distance | Quantity | Real) -> bool: # noqa: D102
19331933
return self._template.shell_body(offset)
19341934

19351935
@ensure_design_is_active
1936-
def remove_faces(self, selection: Face | Iterable[Face], offset: Real) -> bool: # noqa: D102
1936+
def remove_faces( # noqa: D102
1937+
self,
1938+
selection: Face | Iterable[Face],
1939+
offset: Distance | Quantity | Real,
1940+
) -> bool:
19371941
return self._template.remove_faces(selection, offset)
19381942

19391943
@graphics_required

src/ansys/geometry/core/designer/geometry_commands.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ def extrude_faces(
273273
----------
274274
faces : Face | list[Face]
275275
Faces to extrude.
276-
distance : Real
276+
distance : Distance | Quantity | Real
277277
Distance to extrude.
278278
direction : UnitVector3D, default: None
279279
Direction of extrusion. If no direction is provided, it will be inferred.

src/ansys/geometry/core/tools/prepare_tools.py

Lines changed: 39 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -228,15 +228,18 @@ def remove_rounds(self, faces: list["Face"], auto_shrink: bool = False) -> bool:
228228

229229
@min_backend_version(24, 2, 0)
230230
def share_topology(
231-
self, bodies: list["Body"], tol: Real = 0.0, preserve_instances: bool = False
231+
self,
232+
bodies: list["Body"],
233+
tol: Distance | Quantity | Real = 0.0,
234+
preserve_instances: bool = False,
232235
) -> bool:
233236
"""Share topology between the chosen bodies.
234237
235238
Parameters
236239
----------
237240
bodies : list[Body]
238241
List of bodies to share topology between.
239-
tol : Real
242+
tol : Distance | Quantity | Real
240243
Maximum distance between bodies.
241244
preserve_instances : bool
242245
Whether instances are preserved.
@@ -257,6 +260,7 @@ def share_topology(
257260

258261
# Verify inputs
259262
check_type_all_elements_in_iterable(bodies, Body)
263+
tol = tol if isinstance(tol, Distance) else Distance(tol)
260264

261265
response = self._grpc_client._services.prepare_tools.share_topology(
262266
bodies=[body.id for body in bodies],
@@ -268,15 +272,18 @@ def share_topology(
268272

269273
@min_backend_version(25, 2, 0)
270274
def enhanced_share_topology(
271-
self, bodies: list["Body"], tol: Real = 0.0, preserve_instances: bool = False
275+
self,
276+
bodies: list["Body"],
277+
tol: Distance | Quantity | Real = 0.0,
278+
preserve_instances: bool = False,
272279
) -> RepairToolMessage:
273280
"""Share topology between the chosen bodies.
274281
275282
Parameters
276283
----------
277284
bodies : list[Body]
278285
List of bodies to share topology between.
279-
tol : Real
286+
tol : Distance | Quantity | Real
280287
Maximum distance between bodies.
281288
preserve_instances : bool
282289
Whether instances are preserved.
@@ -299,6 +306,7 @@ def enhanced_share_topology(
299306

300307
# Verify inputs
301308
check_type_all_elements_in_iterable(bodies, Body)
309+
tol = tol if isinstance(tol, Distance) else Distance(tol)
302310

303311
response = self._grpc_client._services.prepare_tools.enhanced_share_topology(
304312
bodies=[body.id for body in bodies],
@@ -318,7 +326,10 @@ def enhanced_share_topology(
318326
@check_input_types
319327
@min_backend_version(25, 2, 0)
320328
def find_logos(
321-
self, bodies: list["Body"] = None, min_height: Real = None, max_height: Real = None
329+
self,
330+
bodies: list["Body"] = None,
331+
min_height: Distance | Quantity | Real = None,
332+
max_height: Distance | Quantity | Real = None,
322333
) -> "LogoProblemArea":
323334
"""Detect logos in geometry.
324335
@@ -329,9 +340,9 @@ def find_logos(
329340
----------
330341
bodies : list[Body], optional
331342
List of bodies where logos should be detected
332-
min_height : real, optional
343+
min_height : Distance | Quantity | Real, optional
333344
The minimum height when searching for logos
334-
max_height: real, optional
345+
max_height: Distance | Quantity | Real, optional
335346
The minimum height when searching for logos
336347
337348
Returns
@@ -357,6 +368,13 @@ def find_logos(
357368
check_type_all_elements_in_iterable(bodies, Body)
358369

359370
bodies = [] if bodies is None else bodies
371+
372+
# Convert the height inputs to Distance if they are not already
373+
if min_height:
374+
min_height = min_height if isinstance(min_height, Distance) else Distance(min_height)
375+
if max_height:
376+
max_height = max_height if isinstance(max_height, Distance) else Distance(max_height)
377+
360378
response = self._grpc_client._services.prepare_tools.find_logos(
361379
bodies=[body.id for body in bodies],
362380
min_height=min_height,
@@ -372,7 +390,10 @@ def find_logos(
372390
@check_input_types
373391
@min_backend_version(25, 2, 0)
374392
def find_and_remove_logos(
375-
self, bodies: list["Body"] = None, min_height: Real = None, max_height: Real = None
393+
self,
394+
bodies: list["Body"] = None,
395+
min_height: Distance | Quantity | Real = None,
396+
max_height: Distance | Quantity | Real = None,
376397
) -> bool:
377398
"""Detect and remove logos in geometry.
378399
@@ -382,10 +403,10 @@ def find_and_remove_logos(
382403
----------
383404
bodies : list[Body], optional
384405
List of bodies where logos should be detected and removed.
385-
min_height : real, optional
386-
The minimum height when searching for logos
387-
max_height: real, optional
406+
min_height : Distance | Quantity | Real, optional
388407
The minimum height when searching for logos
408+
max_height: Distance | Quantity | Real, optional
409+
The maximum height when searching for logos
389410
390411
Returns
391412
-------
@@ -409,6 +430,13 @@ def find_and_remove_logos(
409430
check_type_all_elements_in_iterable(bodies, Body)
410431

411432
bodies = [] if bodies is None else bodies
433+
434+
# Convert the height inputs to Distance if they are not already
435+
if min_height:
436+
min_height = min_height if isinstance(min_height, Distance) else Distance(min_height)
437+
if max_height:
438+
max_height = max_height if isinstance(max_height, Distance) else Distance(max_height)
439+
412440
response = self._grpc_client._services.prepare_tools.find_and_remove_logos(
413441
bodies=[body.id for body in bodies],
414442
min_height=min_height,

0 commit comments

Comments
 (0)