diff --git a/src/Mod/Sketcher/App/SketchObject.cpp b/src/Mod/Sketcher/App/SketchObject.cpp index e0db83b8e..14ec17bbf 100644 --- a/src/Mod/Sketcher/App/SketchObject.cpp +++ b/src/Mod/Sketcher/App/SketchObject.cpp @@ -58,6 +58,7 @@ #include #include +#include #include #include #include @@ -1729,20 +1730,32 @@ bool SketchObject::isExternalAllowed(App::Document *pDoc, App::DocumentObject *p // Note: Checking for the body of the support doesn't work when the support are the three base planes App::DocumentObject *support = this->Support.getValue(); - Part::BodyBase* body = Part::BodyBase::findBodyOf(this); - 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; + Part::BodyBase* body_this = Part::BodyBase::findBodyOf(this); + Part::BodyBase* body_obj = Part::BodyBase::findBodyOf(pObj); + App::Part* part_this = App::Part::getPartOfObject(this, true); + App::Part* part_obj = App::Part::getPartOfObject(pObj, true); + if (part_this == part_obj){ //either in the same part, or in the root of document + if (body_this == NULL) { + return true; + } else if (body_this == body_obj) { + return true; + } else { + if ( this->allowOtherBody ) { // Selection outside of body not allowed if flag is not set + return true; + } else { + if (rsn) + *rsn = rlOtherBody; + return false; + } } } else { - // Legacy parts - don't allow selection outside of the support - if (pObj != support) - return false; + // cross-part link. Disallow, should be done via shapebinders only + if (rsn) + *rsn = rlOtherPart; + return false; } + assert(0); return true; } diff --git a/src/Mod/Sketcher/App/SketchObject.h b/src/Mod/Sketcher/App/SketchObject.h index 39afacf7c..263c022b2 100644 --- a/src/Mod/Sketcher/App/SketchObject.h +++ b/src/Mod/Sketcher/App/SketchObject.h @@ -74,8 +74,8 @@ public: /*! \brief Returns true if the sketcher supports the given geometry - \param geo - the geometry - \retval bool - true if the geometry is supported + \param geo - the geometry + \retval bool - true if the geometry is supported */ bool isSupportedGeometry(const Part::Geometry *geo) const; /// add unspecified geometry @@ -267,6 +267,7 @@ public: rlOtherDoc, rlCircularReference, rlOtherPart, + rlOtherBody, }; /// Return true if this object is allowed as external geometry for the /// sketch. rsn argument recieves the reason for disallowing. @@ -285,8 +286,8 @@ protected: void constraintsRemoved(const std::set &removed); /*! \brief Returns a list of supported geometries from the input list - \param geoList - the geometry list - \retval list - the supported geometry list + \param geoList - the geometry list + \retval list - the supported geometry list */ std::vector supportedGeometry(const std::vector &geoList) const; diff --git a/src/Mod/Sketcher/Gui/CommandCreateGeo.cpp b/src/Mod/Sketcher/Gui/CommandCreateGeo.cpp index 75562db17..11234f41a 100644 --- a/src/Mod/Sketcher/Gui/CommandCreateGeo.cpp +++ b/src/Mod/Sketcher/Gui/CommandCreateGeo.cpp @@ -4476,7 +4476,8 @@ namespace SketcherGui { { Sketcher::SketchObject *sketch = static_cast(object); sketch->allowOtherBody = (QApplication::keyboardModifiers() == Qt::ControlModifier); - + + this->notAllowedReason = ""; Sketcher::SketchObject::eReasonList msg; if (!sketch->isExternalAllowed(pDoc, pObj, &msg)){ switch(msg){ @@ -4486,8 +4487,11 @@ namespace SketcherGui { case Sketcher::SketchObject::rlOtherDoc: this->notAllowedReason = QT_TR_NOOP("This object is in another document."); break; + case Sketcher::SketchObject::rlOtherBody: + this->notAllowedReason = QT_TR_NOOP("This object belongs to another body, can't link. Hold Ctrl to allow crossreferences."); + break; case Sketcher::SketchObject::rlOtherPart: - this->notAllowedReason = QT_TR_NOOP("This object belongs to another part or body, can't link. Hold Ctrl to allow crossreferences."); + this->notAllowedReason = QT_TR_NOOP("This object belongs to another part, can't link."); break; default: break;