From d22772d5fd7899d83c2388188ed92865f6e1a33f Mon Sep 17 00:00:00 2001 From: wmayer Date: Thu, 24 Oct 2013 17:30:38 +0200 Subject: [PATCH] + Method to convert any curve into B-Spline --- src/Mod/Part/App/GeometryCurvePy.xml | 8 +++++++ src/Mod/Part/App/GeometryCurvePyImp.cpp | 28 +++++++++++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/src/Mod/Part/App/GeometryCurvePy.xml b/src/Mod/Part/App/GeometryCurvePy.xml index e4308eb72..925686b51 100644 --- a/src/Mod/Part/App/GeometryCurvePy.xml +++ b/src/Mod/Part/App/GeometryCurvePy.xml @@ -58,6 +58,14 @@ length([uMin,uMax,Tol]) -> Float of the nearest orthogonal projection of the point. + + + + Converts a curve of any type (only part from First to Last) + toBSpline([Float=First, Float=Last]) -> B-Spline curve + + + diff --git a/src/Mod/Part/App/GeometryCurvePyImp.cpp b/src/Mod/Part/App/GeometryCurvePyImp.cpp index 45b35f1da..b52b2a1ee 100644 --- a/src/Mod/Part/App/GeometryCurvePyImp.cpp +++ b/src/Mod/Part/App/GeometryCurvePyImp.cpp @@ -43,6 +43,7 @@ # include # include # include +# include #endif #include @@ -54,6 +55,7 @@ #include "RectangularTrimmedSurfacePy.h" #include "BSplineSurfacePy.h" #include "PlanePy.h" +#include "BSplineCurvePy.h" #include "TopoShape.h" #include "TopoShapePy.h" @@ -339,6 +341,32 @@ PyObject* GeometryCurvePy::intersect2d(PyObject *args) } } +PyObject* GeometryCurvePy::toBSpline(PyObject * args) +{ + Handle_Geom_Geometry g = getGeometryPtr()->handle(); + Handle_Geom_Curve c = Handle_Geom_Curve::DownCast(g); + try { + if (!c.IsNull()) { + double u,v; + u=c->FirstParameter(); + v=c->LastParameter(); + if (!PyArg_ParseTuple(args, "|dd", &u,&v)) + return 0; + ShapeConstruct_Curve scc; + Handle_Geom_BSplineCurve spline = scc.ConvertToBSpline(c, u, v, Precision::Confusion()); + return new BSplineCurvePy(new GeomBSplineCurve(spline)); + } + } + catch (Standard_Failure) { + Handle_Standard_Failure e = Standard_Failure::Caught(); + PyErr_SetString(PyExc_Exception, e->GetMessageString()); + return 0; + } + + PyErr_SetString(PyExc_Exception, "Geometry is not a curve"); + return 0; +} + Py::Float GeometryCurvePy::getFirstParameter(void) const { return Py::Float(Handle_Geom_Curve::DownCast