mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-12-01 14:07: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.
114 lines
3.4 KiB
C++
114 lines
3.4 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/.
|
|
*/
|
|
|
|
#include "stdafx.h"
|
|
#include "editor/project/projectGenerated.hpp"
|
|
#include "editor/project/sceneryText.hpp"
|
|
|
|
#include <algorithm>
|
|
#include <map>
|
|
|
|
namespace project
|
|
{
|
|
|
|
std::uint64_t checksum(std::string_view const Text)
|
|
{
|
|
auto const text{scenery_text::joined(scenery_text::split(Text))};
|
|
std::uint64_t result{14695981039346656037ull};
|
|
for (auto const c : text)
|
|
{
|
|
result ^= static_cast<unsigned char>(c);
|
|
result *= 1099511628211ull;
|
|
}
|
|
return result;
|
|
}
|
|
|
|
void record_generated(document &Project, layout::generated_line const &Line, std::string const &File)
|
|
{
|
|
std::erase_if(Project.generated, [&](generated_node const &Node) { return Node.kind == "track" && Node.line == Line.line; });
|
|
for (auto const &piece : Line.pieces)
|
|
{
|
|
generated_node node;
|
|
node.name = piece.name;
|
|
node.line = Line.line;
|
|
node.file = File;
|
|
node.sum = checksum(piece.text);
|
|
Project.generated.push_back(std::move(node));
|
|
}
|
|
// written again by the editor: the author decided
|
|
Project.hand_changed.erase(Line.line);
|
|
}
|
|
|
|
void record_generated(document &Project, layout::generated_turnout const &Turnout, std::string const &File)
|
|
{
|
|
auto const *turnout{Project.network.find(Turnout.turnout)};
|
|
if (turnout == nullptr)
|
|
return;
|
|
auto const main{turnout->main};
|
|
std::erase_if(Project.generated, [&](generated_node const &Node) { return Node.line == main; });
|
|
// each track of the simulator it's made of, by its main track: the switch tracks, and the plain tracks of a double switch, a slip or a
|
|
// crossing piece by piece
|
|
auto const keep = [&](std::string const &Kind, std::string const &Name, std::string const &Text) {
|
|
generated_node node;
|
|
node.kind = Kind;
|
|
node.name = Name;
|
|
node.line = main;
|
|
node.file = File;
|
|
node.sum = checksum(Text);
|
|
Project.generated.push_back(std::move(node));
|
|
};
|
|
if (Turnout.parts.empty())
|
|
keep("switch", Turnout.name, Turnout.text);
|
|
for (auto const &part : Turnout.parts)
|
|
{
|
|
if (part.is_switch)
|
|
{
|
|
keep("switch", part.name, part.text);
|
|
continue;
|
|
}
|
|
for (auto const &piece : part.pieces[0])
|
|
keep("track", piece.name, piece.text);
|
|
}
|
|
Project.hand_changed.erase(main);
|
|
}
|
|
|
|
std::vector<hand_change> find_hand_changes(document const &Project, std::function<std::optional<std::string>(std::string const &)> const &Files)
|
|
{
|
|
std::vector<hand_change> result;
|
|
std::map<std::string, std::optional<std::string>> texts;
|
|
for (auto const &node : Project.generated)
|
|
{
|
|
auto found{texts.find(node.file)};
|
|
if (found == texts.end())
|
|
found = texts.emplace(node.file, Files(node.file)).first;
|
|
auto const &text{found->second};
|
|
auto const now{text.has_value() ? scenery_text::node_text(*text, node.name) : std::nullopt};
|
|
if (now.has_value() && checksum(*now) == node.sum)
|
|
continue;
|
|
result.push_back({node.line, node.name, node.file, false == now.has_value()});
|
|
}
|
|
return result;
|
|
}
|
|
|
|
std::set<layout::line_id> mark_hand_changes(document &Project, std::vector<hand_change> const &Changes)
|
|
{
|
|
std::set<layout::line_id> result;
|
|
for (auto const &change : Changes)
|
|
if (Project.hand_changed.insert(change.line).second)
|
|
result.insert(change.line);
|
|
return result;
|
|
}
|
|
|
|
bool may_overwrite(document const &Project, layout::line_id const Line)
|
|
{
|
|
return false == Project.hand_changed.contains(Line);
|
|
}
|
|
|
|
} // namespace project
|