18
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-12-01 19:57:06 +01:00
Files
maszyna/editor/layout/layoutLine.hpp
T
maj00r 4a3b36c204 feat(editor): the turnouts of the track geometry, laid into a line, moved, changed and taken out, their legs nodes
E2b (editor-tracks-domain.md §2, §4 "Rozjazd", §7, §8): a turnout is an aggregate of the domain model, laid from the catalogue the
editor lays its switches from, its rules invariants which refuse.

- layoutTurnout: the type of the catalogue (switch_design::catalogue(), Id-4) as the model lays it: R, 1:n, a, b, the main length,
  the lead and the parts of the diverging track, the movable nose, the blades; the ordinary switches whose diverging track leaves
  tangentially, the double, symmetric and secant ones refused with the reason (E5). The diverging track laid off the start along the
  turnout: on a straight the curve of the type; bent with the main track the curve of the basic switch of the radius of table 11.8
  (switch_curve::bent_radius), over the length which keeps its turn off the main track, so the angle of the frog stays 1:n, the lead
  and the straight through the frog bent along with the main track; the cant of the main track all along it, the grade of its start.
  The speeds: the diverging one by switch_curve::branch_speed (the rule the editor writes), the main one the line's, bent no faster
  than the deficiency of the frog lets it; the velocity written by the same rule as the editor's.
- The turnout: its type, hand, direction along the line, its start, the ends of its two tracks (nodes), its main and diverging track
  (lines it owns), derived: the kilometrage of its start, the bending, the cant, the speeds. The network keeps the turnouts with the
  lines and the nodes, in the snapshots of undo and in the transactions; settle() has a turnout whose main track or start changed
  lay its diverging track again, move the node at its end and lay again the lines going on from there.
- The nodes: three ends at the start of a turnout, its two tracks on one side of it; the start of a diverging track tells its node
  nothing (the node keeps the curvature of the main track) and runs on into no line, the end of one sets its node.
- check(): the turnouts whose tracks or legs are touched, their invariants (the legs, the tracks, the main track as long as the type)
  and the rules of Q2 and 11.4 through switch_curve::check (the curvature of each track of one sign, KZW II refused; the cant the same
  over it; the ends of the ramps at its ends or 6 m off it), a switch of 1:9.403 or steeper than 1:9 bent in a main track refused (the
  model knows a main track from a side one, where the editor only warns), table 11.9 and a transition under it as warnings. The norms
  of the E1 module with the switch context: the elements of a turnout track are a connection of tracks of their frog (fixed or movable
  nose: the deficiency of tab. 9.7), bent or not (the cant of tab. 9.6), at its speeds; the chain of the line runs through the main
  track, the element cut by a turnout open. BLOCK findings are kept apart from the broken invariants (verdict::blocks).
- The commands: insert a turnout at a chainage of a line (cut at its legs, the part between them its main track), move it along its
  line (the lines on both sides and its main track one line again, cut anew, the ids kept, a line going on from the end of its
  diverging track carried with it), change its type or hand, remove it (the line one again where it can be: the merge laid and kept
  only where it's the same track within a micrometre). The tracks of a turnout aren't split, deleted or edited as lines; a line is joined
  to the free side of a turnout's start, or to the end of its diverging track from a straight (the curvature stepping there).

Tests: U: the types laid and refused; the legs on a straight against the catalogue for four types both hands both ways (the main
track a + b, the tangent of the diverging end meeting the main track at R tan(a/2), Id-4's a within half a millimetre, the angle 1:n,
the speeds of table 11.2); Rz 60E1-500-1:12 bent outward and inward into R 1200 m with 60 mm (r" 857.8 m and 352.7 m, 60 km/h, the
angle of the frog kept, the cant over it); refusals: KZW II, a ramp under it and 3 m off it, a 1:7.5 bent in a main track (laid in a
side track), no type, no hand, no room; moved, changed, turned, taken out with the line laid again within a micrometre, each a step
to undo; a line from the diverging end carried along. P: 250 random edits with turnouts each, seeds 20261124, 31 and 977 (laid,
moved, changed, taken out, with vertices moved and set, splits, joins, deletions, undo, redo): the invariants after each (the legs
and the nodes whole, three ends only at a start, the velocity by the rule), no BLOCK, a refusal changing nothing, an undo exact.
2026-11-23 12:41:49 +01:00

203 lines
6.6 KiB
C++

/*
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/layout/layoutElements.hpp"
#include "editor/norms/norms.hpp"
#include <cstdint>
#include <string>
#include <vector>
#include <glm/glm.hpp>
// The line of the track geometry (editor-tracks-domain.md §2 and §4, "Linia"): the axis of a track between two nodes, given as a tangent
// polygon of vertices between them, each with its radius, its transition curves and its cant, and a grade line of breaks with vertical
// curves; solved into the elements one after another, the cant and the heights as functions of the chainage. The ends of the line are
// its nodes: it has no coordinates of its own there, the polygon starts and ends at the points of the nodes.
namespace layout
{
// the identifiers of the domain: given once, never given again, 0 for none
enum class node_id : std::uint32_t
{
none = 0
};
enum class line_id : std::uint32_t
{
none = 0
};
enum class vertex_id : std::uint32_t
{
none = 0
};
enum class turnout_id : std::uint32_t
{
none = 0
};
inline std::uint32_t number(node_id const Id) { return static_cast<std::uint32_t>(Id); }
inline std::uint32_t number(line_id const Id) { return static_cast<std::uint32_t>(Id); }
inline std::uint32_t number(vertex_id const Id) { return static_cast<std::uint32_t>(Id); }
inline std::uint32_t number(turnout_id const Id) { return static_cast<std::uint32_t>(Id); }
enum class transition_shape
{
clothoid,
cubic_parabola, // the abscissa along the tangent is the transition length given
bloss
};
// how the cant changes along a transition curve
enum class ramp_shape
{
linear,
bloss
};
// a break of the tangents: where they meet, the radius of the arc between them, the transition curves into it and out of it, its cant
struct vertex
{
vertex_id id{vertex_id::none};
glm::dvec2 point{0.0}; // plan, the scenery's x and z
double radius{600.0}; // m
double transition_in{0.0}; // m
double transition_out{0.0};
double cant{0.0}; // mm, leaning into the turn
bool operator==(vertex const &) const = default;
};
// a break of the grade line: at the chainage, the height there, the radius of the vertical curve rounding it
struct grade_break
{
double chainage{0.0};
double elevation{0.0};
double vertical_radius{5000.0};
bool operator==(grade_break const &) const = default;
};
// the cant, mm, signed: above 0 leaning left as the line runs, from the start of the stretch to its end, a ramp or a stretch held
struct cant_stretch
{
double from{0.0};
double to{0.0};
double start{0.0};
double end{0.0};
ramp_shape shape{ramp_shape::linear};
bool operator==(cant_stretch const &) const = default;
};
// the grade line: the breaks between the ends, each with the tangent of its vertical curve
struct profile_point
{
double chainage{0.0};
double elevation{0.0};
double vertical_radius{0.0};
double tangent{0.0}; // m from the break to either end of its vertical curve
bool operator==(profile_point const &) const = default;
};
// the values of the line at an end, as the line runs from its start to its end
struct end_values
{
glm::dvec3 position{0.0};
glm::dvec2 heading{0.0, 1.0};
double curvature{0.0};
double cant{0.0}; // mm, signed
double grade{0.0};
bool operator==(end_values const &) const = default;
};
// how the curve next to an end of the line meets its node: as the node holds it (the end goes on from a curve, the line was split
// inside one), or from a straight
struct end_condition
{
glm::dvec3 position{0.0};
bool continues{false};
double curvature{0.0}; // as the line runs, of the node where the end continues
double cant{0.0};
};
struct line_shape
{
std::vector<vertex> vertices;
std::vector<grade_break> grades;
transition_shape transition{transition_shape::clothoid};
ramp_shape ramp{ramp_shape::linear};
bool operator==(line_shape const &) const = default;
};
// the line solved: the elements, the cant and the grade line along it; errors where it can't be laid as given
struct solved_line
{
std::vector<element> elements;
std::vector<cant_stretch> cant;
std::vector<profile_point> profile;
double length{0.0};
end_values start;
end_values end;
std::vector<std::string> errors;
bool valid() const { return errors.empty() && false == elements.empty(); }
bool operator==(solved_line const &) const = default;
// the element at the chainage, the later one at a boundary
std::size_t element_at(double const Chainage) const;
glm::dvec2 position(double const Chainage) const;
glm::dvec2 tangent(double const Chainage) const;
double curvature(double const Chainage) const;
// mm, signed; where a stretch begins, its own value
double cant_at(double const Chainage) const;
double elevation(double const Chainage) const;
double grade(double const Chainage) const;
glm::dvec3 point(double const Chainage) const;
};
// the line laid between the end conditions; the vertices and the breaks as given, the ends from the nodes
solved_line solve(line_shape const &Shape, end_condition const &Start, end_condition const &End);
// the shape of a curve of a vertex in the frame of the tangent point where it starts, heading along x: the elements, and how far the
// tangent points are from the vertex
struct curve_fit
{
std::vector<element> elements;
double tangent_in{0.0};
double tangent_out{0.0};
double arc{0.0};
std::string error;
};
// Deflection: signed, above 0 turning left. From and To: the curvatures the transitions start at and end at, signed
curve_fit fit_curve(transition_shape const Shape, double const Deflection, double const Radius, double const In, double const Out, double const From = 0.0, double const To = 0.0);
// the line as the norms describe it (norms::line), the class of the line telling the speed of its elements
norms::line described(solved_line const &Line, norms::line_class const &Class, std::string Name = {});
// the cant, the transition length and the radius the norms prefer for a curve of the radius at the line class, by the profile:
// the regular cant within the preferred deficiency and greatest cant, the transitions long enough for the preferred ramp gradient,
// cant rate and deficiency rate, rounded up to whole metres
struct curve_norms
{
double cant{0.0};
double transition{0.0};
double radius_prefer{0.0};
double radius_block{0.0};
};
curve_norms preferred_curve(norms::profile_id const Profile, norms::line_class const &Class, double const Radius);
// mm of the cant as degrees of the roll of the track: on the base of the rail heads, 1500 mm
double roll_of(double const Cant);
} // namespace layout