1313from OCC .Core .BRepAlgo import brepalgo_IsValid
1414from OCC .Core .BRepGProp import brepgprop_LinearProperties
1515from OCC .Core .GProp import GProp_GProps
16+ from OCC .Core .GeomConvert import GeomConvert_ApproxCurve
17+ from OCC .Core .GeomAbs import GeomAbs_Shape
1618
1719from compas .data import Data
1820from compas .geometry import Point
@@ -106,32 +108,51 @@ def __init__(self, occ_edge: TopoDS_Edge = None):
106108
107109 @property
108110 def data (self ):
109- if self .is_line :
110- line = compas_line_from_occ_line (self .occ_adaptor .Line ())
111- data = {
112- "type" : "line" ,
113- "value" : line .data ,
114- "points" : [self .vertices [0 ].point , self .vertices [- 1 ].point ],
115- }
116- elif self .is_circle :
117- circle = compas_circle_from_occ_circle (self .occ_adaptor .Circle ())
118- data = {
119- "type" : "circle" ,
120- "value" : circle .data ,
111+ if self .is_bspline :
112+ curve = self .nurbscurve
113+ return {
114+ "type" : "nurbs" ,
115+ "value" : curve .data ,
121116 "points" : [self .vertices [0 ].point , self .vertices [- 1 ].point ],
122117 }
123- else :
124- curve = self .nurbscurve
118+
119+ try :
120+ convert = GeomConvert_ApproxCurve (
121+ self .curve , 1e-3 , GeomAbs_Shape .GeomAbs_C1 , 1 , 5
122+ )
123+ curve = OCCNurbsCurve ()
124+ curve .occ_curve = convert .Curve ()
125125 data = {
126126 "type" : "nurbs" ,
127127 "value" : curve .data ,
128128 "points" : [self .vertices [0 ].point , self .vertices [- 1 ].point ],
129129 }
130+ except Exception :
131+ if self .is_line :
132+ line = compas_line_from_occ_line (self .occ_adaptor .Line ())
133+ data = {
134+ "type" : "line" ,
135+ "value" : line .data ,
136+ "points" : [self .vertices [0 ].point , self .vertices [- 1 ].point ],
137+ }
138+ elif self .is_circle :
139+ circle = compas_circle_from_occ_circle (self .occ_adaptor .Circle ())
140+ data = {
141+ "type" : "circle" ,
142+ "value" : circle .data ,
143+ "points" : [self .vertices [0 ].point , self .vertices [- 1 ].point ],
144+ }
145+ else :
146+ raise
130147 return data
131148
132149 @data .setter
133150 def data (self , data ):
134- if data ["type" ] == "line" :
151+ if data ["type" ] == "nurbs" :
152+ curve = OCCNurbsCurve .from_data (data ["value" ])
153+ points = data ["points" ]
154+ edge = BRepEdge .from_curve (curve , points = points )
155+ elif data ["type" ] == "line" :
135156 line = Line .from_data (data ["value" ])
136157 points = data ["points" ]
137158 edge = BRepEdge .from_line (line , points = points )
@@ -140,9 +161,7 @@ def data(self, data):
140161 points = data ["points" ]
141162 edge = BRepEdge .from_circle (circle , points = points )
142163 else :
143- curve = OCCNurbsCurve .from_data (data ["value" ])
144- points = data ["points" ]
145- edge = BRepEdge .from_curve (curve , points = points )
164+ raise NotImplementedError
146165 self .occ_edge = edge .occ_edge
147166
148167 # ==============================================================================
0 commit comments