Skip to content

Commit 864a537

Browse files
committed
Exposure of enclosure APIs
The PR exposes 3 separate APIs for the creation of Box, Cylinder and Sphere enclosure. Enclosure options are common to the 3 cases. Specific argument are given to each method and grpc request
1 parent 8b628a2 commit 864a537

File tree

5 files changed

+436
-2
lines changed

5 files changed

+436
-2
lines changed

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,3 +83,17 @@ 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 create_box_enclosure(self, **kwargs) -> dict:
89+
"""Create a box enclosure around bodies."""
90+
pass
91+
92+
@abstractmethod
93+
def create_cylinder_enclosure(self, **kwargs) -> dict:
94+
"""Create a cylinder enclosure around bodies."""
95+
pass
96+
97+
@abstractmethod
98+
def create_sphere_enclosure(self, **kwargs) -> dict:
99+
"""Create a sphere enclosure around bodies."""

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

Lines changed: 105 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,20 @@
2323

2424
import grpc
2525

26+
from ansys.api.geometry.v0.preparetools_pb2 import (
27+
CreateEnclosureBoxRequest,
28+
CreateEnclosureCylinderRequest,
29+
CreateEnclosureSphereRequest,
30+
)
31+
from ansys.api.geometry.v0.models_pb2 import Body
32+
from ansys.api.geometry.v0.preparetools_pb2 import EnclosureOptions as GRPCEnclosureOptions
33+
2634
from ansys.geometry.core.errors import protect_grpc
35+
from ansys.geometry.core.tools.prepare_tools import EnclosureOptions
2736

2837
from ..base.conversions import from_measurement_to_server_length
2938
from ..base.prepare_tools import GRPCPrepareToolsService
30-
from .conversions import build_grpc_id
39+
from .conversions import build_grpc_id, from_frame_to_grpc_frame, serialize_tracker_command_response
3140

3241

3342
class GRPCPrepareToolsServiceV0(GRPCPrepareToolsService):
@@ -295,3 +304,98 @@ def detect_helixes(self, **kwargs) -> dict: # noqa: D102
295304
for helix in response.helixes
296305
]
297306
}
307+
308+
@protect_grpc
309+
def create_box_enclosure(self, **kwargs) -> dict: # noqa: D102
310+
enclosure_options = kwargs["enclosure_options"]
311+
frame = enclosure_options.frame
312+
grpc_enclosure_options = GRPCEnclosureOptions(
313+
create_shared_topology=enclosure_options.create_shared_topology,
314+
subtract_bodies=enclosure_options.subtract_bodies,
315+
frame=from_frame_to_grpc_frame(frame) if frame is not None else None,
316+
)
317+
# Create the request - assumes all inputs are valid and of the proper type
318+
request = CreateEnclosureBoxRequest(
319+
bodies=[Body(id=body.id) for body in kwargs["bodies"]],
320+
x_low=kwargs["x_low"],
321+
x_high=kwargs["x_high"],
322+
y_low=kwargs["y_low"],
323+
y_high=kwargs["y_high"],
324+
z_low=kwargs["z_low"],
325+
z_high=kwargs["z_high"],
326+
enclosure_options=grpc_enclosure_options,
327+
)
328+
329+
# Call the gRPC service
330+
response = self.stub.CreateEnclosureBox(request)
331+
332+
# Return the response - formatted as a dictionary
333+
serialized_tracker_response = serialize_tracker_command_response(
334+
response=response.command_response
335+
)
336+
return {
337+
"success": response.success,
338+
"created_bodies": [body.id for body in response.created_bodies],
339+
"tracker_response": serialized_tracker_response,
340+
}
341+
342+
@protect_grpc
343+
def create_cylinder_enclosure(self, **kwargs) -> dict: # noqa: D102
344+
enclosure_options = kwargs["enclosure_options"]
345+
frame = enclosure_options.frame
346+
grpc_enclosure_options = GRPCEnclosureOptions(
347+
create_shared_topology=enclosure_options.create_shared_topology,
348+
subtract_bodies=enclosure_options.subtract_bodies,
349+
frame=from_frame_to_grpc_frame(frame) if frame is not None else None,
350+
)
351+
# Create the request - assumes all inputs are valid and of the proper type
352+
request = CreateEnclosureCylinderRequest(
353+
bodies=[Body(id=body.id) for body in kwargs["bodies"]],
354+
axial_distance_low=kwargs["axial_distance_low"],
355+
axial_distance_high=kwargs["axial_distance_high"],
356+
radial_distance=kwargs["radial_distance"],
357+
enclosure_options=grpc_enclosure_options,
358+
)
359+
360+
# Call the gRPC service
361+
response = self.stub.CreateEnclosureCylinder(request)
362+
363+
# Return the response - formatted as a dictionary
364+
serialized_tracker_response = serialize_tracker_command_response(
365+
response=response.command_response
366+
)
367+
return {
368+
"success": response.success,
369+
"created_bodies": [body.id for body in response.created_bodies],
370+
"tracker_response": serialized_tracker_response,
371+
}
372+
373+
@protect_grpc
374+
def create_sphere_enclosure(self, **kwargs) -> dict: # noqa: D102
375+
enclosure_options = kwargs["enclosure_options"]
376+
frame = enclosure_options.frame
377+
grpc_enclosure_options = GRPCEnclosureOptions(
378+
create_shared_topology=enclosure_options.create_shared_topology,
379+
subtract_bodies=enclosure_options.subtract_bodies,
380+
frame=from_frame_to_grpc_frame(frame) if frame is not None else None,
381+
)
382+
# Create the request - assumes all inputs are valid and of the proper type
383+
384+
request = CreateEnclosureSphereRequest(
385+
bodies=[Body(id=body.id) for body in kwargs["bodies"]],
386+
radial_distance=kwargs["radial_distance"],
387+
enclosure_options=grpc_enclosure_options,
388+
)
389+
390+
# Call the gRPC service
391+
response = self.stub.CreateEnclosureSphere(request)
392+
393+
# Return the response - formatted as a dictionary
394+
serialized_tracker_response = serialize_tracker_command_response(
395+
response=response.command_response
396+
)
397+
return {
398+
"success": response.success,
399+
"created_bodies": [body.id for body in response.created_bodies],
400+
"tracker_response": serialized_tracker_response,
401+
}

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,3 +82,15 @@ 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 create_box_enclosure(self, **kwargs) -> dict: # noqa: D102
88+
raise NotImplementedError
89+
90+
@protect_grpc
91+
def create_cylinder_enclosure(self, **kwargs) -> dict: # noqa: D102
92+
raise NotImplementedError
93+
94+
@protect_grpc
95+
def create_sphere_enclosure(self, **kwargs) -> dict: # noqa: D102
96+
raise NotImplementedError

0 commit comments

Comments
 (0)