From 331817d1b7393e748cbb0b4ceace761d2ee6d330 Mon Sep 17 00:00:00 2001 From: Abdullah Tahiri Date: Mon, 11 Feb 2019 17:42:43 +0100 Subject: [PATCH] Part: Geometry extension set with unique id (type+name) and list based getExtensions python --- src/Mod/Part/App/Geometry.cpp | 6 ++++-- src/Mod/Part/App/GeometryPy.xml | 2 +- src/Mod/Part/App/GeometryPyImp.cpp | 14 +++++++------- 3 files changed, 12 insertions(+), 10 deletions(-) diff --git a/src/Mod/Part/App/Geometry.cpp b/src/Mod/Part/App/Geometry.cpp index 0cc5f6b42a..0e67d9cef8 100644 --- a/src/Mod/Part/App/Geometry.cpp +++ b/src/Mod/Part/App/Geometry.cpp @@ -311,13 +311,15 @@ void Geometry::setExtension(std::unique_ptr && geo) bool hasext=false; for( auto & ext : extensions) { - if(ext->getTypeId() == geo->getTypeId()){ + // if same type and name, this modifies the existing extension. + if( ext->getTypeId() == geo->getTypeId() && + ext->getName() == geo->getName()){ ext = std::move(geo); hasext = true; } } - if(!hasext) + if(!hasext) // new type-name unique id, so add. extensions.push_back(std::move(geo)); } diff --git a/src/Mod/Part/App/GeometryPy.xml b/src/Mod/Part/App/GeometryPy.xml index f6ec0be9a9..fa6bb72f61 100644 --- a/src/Mod/Part/App/GeometryPy.xml +++ b/src/Mod/Part/App/GeometryPy.xml @@ -88,7 +88,7 @@ It describes the common behavior of these objects when: Deletes all extensions of the indicated name. - + Returns a list with information about the geometry extensions. diff --git a/src/Mod/Part/App/GeometryPyImp.cpp b/src/Mod/Part/App/GeometryPyImp.cpp index 0a658e9704..a7e93de9b3 100644 --- a/src/Mod/Part/App/GeometryPyImp.cpp +++ b/src/Mod/Part/App/GeometryPyImp.cpp @@ -247,7 +247,8 @@ PyObject* GeometryPy::setExtension(PyObject *args) Part::GeometryExtension * ext; ext = static_cast(o)->getGeometryExtensionPtr(); - std::unique_ptr cpy = ext->copy(); // allocate new extension in memory + // make copy of Python managed memory and wrap it in smart pointer + auto cpy = ext->copy(); this->getGeometryPtr()->setExtension(std::move(cpy)); Py_Return; @@ -417,7 +418,7 @@ PyObject* GeometryPy::deleteExtensionOfName(PyObject *args) return 0; } -PyObject* GeometryPy::showExtensions(PyObject *args) +PyObject* GeometryPy::getExtensions(PyObject *args) { if (!PyArg_ParseTuple(args, "")){ PyErr_SetString(PartExceptionOCCError, "No arguments were expected"); @@ -427,21 +428,20 @@ PyObject* GeometryPy::showExtensions(PyObject *args) try { const std::vector> ext = this->getGeometryPtr()->getExtensions(); + PyObject* list = PyList_New(ext.size()); Py::Tuple tuple(ext.size()); for (std::size_t i=0; i p = ext[i].lock(); if(p) { - str << "<" << p->getTypeId().getName() << ", \"" << p->getName() << "\">"; - - tuple.setItem(i, Py::String(str.str())); + PyList_SetItem( list, i, p->getPyObject()); } } - return Py::new_reference_to(tuple); + return list; } catch(Base::ValueError e) { PyErr_SetString(PartExceptionOCCError, e.what());