|
23 | 23 |
|
24 | 24 | import grpc |
25 | 25 |
|
| 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 | + |
26 | 34 | from ansys.geometry.core.errors import protect_grpc |
| 35 | +from ansys.geometry.core.tools.prepare_tools import EnclosureOptions |
27 | 36 |
|
28 | 37 | from ..base.conversions import from_measurement_to_server_length |
29 | 38 | 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 |
31 | 40 |
|
32 | 41 |
|
33 | 42 | class GRPCPrepareToolsServiceV0(GRPCPrepareToolsService): |
@@ -295,3 +304,98 @@ def detect_helixes(self, **kwargs) -> dict: # noqa: D102 |
295 | 304 | for helix in response.helixes |
296 | 305 | ] |
297 | 306 | } |
| 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 | + } |
0 commit comments