From 5c1d097161a8b44ce3906f2d7dfe472ab12aa4df Mon Sep 17 00:00:00 2001 From: Kacper Donat Date: Sat, 28 Jun 2025 19:59:27 +0200 Subject: [PATCH] Sketcher: Use generic tool hints table for DrawSketchHandlerBSpline --- .../Sketcher/Gui/DrawSketchHandlerBSpline.h | 108 +++++++----------- 1 file changed, 40 insertions(+), 68 deletions(-) diff --git a/src/Mod/Sketcher/Gui/DrawSketchHandlerBSpline.h b/src/Mod/Sketcher/Gui/DrawSketchHandlerBSpline.h index 0d12a1f76e..6d90ae37fb 100644 --- a/src/Mod/Sketcher/Gui/DrawSketchHandlerBSpline.h +++ b/src/Mod/Sketcher/Gui/DrawSketchHandlerBSpline.h @@ -95,10 +95,6 @@ public: } private: - std::list getToolHints() const override - { - return lookupBSplineHints(constructionMethod(), state()); - } void updateDataAndDrawToPosition(Base::Vector2d onSketchPos) override { prevCursorPosition = onSketchPos; @@ -408,6 +404,46 @@ private: sugConstraints[1].clear(); } + std::list getToolHints() const override + { + using State = std::pair; + using enum Gui::InputHint::UserInput; + + const auto switchHint = + Gui::InputHint {.message = QObject::tr("%1 switch mode"), .sequences = {KeyM}}; + + return Gui::lookupHints( + {constructionMethod(), state()}, + {// ControlPoints method + {.state = {ConstructionMethod::ControlPoints, SelectMode::SeekFirst}, + .hints = + { + {QObject::tr("%1 pick first control point"), {MouseLeft}}, + switchHint, + }}, + {.state = {ConstructionMethod::ControlPoints, SelectMode::SeekSecond}, + .hints = + { + {QObject::tr("%1 pick next control point"), {MouseLeft}}, + {QObject::tr("%1 finish B-spline"), {MouseRight}}, + switchHint, + }}, + + // Knots method + {.state = {ConstructionMethod::Knots, SelectMode::SeekFirst}, + .hints = + { + {QObject::tr("%1 pick first knot"), {MouseLeft}}, + switchHint, + }}, + {.state = {ConstructionMethod::Knots, SelectMode::SeekSecond}, + .hints = { + {QObject::tr("%1 pick next knot"), {MouseLeft}}, + {QObject::tr("%1 finish B-spline"), {MouseRight}}, + switchHint, + }}}); + } + std::string getToolName() const override { return "DSH_BSpline"; @@ -792,21 +828,6 @@ private: } } } - -private: - struct HintEntry - { - ConstructionMethod method; - SelectMode state; - std::list hints; - }; - - using HintTable = std::vector; - - static Gui::InputHint switchModeHint(); - static HintTable getBSplineHintTable(); - static std::list lookupBSplineHints(ConstructionMethod method, - SelectMode state); }; template<> @@ -1226,55 +1247,6 @@ void DSHBSplineController::addConstraints() } } -Gui::InputHint DrawSketchHandlerBSpline::switchModeHint() -{ - return {QObject::tr("%1 switch mode"), {Gui::InputHint::UserInput::KeyM}}; -} - -DrawSketchHandlerBSpline::HintTable DrawSketchHandlerBSpline::getBSplineHintTable() -{ - const auto switchHint = switchModeHint(); - return { - // Structure: {ConstructionMethod, SelectMode, {hints...}} - - // ControlPoints method - {ConstructionMethod::ControlPoints, - SelectMode::SeekFirst, - {{QObject::tr("%1 pick first control point"), {Gui::InputHint::UserInput::MouseLeft}}, - switchHint}}, - {ConstructionMethod::ControlPoints, - SelectMode::SeekSecond, - {{QObject::tr("%1 pick next control point"), {Gui::InputHint::UserInput::MouseLeft}}, - {QObject::tr("%1 finish B-spline"), {Gui::InputHint::UserInput::MouseRight}}, - switchHint}}, - - // Knots method - {ConstructionMethod::Knots, - SelectMode::SeekFirst, - {{QObject::tr("%1 pick first knot"), {Gui::InputHint::UserInput::MouseLeft}}, switchHint}}, - {ConstructionMethod::Knots, - SelectMode::SeekSecond, - {{QObject::tr("%1 pick next knot"), {Gui::InputHint::UserInput::MouseLeft}}, - {QObject::tr("%1 finish B-spline"), {Gui::InputHint::UserInput::MouseRight}}, - switchHint}}}; -} - -std::list DrawSketchHandlerBSpline::lookupBSplineHints(ConstructionMethod method, - SelectMode state) -{ - const auto bSplineHintTable = getBSplineHintTable(); - - auto it = std::find_if(bSplineHintTable.begin(), - bSplineHintTable.end(), - [method, state](const HintEntry& entry) { - return entry.method == method && entry.state == state; - }); - - return (it != bSplineHintTable.end()) ? it->hints : std::list {}; -} -// TODO: On pressing, say, W, modify last pole's weight -// TODO: On pressing, say, M, modify next knot's multiplicity - } // namespace SketcherGui