From c383583afbb696717a5b9e741b1e51f39d7ea378 Mon Sep 17 00:00:00 2001 From: maj00r <73280030+maj00r@users.noreply.github.com> Date: Sun, 29 Nov 2026 23:01:16 +0100 Subject: [PATCH] fix(editor): the hand of a turnout commented as the code has it, an Apply with no edit adds no step, a profile opened drops the error of the one before, tests of the side - The comments of layoutCommands.hpp and layoutNetwork.hpp give hand 1 as right and -1 as left, as the migration and the inspector have it since #464 (R of a switch record). - The grade line of a line of the model applied with no edit: the breaks compared within a micrometre, the chainages having gone to the route and back; compared exactly, it added a step. - profile_open() clears the error of the route opened before. - Self-test expectations: modelpreview current (the preview worked out for the design as it is now, m_11), modelspacing signed by the side (m_13 to the right, -4.5 m), modelside of a switch (m_8 right, then left after the side is changed). --- application/editormode.h | 1 + application/editormodemodel.cpp | 43 ++++++++++++++++++++++--- application/editormodemodeledit.cpp | 20 +++++++++--- application/editormodeprofile.cpp | 2 ++ editor/layout/layoutCommands.hpp | 2 +- editor/layout/layoutNetwork.hpp | 2 +- tests/editor/README.md | 5 +-- tests/editor/cases/m_11_vertex_drag.txt | 1 + tests/editor/cases/m_13_parallel.txt | 6 ++-- tests/editor/cases/m_8_turnout.txt | 2 ++ 10 files changed, 68 insertions(+), 16 deletions(-) diff --git a/application/editormode.h b/application/editormode.h index 3c830d0b9..834c41889 100644 --- a/application/editormode.h +++ b/application/editormode.h @@ -3493,6 +3493,7 @@ class editor_mode : public application_mode, private editor_track::observer, pri bool model_plan_commands(layout::line_id const Line, std::vector &Commands, std::string &Why) const; // a handle of the route design dragged on a line of the model: tried as it goes, drawn by the line and the mouse void model_plan_preview(); + std::string model_plan_key() const; // the design of the route as the preview of the model was worked out for it void draw_model_plan_preview() const; bool m_model_delete_confirmed{false}; // the old delete let through, the scenarios looked through selftest_result selftest_dispatch(std::string const &command, std::istringstream &words); diff --git a/application/editormodemodel.cpp b/application/editormodemodel.cpp index 8cc24180f..21d7447c9 100644 --- a/application/editormodemodel.cpp +++ b/application/editormodemodel.cpp @@ -1773,18 +1773,48 @@ editor_mode::selftest_result editor_mode::selftest_model(std::string const &comm } if (what == "modelspacing") { - // how far the other line runs from the point of the line at the chainage, within the bounds - unsigned line{0}, other{0}; - double chainage{0.0}, low{0.0}, high{0.0}; + // how far the other line runs from the point of the line at the chainage, within the bounds: above 0 to the left of the line as it + // runs (left_of, as the offset of the parallel tool), below 0 to its right, so a line laid on the other side fails it + unsigned line{0}; + unsigned other{0}; + double chainage{0.0}; + double low{0.0}; + double high{0.0}; words >> line >> other >> chainage >> low >> high; auto const *one{model_network().find(static_cast(line))}; auto const *two{model_network().find(static_cast(other))}; auto got{std::numeric_limits::quiet_NaN()}; if (one != nullptr && two != nullptr && one->solved.valid() && two->solved.valid()) - layout::chainage_of(two->solved, one->solved.position(std::clamp(chainage, 0.0, one->solved.length)), &got); + { + auto const at{std::clamp(chainage, 0.0, one->solved.length)}; + auto const point{one->solved.position(at)}; + auto const across{two->solved.position(layout::chainage_of(two->solved, point, &got))}; + if (glm::dot(across - point, layout::left_of(glm::normalize(one->solved.tangent(at)))) < 0.0) + got = -got; + } expectation(got >= low && got <= high, format("modelspacing %u %u %.1f", line, other, chainage), format("%.4f", got), format("%.4f .. %.4f", low, high)); return selftest_result::handled; } + if (what == "modelside") + { + // the side the diverging track of the switch leaves its main track to, as the switch runs from its start: right where the + // cross product of the two in the plan is above 0, as a switch record has R (switch_store::classify), left below it + std::string name; + std::string wanted; + words >> name >> wanted; + auto const *track{simulation::Paths.find(name)}; + std::string got{"none"}; + if (track != nullptr && false == track->m_editorremoved && track->eType == tt_Switch && track->m_paths.size() >= 2) + { + auto const &main{track->m_paths[0].points}; + auto const &diverging{track->m_paths[1].points}; + auto const along{glm::dvec2{main[segment_data::point::end].x - main[segment_data::point::start].x, main[segment_data::point::end].z - main[segment_data::point::start].z}}; + auto const off{glm::dvec2{diverging[segment_data::point::end].x - main[segment_data::point::start].x, diverging[segment_data::point::end].z - main[segment_data::point::start].z}}; + got = along.x * off.y - along.y * off.x > 0.0 ? "right" : "left"; + } + expectation(got == wanted, "modelside " + name, got, wanted); + return selftest_result::handled; + } if (what == "modelnodes") { // the nodes of the model: a line laid on from the free end of another one shares the node there @@ -1841,7 +1871,10 @@ editor_mode::selftest_result editor_mode::selftest_model(std::string const &comm std::string wanted; words >> wanted; auto const &preview{model().preview}; - auto const got{preview.key.empty() ? std::string{"none"} : std::string{"shown"}}; + auto got{preview.key.empty() ? std::string{"none"} : std::string{"shown"}}; + // current: worked out for the design as it is now, not left as the first frame of the drag showed it + if (wanted == "current" && false == preview.key.empty()) + got = preview.key == model_plan_key() ? "current" : "stale"; expectation(got == wanted, "modelpreview " + wanted, got + (preview.key.empty() ? "" : (preview.refused ? " refused: " : ": ") + editor_selftest::one_line(preview.text)), wanted); return selftest_result::handled; } diff --git a/application/editormodemodeledit.cpp b/application/editormodemodeledit.cpp index 8f737c513..4de8bb8a6 100644 --- a/application/editormodemodeledit.cpp +++ b/application/editormodemodeledit.cpp @@ -145,7 +145,13 @@ bool editor_mode::model_profile_apply() state.error = model_shown(); return true; } - if (command.grades == line->shape.grades) + // the same breaks, within what taking the chainages to the route and back changes of them: compared exactly, an Apply with no edit + // added a step + auto const unchanged{std::ranges::equal(command.grades, line->shape.grades, [](auto const &A, auto const &B) { + double constexpr kNear{1e-6}; + return std::abs(A.chainage - B.chainage) < kNear && std::abs(A.elevation - B.elevation) < kNear && std::abs(A.vertical_radius - B.vertical_radius) < kNear * std::max(1.0, B.vertical_radius); + })}; + if (unchanged) { state.status = STR_C("Nothing changed"); return true; @@ -252,6 +258,14 @@ void editor_mode::model_plan_reload(layout::line_id const Line) // a handle of the route design dragged on a line of the model: the line as the model lays it and the norms' line, before it's let go +std::string editor_mode::model_plan_key() const +{ + std::string key; + for (auto const &vertex : m_route.design.vertices) + key += format("%.4f %.4f %.4f %.3f %.3f %.3f %.1f;", vertex.position.x, vertex.position.y, vertex.offset, vertex.radius, vertex.transition_in, vertex.transition_out, vertex.cant); + return key; +} + void editor_mode::model_plan_preview() { auto &preview{model().preview}; @@ -263,9 +277,7 @@ void editor_mode::model_plan_preview() } // the first and the last vertex of two or more are dragged along the tangents of the ends by their offsets, which their positions // don't follow (model_plan_commands places them so): without the offset the preview stayed as its first frame showed it - std::string key; - for (auto const &vertex : m_route.design.vertices) - key += format("%.4f %.4f %.4f %.3f %.3f %.3f %.1f;", vertex.position.x, vertex.position.y, vertex.offset, vertex.radius, vertex.transition_in, vertex.transition_out, vertex.cant); + auto const key{model_plan_key()}; if (key == preview.key) return; preview = {}; diff --git a/application/editormodeprofile.cpp b/application/editormodeprofile.cpp index dbad028dd..d1a9e5d02 100644 --- a/application/editormodeprofile.cpp +++ b/application/editormodeprofile.cpp @@ -776,6 +776,8 @@ void editor_mode::profile_open(TTrack *From, TTrack *To) auto &state{m_profile}; state.open = true; state.status.clear(); + // what was wrong with the route opened before isn't of this one + state.error.clear(); editor_track::route route; if (false == editor_track::find_route(From, To, route, state.error)) return; diff --git a/editor/layout/layoutCommands.hpp b/editor/layout/layoutCommands.hpp index 0355d84dc..6a300e66d 100644 --- a/editor/layout/layoutCommands.hpp +++ b/editor/layout/layoutCommands.hpp @@ -127,7 +127,7 @@ struct set_line_profile }; // a turnout of the type of the catalogue laid into the line, its start at the chainage: the line cut at its legs, the part between them its -// main track, its diverging track leaving it to the hand (1 left, -1 right) as it runs from its start, along the line (direction 1) or +// main track, its diverging track leaving it to the hand (1 right, -1 left) as it runs from its start, along the line (direction 1) or // against it (-1); bent as the line under it is. Refused with the reasons where a rule of the turnouts or a BLOCK limit of the norms is broken struct insert_turnout { diff --git a/editor/layout/layoutNetwork.hpp b/editor/layout/layoutNetwork.hpp index d7b315646..fd547a591 100644 --- a/editor/layout/layoutNetwork.hpp +++ b/editor/layout/layoutNetwork.hpp @@ -113,7 +113,7 @@ struct turnout { turnout_id id{turnout_id::none}; std::string type; // of the catalogue, "Rz 60E1-500-1:12" - int hand{1}; // the side the diverging track leaves to as the turnout runs from its start: 1 left, -1 right + int hand{1}; // the side the diverging track leaves to as the turnout runs from its start: 1 right, -1 left (the R of a switch record) int direction{1}; // 1: its main track runs as the line it was laid into does, from the start of the turnout; -1 against it node_id start{node_id::none}; node_id main_end{node_id::none}; diff --git a/tests/editor/README.md b/tests/editor/README.md index 21e8ebb07..0bd20e9db 100644 --- a/tests/editor/README.md +++ b/tests/editor/README.md @@ -119,8 +119,9 @@ tool's `parallel ` lay turnouts, crossovers and lines of the mod | `expect modelproposal ` | the solver's best proposal for the crossover refused last | | `expect modelgrades `, `expect modelvertices ` | the breaks of the grade line / the vertices of a line of the model | | `expect modelvertexat ` | where the vertex of a line of the model is in the plan | -| `expect modelpreview ` | a handle of the route design dragged on a line of the model: the line as the model would lay it is tried and told | -| `expect modelspacing ` | how far the other line runs from the point of the line at the chainage | +| `expect modelpreview ` | a handle of the route design dragged on a line of the model: the line as the model would lay it is tried and told; current: tried for the design as it is now | +| `expect modelspacing ` | how far the other line runs from the point of the line at the chainage: above 0 to its left as it runs, below 0 to its right | +| `expect modelside ` | the side the diverging track of the switch leaves to as the switch runs from its start | Files `scenery/autotest_editor..scn` are copied next to the copy of the fixture as `autotest_editor__.scn`, the name of the fixture in them made the name of its copy: scenarios of its map, for the scenario index (`autotest_editor.uses.scn`, a trainset on `s1`). diff --git a/tests/editor/cases/m_11_vertex_drag.txt b/tests/editor/cases/m_11_vertex_drag.txt index 1b767c365..f967ba9f4 100644 --- a/tests/editor/cases/m_11_vertex_drag.txt +++ b/tests/editor/cases/m_11_vertex_drag.txt @@ -20,6 +20,7 @@ wait 2 glide 800 0 180 8 2 wait 2 expect modelpreview shown +expect modelpreview current button left release wait 5 expect modelrefused 0 diff --git a/tests/editor/cases/m_13_parallel.txt b/tests/editor/cases/m_13_parallel.txt index d41f9f515..0932cdf39 100644 --- a/tests/editor/cases/m_13_parallel.txt +++ b/tests/editor/cases/m_13_parallel.txt @@ -17,9 +17,9 @@ expect modellines 2 expect managed @2.0 2 expect modelends expect steps 2 -# 4.5 m on the straight and in the arc, concentric (no widening of the gauge in a curve of R 250 m or more) -expect modelspacing 1 2 10 4.4999 4.5001 -expect modelspacing 1 2 400 4.498 4.502 +# 4.5 m to its right on the straight and in the arc, concentric (no widening of the gauge in a curve of R 250 m or more) +expect modelspacing 1 2 10 -4.5001 -4.4999 +expect modelspacing 1 2 400 -4.502 -4.498 undo wait 2 expect modellines 1 diff --git a/tests/editor/cases/m_8_turnout.txt b/tests/editor/cases/m_8_turnout.txt index 377f440dc..d64f6d83a 100644 --- a/tests/editor/cases/m_8_turnout.txt +++ b/tests/editor/cases/m_8_turnout.txt @@ -18,6 +18,7 @@ expect steps 2 expect managed t1 any expect switchpanel placed expect modelends +expect modelside t1 right undo wait 2 expect modellines 1 @@ -45,6 +46,7 @@ wait 2 expect modelrefused 0 expect steps 5 expect modelends +expect modelside t1 left modeltracks # taken out by Del, once the scenarios of the map are looked through (none names it): the line one line again modeldel t1