App: report error on copying OriginGroup without dependency

This commit is contained in:
Zheng, Lei
2020-08-26 16:33:32 +08:00
committed by wwmayer
parent 2c8f78b299
commit 73dcb6128c
3 changed files with 25 additions and 2 deletions

View File

@@ -149,6 +149,26 @@ void OriginGroupExtension::onExtendedUnsetupObject () {
GeoFeatureGroupExtension::onExtendedUnsetupObject ();
}
void OriginGroupExtension::extensionOnChanged(const Property* p) {
if(p == &Origin) {
App::DocumentObject *owner = getExtendedObject();
App::DocumentObject *origin = Origin.getValue();
// Document::Importing indicats the object is being imported (i.e.
// copied). So check the Origin ownership here to prevent copy without
// dependency
if (origin && owner && owner->getDocument()
&& owner->getDocument()->testStatus(Document::Importing)) {
for (auto o : origin->getInList()) {
if(o != owner && o->hasExtension(App::OriginGroupExtension::getExtensionClassTypeId())) {
Origin.setValue(nullptr);
throw Base::RuntimeError("Origin can only be in a single OriginGroup");
}
}
}
}
GeoFeatureGroupExtension::extensionOnChanged(p);
}
void OriginGroupExtension::relinkToOrigin(App::DocumentObject* obj)
{
//we get all links and replace the origin objects if needed (subnames need not to change, they