Skip to content
1 change: 1 addition & 0 deletions doc/changelog.d/2432.maintenance.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
V1 implementation of parts and commands stubs
29 changes: 26 additions & 3 deletions src/ansys/geometry/core/_grpc/_services/v1/commands.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.commands import GRPCCommandsService
from .conversions import build_grpc_id


class GRPCCommandsServiceV1(GRPCCommandsService):
Expand All @@ -43,10 +44,32 @@ class GRPCCommandsServiceV1(GRPCCommandsService):

@protect_grpc
def __init__(self, channel: grpc.Channel): # noqa: D102
from ansys.api.geometry.v1.commands_pb2_grpc import CommandsStub
from ansys.api.discovery.v1.design.designentity_pb2_grpc import DesignEntityStub

self.stub = CommandsStub(channel)
self.stub = DesignEntityStub(channel)

@protect_grpc
def set_name(self, **kwargs) -> dict: # 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(id),
name=kwargs["name"],
)
for id in kwargs["selection_ids"]
]
)

# Call the gRPC service
result = self.stub.SetName(request)

# Return the result - formatted as a dictionary
return {
"success": len(result.successfully_set_ids) == len(kwargs["selection_ids"]),
}
45 changes: 44 additions & 1 deletion src/ansys/geometry/core/_grpc/_services/v1/conversions.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@

from typing import TYPE_CHECKING

from ansys.api.discovery.v1.commonenums_pb2 import BackendType as GRPCBackendType
from ansys.api.discovery.v1.commonenums_pb2 import (
BackendType as GRPCBackendType,
FileFormat as GRPCFileFormat,
)
from ansys.api.discovery.v1.commonmessages_pb2 import (
Arc as GRPCArc,
Circle as GRPCCircle,
Expand Down Expand Up @@ -76,6 +79,7 @@
import semver

from ansys.geometry.core.connection.backend import BackendType
from ansys.geometry.core.designer.design import DesignFileFormat
from ansys.geometry.core.designer.face import SurfaceType
from ansys.geometry.core.materials.material import Material
from ansys.geometry.core.materials.property import MaterialProperty
Expand Down Expand Up @@ -1412,6 +1416,45 @@ def from_enclosure_options_to_grpc_enclosure_options(
)


def from_design_file_format_to_grpc_file_format(
design_file_format: "DesignFileFormat",
) -> GRPCFileFormat:
"""Convert from a ``DesignFileFormat`` object to a gRPC file format.

Parameters
----------
design_file_format : DesignFileFormat
The file format desired

Returns
-------
GRPCFileFormat
Converted gRPC FileFormat.
"""
from ansys.geometry.core.designer.design import DesignFileFormat

if design_file_format == DesignFileFormat.SCDOCX:
return GRPCFileFormat.FILEFORMAT_SCDOCX
elif design_file_format == DesignFileFormat.PARASOLID_TEXT:
return GRPCFileFormat.FILEFORMAT_PARASOLID_TEXT
elif design_file_format == DesignFileFormat.PARASOLID_BIN:
return GRPCFileFormat.FILEFORMAT_PARASOLID_BINARY
elif design_file_format == DesignFileFormat.FMD:
return GRPCFileFormat.FILEFORMAT_FMD
elif design_file_format == DesignFileFormat.STEP:
return GRPCFileFormat.FILEFORMAT_STEP
elif design_file_format == DesignFileFormat.IGES:
return GRPCFileFormat.FILEFORMAT_IGES
elif design_file_format == DesignFileFormat.PMDB:
return GRPCFileFormat.FILEFORMAT_PMDB
elif design_file_format == DesignFileFormat.STRIDE:
return GRPCFileFormat.FILEFORMAT_STRIDE
elif design_file_format == DesignFileFormat.DISCO:
return GRPCFileFormat.FILEFORMAT_DISCO
else:
return None


def serialize_tracked_command_response(response: GRPCTrackedCommandResponse) -> dict:
"""Serialize a TrackedCommandResponse object into a dictionary.

Expand Down
22 changes: 19 additions & 3 deletions src/ansys/geometry/core/_grpc/_services/v1/parts.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,26 @@ class GRPCPartsServiceV1(GRPCPartsService): # pragma: no cover

@protect_grpc
def __init__(self, channel: grpc.Channel): # noqa: D102
from ansys.api.geometry.v1.parts_pb2_grpc import PartsStub
from ansys.api.discovery.v1.commands.file_pb2_grpc import FileStub

self.stub = PartsStub(channel)
self.stub = FileStub(channel)

@protect_grpc
def export(self, **kwargs) -> dict: # noqa: D102
raise NotImplementedError
from ansys.api.discovery.v1.commands.file_pb2 import SaveRequest

from .conversions import from_design_file_format_to_grpc_file_format

# Create the request - assumes all inputs are valid and of the proper type
request = SaveRequest(format=from_design_file_format_to_grpc_file_format(kwargs["format"]))

# Call the gRPC service
response_stream = self.stub.Save(request)

# Return the response - formatted as a dictionary
data = bytes()
for response in response_stream:
data += response.data
return {
"data": data,
}
Loading