17
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-11-02 06:59:13 +01:00

feat(editor): the kilometrage tool leads a line through a station along the tracks chosen, the straight paths of the switches by default, from the track chosen on along them until the line meets its tracks again or on and away at a junction, kept as //$k via lines; a track beside that comes back onto the line between the stretches it runs beside it or both ways is a track of a station, not the other track of a double-track line

This commit is contained in:
maj00r
2026-10-22 14:16:42 +02:00
parent 5ecb6ebe00
commit 7cc8e5bb9a
10 changed files with 533 additions and 38 deletions

View File

@@ -9,9 +9,11 @@ http://mozilla.org/MPL/2.0/.
#pragma once
#include <algorithm>
#include <cstddef>
#include <optional>
#include <string>
#include <utility>
#include <vector>
#include <glm/glm.hpp>
@@ -22,7 +24,8 @@ class TTrack;
// the kilometrage of the railway lines, set in the track editor and kept in the scenery files as "//$k" comment lines: the
// points of a line where its km is known, from a post or a document, and the points where it jumps, with the km on both
// sides. the km run along the axis of a single-track line and between the tracks of a double-track one, along the longer track
// where the tracks part on formations of their own (PKP GK-1 6.1.12), the other tracks get the km straight across from them
// where the tracks part on formations of their own (PKP GK-1 6.1.12), the other tracks get the km straight across from them.
// through a station the line runs along the straight paths of the switches, unless the tracks it runs along there are set
namespace kilometrage
{
@@ -35,20 +38,38 @@ struct mark
double km{0.0}; // the km the point is reached at, coming along the rising km
std::optional<double> beyond; // of a jump: the km on from the point
};
// a track a line runs along through a station, other than the one the straight paths of the switches lead it along: from it
// the line goes on along the straight paths until it meets the rest of it again, or on and away where it doesn't
struct via
{
scene::layer_handle layer{null_handle};
std::string line;
glm::dvec3 point{0.0}; // on the axis of the track, of the path of a switch the line takes
};
// all of the kilometrage set, for the undo history
struct state
{
std::vector<mark> marks;
std::vector<via> vias;
};
void reset();
void load();
std::vector<mark> const &marks();
std::vector<via> const &vias();
state current();
// a new mark, kept in the file of the layer of the track nearest to it
void put(mark Entry);
void change(std::size_t const Index, mark Entry);
void remove(std::size_t const Index);
// the marks as they were before the changes made since the last call, if there were any; the current ones become the base
std::optional<std::vector<mark>> take_changes();
// the current marks become the base, the changes made so far aren't a part of the undo history
void put(via Entry);
void remove_via(std::size_t const Index);
// the kilometrage as it was before the changes made since the last call, if there were any; the current one becomes the base
std::optional<state> take_changes();
// the current kilometrage becomes the base, the changes made so far aren't a part of the undo history
void settle();
// puts the marks back as they were, for undo and redo
void restore(std::vector<mark> Marks);
// puts the kilometrage back as it was, for undo and redo
void restore(state State);
// the axes found are dropped when the tracks change: Edits counts the changes of the tracks made in the editor
void follow(std::size_t const Edits);
// counts the times the axes were dropped: what is made from them is made again when it changes
@@ -86,6 +107,9 @@ struct axis
std::vector<side> sides;
std::vector<anchor> anchors; // by the chainage
std::vector<std::size_t> astray; // the marks of the line away from its axis
std::vector<std::size_t> blocked; // the vias of the line it doesn't run along: no track of theirs, or another via led it elsewhere
std::vector<std::pair<TTrack const *, int>> paths; // the paths of the tracks the line runs along, of the track beside too
bool runs_along(TTrack const *Track, int const Path) const { return std::find(paths.begin(), paths.end(), std::make_pair(Track, Path)) != paths.end(); }
double length() const { return chainage.empty() ? 0.0 : chainage.back(); }
};
// the numbers of the lines with marks
@@ -105,6 +129,10 @@ double km_on(axis const &Axis, axis::side const &Side, double const Along);
bool km_at(std::string const &Line, glm::dvec3 const &Point, double &Km, double const Reach = 30.0);
// the track nearest to the point in the plan within the reach, nullptr for none
TTrack *track_near(glm::dvec3 const &Point, double const Reach);
// the path of the track nearest to the point in the plan, On: the point of it nearest
int path_near(TTrack const &Track, glm::dvec3 const &Point, glm::dvec3 &On);
// the track with a path nearest to the point within the reach, nullptr for none, Path: the path
TTrack *track_near(glm::dvec3 const &Point, double const Reach, int &Path);
// "100,234", as PKP PLK write the km
std::string text(double const Km);