Group: ensure single group only
This commit is contained in:
@@ -281,8 +281,6 @@ std::vector< DocumentObject* > GeoFeatureGroupExtension::getCSRelevantLinks(Docu
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Python feature ---------------------------------------------------------
|
||||
|
||||
namespace App {
|
||||
|
||||
@@ -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*);
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -100,6 +100,8 @@ public:
|
||||
|
||||
virtual PyObject* getExtensionPyObject(void);
|
||||
|
||||
virtual void extensionOnChanged(const Property* p) override;
|
||||
|
||||
/// Properties
|
||||
PropertyLinkList Group;
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user