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 9c76001e9a feat(editor): the project file of the track geometry, one per map, of a schema of its own
The first part of E3 (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. editor/project/projectFile reads and writes it, nothing else does; nothing of the editor uses it yet.

- <map>.eu07proj next to the file of the map, shared by the scenarios of the map; plain text, a line a record, the version of the
  schema on the first line. Version 1:
    eu07proj 1
    next node 9 line 8 vertex 1 turnout 3
    norms plk
    area granica ch 4 -500 0 -100 0 -100 400 -500 400
    lineprofile 91 en13803
    class 1 vmax 80 vmin 0 traffic mixed track main load 5 features 0
    node 3 at 300 101.2 0 heading 1 0 curvature 0 cant 0 grade 0.004 ends 3 1 end 1 2 start 1 4 start 1
    line 1 from 1 to 3 class 1 chainage 0 transition clothoid ramp linear continues 0 0 turnout 0 profile tsi
    vertex 2 at 0 800 radius 300 in 60 out 60 cant 40
    grade 200 101.5 5000
    end
    turnouts
    turnout 1 type Rz%2060E1-500-1:12 hand 1 direction 1 start 3 main 2 4 diverging 4 5 chainage 300 radii 0 500 cant 0
      speeds 80 60 velocity -60 movable 0
    end
    anchors ... end                      kept for E6 as read, empty in version 1
    generated ... end                    the tracks the generator wrote (the next commit)
    legacy h trasa/tory.scm line 1 [why ...] / | <the //$ line> / end    the //$ lines read when the map was first opened
  The profile of the scenery, the areas and the lines by name; the classes of the lines, each one once, the lines naming theirs; the
  nodes with all they hold, the ends in their order; the lines with their vertices, grade breaks, shapes, chainage, turnout and
  profile of their own; the turnouts of E2b with their legs, their tracks and what they derive. Numbers in the shortest form which
  reads back to the same double, names and files with %20 for a blank.
- Read: the lines laid between their nodes as read, then the diverging tracks laid by their turnouts off the main tracks, the nodes
  and the turnouts as written; what refers to what checked (a line's ends held once by its nodes, the classes there, the turnouts and
  their tracks each of the other); a file of a newer schema refused before anything of it is read, with the reason, as is one which
  isn't a project file, has a record not of its version or a section not ended. Saved through a file next to it put in its place.
- The identifiers handed out are kept (next), so none is handed out again after a load, whatever was deleted before the save:
  layout::network gets handed() and hand_out(), the turnouts' counter with them; nothing else of editor/layout changes.

Tests: G: a network edited by the model (a line deleted between two) written, read and written again: the same text, the lines laid
again the same to the bit as the model laid them; two turnouts, one against the line, and a line of a profile of its own: the same to
the bit, the diverging tracks too (the network as settle() leaves it: the model lays the diverging track of a turnout against the line
before the node at its start takes the grade of the line beyond it, 1e-16 off); the golden file of data/project/ read and written back
the same, with the line ends of windows too; the anchors kept as read. A newer schema, an empty file, not a project file, broken
records (a turnout whose track isn't its among them) refused cleanly. U: the identifiers after the last line is deleted, a save and
a load: the next line, its nodes and its vertices numbered past them.
2026-11-23 13:11:45 +01:00

120 lines
5.7 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>
// 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>
// end the turnouts (E2b), their tracks lines of them; the diverging ones 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