Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: find and fix edge methods #1672

Open
wants to merge 17 commits into
base: blitz
Choose a base branch
from
Open
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/1672.added.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
find and fix edge methods
141 changes: 140 additions & 1 deletion src/ansys/geometry/core/tools/repair_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,11 @@
get_edges_from_ids,
get_faces_from_ids,
)
from ansys.geometry.core.misc.checks import check_type_all_elements_in_iterable, min_backend_version
from ansys.geometry.core.misc.checks import (
check_type,
check_type_all_elements_in_iterable,
min_backend_version,
)
from ansys.geometry.core.tools.problem_areas import (
DuplicateFaceProblemAreas,
ExtraEdgeProblemAreas,
Expand All @@ -58,6 +62,7 @@
StitchFaceProblemAreas,
UnsimplifiedFaceProblemAreas,
)
from ansys.geometry.core.tools.repair_tool_message import RepairToolMessage
from ansys.geometry.core.typing import Real

if TYPE_CHECKING: # pragma: no cover
Expand Down Expand Up @@ -390,3 +395,137 @@ def find_simplify(self, bodies: list["Body"]) -> list[UnsimplifiedFaceProblemAre
)
for res in problem_areas_response.result
]

@protect_grpc
@min_backend_version(25, 2, 0)
def find_and_fix_short_edges(
self, bodies: list["Body"], length: Real = 0.0
) -> RepairToolMessage:
RobPasMue marked this conversation as resolved.
Show resolved Hide resolved
"""Find and fix the short edge problem areas.

This method finds the short edges in the bodies and fixes them.

Parameters
----------
bodies : list[Body]
List of bodies that short edges are investigated on.
length : Real
The maximum length of the edges.

Returns
-------
RepairToolMessage
Message containing created and/or modified bodies.
"""
check_type_all_elements_in_iterable(bodies, Body)
check_type(length, Real)

if not bodies:
return RepairToolMessage(False, [], [])

response = self._repair_stub.FindAndFixShortEdges(
FindShortEdgesRequest(
selection=[body.id for body in bodies],
max_edge_length=DoubleValue(value=length),
)
)

parent_design = get_design_from_body(bodies[0])
parent_design._update_design_inplace()
message = RepairToolMessage(
response.result.success,
response.result.created_bodies_monikers,
response.result.modified_bodies_monikers,
)
return message

@protect_grpc
@min_backend_version(25, 2, 0)
def find_and_fix_extra_edges(
self, bodies: list["Body"], length: Real = 0.0
) -> RepairToolMessage:
"""Find and fix the extra edge problem areas.

This method finds the extra edges in the bodies and fixes them.

Parameters
----------
bodies : list[Body]
List of bodies that short edges are investigated on.
length : Real
The maximum length of the edges.

Returns
-------
RepairToolMessage
Message containing created and/or modified bodies.
"""
check_type_all_elements_in_iterable(bodies, Body)
check_type(length, Real)

if not bodies:
return RepairToolMessage(False, [], [])

response = self._repair_stub.FindAndFixExtraEdges(
FindExtraEdgesRequest(
selection=[body.id for body in bodies],
max_edge_length=DoubleValue(value=length),
)
)

parent_design = get_design_from_body(bodies[0])
parent_design._update_design_inplace()
message = RepairToolMessage(
response.result.success,
response.result.created_bodies_monikers,
response.result.modified_bodies_monikers,
)
return message

@protect_grpc
@min_backend_version(25, 2, 0)
def find_and_fix_split_edges(
self, bodies: list["Body"], angle: Real = 0.0, length: Real = 0.0
) -> RepairToolMessage:
"""Find and fix the split edge problem areas.

This method finds the extra edges in the bodies and fixes them.

Parameters
----------
bodies : list[Body]
List of bodies that split edges are investigated on.
angle : Real
The maximum angle between edges.
length : Real
The maximum length of the edges.

Returns
-------
RepairToolMessage
Message containing created and/or modified bodies.
"""
check_type_all_elements_in_iterable(bodies, Body)
check_type(length, Real)

if not bodies:
return RepairToolMessage(False, [], [])

angle_value = DoubleValue(value=float(angle))
length_value = DoubleValue(value=float(length))
body_ids = [body.id for body in bodies]

response = self._repair_stub.FindAndFixSplitEdges(
FindSplitEdgesRequest(
bodies_or_faces=body_ids, angle=angle_value, distance=length_value
)
)

parent_design = get_design_from_body(bodies[0])
parent_design._update_design_inplace()
message = RepairToolMessage(
response.result.success,
response.result.created_bodies_monikers,
response.result.modified_bodies_monikers,
)
return message
Loading