From c43658ea897df9b5aa5a23800b8bcdb239b73cc5 Mon Sep 17 00:00:00 2001 From: PaddleStroke Date: Wed, 15 May 2024 14:40:25 +0200 Subject: [PATCH] Sketcher: fixes #13999 --- .../Gui/DrawSketchControllableHandler.h | 10 +++++---- .../Sketcher/Gui/DrawSketchDefaultHandler.h | 21 +++++++++++++------ 2 files changed, 21 insertions(+), 10 deletions(-) diff --git a/src/Mod/Sketcher/Gui/DrawSketchControllableHandler.h b/src/Mod/Sketcher/Gui/DrawSketchControllableHandler.h index 2dd00ad373..6b07bd3baf 100644 --- a/src/Mod/Sketcher/Gui/DrawSketchControllableHandler.h +++ b/src/Mod/Sketcher/Gui/DrawSketchControllableHandler.h @@ -157,13 +157,15 @@ private: toolWidgetManager.resetControls(); } - void onModeChanged() override + bool onModeChanged() override { DrawSketchHandler::resetPositionText(); toolWidgetManager.onHandlerModeChanged(); - DSDefaultHandler::onModeChanged(); - - toolWidgetManager.afterHandlerModeChanged(); + if (DSDefaultHandler::onModeChanged()) { + // If onModeChanged returns false, then the handler has been purged. + toolWidgetManager.afterHandlerModeChanged(); + } + return true; } void onConstructionMethodChanged() override diff --git a/src/Mod/Sketcher/Gui/DrawSketchDefaultHandler.h b/src/Mod/Sketcher/Gui/DrawSketchDefaultHandler.h index da16ac413f..578d18f4b1 100644 --- a/src/Mod/Sketcher/Gui/DrawSketchDefaultHandler.h +++ b/src/Mod/Sketcher/Gui/DrawSketchDefaultHandler.h @@ -219,7 +219,10 @@ protected: } } - virtual void onModeChanged() {}; + virtual bool onModeChanged() + { + return true; + }; private: SelectModeT Mode; @@ -479,8 +482,10 @@ protected: * 3. createAutoConstraints() : Must be provided with the commands to create autoconstraints * * It recomputes if not solves and handles continuous mode automatically + * + * It returns true if the handler has been purged. */ - void finish() + bool finish() { if (this->isState(SelectMode::End)) { unsetCursor(); @@ -507,8 +512,9 @@ protected: Base::Console().Error(e.what()); } - handleContinuousMode(); + return handleContinuousMode(); } + return false; } /** @brief This function resets the handler to the initial state. @@ -547,16 +553,18 @@ protected: * * It performs all the operations in reset(). */ - void handleContinuousMode() + bool handleContinuousMode() { if (continuousMode) { // This code enables the continuous creation mode. reset(); // It is ok not to call to purgeHandler in continuous creation mode because the // handler is destroyed by the quit() method on pressing the right button of the mouse + return false; } else { sketchgui->purgeHandler(); // no code after, Handler get deleted in ViewProvider + return true; } } //@} @@ -627,10 +635,11 @@ protected: /** @brief Default behaviour that upon arriving to the End state of the state machine, the * command is finished. */ - void onModeChanged() override + bool onModeChanged() override { angleSnappingControl(); - finish(); // internally checks that state is SelectMode::End, and only finishes then. + return !finish(); // internally checks that state is SelectMode::End, and only finishes + // then. }; //@}