Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: single design per modeler session refactoring #1721

Draft
wants to merge 8 commits into
base: main
Choose a base branch
from
1 change: 1 addition & 0 deletions doc/changelog.d/1721.added.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
single design per modeler session refactoring
7 changes: 0 additions & 7 deletions src/ansys/geometry/core/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,5 @@
"""Global constant for checking whether to use service colors for plotting
purposes. If set to False, the default colors will be used (speed gain)."""

DISABLE_MULTIPLE_DESIGN_CHECK: bool = False
"""Global constant for disabling the ``ensure_design_is_active`` check.

Only set this to false if you are sure you want to disable this check
and you will ONLY be working with one design.
"""

DOCUMENTATION_BUILD: bool = os.environ.get("PYANSYS_GEOMETRY_DOC_BUILD", "false").lower() == "true"
"""Global flag for the documentation to use the proper PyVista Jupyter backend."""
22 changes: 7 additions & 15 deletions src/ansys/geometry/core/connection/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import warnings

from ansys.geometry.core.errors import protect_grpc
from ansys.geometry.core.misc.checks import deprecated_method

# TODO: Remove this context and filter once the protobuf UserWarning issue is downgraded to INFO
# https://github.com/grpc/grpc/issues/37609
Expand Down Expand Up @@ -224,18 +225,6 @@ def __init__(

# Store the backend type
self._backend_type = backend_type
self._multiple_designs_allowed = (
False
if backend_type
in (
BackendType.DISCOVERY,
BackendType.LINUX_SERVICE,
BackendType.CORE_LINUX,
BackendType.CORE_WINDOWS,
BackendType.DISCOVERY_HEADLESS,
)
else True
)

# retrieve the backend version
if hasattr(grpc_backend_response, "version"):
Expand Down Expand Up @@ -277,15 +266,18 @@ def backend_version(self) -> semver.version.Version:
return self._backend_version

@property
@deprecated_method(info="Multiple designs for the same service are no longer supported.")
def multiple_designs_allowed(self) -> bool:
"""Flag indicating whether multiple designs are allowed.

Deprecated since version 0.8.X.

Notes
-----
This method will return ``False`` if the backend type is ``Discovery`` or
``Linux Service``. Otherwise, it will return ``True``.
Currently, only one design is allowed per service. This method will always
return ``False``.
"""
return self._multiple_designs_allowed
return False

@property
def channel(self) -> grpc.Channel:
Expand Down
28 changes: 0 additions & 28 deletions src/ansys/geometry/core/designer/body.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@
from ansys.geometry.core.misc.checks import (
check_type,
check_type_all_elements_in_iterable,
ensure_design_is_active,
min_backend_version,
)
from ansys.geometry.core.misc.measurements import DEFAULT_UNITS, Angle, Distance
Expand Down Expand Up @@ -1438,7 +1437,6 @@ def parent_component(self) -> "Component": # noqa: D102

@property
@protect_grpc
@ensure_design_is_active
def faces(self) -> list[Face]: # noqa: D102
self._template._grpc_client.log.debug(f"Retrieving faces for body {self.id} from server.")
grpc_faces = self._template._bodies_stub.GetFaces(EntityIdentifier(id=self.id))
Expand All @@ -1455,7 +1453,6 @@ def faces(self) -> list[Face]: # noqa: D102

@property
@protect_grpc
@ensure_design_is_active
def edges(self) -> list[Edge]: # noqa: D102
self._template._grpc_client.log.debug(f"Retrieving edges for body {self.id} from server.")
grpc_edges = self._template._bodies_stub.GetEdges(EntityIdentifier(id=self.id))
Expand Down Expand Up @@ -1511,39 +1508,32 @@ def surface_offset(self) -> Union["MidSurfaceOffsetType", None]: # noqa: D102
return self._surface_offset

@property
@ensure_design_is_active
def volume(self) -> Quantity: # noqa: D102
return self._template.volume

@property
@ensure_design_is_active
def material(self) -> Material: # noqa: D102
return self._template.material

@material.setter
def material(self, value: Material): # noqa: D102
self._template.material = value

@ensure_design_is_active
def assign_material(self, material: Material) -> None: # noqa: D102
self._template.assign_material(material)

@ensure_design_is_active
def get_assigned_material(self) -> Material: # noqa: D102
return self._template.get_assigned_material()

@ensure_design_is_active
def add_midsurface_thickness(self, thickness: Quantity) -> None: # noqa: D102
self._template.add_midsurface_thickness(thickness)

@ensure_design_is_active
def add_midsurface_offset( # noqa: D102
self, offset: "MidSurfaceOffsetType"
) -> None:
self._template.add_midsurface_offset(offset)

@protect_grpc
@ensure_design_is_active
def imprint_curves( # noqa: D102
self, faces: list[Face], sketch: Sketch
) -> tuple[list[Edge], list[Face]]:
Expand Down Expand Up @@ -1595,7 +1585,6 @@ def imprint_curves( # noqa: D102
return (new_edges, new_faces)

@protect_grpc
@ensure_design_is_active
def project_curves( # noqa: D102
self,
direction: UnitVector3D,
Expand Down Expand Up @@ -1632,7 +1621,6 @@ def project_curves( # noqa: D102

@check_input_types
@protect_grpc
@ensure_design_is_active
def imprint_projected_curves( # noqa: D102
self,
direction: UnitVector3D,
Expand Down Expand Up @@ -1667,29 +1655,23 @@ def imprint_projected_curves( # noqa: D102

return imprinted_faces

@ensure_design_is_active
def set_name(self, name: str) -> None: # noqa: D102
return self._template.set_name(name)

@ensure_design_is_active
def set_fill_style(self, fill_style: FillStyle) -> None: # noqa: D102
return self._template.set_fill_style(fill_style)

@ensure_design_is_active
def set_suppressed(self, suppressed: bool) -> None: # noqa: D102
return self._template.set_suppressed(suppressed)

@ensure_design_is_active
def set_color(self, color: str | tuple[float, float, float]) -> None: # noqa: D102
return self._template.set_color(color)

@ensure_design_is_active
def translate( # noqa: D102
self, direction: UnitVector3D, distance: Quantity | Distance | Real
) -> None:
return self._template.translate(direction, distance)

@ensure_design_is_active
def rotate( # noqa: D102
self,
axis_origin: Point3D,
Expand All @@ -1698,37 +1680,29 @@ def rotate( # noqa: D102
) -> None:
return self._template.rotate(axis_origin, axis_direction, angle)

@ensure_design_is_active
def scale(self, value: Real) -> None: # noqa: D102
return self._template.scale(value)

@ensure_design_is_active
def map(self, frame: Frame) -> None: # noqa: D102
return self._template.map(frame)

@ensure_design_is_active
def mirror(self, plane: Plane) -> None: # noqa: D102
return self._template.mirror(plane)

@ensure_design_is_active
def get_collision(self, body: "Body") -> CollisionType: # noqa: D102
return self._template.get_collision(body)

@ensure_design_is_active
def copy(self, parent: "Component", name: str = None) -> "Body": # noqa: D102
return self._template.copy(parent, name)

@ensure_design_is_active
def tessellate( # noqa: D102
self, merge: bool = False
) -> Union["PolyData", "MultiBlock"]:
return self._template.tessellate(merge, self.parent_component.get_world_transform())

@ensure_design_is_active
def shell_body(self, offset: Real) -> bool: # noqa: D102
return self._template.shell_body(offset)

@ensure_design_is_active
def remove_faces(self, selection: Face | Iterable[Face], offset: Real) -> bool: # noqa: D102
return self._template.remove_faces(selection, offset)

Expand Down Expand Up @@ -1787,7 +1761,6 @@ def unite(self, other: Union["Body", Iterable["Body"]], keep_other: bool = False

@protect_grpc
@reset_tessellation_cache
@ensure_design_is_active
@check_input_types
def __generic_boolean_command(
self,
Expand Down Expand Up @@ -1840,7 +1813,6 @@ def __generic_boolean_command(

@protect_grpc
@reset_tessellation_cache
@ensure_design_is_active
@check_input_types
def __generic_boolean_op(
self,
Expand Down
21 changes: 1 addition & 20 deletions src/ansys/geometry/core/designer/component.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
from ansys.geometry.core.math.matrix import Matrix44
from ansys.geometry.core.math.point import Point3D
from ansys.geometry.core.math.vector import UnitVector3D, Vector3D
from ansys.geometry.core.misc.checks import ensure_design_is_active, min_backend_version
from ansys.geometry.core.misc.checks import min_backend_version
from ansys.geometry.core.misc.measurements import DEFAULT_UNITS, Angle, Distance
from ansys.geometry.core.shapes.curves.circle import Circle
from ansys.geometry.core.shapes.curves.trimmed_curve import TrimmedCurve
Expand Down Expand Up @@ -358,7 +358,6 @@ def get_world_transform(self) -> Matrix44:
return self.parent_component.get_world_transform() * self._master_component.transform

@protect_grpc
@ensure_design_is_active
def modify_placement(
self,
translation: Vector3D | None = None,
Expand Down Expand Up @@ -416,7 +415,6 @@ def reset_placement(self):
self.modify_placement()

@check_input_types
@ensure_design_is_active
def add_component(
self, name: str, template: Optional["Component"] = None, instance_name: str = None
) -> "Component":
Expand Down Expand Up @@ -460,7 +458,6 @@ def add_component(

@protect_grpc
@check_input_types
@ensure_design_is_active
def set_shared_topology(self, share_type: SharedTopologyType) -> None:
"""Set the shared topology to apply to the component.

Expand All @@ -482,7 +479,6 @@ def set_shared_topology(self, share_type: SharedTopologyType) -> None:

@protect_grpc
@check_input_types
@ensure_design_is_active
def extrude_sketch(
self,
name: str,
Expand Down Expand Up @@ -567,7 +563,6 @@ def extrude_sketch(
@min_backend_version(24, 2, 0)
@protect_grpc
@check_input_types
@ensure_design_is_active
def sweep_sketch(
self,
name: str,
Expand Down Expand Up @@ -617,7 +612,6 @@ def sweep_sketch(
@min_backend_version(24, 2, 0)
@protect_grpc
@check_input_types
@ensure_design_is_active
def sweep_chain(
self,
name: str,
Expand Down Expand Up @@ -717,7 +711,6 @@ def revolve_sketch(

@protect_grpc
@check_input_types
@ensure_design_is_active
def extrude_face(
self,
name: str,
Expand Down Expand Up @@ -780,7 +773,6 @@ def extrude_face(

@protect_grpc
@check_input_types
@ensure_design_is_active
@min_backend_version(24, 2, 0)
def create_sphere(self, name: str, center: Point3D, radius: Distance) -> Body:
"""Create a sphere body defined by the center point and the radius.
Expand Down Expand Up @@ -814,7 +806,6 @@ def create_sphere(self, name: str, center: Point3D, radius: Distance) -> Body:

@protect_grpc
@check_input_types
@ensure_design_is_active
@min_backend_version(24, 2, 0)
def create_body_from_loft_profile(
self,
Expand Down Expand Up @@ -881,7 +872,6 @@ def create_body_from_loft_profile(

@protect_grpc
@check_input_types
@ensure_design_is_active
def create_surface(self, name: str, sketch: Sketch) -> Body:
"""Create a surface body with a sketch profile.

Expand Down Expand Up @@ -919,7 +909,6 @@ def create_surface(self, name: str, sketch: Sketch) -> Body:

@protect_grpc
@check_input_types
@ensure_design_is_active
def create_surface_from_face(self, name: str, face: Face) -> Body:
"""Create a surface body based on a face.

Expand Down Expand Up @@ -960,7 +949,6 @@ def create_surface_from_face(self, name: str, face: Face) -> Body:

@protect_grpc
@check_input_types
@ensure_design_is_active
@min_backend_version(25, 1, 0)
def create_body_from_surface(self, name: str, trimmed_surface: TrimmedSurface) -> Body:
"""Create a surface body from a trimmed surface.
Expand Down Expand Up @@ -1036,7 +1024,6 @@ def create_surface_from_trimmed_curves(
return Body(response.id, response.name, self, tb)

@check_input_types
@ensure_design_is_active
def create_coordinate_system(self, name: str, frame: Frame) -> CoordinateSystem:
"""Create a coordinate system.

Expand All @@ -1059,7 +1046,6 @@ def create_coordinate_system(self, name: str, frame: Frame) -> CoordinateSystem:

@protect_grpc
@check_input_types
@ensure_design_is_active
def translate_bodies(
self, bodies: list[Body], direction: UnitVector3D, distance: Quantity | Distance | Real
) -> None:
Expand Down Expand Up @@ -1111,7 +1097,6 @@ def translate_bodies(

@protect_grpc
@check_input_types
@ensure_design_is_active
def create_beams(
self, segments: list[tuple[Point3D, Point3D]], profile: BeamProfile
) -> list[Beam]:
Expand Down Expand Up @@ -1172,7 +1157,6 @@ def create_beam(self, start: Point3D, end: Point3D, profile: BeamProfile) -> Bea

@protect_grpc
@check_input_types
@ensure_design_is_active
def delete_component(self, component: Union["Component", str]) -> None:
"""Delete a component (itself or its children).

Expand Down Expand Up @@ -1207,7 +1191,6 @@ def delete_component(self, component: Union["Component", str]) -> None:

@protect_grpc
@check_input_types
@ensure_design_is_active
def delete_body(self, body: Body | str) -> None:
"""Delete a body belonging to this component (or its children).

Expand Down Expand Up @@ -1259,7 +1242,6 @@ def add_design_point(

@protect_grpc
@check_input_types
@ensure_design_is_active
def add_design_points(
self,
name: str,
Expand Down Expand Up @@ -1295,7 +1277,6 @@ def add_design_points(

@protect_grpc
@check_input_types
@ensure_design_is_active
def delete_beam(self, beam: Beam | str) -> None:
"""Delete an existing beam belonging to this component's scope.

Expand Down
Loading
Loading