Skip to content

Commit 145273f

Browse files
feat: move coordinate systems stub to grpc layer (#1943)
Co-authored-by: pyansys-ci-bot <92810346+pyansys-ci-bot@users.noreply.github.com>
1 parent 2d6153e commit 145273f

File tree

12 files changed

+260
-51
lines changed

12 files changed

+260
-51
lines changed

doc/changelog.d/1943.added.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
move coordinate systems stub to grpc layer

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

Lines changed: 35 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
from .._version import GeometryApiProtos, set_proto_version
2626
from .base.admin import GRPCAdminService
2727
from .base.bodies import GRPCBodyService
28+
from .base.coordinate_systems import GRPCCoordinateSystemService
2829
from .base.dbuapplication import GRPCDbuApplicationService
2930
from .base.driving_dimensions import GRPCDrivingDimensionsService
3031
from .base.measurement_tools import GRPCMeasurementToolsService
@@ -77,6 +78,7 @@ def __init__(self, channel: grpc.Channel, version: GeometryApiProtos | str | Non
7778
self._measurement_tools = None
7879
self._prepare_tools = None
7980
self._driving_dimensions = None
81+
self._coordinate_systems = None
8082

8183
@property
8284
def bodies(self) -> GRPCBodyService:
@@ -85,7 +87,7 @@ def bodies(self) -> GRPCBodyService:
8587
8688
Returns
8789
-------
88-
BodyServiceBase
90+
GRPCBodyService
8991
The body service for the specified version.
9092
"""
9193
if not self._bodies:
@@ -111,7 +113,7 @@ def admin(self) -> GRPCAdminService:
111113
112114
Returns
113115
-------
114-
AdminServiceBase
116+
GRPCAdminService
115117
The admin service for the specified version.
116118
"""
117119
if not self._admin:
@@ -137,7 +139,7 @@ def dbu_application(self) -> GRPCDbuApplicationService:
137139
138140
Returns
139141
-------
140-
DbuApplicationServiceBase
142+
GRPCDbuApplicationService
141143
The DBU application service for the specified version.
142144
"""
143145
if not self._dbu_application:
@@ -163,7 +165,7 @@ def named_selection(self) -> GRPCNamedSelectionService:
163165
164166
Returns
165167
-------
166-
NamedSelectionServiceBase
168+
GRPCNamedSelectionService
167169
The named selection service for the specified version.
168170
"""
169171
if not self._named_selection:
@@ -189,7 +191,7 @@ def measurement_tools(self) -> GRPCMeasurementToolsService:
189191
190192
Returns
191193
-------
192-
MeasurementToolsServiceBase
194+
GRPCMeasurementToolsService
193195
The measurement tools service for the specified version.
194196
"""
195197
if not self._measurement_tools:
@@ -215,7 +217,7 @@ def prepare_tools(self) -> GRPCPrepareToolsService:
215217
216218
Returns
217219
-------
218-
PrepareToolsServiceBase
220+
GRPCPrepareToolsService
219221
The prepare tools service for the specified version.
220222
"""
221223
if not self._prepare_tools:
@@ -241,7 +243,7 @@ def driving_dimensions(self) -> GRPCDrivingDimensionsService:
241243
242244
Returns
243245
-------
244-
DrivingDimensionsServiceBase
246+
GRPCDrivingDimensionsService
245247
The driving dimensions service for the specified version.
246248
"""
247249
if not self._driving_dimensions:
@@ -259,3 +261,29 @@ def driving_dimensions(self) -> GRPCDrivingDimensionsService:
259261
raise ValueError(f"Unsupported version: {self.version}")
260262

261263
return self._driving_dimensions
264+
265+
@property
266+
def coordinate_systems(self) -> GRPCCoordinateSystemService:
267+
"""
268+
Get the coordinate systems service for the specified version.
269+
270+
Returns
271+
-------
272+
GRPCCoordinateSystemService
273+
The coordinate systems service for the specified version.
274+
"""
275+
if not self._coordinate_systems:
276+
# Import the appropriate coordinate systems service based on the version
277+
from .v0.coordinate_systems import GRPCCoordinateSystemServiceV0
278+
from .v1.coordinate_systems import GRPCCoordinateSystemServiceV1
279+
280+
if self.version == GeometryApiProtos.V0:
281+
self._coordinate_systems = GRPCCoordinateSystemServiceV0(self.channel)
282+
elif self.version == GeometryApiProtos.V1: # pragma: no cover
283+
# V1 is not implemented yet
284+
self._coordinate_systems = GRPCCoordinateSystemServiceV1(self.channel)
285+
else: # pragma: no cover
286+
# This should never happen as the version is set in the constructor
287+
raise ValueError(f"Unsupported version: {self.version}")
288+
289+
return self._coordinate_systems

src/ansys/geometry/core/_grpc/_services/base/admin.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class GRPCAdminService(ABC):
3636
"""
3737

3838
def __init__(self, channel: grpc.Channel):
39-
"""Initialize the AdminServiceBase class."""
39+
"""Initialize the GRPCAdminService class."""
4040
pass # pragma: no cover
4141

4242
@abstractmethod

src/ansys/geometry/core/_grpc/_services/base/bodies.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class GRPCBodyService(ABC):
3636
"""
3737

3838
def __init__(self, channel: grpc.Channel):
39-
"""Initialize the BodyServiceBase class."""
39+
"""Initialize the GRPCBodyService class."""
4040
pass # pragma: no cover
4141

4242
@abstractmethod
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
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 coordinate systems service implementation (abstraction layer)."""
23+
24+
from abc import ABC, abstractmethod
25+
26+
import grpc
27+
28+
29+
class GRPCCoordinateSystemService(ABC):
30+
"""Coordinate systems 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 GRPCCoordinateSystemService class."""
40+
pass # pragma: no cover
41+
42+
@abstractmethod
43+
def create(self, **kwargs) -> dict:
44+
"""Create a coordinate system."""
45+
pass # pragma: no cover

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class GRPCDrivingDimensionsService(ABC):
3636
"""
3737

3838
def __init__(self, channel: grpc.Channel):
39-
"""Initialize the DrivingDimensionsServiceBase class."""
39+
"""Initialize the GRPCDrivingDimensionsService class."""
4040
pass # pragma: no cover
4141

4242
@abstractmethod

src/ansys/geometry/core/_grpc/_services/base/measurement_tools.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class GRPCMeasurementToolsService(ABC):
3636
"""
3737

3838
def __init__(self, channel: grpc.Channel):
39-
"""Initialize the MeasurementToolsService class."""
39+
"""Initialize the GRPCMeasurementToolsService class."""
4040
pass # pragma: no cover
4141

4242
@abstractmethod

src/ansys/geometry/core/_grpc/_services/base/prepare_tools.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class GRPCPrepareToolsService(ABC):
3636
"""
3737

3838
def __init__(self, channel: grpc.Channel):
39-
"""Initialize the PrepareToolsService class."""
39+
"""Initialize the GRPCPrepareToolsService class."""
4040
pass # pragma: no cover
4141

4242
@abstractmethod

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

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,50 @@ def from_frame_to_grpc_frame(frame: "Frame") -> GRPCFrame:
264264
)
265265

266266

267+
def from_grpc_frame_to_frame(frame: GRPCFrame) -> "Frame":
268+
"""Convert a frame gRPC message to a ``Frame`` class.
269+
270+
Parameters
271+
----------
272+
frame : GRPCFrame
273+
Source frame data.
274+
275+
Returns
276+
-------
277+
Frame
278+
Converted frame.
279+
"""
280+
from ansys.geometry.core.math.frame import Frame
281+
from ansys.geometry.core.math.point import Point3D
282+
from ansys.geometry.core.math.vector import UnitVector3D
283+
from ansys.geometry.core.misc.measurements import DEFAULT_UNITS
284+
285+
return Frame(
286+
Point3D(
287+
input=[
288+
frame.origin.x,
289+
frame.origin.y,
290+
frame.origin.z,
291+
],
292+
unit=DEFAULT_UNITS.SERVER_LENGTH,
293+
),
294+
UnitVector3D(
295+
input=[
296+
frame.dir_x.x,
297+
frame.dir_x.y,
298+
frame.dir_x.z,
299+
]
300+
),
301+
UnitVector3D(
302+
input=[
303+
frame.dir_y.x,
304+
frame.dir_y.y,
305+
frame.dir_y.z,
306+
]
307+
),
308+
)
309+
310+
267311
def from_plane_to_grpc_plane(plane: "Plane") -> GRPCPlane:
268312
"""Convert a ``Plane`` class to a plane gRPC message.
269313
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
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 coordinate systems service implementation for v0."""
23+
24+
import grpc
25+
26+
from ansys.geometry.core.errors import protect_grpc
27+
28+
from ..base.coordinate_systems import GRPCCoordinateSystemService
29+
30+
31+
class GRPCCoordinateSystemServiceV0(GRPCCoordinateSystemService):
32+
"""Coordinate systems service for gRPC communication with the Geometry server.
33+
34+
This class provides methods to interact with the Geometry server's
35+
coordinate systems 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.geometry.v0.coordinatesystems_pb2_grpc import CoordinateSystemsStub
47+
48+
self.stub = CoordinateSystemsStub(channel)
49+
50+
@protect_grpc
51+
def create(self, **kwargs) -> dict: # noqa: D102
52+
from ansys.api.geometry.v0.coordinatesystems_pb2 import CreateRequest
53+
54+
from .conversions import from_frame_to_grpc_frame, from_grpc_frame_to_frame
55+
56+
# Create the request - assumes all inputs are valid and of the proper type
57+
request = CreateRequest(
58+
parent=kwargs["parent_id"],
59+
name=kwargs["name"],
60+
frame=from_frame_to_grpc_frame(kwargs["frame"]),
61+
)
62+
63+
# Call the gRPC service
64+
response = self.stub.Create(request=request)
65+
66+
# Return the response - formatted as a dictionary
67+
return {
68+
"id": response.id,
69+
"name": response.name,
70+
"frame": from_grpc_frame_to_frame(response.frame),
71+
}

0 commit comments

Comments
 (0)