18
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-12-02 00:22:42 +01:00
Files
maszyna/editor/layout/layoutAnchors.hpp
T
maj00r 10d3da2164 feat(editor): an old scenery read with no scene, its lineside objects anchored to the lines with a confidence, the anchors in the project file
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.
2026-11-23 16:59:29 +01:00

106 lines
4.6 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 "editor/editorInfra.hpp"
#include <cstdint>
#include <map>
#include <optional>
#include <string>
#include <vector>
#include <glm/glm.hpp>
// The anchors of the lineside objects (editor-tracks-domain.md §2 "Kotwica", §3 "Otoczenie", §10 "Powiązania otoczenia", stage E6): where an
// object stands along a line of the domain, its chainage, how far to the left of the line (below 0 to the right) and how high above it,
// its turn against the heading of the line there; so when the line changes, the object is put where it stands along the new one. The
// anchors of an old scenery are inferred for all the kinds of objects from where they stand and from the events and the memory cells which
// name the tracks, each with a confidence, the doubtful ones to be looked over; a wire (a traction piece) anchored by its four points and
// bound to the poles its ends hang on. The old binding of the editor (//$b) is the same mechanism along the paths of the tracks.
namespace layout
{
// a lineside object of a scenery, as its node has it
struct lineside_object
{
std::string kind; // model, traction, memcell, eventlauncher
std::string name; // of the node, empty for none
std::string key; // the file of a model, the power supply of a traction, the track of a memory cell; - for none
infra::category group{infra::category::other};
glm::dvec3 location{0.0}; // in the world
double yaw{0.0}; // degrees, of a model
std::vector<glm::dvec3> points; // a traction: the ends of its wires, as it has them (p1 p2 at the contact wire, p3 p4 above them)
std::vector<std::string> tracks; // the tracks which name it: a memory cell's own, those whose events act on it (made small)
std::string file; // where it's written, relative to the scenery folder
std::size_t line{0};
};
// a point along a line: its chainage, metres to the left of the line (below 0 to the right), above the line
struct anchor_point
{
double chainage{0.0};
double offset{0.0};
double height{0.0};
bool operator==(anchor_point const &) const = default;
};
struct anchor
{
std::uint32_t id{0};
// the object, as it was found: its kind, name, key and the location it stood at when it was anchored (to find it in the scene)
std::string kind;
std::string name;
std::string key{"-"};
infra::category group{infra::category::other};
glm::dvec3 location{0.0};
double yaw{0.0};
// where it stands along the line
line_id line{line_id::none};
anchor_point at;
std::vector<anchor_point> points; // a wire: its four points
double turn{0.0}; // degrees, its yaw against the heading of the line there
double confidence{0.0}; // 0 to 1
std::vector<std::string> reasons; // what the confidence rests on, or what makes it doubtful
std::vector<std::uint32_t> poles; // a wire: the anchors of the poles its ends hang on
bool operator==(anchor const &) const = default;
// confidence below this: to be looked over by the author before the object follows a change of its line
static constexpr double doubtful_below{0.6};
bool doubtful() const { return confidence < doubtful_below; }
};
// the anchors of the objects to the lines of the network, numbered from First: each to the line it stands by, as near as it is and as its
// events and memory cells name its tracks (Tracks: the lines the old tracks of the names, made small, became); the objects standing by no
// line left out. In the order of the objects
std::vector<anchor> infer_anchors(network const &Network, std::vector<lineside_object> const &Objects, std::map<std::string, line_id> const &Tracks, std::uint32_t const First = 1);
// where the anchored object stands along its line now: its location, yaw and points; none where its line is gone
struct placement
{
glm::dvec3 location{0.0};
double yaw{0.0};
std::vector<glm::dvec3> points;
};
std::optional<placement> place(network const &Network, anchor const &Anchor);
// the anchors following a change of the network from Before to After: an anchor whose line is there still keeps its chainage (on the
// length the line has now); one whose line is gone (split, joined, taken by a turnout) is anchored again where it stood before, to the line
// there now. The anchors whose objects move, with where to, in the order of the anchors; the anchors updated
struct moved
{
std::size_t anchor{0};
placement to;
};
std::vector<moved> follow(network const &Before, network const &After, std::vector<anchor> &Anchors);
} // namespace layout