18
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-12-02 10:46:45 +01:00

feat(editor): the //$r switches of an old scenery on the lines of its alignments made turnouts of its project

E5, what E3 left (editor-tracks-domain.md §9 "Migracja"): the //$r records were kept in the project file as a block a file; the switches
among them which the domain can lay now become its turnouts when the map is first opened.

- A switch or a double switch of the editor becomes a turnout where its record names a type of the catalogue (its type, rail, radius, ratio
  and a, b of an ordinary or a symmetric one; the first of the catalogue's order where a movable nose is the only difference, which the
  record doesn't keep), its start lies on a line made of an alignment within a centimetre and its direction along the line or against it,
  and its main track is bent as the record says the line is there (straight, or the radius within 5 %). It's laid into the line by the
  command insert_turnout, the hand of the record, with edit_policy::no_new_block: the old line may break the norms where nobody touched
  it, the turnout may add no BLOCK finding to it.
- Its record goes on its own into the project with the main track of the turnout (as an //$h record keeps the line it became); the rest of
  the block stays as written, the comments with it, why each switch didn't become a turnout with it: a slip or a crossing (their records
  don't tell the side of the crossing track), a connection (the solver of the connections lays it anew), a lifted outer track, no type of
  the catalogue, no line under it, a bending other than the line's, or the reasons the command refused it for. A block none of whose
  switches became one is kept as before, with the reasons.

Tests: U: an alignment of data/records with five //$r lines: two switches on its straight, along it and against it, to the left and to
the right, made turnouts of their types at their starts (the structure whole, no reason); one beside the line, one of no type of the
catalogue and a connection kept in the block with the comment, each with why; the two records each with the main track of its turnout;
the project written and read back the same. The records of data/records and of the map of data/project/migration (no switch on a line)
kept whole as before. Unit tests 1096 -> 1097.
This commit is contained in:
maj00r
2026-11-23 14:49:14 +01:00
parent efcc28b0ed
commit 84dca7cccb
3 changed files with 254 additions and 2 deletions
+68
View File
@@ -9,10 +9,12 @@
#include "editor/editorAlignment.hpp"
#include "editor/editorRecords.hpp"
#include "editor/project/projectMigration.hpp"
#include "layout_fixture.h"
#include <filesystem>
#include <fstream>
#include <iterator>
#include <map>
#include <string>
namespace {
@@ -245,3 +247,69 @@ TEST_CASE("project migration: a map opened for the first time gets its project o
CHECK(project::same(*again.project.project, project));
round_trip(project);
}
TEST_CASE("project migration: the //$r switches on the lines made of the alignments become turnouts, the rest kept as written with why") {
// the first alignment of data/records: a straight north for 570 m, then a curve to the east; switches on its straight both ways, one
// beside it, one of no type of the catalogue and a connection
auto alignment{file_text(std::string{EU07_UNIT_TESTS_DATA} + "/records/alignment.scn")};
// up to the end of its record, not to its ends
auto const end{alignment.find("//$h end\r\n") != std::string::npos ? alignment.find("//$h end\r\n") : alignment.find("//$h end\n")};
REQUIRE(end != std::string::npos);
alignment = alignment.substr(0, end + 8) + "\n";
std::vector<std::string> const switches{
"switch z1 Rz 60E1 500.000 12.000 L 20.797 20.797 0.000 parts 1 z1 start 0.0000 0.0000 200.0000 dir 0.000000000 1.000000000 km - number - source designed",
"switch z2 Rz 60E1 190.000 9.000 R 10.523 16.615 0.000 parts 1 z2 start 0.0000 0.0000 450.0000 dir 0.000000000 -1.000000000 km - number - source designed",
"switch z3 Rz 60E1 500.000 12.000 L 20.797 20.797 0.000 parts 1 z3 start 50.0000 0.0000 300.0000 dir 0.000000000 1.000000000 km - number - source designed",
"switch z4 Rz 60E1 777.000 13.000 L 1.000 1.000 0.000 parts 1 z4 start 0.0000 0.0000 100.0000 dir 0.000000000 1.000000000 km - number - source designed",
"connection c1 Rz 60E1 500.000 12.000 R 20.797 20.797 0.000 parts 2 c3 c4 start 0.0000 0.0000 350.0000 dir 0.000000000 1.000000000 km - number - source designed",
};
std::string text{alignment + "//$r # switches placed in the track editor, the simulation skips these lines\n"};
for (auto const &line : switches) {
text += "//$r " + line + "\n";
}
auto const migrated{project::migrate({{"switches.scn", {}, project::marked_lines(text)}})};
CAPTURE(notes_of(migrated.notes));
auto const &project{migrated.project};
auto const &network{project.network};
REQUIRE(network.turnouts().size() == 2);
// the old design breaks the norms in its curve, which the turnouts may not add to (edit_policy::no_new_block)
test::layout_fixture::check_structure(network);
CHECK(layout::check_all(network).reasons.empty());
// the two on the straight: their types, hands and ways along the line, their starts where the records put them
std::map<std::string, layout::turnout const *> by_type;
for (auto const &[id, turnout] : network.turnouts()) {
by_type[turnout.type] = &turnout;
}
REQUIRE(by_type.contains("Rz 60E1-500-1:12"));
REQUIRE(by_type.contains("Rz 60E1-190-1:9"));
auto const &first{*by_type.at("Rz 60E1-500-1:12")};
auto const &second{*by_type.at("Rz 60E1-190-1:9")};
CHECK(first.hand == 1);
CHECK(first.direction == 1);
CHECK(second.hand == -1);
CHECK(second.direction == -1);
CHECK(glm::distance(geometry::plan_of(network.find(first.start)->position), glm::dvec2{0.0, 200.0}) < 1e-9);
CHECK(glm::distance(geometry::plan_of(network.find(second.start)->position), glm::dvec2{0.0, 450.0}) < 1e-9);
// each a record of its own with its main track; the rest of the block kept as written, why with it
std::vector<project::legacy_record const *> records;
for (auto const &record : project.legacy) {
if (record.mark == 'r') {
records.push_back(&record);
}
}
REQUIRE(records.size() == 3);
auto const &kept{*records[0]};
CHECK(kept.line == line_id::none);
CHECK(kept.lines == std::vector<std::string>{"# switches placed in the track editor, the simulation skips these lines", switches[2], switches[3], switches[4]});
CAPTURE(kept.why);
CHECK(kept.why.find("z3: Rz 60E1-500-1:12: its start lies on no line of the domain") != std::string::npos);
CHECK(kept.why.find("z4: no Rz of the catalogue") != std::string::npos);
CHECK(kept.why.find("c1: a connection of switches") != std::string::npos);
CHECK(records[1]->lines == std::vector<std::string>{switches[0]});
CHECK(records[1]->line == first.main);
CHECK(records[2]->lines == std::vector<std::string>{switches[1]});
CHECK(records[2]->line == second.main);
// all of the lines of the block in the project, written and read back the same
CHECK(editor_records::read_switches(kept.lines, {}, 0).size() == 3);
round_trip(project);
}