mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-12-01 07:07:05 +01:00
10d3da2164
The rest of E6a (editor-tracks-domain.md §2 "Kotwica", §3 "Otoczenie", §9, §10 "Powiązania otoczenia ... z oceną pewności; wątpliwe pokazane do przejrzenia; przewody wiązane ze słupami"). - editor/project/legacyScenery: the tracks of the railway (normal and switch) and the lineside objects (models, wires, memory cells, event launchers) of a scenery read from the text of its files with their includes, as the simulator places them: the tracks and the wires moved by the origin only, the rest by the origin, the rotation and the scale (sceneryText now tells the placement in effect at each statement). The tracks naming an object: a memory cell's own, and those whose events (event0 to eventall2 of their entries, the events <track>:eventN) act on it, multiple events followed four deep. The kind of an object by its file and name, as the binding of the editor tells it (infra::classify). - editor/layout/layoutAnchors: an anchor puts an object along a line: its chainage, the offset to the left of the line (below 0 to the right), the height above it, its turn against the heading there; a wire by its four points, bound to the poles its ends hang on (a pole, or a model the names take for a part of the catenary, within 8 m of each end, along the same line). infer_anchors() anchors every object within 30 m of a line to the nearest one, with a confidence from 0 to 1 and the reasons for it: named by a track of a line, 0.95 at least (0.85 where another line is nearer, half of the fit where the line named isn't near); else how its distance fits its kind (a signal 0 to 6 m, a sign or a pole 1.5 to 8 m, a wire 0 to 1.5 m, equipment 0 to 3 m, logic and the rest 0 to 15 m, the environment at half), a third past the end of a line or 15 m above or below it, half where another line is as near within a metre, 0.8 for a sign, a signal or a pole turned more than 10 degree off square to the track; a wire on poles at both ends 0.9 at least, on none 0.7 of what it had. Below 0.6 doubtful, to be looked over. place() puts the object where it stands along its line now; follow() after a change of the network: an anchor whose line is there keeps its chainage, one whose line is gone (cut, joined, taken by a turnout) is anchored again where it stood, to the line there now; the anchors whose objects move, with where to. Moving the nodes of the scene, and taking the anchors back with an undo, is the editor's. - take_over_tracks() given the objects of the scenery anchors them to the lines it laid, the old tracks naming them by the lines they became, and lists the doubtful ones, with the deviations, for the question. - The project file: the anchors section, reserved and empty in version 1 so far, holds the anchors: "anchor <id> <kind> <name> <key> group <n> at <x y z> yaw <deg> line <id> chainage <m> offset <m> height <m> turn <deg> confidence <c> points <n> ... poles <n> ... [why <reasons>]". The schema stays 1: it's unreleased and the section was empty. - The //$b bindings of the old editor (the same mechanism along the paths of the tracks) aren't made anchors yet. Tests: G: data/takeover/old.scn, written by make_old.py (a line of 26 tracks with a curve of R 500 m, clothoids of 60 m and 80 mm, a break of the grade with no vertical curve, tracks of no name and written backwards, events and an isolated circuit; a switch at its end and a line on from each of its legs; a signal named by the events of a track and its memory cell, a pole every 50 m and the wires between them, hectometre posts, a tree 25 m off, a cabinet between two lines): read with no scene; its plain tracks taken over as three lines with no question, R 500 m, the clothoids and the cant read back within 1 and 5 %, the lines held at the legs of the switch in its headings, one step undone and done again the same; the tracks made again ending at the old joints, each old name once, the events and the circuit on their pieces, also after the curve was made 20 m wider; written into the project file and read back. The signal and its memory cell anchored with 0.9 or more, the poles with 1, every wire bound to its two poles, the tree and the cabinet doubtful; the curve made wider: the objects along it follow at their chainages and offsets, the signal on the straight before it stays; the anchors written into the project file and read back. The case of the project file which kept the section of the anchors as text reads and writes two anchors now. Unit tests 1104 -> 1108.
137 lines
5.3 KiB
C++
137 lines
5.3 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/layoutAnchors.hpp"
|
|
#include "editor/layout/layoutCommands.hpp"
|
|
#include "editor/layout/layoutRecognition.hpp"
|
|
#include "world/Segment.h"
|
|
|
|
#include <cstddef>
|
|
#include <optional>
|
|
#include <string>
|
|
#include <vector>
|
|
#include <glm/glm.hpp>
|
|
|
|
// The old tracks of a scenery taken over by the domain (editor-tracks-domain.md §10, stage E6): the tracks of the simulator which no line of
|
|
// the domain describes, chained the way a train runs them, each chain recognized as a line (layoutRecognition.hpp) and laid by one command
|
|
// of the model, the joints of the old tracks kept as hard points of its pieces (line::hard_splits) so their names, events and isolated
|
|
// circuits stay where they were. A switch, an old track which isn't taken over, a fork hold the end of a chain: the line runs on from it in
|
|
// its heading, the switch staying as it is (a fixed constraint), not cutting the line where nothing else does.
|
|
namespace layout
|
|
{
|
|
|
|
// an old track as the text of its entry has it, in the world: its name, its paths, the words of the entry before and after the paths
|
|
struct legacy_track
|
|
{
|
|
std::string name; // empty for none
|
|
bool is_switch{false};
|
|
std::vector<segment_data> paths; // a switch: the main path, then the diverging one, both from its start
|
|
std::string surface; // the words between the length and the paths: the width, the friction, ... the visibility and the materials
|
|
std::string attributes; // the words after the paths up to endtrack
|
|
std::string file; // where it's written, relative to the scenery folder
|
|
std::size_t line{0};
|
|
|
|
// the speed of the track, 0 where its entry has none
|
|
double velocity() const;
|
|
};
|
|
|
|
// a path of a chain of old tracks, run from its start (forward) or from its end
|
|
struct legacy_link
|
|
{
|
|
std::size_t track{0};
|
|
int path{0};
|
|
bool forward{true};
|
|
|
|
bool operator==(legacy_link const &) const = default;
|
|
};
|
|
|
|
// how a chain of old tracks ends: at a free end, held by what goes on from there and stays (a switch, an old track not taken over), or at a
|
|
// fork of more tracks than one
|
|
enum class legacy_end_kind
|
|
{
|
|
free,
|
|
held,
|
|
fork
|
|
};
|
|
|
|
struct legacy_end
|
|
{
|
|
legacy_end_kind kind{legacy_end_kind::free};
|
|
glm::dvec2 heading{0.0, 1.0}; // held: into the chain at its start, out of it at its end
|
|
std::optional<std::size_t> by; // the track holding it
|
|
};
|
|
|
|
struct legacy_chain
|
|
{
|
|
std::vector<legacy_link> links;
|
|
legacy_end start;
|
|
legacy_end end;
|
|
};
|
|
|
|
// m: the ends of the paths closer than this are joined, as the simulator joins them
|
|
inline constexpr double legacy_joint{0.02};
|
|
|
|
// the chains of the plain tracks of Take (indices of Tracks), each as far as the tracks run on one into the other: a track joined at an end to
|
|
// exactly one other plain track of Take goes on into it; a switch, a track not taken, a fork, a free end end it. Each runs from its end the
|
|
// smaller in x (then in z) to the other one, whichever track it was found from
|
|
std::vector<legacy_chain> walk_chains(std::vector<legacy_track> const &Tracks, std::vector<std::size_t> const &Take);
|
|
|
|
// the paths of the chain as the recognition takes them
|
|
std::vector<chain_path> paths_of(std::vector<legacy_track> const &Tracks, legacy_chain const &Chain);
|
|
|
|
struct takeover_options
|
|
{
|
|
recognition_options recognition;
|
|
norms::line_class category; // of the lines made; the speed the highest of the old tracks, where they have one
|
|
};
|
|
|
|
// a line the takeover makes of a chain of old tracks
|
|
struct taken_line
|
|
{
|
|
legacy_chain chain;
|
|
recognized_line fit;
|
|
std::vector<hard_split> hard_splits; // the old tracks along it
|
|
norms::line_class category;
|
|
bool silent{false}; // it keeps within the tolerance: taken over with no question
|
|
};
|
|
|
|
struct takeover_plan
|
|
{
|
|
std::vector<taken_line> lines;
|
|
takeover_tolerance tolerance;
|
|
std::vector<std::string> notes; // the tracks which can't be taken over, and why
|
|
measured_deviation worst; // the farthest any line of it keeps off its old tracks
|
|
bool silent() const;
|
|
// the command laying the lines
|
|
take_over command() const;
|
|
};
|
|
|
|
// the old tracks of Take chained and recognized as lines; nothing is laid
|
|
takeover_plan plan_takeover(std::vector<legacy_track> const &Tracks, std::vector<std::size_t> const &Take, takeover_options const &Options = {});
|
|
|
|
// what a takeover did: the outcome of the command, the deviation of each line it laid from its old tracks (in the order of the plan), and
|
|
// whether it was within the tolerance, which takes it over with no question asked; the anchors of the lineside objects by the lines it
|
|
// laid, the doubtful ones to be looked over
|
|
struct takeover_result
|
|
{
|
|
outcome made;
|
|
std::vector<measured_deviation> deviations;
|
|
measured_deviation worst;
|
|
bool silent{false};
|
|
std::vector<anchor> anchors;
|
|
std::vector<std::size_t> doubtful() const;
|
|
};
|
|
// the lines of the plan laid by one command of the model, one step to undo; the norms not refusing what the old tracks break (told in
|
|
// made.broken). The objects given (those of the scenery) anchored to the lines laid, named by their old tracks, numbered from First
|
|
takeover_result take_over_tracks(model &Model, takeover_plan const &Plan, std::vector<lineside_object> const &Objects = {}, std::uint32_t const First = 1);
|
|
|
|
} // namespace layout
|