Skip to content

Commit cf3d620

Browse files
RobPasMuepre-commit-ci[bot]pyansys-ci-botPipKat
authored
fix: GetSurface and GetCurve not available prior to 24R2 (#1171)
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: pyansys-ci-bot <pyansys.github.bot@ansys.com> Co-authored-by: Kathy Pippert <84872299+PipKat@users.noreply.github.com>
1 parent 4f4a656 commit cf3d620

File tree

6 files changed

+45
-17
lines changed

6 files changed

+45
-17
lines changed

doc/changelog.d/1171.fixed.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
fix: GetSurface and GetCurve not available prior to 24R2

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ Issues = "https://github.com/ansys/pyansys-geometry/issues"
102102
Discussions = "https://github.com/ansys/pyansys-geometry/discussions"
103103
Documentation = "https://geometry.docs.pyansys.com"
104104
Releases = "https://github.com/ansys/pyansys-geometry/releases"
105+
Changelog = "https://github.com/ansys/pyansys-geometry/blob/main/doc/source/changelog.rst"
105106

106107
[tool.flit.module]
107108
name = "ansys.geometry.core"

src/ansys/geometry/core/connection/client.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import grpc
3434
from grpc._channel import _InactiveRpcError
3535
from grpc_health.v1 import health_pb2, health_pb2_grpc
36+
import semver
3637

3738
from ansys.geometry.core.connection.backend import BackendType
3839
from ansys.geometry.core.connection.defaults import DEFAULT_HOST, DEFAULT_PORT, MAX_MESSAGE_LENGTH
@@ -193,10 +194,12 @@ def __init__(
193194
# retrieve the backend version
194195
if hasattr(grpc_backend_response, "version"):
195196
ver = grpc_backend_response.version
196-
self._backend_version = f"{ver.major_release}.{ver.minor_release}.{ver.service_pack}"
197+
self._backend_version = semver.Version(
198+
ver.major_release, ver.minor_release, ver.service_pack
199+
)
197200
else:
198201
logger.warning("The backend version is only available after 24.1 version.")
199-
self._backend_version = "24.1.0"
202+
self._backend_version = semver.Version(24, 1, 0)
200203

201204
@property
202205
def backend_type(self) -> BackendType:
@@ -214,15 +217,14 @@ def backend_type(self) -> BackendType:
214217
return self._backend_type
215218

216219
@property
217-
def backend_version(self) -> str:
220+
def backend_version(self) -> semver.Version:
218221
"""
219222
Get the current backend version.
220223
221224
Returns
222225
-------
223-
str
224-
Backend version in semantic versioning format (that is, Ansys 24R1 SP2
225-
would be ``24.1.2``).
226+
semver.Version
227+
Backend version.
226228
"""
227229
return self._backend_version
228230

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

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@
3030

3131
from ansys.geometry.core.connection.client import GrpcClient
3232
from ansys.geometry.core.connection.conversions import grpc_curve_to_curve
33-
from ansys.geometry.core.errors import protect_grpc
33+
from ansys.geometry.core.errors import GeometryRuntimeError, protect_grpc
3434
from ansys.geometry.core.math.point import Point3D
35-
from ansys.geometry.core.misc.checks import ensure_design_is_active
35+
from ansys.geometry.core.misc.checks import ensure_design_is_active, min_backend_version
3636
from ansys.geometry.core.misc.measurements import DEFAULT_UNITS
3737
from ansys.geometry.core.shapes.curves.trimmed_curve import ReversedTrimmedCurve, TrimmedCurve
3838
from ansys.geometry.core.shapes.parameterization import Interval
@@ -107,6 +107,7 @@ def is_reversed(self) -> bool:
107107
return self._is_reversed
108108

109109
@property
110+
@min_backend_version(24, 2, 0)
110111
def shape(self) -> TrimmedCurve:
111112
"""
112113
Underlying trimmed curve of the edge.
@@ -142,7 +143,13 @@ def shape(self) -> TrimmedCurve:
142143
@ensure_design_is_active
143144
def length(self) -> Quantity:
144145
"""Calculated length of the edge."""
145-
return self.shape.length
146+
try:
147+
return self.shape.length
148+
except GeometryRuntimeError: # pragma: no cover
149+
# Only for versions earlier than 24.2.0 (before the introduction of the shape property)
150+
self._grpc_client.log.debug("Requesting edge length from server.")
151+
length_response = self._edges_stub.GetLength(self._grpc_id)
152+
return Quantity(length_response.length, DEFAULT_UNITS.SERVER_LENGTH)
146153

147154
@property
148155
def curve_type(self) -> CurveType:

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

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,11 @@
2525

2626
from ansys.api.dbu.v0.dbumodels_pb2 import EntityIdentifier
2727
from ansys.api.geometry.v0.edges_pb2_grpc import EdgesStub
28-
from ansys.api.geometry.v0.faces_pb2 import CreateIsoParamCurvesRequest
28+
from ansys.api.geometry.v0.faces_pb2 import (
29+
CreateIsoParamCurvesRequest,
30+
EvaluateRequest,
31+
GetNormalRequest,
32+
)
2933
from ansys.api.geometry.v0.faces_pb2_grpc import FacesStub
3034
from ansys.api.geometry.v0.models_pb2 import Edge as GRPCEdge
3135
from beartype.typing import TYPE_CHECKING, List
@@ -34,10 +38,10 @@
3438
from ansys.geometry.core.connection.client import GrpcClient
3539
from ansys.geometry.core.connection.conversions import grpc_curve_to_curve, grpc_surface_to_surface
3640
from ansys.geometry.core.designer.edge import Edge
37-
from ansys.geometry.core.errors import protect_grpc
41+
from ansys.geometry.core.errors import GeometryRuntimeError, protect_grpc
3842
from ansys.geometry.core.math.point import Point3D
3943
from ansys.geometry.core.math.vector import UnitVector3D
40-
from ansys.geometry.core.misc.checks import ensure_design_is_active
44+
from ansys.geometry.core.misc.checks import ensure_design_is_active, min_backend_version
4145
from ansys.geometry.core.misc.measurements import DEFAULT_UNITS
4246
from ansys.geometry.core.shapes.box_uv import BoxUV
4347
from ansys.geometry.core.shapes.curves.trimmed_curve import TrimmedCurve
@@ -196,6 +200,7 @@ def body(self) -> "Body":
196200
return self._body
197201

198202
@property
203+
@min_backend_version(24, 2, 0)
199204
def shape(self) -> TrimmedSurface:
200205
"""
201206
Underlying trimmed surface of the face.
@@ -305,7 +310,13 @@ def normal(self, u: float = 0.5, v: float = 0.5) -> UnitVector3D:
305310
This :class:`UnitVector3D` object is perpendicular to the surface at the
306311
given UV coordinates.
307312
"""
308-
return self.shape.normal(u, v)
313+
try:
314+
return self.shape.normal(u, v)
315+
except GeometryRuntimeError: # pragma: no cover
316+
# Only for versions earlier than 24.2.0 (before the introduction of the shape property)
317+
self._grpc_client.log.debug(f"Requesting face normal from server with (u,v)=({u},{v}).")
318+
response = self._faces_stub.GetNormal(GetNormalRequest(id=self.id, u=u, v=v)).direction
319+
return UnitVector3D([response.x, response.y, response.z])
309320

310321
@protect_grpc
311322
def point(self, u: float = 0.5, v: float = 0.5) -> Point3D:
@@ -333,7 +344,13 @@ def point(self, u: float = 0.5, v: float = 0.5) -> Point3D:
333344
:class:`Point3D`
334345
object evaluated at the given UV coordinates.
335346
"""
336-
return self.shape.evaluate_proportion(u, v).position
347+
try:
348+
return self.shape.evaluate_proportion(u, v).position
349+
except GeometryRuntimeError: # pragma: no cover
350+
# Only for versions earlier than 24.2.0 (before the introduction of the shape property)
351+
self._grpc_client.log.debug(f"Requesting face point from server with (u,v)=({u},{v}).")
352+
response = self._faces_stub.Evaluate(EvaluateRequest(id=self.id, u=u, v=v)).point
353+
return Point3D([response.x, response.y, response.z], DEFAULT_UNITS.SERVER_LENGTH)
337354

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

src/ansys/geometry/core/misc/checks.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -331,19 +331,19 @@ def min_backend_version(major: int, minor: int, service_pack: int):
331331

332332
def backend_version_decorator(method):
333333
def wrapper(self, *args, **kwargs):
334-
method_version = f"{major}.{minor}.{service_pack}"
334+
method_version = semver.Version(major, minor, service_pack)
335335
if hasattr(self, "_grpc_client"):
336336
if self._grpc_client is None:
337337
raise GeometryRuntimeError(
338338
"The client is not available. You must initialize the client first."
339339
)
340340
elif self._grpc_client.backend_version is not None:
341-
comp = semver.compare(method_version, self._grpc_client.backend_version)
341+
comp = method_version.compare(self._grpc_client.backend_version)
342342
# if comp is 1, method version is higher than backend version.
343343
if comp == 1:
344344

345345
# Check if the version is "0.0.0" (i.e., the version is not available)
346-
if self._grpc_client.backend_version == "0.0.0":
346+
if str(self._grpc_client.backend_version) == "0.0.0":
347347
raise GeometryRuntimeError(
348348
f"The method '{method.__name__}' requires a minimum Ansys release version of " # noqa: E501
349349
+ f"{method_version}, but the current version used is 24.1.0 or lower." # noqa: E501

0 commit comments

Comments
 (0)