Skip to content

Commit

Permalink
Expose method to Python to get property name of main geometry
Browse files Browse the repository at this point in the history
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
  • Loading branch information
wwmayer committed May 10, 2017
1 parent 19b1452 commit 03bf3ac
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 23 deletions.
10 changes: 10 additions & 0 deletions src/App/GeoFeature.cpp
Expand Up @@ -27,6 +27,7 @@
#endif

#include "GeoFeature.h"
#include <App/GeoFeaturePy.h>

using namespace App;

Expand Down Expand Up @@ -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);
}
5 changes: 5 additions & 0 deletions src/App/GeoFeature.h
Expand Up @@ -61,6 +61,11 @@ class AppExport GeoFeature : public App::DocumentObject
* 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
Expand Down
10 changes: 9 additions & 1 deletion src/App/GeoFeaturePy.xml
Expand Up @@ -15,7 +15,15 @@
</Documentation>
<Methode Name="getPaths">
<Documentation>
<UserDocu>returns all posible paths to the root of the document</UserDocu>
<UserDocu>returns all possible paths to the root of the document</UserDocu>
</Documentation>
</Methode>
<Methode Name="getPropertyNameOfGeometry">
<Documentation>
<UserDocu>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.</UserDocu>
</Documentation>
</Methode>
<CustomAttributes />
Expand Down
20 changes: 13 additions & 7 deletions src/App/GeoFeaturePyImp.cpp
Expand Up @@ -28,6 +28,7 @@
// inclusion of the generated files (generated out of GeoFeaturePy.xml)
#include "GeoFeaturePy.h"
#include "GeoFeaturePy.cpp"
#include <CXX/Objects.hxx>

using namespace App;

Expand All @@ -37,17 +38,24 @@ std::string GeoFeaturePy::representation(void) const
return std::string("<GeoFeature object>");
}



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
{
Expand All @@ -58,5 +66,3 @@ int GeoFeaturePy::setCustomAttributes(const char* /*attr*/, PyObject* /*obj*/)
{
return 0;
}


4 changes: 2 additions & 2 deletions src/Mod/Mesh/App/MeshFeaturePy.xml
@@ -1,13 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<GenerateModel xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="generateMetaModel_Module.xsd">
<PythonExport
Father="DocumentObjectPy"
Father="GeoFeaturePy"
Name="MeshFeaturePy"
Twin="Feature"
TwinPointer="Feature"
Include="Mod/Mesh/App/MeshFeature.h"
Namespace="Mesh"
FatherInclude="App/DocumentObjectPy.h"
FatherInclude="App/GeoFeaturePy.h"
FatherNamespace="App">
<Documentation>
<Author Licence="LGPL" Name="Werner Mayer" EMail="wmayer@users.sourceforge.net" />
Expand Down
9 changes: 2 additions & 7 deletions src/Mod/Part/App/PartFeaturePy.xml
@@ -1,22 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<GenerateModel xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="generateMetaModel_Module.xsd">
<PythonExport
Father="DocumentObjectPy"
Father="GeoFeaturePy"
Name="PartFeaturePy"
Twin="Feature"
TwinPointer="Feature"
Include="Mod/Part/App/PartFeature.h"
Namespace="Part"
FatherInclude="App/DocumentObjectPy.h"
FatherInclude="App/GeoFeaturePy.h"
FatherNamespace="App">
<Documentation>
<Author Licence="LGPL" Name="Juergen Riegel" EMail="FreeCAD@juergen-riegel.net" />
<UserDocu>This is the father of all shape object classes</UserDocu>
</Documentation>
<Methode Name="test">
<Documentation>
<UserDocu>test</UserDocu>
</Documentation>
</Methode>
</PythonExport>
</GenerateModel>
6 changes: 0 additions & 6 deletions src/Mod/Part/App/PartFeaturePyImp.cpp
Expand Up @@ -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;
}

0 comments on commit 03bf3ac

Please sign in to comment.