From 46d41549c9531664b850ab157a9245b61122d1f9 Mon Sep 17 00:00:00 2001 From: maj00r Date: Mon, 12 Oct 2026 18:11:17 +0200 Subject: [PATCH] feat(editor): the profile takes the switch zones from the //$r records: the parts of a double slip and the paths of a crossing make one zone from its first part to its last, a crossing made of plain paths is a zone too, the zone is named by the number and the type of the switch; a switch with no record stays a zone named by its path; self-test vprofile logs the zones --- application/editormodeprofile.cpp | 20 +++++++++++++++++++- application/editormodeselftest.cpp | 2 ++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/application/editormodeprofile.cpp b/application/editormodeprofile.cpp index 1a2d1a0b..5f5c3496 100644 --- a/application/editormodeprofile.cpp +++ b/application/editormodeprofile.cpp @@ -13,6 +13,7 @@ http://mozilla.org/MPL/2.0/. #include "editor/editorFormat.hpp" #include "editor/editorAlignmentStore.hpp" #include "editor/editorGeometry.hpp" +#include "editor/editorSwitchStore.hpp" #include "world/Track.h" #include "scene/scenelayers.h" @@ -430,9 +431,26 @@ void editor_mode::profile_resample() context.length = state.route.length; if (samples.empty()) return; + std::optional open; for (auto const &span : state.route.spans) - if (span.track->eType != tt_Normal) + { + if (auto const found{switch_store::named(*span.track)}) + { + if (open.has_value() && open->name == found->name && span.from - context.switches.back().to <= std::max(found->a + found->b, context.switches.back().to - context.switches.back().from)) + { + context.switches.back().to = span.to; + continue; + } + auto const label{switch_store::label(*found)}; + context.switches.push_back({span.from, span.to, found->number != "-" ? found->number + ' ' + label : label}); + open = found; + } + else if (span.track->eType != tt_Normal) + { context.switches.push_back({span.from, span.to, span.track->name()}); + open.reset(); + } + } context.start_elevation = samples.front().position.y; context.end_elevation = samples.back().position.y; context.start_joined = editor_track::adjoining_grade(state.route, false, context.start_grade); diff --git a/application/editormodeselftest.cpp b/application/editormodeselftest.cpp index 1d07b753..c3f51105 100644 --- a/application/editormodeselftest.cpp +++ b/application/editormodeselftest.cpp @@ -1090,6 +1090,8 @@ editor_mode::selftest_result editor_mode::selftest_track(std::string const &comm m_profile.origin = 0.0; profile_open(first, last); WriteLog(format("SELFTEST vprofile: %zu spans, %.3f m, km of the start %.3f", m_profile.route.spans.size(), m_profile.route.length, m_profile.origin / 1000.0)); + for (auto const &zone : m_profile.context.switches) + WriteLog(format("SELFTEST vprofile zone %.3f %.3f %s", zone.from, zone.to, zone.name.c_str())); return selftest_result::handled; } if (command == "backwardcurve")