From 1bb663c8974e39fa3e9d6839d47d48078c167d85 Mon Sep 17 00:00:00 2001 From: wmayer Date: Tue, 17 Jan 2012 15:08:47 +0000 Subject: [PATCH] + add method to get intersection of two curves git-svn-id: https://free-cad.svn.sourceforge.net/svnroot/free-cad/trunk@5414 e8eeb9e2-ec13-0410-a4a9-efa5cf37419d --- src/Mod/Part/App/GeometryCurvePy.xml | 5 ++++ src/Mod/Part/App/GeometryCurvePyImp.cpp | 40 +++++++++++++++++++++++++ 2 files changed, 45 insertions(+) diff --git a/src/Mod/Part/App/GeometryCurvePy.xml b/src/Mod/Part/App/GeometryCurvePy.xml index 1b3b48e86..eaae3fb19 100644 --- a/src/Mod/Part/App/GeometryCurvePy.xml +++ b/src/Mod/Part/App/GeometryCurvePy.xml @@ -41,6 +41,11 @@ Make a ruled surface of this and the given curves + + + Get intersection points with another curve lying on a plane. + + Returns the parameter on the curve diff --git a/src/Mod/Part/App/GeometryCurvePyImp.cpp b/src/Mod/Part/App/GeometryCurvePyImp.cpp index 55d1a9a76..2c9deb4e6 100644 --- a/src/Mod/Part/App/GeometryCurvePyImp.cpp +++ b/src/Mod/Part/App/GeometryCurvePyImp.cpp @@ -26,9 +26,13 @@ # include # include # include +# include # include +# include +# include # include # include +# include # include # include # include @@ -48,6 +52,7 @@ #include "GeometryCurvePy.cpp" #include "RectangularTrimmedSurfacePy.h" #include "BSplineSurfacePy.h" +#include "PlanePy.h" #include "TopoShape.h" #include "TopoShapePy.h" @@ -261,6 +266,41 @@ PyObject* GeometryCurvePy::makeRuledSurface(PyObject *args) return 0; } +PyObject* GeometryCurvePy::intersect2d(PyObject *args) +{ + PyObject *c,*p; + if (!PyArg_ParseTuple(args, "O!O!", &(Part::GeometryCurvePy::Type), &c, + &(Part::PlanePy::Type), &p)) + return 0; + + try { + Handle_Geom_Curve self = Handle_Geom_Curve::DownCast(getGeometryPtr()->handle()); + Handle_Geom_Curve curv = Handle_Geom_Curve::DownCast(static_cast(c)-> + getGeometryPtr()->handle()); + Handle_Geom_Plane plane = Handle_Geom_Plane::DownCast(static_cast(p)-> + getGeometryPtr()->handle()); + + Handle_Geom2d_Curve curv1 = GeomAPI::To2d(self, plane->Pln()); + Handle_Geom2d_Curve curv2 = GeomAPI::To2d(curv, plane->Pln()); + Geom2dAPI_InterCurveCurve intCC(curv1, curv2); + int nbPoints = intCC.NbPoints(); + Py::List list; + for (int i=1; i<= nbPoints; i++) { + gp_Pnt2d pt = intCC.Point(i); + Py::Tuple tuple(2); + tuple.setItem(0, Py::Float(pt.X())); + tuple.setItem(1, Py::Float(pt.Y())); + list.append(tuple); + } + return Py::new_reference_to(list); + } + catch (Standard_Failure) { + Handle_Standard_Failure e = Standard_Failure::Caught(); + PyErr_SetString(PyExc_Exception, e->GetMessageString()); + return 0; + } +} + Py::Float GeometryCurvePy::getFirstParameter(void) const { return Py::Float(Handle_Geom_Curve::DownCast