mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-12-01 10:37:07 +01:00
555b77b11d
Continues E2 (editor-tracks-domain.md §4 "Edycja = polecenie", §8): the lines meet at nodes, and every edit is a command which proposes a new state, has what depends on it laid again, is checked and kept, or refused with its reasons and nothing changed. - layoutNetwork: the node, its place (the only coordinates of the ends of the lines), the heading, the curvature, the cant and the grade, and the ends of the lines meeting there, each with its sense along the heading; the network of the nodes and the lines with the profiles of the norms by place and the identifiers handed out once, never again (an undone line made again is a new one). A transaction keeps each line and node the first time it touches it, so a change is rolled back whole or recorded. - settle(): the lines touched laid again; the nodes take the values of their ends (a free end follows its line, a node keeps the curvature and the cant a line going on from it reads), a line going on from a node whose curve changed is laid again. - check(): the invariants of the touched lines and nodes: laid, at their nodes, two ends at most on the two sides of a node (more is a turnout, E5), the heading the same within 1e-9 rad, the cant within 0.5 mm, the grade within the 2 per mille that needs no rounding; and the norms along the chains through the touched lines (the lines running on through the nodes as one line, the elements running on alike across a node as one, a jump of the curvature at a node a step of the deficiency the profile judges): BLOCK refuses, WARN and PREFER are told as notices. - layoutCommands: create a line between two new nodes; move a vertex; set its radius, transitions or cant; split a line at a chainage (the track kept as it was: on a straight, in an arc, in a clothoid with a straight ramp, the parts going on from the new node at its curvature and cant; refused inside a vertical curve and inside a Bloss or cubic parabola transition); join two free ends with a line solved between them (a straight, a curve where the tangents meet, or two curves, the largest radius which fits with the cant and the transitions the norms prefer, a grade line meeting the grades of the ends); delete a line (a node left with no end goes). The model keeps the network and the steps: undo and redo restore the snapshots of the lines and nodes a command touched, one step a command. Tests: the cases of each command, a refusal (a radius under the least, a cant over the greatest, curves overlapping, transitions too long) leaving the state as it was, a WARN radius kept with its notice, undo and redo, the track the same along a line split on a straight, in an arc and in a clothoid, a middle part deleted and joined again both ways round, a straight joining two ends on one straight. P: 300 random edits each with the seeds 20261123, 7 and 450 (moved vertices, new radii, transitions and cants, splits, joins, deletions, undo, redo): after each the invariants checked on their own (each element running on from the last, the cant running on, the ends of the lines at their nodes to the bit, the heading, the cant and the grade running on through the nodes) and no BLOCK along any chain; a refused command leaves the state as it was, an undo gives the state before the command.
196 lines
6.8 KiB
C++
196 lines
6.8 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/layoutLine.hpp"
|
|
#include "editor/norms/norms.hpp"
|
|
|
|
#include <map>
|
|
#include <optional>
|
|
#include <set>
|
|
#include <string>
|
|
#include <vector>
|
|
#include <glm/glm.hpp>
|
|
|
|
// The lines and the nodes of the track geometry (editor-tracks-domain.md §4): the aggregates, their invariants and the checks of them.
|
|
// A node is the point the ends of the lines meet at: its place, the heading, the curvature, the cant and the grade there, and the ends
|
|
// meeting in it. The continuity of the track is the invariant of the node: the ends of its lines have its place by construction (a line
|
|
// has no coordinates of its own at its ends), and its heading, its cant and its grade within what the norms let pass; the curvature
|
|
// may change there only by a step of the cant deficiency the profile allows. Turnouts, whose legs are nodes too, come with stage E5;
|
|
// until then a node has two ends at most.
|
|
namespace layout
|
|
{
|
|
|
|
enum class line_end
|
|
{
|
|
start,
|
|
end
|
|
};
|
|
|
|
// an end of a line meeting at a node; the sense tells whether the line runs from there along the heading of the node or against it
|
|
struct end_ref
|
|
{
|
|
line_id line{line_id::none};
|
|
line_end end{line_end::start};
|
|
int sense{1};
|
|
|
|
bool operator==(end_ref const &) const = default;
|
|
// the side of the node the line lies on: 1 ahead of it, along its heading, -1 behind it
|
|
int side() const { return end == line_end::start ? sense : -sense; }
|
|
};
|
|
|
|
struct node
|
|
{
|
|
node_id id{node_id::none};
|
|
glm::dvec3 position{0.0}; // the scenery's x, the height, z
|
|
glm::dvec2 heading{0.0, 1.0}; // plan, unit
|
|
double curvature{0.0}; // 1/m along the heading, above 0 turning left
|
|
double cant{0.0}; // mm along the heading, above 0 leaning left
|
|
double grade{0.0}; // along the heading, above 0 rising
|
|
std::vector<end_ref> ends;
|
|
|
|
bool operator==(node const &) const = default;
|
|
};
|
|
|
|
struct line
|
|
{
|
|
line_id id{line_id::none};
|
|
node_id start{node_id::none};
|
|
node_id end{node_id::none};
|
|
line_shape shape;
|
|
// the curve next to the end goes on from the curve the node holds, beginning or ending right at it: a line split inside a curve
|
|
bool start_continues{false};
|
|
bool end_continues{false};
|
|
double chainage_start{0.0}; // m, the kilometrage of the start of the line
|
|
norms::line_class category;
|
|
// derived: the line laid between its nodes
|
|
solved_line solved;
|
|
|
|
bool operator==(line const &) const = default;
|
|
node_id node_at(line_end const End) const { return End == line_end::start ? start : end; }
|
|
bool continues(line_end const End) const { return End == line_end::start ? start_continues : end_continues; }
|
|
};
|
|
|
|
class transaction;
|
|
|
|
// the lines and the nodes of a scenery, with the profiles of the norms by place; identifiers given once and never again
|
|
class network
|
|
{
|
|
public:
|
|
node const *find(node_id const Id) const;
|
|
line const *find(line_id const Id) const;
|
|
std::map<node_id, node> const &nodes() const { return m_nodes; }
|
|
std::map<line_id, line> const &lines() const { return m_lines; }
|
|
// the same lines and nodes: the identifiers handed out so far aren't compared
|
|
bool same(network const &Other) const { return m_nodes == Other.m_nodes && m_lines == Other.m_lines; }
|
|
|
|
norms::area_map areas; // the profiles of the norms by place
|
|
|
|
node_id new_node() { return static_cast<node_id>(++m_last_node); }
|
|
line_id new_line() { return static_cast<line_id>(++m_last_line); }
|
|
vertex_id new_vertex() { return static_cast<vertex_id>(++m_last_vertex); }
|
|
|
|
// the end of the line meeting at its node, as the node keeps it
|
|
end_ref const *end_of(line_id const Line, line_end const End) const;
|
|
// how the end of the line meets its node, for laying the line
|
|
end_condition condition(line const &Line, line_end const End) const;
|
|
|
|
private:
|
|
friend class transaction;
|
|
std::map<node_id, node> m_nodes;
|
|
std::map<line_id, line> m_lines;
|
|
std::uint32_t m_last_node{0};
|
|
std::uint32_t m_last_line{0};
|
|
std::uint32_t m_last_vertex{0};
|
|
};
|
|
|
|
// the lines and nodes as they were before a change, or are after it: none where one didn't exist
|
|
struct snapshot
|
|
{
|
|
std::map<line_id, std::optional<line>> lines;
|
|
std::map<node_id, std::optional<node>> nodes;
|
|
};
|
|
|
|
// a change of the network in the making: each line and node it touches is kept as it was the first time, so the change can be taken
|
|
// back whole, or recorded for undoing and redoing
|
|
class transaction
|
|
{
|
|
public:
|
|
explicit transaction(network &Network) : m_network{Network} {}
|
|
network const &view() const { return m_network; }
|
|
network &ids() { return m_network; }
|
|
|
|
line &change(line_id const Id);
|
|
node &change(node_id const Id);
|
|
line &add(line Line);
|
|
node &add(node Node);
|
|
void erase(line_id const Id);
|
|
void erase(node_id const Id);
|
|
|
|
std::set<line_id> touched_lines() const;
|
|
std::set<node_id> touched_nodes() const;
|
|
snapshot before() const { return m_before; }
|
|
snapshot after() const;
|
|
// everything as it was before the transaction
|
|
void roll_back();
|
|
|
|
private:
|
|
network &m_network;
|
|
snapshot m_before;
|
|
};
|
|
|
|
// puts a snapshot in place: the lines and the nodes it has as it has them
|
|
void restore(network &Network, snapshot const &State);
|
|
|
|
// the lines touched laid again between their nodes, and what depends on them: the nodes take the heading, the curvature, the cant and the
|
|
// grade of the ends they hold (a node at a free end follows its line), and a line going on from a curve at a node whose curve changed is
|
|
// laid again
|
|
void settle(transaction &Change);
|
|
|
|
// a line running on through the nodes of two ends: the lines in their order, each forward or backward
|
|
struct chain_part
|
|
{
|
|
line_id line{line_id::none};
|
|
bool forward{true};
|
|
};
|
|
std::vector<chain_part> chain_of(network const &Network, line_id const Line);
|
|
// the chain described as one line for the norms: the elements running on alike across the nodes as one, the ends open
|
|
struct described_chain
|
|
{
|
|
norms::line line;
|
|
std::vector<double> starts; // the chainage each part starts at
|
|
};
|
|
described_chain describe_chain(network const &Network, std::vector<chain_part> const &Chain);
|
|
|
|
// what the norms found on a line changed
|
|
struct notice
|
|
{
|
|
line_id line{line_id::none};
|
|
double chainage{0.0}; // along the line
|
|
norms::finding finding;
|
|
std::string text;
|
|
};
|
|
|
|
struct verdict
|
|
{
|
|
std::vector<std::string> reasons; // what breaks an invariant or a BLOCK limit
|
|
std::vector<notice> notices; // WARN and PREFER
|
|
bool fine() const { return reasons.empty(); }
|
|
};
|
|
// the invariants of the touched lines and nodes, and the norms along the chains through the touched lines
|
|
verdict check(network const &Network, std::set<line_id> const &Lines, std::set<node_id> const &Nodes);
|
|
// the same over all of the network
|
|
verdict check_all(network const &Network);
|
|
|
|
// "cant deficiency 162 mm, the limit 150 mm (ST-T1-A6 tab. 9.4)"
|
|
std::string finding_text(norms::finding const &Finding);
|
|
|
|
} // namespace layout
|