18
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-12-01 21:07:06 +01:00

feat(editor): the joints of old tracks as hard points of the pieces, the names, events and circuits of the old tracks kept by the lines

E6 (editor-tracks-domain.md §5 "Podział na kawałki zachowuje miejsca...", §10 "Stare złącza jako twarde punkty podziału"), the hook of the
generator E2a left (generator_options::hard_splits, a line given any refused).

- A line keeps the old tracks it was taken over from (line::hard_splits): where along it the stretch of each begins, its name, the words of
  its entry before the path (the width, the friction, ... the visibility and the materials) and after it (the speed, the events, the
  isolated circuits and the rest), whether it ran against the line. In the line rather than in the options of the generator, so a command
  which cuts or joins lines carries them and an undo puts them back: a line cut (split_line, a turnout laid into it) gives those past the
  cut to the part after it, and the old track cut in two keeps its name and its events on the part it ran into first, the other part a
  stretch of it the generator names (continued); two lines joined, the second one's after the first one's.
- The generator ends the pieces at each joint inside the line (a joint stays, a break of the elements next to it gives way) and writes the
  pieces of a stretch as the old track was: its name on the piece it ran into first with all its attributes, <name>_2, <name>_3... on the
  others with them but its events (an event of a track is called once), its surface, the path written the way it ran (event1 and event2,
  the sign of the rolls); an old track of no name named by the generator, its events kept. A line with none is made as before.
- The project file: "old <chainage> <name> reversed <0|1> continued <0|1> surface <words> attributes <words>" in the block of a line;
  version 1, unreleased, read as before without them.

Tests: G: a line of three curves given three old tracks (one named with its events and its circuit, one of no name, one which ran against
the line): the pieces end at the joints, each name once, the attributes of the first on its first piece and without its event on the
others, the event of the unnamed one once, the one which ran against the line written from the end of the line; written into the project
file and read back the same. It takes the place of the E2a case of the hook refusing. Unit tests 1103 -> 1103.
This commit is contained in:
maj00r
2026-11-23 16:38:09 +01:00
parent 3f5f2af1ce
commit d87da1c476
7 changed files with 224 additions and 39 deletions
+43 -10
View File
@@ -8,6 +8,7 @@
#include "layout_fixture.h"
#include "track_text.h"
#include "editor/layout/layoutGenerator.hpp"
#include "editor/project/projectFile.hpp"
#include <algorithm>
#include <set>
@@ -302,16 +303,48 @@ TEST_CASE("layout generator: the names come from the ids of the line and its ver
CHECK(layout::generate(model.state(), id).text() == after.text());
}
TEST_CASE("layout generator: the joints of old tracks as hard points of the pieces are stage E6, a line given them isn't made") {
TEST_CASE("layout generator: the joints of old tracks as hard points of the pieces, their names, attributes and the way they ran kept") {
auto const model{laid(three_curves())};
auto const id{model.state().lines().begin()->first};
layout::generator_options options;
options.hard_splits[id] = {{350.0, "old_track"}};
auto const made{layout::generate(model.state(), id, options)};
CHECK(made.pieces.empty());
REQUIRE(made.errors.size() == 1);
CHECK(made.errors.front().find("E6") != std::string::npos);
std::vector<std::string> errors;
CHECK(layout::generate_all(model.state(), {}, errors).find("endtrack") != std::string::npos);
CHECK(errors.empty());
auto network{model.state()};
auto &line{const_cast<layout::line &>(*network.find(id))};
auto const length{line.solved.length};
// three old tracks: one of a name with its events and circuit, one of none, one of a name which ran against the line
layout::old_track first{"tor_a", "1.435 0.25 25.0 20 0 flat vis rail 4 bed 0.2 0.5 1.1", "velocity 60 event1 ev_a isolated obw_a", false, false};
layout::old_track second{"", "", "velocity 70 event2 ev_b", false, false};
layout::old_track third{"tor_c", "", "velocity 80 event1 ev_c", true, false};
line.hard_splits = {{0.0, first}, {350.0, second}, {length - 100.0, third}};
auto const made{layout::generate(network, id)};
REQUIRE(made.errors.empty());
// the pieces end at the joints
auto const ends_at = [&](double const Chainage) { return std::ranges::any_of(made.pieces, [&](layout::generated_piece const &Piece) { return std::abs(Piece.to - Chainage) < 1e-9; }); };
CHECK(ends_at(350.0));
CHECK(ends_at(length - 100.0));
std::map<std::string, std::string> texts;
for (auto const &piece : made.pieces) {
CHECK(texts.emplace(piece.name, piece.text).second);
}
// the first old track: its name on its first piece with all of its attributes, the others numbered on without its events
REQUIRE(texts.contains("tor_a"));
CHECK(texts["tor_a"].find("1.435 0.25 25.0 20 0 flat vis rail 4 bed 0.2 0.5 1.1") != std::string::npos);
CHECK(texts["tor_a"].ends_with(" velocity 60 event1 ev_a isolated obw_a endtrack\n"));
for (auto const &[name, text] : texts) {
if (name.starts_with("tor_a_")) {
CHECK(text.ends_with(" velocity 60 isolated obw_a endtrack\n"));
}
}
// of no name: named by the generator, its events on the first piece only
auto const events_b{std::ranges::count_if(texts, [](auto const &Each) { return Each.second.find("event2 ev_b") != std::string::npos; })};
CHECK(events_b == 1);
// the last one ran against the line: its piece written from the end of the line, the named one where it started
REQUIRE(texts.contains("tor_c"));
auto const named_c{std::ranges::find_if(made.pieces, [](layout::generated_piece const &Piece) { return Piece.name == "tor_c"; })};
CHECK(std::abs(named_c->to - length) < 1e-9);
CHECK(named_c->path.points[segment_data::point::start] == network.find(line.end)->position);
// written and read back as the line has them
project::document project;
project.network = network;
auto const read{project::read(project::write(project))};
REQUIRE(read.project.has_value());
CHECK(read.project->network.find(id)->hard_splits == line.hard_splits);
}