From e22e215d16993d673c859e512bd309adf8455651 Mon Sep 17 00:00:00 2001 From: wmayer Date: Fri, 25 Sep 2020 15:07:47 +0200 Subject: [PATCH] Part: implement BSplineSurface.buildFromNSections based on GeomFill_NSections --- src/Mod/Part/App/BSplineSurfacePy.xml | 9 +++- src/Mod/Part/App/BSplineSurfacePyImp.cpp | 61 ++++++++++++++++++++++++ 2 files changed, 69 insertions(+), 1 deletion(-) diff --git a/src/Mod/Part/App/BSplineSurfacePy.xml b/src/Mod/Part/App/BSplineSurfacePy.xml index 817b8d7baa..b53cbecb4c 100644 --- a/src/Mod/Part/App/BSplineSurfacePy.xml +++ b/src/Mod/Part/App/BSplineSurfacePy.xml @@ -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)] - + + + + + Builds a B-Spline from a list of control curves + + + diff --git a/src/Mod/Part/App/BSplineSurfacePyImp.cpp b/src/Mod/Part/App/BSplineSurfacePyImp.cpp index 30d17ba837..45701f8a20 100644 --- a/src/Mod/Part/App/BSplineSurfacePyImp.cpp +++ b/src/Mod/Part/App/BSplineSurfacePyImp.cpp @@ -35,6 +35,7 @@ # include # include #endif +# include #include #include @@ -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(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