Sketcher: change rules of external linkage

Was:
+ allowed: links to support
+ allowed: free links within one body,
+ Ctrl-protected: links between bodies of ?one? part
- blocked: (everything else) . i.e., if sketch is not in a body, only
links to support are allowed.

New:

* Across Parts, from Part to outside part, from document into part:
blocked
* Within one part (also if directly in document): allowed.
except links from body to outside or to other bodies are screened (hold
Ctrl to allow).
Support (attachment) is totally ignored in this logic.
This commit is contained in:
DeepSOIC 2016-05-19 23:59:26 +03:00
parent 711213d58e
commit 0f75ad6637
3 changed files with 34 additions and 16 deletions

View File

@ -58,6 +58,7 @@
#include <App/Document.h>
#include <App/FeaturePythonPyImp.h>
#include <App/Part.h>
#include <Base/Writer.h>
#include <Base/Reader.h>
#include <Base/Tools.h>
@ -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;
}

View File

@ -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<App::ObjectIdentifier> &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<Part::Geometry *> supportedGeometry(const std::vector<Part::Geometry *> &geoList) const;

View File

@ -4476,7 +4476,8 @@ namespace SketcherGui {
{
Sketcher::SketchObject *sketch = static_cast<Sketcher::SketchObject*>(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;