Skip to content
Merged
Show file tree
Hide file tree
Changes from 10 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/1921.added.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
grpc driving dimensions stub implementation
30 changes: 29 additions & 1 deletion src/ansys/geometry/core/_grpc/_services/_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
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
Expand Down Expand Up @@ -75,6 +76,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:
Expand Down Expand Up @@ -213,7 +215,7 @@ def prepare_tools(self) -> GRPCPrepareToolsService:

Returns
-------
NamedSelectionServiceBase
PrepareToolsServiceBase
The prepare tools service for the specified version.
"""
if not self._prepare_tools:
Expand All @@ -231,3 +233,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
Original file line number Diff line number Diff line change
@@ -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
80 changes: 79 additions & 1 deletion src/ansys/geometry/core/_grpc/_services/v0/conversions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -61,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
Expand Down Expand Up @@ -723,3 +732,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)
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
# 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


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

from .conversions import from_grpc_driving_dimension_to_driving_dimension

# 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

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(
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),
}
Original file line number Diff line number Diff line change
@@ -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
Loading
Loading