mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-12-01 19:57:06 +01:00
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.
This commit is contained in:
@@ -348,9 +348,18 @@ std::string write(document const &Project)
|
||||
}
|
||||
put("turnouts");
|
||||
for (auto const &[id, turnout] : network.turnouts())
|
||||
put(std::format("turnout {} type {} hand {} direction {} start {} main {} {} diverging {} {} chainage {} radii {} {} cant {} speeds {} {} velocity {} movable {}", layout::number(id), word(turnout.type), turnout.hand, turnout.direction,
|
||||
layout::number(turnout.start), layout::number(turnout.main), layout::number(turnout.main_end), layout::number(turnout.diverging), layout::number(turnout.diverging_end), number(turnout.chainage),
|
||||
number(turnout.main_radius), number(turnout.diverging_radius), number(turnout.cant), number(turnout.speed_main), number(turnout.speed_diverging), number(turnout.velocity), turnout.movable ? 1 : 0));
|
||||
{
|
||||
auto text{std::format("turnout {} type {} hand {} direction {} start {} main {} {} diverging {} {} chainage {} radii {} {} cant {} speeds {} {} velocity {} movable {}", layout::number(id), word(turnout.type), turnout.hand,
|
||||
turnout.direction, layout::number(turnout.start), layout::number(turnout.main), layout::number(turnout.main_end), layout::number(turnout.diverging), layout::number(turnout.diverging_end),
|
||||
number(turnout.chainage), number(turnout.main_radius), number(turnout.diverging_radius), number(turnout.cant), number(turnout.speed_main), number(turnout.speed_diverging),
|
||||
number(turnout.velocity), turnout.movable ? 1 : 0)};
|
||||
// the tracks and the legs of the double switches, the slips and the crossings, only where the turnout has them
|
||||
if (turnout.second != node_id::none)
|
||||
text += std::format(" second {} {} {} {}", layout::number(turnout.second), layout::number(turnout.main2), layout::number(turnout.diverging2), layout::number(turnout.diverging2_end));
|
||||
if (turnout.crossing != line_id::none)
|
||||
text += std::format(" crossing {} {} {} slip {}", layout::number(turnout.crossing), layout::number(turnout.cross_start), layout::number(turnout.cross_end), layout::number(turnout.diverging2));
|
||||
put(text);
|
||||
}
|
||||
put("end");
|
||||
put("anchors");
|
||||
for (auto const &line : Project.anchors)
|
||||
@@ -372,6 +381,30 @@ std::string write(document const &Project)
|
||||
return text;
|
||||
}
|
||||
|
||||
namespace
|
||||
{
|
||||
|
||||
// the tracks of the turnout there and its, its legs there, the tracks it lays itself between its legs
|
||||
bool whole_turnout(layout::network const &Network, layout::turnout const &Turnout)
|
||||
{
|
||||
auto const held = [&](node_id const Node) { return Node == node_id::none || Network.find(Node) != nullptr; };
|
||||
auto const between = [&](line_id const Track, node_id const From, node_id const To) {
|
||||
auto const *track{Network.find(Track)};
|
||||
return Track == line_id::none || (track != nullptr && track->start == From && track->end == To);
|
||||
};
|
||||
auto const tracks{layout::tracks_of(Turnout)};
|
||||
if (Network.find(Turnout.main) == nullptr || (Turnout.diverging == line_id::none && Turnout.crossing == line_id::none))
|
||||
return false;
|
||||
if (false == std::ranges::all_of(tracks, [&](line_id const Track) { return Network.find(Track) != nullptr && Network.find(Track)->turnout == Turnout.id; }))
|
||||
return false;
|
||||
auto const slip{Turnout.crossing != line_id::none};
|
||||
return held(Turnout.start) && held(Turnout.main_end) && held(Turnout.diverging_end) && held(Turnout.second) && held(Turnout.diverging2_end) && held(Turnout.cross_start) &&
|
||||
held(Turnout.cross_end) && between(Turnout.diverging, Turnout.start, slip ? Turnout.cross_end : Turnout.diverging_end) &&
|
||||
between(Turnout.diverging2, slip ? Turnout.cross_start : Turnout.second, Turnout.diverging2_end) && between(Turnout.crossing, Turnout.cross_start, Turnout.cross_end);
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
read_result read(std::string_view const Text)
|
||||
{
|
||||
read_result result;
|
||||
@@ -481,6 +514,25 @@ read_result read(std::string_view const Text)
|
||||
turnout.velocity = words.real("the velocity");
|
||||
words.expect("movable");
|
||||
turnout.movable = words.choice("movable", std::array<std::string_view, 2>{"0", "1"}) == 1;
|
||||
if (words.peek() == "second")
|
||||
{
|
||||
words.next("second");
|
||||
turnout.second = static_cast<node_id>(words.id("the node of the second switch"));
|
||||
turnout.main2 = static_cast<line_id>(words.id("the main track of the second switch"));
|
||||
turnout.diverging2 = static_cast<line_id>(words.id("the diverging track of the second switch"));
|
||||
turnout.diverging2_end = static_cast<node_id>(words.id("the node at the end of the diverging track of the second switch"));
|
||||
}
|
||||
if (words.peek() == "crossing")
|
||||
{
|
||||
words.next("crossing");
|
||||
turnout.crossing = static_cast<line_id>(words.id("the crossing track"));
|
||||
turnout.cross_start = static_cast<node_id>(words.id("the node at the start of the crossing track"));
|
||||
turnout.cross_end = static_cast<node_id>(words.id("the node at the end of the crossing track"));
|
||||
words.expect("slip");
|
||||
turnout.diverging2 = static_cast<line_id>(words.id("the second slip curve"));
|
||||
if (turnout.diverging2 != line_id::none)
|
||||
turnout.diverging2_end = turnout.main_end;
|
||||
}
|
||||
words.finish();
|
||||
if (false == words.failed())
|
||||
{
|
||||
@@ -796,25 +848,25 @@ read_result read(std::string_view const Text)
|
||||
result.error = std::format("node {}: line {} doesn't end at it", layout::number(id), layout::number(end.line));
|
||||
return result;
|
||||
}
|
||||
// the turnouts and their tracks, each of them of the other
|
||||
// the turnouts and their tracks, each of them of the other; the tracks it lays itself between its legs as written
|
||||
for (auto const &[id, turnout] : network.turnouts())
|
||||
{
|
||||
auto const *main{network.find(turnout.main)};
|
||||
auto const *diverging{network.find(turnout.diverging)};
|
||||
auto const held = [&](node_id const Node) { return network.find(Node) != nullptr; };
|
||||
if (main == nullptr || diverging == nullptr || main->turnout != id || diverging->turnout != id || false == held(turnout.start) || false == held(turnout.main_end) || false == held(turnout.diverging_end) ||
|
||||
diverging->start != turnout.start || diverging->end != turnout.diverging_end)
|
||||
if (false == whole_turnout(network, turnout))
|
||||
{
|
||||
result.error = std::format("turnout {}: its tracks or its legs aren't the ones written", layout::number(id));
|
||||
return result;
|
||||
}
|
||||
}
|
||||
for (auto const &[id, laid] : network.lines())
|
||||
if (auto const *owner{network.find(laid.turnout)}; laid.turnout != turnout_id::none && (owner == nullptr || (owner->main != id && owner->diverging != id)))
|
||||
{
|
||||
auto const *owner{network.find(laid.turnout)};
|
||||
auto const tracks{owner != nullptr ? layout::tracks_of(*owner) : std::vector<line_id>{}};
|
||||
if (laid.turnout != turnout_id::none && std::ranges::find(tracks, id) == tracks.end())
|
||||
{
|
||||
result.error = std::format("line {}: turnout {} hasn't it", layout::number(id), layout::number(laid.turnout));
|
||||
return result;
|
||||
}
|
||||
}
|
||||
// the identifiers: none handed out again, whatever the record of them says
|
||||
layout::network::handed_out last;
|
||||
for (auto const &[id, node] : network.nodes())
|
||||
@@ -836,14 +888,10 @@ read_result read(std::string_view const Text)
|
||||
result.notes.push_back("the next identifiers written are lower than the ones in use, taken past them");
|
||||
network.hand_out(*next);
|
||||
network.hand_out(last);
|
||||
// the lines laid between their nodes as read; the diverging tracks then, laid by their turnouts off their main tracks
|
||||
auto const diverging = [&](layout::line const &Line) {
|
||||
auto const *owner{network.find(Line.turnout)};
|
||||
return owner != nullptr && owner->diverging == Line.id;
|
||||
};
|
||||
// the lines laid between their nodes as read; the tracks the turnouts lay themselves then, off their main tracks
|
||||
for (auto const &[id, laid] : network.lines())
|
||||
{
|
||||
if (diverging(laid))
|
||||
if (layout::laid_by_turnout(network, id))
|
||||
continue;
|
||||
auto solved{layout::solve(laid.shape, network.condition(laid, layout::line_end::start), network.condition(laid, layout::line_end::end))};
|
||||
for (auto const &error : solved.errors)
|
||||
@@ -859,10 +907,11 @@ read_result read(std::string_view const Text)
|
||||
result.notes.push_back(std::format("turnout {}: {}", layout::number(id), why.empty() ? "no type " + turnout.type : why));
|
||||
continue;
|
||||
}
|
||||
auto laid{layout::lay_diverging(layout::frame_of(network, turnout), *type, turnout.hand)};
|
||||
auto const laid{layout::lay_tracks(network, turnout, *type)};
|
||||
for (auto const &error : laid.errors)
|
||||
result.notes.push_back(std::format("turnout {}: {}", layout::number(id), error));
|
||||
change.change(turnout.diverging).solved = std::move(laid);
|
||||
for (auto const &track : laid.tracks)
|
||||
change.change(track.line).solved = track.solved;
|
||||
}
|
||||
result.project = std::move(project);
|
||||
return result;
|
||||
|
||||
Reference in New Issue
Block a user