|
27 | 27 |
|
28 | 28 | from ..base.conversions import from_measurement_to_server_length |
29 | 29 | from ..base.prepare_tools import GRPCPrepareToolsService |
30 | | -from .conversions import build_grpc_id |
| 30 | +from .conversions import ( |
| 31 | + build_grpc_id, |
| 32 | + from_enclosure_options_to_grpc_enclosure_options, |
| 33 | + serialize_tracker_command_response, |
| 34 | +) |
31 | 35 |
|
32 | 36 |
|
33 | 37 | class GRPCPrepareToolsServiceV0(GRPCPrepareToolsService): |
@@ -295,3 +299,97 @@ def detect_helixes(self, **kwargs) -> dict: # noqa: D102 |
295 | 299 | for helix in response.helixes |
296 | 300 | ] |
297 | 301 | } |
| 302 | + |
| 303 | + @protect_grpc |
| 304 | + def create_box_enclosure(self, **kwargs) -> dict: # noqa: D102 |
| 305 | + from ansys.api.geometry.v0.models_pb2 import Body as GRPCBody |
| 306 | + from ansys.api.geometry.v0.preparetools_pb2 import CreateEnclosureBoxRequest |
| 307 | + |
| 308 | + grpc_enclosure_options = from_enclosure_options_to_grpc_enclosure_options( |
| 309 | + kwargs["enclosure_options"] |
| 310 | + ) |
| 311 | + |
| 312 | + # Create the request - assumes all inputs are valid and of the proper type |
| 313 | + request = CreateEnclosureBoxRequest( |
| 314 | + bodies=[GRPCBody(id=body.id) for body in kwargs["bodies"]], |
| 315 | + x_low=from_measurement_to_server_length(kwargs["x_low"]), |
| 316 | + x_high=from_measurement_to_server_length(kwargs["x_high"]), |
| 317 | + y_low=from_measurement_to_server_length(kwargs["y_low"]), |
| 318 | + y_high=from_measurement_to_server_length(kwargs["y_high"]), |
| 319 | + z_low=from_measurement_to_server_length(kwargs["z_low"]), |
| 320 | + z_high=from_measurement_to_server_length(kwargs["z_high"]), |
| 321 | + enclosure_options=grpc_enclosure_options, |
| 322 | + ) |
| 323 | + |
| 324 | + # Call the gRPC service |
| 325 | + response = self.stub.CreateEnclosureBox(request) |
| 326 | + |
| 327 | + # Return the response - formatted as a dictionary |
| 328 | + serialized_tracker_response = serialize_tracker_command_response( |
| 329 | + response=response.command_response |
| 330 | + ) |
| 331 | + return { |
| 332 | + "success": response.success, |
| 333 | + "created_bodies": [body.id for body in response.created_bodies], |
| 334 | + "tracker_response": serialized_tracker_response, |
| 335 | + } |
| 336 | + |
| 337 | + @protect_grpc |
| 338 | + def create_cylinder_enclosure(self, **kwargs) -> dict: # noqa: D102 |
| 339 | + from ansys.api.geometry.v0.models_pb2 import Body as GRPCBody |
| 340 | + from ansys.api.geometry.v0.preparetools_pb2 import CreateEnclosureCylinderRequest |
| 341 | + |
| 342 | + grpc_enclosure_options = from_enclosure_options_to_grpc_enclosure_options( |
| 343 | + kwargs["enclosure_options"] |
| 344 | + ) |
| 345 | + |
| 346 | + # Create the request - assumes all inputs are valid and of the proper type |
| 347 | + request = CreateEnclosureCylinderRequest( |
| 348 | + bodies=[GRPCBody(id=body.id) for body in kwargs["bodies"]], |
| 349 | + axial_distance_low=from_measurement_to_server_length(kwargs["axial_distance_low"]), |
| 350 | + axial_distance_high=from_measurement_to_server_length(kwargs["axial_distance_high"]), |
| 351 | + radial_distance=from_measurement_to_server_length(kwargs["radial_distance"]), |
| 352 | + enclosure_options=grpc_enclosure_options, |
| 353 | + ) |
| 354 | + |
| 355 | + # Call the gRPC service |
| 356 | + response = self.stub.CreateEnclosureCylinder(request) |
| 357 | + |
| 358 | + # Return the response - formatted as a dictionary |
| 359 | + serialized_tracker_response = serialize_tracker_command_response( |
| 360 | + response=response.command_response |
| 361 | + ) |
| 362 | + return { |
| 363 | + "success": response.success, |
| 364 | + "created_bodies": [body.id for body in response.created_bodies], |
| 365 | + "tracker_response": serialized_tracker_response, |
| 366 | + } |
| 367 | + |
| 368 | + @protect_grpc |
| 369 | + def create_sphere_enclosure(self, **kwargs) -> dict: # noqa: D102 |
| 370 | + from ansys.api.geometry.v0.models_pb2 import Body as GRPCBody |
| 371 | + from ansys.api.geometry.v0.preparetools_pb2 import CreateEnclosureSphereRequest |
| 372 | + |
| 373 | + grpc_enclosure_options = from_enclosure_options_to_grpc_enclosure_options( |
| 374 | + kwargs["enclosure_options"] |
| 375 | + ) |
| 376 | + |
| 377 | + # Create the request - assumes all inputs are valid and of the proper type |
| 378 | + request = CreateEnclosureSphereRequest( |
| 379 | + bodies=[GRPCBody(id=body.id) for body in kwargs["bodies"]], |
| 380 | + radial_distance=from_measurement_to_server_length(kwargs["radial_distance"]), |
| 381 | + enclosure_options=grpc_enclosure_options, |
| 382 | + ) |
| 383 | + |
| 384 | + # Call the gRPC service |
| 385 | + response = self.stub.CreateEnclosureSphere(request) |
| 386 | + |
| 387 | + # Return the response - formatted as a dictionary |
| 388 | + serialized_tracker_response = serialize_tracker_command_response( |
| 389 | + response=response.command_response |
| 390 | + ) |
| 391 | + return { |
| 392 | + "success": response.success, |
| 393 | + "created_bodies": [body.id for body in response.created_bodies], |
| 394 | + "tracker_response": serialized_tracker_response, |
| 395 | + } |
0 commit comments