18
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-12-02 14:16:48 +01:00

feat(editor): the norms checked on the tracks laid, read only: a Norms tab of the track analysis and its report

The second half of E1: what the tracks of a scenery are against a profile of the norms, listed. Nothing of the tracks is changed.

- editor/editorNormsReport: a line of paths sampled a metre apart, two samples at each joint, into what the norms read a line
  from: the plan, the curvature signed by the turn, the cant on the base of 1500 mm (as the simulator takes the rolls) signed by
  the side it leans to as the line runs, the grade, the speed of each path (a switch's for its diverging track alone too), and
  what the path is a part of (a switch, its diverging track, a curved switch, a movable frog, a crossing). The line described,
  checked, and each finding set back on its path with a point of it; its message, "cant ramp 3.00 mm/m, PLK allows at most 2.50 mm/m
  (tab. 9.12)", "break of the grade with no vertical curve, PLK asks for a radius of at least 2500 m (tab. 10.2)", through STR_C;
  the text of the report: the class, the elements, the cant, the grade line and the findings of each line.
- The Norms tab of the track window, under More beside Speed and Joints, no key; its window is ###trackanalysis, as theirs. The
  line through the selected path (run_route, as the speed check walks it) or the whole scenery: the lines through the plain tracks,
  then each path of a switch none of them ran along, checked with the line it lies in and its own findings kept, a place two lines
  run through listed once. The profile (PLK by default) and the class of the line folded under a line saying it: the line speed for
  the tracks with none of their own (on by default: the speed of each track), the slow trains (tab. 8.1 by default), the traffic,
  main track or siding, the load, at a platform. The results in the table of the speed check and the joints, the worst first,
  coloured by the tier, the values above the recommended ones on a tick; a click on a row shows the place, the hard limits and the
  warnings are marked in the view. The icon is drawn into its own cell of editor_icons.png only (the generator has it): the sheet
  drawn again with this Pillow differs in other cells.
- Self-test: normsreport <file> [scope] [plk|tsi|en|ch] [km/h] writes the report to the file; expect findings <tier> <least> <most>;
  the case e1_norms_report checks the curves k0..k3 of the fixture at 60 km/h against PLK and the whole scenery against the TSI.
- Golden: data/norms/line.scn, a line of 14 tracks written by make_line.py there (curves with and without transitions, cant on and
  off a curve and along a straight, reverse curves 10 m apart, short straights, a grade with breaks), and its report against the
  four profiles in data/norms/line_report.txt; EU07_UNIT_TESTS_UPDATE_GOLDEN=1 writes it anew. A test lays a canted corner with the
  alignment of the editor and finds the samples leaning into it, both turns and run both ways, I = Deq - D.

alignment::limits stays as the laying tools use it. Where its values differ from PLK P0:
- unbalanced 0.6 m/s2 is I 92 mm on the 1500 mm base; P0 110 mm (P1 130) on the running lines, 80 on the sidings;
- ramp_factor 10, a ramp of 1:(10 V), 1 mm/m at 100 km/h and 2.5 mm/m at 40 km/h, has no counterpart: P0 1.6 mm/m at any speed;
- jerk 0.3 m/s3 is dI/dt 46 mm/s; P0 55 mm/s;
- vertical_factor 0.4 V^2 and vertical_min 2000 m; P0 max(0.77 V^2, 5000 m) (P1 max(0.35 V^2, 5000), P2 max(0.25 V^2, 2000));
- arc_min 20 m and arc_min_factor 0.4 V; P0 max(0.35 V, 30 m) up to 120 km/h, 0.40 V up to 200 km/h, also for the straights, where
  tangent_min_time is 0;
- the same: cant_max 150 mm (P0 = P1 = P2 on ballast), cant_rate 35 mm/s (P0 of tab. 9.13), the base of 1500 mm.
This commit is contained in:
maj00r
2026-11-23 10:28:27 +01:00
parent db5a171ccd
commit 38f90387c4
21 changed files with 1424 additions and 12 deletions
+2
View File
@@ -216,6 +216,7 @@ set(SOURCES
"editor/norms/normsLimits.cpp"
"editor/norms/normsEngine.cpp"
"editor/norms/normsLine.cpp"
"editor/editorNormsReport.cpp"
"editor/editorProfile.cpp"
"editor/editorGauge.cpp"
"editor/editorInfra.cpp"
@@ -253,6 +254,7 @@ set(SOURCES
"application/editormodeminimap.cpp"
"application/editormodeinfra.cpp"
"application/editormodespeed.cpp"
"application/editormodenorms.cpp"
"application/editormodesrk.cpp"
"application/editormodekm.cpp"
"application/editormodejoints.cpp"
+3
View File
@@ -1676,6 +1676,8 @@ bool editor_mode::update()
steps.step("speed");
m_joints.update();
steps.step("joints");
m_norms.update();
steps.step("norms");
if (m_nmt_state.grade_lines_dirty)
{
m_nmt_state.grade_lines_dirty = false;
@@ -1693,6 +1695,7 @@ bool editor_mode::update()
draw_infra_overlay();
m_speed.draw_overlay();
m_joints.draw_overlay();
m_norms.draw_overlay();
m_srk.draw_overlay();
m_km.draw_overlay();
steps.step("overlays");
+5 -3
View File
@@ -21,6 +21,7 @@ http://mozilla.org/MPL/2.0/.
#include "application/editormodelineside.h"
#include "application/editormodeparallel.h"
#include "application/editormodespeed.h"
#include "application/editormodenorms.h"
#include "application/editormodesrk.h"
#include "application/editormodekm.h"
#include "application/editormodevehicle.h"
@@ -2235,7 +2236,7 @@ class editor_mode : public application_mode, private editor_track::observer, pri
editor_icons::icon picture;
int family; // 0 builds the track, 1 equips it, 2 checks it
};
static std::array<track_mode, 15> const &track_modes();
static std::array<track_mode, 16> const &track_modes();
bool track_plan_tab() const { return m_track_tab == track_tab::straights || m_track_tab == track_tab::route; }
// a tool of the station: they share its schematic
bool srk_tab() const { return m_track_tab == track_tab::station || m_track_tab == track_tab::station_signals || m_track_tab == track_tab::line_block; }
@@ -2293,7 +2294,7 @@ class editor_mode : public application_mode, private editor_track::observer, pri
void render_track_tool_options();
void render_track_selection();
void show_track_tab(track_tab const Wanted) override;
bool track_analysis_tab() const { return m_track_tab == track_tab::profile || m_track_tab == track_tab::speed || m_track_tab == track_tab::joints || m_track_tab == track_tab::infra; }
bool track_analysis_tab() const { return m_track_tab == track_tab::profile || m_track_tab == track_tab::speed || m_track_tab == track_tab::joints || m_track_tab == track_tab::norms || m_track_tab == track_tab::infra; }
bool track_shortcut(int const Key);
bool track_busy() const; // something going on in the mode, which Esc drops before it leaves the mode
std::string track_mode_name() const;
@@ -3456,6 +3457,7 @@ class editor_mode : public application_mode, private editor_track::observer, pri
gauge_tool m_gauge{*this, *this, *this, *this};
speed_tool m_speed{*this, *this, *this, *this};
joints_tool m_joints{*this, *this, *this, *this};
norms_tool m_norms{*this, *this, *this};
vehicle_tool m_vehicle{*this, *this};
hekto_tool m_hekto{*this, *this, *this, *this, *this, *this};
fouling_tool m_fouling{*this, *this, *this, *this, *this};
@@ -3464,7 +3466,7 @@ class editor_mode : public application_mode, private editor_track::observer, pri
km_tool m_km{*this, *this, *this, *this};
track_ride m_ride;
minimap_tool m_minimap{*this, *this, m_ride};
std::vector<editor_tool *> m_tools{&m_gauge, &m_speed, &m_joints, &m_vehicle, &m_hekto, &m_fouling, &m_parallel, &m_srk, &m_km, &m_ride, &m_minimap};
std::vector<editor_tool *> m_tools{&m_gauge, &m_speed, &m_joints, &m_norms, &m_vehicle, &m_hekto, &m_fouling, &m_parallel, &m_srk, &m_km, &m_ride, &m_minimap};
void infra_rebase();
void render_infra_search();
+420
View File
@@ -0,0 +1,420 @@
/*
This Source Code Form is subject to the
terms of the Mozilla Public License, v.
2.0. If a copy of the MPL was not
distributed with this file, You can
obtain one at
http://mozilla.org/MPL/2.0/.
*/
#include "stdafx.h"
#include "application/editormodenorms.h"
#include "application/editorprojection.h"
#include "application/editormodeshared.h"
#include "editor/editorFormat.hpp"
#include "simulation/simulation.h"
#include "utilities/Globals.h"
#include "utilities/Logs.h"
#include "world/Track.h"
#include "imgui/imgui.h"
#include "utilities/translation.h"
#include <algorithm>
#include <array>
#include <chrono>
#include <cmath>
#include <fstream>
#include <set>
#include <unordered_set>
#include <utility>
namespace
{
double constexpr kLineReach{5000.0}; // m each way, for the line through the selected path
double constexpr kSceneryReach{20000.0}; // m each way, for the lines of the scenery
double constexpr kBranchReach{300.0}; // m each way around the diverging track of a switch
double constexpr kOverlayRange{3000.0};
bool rail(TTrack const &Track)
{
return (Track.iCategoryFlag & 15) == 1 && false == Track.m_editorremoved && Track.m_road == nullptr && editor_track::is_supported(Track);
}
std::vector<norms_report::span> spans_of(editor_track::route const &Route)
{
std::vector<norms_report::span> result;
result.reserve(Route.spans.size());
for (auto const &span : Route.spans)
result.push_back({span.track, span.path, span.forward});
return result;
}
int rank(norms::tier const Tier)
{
switch (Tier)
{
case norms::tier::block: return 0;
case norms::tier::warn: return 1;
default: return 2;
}
}
ImVec4 tier_colour(norms::tier const Tier)
{
switch (Tier)
{
case norms::tier::block: return {1.0f, 0.45f, 0.4f, 1.0f};
case norms::tier::warn: return {1.0f, 0.75f, 0.3f, 1.0f};
default: return ImGui::GetStyleColorVec4(ImGuiCol_TextDisabled);
}
}
std::string source_text(norms::finding const &Finding)
{
if (Finding.from.document.empty())
return "-";
return std::string{Finding.from.document} + " " + std::string{Finding.from.place};
}
std::array<char const *, 4> constexpr kProfileKeys{"plk", "tsi", "en", "ch"};
} // namespace
void norms_tool::start()
{
auto &state{m_state};
state.queue.clear();
state.next = 0;
state.lines.clear();
state.results.clear();
state.selected = -1;
state.status.clear();
state.options.profile = static_cast<norms::profile_id>(std::clamp(state.profile, 0, static_cast<int>(norms::profile_id::count) - 1));
if (state.scope == 0)
{
auto *track{m_selection.selected_track()};
if (track == nullptr || false == rail(*track))
{
state.status = STR_C("Select a track first");
return;
}
state.queue.push_back({spans_of(editor_track::run_route(*track, kLineReach)), -1});
}
else
{
// the lines through the plain tracks, then each path of a switch none of them ran along, with the line it lies in
std::unordered_set<TTrack const *> covered;
std::set<std::pair<TTrack const *, int>> switch_paths;
for (auto *track : simulation::Paths.sequence())
{
if (track == nullptr || false == rail(*track) || track->eType != tt_Normal || covered.contains(track))
continue;
auto const route{editor_track::run_route(*track, kSceneryReach)};
for (auto const &span : route.spans)
{
if (span.track->eType == tt_Normal)
covered.insert(span.track);
else
switch_paths.emplace(span.track, span.path);
}
state.queue.push_back({spans_of(route), -1});
}
for (auto *track : simulation::Paths.sequence())
{
if (track == nullptr || false == rail(*track) || track->eType != tt_Switch)
continue;
for (int path = 0; path < static_cast<int>(track->m_paths.size()); ++path)
{
if (switch_paths.contains({track, path}))
continue;
auto const route{editor_track::run_route(*track, kBranchReach, path)};
auto const own{std::ranges::find_if(route.spans, [track, path](editor_track::route_span const &Span) { return Span.track == track && Span.path == path; })};
if (own == route.spans.end())
continue;
state.queue.push_back({spans_of(route), static_cast<int>(std::distance(route.spans.begin(), own))});
}
}
}
state.history = m_history.history_revision();
}
void norms_tool::update()
{
auto &state{m_state};
if (state.queue.empty())
return;
auto const deadline{std::chrono::steady_clock::now() + std::chrono::milliseconds(15)};
while (state.next < state.queue.size() && std::chrono::steady_clock::now() < deadline)
{
auto const &line{state.queue[state.next++]};
auto checked{norms_report::check(line.spans, state.options, nullptr, line.own)};
for (auto const &entry : checked.entries)
{
// a place two lines run through is listed once
if (std::ranges::none_of(state.results, [&entry](norms_report::entry const &Other) {
return Other.track == entry.track && Other.path == entry.path && Other.finding.what == entry.finding.what && Other.finding.level == entry.finding.level &&
std::abs(Other.finding.value - entry.finding.value) < 1e-6;
}))
state.results.push_back(entry);
}
state.lines.push_back(std::move(checked));
}
if (state.next >= state.queue.size())
finish();
}
void norms_tool::finish()
{
auto &state{m_state};
// the worst first: the hard limits, the warnings, the values above the recommended ones
std::ranges::stable_sort(state.results, [](norms_report::entry const &A, norms_report::entry const &B) { return rank(A.finding.level) < rank(B.finding.level); });
auto const count = [&state](norms::tier const Tier) { return std::ranges::count_if(state.results, [Tier](norms_report::entry const &Entry) { return Entry.finding.level == Tier; }); };
state.status = format(STR_P("%zu line checked against %s: %d beyond the hard limits, %d warnings, %d above the recommended values",
"%zu lines checked against %s: %d beyond the hard limits, %d warnings, %d above the recommended values", static_cast<long long>(state.lines.size())),
state.lines.size(),
std::string{norms::profile_of(state.options.profile).name}.c_str(), static_cast<int>(count(norms::tier::block)), static_cast<int>(count(norms::tier::warn)),
static_cast<int>(count(norms::tier::prefer)));
state.queue.clear();
state.next = 0;
WriteLog("Editor: norms - " + state.status, logtype::generic);
}
std::vector<int> norms_tool::listed() const
{
std::vector<int> result;
for (int i = 0; i < static_cast<int>(m_state.results.size()); ++i)
if (m_state.notes || m_state.results[i].finding.level != norms::tier::prefer)
result.push_back(i);
return result;
}
void norms_tool::focus(int const Index)
{
auto &state{m_state};
if (Index < 0 || Index >= static_cast<int>(state.results.size()))
return;
state.selected = Index;
auto const &entry{state.results[Index]};
auto const &paths{simulation::Paths.sequence()};
if (entry.track == nullptr || std::ranges::find(paths, entry.track) == paths.end() || entry.track->m_editorremoved)
return;
m_selection.set_current_node(entry.track);
m_view.focus_track(*entry.track, entry.path, entry.position);
}
void norms_tool::forget(scene::basic_node const *Node)
{
auto &state{m_state};
auto const removed{std::erase_if(state.results, [Node](norms_report::entry const &Entry) { return Entry.track == Node; })};
if (removed > 0)
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; });
}
void norms_tool::render_class()
{
auto &options{m_state.options};
auto &line{options.line};
if (begin_fields_fitted("##normsprofile", 0.55f, {"Profile"}))
{
field_row("Profile");
auto const current{std::string{norms::profile_of(static_cast<norms::profile_id>(m_state.profile)).name}};
if (ImGui::BeginCombo("##normsprofile", current.c_str()))
{
for (int i = 0; i < static_cast<int>(norms::profile_id::count); ++i)
if (ImGui::Selectable(std::string{norms::profile_of(static_cast<norms::profile_id>(i)).name}.c_str(), i == m_state.profile))
m_state.profile = i;
ImGui::EndCombo();
}
item_tooltip("PLK: P0 recommended, beyond P1 a warning, beyond P2 the hard limit. The limits of the TSI hold in every profile");
ImGui::EndTable();
}
// the class of the line folded to a line of what it is
std::array<char const *, 3> const kinds{norms_report::traffic_name(norms::traffic::passenger), norms_report::traffic_name(norms::traffic::mixed), norms_report::traffic_name(norms::traffic::freight)};
std::array<char const *, 2> const tracks{STR_C("main track"), STR_C("siding")};
auto const vmin{line.vmin > 0.0 ? line.vmin : norms::slow_speed(line.kind, line.vmax)};
auto const summary{format(STR_C("Line class: %.0f km/h, slow trains %.0f km/h, %s, %s"), line.vmax, vmin, kinds[static_cast<std::size_t>(line.kind)], tracks[static_cast<std::size_t>(line.track)])};
if (false == ImGui::TreeNode("##normsclass", "%s", summary.c_str()))
return;
if (begin_fields_fitted("##normsclassfields", 0.55f, {"Line speed (km/h)", "Slow trains (km/h)", "Traffic", "Track", "Load (Tg a year)"}))
{
field_row("Line speed (km/h)");
ImGui::InputDouble("##normsvmax", &line.vmax, 0.0, 0.0, "%.0f");
item_tooltip("For the tracks with no speed of their own, or for all of them");
field_row("Slow trains (km/h)");
ImGui::InputDouble("##normsvmin", &line.vmin, 0.0, 0.0, "%.0f");
item_tooltip("The cant excess is checked at this speed. 0: by the type of the line, ST-T1-A6 tab. 8.1");
field_row("Traffic");
auto kind{static_cast<int>(line.kind)};
if (ImGui::Combo("##normstraffic", &kind, kinds.data(), static_cast<int>(kinds.size())))
line.kind = static_cast<norms::traffic>(kind);
field_row("Track");
auto track{static_cast<int>(line.track)};
if (ImGui::Combo("##normstrack", &track, tracks.data(), static_cast<int>(tracks.size())))
line.track = static_cast<norms::track_kind>(track);
field_row("Load (Tg a year)");
ImGui::InputDouble("##normsload", &line.load, 0.0, 0.0, "%.0f");
item_tooltip("The tonnage over the track a year, for the cant excess of ST-T1-A6 tab. 9.8");
ImGui::EndTable();
}
line.vmax = std::clamp(line.vmax, 10.0, 350.0);
line.vmin = std::clamp(line.vmin, 0.0, line.vmax);
line.load = std::clamp(line.load, 0.0, 100.0);
ImGui::Checkbox(STR_C("The speed of the tracks where they have one"), &options.track_speeds);
bool platform{(line.features & norms::feature::platform) != 0};
if (ImGui::Checkbox(STR_C("Tracks at a platform"), &platform))
line.features = platform ? line.features | norms::feature::platform : line.features & ~norms::feature::platform;
ImGui::TextDisabled("%s", STR_C("Change the class, then Check again"));
ImGui::TreePop();
}
void norms_tool::render_results()
{
auto &state{m_state};
auto const listed_rows{listed()};
bool const chosen{state.selected >= 0 && state.selected < static_cast<int>(state.results.size())};
auto const details{chosen ? ImGui::GetTextLineHeightWithSpacing() * 3.0f : 0.0f};
// each column as wide as what's in it and its name and a little apart, the last one to the edge; the names stay at the top as the
// list scrolls
ImGui::PushStyleVar(ImGuiStyleVar_CellPadding, ImVec2(std::round(ImGui::GetFontSize() * 0.6f), ImGui::GetStyle().CellPadding.y));
// down to the bottom of the window, but some rows at least where the window is short (docked across the bottom), which scrolls then
auto const height{std::max(ImGui::GetContentRegionAvail().y - details, ImGui::GetTextLineHeightWithSpacing() * 8.0f)};
if (ImGui::BeginTable("normsresults", 6, ImGuiTableFlags_SizingFixedFit | ImGuiTableFlags_ScrollY | ImGuiTableFlags_BordersOuter, ImVec2(0.0f, height)))
{
for (int column = 0; column < 6; ++column)
ImGui::TableSetupColumn(nullptr, column == 5 ? ImGuiTableColumnFlags_WidthStretch : ImGuiTableColumnFlags_None);
ImGui::TableSetupScrollFreeze(0, 1);
ImGui::TableNextRow();
for (auto const *header : {"Path", "Tier", "Parameter", "Value", "Limit", "Source"})
{
ImGui::TableNextColumn();
ImGui::TextDisabled("%s", STR_C(header));
}
ImGuiListClipper clipper;
clipper.Begin(static_cast<int>(listed_rows.size()));
while (clipper.Step())
for (int row = clipper.DisplayStart; row < clipper.DisplayEnd; ++row)
{
auto const index{listed_rows[row]};
auto const &entry{state.results[index]};
auto const &finding{entry.finding};
ImGui::TableNextRow();
ImGui::TableNextColumn();
ImGui::PushStyleColor(ImGuiCol_Text, tier_colour(finding.level));
auto const name{entry.track != nullptr ? name_of(*entry.track) : std::string{"-"}};
if (ImGui::Selectable((name + "##norms" + std::to_string(index)).c_str(), state.selected == index, ImGuiSelectableFlags_SpanAllColumns))
focus(index);
ImGui::PopStyleColor();
if (ImGui::IsItemHovered())
ImGui::SetTooltip("%s", norms_report::message(finding, entry.kind).c_str());
ImGui::TableNextColumn();
ImGui::TextColored(tier_colour(finding.level), "%s", norms_report::tier_name(finding.level));
ImGui::TableNextColumn();
ImGui::TextUnformatted(norms_report::parameter_name(finding.what, entry.kind));
ImGui::TableNextColumn();
ImGui::TextUnformatted(finding.what == norms::parameter::profile_boundary ? "-" : norms_report::value_text(finding.what, finding.value).c_str());
ImGui::TableNextColumn();
ImGui::TextUnformatted(finding.what == norms::parameter::profile_boundary ? "-" : norms_report::value_text(finding.what, finding.limit).c_str());
ImGui::TableNextColumn();
ImGui::TextUnformatted(source_text(finding).c_str());
}
ImGui::EndTable();
}
ImGui::PopStyleVar();
if (chosen)
{
auto const &entry{state.results[state.selected]};
ImGui::TextWrapped("%s", norms_report::message(entry.finding, entry.kind).c_str());
}
}
void norms_tool::render_options()
{
auto &state{m_state};
ImGui::PushTextWrapPos(0.0f);
ImGui::TextDisabled("%s", STR_C("Checks the geometry of the tracks against the norms of a profile: what is beyond them is listed, nothing is changed"));
ImGui::PopTextWrapPos();
segmented("normsscope", state.scope, {{0, STR_C("Line through the selected path")}, {1, STR_C("Whole scenery")}});
render_class();
if (false == state.queue.empty())
{
auto const progress{static_cast<float>(state.next) / static_cast<float>(state.queue.size())};
ImGui::ProgressBar(progress, ImVec2(-70.0f, 0.0f), format(STR_C("Checking %zu / %zu"), state.next, state.queue.size()).c_str());
ImGui::SameLine();
if (ImGui::SmallButton(STR_C("Cancel")))
state.queue.resize(state.next);
}
else
{
ImGui::PushStyleColor(ImGuiCol_Button, ImGui::ColorConvertU32ToFloat4(family_colour(2, 0.55f)));
ImGui::PushStyleColor(ImGuiCol_ButtonHovered, ImGui::ColorConvertU32ToFloat4(family_colour(2, 0.75f)));
if (ImGui::Button(STR_C("Check"), ImVec2(-1.0f, tall_button_height())))
start();
ImGui::PopStyleColor(2);
item_tooltip("The radius, the cant and its deficiency and excess, their changes along the ramps and the transitions and at the joints, the lengths of the straights, arcs and transitions, the vertical curves and the grades");
}
if (false == state.status.empty())
ImGui::TextWrapped("%s", state.status.c_str());
if (state.results.empty())
return;
if (state.history != m_history.history_revision())
ImGui::TextColored(ImVec4(1.0f, 0.75f, 0.3f, 1.0f), "%s", STR_C("The scenery changed since the check"));
ImGui::Checkbox(STR_C("Above the recommended values too"), &state.notes);
render_results();
}
void norms_tool::draw_overlay() const
{
auto const &state{m_state};
if (false == state.open || state.results.empty())
return;
screen_projection const projection;
auto *drawlist{ImGui::GetBackgroundDrawList(ImGui::GetMainViewport())};
glm::dvec3 const camera{Global.pCamera.Pos};
for (int i = 0; i < static_cast<int>(state.results.size()); ++i)
{
auto const &entry{state.results[i]};
auto const level{entry.finding.level};
if (level == norms::tier::prefer || glm::distance(entry.position, camera) > kOverlayRange)
continue;
ImVec2 screen;
if (false == projection.project(entry.position, screen))
continue;
auto colour{level == norms::tier::block ? IM_COL32(255, 70, 60, 230) : IM_COL32(255, 180, 60, 200)};
if (i == state.selected)
colour = IM_COL32(255, 255, 80, 255);
drawlist->AddCircle(screen, 12.0f, colour, 16, 2.5f);
drawlist->AddText(ImVec2(screen.x + 14.0f, screen.y - 7.0f), colour, norms_report::parameter_name(entry.finding.what, entry.kind));
}
}
editor_selftest_result norms_tool::selftest(std::string const &Command, std::istringstream &Words)
{
if (Command != "normsreport")
return editor_selftest_result::unhandled;
std::string file;
int scope{0};
std::string profile{"plk"};
double speed{0.0};
Words >> file >> scope >> profile >> speed;
m_state.scope = scope;
auto const key{std::ranges::find(kProfileKeys, profile)};
m_state.profile = key != kProfileKeys.end() ? static_cast<int>(std::distance(kProfileKeys.begin(), key)) : 0;
if (speed > 0.0)
m_state.options.line.vmax = speed;
start();
while (false == m_state.queue.empty())
update();
std::string text{norms_report::header(m_state.options)};
for (auto const &line : m_state.lines)
text += norms_report::text(line, true);
std::ofstream out{file, std::ios::binary};
out << text;
WriteLog(format("SELFTEST normsreport %s: %s", file.c_str(), m_state.status.c_str()));
return editor_selftest_result::handled;
}
+65
View File
@@ -0,0 +1,65 @@
/*
This Source Code Form is subject to the
terms of the Mozilla Public License, v.
2.0. If a copy of the MPL was not
distributed with this file, You can
obtain one at
http://mozilla.org/MPL/2.0/.
*/
#pragma once
#include "application/editortool.h"
#include "editor/editorNormsReport.hpp"
#include <string>
#include <vector>
// the norms of the track geometry checked on the tracks laid, read only: a line or the whole scenery against a profile and a class
// of the line, what's beyond the limits listed in the track analysis window, a row clicked showing the place
class norms_tool final : public editor_tool
{
public:
norms_tool(editor_selection &Selection, editor_view &View, editor_history &History) : m_selection{Selection}, m_view{View}, m_history{History} {}
void update() override;
void draw_overlay() const override;
void render_options() override;
void forget(scene::basic_node const *Node) override;
editor_selftest_result selftest(std::string const &Command, std::istringstream &Words) override;
void set_open(bool const Open) { m_state.open = Open; }
// what the last check found, for the expectations of the self-test
std::vector<norms_report::entry> const &results() const { return m_state.results; }
private:
editor_selection &m_selection;
editor_view &m_view;
editor_history &m_history;
// a line to check: its paths, and the one span whose findings alone are kept (the diverging track of a switch), -1 all
struct pending
{
std::vector<norms_report::span> spans;
int own{-1};
};
struct state
{
bool open{false};
int scope{0}; // 0: the line through the selected path, 1: the whole scenery
int profile{0};
norms_report::options options;
bool notes{false}; // the values above the recommended ones listed too
std::vector<pending> queue;
std::size_t next{0};
std::vector<norms_report::checked_line> lines;
std::vector<norms_report::entry> results;
int selected{-1};
std::size_t history{0}; // size of the undo history at the check
std::string status;
};
state m_state;
void start();
void finish();
void focus(int const Index);
std::vector<int> listed() const;
void render_class();
void render_results();
};
+4
View File
@@ -151,6 +151,9 @@ editor_mode::selftest_result editor_mode::selftest_dispatch(std::string const &c
// a line of known curves, the points along them clicked as a curve traced, the line they make logged
// laychain <layout> <R> <x> <z> | b | u | r | e | t | p... the points clicked, Backspace, undo, redo, Enter, Tab, the line logged
// joints <x> <z>... the joints check over the scenery, the issues around the points logged, every issue with free ends without points
// normsreport <file> [scope 0|1] [plk|tsi|en|ch] [km/h] the tracks checked against the norms of the profile, the line through the
// selected path (0) or the whole scenery (1), the speed of the line class where the tracks have none:
// the report written to the file, its counts logged
// route <x> <z> <single 0|1> the route design of the path nearest the point, a curve or the whole line
// routevertex <i> <R> <L in> <L out> <cant>, routearc <i> <R> <L> <share>, routeshare <i> <share>, routekm <km>
// routeapply, routetake as the buttons of the route design do it
@@ -224,6 +227,7 @@ editor_mode::selftest_result editor_mode::selftest_dispatch(std::string const &c
// expect track <name> <present|removed>
// expect route <track> <in|out> the track is a part of the line open in the route tool, or not
// expect norms gauge <mm> [tolerance] the rail axes distance of the norms the tracks are laid to
// expect findings <note|warning|block|any> <least> <most> how many of the tier the last check of the norms found (normsreport)
// expect height <track> <start|end> <m> <tolerance> the height of the end of the first path
// expect lift <track> <start|end> <label> <m> <tolerance> how far the end of the first path is above the height marked
// expect includes <track> <count> the includes whose parameters name the track: the model and the events of a turntable
+23 -1
View File
@@ -257,6 +257,26 @@ void expect_norm(std::string const &What, std::istringstream &Words, alignment::
expect_near(What, Norms.gauge, wanted, optional_number(Words, 0.5));
}
// expect findings <note|warning|block|any> <least> <most>: how many the last check of the norms found of the tier
void expect_findings(std::string const &What, std::istringstream &Words, std::vector<norms_report::entry> const &Findings)
{
std::string tier;
int least{0};
int most{0};
Words >> tier >> least >> most;
if (malformed(What, Words))
return;
std::map<std::string, norms::tier, std::less<>> const tiers{{"note", norms::tier::prefer}, {"warning", norms::tier::warn}, {"block", norms::tier::block}};
auto const wanted{tiers.find(tier)};
if (tier != "any" && wanted == tiers.end())
{
expectation(false, What, "no tier " + tier, "note, warning, block or any");
return;
}
auto const count{std::ranges::count_if(Findings, [&](norms_report::entry const &Entry) { return tier == "any" || Entry.finding.level == wanted->second; })};
expectation(count >= least && count <= most, What, std::to_string(count), format("%d to %d", least, most));
}
// expect height <track> <start|end> <m> <tolerance>, expect lift <track> <start|end> <label> <m> <tolerance>
void expect_height(std::string const &What, std::string const &Kind, std::istringstream &Words, std::map<std::string, double> const &Marks)
{
@@ -379,9 +399,11 @@ editor_mode::selftest_result editor_mode::selftest_expect(std::string const &com
expect_includes(what, words);
else if (kind == "status")
expect_status(what, words, m_switch.status);
else if (kind == "findings")
expect_findings(what, words, m_norms.results());
else if (kind == "steps")
expect_steps(what, words, static_cast<std::size_t>(std::ranges::count_if(m_history, [](EditorSnapshot const &Step) { return false == Step.joined; })));
else
expectation(false, what, "no expectation " + kind, "cant, joint, records, speed, gauge, track, route, norms, height, lift, includes, status or steps");
expectation(false, what, "no expectation " + kind, "cant, joint, records, speed, gauge, track, route, norms, findings, height, lift, includes, status or steps");
return selftest_result::handled;
}
+28 -4
View File
@@ -478,9 +478,9 @@ void editor_mode::restore_track_snapshot(EditorSnapshot const &Snapshot, std::ve
profile_restore();
}
std::array<editor_mode::track_mode, 15> const &editor_mode::track_modes()
std::array<editor_mode::track_mode, 16> const &editor_mode::track_modes()
{
static std::array<track_mode, 15> const modes{{
static std::array<track_mode, 16> const modes{{
{"Select", "Esc", track_tab::path, "LMB on a path selects it: its points, control vectors and parameters", editor_icons::icon::select, 0},
{"Lay track", "L", track_tab::lay, "Lays new track through the clicked points, on the ground or from a free end of a track", editor_icons::icon::lay_track, 0},
{"Plan", "G", track_tab::straights, "The plan of the line laid: LMB on a straight drags its ends or the middle, on a curve its vertex and radius. C works too", editor_icons::icon::curve, 0},
@@ -496,6 +496,7 @@ std::array<editor_mode::track_mode, 15> const &editor_mode::track_modes()
{"Profile", "P", track_tab::profile, "Vertical profile (grade line) along the line", editor_icons::icon::profile, 2},
{"Speed", "V", track_tab::speed, "Speed limits of the paths against the speed their geometry allows", editor_icons::icon::speed, 2},
{"Joints", "J", track_tab::joints, "Ends of the paths which almost meet, steps, kinks, jumps of the cant and of the grade at the joints", editor_icons::icon::joints, 2},
{"Norms", nullptr, track_tab::norms, "The geometry of the tracks against the norms of a profile (PLK, TSI, EN 13803, AB-EBV): what is beyond them, read only", editor_icons::icon::norms, 2},
// the infrastructure tool (track_tab::infra) is left out: no button nor key
}};
return modes;
@@ -641,6 +642,7 @@ std::string editor_mode::track_mode_name() const
case track_tab::profile: return STR_C("Vertical profile");
case track_tab::speed: return STR_C("Speed check");
case track_tab::joints: return STR_C("Joints");
case track_tab::norms: return STR_C("Norms");
case track_tab::lineside: return STR_C("Posts along the track");
case track_tab::infra: return STR_C("Infrastructure");
case track_tab::parallel: return STR_C("Parallel track");
@@ -654,6 +656,23 @@ std::string editor_mode::track_mode_name() const
}
}
namespace
{
// the title of the window a check of the track tab lists what it finds in
char const *track_analysis_title(editor_track_tab const Tab)
{
switch (Tab)
{
case editor_track_tab::speed: return STR_C("Speed check");
case editor_track_tab::joints: return STR_C("Joints");
case editor_track_tab::norms: return STR_C("Norms");
default: return STR_C("Infrastructure");
}
}
} // namespace
void editor_mode::render_track_inspector()
{
auto const &io{ImGui::GetIO()};
@@ -661,6 +680,7 @@ void editor_mode::render_track_inspector()
m_speed.set_open(m_track_window_open && m_track_tab == track_tab::speed);
m_infra.open = m_track_window_open && m_track_tab == track_tab::infra;
m_joints.set_open(m_track_window_open && m_track_tab == track_tab::joints);
m_norms.set_open(m_track_window_open && m_track_tab == track_tab::norms);
m_srk.set_open(m_track_window_open && srk_tab(), m_track_tab == track_tab::station_signals ? srk_tool::part::signals : m_track_tab == track_tab::line_block ? srk_tool::part::lines : srk_tool::part::station);
m_km.set_open(m_track_window_open && m_track_tab == track_tab::kilometrage);
if (false == m_track_window_open || m_track_tab != track_tab::lineside)
@@ -685,9 +705,9 @@ void editor_mode::render_track_inspector()
// the tools of the mode are drawn in the tool options window and the selected path in the inspector, see
// render_track_tool_options() and render_track_selection(); the checks list what they find in a window of their own
if (m_track_tab == track_tab::speed || m_track_tab == track_tab::joints || m_track_tab == track_tab::infra)
if (m_track_tab == track_tab::speed || m_track_tab == track_tab::joints || m_track_tab == track_tab::norms || m_track_tab == track_tab::infra)
{
auto const *title{m_track_tab == track_tab::speed ? STR_C("Speed check") : m_track_tab == track_tab::joints ? STR_C("Joints") : STR_C("Infrastructure")};
auto const *title{track_analysis_title(m_track_tab)};
ImGui::SetNextWindowSize(ImVec2(600.0f, std::min(320.0f, io.DisplaySize.y - 80.0f)), ImGuiCond_FirstUseEver);
if (ImGui::Begin((std::string{title} + "###trackanalysis").c_str(), nullptr, ImGuiWindowFlags_NoCollapse))
{
@@ -695,6 +715,7 @@ void editor_mode::render_track_inspector()
{
case track_tab::speed: m_speed.render_options(); break;
case track_tab::joints: m_joints.render_options(); break;
case track_tab::norms: m_norms.render_options(); break;
default: render_infra_body(); break;
}
}
@@ -741,6 +762,7 @@ void editor_mode::render_track_tool_options()
case track_tab::profile: render_profile_body(); break;
case track_tab::speed:
case track_tab::joints:
case track_tab::norms:
case track_tab::infra:
ImGui::TextDisabled("%s", STR_C("What the check finds is listed in its window"));
break;
@@ -2034,6 +2056,8 @@ std::vector<editor_mode::key_hint> editor_mode::track_key_hints(bool const All)
hints = {{"LMB on a track", "a point of the km there"}, {"Mouse over a track", "its km by the cursor"}};
else if (m_track_window_open && m_track_tab == track_tab::joints)
hints = {{"LMB on a row", "show the place"}, {"Fix", "joins the ends, aligns them"}};
else if (m_track_window_open && m_track_tab == track_tab::norms)
hints = {{"LMB on a row", "show the place"}};
else if (m_track_window_open && m_track_tab == track_tab::infra)
hints = {{"LMB", "select a path"}};
else if (m_track_tab == track_tab::straights && m_straights.tool == 1)
+2 -1
View File
@@ -185,7 +185,7 @@ void editor_mode::work_area_tools(std::vector<tool_button> &Buttons)
add(track_tab::signals, true);
add(track_tab::kilometrage, false);
add(track_tab::lineside, false);
auto const advanced{m_track_tab == track_tab::turntable || srk_tab() || vehicle || m_track_tab == track_tab::profile || m_track_tab == track_tab::speed || m_track_tab == track_tab::joints || m_gauge.is_open()};
auto const advanced{m_track_tab == track_tab::turntable || srk_tab() || vehicle || m_track_tab == track_tab::profile || m_track_tab == track_tab::speed || m_track_tab == track_tab::joints || m_track_tab == track_tab::norms || m_gauge.is_open()};
auto const more{EditorSettings.track_tools_more()};
Buttons.push_back({icon::more, more ? STR_C("Less") : STR_C("More"), nullptr, STR_C("Turntable, stations and their signals, line block, trainset, profile, speed, joints, gauge"), more, [more]() {
EditorSettings.track_tools_more(false == more);
@@ -205,6 +205,7 @@ void editor_mode::work_area_tools(std::vector<tool_button> &Buttons)
add(track_tab::profile, true);
add(track_tab::speed, false);
add(track_tab::joints, false);
add(track_tab::norms, false);
Buttons.push_back({icon::gauge, STR_C("Structure gauge"), nullptr, STR_C("Checks which models enter the structure gauge of the tracks and the clearance over the roads (skrajnia budowli)"), m_gauge.is_open(),
[this]() { m_gauge.toggle(); }});
Buttons.back().accent = family_colour(2);
+1 -1
View File
@@ -36,7 +36,7 @@ enum class editor_selftest_result
enum class editor_first_step { tracks, lay, laid, wheel, join, turnout, undo, save, drive, look, top, select, shape, profile, profile_point, profile_apply, terrain, nmt, plan, plan_band, plan_apply, signal, posts, bend, trace, gizmo, vector, template_open, template_clicked, ride, count };
enum class editor_track_tab { straights, route, path, turnout, profile, speed, joints, infra, lay, lineside, turntable, parallel, signals, station, station_signals, line_block, kilometrage };
enum class editor_track_tab { straights, route, path, turnout, profile, speed, joints, infra, lay, lineside, turntable, parallel, signals, station, station_signals, line_block, kilometrage, norms };
struct track_hover
{
+2
View File
@@ -62,6 +62,8 @@ enum class icon
// the tools of the signalling beside signal and station
station_signals,
line_block,
// the check of the geometry of the tracks against the norms
norms,
count
};
+321
View File
@@ -0,0 +1,321 @@
/*
This Source Code Form is subject to the
terms of the Mozilla Public License, v.
2.0. If a copy of the MPL was not
distributed with this file, You can
obtain one at
http://mozilla.org/MPL/2.0/.
*/
#include "stdafx.h"
#include "editor/editorNormsReport.hpp"
#include "editor/editorFormat.hpp"
#include "editor/editorGeometry.hpp"
#include "utilities/translation.h"
#include "world/Track.h"
#include <algorithm>
#include <cmath>
namespace norms_report
{
namespace
{
double constexpr kBase{1500.0}; // mm between the rails the cant is measured on, as the simulator takes the rolls (Segment.cpp)
double constexpr kStraight{1.0 / 30000.0};
// the speed limit of the path, 0 for none (or a damaged track): a switch keeps one for both its tracks, -2 and below for the diverging
// one alone
double path_speed(TTrack &Track, int const Path)
{
auto velocity{Track.VelocityGet()};
if (Track.SwitchExtension && (Track.eType == tt_Switch || Track.eType == tt_Cross))
velocity = Track.SwitchExtension->fVelocity;
if (Track.eType == tt_Switch && velocity <= -2.0)
return Path == 0 ? 0.0 : -velocity;
return velocity > 0.0 ? velocity : 0.0;
}
double curvature_of(geometry::bezier const &Curve, double const T)
{
auto const first{Curve.first(T)};
auto const second{Curve.second(T)};
auto const planar{std::hypot(first.x, first.z)};
return planar > 1e-9 ? (first.x * second.z - first.z * second.x) / (planar * planar * planar) : 0.0;
}
unsigned features_of(TTrack const &Track, int const Path)
{
unsigned result{0};
if (Track.eType == tt_Cross)
return norms::feature::switch_track | norms::feature::crossing;
if (Track.eType != tt_Switch)
return result;
result |= norms::feature::switch_track;
if (Path > 0)
result |= norms::feature::diverging;
if (Track.SwitchExtension && Track.SwitchExtension->m_movablenose)
result |= norms::feature::movable_frog;
if (false == Track.m_paths.empty() && std::abs(curvature_of(geometry::bezier{Track.m_paths[0]}, 0.5)) > kStraight)
result |= norms::feature::curved_switch;
return result;
}
std::string label(norms::profile_id const Profile)
{
return std::string{norms::profile_of(Profile).label};
}
// the place of the limit, with its document where that isn't the one the profile or the hard limit is named after
std::string place(norms::finding const &Finding, std::string_view const Named)
{
if (Finding.from.document == Named || Finding.from.document.empty())
return std::string{Finding.from.place};
return std::string{Finding.from.document} + " " + std::string{Finding.from.place};
}
std::string kind_text(norms::element const &Element)
{
auto const radius = [](double const Curvature) { return std::abs(Curvature) > 1e-9 ? format("%.0f", 1.0 / Curvature) : std::string{"-"}; };
switch (Element.kind)
{
case norms::element_kind::arc: return format(STR_C("arc R %s"), radius(Element.curvature_start).c_str());
case norms::element_kind::transition: return format(STR_C("transition R %s -> %s"), radius(Element.curvature_start).c_str(), radius(Element.curvature_end).c_str());
default: return STR_C("straight");
}
}
} // namespace
sampled_line sample(std::vector<span> const &Line, double const Step, bool const TrackSpeeds)
{
sampled_line result;
double chainage{0.0};
for (auto const &span : Line)
{
auto const from{chainage};
if (span.track == nullptr || span.path < 0 || span.path >= static_cast<int>(span.track->m_paths.size()))
{
result.spans.emplace_back(from, from);
continue;
}
auto const &path{span.track->m_paths[span.path]};
// a path made of several curves is sampled along them, its own curve stands in for them in older versions only
std::vector<segment_data const *> parts;
if (path.pieces.empty())
parts.push_back(&path);
else
for (auto const &part : path.pieces)
parts.push_back(&part);
if (false == span.forward)
std::ranges::reverse(parts);
auto const speed{TrackSpeeds ? path_speed(*span.track, span.path) : 0.0};
auto const features{features_of(*span.track, span.path)};
auto const side{span.forward ? 1.0 : -1.0};
for (auto const *part : parts)
{
geometry::bezier const curve{*part};
auto const count{std::max(2, static_cast<int>(std::ceil(curve.plan_length(16) / std::max(0.1, Step))))};
auto previous{geometry::plan_of(curve.point(span.forward ? 0.0 : 1.0))};
for (int j = 0; j <= count; ++j)
{
auto const share{static_cast<double>(j) / count};
auto const t{span.forward ? share : 1.0 - share};
auto const position{curve.point(t)};
chainage += glm::distance(previous, geometry::plan_of(position));
previous = geometry::plan_of(position);
auto const along{curve.first(t) * side};
auto const planar{std::hypot(along.x, along.z)};
auto const roll{glm::radians(static_cast<double>(part->rolls[0]) + static_cast<double>(part->rolls[1] - part->rolls[0]) * t)};
norms::sample next;
next.chainage = chainage;
next.at = {position.x, position.z};
next.grade = planar > 1e-9 ? along.y / planar : 0.0;
next.curvature = curvature_of(curve, t) * side;
next.cant = kBase * std::sin(roll) * side;
next.speed = speed;
next.features = features;
result.samples.push_back(next);
}
}
result.spans.emplace_back(from, chainage);
}
return result;
}
checked_line check(std::vector<span> const &Line, options const &Options, norms::area_map const *Areas, int const Own)
{
checked_line result;
if (Line.empty())
return result;
auto const sampled{sample(Line, Options.step, Options.track_speeds)};
std::string name;
if (Line.front().track != nullptr)
name = Line.front().track->name();
result.described = norms::describe(sampled.samples, name);
norms::area_map own_areas;
own_areas.scenery = Options.profile;
auto const findings{norms::evaluate(result.described, Options.line, Areas != nullptr ? *Areas : own_areas)};
for (auto const &finding : findings)
{
// the span the finding begins on: the last one starting at or before it, past an empty one
std::size_t index{0};
for (std::size_t i = 0; i < sampled.spans.size(); ++i)
if (sampled.spans[i].first <= finding.chainage + 1e-6 && sampled.spans[i].second > sampled.spans[i].first)
index = i;
if (Own >= 0 && static_cast<int>(index) != Own)
continue;
auto const &span{Line[index]};
entry next;
next.finding = finding;
next.kind = finding.element < result.described.elements.size() ? result.described.elements[finding.element].kind : norms::element_kind::straight;
next.line = name;
next.track = span.track;
next.path = span.path;
if (span.track != nullptr && span.path >= 0 && span.path < static_cast<int>(span.track->m_paths.size()))
{
geometry::bezier const curve{span.track->m_paths[span.path]};
auto const [from, to]{sampled.spans[index]};
auto const into{std::clamp(finding.chainage - from, 0.0, to - from)};
next.position = curve.point(std::clamp(curve.parameter(span.forward ? into : (to - from) - into), 0.0, 1.0));
}
result.entries.push_back(next);
}
return result;
}
char const *traffic_name(norms::traffic const Kind)
{
switch (Kind)
{
case norms::traffic::passenger: return STR_C("passenger traffic");
case norms::traffic::freight: return STR_C("freight traffic");
default: return STR_C("mixed traffic");
}
}
char const *tier_name(norms::tier const Tier)
{
switch (Tier)
{
case norms::tier::prefer: return STR_C("note");
case norms::tier::warn: return STR_C("warning");
case norms::tier::block: return STR_C("hard limit");
default: return "-";
}
}
char const *parameter_name(norms::parameter const What, norms::element_kind const Kind)
{
using enum norms::parameter;
switch (What)
{
case cant_deficiency: return STR_C("cant deficiency");
case cant_excess: return STR_C("cant excess");
case deficiency_jump: return STR_C("abrupt change of the cant deficiency");
case cant_gradient: return STR_C("cant ramp");
case cant_rate: return STR_C("cant change rate");
case deficiency_rate: return STR_C("cant deficiency change rate");
case element_length: return Kind == norms::element_kind::arc ? STR_C("arc") : STR_C("straight");
case transition_length: return STR_C("transition curve");
case transition_shift: return STR_C("shift of the arc by its transition");
case radius: return STR_C("radius");
case cant:
case cant_min: return STR_C("cant");
case vertical_radius: return STR_C("vertical curve");
case grade: return STR_C("grade");
case profile_boundary: return STR_C("profile boundary");
default: return "-";
}
}
std::string value_text(norms::parameter const What, double const Value)
{
using enum norms::parameter;
switch (What)
{
case cant_gradient: return format("%.2f mm/m", Value);
case cant_rate:
case deficiency_rate: return format("%.0f mm/s", Value);
case element_length:
case transition_length:
case intermediate_length: return format("%.1f m", Value);
case transition_shift: return format("%.3f m", Value);
case radius:
case vertical_radius: return format("%.0f m", Value);
case grade: return format(STR_C("%.1f per mille"), Value);
default: return format("%.0f mm", Value);
}
}
std::string message(norms::finding const &Finding, norms::element_kind const Kind)
{
if (Finding.what == norms::parameter::profile_boundary)
return format(STR_C("arc across the boundary of %s and %s, to be settled"), label(Finding.profile).c_str(), label(Finding.other).c_str());
// the limit named by the profile, or by its document when hard; the place with its document where that's another one
auto const &profile{norms::profile_of(Finding.profile)};
auto const who{Finding.hard ? std::string{Finding.from.document} : std::string{profile.label}};
auto const where{place(Finding, Finding.hard ? Finding.from.document : profile.document)};
auto const limit{value_text(Finding.what, Finding.limit)};
std::string text;
if (Finding.what == norms::parameter::vertical_radius && Finding.value <= 0.0)
text = format(STR_C("break of the grade with no vertical curve, %s asks for a radius of at least %s (%s)"), who.c_str(), limit.c_str(), where.c_str());
else
{
auto const least{norms::minimum(Finding.what)};
char const *pattern{nullptr};
if (Finding.level == norms::tier::prefer)
pattern = least ? STR_C("%s %s, %s recommends at least %s (%s)") : STR_C("%s %s, %s recommends at most %s (%s)");
else
pattern = least ? STR_C("%s %s, %s asks for at least %s (%s)") : STR_C("%s %s, %s allows at most %s (%s)");
text = format(pattern, parameter_name(Finding.what, Kind), value_text(Finding.what, Finding.value).c_str(), who.c_str(), limit.c_str(), where.c_str());
}
if (false == Finding.confirmed)
text += STR_C(", the limit not confirmed");
return text;
}
std::string header(options const &Options)
{
auto const &line{Options.line};
auto const vmin{line.vmin > 0.0 ? line.vmin : norms::slow_speed(line.kind, line.vmax)};
auto text{format(STR_C("Norms: %s, line %.0f km/h, slow trains %.0f km/h, %s, %s, %.0f Tg a year"), std::string{norms::profile_of(Options.profile).name}.c_str(), line.vmax, vmin,
traffic_name(line.kind), line.track == norms::track_kind::main ? STR_C("main track") : STR_C("siding"), line.load)};
if (Options.track_speeds)
text += STR_C(", the speed of the tracks where they have one");
return text + "\n";
}
std::string text(checked_line const &Line, bool const Elements)
{
auto const &line{Line.described};
auto const length{line.elements.empty() ? 0.0 : line.elements.back().end()};
auto result{format(STR_C("Line %s: %.1f m, %zu elements, %zu findings"), line.name.c_str(), length, line.elements.size(), Line.entries.size()) + "\n"};
if (Elements)
{
for (auto const &element : line.elements)
result += format(" %8.1f %8.1f %s", element.start, element.length, kind_text(element).c_str()) + (element.speed > 0.0 ? format(" %.0f km/h", element.speed) : std::string{}) +
((element.features & norms::feature::switch_track) != 0 ? std::string{" "} + STR_C("switch") : std::string{}) + "\n";
result += STR_C(" cant (m: mm):");
for (auto const &point : line.cant)
result += format(" %.1f: %.1f", point.chainage, point.cant);
result += "\n";
result += STR_C(" grade (m: per mille):");
for (auto const &piece : line.grades)
result += format(" %.1f: %.2f", piece.start, piece.grade_start * 1000.0) + (piece.grade_end != piece.grade_start ? format(" .. %.2f", piece.grade_end * 1000.0) : std::string{});
result += "\n";
}
for (auto const &entry : Line.entries)
{
auto const &finding{entry.finding};
auto const track{entry.track != nullptr ? entry.track->name() : std::string{}};
result += format(" %8.1f %-10s %s [%s]", finding.chainage, tier_name(finding.level), message(finding, entry.kind).c_str(), track.c_str()) + "\n";
}
return result;
}
} // namespace norms_report
+84
View File
@@ -0,0 +1,84 @@
/*
This Source Code Form is subject to the
terms of the Mozilla Public License, v.
2.0. If a copy of the MPL was not
distributed with this file, You can
obtain one at
http://mozilla.org/MPL/2.0/.
*/
#pragma once
#include "editor/norms/norms.hpp"
#include <glm/glm.hpp>
#include <string>
#include <utility>
#include <vector>
class TTrack;
// the norms checked on the tracks laid, read only: a line of paths sampled into what the norms describe a line from, the findings set
// back on the paths, their messages and the report written (editor-tracks-domain.md §6, stage E1). Nothing of the tracks is changed
namespace norms_report
{
// a path of a track the line runs along, from its start or from its end
struct span
{
TTrack *track{nullptr};
int path{0};
bool forward{true};
};
struct options
{
norms::profile_id profile{norms::profile_id::plk};
norms::line_class line;
// the speed of each path where it has one, the one of the line class elsewhere; otherwise the one of the line class everywhere
bool track_speeds{true};
double step{1.0}; // m between the samples
};
struct sampled_line
{
std::vector<norms::sample> samples;
std::vector<std::pair<double, double>> spans; // the chainages each span runs over
};
// the samples along the line: the plan, the curvature signed by the turn, the cant on the base of 1500 mm signed with the side it leans
// to as the line runs, the grade, the speed of the path, what the path is part of (a switch, its diverging track, a crossing); two at
// each joint, the end of the one path and the start of the next
sampled_line sample(std::vector<span> const &Line, double const Step, bool const TrackSpeeds);
struct entry
{
norms::finding finding;
norms::element_kind kind{norms::element_kind::straight}; // of the element it's on
std::string line;
TTrack *track{nullptr};
int path{0};
glm::dvec3 position{0.0};
};
struct checked_line
{
norms::line described;
std::vector<entry> entries;
};
// the line checked against the profiles of the areas (the profile of the options where the map has none of its own, Areas being null);
// Own: the index of the span whose findings alone are kept, as for the diverging track of a switch checked along the line it lies in;
// below 0 all of them
checked_line check(std::vector<span> const &Line, options const &Options, norms::area_map const *Areas = nullptr, int const Own = -1);
char const *traffic_name(norms::traffic const Kind);
char const *tier_name(norms::tier const Tier);
char const *parameter_name(norms::parameter const What, norms::element_kind const Kind);
std::string value_text(norms::parameter const What, double const Value);
// "cant ramp 2.7 mm/m, PLK allows at most 2.5 mm/m (tab. 9.12)"
std::string message(norms::finding const &Finding, norms::element_kind const Kind);
// the report written: what it was checked against, then each line, its elements with Elements, and its findings
std::string header(options const &Options);
std::string text(checked_line const &Line, bool const Elements);
} // namespace norms_report
Binary file not shown.

Before

Width:  |  Height:  |  Size: 50 KiB

After

Width:  |  Height:  |  Size: 50 KiB

+7 -1
View File
@@ -415,11 +415,17 @@ def line_block(d):
line(d, [(31, 44), (31, 62)], W - 10)
def norms(d):
# a curve of the track and a set square: its geometry measured against the norms
arc(d, 60, 60, 46, 180, 270)
poly(d, [(8, 34), (8, 58), (32, 58)], outline=True, width=W - 6)
ICONS = [select, insert, brush, area_fill, copy_to_bank, translate, rotate, scale,
local_space, ortho, perspective, sculpt, smooth, chunks, orthophoto, road,
place, lanes, lay_track, switch, straight, curve, signal, objects,
vehicle, profile, speed, joints, infra, gauge, turntable, parallel, station, kilometrage, more, work_surroundings,
work_tracks, work_roads, work_terrain, station_signals, line_block]
work_tracks, work_roads, work_terrain, station_signals, line_block, norms]
def cutouts(name, d):
+16
View File
@@ -0,0 +1,16 @@
# E1: the report of the norms on the tracks of the scenery, read only.
# k0..k3: a straight, 60 m of R 2000 m and 60 m of R 400 m turning the same way with no transitions and no cant, a straight.
# At 60 km/h against PLK: the abrupt changes of the cant deficiency at both ends of the arc of R 400 m (85 and 106 mm) are beyond the
# 60 mm of P2 (ST-T1-A6 tab. 9.15), the radius of 400 m below the 600 m recommended; the cant deficiency of 106 mm is within P0
wait 5
select k1
normsreport scenery/autotest_editor_e1_norms_report_line.txt 0 plk 60
expect findings block 2 2
expect findings warning 0 0
expect findings note 1 1
# the whole scenery against the TSI alone at 100 km/h: R 400 m with no cant, I 295 mm, and the abrupt changes at it, beyond the TSI
normsreport scenery/autotest_editor_e1_norms_report_all.txt 1 tsi 100
expect findings block 3 100
expect findings warning 0 0
expect findings note 0 0
quit
+2 -1
View File
@@ -50,11 +50,12 @@ add_executable(${UNIT_TESTS_NAME}
track_stubs.cpp
# and the cant the track editor matches at the joints of the tracks
"${CMAKE_SOURCE_DIR}/editor/editorTrackShape.cpp"
# the norms of the track geometry, a module of its own (test_norms_*.cpp)
# the norms of the track geometry, a module of its own, and the report of the norms on the tracks laid (test_norms_*.cpp)
"${CMAKE_SOURCE_DIR}/editor/norms/normsTables.cpp"
"${CMAKE_SOURCE_DIR}/editor/norms/normsLimits.cpp"
"${CMAKE_SOURCE_DIR}/editor/norms/normsEngine.cpp"
"${CMAKE_SOURCE_DIR}/editor/norms/normsLine.cpp"
"${CMAKE_SOURCE_DIR}/editor/editorNormsReport.cpp"
${UNIT_TEST_CASES})
# the core library brings the game's build settings along
+29
View File
@@ -0,0 +1,29 @@
// a line for the golden report of the norms, written by make_line.py
// a straight, 150 m at 100 km/h
node -1 0 n01 track normal 150 1.435 0.15 25 20 0 flat vis rail_screw_used1 4 tpbps-new2 0.2 0.5 1.1 0 0 0 0 0 0 0 0 0 0 0 0 150 0 0 velocity 100 endtrack
// a transition of 60 m into R 600 m to the left, the cant ramp 0 - 60 mm along it
node -1 0 n02 track normal 60 1.435 0.15 25 20 0 flat vis rail_screw_used1 4 tpbps-new2 0.2 0.5 1.1 0 0 150 0 0 0 20 1 0 -20 -1 0 210 2.292443 0 velocity 100 endtrack
// the arc of R 600 m, 100 m, the cant 60 mm: I 137 mm at 100 km/h
node -1 0 n03 track normal 100 1.435 0.15 25 20 0 flat vis rail_screw_used1 4 tpbps-new2 0.2 0.5 1.1 -1 0 210 2.292443 -1.665551 0 33.311024 7.168642 0 -32.573132 -14.274362 0 308.998306 2.292443 600 velocity 100 endtrack
// the transition out of it, 60 m, the cant ramp 60 - 0 mm
node -1 0 n04 track normal 60 1.435 0.15 25 20 0 flat vis rail_screw_used1 4 tpbps-new2 0.2 0.5 1.1 -14.274362 0 308.998306 2.292443 -4.304066 0 19.556968 5.268742 0 -19.293531 -29.115913 0 367.142337 0 0 velocity 100 endtrack
// a straight of 28 m, shorter than 0.35 V
node -1 0 n05 track normal 28 1.435 0.15 25 20 0 flat vis rail_screw_used1 4 tpbps-new2 0.2 0.5 1.1 -29.115913 0 367.142337 0 0 0 0 0 0 0 -36.492153 0 394.153281 0 0 velocity 100 endtrack
// R 400 m to the right with no transition, 80 m at 60 km/h
node -1 0 n06 track normal 80 1.435 0.15 25 20 0 flat vis rail_screw_used1 4 tpbps-new2 0.2 0.5 1.1 -36.492153 0 394.153281 0 -7.03085 0 25.746167 1.775727 0 -26.629772 -49.735181 0 472.914422 0 400 velocity 60 endtrack
// a straight of 10 m between reverse curves
node -1 0 n07 track normal 10 1.435 0.15 25 20 0 flat vis rail_screw_used1 4 tpbps-new2 0.2 0.5 1.1 -49.735181 0 472.914422 0 0 0 0 0 0 0 -50.400524 0 482.892263 0 0 velocity 60 endtrack
// R 500 m to the left with no transition, 60 m at 60 km/h
node -1 0 n08 track normal 60 1.435 0.15 25 20 0 flat vis rail_screw_used1 4 tpbps-new2 0.2 0.5 1.1 -50.400524 0 482.892263 0 -1.331085 0 19.961672 3.711168 0 -19.658773 -57.970721 0 542.376498 0 500 velocity 60 endtrack
// a straight of 50 m, level
node -1 0 n09 track normal 50 1.435 0.15 25 20 0 flat vis rail_screw_used1 4 tpbps-new2 0.2 0.5 1.1 -57.970721 0 542.376498 0 0 0 0 0 0 0 -67.245858 0 591.508685 0 0 velocity 100 endtrack
// a straight of 50 m rising 8 per mille from a break of the grade
node -1 0 n10 track normal 50 1.435 0.15 25 20 0 flat vis rail_screw_used1 4 tpbps-new2 0.2 0.5 1.1 -67.245858 0 591.508685 0 0 0 0 0 0 0 -76.520995 0.4 640.640873 0 0 velocity 100 endtrack
// a straight of 30 m, level again, the cant ramp 0 - 90 mm along it, 3 mm/m
node -1 0 n11 track normal 30 1.435 0.15 25 20 0 flat vis rail_screw_used1 4 tpbps-new2 0.2 0.5 1.1 -76.520995 0.4 640.640873 0 0 0 0 0 0 0 -82.086077 0.4 670.120185 3.439813 0 velocity 100 endtrack
// R 1200 m to the left with no transition, 150 m, the cant 90 mm
node -1 0 n12 track normal 150 1.435 0.15 25 20 0 flat vis rail_screw_used1 4 tpbps-new2 0.2 0.5 1.1 -82.086077 0.4 670.120185 3.439813 -9.278157 0 49.148187 15.333303 0 -47.607965 -119.039379 0.4 815.396377 3.439813 1200 velocity 100 endtrack
// a straight of 60 m, the cant ramp 90 - 0 mm along it
node -1 0 n13 track normal 60 1.435 0.15 25 20 0 flat vis rail_screw_used1 4 tpbps-new2 0.2 0.5 1.1 -119.039379 0.4 815.396377 3.439813 0 0 0 0 0 0 -137.433353 0.4 872.507336 0 0 velocity 100 endtrack
// a straight of 100 m
node -1 0 n14 track normal 100 1.435 0.15 25 20 0 flat vis rail_screw_used1 4 tpbps-new2 0.2 0.5 1.1 -137.433353 0.4 872.507336 0 0 0 0 0 0 0 -168.089976 0.4 967.692269 0 0 velocity 100 endtrack
+71
View File
@@ -0,0 +1,71 @@
Norms: PLK ST-T1-A6, 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, 19 findings
0.0 150.0 straight 100 km/h
150.0 60.0 transition R - -> 600 100 km/h
210.0 100.0 arc R 600 100 km/h
310.0 60.0 transition R 600 -> - 100 km/h
370.0 28.0 straight 100 km/h
398.0 80.0 arc R -400 60 km/h
478.0 10.0 straight 60 km/h
488.0 60.0 arc R 500 60 km/h
548.0 130.0 straight 100 km/h
678.0 150.0 arc R 1200 100 km/h
828.0 160.0 straight 100 km/h
cant (m: mm): 0.0: 0.0 150.0: 0.0 210.0: 60.0 310.0: 60.0 370.0: 0.0 648.0: 0.0 678.0: 90.0 828.0: 90.0 888.0: 0.0 988.0: 0.0
grade (m: per mille): 0.0: 0.00 598.0: 8.00 648.0: 0.00
150.0 note cant deficiency change rate 63 mm/s, PLK recommends at most 55 mm/s (tab. 9.14) [n02]
210.0 warning cant deficiency 137 mm, PLK allows at most 130 mm (tab. 9.7) [n03]
310.0 note cant deficiency change rate 63 mm/s, PLK recommends at most 55 mm/s (tab. 9.14) [n04]
370.0 warning straight 28.0 m, PLK asks for at least 35.0 m (tab. 9.1) [n05]
398.0 hard limit abrupt change of the cant deficiency 106 mm, PLK allows at most 60 mm (tab. 9.15) [n06]
398.0 note radius 400 m, PLK recommends at least 600 m (tab. 9.2) [n06]
478.0 hard limit abrupt change of the cant deficiency 191 mm, PLK allows at most 60 mm (tab. 9.15) [n07]
478.0 hard limit straight 10.0 m, PLK asks for at least 20.0 m (tab. 9.1) [n07]
488.0 note radius 500 m, PLK recommends at least 600 m (tab. 9.2) [n08]
548.0 hard limit abrupt change of the cant deficiency 85 mm, PLK allows at most 60 mm (tab. 9.15) [n09]
598.0 hard limit break of the grade with no vertical curve, PLK asks for a radius of at least 2500 m (tab. 10.2) [n10]
598.0 note grade 8.0 per mille, PLK recommends at most 6.0 per mille (tab. 10.1) [n10]
648.0 hard limit cant ramp 3.00 mm/m, PLK allows at most 2.50 mm/m (tab. 9.12) [n11]
648.0 hard limit cant change rate 83 mm/s, PLK allows at most 60 mm/s (tab. 9.13) [n11]
648.0 hard limit cant deficiency change rate 83 mm/s, PLK allows at most 80 mm/s (tab. 9.14) [n11]
648.0 hard limit break of the grade with no vertical curve, PLK asks for a radius of at least 2500 m (tab. 10.2) [n11]
678.0 hard limit abrupt change of the cant deficiency 98 mm, PLK allows at most 50 mm (tab. 9.15) [n12]
828.0 hard limit abrupt change of the cant deficiency 98 mm, PLK allows at most 50 mm (tab. 9.15) [n13]
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
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
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]
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]
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]
678.0 warning abrupt change of the cant deficiency 98 mm, EN 13803 allows at most 40 mm (EN 13803-2 7.1.3), the limit not confirmed [n12]
828.0 warning abrupt change of the cant deficiency 98 mm, EN 13803 allows at most 40 mm (EN 13803-2 7.1.3), the limit not confirmed [n13]
Norms: CH AB-EBV, 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, 14 findings
150.0 warning cant deficiency change rate 63 mm/s, AB-EBV allows at most 55 mm/s (AB 17 4.3.1) [n02]
210.0 warning cant deficiency 137 mm, AB-EBV allows at most 130 mm (AB 17 3.6.2.1) [n03]
310.0 warning cant deficiency change rate 63 mm/s, AB-EBV allows at most 55 mm/s (AB 17 4.3.1) [n04]
398.0 warning abrupt change of the cant deficiency 106 mm, AB-EBV allows at most 50 mm (AB 17 5.3.1) [n06]
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]
478.0 hard limit straight 10.0 m, AB-EBV asks for at least 11.7 m (AB 17 3.2) [n07]
548.0 warning abrupt change of the cant deficiency 85 mm, AB-EBV allows at most 50 mm (AB 17 5.3.1) [n09]
598.0 hard limit break of the grade with no vertical curve, AB-EBV asks for a radius of at least 1750 m (AB 17 7.2) [n10]
648.0 hard limit cant ramp 3.00 mm/m, AB-EBV allows at most 2.50 mm/m (AB 17 4.2.1) [n11]
648.0 hard limit cant change rate 83 mm/s, AB-EBV allows at most 60 mm/s (AB 17 4.3.2) [n11]
648.0 warning cant deficiency change rate 83 mm/s, AB-EBV allows at most 55 mm/s (AB 17 4.3.1) [n11]
648.0 hard limit break of the grade with no vertical curve, AB-EBV asks for a radius of at least 2500 m (AB 17 7.2) [n11]
678.0 warning abrupt change of the cant deficiency 98 mm, AB-EBV allows at most 44 mm (AB 17 5.3.1) [n12]
828.0 warning abrupt change of the cant deficiency 98 mm, AB-EBV allows at most 44 mm (AB 17 5.3.1) [n13]
+129
View File
@@ -0,0 +1,129 @@
#!/usr/bin/env python3
# writes line.scn next to this script: a line of plain tracks for the golden report of the norms (test_norms_report.cpp), each track
# written the way the game writes it (TTrack::export_as_text_). The curves are cubic Bezier paths: an arc of up to 20 degrees a track,
# its control vectors 4/3 tan(a/4) R long; a transition curve a cubic parabola, which a Bezier curve is exactly. The cant is the roll of
# the paths, on the base of 1500 mm, leaning into the turn; the grade the height of the ends and of the control vectors.
# python3 make_line.py
import math
import os
BASE = 1500.0 # mm
class Line:
def __init__(self):
self.x, self.y, self.z = 0.0, 0.0, 0.0
self.dx, self.dz = 0.0, 1.0 # along +z
self.grade = 0.0
self.count = 0
self.lines = []
def left(self):
# the normal to the left, the way the curvature is positive: counterclockwise in x, z
return -self.dz, self.dx
def track(self, comment, p0, c1, c2, p3, roll0, roll1, speed, length, radius=0.0):
self.count += 1
name = "n%02d" % self.count
# the heights of the ends and of the control vectors along the grade
y0 = self.y
y3 = y0 + self.grade * length
c1y = self.grade * math.hypot(c1[0], c1[1])
c2y = -self.grade * math.hypot(c2[0], c2[1])
self.y = y3
numbers = [p0[0], y0, p0[1], roll0, c1[0], c1y, c1[1], c2[0], c2y, c2[1], p3[0], y3, p3[1], roll1, radius]
text = " ".join(fmt(v) for v in numbers)
self.lines.append("// %s" % comment)
self.lines.append("node -1 0 %s track normal %s 1.435 0.15 25 20 0 flat vis rail_screw_used1 4 tpbps-new2 0.2 0.5 1.1 %s velocity %s endtrack"
% (name, fmt(length), text, fmt(speed)))
def straight(self, comment, length, speed, cant0=0.0, cant1=0.0):
p0 = (self.x, self.z)
p3 = (self.x + self.dx * length, self.z + self.dz * length)
self.track(comment, p0, (0.0, 0.0), (0.0, 0.0), p3, roll(cant0), roll(cant1), speed, length)
self.x, self.z = p3
def arc(self, comment, radius, length, turn, speed, cant):
# turn: 1 to the left, -1 to the right; split into pieces of up to 20 degrees
angle = length / radius
pieces = max(1, math.ceil(math.degrees(angle) / 20.0 - 1e-9))
for i in range(pieces):
a = angle / pieces
nx, nz = self.left()
cx, cz = self.x + turn * radius * nx, self.z + turn * radius * nz
# the point and the heading turned by a around the centre
rx, rz = self.x - cx, self.z - cz
ca, sa = math.cos(turn * a), math.sin(turn * a)
ex, ez = cx + rx * ca - rz * sa, cz + rx * sa + rz * ca
edx, edz = self.dx * ca - self.dz * sa, self.dx * sa + self.dz * ca
k = 4.0 / 3.0 * math.tan(a / 4.0) * radius
text = comment if pieces == 1 else "%s, piece %d of %d" % (comment, i + 1, pieces)
self.track(text, (self.x, self.z), (self.dx * k, self.dz * k), (-edx * k, -edz * k), (ex, ez),
turn * roll(cant), turn * roll(cant), speed, radius * a, radius)
self.x, self.z, self.dx, self.dz = ex, ez, edx, edz
def transition_in(self, comment, radius, length, turn, speed, cant):
# y = x^3 / (6 R L) along the heading, to the side of the turn: the curvature goes from 0 to about 1 / R
nx, nz = self.left()
sx, sz = self.dx, self.dz
side = turn * length * length / (6.0 * radius)
ex = self.x + sx * length + nx * side
ez = self.z + sz * length + nz * side
slope = turn * length / (2.0 * radius)
c2 = (-(sx * length + nx * 3.0 * side) / 3.0, -(sz * length + nz * 3.0 * side) / 3.0)
self.track(comment, (self.x, self.z), (sx * length / 3.0, sz * length / 3.0), c2, (ex, ez), 0.0, turn * roll(cant), speed, length)
norm = math.hypot(1.0, slope)
self.dx, self.dz = (sx + nx * slope) / norm, (sz + nz * slope) / norm
self.x, self.z = ex, ez
def transition_out(self, comment, radius, length, turn, speed, cant):
# the mirror of the one in: from the curvature of the arc to the straight it ends on
angle = turn * math.atan(length / (2.0 * radius))
ca, sa = math.cos(angle), math.sin(angle)
bx, bz = self.dx * ca - self.dz * sa, self.dx * sa + self.dz * ca
nbx, nbz = -bz, bx
side = turn * length * length / (6.0 * radius)
fx = self.x + length * bx - nbx * side
fz = self.z + length * bz - nbz * side
c1 = ((length * bx - nbx * 3.0 * side) / 3.0, (length * bz - nbz * 3.0 * side) / 3.0)
c2 = (-length * bx / 3.0, -length * bz / 3.0)
self.track(comment, (self.x, self.z), c1, c2, (fx, fz), turn * roll(cant), 0.0, speed, length)
self.x, self.z, self.dx, self.dz = fx, fz, bx, bz
def roll(cant):
return math.degrees(math.asin(cant / BASE))
def fmt(value):
text = "%.6f" % value
text = text.rstrip("0").rstrip(".")
return "0" if text in ("-0", "") else text
def main():
line = Line()
line.straight("a straight, 150 m at 100 km/h", 150.0, 100.0)
line.transition_in("a transition of 60 m into R 600 m to the left, the cant ramp 0 - 60 mm along it", 600.0, 60.0, 1, 100.0, 60.0)
line.arc("the arc of R 600 m, 100 m, the cant 60 mm: I 137 mm at 100 km/h", 600.0, 100.0, 1, 100.0, 60.0)
line.transition_out("the transition out of it, 60 m, the cant ramp 60 - 0 mm", 600.0, 60.0, 1, 100.0, 60.0)
line.straight("a straight of 28 m, shorter than 0.35 V", 28.0, 100.0)
line.arc("R 400 m to the right with no transition, 80 m at 60 km/h", 400.0, 80.0, -1, 60.0, 0.0)
line.straight("a straight of 10 m between reverse curves", 10.0, 60.0)
line.arc("R 500 m to the left with no transition, 60 m at 60 km/h", 500.0, 60.0, 1, 60.0, 0.0)
line.straight("a straight of 50 m, level", 50.0, 100.0)
line.grade = 0.008
line.straight("a straight of 50 m rising 8 per mille from a break of the grade", 50.0, 100.0)
line.grade = 0.0
line.straight("a straight of 30 m, level again, the cant ramp 0 - 90 mm along it, 3 mm/m", 30.0, 100.0, 0.0, 90.0)
line.arc("R 1200 m to the left with no transition, 150 m, the cant 90 mm", 1200.0, 150.0, 1, 100.0, 90.0)
line.straight("a straight of 60 m, the cant ramp 90 - 0 mm along it", 60.0, 100.0, 90.0, 0.0)
line.straight("a straight of 100 m", 100.0, 100.0)
here = os.path.dirname(os.path.abspath(__file__))
with open(os.path.join(here, "line.scn"), "w", newline="\n") as out:
out.write("// a line for the golden report of the norms, written by make_line.py\n")
out.write("\n".join(line.lines) + "\n")
if __name__ == "__main__":
main()
+210
View File
@@ -0,0 +1,210 @@
// the report of the norms on the tracks laid (editor/editorNormsReport.cpp): tracks read from the text of a scenery with no scene, the
// way test_track_text.cpp reads them, chained into a line, sampled, described as elements and checked. The line of data/norms/line.scn
// (written by make_line.py there) against each profile gives the report kept in data/norms/line_report.txt; with
// EU07_UNIT_TESTS_UPDATE_GOLDEN=1 the report is written there instead, to be looked through as the change it is
#include "stdafx.h"
#include "doctest.h"
#include "track_text.h"
#include "editor/editorAlignment.hpp"
#include "editor/editorGeometry.hpp"
#include "editor/editorNormsReport.hpp"
#include <cmath>
#include <cstdlib>
#include <fstream>
#include <memory>
#include <sstream>
#include <string>
#include <vector>
namespace {
using test::read_track;
using test::track_reading;
std::string const kData{EU07_UNIT_TESTS_DATA "/norms/"};
std::vector<std::unique_ptr<TTrack>> read_tracks(std::string const &File) {
std::ifstream in{File};
REQUIRE(in.good());
std::vector<std::unique_ptr<TTrack>> result;
std::string line;
while (std::getline(in, line)) {
// a checkout may end the lines with CR LF
std::erase(line, '\r');
if (line.rfind("node", 0) == 0) {
result.push_back(read_track(line));
}
}
return result;
}
// the tracks one after another, from the first one: each next the one an end of which is where the line has come to
std::vector<norms_report::span> chained(std::vector<std::unique_ptr<TTrack>> const &Tracks) {
std::vector<norms_report::span> result;
if (Tracks.empty()) {
return result;
}
std::vector<bool> taken(Tracks.size(), false);
result.push_back({Tracks.front().get(), 0, true});
taken.front() = true;
auto reached{Tracks.front()->m_paths[0].points[segment_data::point::end]};
for (bool found{true}; found;) {
found = false;
for (std::size_t i = 0; i < Tracks.size() && false == found; ++i) {
if (taken[i]) {
continue;
}
auto const &path{Tracks[i]->m_paths[0]};
auto const at_start{geometry::plan_distance(path.points[segment_data::point::start], reached) < geometry::same_point};
auto const at_end{geometry::plan_distance(path.points[segment_data::point::end], reached) < geometry::same_point};
if (false == at_start && false == at_end) {
continue;
}
result.push_back({Tracks[i].get(), 0, at_start});
reached = path.points[at_start ? segment_data::point::end : segment_data::point::start];
taken[i] = true;
found = true;
}
}
return result;
}
std::string normalized(std::string Text) {
std::erase(Text, '\r');
return Text;
}
std::string file_text(std::string const &File) {
std::ifstream in{File, std::ios::binary};
std::ostringstream text;
text << in.rdbuf();
return normalized(text.str());
}
// the track text of a path laid by the editor, for it to be read as the scenery loader reads it
std::string entry(std::string const &Name, segment_data const &Path) {
std::ostringstream text;
text.precision(10);
auto const length{geometry::bezier{Path}.plan_length()};
text << "node -1 0 " << Name << " track normal " << length << " 1.435 0.15 25 20 0 flat vis rail_screw_used1 4 tpbps-new2 0.2 0.5 1.1";
auto const &points{Path.points};
for (auto const index : {segment_data::point::start, segment_data::point::control1, segment_data::point::control2, segment_data::point::end}) {
text << ' ' << points[index].x << ' ' << points[index].y << ' ' << points[index].z;
if (index == segment_data::point::start) {
text << ' ' << Path.rolls[0];
} else if (index == segment_data::point::end) {
text << ' ' << Path.rolls[1];
}
}
text << " 0 endtrack";
return text.str();
}
} // namespace
TEST_CASE("norms report: the cant of a curve laid by the editor leans into it, both ways and run both ways, as the samples sign it") {
track_reading const reading;
for (auto const side : {1.0, -1.0}) {
CAPTURE(side);
// a corner of R 400 m with transitions of 60 m and a cant of 80 mm, as in test_cant.cpp
alignment::design design;
design.start = {0.0, 0.0, 0.0};
design.end = {1000.0 * side, 0.0, 1000.0};
design.start_direction = {0.0, 1.0};
design.end_direction = {side, 0.0};
alignment::vertex vertex;
vertex.position = {0.0, 1000.0};
vertex.radius = 400.0;
vertex.transition_in = 60.0;
vertex.transition_out = 60.0;
vertex.cant = 80.0;
design.vertices.push_back(vertex);
auto const line{alignment::compute(design)};
REQUIRE(line.valid);
std::vector<std::unique_ptr<TTrack>> tracks;
int count{0};
for (auto const &path : alignment::pieces(line, design, alignment::minimum_pieces(line, design))) {
tracks.push_back(read_track(entry("corner" + std::to_string(++count), path)));
}
auto spans{chained(tracks)};
REQUIRE(spans.size() == tracks.size());
for (auto const backward : {false, true}) {
CAPTURE(backward);
if (backward) {
std::ranges::reverse(spans);
for (auto &span : spans) {
span.forward = !span.forward;
}
}
auto const sampled{norms_report::sample(spans, 1.0, false)};
int curved{0};
for (auto const &sample : sampled.samples) {
if (std::abs(sample.curvature) > 1.0 / 450.0) {
++curved;
CHECK(sample.curvature * sample.cant > 0.0);
CHECK(std::abs(sample.cant) > 70.0);
CHECK(std::abs(sample.cant) < 80.5);
}
}
CHECK(curved > 50);
// so at 80 km/h the arc falls short by 11.8 V^2 / R - 80 mm, not by more
norms_report::options options;
options.line.vmax = 80.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));
}
}
}
}
}
TEST_CASE("norms report: the golden report of the line of data/norms/line.scn against each profile") {
track_reading const reading;
auto const tracks{read_tracks(kData + "line.scn")};
REQUIRE(tracks.size() == 14);
auto const spans{chained(tracks)};
REQUIRE(spans.size() == tracks.size());
std::string report;
for (auto const profile : {norms::profile_id::plk, norms::profile_id::tsi, norms::profile_id::en13803, norms::profile_id::ch}) {
norms_report::options options;
options.profile = profile;
options.line.vmax = 100.0;
options.line.kind = norms::traffic::mixed;
options.line.track = norms::track_kind::main;
options.line.load = 5.0;
auto const checked{norms_report::check(spans, options)};
report += norms_report::header(options) + norms_report::text(checked, profile == norms::profile_id::plk) + "\n";
// every finding lies on a track of the line, at a point of it
for (auto const &found : checked.entries) {
CHECK(found.track != nullptr);
}
}
auto const golden{kData + "line_report.txt"};
if (auto const *update{std::getenv("EU07_UNIT_TESTS_UPDATE_GOLDEN")}; update != nullptr && std::string{update} == "1") {
std::ofstream{golden, std::ios::binary} << report;
MESSAGE("written " << golden);
return;
}
auto const expected{file_text(golden)};
// line by line, for the first difference to be shown by itself
std::istringstream got{report};
std::istringstream kept{expected};
std::string got_line;
std::string kept_line;
int number{0};
while (true) {
auto const more_got{static_cast<bool>(std::getline(got, got_line))};
auto const more_kept{static_cast<bool>(std::getline(kept, kept_line))};
++number;
if (false == more_got && false == more_kept) {
break;
}
CAPTURE(number);
REQUIRE(got_line == kept_line);
}
}