diff --git a/src/Mod/Sketcher/Gui/Command.cpp b/src/Mod/Sketcher/Gui/Command.cpp index 5b694dacae..9264ae4f99 100644 --- a/src/Mod/Sketcher/Gui/Command.cpp +++ b/src/Mod/Sketcher/Gui/Command.cpp @@ -50,6 +50,7 @@ #include "SketchOrientationDialog.h" #include "TaskSketcherValidation.h" #include "ViewProviderSketch.h" +#include "Utils.h" using namespace std; @@ -130,14 +131,6 @@ namespace SketcherGui { } } //namespace SketcherGui -bool isSketchInEdit(Gui::Document* doc) { - if (doc) { - // checks if a Sketch Viewprovider is in Edit and is in no special mode - auto* vp = dynamic_cast(doc->getInEdit()); - return (vp != nullptr); - } - return false; -} /* Sketch commands =======================================================*/ DEF_STD_CMD_A(CmdSketcherNewSketch) @@ -363,13 +356,7 @@ void CmdSketcherStopOperation::activated(int iMsg) bool CmdSketcherStopOperation::isActive() { - Gui::Document *doc = getActiveGuiDocument(); - if (doc) { - SketcherGui::ViewProviderSketch* vp = dynamic_cast(doc->getInEdit()); - if (vp) - return true; - } - return false; + return isSketchInEdit(getActiveGuiDocument()); } DEF_STD_CMD_A(CmdSketcherReorientSketch) diff --git a/src/Mod/Sketcher/Gui/Utils.cpp b/src/Mod/Sketcher/Gui/Utils.cpp index 0e21358b49..90e82389da 100644 --- a/src/Mod/Sketcher/Gui/Utils.cpp +++ b/src/Mod/Sketcher/Gui/Utils.cpp @@ -315,22 +315,28 @@ void SketcherGui::ActivateHandler(Gui::Document* doc, DrawSketchHandler* handler } } -bool SketcherGui::isCommandActive(Gui::Document* doc, bool actsOnSelection) -{ +bool SketcherGui::isSketchInEdit(Gui::Document* doc) { if (doc) { // checks if a Sketch Viewprovider is in Edit and is in no special mode - if (doc->getInEdit() - && doc->getInEdit()->isDerivedFrom(SketcherGui::ViewProviderSketch::getClassTypeId())) { - auto mode = - static_cast(doc->getInEdit())->getSketchMode(); - if (mode == ViewProviderSketch::STATUS_NONE - || mode == ViewProviderSketch::STATUS_SKETCH_UseHandler) { - if (!actsOnSelection) - return true; - else if (Gui::Selection().countObjectsOfType( - Sketcher::SketchObject::getClassTypeId()) - > 0) - return true; + auto* vp = dynamic_cast(doc->getInEdit()); + return (vp != nullptr); + } + return false; +} + +bool SketcherGui::isCommandActive(Gui::Document* doc, bool actsOnSelection) +{ + if(isSketchInEdit(doc)) { + auto mode = static_cast(doc->getInEdit())->getSketchMode(); + + if (mode == ViewProviderSketch::STATUS_NONE || + mode == ViewProviderSketch::STATUS_SKETCH_UseHandler) { + + if (!actsOnSelection) { + return true; + } + else if (Gui::Selection().countObjectsOfType(Sketcher::SketchObject::getClassTypeId()) > 0) { + return true; } } } diff --git a/src/Mod/Sketcher/Gui/Utils.h b/src/Mod/Sketcher/Gui/Utils.h index c89cf0ff12..291e5682fb 100644 --- a/src/Mod/Sketcher/Gui/Utils.h +++ b/src/Mod/Sketcher/Gui/Utils.h @@ -117,6 +117,10 @@ double GetPointAngle (const Base::Vector2d &p1, const Base::Vector2d &p2); void ActivateHandler(Gui::Document *doc, DrawSketchHandler *handler); +/// Returns if a sketch is in edit mode +bool isSketchInEdit(Gui::Document* doc); + +/// Returns whether an edit mode command should be activated or not. It is only activated if the sketcher is no special state or a sketchHandler is active. bool isCommandActive(Gui::Document *doc, bool actsOnSelection = false); SketcherGui::ViewProviderSketch* getSketchViewprovider(Gui::Document *doc);