From fa020cf867746acbc987ef2c727fc65d80fcb21b Mon Sep 17 00:00:00 2001 From: jrheinlaender Date: Sun, 7 Jul 2013 11:31:59 +0200 Subject: [PATCH] Allow selecting geometry from another body inside the same part as a reference --- src/Mod/PartDesign/Gui/FeaturePickDialog.cpp | 2 +- src/Mod/PartDesign/Gui/ReferenceSelection.cpp | 18 ++++++++++-------- src/Mod/PartDesign/Gui/ReferenceSelection.h | 8 +++++++- 3 files changed, 18 insertions(+), 10 deletions(-) diff --git a/src/Mod/PartDesign/Gui/FeaturePickDialog.cpp b/src/Mod/PartDesign/Gui/FeaturePickDialog.cpp index 9576b7bba..b0b0d0e61 100644 --- a/src/Mod/PartDesign/Gui/FeaturePickDialog.cpp +++ b/src/Mod/PartDesign/Gui/FeaturePickDialog.cpp @@ -68,7 +68,7 @@ FeaturePickDialog::FeaturePickDialog(std::vector& objects, connect(ui->radioXRef, SIGNAL(toggled(bool)), this, SLOT(onUpdate(bool))); ui->checkReverse->setChecked(false); - ui->checkOtherBody->setChecked(false); + ui->checkOtherBody->setChecked(true); ui->checkOtherBody->setEnabled(false); // TODO: implement ui->checkOtherFeature->setChecked(false); ui->checkOtherFeature->setEnabled(false); // TODO: implement diff --git a/src/Mod/PartDesign/Gui/ReferenceSelection.cpp b/src/Mod/PartDesign/Gui/ReferenceSelection.cpp index 46f97f293..7cb465735 100644 --- a/src/Mod/PartDesign/Gui/ReferenceSelection.cpp +++ b/src/Mod/PartDesign/Gui/ReferenceSelection.cpp @@ -60,7 +60,7 @@ bool ReferenceSelection::allow(App::Document* pDoc, App::DocumentObject* pObj, c // Allow selecting Part::Datum features from the active Body if (ActivePartObject == NULL) return false; - if (!ActivePartObject->hasFeature(pObj)) + if (!allowOtherBody && !ActivePartObject->hasFeature(pObj)) return false; if (plane && (pObj->getTypeId().isDerivedFrom(PartDesign::Plane::getClassTypeId()))) @@ -73,16 +73,18 @@ bool ReferenceSelection::allow(App::Document* pDoc, App::DocumentObject* pObj, c return false; } - // Handle selection of geometry elements - if (support == NULL) - return false; + // Handle selection of geometry elements if (!sSubName || sSubName[0] == '\0') return false; - if (pObj != support) - return false; + if (!allowOtherBody) { + if (support == NULL) + return false; + if (pObj != support) + return false; + } std::string subName(sSubName); if (edge && subName.size() > 4 && subName.substr(0,4) == "Edge") { - const Part::TopoShape &shape = static_cast(support)->Shape.getValue(); + const Part::TopoShape &shape = static_cast(pObj)->Shape.getValue(); TopoDS_Shape sh = shape.getSubShape(subName.c_str()); const TopoDS_Edge& edge = TopoDS::Edge(sh); if (!edge.IsNull()) { @@ -96,7 +98,7 @@ bool ReferenceSelection::allow(App::Document* pDoc, App::DocumentObject* pObj, c } } if (plane && subName.size() > 4 && subName.substr(0,4) == "Face") { - const Part::TopoShape &shape = static_cast(support)->Shape.getValue(); + const Part::TopoShape &shape = static_cast(pObj)->Shape.getValue(); TopoDS_Shape sh = shape.getSubShape(subName.c_str()); const TopoDS_Face& face = TopoDS::Face(sh); if (!face.IsNull()) { diff --git a/src/Mod/PartDesign/Gui/ReferenceSelection.h b/src/Mod/PartDesign/Gui/ReferenceSelection.h index 46699c9de..7c719e4b8 100644 --- a/src/Mod/PartDesign/Gui/ReferenceSelection.h +++ b/src/Mod/PartDesign/Gui/ReferenceSelection.h @@ -30,14 +30,20 @@ namespace PartDesignGui { class ReferenceSelection : public Gui::SelectionFilterGate { const App::DocumentObject* support; + // If set to true, allow picking edges or planes or both bool edge, plane; + // If set to true, allow only linear edges and planar faces bool planar; + // If set to true, allow picking datum points bool point; + // If set to true, allow picking objects from another body in the same part + bool allowOtherBody; + public: ReferenceSelection(const App::DocumentObject* support_, const bool edge_, const bool plane_, const bool planar_, const bool point_ = false) : Gui::SelectionFilterGate((Gui::SelectionFilter*)0), - support(support_), edge(edge_), plane(plane_), planar(planar_), point(point_) + support(support_), edge(edge_), plane(plane_), planar(planar_), point(point_), allowOtherBody(true) { } /**