From 29a4f08ed3cffc8ecde33f3007f41800056a6b9b Mon Sep 17 00:00:00 2001 From: Eric Price <32105268+AIRCAP@users.noreply.github.com> Date: Mon, 7 Oct 2024 15:33:31 +0200 Subject: [PATCH] Changed QuickMeasurement to be conservative (#17060) * Changed QuickMeasurement to be conservative QuickMeasurement should not measure while tool dialogs are open this includes but is not limited to editing sketches also changed several other sanity checks to be opt-in vs opt-out, as discussed. * move the test if it is safe to measure to when the measurement actually happens - avoids any potential race conditions --- src/Mod/Measure/Gui/QuickMeasure.cpp | 34 ++++++++++++++++++---------- 1 file changed, 22 insertions(+), 12 deletions(-) diff --git a/src/Mod/Measure/Gui/QuickMeasure.cpp b/src/Mod/Measure/Gui/QuickMeasure.cpp index a2ba43d5c2..ffdaf354da 100644 --- a/src/Mod/Measure/Gui/QuickMeasure.cpp +++ b/src/Mod/Measure/Gui/QuickMeasure.cpp @@ -36,7 +36,7 @@ #include #include #include -#include +#include #include #include @@ -104,31 +104,41 @@ void QuickMeasure::processSelection() void QuickMeasure::tryMeasureSelection() { + Gui::Document* doc = Gui::Application::Instance->activeDocument(); measurement->clear(); - addSelectionToMeasurement(); + if (doc && Gui::Control().activeDialog() == nullptr) { + // we (still) have a doc and are not in a tool dialog where the user needs to click on stuff + addSelectionToMeasurement(); + } printResult(); } bool QuickMeasure::shouldMeasure(const Gui::SelectionChanges& msg) const { - if (msg.Type == Gui::SelectionChanges::SetPreselect - || msg.Type == Gui::SelectionChanges::RmvPreselect) { - return false; - } + // measure only IF Gui::Document* doc = Gui::Application::Instance->activeDocument(); - return doc != nullptr; + if (doc) { + // we have a document + if (msg.Type == Gui::SelectionChanges::AddSelection + || msg.Type == Gui::SelectionChanges::RmvSelection + || msg.Type == Gui::SelectionChanges::SetSelection + || msg.Type == Gui::SelectionChanges::ClrSelection) { + // the event is about a change in selected objects + return true; + } + } + return false; } bool QuickMeasure::isObjAcceptable(App::DocumentObject* obj) { - if (!obj || !obj->isDerivedFrom(Part::Feature::getClassTypeId())) { - return false; + // only measure shapes + if (obj && obj->isDerivedFrom(Part::Feature::getClassTypeId())) { + return true; } - std::string vpType = obj->getViewProviderName(); - auto* vp = Gui::Application::Instance->getViewProvider(obj); - return !(vpType == "SketcherGui::ViewProviderSketch" && vp && vp->isEditing()); + return false; } void QuickMeasure::addSelectionToMeasurement()