From 81e53bbdef7a1d7c0eea5b8b0812d36b00b8e604 Mon Sep 17 00:00:00 2001 From: maj00r <73280030+maj00r@users.noreply.github.com> Date: Mon, 23 Nov 2026 13:59:37 +0100 Subject: [PATCH] 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 , 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. --- application/editormode.cpp | 1 + application/editormode.h | 16 +- application/editormodeselftest.cpp | 1 + application/editormodeselftestexpect.cpp | 21 +- application/editormodeswitchtemplate.cpp | 46 +++- application/editormodeswitchtool.cpp | 189 ++++++++++------ application/editormodetrack.cpp | 212 ++++++++++-------- lang/editor_pl.po | 32 +++ tests/editor/README.md | 4 +- .../editor/cases/lf_2_switch_panel_states.txt | 18 ++ 10 files changed, 362 insertions(+), 178 deletions(-) create mode 100644 tests/editor/cases/lf_2_switch_panel_states.txt diff --git a/application/editormode.cpp b/application/editormode.cpp index a1cb9358c..82d4acc85 100644 --- a/application/editormode.cpp +++ b/application/editormode.cpp @@ -1100,6 +1100,7 @@ std::string editor_mode::switch_refused(std::string Text) { // not in the status line as well: told there, it stayed after the next switch was laid ui()->set_refusal(Text); + m_switch.refusal = Text; return Text; } diff --git a/application/editormode.h b/application/editormode.h index 28278f497..24de86e8f 100644 --- a/application/editormode.h +++ b/application/editormode.h @@ -1580,6 +1580,7 @@ class editor_mode : public application_mode, private editor_track::observer, pri glm::dvec3 mouse{0.0}; editor_track::straight line; std::string status; + std::string refusal; // the last of the statuses which told a switch refused, told in red while it's the status char name[64]{}; struct drive_family { @@ -1682,7 +1683,8 @@ class editor_mode : public application_mode, private editor_track::observer, pri // the template to choose: the speeds on the diverging track as chips, the templates of the rail by their skos, all the others // folded under. Fits: those of the kind wanted; Rail: of the track, empty when it doesn't tell; Popup: inside a combo, with no // windows of its own. Gives the index picked, -1 while none is - int render_template_picker(char const *Id, std::function const &Fits, std::string const &Rail, int const Chosen, bool const Popup); + // in the panel (not Popup) the template chosen is a line, Unlisted where it's of none of them, which opens the list + int render_template_picker(char const *Id, std::function const &Fits, std::string const &Rail, int const Chosen, bool const Popup, std::string const &Unlisted = {}); // the template of the selected switch, slip or crossing, changed with a pick: in a combo for the inspector, else in full; nothing // for another track void render_switch_template(TTrack &Track, bool const Combo); @@ -1953,8 +1955,9 @@ class editor_mode : public application_mode, private editor_track::observer, pri extending }; lay_state lay_panel_state() const; - // the state of the panel of the lay tool in words, for the expectations of the self-test + // the states of the panels of the lay tool and of the switch tool in words, for the expectations of the self-test std::string shown_lay_panel() const; + std::string shown_switch_panel() const; // the line shown at a glance: its length, its curves, the speed of the slowest one and how many are below the norms for the speed // it's designed for struct lay_quality @@ -2022,6 +2025,14 @@ class editor_mode : public application_mode, private editor_track::observer, pri // how much more the curve at the cursor was turned last to reach it, the first one tried for the next line mutable double m_turned_last{0.0}; void render_switch_ui(); + // what the switch tool places, as a bar of its kinds + void render_switch_kinds(switch_kind const Kind); + // a switch dragged: the length of its template, the side its diverging track goes to and the speed on it, what keeps it from being + // laid; the side 1 the right + void render_switch_drag(); + int switch_drag_side(std::string &Refusal) const; + // the track was made by the last step of the history, with those made together with it + bool just_laid(TTrack const *Track) const; void render_switch_timbers(); void render_rail_profile_hint(TTrack &Track); bool start_switch_placement(); @@ -2394,6 +2405,7 @@ class editor_mode : public application_mode, private editor_track::observer, pri bool track_busy() const; // something going on in the mode, which Esc drops before it leaves the mode std::string track_mode_name() const; void render_turnout_ui(); + void render_switch_drive(TTrack &Switch, bool const Double); struct track_name_edit { TTrack const *track{nullptr}; diff --git a/application/editormodeselftest.cpp b/application/editormodeselftest.cpp index bd63b6ec3..2ef5b5747 100644 --- a/application/editormodeselftest.cpp +++ b/application/editormodeselftest.cpp @@ -243,6 +243,7 @@ editor_mode::selftest_result editor_mode::selftest_dispatch(std::string const &c // download area / the question of the terrain open // expect laypanel the state of the panel of the lay tool, as its step tells it, and // whether its settings are shown or folded to the line of their summary +// expect switchpanel the state of the panel of the switch tool, as its step tells it // expect steps the steps of the history Ctrl+Z takes back, the ones made together counted once // each expect logs SELFTEST PASS or SELFTEST FAIL; a failed one, or a command no group takes, // makes the run end with editor_selftest::failed_exit_code diff --git a/application/editormodeselftestexpect.cpp b/application/editormodeselftestexpect.cpp index 5e72c4f4b..72d3b3b29 100644 --- a/application/editormodeselftestexpect.cpp +++ b/application/editormodeselftestexpect.cpp @@ -466,8 +466,8 @@ void expect_selected(std::string const &What, std::istringstream &Words, std::op expectation(glm::distance(*Selected, wanted) <= tolerance, What, format("%.3f %.3f %.3f", Selected->x, Selected->y, Selected->z), format("%.3f %.3f %.3f within %.3f", wanted.x, wanted.y, wanted.z, tolerance)); } -// expect laypanel : the state the panel of the lay tool is in, as the step at its top tells it, and whether its -// settings are shown or folded to the line of their summary +// expect laypanel , expect switchpanel : the state the panel of the tool is in, as the step at its top +// tells it, and whether the settings of the lay tool are shown or folded to the line of their summary void expect_panel(std::string const &What, std::istringstream &Words, std::string const &Got) { std::string wanted; @@ -493,6 +493,7 @@ struct shown_state std::map windows; // shortcuts, settings, weather, orthophoto std::optional selected; // where the node selected stands std::string lay_panel; // the state of the panel of the lay tool and whether its settings are shown + std::string switch_panel; // the state of the panel of the switch tool }; // the expectations of what the editor shows; false: no expectation of the kind @@ -516,6 +517,8 @@ bool expect_shown(std::string const &Kind, std::string const &What, std::istring expect_selected(What, Words, Shown.selected); else if (Kind == "laypanel") expect_panel(What, Words, Shown.lay_panel); + else if (Kind == "switchpanel") + expect_panel(What, Words, Shown.switch_panel); else return false; return true; @@ -584,13 +587,13 @@ editor_mode::selftest_result editor_mode::selftest_expect(std::string const &com shown_state shown{m_switch.status, ui()->refusal_shown(), ui()->status_line(), m_lay.mouse, {{"grow", m_nmt_state.grow}, {"area", EditorSettings.terrain_model().area}, {"prompt", m_nmt_state.prompt}}, tool_name(ui()->mode()), {{"shortcuts", m_shortcuts_open}, {"settings", m_settings_open}, {"weather", m_environment_open}, {"orthophoto", m_orthophoto_window}}, std::nullopt, - shown_lay_panel()}; + shown_lay_panel(), shown_switch_panel()}; if (m_node != nullptr) shown.selected = m_node->location(); if (false == expect_shown(kind, what, words, shown)) expectation(false, what, "no expectation " + kind, "cant, joint, records, speed, gauge, track, route, norms, findings, height, lift, includes, status, statuslacks, refusal, statusline, laycursor, terrain, tool, window, " - "selected, laypanel or steps"); + "selected, laypanel, switchpanel or steps"); } return selftest_result::handled; } @@ -603,3 +606,13 @@ std::string editor_mode::shown_lay_panel() const auto const shown{panel == lay_state::ready || panel == lay_state::laid || m_lay.settings_open}; return std::string{states[static_cast(panel)]} + (shown ? " shown" : " folded"); } + +std::string editor_mode::shown_switch_panel() const +{ + if (m_switch.placing) + return "dragging"; + auto const *track{selected_track()}; + if (track == nullptr || track->eType != tt_Switch) + return "ready"; + return just_laid(track) ? "placed" : "selected"; +} diff --git a/application/editormodeswitchtemplate.cpp b/application/editormodeswitchtemplate.cpp index 5c28f7e91..124a1e248 100644 --- a/application/editormodeswitchtemplate.cpp +++ b/application/editormodeswitchtemplate.cpp @@ -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 const &Fits, std::string const &Rail, int const Chosen, bool const Popup) +int editor_mode::render_template_picker(char const *Id, std::function 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 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(speed_of(templates[Chosen])) : -1}; std::vector labels; for (auto const &[value, index] : speeds) - labels.push_back(format("%d km/h", value)); + labels.push_back(format("%d", value)); std::vector 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::functionGetBoolRef(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> groups; auto const group_of = [&](int const Index) -> std::pair { @@ -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); } diff --git a/application/editormodeswitchtool.cpp b/application/editormodeswitchtool.cpp index 878e18aa3..5fd23daa0 100644 --- a/application/editormodeswitchtool.cpp +++ b/application/editormodeswitchtool.cpp @@ -13,6 +13,7 @@ http://mozilla.org/MPL/2.0/. #include "application/editormode.h" #include "application/editorgestures.h" #include "application/editormodeshared.h" +#include "application/editorflow.h" #include "editor/editorConnections.hpp" #include "editor/editorFormat.hpp" #include "editor/editorTrack.hpp" @@ -177,68 +178,36 @@ void editor_mode::render_switch_ui() { auto &tool{m_switch}; auto const kind{current_switch_kind()}; - - // what to place, each with the templates and the options of its own only - struct choice + // dragged: what it lays as it's let go, and what keeps it from being laid + if (tool.placing) { - switch_kind kind; - char const *label; - char const *tooltip; - }; - choice const choices[] = {{switch_kind::single, "Switch", "A switch in a straight or a curve"}, - {switch_kind::slip, "Slip switch", "Rkp or Rkpd dragged out on one straight with its crossing track, at a crossing of two straights at its skos, or bent into a curve of a side track"}, - {switch_kind::crossing, "Crossing", "A crossing of two straights"}}; - { - auto const gap{std::round(ImGui::GetFontSize() * 0.4f)}; - auto const width{std::floor((ImGui::GetContentRegionAvail().x - gap) * 0.5f)}; - int shown{0}; - for (auto const &entry : choices) - { - if (entry.kind != switch_kind::single && false == switch_kind_offered(entry.kind)) - continue; - if (shown % 2 == 1) - ImGui::SameLine(0.0f, gap); - else if (shown > 0) - ImGui::Dummy(ImVec2(0.0f, gap * 0.25f)); - if (kind_tile(entry.label, STR_C(entry.label), static_cast(&entry - choices), kind == entry.kind, width) && kind != entry.kind) - choose_switch_kind(entry.kind); - item_tooltip(entry.tooltip); - ++shown; - } + render_switch_drag(); + return; } - // how to place it with the mouse - std::vector> how; - switch (kind) - { - case switch_kind::slip: - how = {{"Drag on a straight", "the slip with its crossing track, through the quarter of the cursor"}, {"Drag at a crossing", "of two straights at the skos of the slip: it goes there"}, {"Drag on a curve", "bent into it, in a side track only (11.4 pkt 4b)"}}; - break; - case switch_kind::crossing: how = {{"Drag at a crossing", "of two straights: it goes there"}}; break; - case switch_kind::connection: - how = {{"Drag", "from a straight onto the other track"}, {"Shift+wheel", "the kind"}, {"Ctrl+wheel", "R of the aligning curve"}}; - if (tool.connection == static_cast(connection::kind::double_crossover)) - how.push_back({"Alt+wheel", "where they meet"}); - break; - default: - how = {{"Drag on a track", "along: the direction, sideways: the side"}, - {"Drag onto the other track", "a crossover; over a crossover the other way a double or a scissors one, across tracks a ladder"}, - {"Drag from a free end", "a switch going on from the end of a track"}}; - break; - } - gesture_rows(how); + char const *step{STR_C("Press on a straight and drag along it and to the side")}; + if (kind == switch_kind::slip) + step = STR_C("Press on a straight or at a crossing and drag"); + else if (kind == switch_kind::crossing) + step = STR_C("Press at a crossing of two straights and drag"); + else if (kind == switch_kind::connection) + step = STR_C("Press on a straight and drag onto the other track"); + editor_flow::step_line(step); + // a switch refused: why, in one message in red under the step, where it's read first + if (false == tool.status.empty()) + editor_flow::message_line(tool.status, tool.status == tool.refusal ? editor_flow::kRefused : ImVec4(1.0f, 0.7f, 0.2f, 1.0f)); + render_switch_kinds(kind); - // the templates of the kind: by the speed, by the skos for the rail of the selected track, all of them under; the lengths and the - // rest of the label in the tooltip - ImGui::TextDisabled("%s", STR_C(kind == switch_kind::connection ? "The first switch" : "Template")); + // the template: the rail and the speed on the diverging track as chips, the one they pick as a line which opens the list of them all; + // the lengths and the rest of the label in the tooltip auto const rail{editor_track::rail_of(selected_track())}; if (false == rail.empty()) - { - ImGui::SameLine(); ImGui::TextDisabled(STR_C("rail of the track %s"), rail.c_str()); - } else if (auto *track{selected_track()}; track != nullptr && (track->iCategoryFlag & 15) == 1 && track->m_profile1.first.empty()) + { + ImGui::TextDisabled("%s", STR_C("Template")); render_rail_profile_hint(*track); - if (auto const picked{render_template_picker("##place", [&](editor_track::switch_template const &Template) { return of_kind(Template, static_cast(kind)); }, rail, tool.armed, false)}; picked >= 0) + } + if (auto const picked{render_template_picker("##place", [kind](editor_track::switch_template const &Template) { return of_kind(Template, static_cast(kind)); }, rail, tool.armed, false)}; picked >= 0) { tool.last = picked; tool.armed = picked; @@ -273,20 +242,114 @@ void editor_mode::render_switch_ui() } item_tooltip("Looks for the switches of the scenery, to use their shapes as the templates"); render_switch_timbers(); + if (ImGui::Button(STR_C("Template editor..."))) + m_switch_designer.open = true; + item_tooltip("Own switch templates: diverging tracks of straights, arcs and transition curves, double switches"); ImGui::TreePop(); } ImGui::PopID(); - if (false == tool.status.empty()) - { - ImGui::PushTextWrapPos(0.0f); - ImGui::TextColored(ImVec4(1.0f, 0.7f, 0.2f, 1.0f), "%s", tool.status.c_str()); - ImGui::PopTextWrapPos(); - } render_stray_drives(); +} - if (ImGui::Button(STR_C("Template editor..."))) - m_switch_designer.open = true; - item_tooltip("Own switch templates: diverging tracks of straights, arcs and transition curves, double switches"); +void editor_mode::render_switch_kinds(switch_kind const Kind) +{ + // what to place, each with the templates and the options of its own only; the slips and the crossings where there are templates of them + segment_option const single{static_cast(switch_kind::single), STR_C("Switch"), "A switch in a straight or a curve"}; + segment_option const slip{static_cast(switch_kind::slip), STR_C("Slip"), + "Rkp or Rkpd dragged out on one straight with its crossing track, at a crossing of two straights at its skos, or bent into a curve of a side track"}; + segment_option const crossing{static_cast(switch_kind::crossing), STR_C("Crossing"), "A crossing of two straights"}; + auto const slips{switch_kind_offered(switch_kind::slip)}; + auto const crossings{switch_kind_offered(switch_kind::crossing)}; + // a connection of tracks is chosen among the settings: none of these lit then + int chosen{Kind == switch_kind::connection ? -1 : static_cast(Kind)}; + bool changed{false}; + if (slips && crossings) + changed = segmented("switchkind", chosen, {single, slip, crossing}); + else if (slips) + changed = segmented("switchkind", chosen, {single, slip}); + else if (crossings) + changed = segmented("switchkind", chosen, {single, crossing}); + if (changed) + choose_switch_kind(static_cast(chosen)); +} + +int editor_mode::switch_drag_side(std::string &Refusal) const +{ + auto const &tool{m_switch}; + Refusal.clear(); + if (tool.free) + { + if (free_bend bend; free_switch_bend(bend)) + { + if (false == bend.report.refusals.empty()) + Refusal = bend.report.refusals.front(); + else if (false == bend.problem.empty()) + Refusal = bend.problem; + return bend.side; + } + glm::dvec3 start; + glm::dvec2 heading; + int side{1}; + double grade{0.0}; + free_switch_pose(start, heading, side, grade); + return side; + } + if (tool.curved) + { + int forward{1}; + int side{1}; + curved_switch_pose(forward, side); + if (tool.connection >= 0 || tool.armed < 0 || tool.armed >= static_cast(tool.templates.size()) || tool.templates[tool.armed].double_slip) + return side; + if (auto const preview{switch_preview()}; preview.size() >= 2) + { + auto const report{curved_switch_report(preview, tool.frame, curved_switch_start(forward), forward, &tool.frame_tracks)}; + if (false == report.refusals.empty()) + Refusal = report.refusals.front(); + } + return side; + } + glm::dvec2 const offset{tool.mouse.x - tool.point.x, tool.mouse.z - tool.point.z}; + auto const forward{glm::dot(offset, tool.line.direction) >= 0.0 ? 1 : -1}; + glm::dvec2 const direction{tool.line.direction * static_cast(forward)}; + return direction.x * offset.y - direction.y * offset.x >= 0.0 ? 1 : -1; +} + +void editor_mode::render_switch_drag() +{ + auto const &tool{m_switch}; + editor_flow::step_line(STR_C("Let go to insert")); + if (tool.armed < 0 || tool.armed >= static_cast(tool.templates.size())) + return; + // the length, the side of the diverging track, the speed on it; what keeps it from being laid in one line in red, what it's moved by + // to stay on its track in orange + auto const &shape{tool.templates[tool.armed]}; + std::string refusal; + auto const side{switch_drag_side(refusal)}; + auto line{format("%.1f m · %s", shape.length, side > 0 ? STR_C("right") : STR_C("left"))}; + if (auto const speed{shape.radius > 0.0 ? editor_track::diverging_speed(shape.radius) : 0.0}; speed > 0.0) + line += format(" · %.0f km/h", speed); + ImGui::TextUnformatted(line.c_str()); + if (false == refusal.empty()) + editor_flow::message_line(refusal, editor_flow::kRefused); + else if (auto const problem{switch_drag_problem()}; problem.has_value()) + editor_flow::message_line(problem->text, ImVec4(1.0f, 0.7f, 0.2f, 1.0f)); + // a branch let go at a track it doesn't fit into: the switch is laid, the branch not led into the track + if (switch_link plan; false == tool.free && tool.connection < 0 && false == plan_switch_link(plan) && false == plan.reason.empty()) + editor_flow::message_line(plan.reason, ImVec4(1.0f, 0.7f, 0.2f, 1.0f)); +} + +bool editor_mode::just_laid(TTrack const *Track) const +{ + // the last step of the history, with those made together with it + for (auto step{m_history.rbegin()}; step != m_history.rend(); ++step) + { + if (std::ranges::find(step->created, Track) != step->created.end()) + return true; + if (false == step->joined) + break; + } + return false; } // the timbers of all the switches and crossings of the scenery at once: a button for each model of timbers of the scenery data diff --git a/application/editormodetrack.cpp b/application/editormodetrack.cpp index dbd4d314d..6fcea16bb 100644 --- a/application/editormodetrack.cpp +++ b/application/editormodetrack.cpp @@ -1234,7 +1234,11 @@ void editor_mode::render_turnout_ui() format(STR_C("First switch: diverging %s, end offset %.3f m"), offset > 0.0 ? STR_C("right") : STR_C("left"), std::abs(offset)); } else - ImGui::Text(STR_C("Length %.3f m, diverging %s, end offset %.3f m"), length, offset > 0.0 ? STR_C("right") : STR_C("left"), std::abs(offset)); + about = format(STR_C("Length %.3f m, diverging %s, end offset %.3f m"), length, offset > 0.0 ? STR_C("right") : STR_C("left"), std::abs(offset)); + // the step: the switch laid just now and how to take it back, or how to move the one selected + auto const laid{just_laid(track)}; + auto const step{laid ? format(STR_C("Switch %s inserted · Ctrl+Z undoes"), name_of(*track).c_str()) : format(STR_C("Switch %s: drag it along its track to move it"), name_of(*track).c_str())}; + editor_flow::step_line(step.c_str()); { // the switch in plan at one scale: the main track white, the diverging one yellow, the angle at its end, the length under auto const font{ImGui::GetFontSize()}; @@ -1311,97 +1315,7 @@ void editor_mode::render_turnout_ui() list->AddText(ImVec2(std::round(top.x + (width - size.x) * 0.5f), y), ImGui::GetColorU32(ImGuiCol_TextDisabled), text.c_str()); } render_switch_template(*track, false); - // the name, the number, the rail and the kilometre of the switch, with what the scenery keeps of it - if (ImGui::CollapsingHeader(STR_C("Details##switchdetails"))) - { - render_track_name(*track); - render_switch_record(*track); - if (angle > 1e-6) - ImGui::Text(STR_C("Angle 1:%.2f (%.4f deg), R in the entry %.0f m"), 1.0 / std::tan(angle), glm::degrees(angle), diverging.radius); - } - auto const drive_ui = [&](TTrack &Switch) { - ImGui::PushID(&Switch); - if (set.has_value()) - ImGui::TextUnformatted(Switch.name().c_str()); - if (false == EditorIncludes.scanned()) - ImGui::TextDisabled("%s", STR_C("Looking for the templates...")); - else if (auto const drive{find_switch_drive(Switch, false)}) - { - auto const family{drive->family}; - auto const variant{drive->index}; - // a drive not described for the editor is shown by its file - auto const described{family >= 0 && family < static_cast(m_switch.drives.size())}; - auto const &file{drive->standing.file}; - auto const shown{described ? m_switch.drives[family].name : format("%s (%s)", file.substr(file.find_last_of('/') + 1).c_str(), STR_C("not described"))}; - if (begin_fields("##standingdrive", 0.3f)) - { - field_row("Drive##standing"); - if (false == described) - ImGui::TextUnformatted(shown.c_str()); - else if (ImGui::BeginCombo("##standing", shown.c_str())) - { - for (int i = 0; i < static_cast(m_switch.drives.size()); ++i) - if (ImGui::Selectable(m_switch.drives[i].name.c_str(), family == i) && i != family) - replace_switch_drive(Switch, i, false); - ImGui::EndCombo(); - } - if (described && ImGui::IsItemHovered()) - ImGui::SetTooltip("%s\n%s", STR_C("Puts another drive in place of the drive of this switch, on the same side"), format(STR_C("Drive: events %s+ and %s- switch it, also in the map"), Switch.name().c_str(), Switch.name().c_str()).c_str()); - ImGui::EndTable(); - } - int side{((variant >> 1) == (variant & 1)) ? 0 : 1}; - if (false == described) - { - ImGui::PushTextWrapPos(0.0f); - ImGui::TextDisabled("%s", STR_C("A drive not described for the editor, as the one of a double switch, which may also set the speed or carry the ballast of the switch: the editor keeps it as it is, it stays where it is when the switch is moved and goes when the last switch it throws is deleted")); - ImGui::PopTextWrapPos(); - } - else if (segmented("standingside", side, {{0, STR_C("diverging side"), "Puts the drive of the switch on the other side of the track: the same drive, its variant for the other side"}, - {1, STR_C("other side"), "Puts the drive of the switch on the other side of the track: the same drive, its variant for the other side"}})) - flip_switch_drive(Switch); - } - else if ((simulation::Events.FindEvent(Switch.name() + "+") != nullptr && simulation::Events.FindEvent(Switch.name() + "-") != nullptr) || (m_track_name.track == &Switch && m_track_name.uses.includes > 0)) - ImGui::TextDisabled(STR_C("Drive: events %s+ and %s- switch it, also in the map"), Switch.name().c_str(), Switch.name().c_str()); - else - { - ImGui::TextColored(ImVec4(1.0f, 0.7f, 0.2f, 1.0f), "%s", STR_C("No drive: the switch can't be switched during the game")); - render_switch_drive_choice(); - if (m_switch.drive >= 0 && ImGui::Button(STR_C("Put the drive by the switch"))) - place_switch_drive(Switch); - } - ImGui::PopID(); - }; - drive_ui(*track); - if (set.has_value()) - drive_ui(*set->second); - { - bool frogs{track->SwitchExtension->m_frogs}; - bool movable{track->SwitchExtension->m_movablenose}; - char const *const frogtip{"Cuts the rails of the switch at its frog and lays wing rails and check rails.\n" - "Off for a switch whose include has its own model of them"}; - char const *const nosetip{"The nose of the frog moves with the blades over to the wing rail of the track set, leaving no gap; the frog has no check rails"}; - ImGui::BeginDisabled(false == Global.Frogs); - if (frogs) - toggle_chips("switchfrogs", {{STR_C("Frog and check rails made from the rails"), &frogs, frogtip}, {STR_C("Movable nose"), &movable, nosetip}}); - else - toggle_chips("switchfrogs", {{STR_C("Frog and check rails made from the rails"), &frogs, frogtip}}); - ImGui::EndDisabled(); - if (false == Global.Frogs && ImGui::IsItemHovered(ImGuiHoveredFlags_AllowWhenDisabled)) - ImGui::SetTooltip("%s", STR_C("Turned on with frogs yes in eu07.ini")); - if (Global.Frogs && (frogs != track->SwitchExtension->m_frogs || movable != track->SwitchExtension->m_movablenose)) - { - auto const before{editor_track::capture(*track)}; - track->SwitchExtension->m_frogs = frogs; - track->SwitchExtension->m_movablenose = movable; - push_track_snapshot({{track, before}}); - editor_track::commit_parameters(*track); - } - } - if (false == m_switch.status.empty()) - ImGui::TextWrapped("%s", m_switch.status.c_str()); - auto &tool{m_switch}; - ImGui::Separator(); auto const finish_set = [&](std::string const &Status) { switch_store::follow(); records_to_history(); @@ -1474,9 +1388,51 @@ void editor_mode::render_turnout_ui() item_tooltip("Mirrors the switch: the diverging track goes to the other side"); double low{0.0}, high{0.0}, reach{length}; auto const slides{switch_slides(*track) && (set.has_value() ? switch_slides(*set->second) && double_room(*set, low, high, reach, m_switch.status) : switch_room(*track, low, high, m_switch.status))}; - ImGui::PushID("turnout"); - if (ImGui::TreeNode(STR_C("More settings"))) + // a switch with no drive can't be switched in the game: told, and put right, over the details + auto const driveless = [this](TTrack &Switch) { + auto const named{simulation::Events.FindEvent(Switch.name() + "+") != nullptr && simulation::Events.FindEvent(Switch.name() + "-") != nullptr}; + return EditorIncludes.scanned() && false == find_switch_drive(Switch, false).has_value() && false == named && (m_track_name.track != &Switch || m_track_name.uses.includes == 0); + }; + std::vector switches{track}; + if (set.has_value()) + switches.push_back(set->second); + for (auto *each : switches) + if (driveless(*each)) + render_switch_drive(*each, set.has_value()); + // the name, the number, the rail and the kilometre of the switch, with what the scenery keeps of it, its drive and its frog, how it + // slides along its track + if (ImGui::CollapsingHeader(STR_C("Details##switchdetails"))) { + render_track_name(*track); + render_switch_record(*track); + if (angle > 1e-6) + ImGui::Text(STR_C("Angle 1:%.2f (%.4f deg), R in the entry %.0f m"), 1.0 / std::tan(angle), glm::degrees(angle), diverging.radius); + for (auto *each : switches) + if (false == driveless(*each)) + render_switch_drive(*each, set.has_value()); + { + bool frogs{track->SwitchExtension->m_frogs}; + bool movable{track->SwitchExtension->m_movablenose}; + char const *const frogtip{"Cuts the rails of the switch at its frog and lays wing rails and check rails.\n" + "Off for a switch whose include has its own model of them"}; + char const *const nosetip{"The nose of the frog moves with the blades over to the wing rail of the track set, leaving no gap; the frog has no check rails"}; + ImGui::BeginDisabled(false == Global.Frogs); + if (frogs) + toggle_chips("switchfrogs", {{STR_C("Frog and check rails made from the rails"), &frogs, frogtip}, {STR_C("Movable nose"), &movable, nosetip}}); + else + toggle_chips("switchfrogs", {{STR_C("Frog and check rails made from the rails"), &frogs, frogtip}}); + ImGui::EndDisabled(); + if (false == Global.Frogs && ImGui::IsItemHovered(ImGuiHoveredFlags_AllowWhenDisabled)) + ImGui::SetTooltip("%s", STR_C("Turned on with frogs yes in eu07.ini")); + if (Global.Frogs && (frogs != track->SwitchExtension->m_frogs || movable != track->SwitchExtension->m_movablenose)) + { + auto const before{editor_track::capture(*track)}; + track->SwitchExtension->m_frogs = frogs; + track->SwitchExtension->m_movablenose = movable; + push_track_snapshot({{track, before}}); + editor_track::commit_parameters(*track); + } + } if (slides) { ImGui::PushItemWidth(100.0f); @@ -1491,7 +1447,7 @@ void editor_mode::render_turnout_ui() } else if (false == set.has_value()) { - // one bent into a curve slides along it, the tracks next to it keeping a metre; its curve found only while the settings are open + // one bent into a curve slides along it, the tracks next to it keeping a metre; its curve found only while the details are open std::vector bentframe; std::array bentsides{}; double bentstation{0.0}; @@ -1511,11 +1467,70 @@ void editor_mode::render_turnout_ui() format(STR_C("Room on the curve: %.2f m back, %.2f m ahead"), back, ahead).c_str()); } } - ImGui::TreePop(); + ImGui::TextDisabled("%s", STR_C("The textures, the speed and the other properties of the switch are in the inspector")); + } + // what the tool told of the switch: the step says it was laid, the rest of it here, a refusal in red + std::string_view told{m_switch.status}; + if (auto const cut{told.find('\n')}; laid && told.substr(0, cut).find(track->name()) != std::string_view::npos) + told = cut == std::string_view::npos ? std::string_view{} : told.substr(cut + 1); + if (false == told.empty()) + editor_flow::message_line(told, m_switch.status == m_switch.refusal ? editor_flow::kRefused : ImGui::GetStyleColorVec4(ImGuiCol_TextDisabled)); +} + +// the drive of the switch: the one by it, which can be put in place of another one or on the other side of the track, or none, told so +// with what puts one there; Double: the switch of a double one, named +void editor_mode::render_switch_drive(TTrack &Switch, bool const Double) +{ + ImGui::PushID(&Switch); + if (Double) + ImGui::TextUnformatted(Switch.name().c_str()); + if (false == EditorIncludes.scanned()) + ImGui::TextDisabled("%s", STR_C("Looking for the templates...")); + else if (auto const drive{find_switch_drive(Switch, false)}) + { + auto const family{drive->family}; + auto const variant{drive->index}; + // a drive not described for the editor is shown by its file + auto const described{family >= 0 && family < static_cast(m_switch.drives.size())}; + auto const &file{drive->standing.file}; + auto const shown{described ? m_switch.drives[family].name : format("%s (%s)", file.substr(file.find_last_of('/') + 1).c_str(), STR_C("not described"))}; + if (begin_fields("##standingdrive", 0.3f)) + { + field_row("Drive##standing"); + if (false == described) + ImGui::TextUnformatted(shown.c_str()); + else if (ImGui::BeginCombo("##standing", shown.c_str())) + { + for (int i = 0; i < static_cast(m_switch.drives.size()); ++i) + if (ImGui::Selectable(m_switch.drives[i].name.c_str(), family == i) && i != family) + replace_switch_drive(Switch, i, false); + ImGui::EndCombo(); + } + if (described && ImGui::IsItemHovered()) + ImGui::SetTooltip("%s\n%s", STR_C("Puts another drive in place of the drive of this switch, on the same side"), format(STR_C("Drive: events %s+ and %s- switch it, also in the map"), Switch.name().c_str(), Switch.name().c_str()).c_str()); + ImGui::EndTable(); + } + int side{((variant >> 1) == (variant & 1)) ? 0 : 1}; + if (false == described) + { + ImGui::PushTextWrapPos(0.0f); + ImGui::TextDisabled("%s", STR_C("A drive not described for the editor, as the one of a double switch, which may also set the speed or carry the ballast of the switch: the editor keeps it as it is, it stays where it is when the switch is moved and goes when the last switch it throws is deleted")); + ImGui::PopTextWrapPos(); + } + else if (segmented("standingside", side, {{0, STR_C("diverging side"), "Puts the drive of the switch on the other side of the track: the same drive, its variant for the other side"}, + {1, STR_C("other side"), "Puts the drive of the switch on the other side of the track: the same drive, its variant for the other side"}})) + flip_switch_drive(Switch); + } + else if ((simulation::Events.FindEvent(Switch.name() + "+") != nullptr && simulation::Events.FindEvent(Switch.name() + "-") != nullptr) || (m_track_name.track == &Switch && m_track_name.uses.includes > 0)) + ImGui::TextDisabled(STR_C("Drive: events %s+ and %s- switch it, also in the map"), Switch.name().c_str(), Switch.name().c_str()); + else + { + ImGui::TextColored(ImVec4(1.0f, 0.7f, 0.2f, 1.0f), "%s", STR_C("No drive: the switch can't be switched during the game")); + render_switch_drive_choice(); + if (m_switch.drive >= 0 && ImGui::Button(STR_C("Put the drive by the switch"))) + place_switch_drive(Switch); } ImGui::PopID(); - ImGui::Separator(); - ImGui::TextDisabled("%s", STR_C("The textures, the speed and the other properties of the switch are in the inspector")); } void editor_mode::render_path_events(TTrack &Track) @@ -2100,7 +2115,8 @@ std::vector editor_mode::track_key_hints(bool const All) else if (m_track_tab == track_tab::turnout && current_switch_kind() == switch_kind::slip) hints = {{"Press+drag on a straight", "the slip with its crossing track, through the quarter of the cursor"}, {"Press+drag at a crossing", "of two straights at the skos of the slip"}, {"Press+drag on a curve", "the slip bent into it, in a side track only (11.4 pkt 4b)"}}; else if (m_track_tab == track_tab::turnout) - hints = {{"Press+drag on the track", "along: direction, sideways: side"}, {"List in the panel", "the type of the switch"}, {"Press+drag on another track", "a switch on it"}}; + // the template is a line of the panel, its list behind the pencil: the gestures of the view first + hints = {{"Press+drag on the track", "along: direction, sideways: side"}, {"Press+drag on another track", "a switch on it"}, {"Press+drag from a free end", "a switch going on from the end of a track"}, {"List in the panel", "the type of the switch"}}; else if (m_track_tab == track_tab::profile && m_profile.route.spans.empty()) hints = {{"LMB on a track", "the grade line of its whole line"}, {"Shift+LMB on more tracks", "the route between the outermost ones"}, {"Shift+drag a box", "the route over the tracks in it"}}; else if (m_track_tab == track_tab::profile && m_profile.picking) diff --git a/lang/editor_pl.po b/lang/editor_pl.po index 31541b32a..348779bd6 100644 --- a/lang/editor_pl.po +++ b/lang/editor_pl.po @@ -14829,3 +14829,35 @@ msgstr "cofnij" msgid "Ctrl+Shift+wheel" msgstr "Ctrl+Shift+kółko" + +# scenery editor: the flow of the switch tool, a step at a time + +msgid "Press on a straight and drag along it and to the side" +msgstr "Wciśnij na prostej i przeciągnij wzdłuż niej i w bok" + +msgid "Press on a straight or at a crossing and drag" +msgstr "Wciśnij na prostej albo na skrzyżowaniu i przeciągnij" + +msgid "Press at a crossing of two straights and drag" +msgstr "Wciśnij na skrzyżowaniu dwóch prostych i przeciągnij" + +msgid "Press on a straight and drag onto the other track" +msgstr "Wciśnij na prostej i przeciągnij na drugi tor" + +msgid "Slip" +msgstr "Krzyżowy" + +msgid "Diverging speed (km/h)" +msgstr "Prędkość zwrotna (km/h)" + +msgid "Pick a template" +msgstr "Wybierz szablon" + +msgid "Let go to insert" +msgstr "Puść, aby wstawić" + +msgid "Switch %s inserted · Ctrl+Z undoes" +msgstr "Rozjazd %s wstawiony · Ctrl+Z cofa" + +msgid "Switch %s: drag it along its track to move it" +msgstr "Rozjazd %s: przeciągnij go wzdłuż toru, aby przesunąć" diff --git a/tests/editor/README.md b/tests/editor/README.md index 71d65f27f..21dc02acf 100644 --- a/tests/editor/README.md +++ b/tests/editor/README.md @@ -87,6 +87,7 @@ The expectations (`expect ...`), each logged as `SELFTEST PASS ` or | `expect laycursor ` | the point the line of the lay tool goes to from its last point clicked, in the plan | | `expect terrain <0\|1>` | the terrain model is made under the tracks as they're laid / around the camera within the download area / the question of the terrain of a new scenery is open | | `expect laypanel ` | the state of the panel of the lay tool, as the step at its top tells it, and whether its settings are shown or folded to the line of their summary | +| `expect switchpanel ` | the state of the panel of the switch tool, as the step at its top tells it | | `expect steps ` | the steps of the history Ctrl+Z takes back, the ones made together counted once: none made by a change refused | | `expect tool ` | the tool of the surroundings in use: `select`, `insert`, `brush`, `fill`, `copy`, or `track` while the field of work of the tracks is | | `expect window <0\|1>` | the window of the shortcuts (F1), of the settings of the editor, of the weather and the time, of the settings of the orthophoto is open | @@ -134,8 +135,9 @@ and the consistency of the interface of the editor (P2 of the plan of the editor | `c_1_bank_card_arms_insert` | a model of the node bank clicked with the select tool of the surroundings arms the insert tool with it; inserted where there's no ground under the cursor it stands at the height 0 where the cursor points, and the status says where | | `c_2_esc_closes_shortcuts` | Esc closes the window of the shortcuts, as F1 does, also in the tracks | -and the flow of the lay tool, a step at a time: +and the flow of the lay and the switch tools, a step at a time: | case | fix | | --- | --- | | `lf_1_lay_panel_states` | the panel of the lay tool goes from ready, its settings shown, to clicking, its settings folded to a line, to the line laid told over the settings, and back to ready when it's taken back; the same in the mode of a curve traced | +| `lf_2_switch_panel_states` | the panel of the switch tool stays ready after a switch refused, is placed after a switch laid, and tells a switch selected again after another one was laid | diff --git a/tests/editor/cases/lf_2_switch_panel_states.txt b/tests/editor/cases/lf_2_switch_panel_states.txt new file mode 100644 index 000000000..c182e7e66 --- /dev/null +++ b/tests/editor/cases/lf_2_switch_panel_states.txt @@ -0,0 +1,18 @@ +# Laying flow: the panel of the switch tool goes through its states, each with its step at its top. A plain track selected: ready. A +# switch refused leaves it ready, the refusal told. A switch laid: placed, told so until another step of the history. Another switch +# laid after it and the first one selected again: selected. i0: a straight taking the cant of 60 mm on along all of it (a switch there +# breaks 11.4 pkt 7); a2 and s2: plain straights of the lines a and s, x 0 and x 40, z 100..200 +wait 5 +curvedswitch i0 300 -40 302 -20 Rz_60E1-300-1:9 +expect switchpanel ready +expect status 11.4 pkt 7 +curvedswitch a2 0 140 3 160 Rz_60E1-300-1:9 +expect track z1 present +expect switchpanel placed +curvedswitch s2 40 140 43 160 Rz_60E1-300-1:9 +expect track z2 present +expect switchpanel placed +select z1 +wait 2 +expect switchpanel selected +quit