From 854452e2e1ba9b4282528f4d5330217d6eb4206a Mon Sep 17 00:00:00 2001 From: Abdullah Tahiri Date: Mon, 11 Feb 2019 16:00:26 +0100 Subject: [PATCH] Part: Geometry - methods to remove extensions by name and type --- src/Mod/Part/App/Geometry.cpp | 22 ++++++++++++++ src/Mod/Part/App/Geometry.h | 2 ++ src/Mod/Part/App/GeometryPy.xml | 10 +++++++ src/Mod/Part/App/GeometryPyImp.cpp | 48 ++++++++++++++++++++++++++++++ 4 files changed, 82 insertions(+) diff --git a/src/Mod/Part/App/Geometry.cpp b/src/Mod/Part/App/Geometry.cpp index 4037c91688..6bf0c91333 100644 --- a/src/Mod/Part/App/Geometry.cpp +++ b/src/Mod/Part/App/Geometry.cpp @@ -301,6 +301,28 @@ void Geometry::setExtension(std::unique_ptr && geo) extensions.push_back(std::move(geo)); } +void Geometry::deleteExtension(Base::Type type) +{ + extensions.erase( + std::remove_if( extensions.begin(), + extensions.end(), + [&type](const std::shared_ptr& ext){ + return ext->getTypeId() == type; + }), + extensions.end()); +} + +void Geometry::deleteExtension(std::string name) +{ + extensions.erase( + std::remove_if( extensions.begin(), + extensions.end(), + [&name](const std::shared_ptr& ext){ + return ext->getName() == name; + }), + extensions.end()); +} + void Geometry::createNewTag() { diff --git a/src/Mod/Part/App/Geometry.h b/src/Mod/Part/App/Geometry.h index 2334c6dd75..d902823982 100644 --- a/src/Mod/Part/App/Geometry.h +++ b/src/Mod/Part/App/Geometry.h @@ -102,6 +102,8 @@ public: bool hasExtension(Base::Type type) const; const std::weak_ptr getExtension(Base::Type type) const; void setExtension(std::unique_ptr &&geo); + void deleteExtension(Base::Type type); + void deleteExtension(std::string name); protected: /// create a new tag for the geometry object diff --git a/src/Mod/Part/App/GeometryPy.xml b/src/Mod/Part/App/GeometryPy.xml index 7d7d0bd335..ef5fb5d76b 100644 --- a/src/Mod/Part/App/GeometryPy.xml +++ b/src/Mod/Part/App/GeometryPy.xml @@ -63,6 +63,16 @@ It describes the common behavior of these objects when: Sets a geometry extension of the indicated type. + + + Deletes all extensions of the indicated type. + + + + + 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 06a3cce2ce..46ff3458c0 100644 --- a/src/Mod/Part/App/GeometryPyImp.cpp +++ b/src/Mod/Part/App/GeometryPyImp.cpp @@ -291,6 +291,54 @@ PyObject* GeometryPy::getExtension(PyObject *args) return 0; } +PyObject* GeometryPy::deleteExtensionType(PyObject *args) +{ + char* o; + if (PyArg_ParseTuple(args, "s", &o)) { + + Base::Type type = Base::Type::fromName(o); + + if(type != Base::Type::badType()) { + try { + this->getGeometryPtr()->deleteExtension(type); + Py_Return; + } + catch(Base::ValueError e) { + PyErr_SetString(PartExceptionOCCError, e.what()); + return 0; + } + } + else + { + PyErr_SetString(PartExceptionOCCError, "Type does not exist"); + return 0; + } + + } + + PyErr_SetString(PartExceptionOCCError, "A string with a type object was expected"); + return 0; +} + +PyObject* GeometryPy::deleteExtensionName(PyObject *args) +{ + char* o; + if (PyArg_ParseTuple(args, "s", &o)) { + + try { + this->getGeometryPtr()->deleteExtension(std::string(o)); + Py_Return; + } + catch(Base::ValueError e) { + PyErr_SetString(PartExceptionOCCError, e.what()); + return 0; + } + } + + PyErr_SetString(PartExceptionOCCError, "A string with the name of the extension was expected"); + return 0; +} + PyObject* GeometryPy::showExtensions(PyObject *args) { if (!PyArg_ParseTuple(args, "")){