From d8e99c1923022386f0ddb022db4b595b2452ebd2 Mon Sep 17 00:00:00 2001 From: Abdullah Tahiri Date: Mon, 11 Feb 2019 16:21:40 +0100 Subject: [PATCH] Part:: Geometry container extend hasExtension to type and name --- src/Mod/Part/App/Geometry.cpp | 10 +++++++ src/Mod/Part/App/Geometry.h | 1 + src/Mod/Part/App/GeometryPy.xml | 10 +++++++ src/Mod/Part/App/GeometryPyImp.cpp | 47 ++++++++++++++++++++++++++++++ 4 files changed, 68 insertions(+) diff --git a/src/Mod/Part/App/Geometry.cpp b/src/Mod/Part/App/Geometry.cpp index 6bf0c91333..317546722d 100644 --- a/src/Mod/Part/App/Geometry.cpp +++ b/src/Mod/Part/App/Geometry.cpp @@ -276,6 +276,16 @@ bool Geometry::hasExtension(Base::Type type) const return false; } +bool Geometry::hasExtension(std::string name) const +{ + for( auto ext : extensions) { + if(ext->getName() == name) + return true; + } + + return false; +} + const std::weak_ptr Geometry::getExtension(Base::Type type) const { for( auto ext : extensions) { diff --git a/src/Mod/Part/App/Geometry.h b/src/Mod/Part/App/Geometry.h index d902823982..986c2ed5cc 100644 --- a/src/Mod/Part/App/Geometry.h +++ b/src/Mod/Part/App/Geometry.h @@ -100,6 +100,7 @@ public: const std::vector> getExtensions() const; bool hasExtension(Base::Type type) const; + bool hasExtension(std::string name) const; const std::weak_ptr getExtension(Base::Type type) const; void setExtension(std::unique_ptr &&geo); void deleteExtension(Base::Type type); diff --git a/src/Mod/Part/App/GeometryPy.xml b/src/Mod/Part/App/GeometryPy.xml index ef5fb5d76b..b794705abd 100644 --- a/src/Mod/Part/App/GeometryPy.xml +++ b/src/Mod/Part/App/GeometryPy.xml @@ -51,6 +51,16 @@ It describes the common behavior of these objects when: Create a clone of this geometry with the same Tag + + + + + Returns a boolean indicating whether a geometry extension of the type indicated as a string exists. + + + + + Returns a boolean indicating whether a geometry extension with the name indicated as a string exists. diff --git a/src/Mod/Part/App/GeometryPyImp.cpp b/src/Mod/Part/App/GeometryPyImp.cpp index 46ff3458c0..458a47c9b8 100644 --- a/src/Mod/Part/App/GeometryPyImp.cpp +++ b/src/Mod/Part/App/GeometryPyImp.cpp @@ -291,6 +291,53 @@ PyObject* GeometryPy::getExtension(PyObject *args) return 0; } +PyObject* GeometryPy::hasExtensionType(PyObject *args) +{ + char* o; + if (PyArg_ParseTuple(args, "s", &o)) { + + Base::Type type = Base::Type::fromName(o); + + if(type != Base::Type::badType()) { + try { + return Py::new_reference_to(Py::Boolean(this->getGeometryPtr()->hasExtension(type))); + } + catch(Base::ValueError e) { + PyErr_SetString(PartExceptionOCCError, e.what()); + return 0; + } + } + else + { + PyErr_SetString(PartExceptionOCCError, "Exception type does not exist"); + return 0; + } + + } + + PyErr_SetString(PartExceptionOCCError, "A string with the type of the geometry extension was expected"); + return 0; +} + +PyObject* GeometryPy::hasExtensionName(PyObject *args) +{ + char* o; + if (PyArg_ParseTuple(args, "s", &o)) { + + try { + return Py::new_reference_to(Py::Boolean(this->getGeometryPtr()->hasExtension(std::string(o)))); + } + catch(Base::ValueError e) { + PyErr_SetString(PartExceptionOCCError, e.what()); + return 0; + } + + } + + PyErr_SetString(PartExceptionOCCError, "A string with the type of the geometry extension was expected"); + return 0; +} + PyObject* GeometryPy::deleteExtensionType(PyObject *args) { char* o;