40
40
Ellipse as GRPCEllipse ,
41
41
Frame as GRPCFrame ,
42
42
Geometries as GRPCGeometries ,
43
+ Knot as GRPCKnot ,
43
44
Line as GRPCLine ,
44
45
Material as GRPCMaterial ,
45
46
MaterialProperty as GRPCMaterialProperty ,
47
+ NurbsCurve as GRPCNurbsCurve ,
46
48
Plane as GRPCPlane ,
47
49
Point as GRPCPoint ,
48
50
Polygon as GRPCPolygon ,
73
75
ParameterUpdateStatus ,
74
76
)
75
77
from ansys .geometry .core .shapes .curves .curve import Curve
78
+ from ansys .geometry .core .shapes .curves .nurbs import NURBSCurve
76
79
from ansys .geometry .core .shapes .curves .trimmed_curve import TrimmedCurve
77
80
from ansys .geometry .core .shapes .surfaces .surface import Surface
78
81
from ansys .geometry .core .shapes .surfaces .trimmed_surface import TrimmedSurface
@@ -621,6 +624,7 @@ def from_curve_to_grpc_curve(curve: "Curve") -> GRPCCurveGeometry:
621
624
from ansys .geometry .core .shapes .curves .circle import Circle
622
625
from ansys .geometry .core .shapes .curves .ellipse import Ellipse
623
626
from ansys .geometry .core .shapes .curves .line import Line
627
+ from ansys .geometry .core .shapes .curves .nurbs import NURBSCurve
624
628
625
629
grpc_curve = None
626
630
@@ -645,12 +649,88 @@ def from_curve_to_grpc_curve(curve: "Curve") -> GRPCCurveGeometry:
645
649
major_radius = curve .major_radius .m ,
646
650
minor_radius = curve .minor_radius .m ,
647
651
)
652
+ elif isinstance (curve , NURBSCurve ):
653
+ grpc_curve = GRPCCurveGeometry (nurbs_curve = from_nurbs_curve_to_grpc_nurbs_curve (curve ))
648
654
else :
649
655
raise ValueError (f"Unsupported curve type: { type (curve )} " )
650
656
651
657
return grpc_curve
652
658
653
659
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
+
654
734
def from_grpc_curve_to_curve (curve : GRPCCurveGeometry ) -> "Curve" :
655
735
"""Convert a curve gRPC message to a ``Curve``.
656
736
0 commit comments