4040 Ellipse as GRPCEllipse ,
4141 Frame as GRPCFrame ,
4242 Geometries as GRPCGeometries ,
43+ Knot as GRPCKnot ,
4344 Line as GRPCLine ,
4445 Material as GRPCMaterial ,
4546 MaterialProperty as GRPCMaterialProperty ,
47+ NurbsCurve as GRPCNurbsCurve ,
4648 Plane as GRPCPlane ,
4749 Point as GRPCPoint ,
4850 Polygon as GRPCPolygon ,
7375 ParameterUpdateStatus ,
7476 )
7577 from ansys .geometry .core .shapes .curves .curve import Curve
78+ from ansys .geometry .core .shapes .curves .nurbs import NURBSCurve
7679 from ansys .geometry .core .shapes .curves .trimmed_curve import TrimmedCurve
7780 from ansys .geometry .core .shapes .surfaces .surface import Surface
7881 from ansys .geometry .core .shapes .surfaces .trimmed_surface import TrimmedSurface
@@ -621,6 +624,7 @@ def from_curve_to_grpc_curve(curve: "Curve") -> GRPCCurveGeometry:
621624 from ansys .geometry .core .shapes .curves .circle import Circle
622625 from ansys .geometry .core .shapes .curves .ellipse import Ellipse
623626 from ansys .geometry .core .shapes .curves .line import Line
627+ from ansys .geometry .core .shapes .curves .nurbs import NURBSCurve
624628
625629 grpc_curve = None
626630
@@ -645,12 +649,88 @@ def from_curve_to_grpc_curve(curve: "Curve") -> GRPCCurveGeometry:
645649 major_radius = curve .major_radius .m ,
646650 minor_radius = curve .minor_radius .m ,
647651 )
652+ elif isinstance (curve , NURBSCurve ):
653+ grpc_curve = GRPCCurveGeometry (nurbs_curve = from_nurbs_curve_to_grpc_nurbs_curve (curve ))
648654 else :
649655 raise ValueError (f"Unsupported curve type: { type (curve )} " )
650656
651657 return grpc_curve
652658
653659
660+ def from_nurbs_curve_to_grpc_nurbs_curve (curve : "NURBSCurve" ) -> GRPCNurbsCurve :
661+ """Convert a ``NURBSCurve`` to a NURBS curve gRPC message.
662+
663+ Parameters
664+ ----------
665+ curve : NURBSCurve
666+ Curve to convert.
667+
668+ Returns
669+ -------
670+ GRPCNurbsCurve
671+ Geometry service gRPC ``NURBSCurve`` message.
672+ """
673+ from ansys .api .geometry .v0 .models_pb2 import (
674+ ControlPoint as GRPCControlPoint ,
675+ NurbsData as GRPCNurbsData ,
676+ )
677+
678+ # Convert control points
679+ control_points = [
680+ GRPCControlPoint (
681+ position = from_point3d_to_grpc_point (pt ),
682+ weight = curve .weights [i ],
683+ )
684+ for i , pt in enumerate (curve .control_points )
685+ ]
686+
687+ # Convert nurbs data
688+ nurbs_data = GRPCNurbsData (
689+ degree = curve .degree ,
690+ knots = from_knots_to_grpc_knots (curve .knots ),
691+ order = curve .degree + 1 ,
692+ )
693+
694+ return GRPCNurbsCurve (
695+ control_points = control_points ,
696+ nurbs_data = nurbs_data ,
697+ )
698+
699+
700+ def from_knots_to_grpc_knots (knots : list [float ]) -> list [GRPCKnot ]:
701+ """Convert a list of knots to a list of gRPC knot messages.
702+
703+ Parameters
704+ ----------
705+ knots : list[float]
706+ Source knots data.
707+
708+ Returns
709+ -------
710+ list[GRPCKnot]
711+ Geometry service gRPC knot messages.
712+ """
713+ from collections import Counter
714+
715+ # Count multiplicities
716+ multiplicities = Counter (knots )
717+
718+ # Get unique knots (parameters) in order
719+ unique_knots = sorted (set (knots ))
720+ knot_multiplicities = [(knot , multiplicities [knot ]) for knot in unique_knots ]
721+
722+ # Convert to gRPC knot messages
723+ grpc_knots = [
724+ GRPCKnot (
725+ parameter = knot ,
726+ multiplicity = multiplicity ,
727+ )
728+ for knot , multiplicity in knot_multiplicities
729+ ]
730+
731+ return grpc_knots
732+
733+
654734def from_grpc_curve_to_curve (curve : GRPCCurveGeometry ) -> "Curve" :
655735 """Convert a curve gRPC message to a ``Curve``.
656736
0 commit comments