18
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-12-01 05:57:08 +01:00
Files
maszyna/editor/project/projectFile.hpp
T
maj00r d87da1c476 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.
2026-11-23 16:59:27 +01:00

126 lines
6.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/.
*/
#pragma once
#include "editor/layout/layoutNetwork.hpp"
#include <cstdint>
#include <filesystem>
#include <optional>
#include <set>
#include <string>
#include <string_view>
#include <vector>
// The project file of the track geometry (editor-tracks-domain.md §9): the domain of the editor written next to the scenery, the
// .scn and .scm files staying what the simulator reads. One file per map, shared by its scenarios: <map>.eu07proj next to the file of
// the map. Plain text, a line a record, read and written here only; the schema version on the first line, a file of a newer one refused.
//
// Version 1:
// eu07proj 1
// next node <n> line <n> vertex <n> turnout <n> the identifiers handed out next; none is handed out again
// norms <profile> the profile of the scenery: plk, tsi, en13803, ch
// area <name> <profile> <count> <x z>... a profile for an area outlined in the plan
// lineprofile <name> <profile> a profile for a line by name
// class <n> vmax <km/h> vmin <km/h> traffic <passenger|mixed|freight> track <main|side> load <Tg> features <flags>
// node <id> at <x y z> heading <x z> curvature <1/m> cant <mm> grade <ratio> ends <count> {<line> <start|end> <sense 1|-1>}
// line <id> from <node> to <node> class <n> chainage <m> transition <clothoid|parabola|bloss> ramp <linear|bloss> continues <0|1> <0|1>
// turnout <id, 0 for a line of its own> profile <profile, - for the one of its place>
// vertex <id> at <x z> radius <m> in <m> out <m> cant <mm>
// grade <chainage> <elevation> <vertical radius>
// old <chainage> <name> reversed <0|1> continued <0|1> surface <words> attributes <words> an old track the line was taken over from
// (E6): where its stretch begins, its name, whether it ran against the line, whether it's
// a part a split cut off, the words of its entry before the path and after it
// end
// turnouts
// turnout <id> type <name> hand <1|-1> direction <1|-1> start <node> main <line> <node> diverging <line> <node> chainage <m>
// radii <main> <diverging> cant <mm> speeds <main> <diverging> velocity <km/h> movable <0|1>
// [second <node> <main track on> <diverging track> <node at its end>] a double switch: its second switch (E5)
// [crossing <line> <node> <node> slip <line, 0 for none>] a slip or a crossing: the crossing track, the second slip
// curve; the diverging track 0 0 of a crossing (E5)
// end the turnouts (E2b), their tracks lines of them; the ones they lay laid by the turnouts
// anchors ... end kept for the anchors of the lineside objects (E6), as read; empty in version 1
// generated
// track <name> line <id> file <file> sum <16 hex digits> a track written by the generator, the checksum of its text
// switch <name> line <id> file <file> sum <16 hex digits> the switch track of a turnout, by its main track
// hand <line> a line whose tracks were changed outside the editor, not written over
// end
// legacy <mark> <file> line <id> [why <the rest of the line>] //$ lines read when the map was first opened, as they were
// | <the line>
// end
// Lines starting with # are comments. The numbers are written in the shortest form which reads back to the same double; names and files
// with %20 for a blank and %25 for a percent sign.
namespace project
{
inline constexpr int schema_version{1};
inline constexpr std::string_view extension{".eu07proj"};
// a node of the simulator written by the generator: the name, the line it's made of (the main track of a turnout for its switch track),
// the file it's written into and the checksum of its text (checksum()), to tell a change made outside the editor
struct generated_node
{
std::string kind{"track"};
std::string name;
layout::line_id line{layout::line_id::none};
std::string file; // relative to the folder of the scenery, as the includes name it
std::uint64_t sum{0};
bool operator==(generated_node const &) const = default;
};
// the //$ lines of a kind read from a scenery file when the map was first opened (§9: they stay in the file until the author removes
// them): an //$h or an //$p record with the line it became, if it became one, and why not; the lines of the other kinds as a whole
struct legacy_record
{
char mark{'h'};
std::string file;
layout::line_id line{layout::line_id::none};
std::string why;
std::vector<std::string> lines; // the mark taken off
bool operator==(legacy_record const &) const = default;
};
struct document
{
layout::network network; // the lines, the nodes and the turnouts, the profiles of the norms by place, the identifiers handed out
std::vector<generated_node> generated;
std::set<layout::line_id> hand_changed;
std::vector<std::string> anchors; // the section reserved for the anchors of the lineside objects, kept as read
std::vector<legacy_record> legacy;
};
// the same contents: the lines and the nodes, the norms, the identifiers handed out and the rest
bool same(document const &A, document const &B);
std::string write(document const &Project);
struct read_result
{
std::optional<document> project;
std::string error; // why there's none: not a project file, a newer schema, a line it can't read
std::vector<std::string> notes; // the lines which can't be laid as they are written
};
// the lines are laid between their nodes as read; the nodes keep what's written of them
read_result read(std::string_view const Text);
// <map>.eu07proj next to the file of the map
std::filesystem::path path_of(std::filesystem::path const &Map);
read_result load(std::filesystem::path const &Path);
// written whole, through a file next to it put in its place, so a failed write leaves the old one; false with the reason in Error
bool save(document const &Project, std::filesystem::path const &Path, std::string &Error);
// the words of the file: a name with no blanks, %20 for a blank, %25 for a percent sign; - for none
std::string word(std::string_view const Text);
std::string unword(std::string_view const Word);
} // namespace project