Skip to content

Commit 3245b0c

Browse files
committed
Add static method write_edge in NurbsHandler
1 parent 5b090d8 commit 3245b0c

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

pygem/nurbshandler.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -398,6 +398,43 @@ def parse_shape(self, filename):
398398

399399
return l_shells
400400

401+
@staticmethod
402+
def write_edge(points_edge, topo_edge):
403+
"""
404+
Method to recreate an Edge associated to a geometric curve
405+
after the modification of its points.
406+
:param points_edge: the deformed points array.
407+
:param topo_edge: the Edge to be modified
408+
:return: Edge (Shape)
409+
410+
:rtype: TopoDS_Edge
411+
412+
"""
413+
# convert Edge to Geom B-spline Curve
414+
nurbs_converter = BRepBuilderAPI_NurbsConvert(topo_edge)
415+
nurbs_converter.Perform(topo_edge)
416+
nurbs_curve = nurbs_converter.Shape()
417+
topo_curve = OCC.TopoDS.topods_Edge(nurbs_curve)
418+
h_geomcurve, param_min, param_max = BRep_Tool.Curve(topo_curve)
419+
h_bcurve = geomconvert_CurveToBSplineCurve(h_geomcurve)
420+
bspline_edge_curve = h_bcurve.GetObject()
421+
422+
# Edge geometric properties
423+
nb_cpt = bspline_edge_curve.NbPoles()
424+
# check consistency
425+
if points_edge.shape[0] != nb_cpt:
426+
raise ValueError("Input control points do not have not have the "
427+
"same number as the geometric edge!")
428+
429+
else:
430+
for i in range(1, nb_cpt + 1):
431+
cpt = points_edge[i - 1]
432+
bspline_edge_curve.SetPole(i, gp_Pnt(cpt[0], cpt[1], cpt[2]))
433+
434+
new_edge = BRepBuilderAPI_MakeEdge(bspline_edge_curve.GetHandle())
435+
436+
return new_edge.Edge()
437+
401438
def write_shape_to_file(self, shape, filename):
402439
"""
403440
Abstract method to write the 'shape' to the `filename`.

0 commit comments

Comments
 (0)