|
25 | 25 |
|
26 | 26 | from ansys.api.dbu.v0.dbumodels_pb2 import EntityIdentifier |
27 | 27 | 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 | +) |
29 | 33 | from ansys.api.geometry.v0.faces_pb2_grpc import FacesStub |
30 | 34 | from ansys.api.geometry.v0.models_pb2 import Edge as GRPCEdge |
31 | 35 | from beartype.typing import TYPE_CHECKING, List |
|
34 | 38 | from ansys.geometry.core.connection.client import GrpcClient |
35 | 39 | from ansys.geometry.core.connection.conversions import grpc_curve_to_curve, grpc_surface_to_surface |
36 | 40 | 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 |
38 | 42 | from ansys.geometry.core.math.point import Point3D |
39 | 43 | 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 |
41 | 45 | from ansys.geometry.core.misc.measurements import DEFAULT_UNITS |
42 | 46 | from ansys.geometry.core.shapes.box_uv import BoxUV |
43 | 47 | from ansys.geometry.core.shapes.curves.trimmed_curve import TrimmedCurve |
@@ -196,6 +200,7 @@ def body(self) -> "Body": |
196 | 200 | return self._body |
197 | 201 |
|
198 | 202 | @property |
| 203 | + @min_backend_version(24, 2, 0) |
199 | 204 | def shape(self) -> TrimmedSurface: |
200 | 205 | """ |
201 | 206 | Underlying trimmed surface of the face. |
@@ -305,7 +310,13 @@ def normal(self, u: float = 0.5, v: float = 0.5) -> UnitVector3D: |
305 | 310 | This :class:`UnitVector3D` object is perpendicular to the surface at the |
306 | 311 | given UV coordinates. |
307 | 312 | """ |
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]) |
309 | 320 |
|
310 | 321 | @protect_grpc |
311 | 322 | 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: |
333 | 344 | :class:`Point3D` |
334 | 345 | object evaluated at the given UV coordinates. |
335 | 346 | """ |
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) |
337 | 354 |
|
338 | 355 | def __grpc_edges_to_edges(self, edges_grpc: List[GRPCEdge]) -> List[Edge]: |
339 | 356 | """ |
|
0 commit comments