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")