Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions doc/changelog.d/2340.maintenance.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add unit support
37 changes: 31 additions & 6 deletions src/ansys/geometry/core/_grpc/_services/v0/prepare_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

from ansys.geometry.core.errors import protect_grpc

from ..base.conversions import from_measurement_to_server_length
from ..base.prepare_tools import GRPCPrepareToolsService
from .conversions import build_grpc_id

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

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

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

# Check height objects
min_height = (
from_measurement_to_server_length(kwargs["min_height"])
if kwargs["min_height"] is not None
else None
)
max_height = (
from_measurement_to_server_length(kwargs["max_height"])
if kwargs["max_height"] is not None
else None
)

# Create the request - assumes all inputs are valid and of the proper type
request = FindLogosRequest(
bodies=[build_grpc_id(body) for body in kwargs["bodies"]],
options=FindLogoOptions(
min_height=kwargs["min_height"],
max_height=kwargs["max_height"],
min_height=min_height,
max_height=max_height,
),
)

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

# Check height objects
min_height = (
from_measurement_to_server_length(kwargs["min_height"])
if kwargs["min_height"] is not None
else None
)
max_height = (
from_measurement_to_server_length(kwargs["max_height"])
if kwargs["max_height"] is not None
else None
)

# Create the request - assumes all inputs are valid and of the proper type
request = FindLogosRequest(
bodies=[build_grpc_id(body) for body in kwargs["bodies"]],
options=FindLogoOptions(
min_height=kwargs["min_height"],
max_height=kwargs["max_height"],
min_height=min_height,
max_height=max_height,
),
)

Expand Down
14 changes: 8 additions & 6 deletions src/ansys/geometry/core/_grpc/_services/v0/repair_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@

from ansys.geometry.core.errors import protect_grpc

from ..base.conversions import from_measurement_to_server_angle, from_measurement_to_server_length
from ..base.repair_tools import GRPCRepairToolsService
from .conversions import (
serialize_tracker_command_response,
Expand Down Expand Up @@ -64,8 +65,10 @@ def find_split_edges(self, **kwargs) -> dict: # noqa: D102
# Create the request - assumes all inputs are valid and of the proper type
request = FindSplitEdgesRequest(
bodies_or_faces=kwargs["bodies_or_faces"],
angle=DoubleValue(value=float(kwargs["angle"])),
distance=DoubleValue(value=float(kwargs["distance"])),
angle=DoubleValue(value=float(from_measurement_to_server_angle(kwargs["angle"]))),
distance=DoubleValue(
value=float(from_measurement_to_server_length(kwargs["distance"]))
),
)

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

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

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

Expand Down
8 changes: 6 additions & 2 deletions src/ansys/geometry/core/designer/body.py
Original file line number Diff line number Diff line change
Expand Up @@ -1929,11 +1929,15 @@ def tessellate( # noqa: D102
)

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

@ensure_design_is_active
def remove_faces(self, selection: Face | Iterable[Face], offset: Real) -> bool: # noqa: D102
def remove_faces( # noqa: D102
self,
selection: Face | Iterable[Face],
offset: Distance | Quantity | Real,
) -> bool:
return self._template.remove_faces(selection, offset)

@graphics_required
Expand Down
2 changes: 1 addition & 1 deletion src/ansys/geometry/core/designer/geometry_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ def extrude_faces(
----------
faces : Face | list[Face]
Faces to extrude.
distance : Real
distance : Distance | Quantity | Real
Distance to extrude.
direction : UnitVector3D, default: None
Direction of extrusion. If no direction is provided, it will be inferred.
Expand Down
50 changes: 39 additions & 11 deletions src/ansys/geometry/core/tools/prepare_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,15 +228,18 @@ def remove_rounds(self, faces: list["Face"], auto_shrink: bool = False) -> bool:

@min_backend_version(24, 2, 0)
def share_topology(
self, bodies: list["Body"], tol: Real = 0.0, preserve_instances: bool = False
self,
bodies: list["Body"],
tol: Distance | Quantity | Real = 0.0,
preserve_instances: bool = False,
) -> bool:
"""Share topology between the chosen bodies.

Parameters
----------
bodies : list[Body]
List of bodies to share topology between.
tol : Real
tol : Distance | Quantity | Real
Maximum distance between bodies.
preserve_instances : bool
Whether instances are preserved.
Expand All @@ -257,6 +260,7 @@ def share_topology(

# Verify inputs
check_type_all_elements_in_iterable(bodies, Body)
tol = tol if isinstance(tol, Distance) else Distance(tol)

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

@min_backend_version(25, 2, 0)
def enhanced_share_topology(
self, bodies: list["Body"], tol: Real = 0.0, preserve_instances: bool = False
self,
bodies: list["Body"],
tol: Distance | Quantity | Real = 0.0,
preserve_instances: bool = False,
) -> RepairToolMessage:
"""Share topology between the chosen bodies.

Parameters
----------
bodies : list[Body]
List of bodies to share topology between.
tol : Real
tol : Distance | Quantity | Real
Maximum distance between bodies.
preserve_instances : bool
Whether instances are preserved.
Expand All @@ -299,6 +306,7 @@ def enhanced_share_topology(

# Verify inputs
check_type_all_elements_in_iterable(bodies, Body)
tol = tol if isinstance(tol, Distance) else Distance(tol)

response = self._grpc_client._services.prepare_tools.enhanced_share_topology(
bodies=[body.id for body in bodies],
Expand All @@ -318,7 +326,10 @@ def enhanced_share_topology(
@check_input_types
@min_backend_version(25, 2, 0)
def find_logos(
self, bodies: list["Body"] = None, min_height: Real = None, max_height: Real = None
self,
bodies: list["Body"] = None,
min_height: Distance | Quantity | Real = None,
max_height: Distance | Quantity | Real = None,
) -> "LogoProblemArea":
"""Detect logos in geometry.

Expand All @@ -329,9 +340,9 @@ def find_logos(
----------
bodies : list[Body], optional
List of bodies where logos should be detected
min_height : real, optional
min_height : Distance | Quantity | Real, optional
The minimum height when searching for logos
max_height: real, optional
max_height: Distance | Quantity | Real, optional
The minimum height when searching for logos

Returns
Expand All @@ -357,6 +368,13 @@ def find_logos(
check_type_all_elements_in_iterable(bodies, Body)

bodies = [] if bodies is None else bodies

# Convert the height inputs to Distance if they are not already
if min_height:
min_height = min_height if isinstance(min_height, Distance) else Distance(min_height)
if max_height:
max_height = max_height if isinstance(max_height, Distance) else Distance(max_height)

response = self._grpc_client._services.prepare_tools.find_logos(
bodies=[body.id for body in bodies],
min_height=min_height,
Expand All @@ -372,7 +390,10 @@ def find_logos(
@check_input_types
@min_backend_version(25, 2, 0)
def find_and_remove_logos(
self, bodies: list["Body"] = None, min_height: Real = None, max_height: Real = None
self,
bodies: list["Body"] = None,
min_height: Distance | Quantity | Real = None,
max_height: Distance | Quantity | Real = None,
) -> bool:
"""Detect and remove logos in geometry.

Expand All @@ -382,10 +403,10 @@ def find_and_remove_logos(
----------
bodies : list[Body], optional
List of bodies where logos should be detected and removed.
min_height : real, optional
The minimum height when searching for logos
max_height: real, optional
min_height : Distance | Quantity | Real, optional
The minimum height when searching for logos
max_height: Distance | Quantity | Real, optional
The maximum height when searching for logos

Returns
-------
Expand All @@ -409,6 +430,13 @@ def find_and_remove_logos(
check_type_all_elements_in_iterable(bodies, Body)

bodies = [] if bodies is None else bodies

# Convert the height inputs to Distance if they are not already
if min_height:
min_height = min_height if isinstance(min_height, Distance) else Distance(min_height)
if max_height:
max_height = max_height if isinstance(max_height, Distance) else Distance(max_height)

response = self._grpc_client._services.prepare_tools.find_and_remove_logos(
bodies=[body.id for body in bodies],
min_height=min_height,
Expand Down
Loading
Loading