diff --git a/src/Mod/Sketcher/Gui/DrawSketchHandlerArc.h b/src/Mod/Sketcher/Gui/DrawSketchHandlerArc.h index 54123fb115..4e72ddebd3 100644 --- a/src/Mod/Sketcher/Gui/DrawSketchHandlerArc.h +++ b/src/Mod/Sketcher/Gui/DrawSketchHandlerArc.h @@ -28,7 +28,8 @@ #include #include #include - +#include +#include #include #include @@ -41,6 +42,9 @@ #include "CircleEllipseConstructionMethod.h" +#include +#include + using namespace std; namespace SketcherGui @@ -84,6 +88,11 @@ public: ~DrawSketchHandlerArc() override = default; private: + std::list getToolHints() const override + { + return lookupArcHints(constructionMethod(), state()); + } + void updateDataAndDrawToPosition(Base::Vector2d onSketchPos) override { switch (state()) { @@ -423,6 +432,21 @@ private: } } + // Hint table structures + struct HintEntry + { + ConstructionMethod method; + SelectMode state; + std::list hints; + }; + + using HintTable = std::vector; + + // Static declaration + static Gui::InputHint switchModeHint(); + static HintTable getArcHintTable(); + static std::list lookupArcHints(ConstructionMethod method, SelectMode state); + private: Base::Vector2d centerPoint, firstPoint, secondPoint; double radius, startAngle, endAngle, arcAngle; @@ -887,6 +911,66 @@ void DSHArcController::addConstraints() } } +template<> +void DSHArcController::doConstructionMethodChanged() +{ + handler->updateHint(); +} + +// Static member definitions +Gui::InputHint DrawSketchHandlerArc::switchModeHint() +{ + return {QObject::tr("%1 switch mode"), {Gui::InputHint::UserInput::KeyM}}; +} + +DrawSketchHandlerArc::HintTable DrawSketchHandlerArc::getArcHintTable() +{ + const auto switchHint = switchModeHint(); + return { + // Structure: {ConstructionMethod, SelectMode, {hints...}} + + // Center method + {ConstructionMethod::Center, + SelectMode::SeekFirst, + {{QObject::tr("%1 pick arc center"), {Gui::InputHint::UserInput::MouseLeft}}, switchHint}}, + {ConstructionMethod::Center, + SelectMode::SeekSecond, + {{QObject::tr("%1 pick arc start point"), {Gui::InputHint::UserInput::MouseLeft}}, + switchHint}}, + {ConstructionMethod::Center, + SelectMode::SeekThird, + {{QObject::tr("%1 pick arc end point"), {Gui::InputHint::UserInput::MouseLeft}}, + switchHint}}, + + // ThreeRim method + {ConstructionMethod::ThreeRim, + SelectMode::SeekFirst, + {{QObject::tr("%1 pick first arc point"), {Gui::InputHint::UserInput::MouseLeft}}, + switchHint}}, + {ConstructionMethod::ThreeRim, + SelectMode::SeekSecond, + {{QObject::tr("%1 pick second arc point"), {Gui::InputHint::UserInput::MouseLeft}}, + switchHint}}, + {ConstructionMethod::ThreeRim, + SelectMode::SeekThird, + {{QObject::tr("%1 pick third arc point"), {Gui::InputHint::UserInput::MouseLeft}}, + switchHint}}}; +} + +std::list DrawSketchHandlerArc::lookupArcHints(ConstructionMethod method, + SelectMode state) +{ + const auto arcHintTable = getArcHintTable(); + + auto it = std::find_if(arcHintTable.begin(), + arcHintTable.end(), + [method, state](const HintEntry& entry) { + return entry.method == method && entry.state == state; + }); + + return (it != arcHintTable.end()) ? it->hints : std::list {}; +} + } // namespace SketcherGui diff --git a/src/Mod/Sketcher/Gui/DrawSketchHandlerArcOfEllipse.h b/src/Mod/Sketcher/Gui/DrawSketchHandlerArcOfEllipse.h index a4ebaad0f1..0e46759865 100644 --- a/src/Mod/Sketcher/Gui/DrawSketchHandlerArcOfEllipse.h +++ b/src/Mod/Sketcher/Gui/DrawSketchHandlerArcOfEllipse.h @@ -26,6 +26,7 @@ #include #include #include +#include #include @@ -218,6 +219,8 @@ public: setAngleSnapping(false); Mode = STATUS_Close; } + + updateHint(); return true; } @@ -382,6 +385,9 @@ public: // ViewProvider } } + + updateHint(); + return true; } @@ -397,8 +403,52 @@ protected: Base::Vector2d centerPoint, axisPoint, startingPoint, endPoint; double rx, ry, startAngle, endAngle, arcAngle, arcAngle_t; std::vector sugConstr1, sugConstr2, sugConstr3, sugConstr4; + +private: + std::list getToolHints() const override + { + return lookupArcOfEllipseHints(Mode); + } + +private: + struct HintEntry + { + int mode; + std::list hints; + }; + + using HintTable = std::vector; + + static HintTable getArcOfEllipseHintTable(); + static std::list lookupArcOfEllipseHints(int mode); }; +DrawSketchHandlerArcOfEllipse::HintTable DrawSketchHandlerArcOfEllipse::getArcOfEllipseHintTable() +{ + return {// Structure: {mode, {hints...}} + {STATUS_SEEK_First, + {{QObject::tr("%1 pick ellipse center"), {Gui::InputHint::UserInput::MouseLeft}}}}, + {STATUS_SEEK_Second, + {{QObject::tr("%1 pick axis point"), {Gui::InputHint::UserInput::MouseLeft}}}}, + {STATUS_SEEK_Third, + {{QObject::tr("%1 pick arc start point"), {Gui::InputHint::UserInput::MouseLeft}}}}, + {STATUS_SEEK_Fourth, + {{QObject::tr("%1 pick arc end point"), {Gui::InputHint::UserInput::MouseLeft}}}}}; +} + +std::list DrawSketchHandlerArcOfEllipse::lookupArcOfEllipseHints(int mode) +{ + const auto arcOfEllipseHintTable = getArcOfEllipseHintTable(); + + auto it = std::find_if(arcOfEllipseHintTable.begin(), + arcOfEllipseHintTable.end(), + [mode](const HintEntry& entry) { + return entry.mode == mode; + }); + + return (it != arcOfEllipseHintTable.end()) ? it->hints : std::list {}; +} + } // namespace SketcherGui diff --git a/src/Mod/Sketcher/Gui/DrawSketchHandlerArcOfHyperbola.h b/src/Mod/Sketcher/Gui/DrawSketchHandlerArcOfHyperbola.h index 9f96e3f169..42eee19f90 100644 --- a/src/Mod/Sketcher/Gui/DrawSketchHandlerArcOfHyperbola.h +++ b/src/Mod/Sketcher/Gui/DrawSketchHandlerArcOfHyperbola.h @@ -28,6 +28,7 @@ #include #include #include +#include #include @@ -210,6 +211,8 @@ public: Mode = STATUS_Close; } + + updateHint(); return true; } @@ -391,6 +394,7 @@ public: // ViewProvider } } + updateHint(); return true; } @@ -407,8 +411,52 @@ protected: Base::Vector2d centerPoint, axisPoint, startingPoint, endPoint; double arcAngle, arcAngle_t; std::vector sugConstr1, sugConstr2, sugConstr3, sugConstr4; + +private: + std::list getToolHints() const override + { + return lookupArcOfHyperbolaHints(Mode); + } + +private: + struct HintEntry + { + int mode; + std::list hints; + }; + + using HintTable = std::vector; + + static HintTable getArcOfHyperbolaHintTable(); + static std::list lookupArcOfHyperbolaHints(int mode); }; +DrawSketchHandlerArcOfHyperbola::HintTable +DrawSketchHandlerArcOfHyperbola::getArcOfHyperbolaHintTable() +{ + return {// Structure: {mode, {hints...}} + {STATUS_SEEK_First, + {{QObject::tr("%1 pick center point"), {Gui::InputHint::UserInput::MouseLeft}}}}, + {STATUS_SEEK_Second, + {{QObject::tr("%1 pick axis point"), {Gui::InputHint::UserInput::MouseLeft}}}}, + {STATUS_SEEK_Third, + {{QObject::tr("%1 pick arc start point"), {Gui::InputHint::UserInput::MouseLeft}}}}, + {STATUS_SEEK_Fourth, + {{QObject::tr("%1 pick arc end point"), {Gui::InputHint::UserInput::MouseLeft}}}}}; +} + +std::list DrawSketchHandlerArcOfHyperbola::lookupArcOfHyperbolaHints(int mode) +{ + const auto arcOfHyperbolaHintTable = getArcOfHyperbolaHintTable(); + + auto it = std::find_if(arcOfHyperbolaHintTable.begin(), + arcOfHyperbolaHintTable.end(), + [mode](const HintEntry& entry) { + return entry.mode == mode; + }); + + return (it != arcOfHyperbolaHintTable.end()) ? it->hints : std::list {}; +} } // namespace SketcherGui diff --git a/src/Mod/Sketcher/Gui/DrawSketchHandlerArcOfParabola.h b/src/Mod/Sketcher/Gui/DrawSketchHandlerArcOfParabola.h index 1df0950fe0..e84b1e100e 100644 --- a/src/Mod/Sketcher/Gui/DrawSketchHandlerArcOfParabola.h +++ b/src/Mod/Sketcher/Gui/DrawSketchHandlerArcOfParabola.h @@ -29,6 +29,7 @@ #include #include +#include #include @@ -193,6 +194,8 @@ public: endPoint = onSketchPos; Mode = STATUS_Close; } + + updateHint(); return true; } @@ -313,6 +316,7 @@ public: // ViewProvider } } + updateHint(); return true; } @@ -328,9 +332,52 @@ protected: Base::Vector2d focusPoint, axisPoint, startingPoint, endPoint; double startAngle, endAngle, arcAngle, arcAngle_t; std::vector sugConstr1, sugConstr2, sugConstr3, sugConstr4; + +private: + std::list getToolHints() const override + { + return lookupParabolaHints(Mode); + } + +private: + struct HintEntry + { + int mode; + std::list hints; + }; + + using HintTable = std::vector; + + static HintTable getParabolaHintTable(); + static std::list lookupParabolaHints(int mode); }; +DrawSketchHandlerArcOfParabola::HintTable DrawSketchHandlerArcOfParabola::getParabolaHintTable() +{ + return {// Structure: {mode, {hints...}} + {STATUS_SEEK_First, + {{QObject::tr("%1 pick focus point"), {Gui::InputHint::UserInput::MouseLeft}}}}, + {STATUS_SEEK_Second, + {{QObject::tr("%1 pick axis point"), {Gui::InputHint::UserInput::MouseLeft}}}}, + {STATUS_SEEK_Third, + {{QObject::tr("%1 pick starting point"), {Gui::InputHint::UserInput::MouseLeft}}}}, + {STATUS_SEEK_Fourth, + {{QObject::tr("%1 pick end point"), {Gui::InputHint::UserInput::MouseLeft}}}}}; +} + +std::list DrawSketchHandlerArcOfParabola::lookupParabolaHints(int mode) +{ + const auto parabolaHintTable = getParabolaHintTable(); + + auto it = std::find_if(parabolaHintTable.begin(), + parabolaHintTable.end(), + [mode](const HintEntry& entry) { + return entry.mode == mode; + }); + + return (it != parabolaHintTable.end()) ? it->hints : std::list {}; +} + } // namespace SketcherGui - #endif // SKETCHERGUI_DrawSketchHandlerArcOfParabola_H diff --git a/src/Mod/Sketcher/Gui/DrawSketchHandlerArcSlot.h b/src/Mod/Sketcher/Gui/DrawSketchHandlerArcSlot.h index cbd996489a..e9de9cc68c 100644 --- a/src/Mod/Sketcher/Gui/DrawSketchHandlerArcSlot.h +++ b/src/Mod/Sketcher/Gui/DrawSketchHandlerArcSlot.h @@ -30,6 +30,7 @@ #include #include #include +#include #include @@ -93,6 +94,23 @@ public: ~DrawSketchHandlerArcSlot() override = default; private: + std::list getToolHints() const override + { + return lookupArcSlotHints(state()); + } + +private: + struct HintEntry + { + SelectMode state; + std::list hints; + }; + + using HintTable = std::vector; + + static HintTable getArcSlotHintTable(); + static std::list lookupArcSlotHints(SelectMode state); + void updateDataAndDrawToPosition(Base::Vector2d onSketchPos) override { switch (state()) { @@ -938,6 +956,32 @@ void DSHArcSlotController::addConstraints() } } +DrawSketchHandlerArcSlot::HintTable DrawSketchHandlerArcSlot::getArcSlotHintTable() +{ + return {// Structure: {SelectMode, {hints...}} + {SelectMode::SeekFirst, + {{QObject::tr("%1 pick slot center"), {Gui::InputHint::UserInput::MouseLeft}}}}, + {SelectMode::SeekSecond, + {{QObject::tr("%1 pick slot radius"), {Gui::InputHint::UserInput::MouseLeft}}}}, + {SelectMode::SeekThird, + {{QObject::tr("%1 pick slot angle"), {Gui::InputHint::UserInput::MouseLeft}}}}, + {SelectMode::SeekFourth, + {{QObject::tr("%1 pick slot width"), {Gui::InputHint::UserInput::MouseLeft}}}}}; +} + +std::list DrawSketchHandlerArcSlot::lookupArcSlotHints(SelectMode state) +{ + const auto arcSlotHintTable = getArcSlotHintTable(); + + auto it = std::find_if(arcSlotHintTable.begin(), + arcSlotHintTable.end(), + [state](const HintEntry& entry) { + return entry.state == state; + }); + + return (it != arcSlotHintTable.end()) ? it->hints : std::list {}; +} + } // namespace SketcherGui diff --git a/src/Mod/Sketcher/Gui/DrawSketchHandlerBSpline.h b/src/Mod/Sketcher/Gui/DrawSketchHandlerBSpline.h index ac79f17a90..05830bd4bb 100644 --- a/src/Mod/Sketcher/Gui/DrawSketchHandlerBSpline.h +++ b/src/Mod/Sketcher/Gui/DrawSketchHandlerBSpline.h @@ -29,7 +29,7 @@ #include #include #include - +#include #include #include "DrawSketchDefaultWidgetController.h" @@ -95,6 +95,10 @@ public: } private: + std::list getToolHints() const override + { + return lookupBSplineHints(constructionMethod(), state()); + } void updateDataAndDrawToPosition(Base::Vector2d onSketchPos) override { prevCursorPosition = onSketchPos; @@ -788,6 +792,21 @@ 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<> @@ -1086,6 +1105,8 @@ void DSHBSplineController::doConstructionMethodChanged() syncConstructionMethodComboboxToHandler(); bool byCtrlPoints = handler->constructionMethod() == ConstructionMethod::ControlPoints; toolWidget->setParameterVisible(WParameter::First, byCtrlPoints); + + handler->updateHint(); } @@ -1193,10 +1214,55 @@ 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 diff --git a/src/Mod/Sketcher/Gui/DrawSketchHandlerCircle.h b/src/Mod/Sketcher/Gui/DrawSketchHandlerCircle.h index e4151f601f..ef165ee0f7 100644 --- a/src/Mod/Sketcher/Gui/DrawSketchHandlerCircle.h +++ b/src/Mod/Sketcher/Gui/DrawSketchHandlerCircle.h @@ -28,6 +28,7 @@ #include #include #include +#include #include @@ -77,6 +78,11 @@ public: ~DrawSketchHandlerCircle() override = default; private: + std::list getToolHints() const override + { + return lookupCircleHints(constructionMethod(), state()); + } + void updateDataAndDrawToPosition(Base::Vector2d onSketchPos) override { switch (state()) { @@ -302,6 +308,19 @@ private: } private: + struct HintEntry + { + ConstructionMethod method; + SelectMode state; + std::list hints; + }; + + using HintTable = std::vector; + + static Gui::InputHint switchModeHint(); + static HintTable getCircleHintTable(); + static std::list lookupCircleHints(ConstructionMethod method, SelectMode state); + Base::Vector2d centerPoint, firstPoint, secondPoint; double radius; bool isDiameter; @@ -605,6 +624,13 @@ void DSHCircleController::doChangeDrawSketchHandlerMode() } } +template<> +void DSHCircleController::doConstructionMethodChanged() +{ + // Just update hints - combobox already handled by framework + handler->updateHint(); +} + template<> void DSHCircleController::addConstraints() { @@ -701,6 +727,54 @@ void DSHCircleController::addConstraints() // No constraint possible for 3 rim circle. } +Gui::InputHint DrawSketchHandlerCircle::switchModeHint() +{ + return {QObject::tr("%1 switch mode"), {Gui::InputHint::UserInput::KeyM}}; +} + +DrawSketchHandlerCircle::HintTable DrawSketchHandlerCircle::getCircleHintTable() +{ + const auto switchHint = switchModeHint(); + return { + // Structure: {ConstructionMethod, SelectMode, {hints...}} + + // Center method + {ConstructionMethod::Center, + SelectMode::SeekFirst, + {{QObject::tr("%1 pick circle center"), {Gui::InputHint::UserInput::MouseLeft}}, + switchHint}}, + {ConstructionMethod::Center, + SelectMode::SeekSecond, + {{QObject::tr("%1 pick rim point"), {Gui::InputHint::UserInput::MouseLeft}}, switchHint}}, + + // ThreeRim method + {ConstructionMethod::ThreeRim, + SelectMode::SeekFirst, + {{QObject::tr("%1 pick first rim point"), {Gui::InputHint::UserInput::MouseLeft}}, + switchHint}}, + {ConstructionMethod::ThreeRim, + SelectMode::SeekSecond, + {{QObject::tr("%1 pick second rim point"), {Gui::InputHint::UserInput::MouseLeft}}, + switchHint}}, + {ConstructionMethod::ThreeRim, + SelectMode::SeekThird, + {{QObject::tr("%1 pick third rim point"), {Gui::InputHint::UserInput::MouseLeft}}, + switchHint}}}; +} + +std::list DrawSketchHandlerCircle::lookupCircleHints(ConstructionMethod method, + SelectMode state) +{ + const auto circleHintTable = getCircleHintTable(); + + auto it = std::find_if(circleHintTable.begin(), + circleHintTable.end(), + [method, state](const HintEntry& entry) { + return entry.method == method && entry.state == state; + }); + + return (it != circleHintTable.end()) ? it->hints : std::list {}; +} } // namespace SketcherGui diff --git a/src/Mod/Sketcher/Gui/DrawSketchHandlerEllipse.h b/src/Mod/Sketcher/Gui/DrawSketchHandlerEllipse.h index c83c755987..1907e5c492 100644 --- a/src/Mod/Sketcher/Gui/DrawSketchHandlerEllipse.h +++ b/src/Mod/Sketcher/Gui/DrawSketchHandlerEllipse.h @@ -84,6 +84,24 @@ 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()); + } + void updateDataAndDrawToPosition(Base::Vector2d onSketchPos) override { switch (state()) { @@ -952,7 +970,47 @@ 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 diff --git a/src/Mod/Sketcher/Gui/DrawSketchHandlerLine.h b/src/Mod/Sketcher/Gui/DrawSketchHandlerLine.h index 50f7ea7377..aec0f2abfc 100644 --- a/src/Mod/Sketcher/Gui/DrawSketchHandlerLine.h +++ b/src/Mod/Sketcher/Gui/DrawSketchHandlerLine.h @@ -28,6 +28,7 @@ #include #include #include +#include #include @@ -37,6 +38,9 @@ #include "GeometryCreationMode.h" #include "Utils.h" +#include +#include + namespace SketcherGui { @@ -251,6 +255,24 @@ private: isConstructionMode()); } } + + std::list getToolHints() const override + { + return lookupLineHints(static_cast(constructionMethod()), static_cast(state())); + } + + struct HintEntry + { + int constructionMethod; + int state; + std::list hints; + }; + + using HintTable = std::vector; + + static Gui::InputHint switchModeHint(); + static HintTable getLineHintTable(); + static std::list lookupLineHints(int method, int state); }; template<> @@ -796,6 +818,65 @@ void DSHLineController::addConstraints() } } +Gui::InputHint DrawSketchHandlerLine::switchModeHint() +{ + return {QObject::tr("%1 switch mode"), {Gui::InputHint::UserInput::KeyM}}; +} + +DrawSketchHandlerLine::HintTable DrawSketchHandlerLine::getLineHintTable() +{ + const auto switchHint = switchModeHint(); + return {// Structure: {constructionMethod, state, {hints...}} + + // OnePointLengthAngle (0) + {0, + 0, + {// SeekFirst + {QObject::tr("%1 pick first point"), {Gui::InputHint::UserInput::MouseLeft}}, + switchHint}}, + {0, + 1, + {// SeekSecond + {QObject::tr("%1 pick second point"), {Gui::InputHint::UserInput::MouseLeft}}, + switchHint}}, + + // OnePointWidthHeight (1) + {1, + 0, + {// SeekFirst + {QObject::tr("%1 pick first point"), {Gui::InputHint::UserInput::MouseLeft}}, + switchHint}}, + {1, + 1, + {// SeekSecond + {QObject::tr("%1 pick second point"), {Gui::InputHint::UserInput::MouseLeft}}, + switchHint}}, + + // TwoPoints (2) + {2, + 0, + {// SeekFirst + {QObject::tr("%1 pick first point"), {Gui::InputHint::UserInput::MouseLeft}}, + switchHint}}, + {2, + 1, + {// SeekSecond + {QObject::tr("%1 pick second point"), {Gui::InputHint::UserInput::MouseLeft}}, + switchHint}}}; +} + +std::list DrawSketchHandlerLine::lookupLineHints(int method, int state) +{ + const auto lineHintTable = getLineHintTable(); + + auto it = std::find_if(lineHintTable.begin(), + lineHintTable.end(), + [method, state](const HintEntry& entry) { + return entry.constructionMethod == method && entry.state == state; + }); + + return (it != lineHintTable.end()) ? it->hints : std::list {}; +} } // namespace SketcherGui diff --git a/src/Mod/Sketcher/Gui/DrawSketchHandlerLineSet.h b/src/Mod/Sketcher/Gui/DrawSketchHandlerLineSet.h index f113e59e81..640d91dfd3 100644 --- a/src/Mod/Sketcher/Gui/DrawSketchHandlerLineSet.h +++ b/src/Mod/Sketcher/Gui/DrawSketchHandlerLineSet.h @@ -31,6 +31,7 @@ #include #include #include +#include #include @@ -96,16 +97,6 @@ public: SNAP_MODE_45Degree }; - std::list getToolHints() const override - { - using UserInput = Gui::InputHint::UserInput; - - return { - {QWidget::tr("%1 change mode"), {UserInput::KeyM}}, - {QWidget::tr("%1 start drawing"), {UserInput::MouseLeft}}, - {QWidget::tr("%1 stop drawing"), {UserInput::MouseRight}}, - }; - } void registerPressedKey(bool pressed, int key) override { @@ -341,6 +332,7 @@ public: bool pressButton(Base::Vector2d onSketchPos) override { + if (Mode == STATUS_SEEK_First) { EditCurve[0] = onSketchPos; // this may be overwritten if previousCurve is found @@ -447,6 +439,9 @@ public: } } } + + updateHint(); + return true; } @@ -719,6 +714,9 @@ public: mouseMove(onSketchPos); // trigger an update of EditCurve } } + + updateHint(); + return true; } @@ -762,11 +760,27 @@ public: } private: + struct HintEntry + { + int mode; + std::list hints; + }; + + using HintTable = std::vector; + + static HintTable getLineSetHintTable(); + static std::list lookupLineSetHints(int mode); + QString getCrosshairCursorSVGName() const override { return QStringLiteral("Sketcher_Pointer_Create_Lineset"); } + std::list getToolHints() const override + { + return lookupLineSetHints(Mode); + } + protected: SELECT_MODE Mode; SEGMENT_MODE SegmentMode; @@ -827,7 +841,29 @@ protected: } }; +DrawSketchHandlerLineSet::HintTable DrawSketchHandlerLineSet::getLineSetHintTable() +{ + return {// Structure: {mode, {hints...}} + {STATUS_SEEK_First, + {{QObject::tr("%1 pick first point"), {Gui::InputHint::UserInput::MouseLeft}}}}, + {STATUS_SEEK_Second, + {{QObject::tr("%1 pick next point"), {Gui::InputHint::UserInput::MouseLeft}}, + {QObject::tr("%1 finish"), {Gui::InputHint::UserInput::MouseRight}}, + {QObject::tr("%1 switch mode"), {Gui::InputHint::UserInput::KeyM}}}}}; +} +std::list DrawSketchHandlerLineSet::lookupLineSetHints(int mode) +{ + const auto lineSetHintTable = getLineSetHintTable(); + + auto it = std::find_if(lineSetHintTable.begin(), + lineSetHintTable.end(), + [mode](const HintEntry& entry) { + return entry.mode == mode; + }); + + return (it != lineSetHintTable.end()) ? it->hints : std::list {}; +} } // namespace SketcherGui diff --git a/src/Mod/Sketcher/Gui/DrawSketchHandlerPoint.h b/src/Mod/Sketcher/Gui/DrawSketchHandlerPoint.h index 969af3fd32..b4d3b44fea 100644 --- a/src/Mod/Sketcher/Gui/DrawSketchHandlerPoint.h +++ b/src/Mod/Sketcher/Gui/DrawSketchHandlerPoint.h @@ -27,6 +27,7 @@ #include #include #include +#include #include @@ -35,6 +36,9 @@ #include "DrawSketchDefaultWidgetController.h" #include "DrawSketchControllableHandler.h" +#include +#include + namespace SketcherGui { @@ -59,6 +63,11 @@ public: ~DrawSketchHandlerPoint() override = default; private: + std::list getToolHints() const override + { + return lookupPointHints(static_cast(state())); + } + void updateDataAndDrawToPosition(Base::Vector2d onSketchPos) override { switch (state()) { @@ -125,6 +134,17 @@ private: private: Base::Vector2d editPoint; + + struct HintEntry + { + int stateValue; + std::list hints; + }; + + using HintTable = std::vector; + + static HintTable getPointHintTable(); + static std::list lookupPointHints(int stateValue); }; template<> @@ -265,6 +285,25 @@ void DSHPointController::addConstraints() } } +DrawSketchHandlerPoint::HintTable DrawSketchHandlerPoint::getPointHintTable() +{ + return {// Structure: {ConstructionMethod, SelectMode, {hints...}} + {0, {{QObject::tr("%1 place a point"), {Gui::InputHint::UserInput::MouseLeft}}}}}; +} + +std::list DrawSketchHandlerPoint::lookupPointHints(int stateValue) +{ + const auto pointHintTable = getPointHintTable(); + + auto it = std::find_if(pointHintTable.begin(), + pointHintTable.end(), + [stateValue](const HintEntry& entry) { + return entry.stateValue == stateValue; + }); + + return (it != pointHintTable.end()) ? it->hints : std::list {}; +} + } // namespace SketcherGui diff --git a/src/Mod/Sketcher/Gui/DrawSketchHandlerPolygon.h b/src/Mod/Sketcher/Gui/DrawSketchHandlerPolygon.h index cf2d23d69e..10ea925ed0 100644 --- a/src/Mod/Sketcher/Gui/DrawSketchHandlerPolygon.h +++ b/src/Mod/Sketcher/Gui/DrawSketchHandlerPolygon.h @@ -30,6 +30,7 @@ #include #include #include +#include #include @@ -74,29 +75,6 @@ public: {} ~DrawSketchHandlerPolygon() override = default; - std::list getToolHints() const override - { - using UserInput = Gui::InputHint::UserInput; - - switch (state()) { - case SelectMode::SeekFirst: - return { - {QWidget::tr("%1 pick polygon center"), {UserInput::MouseLeft}}, - {QWidget::tr("%1/%2 increase / decrease number of sides"), - {UserInput::KeyU, UserInput::KeyJ}}, - }; - case SelectMode::SeekSecond: - return { - {QWidget::tr("%1 pick rotation and size"), {UserInput::MouseMove}}, - {QWidget::tr("%1 confirm"), {UserInput::MouseLeft}}, - {QWidget::tr("%1/%2 increase / decrease number of sides"), - {UserInput::KeyU, UserInput::KeyJ}}, - }; - default: - return {}; - } - } - private: void updateDataAndDrawToPosition(Base::Vector2d onSketchPos) override { @@ -284,6 +262,23 @@ private: prevCorner = newCorner; } } + + std::list getToolHints() const override + { + return lookupPolygonHints(state()); + } + +private: + struct HintEntry + { + SelectMode state; + std::list hints; + }; + + using HintTable = std::vector; + + static HintTable getPolygonHintTable(); + static std::list lookupPolygonHints(SelectMode state); }; template<> @@ -552,6 +547,32 @@ void DSHPolygonController::addConstraints() } } +DrawSketchHandlerPolygon::HintTable DrawSketchHandlerPolygon::getPolygonHintTable() +{ + return {// Structure: {SelectMode, {hints...}} + {SelectMode::SeekFirst, + {{QObject::tr("%1 pick polygon center"), {Gui::InputHint::UserInput::MouseLeft}}, + {QObject::tr("%1/%2 increase / decrease number of sides"), + {Gui::InputHint::UserInput::KeyU, Gui::InputHint::UserInput::KeyJ}}}}, + {SelectMode::SeekSecond, + {{QObject::tr("%1 pick rotation and size"), {Gui::InputHint::UserInput::MouseMove}}, + {QObject::tr("%1 confirm"), {Gui::InputHint::UserInput::MouseLeft}}, + {QObject::tr("%1/%2 increase / decrease number of sides"), + {Gui::InputHint::UserInput::KeyU, Gui::InputHint::UserInput::KeyJ}}}}}; +} + +std::list DrawSketchHandlerPolygon::lookupPolygonHints(SelectMode state) +{ + const auto polygonHintTable = getPolygonHintTable(); + + auto it = std::find_if(polygonHintTable.begin(), + polygonHintTable.end(), + [state](const HintEntry& entry) { + return entry.state == state; + }); + + return (it != polygonHintTable.end()) ? it->hints : std::list {}; +} } // namespace SketcherGui diff --git a/src/Mod/Sketcher/Gui/DrawSketchHandlerRectangle.h b/src/Mod/Sketcher/Gui/DrawSketchHandlerRectangle.h index f3ba68f73f..62689a760e 100644 --- a/src/Mod/Sketcher/Gui/DrawSketchHandlerRectangle.h +++ b/src/Mod/Sketcher/Gui/DrawSketchHandlerRectangle.h @@ -30,7 +30,7 @@ #include #include #include - +#include #include #include "DrawSketchDefaultWidgetController.h" @@ -109,6 +109,25 @@ public: ~DrawSketchHandlerRectangle() override = default; private: + std::list getToolHints() const override + { + return lookupRectangleHints(constructionMethod(), state()); + } + +private: + struct HintEntry + { + ConstructionMethods::RectangleConstructionMethod method; + SelectMode state; + std::list hints; + }; + + using HintTable = std::vector; + + static Gui::InputHint switchModeHint(); + static HintTable getRectangleHintTable(); + static std::list + lookupRectangleHints(ConstructionMethods::RectangleConstructionMethod method, SelectMode state); void updateDataAndDrawToPosition(Base::Vector2d onSketchPos) override { using std::numbers::pi; @@ -2658,7 +2677,110 @@ void DSHRectangleController::addConstraints() } } +template<> +void DSHRectangleController::doConstructionMethodChanged() +{ + handler->updateHint(); +} +Gui::InputHint DrawSketchHandlerRectangle::switchModeHint() +{ + return {QObject::tr("%1 switch mode"), {Gui::InputHint::UserInput::KeyM}}; +} + +DrawSketchHandlerRectangle::HintTable DrawSketchHandlerRectangle::getRectangleHintTable() +{ + const auto switchHint = switchModeHint(); + return {// Structure: {ConstructionMethod, SelectMode, {hints...}} + + // Diagonal method + {ConstructionMethods::RectangleConstructionMethod::Diagonal, + SelectMode::SeekFirst, + {{QObject::tr("%1 pick first corner"), {Gui::InputHint::UserInput::MouseLeft}}, + switchHint}}, + {ConstructionMethods::RectangleConstructionMethod::Diagonal, + SelectMode::SeekSecond, + {{QObject::tr("%1 pick opposite corner"), {Gui::InputHint::UserInput::MouseLeft}}, + switchHint}}, + {ConstructionMethods::RectangleConstructionMethod::Diagonal, + SelectMode::SeekThird, + {{QObject::tr("%1 set corner radius or frame thickness"), + {Gui::InputHint::UserInput::MouseMove}}, + switchHint}}, + {ConstructionMethods::RectangleConstructionMethod::Diagonal, + SelectMode::SeekFourth, + {{QObject::tr("%1 set frame thickness"), {Gui::InputHint::UserInput::MouseMove}}, + switchHint}}, + + // CenterAndCorner method + {ConstructionMethods::RectangleConstructionMethod::CenterAndCorner, + SelectMode::SeekFirst, + {{QObject::tr("%1 pick center"), {Gui::InputHint::UserInput::MouseLeft}}, switchHint}}, + {ConstructionMethods::RectangleConstructionMethod::CenterAndCorner, + SelectMode::SeekSecond, + {{QObject::tr("%1 pick corner"), {Gui::InputHint::UserInput::MouseLeft}}, switchHint}}, + {ConstructionMethods::RectangleConstructionMethod::CenterAndCorner, + SelectMode::SeekThird, + {{QObject::tr("%1 set corner radius or frame thickness"), + {Gui::InputHint::UserInput::MouseMove}}, + switchHint}}, + {ConstructionMethods::RectangleConstructionMethod::CenterAndCorner, + SelectMode::SeekFourth, + {{QObject::tr("%1 set frame thickness"), {Gui::InputHint::UserInput::MouseMove}}, + switchHint}}, + + // ThreePoints method + {ConstructionMethods::RectangleConstructionMethod::ThreePoints, + SelectMode::SeekFirst, + {{QObject::tr("%1 pick first corner"), {Gui::InputHint::UserInput::MouseLeft}}, + switchHint}}, + {ConstructionMethods::RectangleConstructionMethod::ThreePoints, + SelectMode::SeekSecond, + {{QObject::tr("%1 pick second corner"), {Gui::InputHint::UserInput::MouseLeft}}, + switchHint}}, + {ConstructionMethods::RectangleConstructionMethod::ThreePoints, + SelectMode::SeekThird, + {{QObject::tr("%1 pick third corner"), {Gui::InputHint::UserInput::MouseLeft}}, + switchHint}}, + {ConstructionMethods::RectangleConstructionMethod::ThreePoints, + SelectMode::SeekFourth, + {{QObject::tr("%1 set corner radius or frame thickness"), + {Gui::InputHint::UserInput::MouseMove}}, + switchHint}}, + + // CenterAnd3Points method + {ConstructionMethods::RectangleConstructionMethod::CenterAnd3Points, + SelectMode::SeekFirst, + {{QObject::tr("%1 pick center"), {Gui::InputHint::UserInput::MouseLeft}}, switchHint}}, + {ConstructionMethods::RectangleConstructionMethod::CenterAnd3Points, + SelectMode::SeekSecond, + {{QObject::tr("%1 pick first corner"), {Gui::InputHint::UserInput::MouseLeft}}, + switchHint}}, + {ConstructionMethods::RectangleConstructionMethod::CenterAnd3Points, + SelectMode::SeekThird, + {{QObject::tr("%1 pick second corner"), {Gui::InputHint::UserInput::MouseLeft}}, + switchHint}}, + {ConstructionMethods::RectangleConstructionMethod::CenterAnd3Points, + SelectMode::SeekFourth, + {{QObject::tr("%1 set corner radius or frame thickness"), + {Gui::InputHint::UserInput::MouseMove}}, + switchHint}}}; +} + +std::list DrawSketchHandlerRectangle::lookupRectangleHints( + ConstructionMethods::RectangleConstructionMethod method, + SelectMode state) +{ + const auto rectangleHintTable = getRectangleHintTable(); + + auto it = std::find_if(rectangleHintTable.begin(), + rectangleHintTable.end(), + [method, state](const HintEntry& entry) { + return entry.method == method && entry.state == state; + }); + + return (it != rectangleHintTable.end()) ? it->hints : std::list {}; +} } // namespace SketcherGui diff --git a/src/Mod/Sketcher/Gui/DrawSketchHandlerSlot.h b/src/Mod/Sketcher/Gui/DrawSketchHandlerSlot.h index 46b27d58b3..cd65a7b965 100644 --- a/src/Mod/Sketcher/Gui/DrawSketchHandlerSlot.h +++ b/src/Mod/Sketcher/Gui/DrawSketchHandlerSlot.h @@ -31,6 +31,7 @@ #include #include #include +#include #include @@ -80,6 +81,11 @@ public: ~DrawSketchHandlerSlot() override = default; private: + std::list getToolHints() const override + { + return lookupSlotHints(state()); + } + void updateDataAndDrawToPosition(Base::Vector2d onSketchPos) override { switch (state()) { @@ -343,6 +349,17 @@ private: double radius, length, angle; bool isHorizontal, isVertical; int firstCurve; + + struct HintEntry + { + SelectMode state; + std::list hints; + }; + + using HintTable = std::vector; + + static HintTable getSlotHintTable(); + static std::list lookupSlotHints(SelectMode state); }; template<> @@ -675,6 +692,29 @@ void DSHSlotController::addConstraints() } } +DrawSketchHandlerSlot::HintTable DrawSketchHandlerSlot::getSlotHintTable() +{ + return {// Structure: {SelectMode, {hints...}} + {SelectMode::SeekFirst, + {{QObject::tr("%1 pick slot start point"), {Gui::InputHint::UserInput::MouseLeft}}}}, + {SelectMode::SeekSecond, + {{QObject::tr("%1 pick slot end point"), {Gui::InputHint::UserInput::MouseLeft}}}}, + {SelectMode::SeekThird, + {{QObject::tr("%1 set slot radius"), {Gui::InputHint::UserInput::MouseMove}}}}}; +} + +std::list DrawSketchHandlerSlot::lookupSlotHints(SelectMode state) +{ + const auto slotHintTable = getSlotHintTable(); + + auto it = + std::find_if(slotHintTable.begin(), slotHintTable.end(), [state](const HintEntry& entry) { + return entry.state == state; + }); + + return (it != slotHintTable.end()) ? it->hints : std::list {}; +} + } // namespace SketcherGui