18
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-12-02 09:36:48 +01:00

feat(editor): laying from the photo: the points clicked along the track laid as recognised, told on the view, going on after Enter

quirky-crafting-summit, Etap 2. The lay tool has two shapes, From the photo and Bends: from the photo where the photo is on, the bends
without it, Tab switching them for the points clicked so far and on. The curve traced between bends (Tab) and its radii Auto/1R/2R/3R
are gone from the panel; the radii are changed in Plan afterwards.

- From the photo the points clicked go to the tracer (editor/editorTrace), each with the noise of two pixels of the view at it; the line
  shown is the one of the points clicked, worked out once for them, a dashed leg to the cursor. On the view: "straight 420 m", "curve R
  850 m", "nearly straight · curve R 9 km", "compound curve R 600/450 m", "R 300 m · up to 70 km/h" in orange; the points green, yellow
  or red by how far the line is from them in their noise, one which doesn't fit yellow and ringed, "doesn't fit - Backspace takes it
  back" by the cursor.
- A curve sharper than the norms at the speed of the line is laid slowed down: its tracks and its transitions get its speed, told in the
  status. One below the least radius of the kind of the track (the block of the norms) isn't laid, Lay disabled, the points kept; It's a
  side track offered where a side track may be that sharp (no profile has it so now).
- After Enter the tool stays at the end laid: the next clicks carry the line on from its free end, joined to it, with no need to hit the
  ring; Esc ends it. A free end is reached within 1 m on the ground only, not the end of the track beside.
- The first point turns the view from above on; a click in the outer 15 % of the view glides the view on by half of what the point is off
  its middle.
- The step: Click along the middle of the track on the photo: every 100-300 m on straights, closer on curves. Enter lays. The bar under
  the view: LMB a point on the track, Enter lay, Backspace take back.
- A tool key (G, T, N...) over points not laid warns as Esc does, the second press within 3 s goes; Enter over a single point clicked
  tells to click two instead of dropping it silently.
- With the editing on the model the line traced is laid the old way, told so, as the curve traced was.

Self-test: laymode traced|default, laysigma <m>; laysample lays out curves of the norms, compound ones too, and clicks them traced (no
Tab); laywalk clicks traced; expect laid curves|clicks|length|radius|speed|nearly|slowtracks|joined, expect laykeys <tabs> <enters>,
expect laycontinue; a self-test starts with the bends, whatever the orthophoto of the player's settings. The cases tr_1_three_curves
(3.2 km, three curves, 16 clicks, no Tab, one Enter), tr_2_nearly_straight (R 9 km), tr_3_compound (R 600/400), tr_4_below_norms (R 300
at 120 km/h laid for 70, R 150 refused), tr_5_continue. lf_1_lay_panel_states goes through the shape from the photo in place of the
curve traced, which the panel has no more.

lang/editor_pl.po: the Polish of the new texts; the ones of the curve traced and of its radii gone, the eight of the plan which no
source had any more among them.
This commit is contained in:
maj00r
2026-11-24 00:51:56 +01:00
parent 656c5b4d75
commit 6febdb0d64
17 changed files with 1055 additions and 186 deletions
+1 -1
View File
@@ -7980,7 +7980,7 @@ void editor_mode::on_key(int const Key, int const Scancode, int const Action, in
m_switch.one_sided = false == m_switch.one_sided;
break;
}
// laying: the bends of straights or a curve traced, for the points clicked from now on
// laying: the bends of straights or the line traced on the photo, for the points clicked so far and on
if (is_press(Action) && false == anyModifier && ui()->mode() == nodebank_panel::TRACK && m_lay.active && false == ImGui::GetIO().WantTextInput)
lay_switch_mode();
break;
+51 -4
View File
@@ -37,6 +37,7 @@ http://mozilla.org/MPL/2.0/.
#include "editor/editorTrackTrace.hpp"
#include "editor/editorConnections.hpp"
#include "editor/editorAlignment.hpp"
#include "editor/editorTrace.hpp"
#include "editor/editorAlignmentStore.hpp"
#include "editor/editorSwitchStore.hpp"
#include "editor/editorSwitchCurve.hpp"
@@ -1887,12 +1888,14 @@ class editor_mode : public application_mode, private editor_track::observer, pri
std::vector<TTrack *> line;
};
extend_tool m_extend;
// what a point clicked while laying is: a bend of the straights, eased with a large curve, or a point along the middle of a curve
// seen on the photo, the curve ending at the last of these
// what a point clicked while laying is: a bend of the straights, eased with a large curve, or a point along the middle of the track
// seen on the photo, the straights and the curves recognised from them (traced, "Po zdjęciu"); a curve traced between straights
// clicked as bends (curve) is the shape of before, the self-test's alone
enum class lay_mode
{
straights,
curve
curve,
traced
};
// a curve traced on the photo as it's laid, how far the points clicked along it are from it
struct lay_trace
@@ -1910,6 +1913,9 @@ class editor_mode : public application_mode, private editor_track::observer, pri
alignment::result shape;
std::vector<char> corners;
std::vector<lay_trace> traces;
// the line traced on the photo: its straights and curves as recognised, the speeds of the curves slowed down, the points which
// don't fit; refused where a curve is below the least radius of the kind of the track
std::optional<trace::result> traced;
// the straights of a fixed direction the next bend slides along: from a free end, out of a curve traced
std::vector<std::pair<glm::dvec3, glm::dvec3>> guides;
// where the grade breaks from point to point: the bends kept as such, at the heights clicked; a curve traced, or bends made
@@ -1922,7 +1928,22 @@ class editor_mode : public application_mode, private editor_track::observer, pri
bool active{false};
std::vector<glm::dvec3> points;
std::vector<lay_mode> modes; // of the points, as each was clicked
std::vector<double> sigmas; // m, the noise of each click: two pixels of the view at it
double sigma_given{0.0}; // m, the noise of the clicks of a self-test, where above 0
lay_mode mode{lay_mode::straights};
// the shape the user chose with Tab or in the panel; until then it follows the photo: traced where it's on, the bends where not
bool shape_chosen{false};
// the line laid goes on: the end of the one laid last is the first point, its free end held, till Esc
bool continuing{false};
// a click near the edge of the view glides the view: towards where the camera goes, from when
std::optional<glm::dvec2> glide;
double glide_time{0.0};
// a tool key pressed over points not laid only warns, the second press within 3 s goes
int leave_key{0};
double leave_time{-100.0};
// the shapes switched with Tab and the lines laid with Enter, told to the self-test
int tabs{0};
int enters{0};
int radii{0}; // of a curve traced: 0 as many as the points need, up to three
bool straights_between{true}; // a curve traced may be two with a straight between them
lay_line_plan plan; // of the line shown
@@ -1945,6 +1966,7 @@ class editor_mode : public application_mode, private editor_track::observer, pri
std::vector<glm::dvec3> points; // the ones clicked it was worked out for
};
std::optional<worked_out> shown;
std::vector<double> traced_key; // what the line traced shown was worked out for: its points, the free end reached, the edits
// the cursor the line is being worked out for, kept till all its fits are done: what it was worked out from
struct settling_cursor
{
@@ -1989,6 +2011,7 @@ class editor_mode : public application_mode, private editor_track::observer, pri
std::vector<TTrack *> tracks;
double length{0.0};
std::vector<laid_curve> curves;
std::optional<trace::result> traced; // the line traced on the photo it was laid by
};
laid_line laid;
};
@@ -2054,8 +2077,10 @@ class editor_mode : public application_mode, private editor_track::observer, pri
void lay_finish(editor_track::snap_target const &End);
void lay_cancel();
void lay_enter();
// Tab: the bends of straights or the curve traced, for the points clicked from now on
// Tab: the bends of straights or the line traced on the photo, for the points clicked so far and from now on
void lay_switch_mode();
// the shape the lay tool starts with: traced where the photo is on, else the bends, till the user chooses one
void lay_shape_default();
// the points the same in number as their modes, a point with none a bend of straights
void lay_trim();
// the track through the points clicked, each the way its mode says; End: the free end it finishes at, the last point then
@@ -2078,6 +2103,28 @@ class editor_mode : public application_mode, private editor_track::observer, pri
return [this](alignment::design const &Base, std::vector<glm::dvec2> const &Points) { return traced_stretch(Base, Points, 0, false, false); };
}
mutable std::vector<std::pair<std::vector<double>, alignment::trace_stretch>> m_stretch_cache;
// the line traced on the photo click after click, the points of the lay tool given to it as they come; and the one ending at a free end
// the cursor is over, kept for it
mutable trace::tracer m_tracer;
mutable std::optional<std::pair<glm::dvec3, trace::result>> m_tracer_ended;
// the tracer of the points clicked now: started anew where the free end it goes on from or the settings changed
trace::tracer const &tracer_now(bool const DropLast = false) const;
trace::settings trace_settings() const;
std::optional<trace::hold> trace_start() const;
// the line traced through the points, ending at the free end End where there's one
bool traced_line(std::vector<glm::dvec3> const &Points, editor_track::snap_target const &End, lay_line_plan &Plan, std::string &Error) const;
// what a curve traced on the photo is, told by the view and the cursor: "curve R 850 m", "nearly straight · curve R 9 km", "compound
// curve R 600/450 m", "R 300 m · up to 70 km/h" in the colour of a warning, refused in the one of an error
static std::string traced_label(trace::curve const &Curve);
static ImU32 traced_colour(trace::curve const &Curve);
// laying by the points traced on the photo: the shape of the points clicked now
bool lay_traced() const { return m_lay.mode == lay_mode::traced; }
// the noise of a click at the point, from the size of a pixel of the view there
double click_sigma_at(glm::dvec3 const &Point) const;
// the view glides on to bring the last point nearer to its middle
void lay_glide();
// the least radius of the norms the tracks are laid to, for the kind of the track given
double least_radius(norms::track_kind const Track) const;
// the stretch the cursor moves along is fitted on a thread, the frames drawn meanwhile with the fit done last
mutable alignment::stretch_fitter m_stretch_fitter;
// a fit the line asked the thread for isn't done yet: the line is one of the fits meanwhile
+443 -42
View File
@@ -180,6 +180,8 @@ void editor_mode::update_build_tools()
lay.preview_length = 0.0;
if (false == lay.active)
return;
lay_shape_default();
lay_glide();
// a slow preview tells in the log where the time went: the cursor on the ground, the snap, the height, the plan of the line
auto stamp{std::chrono::steady_clock::now()};
auto const lap = [&]() {
@@ -199,6 +201,9 @@ void editor_mode::update_build_tools()
if (ImGui::GetIO().KeyAlt && m_typed.empty() && false == lay.points.empty())
lay.mouse = lay_angle_snap(lay.mouse, lay.skew);
lay.mouse_snap = m_typed.empty() ? snap_free_end(lay.mouse, cursor, nullptr, kRailCategory, {}) : editor_track::find_free_end(nullptr, kRailCategory, lay.mouse, kLaySnapRadius, {});
// tracing the photo a free end is reached on the ground, within a metre: the end of the track beside isn't the one clicked at
if (lay_traced() && lay.mouse_snap.track != nullptr && plan_distance(lay.mouse_snap.position, lay.mouse) > kTraceSnap)
lay.mouse_snap = {};
}
auto const snapping{lap()};
if (pointing && lay.mouse_snap.track == nullptr)
@@ -237,16 +242,37 @@ void editor_mode::update_build_tools()
else
{
end = {};
if (plan_distance(mouse, points.back()) > 1.0)
// the line traced is the one of the points clicked: the cursor isn't one of them, a leg to it is drawn apart
if (false == lay_traced() && plan_distance(mouse, points.back()) > 1.0)
{
points.push_back(mouse);
modes.push_back(lay.mode);
}
}
// the line traced is the one of the points clicked, and of the free end reached: worked out once for them, not at every frame
std::vector<double> traced_key;
if (lay_traced())
{
for (auto const &point : points)
traced_key.insert(traced_key.end(), {point.x, point.y, point.z});
traced_key.insert(traced_key.end(), {end.track != nullptr ? 1.0 : 0.0, static_cast<double>(m_track_edits), static_cast<double>(EditorSettings.heights()), lay.style.velocity});
if (lay.shown.has_value() && traced_key == lay.traced_key)
{
auto const &shown{*lay.shown};
lay.preview = shown.preview;
lay.preview_error = shown.error;
lay.preview_length = shown.length;
lay.plan = shown.plan;
m_eased_last = shown.eased;
m_join_last = shown.join;
return;
}
}
m_fits_waiting = false;
m_follow_preview = true;
lay.preview = lay_pieces(points, modes, end, lay.preview_length, lay.preview_error, &lay.plan);
m_follow_preview = false;
lay.traced_key = traced_key;
if (false == m_fits_waiting || false == lay.whole)
{
lay.shown = lay_tool::worked_out{lay.preview, lay.preview_error, lay.preview_length, lay.plan, m_eased_last, m_join_last, lay.points};
@@ -1174,7 +1200,9 @@ std::vector<segment_data> editor_mode::lay_pieces(std::vector<glm::dvec3> const
if (Points.size() < 2)
return {};
auto const unknown{std::numeric_limits<double>::quiet_NaN()};
if (Points.size() == 2 && End.track != nullptr)
// traced on the photo, a point and a free end make a line ending at the end; from one free end to another the join lays the curve
auto const traced_join{std::all_of(Modes.begin(), Modes.end(), [](lay_mode const Mode) { return Mode == lay_mode::traced; }) && tool.start.track == nullptr};
if (Points.size() == 2 && End.track != nullptr && false == traced_join)
{
// two free ends: the curve between them is the one the join finds
if (tool.start.track != nullptr)
@@ -1320,6 +1348,9 @@ bool editor_mode::lay_line(std::vector<glm::dvec3> const &Points, std::vector<la
{
auto const &tool{m_lay};
Plan = {};
// the points traced on the photo: the straights and the curves they show
if (false == Modes.empty() && std::all_of(Modes.begin(), Modes.end(), [](lay_mode const Mode) { return Mode == lay_mode::traced; }))
return traced_line(Points, End, Plan, Error);
auto &design{Plan.design};
design.norms = laying_norms();
design.shape = m_route.design.shape;
@@ -1932,6 +1963,202 @@ bool editor_mode::lay_line(std::vector<glm::dvec3> const &Points, std::vector<la
return true;
}
std::string editor_mode::traced_label(trace::curve const &Curve)
{
auto const radii{trace::radii_text(Curve)};
if (Curve.refused)
return format(STR_C("R %s · below the least radius"), radii.c_str());
if (Curve.restricted)
return format(STR_C("R %s · up to %.0f km/h"), radii.c_str(), Curve.speed);
if (Curve.nearly_straight)
return format(STR_C("nearly straight · curve R %s"), radii.c_str());
if (Curve.compound())
return format(STR_C("compound curve R %s"), radii.c_str());
return format(STR_C("curve R %s"), radii.c_str());
}
ImU32 editor_mode::traced_colour(trace::curve const &Curve)
{
if (Curve.refused)
return overlay_color::invalid;
return Curve.restricted ? overlay_color::warning : overlay_color::marked;
}
double editor_mode::least_radius(norms::track_kind const Track) const
{
auto const setup{setup_now()};
norms::query where;
where.speed = setup.speed;
where.radius = 1000.0;
where.kind = setup.traffic;
where.track = Track;
double least{0.0};
for (auto const &limits : {norms::limits(setup.profile, norms::parameter::radius, where), norms::hard_limits(norms::parameter::radius, where)})
if (limits.block.has_value() && limits.block->confirmed)
least = std::max(least, limits.block->value);
return least;
}
trace::settings editor_mode::trace_settings() const
{
trace::settings settings;
settings.norms = laying_norms();
settings.shape = m_route.design.shape;
settings.speed = std::max(1.0, design_speed(m_lay.start.track, nullptr));
settings.radius_least = least_radius(setup_now().track);
return settings;
}
std::optional<trace::hold> editor_mode::trace_start() const
{
auto const &start{m_lay.start};
if (start.track == nullptr || glm::length(plan_of(start.direction)) < 1e-6)
return std::nullopt;
trace::hold hold;
hold.position = plan_of(start.position);
hold.heading = glm::normalize(-plan_of(start.direction));
// the curve of the track goes on into the line: of a plain track, of the diverging track of a switch at its radius
if (start.track->eType == tt_Normal || start.track->eType == tt_Switch)
if (auto const bend{editor_track::bend_at(*start.track, start.position)}; bend.has_value() && std::abs(bend->curvature) >= 1e-4)
{
hold.curvature = bend->curvature;
hold.cant = std::max(0.0, laying_norms().gauge * std::sin(glm::radians(bend->roll)) * (bend->curvature > 0.0 ? 1.0 : -1.0));
hold.fixed = start.track->eType == tt_Switch;
}
return hold;
}
trace::tracer const &editor_mode::tracer_now(bool const DropLast) const
{
// the points clicked after the free end it goes on from, but the free end reached last
std::vector<glm::dvec2> points;
std::vector<double> sigmas;
auto const &tool{m_lay};
for (std::size_t i = tool.start.track != nullptr ? 1 : 0; i + (DropLast ? 1 : 0) < tool.points.size(); ++i)
{
points.push_back(plan_of(tool.points[i]));
sigmas.push_back(i < tool.sigmas.size() && tool.sigmas[i] > 0.0 ? tool.sigmas[i] : trace::click_sigma(0.1));
}
auto const settings{trace_settings()};
auto const start{trace_start()};
auto const same = [](std::optional<trace::hold> const &A, std::optional<trace::hold> const &B) {
if (A.has_value() != B.has_value())
return false;
return false == A.has_value() || (A->position == B->position && A->heading == B->heading && A->curvature == B->curvature && A->cant == B->cant && A->fixed == B->fixed);
};
if (false == (m_tracer.options() == settings) || false == same(m_tracer.start(), start))
{
m_tracer = trace::tracer{settings, start};
m_tracer_ended.reset();
}
// back to the points in common, then on with the ones clicked since
auto const &have{m_tracer.points()};
std::size_t common{0};
while (common < have.size() && common < points.size() && have[common] == points[common])
++common;
if (m_tracer.size() != common || points.size() != common)
m_tracer_ended.reset();
while (m_tracer.size() > common)
m_tracer.pop();
for (auto i{m_tracer.size()}; i < points.size(); ++i)
{
m_tracer.add(points[i], sigmas[i]);
auto const &now{m_tracer.now()};
if (now.milliseconds > 30.0)
WriteLog(format("Editor: the line traced took %.0f ms at point %zu, %zu evaluations%s", now.milliseconds, i + 1, now.evaluations, now.budget_spent ? ", the budget spent" : ""), logtype::generic);
}
return m_tracer;
}
bool editor_mode::traced_line(std::vector<glm::dvec3> const &Points, editor_track::snap_target const &End, lay_line_plan &Plan, std::string &Error) const
{
auto const &tool{m_lay};
auto const joined{End.track != nullptr && glm::length(plan_of(End.direction)) > 1e-6};
// the points of the tool are the ones traced: those given here, but the free end reached last, are the same
auto const &tracer{tracer_now(joined && false == tool.points.empty() && plan_distance(tool.points.back(), End.position) < 1e-6)};
trace::result line;
if (joined)
{
trace::hold end;
end.position = plan_of(End.position);
end.heading = glm::normalize(plan_of(End.direction));
if (false == m_tracer_ended.has_value() || m_tracer_ended->first != End.position)
m_tracer_ended = std::make_pair(End.position, tracer.ended(end));
line = m_tracer_ended->second;
}
else
line = tracer.now();
if (false == line.valid)
{
Error = line.error == "points" ? STR_C("Click at least two points") : STR_C("No line follows the points clicked along it");
return false;
}
Plan.traced = line;
Plan.design = line.design;
Plan.design.start.y = Points.front().y;
Plan.design.end.y = Points.back().y;
Plan.shape = alignment::compute(Plan.design);
if (false == Plan.shape.valid)
{
Plan.design = line.design;
Plan.shape = line.laid;
}
Plan.corners.assign(Plan.design.vertices.size(), 0);
lay_trace trace;
for (std::size_t i = tool.start.track != nullptr ? 1 : 0; i < tool.points.size(); ++i)
if (false == joined || plan_distance(tool.points[i], End.position) > 1e-6)
trace.points.push_back(tool.points[i]);
trace.offsets = line.offsets;
trace.rms = line.rms;
trace.worst = line.worst;
trace.curves = line.curves.size();
// the grade breaks at the points on the straights, a curve goes at one grade from end to end
for (std::size_t i = 1; i + 1 < trace.points.size() && i < line.on_straight.size(); ++i)
if (line.on_straight[i] != 0)
Plan.knots.push_back(trace.points[i]);
Plan.traces.push_back(std::move(trace));
if (line.refused)
for (auto const &curve : line.curves)
if (curve.refused)
{
Error = format(STR_C("Not laid: R %.0f m is below the least radius of %.0f m the norms allow for this track at any speed"), curve.sharpest(), trace_settings().radius_least);
break;
}
return true;
}
double editor_mode::click_sigma_at(glm::dvec3 const &Point) const
{
if (m_lay.sigma_given > 0.0)
return m_lay.sigma_given;
// the ground a pixel covers there, the shorter of the two ways across it: seen at a slant, along the view it's longer
screen_projection const projection;
ImVec2 at;
ImVec2 east;
ImVec2 south;
if (false == projection.project(Point, at) || false == projection.project(Point + glm::dvec3{1.0, 0.0, 0.0}, east) || false == projection.project(Point + glm::dvec3{0.0, 0.0, 1.0}, south))
return trace::click_sigma(0.25);
auto const pixels{std::max(std::hypot(east.x - at.x, east.y - at.y), std::hypot(south.x - at.x, south.y - at.y))};
return trace::click_sigma(pixels > 1e-6 ? 1.0 / pixels : 0.25);
}
void editor_mode::lay_glide()
{
auto &tool{m_lay};
if (false == tool.glide.has_value())
return;
// a quarter of a second, the camera easing towards where it goes
auto const now{ImGui::GetTime()};
auto const share{std::clamp((now - tool.glide_time) / 0.25, 0.0, 1.0)};
auto const left{*tool.glide - glm::dvec2{Camera.Pos.x, Camera.Pos.z}};
auto const step{share >= 1.0 ? left : left * std::min(1.0, 0.25 + 0.5 * share)};
Camera.Pos.x += step.x;
Camera.Pos.z += step.y;
Global.pCamera = Camera;
if (share >= 1.0 || glm::length(left) < 0.01)
tool.glide.reset();
}
std::optional<alignment::trace_stretch> editor_mode::traced_stretch(alignment::design const &Base, std::vector<glm::dvec2> const &Points, int const Radii, bool const Straights, bool const Meanwhile,
bool *Exact, bool const Going) const
{
@@ -1997,19 +2224,39 @@ void editor_mode::lay_trim()
{
auto &tool{m_lay};
tool.modes.resize(tool.points.size(), lay_mode::straights);
tool.sigmas.resize(tool.points.size(), 0.0);
}
void editor_mode::lay_switch_mode()
{
auto &tool{m_lay};
tool.mode = tool.mode == lay_mode::straights ? lay_mode::curve : lay_mode::straights;
m_track_layout = tool.mode == lay_mode::curve ? track_layout::arc_straight : track_layout::straight;
if (tool.mode == lay_mode::curve)
++tool.tabs;
tool.shape_chosen = true;
tool.mode = tool.mode == lay_mode::traced ? lay_mode::straights : lay_mode::traced;
// the points clicked so far are read the other way too: one line, one shape
lay_trim();
for (auto &mode : tool.modes)
mode = tool.mode;
// a shape dragged out of a free end: an arc and a straight traced on the photo, a straight with the bends, as Tab had it
m_track_layout = tool.mode == lay_mode::traced ? track_layout::arc_straight : track_layout::straight;
if (tool.mode == lay_mode::traced)
first_step_done(first_step::trace);
tool.hint = tool.mode == lay_mode::curve ? STR("Curve traced on the photo, Tab: the straights") : STR("Straights, Tab: a curve traced on the photo");
tool.hint = tool.mode == lay_mode::traced ? STR("From the photo: click along the middle of the track. Tab: the bends") : STR("The bends of straights. Tab: from the photo");
tool.hint_time = ImGui::GetTime();
}
void editor_mode::lay_shape_default()
{
auto &tool{m_lay};
if (tool.shape_chosen || false == tool.points.empty())
return;
auto const mode{m_orthophoto.enabled() ? lay_mode::traced : lay_mode::straights};
if (mode == tool.mode)
return;
tool.mode = mode;
m_track_layout = mode == lay_mode::traced ? track_layout::arc_straight : track_layout::straight;
}
void editor_mode::lay_click()
{
auto &tool{m_lay};
@@ -2028,6 +2275,7 @@ void editor_mode::lay_click()
if (tool.points.empty())
{
tool.start = snap;
tool.continuing = false;
auto point{snap.track != nullptr ? snap.position : tool.mouse};
if (auto const *axis{snap.track == nullptr && ImGui::GetIO().KeyAlt ? skew_reference(point, point, kSkewSeat) : nullptr})
{
@@ -2039,6 +2287,10 @@ void editor_mode::lay_click()
}
tool.points.push_back(point);
tool.modes.push_back(tool.mode);
tool.sigmas.push_back(click_sigma_at(point));
// the photo is traced from above: the view turns to it at the first point
if (lay_traced() && false == Global.EditorOrtho)
toggle_ortho();
return;
}
// the points only make the line shown: it's laid by Enter, or by a click on a free end
@@ -2048,6 +2300,25 @@ void editor_mode::lay_click()
m_typed.clear();
tool.points.push_back(point);
tool.modes.push_back(tool.mode);
tool.sigmas.push_back(click_sigma_at(point));
tool.continuing = false;
// a point clicked near the edge of the view: the view glides on to bring it nearer to the middle
if (ImVec2 screen; lay_traced() && screen_projection{}.project(point, screen))
{
auto const &size{ImGui::GetIO().DisplaySize};
auto const margin{0.15f};
if (size.x > 0.0f && size.y > 0.0f && (screen.x < size.x * margin || screen.x > size.x * (1.0f - margin) || screen.y < size.y * margin || screen.y > size.y * (1.0f - margin)))
{
// the point half way to the middle of the view: the camera moves by half of what it's off the middle on the ground
glm::dvec3 middle;
if (screen_projection{}.on_level(ImVec2(size.x * 0.5f, size.y * 0.5f), point.y, middle))
{
auto const shift{plan_of(point - middle) * 0.5};
tool.glide = glm::dvec2{Camera.Pos.x, Camera.Pos.z} + shift;
tool.glide_time = ImGui::GetTime();
}
}
}
}
void editor_mode::lay_finish(editor_track::snap_target const &End)
@@ -2060,6 +2331,18 @@ void editor_mode::lay_finish(editor_track::snap_target const &End)
auto const pieces{lay_pieces(tool.points, tool.modes, End, length, error, &plan)};
auto const eased{m_eased_last};
tool.status_time = ImGui::GetTime();
// a curve traced below the least radius of the track: nothing laid, the points kept to be put right
if (plan.traced.has_value() && plan.traced->refused)
{
tool.laid_now = false;
tool.status = error;
if (End.track != nullptr && false == tool.points.empty())
{
tool.points.pop_back();
lay_trim();
}
return;
}
if (pieces.empty())
{
tool.laid_now = false;
@@ -2115,6 +2398,31 @@ void editor_mode::lay_finish(editor_track::snap_target const &End)
for (auto const &piece : pieces)
created.push_back(style != nullptr ? editor_track::create_path(*style, piece) : editor_track::create_path(tool.style, piece));
give_own_speed(created);
// the tracks of a curve traced slowed down, its transitions with it, get its speed
if (plan.traced.has_value() && plan.shape.valid)
for (auto const &curve : plan.traced->curves)
{
if (false == curve.restricted)
continue;
// where the curve lies along the line laid with the heights
auto const k{static_cast<int>(&curve - plan.traced->curves.data())};
auto from{plan.shape.length};
auto to{0.0};
for (auto const &e : plan.shape.elements)
if (e.vertex == k && e.kind != alignment::element_kind::straight && e.length > 1e-6)
{
from = std::min(from, e.chainage);
to = std::max(to, e.chainage + e.length);
}
for (auto *track : created)
{
auto const &path{track->m_paths.front()};
auto const middle{plan_of(bezier{path}.point(0.5))};
auto const along{alignment::project(plan.shape, {middle})};
if (false == along.empty() && along.front().chainage > from - 0.01 && along.front().chainage < to + 0.01)
editor_track::velocity(*track, curve.speed);
}
}
editor_track::commit(created);
// the scenery keeps the design the tracks were laid by, as it is, for the plan to edit; read from the paths again it wouldn't be
// the same, a compound curve with transitions between its arcs least of all. A track laid with no design of the line, between two
@@ -2170,17 +2478,59 @@ void editor_mode::lay_finish(editor_track::snap_target const &End)
tool.laid = {created, length, {}};
if (plan.shape.valid)
for (auto const &curve : plan.shape.curves)
tool.laid.curves.emplace_back(format("%d. %s", curve.vertex + 1, curve_label(curve, laying_norms()).c_str()), alignment::meets_norms(curve, plan.design));
if (nmt_fit_laid(tool.history, created.back()->m_paths.front().points[segment_data::point::end]))
{
auto label{curve_label(curve, laying_norms())};
// a curve traced laid slowed down tells the speed it's laid for, not the one its arc alone would allow
if (plan.traced.has_value() && curve.vertex >= 0 && curve.vertex < static_cast<int>(plan.traced->curves.size()) && plan.traced->curves[curve.vertex].restricted)
{
auto const allows{speed_of(curve_sharpest(curve), laying_norms())};
if (false == allows.empty() && label.size() >= allows.size() && label.compare(label.size() - allows.size(), allows.size(), allows) == 0)
label.erase(label.size() - allows.size());
label += format(STR_C(" (up to %.0f km/h)"), plan.traced->curves[curve.vertex].speed);
}
tool.laid.curves.emplace_back(format("%d. %s", curve.vertex + 1, label.c_str()), alignment::meets_norms(curve, plan.design));
}
tool.laid.traced = plan.traced;
// the curves slowed down, told
if (plan.traced.has_value())
for (auto const &curve : plan.traced->curves)
if (curve.restricted)
tool.status += "\n" + format(STR_C("Curve R %s laid for %.0f km/h: sharper than the norms allow at %.0f km/h"), trace::radii_text(curve).c_str(), curve.speed, plan.design.speed);
auto const end{created.back()->m_paths.front().points[segment_data::point::end]};
if (nmt_fit_laid(tool.history, end))
tool.status += "\n" + STR("The grade line of the whole track laid in a row fitted to the terrain model, as the tracks go onto the terrain");
m_nmt_state.laying = false;
nmt_check_buried(tool.history);
WriteLog("Editor: " + tool.status, logtype::generic);
auto const traced{false == tool.modes.empty() && tool.modes.back() == lay_mode::traced};
auto const sigma{tool.sigmas.empty() ? 0.0 : tool.sigmas.back()};
tool.points.clear();
tool.modes.clear();
tool.sigmas.clear();
tool.start = {};
tool.laid_step = m_history.size();
straight_refresh();
// traced on the photo, the line goes on from the end laid till Esc: the next click carries it on, no need to hit the end. The end
// found in the plan: the grade line fitted to the terrain may have lifted or lowered it
if (traced && End.track == nullptr)
{
editor_track::snap_target free;
auto nearest{0.05};
for (auto const &candidate : editor_track::free_ends(nullptr, kRailCategory, end, 100.0, {}))
if (auto const distance{plan_distance(candidate.position, end)}; distance < nearest)
{
nearest = distance;
free = candidate;
}
if (free.track != nullptr)
{
tool.start = free;
tool.points = {free.position};
tool.modes = {lay_mode::traced};
tool.sigmas = {sigma};
tool.continuing = true;
}
}
}
void editor_mode::lay_told(double const Length, std::size_t const Tracks)
@@ -2196,6 +2546,7 @@ void editor_mode::lay_told(double const Length, std::size_t const Tracks)
void editor_mode::lay_enter()
{
auto &tool{m_lay};
++tool.enters;
if (false == m_typed.empty())
{
lay_click();
@@ -2212,10 +2563,17 @@ void editor_mode::lay_enter()
lay_finish(end);
return;
}
// a single point is no track: Enter drops it
// a single point is no track: the end of the line laid last it goes on from is left by Enter, one clicked is told
if (tool.points.size() < 2)
{
lay_cancel();
if (tool.continuing)
{
lay_cancel();
return;
}
tool.status = STR_C("Click at least two points");
tool.status_time = ImGui::GetTime();
tool.laid_now = false;
return;
}
// the laying ends with the track laid: the next click starts anew where it's made, a click on the free end left goes on from
@@ -2228,6 +2586,8 @@ void editor_mode::lay_cancel()
auto &tool{m_lay};
tool.points.clear();
tool.modes.clear();
tool.sigmas.clear();
tool.continuing = false;
tool.start = {};
tool.preview.clear();
tool.plan = {};
@@ -2238,7 +2598,8 @@ void editor_mode::lay_cancel()
std::size_t editor_mode::lay_pending() const
{
return m_lay.points.size();
// the end of the line laid last isn't a point clicked
return m_lay.points.size() - (m_lay.continuing && false == m_lay.points.empty() ? 1 : 0);
}
void editor_mode::lay_escape()
@@ -2247,7 +2608,7 @@ void editor_mode::lay_escape()
lay_trim();
// the points clicked are no track yet and nothing brings them back: a slip of Esc only warns, the second one drops them
auto const pending{lay_pending()};
if (tool.points.size() < 2 || ImGui::GetTime() - tool.escape_time < 3.0)
if (tool.points.size() < 2 || (tool.continuing && tool.points.size() < 2) || ImGui::GetTime() - tool.escape_time < 3.0)
{
lay_cancel();
tool.escape_time = -100.0;
@@ -2282,10 +2643,13 @@ void editor_mode::lay_back()
{
tool.points.pop_back();
tool.modes.pop_back();
tool.sigmas.pop_back();
return;
}
tool.points.clear();
tool.modes.clear();
tool.sigmas.clear();
tool.continuing = false;
tool.start = {};
}
@@ -2395,6 +2759,9 @@ editor_mode::lay_state editor_mode::lay_panel_state() const
{
if (m_extend.active)
return lay_state::extending;
// the line laid just now goes on from its end: told as laid till another point is clicked
if (m_lay.continuing && m_lay.points.size() == 1 && m_lay.laid_now && m_lay.laid_step == m_history.size())
return lay_state::laid;
if (false == m_lay.points.empty())
return lay_state::clicking;
if (m_lay.laid_now && m_lay.laid_step == m_history.size())
@@ -2467,7 +2834,10 @@ editor_mode::lay_quality editor_mode::lay_quality_now() const
quality.speed = lay.plan.design.speed;
for (auto const &curve : lay.plan.shape.curves)
{
auto const speed{arc_speed(curve_sharpest(curve), norms)};
// a curve traced slowed down is laid for its speed
auto speed{arc_speed(curve_sharpest(curve), norms)};
if (lay.plan.traced.has_value() && curve.vertex >= 0 && curve.vertex < static_cast<int>(lay.plan.traced->curves.size()) && lay.plan.traced->curves[curve.vertex].restricted)
speed = std::min(speed, lay.plan.traced->curves[curve.vertex].speed);
quality.slowest = quality.curves == 0 ? speed : std::min(quality.slowest, speed);
++quality.curves;
if (false == alignment::meets_norms(curve, lay.plan.design))
@@ -2492,12 +2862,7 @@ editor_mode::lay_quality editor_mode::lay_quality_now() const
std::string editor_mode::lay_settings_summary() const
{
auto const &lay{m_lay};
std::string text{lay.mode == lay_mode::curve ? STR_C("Curve") : STR_C("Straights")};
if (lay.mode == lay_mode::curve)
{
static char const *const radii[]{"Auto", "1 R", "2 R", "3 R"};
text += std::string{" · "} + STR_C(radii[std::clamp(lay.radii, 0, 3)]);
}
std::string text{lay.mode == lay_mode::traced ? STR_C("From the photo") : STR_C("Bends")};
auto const [from, to]{laying_ends()};
text += format(" · %.0f km/h", design_speed(from, to));
static char const *const heights[]{"along the ground", "through the points", "level"};
@@ -2509,6 +2874,19 @@ std::vector<std::string> editor_mode::lay_leg() const
auto const &lay{m_lay};
auto const norms{laying_norms()};
std::vector<std::string> lines;
// traced on the photo: what the line ends with, and the point clicked last where the line couldn't follow it
if (lay.plan.traced.has_value() && lay.plan.shape.valid)
{
auto const &traced{*lay.plan.traced};
auto const &shape{lay.plan.shape};
if (false == shape.elements.empty() && shape.elements.back().kind == alignment::element_kind::straight && false == lay.points.empty())
lines.push_back(format(STR_C("straight %.0f m"), shape.elements.back().length));
else if (false == traced.curves.empty())
lines.push_back(traced_label(traced.curves.back()));
if (false == traced.misfit.empty() && traced.misfit.back() != 0)
lines.push_back(STR_C("doesn't fit - Backspace takes it back"));
return lines;
}
if (lay.plan.shape.valid)
{
// the straight the cursor is at the end of, and the curve of the last bend before it
@@ -2552,6 +2930,9 @@ std::string editor_mode::extend_leg(double const Length, double const Radius, TT
std::string editor_mode::lay_error() const
{
auto const &lay{m_lay};
// a line traced refused, a curve below the least radius of the track, is told as one which can't be laid
if (lay.plan.traced.has_value() && lay.plan.traced->refused)
return lay.preview_error;
// a line of a design laid with the norms broken is told so by its curves, in orange, and by the badge of the panel
if (lay.preview_error.empty() || (false == lay.preview.empty() && lay.plan.shape.valid))
return {};
@@ -2632,15 +3013,24 @@ void editor_mode::render_lay_ui()
void editor_mode::render_lay_step(lay_state const State)
{
auto const curve{m_lay.mode == lay_mode::curve};
auto const traced{m_lay.mode == lay_mode::traced};
switch (State)
{
case lay_state::extending: editor_flow::step_line(STR_C("Drag to lay from the end; let go to lay it")); break;
case lay_state::clicking:
editor_flow::step_line(curve ? STR_C("Click points along the curve on the photo") : STR_C("Click the next bends"),
editor_flow::step_line(traced ? STR_C("Click along the middle of the track on the photo: every 100-300 m on straights, closer on curves. Enter lays") : STR_C("Click the next bends"),
m_lay.points.size() > 1 ? STR_C("Enter lays · Backspace takes back a point · Esc drops") : STR_C("Backspace takes back the point · Esc drops"));
break;
default: editor_flow::step_line(curve ? STR_C("Click points along the curve on the photo") : STR_C("Click on the ground or at a free end of a track")); break;
case lay_state::laid:
if (m_lay.continuing)
{
editor_flow::step_line(STR_C("Click on along the track to go on with it; Esc ends the line"));
break;
}
[[fallthrough]];
default:
editor_flow::step_line(traced ? STR_C("Click along the middle of the track on the photo: every 100-300 m on straights, closer on curves. Enter lays") : STR_C("Click on the ground or at a free end of a track"));
break;
}
}
@@ -2653,34 +3043,31 @@ void editor_mode::render_lay_settings()
ImGui::TableSetupColumn("##choice", ImGuiTableColumnFlags_WidthStretch);
ImGui::TableSetupColumn("##why", ImGuiTableColumnFlags_WidthFixed);
ImGui::TableNextColumn();
if (int mode{tool.mode == lay_mode::curve ? 1 : 0};
if (int mode{tool.mode == lay_mode::traced ? 0 : 1};
segmented("laymode", mode,
{{0, STR_C("Straights Tab"), "Each point clicked is a bend of the straights: the bend eased with two transition curves meeting, with no cant, of a large radius; where they don't fit, an arc with the transitions and the cant of the norms, as large as fits"},
{1, STR_C("Curve Tab"), "Click points along the middle of a curve seen on the photo: the curve, compound or with a straight in it, is fitted to them and ends at the last one, heading as they do there. It comes from the straight before it, of the points clicked before or of the free end, and goes on with the curve of a free end, a switch too, where the points turn its way"}}) &&
(mode == 1) != (tool.mode == lay_mode::curve))
{{0, STR_C("From the photo Tab"), "Click points along the middle of the track seen on the photo, on its straights and its curves: the straights and the curves, gentle, compound or the other way too, are recognised from them, with the transitions and the cant of the norms. A curve sharper than the norms allow at the speed is laid slower"},
{1, STR_C("Bends Tab"), "Each point clicked is a bend of the straights: the bend eased with two transition curves meeting, with no cant, of a large radius; where they don't fit, an arc with the transitions and the cant of the norms, as large as fits"}}) &&
(mode == 0) != (tool.mode == lay_mode::traced))
lay_switch_mode();
ImGui::TableNextColumn();
auto const curve{tool.mode == lay_mode::curve};
auto const traced{tool.mode == lay_mode::traced};
if (ImGui::SmallButton("?##layshape"))
{
m_first_steps_open = true;
m_tutorial_goto = curve ? "Curves" : "Radius of the curves at the bends";
m_tutorial_goto = traced ? "Curves" : "Radius of the curves at the bends";
}
if (ImGui::IsItemHovered())
{
ImGui::BeginTooltip();
ImGui::PushTextWrapPos(std::round(ImGui::GetFontSize() * 30.0f));
ImGui::TextUnformatted(curve ? STR_C("Click points along the middle of the track on the photo; the curve ends at the last one")
: STR_C("The largest radius that fits between your points is taken: two transition curves meeting, with no cant, from 6000 m down to 2000 m, and below that an arc with the transitions and the cant of the norms"));
ImGui::TextUnformatted(traced ? STR_C("Click along the middle of the track on the photo, on the straights and the curves; Enter lays")
: STR_C("The largest radius that fits between your points is taken: two transition curves meeting, with no cant, from 6000 m down to 2000 m, and below that an arc with the transitions and the cant of the norms"));
ImGui::TextDisabled("%s", STR_C("What it is: the lesson of the tutorial"));
ImGui::PopTextWrapPos();
ImGui::EndTooltip();
}
ImGui::EndTable();
}
if (tool.mode == lay_mode::curve)
segmented("layradii", tool.radii,
{{0, STR_C("Auto"), "As few radii as follow the points, up to three"}, {1, STR_C("1 R"), "One radius"}, {2, STR_C("2 R"), "A compound curve of two radii"}, {3, STR_C("3 R"), "A compound curve of three radii"}});
// the name on the left of the field, as in the inspector, the values to pick with a click under it
if (begin_fields("##layspeed"))
{
@@ -2769,7 +3156,7 @@ void editor_mode::render_lay_details()
ImGui::TextDisabled("%s", on.c_str());
}
// how close a curve traced follows the points clicked along it
if (tool.mode == lay_mode::curve && false == plan.traces.empty() && false == plan.traces.back().offsets.empty())
if ((tool.mode == lay_mode::curve || tool.mode == lay_mode::traced) && false == plan.traces.empty() && false == plan.traces.back().offsets.empty())
{
auto const &trace{plan.traces.back()};
metric_tiles({{format("%zu", trace.points.size()), STR_C("points"), ImGui::GetColorU32(ImGuiCol_Text)},
@@ -2803,8 +3190,8 @@ void editor_mode::render_lay_details()
void editor_mode::render_lay_buttons()
{
auto &tool{m_lay};
// the points clicked are no track until they're laid: Enter lays them, a single point is none
ImGui::BeginDisabled(tool.points.size() < 2);
// the points clicked are no track until they're laid: Enter lays them, a single point is none; a line traced refused none either
ImGui::BeginDisabled(tool.points.size() < 2 || (tool.plan.traced.has_value() && tool.plan.traced->refused));
if (main_button(STR_C("Lay (Enter)"), ImVec2(0.0f, 0.0f)))
{
// the cursor is over the panel: no free end under it to join
@@ -2823,11 +3210,6 @@ void editor_mode::render_lay_more()
auto &tool{m_lay};
if (false == ImGui::TreeNode(STR_C("More settings")))
return;
if (tool.mode == lay_mode::curve)
{
ImGui::Checkbox(STR_C("Two curves with a straight between them, where the points show one"), &tool.straights_between);
item_tooltip("The points along the curve may make two curves, turning the same way or not, with a straight between them, where these follow the points much closer than one curve");
}
ImGui::Checkbox(STR_C("This speed also on from a track with a speed of its own"), &tool.own_speed);
item_tooltip("Off: a track laid on from another one, or joined to it, is designed for the speed of that track and takes it.\nOn: it's designed for the speed above and the new tracks get it.\nWhile laying: Ctrl+Shift+wheel");
ImGui::TextDisabled("%s", STR_C("Dragged from a free end, or laid from a point to one"));
@@ -2918,8 +3300,27 @@ void editor_mode::render_lay_status(lay_state const State)
auto &tool{m_lay};
if (scene::Layers.active() == null_handle)
editor_flow::message_line(STR_C("The scenery isn't opened for editing: new track won't be saved"), ImVec4(1.0f, 0.7f, 0.2f, 1.0f));
auto const refused{tool.plan.traced.has_value() && tool.plan.traced->refused};
if (auto const error{lay_error()}; tool.active && State == lay_state::clicking && false == error.empty())
editor_flow::message_line(error, tool.preview.empty() ? editor_flow::kRefused : ImVec4(1.0f, 0.7f, 0.2f, 1.0f));
editor_flow::message_line(error, tool.preview.empty() || refused ? editor_flow::kRefused : ImVec4(1.0f, 0.7f, 0.2f, 1.0f));
// refused on a main track where a side track may be that sharp: one click makes it one
if (refused && State == lay_state::clicking && setup_now().track == norms::track_kind::main)
{
auto sharpest{std::numeric_limits<double>::max()};
for (auto const &curve : tool.plan.traced->curves)
if (curve.refused)
sharpest = std::min(sharpest, curve.sharpest());
if (auto const side{least_radius(norms::track_kind::side)}; side < least_radius(norms::track_kind::main) && sharpest >= side)
{
if (ImGui::Button(STR_C("It's a side track")))
{
auto setup{setup_now()};
setup.track = norms::track_kind::side;
setup_apply(setup, true);
}
item_tooltip("The assumptions of the project: a side track (a station track), whose least radius is smaller");
}
}
if (tool.status.empty())
return;
if (State != lay_state::laid)
+1 -1
View File
@@ -1458,7 +1458,7 @@ void editor_mode::draw_route_overlay() const
void editor_mode::render_route_trace()
{
auto &trace{m_route.trace};
// the curve is traced on the photo with the laying (Tab), the plan has no button of its own for it
// the line is traced on the photo with the laying (From the photo), the plan has no button of its own for it
if (false == trace.active)
return;
ImGui::SeparatorText(STR_C("Tracing the curve"));
+12 -4
View File
@@ -140,19 +140,24 @@ editor_mode::selftest_result editor_mode::selftest_dispatch(std::string const &c
// laymonkey <seed> <count> [case] random lines laid to and from the free ends of the scenery, as the preview shows them: gaps and
// angles at the joints, loops, the turning wasted and the sharpest curve logged; case: that one alone
// layspeed <km/h> <own 0|1> the speed set for the laying, and whether it goes also on from a track with its own
// laymode <straights|curve>, laytrace <radii 0..3> <straights between 0|1> as the panel of the laying sets them
// laymode <traced|straights|curve|default>, laytrace <radii 0..3> <straights between 0|1> as the panel of the laying sets them, not counted as
// Tab; curve: a curve traced between bends, the shape of before, reached by the self-test alone; default:
// as the user who hasn't chosen, traced where the photo is on
// laysigma <m> the noise of the clicks from now on; 0: two pixels of the view at each
// endcurves logs every free end of the rails: where, the way out and the curvature its track goes on with
// curvejoint <x> <z> logs the paths meeting at the end nearest the point, the curvature of each and its jump from the ones before to the ones after
// cantcheck <label> logs each jump of the cant at a joint of plain tracks, and the steepest ramp of the cant on a path
// fitcheck <label> logs the steps and grade breaks at the joints, the switches off their plane, the rails against the ground
// laywalk <from|into> <x> <z> <spacing> <noise> <k0> <k1> <L>... a line of known curves on from the free end nearest the point,
// the points along it clicked in the mode of a curve, from the end or towards it (see the command)
// the points along it clicked traced on the photo, from the end or towards it (see the command)
// laybends <x> <z> <distance> <degrees> ... <distance> the bends of straights clicked from the free end nearest the point
// layp <x> <z>... the points clicked in the mode set, on the ground, a free end within 3 m reached
// layreport <label> logs the line the points clicked make, as Enter would lay it: its bends and curves, warnings, traces
// layenter, layback, laycancel as Enter, Backspace and Esc while laying
// laysample <x> <z> <heading> <spacing> <noise> <deflection> <R> [<from the first vertex to the second, m> <deflection> <R>]
// a line of known curves, the points along them clicked as a curve traced, the line they make logged
// laysample <x> <z> <heading> <lead> <straight> <spacing> <noise> <deflection> <R[/R2]> <after> [<deflection> <R> <after>]...
// a line of known curves of the norms, lead and after the metres from vertex to vertex, the points
// along it clicked traced on the photo every straight
// metres on its straights and every spacing metres along its curves, the line they make logged
// laychain <layout> <R> <x> <z> | b | u | r | e | t | p... the points clicked, Backspace, undo, redo, Enter, Tab, the line logged
// joints <x> <z>... the joints check over the scenery, the issues around the points logged, every issue with free ends without points
// normsreport <file> [scope 0|1] [plk|tsi|en|ch] [km/h] the tracks checked against the norms of the profile, the line through the
@@ -291,6 +296,9 @@ void editor_mode::selftest_step()
if (false == line.empty() && line.front() != '#')
test.lines.push_back(line);
WriteLog("SELFTEST: " + std::to_string(test.lines.size()) + " steps from " + file);
// the lay tool lays the bends whatever the orthophoto of the settings of the player: a case traces the photo by laymode traced
m_lay.shape_chosen = true;
m_lay.mode = lay_mode::straights;
}
++editor_selftest::frames();
// how long each frame took, for the longest one perf tells
+133 -1
View File
@@ -531,6 +531,120 @@ bool expect_shown(std::string const &Kind, std::string const &What, std::istring
return true;
}
// expect laid <what> ...: the line the lay tool laid last, traced on the photo:
// curves <count>, clicks <at most> (the points it was traced through), length <m> <tolerance>,
// radius <curve> <R>[/<R>...] <tolerance %> (the radii of its arcs), speed <curve> <km/h> (the one it's laid for), nearly <curve> <0|1>,
// slowtracks <km/h> <at least> (its tracks given that speed), joined <0|1> (its first track joined to another at its start)
void expect_laid(std::string const &What, std::istringstream &Words, std::vector<TTrack *> const &Tracks, double const Length, std::optional<trace::result> const &Traced)
{
std::string which;
Words >> which;
if (false == Traced.has_value())
{
expectation(false, What, "no line traced laid", "one");
return;
}
auto const &line{*Traced};
auto const curve_at = [&](int const Index) -> trace::curve const * {
if (Index < 0 || Index >= static_cast<int>(line.curves.size()))
{
expectation(false, What, format("%zu curves", line.curves.size()), format("curve %d", Index));
return nullptr;
}
return &line.curves[Index];
};
if (which == "curves")
{
std::size_t count{0};
Words >> count;
if (malformed(What, Words))
return;
std::string got;
for (auto const &curve : line.curves)
got += (got.empty() ? "" : ", ") + trace::radii_text(curve);
expectation(line.curves.size() == count, What, format("%zu (%s)", line.curves.size(), got.c_str()), std::to_string(count));
}
else if (which == "clicks")
{
std::size_t most{0};
Words >> most;
if (malformed(What, Words))
return;
expectation(line.offsets.size() <= most, What, std::to_string(line.offsets.size()), format("at most %zu", most));
}
else if (which == "length")
{
double wanted{0.0};
double tolerance{0.0};
Words >> wanted >> tolerance;
if (malformed(What, Words))
return;
expect_near(What, Length, wanted, tolerance);
}
else if (which == "radius")
{
int index{0};
std::string radii;
double tolerance{0.0};
Words >> index >> radii >> tolerance;
if (malformed(What, Words))
return;
auto const *curve{curve_at(index)};
if (curve == nullptr)
return;
std::vector<double> wanted;
for (std::istringstream each{radii}; ; )
{
double radius{0.0};
if (false == static_cast<bool>(each >> radius))
break;
wanted.push_back(radius);
each.ignore(1);
}
auto passed{wanted.size() == curve->radii.size()};
for (std::size_t i = 0; passed && i < wanted.size(); ++i)
passed = std::abs(curve->radii[i] - wanted[i]) <= wanted[i] * tolerance / 100.0;
expectation(passed, What, trace::radii_text(*curve), radii + format(" +- %.1f %%", tolerance));
}
else if (which == "speed" || which == "nearly")
{
int index{0};
double wanted{0.0};
Words >> index >> wanted;
if (malformed(What, Words))
return;
auto const *curve{curve_at(index)};
if (curve == nullptr)
return;
if (which == "speed")
expectation(std::abs(curve->speed - wanted) < 0.5, What, format("%.0f km/h", curve->speed), format("%.0f km/h", wanted));
else
expectation(curve->nearly_straight == (wanted != 0.0), What, curve->nearly_straight ? "1" : "0", wanted != 0.0 ? "1" : "0");
}
else if (which == "joined")
{
// the first track of the line laid joined at its start to the track it goes on from
int wanted{0};
Words >> wanted;
if (malformed(What, Words))
return;
auto const joined{false == Tracks.empty() && (Tracks.front()->trPrev != nullptr || Tracks.front()->trNext != nullptr) && Tracks.front()->trPrev != Tracks.front()};
expectation(joined == (wanted != 0), What, joined ? "1" : "0", wanted != 0 ? "1" : "0");
}
else if (which == "slowtracks")
{
double speed{0.0};
std::size_t least{0};
Words >> speed >> least;
if (malformed(What, Words))
return;
auto const count{static_cast<std::size_t>(std::ranges::count_if(Tracks, [&](TTrack const *Track) { return false == Track->m_editorremoved && std::abs(editor_track::velocity(*Track) - speed) < 0.5; }))};
expectation(count >= least, What, std::to_string(count), format("at least %zu", least));
}
else
expectation(false, What, "no expectation laid " + which, "curves, clicks, length, radius, speed, nearly, joined or slowtracks");
}
// expect steps <count>: the steps Ctrl+Z takes back, the ones made together counted once
void expect_steps(std::string const &What, std::istringstream &Words, std::size_t const Steps)
{
@@ -589,6 +703,24 @@ editor_mode::selftest_result editor_mode::selftest_expect(std::string const &com
expect_findings(what, words, m_norms.results());
else if (kind == "steps")
expect_steps(what, words, static_cast<std::size_t>(std::ranges::count_if(m_history, [](EditorSnapshot const &Step) { return false == Step.joined; })));
else if (kind == "laid")
expect_laid(what, words, m_lay.laid.tracks, m_lay.laid.length, m_lay.laid.traced);
else if (kind == "laykeys")
{
// the shapes switched with Tab and the lines laid with Enter since the start
int tabs{0};
int enters{0};
words >> tabs >> enters;
if (false == malformed(what, words))
expectation(m_lay.tabs == tabs && m_lay.enters == enters, what, format("%d Tab, %d Enter", m_lay.tabs, m_lay.enters), format("%d Tab, %d Enter", tabs, enters));
}
else if (kind == "laycontinue")
{
int wanted{0};
words >> wanted;
if (false == malformed(what, words))
expectation(m_lay.continuing == (wanted != 0), what, m_lay.continuing ? "1" : "0", wanted != 0 ? "1" : "0");
}
else
{
shown_state shown{m_switch.status, ui()->refusal_shown(), ui()->status_line(), m_lay.mouse,
@@ -606,7 +738,7 @@ editor_mode::selftest_result editor_mode::selftest_expect(std::string const &com
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, switchpanel or steps");
"selected, laypanel, switchpanel, steps, laid, laykeys or laycontinue");
}
return selftest_result::handled;
}
+124 -59
View File
@@ -475,14 +475,34 @@ editor_mode::selftest_result editor_mode::selftest_join(std::string const &comma
WriteLog("SELFTEST layplan warning: " + warning);
for (auto const &trace : plan.traces)
WriteLog(format("SELFTEST layplan trace: %zu points, %zu curves, departure %.3f m, at most %.3f m", trace.points.size(), trace.curves, trace.rms, trace.worst));
if (plan.traced.has_value())
for (auto const &curve : plan.traced->curves)
WriteLog(format("SELFTEST layplan traced curve: %s, %.0f km/h%s%s%s", trace::radii_text(curve).c_str(), curve.speed, curve.restricted ? ", slowed down" : "", curve.nearly_straight ? ", nearly straight" : "",
curve.refused ? ", refused" : ""));
};
// the shape of the points clicked from now on, set as the panel sets it, not counted as Tab: traced (on the photo), straights (the
// bends), curve (a curve traced between bends, the shape of before)
if (command == "laymode")
{
std::string which;
words >> which;
if ((which == "curve") != (m_lay.mode == lay_mode::curve))
lay_switch_mode();
WriteLog("SELFTEST laymode: " + std::string{m_lay.mode == lay_mode::curve ? "curve" : "straights"});
// default: as for the user who hasn't chosen, traced where the photo is on
m_lay.shape_chosen = which != "default";
m_lay.mode = which == "traced" ? lay_mode::traced : which == "curve" ? lay_mode::curve : lay_mode::straights;
if (false == m_lay.shape_chosen)
lay_shape_default();
lay_trim();
if (m_lay.mode != lay_mode::curve)
for (auto &mode : m_lay.modes)
mode = m_lay.mode;
WriteLog("SELFTEST laymode: " + std::string{m_lay.mode == lay_mode::traced ? "traced" : m_lay.mode == lay_mode::curve ? "curve" : "straights"});
return selftest_result::handled;
}
// the noise of the clicks from now on, m; 0 of the view as it is
if (command == "laysigma")
{
words >> m_lay.sigma_given;
WriteLog(format("SELFTEST laysigma: %.3f m", m_lay.sigma_given));
return selftest_result::handled;
}
if (command == "laytrace")
@@ -568,12 +588,12 @@ editor_mode::selftest_result editor_mode::selftest_join(std::string const &comma
bend->curvature, chainage, position.x, position.y, heading, along.size()));
m_lay.active = true;
lay_cancel();
if (m_lay.mode != lay_mode::straights)
lay_switch_mode();
// traced on the photo, every point the same, no Tab
auto const mode{m_lay.mode};
m_lay.mode = lay_mode::traced;
if (way == "into")
{
lay_point(shifted(position + out * 60.0, side, 0));
lay_switch_mode();
lay_point(shifted(position + out * 30.0, side, 1));
for (auto i{along.size()}; i-- > 0;)
if (glm::distance(along[i], glm::dvec2{end.position.x, end.position.z}) > 3.5)
@@ -584,14 +604,13 @@ editor_mode::selftest_result editor_mode::selftest_join(std::string const &comma
else
{
lay_point(end.position);
lay_switch_mode();
for (std::size_t i = 0; i < along.size(); ++i)
lay_point(shifted(along[i], across[i], static_cast<int>(i)));
lay_point(shifted(position + out * 30.0, side, 1));
lay_point(shifted(position + out * 60.0, side, 2));
WriteLog(format("SELFTEST laywalk from: %zu points, start %s", m_lay.points.size(), m_lay.start.track != nullptr ? m_lay.start.track->name().c_str() : "-"));
}
lay_switch_mode();
m_lay.mode = mode;
return selftest_result::handled;
}
// the bends of straights from the free end nearest the point, within 60 m: the free end clicked, then each point the distance on
@@ -646,77 +665,123 @@ editor_mode::selftest_result editor_mode::selftest_join(std::string const &comma
WriteLog(format("SELFTEST %s: %zu points, history %zu, %s", command.c_str(), m_lay.points.size(), m_history.size(), m_lay.status.c_str()));
return selftest_result::handled;
}
// a line of known curves, turning by the deflections given (degrees, to the left positive), the points along its curves clicked as
// they would be on the photo: the start as a bend, then in the mode of a curve from 30 m before the first curve to the end of the
// last one and two on the straight after it, every Spacing metres, shifted across by up to Noise
// a line of known curves, as the photo would show it, the points along it clicked as on the photo, traced, no Tab: from x z heading
// (degrees) Lead metres to the first vertex, then for each curve its deflection (degrees, to the left positive), its radius and the metres
// to the next vertex or to the end; its transitions and its cant of the norms at the speed of the line, a compound curve of radii R1/R2
// of arcs alike, a curve with no room for them laid smaller (logged). The
// points every Straight metres on the straights, every Spacing metres along the curves, shifted across by up to Noise, the last one at
// the end of the line; left for Enter
// laysample <x> <z> <heading> <lead> <straight> <spacing> <noise> <deflection> <R[/R2]> <after> [<deflection> <R> <after> ...]
if (command == "laysample")
{
double x{0.0}, z{0.0}, heading{0.0}, spacing{20.0}, noise{0.0}, deflection{30.0}, radius{1000.0};
words >> x >> z >> heading >> spacing >> noise >> deflection >> radius;
double apart{0.0}, second{0.0}, secondradius{0.0};
auto const two{static_cast<bool>(words >> apart >> second >> secondradius)};
double x{0.0}, z{0.0}, heading{0.0}, lead{400.0}, straight{150.0}, spacing{20.0}, noise{0.0};
words >> x >> z >> heading >> lead >> straight >> spacing >> noise;
struct sampled_curve
{
double deflection{0.0};
std::vector<double> radii;
double after{0.0};
};
std::vector<sampled_curve> curves;
for (std::string radii; true;)
{
sampled_curve curve;
if (false == static_cast<bool>(words >> curve.deflection >> radii >> curve.after))
break;
for (std::istringstream each{radii}; ;)
{
double radius{0.0};
if (false == static_cast<bool>(each >> radius))
break;
curve.radii.push_back(radius);
each.ignore(1);
}
curves.push_back(curve);
}
alignment::design truth;
truth.norms = laying_norms();
truth.shape = m_route.design.shape;
truth.speed = design_speed(nullptr, nullptr);
glm::dvec2 const start{x, z};
glm::dvec2 point{x, z};
glm::dvec2 direction{std::cos(glm::radians(heading)), std::sin(glm::radians(heading))};
auto const corner1{start + direction * 400.0};
direction = geometry::turned(direction, glm::radians(deflection));
auto corner2{corner1};
if (two)
truth.start = {point.x, 0.0, point.y};
truth.start_direction = direction;
auto leg{lead};
for (auto const &curve : curves)
{
corner2 = corner1 + direction * apart;
direction = geometry::turned(direction, glm::radians(second));
}
auto const end{corner2 + direction * 400.0};
truth.start = {start.x, 0.0, start.y};
truth.end = {end.x, 0.0, end.y};
truth.start_direction = glm::normalize(corner1 - start);
truth.end_direction = direction;
auto const curve_of = [&](double const Radius) {
point += direction * leg;
alignment::vertex vertex;
vertex.radius = Radius;
auto const recommended{alignment::recommend(std::min(truth.speed, alignment::speed_limit(Radius, truth.norms)), Radius, truth.norms)};
vertex.transition_in = vertex.transition_out = recommended.transition;
vertex.cant = recommended.cant;
vertex.offset = 400.0;
return vertex;
};
truth.vertices.push_back(curve_of(radius));
if (two)
truth.vertices.push_back(curve_of(secondradius));
vertex.position = point;
vertex.radius = curve.radii.front();
auto sharpest{vertex.radius};
if (curve.radii.size() > 1)
{
vertex.compound = true;
vertex.share = 1.0;
for (std::size_t i = 1; i < curve.radii.size(); ++i)
vertex.arcs.push_back({curve.radii[i], 0.0, 1.0});
for (auto const radius : curve.radii)
sharpest = std::min(sharpest, radius);
}
auto const allowed{std::min(truth.speed, alignment::speed_limit(sharpest, truth.norms))};
auto const cant{alignment::recommend(allowed, sharpest, truth.norms).cant};
vertex.cant = cant;
vertex.transition_in = alignment::transition_length(allowed, curve.radii.front(), cant * sharpest / curve.radii.front(), truth.norms);
vertex.transition_out = alignment::transition_length(allowed, curve.radii.back(), cant * sharpest / curve.radii.back(), truth.norms);
if (vertex.compound)
alignment::recommend_between(vertex, allowed, truth.norms);
truth.vertices.push_back(vertex);
direction = geometry::turned(direction, glm::radians(curve.deflection));
leg = curve.after;
}
point += direction * leg;
truth.end = {point.x, 0.0, point.y};
truth.end_direction = direction;
if (truth.vertices.size() >= 2)
{
truth.vertices.front().offset = lead;
truth.vertices.back().offset = leg;
}
auto const result{alignment::compute(truth)};
for (auto const &curve : result.curves)
WriteLog(format("SELFTEST laysample truth %d: R %.1f, L %.1f/%.1f, cant %.0f, deflection %.3f deg, valid %d", curve.vertex, curve.radius, curve.transition_in, curve.transition_out, curve.cant, glm::degrees(curve.deflection), result.valid ? 1 : 0));
{
auto radii{format("%.1f", curve.radius)};
if (curve.radii.size() > 1)
{
radii.clear();
for (auto const radius : curve.radii)
radii += (radii.empty() ? "" : "/") + format("%.1f", radius);
}
WriteLog(format("SELFTEST laysample truth %d: R %s, L %.1f/%.1f, cant %.0f, deflection %.3f deg, valid %d", curve.vertex, radii.c_str(), curve.transition_in, curve.transition_out, curve.cant, glm::degrees(curve.deflection), result.valid ? 1 : 0));
}
for (auto const &warning : result.radius_warnings)
WriteLog("SELFTEST laysample truth: " + warning);
if (false == result.valid)
return selftest_result::handled;
auto from{result.length};
auto to{0.0};
for (auto const &e : result.elements)
if (e.kind != alignment::element_kind::straight)
{
from = std::min(from, e.chainage);
to = std::max(to, e.chainage + e.length);
}
auto const curved = [&](double const Chainage) {
for (auto const &e : result.elements)
if (e.kind != alignment::element_kind::straight && Chainage >= e.chainage - 1e-6 && Chainage <= e.chainage + e.length + 1e-6)
return true;
return false;
};
m_lay.active = true;
lay_cancel();
if (m_lay.mode != lay_mode::straights)
lay_switch_mode();
auto const mode{m_lay.mode};
m_lay.mode = lay_mode::traced;
auto const along = [&](double const Chainage, double const Shift) {
auto const station{alignment::evaluate(result, Chainage)};
glm::dvec3 const across{-station.direction.z, 0.0, station.direction.x};
return station.position + glm::normalize(across) * Shift;
};
lay_point(truth.start);
lay_switch_mode();
auto const first{std::max(0.0, from - 30.0)};
for (int count = 0; first + count * spacing <= to; ++count)
lay_point(along(first + count * spacing, noise * (count % 3 == 0 ? 1.0 : count % 3 == 1 ? -0.6 : 0.2)));
lay_point(along(to + 30.0, noise * 0.5));
lay_point(along(to + 60.0, -noise * 0.5));
lay_switch_mode();
WriteLog(format("SELFTEST laysample: %zu points clicked over %.1f m of curves", m_lay.points.size(), to - from));
int count{0};
for (double s{0.0}; s < result.length - 1.0; ++count)
{
lay_point(along(s, noise * (count % 3 == 0 ? 1.0 : count % 3 == 1 ? -0.6 : 0.2)));
s += curved(s) || curved(s + 0.5 * straight) ? spacing : straight;
}
lay_point(along(result.length, noise * 0.5));
m_lay.mode = mode;
WriteLog(format("SELFTEST laysample: %zu points clicked along %.1f m", m_lay.points.size(), result.length));
lay_report("sample");
return selftest_result::handled;
}
+68 -8
View File
@@ -601,6 +601,21 @@ bool editor_mode::track_shortcut(int const Key)
// the key of the mode on leaves it
auto const on{m_track_tab == mode.tab || (mode.tab == track_tab::straights && track_plan_tab())};
auto const leaving{m_track_window_open && on && false == (mode.tab == track_tab::lineside && m_vehicle.tab().open)};
// the points clicked and not laid yet would go with the lay tool: the key only warns, as Esc does, pressed again within 3 s it goes
if (auto const pending{m_lay.active ? lay_pending() : 0}; pending >= 1 && m_lay.points.size() >= 2 && (leaving ? track_tab::path : mode.tab) != track_tab::lay)
{
auto const now{ImGui::GetTime()};
if (m_lay.leave_key != Key || now - m_lay.leave_time >= 3.0)
{
m_lay.leave_key = Key;
m_lay.leave_time = now;
m_lay.escape_time = now;
m_lay.status = format(STR_P("%s again drops the point not laid, Enter lays it", "%s again drops the %zu points not laid, Enter lays them", static_cast<long long>(pending)), mode.key, pending);
m_lay.status_time = now;
return true;
}
m_lay.leave_key = 0;
}
show_track_tab(leaving ? track_tab::path : mode.tab);
// B opens on the posts, as the button of Posts does, also from the trainset
if (mode.tab == track_tab::lineside && false == leaving)
@@ -2074,12 +2089,16 @@ std::vector<editor_mode::key_hint> editor_mode::track_key_hints(bool const All)
// a shape dragged out of a free end tells its own
if (m_lay.active && false == m_extend.active)
{
bool const curve{m_lay.mode == lay_mode::curve};
auto const *tab{curve ? "back to the straights" : "a curve from the photo"};
auto const *next{curve ? "the next point along the curve" : "the next bend"};
bool const traced{m_lay.mode == lay_mode::traced};
auto const *tab{traced ? "the bends" : "from the photo"};
auto const *next{traced ? "a point on the track" : "the next bend"};
auto const *alt{"the direction in steps of 15 degrees, or 1:9, 1:6.6... to a straight track"};
if (m_lay.points.empty())
hints = {{"LMB", "the first point"}, {"LMB on a free end", "from the end"}, {"Tab", tab}, {"Drag from a free end", "lays the shape to the cursor"}, {"Shift+click a straight", "a parallel track (N)"}, {"Alt", alt}, {"Esc", "stop laying"}};
hints = {{"LMB", traced ? "a point on the track" : "the first point"}, {"LMB on a free end", "from the end"}, {"Tab", tab}, {"Drag from a free end", "lays the shape to the cursor"}, {"Shift+click a straight", "a parallel track (N)"}, {"Alt", alt}, {"Esc", "stop laying"}};
else if (traced && m_lay.continuing && m_lay.points.size() == 1)
hints = {{"LMB", "goes on with the line laid"}, {"Esc", "ends the line"}, {"Tab", tab}};
else if (traced && m_lay.points.size() > 1)
hints = {{"LMB", next}, {"Enter", "lay"}, {"Backspace", "take back"}, {"LMB on a free end", "join and lay"}, {"Tab", tab}, {"Esc", "twice: drop the points not laid"}};
else if (m_lay.points.size() > 1)
// the points clicked are no track until Enter: it comes right after the click, where the bar at the bottom shows it
hints = {{"LMB", next}, {"Enter", "lay"}, {"Backspace", "take back"}, {"LMB on a free end", "join and lay"}, {"Tab", tab}, {"Alt", alt}, {"Esc", "twice: drop the points not laid"}};
@@ -2088,7 +2107,7 @@ std::vector<editor_mode::key_hint> editor_mode::track_key_hints(bool const All)
hints = {{"LMB", next}, {"LMB on a free end", "join and lay"}, {"Backspace", "take back"}};
if (m_lay.mouse_snap.track != nullptr && m_lay.start.track != nullptr)
hints.insert(hints.end(), {{"Ctrl+wheel", "radius"}, {"Shift+wheel", "another shape"}});
else if (m_lay.mouse_snap.track != nullptr && curve)
else if (m_lay.mouse_snap.track != nullptr && m_lay.mode == lay_mode::curve)
hints.push_back({"Ctrl+wheel", "radius"});
hints.insert(hints.end(), {{"Ctrl+Shift+wheel", "speed"}, {"Tab", tab}, {"Alt", alt}, {"Enter", "stop laying"}, {"Esc", "stop laying"}});
}
@@ -3114,8 +3133,16 @@ void editor_mode::draw_build_overlay() const
{
for (auto const &curve : plan.shape.curves)
if (curve.vertex >= 0 && curve.vertex < static_cast<int>(plan.shape.vertex_chainages.size()))
label_at(alignment::evaluate(plan.shape, plan.shape.vertex_chainages[curve.vertex]).position, curve_short(curve, laying_norms()),
alignment::meets_norms(curve, plan.design) ? overlay_color::marked : overlay_color::warning);
{
auto const at{alignment::evaluate(plan.shape, plan.shape.vertex_chainages[curve.vertex]).position};
if (plan.traced.has_value() && curve.vertex < static_cast<int>(plan.traced->curves.size()))
{
auto const &traced{plan.traced->curves[curve.vertex]};
label_at(at, traced_label(traced), traced_colour(traced));
continue;
}
label_at(at, curve_short(curve, laying_norms()), alignment::meets_norms(curve, plan.design) ? overlay_color::marked : overlay_color::warning);
}
for (auto const &e : plan.shape.elements)
if (e.kind == alignment::element_kind::straight && e.length >= 20.0)
label_at(alignment::evaluate(plan.shape, e.chainage + e.length * 0.5).position, format(STR_C("straight %.0f m"), e.length), overlay_color::highlight);
@@ -3159,7 +3186,7 @@ void editor_mode::draw_build_overlay() const
i = j;
}
for (auto const &[colour, width] : {std::pair{IM_COL32(0, 0, 0, 120), 3.0f}, std::pair{IM_COL32(255, 255, 255, 160), 1.0f}})
for (std::size_t i = 0; i + 1 < lay.points.size(); ++i)
for (std::size_t i = 0; i + 1 < lay.points.size() && lay.mode != lay_mode::traced; ++i)
projection.line(drawlist, lay.points[i], lay.points[i + 1], colour, width);
// the bends of straights as squares, the points along a curve as dots in the colour of how far the line laid is from them
auto const departure = [&](glm::dvec3 const &Point) {
@@ -3180,6 +3207,28 @@ void editor_mode::draw_build_overlay() const
drawwidth(lay.points[i], overlay_color::grip);
continue;
}
if (i < lay.modes.size() && lay.modes[i] == lay_mode::traced)
{
auto colour{overlay_color::grip};
if (auto const off{departure(lay.points[i])}; off >= 0.0)
{
auto const sigma{i < lay.sigmas.size() && lay.sigmas[i] > 0.0 ? lay.sigmas[i] : 0.1};
colour = off <= std::max(0.1, sigma) ? IM_COL32(90, 220, 110, 255) : off <= std::max(0.3, 3.0 * sigma) ? IM_COL32(255, 200, 60, 255) : IM_COL32(255, 90, 70, 255);
}
// the point the line couldn't be fitted to: the line stayed as it was
if (plan.traced.has_value())
{
auto const index{i - (lay.start.track != nullptr ? 1 : 0)};
if (index < plan.traced->misfit.size() && plan.traced->misfit[index] != 0)
{
colour = IM_COL32(255, 200, 60, 255);
drawlist->AddCircle(screen, 8.5f, colour, 16, 2.0f);
}
}
drawlist->AddCircleFilled(screen, 4.5f, colour);
drawlist->AddCircle(screen, 4.5f, IM_COL32(0, 0, 0, 170), 12, 1.5f);
continue;
}
if (i < lay.modes.size() && lay.modes[i] == lay_mode::curve)
{
auto const off{departure(lay.points[i])};
@@ -3191,6 +3240,17 @@ void editor_mode::draw_build_overlay() const
drawlist->AddRectFilled(ImVec2(screen.x - 4.5f, screen.y - 4.5f), ImVec2(screen.x + 4.5f, screen.y + 4.5f), overlay_color::grip);
drawlist->AddRect(ImVec2(screen.x - 4.5f, screen.y - 4.5f), ImVec2(screen.x + 4.5f, screen.y + 4.5f), IM_COL32(0, 0, 0, 170), 0.0f, 0, 1.5f);
}
// traced: the leg from the last point to the cursor, dashed, where the next click goes
if (lay.mode == lay_mode::traced && false == lay.points.empty() && lay.mouse_snap.track == nullptr && plan_distance(lay.points.back(), lay.mouse) > 1.0)
{
auto const &from{lay.points.back()};
auto const length{plan_distance(from, lay.mouse)};
auto const dashes{std::clamp(static_cast<int>(length / 3.0), 1, 400)};
for (int k = 0; k < dashes; k += 2)
projection.line(drawlist, glm::mix(from, lay.mouse, static_cast<double>(k) / dashes), glm::mix(from, lay.mouse, static_cast<double>(k + 1) / dashes), IM_COL32(255, 255, 255, 170), 1.5f);
if (ImVec2 cursor; projection.project(lay.mouse, cursor))
drawlist->AddCircle(cursor, 6.0f, overlay_color::grip, 16, 2.0f);
}
// the point the cursor would add along a curve
if (ImVec2 cursor; lay.mode == lay_mode::curve && false == lay.points.empty() && lay.mouse_snap.track == nullptr && projection.project(lay.mouse, cursor))
{
+1
View File
@@ -221,6 +221,7 @@ editor_track::point_kind const kPointKinds[] = {editor_track::point_kind::start,
float const kHandleRadius{10.0f};
double const kLaySnapRadius{5.0};
double const kTraceSnap{1.0}; // m on the ground a free end is reached within while tracing the photo
float const kSnapPixels{16.0f};
double const kSwitchReach{6.0}; // a press farther from the selected track selects another one instead of placing the switch
double const kFreeSwitchLock{4.0}; // m of the drag a switch with no track takes the direction of its main track from
+83 -63
View File
@@ -11722,24 +11722,9 @@ msgstr "Prosta przed łukiem i prosta za nim się nie przecinają"
msgid "No curve follows the points clicked along it"
msgstr "Żaden łuk nie przechodzi przez punkty kliknięte wzdłuż niego"
msgid "Curve: click points along the middle of the track, the last two on the straight after the curve. Tab: back to the straights"
msgstr "Łuk: klikaj punkty po środku toru, dwa ostatnie na prostej za łukiem. Tab: z powrotem proste"
msgid "Straights: each point clicked is a bend of the straights, eased with a large curve. Tab: a curve traced on the photo"
msgstr "Proste: każdy kliknięty punkt to załamanie prostych, wyokrąglone dużym łukiem. Tab: łuk odrysowany z ortofotomapy"
msgid "Straights Tab"
msgstr "Proste Tab"
msgid "Curve Tab"
msgstr "Łuk Tab"
msgid "Each point clicked is a bend of the straights: the bend eased with two transition curves meeting, with no cant, of a large radius; where they don't fit, an arc with the transitions and the cant of the norms, as large as fits"
msgstr "Każdy kliknięty punkt to załamanie prostych: wyokrąglone dwiema stycznymi krzywymi przejściowymi bez przechyłki, o dużym promieniu; gdzie się nie mieszczą, łukiem z krzywymi przejściowymi i przechyłką według norm, tak dużym, jak się mieści"
msgid "Click points along the middle of a curve seen on the photo, the last two on the straight after it: the curve, compound or with a straight in it, is fitted to them. It comes from the straight before it, of the points clicked before or of the free end"
msgstr "Klikaj punkty po środku łuku widocznego na ortofotomapie, dwa ostatnie na prostej za nim: łuk, także koszowy albo z prostą w środku, zostanie do nich dopasowany. Wychodzi z prostej przed nim, wyznaczonej punktami klikniętymi wcześniej albo wolnym końcem"
msgid "Radius of the curves at the bends"
msgstr "Promień łuków na załamaniach"
@@ -11755,15 +11740,6 @@ msgstr "Promień, przy którym stykają się dwie krzywe przejściowe załamania
msgid "The radius tried first; a bend too slight for transitions long enough at the speed takes a larger one"
msgstr "Promień próbowany najpierw; załamanie zbyt małe na krzywe przejściowe dość długie dla prędkości dostaje większy"
msgid "Two curves with a straight between them, where the points show one"
msgstr "Dwa łuki z prostą między nimi, gdy punkty ją pokazują"
msgid "The points along the curve may make two curves, turning the same way or not, with a straight between them, where these follow the points much closer than one curve"
msgstr "Punkty wzdłuż łuku mogą dać dwa łuki, w tę samą stronę albo przeciwne, z prostą między nimi, gdy trzymają się punktów dużo lepiej niż jeden łuk"
msgid "Click points along the middle of the track on the photo, the last two on the straight after the curve"
msgstr "Klikaj punkty po środku toru na ortofotomapie, dwa ostatnie na prostej za łukiem"
msgid "Curves of the track laid"
msgstr "Łuki kładzionego toru"
@@ -11785,15 +11761,9 @@ msgstr "ten łuk nie spełnia norm, zostanie położony mimo to"
msgid "%zu points, departure %.0f cm, at most %.0f cm"
msgstr "%zu punktów, odchyłka %.0f cm, najwięcej %.0f cm"
msgid "Curve traced, Tab: the bends of straights"
msgstr "Łuk odrysowywany, Tab: załamania prostych"
msgid "back to the bends of straights"
msgstr "z powrotem załamania prostych"
msgid "trace a curve on the photo"
msgstr "odrysuj łuk z ortofotomapy"
msgid "a point along the middle of the curve, the last two on the straight after it"
msgstr "punkt po środku łuku, dwa ostatnie na prostej za nim"
@@ -11809,9 +11779,6 @@ msgstr "Układanie toru: każdy klik to załamanie prostych, wyokrąglone dużym
msgid "Tab while laying"
msgstr "Tab przy układaniu"
msgid "The points clicked next go along the middle of a curve seen on the photo, the last two on the straight after it; Tab again: back to the bends"
msgstr "Następne punkty idą po środku łuku widocznego na ortofotomapie, dwa ostatnie na prostej za nim; ponownie Tab: z powrotem załamania"
msgid "Type the length of the next straight, Enter puts the point"
msgstr "Wpisz długość następnej prostej, Enter stawia punkt"
@@ -12104,9 +12071,6 @@ msgstr "Kliknij kilka punktów i naciśnij Enter"
msgid "Every place where the line turns gets a curve, as big as fits. An orange label means the curve breaks the rules for the speed set in the panel"
msgstr "Każde miejsce, w którym linia skręca, dostaje łuk, tak duży, jak się zmieści. Pomarańczowy opis znaczy, że łuk nie spełnia przepisów dla prędkości ustawionej w panelu"
msgid "A curve seen on the photo: click points along its middle, the last two on the straight after it; one of two or three radii comes out a compound curve"
msgstr "Łuk widoczny na ortofotomapie: klikaj punkty wzdłuż jego środka, dwa ostatnie na prostej za nim; łuk o dwóch albo trzech promieniach wychodzi jako koszowy"
msgid "Lay a track that turns"
msgstr "Ułóż tor, który skręca"
@@ -12293,12 +12257,6 @@ msgstr "Następne punkty idą po środku łuku widocznego na ortofotomapie, któ
msgid "Curve: click points along the middle of the track, the curve ends at the last one. Tab: back to the straights"
msgstr "Łuk: klikaj punkty po środku toru, łuk kończy się na ostatnim. Tab: z powrotem proste"
msgid "Click points along the middle of a curve seen on the photo: the curve, compound or with a straight in it, is fitted to them and ends at the last one, heading as they do there. It comes from the straight before it, of the points clicked before or of the free end, and goes on with the curve of a free end, a switch too, where the points turn its way"
msgstr "Klikaj punkty po środku łuku widocznego na ortofotomapie: łuk, także koszowy albo z prostą w środku, zostanie do nich dopasowany i kończy się na ostatnim, w kierunku, w jakim tam biegną. Wychodzi z prostej przed nim, wyznaczonej punktami klikniętymi wcześniej albo wolnym końcem, a gdy punkty skręcają w stronę łuku wolnego końca, także rozjazdu, ten łuk idzie dalej"
msgid "Click points along the middle of the track on the photo; the curve ends at the last one"
msgstr "Klikaj punkty po środku toru na ortofotomapie; łuk kończy się na ostatnim"
msgid "a point along the middle of the curve, which ends at the last one"
msgstr "punkt po środku łuku, który kończy się na ostatnim"
@@ -14710,9 +14668,6 @@ msgstr "Kliknij na terenie albo na wolnym końcu toru"
msgid "Click the next bends"
msgstr "Klikaj kolejne załamania"
msgid "Click points along the curve on the photo"
msgstr "Klikaj punkty wzdłuż łuku na ortofotomapie"
msgid "Enter lays · Backspace takes back a point · Esc drops"
msgstr "Enter układa · Backspace cofa punkt · Esc porzuca"
@@ -14731,9 +14686,6 @@ msgstr[2] "Ułożono %.0f m (%zu torów) · Ctrl+Z cofa"
msgid "notes"
msgstr "uwagi"
msgid "Straights"
msgstr "Proste"
msgid "along the ground"
msgstr "po terenie"
@@ -14782,30 +14734,15 @@ msgstr "łuk R %s m"
msgid "R %s · up to %.0f km/h"
msgstr "R %s · do %.0f km/h"
msgid "Curve traced on the photo, Tab: the straights"
msgstr "Łuk odrysowany z ortofotomapy, Tab: proste"
msgid "Straights, Tab: a curve traced on the photo"
msgstr "Proste, Tab: łuk odrysowany z ortofotomapy"
msgid "the first point"
msgstr "pierwszy punkt"
msgid "from the end"
msgstr "od końca"
msgid "a curve from the photo"
msgstr "łuk z ortofotomapy"
msgid "back to the straights"
msgstr "z powrotem proste"
msgid "the next bend"
msgstr "następne załamanie"
msgid "the next point along the curve"
msgstr "następny punkt łuku"
msgid "take back"
msgstr "cofnij"
@@ -15470,3 +15407,86 @@ msgstr "Zdjęcia lotnicze z geoportal.gov.pl, te same co pod scenerią w edytorz
msgid "Zoom in for the photos"
msgstr "Przybliż, by zobaczyć zdjęcia"
# scenery editor: laying traced on the photo
msgid "From the photo"
msgstr "Po zdjęciu"
msgid "Bends"
msgstr "Załamania"
msgid "From the photo Tab"
msgstr "Po zdjęciu Tab"
msgid "Bends Tab"
msgstr "Załamania Tab"
msgid "doesn't fit - Backspace takes it back"
msgstr "nie pasuje — Backspace cofa"
msgid "Click along the middle of the track on the photo: every 100-300 m on straights, closer on curves. Enter lays"
msgstr "Klikaj po środku toru na zdjęciu — na prostych co 100–300 m, na łukach gęściej. Enter układa"
msgid "Click on along the track to go on with it; Esc ends the line"
msgstr "Klikaj dalej po torze, żeby go ciągnąć; Esc kończy linię"
msgid "Click points along the middle of the track seen on the photo, on its straights and its curves: the straights and the curves, gentle, compound or the other way too, are recognised from them, with the transitions and the cant of the norms. A curve sharper than the norms allow at the speed is laid slower"
msgstr "Klikaj punkty po środku toru widocznego na zdjęciu, na prostych i na łukach: proste i łuki, także łagodne, koszowe i w drugą stronę, edytor rozpozna sam, z krzywymi przejściowymi i przechyłką według norm. Łuk ciaśniejszy, niż normy pozwalają przy tej prędkości, zostanie ułożony z ograniczeniem prędkości"
msgid "Click along the middle of the track on the photo, on the straights and the curves; Enter lays"
msgstr "Klikaj po środku toru na zdjęciu, na prostych i na łukach; Enter układa"
msgid "From the photo: click along the middle of the track. Tab: the bends"
msgstr "Po zdjęciu: klikaj po środku toru. Tab: załamania"
msgid "The bends of straights. Tab: from the photo"
msgstr "Załamania prostych. Tab: po zdjęciu"
msgid "R %s · below the least radius"
msgstr "R %s · poniżej najmniejszego promienia"
msgid "nearly straight · curve R %s"
msgstr "prawie prosto · łuk R %s"
msgid "compound curve R %s"
msgstr "łuk koszowy R %s"
msgid "curve R %s"
msgstr "łuk R %s"
msgid "No line follows the points clicked along it"
msgstr "Żadna linia nie pasuje do klikniętych punktów"
msgid "Not laid: R %.0f m is below the least radius of %.0f m the norms allow for this track at any speed"
msgstr "Nie ułożono: R %.0f m to mniej niż najmniejszy promień %.0f m, na jaki normy pozwalają dla tego toru przy jakiejkolwiek prędkości"
msgid "Curve R %s laid for %.0f km/h: sharper than the norms allow at %.0f km/h"
msgstr "Łuk R %s ułożony na %.0f km/h: ciaśniejszy, niż normy pozwalają przy %.0f km/h"
msgid "It's a side track"
msgstr "To tor boczny"
msgid "The assumptions of the project: a side track (a station track), whose least radius is smaller"
msgstr "Założenia projektu: tor boczny (stacyjny), którego najmniejszy promień jest mniejszy"
msgid "the bends"
msgstr "załamania"
msgid "from the photo"
msgstr "po zdjęciu"
msgid "a point on the track"
msgstr "punkt na torze"
msgid "goes on with the line laid"
msgstr "ciągnie ułożoną linię"
msgid "ends the line"
msgstr "kończy linię"
msgid "%s again drops the point not laid, Enter lays it"
msgid_plural "%s again drops the %zu points not laid, Enter lays them"
msgstr[0] "%s jeszcze raz porzuca nieułożony punkt, Enter go układa"
msgstr[1] "%s jeszcze raz porzuca %zu nieułożone punkty, Enter je układa"
msgstr[2] "%s jeszcze raz porzuca %zu nieułożonych punktów, Enter je układa"
+16 -1
View File
@@ -125,6 +125,10 @@ tool's `parallel <spacing> <side>` lay turnouts, crossovers and lines of the mod
| `expect setup none`, `expect setup <key> <value>` | the assumptions of the project of the scenery: none said yet, or the value of a key as their record writes it (`norms`, `speed`, `traffic`, `track`, `gauge`, `rail`) |
| `expect setupmark <present\|absent>` | the scenery holds the line of the assumptions (`//$u setup ...`), or not |
| `expect layspeed <km/h>` | the speed the lay tool lays at |
| `expect laid curves <count>`, `expect laid clicks <at most>`, `expect laid length <m> <tolerance>` | the line traced on the photo laid last: its curves, the points it was traced through, its length |
| `expect laid radius <curve> <R>[/<R>...] <tolerance %>`, `expect laid speed <curve> <km/h>`, `expect laid nearly <curve> <0\|1>` | a curve of it: the radii of its arcs, the speed it's laid for, nearly straight (R 5 km and more) |
| `expect laid slowtracks <km/h> <at least>`, `expect laid joined <0\|1>` | its tracks given the speed of a curve slowed down; its first track joined at its start to the one it goes on from |
| `expect laykeys <tabs> <enters>`, `expect laycontinue <0\|1>` | the shapes switched with Tab and the lines laid with Enter so far; the lay tool goes on from the end of the line laid |
Files `scenery/autotest_editor.<part>.scn` are copied next to the copy of the fixture as `autotest_editor_<case>_<part>.scn`, the name of
the fixture in them made the name of its copy: scenarios of its map, for the scenario index (`autotest_editor.uses.scn`, a trainset on `s1`).
@@ -176,7 +180,7 @@ 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_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 traced on the photo |
| `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 |
and the editing on the model of the track geometry (E4a of the plan of the track editing), with the setting on:
@@ -213,6 +217,17 @@ and the aerial photo with no fuss (stage 3 of laying the tracks over the aerial
| `ph_3_tracks_over_photo` | in the top view zoomed in under 0.5 m a pixel the tracks are drawn over the photo; without the photo they aren't |
| `ph_4_toolbar_toggle` | the photo button of the toolbar of the tracks and ~ turn the photo on and off as the user's choice, the terrain of the model doesn't turn it on again; F1 lists ~ |
and laying traced on the photo (`laymode traced`, `laysigma`, `laysample`: the points along a line of known curves of the norms, clicked
as on the photo):
| case | checks |
| --- | --- |
| `tr_1_three_curves` | a line of 3.2 km with three curves, clicked in 20 points at most, no Tab, one Enter: the three curves found, their radii within 3 %, laid at the speed of the line |
| `tr_2_nearly_straight` | a curve of R 9 km over 800 m, clicked every 200 m: a curve, nearly straight, its radius within 10 % |
| `tr_3_compound` | a compound curve of R 600 and 400 m clicked along it: one curve of two radii, each within 3 % |
| `tr_4_below_norms` | a curve of R 300 m on a line of 120 km/h laid slowed down to 70 km/h, its tracks given it; one of R 150 m, below the least radius of a main track, not laid |
| `tr_5_continue` | after Enter the next clicks carry the line on from its end, joined to it; Esc ends it |
and the assumptions of the project and the norms enforced when laying (`editor-project-setup.md`):
| case | checks |
+2 -2
View File
@@ -1,6 +1,6 @@
# Laying flow: the panel of the lay tool goes through its states, each with its step at its top. Nothing clicked: its settings shown.
# Points clicked: the settings folded to the line of their summary. The line laid with Enter: told in one line over the settings
# shown again. Taken back with Ctrl+Z: ready, the line laid no more told. The same in the mode of a curve traced. The points go on
# shown again. Taken back with Ctrl+Z: ready, the line laid no more told. The same traced on the photo. The points go on
# the empty ground between the turntable tt1 and the curves (x 220..270), the camera straight above them
wait 5
tap f3
@@ -22,7 +22,7 @@ expect laypanel laid shown
undo
wait 2
expect laypanel ready shown
laymode curve
laymode traced
wait 2
expect laypanel ready shown
layp 225 120 235 165 245 180
+26
View File
@@ -0,0 +1,26 @@
# Laying from the photo: a line of 3.2 km with three curves of the norms (R 1200, 900 the other way, 1500) clicked along the middle of the
# track as on the photo, sparsely, 20 clicks at most, in the shape traced on the photo, with no Tab and one Enter: the three curves are
# recognised, their radii within 3 %, laid at the speed of the line. The empty ground north-east of the fixture (x 2000.., z 2000..)
wait 5
tap f3
wait 2
tap l
wait 2
laymode traced
laysigma 0.2
laysample 2000 2000 0 500 300 160 0.15 30 1200 1130 -40 900 1130 25 1500 600
wait 2
expect laypanel clicking folded
layenter
wait 2
expect laypanel laid shown
expect laid clicks 20
expect laid curves 3
expect laid radius 0 1200 3
expect laid radius 1 900 3
expect laid radius 2 1500 3
expect laid speed 0 100
expect laid speed 1 100
expect laid speed 2 100
expect laykeys 0 1
quit
@@ -0,0 +1,18 @@
# Laying from the photo: a "straight" which is a curve of R 9 km over 800 m, clicked every 200 m: recognised as a curve, nearly straight,
# its radius within 10 %, not laid as a straight. The empty ground north-east of the fixture
wait 5
tap f3
wait 2
tap l
wait 2
laymode traced
laysigma 0.2
laysample 2000 3000 0 700 200 200 0.15 5.09 9000 700
wait 2
layenter
wait 2
expect laid curves 1
expect laid nearly 0 1
expect laid radius 0 9000 10
expect laykeys 0 1
quit
+16
View File
@@ -0,0 +1,16 @@
# Laying from the photo: a compound curve of R 600 and 400 m of the norms, clicked close along the curve as the hint says: one curve of two
# radii, each within 3 %. The empty ground north-east of the fixture
wait 5
tap f3
wait 2
tap l
wait 2
laymode traced
laysigma 0.15
laysample 2000 4000 0 600 150 15 0.1 60 600/400 600
wait 2
layenter
wait 2
expect laid curves 1
expect laid radius 0 600/400 3
quit
+29
View File
@@ -0,0 +1,29 @@
# Laying from the photo: a curve of R 300 m on a line of 120 km/h, sharper than the norms allow at that speed, is laid slowed down to the
# speed its radius allows, 70 km/h, its tracks given that speed, with no question. One of R 150 m, below the least radius of a main track
# (PLK 180 m), isn't laid at all: the points stay to be put right. The empty ground north-east of the fixture
wait 5
setup norms plk speed 120 traffic mixed track main gauge 1435 rail 60E1
expect layspeed 120
tap f3
wait 2
tap l
wait 2
laymode traced
laysigma 0.15
laysample 2000 5000 0 300 150 25 0.1 50 300 300
wait 2
layenter
wait 2
expect laid curves 1
expect laid radius 0 300 3
expect laid speed 0 70
expect laid slowtracks 70 2
laycancel
laysample 3500 5000 0 300 150 15 0.1 60 150 300
wait 2
expect steps 1
layenter
wait 2
expect steps 1
expect laypanel clicking folded
quit
+31
View File
@@ -0,0 +1,31 @@
# Laying from the photo: after Enter the tool stays at the end laid, the next clicks carry the line on from there, joined to it, with no
# click on the free end; Esc ends it. The empty ground north-east of the fixture
wait 5
tap f3
wait 2
tap l
wait 2
laymode traced
laysigma 0.15
layp 2000 6000 2150 6000 2300 6000 2450 6000
wait 2
layenter
wait 2
expect laycontinue 1
expect laypanel laid shown
expect laid curves 0
# on along the same straight, then into a curve to the left
layp 2600 6000 2750 6000 2900 6000 3050 6002.5 3200 6012 3340 6030
wait 2
expect laypanel clicking folded
layenter
wait 2
expect laid joined 1
expect laid curves 1
expect laycontinue 1
expect steps 2
tap esc
wait 2
expect laycontinue 0
expect laypanel ready shown
quit