18
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-12-04 23:45:17 +01:00

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.
This commit is contained in:
maj00r
2026-11-29 23:03:43 +01:00
parent 1f6ee9d1ac
commit 75c8ec74ce
+30 -15
View File
@@ -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<TTrack *> 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<std::pair<TTrack *, editor_track::state>> states;
std::vector<TTrack *> created;
std::vector<TTrack *> 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())