From ee4436b2c02b9e3663c3f8dd64f2bdd3fc5a5aa7 Mon Sep 17 00:00:00 2001 From: wmayer Date: Thu, 15 Jan 2015 11:39:53 +0100 Subject: [PATCH] + add toShape() to Part.Point, allow to pass Part.Point in Part.Vertex --- src/Mod/Part/App/PointPy.xml | 5 ++++ src/Mod/Part/App/PointPyImp.cpp | 29 +++++++++++++++++++++++ src/Mod/Part/App/TopoShapeVertexPyImp.cpp | 15 +++++++++++- 3 files changed, 48 insertions(+), 1 deletion(-) diff --git a/src/Mod/Part/App/PointPy.xml b/src/Mod/Part/App/PointPy.xml index 9ad55f961..e9507efca 100644 --- a/src/Mod/Part/App/PointPy.xml +++ b/src/Mod/Part/App/PointPy.xml @@ -23,6 +23,11 @@ Part.Point(Point) Part.Point(Vector) Creates a line for the given coordinates + + + Create a vertex from this point. + + X component of this point. diff --git a/src/Mod/Part/App/PointPyImp.cpp b/src/Mod/Part/App/PointPyImp.cpp index 91417844a..4219bbd0d 100644 --- a/src/Mod/Part/App/PointPyImp.cpp +++ b/src/Mod/Part/App/PointPyImp.cpp @@ -23,11 +23,13 @@ #include "PreCompiled.h" #ifndef _PreComp_ +# include # include # include # include # include # include +# include #endif #include @@ -36,6 +38,9 @@ #include "Geometry.h" #include "PointPy.h" #include "PointPy.cpp" +#include "OCCError.h" +#include "TopoShape.h" +#include "TopoShapeVertexPy.h" using namespace Part; @@ -99,6 +104,30 @@ int PointPy::PyInit(PyObject* args, PyObject* /*kwd*/) return -1; } +PyObject* PointPy::toShape(PyObject *args) +{ + Handle_Geom_CartesianPoint this_point = Handle_Geom_CartesianPoint::DownCast + (this->getGeomPointPtr()->handle()); + try { + if (!this_point.IsNull()) { + if (!PyArg_ParseTuple(args, "")) + return 0; + + BRepBuilderAPI_MakeVertex mkBuilder(this_point->Pnt()); + const TopoDS_Vertex& sh = mkBuilder.Vertex(); + return new TopoShapeVertexPy(new TopoShape(sh)); + } + } + catch (Standard_Failure) { + Handle_Standard_Failure e = Standard_Failure::Caught(); + PyErr_SetString(PartExceptionOCCError, e->GetMessageString()); + return 0; + } + + PyErr_SetString(PartExceptionOCCError, "Geometry is not a point"); + return 0; +} + Py::Float PointPy::getX(void) const { Handle_Geom_CartesianPoint this_point = Handle_Geom_CartesianPoint::DownCast diff --git a/src/Mod/Part/App/TopoShapeVertexPyImp.cpp b/src/Mod/Part/App/TopoShapeVertexPyImp.cpp index 9be1003bf..848138f22 100644 --- a/src/Mod/Part/App/TopoShapeVertexPyImp.cpp +++ b/src/Mod/Part/App/TopoShapeVertexPyImp.cpp @@ -31,13 +31,14 @@ # include # include # include +# include #endif #include #include #include -#include "TopoShapeEdgePy.h" +#include "PointPy.h" #include "TopoShapeVertexPy.h" #include "TopoShapeVertexPy.cpp" @@ -94,6 +95,18 @@ int TopoShapeVertexPy::PyInit(PyObject* args, PyObject* /*kwd*/) } } } + if (!success) { + PyErr_Clear(); // set by PyArg_ParseTuple() + if (PyArg_ParseTuple(args,"O!",&(PointPy::Type), &object)) { + Handle_Geom_CartesianPoint this_point = Handle_Geom_CartesianPoint::DownCast + (static_cast(object)->getGeomPointPtr()->handle()); + gp_Pnt pnt = this_point->Pnt(); + x = pnt.X(); + y = pnt.Y(); + z = pnt.Z(); + success = true; + } + } if (!success) { PyErr_Clear(); // set by PyArg_ParseTuple() if (PyArg_ParseTuple(args,"O!",&(Part::TopoShapePy::Type), &object)) {