Skip to content

Commit f1511b3

Browse files
committed
complete migration of design class to mediator pattern for version handling
1 parent a34e91d commit f1511b3

File tree

4 files changed

+118
-27
lines changed

4 files changed

+118
-27
lines changed

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

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,3 +103,28 @@ 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 assign_midsurface_thickness(self, **kwargs) -> dict:
109+
""" "Add a mid-surface thickness to a list of bodies."""
110+
pass
111+
112+
@abstractmethod
113+
def assign_midsurface_offset_type(self, **kwargs) -> dict:
114+
""" "Add a mid-surface offset type to a list of bodies."""
115+
pass
116+
117+
@abstractmethod
118+
def delete_beam_profile(self, **kwargs) -> dict:
119+
""" "Remove a beam profile on the active geometry server instance."""
120+
pass
121+
122+
@abstractmethod
123+
def create_beam_circular_profile(self, **kwargs) -> dict:
124+
""" "Add a new beam circular profile under the design for creating beams."""
125+
pass
126+
127+
@abstractmethod
128+
def download_file(self, **kwargs) -> dict:
129+
""" "Download the design from the server."""
130+
pass

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

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

24+
from ansys.api.geometry.v0.commands_pb2 import (
25+
AssignMidSurfaceOffsetTypeRequest,
26+
AssignMidSurfaceThicknessRequest,
27+
CreateBeamCircularProfileRequest,
28+
)
29+
from google.protobuf.empty_pb2 import Empty
2430
import grpc
2531

2632
from ansys.geometry.core.errors import protect_grpc
@@ -36,6 +42,8 @@
3642
from_grpc_matrix_to_matrix,
3743
from_grpc_point_to_point3d,
3844
from_grpc_tess_to_raw_data,
45+
from_plane_to_grpc_plane,
46+
from_point3d_to_grpc_point,
3947
from_tess_options_to_grpc_tess_options,
4048
)
4149

@@ -481,3 +489,55 @@ def stream_design_tessellation(self, **kwargs) -> dict: # noqa: D102
481489
return {
482490
"tessellation": tess_map,
483491
}
492+
493+
@protect_grpc
494+
def assign_midsurface_thickness(self, **kwargs) -> dict:
495+
""" "Add a mid-surface thickness to a list of bodies."""
496+
# Create the request - assumes all inputs are valid and of the proper type
497+
request = AssignMidSurfaceThicknessRequest(
498+
bodies_or_faces=kwargs["bodies_or_faces"], thickness=kwargs["thickness"]
499+
)
500+
501+
# Call the gRPC service
502+
response = self.commands_stub.AssignMidSurfaceThickness(request)
503+
504+
@protect_grpc
505+
def assign_midsurface_offset_type(self, **kwargs) -> dict:
506+
# Create the request - assumes all inputs are valid and of the proper type
507+
request = AssignMidSurfaceOffsetTypeRequest(
508+
bodies_or_faces=kwargs["bodies_or_faces"], offset_type=kwargs["offset_type"]
509+
)
510+
511+
# Call the gRPC service
512+
response = self.commands_stub.AssignMidSurfaceOffsetType(request)
513+
514+
@protect_grpc
515+
def delete_beam_profile(self, **kwargs) -> dict:
516+
# Create the request - assumes all inputs are valid and of the proper type
517+
request = build_grpc_id(id=kwargs["id"])
518+
519+
# Call the gRPC service
520+
response = self.commands_stub.DeleteBeamProfile(request)
521+
522+
@protect_grpc
523+
def create_beam_circular_profile(self, **kwargs) -> dict:
524+
# Create the request - assumes all inputs are valid and of the proper type
525+
request = CreateBeamCircularProfileRequest(
526+
origin=from_point3d_to_grpc_point(kwargs["center"]),
527+
radius=kwargs["radius"],
528+
plane=from_plane_to_grpc_plane(kwargs["plane"]), name=kwargs["name"],
529+
)
530+
531+
# Call the gRPC service
532+
response = self.commands_stub.CreateBeamCircularProfile(request)
533+
534+
# Return the response - formatted as a dictionary
535+
return {"id": response.id}
536+
537+
@protect_grpc
538+
def download_file(self, **kwargs) -> dict: # noqa: D102
539+
# Call the gRPC service
540+
response = self.commands_stub.DownloadFile(Empty())
541+
542+
# Return the response - formatted as a dictionary
543+
return {"data": response.data}

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

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,3 +98,23 @@ 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 assign_midsurface_thickness(self, **kwargs) -> dict: # noqa: D102
104+
raise NotImplementedError
105+
106+
@protect_grpc
107+
def assign_midsurface_offset_type(self, **kwargs) -> dict: # noqa: D102
108+
raise NotImplementedError
109+
110+
@protect_grpc
111+
def delete_beam_profile(self, **kwargs) -> dict: # noqa: D102
112+
raise NotImplementedError
113+
114+
@protect_grpc
115+
def create_beam_circular_profile(self, **kwargs) -> dict: # noqa: D102
116+
raise NotImplementedError
117+
118+
@protect_grpc
119+
def download_file(self, **kwargs) -> dict: # noqa: D102
120+
raise NotImplementedError

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

Lines changed: 13 additions & 27 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,
@@ -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),
810+
self._grpc_client.log.debug(f"Creating a beam circular profile on {self.id}...")
811+
812+
response = self._grpc_client._services.designs.create_beam_circular_profile(
813+
center=center,
823814
radius=radius.value.m_as(DEFAULT_UNITS.SERVER_LENGTH),
824-
plane=plane_to_grpc_plane(Plane(center, dir_x, dir_y)),
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(
@@ -912,10 +900,8 @@ def add_midsurface_thickness(self, thickness: Quantity, bodies: list[Body]) -> N
912900
)
913901

914902
# 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-
)
903+
self._grpc_client._services.designs.assign_midsurface_thickness(
904+
bodies_or_faces=ids, thickness=thickness.m_as(DEFAULT_UNITS.SERVER_LENGTH)
919905
)
920906

921907
# Once the assignment has gone fine, store the values
@@ -952,8 +938,8 @@ def add_midsurface_offset(self, offset_type: MidSurfaceOffsetType, bodies: list[
952938
)
953939

954940
# Assign mid-surface offset type
955-
self._commands_stub.AssignMidSurfaceOffsetType(
956-
AssignMidSurfaceOffsetTypeRequest(bodies_or_faces=ids, offset_type=offset_type.value)
941+
self._grpc_client._services.designs.assign_midsurface_offset_type(
942+
bodies_or_faces=ids, offset_type=offset_type.value
957943
)
958944

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

978964
if removal_obj:
979-
self._commands_stub.DeleteBeamProfile(EntityIdentifier(id=removal_obj.id))
965+
self._grpc_client._services.designs.delete_beam_profile(id=removal_obj.id)
980966
self._beam_profiles.pop(removal_name)
981967
self._grpc_client.log.debug(f"Beam profile {removal_name} successfully deleted.")
982968
else:

0 commit comments

Comments
 (0)