Skip to content

Commit bd47714

Browse files
jacobrkerstetterpre-commit-ci[bot]pyansys-ci-botRobPasMue
authored
feat: grpc driving dimensions stub implementation (#1921)
Co-authored-by: Jacob Kerstetter <[email protected]> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: pyansys-ci-bot <[email protected]> Co-authored-by: Roberto Pastor Muela <[email protected]>
1 parent 4630424 commit bd47714

File tree

8 files changed

+313
-87
lines changed

8 files changed

+313
-87
lines changed

doc/changelog.d/1921.added.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
grpc driving dimensions stub implementation

src/ansys/geometry/core/_grpc/_services/_service.py

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
from .base.admin import GRPCAdminService
2727
from .base.bodies import GRPCBodyService
2828
from .base.dbuapplication import GRPCDbuApplicationService
29+
from .base.driving_dimensions import GRPCDrivingDimensionsService
2930
from .base.measurement_tools import GRPCMeasurementToolsService
3031
from .base.named_selection import GRPCNamedSelectionService
3132
from .base.prepare_tools import GRPCPrepareToolsService
@@ -75,6 +76,7 @@ def __init__(self, channel: grpc.Channel, version: GeometryApiProtos | str | Non
7576
self._named_selection = None
7677
self._measurement_tools = None
7778
self._prepare_tools = None
79+
self._driving_dimensions = None
7880

7981
@property
8082
def bodies(self) -> GRPCBodyService:
@@ -213,7 +215,7 @@ def prepare_tools(self) -> GRPCPrepareToolsService:
213215
214216
Returns
215217
-------
216-
NamedSelectionServiceBase
218+
PrepareToolsServiceBase
217219
The prepare tools service for the specified version.
218220
"""
219221
if not self._prepare_tools:
@@ -231,3 +233,29 @@ def prepare_tools(self) -> GRPCPrepareToolsService:
231233
raise ValueError(f"Unsupported version: {self.version}")
232234

233235
return self._prepare_tools
236+
237+
@property
238+
def driving_dimensions(self) -> GRPCDrivingDimensionsService:
239+
"""
240+
Get the driving dimensions service for the specified version.
241+
242+
Returns
243+
-------
244+
DrivingDimensionsServiceBase
245+
The driving dimensions service for the specified version.
246+
"""
247+
if not self._driving_dimensions:
248+
# Import the appropriate driving dimensions service based on the version
249+
from .v0.driving_dimensions import GRPCDrivingDimensionsServiceV0
250+
from .v1.driving_dimensions import GRPCDrivingDimensionsServiceV1
251+
252+
if self.version == GeometryApiProtos.V0:
253+
self._driving_dimensions = GRPCDrivingDimensionsServiceV0(self.channel)
254+
elif self.version == GeometryApiProtos.V1: # pragma: no cover
255+
# V1 is not implemented yet
256+
self._driving_dimensions = GRPCDrivingDimensionsServiceV1(self.channel)
257+
else: # pragma: no cover
258+
# This should never happen as the version is set in the constructor
259+
raise ValueError(f"Unsupported version: {self.version}")
260+
261+
return self._driving_dimensions
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# Copyright (C) 2023 - 2025 ANSYS, Inc. and/or its affiliates.
2+
# SPDX-License-Identifier: MIT
3+
#
4+
#
5+
# Permission is hereby granted, free of charge, to any person obtaining a copy
6+
# of this software and associated documentation files (the "Software"), to deal
7+
# in the Software without restriction, including without limitation the rights
8+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
# copies of the Software, and to permit persons to whom the Software is
10+
# furnished to do so, subject to the following conditions:
11+
#
12+
# The above copyright notice and this permission notice shall be included in all
13+
# copies or substantial portions of the Software.
14+
#
15+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
# SOFTWARE.
22+
"""Module containing the Driving Dimension service implementation (abstraction layer)."""
23+
24+
from abc import ABC, abstractmethod
25+
26+
import grpc
27+
28+
29+
class GRPCDrivingDimensionsService(ABC):
30+
"""Driving Dimension service for gRPC communication with the Geometry server.
31+
32+
Parameters
33+
----------
34+
channel : grpc.Channel
35+
The gRPC channel to the server.
36+
"""
37+
38+
def __init__(self, channel: grpc.Channel):
39+
"""Initialize the DrivingDimensionsServiceBase class."""
40+
pass # pragma: no cover
41+
42+
@abstractmethod
43+
def get_all_parameters(self, **kwargs) -> dict:
44+
"""Get driving dimensions."""
45+
pass # pragma: no cover
46+
47+
@abstractmethod
48+
def set_parameter(self, **kwargs) -> dict:
49+
"""Set driving dimensions."""
50+
pass # pragma: no cover

src/ansys/geometry/core/_grpc/_services/v0/conversions.py

Lines changed: 82 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,11 @@
2626
import pint
2727

2828
from ansys.api.dbu.v0.admin_pb2 import BackendType as GRPCBackendType
29-
from ansys.api.dbu.v0.dbumodels_pb2 import EntityIdentifier
29+
from ansys.api.dbu.v0.dbumodels_pb2 import (
30+
DrivingDimension as GRPCDrivingDimension,
31+
EntityIdentifier,
32+
)
33+
from ansys.api.dbu.v0.drivingdimensions_pb2 import UpdateStatus as GRPCUpdateStatus
3034
from ansys.api.geometry.v0.models_pb2 import (
3135
Arc as GRPCArc,
3236
Circle as GRPCCircle,
@@ -61,6 +65,10 @@
6165
from ansys.geometry.core.math.point import Point2D, Point3D
6266
from ansys.geometry.core.math.vector import UnitVector3D
6367
from ansys.geometry.core.misc.options import TessellationOptions
68+
from ansys.geometry.core.parameters.parameter import (
69+
Parameter,
70+
ParameterUpdateStatus,
71+
)
6472
from ansys.geometry.core.shapes.curves.curve import Curve
6573
from ansys.geometry.core.shapes.curves.trimmed_curve import TrimmedCurve
6674
from ansys.geometry.core.shapes.surfaces.surface import Surface
@@ -723,3 +731,76 @@ def from_grpc_backend_type_to_backend_type(
723731
raise ValueError(f"Invalid backend type: {grpc_backend_type}")
724732

725733
return backend_type
734+
735+
736+
def from_grpc_driving_dimension_to_driving_dimension(
737+
driving_dimension: GRPCDrivingDimension,
738+
) -> "Parameter":
739+
"""Convert a gRPC driving dimension to a driving dimension object.
740+
741+
Parameters
742+
----------
743+
driving_dimension : GRPCDrivingDimension
744+
Source driving dimension type.
745+
746+
Returns
747+
-------
748+
Parameter
749+
Converted driving dimension.
750+
"""
751+
from ansys.geometry.core.parameters.parameter import Parameter, ParameterType
752+
753+
return Parameter(
754+
id=driving_dimension.id,
755+
name=driving_dimension.name,
756+
dimension_type=ParameterType(driving_dimension.dimension_type),
757+
dimension_value=driving_dimension.dimension_value,
758+
)
759+
760+
761+
def from_driving_dimension_to_grpc_driving_dimension(
762+
driving_dimension: "Parameter",
763+
) -> GRPCDrivingDimension:
764+
"""Convert a driving dimension object to a gRPC driving dimension.
765+
766+
Parameters
767+
----------
768+
driving_dimension : Parameter
769+
Source driving dimension type.
770+
771+
Returns
772+
-------
773+
GRPCDrivingDimension
774+
Converted driving dimension.
775+
"""
776+
return GRPCDrivingDimension(
777+
id=driving_dimension.id,
778+
name=driving_dimension.name,
779+
dimension_type=driving_dimension.dimension_type.value,
780+
dimension_value=driving_dimension.dimension_value,
781+
)
782+
783+
784+
def from_grpc_update_status_to_parameter_update_status(
785+
update_status: GRPCUpdateStatus,
786+
) -> "ParameterUpdateStatus":
787+
"""Convert a gRPC update status to a parameter update status.
788+
789+
Parameters
790+
----------
791+
update_status : GRPCUpdateStatus
792+
Source update status.
793+
794+
Returns
795+
-------
796+
ParameterUpdateStatus
797+
Converted update status.
798+
"""
799+
from ansys.geometry.core.parameters.parameter import ParameterUpdateStatus
800+
801+
status_mapping = {
802+
GRPCUpdateStatus.SUCCESS: ParameterUpdateStatus.SUCCESS,
803+
GRPCUpdateStatus.FAILURE: ParameterUpdateStatus.FAILURE,
804+
GRPCUpdateStatus.CONSTRAINED_PARAMETERS: ParameterUpdateStatus.CONSTRAINED_PARAMETERS,
805+
}
806+
return status_mapping.get(update_status, ParameterUpdateStatus.UNKNOWN)
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
# Copyright (C) 2023 - 2025 ANSYS, Inc. and/or its affiliates.
2+
# SPDX-License-Identifier: MIT
3+
#
4+
#
5+
# Permission is hereby granted, free of charge, to any person obtaining a copy
6+
# of this software and associated documentation files (the "Software"), to deal
7+
# in the Software without restriction, including without limitation the rights
8+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
# copies of the Software, and to permit persons to whom the Software is
10+
# furnished to do so, subject to the following conditions:
11+
#
12+
# The above copyright notice and this permission notice shall be included in all
13+
# copies or substantial portions of the Software.
14+
#
15+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
# SOFTWARE.
22+
"""Module containing the Driving Dimension service implementation for v0."""
23+
24+
import grpc
25+
26+
from ansys.geometry.core.errors import protect_grpc
27+
28+
from ..base.driving_dimensions import GRPCDrivingDimensionsService
29+
30+
31+
class GRPCDrivingDimensionsServiceV0(GRPCDrivingDimensionsService):
32+
"""Driving Dimension service for gRPC communication with the Geometry server.
33+
34+
This class provides methods to interact with the Geometry server's
35+
driving dimension service. It is specifically designed for the v0 version of the
36+
Geometry API.
37+
38+
Parameters
39+
----------
40+
channel : grpc.Channel
41+
The gRPC channel to the server.
42+
"""
43+
44+
@protect_grpc
45+
def __init__(self, channel: grpc.Channel): # noqa: D102
46+
from ansys.api.dbu.v0.drivingdimensions_pb2_grpc import DrivingDimensionsStub
47+
48+
self.stub = DrivingDimensionsStub(channel)
49+
50+
@protect_grpc
51+
def get_all_parameters(self, **kwargs) -> dict: # noqa: D102
52+
from ansys.api.dbu.v0.drivingdimensions_pb2 import GetAllRequest
53+
54+
from .conversions import from_grpc_driving_dimension_to_driving_dimension
55+
56+
# Call the gRPC service
57+
response = self.stub.GetAll(GetAllRequest())
58+
59+
# Return the response - formatted as a dictionary
60+
return {
61+
"parameters": [
62+
from_grpc_driving_dimension_to_driving_dimension(param)
63+
for param in response.driving_dimensions
64+
],
65+
}
66+
67+
@protect_grpc
68+
def set_parameter(self, **kwargs) -> dict: # noqa: D102
69+
from ansys.api.dbu.v0.drivingdimensions_pb2 import UpdateRequest
70+
71+
from .conversions import (
72+
from_driving_dimension_to_grpc_driving_dimension,
73+
from_grpc_update_status_to_parameter_update_status,
74+
)
75+
76+
# Create the request - assumes all inputs are valid and of the proper type
77+
request = UpdateRequest(
78+
driving_dimension=from_driving_dimension_to_grpc_driving_dimension(
79+
kwargs["driving_dimension"]
80+
),
81+
)
82+
83+
# Call the gRPC service
84+
response = self.stub.UpdateParameter(request)
85+
86+
# Return the response - formatted as a dictionary
87+
return {
88+
"status": from_grpc_update_status_to_parameter_update_status(response.status),
89+
}
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
# Copyright (C) 2023 - 2025 ANSYS, Inc. and/or its affiliates.
2+
# SPDX-License-Identifier: MIT
3+
#
4+
#
5+
# Permission is hereby granted, free of charge, to any person obtaining a copy
6+
# of this software and associated documentation files (the "Software"), to deal
7+
# in the Software without restriction, including without limitation the rights
8+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
# copies of the Software, and to permit persons to whom the Software is
10+
# furnished to do so, subject to the following conditions:
11+
#
12+
# The above copyright notice and this permission notice shall be included in all
13+
# copies or substantial portions of the Software.
14+
#
15+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
# SOFTWARE.
22+
"""Module containing the Driving Dimension service implementation for v1."""
23+
24+
import grpc
25+
26+
from ansys.geometry.core.errors import protect_grpc
27+
28+
from ..base.driving_dimensions import GRPCDrivingDimensionsService
29+
30+
31+
class GRPCDrivingDimensionsServiceV1(GRPCDrivingDimensionsService):
32+
"""Driving Dimensions service for gRPC communication with the Geometry server.
33+
34+
This class provides methods to interact with the Geometry server's
35+
Driving Dimensions service. It is specifically designed for the v1 version
36+
of the Geometry API.
37+
38+
Parameters
39+
----------
40+
channel : grpc.Channel
41+
The gRPC channel to the server.
42+
"""
43+
44+
@protect_grpc
45+
def __init__(self, channel: grpc.Channel): # noqa: D102
46+
from ansys.api.geometry.v1.drivingdimensions_pb2_grpc import DrivingDimensionsStub
47+
48+
self.stub = DrivingDimensionsStub(channel)
49+
50+
@protect_grpc
51+
def get_all_parameters(self, **kwargs) -> dict: # noqa: D102
52+
raise NotImplementedError
53+
54+
@protect_grpc
55+
def set_parameter(self, **kwargs) -> dict: # noqa: D102
56+
raise NotImplementedError

0 commit comments

Comments
 (0)