diff --git a/doc/changelog.d/2433.maintenance.md b/doc/changelog.d/2433.maintenance.md new file mode 100644 index 0000000000..e0c120c6de --- /dev/null +++ b/doc/changelog.d/2433.maintenance.md @@ -0,0 +1 @@ +V1 implementation of named selections stub diff --git a/src/ansys/geometry/core/_grpc/_services/v1/named_selection.py b/src/ansys/geometry/core/_grpc/_services/v1/named_selection.py index 200c24c356..540e13ad8d 100644 --- a/src/ansys/geometry/core/_grpc/_services/v1/named_selection.py +++ b/src/ansys/geometry/core/_grpc/_services/v1/named_selection.py @@ -26,6 +26,7 @@ from ansys.geometry.core.errors import protect_grpc from ..base.named_selection import GRPCNamedSelectionService +from .conversions import build_grpc_id class GRPCNamedSelectionServiceV1(GRPCNamedSelectionService): # pragma: no cover @@ -43,22 +44,100 @@ class GRPCNamedSelectionServiceV1(GRPCNamedSelectionService): # pragma: no cove @protect_grpc def __init__(self, channel: grpc.Channel): # noqa: D102 - from ansys.api.geometry.v1.namedselections_pb2_grpc import NamedSelectionsStub + from ansys.api.discovery.v1.design.selections.namedselection_pb2_grpc import ( + NamedSelectionStub, + ) - self.stub = NamedSelectionsStub(channel) + self.stub = NamedSelectionStub(channel) @protect_grpc def get_named_selection(self, **kwargs): # noqa: D102 - raise NotImplementedError + from ansys.api.discovery.v1.commonmessages_pb2 import EntityRequest + + # Create the request - assumes all inputs are valid and of the proper type + request = EntityRequest(id=build_grpc_id(kwargs["id"])) + + # Call the gRPC service + response = self.stub.Get(request).named_selection + + # Return the response - formatted as a dictionary + return { + "id": response.id.id, + "name": response.name, + "bodies": [body.id.id for body in response.bodies], + "faces": [face.id.id for face in response.faces], + "edges": [edge.id.id for edge in response.edges], + "beams": [beam.id.id for beam in response.beams], + "design_points": [dp.id.id for dp in response.design_points], + "components": [comp.id.id for comp in response.components], + "vertices": [vertex.id.id for vertex in response.vertices], + } @protect_grpc def create_named_selection(self, **kwargs): # noqa: D102 - raise NotImplementedError + from ansys.api.discovery.v1.design.selections.namedselection_pb2 import ( + CreateRequest, + CreateRequestData, + ) + + # Create the request - assumes all inputs are valid and of the proper type + request = CreateRequest( + request_data=[ + CreateRequestData( + name=kwargs["name"], + members_ids=[build_grpc_id(id) for id in kwargs["members"]], + ) + ] + ) + + # Call the gRPC service + response = self.stub.Create(request).named_selections[0] + + # Return the response - formatted as a dictionary + return { + "id": response.id.id, + "name": response.name, + "bodies": [body.id.id for body in response.bodies], + "faces": [face.id.id for face in response.faces], + "edges": [edge.id.id for edge in response.edges], + "beams": [beam.id.id for beam in response.beams], + "design_points": [dp.id.id for dp in response.design_points], + "components": [comp.id.id for comp in response.components], + "vertices": [vertex.id.id for vertex in response.vertices], + } @protect_grpc def delete_named_selection(self, **kwargs): # noqa: D102 - raise NotImplementedError + from ansys.api.discovery.v1.commonmessages_pb2 import MultipleEntitiesRequest + + # Create the request - assumes all inputs are valid and of the proper type + request = MultipleEntitiesRequest(ids=[build_grpc_id(kwargs["id"])]) + + # Call the gRPC service + self.stub.Delete(request) + + # Return the response - empty dictionary + return {} @protect_grpc def rename_named_selection(self, **kwargs): # noqa: D102 - raise NotImplementedError + from ansys.api.discovery.v1.design.designmessages_pb2 import ( + SetDesignEntityNameRequest, + SetDesignEntityNameRequestData, + ) + + # Create the request - assumes all inputs are valid and of the proper type + request = SetDesignEntityNameRequest( + request_data=[ + SetDesignEntityNameRequestData( + id=build_grpc_id(kwargs["id"]), + name=kwargs["new_name"], + ) + ] + ) + + # Call the gRPC service + self.stub.SetName(request) + + # Return the response - empty dictionary + return {}