From be249f902d4181cc70f3f0e3d5c6104e097c0ca3 Mon Sep 17 00:00:00 2001 From: Sergo Date: Tue, 11 Oct 2016 20:58:27 -0400 Subject: [PATCH] PD: add SelectionFilterGate to filter dependents, fix mirror taskview --- src/Mod/PartDesign/Gui/ReferenceSelection.cpp | 10 +++++++-- src/Mod/PartDesign/Gui/ReferenceSelection.h | 20 +++++++++++++----- .../PartDesign/Gui/TaskDatumParameters.cpp | 2 +- .../PartDesign/Gui/TaskMirroredParameters.cpp | 21 +++++++------------ .../Gui/TaskTransformedParameters.cpp | 4 +++- 5 files changed, 35 insertions(+), 22 deletions(-) diff --git a/src/Mod/PartDesign/Gui/ReferenceSelection.cpp b/src/Mod/PartDesign/Gui/ReferenceSelection.cpp index fa2e72ee5..6bf0caa68 100644 --- a/src/Mod/PartDesign/Gui/ReferenceSelection.cpp +++ b/src/Mod/PartDesign/Gui/ReferenceSelection.cpp @@ -175,12 +175,18 @@ bool ReferenceSelection::allow(App::Document* pDoc, App::DocumentObject* pObj, c bool NoDependentsSelection::allow(App::Document* pDoc, App::DocumentObject* pObj, const char* sSubName) { - if (support && !support->testIfLinkDAGCompatible(pObj)) { + if (support && support->testIfLinkDAGCompatible(pObj)) { + return true; + } + else { this->notAllowedReason = QT_TR_NOOP("Selecting this will cause circular dependency."); return false; } +} - return refSelection.allow(pDoc, pObj, sSubName); +bool CombineSelectionFilterGates::allow(App::Document* pDoc, App::DocumentObject* pObj, const char* sSubName) +{ + return filter1->allow(pDoc, pObj, sSubName) && filter2->allow(pDoc, pObj, sSubName); } diff --git a/src/Mod/PartDesign/Gui/ReferenceSelection.h b/src/Mod/PartDesign/Gui/ReferenceSelection.h index acb39dfb2..dced12392 100644 --- a/src/Mod/PartDesign/Gui/ReferenceSelection.h +++ b/src/Mod/PartDesign/Gui/ReferenceSelection.h @@ -56,21 +56,31 @@ public: class NoDependentsSelection : public Gui::SelectionFilterGate { - ReferenceSelection refSelection; const App::DocumentObject* support; public: - NoDependentsSelection(const App::DocumentObject* support_, - const bool edge_, const bool plane_, const bool planar_, const bool point_ = false) - : Gui::SelectionFilterGate((Gui::SelectionFilter*)0), refSelection(support_, edge_, plane_, planar_, point_), support(support_) + NoDependentsSelection(const App::DocumentObject* support_) + : Gui::SelectionFilterGate((Gui::SelectionFilter*)0), support(support_) { } /** * Allow the user to pick only objects wich are not in objs getDependencyList */ - bool allow(App::Document* pDoc, App::DocumentObject* pObj, const char* sSubName); + bool allow(App::Document* pDoc, App::DocumentObject* pObj, const char* sSubName) override; }; +class CombineSelectionFilterGates: public Gui::SelectionFilterGate +{ + std::unique_ptr filter1; + std::unique_ptr filter2; + +public: + CombineSelectionFilterGates(std::unique_ptr &filter1_, std::unique_ptr &filter2_) + : Gui::SelectionFilterGate((Gui::SelectionFilter*)0), filter1(std::move(filter1_)), filter2(std::move(filter2_)) + { + } + bool allow(App::Document* pDoc, App::DocumentObject* pObj, const char* sSubName) override; +}; // Convenience methods /// Extract reference from Selection void getReferencedSelection(const App::DocumentObject* thisObj, const Gui::SelectionChanges& msg, diff --git a/src/Mod/PartDesign/Gui/TaskDatumParameters.cpp b/src/Mod/PartDesign/Gui/TaskDatumParameters.cpp index 7ded13011..370218d61 100644 --- a/src/Mod/PartDesign/Gui/TaskDatumParameters.cpp +++ b/src/Mod/PartDesign/Gui/TaskDatumParameters.cpp @@ -223,7 +223,7 @@ TaskDatumParameters::TaskDatumParameters(ViewProviderDatum *DatumView,QWidget *p DatumView->setPickable(false); - Gui::Selection().addSelectionGate(new NoDependentsSelection(DatumView->getObject(), true, true, true, true)); + Gui::Selection().addSelectionGate(new NoDependentsSelection(DatumView->getObject())); // connect object deletion with slot auto bnd = boost::bind(&TaskDatumParameters::objectDeleted, this, _1); diff --git a/src/Mod/PartDesign/Gui/TaskMirroredParameters.cpp b/src/Mod/PartDesign/Gui/TaskMirroredParameters.cpp index 43e3c72ed..33a4f8885 100644 --- a/src/Mod/PartDesign/Gui/TaskMirroredParameters.cpp +++ b/src/Mod/PartDesign/Gui/TaskMirroredParameters.cpp @@ -184,23 +184,18 @@ void TaskMirroredParameters::onSelectionChanged(const Gui::SelectionChanges& msg removeItemFromListWidget(ui->listWidgetFeatures, msg.pObjectName); exitSelectionMode(); } else { - // TODO checkme (2015-09-01, Fat-Zer) - exitSelectionMode(); - std::vector mirrorPlanes; - App::DocumentObject* selObj; - PartDesign::Mirrored* pcMirrored = static_cast(getObject()); - getReferencedSelection(pcMirrored, msg, selObj, mirrorPlanes); - if(!selObj) - return; - // Note: ReferenceSelection has already checked the selection for validity - if ( selectionMode == reference || - selObj->isDerivedFrom ( App::Plane::getClassTypeId () ) || - selObj->isDerivedFrom(PartDesign::Plane::getClassTypeId())) { + if ( selectionMode == reference) { + std::vector mirrorPlanes; + App::DocumentObject* selObj; + PartDesign::Mirrored* pcMirrored = static_cast(getObject()); + getReferencedSelection(pcMirrored, msg, selObj, mirrorPlanes); + if (!selObj) + return; pcMirrored->MirrorPlane.setValue(selObj, mirrorPlanes); - recomputeFeature(); updateUI(); } + exitSelectionMode(); } } } diff --git a/src/Mod/PartDesign/Gui/TaskTransformedParameters.cpp b/src/Mod/PartDesign/Gui/TaskTransformedParameters.cpp index 4067eb749..b29f1aca7 100644 --- a/src/Mod/PartDesign/Gui/TaskTransformedParameters.cpp +++ b/src/Mod/PartDesign/Gui/TaskTransformedParameters.cpp @@ -338,7 +338,9 @@ void TaskTransformedParameters::exitSelectionMode() void TaskTransformedParameters::addReferenceSelectionGate(bool edge, bool face) { - Gui::Selection().addSelectionGate(new ReferenceSelection(getBaseObject(), edge, face, /*point =*/ true)); + std::unique_ptr gateRefPtr = std::make_unique(getBaseObject(), edge, face, /*point =*/ true); + std::unique_ptr gateDepPtr = std::make_unique(getTopTransformedObject()); + Gui::Selection().addSelectionGate(new CombineSelectionFilterGates(gateRefPtr, gateDepPtr)); } //**************************************************************************