Skip to content

Commit

Permalink
Part: implement BSplineSurface.buildFromNSections based on GeomFill_N…
Browse files Browse the repository at this point in the history
…Sections
  • Loading branch information
wwmayer committed Sep 25, 2020
1 parent b44d20d commit 92fe662
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/Mod/Part/App/BSplineSurfacePy.xml
Expand Up @@ -721,6 +721,13 @@
arguments: poles (sequence of sequence of Base.Vector), umults, vmults, [uknots, vknots, uperiodic, vperiodic, udegree, vdegree, weights (sequence of sequence of float)]
</UserDocu>
</Documentation>
</Methode>
</Methode>
<Methode Name="buildFromNSections">
<Documentation>
<UserDocu>
Builds a B-Spline from a list of control curves
</UserDocu>
</Documentation>
</Methode>
</PythonExport>
</GenerateModel>
61 changes: 61 additions & 0 deletions src/Mod/Part/App/BSplineSurfacePyImp.cpp
Expand Up @@ -35,6 +35,7 @@
# include <GeomAPI_PointsToBSplineSurface.hxx>
# include <GeomAbs_Shape.hxx>
#endif
# include <GeomFill_NSections.hxx>

#include <Base/GeometryPyCXX.h>
#include <Base/VectorPy.h>
Expand Down Expand Up @@ -1511,6 +1512,66 @@ PyObject* BSplineSurfacePy::buildFromPolesMultsKnots(PyObject *args, PyObject *k
}
}

/*!
* \code
c = Part.Circle()
c.Radius=50
c = c.trim(0, math.pi)
e1 = Part.Ellipse()
e1.Center = (0, 0, 75)
e1.MajorRadius = 30
e1.MinorRadius = 5
e1 = e1.trim(0, math.pi)
e2 = Part.Ellipse()
e2.Center = (0, 0, 100)
e2.MajorRadius = 20
e2.MinorRadius = 5
e2 = e2.trim(0, math.pi)
bs = Part.BSplineSurface()
bs.buildFromNSections([c, e1, e2])
* \endcode
*/
PyObject* BSplineSurfacePy::buildFromNSections(PyObject *args)
{
PyObject* list;
PyObject* refSurf = Py_False;
if (!PyArg_ParseTuple(args, "O|O!", &list, &PyBool_Type, &refSurf))
return nullptr;

try {
TColGeom_SequenceOfCurve curveSeq;
Py::Sequence curves(list);
for (Py::Sequence::iterator it = curves.begin(); it != curves.end(); ++it) {
Py::Object obj(*it);
if (PyObject_TypeCheck(obj.ptr(), &GeometryCurvePy::Type)) {
GeomCurve* geom = static_cast<GeometryCurvePy*>(obj.ptr())->getGeomCurvePtr();
curveSeq.Append(Handle(Geom_Curve)::DownCast(geom->handle()));
}
}

GeomFill_NSections fillOp(curveSeq);
if (PyObject_IsTrue(refSurf)) {
Handle(Geom_BSplineSurface) ref = Handle(Geom_BSplineSurface)::DownCast
(getGeometryPtr()->handle());
fillOp.SetSurface(ref);
}

fillOp.ComputeSurface();

Handle(Geom_BSplineSurface) aSurf = fillOp.BSplineSurface();
this->getGeomBSplineSurfacePtr()->setHandle(aSurf);
Py_Return;
}
catch (const Standard_Failure& e) {
Standard_CString msg = e.GetMessageString();
PyErr_SetString(PartExceptionOCCError, msg ? msg : "");
return nullptr;
}
}

Py::Long BSplineSurfacePy::getUDegree(void) const
{
Handle(Geom_BSplineSurface) surf = Handle(Geom_BSplineSurface)::DownCast
Expand Down

0 comments on commit 92fe662

Please sign in to comment.