diff --git a/doc/changelog.d/2432.maintenance.md b/doc/changelog.d/2432.maintenance.md new file mode 100644 index 0000000000..ad59719750 --- /dev/null +++ b/doc/changelog.d/2432.maintenance.md @@ -0,0 +1 @@ +V1 implementation of parts and commands stubs diff --git a/src/ansys/geometry/core/_grpc/_services/v1/commands.py b/src/ansys/geometry/core/_grpc/_services/v1/commands.py index 763cdbf73b..2898d86fdb 100644 --- a/src/ansys/geometry/core/_grpc/_services/v1/commands.py +++ b/src/ansys/geometry/core/_grpc/_services/v1/commands.py @@ -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): @@ -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"]), + } diff --git a/src/ansys/geometry/core/_grpc/_services/v1/conversions.py b/src/ansys/geometry/core/_grpc/_services/v1/conversions.py index cab99e64bb..d1fc9aab69 100644 --- a/src/ansys/geometry/core/_grpc/_services/v1/conversions.py +++ b/src/ansys/geometry/core/_grpc/_services/v1/conversions.py @@ -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, @@ -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 @@ -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. diff --git a/src/ansys/geometry/core/_grpc/_services/v1/parts.py b/src/ansys/geometry/core/_grpc/_services/v1/parts.py index 2105272b11..ce50e21ecd 100644 --- a/src/ansys/geometry/core/_grpc/_services/v1/parts.py +++ b/src/ansys/geometry/core/_grpc/_services/v1/parts.py @@ -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, + }