18
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-12-01 09:27:10 +01:00
Files
maszyna/editor/layout/layoutGenerator.hpp
T
maj00r ca1f2239df feat(editor): the double, symmetric and secant switches, the slips and the crossings of the catalogue in the domain model
E5 (editor-tracks-domain.md §4 "Rozjazd", §7): every type of the catalogue is a turnout the model lays, its tracks lines it owns and its
legs nodes, kept whole or refused like the ordinary switches E2b laid. E2b refused the rest with "stage E5".

- Secant blades (S42): the diverging track runs along the main one for the pre-blade stretch and turns off it by the angle of the blades
  at their tips, the rest of 1:n on its arc; a turn inside the track, the node at the start keeping the heading of the main track. The
  generator ends a piece there with the heading of the element before it (unchanged where a line runs on in its heading).
- Double switches (Rpd, Rpj, Rps): the main track cut at the start of the second switch, its node holding the main track, the main track
  of the second switch (main2) and its diverging track, to the other side or the same one, as switch_design::build() lays it. Written as
  the switch tool writes them: the first switch, a plain track of a metre before the second one (the simulation joins a switch to plain
  tracks only), the second switch.
- Symmetric switches (Rls): both tracks turning off by half of the angle, to both sides, laid at a free end of a line, which they end (the
  line beyond it would have to turn at the node); not moved along the line.
- Slips (Rkp, Rkpd) and diamond crossings (Skrz): the main track a part of the line, the crossing track across its middle at the angle of
  the slip between two nodes of its own, the slip curves from the start to the end of the crossing track and, of a double slip, from its
  start to the end of the main track; slip_of() lays the curves with the blades of the ordinary switch of the rail, radius and angle (no
  data of the slips' own blades was found), passing the crossing as near as the rails of the simulator's profile let them. The three with
  the blades outside of the diamond whose curves then reach past the half length of Id-4 (49E1 190-1:6,6, 300-1:9, 500-1:9, by up to 0.3 m)
  are laid as long as their curves. Written as the switch tool writes them: a switch at each leg a slip curve leaves, the tracks crossing
  and the middles of the slip curves plain tracks, the joints inside it the same numbers on both sides.
- The rules: a double switch, a slip, a crossing (11.4 pkt 4 a, b) and a symmetric switch (no rule of table 11.8 for it) lie on straights
  only; an invariant, refused with the reason before anything is laid. The norms judge the tracks crossing at a slip or a crossing as
  crossings (no cant, tab. 9.6), its slip curves as diverging tracks.
- The ends of the tracks of a turnout which carry no line through their node (the starts of the diverging tracks, the ends of the slip
  curves) are branch_end(); a node holds such an end beside a track of the same turnout on its side. settle() lays all the tracks a turnout
  lays itself (lay_tracks()), the nodes of its own where they end; lifting, moving, changing (to another kind too) and removing a turnout
  take all of them along.
- The project file: the turnout record gets "second <node> <main2> <diverging2> <node>" and "crossing <line> <node> <node> slip <line>"
  where the turnout has them (diverging 0 0 for a crossing); version 1, unreleased, read as before without them. The generated section
  keeps each track a turnout is made of.
- TSI INF 4.2.3.4(1), 150 m at least, judges the plain line, not the curves of switches (4.2.5): its hard row leaves out the tracks of the
  turnouts, so the industrial S42 switches of R 70 and 140 m are laid.

Tests: U: every type of the catalogue laid (41 ordinary, 3 symmetric, 15 double, 18 slips, 20 crossings) on a straight to both sides
along the line and against it, its legs where the catalogue puts them (the main track a + b, 1:n at the ends, the second switch at the
stagger, the crossing track at the angle of the slip, half its length from the crossing), moved and taken out, the line one again, each a
step to undo; the turn of the secant blades of S42-190-1:7 at the end of the pre-blade stretch; a double switch, two slips and a crossing
refused in a curve, a secant S42 bent in a side track, a symmetric switch refused at the end of a curve. The three fitted to the tangents
of S42-140-1:6,6 16/12 measured are refused by the norms (tab. 9.14) where the transition one is. P: 200 random edits with every type along
arcs and transitions, seeds 5150, 2718 and 1618: the invariants after each, a refusal changing nothing, undone back to the start exactly.
G: every type made into the tracks of the simulator and read back by TTrack::Load, the ends of the paths at the legs or at each other to
the bit, the velocity and the frog; a double switch, a double slip and a crossing written to the project file and read back, their tracks
laid again the same to the bit. The E2b case of the types refused now checks that they're laid. Unit tests 1077 -> 1086.
2026-11-23 14:49:35 +01:00

126 lines
6.1 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/layoutNetwork.hpp"
#include "world/Segment.h"
#include <array>
#include <map>
#include <string>
#include <vector>
// The generator of the tracks of the simulator (editor-tracks-domain.md §3 and §5): the layer between the domain and the simulator,
// which knows nothing of the domain. A line is cut into cubic Bezier pieces, each one a track entry of the text TTrack::Load reads:
// within the tolerance of the element it follows (half a millimetre by default, the curve measured as the simulator draws it, a straight
// of zero control vectors where it takes the curve for one), the rolls and the heights from the functions of the line, the radius from
// the element. A piece ends at a node with the numbers of the node, the same on both sides of it; the names of the tracks come from the
// identifiers of the line and of its vertices, so they don't change with a change of the shape which keeps its elements. A turnout is one
// switch track of two paths, its main and its diverging track, each made of the pieces of its line (pieces1, pieces2), the ends of its legs
// the numbers of its nodes, its velocity as the speed rule gives it, its frog and its blades as its type has them; a double switch, a slip
// and a crossing the switch tracks and the plain tracks the switch tool of the editor makes of them, their joints inside the turnout the
// numbers of the points of its lines there.
namespace layout
{
// a joint of an old track the pieces are to end at, the name of the old track kept for the piece before it (stage E6)
struct hard_split
{
double chainage{0.0};
std::string name;
};
struct generator_options
{
std::string prefix{"l"}; // of the names of the tracks: <prefix><line>_<element><piece>
std::string turnout_prefix{"t"}; // of the names of the switch tracks: <turnout_prefix><turnout>
double tolerance{0.0005}; // m, the farthest a piece may lie from its line, in the plan and in the height
double cant_tolerance{2.0}; // mm the cant may differ from the line between the ends of a piece, where the simulator turns it evenly
// what an entry has between the type and the path: the width, the friction, the sound distance, the quality, the damage, the
// environment and the visibility with the materials
std::string surface{"1.435 0.15 25 20 0 flat vis rail_screw_used1 4 tpbps-new2 0.2 0.5 1.1"};
// the joints of the old tracks as hard points of the pieces, by line: stage E6 (§10, "stare złącza jako twarde punkty podziału").
// Not yet: a line given any is refused, so nothing is made which would lose the names and the events of the old tracks
std::map<line_id, std::vector<hard_split>> hard_splits;
};
struct generated_piece
{
std::string name;
double from{0.0}; // chainage along the line
double to{0.0};
segment_data path; // its control vectors relative to its ends, zero for a straight, as the entry has them
double deviation{0.0}; // m, the farthest the curve as the simulator draws it lies from the line, measured when cut
std::string text; // the entry
};
struct generated_line
{
line_id line{line_id::none};
std::vector<generated_piece> pieces;
std::vector<std::string> errors;
std::string text() const;
};
// the pieces of a line of its own; a track of a turnout is made with its turnout
generated_line generate(network const &Network, line_id const Line, generator_options const &Options = {});
// a track of the simulator a turnout is made of: a switch track of two paths, or a plain track (each of its pieces an entry)
struct generated_part
{
std::string name;
bool is_switch{false};
// of a switch the main and the diverging path from its start, each the pieces of its line, as the paths of the switch have them: the
// path the pieces make, whole, with them (none where one piece makes it); of a plain track its pieces
std::array<std::vector<generated_piece>, 2> pieces;
std::array<segment_data, 2> paths;
std::string text; // the entries
};
struct generated_turnout
{
turnout_id turnout{turnout_id::none};
std::string name;
// the main and the diverging track from the start of the turnout, each the pieces of its line, as the paths of the switch have them:
// the path the pieces make, whole, with them (none where one piece makes it); of its first switch track, where it has more
std::array<std::vector<generated_piece>, 2> pieces;
std::array<segment_data, 2> paths;
double velocity{0.0};
std::vector<std::string> errors;
// the tracks of the simulator it's made of: an ordinary or a symmetric switch one switch track; a double switch two and a short plain
// track between them (<name>, <name>_l, <name>_2); a slip a switch at each leg a slip curve leaves (<name>_a ... _d, plain tracks at the
// others), the tracks crossing and the middles of the slip curves plain ones (_m, _x, _s1, _s2); a crossing two plain tracks (_1, _2)
std::vector<generated_part> parts;
std::string text; // the entries, of all the parts
};
generated_turnout generate(network const &Network, turnout_id const Turnout, generator_options const &Options = {});
// all the lines of the network in the order of their identifiers, then all the turnouts; the errors of the ones which couldn't be made in
// Errors
std::string generate_all(network const &Network, generator_options const &Options, std::vector<std::string> &Errors);
// the curve the simulator draws of the path: a straight where its control vectors are zero, or so close to the third of the chord that
// TTrack takes it for one (its check of 2 cm, TTrack::straightened)
struct drawn_curve
{
glm::dvec3 p0;
glm::dvec3 p1;
glm::dvec3 p2;
glm::dvec3 p3;
glm::dvec3 point(double const T) const;
};
drawn_curve drawn(segment_data const &Path);
bool straightened(segment_data const &Path);
// the farthest the curve drawn lies from the line between the chainages: each point of it set square onto the line, the distance in the
// plan and in the height together
double deviation(solved_line const &Line, drawn_curve const &Curve, double const From, double const To);
} // namespace layout