Sketcher: Use generic tool hints table for DrawSketchHandlerArc
This commit is contained in:
@@ -90,7 +90,55 @@ public:
|
||||
private:
|
||||
std::list<Gui::InputHint> getToolHints() const override
|
||||
{
|
||||
return lookupArcHints(constructionMethod(), state());
|
||||
using State = std::pair<ConstructionMethod, SelectMode>;
|
||||
using enum Gui::InputHint::UserInput;
|
||||
|
||||
const auto switchHint =
|
||||
Gui::InputHint {.message = QObject::tr("%1 switch mode"), .sequences = {KeyM}};
|
||||
|
||||
return Gui::lookupHints<State>(
|
||||
{constructionMethod(), state()},
|
||||
{
|
||||
// Center method
|
||||
{.state = {ConstructionMethod::Center, SelectMode::SeekFirst},
|
||||
.hints =
|
||||
{
|
||||
{QObject::tr("%1 pick arc center"), {MouseLeft}},
|
||||
switchHint,
|
||||
}},
|
||||
{.state = {ConstructionMethod::Center, SelectMode::SeekSecond},
|
||||
.hints =
|
||||
{
|
||||
{QObject::tr("%1 pick arc start point"), {MouseLeft}},
|
||||
switchHint,
|
||||
}},
|
||||
{.state = {ConstructionMethod::Center, SelectMode::SeekThird},
|
||||
.hints =
|
||||
{
|
||||
{QObject::tr("%1 pick arc end point"), {MouseLeft}},
|
||||
switchHint,
|
||||
}},
|
||||
|
||||
// ThreeRim method
|
||||
{.state = {ConstructionMethod::ThreeRim, SelectMode::SeekFirst},
|
||||
.hints =
|
||||
{
|
||||
{QObject::tr("%1 pick first arc point"), {MouseLeft}},
|
||||
switchHint,
|
||||
}},
|
||||
{.state = {ConstructionMethod::ThreeRim, SelectMode::SeekSecond},
|
||||
.hints =
|
||||
{
|
||||
{QObject::tr("%1 pick second arc point"), {MouseLeft}},
|
||||
switchHint,
|
||||
}},
|
||||
{.state = {ConstructionMethod::ThreeRim, SelectMode::SeekThird},
|
||||
.hints =
|
||||
{
|
||||
{QObject::tr("%1 pick third arc point"), {MouseLeft}},
|
||||
switchHint,
|
||||
}},
|
||||
});
|
||||
}
|
||||
|
||||
void updateDataAndDrawToPosition(Base::Vector2d onSketchPos) override
|
||||
@@ -432,21 +480,6 @@ private:
|
||||
}
|
||||
}
|
||||
|
||||
// Hint table structures
|
||||
struct HintEntry
|
||||
{
|
||||
ConstructionMethod method;
|
||||
SelectMode state;
|
||||
std::list<Gui::InputHint> hints;
|
||||
};
|
||||
|
||||
using HintTable = std::vector<HintEntry>;
|
||||
|
||||
// Static declaration
|
||||
static Gui::InputHint switchModeHint();
|
||||
static HintTable getArcHintTable();
|
||||
static std::list<Gui::InputHint> lookupArcHints(ConstructionMethod method, SelectMode state);
|
||||
|
||||
private:
|
||||
Base::Vector2d centerPoint, firstPoint, secondPoint;
|
||||
double radius, startAngle, endAngle, arcAngle;
|
||||
@@ -928,60 +961,6 @@ 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<Gui::InputHint> 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<Gui::InputHint> {};
|
||||
}
|
||||
|
||||
} // namespace SketcherGui
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user