From 5fb7faeeeff205d69d687c795e85c1e02a9ac8b2 Mon Sep 17 00:00:00 2001 From: wmayer Date: Thu, 4 Aug 2016 14:44:40 +0200 Subject: [PATCH] expose getFacesFromSubelement to Python --- src/App/ComplexGeoDataPy.xml | 9 +++++-- src/App/ComplexGeoDataPyImp.cpp | 44 +++++++++++++++++++++++++++++++-- 2 files changed, 49 insertions(+), 4 deletions(-) diff --git a/src/App/ComplexGeoDataPy.xml b/src/App/ComplexGeoDataPy.xml index ca9664bc4..f65ca406a 100644 --- a/src/App/ComplexGeoDataPy.xml +++ b/src/App/ComplexGeoDataPy.xml @@ -14,7 +14,12 @@ Father of all complex geometric data types - + + + Return vertexes and faces from a sub-element + + + Get the BoundBox of the object @@ -33,4 +38,4 @@ - + diff --git a/src/App/ComplexGeoDataPyImp.cpp b/src/App/ComplexGeoDataPyImp.cpp index 9b95b4a85..0d74a2b3a 100644 --- a/src/App/ComplexGeoDataPyImp.cpp +++ b/src/App/ComplexGeoDataPyImp.cpp @@ -26,11 +26,12 @@ #include "ComplexGeoData.h" // inclusion of the generated files (generated out of ComplexGeoDataPy.xml) -#include "ComplexGeoDataPy.h" -#include "ComplexGeoDataPy.cpp" +#include +#include #include #include #include +#include #include using namespace Data; @@ -42,6 +43,45 @@ std::string ComplexGeoDataPy::representation(void) const return std::string(""); } +PyObject* ComplexGeoDataPy::getFacesFromSubelement(PyObject *args) +{ + char *type; + int index; + if (!PyArg_ParseTuple(args, "si", &type, &index)) + return 0; + + std::vector points; + std::vector normals; + std::vector facets; + try { + Data::Segment* segm = getComplexGeoDataPtr()->getSubElement(type, index); + getComplexGeoDataPtr()->getFacesFromSubelement(segm, points, normals, facets); + delete segm; + } + catch (...) { + PyErr_SetString(PyExc_RuntimeError, "failed to get sub-element from object"); + return 0; + } + + Py::Tuple tuple(2); + Py::List vertex; + for (std::vector::const_iterator it = points.begin(); + it != points.end(); ++it) + vertex.append(Py::Object(new Base::VectorPy(*it))); + tuple.setItem(0, vertex); + Py::List facet; + for (std::vector::const_iterator + it = facets.begin(); it != facets.end(); ++it) { + Py::Tuple f(3); + f.setItem(0,Py::Int((int)it->I1)); + f.setItem(1,Py::Int((int)it->I2)); + f.setItem(2,Py::Int((int)it->I3)); + facet.append(f); + } + tuple.setItem(1, facet); + return Py::new_reference_to(tuple); +} + Py::Object ComplexGeoDataPy::getBoundBox(void) const { return Py::BoundingBox(getComplexGeoDataPtr()->getBoundBox());