From 90db4c885b044c9a6d168632df8493dc2503904c Mon Sep 17 00:00:00 2001 From: wmayer Date: Tue, 7 Dec 2021 11:04:22 +0100 Subject: [PATCH] PD: eliminate the boolean argument from TaskSketchBasedParameters::onSelectReference --- src/Mod/PartDesign/Gui/EnumFlags.h | 2 +- src/Mod/PartDesign/Gui/TaskExtrudeParameters.cpp | 8 ++++---- src/Mod/PartDesign/Gui/TaskHelixParameters.cpp | 6 +++--- src/Mod/PartDesign/Gui/TaskRevolutionParameters.cpp | 6 +++--- src/Mod/PartDesign/Gui/TaskSketchBasedParameters.cpp | 6 +++--- src/Mod/PartDesign/Gui/TaskSketchBasedParameters.h | 8 +++++++- 6 files changed, 21 insertions(+), 15 deletions(-) diff --git a/src/Mod/PartDesign/Gui/EnumFlags.h b/src/Mod/PartDesign/Gui/EnumFlags.h index ecd410a6b5..8415e3e8d6 100644 --- a/src/Mod/PartDesign/Gui/EnumFlags.h +++ b/src/Mod/PartDesign/Gui/EnumFlags.h @@ -33,7 +33,7 @@ namespace PartDesignGui { // https://stackoverflow.com/questions/1448396/how-to-use-enums-as-flags-in-c enum class AllowSelection { - NONE = 0, + NONE = 0, /**< This is used to indicate to stop the selection */ EDGE = 1 << 0, /**< Allow picking edges */ FACE = 1 << 1, /**< Allow picking faces */ PLANAR = 1 << 2, /**< Allow only linear edges and planar faces */ diff --git a/src/Mod/PartDesign/Gui/TaskExtrudeParameters.cpp b/src/Mod/PartDesign/Gui/TaskExtrudeParameters.cpp index b5cb476111..711ae4051b 100644 --- a/src/Mod/PartDesign/Gui/TaskExtrudeParameters.cpp +++ b/src/Mod/PartDesign/Gui/TaskExtrudeParameters.cpp @@ -411,9 +411,9 @@ void TaskExtrudeParameters::onDirectionCBChanged(int num) // to distinguish that this is the direction selection selectionFace = false; setDirectionMode(num); - TaskSketchBasedParameters::onSelectReference(true, AllowSelection::EDGE | - AllowSelection::PLANAR | - AllowSelection::CIRCLE); + TaskSketchBasedParameters::onSelectReference(AllowSelection::EDGE | + AllowSelection::PLANAR | + AllowSelection::CIRCLE); } else { if (lnk.getValue()) { @@ -566,7 +566,7 @@ void TaskExtrudeParameters::onButtonFace(const bool pressed) selectionFace = true; // only faces are allowed - TaskSketchBasedParameters::onSelectReference(pressed, AllowSelection::FACE); + TaskSketchBasedParameters::onSelectReference(pressed ? AllowSelection::FACE : AllowSelection::NONE); // Update button if onButtonFace() is called explicitly ui->buttonFace->setChecked(pressed); diff --git a/src/Mod/PartDesign/Gui/TaskHelixParameters.cpp b/src/Mod/PartDesign/Gui/TaskHelixParameters.cpp index 90aa77dbb3..eeaeb9d2c9 100644 --- a/src/Mod/PartDesign/Gui/TaskHelixParameters.cpp +++ b/src/Mod/PartDesign/Gui/TaskHelixParameters.cpp @@ -425,9 +425,9 @@ void TaskHelixParameters::onAxisChanged(int num) App::PropertyLinkSub& lnk = *(axesInList[num]); if (lnk.getValue() == 0) { // enter reference selection mode - TaskSketchBasedParameters::onSelectReference(true, AllowSelection::EDGE | - AllowSelection::PLANAR | - AllowSelection::CIRCLE); + TaskSketchBasedParameters::onSelectReference(AllowSelection::EDGE | + AllowSelection::PLANAR | + AllowSelection::CIRCLE); return; } else { diff --git a/src/Mod/PartDesign/Gui/TaskRevolutionParameters.cpp b/src/Mod/PartDesign/Gui/TaskRevolutionParameters.cpp index a8db50ea67..6daba19ca7 100644 --- a/src/Mod/PartDesign/Gui/TaskRevolutionParameters.cpp +++ b/src/Mod/PartDesign/Gui/TaskRevolutionParameters.cpp @@ -262,9 +262,9 @@ void TaskRevolutionParameters::onAxisChanged(int num) App::PropertyLinkSub &lnk = *(axesInList[num]); if (lnk.getValue() == 0) { // enter reference selection mode - TaskSketchBasedParameters::onSelectReference(true, AllowSelection::EDGE | - AllowSelection::PLANAR | - AllowSelection::CIRCLE); + TaskSketchBasedParameters::onSelectReference(AllowSelection::EDGE | + AllowSelection::PLANAR | + AllowSelection::CIRCLE); } else { if (!pcRevolution->getDocument()->isIn(lnk.getValue())){ Base::Console().Error("Object was deleted\n"); diff --git a/src/Mod/PartDesign/Gui/TaskSketchBasedParameters.cpp b/src/Mod/PartDesign/Gui/TaskSketchBasedParameters.cpp index e5a7ddf572..7375f7f1b9 100644 --- a/src/Mod/PartDesign/Gui/TaskSketchBasedParameters.cpp +++ b/src/Mod/PartDesign/Gui/TaskSketchBasedParameters.cpp @@ -112,7 +112,7 @@ void TaskSketchBasedParameters::finishReferenceSelection(App::DocumentObject* pr } } -void TaskSketchBasedParameters::onSelectReference(const bool pressed, AllowSelectionFlags allow) { +void TaskSketchBasedParameters::onSelectReference(AllowSelectionFlags allow) { // Note: Even if there is no solid, App::Plane and Part::Datum can still be selected PartDesign::ProfileBased* pcSketchBased = dynamic_cast(vp->getObject()); @@ -120,7 +120,7 @@ void TaskSketchBasedParameters::onSelectReference(const bool pressed, AllowSelec // The solid this feature will be fused to App::DocumentObject* prevSolid = pcSketchBased->getBaseObject( /* silent =*/ true ); - if (pressed) { + if (AllowSelectionFlags::Int(allow) != int(AllowSelection::NONE)) { startReferenceSelection(pcSketchBased, prevSolid); Gui::Selection().clearSelection(); Gui::Selection().addSelectionGate(new ReferenceSelection(prevSolid, allow)); @@ -135,7 +135,7 @@ void TaskSketchBasedParameters::onSelectReference(const bool pressed, AllowSelec void TaskSketchBasedParameters::exitSelectionMode() { - onSelectReference(false, AllowSelection::NONE); + onSelectReference(AllowSelection::NONE); } QVariant TaskSketchBasedParameters::setUpToFace(const QString& text) diff --git a/src/Mod/PartDesign/Gui/TaskSketchBasedParameters.h b/src/Mod/PartDesign/Gui/TaskSketchBasedParameters.h index 5fd872f256..6e7f34daa5 100644 --- a/src/Mod/PartDesign/Gui/TaskSketchBasedParameters.h +++ b/src/Mod/PartDesign/Gui/TaskSketchBasedParameters.h @@ -54,7 +54,13 @@ protected: const QString onAddSelection(const Gui::SelectionChanges& msg); virtual void startReferenceSelection(App::DocumentObject* profile, App::DocumentObject* base); virtual void finishReferenceSelection(App::DocumentObject* profile, App::DocumentObject* base); - void onSelectReference(const bool pressed, AllowSelectionFlags); + /*! + * \brief onSelectReference + * Start reference selection mode to allow to select objects of the type defined + * with \a AllowSelectionFlags. + * If AllowSelection::NONE is passed the selection mode is finished. + */ + void onSelectReference(AllowSelectionFlags); void exitSelectionMode(); QVariant setUpToFace(const QString& text); /// Try to find the name of a feature with the given label.