18
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-12-02 09:36:48 +01:00

feat(editor): laying from the photo: the points clicked along the track laid as recognised, told on the view, going on after Enter

quirky-crafting-summit, Etap 2. The lay tool has two shapes, From the photo and Bends: from the photo where the photo is on, the bends
without it, Tab switching them for the points clicked so far and on. The curve traced between bends (Tab) and its radii Auto/1R/2R/3R
are gone from the panel; the radii are changed in Plan afterwards.

- From the photo the points clicked go to the tracer (editor/editorTrace), each with the noise of two pixels of the view at it; the line
  shown is the one of the points clicked, worked out once for them, a dashed leg to the cursor. On the view: "straight 420 m", "curve R
  850 m", "nearly straight · curve R 9 km", "compound curve R 600/450 m", "R 300 m · up to 70 km/h" in orange; the points green, yellow
  or red by how far the line is from them in their noise, one which doesn't fit yellow and ringed, "doesn't fit - Backspace takes it
  back" by the cursor.
- A curve sharper than the norms at the speed of the line is laid slowed down: its tracks and its transitions get its speed, told in the
  status. One below the least radius of the kind of the track (the block of the norms) isn't laid, Lay disabled, the points kept; It's a
  side track offered where a side track may be that sharp (no profile has it so now).
- After Enter the tool stays at the end laid: the next clicks carry the line on from its free end, joined to it, with no need to hit the
  ring; Esc ends it. A free end is reached within 1 m on the ground only, not the end of the track beside.
- The first point turns the view from above on; a click in the outer 15 % of the view glides the view on by half of what the point is off
  its middle.
- The step: Click along the middle of the track on the photo: every 100-300 m on straights, closer on curves. Enter lays. The bar under
  the view: LMB a point on the track, Enter lay, Backspace take back.
- A tool key (G, T, N...) over points not laid warns as Esc does, the second press within 3 s goes; Enter over a single point clicked
  tells to click two instead of dropping it silently.
- With the editing on the model the line traced is laid the old way, told so, as the curve traced was.

Self-test: laymode traced|default, laysigma <m>; laysample lays out curves of the norms, compound ones too, and clicks them traced (no
Tab); laywalk clicks traced; expect laid curves|clicks|length|radius|speed|nearly|slowtracks|joined, expect laykeys <tabs> <enters>,
expect laycontinue; a self-test starts with the bends, whatever the orthophoto of the player's settings. The cases tr_1_three_curves
(3.2 km, three curves, 16 clicks, no Tab, one Enter), tr_2_nearly_straight (R 9 km), tr_3_compound (R 600/400), tr_4_below_norms (R 300
at 120 km/h laid for 70, R 150 refused), tr_5_continue. lf_1_lay_panel_states goes through the shape from the photo in place of the
curve traced, which the panel has no more.

lang/editor_pl.po: the Polish of the new texts; the ones of the curve traced and of its radii gone, the eight of the plan which no
source had any more among them.
This commit is contained in:
maj00r
2026-11-24 00:51:56 +01:00
parent 656c5b4d75
commit 6febdb0d64
17 changed files with 1055 additions and 186 deletions
+133 -1
View File
@@ -531,6 +531,120 @@ bool expect_shown(std::string const &Kind, std::string const &What, std::istring
return true;
}
// expect laid <what> ...: the line the lay tool laid last, traced on the photo:
// curves <count>, clicks <at most> (the points it was traced through), length <m> <tolerance>,
// radius <curve> <R>[/<R>...] <tolerance %> (the radii of its arcs), speed <curve> <km/h> (the one it's laid for), nearly <curve> <0|1>,
// slowtracks <km/h> <at least> (its tracks given that speed), joined <0|1> (its first track joined to another at its start)
void expect_laid(std::string const &What, std::istringstream &Words, std::vector<TTrack *> const &Tracks, double const Length, std::optional<trace::result> const &Traced)
{
std::string which;
Words >> which;
if (false == Traced.has_value())
{
expectation(false, What, "no line traced laid", "one");
return;
}
auto const &line{*Traced};
auto const curve_at = [&](int const Index) -> trace::curve const * {
if (Index < 0 || Index >= static_cast<int>(line.curves.size()))
{
expectation(false, What, format("%zu curves", line.curves.size()), format("curve %d", Index));
return nullptr;
}
return &line.curves[Index];
};
if (which == "curves")
{
std::size_t count{0};
Words >> count;
if (malformed(What, Words))
return;
std::string got;
for (auto const &curve : line.curves)
got += (got.empty() ? "" : ", ") + trace::radii_text(curve);
expectation(line.curves.size() == count, What, format("%zu (%s)", line.curves.size(), got.c_str()), std::to_string(count));
}
else if (which == "clicks")
{
std::size_t most{0};
Words >> most;
if (malformed(What, Words))
return;
expectation(line.offsets.size() <= most, What, std::to_string(line.offsets.size()), format("at most %zu", most));
}
else if (which == "length")
{
double wanted{0.0};
double tolerance{0.0};
Words >> wanted >> tolerance;
if (malformed(What, Words))
return;
expect_near(What, Length, wanted, tolerance);
}
else if (which == "radius")
{
int index{0};
std::string radii;
double tolerance{0.0};
Words >> index >> radii >> tolerance;
if (malformed(What, Words))
return;
auto const *curve{curve_at(index)};
if (curve == nullptr)
return;
std::vector<double> wanted;
for (std::istringstream each{radii}; ; )
{
double radius{0.0};
if (false == static_cast<bool>(each >> radius))
break;
wanted.push_back(radius);
each.ignore(1);
}
auto passed{wanted.size() == curve->radii.size()};
for (std::size_t i = 0; passed && i < wanted.size(); ++i)
passed = std::abs(curve->radii[i] - wanted[i]) <= wanted[i] * tolerance / 100.0;
expectation(passed, What, trace::radii_text(*curve), radii + format(" +- %.1f %%", tolerance));
}
else if (which == "speed" || which == "nearly")
{
int index{0};
double wanted{0.0};
Words >> index >> wanted;
if (malformed(What, Words))
return;
auto const *curve{curve_at(index)};
if (curve == nullptr)
return;
if (which == "speed")
expectation(std::abs(curve->speed - wanted) < 0.5, What, format("%.0f km/h", curve->speed), format("%.0f km/h", wanted));
else
expectation(curve->nearly_straight == (wanted != 0.0), What, curve->nearly_straight ? "1" : "0", wanted != 0.0 ? "1" : "0");
}
else if (which == "joined")
{
// the first track of the line laid joined at its start to the track it goes on from
int wanted{0};
Words >> wanted;
if (malformed(What, Words))
return;
auto const joined{false == Tracks.empty() && (Tracks.front()->trPrev != nullptr || Tracks.front()->trNext != nullptr) && Tracks.front()->trPrev != Tracks.front()};
expectation(joined == (wanted != 0), What, joined ? "1" : "0", wanted != 0 ? "1" : "0");
}
else if (which == "slowtracks")
{
double speed{0.0};
std::size_t least{0};
Words >> speed >> least;
if (malformed(What, Words))
return;
auto const count{static_cast<std::size_t>(std::ranges::count_if(Tracks, [&](TTrack const *Track) { return false == Track->m_editorremoved && std::abs(editor_track::velocity(*Track) - speed) < 0.5; }))};
expectation(count >= least, What, std::to_string(count), format("at least %zu", least));
}
else
expectation(false, What, "no expectation laid " + which, "curves, clicks, length, radius, speed, nearly, joined or slowtracks");
}
// expect steps <count>: the steps Ctrl+Z takes back, the ones made together counted once
void expect_steps(std::string const &What, std::istringstream &Words, std::size_t const Steps)
{
@@ -589,6 +703,24 @@ editor_mode::selftest_result editor_mode::selftest_expect(std::string const &com
expect_findings(what, words, m_norms.results());
else if (kind == "steps")
expect_steps(what, words, static_cast<std::size_t>(std::ranges::count_if(m_history, [](EditorSnapshot const &Step) { return false == Step.joined; })));
else if (kind == "laid")
expect_laid(what, words, m_lay.laid.tracks, m_lay.laid.length, m_lay.laid.traced);
else if (kind == "laykeys")
{
// the shapes switched with Tab and the lines laid with Enter since the start
int tabs{0};
int enters{0};
words >> tabs >> enters;
if (false == malformed(what, words))
expectation(m_lay.tabs == tabs && m_lay.enters == enters, what, format("%d Tab, %d Enter", m_lay.tabs, m_lay.enters), format("%d Tab, %d Enter", tabs, enters));
}
else if (kind == "laycontinue")
{
int wanted{0};
words >> wanted;
if (false == malformed(what, words))
expectation(m_lay.continuing == (wanted != 0), what, m_lay.continuing ? "1" : "0", wanted != 0 ? "1" : "0");
}
else
{
shown_state shown{m_switch.status, ui()->refusal_shown(), ui()->status_line(), m_lay.mouse,
@@ -606,7 +738,7 @@ editor_mode::selftest_result editor_mode::selftest_expect(std::string const &com
if (false == expect_shown(kind, what, words, shown))
expectation(false, what, "no expectation " + kind,
"cant, joint, records, speed, gauge, track, route, norms, findings, height, lift, includes, status, statuslacks, refusal, statusline, laycursor, terrain, tool, window, "
"selected, laypanel, switchpanel or steps");
"selected, laypanel, switchpanel, steps, laid, laykeys or laycontinue");
}
return selftest_result::handled;
}