17
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-10-17 03:59:19 +02:00

feat(editor): Signals mode of the Tracks window (H): semaphores, block, warning, shunting, stop, substitute signals and repeaters placed by the track from the templates of the scenery, described by //$e signal: (kind, mount, lamps, lean, the event the train reads them by) which tools/editor/signal_headers.py writes into them; a click by a track puts the signal on that side 2.25 m from the axis at the rail heads, facing the trains which have it on their right, a drag along turns it to the trains going the way of the drag; its (p1)_sem_info goes to event1 or event2 of the path, warning signals and repeaters, which the train doesn't read, get none; a head leaning away from the track swapped for its counterpart; the plate named like the signal; signals dragged along the track with their event, removed with it, renamed in the node properties with it, each a single step of the undo history; Polish translation

This commit is contained in:
maj00r
2026-10-08 03:12:16 +02:00
parent 4a7d839e5d
commit b02fe0ac2b
14 changed files with 1828 additions and 13 deletions

View File

@@ -251,6 +251,14 @@ bool parse(template_text const &Text, include_info &Info, std::string &Error)
Info.switch_hand = drive["hand"].as<std::string>("");
Info.switch_drive = drive["drive"].as<std::string>("");
}
if (auto const signal{document["signal"]}; signal.IsDefined() && signal.IsMap())
{
Info.signal_kind = signal["kind"].as<std::string>("");
Info.signal_mount = signal["mount"].as<std::string>("");
Info.signal_lamps = signal["lamps"].as<std::string>("");
Info.signal_lean = signal["lean"].as<std::string>("");
Info.signal_read = signal["read"].as<std::string>("");
}
if (auto const table{document["turntable"]}; table.IsDefined() && table.IsMap())
{
Info.turntable_length = table["length"].as<double>(0.0);
@@ -644,7 +652,27 @@ std::string compose_directive(std::string const &File, std::vector<std::string>
return text + " end";
}
std::string directive(std::string const &File, include_info const &Info, int const Parameters, glm::dvec3 const &Location, std::optional<float> Yaw, std::string const &Track, glm::dvec2 const &Tilt)
std::string substitute(std::string const &Text, std::vector<std::string> const &Values)
{
std::string result;
std::size_t length{0};
for (std::size_t idx = 0; idx < Text.size();)
{
auto const id{placeholder(Text, idx, length)};
if (id > 0 && id <= static_cast<int>(Values.size()))
{
result += Values[id - 1];
idx += length;
}
else
{
result += Text[idx++];
}
}
return result;
}
std::string directive(std::string const &File, include_info const &Info, int const Parameters, glm::dvec3 const &Location, std::optional<float> Yaw, std::string const &Track, glm::dvec2 const &Tilt, std::map<std::string, std::string> const &Values)
{
std::vector<std::string> values;
for (auto id = 1; id <= Parameters; ++id)
@@ -652,7 +680,15 @@ std::string directive(std::string const &File, include_info const &Info, int con
auto const lookup{std::find_if(std::begin(Info.parameters), std::end(Info.parameters), [=](include_parameter const &Parameter) { return Parameter.id == id; })};
auto const role{lookup != std::end(Info.parameters) ? lookup->role : std::string{"free"}};
auto value{lookup != std::end(Info.parameters) ? lookup->value : std::string{}};
if (role == "pos.x")
if (auto const given{Values.find("#" + std::to_string(id))}; given != Values.end())
{
value = given->second;
}
else if (auto const given{Values.find(role)}; given != Values.end())
{
value = given->second;
}
else if (role == "pos.x")
{
value = number(Location.x);
}

View File

@@ -9,6 +9,7 @@ http://mozilla.org/MPL/2.0/.
#pragma once
#include <map>
#include <memory>
#include <optional>
#include <string>
@@ -39,6 +40,11 @@ struct include_info
double turntable_length{0.0};
int turntable_angles{0};
int turntable_positions{0};
std::string signal_kind;
std::string signal_mount;
std::string signal_lamps;
std::string signal_lean;
std::string signal_read;
std::vector<include_parameter> parameters;
// description of specified parameter, created if there's none
@@ -71,7 +77,8 @@ bool complete(include_info const &Info, int Parameters, std::string *Issue = nul
// builds include directive which places specified template. Location and Yaw are the placement to pass through
// the parameters with matching roles, in the coordinates of the place the directive goes to; without Yaw the
// rotation parameters receive their default values
std::string directive(std::string const &File, include_info const &Info, int Parameters, glm::dvec3 const &Location, std::optional<float> Yaw, std::string const &Track = {}, glm::dvec2 const &Tilt = glm::dvec2{0.0});
std::string directive(std::string const &File, include_info const &Info, int Parameters, glm::dvec3 const &Location, std::optional<float> Yaw, std::string const &Track = {}, glm::dvec2 const &Tilt = glm::dvec2{0.0}, std::map<std::string, std::string> const &Values = {});
std::string substitute(std::string const &Text, std::vector<std::string> const &Values);
// splits include directive into the name of the included file and the values of the parameters, both as they're
// written. returns: false if the text isn't a complete include directive

View File

@@ -94,6 +94,8 @@ bool editorSettings::load()
m_orthophoto.in_scene = (value == "1");
else if (key == "platform_edge")
parse(value, m_platform_edge);
else if (key == "signal_offset")
parse(value, m_signal_offset);
else if (key.rfind(origin_prefix, 0) == 0)
{
// northing;easting
@@ -133,6 +135,7 @@ bool editorSettings::save()
stream << "ortho_lift " << m_orthophoto.lift << "\n";
stream << "ortho_in_scene " << (m_orthophoto.in_scene ? 1 : 0) << "\n";
stream << "platform_edge " << m_platform_edge << "\n";
stream << "signal_offset " << m_signal_offset << "\n";
stream << std::fixed << std::setprecision(3);
for (auto const &origin : m_orthophoto_origins)
stream << origin.first << " " << origin.second.first << ";" << origin.second.second << "\n";

View File

@@ -41,12 +41,15 @@ public:
double platform_edge() const { return m_platform_edge; }
void platform_edge(double Distance) { m_platform_edge = Distance; }
double signal_offset() const { return m_signal_offset; }
void signal_offset(double Distance) { m_signal_offset = Distance; }
private:
movement_scheme m_movement{movement_scheme::wsad};
orthophoto_settings m_orthophoto;
std::map<std::string, std::pair<double, double>> m_orthophoto_origins;
double m_platform_edge{1.725};
double m_signal_offset{2.25};
};
// global editor settings instance