Skip to content

Commit 10b7493

Browse files
added the rest of methods - may need to remove offset face curves
1 parent 72f4fa1 commit 10b7493

File tree

6 files changed

+311
-2
lines changed

6 files changed

+311
-2
lines changed

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

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
from .base.bodies import GRPCBodyService
3030
from .base.commands import GRPCCommandsService
3131
from .base.coordinate_systems import GRPCCoordinateSystemService
32+
from .base.curves import GRPCCurvesService
3233
from .base.dbuapplication import GRPCDbuApplicationService
3334
from .base.designs import GRPCDesignsService
3435
from .base.driving_dimensions import GRPCDrivingDimensionsService
@@ -88,6 +89,7 @@ def __init__(self, channel: grpc.Channel, version: GeometryApiProtos | str | Non
8889
self._bodies = None
8990
self._commands = None
9091
self._coordinate_systems = None
92+
self._curves = None
9193
self._dbu_application = None
9294
self._designs = None
9395
self._driving_dimensions = None
@@ -258,6 +260,32 @@ def coordinate_systems(self) -> GRPCCoordinateSystemService:
258260

259261
return self._coordinate_systems
260262

263+
@property
264+
def curves(self) -> GRPCCurvesService:
265+
"""
266+
Get the curves service for the specified version.
267+
268+
Returns
269+
-------
270+
GRPCCurvesService
271+
The curves service for the specified version.
272+
"""
273+
if not self._curves:
274+
# Import the appropriate curves service based on the version
275+
from .v0.curves import GRPCCurvesServiceV0
276+
from .v1.curves import GRPCCurvesServiceV1
277+
278+
if self.version == GeometryApiProtos.V0:
279+
self._curves = GRPCCurvesServiceV0(self.channel)
280+
elif self.version == GeometryApiProtos.V1: # pragma: no cover
281+
# V1 is not implemented yet
282+
self._curves = GRPCCurvesServiceV1(self.channel)
283+
else: # pragma: no cover
284+
# This should never happen as the version is set in the constructor
285+
raise ValueError(f"Unsupported version: {self.version}")
286+
287+
return self._curves
288+
261289
@property
262290
def designs(self) -> GRPCDesignsService:
263291
"""
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 curves service implementation (abstraction layer)."""
23+
24+
from abc import ABC, abstractmethod
25+
26+
import grpc
27+
28+
29+
class GRPCCurvesService(ABC): # pragma: no cover
30+
"""Curves 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 GRPCCurvesService class."""
40+
pass
41+
42+
@abstractmethod
43+
def offset_face_curves(self, **kwargs) -> dict:
44+
"""Offset face curves."""
45+
pass
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
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 curves service implementation for v0."""
23+
24+
import grpc
25+
26+
from ansys.geometry.core.errors import protect_grpc
27+
28+
from ..base.conversions import from_measurement_to_server_angle, from_measurement_to_server_length
29+
from ..base.curves import GRPCCurvesService
30+
from .conversions import from_line_to_grpc_line, from_trimmed_curve_to_grpc_trimmed_curve
31+
32+
33+
class GRPCCurvesServiceV0(GRPCCurvesService): # pragma: no cover
34+
"""Curves service for gRPC communication with the Geometry server.
35+
36+
This class provides methods to interact with the Geometry server's
37+
curves service. It is specifically designed for the v0 version of the
38+
Geometry API.
39+
40+
Parameters
41+
----------
42+
channel : grpc.Channel
43+
The gRPC channel to the server.
44+
"""
45+
46+
@protect_grpc
47+
def __init__(self, channel: grpc.Channel): # noqa: D102
48+
from ansys.api.geometry.v0.commands_pb2_grpc import CommandsStub
49+
50+
self.stub = CommandsStub(channel)
51+
52+
@protect_grpc
53+
def offset_face_curves(self, **kwargs): # noqa: D102
54+
from ansys.api.dbu.v0.dbumodels_pb2 import EntityIdentifier
55+
from ansys.api.geometry.v0.commands_pb2 import OffsetFaceCurvesRequest
56+
57+
# Create the request - assumes all inputs are valid and of the proper type
58+
request = OffsetFaceCurvesRequest(
59+
objects=[EntityIdentifier(id=id) for id in kwargs["curve_ids"]],
60+
offset=from_measurement_to_server_length(kwargs["offset"]),
61+
)
62+
63+
# Call the gRPC service
64+
result = self.stub.OffsetFaceCurves(request)
65+
66+
# Return the result - formatted as a dictionary
67+
return {
68+
"success": result.result.success,
69+
"created_curves": [curve.id for curve in result.created_curves]
70+
}
71+
72+
@protect_grpc
73+
def revolve_edges(self, **kwargs): # noqa: D102
74+
from ansys.api.geometry.v0.commands_pb2 import RevolveCurvesRequest
75+
76+
# Create the request - assumes all inputs are valid and of the proper type
77+
request = RevolveCurvesRequest(
78+
curves=[from_trimmed_curve_to_grpc_trimmed_curve(curve) for curve in kwargs["curves"]],
79+
axis=from_line_to_grpc_line(kwargs["axis"]),
80+
angle=from_measurement_to_server_angle(kwargs["angle"]),
81+
symmetric=kwargs["symmetric"],
82+
)
83+
84+
# Call the gRPC service
85+
_ = self.stub.RevolveCurves(request)
86+
87+
# Return the result - formatted as a dictionary
88+
return {}
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 curves service implementation for v1."""
23+
24+
import grpc
25+
26+
from ansys.geometry.core.errors import protect_grpc
27+
28+
from ..base.curves import GRPCCurvesService
29+
30+
31+
class GRPCCurvesServiceV1(GRPCCurvesService): # pragma: no cover
32+
"""Curves service for gRPC communication with the Geometry server.
33+
34+
This class provides methods to interact with the Geometry server's
35+
curves service. It is specifically designed for the v1 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.v1.curves_pb2_grpc import CurvesStub
47+
48+
self.stub = CurvesStub(channel)
49+
50+
@protect_grpc
51+
def offset_face_curves(self, **kwargs): # noqa: D102
52+
raise NotImplementedError
53+
54+
@protect_grpc
55+
def revolve_edges(self, **kwargs): # noqa: D102
56+
raise NotImplementedError

src/ansys/geometry/core/designer/geometry_commands.py

Lines changed: 71 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1792,4 +1792,74 @@ def offset_faces(
17921792
distance=distance,
17931793
direction=direction,
17941794
extrude_type=extrude_type,
1795-
)
1795+
)
1796+
1797+
@min_backend_version(25, 2, 0)
1798+
def offset_face_curves(
1799+
self,
1800+
curves: Union["Curve", list["Curve"]],
1801+
offset: Distance | Quantity | Real,
1802+
) -> bool:
1803+
"""Offsets a given set of face curves by the specified distance.
1804+
1805+
Parameters
1806+
----------
1807+
curves : Curve | list[Curve]
1808+
The curves to offset.
1809+
offset : Distance | Quantity | Real
1810+
The distance to offset the curves.
1811+
1812+
Returns
1813+
-------
1814+
bool
1815+
``True`` when successful, ``False`` when failed.
1816+
"""
1817+
curves = curves if isinstance(curves, list) else [curves]
1818+
offset = offset if isinstance(offset, Distance) else Distance(offset)
1819+
1820+
_ = self._grpc_client._services.curves.offset_face_curves(
1821+
curves=[curve.id for curve in curves], # TODO
1822+
offset=offset
1823+
)
1824+
1825+
@min_backend_version(25, 2, 0)
1826+
def revolve_edges(
1827+
self,
1828+
edges: Union["Edge", list["Edge"]],
1829+
axis: Line,
1830+
angle: Angle | Quantity | Real,
1831+
symmetric: bool,
1832+
) -> None:
1833+
"""Revolve edges around an axis.
1834+
1835+
Parameters
1836+
----------
1837+
edges : Edge | list[Edge]
1838+
Edge(s) to revolve.
1839+
axis : Line
1840+
Axis of revolution.
1841+
angle : Angle | Quantity | Real
1842+
Angular distance to revolve.
1843+
symmetric : bool
1844+
Revolve symmetrically if ``True``, one side if ``False``.
1845+
1846+
Warnings
1847+
--------
1848+
This method is only available starting on Ansys release 25R2.
1849+
"""
1850+
from ansys.geometry.core.designer.edge import Edge
1851+
1852+
edges: list[Edge] = edges if isinstance(edges, list) else [edges]
1853+
check_type_all_elements_in_iterable(edges, Edge)
1854+
1855+
angle = angle if isinstance(angle, Angle) else Angle(angle)
1856+
1857+
_ = self._grpc_client._services.curves.revolve_edges(
1858+
curves=[edge.shape for edge in edges],
1859+
axis=axis,
1860+
angle=angle,
1861+
symmetric=symmetric,
1862+
)
1863+
1864+
design = get_design_from_edge(edges[0])
1865+
design._update_design_inplace()

tests/integration/test_geometry_commands.py

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1431,4 +1431,26 @@ def test_offset_faces(modeler: Modeler):
14311431
)
14321432

14331433
assert box.volume.m == pytest.approx(Quantity(8.8, UNITS.m**3).m, rel=1e-6, abs=1e-8)
1434-
assert box2.volume.m == pytest.approx(Quantity(8.4, UNITS.m**3).m, rel=1e-6, abs=1e-8)
1434+
assert box2.volume.m == pytest.approx(Quantity(8.4, UNITS.m**3).m, rel=1e-6, abs=1e-8)
1435+
1436+
def test_revolve_edges(modeler: Modeler):
1437+
"""Test revolving edges."""
1438+
design = modeler.create_design("revolve_edges")
1439+
box = design.extrude_sketch("box", Sketch().box(Point2D([0, 0]), 2, 2), 2)
1440+
1441+
assert len(box.faces) == 6
1442+
assert box.volume.m == pytest.approx(Quantity(8, UNITS.m**3).m, rel=1e-6, abs=1e-8)
1443+
1444+
# Revolve one edge of the box
1445+
edge = box.faces[2].edges[0]
1446+
axis = Line(Point3D([0, 0, 0], UNITS.m), UNITVECTOR3D_Z)
1447+
modeler.geometry_commands.revolve_edges(edge, axis, Angle(np.pi / 2, UNITS.rad), True)
1448+
1449+
assert len(design.bodies) == 2
1450+
assert design.bodies[0].volume.m == pytest.approx(
1451+
Quantity(8, UNITS.m**3).m, rel=1e-6, abs=1e-8
1452+
)
1453+
assert design.bodies[1].is_surface
1454+
assert design.bodies[1].faces[0].area.m == pytest.approx(
1455+
Quantity(8.88576587632, UNITS.m**2).m, rel=1e-6, abs=1e-8
1456+
)

0 commit comments

Comments
 (0)