Extend python interface for groups and fix test cases

This commit is contained in:
Stefan Tröger
2017-02-12 09:01:22 +01:00
committed by wmayer
parent e5c1f2bc70
commit 1d10dd2835
8 changed files with 178 additions and 105 deletions

View File

@@ -55,6 +55,20 @@
<UserDocu>Recomputes this object</UserDocu>
</Documentation>
</Methode>
<Methode Name="getParentGroup">
<Documentation>
<UserDocu>Returns the group the object is in or None if it is not part of a group.
Note that an object can only be in a single group, hence only a single return
value.</UserDocu>
</Documentation>
</Methode>
<Methode Name="getParentGeoFeatureGroup">
<Documentation>
<UserDocu>Returns the GeoFeatureGroup, and hence the local coorinate system, the object
is in or None if it is not part of a group. Note that an object can only be
in a single group, hence only a single return value.</UserDocu>
</Documentation>
</Methode>
<Attribute Name="OutList" ReadOnly="true">
<Documentation>
<UserDocu>A list of all objects this object links to.</UserDocu>

View File

@@ -25,6 +25,8 @@
#include "DocumentObject.h"
#include "Document.h"
#include "Expression.h"
#include "GroupExtension.h"
#include "GeoFeatureGroupExtension.h"
// inclusion of the generated files (generated out of DocumentObjectPy.xml)
#include <App/DocumentObjectPy.h>
@@ -315,6 +317,42 @@ PyObject* DocumentObjectPy::recompute(PyObject *args)
}
}
PyObject* DocumentObjectPy::getParentGroup(PyObject *args)
{
if (!PyArg_ParseTuple(args, ""))
return NULL;
try {
auto grp = GroupExtension::getGroupOfObject(getDocumentObjectPtr());
if(!grp) {
Py_INCREF(Py_None);
return Py_None;
}
return grp->getPyObject();
}
catch (const Base::Exception& e) {
throw Py::RuntimeError(e.what());
}
}
PyObject* DocumentObjectPy::getParentGeoFeatureGroup(PyObject *args)
{
if (!PyArg_ParseTuple(args, ""))
return NULL;
try {
auto grp = GeoFeatureGroupExtension::getGroupOfObject(getDocumentObjectPtr());
if(!grp) {
Py_INCREF(Py_None);
return Py_None;
}
return grp->getPyObject();
}
catch (const Base::Exception& e) {
throw Py::RuntimeError(e.what());
}
}
PyObject *DocumentObjectPy::getCustomAttributes(const char* attr) const
{
// search for dynamic property

View File

@@ -80,7 +80,7 @@ bool ExtensionContainer::hasExtension(Base::Type t, bool derived) const {
}
return false;
}
return true;
return found;
}
bool ExtensionContainer::hasExtension(const std::string& name) const {

View File

@@ -40,6 +40,7 @@
#include "PropertyLinks.h"
#include "GeoFeatureGroupExtension.h"
#include "OriginFeature.h"
using namespace App;
using namespace Base;
@@ -88,6 +89,14 @@ void ensureCorrectGroups(PropertyContainer* container, App::DocumentObject* obje
if(!container->isDerivedFrom(App::DocumentObject::getClassTypeId()))
return;
//links to origin feature can go over CS borders, as they are the same everywere anyway. This is
//a workaround to allow moving of objects between GeoFeatureGroups that link to origin features.
//During movement there is always a link in to the wron CS and the error would occure. If we
//surpress the error at least the origin links can be fixed afterwards
//TODO: Find a more elegant solution
if(object->isDerivedFrom(App::OriginFeature::getClassTypeId()))
return;
//undo and redo do not need to be handled as they can only go to already checked stated (the link
//state during those actions can get messed up, we really don't want to check for that)
if(object->getDocument()->performsTransactionOperation())