From 4528791e7be7ad77e8ffff646dd251d91a33af42 Mon Sep 17 00:00:00 2001 From: maj00r <73280030+maj00r@users.noreply.github.com> Date: Sun, 29 Nov 2026 23:02:36 +0100 Subject: [PATCH] fix(editor): the traced line takes its fitted grade line once done and follows the setup, the laid end isn't a point clicked, a free end not reached isn't joined - The line traced shown is worked out again while its grade line is being fitted (follow_meanwhile() tells a stopgap), and when the settings of the trace change ("It's a side track", the norms): the key of its cache kept the stopgap, or the refusal, till the next click. - Going on from the end of the line laid, that end stays the start of the points, not one of the points clicked: Esc counted it, and Backspace back to it then Enter said "Click at least two points" instead of ending the line. - Leaving the lay tool cancels the laying with its wait for the terrain: left behind, a stale end with no points was laid when the tool was back. - A free end no candidate of the tracer reaches is told, not laid as joined with a gap left. - A curve the trace laid slower than the line shows its speed in Plan, and a change of its radius there lays it at the speed of the line. - A track dragged out of a free end keeps the heights of the setting while the clicks are traced: the fitted heights are for the sparse points clicked on the photo. - The time of a click of the tracer is checked only with EU07_TRACE_TIMING set: the coverage job of the CI, with no optimisation, took several times as long. The evaluations are checked always. --- application/editormode.h | 2 ++ application/editormodelay.cpp | 21 +++++++++++++++++---- application/editormoderoute.cpp | 13 ++++++++++++- application/editormodetrack.cpp | 8 ++------ application/editormodetrackbed.cpp | 5 ++++- editor/editorGroundFollow.cpp | 7 ++++--- editor/editorGroundFollow.hpp | 4 ++-- lang/editor_pl.po | 8 ++++++++ tests/unit/test_trace.cpp | 9 +++++++-- 9 files changed, 58 insertions(+), 19 deletions(-) diff --git a/application/editormode.h b/application/editormode.h index 0cc520934..4f613646d 100644 --- a/application/editormode.h +++ b/application/editormode.h @@ -1992,6 +1992,7 @@ class editor_mode : public application_mode, private editor_track::observer, pri }; std::optional shown; std::vector traced_key; // what the line traced shown was worked out for: its points, the free end reached, the edits + trace::settings traced_with; // and the settings of the trace: the setup, the norms // the cursor the line is being worked out for, kept till all its fits are done: what it was worked out from struct settling_cursor { @@ -2166,6 +2167,7 @@ class editor_mode : public application_mode, private editor_track::observer, pri mutable alignment::stretch_fitter m_stretch_fitter; // a fit the line asked the thread for isn't done yet: the line is one of the fits meanwhile mutable bool m_fits_waiting{false}; + mutable bool m_grades_waiting{false}; // the grade line of the line shown not fitted yet, a stopgap shown meanwhile // how much more the curve at the cursor was turned last to reach it, the first one tried for the next line mutable double m_turned_last{0.0}; void render_switch_ui(); diff --git a/application/editormodelay.cpp b/application/editormodelay.cpp index ceeb416bb..0da5e8aa0 100644 --- a/application/editormodelay.cpp +++ b/application/editormodelay.cpp @@ -263,7 +263,8 @@ void editor_mode::update_build_tools() for (auto const &point : points) traced_key.insert(traced_key.end(), {point.x, point.y, point.z}); traced_key.insert(traced_key.end(), {end.track != nullptr ? 1.0 : 0.0, static_cast(m_track_edits), static_cast(lay_heights_now()), lay.style.velocity}); - if (lay.shown.has_value() && traced_key == lay.traced_key) + // the setup and the norms the curves are checked by: "It's a side track" lays again a curve refused on a main one + if (lay.shown.has_value() && traced_key == lay.traced_key && trace_settings() == lay.traced_with) { auto const &shown{*lay.shown}; lay.preview = shown.preview; @@ -276,10 +277,15 @@ void editor_mode::update_build_tools() } } m_fits_waiting = false; + m_grades_waiting = false; m_follow_preview = true; lay.preview = lay_pieces(points, modes, end, lay.preview_length, lay.preview_error, &lay.plan); m_follow_preview = false; - lay.traced_key = traced_key; + // shown with a stopgap grade line while the fitter works on it: worked out again the next frame, not kept for these points, so the + // grade line fitted is taken once it's done rather than at the next click + lay.traced_key = m_grades_waiting ? std::vector{} : traced_key; + if (false == traced_key.empty()) + lay.traced_with = trace_settings(); if (false == m_fits_waiting || false == lay.whole) { lay.shown = lay_tool::worked_out{lay.preview, lay.preview_error, lay.preview_length, lay.plan, m_eased_last, m_join_last, lay.points}; @@ -2100,6 +2106,12 @@ bool editor_mode::traced_line(std::vector const &Points, editor_trac Error = line.error == "points" ? STR_C("Click at least two points") : STR_C("No line follows the points clicked along it"); return false; } + // no candidate reaching the free end, the line open at the last point: laid so, the end was taken for joined and a gap left + if (double constexpr kReached{0.05}; joined && plan_distance(line.design.end, End.position) > kReached) + { + Error = STR_C("No line follows the points clicked to the free end: click nearer to it, or lay the line to the last point"); + return false; + } Plan.traced = line; Plan.design = line.design; Plan.design.start.y = Points.front().y; @@ -2312,7 +2324,6 @@ void editor_mode::lay_click() tool.modes.push_back(tool.mode); tool.sigmas.push_back(click_sigma_at(point)); tool.heights.push_back(tool.mouse_height); - tool.continuing = false; if (lay_traced() && tool.points.size() >= 3) first_step_done(first_step::trace_points); // a point clicked near the edge of the view: the view glides on to bring it nearer to the middle @@ -2671,7 +2682,9 @@ bool editor_mode::lay_terrain_coming_at(std::size_t const Index) const editorSettings::lay_heights editor_mode::lay_heights_now() const { - return click_heights::heights_for(EditorSettings.heights(), m_lay.mode == lay_mode::traced, m_lay.heights_chosen); + // the points traced on the photo are sparse, the ground rising and falling between them; a track dragged out of a free end isn't + // made of them, so it keeps the setting while the clicks are traced + return click_heights::heights_for(EditorSettings.heights(), m_lay.mode == lay_mode::traced && false == m_extend.active, m_lay.heights_chosen); } bool editor_mode::lay_terrain_coming() const diff --git a/application/editormoderoute.cpp b/application/editormoderoute.cpp index 9656f96cb..81e0d6e0e 100644 --- a/application/editormoderoute.cpp +++ b/application/editormoderoute.cpp @@ -1622,7 +1622,11 @@ void editor_mode::render_route_gizmo() continue; auto const secant{1.0 / std::cos(curve.deflection * 0.5) - 1.0}; if (secant > 1e-6) + { vertex.radius = std::max(10.0, std::round(distance / secant)); + // the speed a trace laid the curve slower for was of the radius it fitted + vertex.speed = 0.0; + } } route_update(); model_plan_preview(); @@ -2192,7 +2196,14 @@ bool editor_mode::render_route_vertex(int const Index) item_tooltip("The curve begins right at the end of the fragment, at the curvature of the track adjoining there, where it turns the same way; its radius is the one " "which begins it there, the transition at that end goes between the two curves"); } - changed |= field("##radius", vertex.radius, 5.0f, vertex.compound ? STR_C("R1 %.0f m") : STR_C("R %.0f m"), overlay_color::grip, "Radius of the arc: drag sideways, or a double click to type it", part::arc); + // a curve a trace laid slower than the line: told, and laid at the speed of the line once its radius is changed, made wider say + if (vertex.speed > 0.0) + ImGui::TextDisabled("%s", format(STR_C("Laid for %.0f km/h, slower than the line: a change of its radius lays it at the speed of the line"), vertex.speed).c_str()); + if (field("##radius", vertex.radius, 5.0f, vertex.compound ? STR_C("R1 %.0f m") : STR_C("R %.0f m"), overlay_color::grip, "Radius of the arc: drag sideways, or a double click to type it", part::arc)) + { + changed = true; + vertex.speed = 0.0; + } ImGui::SameLine(); changed |= field("##cant", vertex.cant, 1.0f, STR_C("cant %.0f mm"), IM_COL32(240, 170, 60, 255), vertex.compound ? "Height of the outer rail above the inner one on the sharpest arc; the arcs with no cant of their own get it in proportion to their curvature" diff --git a/application/editormodetrack.cpp b/application/editormodetrack.cpp index c83569378..aa6f0cff1 100644 --- a/application/editormodetrack.cpp +++ b/application/editormodetrack.cpp @@ -516,12 +516,8 @@ void editor_mode::show_track_tab(track_tab const Wanted) // what was going on in the mode left stays behind cancel_track_tools(); m_straights.tool = 0; - m_lay.points.clear(); - m_lay.modes.clear(); - m_lay.plan = {}; - m_lay.start = {}; - m_lay.preview.clear(); - m_lay.status.clear(); + // the wait for the terrain under the points with them: left behind, it laid a stale end with no points when the tool was back + lay_cancel(); m_lay.active = Tab == track_tab::lay; m_switch.armed = -1; m_signal.armed = false; diff --git a/application/editormodetrackbed.cpp b/application/editormodetrackbed.cpp index 35db5769b..1d7e4e890 100644 --- a/application/editormodetrackbed.cpp +++ b/application/editormodetrackbed.cpp @@ -137,7 +137,10 @@ void editor_mode::follow_ground(std::vector &Pieces, double const auto const grading{laying_grading(Style)}; auto const bed = [&](std::vector const &Points, std::vector const &Directions) { return bed_heights(Points, Directions, Style); }; if (m_follow_preview) - ground_follow::follow_meanwhile(Pieces, {Height0, Grade0, Height1, Grade1}, bed, grading, m_fitter); + { + if (false == ground_follow::follow_meanwhile(Pieces, {Height0, Grade0, Height1, Grade1}, bed, grading, m_fitter)) + m_grades_waiting = true; + } else ground_follow::follow(Pieces, {Height0, Grade0, Height1, Grade1}, bed, grading, &m_fitter); } diff --git a/editor/editorGroundFollow.cpp b/editor/editorGroundFollow.cpp index dcedfb0c4..4a54bd02e 100644 --- a/editor/editorGroundFollow.cpp +++ b/editor/editorGroundFollow.cpp @@ -349,19 +349,19 @@ void follow(std::vector &Pieces, ends const &Ends, bed_query const lay_on(Pieces, lengths, total, Ends, found ? &graded : nullptr, 1.0); } -void follow_meanwhile(std::vector &Pieces, ends const &Ends, bed_query const &Bed, grading const &Grading, fitter &Fitter) +bool follow_meanwhile(std::vector &Pieces, ends const &Ends, bed_query const &Bed, grading const &Grading, fitter &Fitter) { std::vector lengths; request asked; auto const total{measure(Pieces, Ends, Bed, Grading, lengths, asked)}; if (total < 1e-3) - return; + return true; profile::line graded; bool found{false}; if (Fitter.done(asked, graded, found)) { lay_on(Pieces, lengths, total, Ends, found ? &graded : nullptr, 1.0); - return; + return true; } // the cursor moves on a little from frame to frame: the line fitted for where it was a moment ago is near enough, as long // as the track goes on from the same end @@ -369,6 +369,7 @@ void follow_meanwhile(std::vector &Pieces, ends const &Ends, bed_q auto const stretched{Fitter.latest(last, graded, found) && found && last.total > 1e-3 && same(last.heights.height0, Ends.height0) && same(last.heights.grade0, Ends.grade0)}; Fitter.ask(std::move(asked)); lay_on(Pieces, lengths, total, Ends, stretched ? &graded : nullptr, stretched ? last.total / total : 1.0); + return false; } void follow_points(std::vector &Pieces, std::vector const &Points, ends const &Ends) diff --git a/editor/editorGroundFollow.hpp b/editor/editorGroundFollow.hpp index d8e299435..1e09f8424 100644 --- a/editor/editorGroundFollow.hpp +++ b/editor/editorGroundFollow.hpp @@ -100,8 +100,8 @@ class fitter // is taken instead of fitting it again void follow(std::vector &Pieces, ends const &Ends, bed_query const &Bed, grading const &Grading = {}, fitter const *Fitted = nullptr); // the same, though the line is fitted by the fitter: until it has it, the track gets the line it fitted last stretched over its -// length, if it went on from the same end, or the heights from end to end -void follow_meanwhile(std::vector &Pieces, ends const &Ends, bed_query const &Bed, grading const &Grading, fitter &Fitter); +// length, if it went on from the same end, or the heights from end to end. False while the line is such a stopgap +bool follow_meanwhile(std::vector &Pieces, ends const &Ends, bed_query const &Bed, grading const &Grading, fitter &Fitter); // from point to point: the points set square onto the pieces, an even grade between each two of them, the grade breaking only at // them; from the ends of the heights given, a grade given there led on into the first and the last stretch void follow_points(std::vector &Pieces, std::vector const &Points, ends const &Ends); diff --git a/lang/editor_pl.po b/lang/editor_pl.po index 159591d59..aec1092f3 100644 --- a/lang/editor_pl.po +++ b/lang/editor_pl.po @@ -15531,3 +15531,11 @@ msgstr "Esc anuluje · Enter układa bez czekania" msgid "Not laid: the points stay, Enter lays them" msgstr "Nie ułożono: punkty zostają, Enter je układa" + +# scenery editor: the trace on the photo, after the review + +msgid "No line follows the points clicked to the free end: click nearer to it, or lay the line to the last point" +msgstr "Żadna linia nie prowadzi przez kliknięte punkty do wolnego końca: kliknij bliżej niego albo połóż linię do ostatniego punktu" + +msgid "Laid for %.0f km/h, slower than the line: a change of its radius lays it at the speed of the line" +msgstr "Położony na %.0f km/h, wolniej niż linia: zmiana jego promienia kładzie go na prędkość linii" diff --git a/tests/unit/test_trace.cpp b/tests/unit/test_trace.cpp index 689f07595..743815343 100644 --- a/tests/unit/test_trace.cpp +++ b/tests/unit/test_trace.cpp @@ -5,6 +5,7 @@ #include #include +#include #include #include #include @@ -393,7 +394,10 @@ TEST_CASE("trace: a click of the worst case, a compound curve of three radii of std::vector evaluations(points.points.size(), 0); trace::result last; auto slowest{std::numeric_limits::max()}; - for (int run = 0; run < 10 && slowest > 30.0; ++run) { + // the time only where it's asked for (EU07_TRACE_TIMING set): the coverage job of the CI builds the tests with no optimisation and + // takes several times as long; the evaluations, the same everywhere, are checked always + auto const timed{std::getenv("EU07_TRACE_TIMING") != nullptr}; + for (int run = 0; run < (timed ? 10 : 2) && slowest > 30.0; ++run) { trace::tracer line{settings_at(100.0)}; for (std::size_t i = 0; i < points.points.size(); ++i) { line.add(points.points[i], points.sigmas[i]); @@ -408,7 +412,8 @@ TEST_CASE("trace: a click of the worst case, a compound curve of three radii of MESSAGE("slowest click " << slowest << " ms, most evaluations " << *std::max_element(evaluations.begin(), evaluations.end())); INFO(described(last)); CHECK(last.curves.size() == 1); - CHECK(slowest <= 30.0); + if (timed) + CHECK(slowest <= 30.0); } TEST_CASE("trace: a run beside a neighbour at a constant spacing is parallel") {