17
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-11-01 03:29:03 +01:00

feat(editor): the work of the editor sessions not committed yet, as it stands: a curve traced on from the end of the diverging track of a switch goes on at its radius with no transition in, or from a straight right at the switch (alignment start_held, fit_going_on), the plan taking an end adjoining R 10 km or more for a straight; the switches and slips laid into curves, slid along them and laid alone on one straight (frame_path, switch slide); the route plan reading curves going on from the tracks adjoining, the kept designs taken or forgotten; the orthophoto and terrain model settings, downloads and layers, the tracks onto the terrain; the curvature of a path in the plan (bezier::plan_curvature); the Polish texts of all of it. Not built as committed

This commit is contained in:
maj00r
2026-10-29 22:19:06 +01:00
parent 2eda26b94c
commit 80379b991c
49 changed files with 4718 additions and 1114 deletions

View File

@@ -13,6 +13,7 @@ http://mozilla.org/MPL/2.0/.
#include "utilities/utilities.h"
#include <cctype>
#include <cstdio>
#include <cstdlib>
#include <filesystem>
#include <fstream>
@@ -48,16 +49,52 @@ template <typename Type_> void parse(std::string const &Text, Type_ &Out)
}
const std::string origin_prefix{"ortho_origin@"};
const std::string offset_prefix{"nmt_offset@"};
// settings are whitespace separated key/value pairs, so the scenery name used in the key can't contain spaces
std::string origin_key(std::string const &Scenery)
std::string scenery_key(std::string const &Prefix, std::string const &Scenery)
{
std::string key = origin_prefix + Scenery;
std::string key = Prefix + Scenery;
for (char &c : key)
if (std::isspace(static_cast<unsigned char>(c)))
c = '_';
return key;
}
// a field of a WMS layer in the settings, which keep values with no blank in them: the blanks, the separator of the fields and the
// percent sign go as %XX
std::string encoded(std::string const &Text)
{
std::string out;
for (unsigned char const c : Text)
{
if (std::isspace(c) || c == ';' || c == '%')
{
char hex[4];
std::snprintf(hex, sizeof(hex), "%%%02X", c);
out += hex;
}
else
out += static_cast<char>(c);
}
return out;
}
std::string decoded(std::string const &Text)
{
std::string out;
for (std::size_t i = 0; i < Text.size(); ++i)
{
if (Text[i] == '%' && i + 2 < Text.size() && std::isxdigit(static_cast<unsigned char>(Text[i + 1])) && std::isxdigit(static_cast<unsigned char>(Text[i + 2])))
{
out += static_cast<char>(std::strtoul(Text.substr(i + 1, 2).c_str(), nullptr, 16));
i += 2;
}
else
out += Text[i];
}
return out;
}
}
bool editorSettings::load()
@@ -92,6 +129,8 @@ bool editorSettings::load()
parse(value, m_orthophoto.lift);
else if (key == "ortho_in_scene")
m_orthophoto.in_scene = (value == "1");
else if (key == "ortho_on")
m_orthophoto.on = (value == "1");
else if (key == "platform_edge")
parse(value, m_platform_edge);
else if (key == "signal_offset")
@@ -108,6 +147,16 @@ bool editorSettings::load()
m_terrain_offer = (value == "1");
else if (key == "track_tools_all")
m_track_tools_more = (value == "1");
else if (key == "terrain_while_laying")
m_terrain_while_laying = (value == "1");
else if (key == "nmt_band")
parse(value, m_terrain_model.band);
else if (key == "nmt_around")
parse(value, m_terrain_model.around);
else if (key == "nmt_shape")
m_terrain_model.shape = (value == "1");
else if (key == "nmt_follow")
m_terrain_model.follow = (value == "1");
else if (key == "top_ballast")
m_top_tracks = value == "1" ? 0 : 1;
else if (key == "top_tracks")
@@ -130,6 +179,31 @@ bool editorSettings::load()
// before, when they were the default, are left behind
else if (key == "laying_heights")
m_heights = value == "points" ? lay_heights::points : value == "level" ? lay_heights::level : lay_heights::fitted;
// visible;opacity;address;layers;title;terms
else if (key == "wms_layer")
{
std::vector<std::string> fields;
for (std::size_t from{0};;)
{
auto const separator{value.find(';', from)};
fields.push_back(decoded(value.substr(from, separator == std::string::npos ? std::string::npos : separator - from)));
if (separator == std::string::npos)
break;
from = separator + 1;
}
if (fields.size() < 4 || fields[2].empty() || fields[3].empty())
continue;
wms_layer layer;
layer.visible = fields[0] == "1";
parse(fields[1], layer.opacity);
layer.url = fields[2];
layer.layers = fields[3];
if (fields.size() > 4)
layer.title = fields[4];
if (fields.size() > 5)
layer.terms = fields[5];
m_wms_layers.push_back(layer);
}
else if (key.rfind(origin_prefix, 0) == 0)
{
// northing;easting
@@ -141,6 +215,16 @@ bool editorSettings::load()
parse(value.substr(separator + 1), east);
m_orthophoto_origins[key] = {north, east};
}
else if (key.rfind(offset_prefix, 0) == 0)
{
// offset;fitted
auto const separator = value.find(';');
if (separator == std::string::npos)
continue;
double offset{0.0};
parse(value.substr(0, separator), offset);
m_terrain_model_offsets[key] = {offset, value.substr(separator + 1) == "1"};
}
}
return true;
}
@@ -168,6 +252,8 @@ bool editorSettings::save()
stream << "ortho_drape " << (m_orthophoto.drape ? 1 : 0) << "\n";
stream << "ortho_lift " << m_orthophoto.lift << "\n";
stream << "ortho_in_scene " << (m_orthophoto.in_scene ? 1 : 0) << "\n";
if (m_orthophoto.on.has_value())
stream << "ortho_on " << (*m_orthophoto.on ? 1 : 0) << "\n";
stream << "platform_edge " << m_platform_edge << "\n";
stream << "signal_offset " << m_signal_offset << "\n";
stream << "nodebank_previews " << (m_nodebank_previews ? 1 : 0) << "\n";
@@ -176,19 +262,28 @@ bool editorSettings::save()
stream << "first_steps " << (m_first_steps ? 1 : 0) << "\n";
stream << "terrain_offer " << (m_terrain_offer ? 1 : 0) << "\n";
stream << "track_tools_all " << (m_track_tools_more ? 1 : 0) << "\n";
stream << "terrain_while_laying " << (m_terrain_while_laying ? 1 : 0) << "\n";
stream << "nmt_band " << m_terrain_model.band << "\n";
stream << "nmt_around " << m_terrain_model.around << "\n";
stream << "nmt_shape " << (m_terrain_model.shape ? 1 : 0) << "\n";
stream << "nmt_follow " << (m_terrain_model.follow ? 1 : 0) << "\n";
stream << "top_tracks " << m_top_tracks << "\n";
stream << "top_rails " << std::hex << (m_top_rails & 0xffffffu) << std::dec << "\n";
stream << "corner_radii " << m_corner_low << ";" << m_corner_high << "\n";
stream << "laying_heights " << (m_heights == lay_heights::points ? "points" : m_heights == lay_heights::level ? "level" : "fitted") << "\n";
for (auto const &layer : m_wms_layers)
stream << "wms_layer " << (layer.visible ? 1 : 0) << ";" << layer.opacity << ";" << encoded(layer.url) << ";" << encoded(layer.layers) << ";" << encoded(layer.title) << ";" << encoded(layer.terms) << "\n";
stream << std::fixed << std::setprecision(3);
for (auto const &origin : m_orthophoto_origins)
stream << origin.first << " " << origin.second.first << ";" << origin.second.second << "\n";
for (auto const &offset : m_terrain_model_offsets)
stream << offset.first << " " << offset.second.first << ";" << (offset.second.second ? 1 : 0) << "\n";
return true;
}
bool editorSettings::orthophoto_origin(std::string const &Scenery, double &North, double &East) const
{
auto const lookup = m_orthophoto_origins.find(origin_key(Scenery));
auto const lookup = m_orthophoto_origins.find(scenery_key(origin_prefix, Scenery));
if (lookup == m_orthophoto_origins.end())
return false;
North = lookup->second.first;
@@ -198,5 +293,24 @@ bool editorSettings::orthophoto_origin(std::string const &Scenery, double &North
void editorSettings::orthophoto_origin(std::string const &Scenery, double North, double East)
{
m_orthophoto_origins[origin_key(Scenery)] = {North, East};
m_orthophoto_origins[scenery_key(origin_prefix, Scenery)] = {North, East};
}
bool editorSettings::terrain_model_offset(std::string const &Scenery, double &Offset, bool &Fitted) const
{
auto const lookup = m_terrain_model_offsets.find(scenery_key(offset_prefix, Scenery));
if (lookup == m_terrain_model_offsets.end())
return false;
Offset = lookup->second.first;
Fitted = lookup->second.second;
return true;
}
void editorSettings::terrain_model_offset(std::string const &Scenery, double Offset, bool Fitted)
{
// the model as it is, never fitted, is what a scenery without the line has
if (Offset == 0.0 && false == Fitted)
m_terrain_model_offsets.erase(scenery_key(offset_prefix, Scenery));
else
m_terrain_model_offsets[scenery_key(offset_prefix, Scenery)] = {Offset, Fitted};
}