From 10518485e2cff58baffe9bef9fbd940d3462950a Mon Sep 17 00:00:00 2001 From: Mike Kaplan Date: Tue, 21 Jan 2025 10:29:06 -0800 Subject: [PATCH 01/11] Find and Fix Edges Methods (split, extra, short) --- src/ansys/geometry/core/tools/repair_tools.py | 116 ++++++++++++++++++ 1 file changed, 116 insertions(+) diff --git a/src/ansys/geometry/core/tools/repair_tools.py b/src/ansys/geometry/core/tools/repair_tools.py index 74ae2246a7..a857c84802 100644 --- a/src/ansys/geometry/core/tools/repair_tools.py +++ b/src/ansys/geometry/core/tools/repair_tools.py @@ -54,6 +54,7 @@ SplitEdgeProblemAreas, StitchFaceProblemAreas, ) +from ansys.geometry.core.tools.repair_tool_message import RepairToolMessage from ansys.geometry.core.typing import Real if TYPE_CHECKING: # pragma: no cover @@ -350,3 +351,118 @@ def find_stitch_faces(self, bodies: list["Body"]) -> list[StitchFaceProblemAreas ) for res in problem_areas_response.result ] + + def find_and_fix_short_edges( + self, bodies: list["Body"], length: Real = 0.0 + ) -> RepairToolMessage: + """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. + + Returns + ------- + RepairToolMessage + Message containing created and/or modified bodies. + """ + 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 + + 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. + + Returns + ------- + RepairToolMessage + Message containing created and/or modified bodies. + """ + 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 + + 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. + """ + 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 \ No newline at end of file From 01cf671ed9a7b97b935b6c571357bbb270fa7e9b Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 21 Jan 2025 18:32:01 +0000 Subject: [PATCH 02/11] chore: auto fixes from pre-commit hooks --- src/ansys/geometry/core/tools/repair_tools.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/ansys/geometry/core/tools/repair_tools.py b/src/ansys/geometry/core/tools/repair_tools.py index a857c84802..b9b93ae464 100644 --- a/src/ansys/geometry/core/tools/repair_tools.py +++ b/src/ansys/geometry/core/tools/repair_tools.py @@ -351,7 +351,7 @@ def find_stitch_faces(self, bodies: list["Body"]) -> list[StitchFaceProblemAreas ) for res in problem_areas_response.result ] - + def find_and_fix_short_edges( self, bodies: list["Body"], length: Real = 0.0 ) -> RepairToolMessage: @@ -423,7 +423,7 @@ def find_and_fix_extra_edges( response.result.modified_bodies_monikers, ) return message - + def find_and_fix_split_edges( self, bodies: list["Body"], angle: Real = 0.0, length: Real = 0.0 ) -> RepairToolMessage: @@ -447,7 +447,7 @@ def find_and_fix_split_edges( """ 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] @@ -465,4 +465,4 @@ def find_and_fix_split_edges( response.result.created_bodies_monikers, response.result.modified_bodies_monikers, ) - return message \ No newline at end of file + return message From 2bd434f57e8385576df70354881787f2c7f4c2a4 Mon Sep 17 00:00:00 2001 From: pyansys-ci-bot <92810346+pyansys-ci-bot@users.noreply.github.com> Date: Tue, 21 Jan 2025 18:33:06 +0000 Subject: [PATCH 03/11] chore: adding changelog file 1672.added.md [dependabot-skip] --- doc/changelog.d/1672.added.md | 1 + 1 file changed, 1 insertion(+) create mode 100644 doc/changelog.d/1672.added.md diff --git a/doc/changelog.d/1672.added.md b/doc/changelog.d/1672.added.md new file mode 100644 index 0000000000..37aa0ea13a --- /dev/null +++ b/doc/changelog.d/1672.added.md @@ -0,0 +1 @@ +find and fix edge methods \ No newline at end of file From 010013cd79d6354bfde2341c3dbc9903c1a1abeb Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 21 Jan 2025 22:29:10 +0000 Subject: [PATCH 04/11] chore: auto fixes from pre-commit hooks --- src/ansys/geometry/core/tools/repair_tools.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ansys/geometry/core/tools/repair_tools.py b/src/ansys/geometry/core/tools/repair_tools.py index 0edc3fa3e6..1f9cb1757b 100644 --- a/src/ansys/geometry/core/tools/repair_tools.py +++ b/src/ansys/geometry/core/tools/repair_tools.py @@ -463,7 +463,7 @@ def find_and_fix_extra_edges( response.result.modified_bodies_monikers, ) return message - + def find_and_fix_split_edges( self, bodies: list["Body"], angle: Real = 0.0, length: Real = 0.0 ) -> RepairToolMessage: @@ -487,7 +487,7 @@ def find_and_fix_split_edges( """ 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] From 36d8cfe17f146ba3919750390ae1a3e04d976b84 Mon Sep 17 00:00:00 2001 From: Roberto Pastor Muela <37798125+RobPasMue@users.noreply.github.com> Date: Wed, 22 Jan 2025 08:18:26 +0100 Subject: [PATCH 05/11] fix: tab issues --- src/ansys/geometry/core/tools/repair_tools.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ansys/geometry/core/tools/repair_tools.py b/src/ansys/geometry/core/tools/repair_tools.py index 1f9cb1757b..6165af6e66 100644 --- a/src/ansys/geometry/core/tools/repair_tools.py +++ b/src/ansys/geometry/core/tools/repair_tools.py @@ -392,7 +392,7 @@ def find_simplify(self, bodies: list["Body"]) -> list[UnsimplifiedFaceProblemAre for res in problem_areas_response.result ] - def find_and_fix_short_edges( + def find_and_fix_short_edges( self, bodies: list["Body"], length: Real = 0.0 ) -> RepairToolMessage: """Find and fix the short edge problem areas. @@ -505,4 +505,4 @@ def find_and_fix_split_edges( response.result.created_bodies_monikers, response.result.modified_bodies_monikers, ) - return message \ No newline at end of file + return message From b98bb00a2e86818593587bcfb520465b2e542125 Mon Sep 17 00:00:00 2001 From: Mike Kaplan Date: Wed, 22 Jan 2025 07:25:05 -0800 Subject: [PATCH 06/11] type checking / documentation fixes --- src/ansys/geometry/core/tools/repair_tools.py | 20 ++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/src/ansys/geometry/core/tools/repair_tools.py b/src/ansys/geometry/core/tools/repair_tools.py index 0edc3fa3e6..73e2abe5a2 100644 --- a/src/ansys/geometry/core/tools/repair_tools.py +++ b/src/ansys/geometry/core/tools/repair_tools.py @@ -22,6 +22,7 @@ """Provides tools for repairing bodies.""" from typing import TYPE_CHECKING +from beartype import beartype as check_input_types from google.protobuf.wrappers_pb2 import DoubleValue @@ -391,8 +392,11 @@ def find_simplify(self, bodies: list["Body"]) -> list[UnsimplifiedFaceProblemAre ) for res in problem_areas_response.result ] - - def find_and_fix_short_edges( + + @protect_grpc + @check_input_types + @min_backend_version(25, 2, 0) + def find_and_fix_short_edges( self, bodies: list["Body"], length: Real = 0.0 ) -> RepairToolMessage: """Find and fix the short edge problem areas. @@ -403,6 +407,8 @@ def find_and_fix_short_edges( ---------- bodies : list[Body] List of bodies that short edges are investigated on. + length : Real + The maximum length of the edges. Returns ------- @@ -428,6 +434,9 @@ def find_and_fix_short_edges( ) return message + @protect_grpc + @check_input_types + @min_backend_version(25, 2, 0) def find_and_fix_extra_edges( self, bodies: list["Body"], length: Real = 0.0 ) -> RepairToolMessage: @@ -439,6 +448,8 @@ def find_and_fix_extra_edges( ---------- bodies : list[Body] List of bodies that short edges are investigated on. + length : Real + The maximum length of the edges. Returns ------- @@ -463,7 +474,10 @@ def find_and_fix_extra_edges( response.result.modified_bodies_monikers, ) return message - + + @protect_grpc + @check_input_types + @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: From c9a0239e577edb39f68a7381a46a2c9e4a610355 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed, 22 Jan 2025 15:28:17 +0000 Subject: [PATCH 07/11] chore: auto fixes from pre-commit hooks --- src/ansys/geometry/core/tools/repair_tools.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ansys/geometry/core/tools/repair_tools.py b/src/ansys/geometry/core/tools/repair_tools.py index 39d9f7c767..e2267e2fac 100644 --- a/src/ansys/geometry/core/tools/repair_tools.py +++ b/src/ansys/geometry/core/tools/repair_tools.py @@ -501,7 +501,7 @@ def find_and_fix_split_edges( """ 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] From 91b2593e05d498fb049a95203c7d436572b0f8c8 Mon Sep 17 00:00:00 2001 From: Mike Kaplan Date: Wed, 22 Jan 2025 07:28:34 -0800 Subject: [PATCH 08/11] fix indentation --- src/ansys/geometry/core/tools/repair_tools.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ansys/geometry/core/tools/repair_tools.py b/src/ansys/geometry/core/tools/repair_tools.py index 39d9f7c767..5b5c07f838 100644 --- a/src/ansys/geometry/core/tools/repair_tools.py +++ b/src/ansys/geometry/core/tools/repair_tools.py @@ -393,7 +393,7 @@ def find_simplify(self, bodies: list["Body"]) -> list[UnsimplifiedFaceProblemAre for res in problem_areas_response.result ] - @protect_grpc + @protect_grpc @check_input_types @min_backend_version(25, 2, 0) def find_and_fix_short_edges( From 0cf0b1484e0a62cb493df8725212e793e3d07f37 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed, 22 Jan 2025 15:29:51 +0000 Subject: [PATCH 09/11] chore: auto fixes from pre-commit hooks --- src/ansys/geometry/core/tools/repair_tools.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ansys/geometry/core/tools/repair_tools.py b/src/ansys/geometry/core/tools/repair_tools.py index 8c4eba9011..bd588ee481 100644 --- a/src/ansys/geometry/core/tools/repair_tools.py +++ b/src/ansys/geometry/core/tools/repair_tools.py @@ -22,8 +22,8 @@ """Provides tools for repairing bodies.""" from typing import TYPE_CHECKING -from beartype import beartype as check_input_types +from beartype import beartype as check_input_types from google.protobuf.wrappers_pb2 import DoubleValue from ansys.api.geometry.v0.bodies_pb2_grpc import BodiesStub From 61116650f0f7c0d1e322e2a439554bfa4ac5ce15 Mon Sep 17 00:00:00 2001 From: Mike Kaplan Date: Wed, 22 Jan 2025 07:47:34 -0800 Subject: [PATCH 10/11] move type check inside method --- src/ansys/geometry/core/tools/repair_tools.py | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/src/ansys/geometry/core/tools/repair_tools.py b/src/ansys/geometry/core/tools/repair_tools.py index 8c4eba9011..beeab8676e 100644 --- a/src/ansys/geometry/core/tools/repair_tools.py +++ b/src/ansys/geometry/core/tools/repair_tools.py @@ -22,7 +22,6 @@ """Provides tools for repairing bodies.""" from typing import TYPE_CHECKING -from beartype import beartype as check_input_types from google.protobuf.wrappers_pb2 import DoubleValue @@ -47,7 +46,8 @@ 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, @@ -394,7 +394,6 @@ def find_simplify(self, bodies: list["Body"]) -> list[UnsimplifiedFaceProblemAre ] @protect_grpc - @check_input_types @min_backend_version(25, 2, 0) def find_and_fix_short_edges( self, bodies: list["Body"], length: Real = 0.0 @@ -415,6 +414,10 @@ def find_and_fix_short_edges( 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, [], []) @@ -435,7 +438,6 @@ def find_and_fix_short_edges( return message @protect_grpc - @check_input_types @min_backend_version(25, 2, 0) def find_and_fix_extra_edges( self, bodies: list["Body"], length: Real = 0.0 @@ -456,6 +458,10 @@ def find_and_fix_extra_edges( 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, [], []) @@ -476,7 +482,6 @@ def find_and_fix_extra_edges( return message @protect_grpc - @check_input_types @min_backend_version(25, 2, 0) def find_and_fix_split_edges( self, bodies: list["Body"], angle: Real = 0.0, length: Real = 0.0 @@ -499,6 +504,10 @@ def find_and_fix_split_edges( 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, [], []) From 846ce44e38e8443a3588398700c081964c1eac5c Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed, 22 Jan 2025 15:48:08 +0000 Subject: [PATCH 11/11] chore: auto fixes from pre-commit hooks --- src/ansys/geometry/core/tools/repair_tools.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/ansys/geometry/core/tools/repair_tools.py b/src/ansys/geometry/core/tools/repair_tools.py index 2d7272238d..c039fae08f 100644 --- a/src/ansys/geometry/core/tools/repair_tools.py +++ b/src/ansys/geometry/core/tools/repair_tools.py @@ -23,7 +23,6 @@ from typing import TYPE_CHECKING -from beartype import beartype as check_input_types from google.protobuf.wrappers_pb2 import DoubleValue from ansys.api.geometry.v0.bodies_pb2_grpc import BodiesStub @@ -47,8 +46,11 @@ get_edges_from_ids, get_faces_from_ids, ) - -from ansys.geometry.core.misc.checks import check_type, 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, @@ -415,7 +417,6 @@ def find_and_fix_short_edges( RepairToolMessage Message containing created and/or modified bodies. """ - check_type_all_elements_in_iterable(bodies, Body) check_type(length, Real) @@ -459,7 +460,6 @@ def find_and_fix_extra_edges( RepairToolMessage Message containing created and/or modified bodies. """ - check_type_all_elements_in_iterable(bodies, Body) check_type(length, Real) @@ -505,7 +505,6 @@ def find_and_fix_split_edges( RepairToolMessage Message containing created and/or modified bodies. """ - check_type_all_elements_in_iterable(bodies, Body) check_type(length, Real)