Skip to content

Commit 711ab4a

Browse files
smereupyansys-ci-botpre-commit-ci[bot]RobPasMue
authored
feat: finalize version handling for design class (#2323)
Co-authored-by: PyAnsys CI Bot <[email protected]> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Roberto Pastor Muela <[email protected]>
1 parent f58972a commit 711ab4a

File tree

9 files changed

+93
-40
lines changed

9 files changed

+93
-40
lines changed

doc/changelog.d/2323.added.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Finalize version handling for design class

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,3 +53,13 @@ def create_descriptive_beam_segments(self, **kwargs) -> dict:
5353
def delete_beam(self, **kwargs) -> dict:
5454
"""Delete a beam."""
5555
pass
56+
57+
@abstractmethod
58+
def delete_beam_profile(self, **kwargs) -> dict:
59+
"""Remove a beam profile on the active geometry server instance."""
60+
pass
61+
62+
@abstractmethod
63+
def create_beam_circular_profile(self, **kwargs) -> dict:
64+
"""Add a new beam circular profile under the design for creating beams."""
65+
pass

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,3 +103,8 @@ def upload_file_stream(self, **kwargs) -> dict:
103103
def stream_design_tessellation(self, **kwargs) -> dict:
104104
"""Stream the tessellation of a design."""
105105
pass
106+
107+
@abstractmethod
108+
def download_file(self, **kwargs) -> dict:
109+
"""Download the design from the server."""
110+
pass

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

Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,20 @@
2121
# SOFTWARE.
2222
"""Module containing the beams service implementation for v0."""
2323

24+
from ansys.api.geometry.v0.commands_pb2 import CreateBeamCircularProfileRequest
2425
import grpc
2526

2627
from ansys.geometry.core.errors import protect_grpc
2728

2829
from ..base.beams import GRPCBeamsService
29-
from ..base.conversions import to_distance
30+
from ..base.conversions import from_measurement_to_server_length, to_distance
3031
from .conversions import (
3132
build_grpc_id,
3233
from_grpc_curve_to_curve,
3334
from_grpc_frame_to_frame,
3435
from_grpc_material_to_material,
3536
from_grpc_point_to_point3d,
37+
from_plane_to_grpc_plane,
3638
from_point3d_to_grpc_point,
3739
)
3840

@@ -54,7 +56,7 @@ class GRPCBeamsServiceV0(GRPCBeamsService):
5456
def __init__(self, channel: grpc.Channel): # noqa: D102
5557
from ansys.api.geometry.v0.commands_pb2_grpc import CommandsStub
5658

57-
self.stub = CommandsStub(channel)
59+
self.commands_stub = CommandsStub(channel)
5860

5961
@protect_grpc
6062
def create_beam_segments(self, **kwargs) -> dict: # noqa: D102
@@ -79,7 +81,7 @@ def create_beam_segments(self, **kwargs) -> dict: # noqa: D102
7981
)
8082

8183
# Call the gRPC service
82-
resp = self.stub.CreateBeamSegments(request)
84+
resp = self.commands_stub.CreateBeamSegments(request)
8385

8486
# Return the response - formatted as a dictionary
8587
return {
@@ -111,7 +113,7 @@ def create_descriptive_beam_segments(self, **kwargs) -> dict: # noqa: D102
111113
)
112114

113115
# Call the gRPC service
114-
resp = self.stub.CreateDescriptiveBeamSegments(request)
116+
resp = self.commands_stub.CreateDescriptiveBeamSegments(request)
115117

116118
# Return the response - formatted as a dictionary
117119
return {
@@ -174,7 +176,34 @@ def delete_beam(self, **kwargs) -> dict: # noqa: D102
174176
request = build_grpc_id(kwargs["beam_id"])
175177

176178
# Call the gRPC service
177-
_ = self.stub.DeleteBeam(request)
179+
_ = self.commands_stub.DeleteBeam(request)
178180

179181
# Return the response - formatted as a dictionary
180182
return {}
183+
184+
@protect_grpc
185+
def delete_beam_profile(self, **kwargs) -> dict: # noqa: D102
186+
# Create the request - assumes all inputs are valid and of the proper type
187+
request = build_grpc_id(id=kwargs["id"])
188+
189+
# Call the gRPC service
190+
_ = self.commands_stub.DeleteBeamProfile(request)
191+
192+
# Return the response - formatted as a dictionary
193+
return {}
194+
195+
@protect_grpc
196+
def create_beam_circular_profile(self, **kwargs) -> dict: # noqa: D102
197+
# Create the request - assumes all inputs are valid and of the proper type
198+
request = CreateBeamCircularProfileRequest(
199+
origin=from_point3d_to_grpc_point(kwargs["center"]),
200+
radius=from_measurement_to_server_length(kwargs["radius"]),
201+
plane=from_plane_to_grpc_plane(kwargs["plane"]),
202+
name=kwargs["name"],
203+
)
204+
205+
# Call the gRPC service
206+
response = self.commands_stub.CreateBeamCircularProfile(request)
207+
208+
# Return the response - formatted as a dictionary
209+
return {"id": response.id}

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
# SOFTWARE.
2222
"""Module containing the designs service implementation for v0."""
2323

24+
from google.protobuf.empty_pb2 import Empty
2425
import grpc
2526

2627
from ansys.geometry.core.errors import protect_grpc
@@ -481,3 +482,11 @@ def stream_design_tessellation(self, **kwargs) -> dict: # noqa: D102
481482
return {
482483
"tessellation": tess_map,
483484
}
485+
486+
@protect_grpc
487+
def download_file(self, **kwargs) -> dict: # noqa: D102
488+
# Call the gRPC service
489+
response = self.commands_stub.DownloadFile(Empty())
490+
491+
# Return the response - formatted as a dictionary
492+
return {"data": response.data}

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,3 +58,11 @@ def create_descriptive_beam_segments(self, **kwargs) -> dict: # noqa: D102
5858
@protect_grpc
5959
def delete_beam(self, **kwargs) -> dict: # noqa: D102
6060
raise NotImplementedError
61+
62+
@protect_grpc
63+
def delete_beam_profile(self, **kwargs) -> dict: # noqa: D102
64+
raise NotImplementedError
65+
66+
@protect_grpc
67+
def create_beam_circular_profile(self, **kwargs) -> dict: # noqa: D102
68+
raise NotImplementedError

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,3 +98,7 @@ def upload_file_stream(self, **kwargs) -> dict: # noqa: D102
9898
@protect_grpc
9999
def stream_design_tessellation(self, **kwargs) -> dict: # noqa: D102
100100
raise NotImplementedError
101+
102+
@protect_grpc
103+
def download_file(self, **kwargs) -> dict: # noqa: D102
104+
raise NotImplementedError

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

Lines changed: 20 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -25,23 +25,12 @@
2525
from pathlib import Path
2626
from typing import Union
2727

28-
from ansys.api.dbu.v0.dbumodels_pb2 import EntityIdentifier
29-
from ansys.api.geometry.v0.commands_pb2 import (
30-
AssignMidSurfaceOffsetTypeRequest,
31-
AssignMidSurfaceThicknessRequest,
32-
CreateBeamCircularProfileRequest,
33-
)
3428
from ansys.api.geometry.v0.commands_pb2_grpc import CommandsStub
3529
from beartype import beartype as check_input_types
36-
from google.protobuf.empty_pb2 import Empty
3730
import numpy as np
3831
from pint import Quantity, UndefinedUnitError
3932

4033
from ansys.geometry.core.connection.backend import BackendType
41-
from ansys.geometry.core.connection.conversions import (
42-
plane_to_grpc_plane,
43-
point3d_to_grpc_point,
44-
)
4534
from ansys.geometry.core.designer.beam import (
4635
Beam,
4736
BeamCircularProfile,
@@ -70,13 +59,13 @@
7059
ensure_design_is_active,
7160
min_backend_version,
7261
)
73-
from ansys.geometry.core.misc.measurements import DEFAULT_UNITS, Distance
62+
from ansys.geometry.core.misc.measurements import Distance
7463
from ansys.geometry.core.misc.options import ImportOptions, TessellationOptions
7564
from ansys.geometry.core.modeler import Modeler
7665
from ansys.geometry.core.parameters.parameter import Parameter, ParameterUpdateStatus
7766
from ansys.geometry.core.shapes.curves.trimmed_curve import TrimmedCurve
7867
from ansys.geometry.core.shapes.parameterization import Interval, ParamUV
79-
from ansys.geometry.core.typing import RealSequence
68+
from ansys.geometry.core.typing import Real, RealSequence
8069

8170

8271
@unique
@@ -330,9 +319,9 @@ def __export_and_download_legacy(self, format: DesignFileFormat) -> bytes:
330319
# Process response
331320
self._grpc_client.log.debug(f"Requesting design download in {format} format.")
332321
if format is DesignFileFormat.SCDOCX:
333-
response = self._commands_stub.DownloadFile(Empty())
322+
response = self._grpc_client.services.designs.download_file()
334323
received_bytes = bytes()
335-
received_bytes += response.data
324+
received_bytes += response.get("data")
336325
elif format in [
337326
DesignFileFormat.PARASOLID_TEXT,
338327
DesignFileFormat.PARASOLID_BIN,
@@ -818,17 +807,16 @@ def add_beam_circular_profile(
818807
if not dir_x.is_perpendicular_to(dir_y):
819808
raise ValueError("Direction X and direction Y must be perpendicular.")
820809

821-
request = CreateBeamCircularProfileRequest(
822-
origin=point3d_to_grpc_point(center),
823-
radius=radius.value.m_as(DEFAULT_UNITS.SERVER_LENGTH),
824-
plane=plane_to_grpc_plane(Plane(center, dir_x, dir_y)),
810+
self._grpc_client.log.debug(f"Creating a beam circular profile on {self.id}...")
811+
812+
response = self._grpc_client._services.beams.create_beam_circular_profile(
813+
center=center,
814+
radius=radius,
815+
plane=Plane(center, dir_x, dir_y),
825816
name=name,
826817
)
827818

828-
self._grpc_client.log.debug(f"Creating a beam circular profile on {self.id}...")
829-
830-
response = self._commands_stub.CreateBeamCircularProfile(request)
831-
profile = BeamCircularProfile(response.id, name, radius, center, dir_x, dir_y)
819+
profile = BeamCircularProfile(response.get("id"), name, radius, center, dir_x, dir_y)
832820
self._beam_profiles[profile.name] = profile
833821

834822
self._grpc_client.log.debug(
@@ -885,7 +873,9 @@ def set_parameter(self, dimension: Parameter) -> ParameterUpdateStatus:
885873
@protect_grpc
886874
@check_input_types
887875
@ensure_design_is_active
888-
def add_midsurface_thickness(self, thickness: Quantity, bodies: list[Body]) -> None:
876+
def add_midsurface_thickness(
877+
self, thickness: Distance | Quantity | Real, bodies: list[Body]
878+
) -> None:
889879
"""Add a mid-surface thickness to a list of bodies.
890880
891881
Parameters
@@ -899,6 +889,7 @@ def add_midsurface_thickness(self, thickness: Quantity, bodies: list[Body]) -> N
899889
-----
900890
Only surface bodies will be eligible for mid-surface thickness assignment.
901891
"""
892+
thickness = thickness if isinstance(thickness, Distance) else Distance(thickness)
902893
# Store only assignable ids
903894
ids: list[str] = []
904895
ids_bodies: list[Body] = []
@@ -912,15 +903,11 @@ def add_midsurface_thickness(self, thickness: Quantity, bodies: list[Body]) -> N
912903
)
913904

914905
# Assign mid-surface thickness
915-
self._commands_stub.AssignMidSurfaceThickness(
916-
AssignMidSurfaceThicknessRequest(
917-
bodies_or_faces=ids, thickness=thickness.m_as(DEFAULT_UNITS.SERVER_LENGTH)
918-
)
919-
)
906+
self._grpc_client._services.bodies.assign_midsurface_thickness(ids=ids, thickness=thickness)
920907

921908
# Once the assignment has gone fine, store the values
922909
for body in ids_bodies:
923-
body._surface_thickness = thickness
910+
body._surface_thickness = thickness.value
924911

925912
@protect_grpc
926913
@check_input_types
@@ -952,8 +939,8 @@ def add_midsurface_offset(self, offset_type: MidSurfaceOffsetType, bodies: list[
952939
)
953940

954941
# Assign mid-surface offset type
955-
self._commands_stub.AssignMidSurfaceOffsetType(
956-
AssignMidSurfaceOffsetTypeRequest(bodies_or_faces=ids, offset_type=offset_type.value)
942+
self._grpc_client._services.bodies.assign_midsurface_offset(
943+
ids=ids, offset_type=offset_type
957944
)
958945

959946
# Once the assignment has gone fine, store the values
@@ -976,7 +963,7 @@ def delete_beam_profile(self, beam_profile: BeamProfile | str) -> None:
976963
removal_obj = self._beam_profiles.get(removal_name, None)
977964

978965
if removal_obj:
979-
self._commands_stub.DeleteBeamProfile(EntityIdentifier(id=removal_obj.id))
966+
self._grpc_client._services.beams.delete_beam_profile(id=removal_obj.id)
980967
self._beam_profiles.pop(removal_name)
981968
self._grpc_client.log.debug(f"Beam profile {removal_name} successfully deleted.")
982969
else:

tests/integration/test_design.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1695,7 +1695,7 @@ def test_midsurface_properties(modeler: Modeler):
16951695
assert "Exists : True" in surf_repr
16961696
assert "Parent component : MidSurfaceProperties" in surf_repr
16971697
assert "Surface body : True" in surf_repr
1698-
assert "Surface thickness : 10 millimeter" in surf_repr
1698+
assert "Surface thickness : 10.0 millimeter" in surf_repr
16991699
assert "Surface offset : MidSurfaceOffsetType.TOP" in surf_repr
17001700
assert f"Color : {DEFAULT_COLOR}" in surf_repr
17011701

@@ -1726,7 +1726,7 @@ def test_midsurface_properties(modeler: Modeler):
17261726
assert "Exists : True" in surf_repr
17271727
assert "Parent component : MidSurfaceProperties" in surf_repr
17281728
assert "Surface body : True" in surf_repr
1729-
assert "Surface thickness : 30 millimeter" in surf_repr
1729+
assert "Surface thickness : 30.0 millimeter" in surf_repr
17301730
assert "Surface offset : MidSurfaceOffsetType.BOTTOM" in surf_repr
17311731
assert f"Color : {DEFAULT_COLOR}" in surf_repr
17321732
except GeometryExitedError:

0 commit comments

Comments
 (0)