From 1f53705b3428380e7a1a8d16d40ed4e56d999e52 Mon Sep 17 00:00:00 2001 From: Jacob Kerstetter Date: Thu, 17 Apr 2025 14:01:46 -0400 Subject: [PATCH 1/9] migrated driving dimensions stub to new location adjusted usages to call stub --- .../geometry/core/_grpc/_services/_service.py | 31 ++++++- .../_services/base/driving_dimensions.py | 50 +++++++++++ .../core/_grpc/_services/v0/conversions.py | 76 ++++++++++++++++- .../_grpc/_services/v0/driving_dimensions.py | 85 +++++++++++++++++++ .../_grpc/_services/v1/driving_dimensions.py | 56 ++++++++++++ src/ansys/geometry/core/designer/design.py | 17 ++-- .../geometry/core/parameters/parameter.py | 74 ---------------- 7 files changed, 303 insertions(+), 86 deletions(-) create mode 100644 src/ansys/geometry/core/_grpc/_services/base/driving_dimensions.py create mode 100644 src/ansys/geometry/core/_grpc/_services/v0/driving_dimensions.py create mode 100644 src/ansys/geometry/core/_grpc/_services/v1/driving_dimensions.py diff --git a/src/ansys/geometry/core/_grpc/_services/_service.py b/src/ansys/geometry/core/_grpc/_services/_service.py index 13c81129d3..950854b6b7 100644 --- a/src/ansys/geometry/core/_grpc/_services/_service.py +++ b/src/ansys/geometry/core/_grpc/_services/_service.py @@ -22,6 +22,8 @@ import grpc +from ansys.geometry.core._grpc._services.base.driving_dimensions import GRPCDrivingDimensionsService + from .._version import GeometryApiProtos, set_proto_version from .base.admin import GRPCAdminService from .base.bodies import GRPCBodyService @@ -75,6 +77,7 @@ def __init__(self, channel: grpc.Channel, version: GeometryApiProtos | str | Non self._named_selection = None self._measurement_tools = None self._prepare_tools = None + self._driving_dimensions = None @property def bodies(self) -> GRPCBodyService: @@ -213,7 +216,7 @@ def prepare_tools(self) -> GRPCPrepareToolsService: Returns ------- - NamedSelectionServiceBase + PrepareToolsServiceBase The prepare tools service for the specified version. """ if not self._prepare_tools: @@ -231,3 +234,29 @@ def prepare_tools(self) -> GRPCPrepareToolsService: raise ValueError(f"Unsupported version: {self.version}") return self._prepare_tools + + @property + def driving_dimensions(self) -> GRPCDrivingDimensionsService: + """ + Get the driving dimensions service for the specified version. + + Returns + ------- + DrivingDimensionsServiceBase + The driving dimensions service for the specified version. + """ + if not self._driving_dimensions: + # Import the appropriate driving dimensions service based on the version + from .v0.driving_dimensions import GRPCDrivingDimensionsServiceV0 + from .v1.driving_dimensions import GRPCDrivingDimensionsServiceV1 + + if self.version == GeometryApiProtos.V0: + self._driving_dimensions = GRPCDrivingDimensionsServiceV0(self.channel) + elif self.version == GeometryApiProtos.V1: # pragma: no cover + # V1 is not implemented yet + self._driving_dimensions = GRPCDrivingDimensionsServiceV1(self.channel) + else: # pragma: no cover + # This should never happen as the version is set in the constructor + raise ValueError(f"Unsupported version: {self.version}") + + return self._driving_dimensions \ No newline at end of file diff --git a/src/ansys/geometry/core/_grpc/_services/base/driving_dimensions.py b/src/ansys/geometry/core/_grpc/_services/base/driving_dimensions.py new file mode 100644 index 0000000000..f70671f330 --- /dev/null +++ b/src/ansys/geometry/core/_grpc/_services/base/driving_dimensions.py @@ -0,0 +1,50 @@ +# Copyright (C) 2023 - 2025 ANSYS, Inc. and/or its affiliates. +# SPDX-License-Identifier: MIT +# +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in all +# copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. +"""Module containing the Driving Dimension service implementation (abstraction layer).""" + +from abc import ABC, abstractmethod + +import grpc + + +class GRPCDrivingDimensionsService(ABC): + """Driving Dimension service for gRPC communication with the Geometry server. + + Parameters + ---------- + channel : grpc.Channel + The gRPC channel to the server. + """ + + def __init__(self, channel: grpc.Channel): + """Initialize the DrivingDimensionsServiceBase class.""" + pass # pragma: no cover + + @abstractmethod + def get_all_parameters(self, **kwargs) -> dict: + """Get driving dimensions.""" + pass # pragma: no cover + + @abstractmethod + def set_parameter(self, **kwargs) -> dict: + """Set driving dimensions.""" + pass # pragma: no cover \ No newline at end of file diff --git a/src/ansys/geometry/core/_grpc/_services/v0/conversions.py b/src/ansys/geometry/core/_grpc/_services/v0/conversions.py index b485b859a3..545487264b 100644 --- a/src/ansys/geometry/core/_grpc/_services/v0/conversions.py +++ b/src/ansys/geometry/core/_grpc/_services/v0/conversions.py @@ -26,7 +26,11 @@ import pint from ansys.api.dbu.v0.admin_pb2 import BackendType as GRPCBackendType -from ansys.api.dbu.v0.dbumodels_pb2 import EntityIdentifier +from ansys.api.dbu.v0.dbumodels_pb2 import ( + DrivingDimension as GRPCDrivingDimension, + EntityIdentifier, +) +from ansys.api.dbu.v0.drivingdimensions_pb2 import UpdateStatus as GRPCUpdateStatus from ansys.api.geometry.v0.models_pb2 import ( Arc as GRPCArc, Circle as GRPCCircle, @@ -49,6 +53,7 @@ TrimmedSurface as GRPCTrimmedSurface, ) from ansys.geometry.core.misc.checks import graphics_required +from ansys.geometry.core.parameters.parameter import Parameter, ParameterType, ParameterUpdateStatus if TYPE_CHECKING: # pragma: no cover import pyvista as pv @@ -723,3 +728,72 @@ def from_grpc_backend_type_to_backend_type( raise ValueError(f"Invalid backend type: {grpc_backend_type}") return backend_type + + +def from_grpc_driving_dimension_to_driving_dimension( + driving_dimension: GRPCDrivingDimension +) -> "Parameter": + """Convert a gRPC driving dimension to a driving dimension object. + + Parameters + ---------- + driving_dimension : GRPCDrivingDimension + Source driving dimension type. + + Returns + ------- + Parameter + Converted driving dimension. + """ + return Parameter( + id=driving_dimension.id, + name=driving_dimension.name, + dimension_type=ParameterType(driving_dimension.dimension_type), + dimension_value=driving_dimension.dimension_value, + ) + + +def from_driving_dimension_to_grpc_driving_dimension( + driving_dimension: "Parameter", +) -> GRPCDrivingDimension: + """Convert a driving dimension object to a gRPC driving dimension. + + Parameters + ---------- + driving_dimension : Parameter + Source driving dimension type. + + Returns + ------- + GRPCDrivingDimension + Converted driving dimension. + """ + return GRPCDrivingDimension( + id=driving_dimension.id, + name=driving_dimension.name, + dimension_type=driving_dimension.dimension_type.value, + dimension_value=driving_dimension.dimension_value, + ) + + +def from_grpc_update_status_to_parameter_update_status( + update_status: GRPCUpdateStatus, +) -> ParameterUpdateStatus: + """Convert a gRPC update status to a parameter update status. + + Parameters + ---------- + update_status : GRPCUpdateStatus + Source update status. + + Returns + ------- + ParameterUpdateStatus + Converted update status. + """ + status_mapping = { + GRPCUpdateStatus.SUCCESS: ParameterUpdateStatus.SUCCESS, + GRPCUpdateStatus.FAILURE: ParameterUpdateStatus.FAILURE, + GRPCUpdateStatus.CONSTRAINED_PARAMETERS: ParameterUpdateStatus.CONSTRAINED_PARAMETERS, + } + return status_mapping.get(update_status, ParameterUpdateStatus.UNKNOWN) \ No newline at end of file diff --git a/src/ansys/geometry/core/_grpc/_services/v0/driving_dimensions.py b/src/ansys/geometry/core/_grpc/_services/v0/driving_dimensions.py new file mode 100644 index 0000000000..8bb2eac19a --- /dev/null +++ b/src/ansys/geometry/core/_grpc/_services/v0/driving_dimensions.py @@ -0,0 +1,85 @@ +# Copyright (C) 2023 - 2025 ANSYS, Inc. and/or its affiliates. +# SPDX-License-Identifier: MIT +# +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in all +# copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. +"""Module containing the Driving Dimension service implementation for v0.""" + +import grpc + +from ansys.geometry.core.errors import protect_grpc + +from ..base.driving_dimensions import GRPCDrivingDimensionsService +from .conversions import ( + from_driving_dimension_to_grpc_driving_dimension, + from_grpc_driving_dimension_to_driving_dimension, + from_grpc_update_status_to_parameter_update_status, +) + + +class GRPCDrivingDimensionsServiceV0(GRPCDrivingDimensionsService): + """Driving Dimension service for gRPC communication with the Geometry server. + + This class provides methods to interact with the Geometry server's + driving dimension service. It is specifically designed for the v0 version of the + Geometry API. + + Parameters + ---------- + channel : grpc.Channel + The gRPC channel to the server. + """ + + @protect_grpc + def __init__(self, channel: grpc.Channel): # noqa: D102 + from ansys.api.dbu.v0.drivingdimensions_pb2_grpc import DrivingDimensionsStub + + self.stub = DrivingDimensionsStub(channel) + + @protect_grpc + def get_all_parameters(self, **kwargs) -> dict: # noqa: D102 + from ansys.api.dbu.v0.drivingdimensions_pb2 import GetAllRequest + + # Call the gRPC service + response = self.stub.GetAll(GetAllRequest()) + + # Return the response - formatted as a dictionary + return { + "parameters": [ + from_grpc_driving_dimension_to_driving_dimension(param) + for param in response.driving_dimensions + ], + } + + @protect_grpc + def set_parameter(self, **kwargs) -> dict: # noqa: D102 + from ansys.api.dbu.v0.drivingdimensions_pb2 import UpdateRequest + + # Create the request - assumes all inputs are valid and of the proper type + request = UpdateRequest( + driving_dimension=from_driving_dimension_to_grpc_driving_dimension(kwargs["driving_dimension"]), + ) + + # Call the gRPC service + response = self.stub.UpdateParameter(request) + + # Return the response - formatted as a dictionary + return { + "status": from_grpc_update_status_to_parameter_update_status(response.status), + } \ No newline at end of file diff --git a/src/ansys/geometry/core/_grpc/_services/v1/driving_dimensions.py b/src/ansys/geometry/core/_grpc/_services/v1/driving_dimensions.py new file mode 100644 index 0000000000..ec6d1ef14f --- /dev/null +++ b/src/ansys/geometry/core/_grpc/_services/v1/driving_dimensions.py @@ -0,0 +1,56 @@ +# Copyright (C) 2023 - 2025 ANSYS, Inc. and/or its affiliates. +# SPDX-License-Identifier: MIT +# +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in all +# copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. +"""Module containing the Driving Dimension service implementation for v1.""" + +import grpc + +from ansys.geometry.core.errors import protect_grpc + +from ..base.driving_dimensions import GRPCDrivingDimensionsService + + +class GRPCDrivingDimensionsServiceV1(GRPCDrivingDimensionsService): + """Driving Dimensions service for gRPC communication with the Geometry server. + + This class provides methods to interact with the Geometry server's + Driving Dimensions service. It is specifically designed for the v1 version + of the Geometry API. + + Parameters + ---------- + channel : grpc.Channel + The gRPC channel to the server. + """ + + @protect_grpc + def __init__(self, channel: grpc.Channel): # noqa: D102 + from ansys.api.geometry.v1.drivingdimensions_pb2_grpc import DrivingDimensionsStub + + self.stub = DrivingDimensionsStub(channel) + + @protect_grpc + def get_all_parameters(self, **kwargs) -> dict: # noqa: D102 + raise NotImplementedError + + @protect_grpc + def set_parameter(self, **kwargs) -> dict: # noqa: D102 + raise NotImplementedError \ No newline at end of file diff --git a/src/ansys/geometry/core/designer/design.py b/src/ansys/geometry/core/designer/design.py index fff6c489e4..82abb67c24 100644 --- a/src/ansys/geometry/core/designer/design.py +++ b/src/ansys/geometry/core/designer/design.py @@ -38,8 +38,6 @@ SaveAsRequest, ) from ansys.api.dbu.v0.designs_pb2_grpc import DesignsStub -from ansys.api.dbu.v0.drivingdimensions_pb2 import GetAllRequest, UpdateRequest -from ansys.api.dbu.v0.drivingdimensions_pb2_grpc import DrivingDimensionsStub from ansys.api.geometry.v0.commands_pb2 import ( AssignMidSurfaceOffsetTypeRequest, AssignMidSurfaceThicknessRequest, @@ -146,7 +144,6 @@ def __init__(self, name: str, modeler: Modeler, read_existing_design: bool = Fal self._commands_stub = CommandsStub(self._grpc_client.channel) self._materials_stub = MaterialsStub(self._grpc_client.channel) self._parts_stub = PartsStub(self._grpc_client.channel) - self._parameters_stub = DrivingDimensionsStub(self._grpc_client.channel) # Initialize needed instance variables self._materials = [] @@ -832,8 +829,8 @@ def get_all_parameters(self) -> list[Parameter]: list[Parameter] List of parameters for the design. """ - response = self._parameters_stub.GetAll(GetAllRequest()) - return [Parameter._from_proto(dimension) for dimension in response.driving_dimensions] + response = self._grpc_client._services.driving_dimensions.get_all_parameters() + return response.get("parameters") @protect_grpc @check_input_types @@ -851,15 +848,15 @@ def set_parameter(self, dimension: Parameter) -> ParameterUpdateStatus: ParameterUpdateStatus Status of the update operation. """ - request = UpdateRequest(driving_dimension=Parameter._to_proto(dimension)) - response = self._parameters_stub.UpdateParameter(request) - status = response.status + response = self._grpc_client._services.driving_dimensions.set_parameter( + driving_dimension=dimension + ) # Update the design in place. This method is computationally expensive, # consider finding a more efficient approach. self._update_design_inplace() - - return ParameterUpdateStatus._from_update_status(status) + + return response.get("status") @protect_grpc @check_input_types diff --git a/src/ansys/geometry/core/parameters/parameter.py b/src/ansys/geometry/core/parameters/parameter.py index 6ec223d0a7..2abcb5e3b5 100644 --- a/src/ansys/geometry/core/parameters/parameter.py +++ b/src/ansys/geometry/core/parameters/parameter.py @@ -23,8 +23,6 @@ from enum import Enum, unique -from ansys.api.dbu.v0.dbumodels_pb2 import DrivingDimension as GRPCDrivingDimension -from ansys.api.dbu.v0.drivingdimensions_pb2 import UpdateStatus as GRPCUpdateStatus from ansys.geometry.core.typing import Real @@ -54,32 +52,6 @@ class ParameterUpdateStatus(Enum): CONSTRAINED_PARAMETERS = 2 UNKNOWN = 3 - @staticmethod - def _from_update_status(status: GRPCUpdateStatus) -> "ParameterUpdateStatus": - """Convert GRPCUpdateStatus to ParameterUpdateStatus. - - Notes - ----- - This method is used to convert the status of the update from gRPC to the - parameter update status. Not to be used directly by the user. - - Parameters - ---------- - status : GRPCUpdateStatus - Status of the update. Coming from gRPC. - - Returns - ------- - ParameterUpdateStatus - Parameter update status. - """ - status_mapping = { - GRPCUpdateStatus.SUCCESS: ParameterUpdateStatus.SUCCESS, - GRPCUpdateStatus.FAILURE: ParameterUpdateStatus.FAILURE, - GRPCUpdateStatus.CONSTRAINED_PARAMETERS: ParameterUpdateStatus.CONSTRAINED_PARAMETERS, - } - return status_mapping.get(status, ParameterUpdateStatus.UNKNOWN) - class Parameter: """Represents a parameter. @@ -103,32 +75,6 @@ def __init__(self, id: int, name: str, dimension_type: ParameterType, dimension_ self._dimension_type = dimension_type self._dimension_value = dimension_value - @classmethod - def _from_proto(cls, proto: GRPCDrivingDimension) -> "Parameter": - """Create a ``Parameter`` instance from a ``proto`` object. - - Notes - ----- - This method is used to convert the parameter from gRPC to the parameter - object. Not to be used directly by the user. - - Parameters - ---------- - proto : GRPCDrivingDimension - Parameter object coming from gRPC. - - Returns - ------- - Parameter - Parameter object. - """ - return cls( - id=proto.id, - name=proto.name, - dimension_type=ParameterType(proto.dimension_type), - dimension_value=proto.dimension_value, - ) - @property def name(self) -> str: """Get the name of the parameter.""" @@ -158,23 +104,3 @@ def dimension_type(self) -> ParameterType: def dimension_type(self, value: ParameterType): """Set the type of the parameter.""" self._dimension_type = value - - def _to_proto(self): - """Convert a ``Parameter`` instance to a ``proto`` object. - - Notes - ----- - This method is used to convert the parameter from the parameter object to - gRPC. Not to be used directly by the user. - - Returns - ------- - GRPCDrivingDimension - Parameter object in gRPC. - """ - return GRPCDrivingDimension( - id=self.id, - name=self.name, - dimension_type=self.dimension_type.value, - dimension_value=self.dimension_value, - ) From 59998cca92cefbcb373da866358e2073a7f537fa Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 17 Apr 2025 18:05:13 +0000 Subject: [PATCH 2/9] chore: auto fixes from pre-commit hooks --- .../geometry/core/_grpc/_services/_service.py | 2 +- .../_grpc/_services/base/driving_dimensions.py | 2 +- .../core/_grpc/_services/v0/conversions.py | 14 +++++++------- .../core/_grpc/_services/v0/driving_dimensions.py | 8 +++++--- .../core/_grpc/_services/v1/driving_dimensions.py | 4 ++-- src/ansys/geometry/core/designer/design.py | 2 +- 6 files changed, 17 insertions(+), 15 deletions(-) diff --git a/src/ansys/geometry/core/_grpc/_services/_service.py b/src/ansys/geometry/core/_grpc/_services/_service.py index 950854b6b7..469a5ab960 100644 --- a/src/ansys/geometry/core/_grpc/_services/_service.py +++ b/src/ansys/geometry/core/_grpc/_services/_service.py @@ -259,4 +259,4 @@ def driving_dimensions(self) -> GRPCDrivingDimensionsService: # This should never happen as the version is set in the constructor raise ValueError(f"Unsupported version: {self.version}") - return self._driving_dimensions \ No newline at end of file + return self._driving_dimensions diff --git a/src/ansys/geometry/core/_grpc/_services/base/driving_dimensions.py b/src/ansys/geometry/core/_grpc/_services/base/driving_dimensions.py index f70671f330..d00389f4b7 100644 --- a/src/ansys/geometry/core/_grpc/_services/base/driving_dimensions.py +++ b/src/ansys/geometry/core/_grpc/_services/base/driving_dimensions.py @@ -47,4 +47,4 @@ def get_all_parameters(self, **kwargs) -> dict: @abstractmethod def set_parameter(self, **kwargs) -> dict: """Set driving dimensions.""" - pass # pragma: no cover \ No newline at end of file + pass # pragma: no cover diff --git a/src/ansys/geometry/core/_grpc/_services/v0/conversions.py b/src/ansys/geometry/core/_grpc/_services/v0/conversions.py index 545487264b..484e72f823 100644 --- a/src/ansys/geometry/core/_grpc/_services/v0/conversions.py +++ b/src/ansys/geometry/core/_grpc/_services/v0/conversions.py @@ -731,7 +731,7 @@ def from_grpc_backend_type_to_backend_type( def from_grpc_driving_dimension_to_driving_dimension( - driving_dimension: GRPCDrivingDimension + driving_dimension: GRPCDrivingDimension, ) -> "Parameter": """Convert a gRPC driving dimension to a driving dimension object. @@ -777,7 +777,7 @@ def from_driving_dimension_to_grpc_driving_dimension( def from_grpc_update_status_to_parameter_update_status( - update_status: GRPCUpdateStatus, + update_status: GRPCUpdateStatus, ) -> ParameterUpdateStatus: """Convert a gRPC update status to a parameter update status. @@ -792,8 +792,8 @@ def from_grpc_update_status_to_parameter_update_status( Converted update status. """ status_mapping = { - GRPCUpdateStatus.SUCCESS: ParameterUpdateStatus.SUCCESS, - GRPCUpdateStatus.FAILURE: ParameterUpdateStatus.FAILURE, - GRPCUpdateStatus.CONSTRAINED_PARAMETERS: ParameterUpdateStatus.CONSTRAINED_PARAMETERS, - } - return status_mapping.get(update_status, ParameterUpdateStatus.UNKNOWN) \ No newline at end of file + GRPCUpdateStatus.SUCCESS: ParameterUpdateStatus.SUCCESS, + GRPCUpdateStatus.FAILURE: ParameterUpdateStatus.FAILURE, + GRPCUpdateStatus.CONSTRAINED_PARAMETERS: ParameterUpdateStatus.CONSTRAINED_PARAMETERS, + } + return status_mapping.get(update_status, ParameterUpdateStatus.UNKNOWN) diff --git a/src/ansys/geometry/core/_grpc/_services/v0/driving_dimensions.py b/src/ansys/geometry/core/_grpc/_services/v0/driving_dimensions.py index 8bb2eac19a..e423633ba7 100644 --- a/src/ansys/geometry/core/_grpc/_services/v0/driving_dimensions.py +++ b/src/ansys/geometry/core/_grpc/_services/v0/driving_dimensions.py @@ -62,7 +62,7 @@ def get_all_parameters(self, **kwargs) -> dict: # noqa: D102 # Return the response - formatted as a dictionary return { "parameters": [ - from_grpc_driving_dimension_to_driving_dimension(param) + from_grpc_driving_dimension_to_driving_dimension(param) for param in response.driving_dimensions ], } @@ -73,7 +73,9 @@ def set_parameter(self, **kwargs) -> dict: # noqa: D102 # Create the request - assumes all inputs are valid and of the proper type request = UpdateRequest( - driving_dimension=from_driving_dimension_to_grpc_driving_dimension(kwargs["driving_dimension"]), + driving_dimension=from_driving_dimension_to_grpc_driving_dimension( + kwargs["driving_dimension"] + ), ) # Call the gRPC service @@ -82,4 +84,4 @@ def set_parameter(self, **kwargs) -> dict: # noqa: D102 # Return the response - formatted as a dictionary return { "status": from_grpc_update_status_to_parameter_update_status(response.status), - } \ No newline at end of file + } diff --git a/src/ansys/geometry/core/_grpc/_services/v1/driving_dimensions.py b/src/ansys/geometry/core/_grpc/_services/v1/driving_dimensions.py index ec6d1ef14f..4d53c4fcdb 100644 --- a/src/ansys/geometry/core/_grpc/_services/v1/driving_dimensions.py +++ b/src/ansys/geometry/core/_grpc/_services/v1/driving_dimensions.py @@ -50,7 +50,7 @@ def __init__(self, channel: grpc.Channel): # noqa: D102 @protect_grpc def get_all_parameters(self, **kwargs) -> dict: # noqa: D102 raise NotImplementedError - + @protect_grpc def set_parameter(self, **kwargs) -> dict: # noqa: D102 - raise NotImplementedError \ No newline at end of file + raise NotImplementedError diff --git a/src/ansys/geometry/core/designer/design.py b/src/ansys/geometry/core/designer/design.py index 82abb67c24..a9286d502c 100644 --- a/src/ansys/geometry/core/designer/design.py +++ b/src/ansys/geometry/core/designer/design.py @@ -855,7 +855,7 @@ def set_parameter(self, dimension: Parameter) -> ParameterUpdateStatus: # Update the design in place. This method is computationally expensive, # consider finding a more efficient approach. self._update_design_inplace() - + return response.get("status") @protect_grpc From 1463df84f46100fe399b0f533e31ae2e43e78d3c Mon Sep 17 00:00:00 2001 From: pyansys-ci-bot <92810346+pyansys-ci-bot@users.noreply.github.com> Date: Thu, 17 Apr 2025 18:06:30 +0000 Subject: [PATCH 3/9] chore: adding changelog file 1921.added.md [dependabot-skip] --- doc/changelog.d/1921.added.md | 1 + 1 file changed, 1 insertion(+) create mode 100644 doc/changelog.d/1921.added.md diff --git a/doc/changelog.d/1921.added.md b/doc/changelog.d/1921.added.md new file mode 100644 index 0000000000..861b8cae3c --- /dev/null +++ b/doc/changelog.d/1921.added.md @@ -0,0 +1 @@ +grpc driving dimensions stub implementation \ No newline at end of file From 2426ff334004348bec7c20a9b3a9514267a5bc1a Mon Sep 17 00:00:00 2001 From: Jacob Kerstetter Date: Thu, 17 Apr 2025 15:07:02 -0400 Subject: [PATCH 4/9] remove unnecessary protect grpc decorators --- src/ansys/geometry/core/designer/design.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/ansys/geometry/core/designer/design.py b/src/ansys/geometry/core/designer/design.py index 82abb67c24..e84d012698 100644 --- a/src/ansys/geometry/core/designer/design.py +++ b/src/ansys/geometry/core/designer/design.py @@ -818,8 +818,7 @@ def add_beam_circular_profile( ) return self._beam_profiles[profile.name] - - @protect_grpc + @min_backend_version(25, 1, 0) def get_all_parameters(self) -> list[Parameter]: """Get parameters for the design. @@ -832,7 +831,6 @@ def get_all_parameters(self) -> list[Parameter]: response = self._grpc_client._services.driving_dimensions.get_all_parameters() return response.get("parameters") - @protect_grpc @check_input_types @min_backend_version(25, 1, 0) def set_parameter(self, dimension: Parameter) -> ParameterUpdateStatus: From 5f9b9d817f7ef86d9db22d0a105ed6dbc7a342b8 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 17 Apr 2025 19:08:56 +0000 Subject: [PATCH 5/9] chore: auto fixes from pre-commit hooks --- src/ansys/geometry/core/designer/design.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ansys/geometry/core/designer/design.py b/src/ansys/geometry/core/designer/design.py index 8275b34de2..f03d34d27f 100644 --- a/src/ansys/geometry/core/designer/design.py +++ b/src/ansys/geometry/core/designer/design.py @@ -818,7 +818,7 @@ def add_beam_circular_profile( ) return self._beam_profiles[profile.name] - + @min_backend_version(25, 1, 0) def get_all_parameters(self) -> list[Parameter]: """Get parameters for the design. From ae0c78178eebb7ece2ae73edf50c2d20dcaee495 Mon Sep 17 00:00:00 2001 From: Jacob Kerstetter Date: Wed, 23 Apr 2025 10:56:04 -0400 Subject: [PATCH 6/9] fixing comments on PR --- src/ansys/geometry/core/_grpc/_services/_service.py | 3 +-- .../geometry/core/_grpc/_services/v0/conversions.py | 6 +++++- .../core/_grpc/_services/v0/driving_dimensions.py | 12 +++++++----- 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/src/ansys/geometry/core/_grpc/_services/_service.py b/src/ansys/geometry/core/_grpc/_services/_service.py index ec748bdbb0..d1ac03727b 100644 --- a/src/ansys/geometry/core/_grpc/_services/_service.py +++ b/src/ansys/geometry/core/_grpc/_services/_service.py @@ -22,12 +22,11 @@ import grpc -from ansys.geometry.core._grpc._services.base.driving_dimensions import GRPCDrivingDimensionsService - from .._version import GeometryApiProtos, set_proto_version from .base.admin import GRPCAdminService from .base.bodies import GRPCBodyService from .base.dbuapplication import GRPCDbuApplicationService +from .base.driving_dimensions import GRPCDrivingDimensionsService from .base.measurement_tools import GRPCMeasurementToolsService from .base.named_selection import GRPCNamedSelectionService from .base.prepare_tools import GRPCPrepareToolsService diff --git a/src/ansys/geometry/core/_grpc/_services/v0/conversions.py b/src/ansys/geometry/core/_grpc/_services/v0/conversions.py index 484e72f823..20981b5ab1 100644 --- a/src/ansys/geometry/core/_grpc/_services/v0/conversions.py +++ b/src/ansys/geometry/core/_grpc/_services/v0/conversions.py @@ -53,7 +53,6 @@ TrimmedSurface as GRPCTrimmedSurface, ) from ansys.geometry.core.misc.checks import graphics_required -from ansys.geometry.core.parameters.parameter import Parameter, ParameterType, ParameterUpdateStatus if TYPE_CHECKING: # pragma: no cover import pyvista as pv @@ -66,6 +65,11 @@ from ansys.geometry.core.math.point import Point2D, Point3D from ansys.geometry.core.math.vector import UnitVector3D from ansys.geometry.core.misc.options import TessellationOptions + from ansys.geometry.core.parameters.parameter import ( + Parameter, + ParameterType, + ParameterUpdateStatus, + ) from ansys.geometry.core.shapes.curves.curve import Curve from ansys.geometry.core.shapes.curves.trimmed_curve import TrimmedCurve from ansys.geometry.core.shapes.surfaces.surface import Surface diff --git a/src/ansys/geometry/core/_grpc/_services/v0/driving_dimensions.py b/src/ansys/geometry/core/_grpc/_services/v0/driving_dimensions.py index e423633ba7..fad5e92891 100644 --- a/src/ansys/geometry/core/_grpc/_services/v0/driving_dimensions.py +++ b/src/ansys/geometry/core/_grpc/_services/v0/driving_dimensions.py @@ -26,11 +26,6 @@ from ansys.geometry.core.errors import protect_grpc from ..base.driving_dimensions import GRPCDrivingDimensionsService -from .conversions import ( - from_driving_dimension_to_grpc_driving_dimension, - from_grpc_driving_dimension_to_driving_dimension, - from_grpc_update_status_to_parameter_update_status, -) class GRPCDrivingDimensionsServiceV0(GRPCDrivingDimensionsService): @@ -56,6 +51,8 @@ def __init__(self, channel: grpc.Channel): # noqa: D102 def get_all_parameters(self, **kwargs) -> dict: # noqa: D102 from ansys.api.dbu.v0.drivingdimensions_pb2 import GetAllRequest + from .conversions import from_grpc_driving_dimension_to_driving_dimension + # Call the gRPC service response = self.stub.GetAll(GetAllRequest()) @@ -71,6 +68,11 @@ def get_all_parameters(self, **kwargs) -> dict: # noqa: D102 def set_parameter(self, **kwargs) -> dict: # noqa: D102 from ansys.api.dbu.v0.drivingdimensions_pb2 import UpdateRequest + from .conversions import ( + from_driving_dimension_to_grpc_driving_dimension, + from_grpc_update_status_to_parameter_update_status, + ) + # Create the request - assumes all inputs are valid and of the proper type request = UpdateRequest( driving_dimension=from_driving_dimension_to_grpc_driving_dimension( From 6064a38910805441d0498ad8863c9457106842ad Mon Sep 17 00:00:00 2001 From: Jacob Kerstetter Date: Wed, 23 Apr 2025 11:10:47 -0400 Subject: [PATCH 7/9] typechecking error fix --- src/ansys/geometry/core/_grpc/_services/v0/conversions.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ansys/geometry/core/_grpc/_services/v0/conversions.py b/src/ansys/geometry/core/_grpc/_services/v0/conversions.py index 20981b5ab1..8eb99e93d4 100644 --- a/src/ansys/geometry/core/_grpc/_services/v0/conversions.py +++ b/src/ansys/geometry/core/_grpc/_services/v0/conversions.py @@ -782,7 +782,7 @@ def from_driving_dimension_to_grpc_driving_dimension( def from_grpc_update_status_to_parameter_update_status( update_status: GRPCUpdateStatus, -) -> ParameterUpdateStatus: +) -> "ParameterUpdateStatus": """Convert a gRPC update status to a parameter update status. Parameters From 47ecb8f337e9fcc4fa5c31f2cbf1438086db1fa8 Mon Sep 17 00:00:00 2001 From: Roberto Pastor Muela <37798125+RobPasMue@users.noreply.github.com> Date: Wed, 23 Apr 2025 17:12:42 +0200 Subject: [PATCH 8/9] Apply suggestions from code review --- src/ansys/geometry/core/_grpc/_services/v0/conversions.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/ansys/geometry/core/_grpc/_services/v0/conversions.py b/src/ansys/geometry/core/_grpc/_services/v0/conversions.py index 8eb99e93d4..f9f5ddf0d1 100644 --- a/src/ansys/geometry/core/_grpc/_services/v0/conversions.py +++ b/src/ansys/geometry/core/_grpc/_services/v0/conversions.py @@ -749,6 +749,8 @@ def from_grpc_driving_dimension_to_driving_dimension( Parameter Converted driving dimension. """ + from ansys.geometry.core.parameters.parameter import Parameter, ParameterType + return Parameter( id=driving_dimension.id, name=driving_dimension.name, @@ -795,6 +797,8 @@ def from_grpc_update_status_to_parameter_update_status( ParameterUpdateStatus Converted update status. """ + from ansys.geometry.core.parameters.parameter import ParameterUpdateStatus + status_mapping = { GRPCUpdateStatus.SUCCESS: ParameterUpdateStatus.SUCCESS, GRPCUpdateStatus.FAILURE: ParameterUpdateStatus.FAILURE, From 298859c6cadebc74a2cd6985dc87d4372571fc90 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed, 23 Apr 2025 15:15:09 +0000 Subject: [PATCH 9/9] chore: auto fixes from pre-commit hooks --- src/ansys/geometry/core/_grpc/_services/v0/conversions.py | 1 - 1 file changed, 1 deletion(-) diff --git a/src/ansys/geometry/core/_grpc/_services/v0/conversions.py b/src/ansys/geometry/core/_grpc/_services/v0/conversions.py index f9f5ddf0d1..daeb01a97c 100644 --- a/src/ansys/geometry/core/_grpc/_services/v0/conversions.py +++ b/src/ansys/geometry/core/_grpc/_services/v0/conversions.py @@ -67,7 +67,6 @@ from ansys.geometry.core.misc.options import TessellationOptions from ansys.geometry.core.parameters.parameter import ( Parameter, - ParameterType, ParameterUpdateStatus, ) from ansys.geometry.core.shapes.curves.curve import Curve