mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-12-01 18:47:06 +01:00
ca1f2239df
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.
285 lines
12 KiB
C++
285 lines
12 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/layoutLine.hpp"
|
|
#include "editor/norms/norms.hpp"
|
|
|
|
#include <algorithm>
|
|
#include <map>
|
|
#include <optional>
|
|
#include <set>
|
|
#include <string>
|
|
#include <vector>
|
|
#include <glm/glm.hpp>
|
|
|
|
// The lines and the nodes of the track geometry (editor-tracks-domain.md §4): the aggregates, their invariants and the checks of them.
|
|
// A node is the point the ends of the lines meet at: its place, the heading, the curvature, the cant and the grade there, and the ends
|
|
// meeting in it. The continuity of the track is the invariant of the node: the ends of its lines have its place by construction (a line
|
|
// has no coordinates of its own at its ends), and its heading, its cant and its grade within what the norms let pass; the curvature
|
|
// may change there only by a step of the cant deficiency the profile allows. The legs of a turnout are nodes too: at its start the main and
|
|
// the diverging track meet the line it lies on, so a node holds two ends, or three at the start of a turnout.
|
|
namespace layout
|
|
{
|
|
|
|
enum class line_end
|
|
{
|
|
start,
|
|
end
|
|
};
|
|
|
|
// an end of a line meeting at a node; the sense tells whether the line runs from there along the heading of the node or against it
|
|
struct end_ref
|
|
{
|
|
line_id line{line_id::none};
|
|
line_end end{line_end::start};
|
|
int sense{1};
|
|
|
|
bool operator==(end_ref const &) const = default;
|
|
// the side of the node the line lies on: 1 ahead of it, along its heading, -1 behind it
|
|
int side() const { return end == line_end::start ? sense : -sense; }
|
|
};
|
|
|
|
struct node
|
|
{
|
|
node_id id{node_id::none};
|
|
glm::dvec3 position{0.0}; // the scenery's x, the height, z
|
|
glm::dvec2 heading{0.0, 1.0}; // plan, unit
|
|
double curvature{0.0}; // 1/m along the heading, above 0 turning left
|
|
double cant{0.0}; // mm along the heading, above 0 leaning left
|
|
double grade{0.0}; // along the heading, above 0 rising
|
|
std::vector<end_ref> ends;
|
|
|
|
bool operator==(node const &) const = default;
|
|
};
|
|
|
|
struct line
|
|
{
|
|
line_id id{line_id::none};
|
|
turnout_id turnout{turnout_id::none}; // the turnout whose track it is, none for a line of its own
|
|
node_id start{node_id::none};
|
|
node_id end{node_id::none};
|
|
line_shape shape;
|
|
// the curve next to the end goes on from the curve the node holds, beginning or ending right at it: a line split inside a curve
|
|
bool start_continues{false};
|
|
bool end_continues{false};
|
|
double chainage_start{0.0}; // m, the kilometrage of the start of the line
|
|
norms::line_class category;
|
|
std::optional<norms::profile_id> profile; // of the norms, its own; none: the one of the area it lies in
|
|
// derived: the line laid between its nodes
|
|
solved_line solved;
|
|
|
|
bool operator==(line const &) const = default;
|
|
node_id node_at(line_end const End) const { return End == line_end::start ? start : end; }
|
|
bool continues(line_end const End) const { return End == line_end::start ? start_continues : end_continues; }
|
|
};
|
|
|
|
// a turnout (editor-tracks-domain.md §2, §4 "Rozjazd", §7): a type of the catalogue laid into a line, its hand and its direction along the
|
|
// line, bent as the line under it is (table 11.8), its speeds computed. Its main track is the part of the line it lies on and its diverging
|
|
// track leaves it at its start, each a line the turnout owns; its legs, the start and the ends of the two tracks, are nodes
|
|
struct turnout
|
|
{
|
|
turnout_id id{turnout_id::none};
|
|
std::string type; // of the catalogue, "Rz 60E1-500-1:12"
|
|
int hand{1}; // the side the diverging track leaves to as the turnout runs from its start: 1 left, -1 right
|
|
int direction{1}; // 1: its main track runs as the line it was laid into does, from the start of the turnout; -1 against it
|
|
node_id start{node_id::none};
|
|
node_id main_end{node_id::none};
|
|
node_id diverging_end{node_id::none}; // none of a crossing
|
|
line_id main{line_id::none};
|
|
line_id diverging{line_id::none}; // none of a crossing
|
|
// a double switch (layoutTurnout.hpp, "twofold"): the node where its second switch starts on the main track, the main track on from
|
|
// there to main_end, the diverging track of the second switch and the node at its end
|
|
node_id second{node_id::none};
|
|
line_id main2{line_id::none};
|
|
line_id diverging2{line_id::none};
|
|
node_id diverging2_end{node_id::none};
|
|
// a slip or a crossing: the crossing track and the nodes at its ends; the diverging track of a slip runs from the start to cross_end,
|
|
// the second one of a double slip (diverging2) from cross_start to main_end
|
|
line_id crossing{line_id::none};
|
|
node_id cross_start{node_id::none};
|
|
node_id cross_end{node_id::none};
|
|
// derived from the line under it
|
|
double chainage{0.0}; // m, the kilometrage of its start
|
|
double main_radius{0.0}; // m, of the main track, signed as table 11.8 takes it: above 0 bent the way the diverging track leaves, 0 straight
|
|
double diverging_radius{0.0}; // m, of the diverging curve bent by table 11.8, signed: above 0 turning to the hand, below 0 the other way
|
|
double cant{0.0}; // mm, the same all over it, above 0 leaning to the side the diverging track leaves to
|
|
double speed_main{0.0}; // km/h
|
|
double speed_diverging{0.0}; // km/h
|
|
double velocity{0.0}; // as the track has it written: the limit of the main track for both, or the diverging one for it alone below 0
|
|
bool movable{false}; // the frog with a movable nose, of the type
|
|
|
|
bool operator==(turnout const &) const = default;
|
|
bool bent() const { return main_radius != 0.0; }
|
|
};
|
|
|
|
class transaction;
|
|
|
|
// the lines and the nodes of a scenery, with the profiles of the norms by place; identifiers given once and never again
|
|
class network
|
|
{
|
|
public:
|
|
node const *find(node_id const Id) const;
|
|
line const *find(line_id const Id) const;
|
|
turnout const *find(turnout_id const Id) const;
|
|
std::map<node_id, node> const &nodes() const { return m_nodes; }
|
|
std::map<line_id, line> const &lines() const { return m_lines; }
|
|
std::map<turnout_id, turnout> const &turnouts() const { return m_turnouts; }
|
|
// the same lines, nodes and turnouts: the identifiers handed out so far aren't compared
|
|
bool same(network const &Other) const { return m_nodes == Other.m_nodes && m_lines == Other.m_lines && m_turnouts == Other.m_turnouts; }
|
|
|
|
norms::area_map areas; // the profiles of the norms by place
|
|
|
|
node_id new_node() { return static_cast<node_id>(++m_last_node); }
|
|
line_id new_line() { return static_cast<line_id>(++m_last_line); }
|
|
vertex_id new_vertex() { return static_cast<vertex_id>(++m_last_vertex); }
|
|
turnout_id new_turnout() { return static_cast<turnout_id>(++m_last_turnout); }
|
|
|
|
// the end of the line meeting at its node, as the node keeps it
|
|
end_ref const *end_of(line_id const Line, line_end const End) const;
|
|
// how the end of the line meets its node, for laying the line
|
|
end_condition condition(line const &Line, line_end const End) const;
|
|
|
|
// the last identifiers handed out, which the project file keeps so that none is handed out again after it's read
|
|
struct handed_out
|
|
{
|
|
std::uint32_t node{0};
|
|
std::uint32_t line{0};
|
|
std::uint32_t vertex{0};
|
|
std::uint32_t turnout{0};
|
|
|
|
bool operator==(handed_out const &) const = default;
|
|
};
|
|
handed_out handed() const { return {m_last_node, m_last_line, m_last_vertex, m_last_turnout}; }
|
|
// the identifiers up to these taken as handed out; none goes back below what was handed out already
|
|
void hand_out(handed_out const &Last)
|
|
{
|
|
m_last_node = std::max(m_last_node, Last.node);
|
|
m_last_line = std::max(m_last_line, Last.line);
|
|
m_last_vertex = std::max(m_last_vertex, Last.vertex);
|
|
m_last_turnout = std::max(m_last_turnout, Last.turnout);
|
|
}
|
|
|
|
private:
|
|
friend class transaction;
|
|
std::map<node_id, node> m_nodes;
|
|
std::map<line_id, line> m_lines;
|
|
std::map<turnout_id, turnout> m_turnouts;
|
|
std::uint32_t m_last_node{0};
|
|
std::uint32_t m_last_line{0};
|
|
std::uint32_t m_last_vertex{0};
|
|
std::uint32_t m_last_turnout{0};
|
|
};
|
|
|
|
// the lines and nodes as they were before a change, or are after it: none where one didn't exist
|
|
struct snapshot
|
|
{
|
|
std::map<line_id, std::optional<line>> lines;
|
|
std::map<node_id, std::optional<node>> nodes;
|
|
std::map<turnout_id, std::optional<turnout>> turnouts;
|
|
};
|
|
|
|
// a change of the network in the making: each line and node it touches is kept as it was the first time, so the change can be taken
|
|
// back whole, or recorded for undoing and redoing
|
|
class transaction
|
|
{
|
|
public:
|
|
explicit transaction(network &Network) : m_network{Network} {}
|
|
network const &view() const { return m_network; }
|
|
network &ids() { return m_network; }
|
|
|
|
line &change(line_id const Id);
|
|
node &change(node_id const Id);
|
|
turnout &change(turnout_id const Id);
|
|
line &add(line Line);
|
|
node &add(node Node);
|
|
turnout &add(turnout Turnout);
|
|
void erase(line_id const Id);
|
|
void erase(node_id const Id);
|
|
void erase(turnout_id const Id);
|
|
|
|
std::set<line_id> touched_lines() const;
|
|
std::set<node_id> touched_nodes() const;
|
|
std::set<turnout_id> touched_turnouts() const;
|
|
snapshot before() const { return m_before; }
|
|
snapshot after() const;
|
|
// everything as it was before the transaction
|
|
void roll_back();
|
|
|
|
private:
|
|
network &m_network;
|
|
snapshot m_before;
|
|
};
|
|
|
|
// puts a snapshot in place: the lines and the nodes it has as it has them
|
|
void restore(network &Network, snapshot const &State);
|
|
|
|
// the lines touched laid again between their nodes, and what depends on them: the nodes take the heading, the curvature, the cant and the
|
|
// grade of the ends they hold (a node at a free end follows its line), and a line going on from a curve at a node whose curve changed is
|
|
// laid again; a turnout whose main track or start changed lays its diverging track again, its end node where the track ends now, and
|
|
// computes its bending and its speeds
|
|
void settle(transaction &Change);
|
|
|
|
// the turnout owning the line, none for a line of its own
|
|
turnout const *owner_of(network const &Network, line_id const Line);
|
|
// the end of a track of a turnout which runs on into no line through its node and tells it nothing, another track of the turnout carrying
|
|
// the line through there: the start of a diverging track, and the end of a slip curve
|
|
bool branch_end(network const &Network, end_ref const &End);
|
|
|
|
// a line running on through the nodes of two ends: the lines in their order, each forward or backward
|
|
struct chain_part
|
|
{
|
|
line_id line{line_id::none};
|
|
bool forward{true};
|
|
};
|
|
std::vector<chain_part> chain_of(network const &Network, line_id const Line);
|
|
// the chain described as one line for the norms: the elements running on alike across the nodes as one, the ends open
|
|
struct described_chain
|
|
{
|
|
norms::line line;
|
|
std::vector<double> starts; // the chainage each part starts at
|
|
};
|
|
described_chain describe_chain(network const &Network, std::vector<chain_part> const &Chain);
|
|
|
|
// what the norms found on a line changed, or the rules of a turnout on it
|
|
struct notice
|
|
{
|
|
line_id line{line_id::none};
|
|
double chainage{0.0}; // along the line
|
|
norms::finding finding; // of a rule of a turnout: no parameter (norms::parameter::count), the tier
|
|
std::string text;
|
|
turnout_id turnout{turnout_id::none}; // a rule of the turnout
|
|
std::vector<glm::dvec2> along; // a BLOCK finding: the element it's on, as points of the plan 2 m apart at most
|
|
};
|
|
|
|
// the BLOCK finding Found is the one Old was: a rule of the same turnout telling the same, or a limit of the same parameter passed on the
|
|
// same stretch of the track (their elements within a metre and a half of each other), by no more
|
|
bool same_finding(notice const &Old, notice const &Found);
|
|
|
|
struct verdict
|
|
{
|
|
std::vector<std::string> reasons; // what breaks an invariant
|
|
std::vector<notice> blocks; // the BLOCK limits of the norms and the hard rules of the turnouts passed
|
|
std::vector<notice> notices; // WARN and PREFER
|
|
bool fine() const { return reasons.empty() && blocks.empty(); }
|
|
// the reasons and the BLOCK limits, as a refusal tells them
|
|
std::vector<std::string> refusals() const;
|
|
};
|
|
// the invariants of the touched lines, nodes and turnouts, the norms along the chains through the touched lines, the rules of the turnouts on
|
|
// them or at the nodes
|
|
verdict check(network const &Network, std::set<line_id> const &Lines, std::set<node_id> const &Nodes, std::set<turnout_id> const &Turnouts = {});
|
|
// the same over all of the network
|
|
verdict check_all(network const &Network);
|
|
|
|
// "cant deficiency 162 mm, the limit 150 mm (ST-T1-A6 tab. 9.4)"
|
|
std::string finding_text(norms::finding const &Finding);
|
|
|
|
} // namespace layout
|