mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-12-01 18:47:06 +01:00
075a66d169
editor-project-setup.md: a new user drew with no word of what: the norms, the speed, the gauge and the rail lay about the panels, set on the way. Now one short step, "What do you draw?" (Co rysujesz?), one screen of defaults and one button: - The fields: the norms (PLK ST-T1-A6, TSI alone, EN 13803, CH; PLK by default, no "none": a fictional scenery has a profile too), the speed of the line (chips 40..200, 100 km/h), the traffic, a main or a side track, the gauge (1435 / 1520 / 1000 / 750 / 600 mm), the rail (60E1 / 49E1 / S42), the look of the tracks under More (the rails and the trackbed as now where left empty). application/editorsetupui.* draws them for all three places below. - Asked for as the last step of the wizard of a new scenery (4., or 2. for a fictional one; its button Start: create and open in the editor), which writes them into the new scenery; and in a scenery with none, as a card in the inspector of the tracks in place of the first steps, until its Start. Changed later in their window, Assumptions of the project, from the editor settings or the line of them under the first steps in Tracks; a change checks the lines laid before against them, the report in the window of the norms, nothing laid changed by it. - Kept with the map (editor/editorProjectSetup.*, one record "setup norms plk speed 100 traffic mixed track main gauge 1435 rail 60E1"): in its project file where it has one (a record of its own; the profile of the scenery the model judges by set with it), else in the scenery as //$u lines, which the simulator skips and the scene layers keep as a mark of the editor. Read when the map is opened, the project file first. A scenery saved without them holds nothing new. - The defaults of the tools from them: the speed of the laying and of the route design, the gauge and the rails and the trackbed of the tracks laid, the norms checked against, the rail of the switch tool and the usual switch of the rail for the speed on its diverging track (the closest speed, the ratio usual for it). A route with no speed of its own takes the speed of the assumptions. Self-test: setup [<key> <value>]..., setupwindow [close]; expect setup none|<key> <value>, expect setupmark <present|absent>, expect layspeed <km/h>. The cases ps_1_setup_saved (set, saved into the scenery, read back after a reopen) and ps_2_setup_project (into the project file with the editing on the model, read from there after a reopen with it off). Tests: U: the record written and read back, the defaults, what it can't read, the class of the line, kept in the project file. lang/editor_pl.po: the Polish of the new texts.
239 lines
8.9 KiB
C++
239 lines
8.9 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/layoutConnection.hpp"
|
|
#include "editor/layout/layoutNetwork.hpp"
|
|
|
|
#include <optional>
|
|
#include <string>
|
|
#include <variant>
|
|
#include <vector>
|
|
|
|
// The edits of the track geometry (editor-tracks-domain.md §4, "Edycja = polecenie"; §8): each one is a command which proposes a new
|
|
// state of the lines, the nodes and the turnouts it touches; what depends on them is laid again, the topology, the rules of the turnouts
|
|
// and the norms are checked (the module of the norms: BLOCK refuses, WARN and PREFER are told), and the change is kept whole or refused
|
|
// with the reasons, the state left as it was. Each one kept is one step to undo, what it touched restored as it was.
|
|
namespace layout
|
|
{
|
|
|
|
// a line laid between two new nodes, its vertices given with their radii, transitions and cants (the ids are given to them); or going on
|
|
// from the free end of another line, or ending at one: the node of that end shared, its place the node's, the line leaving it along the
|
|
// heading of the node or against it as its first leg does (which has to lie on the tangent of the node)
|
|
struct create_line
|
|
{
|
|
glm::dvec3 start{0.0};
|
|
glm::dvec3 end{0.0};
|
|
std::vector<vertex> vertices;
|
|
std::vector<grade_break> grades;
|
|
transition_shape transition{transition_shape::clothoid};
|
|
ramp_shape ramp{ramp_shape::linear};
|
|
norms::line_class category;
|
|
double chainage_start{0.0};
|
|
node_id start_node{node_id::none}; // a free end the line goes on from, none: a new node at start
|
|
node_id end_node{node_id::none}; // a free end the line ends at, none: a new node at end
|
|
};
|
|
|
|
// the vertex moved in the plan
|
|
struct move_vertex
|
|
{
|
|
line_id line{line_id::none};
|
|
vertex_id vertex{vertex_id::none};
|
|
glm::dvec2 point{0.0};
|
|
};
|
|
|
|
// the radius, the transitions, the cant or the place of the vertex, those given: a curve moved and changed at once is one edit
|
|
struct set_vertex
|
|
{
|
|
line_id line{line_id::none};
|
|
vertex_id vertex{vertex_id::none};
|
|
std::optional<double> radius;
|
|
std::optional<double> transition_in;
|
|
std::optional<double> transition_out;
|
|
std::optional<double> cant;
|
|
std::optional<glm::dvec2> point;
|
|
};
|
|
|
|
// the line cut at the chainage by a new node: the part before it keeps the line, the part after it is a new line; the track stays as
|
|
// it was. Inside a curve the parts go on from the node at its curvature and cant; not inside a vertical curve, nor inside a transition
|
|
// curve which isn't a clothoid with a straight cant ramp, whose parts aren't curves of their kind
|
|
struct split_line
|
|
{
|
|
line_id line{line_id::none};
|
|
double chainage{0.0};
|
|
};
|
|
|
|
// a new line laid between two free ends, solved between the nodes: a straight where they face each other on one, a curve where their
|
|
// tangents meet, two curves otherwise. The radius 0 takes the largest the norms prefer which fits, the transition and the cant below 0
|
|
// the ones the norms prefer for the radius. An end in a curve (a line cut inside one) has the new line go on from its curve: the curve
|
|
// where the tangents meet begins right at it, its arc or a transition from its curvature, and the transition at the other end long
|
|
// enough for the curve to fit
|
|
struct join_ends
|
|
{
|
|
node_id from{node_id::none};
|
|
node_id to{node_id::none};
|
|
double radius{0.0};
|
|
double transition{-1.0};
|
|
double cant{-1.0};
|
|
};
|
|
|
|
// the line taken away; a node left with no end goes with it
|
|
struct delete_line
|
|
{
|
|
line_id line{line_id::none};
|
|
};
|
|
|
|
// a vertex put into the line after the one given (none: after its start), its radius, transitions and cant with it (the id is given to it)
|
|
struct insert_vertex
|
|
{
|
|
line_id line{line_id::none};
|
|
vertex_id after{vertex_id::none};
|
|
vertex shape;
|
|
};
|
|
|
|
// the vertex taken out of the line: the tangents of its neighbours meet with no curve of it
|
|
struct remove_vertex
|
|
{
|
|
line_id line{line_id::none};
|
|
vertex_id vertex{vertex_id::none};
|
|
};
|
|
|
|
// the grade line of the line: its breaks with their heights and vertical radii, from its start
|
|
struct set_grades
|
|
{
|
|
line_id line{line_id::none};
|
|
std::vector<grade_break> grades;
|
|
};
|
|
|
|
// the class of the line: its speed, its traffic, main or side track
|
|
struct set_line_class
|
|
{
|
|
line_id line{line_id::none};
|
|
norms::line_class category;
|
|
};
|
|
|
|
// the profile of the norms of the line's own, none: the one of the area it lies in
|
|
struct set_line_profile
|
|
{
|
|
line_id line{line_id::none};
|
|
std::optional<norms::profile_id> profile;
|
|
};
|
|
|
|
// a turnout of the type of the catalogue laid into the line, its start at the chainage: the line cut at its legs, the part between them its
|
|
// main track, its diverging track leaving it to the hand (1 left, -1 right) as it runs from its start, along the line (direction 1) or
|
|
// against it (-1); bent as the line under it is. Refused with the reasons where a rule of the turnouts or a BLOCK limit of the norms is broken
|
|
struct insert_turnout
|
|
{
|
|
line_id line{line_id::none};
|
|
double chainage{0.0};
|
|
std::string type;
|
|
int hand{1};
|
|
int direction{1};
|
|
};
|
|
|
|
// the turnout moved along its line by the distance, above 0 toward the end of its main track: the lines on both sides of it one line again
|
|
// and cut at its legs anew, the line going on from the end of its diverging track carried with it there; checked as when laid
|
|
struct move_turnout
|
|
{
|
|
turnout_id turnout{turnout_id::none};
|
|
double distance{0.0};
|
|
};
|
|
|
|
// the turnout of another type of the catalogue, its start where it is; the hand changed where given
|
|
struct change_turnout
|
|
{
|
|
turnout_id turnout{turnout_id::none};
|
|
std::string type;
|
|
std::optional<int> hand;
|
|
};
|
|
|
|
// the turnout taken out: its diverging track goes, the end of it with it where no line goes on from there; its main track and the lines
|
|
// on both sides of it laid as one line again where they can be
|
|
struct remove_turnout
|
|
{
|
|
turnout_id turnout{turnout_id::none};
|
|
};
|
|
|
|
// lines laid as they were recognized from old tracks (stage E6, layoutLegacy.hpp), one step: each between two new nodes at the ends of its old
|
|
// tracks, its vertices (their ids given), its grade line and the old tracks along it as given. The norms don't refuse it: an old track may
|
|
// break them where nobody touched it, and the BLOCK limits it passes are told (outcome::broken); the invariants refuse it as any edit
|
|
struct take_over
|
|
{
|
|
struct taken
|
|
{
|
|
glm::dvec3 start{0.0};
|
|
glm::dvec3 end{0.0};
|
|
line_shape shape;
|
|
norms::line_class category;
|
|
std::vector<hard_split> hard_splits;
|
|
};
|
|
std::vector<taken> lines;
|
|
};
|
|
|
|
// a crossover between two lines, as the solver of the connections plans it (layoutConnection.hpp): the two turnouts and the line between the
|
|
// ends of their diverging tracks, one step; refused with the best which fits where the norms can't be met
|
|
using command = std::variant<create_line, move_vertex, set_vertex, split_line, join_ends, delete_line, insert_vertex, remove_vertex, set_grades, set_line_class, set_line_profile, insert_turnout,
|
|
move_turnout, change_turnout, remove_turnout, connect_tracks, take_over>;
|
|
|
|
char const *command_name(command const &Command);
|
|
|
|
// how the norms refuse an edit: any BLOCK limit passed along the lines it touches, or only one it adds (an old track, which may break the
|
|
// norms where nobody touched it, stage E6): a BLOCK finding there before the edit, of the same parameter at the same place and no worse, isn't
|
|
// one it adds. The invariants refuse in any case
|
|
enum class edit_policy
|
|
{
|
|
refuse_block,
|
|
no_new_block
|
|
};
|
|
|
|
struct outcome
|
|
{
|
|
bool done{false};
|
|
std::vector<std::string> reasons; // why it was refused
|
|
std::vector<notice> notices; // what the norms warn of, or would prefer otherwise, on the lines changed
|
|
std::vector<notice> broken; // the BLOCK limits the old tracks a takeover laid as they are pass (stage E6): told, not refused
|
|
std::vector<line_id> lines; // made by it
|
|
std::vector<node_id> nodes;
|
|
std::vector<turnout_id> turnouts;
|
|
std::vector<vertex_id> vertices;
|
|
};
|
|
|
|
// the lines and the nodes with the commands which edited them, to undo and redo one by one
|
|
class model
|
|
{
|
|
public:
|
|
model() = default;
|
|
explicit model(norms::area_map Areas) { m_network.areas = std::move(Areas); }
|
|
// the lines, the nodes and the turnouts taken over as they are, the norms not asked: the tracks of an old scenery (stage E6)
|
|
explicit model(network Network) : m_network{std::move(Network)} {}
|
|
|
|
network const &state() const { return m_network; }
|
|
// the profile of the norms of the scenery, where no area nor a line has its own: the assumptions of the project changed, not an edit
|
|
void scenery_profile(norms::profile_id const Profile) { m_network.areas.scenery = Profile; }
|
|
outcome execute(command const &Command, edit_policy const Policy = edit_policy::refuse_block);
|
|
bool undo();
|
|
bool redo();
|
|
std::size_t undoable() const { return m_undo.size(); }
|
|
std::size_t redoable() const { return m_redo.size(); }
|
|
|
|
private:
|
|
struct step
|
|
{
|
|
std::string name;
|
|
snapshot before;
|
|
snapshot after;
|
|
};
|
|
network m_network;
|
|
std::vector<step> m_undo;
|
|
std::vector<step> m_redo;
|
|
};
|
|
|
|
} // namespace layout
|