Skip to content

Commit 31fe126

Browse files
b-matteopre-commit-ci[bot]pyansys-ci-bot
authored
chore: v1 Implementation of driving dimensions stub (#2446)
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: pyansys-ci-bot <[email protected]>
1 parent fa5a148 commit 31fe126

File tree

3 files changed

+50
-6
lines changed

3 files changed

+50
-6
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Chore: v1 Implementation of driving dimensions stub

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1188,7 +1188,7 @@ def from_grpc_driving_dimension_to_driving_dimension(
11881188
id=driving_dimension.id,
11891189
name=driving_dimension.name,
11901190
dimension_type=ParameterType(driving_dimension.dimension_type),
1191-
dimension_value=driving_dimension.dimension_value,
1191+
dimension_value=driving_dimension.dimension_value.value_in_geometry_units,
11921192
)
11931193

11941194

@@ -1211,7 +1211,7 @@ def from_driving_dimension_to_grpc_driving_dimension(
12111211
id=driving_dimension.id,
12121212
name=driving_dimension.name,
12131213
dimension_type=driving_dimension.dimension_type.value,
1214-
dimension_value=driving_dimension.dimension_value,
1214+
dimension_value=from_length_to_grpc_quantity(driving_dimension.dimension_value),
12151215
)
12161216

12171217

src/ansys/geometry/core/_grpc/_services/v1/driving_dimensions.py

Lines changed: 47 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,12 @@
2626
from ansys.geometry.core.errors import protect_grpc
2727

2828
from ..base.driving_dimensions import GRPCDrivingDimensionsService
29+
from .conversions import (
30+
build_grpc_id,
31+
from_driving_dimension_to_grpc_driving_dimension,
32+
from_grpc_driving_dimension_to_driving_dimension,
33+
from_grpc_update_status_to_parameter_update_status,
34+
)
2935

3036

3137
class GRPCDrivingDimensionsServiceV1(GRPCDrivingDimensionsService): # pragma: no cover
@@ -43,14 +49,51 @@ class GRPCDrivingDimensionsServiceV1(GRPCDrivingDimensionsService): # pragma: n
4349

4450
@protect_grpc
4551
def __init__(self, channel: grpc.Channel): # noqa: D102
46-
from ansys.api.geometry.v1.drivingdimensions_pb2_grpc import DrivingDimensionsStub
52+
from ansys.api.discovery.v1.design.parameters.drivingdimension_pb2_grpc import (
53+
DrivingDimensionStub,
54+
)
4755

48-
self.stub = DrivingDimensionsStub(channel)
56+
self.stub = DrivingDimensionStub(channel)
4957

5058
@protect_grpc
5159
def get_all_parameters(self, **kwargs) -> dict: # noqa: D102
52-
raise NotImplementedError
60+
from ansys.api.discovery.v1.commonmessages_pb2 import EntityIdentifier, ParentEntityRequest
61+
62+
# Call the gRPC service
63+
req = ParentEntityRequest(parent_id=EntityIdentifier())
64+
if "parent_id" in kwargs:
65+
req.parent_id = build_grpc_id(kwargs["parent_id"])
66+
67+
response = self.stub.GetAll(req)
68+
69+
# Return the response - formatted as a dictionary
70+
return {
71+
"parameters": [
72+
from_grpc_driving_dimension_to_driving_dimension(param)
73+
for param in response.driving_dimensions
74+
],
75+
"success": response.command_response.success,
76+
}
5377

5478
@protect_grpc
5579
def set_parameter(self, **kwargs) -> dict: # noqa: D102
56-
raise NotImplementedError
80+
from ansys.api.discovery.v1.design.parameters.drivingdimension_pb2 import (
81+
SetDrivingDimensionRequest,
82+
)
83+
84+
# Create the request - assumes all inputs are valid and of the proper type
85+
request = SetDrivingDimensionRequest(
86+
request_data=[
87+
from_driving_dimension_to_grpc_driving_dimension(kwargs["driving_dimension"])
88+
]
89+
)
90+
91+
# Call the gRPC service
92+
response = self.stub.Set(request)
93+
94+
# Return the response - formatted as a dictionary
95+
return {
96+
"status": from_grpc_update_status_to_parameter_update_status(
97+
response.response_data[0].status
98+
),
99+
}

0 commit comments

Comments
 (0)