mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-10-26 23:59:48 +01:00
164 lines
7.1 KiB
C++
164 lines
7.1 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 "application/editortool.h"
|
|
#include "editor/editorStation.hpp"
|
|
#include "scene/scenelayers.h"
|
|
|
|
#include "imgui/imgui.h"
|
|
|
|
#include <optional>
|
|
#include <string>
|
|
#include <unordered_set>
|
|
#include <utility>
|
|
#include <vector>
|
|
|
|
// the signalling of a station (SRK): the station found from a switch of it, its schematic, its name and code
|
|
class srk_tool final : public editor_tool
|
|
{
|
|
public:
|
|
srk_tool(editor_selection &Selection, editor_view &View, editor_history &History, editor_templates &Templates, editor_signals &Signals)
|
|
: m_selection{Selection}, m_view{View}, m_history{History}, m_templates{Templates}, m_signals{Signals}
|
|
{
|
|
}
|
|
void update() override;
|
|
void draw_overlay() const override;
|
|
void render_options() override;
|
|
void render_windows() override;
|
|
void forget(scene::basic_node const *Node) override;
|
|
editor_selftest_result selftest(std::string const &Command, std::istringstream &Words) override;
|
|
void set_open(bool const Open) { m_open = Open; }
|
|
// the stations described go to the files of their layers, as "//$s" lines
|
|
void store();
|
|
|
|
private:
|
|
editor_selection &m_selection;
|
|
editor_view &m_view;
|
|
editor_history &m_history;
|
|
editor_templates &m_templates;
|
|
editor_signals &m_signals;
|
|
// a station described: found again by a switch of it
|
|
struct record
|
|
{
|
|
scene::layer_handle layer{null_handle};
|
|
std::string anchor; // the name of a switch of the station
|
|
TTrack *track{nullptr}; // the switch, once found: it stays the anchor when it gets renamed
|
|
std::string code; // the abbreviation of the station, as MMz
|
|
std::string name;
|
|
std::string line; // the number of the railway line
|
|
std::string km; // of the axis of the station along the line, empty while unknown
|
|
bool reversed{false}; // the km rise to the left of the schematic, the switches numbered from there
|
|
};
|
|
// the schematic: the chainage across, the offsets upwards, exaggerated
|
|
struct view
|
|
{
|
|
double from{0.0};
|
|
double to{1000.0};
|
|
double centre{0.0};
|
|
float exaggeration{0.0f}; // 0: fit at the next draw
|
|
};
|
|
bool m_open{false};
|
|
bool m_strip{true}; // the schematic shown, off for the screenshots of the self-tests
|
|
bool m_loaded{false};
|
|
bool m_changed{false};
|
|
std::vector<record> m_records;
|
|
std::optional<station::layout> m_layout;
|
|
int m_record{-1}; // of the open station, -1 while it has none
|
|
TTrack *m_anchor{nullptr}; // the switch the open station was found from
|
|
bool m_reversed{false}; // the switches numbered from the right end of the schematic
|
|
std::size_t m_history_size{0};
|
|
TTrack const *m_picked{nullptr}; // the track selected when the station was looked for
|
|
view m_view_state;
|
|
int m_hover{-1}; // path of the layout under the mouse in the schematic
|
|
bool m_dragging{false};
|
|
std::vector<std::pair<std::string, std::size_t>> m_found; // the stations of the scenery: a switch and the count of them
|
|
struct circuit_mark
|
|
{
|
|
glm::dvec2 at{0.0}; // in the schematic
|
|
glm::dvec3 world{0.0};
|
|
std::string text;
|
|
ImU32 colour{0};
|
|
double length{0.0};
|
|
bool labelled{true}; // the circuits of the switches go without, named after them
|
|
};
|
|
std::vector<int> m_circuit_of; // of each path of the layout, an index into m_circuits, -1 for none
|
|
std::vector<circuit_mark> m_circuits;
|
|
std::vector<glm::dvec2> m_ticks; // the joints between the circuits, in the schematic
|
|
struct joint_mark
|
|
{
|
|
glm::dvec3 at{0.0};
|
|
glm::dvec3 across{0.0}; // of the track there, in the plan
|
|
};
|
|
std::vector<joint_mark> m_joints; // the same in the scenery
|
|
struct signal_mark
|
|
{
|
|
glm::dvec2 at{0.0}; // in the schematic
|
|
bool ahead{true}; // the trains it faces run along the chainage
|
|
std::string text;
|
|
glm::dvec3 head{0.0}; // above its lamps, in the scenery
|
|
};
|
|
std::vector<signal_mark> m_signal_marks;
|
|
bool m_signals_known{false}; // the signals standing surveyed, once their templates are found
|
|
std::vector<station::lengths> m_lengths; // of the station tracks, by their numbers
|
|
bool m_measured{false};
|
|
bool m_numbered{false}; // the station has tracks numbered by their circuits
|
|
int m_length_hover{-1}; // of the lengths, the row under the mouse
|
|
int m_length_canvas{-1}; // of the lengths, of the track under the mouse in the schematic
|
|
int m_length_shown{-1}; // of the lengths, the one drawn: of the row or the track under the mouse, else of the track selected
|
|
std::string m_status;
|
|
|
|
void load();
|
|
void open(TTrack &Track);
|
|
void refresh();
|
|
record &record_of_open();
|
|
std::string title() const;
|
|
void render_found();
|
|
void render_canvas(float const Height);
|
|
void fit_view(float const Width, float const Height);
|
|
void find_all();
|
|
// the switches numbered along the station and named after its code; one step of the history
|
|
void number_switches();
|
|
// the station cut at the joints of its track circuits and the circuits named; one step of the history
|
|
void set_circuits();
|
|
// the track circuits as the tracks have them, for the schematic
|
|
void survey();
|
|
// the signals placed where the station has none and the standing ones named, the circuits before the entry signals set too; one
|
|
// step of the history
|
|
void set_signals();
|
|
// the signals standing by the station, for the schematic
|
|
void survey_signals();
|
|
// the lengths of the station tracks, the signals given by them
|
|
void measure(std::vector<station::signal> const &Signals);
|
|
// the lengths of the station tracks as the list of the tracks gives them, the useful ones each way
|
|
void render_lengths();
|
|
// the lengths as a table to paste into a spreadsheet, a line a track, the columns parted by tabs
|
|
std::string lengths_table() const;
|
|
// of the lengths, the one of the station track the track is a part of, -1 for none
|
|
int length_of(TTrack const *Track) const;
|
|
// the signals of the lines out of the station: on a double-track line the block signals to the next station and the block
|
|
// sections between them, on a single-track one a warning disc before the entry signal; one step of the history
|
|
void set_lines();
|
|
// the names of the switches and the circuits of the open station begin with it, empty while it has no code
|
|
std::string stem_of_open() const;
|
|
// the km at the chainage of the open station: of the kilometrage of its line, else of its record, else of its switches; false
|
|
// while unknown
|
|
bool km_of_open(double const Chainage, double &Km) const;
|
|
// the km at the chainage of the open station, as the Kilometrage tool sets them for its line; false where it doesn't
|
|
bool km_of_line(double const Chainage, double &Km) const;
|
|
// the line of the open station: of its record, else the one the Kilometrage tool sets the km of through it; empty for none
|
|
std::string line_of_open() const;
|
|
// the station tracks by their numbers with their circuits as the tracks have them, Inside: the tracks of the circuits; false
|
|
// while it has none
|
|
bool station_tracks(std::vector<station::numbered> &Tracks, std::unordered_set<TTrack const *> &Inside) const;
|
|
// the circuits of the station track of the track renamed after another number; one step of the history
|
|
void renumber_track(TTrack const &Track, std::string const &Number);
|
|
};
|