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

@@ -193,8 +193,9 @@ void GeoFeatureGroupExtension::extensionOnChanged(const Property* p) {
//objects are only allowed in a single GeoFeatureGroup
if(p == &Group && !Group.testStatus(Property::User3)) {
if(!getExtendedObject()->isRestoring() &&
!getExtendedObject()->getDocument()->isPerformingTransaction()) {
if((!getExtendedObject()->isRestoring()
|| getExtendedObject()->getDocument()->testStatus(Document::Importing))
&& !getExtendedObject()->getDocument()->isPerformingTransaction()) {
bool error = false;
auto corrected = Group.getValues();

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

View File

@@ -70,6 +70,8 @@ public:
virtual bool extensionGetSubObject(DocumentObject *&ret, const char *subname, PyObject **pyObj,
Base::Matrix4D *mat, bool transform, int depth) const override;
virtual void extensionOnChanged(const Property* p) override;
protected:
/// Checks integrity of the Origin
virtual App::DocumentObjectExecReturn *extensionExecute () override;