From f43f70f395c14f2310ae2e3569fb677f255353ad Mon Sep 17 00:00:00 2001 From: wmayer Date: Mon, 8 Apr 2013 12:54:46 +0200 Subject: [PATCH] Implement GeometryCurvePy::length --- src/Mod/Part/App/GeometryCurvePy.xml | 6 ++++++ src/Mod/Part/App/GeometryCurvePyImp.cpp | 26 +++++++++++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/src/Mod/Part/App/GeometryCurvePy.xml b/src/Mod/Part/App/GeometryCurvePy.xml index 78090909c..e4308eb72 100644 --- a/src/Mod/Part/App/GeometryCurvePy.xml +++ b/src/Mod/Part/App/GeometryCurvePy.xml @@ -26,6 +26,12 @@ Discretizes the curve using a given deflection or number of points and returns a list of points + + + Computes the length of a curve +length([uMin,uMax,Tol]) -> Float + + Computes the point of parameter u on this curve diff --git a/src/Mod/Part/App/GeometryCurvePyImp.cpp b/src/Mod/Part/App/GeometryCurvePyImp.cpp index 01f91500a..78d3efcf2 100644 --- a/src/Mod/Part/App/GeometryCurvePyImp.cpp +++ b/src/Mod/Part/App/GeometryCurvePyImp.cpp @@ -28,6 +28,7 @@ # include # include # include +# include # include # include # include @@ -156,6 +157,31 @@ PyObject* GeometryCurvePy::discretize(PyObject *args) return 0; } +PyObject* GeometryCurvePy::length(PyObject *args) +{ + Handle_Geom_Geometry g = getGeometryPtr()->handle(); + Handle_Geom_Curve c = Handle_Geom_Curve::DownCast(g); + try { + if (!c.IsNull()) { + double u=c->FirstParameter(); + double v=c->LastParameter(); + double t=Precision::Confusion(); + if (!PyArg_ParseTuple(args, "|ddd", &u,&v,&t)) + return 0; + double len = GCPnts_AbscissaPoint::Length(GeomAdaptor_Curve(c),u,v,t); + return PyFloat_FromDouble(len); + } + } + 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; +} + PyObject* GeometryCurvePy::value(PyObject *args) { Handle_Geom_Geometry g = getGeometryPtr()->handle();