3535 Plane as GRPCPlane ,
3636 Point as GRPCPoint ,
3737 Polygon as GRPCPolygon ,
38+ Quantity as GRPCQuantity ,
3839)
3940from ansys .api .discovery .v1 .design .designmessages_pb2 import (
4041 CurveGeometry as GRPCCurveGeometry ,
5051 Surface as GRPCSurface ,
5152 Tessellation as GRPCTessellation ,
5253 TessellationOptions as GRPCTessellationOptions ,
54+ TrackedCommandResponse as GRPCTrackedCommandResponse ,
5355 TrimmedCurve as GRPCTrimmedCurve ,
5456 TrimmedSurface as GRPCTrimmedSurface ,
5557)
6668
6769from ansys .geometry .core .errors import GeometryRuntimeError
6870from ansys .geometry .core .misc .checks import graphics_required
71+ from ansys .geometry .core .misc .measurements import DEFAULT_UNITS
6972from ansys .geometry .core .shapes .surfaces .nurbs import NURBSSurface
7073
7174if TYPE_CHECKING :
8184 from ansys .geometry .core .math .plane import Plane
8285 from ansys .geometry .core .math .point import Point2D , Point3D
8386 from ansys .geometry .core .math .vector import UnitVector3D
87+ from ansys .geometry .core .misc .measurements import Measurement
8488 from ansys .geometry .core .misc .options import TessellationOptions
8589 from ansys .geometry .core .parameters .parameter import (
8690 Parameter ,
@@ -175,9 +179,9 @@ def from_point3d_to_grpc_point(point: "Point3D") -> GRPCPoint:
175179 from ansys .geometry .core .misc .measurements import DEFAULT_UNITS
176180
177181 return GRPCPoint (
178- x = point .x .m_as (DEFAULT_UNITS .SERVER_LENGTH ),
179- y = point .y .m_as (DEFAULT_UNITS .SERVER_LENGTH ),
180- z = point .z .m_as (DEFAULT_UNITS .SERVER_LENGTH ),
182+ x = GRPCQuantity ( value_in_geometry_units = point .x .m_as (DEFAULT_UNITS .SERVER_LENGTH ) ),
183+ y = GRPCQuantity ( value_in_geometry_units = point .y .m_as (DEFAULT_UNITS .SERVER_LENGTH ) ),
184+ z = GRPCQuantity ( value_in_geometry_units = point .z .m_as (DEFAULT_UNITS .SERVER_LENGTH ) ),
181185 )
182186
183187
@@ -198,7 +202,11 @@ def from_grpc_point_to_point3d(point: GRPCPoint) -> "Point3D":
198202 from ansys .geometry .core .misc .measurements import DEFAULT_UNITS
199203
200204 return Point3D (
201- [point .x , point .y , point .z ],
205+ [
206+ point .x .value_in_geometry_units ,
207+ point .y .value_in_geometry_units ,
208+ point .z .value_in_geometry_units ,
209+ ],
202210 DEFAULT_UNITS .SERVER_LENGTH ,
203211 )
204212
@@ -979,23 +987,26 @@ def from_grpc_curve_to_curve(curve: GRPCCurveGeometry) -> "Curve":
979987 Curve
980988 Resulting converted curve.
981989 """
982- from ansys .geometry .core .math .point import Point3D
983990 from ansys .geometry .core .math .vector import UnitVector3D
984991 from ansys .geometry .core .shapes .curves .circle import Circle
985992 from ansys .geometry .core .shapes .curves .ellipse import Ellipse
986993 from ansys .geometry .core .shapes .curves .line import Line
987994
988- origin = Point3D ([ curve .origin . x , curve . origin . y , curve . origin . z ] )
995+ origin = from_grpc_point_to_point3d ( curve .origin )
989996 try :
990997 reference = UnitVector3D ([curve .reference .x , curve .reference .y , curve .reference .z ])
991998 axis = UnitVector3D ([curve .axis .x , curve .axis .y , curve .axis .z ])
992999 except ValueError :
9931000 # curve will be a line
9941001 pass
995- if curve .radius != 0 :
996- result = Circle (origin , curve .radius , reference , axis )
997- elif curve .major_radius != 0 and curve .minor_radius != 0 :
998- result = Ellipse (origin , curve .major_radius , curve .minor_radius , reference , axis )
1002+
1003+ radius = curve .radius .value_in_geometry_units
1004+ major_radius = curve .major_radius .value_in_geometry_units
1005+ minor_radius = curve .minor_radius .value_in_geometry_units
1006+ if radius != 0 :
1007+ result = Circle (origin , radius , reference , axis )
1008+ elif major_radius != 0 and minor_radius != 0 :
1009+ result = Ellipse (origin , major_radius , minor_radius , reference , axis )
9991010 elif curve .nurbs_curve .nurbs_data .degree != 0 :
10001011 result = from_grpc_nurbs_curve_to_nurbs_curve (curve .nurbs_curve )
10011012 elif curve .direction is not None :
@@ -1284,6 +1295,56 @@ def from_grpc_matrix_to_matrix(matrix: GRPCMatrix) -> "Matrix44":
12841295 )
12851296
12861297
1298+ def from_grpc_direction_to_unit_vector (direction : GRPCDirection ) -> "UnitVector3D" :
1299+ """Convert a gRPC direction to a unit vector.
1300+
1301+ Parameters
1302+ ----------
1303+ direction : GRPCDirection
1304+ Source gRPC direction data.
1305+
1306+ Returns
1307+ -------
1308+ UnitVector3D
1309+ Converted unit vector.
1310+ """
1311+ from ansys .geometry .core .math .vector import UnitVector3D
1312+
1313+ return UnitVector3D ([direction .x , direction .y , direction .z ])
1314+
1315+
1316+ def from_length_to_grpc_quantity (input : "Measurement" ) -> GRPCQuantity :
1317+ """Convert a ``Measurement`` containing a length to a gRPC quantity.
1318+
1319+ Parameters
1320+ ----------
1321+ input : Measurement
1322+ Source measurement data.
1323+
1324+ Returns
1325+ -------
1326+ GRPCQuantity
1327+ Converted gRPC quantity.
1328+ """
1329+ return GRPCQuantity (value_in_geometry_units = input .value .m_as (DEFAULT_UNITS .SERVER_LENGTH ))
1330+
1331+
1332+ def from_angle_to_grpc_quantity (input : "Measurement" ) -> GRPCQuantity :
1333+ """Convert a ``Measurement`` containing an angle to a gRPC quantity.
1334+
1335+ Parameters
1336+ ----------
1337+ input : Measurement
1338+ Source measurement data.
1339+
1340+ Returns
1341+ -------
1342+ GRPCQuantity
1343+ Converted gRPC quantity.
1344+ """
1345+ return GRPCQuantity (value_in_geometry_units = input .value .m_as (DEFAULT_UNITS .SERVER_ANGLE ))
1346+
1347+
12871348def _nurbs_curves_compatibility (backend_version : "semver.Version" , grpc_geometries : GRPCGeometries ):
12881349 """Check if the backend version is compatible with NURBS curves in sketches.
12891350
@@ -1351,18 +1412,18 @@ def from_enclosure_options_to_grpc_enclosure_options(
13511412 )
13521413
13531414
1354- def serialize_tracker_command_response ( ** kwargs ) -> dict :
1355- """Serialize a TrackerCommandResponse object into a dictionary.
1415+ def serialize_tracked_command_response ( response : GRPCTrackedCommandResponse ) -> dict :
1416+ """Serialize a TrackedCommandResponse object into a dictionary.
13561417
13571418 Parameters
13581419 ----------
1359- response : TrackerCommandResponse
1360- The gRPC TrackerCommandResponse object to serialize.
1420+ response : GRPCTrackedCommandResponse
1421+ The gRPC TrackedCommandResponse object to serialize.
13611422
13621423 Returns
13631424 -------
13641425 dict
1365- A dictionary representation of the TrackerCommandResponse object.
1426+ A dictionary representation of the TrackedCommandResponse object.
13661427 """
13671428
13681429 def serialize_body (body ):
@@ -1387,17 +1448,17 @@ def serialize_entity_identifier(entity):
13871448 "id" : entity .id ,
13881449 }
13891450
1390- response = kwargs ["response" ]
13911451 return {
1392- "success" : response .success ,
1452+ "success" : getattr ( response .command_response , " success" , False ) ,
13931453 "created_bodies" : [
1394- serialize_body (body ) for body in getattr (response , "created_bodies" , [])
1454+ serialize_body (body ) for body in getattr (response . tracked_changes , "created_bodies" , [])
13951455 ],
13961456 "modified_bodies" : [
1397- serialize_body (body ) for body in getattr (response , "modified_bodies" , [])
1457+ serialize_body (body )
1458+ for body in getattr (response .tracked_changes , "modified_bodies" , [])
13981459 ],
13991460 "deleted_bodies" : [
14001461 serialize_entity_identifier (entity )
1401- for entity in getattr (response , "deleted_bodies" , [])
1462+ for entity in getattr (response . tracked_changes , "deleted_bodies" , [])
14021463 ],
14031464 }
0 commit comments