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

feat(editor): the vertices of a line of the model dragged on the map, the line as the model would lay it shown before they're let go

Continues E4b (editor-tracks-domain.md §0 pkt 2, §8 "Przesuń wierzchołek", "Zmień R / L / D wierzchołka"): the route design opened on a
line of the model has its handles on the map, a vertex and the grip of the radius of each curve.

- While a handle is dragged the change is tried on a copy of the network as it goes: the line as the model would lay it drawn over the
  map, green, or red where it's refused, and by the mouse and in the panel why it's refused or what the norms say of it ("The norms:
  2 notes"). Let go, it's one command of the model: move_vertex for a vertex moved, set_vertex for a radius dragged; a vertex moved and
  its curve changed at once one set_vertex with its place (layout::set_vertex::point), one step. The first and the last vertex of a
  line of two or more go along the tangents of its ends, as the route design drags them.
- No gizmo on the tracks of a line of the model, nor the points of their paths dragged by hand: the line is edited through the route
  design. The gizmo stays for the old tracks and the models.

Self-test: modelplan opens the route design in the field of the tracks; expect modelvertexat <line> <index> <x> <z> <tolerance>, expect
modelpreview <shown|none>. The case m_11_vertex_drag (the vertex dragged with the mouse, the preview told while it's held, one step).

Tests: U: a vertex moved and its curve changed by one set_vertex, one step, taken back.

lang/editor_pl.po: the Polish of the new texts.
This commit is contained in:
maj00r
2026-11-23 17:58:15 +01:00
parent 6e8383df6f
commit b3a2f1fef2
13 changed files with 227 additions and 21 deletions
+71
View File
@@ -16,6 +16,7 @@ http://mozilla.org/MPL/2.0/.
#include "application/editormode.h"
#include "application/editormodemodel.h"
#include "application/editormodeselftest.h"
#include "application/editorprojection.h"
#include "application/editormodeshared.h"
#include "application/editoruilayer.h"
#include "editor/editorFormat.hpp"
@@ -166,3 +167,73 @@ bool editor_mode::model_profile_apply()
WriteLog(format("Editor: model: the grade line of line %s, %zu breaks: %s", line_name(id).c_str(), command.grades.size(), editor_selftest::one_line(model_message()).c_str()), logtype::generic);
return true;
}
// a handle of the route design dragged on a line of the model: the line as the model lays it and the norms' line, before it's let go
void editor_mode::model_plan_preview()
{
auto &preview{model().preview};
auto const line{model_plan_line()};
if (line == layout::line_id::none || false == m_route_dragging)
{
preview = {};
return;
}
std::string key;
for (auto const &vertex : m_route.design.vertices)
key += format("%.4f %.4f %.3f %.3f %.3f %.1f;", vertex.position.x, vertex.position.y, vertex.radius, vertex.transition_in, vertex.transition_out, vertex.cant);
if (key == preview.key)
return;
preview = {};
preview.key = key;
std::vector<layout::command> commands;
if (std::string why; false == model_plan_commands(line, commands, why))
{
preview.refused = true;
preview.text = model_tr(why);
return;
}
// tried on a copy of the network, one after another as they'd be carried out
layout::model copy{model_network()};
std::vector<std::string> notices;
for (auto const &command : commands)
{
auto const outcome{copy.execute(command)};
if (false == outcome.done)
{
preview.refused = true;
preview.text = model_reasons_shown(outcome);
return;
}
for (auto const &notice : outcome.notices)
if (auto const text{model_notice_shown(notice)}; std::ranges::find(notices, text) == notices.end())
notices.push_back(text);
}
preview.text = notices.empty() ? std::string{STR_C("Within the norms")} : format(STR_P("The norms: %zu note", "The norms: %zu notes", static_cast<long long>(notices.size())), notices.size());
for (auto const &notice : notices)
preview.text += "\n" + notice;
if (auto const *laid{copy.state().find(line)}; laid != nullptr && laid->solved.valid())
{
auto const steps{std::clamp(static_cast<int>(laid->solved.length / 2.0), 1, 2000)};
for (int i = 0; i <= steps; ++i)
preview.points.push_back(laid->solved.point(laid->solved.length * i / steps));
}
}
void editor_mode::draw_model_plan_preview() const
{
if (m_model == nullptr)
return;
auto const &preview{m_model->preview};
if (preview.key.empty())
return;
screen_projection const projection;
auto *drawlist{ImGui::GetForegroundDrawList(ImGui::GetMainViewport())};
auto const colour{preview.refused ? IM_COL32(255, 90, 70, 230) : IM_COL32(90, 220, 110, 230)};
for (std::size_t i = 0; i + 1 < preview.points.size(); ++i)
projection.line(drawlist, preview.points[i], preview.points[i + 1], colour, 2.0f);
// by the mouse: refused and why, or the norms' line
auto const &mouse{ImGui::GetIO().MousePos};
auto const text{(preview.refused ? std::string{STR_C("Refused, nothing changes:")} + "\n" : std::string{}) + preview.text};
drawlist->AddText(ImVec2(mouse.x + 18.0f, mouse.y + 18.0f), colour, text.c_str());
}