mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-12-02 21:15:20 +01:00
4a3b36c204
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.
246 lines
10 KiB
C++
246 lines
10 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 <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;
|
|
// 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};
|
|
line_id main{line_id::none};
|
|
line_id diverging{line_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;
|
|
|
|
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 is the start of the diverging track of a turnout, which runs on into no line through its node and tells it nothing
|
|
bool diverging_start(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
|
|
};
|
|
|
|
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
|