From 03bf3ac606d43a6d5e73bc89ee2202a0ff5413a7 Mon Sep 17 00:00:00 2001 From: wmayer Date: Wed, 10 May 2017 10:36:22 +0200 Subject: [PATCH] Expose method to Python to get property name of main geometry fix inheritance of MeshFeaturePy fix inheritance of PartFeaturePy remove useless test() method implement getPyObject in GeoFeature in case a sub-class doesn't implement it --- src/App/GeoFeature.cpp | 10 ++++++++++ src/App/GeoFeature.h | 5 +++++ src/App/GeoFeaturePy.xml | 10 +++++++++- src/App/GeoFeaturePyImp.cpp | 20 +++++++++++++------- src/Mod/Mesh/App/MeshFeaturePy.xml | 4 ++-- src/Mod/Part/App/PartFeaturePy.xml | 9 ++------- src/Mod/Part/App/PartFeaturePyImp.cpp | 6 ------ 7 files changed, 41 insertions(+), 23 deletions(-) diff --git a/src/App/GeoFeature.cpp b/src/App/GeoFeature.cpp index fc2e766b81..8142ec1ec1 100644 --- a/src/App/GeoFeature.cpp +++ b/src/App/GeoFeature.cpp @@ -27,6 +27,7 @@ #endif #include "GeoFeature.h" +#include using namespace App; @@ -58,3 +59,12 @@ const PropertyComplexGeoData* GeoFeature::getPropertyOfGeometry() const { return nullptr; } + +PyObject* GeoFeature::getPyObject(void) +{ + if (PythonObject.is(Py::_None())) { + // ref counter is set to 1 + PythonObject = Py::Object(new GeoFeaturePy(this),true); + } + return Py::new_reference_to(PythonObject); +} diff --git a/src/App/GeoFeature.h b/src/App/GeoFeature.h index 9ca50968dc..292d63ca9d 100644 --- a/src/App/GeoFeature.h +++ b/src/App/GeoFeature.h @@ -61,6 +61,11 @@ public: * The default implementation returns null. */ virtual const PropertyComplexGeoData* getPropertyOfGeometry() const; + /** + * @brief getPyObject returns the Python binding object + * @return the Python binding object + */ + virtual PyObject* getPyObject(void); }; } //namespace App diff --git a/src/App/GeoFeaturePy.xml b/src/App/GeoFeaturePy.xml index 5874da5593..d2f165ce2a 100644 --- a/src/App/GeoFeaturePy.xml +++ b/src/App/GeoFeaturePy.xml @@ -15,7 +15,15 @@ - returns all posible paths to the root of the document + returns all possible paths to the root of the document + + + + + Returns the property name of the actual geometry or None. +For example for a part object it returns the value Shape, +for a mesh the value Mesh and so on. +If an object has no such property then None is returned. diff --git a/src/App/GeoFeaturePyImp.cpp b/src/App/GeoFeaturePyImp.cpp index e0d7d26c4f..9eee2ea815 100644 --- a/src/App/GeoFeaturePyImp.cpp +++ b/src/App/GeoFeaturePyImp.cpp @@ -28,6 +28,7 @@ // inclusion of the generated files (generated out of GeoFeaturePy.xml) #include "GeoFeaturePy.h" #include "GeoFeaturePy.cpp" +#include using namespace App; @@ -37,17 +38,24 @@ std::string GeoFeaturePy::representation(void) const return std::string(""); } - - PyObject* GeoFeaturePy::getPaths(PyObject * /*args*/) { PyErr_SetString(PyExc_NotImplementedError, "Not yet implemented"); return 0; } - - - +PyObject* GeoFeaturePy::getPropertyNameOfGeometry(PyObject * args) +{ + if (!PyArg_ParseTuple(args, "")) + return 0; + GeoFeature* object = this->getGeoFeaturePtr(); + const PropertyComplexGeoData* prop = object->getPropertyOfGeometry(); + const char* name = prop ? prop->getName() : 0; + if (name) { + return Py::new_reference_to(Py::String(std::string(name))); + } + return Py::new_reference_to(Py::None()); +} PyObject *GeoFeaturePy::getCustomAttributes(const char* /*attr*/) const { @@ -58,5 +66,3 @@ int GeoFeaturePy::setCustomAttributes(const char* /*attr*/, PyObject* /*obj*/) { return 0; } - - diff --git a/src/Mod/Mesh/App/MeshFeaturePy.xml b/src/Mod/Mesh/App/MeshFeaturePy.xml index 1124f61c23..24228d2213 100644 --- a/src/Mod/Mesh/App/MeshFeaturePy.xml +++ b/src/Mod/Mesh/App/MeshFeaturePy.xml @@ -1,13 +1,13 @@  diff --git a/src/Mod/Part/App/PartFeaturePy.xml b/src/Mod/Part/App/PartFeaturePy.xml index 5be039f396..035f3beec6 100644 --- a/src/Mod/Part/App/PartFeaturePy.xml +++ b/src/Mod/Part/App/PartFeaturePy.xml @@ -1,22 +1,17 @@  This is the father of all shape object classes - - - test - - diff --git a/src/Mod/Part/App/PartFeaturePyImp.cpp b/src/Mod/Part/App/PartFeaturePyImp.cpp index 805787b638..64dd2a8c6e 100644 --- a/src/Mod/Part/App/PartFeaturePyImp.cpp +++ b/src/Mod/Part/App/PartFeaturePyImp.cpp @@ -46,9 +46,3 @@ int PartFeaturePy::setCustomAttributes(const char* , PyObject *) { return 0; } - -PyObject* PartFeaturePy::test(PyObject * /*args*/) -{ - PyErr_SetString(PyExc_NotImplementedError, "Not yet implemented"); - return 0; -}