18
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-12-01 19:57:06 +01:00

feat(editor): the switch tool a step at a time, the template chosen as a line

The panel of the switch tool goes by states as the lay tool's does, each with its step at the top
(editor-lay-flow.md, second part):

- Ready: "Press on a straight and drag along it and to the side" (a slip, a crossing and a connection with
  steps of their own). What to place as one bar, [Switch | Slip | Crossing], in place of the tiles in two
  rows. The rail of the track, or the rails [60E1 49E1 S42] where it doesn't tell its rail, and the speed on
  the diverging track as chips beside "Diverging speed (km/h)"; the template they pick as one line,
  "Rz 60E1-300-1:9, 50 km/h", its tooltip the lengths and the rest of its label, a pencil at its end opening
  the list of the templates and All templates under it. The gestures of placing are in the card and in the
  bar under the view, no longer rows in the panel; the template editor among More settings.
- Dragging: "Let go to insert" and one line, "27.1 m, left, 40 km/h"; what keeps the switch from being laid
  (the rules a switch bent into a curve or laid on from a free end breaks) in one line in red, the switch
  moved back onto its straight or into its curve and the branch that doesn't fit into a track in orange.
- Placed: "Switch z1 inserted, Ctrl+Z undoes" while the switch is the one the last step of the history laid,
  else "Switch z1: drag it along its track to move it". The sketch, its length and side in its tooltip; the
  speed chips and the template as the line with the pencil, as when placing; Flip the side. A switch with no
  drive says so with what puts one there; the name, the record, the angle, the drive, the frog and the check
  rails, the slide along its track and the note of the inspector are under Details, folded. What the tool
  told of it besides the step under it all.
- Refused: the reason in red right under the step, the rest of a long one in its tooltip.

The drive of the switch is drawn by a function of its own (render_switch_drive), no longer a lambda of the
panel. The status of the switch tool is told in red while it's the refusal last told
(m_switch.refusal), the expectations of the self-tests read it as before. The bar under the view keeps
the gestures of the view first, "List in the panel" after them.

Self-test: expect switchpanel <ready|dragging|placed|selected>, and the case lf_2_switch_panel_states:
ready after a switch refused, placed after one laid, selected after another one laid since.

lang/editor_pl.po: the Polish of the new texts.
This commit is contained in:
maj00r
2026-11-23 13:59:37 +01:00
parent f065098717
commit 81e53bbdef
10 changed files with 362 additions and 178 deletions
+36 -10
View File
@@ -14,6 +14,7 @@ http://mozilla.org/MPL/2.0/.
#include "application/editormode.h"
#include "application/editoruilayer.h"
#include "application/editormodeshared.h"
#include "application/editorflow.h"
#include "editor/editorFormat.hpp"
#include "editor/editorGeometry.hpp"
#include "editor/editorSwitchStore.hpp"
@@ -177,6 +178,15 @@ bool template_row(int const Index, editor_track::switch_template const &Template
return clicked;
}
// the template chosen in a line: its name and the speed on its diverging track
std::string template_summary(editor_track::switch_template const &Template)
{
if (Template.source != nullptr)
return Template.title();
auto const speed{Template.double_slip && Template.type == "Skrz" ? 0.0 : speed_of(Template)};
return switch_name_translated(Template.title()) + (speed > 0.0 ? format(" · %.0f km/h", speed) : std::string{});
}
// the height of a list of the rows in its window, as high as the panel lets it
float list_height(int const Rows, int const Headers)
{
@@ -489,7 +499,7 @@ bool editor_mode::change_switch_template(TTrack &Switch, int const Index)
return true;
}
int editor_mode::render_template_picker(char const *Id, std::function<bool(editor_track::switch_template const &)> const &Fits, std::string const &Rail, int const Chosen, bool const Popup)
int editor_mode::render_template_picker(char const *Id, std::function<bool(editor_track::switch_template const &)> const &Fits, std::string const &Rail, int const Chosen, bool const Popup, std::string const &Unlisted)
{
auto &tool{m_switch};
auto const &templates{tool.templates};
@@ -546,12 +556,13 @@ int editor_mode::render_template_picker(char const *Id, std::function<bool(edito
}
if (speeds.size() > 1)
{
ImGui::TextDisabled("%s", STR_C("Speed on the diverging track"));
ImGui::TextDisabled("%s", STR_C("Diverging speed (km/h)"));
item_tooltip("Picks the usual switch of the rail for the speed; the others of the same speed are on the list under it");
ImGui::SameLine();
int speed{Chosen >= 0 && Chosen < count ? static_cast<int>(speed_of(templates[Chosen])) : -1};
std::vector<std::string> labels;
for (auto const &[value, index] : speeds)
labels.push_back(format("%d km/h", value));
labels.push_back(format("%d", value));
std::vector<segment_option> options;
auto label{labels.begin()};
for (auto const &[value, index] : speeds)
@@ -559,6 +570,23 @@ int editor_mode::render_template_picker(char const *Id, std::function<bool(edito
if (choice_chips("##speeds", speed, options))
picked = speeds[speed];
}
// in the panel the template chosen is a line, which opens the list of them; the list is open while none is chosen
if (false == Popup)
{
auto *open{ImGui::GetStateStorage()->GetBoolRef(ImGui::GetID("##listopen"), false)};
auto const known{Chosen >= 0 && Chosen < count};
auto summary{Unlisted.empty() ? std::string{STR_C("Pick a template")} : Unlisted};
if (known)
summary = template_summary(templates[Chosen]);
auto const tooltip{known ? template_tooltip(templates[Chosen]) : std::string{}};
if (editor_flow::summary_line("##chosen", summary, *open, tooltip.c_str()))
*open = !*open;
if (false == *open && (known || false == Unlisted.empty()))
{
ImGui::PopID();
return picked == Chosen ? -1 : picked;
}
}
// by the skos, the steepest first; the own templates and the one chosen from elsewhere after them
std::vector<std::pair<double, std::string>> groups;
auto const group_of = [&](int const Index) -> std::pair<double, std::string> {
@@ -676,18 +704,16 @@ void editor_mode::render_switch_template(TTrack &Track, bool const Combo)
ImGui::EndTable();
}
}
else
else if (false == blocked.empty())
{
ImGui::TextDisabled("%s", STR_C("Template"));
ImGui::SameLine();
ImGui::TextUnformatted(current >= 0 ? template_name(tool.templates[current]).c_str() : own().c_str());
if (false == blocked.empty())
{
ImGui::TextColored(ImVec4(1.0f, 0.7f, 0.2f, 1.0f), "%s", blocked.c_str());
return;
}
picked = render_template_picker("##turnout", fits, rail, current, false);
ImGui::TextColored(ImVec4(1.0f, 0.7f, 0.2f, 1.0f), "%s", blocked.c_str());
return;
}
else
picked = render_template_picker("##turnout", fits, rail, current, false, own());
if (picked >= 0)
change_switch_template(Track, picked);
}