From 817fd9e638e232fcf94ca31d3ce1d0f5b7eee46f Mon Sep 17 00:00:00 2001 From: Kacper Donat Date: Sat, 28 Jun 2025 19:59:28 +0200 Subject: [PATCH] Sketcher: Use generic tool hints table for DrawSketchHandlerEllipse --- .../Sketcher/Gui/DrawSketchHandlerEllipse.h | 104 ++++++++---------- 1 file changed, 48 insertions(+), 56 deletions(-) diff --git a/src/Mod/Sketcher/Gui/DrawSketchHandlerEllipse.h b/src/Mod/Sketcher/Gui/DrawSketchHandlerEllipse.h index 90413ffd07..8559a95a41 100644 --- a/src/Mod/Sketcher/Gui/DrawSketchHandlerEllipse.h +++ b/src/Mod/Sketcher/Gui/DrawSketchHandlerEllipse.h @@ -84,22 +84,56 @@ public: ~DrawSketchHandlerEllipse() override = default; private: - struct HintEntry - { - ConstructionMethod method; - SelectMode state; - std::list hints; - }; - - using HintTable = std::vector; - - static HintTable getEllipseHintTable(); - static std::list lookupEllipseHints(ConstructionMethod method, - SelectMode state); - std::list getToolHints() const override { - return lookupEllipseHints(constructionMethod(), state()); + using State = std::pair; + using enum Gui::InputHint::UserInput; + + const Gui::InputHint switchModeHint {QObject::tr("%1 switch mode"), {KeyM}}; + + return Gui::lookupHints( + {constructionMethod(), state()}, + { + // Center method + {.state = {ConstructionMethod::Center, SelectMode::SeekFirst}, + .hints = + { + {QObject::tr("%1 pick ellipse center"), {MouseLeft}}, + switchModeHint, + }}, + {.state = {ConstructionMethod::Center, SelectMode::SeekSecond}, + .hints = + { + {QObject::tr("%1 pick axis endpoint"), {MouseLeft}}, + switchModeHint, + }}, + {.state = {ConstructionMethod::Center, SelectMode::SeekThird}, + .hints = + { + {QObject::tr("%1 pick minor axis endpoint"), {MouseLeft}}, + switchModeHint, + }}, + + // ThreeRim method + {.state = {ConstructionMethod::ThreeRim, SelectMode::SeekFirst}, + .hints = + { + {QObject::tr("%1 pick first rim point"), {MouseLeft}}, + switchModeHint, + }}, + {.state = {ConstructionMethod::ThreeRim, SelectMode::SeekSecond}, + .hints = + { + {QObject::tr("%1 pick second rim point"), {MouseLeft}}, + switchModeHint, + }}, + {.state = {ConstructionMethod::ThreeRim, SelectMode::SeekThird}, + .hints = + { + {QObject::tr("%1 pick third rim point"), {MouseLeft}}, + switchModeHint, + }}, + }); } void updateDataAndDrawToPosition(Base::Vector2d onSketchPos) override @@ -978,48 +1012,6 @@ void DSHEllipseController::addConstraints() } // No constraint possible for 3 rim ellipse. } - -DrawSketchHandlerEllipse::HintTable DrawSketchHandlerEllipse::getEllipseHintTable() -{ - return { - // Structure: {ConstructionMethod, SelectMode, {hints...}} - - // Center method - {ConstructionMethod::Center, - SelectMode::SeekFirst, - {{QObject::tr("%1 pick ellipse center"), {Gui::InputHint::UserInput::MouseLeft}}}}, - {ConstructionMethod::Center, - SelectMode::SeekSecond, - {{QObject::tr("%1 pick axis endpoint"), {Gui::InputHint::UserInput::MouseLeft}}}}, - {ConstructionMethod::Center, - SelectMode::SeekThird, - {{QObject::tr("%1 pick minor axis endpoint"), {Gui::InputHint::UserInput::MouseLeft}}}}, - - // ThreeRim method - {ConstructionMethod::ThreeRim, - SelectMode::SeekFirst, - {{QObject::tr("%1 pick first rim point"), {Gui::InputHint::UserInput::MouseLeft}}}}, - {ConstructionMethod::ThreeRim, - SelectMode::SeekSecond, - {{QObject::tr("%1 pick second rim point"), {Gui::InputHint::UserInput::MouseLeft}}}}, - {ConstructionMethod::ThreeRim, - SelectMode::SeekThird, - {{QObject::tr("%1 pick third rim point"), {Gui::InputHint::UserInput::MouseLeft}}}}}; -} - -std::list DrawSketchHandlerEllipse::lookupEllipseHints(ConstructionMethod method, - SelectMode state) -{ - const auto ellipseHintTable = getEllipseHintTable(); - - auto it = std::find_if(ellipseHintTable.begin(), - ellipseHintTable.end(), - [method, state](const HintEntry& entry) { - return entry.method == method && entry.state == state; - }); - - return (it != ellipseHintTable.end()) ? it->hints : std::list {}; -} } // namespace SketcherGui