From 75c8ec74cecfbc292254f11dfc3d02ca5c504340 Mon Sep 17 00:00:00 2001 From: maj00r <73280030+maj00r@users.noreply.github.com> Date: Sun, 29 Nov 2026 23:03:43 +0100 Subject: [PATCH] fix(editor): a station counts its steps by their serials, a failed one leaves nothing to redo, a turnout goes into a track at the height of the line - lay_station() counts the steps of the history by their serials (history_top()), not by its size, which stops growing at the cap of the history: there a station laid in full looked failed, back() took nothing back and Enter laid the line again; the steps weren't joined, and the switches of a crossover came out none. - A station refused takes its turnouts back and drops them from the redo stack: Ctrl+Y laid them without the line between them. - A turnout goes into a plain track within 3 m of the height of the line traced, not into one on a viaduct above it or in a cutting below it. --- application/editormodetracestation.cpp | 45 +++++++++++++++++--------- 1 file changed, 30 insertions(+), 15 deletions(-) diff --git a/application/editormodetracestation.cpp b/application/editormodetracestation.cpp index 800b19ba6..f600e91ac 100644 --- a/application/editormodetracestation.cpp +++ b/application/editormodetracestation.cpp @@ -132,7 +132,10 @@ editor_mode::track_under editor_mode::station_track_at(glm::dvec3 const &Point) { if (track->eType != tt_Normal || track->m_editorremoved || track->m_paths.empty() || (track->iCategoryFlag & 15) != kRailCategory) continue; - auto const distance{plan_distance(editor_track::point_at(*track, editor_track::nearest_parameter(*track, Point)), Point)}; + auto const nearest{editor_track::point_at(*track, editor_track::nearest_parameter(*track, Point))}; + if (double constexpr kAboveBelow{3.0}; std::abs(nearest.y - Point.y) > kAboveBelow) + continue; + auto const distance{plan_distance(nearest, Point)}; if (distance < best) { best = distance; @@ -609,17 +612,18 @@ void editor_mode::lay_station(traced_station const &Station, editor_track::snap_ if (Station.crossover) { auto *style{Station.start->track}; - auto const before{m_history.size()}; + auto const before{history_top()}; if (false == lay_planned_connection(Station.request, Station.connection, style)) { keep(m_switch.status); return; } std::vector switches; - for (auto step{before}; step < m_history.size(); ++step) - for (auto *track : m_history[step].created) - if (track != nullptr && track->eType == tt_Switch && false == track->m_editorremoved) - switches.push_back(track); + for (auto const &step : m_history) + if (step.serial > before) + for (auto *track : step.created) + if (track != nullptr && track->eType == tt_Switch && false == track->m_editorremoved) + switches.push_back(track); tool.status = m_switch.status + "\n" + format(STR_C("Crossover of %s, traced on the photo ยท Ctrl+Z undoes"), Station.start->label.c_str()); tool.laid_now = true; tool.laid = {}; @@ -654,11 +658,21 @@ void editor_mode::lay_station(traced_station const &Station, editor_track::snap_ auto const sigmas{tool.sigmas}; auto const heights{tool.heights}; auto const start{tool.start}; - auto const steps{m_history.size()}; - // the turnouts laid back: the tracks as they were, the points clicked kept + // the steps of the station by their serials: the size of the history stops growing at its cap, and a station laid in full looked + // failed there + auto const top{history_top()}; + // the turnouts laid back: the tracks as they were, the points clicked kept, nothing of them left for Ctrl+Y to lay without the line auto const back = [&](std::string const &Why) { - while (m_history.size() > steps) + auto const redo{g_redo.size()}; + for (auto was{history_top()}; false == m_history.empty() && was > top; was = history_top()) + { undo_last(); + // nothing taken back: not tried again for ever + if (history_top() == was) + break; + } + while (g_redo.size() > redo) + g_redo.pop_back(); straight_refresh(); tool.points = clicked; tool.modes = modes; @@ -681,12 +695,12 @@ void editor_mode::lay_station(traced_station const &Station, editor_track::snap_ std::vector> states; std::vector created; std::vector removed; - auto const at{m_history.size()}; + auto const at{history_top()}; if (false == place_switch_on_straight(line, m_switch.templates[Turnout.shape], nullptr, line.along(Turnout.start), forward, Turnout.fit.side, false, states, created, removed, switch_name_for_new())) return nullptr; auto const placed{created}; push_track_snapshot(std::move(states), std::move(created), std::move(removed)); - if (at > steps && m_history.size() > at) + if (at > top && history_top() > at) m_history.back().joined = true; straight_refresh(); auto const found{std::ranges::find_if(placed, [](TTrack const *Track) { return Track != nullptr && Track->eType == tt_Switch; })}; @@ -756,16 +770,17 @@ void editor_mode::lay_station(traced_station const &Station, editor_track::snap_ tool.modes.assign(points.size(), lay_mode::traced); tool.sigmas = noise; tool.heights = sources; - auto const line_step{m_history.size()}; + auto const line_top{history_top()}; m_station_laying = true; m_station_design = Station.design; lay_finish(into); m_station_laying = false; m_station_design.reset(); - if (m_history.size() <= line_step) + if (history_top() <= line_top) return back(tool.status.empty() ? std::string{STR_C("The track between the turnouts couldn't be laid")} : tool.status); - if (line_step > steps) - m_history[line_step].joined = true; + // the first step of the line joined to the turnouts laid before it + if (auto const first{std::ranges::find_if(m_history, [line_top](EditorSnapshot const &Step) { return Step.serial > line_top; })}; line_top > top && first != m_history.end()) + first->joined = true; for (auto const &each : told) tool.status += "\n" + each; if (Station.alongside.has_value())