From e5449075442e2be42f99ef74a9260b65d340b5f6 Mon Sep 17 00:00:00 2001 From: maj00r <73280030+maj00r@users.noreply.github.com> Date: Tue, 24 Nov 2026 18:20:24 +0100 Subject: [PATCH 1/6] fix(editor): track edits keep the joints, the norms, the records and the saved speed together (#450) - The cant typed in the inspector goes on into the track joined at that end, as the gizmo and the joints tool do it; the neighbours go into the same undo step. The joint stepped before. - A track laid on from a canted joint takes the cant off along the ramp the norms ask for at the speed (`alignment::cant_ramp_length`), not at a fixed 1.5 mm a metre whatever the speed and the norms: 120 mm at 100 km/h over 120 m, not 80 m. - Deleting a track of the line under the route tool keeps the laying norms. They went back to the defaults, and every later lay, extend and join used those. - The gauge is a paste group of its own, off by default: pasting how a track rides or sounds no longer changes its gauge. - The speed of a turntable set in the editor is the one saved. The editor changed the speed the turntable runs at, while the file keeps the limit it was loaded with. - Deleting a set of tracks does what Del does with each: a double switch, a slip and a crossover go whole, the records of the switches go with them, and the model and events of a turntable too. The records stayed behind and on saving were given to another switch, which then showed a wrong type. - Deleting a switch of a crossover takes the crossover out whole, as the connection tools do: the outer track of a crossover on a curve comes down by its lift and the record of the connection goes. Alone, the switch left the outer track up for good, and the connection to the next switch given its name. A switch bent out of the shape of its record is found by its name. Tests: a unit test of the norm ramp. The other changes are in the editor's UI, which the unit tests don't reach. --- application/editormode.h | 8 ++- application/editormodelay.cpp | 22 ++++--- application/editormodetrack.cpp | 74 ++++++++++++++++++++++-- application/editormodetrackprops.cpp | 7 ++- application/editormodetrackux.cpp | 85 ++++++++++++++++++++++++++-- editor/editorAlignment.cpp | 5 ++ editor/editorAlignment.hpp | 3 + editor/editorTrack.cpp | 5 ++ tests/unit/test_alignment.cpp | 24 ++++++++ 9 files changed, 211 insertions(+), 22 deletions(-) diff --git a/application/editormode.h b/application/editormode.h index d25840e18..cb852a238 100644 --- a/application/editormode.h +++ b/application/editormode.h @@ -1292,6 +1292,8 @@ class editor_mode : public application_mode, private editor_track::observer, pri } trace; }; void render_route_ui(); + // lets go of the line under the route tool, a track of it deleted; the norms set for laying stay + void route_drop(); bool render_route_band(); bool render_route_parameters(); bool render_route_vertices(); @@ -2535,7 +2537,7 @@ class editor_mode : public application_mode, private editor_track::observer, pri void copy_track_style(TTrack const &Track); std::size_t paste_track_style(std::vector const &Tracks); // which groups of the properties are pasted or put on the tracks by a preset, in the order of the groups of editormodetrackprops.cpp - using track_groups = std::array; + using track_groups = std::array; // the values of the properties of the chosen groups put on the tracks, in one step of the undo. returns: the number of the // tracks changed, none when no value is of the chosen groups std::optional apply_track_values(std::vector> const &Values, track_groups const &Groups, std::vector const &Tracks, char const *What); @@ -2610,8 +2612,8 @@ class editor_mode : public application_mode, private editor_track::observer, pri std::string from; std::vector> values; // ticked at first by their groups: speed, environment, overhead line, track circuits, rails, trackbed, its shape, sleepers, ride and - // sound, frogs, sleeper placement - track_groups groups{false, false, false, false, true, true, true, true, false, true, true}; + // sound, frogs, sleeper placement, gauge (not by default: the gauge of the track pasted onto stays) + track_groups groups{false, false, false, false, true, true, true, true, false, true, true, false}; std::map ticks; // changed by hand, by the keys of the properties bool picking{false}; // the next click on a track in the view takes its properties bool reveal{false}; // its section of the inspector opens, a track having been taken diff --git a/application/editormodelay.cpp b/application/editormodelay.cpp index ed7e8c78b..9f19a2a6b 100644 --- a/application/editormodelay.cpp +++ b/application/editormodelay.cpp @@ -649,16 +649,16 @@ namespace // the cant of a track joined goes on into the track laid, whatever shape that one has: its difference fades along the pieces from the // joint, over as many of them as the cant takes at the ramp a transition curve has at the least, or over all of them where they're shorter -void lead_cant(std::vector &Pieces, double const Roll, double const Gauge, bool const From_start) +void lead_cant(std::vector &Pieces, double const Roll, alignment::limits const &Norms, double const Speed, bool const From_start) { - double constexpr ramp_slope{1.5}; // mm of the cant to a metre if (Pieces.empty()) return; auto const here{From_start ? Pieces.front().rolls[0] : Pieces.back().rolls[1]}; auto const difference{Roll - static_cast(here)}; if (std::abs(difference) < 1e-3) return; - auto const wanted{Gauge * std::abs(std::sin(glm::radians(difference))) / ramp_slope}; + // the ramp the norms ask for at the speed, as a transition curve has it; over all the pieces where they're shorter + auto const wanted{alignment::cant_ramp_length(Speed, Norms.gauge * std::abs(std::sin(glm::radians(difference))), Norms)}; std::vector lengths; auto reach{0.0}; for (std::size_t i = 0; i < Pieces.size(); ++i) @@ -730,7 +730,7 @@ std::vector editor_mode::extend_pieces() const auto pieces{eased.has_value() && false == eased->pieces.empty() ? eased->pieces : editor_track::layout_pieces(m_track_layout, tool.point, tool.direction, tool.grade, tool.mouse, radius)}; follow_ground(pieces, tool.point.y, tool.grade, tool.mouse.y, std::numeric_limits::quiet_NaN(), tool.track); if (tool.track != nullptr) - lead_cant(pieces, -editor_track::joint_roll(*tool.track, {tool.path, tool.atend ? editor_track::point_kind::end : editor_track::point_kind::start}), laying_norms().gauge, true); + lead_cant(pieces, -editor_track::joint_roll(*tool.track, {tool.path, tool.atend ? editor_track::point_kind::end : editor_track::point_kind::start}), laying_norms(), design_speed(tool.track, nullptr), true); return pieces; } @@ -1189,7 +1189,7 @@ std::vector editor_mode::lay_pieces(std::vector const Length += bezier{piece}.plan_length(); if (pieces.empty()) Error = STR_C("The track can't be laid through these points"); - lead_cant(pieces, editor_track::joint_roll(*End.track, End.point), laying_norms().gauge, false); + lead_cant(pieces, editor_track::joint_roll(*End.track, End.point), laying_norms(), design_speed(End.track, nullptr), false); return pieces; } m_join_last = {}; @@ -1285,9 +1285,9 @@ std::vector editor_mode::lay_pieces(std::vector const else ground_follow::follow_points(pieces, plan.knots, {Points.front().y, grade0, Points.back().y, grade1}); if (tool.start.track != nullptr) - lead_cant(pieces, -editor_track::joint_roll(*tool.start.track, tool.start.point), design.norms.gauge, true); + lead_cant(pieces, -editor_track::joint_roll(*tool.start.track, tool.start.point), design.norms, design.speed, true); if (End.track != nullptr) - lead_cant(pieces, editor_track::joint_roll(*End.track, End.point), design.norms.gauge, false); + lead_cant(pieces, editor_track::joint_roll(*End.track, End.point), design.norms, design.speed, false); if (Plan != nullptr) *Plan = std::move(plan); return pieces; @@ -2304,6 +2304,14 @@ track_hover editor_mode::split_spot() const return track_under_cursor(selected, 20.0f); } +void editor_mode::route_drop() +{ + // the lay, extend and join tools take their norms from here: emptied with the line, they'd go back to the defaults unseen + auto const norms{m_route.design.norms}; + m_route = {}; + m_route.design.norms = norms; +} + alignment::limits editor_mode::laying_norms() const { auto norms{m_route.design.norms}; diff --git a/application/editormodetrack.cpp b/application/editormodetrack.cpp index 6e0fe60c7..3fbfa36de 100644 --- a/application/editormodetrack.cpp +++ b/application/editormodetrack.cpp @@ -1589,7 +1589,25 @@ void editor_mode::render_path_ui() if (std::array cants{lift(path.rolls[0]), lift(path.rolls[1])}; ImGui::DragFloat2("##roll", cants.data(), 0.5f, -388.0f, 388.0f, "%.0f") && std::isfinite(cants[0]) && std::isfinite(cants[1])) path.rolls = {roll(cants[0]), roll(cants[1])}; item_tooltip("Cant at the start and at the end: how much higher one rail is, + raises the left rail looking along the path"); - finish_edit(rebuild::geometry); + // the cant typed at an end goes on into the track joined there, as with the gizmo and the joints tool: the joint + // would step otherwise. the neighbours go into the same undo step + if (ImGui::IsItemActivated()) + m_track_field_before = before; + if (ImGui::IsItemDeactivatedAfterEdit()) + { + std::vector> states{{track, m_track_field_before}}; + std::vector changed{track}; + auto const joints{editor_track::joints(*track)}; + for (auto const &joint : joints) + if (std::find(changed.begin(), changed.end(), joint.other) == changed.end()) + { + states.emplace_back(joint.other, editor_track::capture(*joint.other)); + changed.push_back(joint.other); + } + editor_track::match_rolls(*track, joints); + push_track_snapshot(std::move(states)); + editor_track::commit(changed); + } field_row("Radius"); if (auto radius{path.radius}; ImGui::InputFloat("##radius", &radius, 0.0f, 0.0f, "%.1f") && std::isfinite(radius)) path.radius = radius; @@ -1711,7 +1729,7 @@ void editor_mode::delete_selected_track() push_track_snapshot({}, created, {set->first, set->link, set->second}); drives_deleted({set->first, set->second}); if (std::any_of(m_route.chain.tracks.begin(), m_route.chain.tracks.end(), [&](TTrack const *Each) { return Each == set->first || Each == set->link || Each == set->second; })) - m_route = {}; + route_drop(); m_node = nullptr; ui()->set_node(nullptr); m_track_point = {}; @@ -1742,16 +1760,62 @@ void editor_mode::delete_selected_track() push_track_snapshot({}, created, slip->parts); drives_deleted(slip->switches); if (std::any_of(m_route.chain.tracks.begin(), m_route.chain.tracks.end(), [&](TTrack const *Each) { return std::find(slip->parts.begin(), slip->parts.end(), Each) != slip->parts.end(); })) - m_route = {}; + route_drop(); m_node = nullptr; ui()->set_node(nullptr); m_track_point = {}; straight_refresh(); return; } - // retired first, so the infrastructure it carried and moves elsewhere is in the same undo step + // a switch of a crossover takes the whole crossover out, as the connection tools do: its switches leave their main tracks, the + // insert goes and the outer track of a crossover on a curve comes down by the lift it went up by. Alone, the switch would leave + // the record of the connection behind, the outer track up, and the next switch given its name would take the connection over + if (auto const crossover{crossover_of(*track)}) + { + for (auto const *part : {crossover->first, crossover->second, crossover->insert}) + if (false == part->Dynamics.empty()) + { + ui()->set_status(STR_C("The track can't be deleted while vehicles stand on it"), true); + return; + } + profile_library_load(); + auto library{m_profiles}; + std::vector> states; + std::vector created; + std::vector removed; + TTrack *first{nullptr}; + TTrack *second{nullptr}; + if (false == take_out_crossover(*crossover, states, created, removed, first, second)) + { + ui()->set_status(STR_C("The crossover there can't be taken out"), true); + return; + } + switch_store::follow(); + auto status{std::string{STR_C("The crossover is taken out whole, its switches replaced by their main tracks")}}; + if (auto const note{designs_trimmed(removed)}; false == note.empty()) + status += "\n" + note; + auto const chained{std::any_of(removed.begin(), removed.end(), [&](TTrack const *Each) { return std::find(m_route.chain.tracks.begin(), m_route.chain.tracks.end(), Each) != m_route.chain.tracks.end(); })}; + push_track_snapshot(std::move(states), std::move(created), removed); + drives_deleted(removed); + records_to_history(); + if (crossover->record.lifted()) + profiles_to_history(std::move(library)); + if (chained) + route_drop(); + ui()->set_status(status, false); + m_node = nullptr; + ui()->set_node(nullptr); + m_track_point = {}; + straight_refresh(); + return; + } + // retired first, so the infrastructure it carried and moves elsewhere is in the same undo step. A switch bent out of the shape of + // its record isn't found by the shape, so by its name if (auto const known{switch_store::of(*track)}) switch_store::forget(known->name); + else if (track->eType == tt_Switch) + if (auto const named{switch_store::named(*track)}) + switch_store::forget(named->name); editor_track::retire(*track); // a switch leaves its main track behind, so the line isn't broken, unless Shift asks for all of it std::vector created; @@ -1775,7 +1839,7 @@ void editor_mode::delete_selected_track() m_history.back().instances.push_back(instance); } if (std::find(m_route.chain.tracks.begin(), m_route.chain.tracks.end(), track) != m_route.chain.tracks.end()) - m_route = {}; + route_drop(); m_node = nullptr; ui()->set_node(nullptr); m_track_point = {}; diff --git a/application/editormodetrackprops.cpp b/application/editormodetrackprops.cpp index 4542d0225..4e3d99b48 100644 --- a/application/editormodetrackprops.cpp +++ b/application/editormodetrackprops.cpp @@ -206,12 +206,13 @@ enum group : int ride_sound, frogs, sleeper_placement, // spacing and shift of the sleepers and of the trackbed under them, apart from their models + gauge, // of its own: pasting how a track rides or sounds doesn't change its gauge group_count }; -char const *const kGroupLabels[group_count] = {"Speed", "Environment", "Overhead line", "Track circuits", "Rails", "Trackbed", "Shape of the trackbed", "Sleepers", "Ride and sound", "Frog and check rails", "Sleeper placement"}; +char const *const kGroupLabels[group_count] = {"Speed", "Environment", "Overhead line", "Track circuits", "Rails", "Trackbed", "Shape of the trackbed", "Sleepers", "Ride and sound", "Frog and check rails", "Sleeper placement", "Gauge"}; // the groups as the presets keep them in their file, by names which don't change with the order of the groups -char const *const kGroupKeys[group_count] = {"speed", "environment", "overhead", "circuits", "rails", "trackbed", "bedshape", "sleepers", "ride", "frogs", "sleeperplacement"}; +char const *const kGroupKeys[group_count] = {"speed", "environment", "overhead", "circuits", "rails", "trackbed", "bedshape", "sleepers", "ride", "frogs", "sleeperplacement", "gauge"}; struct track_property { @@ -712,7 +713,7 @@ std::vector make_properties() return true; }; } - add_float(list, "gauge", section::ride, group::ride_sound, "Gauge (m)", "Gauge of the track, 1.435 m for the standard gauge", &TTrack::fTrackWidth, 3, 0.01f, true); + add_float(list, "gauge", section::ride, group::gauge, "Gauge (m)", "Gauge of the track, 1.435 m for the standard gauge", &TTrack::fTrackWidth, 3, 0.01f, true); list.back().applies = any; return list; } diff --git a/application/editormodetrackux.cpp b/application/editormodetrackux.cpp index 57e436900..43372e63e 100644 --- a/application/editormodetrackux.cpp +++ b/application/editormodetrackux.cpp @@ -1939,22 +1939,99 @@ void editor_mode::track_set_delete() { track_set_prune(); std::vector removed; + // of crossovers taken out: the main tracks of their switches laid, the outer track brought down + std::vector> states; + std::vector created; + bool crossovers{false}; + bool lifted{false}; + profile_library_load(); + auto library{m_profiles}; std::size_t kept{0}; + auto const gone = [&](TTrack const *Track) { return std::find(removed.begin(), removed.end(), Track) != removed.end(); }; + auto const blocked = [](TTrack const *Track) { return false == Track->Dynamics.empty() || false == scene::Layers.editable(Track); }; + // as Del does with each: a double switch, a slip and a crossover go whole, the records of the switches go with them for (auto *track : m_track_set) { - if (false == track->Dynamics.empty() || false == scene::Layers.editable(track)) + if (gone(track)) + continue; + if (blocked(track)) { ++kept; continue; } + if (auto const set{double_of(*track)}) + { + if (blocked(set->first) || blocked(set->link) || blocked(set->second)) + { + ++kept; + continue; + } + if (auto const known{switch_store::named(*set->first)}) + switch_store::forget(known->name); + for (auto *part : {set->first, set->link, set->second}) + if (false == gone(part)) + { + editor_track::retire(*part); + removed.push_back(part); + } + continue; + } + if (auto const slip{slip_of(*track)}) + { + if (std::any_of(slip->parts.begin(), slip->parts.end(), blocked)) + { + ++kept; + continue; + } + slip_taken_out(*slip, false); + for (auto *part : slip->parts) + if (false == gone(part)) + removed.push_back(part); + continue; + } + if (auto const crossover{crossover_of(*track)}) + { + if (blocked(crossover->first) || blocked(crossover->second) || blocked(crossover->insert)) + { + ++kept; + continue; + } + TTrack *first{nullptr}; + TTrack *second{nullptr}; + if (take_out_crossover(*crossover, states, created, removed, first, second)) + { + crossovers = true; + lifted = lifted || crossover->record.lifted(); + continue; + } + } + if (auto const known{switch_store::of(*track)}) + switch_store::forget(known->name); + else if (track->eType == tt_Switch) + if (auto const named{switch_store::named(*track)}) + switch_store::forget(named->name); editor_track::retire(*track); removed.push_back(track); - if (std::find(m_route.chain.tracks.begin(), m_route.chain.tracks.end(), track) != m_route.chain.tracks.end()) - m_route = {}; } + if (std::any_of(removed.begin(), removed.end(), [&](TTrack const *Each) { return std::find(m_route.chain.tracks.begin(), m_route.chain.tracks.end(), Each) != m_route.chain.tracks.end(); })) + route_drop(); + if (crossovers) + switch_store::follow(); auto const designs{designs_trimmed(removed)}; - push_track_snapshot({}, {}, removed); + push_track_snapshot(std::move(states), std::move(created), removed); drives_deleted(removed); + // the model and the events of a turntable can't stay without its track + for (auto const *track : removed) + if (track->eType == tt_Table) + for (auto const instance : turntable_includes(*track)) + { + scene::Layers.removed(instance, true); + m_history.back().instances.push_back(instance); + } + if (crossovers) + records_to_history(); + if (lifted) + profiles_to_history(std::move(library)); m_track_set.clear(); m_node = nullptr; ui()->set_node(nullptr); diff --git a/editor/editorAlignment.cpp b/editor/editorAlignment.cpp index fa43be3fb..aef5e31b9 100644 --- a/editor/editorAlignment.cpp +++ b/editor/editorAlignment.cpp @@ -1348,6 +1348,11 @@ glm::dvec3 along_end(glm::dvec3 const &Point, glm::dvec2 const &Direction, doubl } // namespace +double cant_ramp_length(double const Speed, double const Cant, limits const &Limits) +{ + return ramp_length(Speed, std::abs(Cant), Limits); +} + std::pair end_curvatures(element const &Element) { auto const own{Element.radius > 0.0 ? 1.0 / Element.radius : 0.0}; diff --git a/editor/editorAlignment.hpp b/editor/editorAlignment.hpp index 6e9e96828..afac9211e 100644 --- a/editor/editorAlignment.hpp +++ b/editor/editorAlignment.hpp @@ -134,6 +134,9 @@ struct recommendation }; recommendation recommend(double const Speed, double const Radius, limits const &Limits); double transition_length(double const Speed, double const Radius, double const Cant, limits const &Limits); +// the length of a straight cant ramp the norms ask for to change the cant by Cant [mm] at Speed [km/h]: slow enough in time and +// along the track [m], 0 for no change +double cant_ramp_length(double const Speed, double const Cant, limits const &Limits); // the transition curve from the curvature and the cant of one arc to those of the next one, 0 for a straight; the curvature positive // turning one way, the cant with the same sign as the curvature it leans into double transition_between(double const Speed, double const Curvature0, double const Cant0, double const Curvature1, double const Cant1, limits const &Limits); diff --git a/editor/editorTrack.cpp b/editor/editorTrack.cpp index f88c91a18..32084bc00 100644 --- a/editor/editorTrack.cpp +++ b/editor/editorTrack.cpp @@ -1226,11 +1226,16 @@ double editor_track::velocity(TTrack const &Track) { if (Track.SwitchExtension && Track.eType == tt_Switch) return Track.SwitchExtension->fVelocity; + // a turntable keeps the limit of its file where a switch does, and it's that one which is saved + if (Track.SwitchExtension && Track.eType == tt_Table && Track.SwitchExtension->fVelocity != -1.0f) + return Track.SwitchExtension->fVelocity; return Track.fVelocity; } void editor_track::velocity(TTrack &Track, double const Velocity) { + if (Track.SwitchExtension && Track.eType == tt_Table) + Track.SwitchExtension->fVelocity = static_cast(Velocity); if (Track.SwitchExtension && Track.eType == tt_Switch) { Track.SwitchExtension->fVelocity = static_cast(Velocity); diff --git a/tests/unit/test_alignment.cpp b/tests/unit/test_alignment.cpp index 2fe18fbb5..b57a2a4b7 100644 --- a/tests/unit/test_alignment.cpp +++ b/tests/unit/test_alignment.cpp @@ -1162,3 +1162,27 @@ TEST_CASE("alignment: a curve traced on from a switch goes on at its radius, not CHECK(two.vertices.front().arcs.front().radius == doctest::Approx(600.0).epsilon(0.1)); CHECK(two.rms < 0.1); } + +TEST_CASE("alignment: the cant ramp the norms ask for, which a track laid on from a canted joint takes its cant off along") { + alignment::limits const norms; + // no change, no ramp + CHECK(alignment::cant_ramp_length(100.0, 0.0, norms) == doctest::Approx(0.0)); + // 120 mm at 100 km/h: along the track 0.12 * 10 * 100 = 120 m, longer than in time (100 * 120 / (3.6 * 35) = 95.2 m). The lay tool + // used to take any cant off at a fixed 1.5 mm a metre, over 80 m here, whatever the speed and the norms + CHECK(alignment::cant_ramp_length(100.0, 120.0, norms) == doctest::Approx(120.0)); + // the cant taken off or put on alike + CHECK(alignment::cant_ramp_length(100.0, -120.0, norms) == doctest::Approx(120.0)); + // slower, shorter: 0.12 * 10 * 40 = 48 m, to whole 5 m + CHECK(alignment::cant_ramp_length(40.0, 120.0, norms) == doctest::Approx(50.0)); + // the norms of the route tool count: a gentler factor leaves the time the longer, 95.2 m to 100 m + auto gentle{norms}; + gentle.ramp_factor = 5.0; + CHECK(alignment::cant_ramp_length(100.0, 120.0, gentle) == doctest::Approx(100.0)); + // the ramp is never shorter at a higher speed + double previous{0.0}; + for (double speed = 20.0; speed <= 200.0; speed += 10.0) { + auto const length{alignment::cant_ramp_length(speed, 80.0, norms)}; + CHECK(length >= previous); + previous = length; + } +} From 65e48703189fb238fe4851aa67676dfa978a815b Mon Sep 17 00:00:00 2001 From: maj00r <73280030+maj00r@users.noreply.github.com> Date: Tue, 24 Nov 2026 18:34:25 +0100 Subject: [PATCH 2/6] test(editor): a mistyped track fails the self-test, indented comments are skipped, case 7b checks the switch got bent - A blank line or an indented `#` comment in a script is no longer a command no group takes. - `trackcant`, `routegauge` and `tracksetdelete` with a track that isn't there count as a failed expectation. - `expect shaped `: 7b checks that the gizmo drag bent the switch out of its record before deleting it. - The ramp-length loop of test_alignment counts in an integer (Sonar S2193). --- application/editormodeselftest.cpp | 10 +++++++-- application/editormodeselftest.h | 7 +++++++ application/editormodeselftestexpect.cpp | 22 +++++++++++++++++++- application/editormodeselftesttrack.cpp | 12 +++++++++-- application/editormodetrackprops.cpp | 8 +++++++ tests/editor/cases/7b_bent_switch_delete.txt | 3 +++ tests/unit/test_alignment.cpp | 3 ++- 7 files changed, 59 insertions(+), 6 deletions(-) diff --git a/application/editormodeselftest.cpp b/application/editormodeselftest.cpp index 8bc62f626..76173a58c 100644 --- a/application/editormodeselftest.cpp +++ b/application/editormodeselftest.cpp @@ -218,6 +218,7 @@ editor_mode::selftest_result editor_mode::selftest_dispatch(std::string const &c // expect joint the end of the first path against the end of another track // nearest to it within 1 m: the gap, the kink and the step of the cant between them, each at most // expect records [kind] the records of the switch store of the name, with the connections having the switch among theirs +// expect shaped the switch keeps the shape its record says, or was bent out of it // expect speed [tolerance], expect gauge [tolerance] as editor_track::velocity gives it / the gauge // expect track // expect route the track is a part of the line open in the route tool, or not @@ -240,8 +241,13 @@ void editor_mode::selftest_step() std::ifstream stream(file); std::string line; while (std::getline(stream, line)) - if (false == line.empty() && line.front() != '#') - test.lines.push_back(line); + { + // an indented comment or a line of blanks is no command either + auto const first{line.find_first_not_of(" \t\r")}; + if (first == std::string::npos || line[first] == '#') + continue; + test.lines.push_back(line.substr(first)); + } WriteLog("SELFTEST: " + std::to_string(test.lines.size()) + " steps from " + file); } ++editor_selftest::frames(); diff --git a/application/editormodeselftest.h b/application/editormodeselftest.h index 0a2cf479c..8270a7491 100644 --- a/application/editormodeselftest.h +++ b/application/editormodeselftest.h @@ -51,6 +51,13 @@ inline std::size_t &failures() return count; } +// a command whose subject isn't there, a track name mistyped, fails the run as an expectation does +inline void fail() +{ + ++expectations(); + ++failures(); +} + // apart from the 1 of a start which failed or of an error which ended the editor inline constexpr int failed_exit_code{2}; diff --git a/application/editormodeselftestexpect.cpp b/application/editormodeselftestexpect.cpp index 6cb31a6d4..488bf0a18 100644 --- a/application/editormodeselftestexpect.cpp +++ b/application/editormodeselftestexpect.cpp @@ -186,6 +186,24 @@ void expect_records(std::string const &What, std::istringstream &Words) expectation(count == wanted, What, std::to_string(count), std::to_string(wanted)); } +// expect shaped : the switch keeps the shape its record says, or was bent out of it +void expect_shaped(std::string const &What, std::istringstream &Words) +{ + std::string name; + std::string wanted; + Words >> name >> wanted; + if (malformed(What, Words)) + return; + auto const *track{simulation::Paths.find(name)}; + if (track == nullptr || track->m_editorremoved) + { + expectation(false, What, "no track " + name, "a switch"); + return; + } + auto const shaped{switch_store::of(*track).has_value()}; + expectation(shaped == (wanted == "yes"), What, shaped ? "yes" : "no", wanted); +} + // expect speed [tolerance], expect gauge [tolerance] void expect_track_value(std::string const &What, std::string const &Kind, std::istringstream &Words) { @@ -342,6 +360,8 @@ editor_mode::selftest_result editor_mode::selftest_expect(std::string const &com expect_joint(what, words, &editor_mode::cant_of_roll); else if (kind == "records") expect_records(what, words); + else if (kind == "shaped") + expect_shaped(what, words); else if (kind == "speed" || kind == "gauge") expect_track_value(what, kind, words); else if (kind == "track") @@ -355,6 +375,6 @@ editor_mode::selftest_result editor_mode::selftest_expect(std::string const &com else if (kind == "includes") expect_includes(what, words); else - expectation(false, what, "no expectation " + kind, "cant, joint, records, speed, gauge, track, route, norms, height, lift or includes"); + expectation(false, what, "no expectation " + kind, "cant, joint, records, shaped, speed, gauge, track, route, norms, height, lift or includes"); return selftest_result::handled; } diff --git a/application/editormodeselftesttrack.cpp b/application/editormodeselftesttrack.cpp index f29acdb3c..8f1f98d26 100644 --- a/application/editormodeselftesttrack.cpp +++ b/application/editormodeselftesttrack.cpp @@ -404,8 +404,15 @@ editor_mode::selftest_result editor_mode::selftest_track(std::string const &comm double gauge{1500.0}; std::string name; words >> gauge >> name; + auto *track{name.empty() ? nullptr : simulation::Paths.find(name)}; + if (false == name.empty() && (track == nullptr || track->m_editorremoved)) + { + editor_selftest::fail(); + WriteLog("SELFTEST FAIL routegauge: no track " + name); + return selftest_result::handled; + } // the line of the track opened in the route tool, as a click on it with the tool does, unless it's in the line open already - if (auto *track{simulation::Paths.find(name)}; track != nullptr && false == track->m_editorremoved && std::ranges::find(m_route.chain.tracks, track) == m_route.chain.tracks.end()) + if (track != nullptr && std::ranges::find(m_route.chain.tracks, track) == m_route.chain.tracks.end()) { m_track_tab = track_tab::route; m_route.single = false; @@ -426,7 +433,8 @@ editor_mode::selftest_result editor_mode::selftest_track(std::string const &comm std::string reason; if (track == nullptr || track->m_editorremoved || index < 0 || index >= static_cast(track->m_paths.size()) || false == editor_track::can_edit_geometry(*track, reason)) { - WriteLog("SELFTEST trackcant: no path " + name + " " + std::to_string(index) + " to edit " + reason); + editor_selftest::fail(); + WriteLog("SELFTEST FAIL trackcant: no path " + name + " " + std::to_string(index) + " to edit " + reason); return selftest_result::handled; } // as the field of the inspector takes it: the rolls of the path set, then the edit committed with the track as it was before diff --git a/application/editormodetrackprops.cpp b/application/editormodetrackprops.cpp index ef29e0ec8..8b2f3ffa9 100644 --- a/application/editormodetrackprops.cpp +++ b/application/editormodetrackprops.cpp @@ -15,6 +15,7 @@ http://mozilla.org/MPL/2.0/. #include "stdafx.h" #include "application/editormode.h" #include "application/editoruilayer.h" +#include "application/editormodeselftest.h" #include "application/editormodeshared.h" #include "editor/editorFormat.hpp" #include "editor/editorGeometry.hpp" @@ -2098,8 +2099,15 @@ editor_mode::selftest_result editor_mode::selftest_props(std::string const &Comm // the set made of the tracks, also of one, and the last of them selected, as the set stays the selection only with it m_track_set.clear(); for (std::string name; Words >> name;) + { if (auto *track{simulation::Paths.find(name)}; track != nullptr && false == track->m_editorremoved) + { m_track_set.push_back(track); + continue; + } + editor_selftest::fail(); + WriteLog("SELFTEST FAIL tracksetdelete: no track " + name); + } m_node = m_track_set.empty() ? nullptr : m_track_set.back(); m_track_point = {}; ui()->set_node(m_node); diff --git a/tests/editor/cases/7b_bent_switch_delete.txt b/tests/editor/cases/7b_bent_switch_delete.txt index 122bfb253..9b7d7a003 100644 --- a/tests/editor/cases/7b_bent_switch_delete.txt +++ b/tests/editor/cases/7b_bent_switch_delete.txt @@ -3,11 +3,14 @@ wait 5 switchplace Rz_60E1-300-1:9 40 150 1 1 expect records z1 1 switch +expect shaped z1 yes # the end of the diverging path of z1 moved aside with the gizmo: z1 no longer has the shape its record says select z1 gizmo begin translate 1 end gizmo offset 0.5 0 0 gizmo end +# the drag went through: without it the case would only delete a switch which kept its shape +expect shaped z1 no expect records z1 1 switch deletetrack z1 expect track z1 removed diff --git a/tests/unit/test_alignment.cpp b/tests/unit/test_alignment.cpp index b57a2a4b7..bb6faf9f0 100644 --- a/tests/unit/test_alignment.cpp +++ b/tests/unit/test_alignment.cpp @@ -1180,7 +1180,8 @@ TEST_CASE("alignment: the cant ramp the norms ask for, which a track laid on fro CHECK(alignment::cant_ramp_length(100.0, 120.0, gentle) == doctest::Approx(100.0)); // the ramp is never shorter at a higher speed double previous{0.0}; - for (double speed = 20.0; speed <= 200.0; speed += 10.0) { + for (int step{0}; step <= 18; ++step) { + auto const speed{20.0 + 10.0 * step}; auto const length{alignment::cant_ramp_length(speed, 80.0, norms)}; CHECK(length >= previous); previous = length; From 4217650469baf2bcf73c616d0a9e366533176e44 Mon Sep 17 00:00:00 2001 From: maj00r <73280030+maj00r@users.noreply.github.com> Date: Tue, 24 Nov 2026 18:35:19 +0100 Subject: [PATCH 3/6] test(editor): the entries known to be lost are checked apart from should_fail, the cant test says where the inspector conversion is tested - A normal test checks that known_lost.scn and each of its entries are there and read, so the should_fail tests can't pass for data gone missing. - The comment of test_cant.cpp said the tests of cant_of_roll()/roll_of_cant() are here; they are the self-test case 1_inspector_cant.txt, as the unit tests don't link the editor. --- tests/unit/test_cant.cpp | 5 +++-- tests/unit/test_track_text.cpp | 16 ++++++++++++++++ 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/tests/unit/test_cant.cpp b/tests/unit/test_cant.cpp index b8741a529..9a00bbd84 100644 --- a/tests/unit/test_cant.cpp +++ b/tests/unit/test_cant.cpp @@ -1,8 +1,9 @@ // the cant of the tracks the editor lays and joins: from mm to the roll of the paths and back, signed with the turn, and matched // across the joints of the tracks // -// the inspector of the editor shows and takes the cant on a base of 1500 mm in lambdas of its own (application/editormodetrack.cpp); -// named, as editor_mode::cant_of_roll() and roll_of_cant(), they come with the quick fixes of the track editing, and their tests with them +// the inspector of the editor shows and takes the cant on a base of 1500 mm through editor_mode::cant_of_roll() and roll_of_cant() +// (application/editormodetrack.cpp). They live in the editor, which the unit tests don't link, so the self-test cases check them +// through the inspector: tests/editor/cases/1_inspector_cant.txt #include "stdafx.h" #include "doctest.h" diff --git a/tests/unit/test_track_text.cpp b/tests/unit/test_track_text.cpp index 9c9cce236..8e3f15b6b 100644 --- a/tests/unit/test_track_text.cpp +++ b/tests/unit/test_track_text.cpp @@ -182,6 +182,22 @@ TEST_CASE("track text: what the game writes otherwise than it was given, the sam // what doesn't survive yet: each fails until it does, then doctest reports the test passing against should_fail, and the entry goes // over to the files of the entries which come out the same +// what those tests start from, checked apart from them: under should_fail a missing file or entry would pass for a loss +TEST_CASE("track text: the entries known to be lost are there, with what they're about, and read") { + track_reading const reading; + struct known { + char const *name; + char const *about; + }; + for (auto const &[name, about] : {known{"angles", " angle1 15 "}, known{"fouling", " fouling1 ukres_a "}, known{"tor1@iso1", "tor1@iso1"}, known{"digits", " digits "}}) { + CAPTURE(name); + auto const text{entry("known_lost.scn", name)}; + REQUIRE(false == text.empty()); + CHECK(text.find(about) != std::string::npos); + CHECK(read_track(text) != nullptr); + } +} + TEST_CASE("track text: the angles the ends are cut at are written back (known lost: read and dropped)" * doctest::should_fail()) { track_reading const reading; round_trip const trip{entry("known_lost.scn", "angles")}; From a8e1e6ab71a9d3ddd686821f48116550c19ac8b4 Mon Sep 17 00:00:00 2001 From: maj00r <73280030+maj00r@users.noreply.github.com> Date: Tue, 24 Nov 2026 18:40:23 +0100 Subject: [PATCH 4/6] fix(editor): TSI and EN take close jumps of the cant deficiency together, the norms queue keeps its own span after a delete - TSI INF and EN 13803 limit an abrupt change of the cant deficiency but give no intermediate length, so two jumps a few metres apart were each checked alone: at km 478 of the golden line CH reported 191 mm over the TSI limit, TSI itself nothing. With no intermediate length in the profiles of the element, the longest any profile asks for is taken. The golden report changes that way: TSI gets the 191 mm hard limit at km 478, EN reports it instead of 106 and 85 mm one by one. - forget() moves the span whose findings alone are kept (a diverging track) down by the spans removed before it, and drops a queued line whose own span was removed, instead of leaving the index on another span. - The report test of R 400 / 80 mm runs at 90 km/h and requires the finding: at 80 km/h there was none and the check never ran. --- application/editormodenorms.cpp | 20 ++++++++++++++++++-- editor/norms/normsEngine.cpp | 20 ++++++++++++++------ tests/unit/data/norms/line_report.txt | 8 ++++---- tests/unit/test_norms_engine.cpp | 15 +++++++++++++++ tests/unit/test_norms_report.cpp | 13 ++++++------- 5 files changed, 57 insertions(+), 19 deletions(-) diff --git a/application/editormodenorms.cpp b/application/editormodenorms.cpp index fc6d717c5..d77b0597e 100644 --- a/application/editormodenorms.cpp +++ b/application/editormodenorms.cpp @@ -212,8 +212,24 @@ void norms_tool::forget(scene::basic_node const *Node) state.selected = -1; for (auto &line : state.lines) std::erase_if(line.entries, [Node](norms_report::entry const &Entry) { return Entry.track == Node; }); - for (auto &line : state.queue) - std::erase_if(line.spans, [Node](norms_report::span const &Span) { return Span.track == Node; }); + // the span whose findings alone are kept moves down by the spans taken out before it; a line whose own span went has nothing left + // to report + auto const gone = [Node](norms_report::span const &Span) { return Span.track == Node; }; + auto line{state.queue.begin()}; + while (line != state.queue.end()) + { + if (line->own >= 0 && line->own < static_cast(line->spans.size())) + { + if (gone(line->spans[line->own])) + { + line = state.queue.erase(line); + continue; + } + line->own -= static_cast(std::count_if(line->spans.begin(), line->spans.begin() + line->own, gone)); + } + std::erase_if(line->spans, gone); + ++line; + } } void norms_tool::render_class() diff --git a/editor/norms/normsEngine.cpp b/editor/norms/normsEngine.cpp index df571a502..f2e2c7eed 100644 --- a/editor/norms/normsEngine.cpp +++ b/editor/norms/normsEngine.cpp @@ -11,6 +11,7 @@ http://mozilla.org/MPL/2.0/. #include "editor/norms/norms.hpp" #include +#include #include #include @@ -374,15 +375,22 @@ class checker return result; } - // the shortest element between two jumps for them to be taken apart: the longest the profiles of the element between them ask for + // the shortest element between two jumps for them to be taken apart: the longest the profiles of the element between them ask for. + // TSI INF and EN 13803 limit the jump but say nothing of jumps close together, so with only them there the longest any profile + // asks for is taken: otherwise two jumps a metre apart would each pass a limit their sum breaks double intermediate(std::size_t const Index, double const Speed) const { auto const &element{m_line.elements[Index]}; - double result{0.0}; - for (auto const profile : profiles(element)) - if (auto const bound{limits(profile, parameter::intermediate_length, where(element, Speed, 0.0)).block}) - result = std::max(result, bound->value); - return result; + auto const longest = [this, &element, Speed](auto const &Profiles) { + double result{0.0}; + for (auto const profile : Profiles) + if (auto const bound{limits(profile, parameter::intermediate_length, where(element, Speed, 0.0)).block}) + result = std::max(result, bound->value); + return result; + }; + if (auto const own{longest(profiles(element))}; own > 0.0) + return own; + return longest(std::array{profile_id::plk, profile_id::tsi, profile_id::en13803, profile_id::ch}); } // ST-T1-A6 9.11 pkt 8 - 13: the jumps closer than the intermediate length, changing the cant deficiency the same way, are taken diff --git a/tests/unit/data/norms/line_report.txt b/tests/unit/data/norms/line_report.txt index 28b635204..fe0fd0aff 100644 --- a/tests/unit/data/norms/line_report.txt +++ b/tests/unit/data/norms/line_report.txt @@ -34,17 +34,17 @@ Line n01: 988.0 m, 11 elements, 19 findings 828.0 note cant change rate 42 mm/s, PLK recommends at most 35 mm/s (tab. 9.13) [n13] Norms: TSI INF, line 100 km/h, slow trains 60 km/h, mixed traffic, main track, 5 Tg a year, the speed of the tracks where they have one -Line n01: 988.0 m, 11 elements, 3 findings +Line n01: 988.0 m, 11 elements, 4 findings + 478.0 hard limit abrupt change of the cant deficiency 191 mm, TSI INF allows at most 130 mm (4.2.4.4(1)) [n07] 598.0 hard limit break of the grade with no vertical curve, TSI INF asks for a radius of at least 900 m (4.2.3.5(1)) [n10] 648.0 hard limit cant ramp 3.00 mm/m, EN 13803-1 allows at most 2.50 mm/m (5.2.5) [n11] 648.0 hard limit break of the grade with no vertical curve, TSI INF asks for a radius of at least 500 m (4.2.3.5(1)) [n11] Norms: EN 13803, line 100 km/h, slow trains 60 km/h, mixed traffic, main track, 5 Tg a year, the speed of the tracks where they have one -Line n01: 988.0 m, 11 elements, 10 findings +Line n01: 988.0 m, 11 elements, 9 findings 210.0 warning cant deficiency 137 mm, EN 13803 allows at most 130 mm (5.2.3, tab. 1) [n03] 398.0 warning abrupt change of the cant deficiency 106 mm, EN 13803 allows at most 50 mm (EN 13803-2 7.1.3), the limit not confirmed [n06] - 478.0 warning abrupt change of the cant deficiency 106 mm, EN 13803 allows at most 50 mm (EN 13803-2 7.1.3), the limit not confirmed [n07] - 488.0 warning abrupt change of the cant deficiency 85 mm, EN 13803 allows at most 50 mm (EN 13803-2 7.1.3), the limit not confirmed [n08] + 478.0 hard limit abrupt change of the cant deficiency 191 mm, TSI INF allows at most 130 mm (4.2.4.4(1)) [n07] 548.0 warning abrupt change of the cant deficiency 85 mm, EN 13803 allows at most 50 mm (EN 13803-2 7.1.3), the limit not confirmed [n09] 598.0 hard limit break of the grade with no vertical curve, TSI INF asks for a radius of at least 900 m (4.2.3.5(1)) [n10] 648.0 hard limit cant ramp 3.00 mm/m, EN 13803 allows at most 2.50 mm/m (5.2.5) [n11] diff --git a/tests/unit/test_norms_engine.cpp b/tests/unit/test_norms_engine.cpp index 71100e481..fdea9d765 100644 --- a/tests/unit/test_norms_engine.cpp +++ b/tests/unit/test_norms_engine.cpp @@ -237,6 +237,21 @@ TEST_CASE("norms engine: the abrupt changes over a straight shorter than tab. 9. } } +TEST_CASE("norms engine: TSI and EN, which say nothing of jumps close together, take them together over the intermediate length of the other profiles") { + // the reverse curves of the test above, 10 m apart: each jump of 106.2 mm passes the TSI, their 212.4 mm don't + auto const each{11.8 * 60 * 60 / 400.0}; + for (auto const profile : {profile_id::tsi, profile_id::en13803}) { + CAPTURE(static_cast(profile)); + line_builder builder; + builder.straight(100, 60).arc(400, 80, 60).straight(10.0, 60).arc(-400, 80, 60).straight(100, 60); + auto const found{of(evaluate(builder.done(), mixed_main(60), profile), parameter::deficiency_jump)}; + auto const summed{std::ranges::find_if(found, [](norms::finding const &Finding) { return std::abs(Finding.chainage - 180.0) < 1e-6; })}; + REQUIRE(summed != found.end()); + CHECK(summed->value == doctest::Approx(2.0 * each)); + CHECK(summed->length == doctest::Approx(10.0)); + } +} + TEST_CASE("norms engine: the gradient and the rate of change of the cant along a ramp, the rate of change of the deficiency along a transition") { // 100 mm over 50 m at 120 km/h: 2 mm/m, 66.7 mm/s line_builder ramp; diff --git a/tests/unit/test_norms_report.cpp b/tests/unit/test_norms_report.cpp index 1d1aff285..d412ebea4 100644 --- a/tests/unit/test_norms_report.cpp +++ b/tests/unit/test_norms_report.cpp @@ -149,16 +149,15 @@ TEST_CASE("norms report: the cant of a curve laid by the editor leans into it, b } } CHECK(curved > 50); - // so at 80 km/h the arc falls short by 11.8 V^2 / R - 80 mm, not by more + // so at 90 km/h the arc falls short by 11.8 V^2 / R - 80 mm, not by more: 159 mm, past the 110 mm of a finding (at 80 km/h + // the 108.8 mm would make none, and the check would never run) norms_report::options options; - options.line.vmax = 80.0; + options.line.vmax = 90.0; options.track_speeds = false; auto const checked{norms_report::check(spans, options)}; - for (auto const &found : checked.entries) { - if (found.finding.what == norms::parameter::cant_deficiency && found.kind == norms::element_kind::arc) { - CHECK(found.finding.value == doctest::Approx(11.8 * 80 * 80 / 400.0 - 80.0).epsilon(0.02)); - } - } + auto const deficient{std::ranges::find_if(checked.entries, [](auto const &Found) { return Found.finding.what == norms::parameter::cant_deficiency && Found.kind == norms::element_kind::arc; })}; + REQUIRE(deficient != checked.entries.end()); + CHECK(deficient->finding.value == doctest::Approx(11.8 * 90 * 90 / 400.0 - 80.0).epsilon(0.02)); } } } From 4ae90e99c6bc2b644076712ad618e80bf69f7817 Mon Sep 17 00:00:00 2001 From: maj00r <73280030+maj00r@users.noreply.github.com> Date: Tue, 24 Nov 2026 18:43:31 +0100 Subject: [PATCH 5/6] fix(editor): the norms see a Bloss transition as it is, a line splits at the tangent point of an arc with no transitions - A Bloss transition went to the norms as an even one: 60 m into R 600 m at 100 km/h showed 63 mm/s of deficiency change, where its middle reaches 109 mm/s, past the hard limit of 80 mm/s, so the edit wasn't blocked. norms::element::bloss makes the engine follow 3t^2 - 2t^3 of the curvature, look at the transition in eight pieces, and take the shift as L^2 / 40R instead of L^2 / 24R. Two Bloss halves no longer run on into one element of the chain. - split_line right at the tangent point of an arc without transitions was refused ("the tangent there doesn't cross the tangents of the curve"): the curvature there is already the arc's, so it now takes the start or the end of the curve. - Sonar: the chain walk, describe_chain and check_norms check the lines they look up (S2259), join_ends returns when an end isn't found rather than when a reason was given (S836), the test loops count in integers (S2193), the seeded generator of the random edits is marked (S2245). --- editor/layout/layoutCommands.cpp | 13 +++++++--- editor/layout/layoutLine.cpp | 1 + editor/layout/layoutNetwork.cpp | 22 ++++++++++++----- editor/norms/norms.hpp | 6 ++++- editor/norms/normsEngine.cpp | 19 ++++++++++++--- tests/unit/test_layout_commands.cpp | 36 ++++++++++++++++++++++++--- tests/unit/test_layout_elements.cpp | 3 ++- tests/unit/test_norms_engine.cpp | 38 +++++++++++++++++++++++++++++ 8 files changed, 121 insertions(+), 17 deletions(-) diff --git a/editor/layout/layoutCommands.cpp b/editor/layout/layoutCommands.cpp index 103e3e1b3..2121d424d 100644 --- a/editor/layout/layoutCommands.cpp +++ b/editor/layout/layoutCommands.cpp @@ -23,6 +23,7 @@ namespace { double constexpr kParallel{1e-9}; // rad: tangents within this run alike +double constexpr kTouching{1e-6}; // m: a cut this close to the end of an element is at the end double constexpr kShortest{0.1}; // m: no part of a line split shorter; the simulation takes a path under 5 cm for one of no length using reasons = std::vector; @@ -185,13 +186,18 @@ reasons propose(transaction &Change, outcome &Result, split_line const &Command) auto const next{k + 1 == count ? geometry::plan_of(Change.view().find(original.end)->position) : vertices[k + 1].point}; auto const in{glm::normalize(curve.point - previous)}; auto const out{glm::normalize(next - curve.point)}; - if (std::abs(geometry::signed_angle(in, cut.heading)) <= kParallel && std::abs(cut.curvature) < 1e-12) + // at the start or the end of the curve: where its transition leaves the straight, or at the tangent point of an arc with none, + // whose curvature there is already the arc's + auto const straight_there{std::abs(cut.curvature) < 1e-12}; + auto const arc_starts{e.role == element_role::arc && u < kTouching}; + auto const arc_ends{e.role == element_role::arc && u > e.length - kTouching}; + if (std::abs(geometry::signed_angle(in, cut.heading)) <= kParallel && (straight_there || arc_starts)) { // right at the start of the curve take(0, k, before); take(k, count, after); } - else if (std::abs(geometry::signed_angle(cut.heading, out)) <= kParallel && std::abs(cut.curvature) < 1e-12) + else if (std::abs(geometry::signed_angle(cut.heading, out)) <= kParallel && (straight_there || arc_ends)) { take(0, k + 1, before); take(k + 1, count, after); @@ -376,7 +382,8 @@ reasons propose(transaction &Change, outcome &Result, join_ends const &Command) return {"a line can't join a node to itself"}; auto const from{free_end_at(view, Command.from, true, why)}; auto const to{free_end_at(view, Command.to, false, why)}; - if (false == why.empty()) + // an end not found says why in Why + if (false == from.has_value() || false == to.has_value()) return why; auto const &neighbour{*view.find(from->held.line)}; auto const category{neighbour.category}; diff --git a/editor/layout/layoutLine.cpp b/editor/layout/layoutLine.cpp index fd49f3898..db26bd450 100644 --- a/editor/layout/layoutLine.cpp +++ b/editor/layout/layoutLine.cpp @@ -463,6 +463,7 @@ norms::line described(solved_line const &Line, norms::line_class const &Class, s element.length = e.length; element.curvature_start = e.curvature(0.0); element.curvature_end = e.curvature(e.length); + element.bloss = e.kind == element_kind::bloss; element.speed = Class.vmax; auto const from{e.position(0.0)}; auto const to{e.position(e.length)}; diff --git a/editor/layout/layoutNetwork.cpp b/editor/layout/layoutNetwork.cpp index 475b95966..3df6fdb1c 100644 --- a/editor/layout/layoutNetwork.cpp +++ b/editor/layout/layoutNetwork.cpp @@ -97,7 +97,8 @@ norms::element reversed(norms::element Element, double const Length) // the elements run on alike: the same kind, the curvature going on as it did bool runs_on(norms::element const &A, norms::element const &B) { - if (A.kind != B.kind || std::abs(A.curvature_end - B.curvature_start) > kCurvature || A.speed != B.speed || A.features != B.features) + // two halves of Bloss curves make no Bloss curve + if (A.kind != B.kind || A.bloss || B.bloss || std::abs(A.curvature_end - B.curvature_start) > kCurvature || A.speed != B.speed || A.features != B.features) return false; if (A.kind != norms::element_kind::transition) return std::abs(A.curvature_start - B.curvature_end) <= kCurvature; @@ -341,6 +342,8 @@ std::vector chain_of(network const &Network, line_id const Line) { auto const &last{result.back()}; auto const *owner{Network.find(last.line)}; + if (owner == nullptr) + break; auto const beyond{last.forward ? line_end::end : line_end::start}; auto const *other{across(owner->node_at(beyond), last.line, beyond)}; if (other == nullptr || contains(other->line) || Network.find(other->line) == nullptr) @@ -352,6 +355,8 @@ std::vector chain_of(network const &Network, line_id const Line) { auto const &head{result.front()}; auto const *owner{Network.find(head.line)}; + if (owner == nullptr) + break; auto const behind{head.forward ? line_end::start : line_end::end}; auto const *other{across(owner->node_at(behind), head.line, behind)}; if (other == nullptr || contains(other->line) || Network.find(other->line) == nullptr) @@ -367,10 +372,14 @@ described_chain describe_chain(network const &Network, std::vector c double offset{0.0}; for (auto const &part : Chain) { - auto const &owner{*Network.find(part.line)}; + // the chain is made of the lines of the network: one gone is a chain out of date, of which the rest is described + auto const *found{Network.find(part.line)}; + result.starts.push_back(offset); + if (found == nullptr) + continue; + auto const &owner{*found}; auto own{described(owner.solved, owner.category)}; auto const length{owner.solved.length}; - result.starts.push_back(offset); if (false == part.forward) { for (auto &element : own.elements) @@ -497,12 +506,13 @@ void check_norms(network const &Network, std::set const &Lines, verdict for (auto const &part : chain) { done.insert(part.line); - laid = laid && Network.find(part.line)->solved.valid(); + auto const *line{Network.find(part.line)}; + laid = laid && line != nullptr && line->solved.valid(); } if (false == laid) continue; auto const described{describe_chain(Network, chain)}; - auto const &first{*Network.find(chain.front().line)}; + auto const &first{*Network.find(chain.front().line)}; // NOSONAR: every line of the chain was found just above for (auto const &finding : norms::evaluate(described.line, first.category, Network.areas)) { if (finding.level == norms::tier::none) @@ -510,7 +520,7 @@ void check_norms(network const &Network, std::set const &Lines, verdict // the line it's on, by the chainage along the chain auto part{static_cast(std::upper_bound(described.starts.begin(), described.starts.end(), finding.chainage + 1e-9) - described.starts.begin())}; part = part > 0 ? part - 1 : 0; - auto const &owner{*Network.find(chain[part].line)}; + auto const &owner{*Network.find(chain[part].line)}; // NOSONAR: every line of the chain was found just above auto const along{finding.chainage - described.starts[part]}; auto const chainage{chain[part].forward ? along : owner.solved.length - along}; auto const text{finding_text(finding)}; diff --git a/editor/norms/norms.hpp b/editor/norms/norms.hpp index ca712b298..92cee7850 100644 --- a/editor/norms/norms.hpp +++ b/editor/norms/norms.hpp @@ -204,7 +204,8 @@ enum class element_kind arc }; -// an element of the line in the plan: the curvature changes evenly along it from its start to its end, signed, positive turning left +// an element of the line in the plan: the curvature changes evenly along it from its start to its end (or as a Bloss curve does), +// signed, positive turning left struct element { element_kind kind{element_kind::straight}; @@ -212,6 +213,9 @@ struct element double length{0.0}; double curvature_start{0.0}; // 1/m double curvature_end{0.0}; + // a transition whose curvature follows the Bloss curve, 3t^2 - 2t^3 of the change: gentle at its ends, 1.5 times as fast as an + // even one in its middle, the arc moved in by L^2 / 40R instead of L^2 / 24R + bool bloss{false}; double speed{0.0}; // km/h, the highest on it; 0: the one of the line class unsigned features{0}; // switch_track, movable_frog, curved_switch, crossing, expansion, diverging, platform, station // the element is cut by the end of the line or by a switch: its length isn't its own diff --git a/editor/norms/normsEngine.cpp b/editor/norms/normsEngine.cpp index f2e2c7eed..7a6c92062 100644 --- a/editor/norms/normsEngine.cpp +++ b/editor/norms/normsEngine.cpp @@ -28,6 +28,7 @@ namespace double constexpr kC{11.8}; double constexpr kSame{1e-6}; // m: points closer along the line are one +int constexpr kBlossPieces{8}; // a Bloss transition seen as this many pieces, as the cant ramps of the same shape are double constexpr kCurve{1.0 / 50000.0}; // 1/m: a curve, not a straight double constexpr kJumpCurvature{1e-6}; // 1/m double constexpr kStep{0.5}; // mm: a smaller step of the cant isn't one @@ -86,7 +87,8 @@ double curvature_at(element const &Element, double const Chainage) { if (Element.length <= kSame) return Element.curvature_end; - return std::lerp(Element.curvature_start, Element.curvature_end, std::clamp((Chainage - Element.start) / Element.length, 0.0, 1.0)); + auto const t{std::clamp((Chainage - Element.start) / Element.length, 0.0, 1.0)}; + return std::lerp(Element.curvature_start, Element.curvature_end, Element.bloss ? t * t * (3.0 - 2.0 * t) : t); } // a point inside an element where the curvature and the cant are known from inside it @@ -192,6 +194,16 @@ class checker continue; result.push_back({point.chainage, curvature_at(Element, point.chainage), point.cant}); } + // the curvature of a Bloss curve doesn't change evenly: eight pieces of it, for its steeper middle to be seen + if (Element.bloss) + { + for (int i = 1; i < kBlossPieces; ++i) + { + auto const chainage{Element.start + Element.length * i / kBlossPieces}; + result.push_back({chainage, curvature_at(Element, chainage), cant_at(m_line.cant, chainage, true)}); + } + std::ranges::sort(result, {}, &station::chainage); + } result.push_back({end, Element.curvature_end, cant_at(m_line.cant, end, false)}); return result; } @@ -291,8 +303,9 @@ class checker if (element.kind == element_kind::transition) { check(parameter::transition_length, element.length, Index, Here, element.start, element.length); - // the arc moved in by a cubic parabola or a clothoid: L^2 / 24 times the change of the curvature (ST-T1-A6 tab. 9.11) - auto const shift{element.length * element.length * std::abs(element.curvature_end - element.curvature_start) / 24.0}; + // the arc moved in by a cubic parabola or a clothoid: L^2 / 24 times the change of the curvature (ST-T1-A6 tab. 9.11), by a + // Bloss curve L^2 / 40 + auto const shift{element.length * element.length * std::abs(element.curvature_end - element.curvature_start) / (element.bloss ? 40.0 : 24.0)}; check(parameter::transition_shift, shift, Index, Here, element.start, element.length); return; } diff --git a/tests/unit/test_layout_commands.cpp b/tests/unit/test_layout_commands.cpp index 4500fe484..e608c2ace 100644 --- a/tests/unit/test_layout_commands.cpp +++ b/tests/unit/test_layout_commands.cpp @@ -34,7 +34,8 @@ track_points along(layout::network const &Network, std::vector const &L track_points result; for (auto const id : Lines) { auto const &solved{Network.find(id)->solved}; - for (double s = 0.0; s < solved.length; s += Step) { + for (int i{0}; i * Step < solved.length; ++i) { + auto const s{i * Step}; result.points.push_back(solved.point(s)); result.cants.push_back(solved.cant_at(s)); } @@ -58,7 +59,8 @@ void check_same_track(layout::network const &Before, line_id const Whole, layout auto const &first{After.find(First)->solved}; auto const &second{After.find(Second)->solved}; CHECK(first.length + second.length == doctest::Approx(whole.length).epsilon(1e-9)); - for (double s = 0.0; s <= whole.length; s += 7.3) { + for (int i{0}; i * 7.3 <= whole.length; ++i) { + auto const s{i * 7.3}; CAPTURE(s); auto const &part{s < first.length ? first : second}; auto const local{s < first.length ? s : s - first.length}; @@ -200,6 +202,34 @@ TEST_CASE("layout commands: a line split on a straight, in an arc and in a cloth } } +TEST_CASE("layout commands: a line split right at the tangent points of an arc with no transitions keeps the track") { + // one gentle curve with neither transitions nor cant, so its curvature jumps at the tangent points + for (auto const share : {0.0, 1.0}) { + CAPTURE(share); + layout::model model; + layout::create_line gentle; + gentle.start = {0.0, 100.0, 0.0}; + gentle.end = {1200.0, 100.0, 50.0}; + layout::vertex bend; + bend.point = {600.0, 0.0}; + bend.radius = 4000.0; + gentle.vertices = {bend}; + gentle.category = line_class(); + auto const made{model.execute(gentle)}; + CAPTURE(reasons_of(made)); + REQUIRE(made.done); + auto const before{model.state()}; + auto const &line{only_line(model)}; + auto const id{line.id}; + auto const chainage{inside(line, layout::element_role::arc, layout::number(line.shape.vertices[0].id), share)}; + auto const split{model.execute(layout::split_line{id, chainage})}; + CAPTURE(reasons_of(split)); + REQUIRE(split.done); + check_invariants(model.state()); + check_same_track(before, id, model.state(), id, split.lines.front()); + } +} + TEST_CASE("layout commands: a split inside a vertical curve or a Bloss transition is refused; outside them it's kept") { layout::model model; REQUIRE(model.execute(three_curves(layout::transition_shape::bloss)).done); @@ -281,7 +311,7 @@ namespace { // random edits of the network: moved vertices, new radii, transitions and cants, splits, joins, deletions, undoing and redoing void random_edits(unsigned const Seed, int const Count) { - std::mt19937 random{Seed}; + std::mt19937 random{Seed}; // NOSONAR: seeded for repeatable tests, nothing secret is drawn auto const uniform = [&](double const Low, double const High) { return std::uniform_real_distribution{Low, High}(random); }; auto const pick = [&](std::size_t const Size) { return std::uniform_int_distribution{0, Size - 1}(random); }; layout::model model; diff --git a/tests/unit/test_layout_elements.cpp b/tests/unit/test_layout_elements.cpp index 72561852d..44e4088bd 100644 --- a/tests/unit/test_layout_elements.cpp +++ b/tests/unit/test_layout_elements.cpp @@ -116,7 +116,8 @@ TEST_CASE("layout elements: an arc keeps its radius and its centre, points offse auto const e{layout::make_arc({5.0, 7.0}, {0.0, 1.0}, -1.0 / R, 200.0)}; // turning right from heading +z: the centre to the right, at +x glm::dvec2 const centre{5.0 + R, 7.0}; - for (double s = 0.0; s <= 200.0; s += 25.0) { + for (int step{0}; step <= 8; ++step) { + auto const s{25.0 * step}; CAPTURE(s); CHECK(glm::distance(e.position(s), centre) == doctest::Approx(R).epsilon(1e-12)); CHECK(e.curvature(s) == -1.0 / R); diff --git a/tests/unit/test_norms_engine.cpp b/tests/unit/test_norms_engine.cpp index fdea9d765..d8d8be982 100644 --- a/tests/unit/test_norms_engine.cpp +++ b/tests/unit/test_norms_engine.cpp @@ -36,6 +36,11 @@ public: m_line.elements.back().features = Features; return *this; } + // the last transition a Bloss curve + line_builder &bloss() { + m_line.elements.back().bloss = true; + return *this; + } norms::line done() { if (m_line.grades.empty()) { m_line.grades.push_back({0.0, m_end, 0.0, 0.0}); @@ -285,6 +290,39 @@ TEST_CASE("norms engine: the gradient and the rate of change of the cant along a CHECK(change.front().level == tier::block); } +TEST_CASE("norms engine: a Bloss transition changes the cant deficiency fastest in its middle, and moves the arc in by L^2 / 40R") { + // 60 m into R 600 m at 100 km/h, the cant evenly up to 60 mm: 136.7 mm of deficiency, 63.3 mm/s along an even transition, and + // 1.5 * 196.7 - 60 = 235 mm per its length in the middle of a Bloss curve, 108.8 mm/s, past the 80 mm/s of the hard limit + auto const findings = [](bool const Bloss) { + line_builder curve; + curve.straight(100, 100).transition(0, 600, 60, 100); + if (Bloss) + curve.bloss(); + curve.arc(600, 100, 100).transition(600, 0, 60, 100); + if (Bloss) + curve.bloss(); + curve.straight(100, 100); + curve.cant(0, 0).cant(100, 0).cant(160, 60).cant(260, 60).cant(320, 0); + return evaluate(curve.done(), mixed_main(100)); + }; + auto const fastest = [](std::vector const &Found) { + double result{0.0}; + for (auto const &finding : of(Found, parameter::deficiency_rate)) + result = std::max(result, finding.value); + return result; + }; + auto const even{findings(false)}; + auto const bloss{findings(true)}; + CHECK(fastest(even) == doctest::Approx((11.8 * 100 * 100 / 600.0 - 60.0) * 100 / (3.6 * 60.0)).epsilon(0.01)); + // seen as eight pieces, a little below the peak of the curve + CHECK(fastest(bloss) > 100.0); + CHECK(fastest(bloss) < 109.0); + auto const blocked{of(bloss, parameter::deficiency_rate)}; + CHECK(std::ranges::any_of(blocked, [](norms::finding const &Finding) { return Finding.level == tier::block; })); + for (auto const &finding : of(bloss, parameter::transition_shift)) + CHECK(finding.value == doctest::Approx(60.0 * 60.0 / (600.0 * 40.0))); +} + TEST_CASE("norms engine: the lengths of the elements, the transition curves and the radius") { line_builder builder; builder.straight(100, 100).arc(400, 20, 100).straight(28, 100).transition(0, 400, 20, 100).arc(400, 100, 100).transition(400, 0, 60, 100).straight(100, 100); From 44d94ae3d38b36362e130a6f6f615b24c933580a Mon Sep 17 00:00:00 2001 From: maj00r <73280030+maj00r@users.noreply.github.com> Date: Tue, 24 Nov 2026 18:49:59 +0100 Subject: [PATCH 6/6] fix(editor): the answer Without terrain keeps to the scenery open, the settings stay as they were nmt_decline_offer() turned off terrain_while_laying and terrain_model().area in the settings of the editor and saved them, so one Without terrain for a scratch scenery left the terrain off for every scenery opened later. The answer now holds for the scenery open only (nmt_state::declined, read through nmt_area()); the checkbox of the terrain panel shows it and, ticked, turns the terrain on again and keeps it in the settings. The nmtquestion self-test no longer writes the tester's settings, and fails the run if the answer changed them. --- application/editormode.cpp | 4 +-- application/editormode.h | 9 +++++-- application/editormodenmt.cpp | 30 ++++++++++++++------- application/editormodeselftest.cpp | 2 +- application/editormodeselftestexpect.cpp | 2 +- application/editormodeselftestterrain.cpp | 21 +++++++++------ tests/editor/cases/fs_3_without_terrain.txt | 5 ++-- 7 files changed, 47 insertions(+), 26 deletions(-) diff --git a/application/editormode.cpp b/application/editormode.cpp index ad505486c..10e243242 100644 --- a/application/editormode.cpp +++ b/application/editormode.cpp @@ -617,7 +617,7 @@ void editor_mode::ground_sources(editor_orthophoto &Layer) return true; // asked for, the tile goes onto it once it comes; not where no terrain is to be made of the model, as after the answer without // terrain - if (m_nmt.placed() && (m_nmt_state.grow || EditorSettings.terrain_model().area)) + if (m_nmt.placed() && (m_nmt_state.grow || nmt_area())) m_nmt.request({X - 1.0, Z - 1.0}, {X + 1.0, Z + 1.0}); return false; }); @@ -6274,7 +6274,7 @@ void editor_mode::render_ground_warning(tutorial_lesson const &Lesson) // over a panel the pointer is over no ground, and in a scenery laid without terrain no ground is to be there if (Lesson.action != tutorial_lesson::trial::lay || ui()->mode() != nodebank_panel::TRACK || ImGui::GetIO().WantCaptureMouse || false == ImGui::IsMousePosValid()) return; - auto const expected{m_streamer.resident() > 0 || ((m_nmt_state.grow || EditorSettings.terrain_model().area) && m_nmt.placed())}; + auto const expected{m_streamer.resident() > 0 || ((m_nmt_state.grow || nmt_area()) && m_nmt.placed())}; if (expected && false == GfxRenderer->Mouse_Hit()) ImGui::TextColored(ImVec4(1.0f, 0.7f, 0.2f, 1.0f), "%s", STR_C("There is no ground under the mouse: the track will lie flat at height 0. Real ground: F5")); } diff --git a/application/editormode.h b/application/editormode.h index 986626f31..38df9b4bc 100644 --- a/application/editormode.h +++ b/application/editormode.h @@ -385,6 +385,9 @@ class editor_mode : public application_mode, private editor_track::observer, pri double band{300.0}; // m from the tracks the chunks made along them reach bool shape{true}; // the formation and the slopes of the tracks as modifiers of the terrain bool grow{true}; // while a track is laid, the terrain is made around the cursor where there's none + // the answer Without terrain for the scenery open: nothing of the model is made around the camera by itself, whatever the + // settings, which stay as they were for the other sceneries + bool declined{false}; bool laying{false}; // the tracks committed are being laid: they leave the terrain as it is bool follow{true}; // a track with its formation edited takes it along, the formation led anew bool grown{false}; // the chunks waiting were all asked for by growing: the formations aren't made anew after them @@ -656,8 +659,10 @@ class editor_mode : public application_mode, private editor_track::observer, pri void nmt_place_scenery(glm::dvec2 const &Point); void nmt_accept_offer(); // the answer without terrain: the tracks lie on the plane, nothing of the terrain model is loaded by itself any more, under the - // tracks laid nor around the camera + // tracks laid nor around the camera, in the scenery open; the settings stay as they are for the other sceneries void nmt_decline_offer(); + // the terrain of the download area made around the camera by itself: as the settings have it, unless declined for this scenery + bool nmt_area() const; // the whole scenery: tracks, includes and models, moved up or down as one undo step std::size_t nmt_join_ends(); // the turntables as they lie, each with the ends of the tracks running up to it on its rim @@ -3208,7 +3213,7 @@ class editor_mode : public application_mode, private editor_track::observer, pri std::string badge; // the mouse or the keys drawn over the view, for the clips of the tutorial glm::vec2 badge_at{0.0f}; // its bottom left corner, in the pixels of the window std::map marks; // the heights of the ends of tracks kept by mark, for expect lift - std::optional> terrain_kept; // the terrain made while laying and around the camera before nmtquestion + std::optional> terrain_kept; // the terrain made while laying, and the answer without it, before nmtquestion }; selftest m_selftest; using selftest_result = editor_selftest_result; diff --git a/application/editormodenmt.cpp b/application/editormodenmt.cpp index 56e450f3f..15a994301 100644 --- a/application/editormodenmt.cpp +++ b/application/editormodenmt.cpp @@ -1085,7 +1085,7 @@ void editor_mode::nmt_area_terrain() WriteLog(std::string{"Editor: NMT - the terrain of the download area "} + (*Reason != '\0' ? std::string{"held: "} + Reason : std::string{"goes on"}), logtype::generic); } }; - if (false == area.run_only.value_or(EditorSettings.terrain_model().area)) + if (false == area.run_only.value_or(nmt_area())) return held("turned off"); if (m_orthophoto.area().empty()) return held("no area"); @@ -1217,7 +1217,7 @@ void editor_mode::nmt_update() m_nmt_prefetched = wanted; // unless no terrain is made of the model by itself, as after the answer without terrain: what the terrain panel asks for then is // downloaded as it's asked for - if (state.grow || EditorSettings.terrain_model().area) + if (state.grow || nmt_area()) m_nmt.prefetch(wanted); // the terrain around the camera looked at again within the new area m_area_terrain.listed = false; @@ -2140,13 +2140,18 @@ void editor_mode::render_download_area_ui(editor_orthophoto::statistics const &S } } auto &model{EditorSettings.terrain_model()}; - if (ImGui::Checkbox(STR_C("The terrain of the scenery around the camera"), &model.area)) + // as it is for the scenery open: off after the answer Without terrain, and ticked, on again and kept so in the settings + if (bool area{nmt_area()}; ImGui::Checkbox(STR_C("The terrain of the scenery around the camera"), &area)) + { + m_nmt_state.declined = false; + model.area = area; EditorSettings.save(); + } if (ImGui::IsItemHovered()) ImGui::SetTooltip("%s", STR_C("Makes the terrain from the terrain model within the area, around the camera wherever it goes,\n" "a chunk at a time while the editor is idle. The terrain there is already isn't touched.\n" "The chunks made wait in memory until the scenery is saved (Ctrl+S).")); - if (model.area && m_area_terrain.made > 0) + if (nmt_area() && m_area_terrain.made > 0) { ImGui::SameLine(); ImGui::TextDisabled("%s", format(STR_P("%zu chunk made", "%zu chunks made", m_area_terrain.made), m_area_terrain.made).c_str()); @@ -2599,9 +2604,10 @@ void editor_mode::nmt_accept_offer() state.offset = 0.0; nmt_make(nmt_keys_around()); state.prompt = false; - // the terrain goes on under the tracks as they're laid and around the camera, as the answer says, also after the other answer was - // given for a scenery before; the model of the download area is put into the cache again if that answer stopped it + // the terrain goes on under the tracks as they're laid and around the camera, as the answer says, also where the settings had it + // off; the model of the download area is put into the cache again if it was stopped state.grow = true; + state.declined = false; EditorSettings.terrain_while_laying(true); EditorSettings.terrain_model().area = true; EditorSettings.save(); @@ -2615,16 +2621,20 @@ void editor_mode::nmt_decline_offer() state.prompt = false; // nothing of the model loaded any more: not under the tracks as they're laid, as the checkbox of the layers turns it off, nor around // the camera within the download area, as the checkbox of the terrain panel does, nor the squares of the download area into the - // cache. Kept on, they went on being loaded, and where there's no network their requests failed in the log + // cache. Kept on, they went on being loaded, and where there's no network their requests failed in the log. For this scenery only: + // the settings stay as they were, for the sceneries opened later state.grow = false; - EditorSettings.terrain_while_laying(false); - EditorSettings.terrain_model().area = false; - EditorSettings.save(); + state.declined = true; m_nmt.prefetch({}); // nor the squares asked for meanwhile, as the aerial photos asked for them to lie on m_nmt.cancel(); } +bool editor_mode::nmt_area() const +{ + return false == m_nmt_state.declined && EditorSettings.terrain_model().area; +} + void editor_mode::render_nmt_prompt() { auto &state{m_nmt_state}; diff --git a/application/editormodeselftest.cpp b/application/editormodeselftest.cpp index c733f8980..0bcd3a572 100644 --- a/application/editormodeselftest.cpp +++ b/application/editormodeselftest.cpp @@ -194,7 +194,7 @@ editor_mode::selftest_result editor_mode::selftest_dispatch(std::string const &c // to it out along their lines from the rim, against the model there // nmtstate logs how far the tracks going onto the terrain model are // nmtquestion the question of the terrain of a new scenery opened, or answered without terrain as its card does; -// restore: the settings of the terrain made by itself put back as they were before that answer +// restore: the terrain made by itself as it was before that answer, which leaves the settings be // gradelines the grade line each track shares written to the file, for a map of them // fitreport to the file: the tracks off the terrain model, the switches off their plane, the rails on common timbers apart in height // gradeline the common grade line of the route open in the profile tool: its design lifted and applied, the route taken off it and back diff --git a/application/editormodeselftestexpect.cpp b/application/editormodeselftestexpect.cpp index 7f1b87c1a..4f16a1b2f 100644 --- a/application/editormodeselftestexpect.cpp +++ b/application/editormodeselftestexpect.cpp @@ -516,7 +516,7 @@ editor_mode::selftest_result editor_mode::selftest_expect(std::string const &com expect_steps(what, words, static_cast(std::ranges::count_if(m_history, [](EditorSnapshot const &Step) { return false == Step.joined; }))); else if (false == expect_shown(kind, what, words, {m_switch.status, ui()->refusal_shown(), ui()->status_line(), m_lay.mouse, - {{"grow", m_nmt_state.grow}, {"area", EditorSettings.terrain_model().area}, {"prompt", m_nmt_state.prompt}}})) + {{"grow", m_nmt_state.grow}, {"area", nmt_area()}, {"prompt", m_nmt_state.prompt}}})) expectation(false, what, "no expectation " + kind, "cant, joint, records, shaped, speed, gauge, track, route, norms, findings, height, lift, includes, status, statuslacks, refusal, statusline, laycursor, terrain or steps"); return selftest_result::handled; diff --git a/application/editormodeselftestterrain.cpp b/application/editormodeselftestterrain.cpp index cdacd84e8..ed796d446 100644 --- a/application/editormodeselftestterrain.cpp +++ b/application/editormodeselftestterrain.cpp @@ -513,26 +513,31 @@ editor_mode::selftest_result editor_mode::selftest_terrain(std::string const &co if (command == "nmtquestion") { // the question of the terrain of a new scenery: open, as the first L in an empty scenery opens it, or answered without - // terrain, as its card does it; restore: the settings of the terrain made by itself as they were before the answer, which - // keeps them with the editor + // terrain, as its card does it; restore: the terrain made by itself as it was before the answer. The answer keeps to the + // scenery open, so the settings of the tester aren't written std::string answer; words >> answer; - auto &model{EditorSettings.terrain_model()}; + auto const &model{EditorSettings.terrain_model()}; if (answer == "open") m_nmt_state.prompt = true; else if (answer == "flat") { - m_selftest.terrain_kept = std::pair{m_nmt_state.grow, model.area}; + auto const kept{std::pair{EditorSettings.terrain_while_laying(), model.area}}; + m_selftest.terrain_kept = std::pair{m_nmt_state.grow, m_nmt_state.declined}; nmt_decline_offer(); + // the settings as they were: the answer is for this scenery alone + if (std::pair{EditorSettings.terrain_while_laying(), model.area} != kept) + { + editor_selftest::fail(); + WriteLog("SELFTEST FAIL nmtquestion flat: the settings of the terrain changed"); + } } else if (answer == "restore" && m_selftest.terrain_kept.has_value()) { m_nmt_state.grow = m_selftest.terrain_kept->first; - model.area = m_selftest.terrain_kept->second; - EditorSettings.terrain_while_laying(m_nmt_state.grow); - EditorSettings.save(); + m_nmt_state.declined = m_selftest.terrain_kept->second; } - WriteLog(format("SELFTEST nmtquestion %s: prompt %d, terrain while laying %d, around the camera %d", answer.c_str(), m_nmt_state.prompt ? 1 : 0, m_nmt_state.grow ? 1 : 0, model.area ? 1 : 0)); + WriteLog(format("SELFTEST nmtquestion %s: prompt %d, terrain while laying %d, around the camera %d", answer.c_str(), m_nmt_state.prompt ? 1 : 0, m_nmt_state.grow ? 1 : 0, nmt_area() ? 1 : 0)); return selftest_result::handled; } if (command == "nmtgrow") diff --git a/tests/editor/cases/fs_3_without_terrain.txt b/tests/editor/cases/fs_3_without_terrain.txt index a56bc93a4..b2b7c70d7 100644 --- a/tests/editor/cases/fs_3_without_terrain.txt +++ b/tests/editor/cases/fs_3_without_terrain.txt @@ -1,7 +1,8 @@ # First steps: the answer Without terrain to the question of the terrain of a new empty scenery turns off the terrain made of the # terrain model by itself: under the tracks as they're laid (the checkbox of the layers) and around the camera within the download -# area (the checkbox of the terrain panel), so nothing of the model is asked for. The question asked as the first L in an empty -# scenery asks it (the fixture has tracks, so it isn't asked by itself) +# area (the checkbox of the terrain panel), so nothing of the model is asked for. For this scenery only: the settings, kept for the +# sceneries opened later, stay as they were (nmtquestion flat fails the run if they changed). The question asked as the first L +# in an empty scenery asks it (the fixture has tracks, so it isn't asked by itself) wait 5 nmtsettings grow 1 wait 2