diff --git a/doc/changelog.d/2402.maintenance.md b/doc/changelog.d/2402.maintenance.md new file mode 100644 index 0000000000..835718f835 --- /dev/null +++ b/doc/changelog.d/2402.maintenance.md @@ -0,0 +1 @@ +V1 implementation of coordinate system stub diff --git a/src/ansys/geometry/core/_grpc/_services/v1/coordinate_systems.py b/src/ansys/geometry/core/_grpc/_services/v1/coordinate_systems.py index 193de7c26e..610e106950 100644 --- a/src/ansys/geometry/core/_grpc/_services/v1/coordinate_systems.py +++ b/src/ansys/geometry/core/_grpc/_services/v1/coordinate_systems.py @@ -26,6 +26,7 @@ from ansys.geometry.core.errors import protect_grpc from ..base.coordinate_systems import GRPCCoordinateSystemService +from .conversions import from_frame_to_grpc_frame, from_grpc_frame_to_frame class GRPCCoordinateSystemServiceV1(GRPCCoordinateSystemService): # pragma: no cover @@ -43,10 +44,38 @@ class GRPCCoordinateSystemServiceV1(GRPCCoordinateSystemService): # pragma: no @protect_grpc def __init__(self, channel: grpc.Channel): # noqa: D102 - from ansys.api.geometry.v1.coordinatesystems_pb2_grpc import CoordinateSystemsStub + from ansys.api.discovery.v1.design.constructs.coordinatesystem_pb2_grpc import ( + CoordinateSystemStub, + ) - self.stub = CoordinateSystemsStub(channel) + self.stub = CoordinateSystemStub(channel) @protect_grpc def create(self, **kwargs) -> dict: # noqa: D102 - raise NotImplementedError + from ansys.api.discovery.v1.design.constructs.coordinatesystem_pb2 import ( + CreateRequest, + CreateRequestData, + ) + + # Create the request data - assumes all inputs are valid and of the proper type + request = CreateRequest( + request_data=[ + CreateRequestData( + parent_id=kwargs["parent_id"], + name=kwargs["name"], + frame=from_frame_to_grpc_frame(kwargs["frame"]), + ) + ] + ) + + # Call the gRPC service + response = self.stub.Create(request=request) + + # Return the response - formatted as a dictionary + # Note: response.coordinate_systems is a repeated field, we return the first one + coord_system = response.coordinate_systems[0] + return { + "id": coord_system.id, + "name": coord_system.name, + "frame": from_grpc_frame_to_frame(coord_system.frame), + }