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: workflow enhancements for better tool results #1723

Open
wants to merge 3 commits into
base: main
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/1723.added.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
workflow enhancements for better tool results
52 changes: 52 additions & 0 deletions src/ansys/geometry/core/designer/geometry_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -743,6 +743,58 @@ def create_circular_pattern(

return result.result.success

@protect_grpc
@min_backend_version(25, 2, 0)
def modify_circular_pattern(
self,
selection: Union["Face", list["Face"]],
circular_count: int = 0,
linear_count: int = 0,
step_angle: Real = 0.0,
step_linear: Real = 0.0,
) -> bool:
"""Modify a circular pattern. Leave an argument at 0 for it to remain unchanged.

Parameters
----------
selection : Face | list[Face]
Faces that belong to the pattern.
circular_count : int, default: 0
How many members are in the circular pattern.
linear_count : int, default: 0
How many times the circular pattern repeats along the radial lines for a
two-dimensional pattern.
step_angle : Real, default: 0.0
Defines the circular angle
step_linear : Real, default: 0.0
Defines the step, along the radial lines, for a pattern dimension greater than 1
Comment on lines +767 to +770
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
step_angle : Real, default: 0.0
Defines the circular angle
step_linear : Real, default: 0.0
Defines the step, along the radial lines, for a pattern dimension greater than 1
step_angle : Real, default: 0.0
Defines the circular angle.
step_linear : Real, default: 0.0
Defines the step, along the radial lines, for a pattern dimension greater than 1.


Returns
-------
bool
``True`` when successful, ``False`` when failed.
"""
from ansys.geometry.core.designer.face import Face

selection: list[Face] = selection if isinstance(selection, list) else [selection]

check_type_all_elements_in_iterable(selection, Face)

for object in selection:
object.body._reset_tessellation_cache()

result = self._commands_stub.ModifyCircularPattern(
ModifyCircularPatternRequest(
selection=[object._grpc_id for object in selection],
circular_count=circular_count,
linear_count=linear_count,
step_angle=step_angle,
step_linear=step_linear,
)
)

return result.result.success

@protect_grpc
@min_backend_version(25, 2, 0)
def create_fill_pattern(
Expand Down
47 changes: 47 additions & 0 deletions src/ansys/geometry/core/tools/prepare_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
get_design_from_face,
)
from ansys.geometry.core.misc.checks import check_type_all_elements_in_iterable, min_backend_version
from ansys.geometry.core.tools.repair_tool_message import EnhancedRepairToolMessage
from ansys.geometry.core.typing import Real

if TYPE_CHECKING: # pragma: no cover
Expand Down Expand Up @@ -204,3 +205,49 @@ def share_topology(
)
)
return share_topo_response.result

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

Parameters
----------
bodies : list[Body]
List of bodies to share topology between.
tol : Real
Maximum distance between bodies.
preserve_instances : bool
Whether instances are preserved.

Returns
-------
EnhancedRepairToolMessage
Message containing number of problem areas found/fixed, created and/or modified bodies.
"""
from ansys.geometry.core.designer.body import Body

if not bodies:
return EnhancedRepairToolMessage(False, 0, 0, [], [])

# Verify inputs
check_type_all_elements_in_iterable(bodies, Body)

share_topo_response = self._prepare_stub.ShareTopology(
ShareTopologyRequest(
selection=[GRPCBody(id=body.id) for body in bodies],
tolerance=DoubleValue(value=tol),
preserve_instances=BoolValue(value=preserve_instances),
)
)

message = EnhancedRepairToolMessage(
share_topo_response.success,
share_topo_response.found,
share_topo_response.repaired,
share_topo_response.created_bodies_monikers,
share_topo_response.modified_bodies_monikers,
)
return message
58 changes: 58 additions & 0 deletions src/ansys/geometry/core/tools/repair_tool_message.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,61 @@ def created_bodies(self) -> list[str]:
def modified_bodies(self) -> list[str]:
"""The list of the modified bodies after the repair operation."""
return self._modified_bodies


class EnhancedRepairToolMessage:
"""Provides detailed return message for the repair tool methods."""
Comment on lines +58 to +61
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not just modify the old RepairToolMessage?


def __init__(
self,
success: bool,
found: int,
repaired: int,
created_bodies: list[str],
modified_bodies: list[str],
):
"""Initialize a new instance of the extra edge problem area class.

Parameters
----------
success: bool
True if the repair operation was effective, false if it is not.
found: int
Number of problem areas found for the repair operation.
repaired: int
Number of problem areas repaired during the repair operation.
created_bodies: list[str]
List of bodies created after the repair operation.
modified_bodies: list[str]
List of bodies modified after the repair operation.
"""
self._success = success
self._found = found
self._repaired = repaired
self._created_bodies = created_bodies
self._modified_bodies = modified_bodies

@property
def success(self) -> bool:
"""The success of the repair operation."""
return self._success

@property
def found(self) -> int:
"""Number of problem areas found for the repair operation."""
return self._found

@property
def repaired(self) -> int:
"""Number of problem areas repaired during the repair operation."""
return self._repaired

@property
def created_bodies(self) -> list[str]:
"""The list of the created bodies after the repair operation."""
return self._created_bodies

@property
def modified_bodies(self) -> list[str]:
"""The list of the modified bodies after the repair operation."""
return self._modified_bodies
40 changes: 24 additions & 16 deletions src/ansys/geometry/core/tools/repair_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,9 @@
StitchFaceProblemAreas,
UnsimplifiedFaceProblemAreas,
)
from ansys.geometry.core.tools.repair_tool_message import RepairToolMessage
from ansys.geometry.core.tools.repair_tool_message import (
EnhancedRepairToolMessage,
)
from ansys.geometry.core.typing import Real

if TYPE_CHECKING: # pragma: no cover
Expand Down Expand Up @@ -460,7 +462,7 @@ def find_interferences(
@min_backend_version(25, 2, 0)
def find_and_fix_short_edges(
self, bodies: list["Body"], length: Real = 0.0
) -> RepairToolMessage:
) -> EnhancedRepairToolMessage:
"""Find and fix the short edge problem areas.

Notes
Expand All @@ -476,16 +478,16 @@ def find_and_fix_short_edges(

Returns
-------
RepairToolMessage
Message containing created and/or modified bodies.
EnhancedRepairToolMessage
Message containing number of problem areas found/fixed, created and/or modified bodies.
"""
from ansys.geometry.core.designer.body import Body

check_type_all_elements_in_iterable(bodies, Body)
check_type(length, Real)

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

response = self._repair_stub.FindAndFixShortEdges(
FindShortEdgesRequest(
Expand All @@ -496,16 +498,18 @@ def find_and_fix_short_edges(

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

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

Notes
Expand All @@ -521,15 +525,15 @@ def find_and_fix_extra_edges(self, bodies: list["Body"]) -> RepairToolMessage:

Returns
-------
RepairToolMessage
Message containing created and/or modified bodies.
EnhancedRepairToolMessage
Message containing number of problem areas found/fixed, created and/or modified bodies.
"""
from ansys.geometry.core.designer.body import Body

check_type_all_elements_in_iterable(bodies, Body)

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

response = self._repair_stub.FindAndFixExtraEdges(
FindExtraEdgesRequest(
Expand All @@ -539,8 +543,10 @@ def find_and_fix_extra_edges(self, bodies: list["Body"]) -> RepairToolMessage:

parent_design = get_design_from_body(bodies[0])
parent_design._update_design_inplace()
message = RepairToolMessage(
message = EnhancedRepairToolMessage(
response.success,
response.found,
response.repaired,
response.created_bodies_monikers,
response.modified_bodies_monikers,
)
Expand All @@ -550,7 +556,7 @@ def find_and_fix_extra_edges(self, bodies: list["Body"]) -> RepairToolMessage:
@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:
) -> EnhancedRepairToolMessage:
"""Find and fix the split edge problem areas.

Notes
Expand All @@ -568,8 +574,8 @@ def find_and_fix_split_edges(

Returns
-------
RepairToolMessage
Message containing created and/or modified bodies.
EnhancedRepairToolMessage
Message containing number of problem areas found/fixed, created and/or modified bodies.
"""
from ansys.geometry.core.designer.body import Body

Expand All @@ -578,7 +584,7 @@ def find_and_fix_split_edges(
check_type(length, Real)

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

angle_value = DoubleValue(value=float(angle))
length_value = DoubleValue(value=float(length))
Expand All @@ -592,8 +598,10 @@ def find_and_fix_split_edges(

parent_design = get_design_from_body(bodies[0])
parent_design._update_design_inplace()
message = RepairToolMessage(
message = EnhancedRepairToolMessage(
response.success,
response.found,
response.repaired,
response.created_bodies_monikers,
response.modified_bodies_monikers,
)
Expand Down
Loading