Group: ensure single group only

This commit is contained in:
Stefan Tröger
2017-02-09 22:37:41 +01:00
committed by wmayer
parent 26200f95f5
commit f0f7125a11
5 changed files with 30 additions and 2 deletions

View File

@@ -281,8 +281,6 @@ std::vector< DocumentObject* > GeoFeatureGroupExtension::getCSRelevantLinks(Docu
return result;
}
// Python feature ---------------------------------------------------------
namespace App {

View File

@@ -111,6 +111,7 @@ public:
/// obj and from obj excluding expressions and stopping the recursion at other geofeaturegroups.
/// The result is the combination of CSOutList and CSInList.
static std::vector<App::DocumentObject*> getCSRelevantLinks(App::DocumentObject* obj);
private:
Base::Placement recursiveGroupPlacement(GeoFeatureGroupExtension* group);
static std::vector<App::DocumentObject*> getObjectsFromLinks(App::DocumentObject*);

View File

@@ -243,6 +243,30 @@ PyObject* GroupExtension::getExtensionPyObject(void) {
return Py::new_reference_to(ExtensionPythonObject);
}
void GroupExtension::extensionOnChanged(const Property* p) {
//we need to remove all object that have other parent geofeature groups
if(strcmp(p->getName(), "Group")==0) {
bool error = false;
auto corrected = Group.getValues();
for(auto obj : Group.getValues()) {
auto grp = GroupExtension::getGroupOfObject(obj);
if(grp && (grp != getExtendedObject())) {
error = true;
corrected.erase(std::remove(corrected.begin(), corrected.end(), obj), corrected.end());
}
}
if(error) {
Group.setValues(corrected);
throw Base::Exception("Object can only be in a single Group");
}
}
App::Extension::extensionOnChanged(p);
}
namespace App {
EXTENSION_PROPERTY_SOURCE_TEMPLATE(App::GroupExtensionPython, App::GroupExtension)

View File

@@ -100,6 +100,8 @@ public:
virtual PyObject* getExtensionPyObject(void);
virtual void extensionOnChanged(const Property* p) override;
/// Properties
PropertyLinkList Group;

View File

@@ -869,6 +869,9 @@ class UndoRedoCases(unittest.TestCase):
#adding the object to a geofeaturegroup, but not its group, should handle it automatically when used
#addObject
#to test: try add obj to second group, once by addObject, once by .Group = []
def tearDown(self):
# closing doc