Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions doc/changelog.d/2433.maintenance.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
V1 implementation of named selections stub
91 changes: 85 additions & 6 deletions src/ansys/geometry/core/_grpc/_services/v1/named_selection.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 {}
Loading