Skip to content
Merged
1 change: 1 addition & 0 deletions doc/changelog.d/1171.fixed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
fix: GetSurface and GetCurve not available prior to 24R2
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ Issues = "https://github.com/ansys/pyansys-geometry/issues"
Discussions = "https://github.com/ansys/pyansys-geometry/discussions"
Documentation = "https://geometry.docs.pyansys.com"
Releases = "https://github.com/ansys/pyansys-geometry/releases"
Changelog = "https://github.com/ansys/pyansys-geometry/blob/main/doc/source/changelog.rst"

[tool.flit.module]
name = "ansys.geometry.core"
Expand Down
13 changes: 10 additions & 3 deletions src/ansys/geometry/core/designer/edge.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@

from ansys.geometry.core.connection.client import GrpcClient
from ansys.geometry.core.connection.conversions import grpc_curve_to_curve
from ansys.geometry.core.errors import protect_grpc
from ansys.geometry.core.errors import GeometryRuntimeError, protect_grpc
from ansys.geometry.core.math.point import Point3D
from ansys.geometry.core.misc.checks import ensure_design_is_active
from ansys.geometry.core.misc.checks import ensure_design_is_active, min_backend_version
from ansys.geometry.core.misc.measurements import DEFAULT_UNITS
from ansys.geometry.core.shapes.curves.trimmed_curve import ReversedTrimmedCurve, TrimmedCurve
from ansys.geometry.core.shapes.parameterization import Interval
Expand Down Expand Up @@ -107,6 +107,7 @@ def is_reversed(self) -> bool:
return self._is_reversed

@property
@min_backend_version(24, 2, 0)
def shape(self) -> TrimmedCurve:
"""
Underlying trimmed curve of the edge.
Expand Down Expand Up @@ -142,7 +143,13 @@ def shape(self) -> TrimmedCurve:
@ensure_design_is_active
def length(self) -> Quantity:
"""Calculated length of the edge."""
return self.shape.length
try:
return self.shape.length
except GeometryRuntimeError: # pragma: no cover
# Only for versions < 24.2.0 (i.e. before the introduction of the shape property)
self._grpc_client.log.debug("Requesting edge length from server.")
length_response = self._edges_stub.GetLength(self._grpc_id)
return Quantity(length_response.length, DEFAULT_UNITS.SERVER_LENGTH)

@property
def curve_type(self) -> CurveType:
Expand Down
27 changes: 22 additions & 5 deletions src/ansys/geometry/core/designer/face.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,11 @@

from ansys.api.dbu.v0.dbumodels_pb2 import EntityIdentifier
from ansys.api.geometry.v0.edges_pb2_grpc import EdgesStub
from ansys.api.geometry.v0.faces_pb2 import CreateIsoParamCurvesRequest
from ansys.api.geometry.v0.faces_pb2 import (
CreateIsoParamCurvesRequest,
EvaluateRequest,
GetNormalRequest,
)
from ansys.api.geometry.v0.faces_pb2_grpc import FacesStub
from ansys.api.geometry.v0.models_pb2 import Edge as GRPCEdge
from beartype.typing import TYPE_CHECKING, List
Expand All @@ -34,10 +38,10 @@
from ansys.geometry.core.connection.client import GrpcClient
from ansys.geometry.core.connection.conversions import grpc_curve_to_curve, grpc_surface_to_surface
from ansys.geometry.core.designer.edge import Edge
from ansys.geometry.core.errors import protect_grpc
from ansys.geometry.core.errors import GeometryRuntimeError, protect_grpc
from ansys.geometry.core.math.point import Point3D
from ansys.geometry.core.math.vector import UnitVector3D
from ansys.geometry.core.misc.checks import ensure_design_is_active
from ansys.geometry.core.misc.checks import ensure_design_is_active, min_backend_version
from ansys.geometry.core.misc.measurements import DEFAULT_UNITS
from ansys.geometry.core.shapes.box_uv import BoxUV
from ansys.geometry.core.shapes.curves.trimmed_curve import TrimmedCurve
Expand Down Expand Up @@ -196,6 +200,7 @@ def body(self) -> "Body":
return self._body

@property
@min_backend_version(24, 2, 0)
def shape(self) -> TrimmedSurface:
"""
Underlying trimmed surface of the face.
Expand Down Expand Up @@ -305,7 +310,13 @@ def normal(self, u: float = 0.5, v: float = 0.5) -> UnitVector3D:
This :class:`UnitVector3D` object is perpendicular to the surface at the
given UV coordinates.
"""
return self.shape.normal(u, v)
try:
return self.shape.normal(u, v)
except GeometryRuntimeError: # pragma: no cover
# Only for versions < 24.2.0 (i.e. before the introduction of the shape property)
self._grpc_client.log.debug(f"Requesting face normal from server with (u,v)=({u},{v}).")
response = self._faces_stub.GetNormal(GetNormalRequest(id=self.id, u=u, v=v)).direction
return UnitVector3D([response.x, response.y, response.z])

@protect_grpc
def point(self, u: float = 0.5, v: float = 0.5) -> Point3D:
Expand Down Expand Up @@ -333,7 +344,13 @@ def point(self, u: float = 0.5, v: float = 0.5) -> Point3D:
:class:`Point3D`
object evaluated at the given UV coordinates.
"""
return self.shape.evaluate_proportion(u, v).position
try:
return self.shape.evaluate_proportion(u, v).position
except GeometryRuntimeError: # pragma: no cover
# Only for versions < 24.2.0 (i.e. before the introduction of the shape property)
self._grpc_client.log.debug(f"Requesting face point from server with (u,v)=({u},{v}).")
response = self._faces_stub.Evaluate(EvaluateRequest(id=self.id, u=u, v=v)).point
return Point3D([response.x, response.y, response.z], DEFAULT_UNITS.SERVER_LENGTH)

def __grpc_edges_to_edges(self, edges_grpc: List[GRPCEdge]) -> List[Edge]:
"""
Expand Down