diff --git a/src/Mod/Sketcher/App/SketchObject.cpp b/src/Mod/Sketcher/App/SketchObject.cpp index d4c240c34..fa3964b9b 100644 --- a/src/Mod/Sketcher/App/SketchObject.cpp +++ b/src/Mod/Sketcher/App/SketchObject.cpp @@ -1702,13 +1702,26 @@ int SketchObject::trim(int GeoId, const Base::Vector3d& point) return -1; } -bool SketchObject::isExternalAllowed(App::Document *pDoc, App::DocumentObject *pObj) const +bool SketchObject::isExternalAllowed(App::Document *pDoc, App::DocumentObject *pObj, eReasonList* rsn) const { + if (rsn) + *rsn = rlAllowed; + // Externals outside of the Document are NOT allowed - if (this->getDocument() != pDoc) + if (this->getDocument() != pDoc){ + if (rsn) + *rsn = rlOtherDoc; return false; + } + + //circular reference prevention try { - return this->testIfLinkDAGCompatible(pObj); + if (!(this->testIfLinkDAGCompatible(pObj))){ + if (rsn) + *rsn = rlCircularReference; + return false + ; + } } catch (Base::Exception &e) { Base::Console().Warning("Probably, there is a circular reference in the document. Error: %s\n", e.what()); return true; //prohibiting this reference won't remove the problem anyway... @@ -1721,6 +1734,8 @@ bool SketchObject::isExternalAllowed(App::Document *pDoc, App::DocumentObject *p if (body != NULL) { if ( ! body->hasFeature (pObj) && !this->allowOtherBody ) { // Selection outside of body not allowed if flag is not set + if (rsn) + *rsn = rlOtherPart; return false; } } else { diff --git a/src/Mod/Sketcher/App/SketchObject.h b/src/Mod/Sketcher/App/SketchObject.h index 15c38670c..39afacf7c 100644 --- a/src/Mod/Sketcher/App/SketchObject.h +++ b/src/Mod/Sketcher/App/SketchObject.h @@ -261,8 +261,16 @@ public: /// Flag to allow external geometry from other bodies than the one this sketch belongs to bool allowOtherBody; - /// Return true if this object is allowed as external geometry for the sketch - bool isExternalAllowed(App::Document *pDoc, App::DocumentObject *pObj) const; + + enum eReasonList{ + rlAllowed, + rlOtherDoc, + rlCircularReference, + rlOtherPart, + }; + /// Return true if this object is allowed as external geometry for the + /// sketch. rsn argument recieves the reason for disallowing. + bool isExternalAllowed(App::Document *pDoc, App::DocumentObject *pObj, eReasonList* rsn = 0) const; protected: /// get called by the container when a property has changed diff --git a/src/Mod/Sketcher/Gui/CommandCreateGeo.cpp b/src/Mod/Sketcher/Gui/CommandCreateGeo.cpp index 95544db0e..3d1a79dd4 100644 --- a/src/Mod/Sketcher/Gui/CommandCreateGeo.cpp +++ b/src/Mod/Sketcher/Gui/CommandCreateGeo.cpp @@ -4475,8 +4475,21 @@ namespace SketcherGui { bool allow(App::Document *pDoc, App::DocumentObject *pObj, const char *sSubName) { Sketcher::SketchObject *sketch = static_cast(object); - if (!sketch->isExternalAllowed(pDoc, pObj)) + Sketcher::SketchObject::eReasonList msg; + if (!sketch->isExternalAllowed(pDoc, pObj, &msg)){ + switch(msg){ + case Sketcher::SketchObject::rlCircularReference: + this->notAllowedReason = QT_TR_NOOP("Linking this will cause circular dependency."); + break; + case Sketcher::SketchObject::rlOtherDoc: + this->notAllowedReason = QT_TR_NOOP("This object is in another document."); + break; + case Sketcher::SketchObject::rlOtherPart: + this->notAllowedReason = QT_TR_NOOP("This object belongs to another part, can't link."); + break; + } return false; + } // Note: its better to search the support of the sketch in case the sketch support is a base plane //Part::BodyBase* body = Part::BodyBase::findBodyOf(sketch);