Skip to content

Commit 2148d77

Browse files
wip - needs testing
1 parent 00ac1ab commit 2148d77

File tree

5 files changed

+73
-0
lines changed

5 files changed

+73
-0
lines changed

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,3 +83,8 @@ def remove_logo(self, **kwargs) -> dict:
8383
def detect_helixes(self, **kwargs) -> dict:
8484
"""Detect helixes in geometry."""
8585
pass
86+
87+
@abstractmethod
88+
def is_body_sweepable(self, **kwargs) -> dict:
89+
"""Check if body is sweepable."""
90+
pass

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

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,3 +295,29 @@ def detect_helixes(self, **kwargs) -> dict: # noqa: D102
295295
for helix in response.helixes
296296
]
297297
}
298+
299+
@protect_grpc
300+
def is_body_sweepable(self, **kwargs): # noqa: D102
301+
from ansys.api.geometry.v0.preparetools_pb2 import IsBodySweepableRequest
302+
303+
# Create the request - assumes all inputs are valid and of the proper type
304+
request = IsBodySweepableRequest(
305+
body=build_grpc_id(kwargs["body_id"]),
306+
get_source_target_faces=kwargs["get_source_target_faces"],
307+
)
308+
309+
# Call the gRPC service
310+
response = self.stub.IsBodySweepable(request)
311+
312+
# Return the response - formatted as a dictionary
313+
return {
314+
"result": response.result,
315+
"faces": [
316+
{
317+
"id": face.id,
318+
"surface_type": face.surface_type,
319+
"is_reversed": face.is_reversed,
320+
}
321+
for face in response.faces
322+
],
323+
}

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,3 +82,7 @@ def remove_logo(self, **kwargs) -> dict: # noqa: D102
8282
@protect_grpc
8383
def detect_helixes(self, **kwargs) -> dict: # noqa: D102
8484
raise NotImplementedError
85+
86+
@protect_grpc
87+
def is_body_sweepable(self, **kwargs): # noqa: D102
88+
raise NotImplementedError

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

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -527,3 +527,29 @@ def detect_helixes(
527527
for helix in response.get("helixes")
528528
]
529529
}
530+
531+
def is_body_sweepable(self, body: "Body", get_source_target_faces: bool) -> bool:
532+
"""Check if a body is sweepable.
533+
534+
Parameters
535+
----------
536+
body : Body
537+
Body to check.
538+
get_source_target_faces : bool
539+
Whether to get source and target faces.
540+
541+
Returns
542+
-------
543+
bool
544+
True if the body is sweepable, False otherwise.
545+
"""
546+
from ansys.geometry.core.designer.body import Body
547+
548+
# Verify inputs
549+
check_type_all_elements_in_iterable([body], Body)
550+
551+
response = self._grpc_client._services.prepare_tools.is_body_sweepable(
552+
body_id=body.id,
553+
)
554+
555+
return response.get("is_sweepable")

tests/integration/test_prepare_tools.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,3 +234,15 @@ def test_helix_detection(modeler: Modeler):
234234
# Test with multiple bodies
235235
result = modeler.prepare_tools.detect_helixes(bodies)
236236
assert len(result["helixes"]) == 2
237+
238+
239+
def test_is_body_sweepable(modeler: Modeler):
240+
"""Test body sweepability detection."""
241+
design = modeler.open_file(FILES_DIR / "simpleSweepableBody.scdocx")
242+
243+
bodies = design.bodies
244+
assert len(bodies) == 1
245+
246+
# Test sweepability of the body
247+
is_sweepable = modeler.prepare_tools.is_body_sweepable(bodies[0])
248+
assert is_sweepable is True

0 commit comments

Comments
 (0)