Sketcher: Add contextual input hints to edit tools (InputHints Phase 3) (#21806)

* Add input hints to fillet and chamfer tools

* Add hints to trimming tool

* Add hints to splitting tool

* Implement hints for extend tool

* Add hints to external geometry

* Add hints to Carbon Copy tool

* Hint updates to align with developer guidelines

* change "click to set" to "set" per PR comments

* Use enum (or declare one) to be type safe per PR comments

* For "trivial" one-step / one-state tools, refactor with direct hint return rather than using declarative / table pattern.

* Refactor hint tables initializers with C++20 features per PR feedback

- Use designated initializers (.state = , .hints = ) for clearer structure
- Add 'using enum Gui::InputHint::UserInput' to eliminate repetitive prefixes
- Applied to DrawSketchHandlerExtend and DrawSketchHandlerFillet

* Refactor Splitting tool hint implementation with direct return (trivial) pattern

* For fillet change "vertex" to "point" per PR feedback

* Change hint to "pick location on edge to split" per PR feedback
This commit is contained in:
George Peden
2025-06-16 09:05:13 -07:00
committed by GitHub
parent ccf27775dc
commit 94d39087d3
6 changed files with 127 additions and 5 deletions

View File

@@ -191,6 +191,7 @@ public:
return true;
}
}
updateHint();
return false;
}
@@ -218,6 +219,13 @@ private:
Q_UNUSED(sketchgui);
setAxisPickStyle(true);
}
public:
std::list<Gui::InputHint> getToolHints() const override
{
return {{QObject::tr("%1 pick sketch to copy", "Sketcher CarbonCopy: hint"),
{Gui::InputHint::UserInput::MouseLeft}}};
}
};
} // namespace SketcherGui

View File

@@ -344,6 +344,8 @@ public:
sketchgui
->purgeHandler(); // no code after this line, Handler get deleted in ViewProvider
}
updateHint();
return true;
}
@@ -371,6 +373,24 @@ protected:
double Increment;
std::vector<AutoConstraint> SugConstr;
// Add hint structures here
struct HintEntry
{
SelectMode state;
std::list<Gui::InputHint> hints;
};
using HintTable = std::vector<HintEntry>;
static HintTable getExtendHintTable();
static std::list<Gui::InputHint> lookupExtendHints(SelectMode state);
public:
std::list<Gui::InputHint> getToolHints() const override
{
return lookupExtendHints(Mode);
}
private:
int crossProduct(Base::Vector2d& vec1, Base::Vector2d& vec2)
{
@@ -378,8 +398,29 @@ private:
}
};
DrawSketchHandlerExtend::HintTable DrawSketchHandlerExtend::getExtendHintTable()
{
using enum Gui::InputHint::UserInput;
return {
{.state = STATUS_SEEK_First,
.hints = {{QObject::tr("%1 pick edge to extend", "Sketcher Extend: hint"), {MouseLeft}}}},
{.state = STATUS_SEEK_Second,
.hints = {
{QObject::tr("%1 set extension length", "Sketcher Extend: hint"), {MouseLeft}}}}};
}
std::list<Gui::InputHint> DrawSketchHandlerExtend::lookupExtendHints(SelectMode state)
{
const auto extendHintTable = getExtendHintTable();
auto it = std::ranges::find_if(extendHintTable, [state](const HintEntry& entry) {
return entry.state == state;
});
return (it != extendHintTable.end()) ? it->hints : std::list<Gui::InputHint> {};
}
} // namespace SketcherGui
#endif // SKETCHERGUI_DrawSketchHandlerExtend_H

View File

@@ -208,6 +208,8 @@ public:
return true;
}
}
updateHint();
return false;
}
@@ -242,8 +244,14 @@ private:
bool alwaysReference;
bool intersection;
};
public:
std::list<Gui::InputHint> getToolHints() const override
{
return {{QObject::tr("%1 pick external geometry", "Sketcher External: hint"),
{Gui::InputHint::UserInput::MouseLeft}}};
}
};
} // namespace SketcherGui

View File

@@ -402,6 +402,7 @@ private:
moveToNextMode();
}
}
updateHint();
}
@@ -409,6 +410,23 @@ private:
bool preserveCorner;
int vtId, geoId1, geoId2;
Base::Vector2d firstPos, secondPos;
struct HintEntry
{
SelectMode state;
std::list<Gui::InputHint> hints;
};
using HintTable = std::vector<HintEntry>;
static HintTable getFilletHintTable();
static std::list<Gui::InputHint> lookupFilletHints(SelectMode state);
public:
std::list<Gui::InputHint> getToolHints() const override
{
return lookupFilletHints(state());
}
};
template<>
@@ -456,7 +474,33 @@ void DSHFilletController::adaptDrawingToCheckboxChange(int checkboxindex, bool v
handler->updateCursor();
}
DrawSketchHandlerFillet::HintTable DrawSketchHandlerFillet::getFilletHintTable()
{
using enum Gui::InputHint::UserInput;
return {{.state = SelectMode::SeekFirst,
.hints = {{QObject::tr("%1 pick first edge or point", "Sketcher Fillet/Chamfer: hint"),
{MouseLeft}}}},
{.state = SelectMode::SeekSecond,
.hints = {{QObject::tr("%1 pick second edge", "Sketcher Fillet/Chamfer: hint"),
{MouseLeft}}}},
{.state = SelectMode::End,
.hints = {
{QObject::tr("%1 create fillet", "Sketcher Fillet/Chamfer: hint"), {MouseLeft}}}}};
}
std::list<Gui::InputHint> DrawSketchHandlerFillet::lookupFilletHints(SelectMode state)
{
const auto filletHintTable = getFilletHintTable();
auto it = std::ranges::find_if(filletHintTable, [state](const HintEntry& entry) {
return entry.state == state;
});
return (it != filletHintTable.end()) ? it->hints : std::list<Gui::InputHint> {};
}
} // namespace SketcherGui
#endif // SKETCHERGUI_DrawSketchHandlerFillet_H

View File

@@ -187,6 +187,22 @@ private:
{
return QStringLiteral("Sketcher_Pointer_Splitting");
}
enum State
{
WaitingForEdge
};
private:
std::vector<Base::Vector2d> EditMarkers;
bool mousePressed = false;
public:
std::list<Gui::InputHint> getToolHints() const override
{
return {{QObject::tr("%1 pick location on edge to split", "Sketcher Splitting: hint"),
{Gui::InputHint::UserInput::MouseLeft}}};
}
};
} // namespace SketcherGui

View File

@@ -208,10 +208,15 @@ private:
private:
std::vector<Base::Vector2d> EditMarkers;
bool mousePressed = false;
};
public:
std::list<Gui::InputHint> getToolHints() const override
{
return {{QObject::tr("%1 pick edge to trim", "Sketcher Trimming: hint"),
{Gui::InputHint::UserInput::MouseLeft}}};
}
};
} // namespace SketcherGui
#endif // SKETCHERGUI_DrawSketchHandlerTrimming_H