mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-12-01 11:47:06 +01:00
9db76ee180
* fix(editor): track edits keep the joints, the norms, the records and the saved speed together
- The cant typed in the inspector goes on into the track joined at that end, as the gizmo and the
joints tool do it; the neighbours go into the same undo step. The joint stepped before.
- A track laid on from a canted joint takes the cant off along the ramp the norms ask for at the
speed (`alignment::cant_ramp_length`), not at a fixed 1.5 mm a metre whatever the speed and the
norms: 120 mm at 100 km/h over 120 m, not 80 m.
- Deleting a track of the line under the route tool keeps the laying norms. They went back to the
defaults, and every later lay, extend and join used those.
- The gauge is a paste group of its own, off by default: pasting how a track rides or sounds no
longer changes its gauge.
- The speed of a turntable set in the editor is the one saved. The editor changed the speed the
turntable runs at, while the file keeps the limit it was loaded with.
- Deleting a set of tracks does what Del does with each: a double switch, a slip and a crossover go
whole, the records of the switches go with them, and the model and events of a turntable too. The
records stayed behind and on saving were given to another switch, which then showed a wrong type.
- Deleting a switch of a crossover takes the crossover out whole, as the connection tools do: the
outer track of a crossover on a curve comes down by its lift and the record of the connection
goes. Alone, the switch left the outer track up for good, and the connection to the next switch
given its name. A switch bent out of the shape of its record is found by its name.
Tests: a unit test of the norm ramp. The other changes are in the editor's UI, which the unit tests
don't reach.
* test(editor): self-test scripts that fail, a runner, and a case for each fix of the track editing
The editor's self-test scripts only logged: nothing made a run fail. Now:
- `expect` commands check the state and log `SELFTEST PASS` or `SELFTEST FAIL ... got X, expected Y`:
the cant at a track end, the joint at an end (gap, angle, cant step), the records of a switch and
the connections naming it, speed, gauge, a track present or removed, the laying norms' gauge,
heights and lifts against a mark, whether a track is in the line under the route tool, and the
includes of a turntable. A command no group takes counts as a failure, so a mistyped one can't
make the checks after it pass.
- At `quit` the result is logged, and a script whose expectations failed ends the editor with exit
code 2 (a failed start stays 1; the simulator's test mode is unchanged).
- The commit of the inspector's cant field is `track_cant_commit`, which the inspector and the
`trackcant` command both call; `routegauge` sets the laying norms as the route tool does, and
`tracksetdelete` deletes a set of tracks by name.
- `tests/editor/run.py` runs each script of `tests/editor/cases` on a copy of the fixture scenery
in the game folder, with a wall-time limit and a memory cap, reads the exit code and the
`SELFTEST` lines, and deletes the copy. A `#> reopen` line restarts the editor on the saved
scenery. See `tests/editor/README.md`.
- One case per fix of the track editing quick fixes (inspector cant, norms after deleting, the
gauge paste group, turntable speed saved, deleting a set, a set with a double switch, a slip
and a crossover, deleting a switch of a crossover, a bent switch). All pass; with the fixes
reverted all fail.
* feat(editor): the track tool panels keep their fields, results and buttons within the panel
- The card of the tool: after a long gesture the action goes under it, at its indent, when what is
left of the row is narrower than 8 font sizes or the longest word of the action. It was squeezed
into a sliver and broken in the middle of its words.
- A click on the title row of the card folds it to that row (icon, name, family, key, and a small
triangle marker) and opens it again. One flag for all the tools, kept with the editor settings
(`track_card_folded` in eu07_editor.ini), open by default: the card took 250-300 px at the top
of every tool and repeats the hint bar of the view.
- The grade labels of the vertical profile, on the graph and in the view, write the per mille as
the panel does (the translated "per mille", the per mille sign in Polish), not "o/oo".
- The track analysis window: the thresholds of the speed check and of the joints keep to their
widest name and a field of 10 font sizes where the window is wider than that, as docked across
the bottom (`begin_fields_fitted`). The results are tables with each column as wide as what is in
it: the speed check with its column names kept at the top as the list scrolls, the joints with
the kind, the value and the two tracks next to each other. A click on a row shows it as before.
- `same_line_if_fits` puts the next button beside the one before only when it fits in what is left
of the line, at the start of the next line otherwise. Used where the route design puts buttons
side by side, for "Forget the design" in the profile panel, which was cut off at the edge, and for
the buttons of a switch in the inspector.
- The laying options: the speed, the curve radius and the longest path are fields with the name on
the left in two columns (`begin_fields`/`field_row`), as in the inspector, the route and the
profile, the chips of the quick values under them. The segmented choices give the short names
less of the room when a long one doesn't fit in its even share, and go on in a second bar when
they don't fit side by side: "Through the clicked points" overflowed its third of the bar.
* fix(editor): a switch laid gets the speed of its diverging track, one breaking a hard rule of ST-T1-A6 isn't laid
- Every switch laid writes the speed of its diverging track (`velocity`): the switch tool on a
straight, into a curve, from a free end and linked, a double switch, the switches of a slip, a
switch given another template of the catalogue, and a switch moved along the curve it's bent
into. A switch of the catalogue had no limit before, one copied from a switch of the scenery kept
that one's, one laid without a track had the laying speed on both its tracks. The limit is for the
diverging track alone (`velocity -V`); the own limit of the track it goes into stays for both
where it's the lower. The switch tool says the speed and what gives it.
- The speed is formula 9.9 of PKP PLK ST-T1-A6 the other way round, V = sqrt((I + D) r / 11.8), with
the normal cant deficiency of the frog of table 9.7 (110 mm a fixed frog, 130 mm a movable nose),
rounded down to the steps of the speed limits and no more than table 11.2 gives the basic switch.
For the fixed frogs the formula gives table 11.2 itself (190 40, 300 50, 500 60, 760 80, 1200
100 km/h); the 2500-1:26.5 with a movable nose stays 130. A switch bent into a curve takes the
radius of its diverging track from table 11.8 (one-sided r" = (Rr - t^2)/(R + r), two-sided
(Rr + t^2)/(R - r)) and the cant of the line with its sign: leaning against the diverging track it
takes speed away, where the speed check counted it as helping. Rz 60E1-190-1:9 bent out of the
curve R 600 m with 60 mm: 30 km/h, not 40; the 60E1-500-1:12 of the review, out of R 1200 m with
60 mm: 60 km/h at its fixed frog (54 at I = 100 mm, the 0.65 m/s2 the editor took), not 107.
- A switch breaking a hard rule isn't laid, the tracks left as they were, and the switch tool says
why, with the value, the limit and the paragraph: the cant changing within it (11.4 pkt 7), a cant
ramp ending within it or nearer than 6 m (9.6 pkt 16-17; one ending right at an end of the switch
is let be, as the snapping of the start offers it), a double switch, a slip or a crossing bent
(11.4 pkt 4), the curvature of its diverging or its main track turning from one side to the other
(9.7 pkt 12, KZW II). They were warnings shown after the switch was laid, and on a straight the
cant wasn't looked at at all. The line is looked at 10 m past the ends of the curve or the
straight too, so the ramp on the straight before a curve counts. The previews show the refusals.
- A switch moved along its straight or the curve it's bent into, a double switch moved along its
straight, and a switch given another template go through the same checks; one breaking a rule
stays as it is.
- Warnings still: 1:9.403 and steeper than 1:9 bent (11.4 pkt 4c-d), a rule of the running and the
main tracks, which the editor doesn't tell from the side ones, as the warning now says; the limits
of table 11.9 and a cant over 100 mm in a bent switch (table 9.6), as before.
Tests: unit tests of tables 11.8 and 11.9 (the least main radius bends the diverging track to the
least radius the table gives), table 9.7, the speeds of table 11.2 by formula 9.9, the speed of a
bent switch with the cant with its sign (the example of the review), the cant over a switch on a
straight and a double switch bent. Editor cases `q2_1_switch_speed`, `q2_2_switch_refusals` and
`q2_3_switch_move`, with `expect status` (the status of the switch tool) and `expect steps` (the
undo steps), the fixture with a straight taking a cant on and a compound curve without cant. All
pass; with the changes of the editor reverted all three fail.
* test(editor): golden round trips of the tracks and of the //$ lines, the cant at the joints
The safety net of the track editor before its domain model changes (E0 of
editor-tracks-tests.md): what the editor reads from the scenery files and
writes back is read, written and read again in tests/unit, with no game data.
Tracks (test_track_text.cpp, data/tracks/). Entries written the way the game
writes them, read by TTrack::Load() and written by export_as_text(), come out
byte for byte the same, and read again give the same track field by field:
plain tracks with all their attributes (events, speed, isolated, overhead,
vradius, rail profile, friction cell), a curve with cant, radius, uneven,
buckle, cwr and sleeper models, a bridge, switches with trackbed, frogs,
movable nose, blades, uneven of both paths and timbers, a turntable, paths of
pieces, the speeds +40, -40, 0.5, 0 and none of tracks, switches and
turntables, a river, a tributary, a road and a crossing. What the game writes
otherwise than given is checked as it is (table as turn, mountain as
mountains, the length of the path, a switch heard from 10 m, the events in
order, names in lower case, model paths with forward slashes, the texture
length, rolls as floats, no overhead and no vradius left out).
The seam: TTrack built from text with no scene. The engine stubs of the tests
had none of it, so the tests link the few sources reading and writing a track
takes (world/Track.cpp, Segment.cpp, TrackUneven.cpp, MemCell.cpp,
scene/scenenode.cpp, utilities/Timer.cpp, rendering/geometrybank.cpp) and
track_stubs.cpp stands in for the rest: a renderer keeping the materials by
their names, and the scene, events, vehicles and the geometry of the rails,
which reading and writing never reach and which stop the test with their name
if one does. It tests the game's own Load() and export, where a parser of its
own would have meant rewriting Load(), and changes no code of the game. The
stub of basic_node::radius_() goes, scenenode.cpp brings the real one. The
rails don't buckle in the tests (TrackBuckle.cpp needs the environment), the
buckle declared is read and written either way; material names go through a
stand-in, the game's material manager isn't tested here.
The //$ lines (test_editor_records.cpp, data/records/). Their readers and
writers were members of editor_mode, srk_tool and the stores, with the scene
around them; they move as they were into editor/editorRecords.cpp, the one
place each kind is read and written, which the stores call (and which the
migration to the project file of E3 will need apart anyway). The methods of
scene::layer_context move into scene/scenelayercontext.cpp so it links alone.
Each kind, h r k p t w b s c o z, read from golden lines and written back comes
out the same, in the coordinates of the file and of a file placed at an
origin; //$e, the descriptions of the templates, read and saved by
editor_includes in a template in a scratch folder, leaves the file as it was.
Cant (test_cant.cpp). The paths an alignment lays roll by asin(cant/gauge),
signed with the turn, back to the cant of the line at every end; a curve the
other way rolls the other way. At a joint editor_track::match_rolls() gives
the joined track the roll for the travel across it, turned where the paths
face or stand back to back, and the track written keeps it. The inspector's
own conversion on 1500 mm stays in its lambdas here; named, as
editor_mode::cant_of_roll()/roll_of_cant(), it comes with the quick fixes.
Known bugs found, tests of the change each (doctest::should_fail, passing
until fixed, then reported to drop the decorator), data/tracks/known_lost.scn:
- angle1/angle2 are read and dropped: not written back.
- fouling1/fouling2 are read and dropped: not written back.
- name@circuit: the circuit is taken out of the name with the letter before
the @ ("tor1@iso1" becomes track "tor"; substr(0, i - 1)).
- the attributes of the entry (gauge, friction, texture sizes, speed...) are
written to 6 significant digits, a float has 9: more digits are lost on the
first save.
None in the //$ lines.
Unit tests: 957 cases before, 974 after, all passing.
* feat(editor): the norms of the track geometry, a module of their own: the profiles as tables, one engine
Stage E1 of editor-tracks-domain.md (§3, §6): the norms stand on their own in editor/norms, with no scene, no tracks and no user
interface, so they are tested whole in tests/unit. Nothing of the editor uses them yet but the report of the next commit;
alignment::limits stays as the laying tools use it.
- The profiles are tables of rows (normsTables.cpp). A row holds the limits of PREFER / WARN / BLOCK of one parameter where its
conditions hold (a band of the speed, of the radius or of the load, main or side track, the traffic, a switch and its frog, a
crossing, an expansion device, a platform, a station track, ballastless track, crest or sag), with the table or the paragraph of
its document. Where several rows hold the strictest limit of each tier counts. A cell can be unconfirmed: it warns, never blocks.
- PLK, ST-T1-A6 v1.0: P0 PREFER, P1 WARN, P2 BLOCK; tab. 8.1, 9.1, 9.2, 9.6 - 9.8, 9.10, 9.12 - 9.16, 10.1, 10.2, formula 9.8.
- TSI only, Reg. 1299/2014 consolidated 28.9.2023: BLOCK; 4.2.3.3 - 4.2.3.5, 4.2.4.2 - 4.2.4.4.
- EN 13803-1:2010 5.2.1 - 5.2.5: normal WARN, exceptional BLOCK.
- CH, AB-EBV AB 17 (Normalspur, 1.7.2024): Grenzwert im Normalfall WARN, maximaler Grenzwert BLOCK.
- In every profile the global hard limits of §6.3: the TSI rows and the cant gradient of 2.5 mm/m (EN 13803-1 5.2.5, the twist).
- The line class: Vmax, Vmin of the slow trains (by tab. 8.1 when not given), passenger / mixed / freight, main or side track,
the load, and what holds along the line (platform, station, ballastless, suburban, tilting).
- One engine (normsEngine.cpp) over a line of elements (straights, transitions, arcs, the curvature changing evenly along each),
its cant (points, a step being two at one chainage) and its grade line: I at Vmax and E at Vmin; dI/dt along the transitions
and the ramps; ΔI at every jump of the curvature or of the cant, the jumps closer than the intermediate length of the profile
(tab. 9.16) taken together while the deficiency keeps changing one way (9.11 pkt 8 - 13); dD/ds and dD/dt along the ramps, a
step of the cant as its twist on the 5 m base; the lengths of the straights, arcs and transitions and the shift of the arc; R;
D with (R - 50) / 1.5 and the least cant; Rv and the breaks of the grade over 2 per mille; the held grades. A finding names the
parameter, the value, the limit, the tier, the profile, the source, confirmed or not, hard or not, and the chainage. The module
makes no text, its users write the messages.
- Areas (§6.4): the default profile of the scenery, areas outlined in the plan, lines by name (a line's own wins). An element with
its ends under two profiles is checked against both, the worse kept (the stricter one); an arc across a boundary is a warning.
- describe() reads a line from samples along it (the curvature, the cant and the grade simplified by Douglas and Peucker), with a
precision of 0.2 % for the values measured on it.
- The formulas of ST-T1-A6 9.1 - 9.10: Deq, Dreg, I, E, Dmin, Dmax, Rmin, V.
The sources, and what they gave:
- The cells of ST-T1-A6 spanning two or three columns (tab. 9.1, 9.6, 9.7, 9.13 - 9.15, 10.1, 10.2; §6.5 pkt 4) were read on the
pages of the PDF. Tab. 9.15 has for the connections of tracks P0 = P1 = 80 mm at 100 < V <= 160 and 60 mm at 160 < V <= 200,
P2 160 - 0.35 V; the table of §6.2 has P1 = 160 - 0.35 V there. Tab. 9.1 has P1 = P0 (one cell), not "-".
- TSI tab. 8 (§6.5 pkt 3): the 153 mm spans both columns up to 300 km/h, 100 mm only above 300 km/h.
- Unconfirmed, warning only: tab. 9.8, 5 < q <= 10, P0 95 mm, and tab. 9.7, movable frog 230 < V <= 250, P2 110 mm (as printed,
out of line with the rows around them); EN 13803-2:2006+A1:2009 7.1.3, ΔI of the plain line 50 / 40 / 30 mm, read from a garbled
preview.
- Not there: ST-T1-A6 tab. 9.4 (a picture); EN 13803-1 dD/dt, dI/dt, ΔI in S&C, element lengths, Rv and grades (beyond the part of
the standard published as its preview); AB-EBV a limit of the grade of a line, the least cant, the table of the buffer locking of
5.4.2; the TSI has no dD/ds, dD/dt nor dI/dt. DB (Ril 800.0110) is left out: it isn't published, its values are known from
secondary sources only.
- Simplified: the (R - 50) / 1.5 of the TSI holds for every R < 305 m of mixed and freight traffic, leaving out its condition of
a ramp steeper than 1 mm/m; the intermediate element of tab. 9.16 between transitions is the one of tab. 9.1 at P2 (tab. 9.10 at
P2 would do there); a switch has a fixed frog unless the track says it moves; the track is ballasted unless the class says not.
Tests: test_norms_tables.cpp, every value of the PLK tables and of the TSI with its table in the name of the test, the edges of the
bands (a speed on the boundary, R 300, 250 and 200 m), some of EN and AB-EBV; test_norms_engine.cpp, the examples of ST-T1-A6
(Z1-1, Z1-2, załącznik 2, the ramps of Z3-2 and Z3-3), I at Vmax and E at Vmin, ΔI of arcs turning alike and the other way, taken
together over a short straight or not, dD/ds, dD/dt, a step of the cant, dI/dt, the lengths, the vertical curves, the areas and the
boundary, describe().
* feat(editor): the norms checked on the tracks laid, read only: a Norms tab of the track analysis and its report
The second half of E1: what the tracks of a scenery are against a profile of the norms, listed. Nothing of the tracks is changed.
- editor/editorNormsReport: a line of paths sampled a metre apart, two samples at each joint, into what the norms read a line
from: the plan, the curvature signed by the turn, the cant on the base of 1500 mm (as the simulator takes the rolls) signed by
the side it leans to as the line runs, the grade, the speed of each path (a switch's for its diverging track alone too), and
what the path is a part of (a switch, its diverging track, a curved switch, a movable frog, a crossing). The line described,
checked, and each finding set back on its path with a point of it; its message, "cant ramp 3.00 mm/m, PLK allows at most 2.50 mm/m
(tab. 9.12)", "break of the grade with no vertical curve, PLK asks for a radius of at least 2500 m (tab. 10.2)", through STR_C;
the text of the report: the class, the elements, the cant, the grade line and the findings of each line.
- The Norms tab of the track window, under More beside Speed and Joints, no key; its window is ###trackanalysis, as theirs. The
line through the selected path (run_route, as the speed check walks it) or the whole scenery: the lines through the plain tracks,
then each path of a switch none of them ran along, checked with the line it lies in and its own findings kept, a place two lines
run through listed once. The profile (PLK by default) and the class of the line folded under a line saying it: the line speed for
the tracks with none of their own (on by default: the speed of each track), the slow trains (tab. 8.1 by default), the traffic,
main track or siding, the load, at a platform. The results in the table of the speed check and the joints, the worst first,
coloured by the tier, the values above the recommended ones on a tick; a click on a row shows the place, the hard limits and the
warnings are marked in the view. The icon is drawn into its own cell of editor_icons.png only (the generator has it): the sheet
drawn again with this Pillow differs in other cells.
- Self-test: normsreport <file> [scope] [plk|tsi|en|ch] [km/h] writes the report to the file; expect findings <tier> <least> <most>;
the case e1_norms_report checks the curves k0..k3 of the fixture at 60 km/h against PLK and the whole scenery against the TSI.
- Golden: data/norms/line.scn, a line of 14 tracks written by make_line.py there (curves with and without transitions, cant on and
off a curve and along a straight, reverse curves 10 m apart, short straights, a grade with breaks), and its report against the
four profiles in data/norms/line_report.txt; EU07_UNIT_TESTS_UPDATE_GOLDEN=1 writes it anew. A test lays a canted corner with the
alignment of the editor and finds the samples leaning into it, both turns and run both ways, I = Deq - D.
alignment::limits stays as the laying tools use it. Where its values differ from PLK P0:
- unbalanced 0.6 m/s2 is I 92 mm on the 1500 mm base; P0 110 mm (P1 130) on the running lines, 80 on the sidings;
- ramp_factor 10, a ramp of 1:(10 V), 1 mm/m at 100 km/h and 2.5 mm/m at 40 km/h, has no counterpart: P0 1.6 mm/m at any speed;
- jerk 0.3 m/s3 is dI/dt 46 mm/s; P0 55 mm/s;
- vertical_factor 0.4 V^2 and vertical_min 2000 m; P0 max(0.77 V^2, 5000 m) (P1 max(0.35 V^2, 5000), P2 max(0.25 V^2, 2000));
- arc_min 20 m and arc_min_factor 0.4 V; P0 max(0.35 V, 30 m) up to 120 km/h, 0.40 V up to 200 km/h, also for the straights, where
tangent_min_time is 0;
- the same: cant_max 150 mm (P0 = P1 = P2 on ballast), cant_rate 35 mm/s (P0 of tab. 9.13), the base of 1500 mm.
* test(editor): a mistyped track fails the self-test, indented comments are skipped, case 7b checks the switch got bent
- A blank line or an indented `#` comment in a script is no longer a command no group takes.
- `trackcant`, `routegauge` and `tracksetdelete` with a track that isn't there count as a failed expectation.
- `expect shaped <switch> <yes|no>`: 7b checks that the gizmo drag bent the switch out of its record before deleting it.
- The ramp-length loop of test_alignment counts in an integer (Sonar S2193).
* test(editor): the entries known to be lost are checked apart from should_fail, the cant test says where the inspector conversion is tested
- A normal test checks that known_lost.scn and each of its entries are there and read, so the should_fail tests can't pass for
data gone missing.
- The comment of test_cant.cpp said the tests of cant_of_roll()/roll_of_cant() are here; they are the self-test case
1_inspector_cant.txt, as the unit tests don't link the editor.
* fix(editor): TSI and EN take close jumps of the cant deficiency together, the norms queue keeps its own span after a delete
- TSI INF and EN 13803 limit an abrupt change of the cant deficiency but give no intermediate length, so two jumps a few metres
apart were each checked alone: at km 478 of the golden line CH reported 191 mm over the TSI limit, TSI itself nothing. With
no intermediate length in the profiles of the element, the longest any profile asks for is taken. The golden report changes
that way: TSI gets the 191 mm hard limit at km 478, EN reports it instead of 106 and 85 mm one by one.
- forget() moves the span whose findings alone are kept (a diverging track) down by the spans removed before it, and drops a
queued line whose own span was removed, instead of leaving the index on another span.
- The report test of R 400 / 80 mm runs at 90 km/h and requires the finding: at 80 km/h there was none and the check never ran.
3134 lines
144 KiB
C++
3134 lines
144 KiB
C++
/*
|
|
This Source Code Form is subject to the
|
|
terms of the Mozilla Public License, v.
|
|
2.0. If a copy of the MPL was not
|
|
distributed with this file, You can
|
|
obtain one at
|
|
http:
|
|
*/
|
|
|
|
|
|
#include "stdafx.h"
|
|
#include "application/editormode.h"
|
|
#include "editor/editorSettings.hpp"
|
|
#include "application/editoruilayer.h"
|
|
#include "application/editorprojection.h"
|
|
#include "application/editormodeshared.h"
|
|
#include "application/editorgestures.h"
|
|
#include "editor/editorFormat.hpp"
|
|
#include "editor/editorAlignmentStore.hpp"
|
|
#include "editor/editorSwitchStore.hpp"
|
|
#include "editor/editorGeometry.hpp"
|
|
#include "editor/editorIncludeInfo.hpp"
|
|
|
|
#include "utilities/Globals.h"
|
|
#include "utilities/Timer.h"
|
|
#include "rendering/renderer.h"
|
|
#include "world/Track.h"
|
|
#include "scene/scene.h"
|
|
#include "scene/scenelayers.h"
|
|
#include "simulation/simulation.h"
|
|
#include "utilities/Logs.h"
|
|
#include "utilities/translation.h"
|
|
|
|
#include "imgui/imgui.h"
|
|
#include "imgui/ImGuizmo.h"
|
|
#include <glm/gtc/type_ptr.hpp>
|
|
#include <glm/gtc/matrix_transform.hpp>
|
|
#include <algorithm>
|
|
#include <cctype>
|
|
#include <cmath>
|
|
#include <cstdlib>
|
|
#include <cstring>
|
|
#include <functional>
|
|
#include <iterator>
|
|
#include <set>
|
|
|
|
#include "application/editormodetrackshared.h"
|
|
|
|
using namespace track_mode;
|
|
|
|
|
|
TTrack *editor_mode::selected_track() const
|
|
{
|
|
return dynamic_cast<TTrack *>(m_node);
|
|
}
|
|
|
|
bool editor_mode::track_editing() const
|
|
{
|
|
return m_track_gizmo_using || m_dragging;
|
|
}
|
|
|
|
std::size_t editor_mode::history_revision() const
|
|
{
|
|
auto const top{m_history.empty() ? std::uint64_t{0} : m_history.back().serial};
|
|
return static_cast<std::size_t>(top * 1000003u) ^ (m_history.size() << 20) ^ g_redo.size();
|
|
}
|
|
|
|
glm::dvec3 editor_mode::camera_position() const
|
|
{
|
|
return Camera.Pos;
|
|
}
|
|
|
|
track_hover const &editor_mode::hovered_track() const
|
|
{
|
|
return m_hover;
|
|
}
|
|
|
|
std::vector<TTrack *> const &editor_mode::track_set() const
|
|
{
|
|
return m_track_set;
|
|
}
|
|
|
|
editor_track_tab editor_mode::current_track_tab() const
|
|
{
|
|
return m_track_tab;
|
|
}
|
|
|
|
void editor_mode::set_current_node(scene::basic_node *Node)
|
|
{
|
|
m_node = Node;
|
|
ui()->set_node(m_node);
|
|
}
|
|
|
|
alignment::limits const &editor_mode::route_norms() const
|
|
{
|
|
return m_route.design.norms;
|
|
}
|
|
|
|
void editor_mode::clear_track_point()
|
|
{
|
|
m_track_point = {};
|
|
}
|
|
|
|
editor_nmt &editor_mode::terrain_model()
|
|
{
|
|
return m_nmt;
|
|
}
|
|
|
|
double editor_mode::terrain_model_offset() const
|
|
{
|
|
return m_nmt_state.offset;
|
|
}
|
|
|
|
bool editor_mode::terrain_model_fitted() const
|
|
{
|
|
return m_nmt_state.fitted;
|
|
}
|
|
|
|
void editor_mode::select_track(scene::basic_node *Node)
|
|
{
|
|
auto *track = dynamic_cast<TTrack *>(Node);
|
|
if (track == nullptr)
|
|
{
|
|
m_track_point = {};
|
|
return;
|
|
}
|
|
if (track != m_node)
|
|
{
|
|
m_track_point = {};
|
|
m_track_mode_notice.clear();
|
|
}
|
|
// a track out of the set ends it, the set is the selection only together with its tracks
|
|
if (false == in_track_set(track))
|
|
m_track_set.clear();
|
|
m_node = track;
|
|
ui()->set_node(m_node);
|
|
if (ui()->mode() != nodebank_panel::TRACK)
|
|
return;
|
|
m_track_window_open = true;
|
|
m_track_mode_notice.clear();
|
|
if (track_plan_tab() && plan_tab_for(track) != m_track_tab)
|
|
{
|
|
show_track_tab(plan_tab_for(track));
|
|
return;
|
|
}
|
|
// the mode stays as it is, the path is taken up by it if it can be
|
|
switch (m_track_tab)
|
|
{
|
|
case track_tab::straights:
|
|
if (track->eType == tt_Switch)
|
|
m_track_mode_notice = STR_C("Switches aren't a part of a line: T edits the switch, Esc goes back to Select");
|
|
break;
|
|
case track_tab::route:
|
|
if (std::find(m_route.chain.tracks.begin(), m_route.chain.tracks.end(), track) != m_route.chain.tracks.end())
|
|
break;
|
|
if (track->eType != tt_Normal || false == editor_track::is_supported(*track))
|
|
m_track_mode_notice = STR_C("Switches aren't a part of a line: T edits the switch, Esc goes back to Select");
|
|
else if (false == route_load(*track))
|
|
m_track_mode_notice = m_route.error.empty() ? std::string{STR_C("The curve can't be read from this path, edit it as a single path")} : m_route.error;
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
}
|
|
|
|
editor_track::point_ref editor_mode::track_handle_hit() const
|
|
{
|
|
auto *track = selected_track();
|
|
// the tracks of a set are moved by its gizmo, not by the points of one of them
|
|
if (track == nullptr || false == editor_track::is_supported(*track) || m_track_tab != track_tab::path || (m_track_set.size() >= 2 && in_track_set(track)))
|
|
return {};
|
|
|
|
screen_projection const projection;
|
|
float best = kHandleRadius * kHandleRadius;
|
|
editor_track::point_ref hit;
|
|
for (int i = 0; i < static_cast<int>(track->m_paths.size()); ++i)
|
|
{
|
|
for (auto const kind : kPointKinds)
|
|
{
|
|
// the control vectors only with the gizmo out: hidden, a track is changed by its ends and won't bend by chance
|
|
if (false == m_track_gizmo_on && false == editor_track::is_end(kind))
|
|
continue;
|
|
editor_track::point_ref const point{i, kind};
|
|
float const distance = projection.mouse_distance2(editor_track::point_position(*track, point)) * (editor_track::is_end(kind) ? 0.5f : 1.0f);
|
|
if (distance < best)
|
|
{
|
|
best = distance;
|
|
hit = point;
|
|
}
|
|
}
|
|
}
|
|
return hit;
|
|
}
|
|
|
|
void editor_mode::draw_track_overlay() const
|
|
{
|
|
auto const *track = selected_track();
|
|
if (track == nullptr)
|
|
return;
|
|
|
|
screen_projection const projection;
|
|
ImDrawList *drawlist = ImGui::GetBackgroundDrawList(ImGui::GetMainViewport());
|
|
bool const trackmode = ui()->mode() == nodebank_panel::TRACK;
|
|
// a track of the set is drawn with the set, see draw_track_set()
|
|
if (trackmode && m_track_set.size() >= 2 && in_track_set(track))
|
|
return;
|
|
|
|
ImU32 const coursecolor = IM_COL32(40, 220, 255, 220);
|
|
int constexpr samples{32};
|
|
for (auto const &path : track->m_paths)
|
|
{
|
|
auto previous = bezier{path}.point(0.0);
|
|
for (int i = 1; i <= samples; ++i)
|
|
{
|
|
auto const next = bezier{path}.point(static_cast<double>(i) / samples);
|
|
projection.line(drawlist, previous, next, coursecolor, 2.5f);
|
|
previous = next;
|
|
}
|
|
}
|
|
if (false == trackmode || m_route_tab || false == editor_track::is_supported(*track))
|
|
return;
|
|
|
|
// the control vectors are drawn, and dragged, only with the gizmo out
|
|
ImU32 const vectorcolor = IM_COL32(200, 200, 200, 160);
|
|
for (int i = 0; m_track_gizmo_on && i < static_cast<int>(track->m_paths.size()); ++i)
|
|
{
|
|
projection.line(drawlist, editor_track::point_position(*track, {i, editor_track::point_kind::start}), editor_track::point_position(*track, {i, editor_track::point_kind::control1}), vectorcolor, 1.0f);
|
|
projection.line(drawlist, editor_track::point_position(*track, {i, editor_track::point_kind::end}), editor_track::point_position(*track, {i, editor_track::point_kind::control2}), vectorcolor, 1.0f);
|
|
}
|
|
for (int i = 0; i < static_cast<int>(track->m_paths.size()); ++i)
|
|
{
|
|
for (auto const kind : kPointKinds)
|
|
{
|
|
if (false == m_track_gizmo_on && false == editor_track::is_end(kind))
|
|
continue;
|
|
editor_track::point_ref const point{i, kind};
|
|
ImVec2 screen;
|
|
if (false == projection.project(editor_track::point_position(*track, point), screen))
|
|
continue;
|
|
bool const selected = (point == m_track_point);
|
|
if (editor_track::is_end(kind))
|
|
{
|
|
ImU32 const color = editor_track::is_connected(*track, point) ? IM_COL32(60, 220, 60, 255) : IM_COL32(240, 60, 60, 255);
|
|
drawlist->AddCircleFilled(screen, 6.0f, color);
|
|
}
|
|
else
|
|
{
|
|
drawlist->AddRectFilled(ImVec2(screen.x - 4.0f, screen.y - 4.0f), ImVec2(screen.x + 4.0f, screen.y + 4.0f), IM_COL32(230, 230, 230, 255));
|
|
}
|
|
if (selected)
|
|
drawlist->AddCircle(screen, 10.0f, IM_COL32(255, 220, 40, 255), 16, 2.5f);
|
|
}
|
|
}
|
|
if (m_track_snap.track != nullptr)
|
|
{
|
|
ImVec2 screen;
|
|
if (projection.project(m_track_snap.position, screen))
|
|
drawlist->AddCircle(screen, 14.0f, IM_COL32(255, 60, 255, 255), 20, 3.0f);
|
|
projection.line(drawlist, m_track_snap.position, m_track_snap.position + m_track_snap.direction * 5.0, IM_COL32(255, 60, 255, 200), 2.0f);
|
|
}
|
|
}
|
|
|
|
void editor_mode::commit_track_drag(bool const Force)
|
|
{
|
|
// on letting go the rest of what follows the dragged tracks is yet to come, even with all of the drag committed
|
|
if ((false == m_track_dirty && false == (Force && m_track_drag_on_the_way)) || m_track_drag.empty())
|
|
return;
|
|
auto const now = std::chrono::steady_clock::now();
|
|
if (false == Force && now - m_track_last_commit < std::chrono::milliseconds(100))
|
|
return;
|
|
editor_track::commit(m_track_drag, false == Force);
|
|
m_track_drag_on_the_way = false == Force;
|
|
m_track_dirty = false;
|
|
m_track_last_commit = now;
|
|
}
|
|
|
|
void editor_mode::trim_history()
|
|
{
|
|
if (m_max_history_size >= 0 && (int)m_history.size() >= m_max_history_size)
|
|
m_history.erase(m_history.begin(), m_history.begin() + ((int)m_history.size() - m_max_history_size + 1));
|
|
}
|
|
|
|
void editor_mode::push_track_snapshot(std::vector<std::pair<TTrack *, editor_track::state>> States, std::vector<TTrack *> Created, std::vector<TTrack *> Removed)
|
|
{
|
|
// a path made and taken out again within the step was never there for an undo or a redo: an undo retiring the paths made and
|
|
// then reviving the ones taken out would bring it back
|
|
for (auto made{Created.begin()}; made != Created.end();)
|
|
{
|
|
auto const gone{std::find(Removed.begin(), Removed.end(), *made)};
|
|
if (gone == Removed.end())
|
|
{
|
|
++made;
|
|
continue;
|
|
}
|
|
Removed.erase(gone);
|
|
States.erase(std::remove_if(States.begin(), States.end(), [&](auto const &Entry) { return Entry.first == *made; }), States.end());
|
|
made = Created.erase(made);
|
|
}
|
|
if (States.empty() && Created.empty() && Removed.empty())
|
|
return;
|
|
|
|
// what the tracks removed carried goes to the ones laid in their place, now or later, in the step which lays them
|
|
std::vector<TTrack *> changed;
|
|
for (auto const &entry : States)
|
|
changed.push_back(entry.first);
|
|
auto kept{Created};
|
|
kept.insert(kept.end(), changed.begin(), changed.end());
|
|
orphans_register(Removed, kept);
|
|
orphans_take_over(Created, changed);
|
|
trim_history();
|
|
auto *track = false == States.empty() ? States.front().first : false == Created.empty() ? Created.front() : Removed.front();
|
|
EditorSnapshot snap;
|
|
snap.action = EditorSnapshot::Action::TrackEdit;
|
|
snap.node_name = track->name();
|
|
snap.node_ptr = track;
|
|
snap.position = track->location();
|
|
snap.uuid = track->uuid;
|
|
snap.tracks = std::move(States);
|
|
snap.created = std::move(Created);
|
|
snap.removed = std::move(Removed);
|
|
infra_attach(snap);
|
|
snap.alignments = alignment_store::take_changes();
|
|
snap.switch_records = switch_store::take_changes();
|
|
snap.hand_joints = m_srk.take_joint_change();
|
|
snap.directives.insert(snap.directives.end(), m_drive_buffer.begin(), m_drive_buffer.end());
|
|
m_drive_buffer.clear();
|
|
m_history.push_back(std::move(snap));
|
|
g_redo.clear();
|
|
++m_track_edits;
|
|
}
|
|
|
|
void editor_mode::push_kilometrage_snapshot()
|
|
{
|
|
auto before{kilometrage::take_changes()};
|
|
if (false == before.has_value())
|
|
return;
|
|
trim_history();
|
|
EditorSnapshot snap;
|
|
snap.action = EditorSnapshot::Action::Kilometrage;
|
|
snap.kilometrage = std::move(before);
|
|
m_history.push_back(std::move(snap));
|
|
g_redo.clear();
|
|
}
|
|
|
|
void editor_mode::restore_kilometrage(EditorSnapshot &Snapshot)
|
|
{
|
|
if (false == Snapshot.kilometrage.has_value())
|
|
return;
|
|
auto current{kilometrage::current()};
|
|
kilometrage::restore(std::move(*Snapshot.kilometrage));
|
|
Snapshot.kilometrage = std::move(current);
|
|
}
|
|
|
|
bool editor_mode::tracks_editable(std::vector<TTrack *> const &Tracks, std::string &Reason)
|
|
{
|
|
for (auto const *track : Tracks)
|
|
{
|
|
std::string reason;
|
|
if (track != nullptr && false == editor_track::can_edit_geometry(*track, reason))
|
|
{
|
|
Reason = name_of(*track) + ": " + reason;
|
|
return false;
|
|
}
|
|
}
|
|
Reason.clear();
|
|
return true;
|
|
}
|
|
|
|
void editor_mode::restore_track_snapshot(EditorSnapshot const &Snapshot, std::vector<EditorSnapshot> &Opposite, bool const Undo)
|
|
{
|
|
if (Snapshot.tracks.empty() && Snapshot.created.empty() && Snapshot.removed.empty())
|
|
return;
|
|
|
|
++m_track_edits;
|
|
std::vector<TTrack *> tracks;
|
|
for (auto const &entry : Snapshot.tracks)
|
|
tracks.emplace_back(entry.first);
|
|
m_infra_suspended = true;
|
|
EditorSnapshot current{Snapshot};
|
|
current.tracks.clear();
|
|
auto involved{tracks};
|
|
if (Undo)
|
|
involved.insert(involved.end(), Snapshot.created.begin(), Snapshot.created.end());
|
|
for (auto *track : involved)
|
|
current.tracks.emplace_back(track, editor_track::capture(*track));
|
|
current.infra.clear();
|
|
for (auto const &entry : Snapshot.infra)
|
|
if (auto const *binding{infra_find(entry.saved)})
|
|
current.infra.push_back(infra_state_of(*binding));
|
|
if (Snapshot.profiles)
|
|
{
|
|
std::vector<scene::layer_handle> layers;
|
|
for (auto const *library : {&std::as_const(m_profiles), &Snapshot.profile_library})
|
|
for (auto const &entry : *library)
|
|
layers.push_back(entry.layer);
|
|
current.profile_library = std::move(m_profiles);
|
|
m_profiles = Snapshot.profile_library;
|
|
profile_library_mark(std::move(layers));
|
|
}
|
|
alignment_store::settle();
|
|
switch_store::settle();
|
|
if (Snapshot.alignments.has_value())
|
|
{
|
|
current.alignments = alignment_store::records();
|
|
alignment_store::restore(*Snapshot.alignments);
|
|
}
|
|
if (Snapshot.switch_records.has_value())
|
|
{
|
|
current.switch_records = switch_store::records();
|
|
switch_store::restore(*Snapshot.switch_records);
|
|
}
|
|
if (Snapshot.hand_joints.has_value())
|
|
current.hand_joints = m_srk.restore_joints(*Snapshot.hand_joints);
|
|
Opposite.push_back(std::move(current));
|
|
|
|
if (Undo)
|
|
{
|
|
for (auto *track : Snapshot.created)
|
|
editor_track::retire(*track);
|
|
for (auto *track : Snapshot.removed)
|
|
{
|
|
editor_track::revive(*track);
|
|
tracks.push_back(track);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
for (auto *track : Snapshot.removed)
|
|
editor_track::retire(*track);
|
|
for (auto *track : Snapshot.created)
|
|
editor_track::revive(*track);
|
|
}
|
|
// names passed round among the tracks: a track whose name another one gets back gives it up first. The drives the step
|
|
// put back have the names of their switches already
|
|
std::vector<scene::instance_handle> restored;
|
|
for (auto const &entry : Snapshot.directives)
|
|
restored.push_back(entry.first);
|
|
for (auto const &entry : Snapshot.tracks)
|
|
if (entry.second.name != entry.first->name() && std::any_of(Snapshot.tracks.begin(), Snapshot.tracks.end(), [&](auto const &Other) { return Other.first != entry.first && Other.second.name == entry.first->name(); }))
|
|
editor_track::rename(*entry.first, entry.first->name() + "~", restored);
|
|
for (auto const &entry : Snapshot.tracks)
|
|
if (entry.second.name != entry.first->name())
|
|
editor_track::rename(*entry.first, entry.second.name, restored);
|
|
for (auto const &entry : Snapshot.tracks)
|
|
editor_track::apply(*entry.first, entry.second);
|
|
editor_track::commit(tracks);
|
|
for (auto const &entry : Snapshot.infra)
|
|
infra_restore_state(entry);
|
|
m_infra_buffer.clear();
|
|
m_drive_buffer.clear();
|
|
m_infra_suspended = false;
|
|
if (false == m_route.chain.tracks.empty())
|
|
{
|
|
std::string error;
|
|
if (m_route.from->m_editorremoved || m_route.to->m_editorremoved || false == editor_track::find_chain(m_route.from, m_route.to, m_route.chain, error, true))
|
|
{
|
|
m_route.chain = {};
|
|
m_route.result = {};
|
|
m_route.vertex = -1;
|
|
m_route.grip = -1;
|
|
}
|
|
else
|
|
{
|
|
route_bind_ends();
|
|
route_update();
|
|
}
|
|
}
|
|
|
|
lay_after_history(Undo);
|
|
m_track_snap = {};
|
|
m_track_dirty = false;
|
|
m_track_point = {};
|
|
m_node = tracks.empty() || tracks.front()->m_editorremoved ? nullptr : tracks.front();
|
|
ui()->set_node(m_node);
|
|
straight_refresh();
|
|
profile_after_undo();
|
|
if (Snapshot.profiles && false == m_profile.route.spans.empty())
|
|
profile_restore();
|
|
}
|
|
|
|
std::array<editor_mode::track_mode, 16> const &editor_mode::track_modes()
|
|
{
|
|
static std::array<track_mode, 16> const modes{{
|
|
{"Select", "Esc", track_tab::path, "LMB on a path selects it: its points, control vectors and parameters", editor_icons::icon::select, 0},
|
|
{"Lay track", "L", track_tab::lay, "Lays new track through the clicked points, on the ground or from a free end of a track", editor_icons::icon::lay_track, 0},
|
|
{"Plan", "G", track_tab::straights, "The plan of the line laid: LMB on a straight drags its ends or the middle, on a curve its vertex and radius. C works too", editor_icons::icon::curve, 0},
|
|
{"Switch", "T", track_tab::turnout, "Puts switches into a straight or a curve: press on it and drag along the way the switch goes. Edits the geometry of the selected switch", editor_icons::icon::turnout, 0},
|
|
{"Parallel", "N", track_tab::parallel, "A second track beside a track: LMB on it, then the side and the spacing", editor_icons::icon::parallel, 0},
|
|
{"Turntable", "U", track_tab::turntable, "Places a turntable, leads tracks out of it and fits the tracks around to it", editor_icons::icon::turntable, 1},
|
|
{"Signals", "I", track_tab::signals, "Signals placed by hand from the templates in the panel: LMB by a track places the one chosen, a signal dragged slides along its track, LMB on one selects it", editor_icons::icon::signal, 1},
|
|
{"Station", nullptr, track_tab::station, "A station of the scenery: LMB on a switch lays it out as a schematic. Its name and code, the numbers of its switches and tracks, its track circuits", editor_icons::icon::station, 1},
|
|
{"Station signals", nullptr, track_tab::station_signals, "The signals of a whole station placed at once, named after its code, and what its signalling lacks: LMB on a switch opens the station", editor_icons::icon::station_signals, 1},
|
|
{"Line block", nullptr, track_tab::line_block, "The block of the lines out of a station: its block signals, warning discs and block sections", editor_icons::icon::line_block, 1},
|
|
{"Kilometrage", "X", track_tab::kilometrage, "The km of the railway lines: LMB on a track puts a point of the km there, a jump of the km too", editor_icons::icon::kilometrage, 1},
|
|
{"Posts", "B", track_tab::lineside, "Along the track: the hectometre posts every 100 m, the W17 fouling point markers, trainsets", editor_icons::icon::objects, 1},
|
|
{"Profile", "P", track_tab::profile, "Vertical profile (grade line) along the line", editor_icons::icon::profile, 2},
|
|
{"Speed", "V", track_tab::speed, "Speed limits of the paths against the speed their geometry allows", editor_icons::icon::speed, 2},
|
|
{"Joints", "J", track_tab::joints, "Ends of the paths which almost meet, steps, kinks, jumps of the cant and of the grade at the joints", editor_icons::icon::joints, 2},
|
|
{"Norms", nullptr, track_tab::norms, "The geometry of the tracks against the norms of a profile (PLK, TSI, EN 13803, AB-EBV): what is beyond them, read only", editor_icons::icon::norms, 2},
|
|
// the infrastructure tool (track_tab::infra) is left out: no button nor key
|
|
}};
|
|
return modes;
|
|
}
|
|
|
|
void editor_mode::show_track_tab(track_tab const Wanted)
|
|
{
|
|
auto const Tab{Wanted == track_tab::straights || Wanted == track_tab::route ? plan_tab_for(selected_track()) : Wanted};
|
|
m_track_window_open = true;
|
|
m_roadtool.window = false;
|
|
if (Tab == m_track_tab)
|
|
return;
|
|
m_track_mode_notice.clear();
|
|
// what was going on in the mode left stays behind
|
|
cancel_track_tools();
|
|
m_straights.tool = 0;
|
|
m_lay.points.clear();
|
|
m_lay.modes.clear();
|
|
m_lay.plan = {};
|
|
m_lay.start = {};
|
|
m_lay.preview.clear();
|
|
m_lay.status.clear();
|
|
m_lay.active = Tab == track_tab::lay;
|
|
m_switch.armed = -1;
|
|
m_signal.armed = false;
|
|
m_track_tab = Tab;
|
|
auto *track{selected_track()};
|
|
switch (Tab)
|
|
{
|
|
case track_tab::turnout:
|
|
arm_switch();
|
|
break;
|
|
case track_tab::straights:
|
|
if (track != nullptr && track->eType == tt_Switch)
|
|
m_track_mode_notice = STR_C("Switches aren't a part of a line: LMB on a plain path");
|
|
break;
|
|
case track_tab::route:
|
|
if (track != nullptr && std::find(m_route.chain.tracks.begin(), m_route.chain.tracks.end(), track) == m_route.chain.tracks.end())
|
|
{
|
|
if (track->eType != tt_Normal || false == editor_track::is_supported(*track))
|
|
m_track_mode_notice = STR_C("Switches aren't a part of a line: LMB on a plain path");
|
|
else if (false == route_load(*track))
|
|
m_track_mode_notice = m_route.error.empty() ? std::string{STR_C("The curve can't be read from this path, edit it as a single path")} : m_route.error;
|
|
}
|
|
break;
|
|
case track_tab::profile:
|
|
if (track != nullptr && m_profile.route.spans.empty())
|
|
profile_open_run(*track);
|
|
break;
|
|
case track_tab::turntable:
|
|
scan_turntables(false);
|
|
turntable_read(track);
|
|
break;
|
|
case track_tab::signals:
|
|
signal_refresh(true);
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
}
|
|
|
|
void editor_mode::arm_switch()
|
|
{
|
|
auto &tool{m_switch};
|
|
if (false == tool.collected)
|
|
{
|
|
tool.templates = editor_track::standard_switch_templates();
|
|
tool.collected = true;
|
|
}
|
|
tool.status.clear();
|
|
tool.armed = tool.templates.empty() ? -1 : std::clamp(tool.last, 0, static_cast<int>(tool.templates.size()) - 1);
|
|
if (tool.armed >= 0 && tool.templates[tool.armed].double_slip)
|
|
{
|
|
auto const ordinary{std::find_if(tool.templates.begin(), tool.templates.end(), [](editor_track::switch_template const &Template) { return false == Template.double_slip; })};
|
|
tool.armed = ordinary != tool.templates.end() ? static_cast<int>(ordinary - tool.templates.begin()) : -1;
|
|
}
|
|
}
|
|
|
|
bool editor_mode::track_shortcut(int const Key)
|
|
{
|
|
if (Key == GLFW_KEY_M)
|
|
{
|
|
m_tape = {false == m_tape.active, {}, m_tape.mouse};
|
|
return true;
|
|
}
|
|
if (Key == GLFW_KEY_H)
|
|
{
|
|
auto *track{selected_track()};
|
|
if (track == nullptr || track->eType != tt_Switch)
|
|
return false;
|
|
throw_switch(*track);
|
|
return true;
|
|
}
|
|
auto const key{Key == GLFW_KEY_C ? GLFW_KEY_G : Key};
|
|
for (auto const &mode : track_modes())
|
|
{
|
|
if (mode.key == nullptr || mode.key[1] != '\0' || key != GLFW_KEY_A + (mode.key[0] - 'A'))
|
|
continue;
|
|
// 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)};
|
|
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)
|
|
m_hekto.tab().expand = true;
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
editor_mode::track_tab editor_mode::plan_tab_for(TTrack const *Track) const
|
|
{
|
|
if (Track == nullptr)
|
|
return track_plan_tab() ? m_track_tab : track_tab::straights;
|
|
if (Track->eType == tt_Normal && editor_track::is_supported(*Track) && false == editor_track::is_straight(*Track, m_straights.tolerance))
|
|
return track_tab::route;
|
|
return track_tab::straights;
|
|
}
|
|
|
|
bool editor_mode::track_busy() const
|
|
{
|
|
auto const &straights{m_straights};
|
|
return (m_lay.active && false == m_lay.points.empty()) || m_turntable.placing || m_signal.placing || m_signal.moving || straights.dragging || m_extend.active || m_point_drag.active || m_handle_drag.active || m_switch.placing || m_track_point.valid() || m_route.vertex >= 0 || m_route.grip >= 0 || false == straights.detour.empty() || straights.tool != 0 || straights.handle >= 0;
|
|
}
|
|
|
|
std::string editor_mode::track_mode_name() const
|
|
{
|
|
if (m_tape.active)
|
|
return STR_C("Measure");
|
|
if (false == m_track_window_open)
|
|
return STR_C("Select");
|
|
switch (m_track_tab)
|
|
{
|
|
case track_tab::lay: return STR_C("Lay track");
|
|
case track_tab::turnout: return STR_C("Switch");
|
|
case track_tab::straights:
|
|
if (false == m_straights.detour.empty() || m_straights.tool == 2)
|
|
return STR_C("Plan, straight: S-curve");
|
|
if (m_straights.tool == 1)
|
|
return STR_C("Plan, straight: break");
|
|
return STR_C("Plan, straight");
|
|
case track_tab::route: return STR_C("Plan, curve");
|
|
case track_tab::profile: return STR_C("Vertical profile");
|
|
case track_tab::speed: return STR_C("Speed check");
|
|
case track_tab::joints: return STR_C("Joints");
|
|
case track_tab::norms: return STR_C("Norms");
|
|
case track_tab::lineside: return STR_C("Posts along the track");
|
|
case track_tab::infra: return STR_C("Infrastructure");
|
|
case track_tab::parallel: return STR_C("Parallel track");
|
|
case track_tab::signals: return STR_C("Signals");
|
|
case track_tab::station: return STR_C("Station");
|
|
case track_tab::station_signals: return STR_C("Station signals");
|
|
case track_tab::line_block: return STR_C("Line block");
|
|
case track_tab::kilometrage: return STR_C("Kilometrage");
|
|
case track_tab::turntable: return STR_C("Turntable");
|
|
default: return STR_C("Select");
|
|
}
|
|
}
|
|
|
|
namespace
|
|
{
|
|
|
|
// the title of the window a check of the track tab lists what it finds in
|
|
char const *track_analysis_title(editor_track_tab const Tab)
|
|
{
|
|
switch (Tab)
|
|
{
|
|
case editor_track_tab::speed: return STR_C("Speed check");
|
|
case editor_track_tab::joints: return STR_C("Joints");
|
|
case editor_track_tab::norms: return STR_C("Norms");
|
|
default: return STR_C("Infrastructure");
|
|
}
|
|
}
|
|
|
|
} // namespace
|
|
|
|
void editor_mode::render_track_inspector()
|
|
{
|
|
auto const &io{ImGui::GetIO()};
|
|
m_profile.open = m_track_window_open && m_track_tab == track_tab::profile;
|
|
m_speed.set_open(m_track_window_open && m_track_tab == track_tab::speed);
|
|
m_infra.open = m_track_window_open && m_track_tab == track_tab::infra;
|
|
m_joints.set_open(m_track_window_open && m_track_tab == track_tab::joints);
|
|
m_norms.set_open(m_track_window_open && m_track_tab == track_tab::norms);
|
|
m_srk.set_open(m_track_window_open && srk_tab(), m_track_tab == track_tab::station_signals ? srk_tool::part::signals : m_track_tab == track_tab::line_block ? srk_tool::part::lines : srk_tool::part::station);
|
|
m_km.set_open(m_track_window_open && m_track_tab == track_tab::kilometrage);
|
|
if (false == m_track_window_open || m_track_tab != track_tab::lineside)
|
|
{
|
|
m_sweep.open = false;
|
|
m_hekto.tab().open = false;
|
|
m_fouling.tab().open = false;
|
|
m_parallel.tab().open = false;
|
|
m_vehicle.tab().open = false;
|
|
}
|
|
ui()->set_track(m_track_window_open);
|
|
if (false == m_track_window_open)
|
|
{
|
|
// a closed window takes its mode with it
|
|
if (m_track_tab != track_tab::path)
|
|
show_track_tab(track_tab::path);
|
|
m_track_window_open = false;
|
|
return;
|
|
}
|
|
|
|
m_route_tab = m_track_tab != track_tab::path;
|
|
|
|
// the tools of the mode are drawn in the tool options window and the selected path in the inspector, see
|
|
// render_track_tool_options() and render_track_selection(); the checks list what they find in a window of their own
|
|
if (m_track_tab == track_tab::speed || m_track_tab == track_tab::joints || m_track_tab == track_tab::norms || m_track_tab == track_tab::infra)
|
|
{
|
|
auto const *title{track_analysis_title(m_track_tab)};
|
|
ImGui::SetNextWindowSize(ImVec2(600.0f, std::min(320.0f, io.DisplaySize.y - 80.0f)), ImGuiCond_FirstUseEver);
|
|
if (ImGui::Begin((std::string{title} + "###trackanalysis").c_str(), nullptr, ImGuiWindowFlags_NoCollapse))
|
|
{
|
|
switch (m_track_tab)
|
|
{
|
|
case track_tab::speed: m_speed.render_options(); break;
|
|
case track_tab::joints: m_joints.render_options(); break;
|
|
case track_tab::norms: m_norms.render_options(); break;
|
|
default: render_infra_body(); break;
|
|
}
|
|
}
|
|
ImGui::End();
|
|
}
|
|
|
|
m_profile.strip_top = -1.0f;
|
|
if (m_track_tab == track_tab::profile && m_track_window_open)
|
|
render_profile_strip();
|
|
m_srk.render_windows();
|
|
}
|
|
|
|
void editor_mode::render_track_tool_options()
|
|
{
|
|
auto *track{selected_track()};
|
|
// the tools themselves are in the toolbar
|
|
render_track_search();
|
|
ImGui::Spacing();
|
|
render_track_guide();
|
|
// the texts of the tools go on to the next line at the edge of the panel, none of them makes it scroll sideways
|
|
ImGui::PushTextWrapPos(0.0f);
|
|
switch (m_track_tab)
|
|
{
|
|
case track_tab::lay:
|
|
render_lay_ui();
|
|
break;
|
|
case track_tab::parallel:
|
|
m_parallel.render_options();
|
|
break;
|
|
case track_tab::turnout:
|
|
if (track != nullptr && track->eType == tt_Switch)
|
|
render_turnout_ui();
|
|
else
|
|
render_switch_ui();
|
|
break;
|
|
case track_tab::straights:
|
|
render_straight_ui();
|
|
if (ImGui::CollapsingHeader(STR_C("Straights in the scenery")))
|
|
render_straights_ui();
|
|
break;
|
|
case track_tab::route:
|
|
render_route_ui();
|
|
break;
|
|
case track_tab::profile: render_profile_body(); break;
|
|
case track_tab::speed:
|
|
case track_tab::joints:
|
|
case track_tab::norms:
|
|
case track_tab::infra:
|
|
ImGui::TextDisabled("%s", STR_C("What the check finds is listed in its window"));
|
|
break;
|
|
case track_tab::lineside: render_lineside_ui(); break;
|
|
case track_tab::signals:
|
|
render_signal_selected();
|
|
render_signal_ui();
|
|
break;
|
|
case track_tab::station_signals:
|
|
// a signal picked from the lists of the check: its card, to set what it lacks right there
|
|
render_signal_selected();
|
|
m_srk.render_options();
|
|
break;
|
|
case track_tab::station:
|
|
case track_tab::line_block:
|
|
m_srk.render_options();
|
|
break;
|
|
case track_tab::kilometrage: m_km.render_options(); break;
|
|
case track_tab::turntable: render_turntable_ui(); break;
|
|
default:
|
|
render_track_set_ui();
|
|
render_track_spread_ui();
|
|
break;
|
|
}
|
|
ImGui::PopTextWrapPos();
|
|
// what a button of the station tools came to, by the mouse which clicked it: the panel keeps it at its foot, often scrolled away
|
|
std::string told;
|
|
if (bool refused{false}; m_srk.told(told, refused))
|
|
{
|
|
if (refused)
|
|
ui()->set_status(told, true);
|
|
else
|
|
ui()->set_notice(told);
|
|
}
|
|
}
|
|
|
|
void editor_mode::render_track_selection()
|
|
{
|
|
track_field_settle();
|
|
auto const tracks{selected_tracks()};
|
|
if (tracks.empty())
|
|
{
|
|
ImGui::TextDisabled("%s", STR_C("Nothing selected"));
|
|
if (m_track_tab != track_tab::path)
|
|
return;
|
|
ImGui::Spacing();
|
|
gesture_rows({{"LMB on a track", "its properties show here"}, {"Ctrl+F", "finds a track by its name"}});
|
|
ImGui::Spacing();
|
|
ImGui::Separator();
|
|
ImGui::Spacing();
|
|
ImGui::TextDisabled("%s", STR_C("Or start with:"));
|
|
auto const width{std::floor((ImGui::GetContentRegionAvail().x - ImGui::GetStyle().ItemSpacing.x) * 0.5f)};
|
|
if (ImGui::Button(STR_C("Lay a track (L)"), ImVec2(width, ImGui::GetFrameHeight() * 1.4f)))
|
|
show_track_tab(track_tab::lay);
|
|
ImGui::SameLine();
|
|
if (ImGui::Button(STR_C("Tutorial"), ImVec2(width, ImGui::GetFrameHeight() * 1.4f)))
|
|
m_first_steps_open = true;
|
|
return;
|
|
}
|
|
// the properties belong to the select tool and to the switch tool, the other tools show the track they work with
|
|
auto const sheet{m_track_tab == track_tab::path || m_track_tab == track_tab::turnout};
|
|
if (tracks.size() >= 2)
|
|
{
|
|
render_track_set_header(tracks);
|
|
if (false == sheet)
|
|
return;
|
|
render_track_select_tools(tracks);
|
|
render_track_terrain(tracks);
|
|
render_track_properties(tracks);
|
|
render_track_style(tracks);
|
|
ImGui::Spacing();
|
|
ImGui::PushStyleColor(ImGuiCol_Button, ImVec4(0.55f, 0.18f, 0.15f, 1.0f));
|
|
if (ImGui::Button(format(STR_P("Delete %d track", "Delete %d tracks", static_cast<long long>(tracks.size())), static_cast<int>(tracks.size())).c_str()))
|
|
track_set_delete();
|
|
ImGui::PopStyleColor();
|
|
item_tooltip("Deletes the selected tracks (Del); Ctrl+Z brings them back");
|
|
return;
|
|
}
|
|
auto *track{tracks.front()};
|
|
if (false == sheet)
|
|
{
|
|
ImGui::TextUnformatted(name_of(*track).c_str());
|
|
ImGui::TextDisabled("%s, %.2f m", STR_C(track_type_name(*track)), track->Length());
|
|
return;
|
|
}
|
|
render_path_ui();
|
|
}
|
|
|
|
void editor_mode::render_track_guide()
|
|
{
|
|
// a card of the tool in use: what it is for, and how the mouse and the keys drive it, drawn
|
|
auto const &modes{track_modes()};
|
|
auto const tab{false == m_track_window_open ? track_tab::path : m_track_tab == track_tab::route ? track_tab::straights : m_track_tab};
|
|
auto const found{std::find_if(modes.begin(), modes.end(), [&](track_mode const &Mode) { return Mode.tab == tab; })};
|
|
auto const family{found != modes.end() ? found->family : 0};
|
|
auto const accent{family_colour(family)};
|
|
auto const font{ImGui::GetFontSize()};
|
|
auto const pad{std::round(font * 0.6f)};
|
|
auto *list{ImGui::GetWindowDrawList()};
|
|
auto const top{ImGui::GetCursorScreenPos()};
|
|
auto const width{ImGui::GetContentRegionAvail().x};
|
|
auto const right{top.x + width};
|
|
list->ChannelsSplit(2);
|
|
list->ChannelsSetCurrent(1);
|
|
ImGui::BeginGroup();
|
|
ImGui::Dummy(ImVec2(width, pad * 0.6f));
|
|
ImGui::Indent(pad + 3.0f);
|
|
auto const row{ImGui::GetCursorScreenPos()};
|
|
auto const iconside{std::round(font * 1.7f)};
|
|
if (found != modes.end())
|
|
editor_icons::draw(list, found->picture, ImVec2(row.x + iconside * 0.5f, row.y + iconside * 0.5f), accent);
|
|
ImGui::Dummy(ImVec2(iconside, iconside));
|
|
ImGui::SameLine(0.0f, pad);
|
|
ImGui::BeginGroup();
|
|
ImGui::PushStyleColor(ImGuiCol_Text, ImVec4(1.0f, 1.0f, 1.0f, 1.0f));
|
|
ImGui::SetWindowFontScale(1.15f);
|
|
ImGui::TextUnformatted(track_mode_name().c_str());
|
|
ImGui::SetWindowFontScale(1.0f);
|
|
ImGui::PopStyleColor();
|
|
ImGui::PushStyleColor(ImGuiCol_Text, ImGui::ColorConvertU32ToFloat4(accent));
|
|
ImGui::TextUnformatted(family_name(family));
|
|
ImGui::PopStyleColor();
|
|
ImGui::EndGroup();
|
|
// a click on the title row folds the card to it and opens it again; kept with the settings of the editor, for all the tools
|
|
auto const below{ImGui::GetCursorScreenPos()};
|
|
ImGui::SetCursorScreenPos(row);
|
|
auto folded{EditorSettings.track_card_folded()};
|
|
if (ImGui::InvisibleButton("##trackguidefold", ImVec2(std::max(1.0f, right - row.x), std::max(1.0f, below.y - row.y - ImGui::GetStyle().ItemSpacing.y))))
|
|
{
|
|
folded = !folded;
|
|
EditorSettings.track_card_folded(folded);
|
|
EditorSettings.save();
|
|
}
|
|
auto const hovered{ImGui::IsItemHovered()};
|
|
if (hovered)
|
|
ImGui::SetMouseCursor(ImGuiMouseCursor_Hand);
|
|
ImGui::SetCursorScreenPos(below);
|
|
auto marker{right - pad};
|
|
if (found != modes.end() && found->key != nullptr)
|
|
{
|
|
auto const height{std::round(font * 1.35f)};
|
|
auto const cap{std::max(std::round(ImGui::CalcTextSize(found->key).x + height * 0.6f), height)};
|
|
gesture_key(*list, ImVec2(right - pad - cap, row.y + std::round((iconside - height) * 0.5f)), height, found->key);
|
|
marker -= cap + pad;
|
|
}
|
|
// the marker of the fold left of the key: pointing right while folded, down while open
|
|
{
|
|
auto const half{std::round(font * 0.3f)};
|
|
ImVec2 const centre{marker - half, row.y + std::round(iconside * 0.5f)};
|
|
auto const colour{ImGui::GetColorU32(hovered ? ImGuiCol_Text : ImGuiCol_TextDisabled)};
|
|
if (folded)
|
|
list->AddTriangleFilled(ImVec2(centre.x - half * 0.6f, centre.y - half), ImVec2(centre.x - half * 0.6f, centre.y + half), ImVec2(centre.x + half * 0.8f, centre.y), colour);
|
|
else
|
|
list->AddTriangleFilled(ImVec2(centre.x - half, centre.y - half * 0.6f), ImVec2(centre.x + half, centre.y - half * 0.6f), ImVec2(centre.x, centre.y + half * 0.8f), colour);
|
|
}
|
|
if (false == folded)
|
|
{
|
|
auto const wrap{right - pad};
|
|
ImGui::PushTextWrapPos(wrap - ImGui::GetWindowPos().x);
|
|
if (found != modes.end())
|
|
{
|
|
ImGui::PushStyleColor(ImGuiCol_Text, ImGui::GetStyleColorVec4(ImGuiCol_TextDisabled));
|
|
ImGui::TextWrapped("%s", STR_C(found->tooltip));
|
|
ImGui::PopStyleColor();
|
|
}
|
|
// the gestures, each drawn: the mouse with the button lit, the keys as caps
|
|
auto const hints{track_key_hints(false)};
|
|
auto const gesture{std::round(font * 1.25f)};
|
|
std::vector<std::vector<gesture_word>> drawn;
|
|
float column{0.0f};
|
|
for (auto const &hint : hints)
|
|
{
|
|
drawn.push_back(gesture_picture(hint.raw != nullptr ? hint.raw : hint.key));
|
|
column = std::max(column, gesture_width(gesture, drawn.back()));
|
|
}
|
|
column = std::min(column, font * 6.0f);
|
|
// the widest word of a text, which wrapping can't break
|
|
auto const widest_word = [](std::string const &Text) {
|
|
float widest{0.0f};
|
|
for (std::size_t from{0}; from < Text.size();)
|
|
{
|
|
auto const end{std::min(Text.find(' ', from), Text.size())};
|
|
widest = std::max(widest, ImGui::CalcTextSize(Text.c_str() + from, Text.c_str() + end).x);
|
|
from = end + 1;
|
|
}
|
|
return widest;
|
|
};
|
|
if (false == hints.empty())
|
|
ImGui::Dummy(ImVec2(0.0f, pad * 0.3f));
|
|
for (std::size_t i = 0; i < hints.size() && i < 7; ++i)
|
|
{
|
|
auto const at{ImGui::GetCursorScreenPos()};
|
|
auto const line{ImGui::GetTextLineHeight()};
|
|
auto const height{std::max(gesture, line)};
|
|
list->PushClipRect(at, ImVec2(at.x + column, at.y + height), true);
|
|
gesture_draw(*list, ImVec2(at.x, at.y + std::round((height - gesture) * 0.5f)), gesture, drawn[i], ImGui::GetColorU32(ImGuiCol_Text));
|
|
list->PopClipRect();
|
|
ImGui::Dummy(ImVec2(column, height));
|
|
ImGui::SameLine(0.0f, pad);
|
|
ImGui::SetCursorPosY(ImGui::GetCursorPosY() + std::round((height - line) * 0.5f));
|
|
if (hints[i].raw == nullptr || false == gesture_keys_only(hints[i].raw))
|
|
{
|
|
auto const indent{ImGui::GetCursorPosX()};
|
|
ImGui::TextColored(ImVec4(1.0f, 0.83f, 0.3f, 1.0f), "%s", hints[i].key);
|
|
ImGui::SameLine();
|
|
// after a long gesture the action goes under it, at its indent, rather than into a sliver of the row where it
|
|
// would break in the middle of its words
|
|
if (wrap - ImGui::GetCursorScreenPos().x < std::max(font * 8.0f, widest_word(hints[i].action)))
|
|
{
|
|
ImGui::NewLine();
|
|
ImGui::SetCursorPosX(indent);
|
|
}
|
|
}
|
|
ImGui::TextWrapped("%s", hints[i].action.c_str());
|
|
}
|
|
ImGui::PopTextWrapPos();
|
|
ImGui::PushStyleColor(ImGuiCol_Text, ImGui::GetStyleColorVec4(ImGuiCol_TextDisabled));
|
|
ImGui::TextUnformatted(STR_C("F1: all the shortcuts"));
|
|
ImGui::PopStyleColor();
|
|
if (ImGui::IsItemHovered())
|
|
ImGui::SetMouseCursor(ImGuiMouseCursor_Hand);
|
|
if (ImGui::IsItemClicked())
|
|
m_shortcuts_open = true;
|
|
}
|
|
ImGui::Unindent(pad + 3.0f);
|
|
ImGui::Dummy(ImVec2(width, pad * 0.5f));
|
|
ImGui::EndGroup();
|
|
auto const bottom{ImGui::GetItemRectMax().y};
|
|
list->ChannelsSetCurrent(0);
|
|
auto const rounding{std::round(font * 0.35f)};
|
|
list->AddRectFilled(top, ImVec2(right, bottom), (accent & ~IM_COL32_A_MASK) | IM_COL32(0, 0, 0, 28), rounding);
|
|
list->AddRect(top, ImVec2(right, bottom), (accent & ~IM_COL32_A_MASK) | IM_COL32(0, 0, 0, 70), rounding);
|
|
list->AddRectFilled(top, ImVec2(top.x + 4.0f, bottom), accent, rounding, ImDrawFlags_RoundCornersLeft);
|
|
list->ChannelsMerge();
|
|
if (false == m_track_mode_notice.empty())
|
|
{
|
|
ImGui::Spacing();
|
|
ImGui::PushTextWrapPos(ImGui::GetWindowContentRegionMax().x - 8.0f);
|
|
ImGui::TextColored(ImVec4(1.0f, 0.7f, 0.2f, 1.0f), "%s", m_track_mode_notice.c_str());
|
|
ImGui::PopTextWrapPos();
|
|
}
|
|
ImGui::Spacing();
|
|
}
|
|
|
|
void editor_mode::render_track_name(TTrack &Track)
|
|
{
|
|
auto &edit{m_track_name};
|
|
auto const current{Track.name() == "none" ? std::string{} : Track.name()};
|
|
auto const sync = [&]() {
|
|
edit.track = &Track;
|
|
edit.synced = current;
|
|
std::snprintf(edit.text, sizeof(edit.text), "%s", current.c_str());
|
|
edit.uses = editor_track::uses_of_name(Track);
|
|
};
|
|
if (edit.track != &Track)
|
|
{
|
|
sync();
|
|
edit.status.clear();
|
|
}
|
|
else if (edit.synced != current && edit.synced == edit.text)
|
|
sync();
|
|
|
|
std::string why;
|
|
if (false == scene::Layers.editable(&Track, &why))
|
|
{
|
|
ImGui::Text(STR_C("Name: %s"), current.empty() ? STR_C("(no name)") : current.c_str());
|
|
ImGui::SameLine();
|
|
ImGui::TextDisabled(STR_C("(can't be changed: %s)"), why.c_str());
|
|
return;
|
|
}
|
|
auto const apply = [&]() {
|
|
std::string name{edit.text};
|
|
std::string reason;
|
|
if (false == editor_track::name_valid(Track, name, reason))
|
|
return;
|
|
auto const before{editor_track::capture(Track)};
|
|
editor_track::rename(Track, name);
|
|
push_track_snapshot({{&Track, before}});
|
|
edit.status = format(STR_C("Renamed from %s"), current.empty() ? STR_C("(no name)") : current.c_str());
|
|
sync();
|
|
};
|
|
if (begin_fields("##tracknamefields", 0.3f))
|
|
{
|
|
field_row("Name##trackname");
|
|
if (ImGui::InputTextWithHint("##trackname", STR_C("(no name)"), edit.text, sizeof(edit.text), ImGuiInputTextFlags_EnterReturnsTrue | ImGuiInputTextFlags_CharsNoBlank))
|
|
apply();
|
|
if (ImGui::IsItemHovered())
|
|
ImGui::SetTooltip("%s", STR_C("Enter renames the path, Esc while typing takes the text back.\nThe events, memory cells and the map of the game find the path by its name"));
|
|
ImGui::EndTable();
|
|
}
|
|
std::string typed{edit.text};
|
|
if (typed == edit.synced)
|
|
{
|
|
if (false == edit.status.empty())
|
|
{
|
|
ImGui::SameLine();
|
|
ImGui::TextColored(ImVec4(0.5f, 0.9f, 0.5f, 1.f), "%s", edit.status.c_str());
|
|
}
|
|
return;
|
|
}
|
|
std::string reason;
|
|
TTrack *owner{nullptr};
|
|
auto const valid{editor_track::name_valid(Track, typed, reason, &owner)};
|
|
ImGui::SameLine();
|
|
if (valid)
|
|
{
|
|
auto const warned{false == edit.uses.events.empty() || false == edit.uses.loose.empty()};
|
|
if (ImGui::SmallButton(warned ? STR_C("Rename anyway") : STR_C("Rename")))
|
|
apply();
|
|
std::vector<std::string> notes;
|
|
if (typed != edit.text)
|
|
notes.push_back(format(STR_C("Saved as %s: the scenery keeps the names in lower case"), typed.c_str()));
|
|
if (edit.uses.cells > 0 || edit.uses.includes > 0)
|
|
notes.push_back(format(STR_C("The new name goes to %d memory cell(s) and %d include(s), the drives of a switch among them"), edit.uses.cells, edit.uses.includes));
|
|
if (warned)
|
|
notes.push_back(STR_C("The events listed below work until the scenery is loaded again; then they need the new name in their files"));
|
|
if (false == notes.empty() && ImGui::IsItemHovered())
|
|
ImGui::SetTooltip("%s", lines_of(notes).c_str());
|
|
}
|
|
ImGui::SameLine();
|
|
if (ImGui::SmallButton(STR_C("Keep the old")))
|
|
{
|
|
std::snprintf(edit.text, sizeof(edit.text), "%s", edit.synced.c_str());
|
|
return;
|
|
}
|
|
if (false == valid)
|
|
{
|
|
ImGui::TextColored(ImVec4(1.f, 0.45f, 0.35f, 1.f), "%s", STR_C(reason.c_str()));
|
|
if (owner != nullptr)
|
|
{
|
|
ImGui::SameLine();
|
|
if (ImGui::SmallButton(STR_C("Look at it")))
|
|
focus_track(*owner, 0, owner->location());
|
|
}
|
|
return;
|
|
}
|
|
auto const listed = [](std::vector<std::string> const &Names) {
|
|
std::string result;
|
|
for (std::size_t i = 0; i < Names.size() && i < 4; ++i)
|
|
result += (i > 0 ? ", " : "") + Names[i];
|
|
if (Names.size() > 4)
|
|
result += format(" (+%d)", static_cast<int>(Names.size() - 4));
|
|
return result;
|
|
};
|
|
if (false == edit.uses.events.empty())
|
|
ImGui::TextColored(ImVec4(1.f, 0.75f, 0.3f, 1.f), STR_C("These events aim at the path by the old name and the editor doesn't write them: %s"), listed(edit.uses.events).c_str());
|
|
if (false == edit.uses.loose.empty())
|
|
ImGui::TextColored(ImVec4(1.f, 0.75f, 0.3f, 1.f), STR_C("These events belong to the path by the old name: %s"), listed(edit.uses.loose).c_str());
|
|
}
|
|
|
|
void editor_mode::render_turnout_ui()
|
|
{
|
|
auto *track{selected_track()};
|
|
if (track == nullptr || track->eType != tt_Switch || track->m_paths.size() < 2)
|
|
return;
|
|
auto const set{double_of(*track)};
|
|
if (set.has_value())
|
|
track = set->first;
|
|
auto const &main{track->m_paths[0]};
|
|
auto const &diverging{track->m_paths[1]};
|
|
auto const origin{main.points[segment_data::point::start]};
|
|
auto const chord{plan_of(main.points[segment_data::point::end] - origin)};
|
|
auto const &control2{diverging.points[segment_data::point::control2]};
|
|
auto const control{glm::length(plan_of(control2)) > 1e-6 ? control2 : diverging.points[segment_data::point::start] - diverging.points[segment_data::point::end]};
|
|
if (glm::length(chord) < 1e-3 || glm::length(plan_of(control)) < 1e-6)
|
|
{
|
|
ImGui::TextColored(ImVec4(1.0f, 0.4f, 0.3f, 1.0f), STR_C("The geometry of this switch is degenerate, it can't be edited here"));
|
|
return;
|
|
}
|
|
glm::dvec2 const axis{glm::normalize(chord)};
|
|
glm::dvec2 const normal{-axis.y, axis.x};
|
|
auto const length{glm::dot(chord, axis)};
|
|
glm::dvec2 const end{diverging.points[segment_data::point::end].x - origin.x, diverging.points[segment_data::point::end].z - origin.z};
|
|
auto const offset{glm::dot(end, normal)};
|
|
glm::dvec2 const tangent{glm::normalize(glm::dvec2{-control.x, -control.z})};
|
|
auto const angle{std::atan2(std::abs(tangent.x * axis.y - tangent.y * axis.x), glm::dot(tangent, axis))};
|
|
std::string about;
|
|
if (set.has_value())
|
|
{
|
|
auto const &second{set->second->m_paths.front()};
|
|
about = format(STR_C("Double switch %s + %s: length %.3f m, the second switch starts %.3f m on"), set->first->name().c_str(), set->second->name().c_str(), glm::dot(plan_of(second.points[segment_data::point::end] - origin), axis), glm::dot(plan_of(second.points[segment_data::point::start] - origin), axis)) + "\n" +
|
|
format(STR_C("First switch: diverging %s, end offset %.3f m"), offset > 0.0 ? STR_C("right") : STR_C("left"), std::abs(offset));
|
|
}
|
|
else
|
|
ImGui::Text(STR_C("Length %.3f m, diverging %s, end offset %.3f m"), length, offset > 0.0 ? STR_C("right") : STR_C("left"), std::abs(offset));
|
|
{
|
|
// the switch in plan at one scale: the main track white, the diverging one yellow, the angle at its end, the length under
|
|
auto const font{ImGui::GetFontSize()};
|
|
auto const width{ImGui::GetContentRegionAvail().x};
|
|
auto const height{std::round(font * 4.2f)};
|
|
auto const top{ImGui::GetCursorScreenPos()};
|
|
ImGui::Dummy(ImVec2(width, height));
|
|
if (false == about.empty() && ImGui::IsItemHovered())
|
|
ImGui::SetTooltip("%s", about.c_str());
|
|
auto *list{ImGui::GetWindowDrawList()};
|
|
list->AddRectFilled(top, ImVec2(top.x + width, top.y + height), ImGui::GetColorU32(ImGuiCol_FrameBg), std::round(font * 0.35f));
|
|
auto const local = [&](glm::dvec3 const &Point) {
|
|
glm::dvec2 const relative{Point.x - origin.x, Point.z - origin.z};
|
|
return glm::dvec2{glm::dot(relative, axis), glm::dot(relative, normal)};
|
|
};
|
|
std::vector<std::vector<glm::dvec2>> lines;
|
|
std::vector<TTrack *> switches{track};
|
|
if (set.has_value())
|
|
switches.push_back(set->second);
|
|
double far_along{0.0}, low_across{0.0}, high_across{0.0};
|
|
for (auto *each : switches)
|
|
for (auto const &path : each->m_paths)
|
|
{
|
|
geometry::bezier const curve{path};
|
|
std::vector<glm::dvec2> points;
|
|
for (int i = 0; i <= 24; ++i)
|
|
{
|
|
auto const point{local(curve.point(i / 24.0))};
|
|
far_along = std::max(far_along, point.x);
|
|
low_across = std::min(low_across, point.y);
|
|
high_across = std::max(high_across, point.y);
|
|
points.push_back(point);
|
|
}
|
|
lines.push_back(std::move(points));
|
|
}
|
|
auto const pad{std::round(font * 0.7f)};
|
|
auto const label{ImGui::GetTextLineHeight()};
|
|
auto const room{height - 2.0f * pad - label};
|
|
auto const scale{static_cast<float>(std::min((width - 2.0 * pad) / std::max(1.0, far_along), room / std::max(0.5, high_across - low_across)))};
|
|
auto const base{top.y + pad + (room - static_cast<float>(high_across - low_across) * scale) * 0.5f - static_cast<float>(low_across) * scale};
|
|
auto const screen = [&](glm::dvec2 const &Point) { return ImVec2(top.x + pad + static_cast<float>(Point.x) * scale, base + static_cast<float>(Point.y) * scale); };
|
|
// the diverging tracks first, the main ones over them
|
|
for (auto const main : {false, true})
|
|
for (auto const &line : lines)
|
|
{
|
|
if ((std::abs(line.back().y - line.front().y) < 0.05) != main)
|
|
continue;
|
|
std::vector<ImVec2> drawn;
|
|
for (auto const &point : line)
|
|
drawn.push_back(screen(point));
|
|
list->AddPolyline(drawn.data(), static_cast<int>(drawn.size()), main ? IM_COL32(235, 235, 235, 255) : IM_COL32(255, 210, 60, 255), 0, 2.0f);
|
|
}
|
|
// the point of the blades, and the angle at the end of the diverging track
|
|
list->AddCircleFilled(screen(glm::dvec2{0.0, 0.0}), 3.0f, IM_COL32(230, 80, 230, 255));
|
|
if (angle > 1e-6)
|
|
{
|
|
auto const text{format("1:%.1f", 1.0 / std::tan(angle))};
|
|
auto const size{ImGui::CalcTextSize(text.c_str())};
|
|
auto const at{screen(glm::dvec2{far_along, offset})};
|
|
list->AddText(ImVec2(std::round(at.x - size.x - 2.0f), std::round(offset > 0.0 ? at.y - size.y - 1.0f : at.y + 1.0f)), IM_COL32(255, 210, 60, 255), text.c_str());
|
|
}
|
|
if (diverging.radius > 0.0f)
|
|
{
|
|
auto const text{format("R %.0f", static_cast<double>(diverging.radius))};
|
|
auto const size{ImGui::CalcTextSize(text.c_str())};
|
|
auto const at{screen(glm::dvec2{far_along * 0.45, offset * 0.25})};
|
|
list->AddText(ImVec2(std::round(at.x - size.x * 0.5f), std::round(offset > 0.0 ? at.y + 3.0f : at.y - size.y - 3.0f)), IM_COL32(255, 210, 60, 200), text.c_str());
|
|
}
|
|
auto const text{format("%.2f m", far_along)};
|
|
auto const size{ImGui::CalcTextSize(text.c_str())};
|
|
auto const y{top.y + height - pad * 0.4f - label};
|
|
list->AddLine(ImVec2(top.x + pad, y + label * 0.5f), ImVec2(top.x + width - pad, y + label * 0.5f), ImGui::GetColorU32(ImGuiCol_TextDisabled, 0.5f));
|
|
list->AddRectFilled(ImVec2(top.x + (width - size.x) * 0.5f - 4.0f, y), ImVec2(top.x + (width + size.x) * 0.5f + 4.0f, y + label), ImGui::GetColorU32(ImGuiCol_FrameBg));
|
|
list->AddText(ImVec2(std::round(top.x + (width - size.x) * 0.5f), y), ImGui::GetColorU32(ImGuiCol_TextDisabled), text.c_str());
|
|
}
|
|
render_switch_template(*track, false);
|
|
// the name, the number, the rail and the kilometre of the switch, with what the scenery keeps of it
|
|
if (ImGui::CollapsingHeader(STR_C("Details##switchdetails")))
|
|
{
|
|
render_track_name(*track);
|
|
render_switch_record(*track);
|
|
if (angle > 1e-6)
|
|
ImGui::Text(STR_C("Angle 1:%.2f (%.4f deg), R in the entry %.0f m"), 1.0 / std::tan(angle), glm::degrees(angle), diverging.radius);
|
|
}
|
|
auto const drive_ui = [&](TTrack &Switch) {
|
|
ImGui::PushID(&Switch);
|
|
if (set.has_value())
|
|
ImGui::TextUnformatted(Switch.name().c_str());
|
|
if (false == EditorIncludes.scanned())
|
|
ImGui::TextDisabled("%s", STR_C("Looking for the templates..."));
|
|
else if (auto const drive{find_switch_drive(Switch, false)})
|
|
{
|
|
auto const family{drive->family};
|
|
auto const variant{drive->index};
|
|
// a drive not described for the editor is shown by its file
|
|
auto const described{family >= 0 && family < static_cast<int>(m_switch.drives.size())};
|
|
auto const &file{drive->standing.file};
|
|
auto const shown{described ? m_switch.drives[family].name : format("%s (%s)", file.substr(file.find_last_of('/') + 1).c_str(), STR_C("not described"))};
|
|
if (begin_fields("##standingdrive", 0.3f))
|
|
{
|
|
field_row("Drive##standing");
|
|
if (false == described)
|
|
ImGui::TextUnformatted(shown.c_str());
|
|
else if (ImGui::BeginCombo("##standing", shown.c_str()))
|
|
{
|
|
for (int i = 0; i < static_cast<int>(m_switch.drives.size()); ++i)
|
|
if (ImGui::Selectable(m_switch.drives[i].name.c_str(), family == i) && i != family)
|
|
replace_switch_drive(Switch, i, false);
|
|
ImGui::EndCombo();
|
|
}
|
|
if (described && ImGui::IsItemHovered())
|
|
ImGui::SetTooltip("%s\n%s", STR_C("Puts another drive in place of the drive of this switch, on the same side"), format(STR_C("Drive: events %s+ and %s- switch it, also in the map"), Switch.name().c_str(), Switch.name().c_str()).c_str());
|
|
ImGui::EndTable();
|
|
}
|
|
int side{((variant >> 1) == (variant & 1)) ? 0 : 1};
|
|
if (false == described)
|
|
{
|
|
ImGui::PushTextWrapPos(0.0f);
|
|
ImGui::TextDisabled("%s", STR_C("A drive not described for the editor, as the one of a double switch, which may also set the speed or carry the ballast of the switch: the editor keeps it as it is, it stays where it is when the switch is moved and goes when the last switch it throws is deleted"));
|
|
ImGui::PopTextWrapPos();
|
|
}
|
|
else if (segmented("standingside", side, {{0, STR_C("diverging side"), "Puts the drive of the switch on the other side of the track: the same drive, its variant for the other side"},
|
|
{1, STR_C("other side"), "Puts the drive of the switch on the other side of the track: the same drive, its variant for the other side"}}))
|
|
flip_switch_drive(Switch);
|
|
}
|
|
else if ((simulation::Events.FindEvent(Switch.name() + "+") != nullptr && simulation::Events.FindEvent(Switch.name() + "-") != nullptr) || (m_track_name.track == &Switch && m_track_name.uses.includes > 0))
|
|
ImGui::TextDisabled(STR_C("Drive: events %s+ and %s- switch it, also in the map"), Switch.name().c_str(), Switch.name().c_str());
|
|
else
|
|
{
|
|
ImGui::TextColored(ImVec4(1.0f, 0.7f, 0.2f, 1.0f), "%s", STR_C("No drive: the switch can't be switched during the game"));
|
|
render_switch_drive_choice();
|
|
if (m_switch.drive >= 0 && ImGui::Button(STR_C("Put the drive by the switch")))
|
|
place_switch_drive(Switch);
|
|
}
|
|
ImGui::PopID();
|
|
};
|
|
drive_ui(*track);
|
|
if (set.has_value())
|
|
drive_ui(*set->second);
|
|
{
|
|
bool frogs{track->SwitchExtension->m_frogs};
|
|
bool movable{track->SwitchExtension->m_movablenose};
|
|
char const *const frogtip{"Cuts the rails of the switch at its frog and lays wing rails and check rails.\n"
|
|
"Off for a switch whose include has its own model of them"};
|
|
char const *const nosetip{"The nose of the frog moves with the blades over to the wing rail of the track set, leaving no gap; the frog has no check rails"};
|
|
ImGui::BeginDisabled(false == Global.Frogs);
|
|
if (frogs)
|
|
toggle_chips("switchfrogs", {{STR_C("Frog and check rails made from the rails"), &frogs, frogtip}, {STR_C("Movable nose"), &movable, nosetip}});
|
|
else
|
|
toggle_chips("switchfrogs", {{STR_C("Frog and check rails made from the rails"), &frogs, frogtip}});
|
|
ImGui::EndDisabled();
|
|
if (false == Global.Frogs && ImGui::IsItemHovered(ImGuiHoveredFlags_AllowWhenDisabled))
|
|
ImGui::SetTooltip("%s", STR_C("Turned on with frogs yes in eu07.ini"));
|
|
if (Global.Frogs && (frogs != track->SwitchExtension->m_frogs || movable != track->SwitchExtension->m_movablenose))
|
|
{
|
|
auto const before{editor_track::capture(*track)};
|
|
track->SwitchExtension->m_frogs = frogs;
|
|
track->SwitchExtension->m_movablenose = movable;
|
|
push_track_snapshot({{track, before}});
|
|
editor_track::commit_parameters(*track);
|
|
}
|
|
}
|
|
if (false == m_switch.status.empty())
|
|
ImGui::TextWrapped("%s", m_switch.status.c_str());
|
|
|
|
auto &tool{m_switch};
|
|
ImGui::Separator();
|
|
auto const finish_set = [&](std::string const &Status) {
|
|
switch_store::follow();
|
|
records_to_history();
|
|
straight_refresh();
|
|
if (false == Status.empty())
|
|
ui()->set_status(Status, true);
|
|
};
|
|
int const side{offset > 0.0 ? 1 : -1};
|
|
// a switch of a connection laid whole or of a slip turns over with it only
|
|
auto const flips{template_change_blocked(*track).empty() && false == slip_of(*track).has_value() && false == crossover_of(*track).has_value()};
|
|
if (flips && set.has_value() && ImGui::Button(STR_C("Flip the side")))
|
|
{
|
|
auto const mirror = [&](glm::dvec3 const &Vector) {
|
|
auto const across{glm::dot(plan_of(Vector), normal)};
|
|
return glm::dvec3{Vector.x - 2.0 * across * normal.x, Vector.y, Vector.z - 2.0 * across * normal.y};
|
|
};
|
|
auto paths{double_paths(*set)};
|
|
for (auto &path : paths)
|
|
path.transform([&](glm::dvec3 const &Point) { return origin + mirror(Point - origin); }, mirror);
|
|
std::string status;
|
|
if (false == move_double_paths(*set, paths, status))
|
|
ui()->set_status(status, true);
|
|
else
|
|
{
|
|
if (auto entry{switch_store::named(*set->first)})
|
|
{
|
|
switch_store::place(*entry, *set->first);
|
|
switch_store::classify(*entry, *set->first);
|
|
switch_store::put(*entry, alignment_store::layer_of(*set->first));
|
|
}
|
|
finish_set(status);
|
|
}
|
|
}
|
|
else if (flips && false == set.has_value() && ImGui::Button(STR_C("Flip the side")))
|
|
{
|
|
std::string notes;
|
|
bool done{false};
|
|
if (geometry::has_controls(main))
|
|
{
|
|
// bent into a curve: bent into it again of its template, turned over
|
|
if (auto const index{switch_template_index(*track)}; index >= 0)
|
|
done = apply_switch_template(*track, tool.templates[index], true, notes);
|
|
else
|
|
notes = STR_C("A switch bent into a curve of no template of the catalogue isn't flipped: delete it and lay it again");
|
|
}
|
|
else
|
|
{
|
|
// its own shape, mirrored
|
|
editor_track::switch_template own;
|
|
own.source = track;
|
|
for (int i = 0; i < 2; ++i)
|
|
{
|
|
auto &local{own.local[i]};
|
|
local = track->m_paths[i];
|
|
auto const tolocal = [&](glm::dvec3 const &Vector) { return glm::dvec3{glm::dot(plan_of(Vector), normal) * side, Vector.y, glm::dot(plan_of(Vector), axis)}; };
|
|
local.transform([&](glm::dvec3 const &Point) { return tolocal(Point - origin); }, tolocal);
|
|
if (side < 0)
|
|
{
|
|
local.rolls = {-local.rolls[0], -local.rolls[1]};
|
|
for (auto &piece : local.pieces)
|
|
piece.rolls = {-piece.rolls[0], -piece.rolls[1]};
|
|
}
|
|
}
|
|
done = apply_switch_template(*track, own, true, notes);
|
|
}
|
|
if (false == notes.empty())
|
|
ui()->set_status(notes, false == done);
|
|
}
|
|
if (flips)
|
|
item_tooltip("Mirrors the switch: the diverging track goes to the other side");
|
|
double low{0.0}, high{0.0}, reach{length};
|
|
auto const slides{switch_slides(*track) && (set.has_value() ? switch_slides(*set->second) && double_room(*set, low, high, reach, m_switch.status) : switch_room(*track, low, high, m_switch.status))};
|
|
ImGui::PushID("turnout");
|
|
if (ImGui::TreeNode(STR_C("More settings")))
|
|
{
|
|
if (slides)
|
|
{
|
|
ImGui::PushItemWidth(100.0f);
|
|
ImGui::InputDouble("##switchslide", &tool.slide_typed, 0.0, 0.0, "%.2f m");
|
|
ImGui::PopItemWidth();
|
|
ImGui::SameLine();
|
|
if (ImGui::Button(STR_C("Slide along the straight")))
|
|
slide_switch(*track, std::clamp(tool.slide_typed, low, high - reach));
|
|
if (ImGui::IsItemHovered())
|
|
ImGui::SetTooltip("%s\n%s", STR_C("Moves the switch along its straight by the distance typed, + towards the frog; the straight paths on both sides get shorter or longer. Dragging the switch with the mouse does the same"),
|
|
format(STR_C("Room on the straight: %.2f m back, %.2f m ahead"), -low, high - reach).c_str());
|
|
}
|
|
else if (false == set.has_value())
|
|
{
|
|
// one bent into a curve slides along it, the tracks next to it keeping a metre; its curve found only while the settings are open
|
|
std::vector<curve_sample> bentframe;
|
|
std::array<TTrack *, 2> bentsides{};
|
|
double bentstation{0.0};
|
|
if (bent_switch_frame(*track, bentframe, bentsides, bentstation))
|
|
{
|
|
auto const along{nearest_station(bentframe, track->m_paths.front().points[segment_data::point::end]) - bentstation};
|
|
auto const back{std::max(0.0, bentstation)};
|
|
auto const ahead{std::max(0.0, bentframe.back().station - bentstation - along)};
|
|
ImGui::PushItemWidth(100.0f);
|
|
ImGui::InputDouble("##switchslide", &tool.slide_typed, 0.0, 0.0, "%.2f m");
|
|
ImGui::PopItemWidth();
|
|
ImGui::SameLine();
|
|
if (ImGui::Button(STR_C("Slide along the curve")))
|
|
slide_switch(*track, std::clamp(tool.slide_typed, -back, ahead));
|
|
if (ImGui::IsItemHovered())
|
|
ImGui::SetTooltip("%s\n%s", STR_C("Moves the switch along the curve it's bent into by the distance typed, + towards the frog; the tracks of the curve on both sides get shorter or longer, one taken up whole goes and the switch joins what it joined, P4 of another switch say. Dragging the switch with the mouse does the same"),
|
|
format(STR_C("Room on the curve: %.2f m back, %.2f m ahead"), back, ahead).c_str());
|
|
}
|
|
}
|
|
ImGui::TreePop();
|
|
}
|
|
ImGui::PopID();
|
|
ImGui::Separator();
|
|
ImGui::TextDisabled("%s", STR_C("The textures, the speed and the other properties of the switch are in the inspector"));
|
|
}
|
|
|
|
void editor_mode::render_path_events(TTrack &Track)
|
|
{
|
|
auto *track{&Track};
|
|
if (m_track_events_for != track && false == ImGui::IsAnyItemActive())
|
|
{
|
|
m_track_events_for = track;
|
|
m_track_event[0] = '\0';
|
|
m_track_events_missing.clear();
|
|
}
|
|
auto const count{[&]() {
|
|
std::size_t count{0};
|
|
for (int list = 0; list < 6; ++list)
|
|
count += editor_track::events(*track, list).size();
|
|
return count;
|
|
}()};
|
|
if (false == ImGui::CollapsingHeader(format("%s (%zu)###trackevents", STR_C("Events"), count).c_str()))
|
|
return;
|
|
auto const before{editor_track::capture(*track)};
|
|
auto const changed = [&](editor_track::state const &Before) {
|
|
push_track_snapshot({{track, Before}});
|
|
track->mark_dirty();
|
|
};
|
|
ImGui::TextDisabled("%s", STR_C("What the track sets off as the vehicles run on it"));
|
|
item_tooltip("event0: a vehicle with a crew stands on the path, event1: runs along it towards its start, event2: towards its end.\n"
|
|
"eventall0/1/2: the same for any vehicle");
|
|
auto const editable_events{track->Dynamics.empty()};
|
|
for (int list = 0; list < 6; ++list)
|
|
{
|
|
auto &events{editor_track::events(*track, list)};
|
|
for (std::size_t i = 0; i < events.size(); ++i)
|
|
{
|
|
auto const &event{events[i]};
|
|
// bound by the name of the path, not written in the file
|
|
if (event.first.empty())
|
|
{
|
|
ImGui::TextDisabled(STR_C("%s %s (by the name of the path)"), editor_track::event_keyword(list), event.second != nullptr ? STR_C("auto") : "?");
|
|
continue;
|
|
}
|
|
ImGui::PushID(list * 1000 + static_cast<int>(i));
|
|
if (ImGui::SmallButton("x") && editable_events)
|
|
{
|
|
events.erase(events.begin() + i);
|
|
editor_track::bind_events(*track, m_track_events_missing);
|
|
changed(before);
|
|
ImGui::PopID();
|
|
break;
|
|
}
|
|
ImGui::SameLine();
|
|
if (event.second == nullptr)
|
|
ImGui::TextColored(ImVec4(1.0f, 0.5f, 0.3f, 1.0f), STR_C("%s %s (no such event)"), editor_track::event_keyword(list), event.first.c_str());
|
|
else
|
|
ImGui::Text("%s %s", editor_track::event_keyword(list), event.first.c_str());
|
|
ImGui::PopID();
|
|
}
|
|
}
|
|
ImGui::PushItemWidth(100.0f);
|
|
ImGui::Combo("##eventlist", &m_track_event_list, "event0\0event1\0event2\0eventall0\0eventall1\0eventall2\0");
|
|
ImGui::PopItemWidth();
|
|
ImGui::SameLine();
|
|
ImGui::PushItemWidth(-60.0f);
|
|
auto const entered{ImGui::InputText("##eventname", m_track_event.data(), m_track_event.size(), ImGuiInputTextFlags_EnterReturnsTrue)};
|
|
ImGui::PopItemWidth();
|
|
ImGui::SameLine();
|
|
if ((ImGui::Button(STR_C("Add")) || entered) && m_track_event[0] != '\0')
|
|
{
|
|
if (false == editable_events)
|
|
{
|
|
ui()->set_status(STR_C("The events can't change while vehicles stand on the path"), true);
|
|
}
|
|
else
|
|
{
|
|
editor_track::events(*track, m_track_event_list).emplace_back(m_track_event.data(), nullptr);
|
|
editor_track::bind_events(*track, m_track_events_missing);
|
|
changed(before);
|
|
m_track_event[0] = '\0';
|
|
}
|
|
}
|
|
item_tooltip("Name of the event to add to the chosen list. An event which doesn't exist is kept, and reported");
|
|
if (false == m_track_events_missing.empty())
|
|
ImGui::TextColored(ImVec4(1.0f, 0.5f, 0.3f, 1.0f), STR_C("No such events: %s"), m_track_events_missing.c_str());
|
|
}
|
|
|
|
float editor_mode::cant_of_roll(float const Roll)
|
|
{
|
|
return static_cast<float>(1500.0 * std::sin(glm::radians(static_cast<double>(Roll))));
|
|
}
|
|
|
|
float editor_mode::roll_of_cant(float const Cant)
|
|
{
|
|
return static_cast<float>(glm::degrees(std::asin(std::clamp(static_cast<double>(Cant) / 1500.0, -1.0, 1.0))));
|
|
}
|
|
|
|
void editor_mode::track_cant_commit(TTrack &Track, editor_track::state const &Before)
|
|
{
|
|
std::vector<std::pair<TTrack *, editor_track::state>> states{{&Track, Before}};
|
|
std::vector<TTrack *> changed{&Track};
|
|
auto const joints{editor_track::joints(Track)};
|
|
for (auto const &joint : joints)
|
|
if (std::ranges::find(changed, joint.other) == changed.end())
|
|
{
|
|
states.emplace_back(joint.other, editor_track::capture(*joint.other));
|
|
changed.push_back(joint.other);
|
|
}
|
|
editor_track::match_rolls(Track, joints);
|
|
push_track_snapshot(std::move(states));
|
|
editor_track::commit(changed);
|
|
}
|
|
|
|
void editor_mode::render_path_ui()
|
|
{
|
|
auto *track = selected_track();
|
|
if (track == nullptr)
|
|
{
|
|
ImGui::TextDisabled(STR_C("No path selected"));
|
|
return;
|
|
}
|
|
|
|
if (false == editor_track::is_supported(*track))
|
|
{
|
|
ImGui::TextDisabled(STR_C("Editing of this path type isn't supported"));
|
|
return;
|
|
}
|
|
render_track_name(*track);
|
|
ImGui::TextDisabled("%s, %.2f m", STR_C(track_type_name(*track)), track->Length());
|
|
if (track->eType == tt_Normal && false == track->m_paths.empty())
|
|
{
|
|
// the track at a glance: tiles of its length, radius, grade, cant and speed, going on to the next row at the edge
|
|
auto const &path{track->m_paths.front()};
|
|
geometry::bezier const curve{path};
|
|
auto const length{curve.plan_length()};
|
|
auto const first{curve.first(0.5)};
|
|
auto const second{curve.second(0.5)};
|
|
auto const speed{std::hypot(first.x, first.z)};
|
|
auto const bend{speed > 1e-9 ? std::abs(first.x * second.z - first.z * second.x) / (speed * speed * speed) : 0.0};
|
|
auto const straight{editor_track::is_straight(*track, m_straights.tolerance) || bend < 1e-5};
|
|
auto const rise{path.points[segment_data::point::end].y - path.points[segment_data::point::start].y};
|
|
auto const roll{std::max(std::abs(path.rolls[0]), std::abs(path.rolls[1]))};
|
|
metric_tiles({{format("%.2f m", track->Length()), STR_C("length"), ImGui::GetColorU32(ImGuiCol_Text)},
|
|
{straight ? std::string{STR_C("straight")} : format("R %.0f m", 1.0 / bend), STR_C("plan"), straight ? IM_COL32(255, 255, 255, 230) : overlay_color::grip},
|
|
{format("%+.1f mm/m", length > 1e-6 ? rise / length * 1000.0 : 0.0), STR_C("grade"), ImGui::GetColorU32(ImGuiCol_Text)},
|
|
{format("%.0f mm", 1500.0 * std::sin(glm::radians(static_cast<double>(roll)))), STR_C("cant"), IM_COL32(240, 170, 60, 255)},
|
|
{editor_track::velocity(*track) > 0.0 ? format("%.0f km/h", editor_track::velocity(*track)) : std::string{"-"}, STR_C("speed"), ImGui::GetColorU32(ImGuiCol_Text)}});
|
|
}
|
|
std::string reason;
|
|
bool const geometry = editor_track::can_edit_geometry(*track, reason);
|
|
if (false == geometry)
|
|
ImGui::TextColored(ImVec4(1.0f, 0.6f, 0.2f, 1.0f), STR_C("Geometry locked: %s"), reason.c_str());
|
|
if (track->eType == tt_Switch && m_track_tab == track_tab::path)
|
|
{
|
|
same_line_if_fits(STR_C("Edit the switch (T)"));
|
|
if (ImGui::SmallButton(STR_C("Edit the switch (T)")))
|
|
show_track_tab(track_tab::turnout);
|
|
item_tooltip("A switch: the turnout tool sets its geometry, side and drive");
|
|
}
|
|
if (track->eType == tt_Switch && track->SwitchExtension != nullptr)
|
|
{
|
|
same_line_if_fits(STR_C("Throw (H)"));
|
|
if (ImGui::SmallButton(STR_C("Throw (H)")))
|
|
throw_switch(*track);
|
|
item_tooltip(track->SwitchExtension->CurrentIndex ? "Set to the diverging track: throws it over to the main one. In the editor only, to see the blades and the route; the simulation starts with the switches set to the main track"
|
|
: "Set to the main track: throws it over to the diverging one. In the editor only, to see the blades and the route; the simulation starts with the switches set to the main track");
|
|
}
|
|
// the template of a switch, a slip or a crossing, another one picked in place
|
|
if (geometry)
|
|
render_switch_template(*track, true);
|
|
std::vector<TTrack *> const tracks{track};
|
|
render_track_select_tools(tracks);
|
|
render_track_terrain(tracks);
|
|
render_track_properties(tracks);
|
|
render_track_style(tracks);
|
|
render_path_events(*track);
|
|
// the shape is given by dragging in the view, the numbers are for the exact values
|
|
if (m_track_tab != track_tab::path)
|
|
return;
|
|
|
|
auto const before = editor_track::capture(*track);
|
|
enum class rebuild { none, parameters, geometry };
|
|
auto const finish_edit = [&](rebuild const Rebuild) {
|
|
if (ImGui::IsItemActivated())
|
|
m_track_field_before = before;
|
|
if (ImGui::IsItemDeactivatedAfterEdit())
|
|
{
|
|
push_track_snapshot({{track, m_track_field_before}});
|
|
switch (Rebuild)
|
|
{
|
|
case rebuild::geometry: editor_track::commit({track}); break;
|
|
case rebuild::parameters: editor_track::commit_parameters(*track); break;
|
|
default: track->mark_dirty(); break;
|
|
}
|
|
}
|
|
};
|
|
|
|
auto const finite = [](glm::dvec3 const &Point) { return std::isfinite(Point.x) && std::isfinite(Point.y) && std::isfinite(Point.z); };
|
|
if (ImGui::CollapsingHeader(track->eType == tt_Switch ? STR_C("Geometry of the paths") : STR_C("Geometry")))
|
|
{
|
|
for (int i = 0; i < static_cast<int>(track->m_paths.size()); ++i)
|
|
{
|
|
ImGui::PushID(i);
|
|
if (track->m_paths.size() > 1)
|
|
ImGui::TextDisabled(STR_C("Path %d"), i + 1);
|
|
for (auto const kind : kPointKinds)
|
|
{
|
|
editor_track::point_ref const point{i, kind};
|
|
if (kind != editor_track::point_kind::start)
|
|
ImGui::SameLine();
|
|
std::string label = point_label(kind);
|
|
if (editor_track::is_end(kind))
|
|
label += editor_track::is_connected(*track, point) ? " (+)" : " (-)";
|
|
if (ImGui::Selectable(label.c_str(), m_track_point == point, 0, ImVec2(90.0f, 0.0f)))
|
|
m_track_point = (m_track_point == point ? editor_track::point_ref{} : point);
|
|
}
|
|
item_tooltip("(+) joined with another track, (-) a free end");
|
|
|
|
auto &path = track->m_paths[i];
|
|
// the second path of a tributary is only kept to be written back, nothing is drawn nor run on it
|
|
if (false == geometry || (track->m_tributary && i > 0))
|
|
{
|
|
auto const &start = path.points[segment_data::point::start];
|
|
auto const &end = path.points[segment_data::point::end];
|
|
ImGui::TextDisabled(STR_C("Start (%.2f, %.2f, %.2f) End (%.2f, %.2f, %.2f)"), start.x, start.y, start.z, end.x, end.y, end.z);
|
|
ImGui::PopID();
|
|
continue;
|
|
}
|
|
ImGui::PushItemWidth(-110.0f);
|
|
if (m_track_point.valid() && m_track_point.path == i)
|
|
{
|
|
auto const kind{m_track_point.kind};
|
|
if (editor_track::is_end(kind))
|
|
{
|
|
auto position = path.points[kind == editor_track::point_kind::start ? segment_data::point::start : segment_data::point::end];
|
|
if (ImGui::DragScalarN("x, y, z##point", ImGuiDataType_Double, glm::value_ptr(position), 3, 0.01f, nullptr, nullptr, "%.3f") && finite(position))
|
|
editor_track::move_point(*track, m_track_point, position);
|
|
item_tooltip("Drag to move, Ctrl+click to type the value");
|
|
finish_edit(rebuild::geometry);
|
|
}
|
|
else
|
|
{
|
|
auto &vector{path.points[kind == editor_track::point_kind::control1 ? segment_data::point::control1 : segment_data::point::control2]};
|
|
auto typed{vector};
|
|
if (ImGui::DragScalarN(STR_C("vector##point"), ImGuiDataType_Double, glm::value_ptr(typed), 3, 0.01f, nullptr, nullptr, "%.3f") && finite(typed) && glm::length(typed) < 1e5)
|
|
vector = typed;
|
|
item_tooltip("Control vector, relative to its end; zero for a straight");
|
|
finish_edit(rebuild::geometry);
|
|
}
|
|
}
|
|
if (ImGui::TreeNode(STR_C("Cant and radius")))
|
|
{
|
|
if (begin_fields("##cantradius", 0.3f))
|
|
{
|
|
field_row("Cant (mm)");
|
|
if (std::array<float, 2> cants{cant_of_roll(path.rolls[0]), cant_of_roll(path.rolls[1])}; ImGui::DragFloat2("##roll", cants.data(), 0.5f, -388.0f, 388.0f, "%.0f") && std::isfinite(cants[0]) && std::isfinite(cants[1]))
|
|
path.rolls = {roll_of_cant(cants[0]), roll_of_cant(cants[1])};
|
|
item_tooltip("Cant at the start and at the end: how much higher one rail is, + raises the left rail looking along the path");
|
|
if (ImGui::IsItemActivated())
|
|
m_track_field_before = before;
|
|
if (ImGui::IsItemDeactivatedAfterEdit())
|
|
track_cant_commit(*track, m_track_field_before);
|
|
field_row("Radius");
|
|
if (auto radius{path.radius}; ImGui::InputFloat("##radius", &radius, 0.0f, 0.0f, "%.1f") && std::isfinite(radius))
|
|
path.radius = radius;
|
|
item_tooltip("Radius stored with the path in the scenery; the shape itself comes from the control vectors");
|
|
finish_edit(rebuild::geometry);
|
|
ImGui::EndTable();
|
|
}
|
|
if (ImGui::Button(STR_C("Straighten"), ImVec2(-FLT_MIN, 0.0f)))
|
|
{
|
|
push_track_snapshot({{track, before}});
|
|
path.points[segment_data::point::control1] = glm::dvec3{};
|
|
path.points[segment_data::point::control2] = glm::dvec3{};
|
|
path.radius = 0.0f;
|
|
editor_track::commit({track});
|
|
}
|
|
item_tooltip("Removes the control vectors and the radius, the path becomes a straight between its ends");
|
|
ImGui::TreePop();
|
|
}
|
|
ImGui::PopItemWidth();
|
|
ImGui::PopID();
|
|
}
|
|
if (geometry && ImGui::TreeNode(STR_C("Snapping of the ends")))
|
|
{
|
|
if (begin_fields("##snapfields", 0.45f))
|
|
{
|
|
field_row("Snap radius (m)");
|
|
ImGui::DragFloat("##snapradius", &m_track_snap_radius, 0.05f, 0.0f, 50.0f, "%.2f");
|
|
item_tooltip("A dragged free end within this distance of another free end joins it on release");
|
|
ImGui::EndTable();
|
|
}
|
|
toggle_chips("snapflags", {{STR_C("Align with snapped path"), &m_track_align_tangent, "On joining, the end also takes over the direction of the other path, so the joint has no kink"},
|
|
{STR_C("Drag connected ends"), &m_track_drag_connected, "Dragging a joined end, or moving and turning the whole path or switch,\nmoves the ends of the neighbouring paths with it"}});
|
|
ImGui::TreePop();
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// the designs kept for the lines the tracks deleted lay along cut down to the tracks left, in the same step of the undo history: what
|
|
// the status tells of it
|
|
std::string editor_mode::designs_trimmed(std::vector<TTrack *> const &Removed)
|
|
{
|
|
auto const cut{alignment_store::trim(Removed)};
|
|
return cut > 0 ? std::string{STR_P("The design kept for the line is cut down to the tracks left along it", "The designs kept for the lines are cut down to the tracks left along them", static_cast<long long>(cut))} : std::string{};
|
|
}
|
|
|
|
void editor_mode::throw_switch(TTrack &Switch)
|
|
{
|
|
if (Switch.eType != tt_Switch || Switch.SwitchExtension == nullptr)
|
|
return;
|
|
// as the simulation throws it, the blades going over at the speed of the switch, moved on frame by frame by move_thrown_switches. To see
|
|
// the blades and the route the paths make; the simulation starts with the switches set to the main track
|
|
auto const state{1 - (Switch.SwitchExtension->CurrentIndex & 1)};
|
|
Switch.Switch(state);
|
|
if (std::find(m_thrown_switches.begin(), m_thrown_switches.end(), &Switch) == m_thrown_switches.end())
|
|
m_thrown_switches.push_back(&Switch);
|
|
ui()->set_status(format(state ? STR_C("Switch %s set to the diverging track, H throws it back") : STR_C("Switch %s set to the main track, H throws it over"), Switch.name().c_str()), false);
|
|
}
|
|
|
|
void editor_mode::move_thrown_switches()
|
|
{
|
|
auto const elapsed{static_cast<float>(Timer::GetDeltaRenderTime())};
|
|
for (auto thrown{m_thrown_switches.begin()}; thrown != m_thrown_switches.end();)
|
|
{
|
|
auto *track{*thrown};
|
|
if (track->m_editorremoved || track->eType != tt_Switch || track->SwitchExtension == nullptr)
|
|
{
|
|
thrown = m_thrown_switches.erase(thrown);
|
|
continue;
|
|
}
|
|
auto &extension{*track->SwitchExtension};
|
|
auto const left{extension.fDesiredOffset - extension.fOffset};
|
|
auto const step{elapsed * std::max(extension.fOffsetSpeed, 0.01f)};
|
|
auto const done{std::abs(left) <= step};
|
|
extension.fOffset = done ? extension.fDesiredOffset : extension.fOffset + std::copysign(step, left);
|
|
// the blades laid again where they are; the animation of the cell, if it has the switch, finds it over and lets it go
|
|
track->RaAnimate();
|
|
thrown = done ? m_thrown_switches.erase(thrown) : std::next(thrown);
|
|
}
|
|
}
|
|
|
|
void editor_mode::delete_selected_track()
|
|
{
|
|
auto *track{selected_track()};
|
|
if (track == nullptr)
|
|
return;
|
|
if (false == track->Dynamics.empty())
|
|
{
|
|
ui()->set_status(STR_C("The track can't be deleted while vehicles stand on it"), true);
|
|
return;
|
|
}
|
|
if (auto const set{double_of(*track)})
|
|
{
|
|
for (auto *part : {set->first, set->link, set->second})
|
|
if (false == part->Dynamics.empty())
|
|
{
|
|
ui()->set_status(STR_C("The track can't be deleted while vehicles stand on it"), true);
|
|
return;
|
|
}
|
|
if (auto const known{switch_store::named(*set->first)})
|
|
switch_store::forget(known->name);
|
|
auto main{set->first->m_paths.front()};
|
|
main.points[segment_data::point::end] = set->second->m_paths.front().points[segment_data::point::end];
|
|
auto const velocity{speed_check::path_velocity(*set->first, 0)};
|
|
for (auto *part : {set->first, set->link, set->second})
|
|
editor_track::retire(*part);
|
|
std::vector<TTrack *> created;
|
|
if (false == Global.shiftState)
|
|
{
|
|
auto *straight{editor_track::create_path(*set->first, main)};
|
|
editor_track::velocity(*straight, velocity);
|
|
editor_track::commit({straight});
|
|
created.push_back(straight);
|
|
ui()->set_status(STR_C("The double switch is replaced by its main track, Shift+Del removes all of it"), false);
|
|
}
|
|
if (auto const note{designs_trimmed({set->first, set->link, set->second})}; false == note.empty())
|
|
ui()->set_status(note, false);
|
|
push_track_snapshot({}, created, {set->first, set->link, set->second});
|
|
drives_deleted({set->first, set->second});
|
|
if (std::any_of(m_route.chain.tracks.begin(), m_route.chain.tracks.end(), [&](TTrack const *Each) { return Each == set->first || Each == set->link || Each == set->second; }))
|
|
route_drop();
|
|
m_node = nullptr;
|
|
ui()->set_node(nullptr);
|
|
m_track_point = {};
|
|
straight_refresh();
|
|
return;
|
|
}
|
|
// a slip goes whole, its two tracks left crossing in its place unless Shift asks for all of it
|
|
if (auto const slip{slip_of(*track)})
|
|
{
|
|
for (auto const *part : slip->parts)
|
|
if (false == part->Dynamics.empty())
|
|
{
|
|
ui()->set_status(STR_C("The track can't be deleted while vehicles stand on it"), true);
|
|
return;
|
|
}
|
|
auto const created{slip_taken_out(*slip, false == Global.shiftState)};
|
|
if (false == Global.shiftState)
|
|
{
|
|
// kept in the scenery as a crossing
|
|
std::string base;
|
|
for (int i = 1; base.empty() || switch_store::has(base); ++i)
|
|
base = "editor_skrz" + std::to_string(i);
|
|
record_slip(created, "crossing", "Skrz", 0.0, slip->record.ratio > 0.0 ? std::atan(1.0 / slip->record.ratio) : 0.0, base);
|
|
ui()->set_status(STR_C("The slip is replaced by its two tracks crossing, Shift+Del removes all of it"), false);
|
|
}
|
|
if (auto const note{designs_trimmed(slip->parts)}; false == note.empty())
|
|
ui()->set_status(note, false);
|
|
push_track_snapshot({}, created, slip->parts);
|
|
drives_deleted(slip->switches);
|
|
if (std::any_of(m_route.chain.tracks.begin(), m_route.chain.tracks.end(), [&](TTrack const *Each) { return std::find(slip->parts.begin(), slip->parts.end(), Each) != slip->parts.end(); }))
|
|
route_drop();
|
|
m_node = nullptr;
|
|
ui()->set_node(nullptr);
|
|
m_track_point = {};
|
|
straight_refresh();
|
|
return;
|
|
}
|
|
// a switch of a crossover takes the whole crossover out, as the connection tools do: its switches leave their main tracks, the
|
|
// insert goes and the outer track of a crossover on a curve comes down by the lift it went up by. Alone, the switch would leave
|
|
// the record of the connection behind, the outer track up, and the next switch given its name would take the connection over
|
|
if (auto const crossover{crossover_of(*track)})
|
|
{
|
|
for (auto const *part : {crossover->first, crossover->second, crossover->insert})
|
|
if (false == part->Dynamics.empty())
|
|
{
|
|
ui()->set_status(STR_C("The track can't be deleted while vehicles stand on it"), true);
|
|
return;
|
|
}
|
|
profile_library_load();
|
|
auto library{m_profiles};
|
|
std::vector<std::pair<TTrack *, editor_track::state>> states;
|
|
std::vector<TTrack *> created;
|
|
std::vector<TTrack *> removed;
|
|
TTrack *first{nullptr};
|
|
TTrack *second{nullptr};
|
|
if (false == take_out_crossover(*crossover, states, created, removed, first, second))
|
|
{
|
|
ui()->set_status(STR_C("The crossover there can't be taken out"), true);
|
|
return;
|
|
}
|
|
switch_store::follow();
|
|
auto status{std::string{STR_C("The crossover is taken out whole, its switches replaced by their main tracks")}};
|
|
if (auto const note{designs_trimmed(removed)}; false == note.empty())
|
|
status += "\n" + note;
|
|
auto const chained{std::any_of(removed.begin(), removed.end(), [&](TTrack const *Each) { return std::find(m_route.chain.tracks.begin(), m_route.chain.tracks.end(), Each) != m_route.chain.tracks.end(); })};
|
|
push_track_snapshot(std::move(states), std::move(created), removed);
|
|
drives_deleted(removed);
|
|
records_to_history();
|
|
if (crossover->record.lifted())
|
|
profiles_to_history(std::move(library));
|
|
if (chained)
|
|
route_drop();
|
|
ui()->set_status(status, false);
|
|
m_node = nullptr;
|
|
ui()->set_node(nullptr);
|
|
m_track_point = {};
|
|
straight_refresh();
|
|
return;
|
|
}
|
|
// retired first, so the infrastructure it carried and moves elsewhere is in the same undo step. A switch bent out of the shape of
|
|
// its record isn't found by the shape, so by its name
|
|
if (auto const known{switch_store::of(*track)})
|
|
switch_store::forget(known->name);
|
|
else if (track->eType == tt_Switch)
|
|
if (auto const named{switch_store::named(*track)})
|
|
switch_store::forget(named->name);
|
|
editor_track::retire(*track);
|
|
// a switch leaves its main track behind, so the line isn't broken, unless Shift asks for all of it
|
|
std::vector<TTrack *> created;
|
|
if (track->eType == tt_Switch && false == track->m_paths.empty() && false == Global.shiftState)
|
|
{
|
|
auto *main{editor_track::create_path(*track, track->m_paths.front())};
|
|
editor_track::velocity(*main, speed_check::path_velocity(*track, 0));
|
|
editor_track::commit({main});
|
|
created.push_back(main);
|
|
ui()->set_status(STR_C("The switch is replaced by its main track, Shift+Del removes all of it"), false);
|
|
}
|
|
if (auto const note{designs_trimmed({track})}; false == note.empty())
|
|
ui()->set_status(note, false);
|
|
push_track_snapshot({}, created, {track});
|
|
drives_deleted({track});
|
|
// the model and the events of a turntable can't stay without its track
|
|
if (track->eType == tt_Table)
|
|
for (auto const instance : turntable_includes(*track))
|
|
{
|
|
scene::Layers.removed(instance, true);
|
|
m_history.back().instances.push_back(instance);
|
|
}
|
|
if (std::find(m_route.chain.tracks.begin(), m_route.chain.tracks.end(), track) != m_route.chain.tracks.end())
|
|
route_drop();
|
|
m_node = nullptr;
|
|
ui()->set_node(nullptr);
|
|
m_track_point = {};
|
|
straight_refresh();
|
|
}
|
|
|
|
std::vector<editor_mode::key_hint> editor_mode::track_key_hints(bool const All) const
|
|
{
|
|
std::vector<key_hint> hints;
|
|
bool gizmo{false};
|
|
auto const *selected{selected_track()};
|
|
if (m_lay.active)
|
|
{
|
|
bool const curve{m_lay.mode == lay_mode::curve};
|
|
auto const *tab{curve ? "back to the bends of straights" : "trace a curve on the photo"};
|
|
if (m_lay.points.empty())
|
|
hints = {{"LMB", "start, on the ground or at a free end"}, {"Tab", tab}, {"Drag from a free end", "lays the shape to the cursor"}, {"Shift+click a straight", "a parallel track (N)"}, {"Alt", "the direction in steps of 15 degrees, or 1:9, 1:6.6... to a straight track"}, {"Esc", "stop laying"}};
|
|
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", curve ? "a point along the middle of the curve, which ends at the last one" : "a bend of the straights, eased with a large curve"}, {"Enter", "lay the points clicked"},
|
|
{"Backspace", "take back the point"}, {"LMB on a free end", "join and lay"}, {"Tab", tab}, {"Alt", "the direction in steps of 15 degrees, or 1:9, 1:6.6... to a straight track"},
|
|
{"Esc", "twice: drop the points not laid"}};
|
|
}
|
|
else
|
|
{
|
|
hints = {{"LMB", curve ? "a point along the middle of the curve, which ends at the last one" : "a bend of the straights, eased with a large curve"}, {"LMB on a free end", "join and lay"}, {"Tab", tab}};
|
|
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)
|
|
hints.push_back({"Ctrl+wheel", "radius"});
|
|
hints.insert(hints.end(), {{"Alt", "the direction in steps of 15 degrees, or 1:9, 1:6.6... to a straight track"}, {"Enter", "stop laying"},
|
|
{"Backspace", "take back the point"}, {"Esc", "stop laying"}});
|
|
}
|
|
}
|
|
else if (false == m_straights.detour.empty())
|
|
{
|
|
char const *const steps[] = {"leave the axis", "shifted", "start back", "back on the axis"};
|
|
auto const step{std::min<std::size_t>(m_straights.detour.size(), 3)};
|
|
hints = {{m_straights.tool == 2 ? "LMB" : "Shift+click", format(STR_C("point %zu of 4: %s"), step + 1, STR_C(steps[step]))}, {"Esc", "cancel"}};
|
|
}
|
|
else if (m_extend.active)
|
|
{
|
|
hints = {{"Drag", "lays the shape to the cursor, to a free end: joins it"}};
|
|
if (editor_track::snap_target target; extend_snap(target))
|
|
hints.insert(hints.end(), {{"Ctrl+wheel", "radius"}, {"Shift+wheel", "another shape"}});
|
|
else if (m_track_layout != track_layout::straight)
|
|
hints.push_back({"Ctrl+wheel", "radius"});
|
|
hints.insert(hints.end(), {{"Release", "build"}, {"Esc", "cancel"}});
|
|
}
|
|
else if (m_switch.placing && m_switch.free)
|
|
hints = m_switch.free_end.track != nullptr ? std::vector<key_hint>{{"Drag sideways", "side of the diverging track"},
|
|
{"Drag on past its end", "bends the main track toward the cursor"},
|
|
{"Tab", "the diverging track the other way or the same way"},
|
|
{"At a free end", "the main track leads into it, with Shift the diverging one"},
|
|
{"Esc", "cancel"}}
|
|
: std::vector<key_hint>{{"Drag along", "the direction of the main track, held from 4 m on"}, {"Drag sideways", "side of the diverging track"}, {"Back to the start", "the direction free again"}, {"Esc", "cancel"}};
|
|
else if (m_switch.placing && m_switch.curved && current_switch_kind() == switch_kind::slip)
|
|
hints = {{"Drag", "the crossing track ahead through the quarter of the cursor, the slip curve of a single slip on its side"}, {"Esc", "cancel"}};
|
|
else if (m_switch.placing)
|
|
hints = m_switch.connection >= 0 && m_switch.recognised ?
|
|
std::vector<key_hint>{{"Let go", connection_name(m_switch.connection)}, {"Ctrl+wheel", "R of the aligning curve"}, {"Esc", "cancel"}} :
|
|
m_switch.connection >= 0 && false == m_switch.curved ?
|
|
std::vector<key_hint>{{"Drag onto the other track", "the connection there"}, {"Shift+wheel", "another kind"}, {"Ctrl+wheel", "R of the aligning curve"}, {"Alt+wheel", "where a double crossover meets"}, {"Esc", "cancel"}} :
|
|
std::vector<key_hint>{{"Drag along", "direction of the switch"}, {"Drag sideways", "side of the diverging track"}, {"Drag onto the track beside", "a crossover there"}, {"Esc", "cancel"}};
|
|
else if (m_track_tab == track_tab::lay)
|
|
hints = {{"LMB", "start, on the ground or at a free end"}};
|
|
else if (m_track_tab == track_tab::turnout && (selected_track() == nullptr || selected_track()->eType == tt_Switch))
|
|
{
|
|
switch (current_switch_kind())
|
|
{
|
|
case switch_kind::connection: hints = {{"Press on a straight", "and drag onto the other track"}, {"Shift+wheel", "another kind"}, {"Ctrl+wheel", "R of the aligning curve"}}; break;
|
|
case switch_kind::slip:
|
|
case switch_kind::crossing:
|
|
hints = {{"Press+drag at a crossing", "of two straights"}, {"Press+drag on a straight", "with nothing crossing it: the slip with its crossing track, which goes through the quarter of the cursor"}};
|
|
if (current_switch_kind() == switch_kind::slip)
|
|
hints.push_back({"Press+drag on a curve", "the slip bent into it, in a side track only (11.4 pkt 4b)"});
|
|
break;
|
|
default:
|
|
hints = {{"Press+drag on a track", "a switch on it: along its direction, sideways its side"}, {"Press+drag from a free end", "a switch going on from the end of a track"}, {"LMB on a track", "selects it"}};
|
|
break;
|
|
}
|
|
if (selected != nullptr)
|
|
{
|
|
hints.push_back({"Gizmo", "move the selected switch"});
|
|
hints.push_back({"Del", "remove the switch, its main track stays"});
|
|
gizmo = true;
|
|
}
|
|
}
|
|
else if (m_track_tab == track_tab::turnout && m_switch.armed < 0)
|
|
hints = {{"List in the panel", "the type of the switch"}, {"LMB on a track", "another track"}};
|
|
else if (m_track_tab == track_tab::turnout && current_switch_kind() == switch_kind::slip)
|
|
hints = {{"Press+drag on a straight", "the slip with its crossing track, through the quarter of the cursor"}, {"Press+drag at a crossing", "of two straights at the skos of the slip"}, {"Press+drag on a curve", "the slip bent into it, in a side track only (11.4 pkt 4b)"}};
|
|
else if (m_track_tab == track_tab::turnout)
|
|
hints = {{"Press+drag on the track", "along: direction, sideways: side"}, {"List in the panel", "the type of the switch"}, {"Press+drag on another track", "a switch on it"}};
|
|
else if (m_track_tab == track_tab::profile && m_profile.route.spans.empty())
|
|
hints = {{"LMB on a track", "the grade line of its whole line"}, {"Shift+LMB on more tracks", "the route between the outermost ones"}, {"Shift+drag a box", "the route over the tracks in it"}};
|
|
else if (m_track_tab == track_tab::profile && m_profile.picking)
|
|
hints = {{"LMB on a track", "the stretch from switch to switch onto the common grade line"}, {"LMB on a blue one", "off it"}, {"Shift+LMB", "the track only"}, {"Esc", "done"}};
|
|
else if (m_track_tab == track_tab::profile)
|
|
hints = {{"Drag a point", "changes the grade"}, {"Double click", "adds a point"}, {"LMB on another track", "its whole line"}, {"Shift+LMB on more tracks", "the route between the outermost ones"}, {"Shift+drag a box", "the route over the tracks in it"}, {"Apply", "writes the heights into the tracks"}};
|
|
else if (m_track_window_open && m_track_tab == track_tab::speed)
|
|
hints = {{"LMB on a row", "show the path"}};
|
|
else if (m_track_window_open && m_track_tab == track_tab::lineside)
|
|
hints = {{"LMB on a track", "the line the posts go along"}};
|
|
else if (m_track_window_open && m_track_tab == track_tab::parallel)
|
|
hints = {{"LMB on a track", "the new track goes beside it"}, {"Click on a side in the panel", "the side of the new track"}};
|
|
else if (m_track_window_open && m_track_tab == track_tab::signals && m_signal.moving)
|
|
hints = {{"Drag along", "moves the signal along the track"}, {"Drag over the track", "to the other side"}, {"Release", "done"}, {"Esc", "cancel"}};
|
|
else if (m_track_window_open && m_track_tab == track_tab::signals && m_signal.placing)
|
|
hints = {{"Drag along", "the trains it faces run that way"}, {"Release", "done"}, {"Esc", "cancel"}};
|
|
else if (m_track_window_open && m_track_tab == track_tab::signals)
|
|
{
|
|
if (signal_armed() != nullptr)
|
|
hints = {{"LMB by a track", "places the signal on that side"}, {"Press+drag along", "the trains it faces run that way"}, {"Esc", "stops placing"}};
|
|
else
|
|
hints = {{"Pick in the panel", "a signal from the list, then LMB beside a track"}, {"Drag a signal", "moves it along the track"}, {"LMB on a signal", "selects it"}};
|
|
if (m_signal.selected != 0 && m_signal.selected == m_instance)
|
|
hints.push_back({"Del", "removes the selected signal with its event"});
|
|
}
|
|
else if (m_track_window_open && m_track_tab == track_tab::turntable && m_turntable.placing)
|
|
hints = {{"Drag", "turns the bridge"}, {"Release", "places the turntable"}, {"Esc", "cancel"}};
|
|
else if (m_track_window_open && m_track_tab == track_tab::turntable && m_turntable.table != nullptr)
|
|
hints = {{"LMB around it", "leads a track out"}, {"LMB on a free end", "fits that track to the turntable"}};
|
|
else if (m_track_window_open && m_track_tab == track_tab::turntable)
|
|
hints = {{"LMB", "places a new turntable"}};
|
|
else if (m_track_window_open && m_track_tab == track_tab::station && m_srk.editing_joints())
|
|
hints = {{"LMB on a track", "a joint of the track circuits there"}, {"LMB on a joint", "takes it: then on a track moves it, on it again away"}};
|
|
else if (m_track_window_open && srk_tab() && false == m_srk.drawing())
|
|
hints = {{"LMB on a switch", "opens its station"}};
|
|
else if (m_track_window_open && m_track_tab == track_tab::line_block)
|
|
hints = {{"LMB on a track of a line", "a block boundary there, or on one: away"}};
|
|
else if (m_track_window_open && m_track_tab == track_tab::kilometrage)
|
|
hints = {{"LMB on a track", "a point of the km there"}, {"Mouse over a track", "its km by the cursor"}};
|
|
else if (m_track_window_open && m_track_tab == track_tab::joints)
|
|
hints = {{"LMB on a row", "show the place"}, {"Fix", "joins the ends, aligns them"}};
|
|
else if (m_track_window_open && m_track_tab == track_tab::norms)
|
|
hints = {{"LMB on a row", "show the place"}};
|
|
else if (m_track_window_open && m_track_tab == track_tab::infra)
|
|
hints = {{"LMB", "select a path"}};
|
|
else if (m_track_tab == track_tab::straights && m_straights.tool == 1)
|
|
hints = {{"Press+drag on the straight", "breaks it there and turns the rest"}, {"Esc", "cancel"}};
|
|
else if (m_track_tab == track_tab::straights && m_straights.tool == 2)
|
|
hints = {{"LMB on the straight", "point 1 of 4: leave the axis"}, {"Esc", "cancel"}};
|
|
else if (m_track_tab == track_tab::straights && m_straights.dragging && m_straights.handle == 2)
|
|
{
|
|
auto const offer{straight_parallel_offer(m_straights.drag_line, m_straights.preview_start - m_straights.drag_line.start)};
|
|
if (offer.snaps)
|
|
hints = {{"Release", format(STR_C("parallel at %.2f m"), offer.spacing)}, {"Esc", "cancel"}};
|
|
else if (offer.nearby)
|
|
hints = {{"Near another straight", format(STR_C("snap at %.2f m (%.1f°)"), offer.spacing, offer.angle)}, {"Esc", "cancel"}};
|
|
else
|
|
hints = {{"Close to another straight", "snaps parallel at 4.00 / 4.50 / 4.75 m"}, {"Esc", "cancel"}};
|
|
}
|
|
else if (m_track_tab == track_tab::straights && m_straights.current.tracks.empty())
|
|
hints = {{"LMB on a straight", "its ends and the middle to drag"}, {"LMB on a curve", "its vertex and radius to drag"}};
|
|
else if (m_track_tab == track_tab::straights)
|
|
{
|
|
hints = {{"Drag an end", "the curves at it follow"}, {"Drag the middle", "shifts sideways, snaps parallel"}, {"Ctrl+drag", "breaks the straight"}, {"Shift+click x4", "shifts a piece around an obstacle"}, {"Alt+click", "adds another straight to move together"}};
|
|
}
|
|
else if (m_track_tab == track_tab::route && m_route.chain.tracks.empty())
|
|
hints = {{"LMB on a straight", "its ends and the middle to drag"}, {"LMB on a curve", "its vertex and radius to drag"}};
|
|
else if (m_track_tab == track_tab::route)
|
|
hints = {{"Drag a vertex", "the curve follows"}, {"Drag the radius grip", "changes the radius"}, {"Drag in the curvature band", "R up and down, transitions sideways"}, {"Apply", "writes the design into the tracks"}, {"Esc", "release the vertex"}};
|
|
else if (selected == nullptr)
|
|
hints = {{"LMB on a track", "selects it"}, {"Drag on the ground", "selects the tracks in a box"}, {"Shift+LMB", "adds a track to the selection, drag: a box"}, {"RMB on a track", "what can be done with it"}, {"L", "lay a new track"}};
|
|
else if (m_track_tab == track_tab::path && m_track_set.size() >= 2 && in_track_set(selected))
|
|
{
|
|
hints = {{"Inspector", "the properties of all of them at once"}, {"Gizmo", "moves them together"}, {"Shift+LMB", "adds or takes out a track"}, {"Ctrl+Shift+V", "sets what's ticked of the track taken"}, {"Esc", "deselects"}, {"Del", "deletes them"}};
|
|
gizmo = true;
|
|
}
|
|
else if (m_point_drag.moved)
|
|
hints = {{"Drag", "moves the point, level"}, {"Over a free end", "the end joins it"}, {"Release", "done"}, {"Esc", "cancel"}};
|
|
else if (m_track_point.valid())
|
|
{
|
|
char const *action{"moves the point along the axes"};
|
|
if (false == editor_track::is_end(m_track_point.kind))
|
|
action = m_gizmo_op == gizmo_operation::rotate ? "turns the control vector sideways or up, cant at its end, the joined track keeps the tangent" : m_gizmo_op == gizmo_operation::scale ? "length of the control vector" : "moves the control point, the joined track keeps the tangent";
|
|
else if (m_gizmo_op == gizmo_operation::rotate)
|
|
action = "rings about the point: direction, grade, cant; the joined tracks follow";
|
|
else if (m_gizmo_op == gizmo_operation::scale && selected != nullptr && track_gizmo_operation(*selected, true) == gizmo_operation::scale)
|
|
action = "lengthens the track at this end, the curve keeps its radius";
|
|
hints = {{"Drag a point", "moves it, an end onto the ground (Shift: keeps its height), dropped on a free end joins it"}, {"Gizmo", action}, {"Q W E", "gizmo: move, turn, lengthen"}, {"Esc", "releases the point"}};
|
|
gizmo = true;
|
|
}
|
|
else
|
|
{
|
|
char const *action{"moves the whole track"};
|
|
if (m_gizmo_op == gizmo_operation::rotate)
|
|
action = "rings: direction, grade, cant; the joined tracks follow";
|
|
else if (m_gizmo_op == gizmo_operation::scale && selected != nullptr && track_gizmo_operation(*selected, false) == gizmo_operation::scale)
|
|
action = "lengthens the track at its free end, the curve keeps its radius";
|
|
hints = {{"Drag a point", "moves it, an end dropped on a free end joins it"}, {"Gizmo", action}, {"Q W E", "gizmo: move, turn, lengthen"}, {"Shift+LMB", "adds a track to the selection, drag: a box"}, {"L", "new track, also from a free end"}, {"Esc", "deselects"}, {"Del", "deletes the track"}};
|
|
gizmo = true;
|
|
}
|
|
// the gizmo hidden has no handles to drag: Q, W and E bring it out
|
|
if (gizmo && false == m_track_gizmo_on)
|
|
{
|
|
auto const named = [](char const *Key) { return [Key](key_hint const &Hint) { return std::string_view{Hint.key} == Key; }; };
|
|
auto const handles{std::find_if(hints.begin(), hints.end(), named("Gizmo"))};
|
|
if (auto const keys{std::find_if(hints.begin(), hints.end(), named("Q W E"))}; keys != hints.end())
|
|
{
|
|
keys->action = "bring out the gizmo: move, turn, lengthen, bend by the control vectors";
|
|
if (handles != hints.end())
|
|
hints.erase(handles);
|
|
}
|
|
else if (handles != hints.end())
|
|
*handles = {"Q W E", "bring out the gizmo: move, turn, lengthen, bend by the control vectors"};
|
|
// with it hidden only the ends of the track are there to drag, the control vectors come out with it
|
|
if (auto const points{std::find_if(hints.begin(), hints.end(), named("Drag a point"))}; points != hints.end())
|
|
*points = {"Drag an end", "a joint: the neighbours follow; a free end: a new track out of it, with Ctrl it moves"};
|
|
gizmo = false;
|
|
}
|
|
if (auto const *meaning{typed_meaning()}; meaning != nullptr)
|
|
hints.insert(hints.begin() + std::min<std::size_t>(1, hints.size()), {"0-9", meaning});
|
|
if (All)
|
|
{
|
|
if (gizmo && m_gizmo_snap > 0.0f)
|
|
hints.push_back({"Ctrl", format(STR_C("gizmo snaps by %.2f m"), m_gizmo_snap)});
|
|
hints.push_back({"K", "split the path under the cursor, a break of the grade at the height of the ground"});
|
|
hints.push_back({"O", "top view"});
|
|
hints.push_back({"Esc", "back to Select"});
|
|
hints.push_back({"Hold the wheel", "pans the view"});
|
|
hints.push_back({"Ctrl+Z", "undo"});
|
|
hints.push_back({"Ctrl+Y", "redo"});
|
|
hints.push_back({"L T G N U I X B P V J", "tools: lay, switch, plan, parallel, turntable, signals, kilometrage, posts, profile, speed, joints"});
|
|
}
|
|
for (auto &hint : hints)
|
|
{
|
|
hint.raw = hint.key;
|
|
hint.key = STR_C(hint.key);
|
|
hint.action = STR(hint.action);
|
|
}
|
|
return hints;
|
|
}
|
|
|
|
// values of the change in progress, shown next to the cursor
|
|
std::string editor_mode::track_readout() const
|
|
{
|
|
if (m_tape.active)
|
|
return tape_readout();
|
|
auto const name = [](TTrack const *Track) { return name_of(*Track); };
|
|
auto const azimuth = [](glm::dvec3 const &From, glm::dvec3 const &To) {
|
|
auto const degrees{glm::degrees(std::atan2(To.x - From.x, To.z - From.z))};
|
|
return degrees < 0.0 ? degrees + 360.0 : degrees;
|
|
};
|
|
if (m_extend.active)
|
|
{
|
|
double length{0.0};
|
|
double radius{0.0};
|
|
auto const pieces{extend_preview()};
|
|
for (auto const &piece : pieces)
|
|
{
|
|
length += bezier{piece}.plan_length();
|
|
if (piece.radius != 0.0f && (radius == 0.0 || std::abs(piece.radius) < radius))
|
|
radius = std::abs(piece.radius);
|
|
}
|
|
if (m_eased_last.has_value() && false == m_eased_last->pieces.empty())
|
|
radius = m_eased_last->radius;
|
|
editor_track::snap_target target;
|
|
auto const snapped{extend_snap(target) && target.track != nullptr};
|
|
editor_track::branch_link link;
|
|
std::string reason;
|
|
if (plan_branch_link(link, reason))
|
|
return link_summary(target, link, editor_track::branch_radius(m_extend.track->m_paths[1]));
|
|
if (snapped && pieces.empty())
|
|
return format(STR_C("no track fits to the end of %s"), name(target.track).c_str());
|
|
auto text{radius > 0.0 ? format("L %.2f m R %.0f m", length, radius) + speed_of(radius, laying_norms()) : format("L %.2f m %s", length, STR_C("straight"))};
|
|
if (auto const eased{eased_of(m_eased_last)}; false == eased.empty())
|
|
text += "\n" + eased;
|
|
text += "\n" + design_speed_of(m_extend.track, snapped ? target.track : nullptr);
|
|
if (auto const vertical{vertical_of(pieces)}; false == vertical.empty())
|
|
text += "\n" + vertical;
|
|
if (snapped)
|
|
text += "\n" + format(STR_C("joins %s"), name(target.track).c_str());
|
|
for (auto const &warning : switch_exit_warnings(m_extend.track, m_extend.point, snapped ? target.track : nullptr, target.position, pieces))
|
|
text += "\n" + warning;
|
|
if (false == reason.empty())
|
|
text += "\n" + reason;
|
|
return text + "\n" + track_shaping(snapped);
|
|
}
|
|
if (m_lay.active)
|
|
{
|
|
auto const &lay{m_lay};
|
|
// of a list of warnings only the first one by the cursor, the panel lists them all
|
|
auto const first_of = [](std::string const &Lines) {
|
|
auto const end{Lines.find('\n')};
|
|
if (end == std::string::npos)
|
|
return Lines;
|
|
auto const more{static_cast<std::size_t>(std::count(Lines.begin() + end, Lines.end(), '\n'))};
|
|
return Lines.substr(0, end) + "\n" + format(STR_P("and %zu more, in the panel", "and %zu more, in the panel", static_cast<long long>(more)), more);
|
|
};
|
|
std::string text;
|
|
if (lay.points.empty())
|
|
text = lay.mouse_snap.track != nullptr ? std::string{STR_C("goes on from this end of the track")} : std::string{STR_C("start")};
|
|
else if (false == lay.preview.empty() && lay.plan.shape.valid)
|
|
{
|
|
// the curve the cursor makes now: of the last bend, or the one traced
|
|
auto const &plan{lay.plan};
|
|
text = format("L %.1f m", lay.preview_length);
|
|
if (false == plan.shape.curves.empty())
|
|
{
|
|
auto const &curve{plan.shape.curves.back()};
|
|
text += " " + curve_label(curve, laying_norms());
|
|
if (false == alignment::meets_norms(curve, plan.design))
|
|
text += "\n" + STR("this curve doesn't meet the norms, it's laid all the same");
|
|
// the curves next to the free ends going on from the curves of their tracks: the first and the last one
|
|
if (auto const on{curve_goes_on(plan.shape.curves.front())}; false == on.empty())
|
|
text += "\n" + on;
|
|
if (auto const on{curve_goes_on(curve)}; plan.shape.curves.size() > 1 && false == on.empty())
|
|
text += "\n" + on;
|
|
}
|
|
if (lay.mode == lay_mode::curve && false == plan.traces.empty() && false == plan.traces.back().offsets.empty())
|
|
{
|
|
auto const &trace{plan.traces.back()};
|
|
text += "\n" + format(STR_C("%zu points, departure %.0f cm, at most %.0f cm"), trace.points.size(), trace.rms * 100.0, trace.worst * 100.0);
|
|
}
|
|
auto const [from, to]{laying_ends()};
|
|
text += "\n" + design_speed_of(from, to);
|
|
if (auto const vertical{vertical_of(lay.preview)}; false == vertical.empty())
|
|
text += "\n" + vertical;
|
|
}
|
|
else if (false == lay.preview.empty())
|
|
{
|
|
double radius{0.0};
|
|
bool straight{false};
|
|
for (auto const &piece : lay.preview)
|
|
{
|
|
auto const r{piece_plan_radius(piece)};
|
|
if (r < 0.5)
|
|
straight = true;
|
|
else if (radius == 0.0 || r < radius)
|
|
radius = r;
|
|
}
|
|
if (m_eased_last.has_value() && false == m_eased_last->pieces.empty())
|
|
radius = m_eased_last->radius;
|
|
if (radius > 0.0)
|
|
text = (straight ? format("L %.1f m %s + R %.0f m", lay.preview_length, STR_C("straight"), radius) : format("L %.1f m R %.0f m", lay.preview_length, radius)) + speed_of(radius, laying_norms());
|
|
else
|
|
text = format("L %.1f m %s", lay.preview_length, STR_C("straight"));
|
|
if (auto const eased{eased_of(m_eased_last)}; false == eased.empty())
|
|
text += "\n" + eased;
|
|
{
|
|
auto const [from, to]{laying_ends()};
|
|
text += "\n" + design_speed_of(from, to);
|
|
}
|
|
if (auto const vertical{vertical_of(lay.preview)}; false == vertical.empty())
|
|
text += "\n" + vertical;
|
|
}
|
|
for (auto const &warning : switch_exit_warnings(lay.start.track, lay.points.empty() ? lay.mouse : lay.points.front(), lay.mouse_snap.track, lay.mouse_snap.position, lay.preview))
|
|
text += "\n" + warning;
|
|
if (false == lay.points.empty() && lay.mouse_snap.track != nullptr)
|
|
text += "\n" + format(STR_C("joins %s"), name(lay.mouse_snap.track).c_str());
|
|
if (false == lay.preview_error.empty())
|
|
text += "\n" + first_of(lay.preview_error);
|
|
if (lay.points.size() == 1 && lay.mouse_snap.track != nullptr)
|
|
text += "\n" + track_shaping(lay.start.track != nullptr);
|
|
// the bends are laid by default, the bar at the bottom tells of Tab: only the curve traced is named
|
|
if (lay.mode == lay_mode::curve)
|
|
text += "\n" + std::string{STR_C("Curve traced, Tab: the bends of straights")};
|
|
if (ImGui::GetIO().KeyAlt && false == lay.points.empty())
|
|
text += "\n" + (lay.skew.empty() ? format(STR_C("azimuth %.0f deg"), azimuth(lay.points.back(), lay.mouse)) : lay.skew);
|
|
// the warning of the first Esc leads, where it's read first
|
|
if (ImGui::GetTime() - lay.escape_time < 3.0)
|
|
text = lay.status + "\n" + text;
|
|
else if (false == lay.status.empty() && ImGui::GetTime() - lay.status_time < 4.0)
|
|
text += "\n" + first_of(lay.status);
|
|
return text;
|
|
}
|
|
auto const &state{m_straights};
|
|
if (state.tool_placed && state.tool_mouse)
|
|
{
|
|
auto const &line{state.tool_line};
|
|
auto const offset{plan_of(state.tool_handle - state.tool_point)};
|
|
if (state.tool == 1)
|
|
{
|
|
if (glm::length(offset) < 1e-3)
|
|
return {};
|
|
auto const turn{glm::degrees(signed_angle(line.direction, glm::normalize(offset)))};
|
|
return format(STR_C("turn %+.3f deg R %.0f m"), turn, straight_tool_radius(line));
|
|
}
|
|
glm::dvec2 const normal{-line.direction.y, line.direction.x};
|
|
return format(STR_C("shift %+.3f m over %.2f m"), glm::dot(offset, normal), glm::dot(offset, line.direction));
|
|
}
|
|
if (state.dragging && state.fitting)
|
|
{
|
|
auto const &result{m_route.result};
|
|
if (false == result.valid)
|
|
return result.errors.empty() ? std::string{STR_C("no curve fits")} : result.errors.front();
|
|
auto text{format(STR_C("curve L %.2f m"), result.length)};
|
|
for (auto const &curve : result.curves)
|
|
text += format(STR_C(" deflection %.3f deg"), glm::degrees(curve.deflection));
|
|
return text;
|
|
}
|
|
if (state.dragging)
|
|
{
|
|
auto const &grabbed{state.drag_line};
|
|
if (state.handle == 2)
|
|
{
|
|
glm::dvec2 const normal{-grabbed.direction.y, grabbed.direction.x};
|
|
auto const offset{state.preview_start - grabbed.start};
|
|
auto text{format(STR_C("shift %+.3f m"), glm::dot(plan_of(offset), normal))};
|
|
auto const offer{straight_parallel_offer(grabbed, offset)};
|
|
if (offer.snaps)
|
|
text += "\n" + format(STR_C("parallel %.2f m"), offer.spacing);
|
|
else if (offer.nearby)
|
|
text += "\n" + format(STR_C("close: %.2f m %.1f°"), offer.spacing, offer.angle);
|
|
return text;
|
|
}
|
|
return format(STR_C("L %.3f m (%+.3f) azimuth %.4f deg"), plan_distance(state.preview_start, state.preview_end), plan_distance(state.preview_start, state.preview_end) - grabbed.length,
|
|
azimuth(state.preview_start, state.preview_end));
|
|
}
|
|
if (m_track_set_using && m_track_gizmo_drag.operation == gizmo_operation::rotate)
|
|
return format(STR_C("turned %+.2f deg"), glm::degrees(m_track_gizmo_drag.angle));
|
|
auto const *track{selected_track()};
|
|
if (m_track_gizmo_using && track != nullptr)
|
|
{
|
|
auto const &drag{m_track_gizmo_drag};
|
|
if (drag.control)
|
|
{
|
|
auto const control{editor_track::point_position(*track, m_track_point) - editor_track::point_position(*track, editor_track::end_of(m_track_point))};
|
|
auto text{format(STR_C("control %.2f m azimuth %.2f deg"), glm::length(control), azimuth(glm::dvec3{0.0}, control))};
|
|
if (drag.operation == gizmo_operation::rotate && drag.ring == 1)
|
|
text += format(STR_C(" turned %+.2f deg"), glm::degrees(drag.angle));
|
|
if (drag.operation == gizmo_operation::rotate && drag.ring == 0)
|
|
text += format(STR_C(" grade %+.1f per mille"), 1000.0 * grade_of(control) * (glm::dot(level(control), drag.basis[2]) >= 0.0 ? 1.0 : -1.0));
|
|
if (drag.operation == gizmo_operation::rotate && drag.ring == 2)
|
|
text += " " + format(STR_C("cant %.0f mm (%+.0f mm)"), 1500.0 * std::sin(glm::radians(drag.roll0 + drag.roll)), 1500.0 * (std::sin(glm::radians(drag.roll0 + drag.roll)) - std::sin(glm::radians(drag.roll0))));
|
|
if (drag.fixed != glm::dvec3{})
|
|
text += "\n" + STR("along the switch");
|
|
return text;
|
|
}
|
|
if (drag.operation == gizmo_operation::scale && drag.path >= 0)
|
|
{
|
|
auto text{format("L %.3f m (%+.3f)", drag.stretch, drag.stretch - drag.length)};
|
|
if (drag.path < static_cast<int>(drag.paths.size()) && std::abs(drag.paths[drag.path].radius) > 0.5f)
|
|
text += format(" R %.1f m", std::abs(drag.paths[drag.path].radius));
|
|
return text;
|
|
}
|
|
if (drag.operation == gizmo_operation::rotate && drag.ring == 0)
|
|
return format(STR_C("grade changed by %+.1f per mille"), 1000.0 * drag.grade);
|
|
if (drag.operation == gizmo_operation::rotate && drag.ring == 2)
|
|
return format(STR_C("cant %.0f mm (%+.0f mm)"), 1500.0 * std::sin(glm::radians(drag.roll0 + drag.roll)), 1500.0 * (std::sin(glm::radians(drag.roll0 + drag.roll)) - std::sin(glm::radians(drag.roll0))));
|
|
if (drag.operation == gizmo_operation::rotate)
|
|
return format(STR_C("turned %+.2f deg"), glm::degrees(drag.angle));
|
|
if (m_track_point.valid() && m_track_point.path < static_cast<int>(track->m_paths.size()))
|
|
{
|
|
auto const &path{track->m_paths[m_track_point.path]};
|
|
auto text{format("L %.3f m", bezier{path}.plan_length())};
|
|
if (path.radius != 0.0f)
|
|
text += format(" R %.1f m", std::abs(path.radius));
|
|
if (m_track_snap.track != nullptr)
|
|
text += "\n" + format(STR_C("joins %s"), name(m_track_snap.track).c_str());
|
|
return text;
|
|
}
|
|
return format(STR_C("moved %.3f m"), glm::distance(editor_track::pivot(*track), m_track_pivot));
|
|
}
|
|
return {};
|
|
}
|
|
|
|
std::string editor_mode::track_shaping(bool const Joined) const
|
|
{
|
|
if (false == Joined)
|
|
{
|
|
char const *const names[]{"Arc, then straight", "Straight, then arc", "Arc through the cursor", "Straight"};
|
|
auto text{std::string{STR_C(names[static_cast<int>(m_track_layout)])}};
|
|
if (m_track_layout == track_layout::arc_straight || m_track_layout == track_layout::straight_arc)
|
|
text += format(" R %.0f m", m_lay.radius);
|
|
// the shape follows the mode of laying, Tab switching it where the laying goes on
|
|
return text + "\n" + (m_track_layout == track_layout::straight ? STR("Tab while laying: an arc, then a straight") : STR("Ctrl+wheel: radius, Tab while laying: a straight")) +
|
|
STR(", Ctrl+Shift+wheel: speed");
|
|
}
|
|
auto const &join{m_join_last};
|
|
char const *const kinds[]{"", "straight", "arc", "curve", "reverse curve", "free curve"};
|
|
std::string text{STR_C(kinds[static_cast<int>(join.kind)])};
|
|
if (join.radius > 0.0)
|
|
text += format(" R %.0f m", join.radius) + (m_join_radius > 0.0 ? std::string{} : std::string{" "} + STR("(auto)"));
|
|
if (join.cant > 0.0)
|
|
text += format(STR_C(" cant %.0f mm"), join.cant);
|
|
if (join.transition > 0.0)
|
|
text += format(STR_C(" transitions %.0f m"), join.transition);
|
|
if (join.speed > 0.0 && (join.cant > 0.0 || join.transition > 0.0))
|
|
text += format(" V %.0f km/h", join.speed);
|
|
if (join.variants > 1)
|
|
text += format(" %d/%d", (m_join_variant % join.variants + join.variants) % join.variants + 1, join.variants);
|
|
return text + "\n" + STR("Ctrl+wheel: radius, Shift+wheel: another shape") + STR(", Ctrl+Shift+wheel: speed");
|
|
}
|
|
|
|
void editor_mode::draw_empty_scenery_hint()
|
|
{
|
|
if (m_terrain_open || (m_track_tab != track_tab::path && m_track_tab != track_tab::lay) || (m_lay.active && false == m_lay.points.empty()) || m_first_steps_open || ImGui::IsPopupOpen("", ImGuiPopupFlags_AnyPopupId | ImGuiPopupFlags_AnyPopupLevel))
|
|
return;
|
|
auto const &paths{simulation::Paths.sequence()};
|
|
if (std::any_of(paths.begin(), paths.end(), [](TTrack const *Track) { return Track != nullptr && false == Track->m_editorremoved; }))
|
|
return;
|
|
// the line of the empty scenery in the middle of the view says the same: it gives way to this one
|
|
m_empty_hint_frame = ImGui::GetFrameCount();
|
|
auto *list{ImGui::GetBackgroundDrawList(ImGui::GetMainViewport())};
|
|
auto const low{editor_ui::view_min()};
|
|
auto const high{editor_ui::view_max()};
|
|
auto const font{ImGui::GetFontSize()};
|
|
auto const pad{std::round(font * 1.0f)};
|
|
auto const picture{std::round(ImGui::GetTextLineHeight() * 1.3f)};
|
|
auto const title{STR_C("The scenery has no tracks yet")};
|
|
std::vector<std::pair<char const *, char const *>> rows;
|
|
if (m_track_tab == track_tab::path)
|
|
rows.emplace_back("L", "the lay tool");
|
|
rows.emplace_back("LMB", "on the ground: the first point, then the bends of the line, the curves at them made by themselves");
|
|
rows.emplace_back("Enter", "lays the track clicked");
|
|
rows.emplace_back("F1", "all the shortcuts, and the tutorial");
|
|
auto const width{std::min(high.x - low.x - 2.0f * pad, std::round(font * 30.0f))};
|
|
auto const column{std::round(picture * 5.0f)};
|
|
auto const wrap{width - 2.0f * pad - column};
|
|
float height{pad + font * 2.4f + pad * 0.5f};
|
|
for (auto const &row : rows)
|
|
height += std::max(picture, ImGui::CalcTextSize(STR_C(row.second), nullptr, false, wrap).y) + pad * 0.45f;
|
|
height += pad * 0.6f;
|
|
ImVec2 const top{std::round((low.x + high.x - width) * 0.5f), std::round((low.y + high.y - height) * 0.5f)};
|
|
ImVec2 const bottom{top.x + width, top.y + height};
|
|
auto const accent{family_colour(0)};
|
|
list->AddRectFilled(top, bottom, IM_COL32(16, 20, 26, 215), std::round(font * 0.6f));
|
|
list->AddRect(top, bottom, (accent & ~IM_COL32_A_MASK) | IM_COL32(0, 0, 0, 160), std::round(font * 0.6f), 0, 1.5f);
|
|
auto const icon{std::round(font * 2.4f)};
|
|
editor_icons::draw(list, editor_icons::icon::lay_track, ImVec2(top.x + pad + icon * 0.5f, top.y + pad + icon * 0.5f), accent);
|
|
auto const big{font * 1.25f};
|
|
list->AddText(nullptr, big, ImVec2(top.x + pad + icon + pad * 0.6f, std::round(top.y + pad + (icon - big) * 0.5f)), ImGui::GetColorU32(ImGuiCol_Text), title);
|
|
auto y{top.y + pad + icon + pad * 0.5f};
|
|
for (auto const &row : rows)
|
|
{
|
|
auto const text{STR_C(row.second)};
|
|
auto const size{ImGui::CalcTextSize(text, nullptr, false, wrap)};
|
|
auto const line{std::max(picture, size.y)};
|
|
gesture_draw(*list, ImVec2(top.x + pad, std::round(y + (line - picture) * 0.5f)), picture, gesture_picture(row.first), ImGui::GetColorU32(ImGuiCol_Text));
|
|
list->AddText(nullptr, 0.0f, ImVec2(top.x + pad + column, std::round(y + (line - size.y) * 0.5f)), ImGui::GetColorU32(ImGuiCol_Text, 0.85f), text, nullptr, wrap);
|
|
y += line + pad * 0.45f;
|
|
}
|
|
}
|
|
|
|
void editor_mode::draw_track_hints()
|
|
{
|
|
ImGuiIO const &io = ImGui::GetIO();
|
|
auto *drawlist{ImGui::GetBackgroundDrawList(ImGui::GetMainViewport())};
|
|
float const margin{12.0f};
|
|
float const gap{14.0f};
|
|
float const pad{4.0f};
|
|
auto const chip = [&](ImVec2 const At, char const *Text, ImU32 const Background, ImU32 const Foreground) {
|
|
auto const size{ImGui::CalcTextSize(Text)};
|
|
drawlist->AddRectFilled(ImVec2(At.x, At.y - 2.0f), ImVec2(At.x + size.x + 2.0f * pad, At.y + size.y + 2.0f), Background, 3.0f);
|
|
drawlist->AddText(ImVec2(At.x + pad, At.y), Foreground, Text);
|
|
return size.x + 2.0f * pad;
|
|
};
|
|
auto hints{track_key_hints(false)};
|
|
auto const picture{std::round(ImGui::GetTextLineHeight() * 1.15f)};
|
|
std::vector<std::vector<gesture_word>> pictures;
|
|
for (auto const &hint : hints)
|
|
pictures.push_back(gesture_picture(hint.raw != nullptr ? hint.raw : hint.key));
|
|
auto const picture_width = [&](std::size_t const Index) { return pictures[Index].empty() ? 0.0f : gesture_width(picture, pictures[Index]) + 5.0f; };
|
|
auto const width_of = [&](std::size_t const Index) {
|
|
auto const chip_width{hints[Index].raw != nullptr && gesture_keys_only(hints[Index].raw) ? 0.0f : ImGui::CalcTextSize(hints[Index].key).x + 2.0f * pad + 5.0f};
|
|
return picture_width(Index) + chip_width + ImGui::CalcTextSize(hints[Index].action.c_str()).x;
|
|
};
|
|
|
|
auto const mode{track_mode_name()};
|
|
auto const left{editor_ui::view_min().x + margin};
|
|
auto const available{editor_ui::view_max().x - editor_ui::view_min().x - 2.0f * margin};
|
|
float width{ImGui::CalcTextSize(mode.c_str()).x + 2.0f * pad};
|
|
std::size_t shown{0};
|
|
for (; shown < std::min<std::size_t>(hints.size(), 3); ++shown)
|
|
{
|
|
auto const next{width + gap + width_of(shown)};
|
|
if (next > available)
|
|
break;
|
|
width = next;
|
|
}
|
|
auto const height{ImGui::GetTextLineHeight()};
|
|
auto const bottom{m_profile.strip_top > editor_ui::view_min().y + 4.0f * height ? std::min(editor_ui::view_max().y, m_profile.strip_top) : editor_ui::view_max().y};
|
|
auto const y{bottom - margin - height};
|
|
ImVec2 const from{left - 6.0f, y - pad - 2.0f};
|
|
ImVec2 const to{left + width + 6.0f, y + height + pad};
|
|
auto const hovered{io.MousePos.x > from.x - 40.0f && io.MousePos.x < to.x + 40.0f && io.MousePos.y > from.y - 40.0f && io.MousePos.y < to.y + 40.0f};
|
|
auto const fade = [hovered](ImU32 const Colour) { return hovered ? (Colour & ~IM_COL32_A_MASK) | (((Colour >> IM_COL32_A_SHIFT) & 0xFF) / 4 << IM_COL32_A_SHIFT) : Colour; };
|
|
drawlist->AddRectFilled(from, to, fade(IM_COL32(0, 0, 0, 160)), 4.0f);
|
|
auto x{left};
|
|
auto const &modes{track_modes()};
|
|
auto const tab{false == m_track_window_open ? track_tab::path : m_track_tab == track_tab::route ? track_tab::straights : m_track_tab};
|
|
auto const found{std::find_if(modes.begin(), modes.end(), [&](track_mode const &Mode) { return Mode.tab == tab; })};
|
|
auto const family{(family_colour(found != modes.end() ? found->family : 0) & ~IM_COL32_A_MASK) | IM_COL32(0, 0, 0, 235)};
|
|
x += chip(ImVec2(x, y), mode.c_str(), fade(family), fade(IM_COL32(255, 255, 255, 255)));
|
|
for (std::size_t i = 0; i < shown; ++i)
|
|
{
|
|
x += gap;
|
|
if (false == pictures[i].empty())
|
|
x += gesture_draw(*drawlist, ImVec2(x, std::round(y + (height - picture) * 0.5f)), picture, pictures[i], fade(IM_COL32(255, 255, 255, 230))) + 5.0f;
|
|
if (hints[i].raw == nullptr || false == gesture_keys_only(hints[i].raw))
|
|
x += chip(ImVec2(x, y), hints[i].key, fade(IM_COL32(255, 210, 60, 220)), fade(IM_COL32(20, 20, 20, 255))) + 5.0f;
|
|
drawlist->AddText(ImVec2(x, y), fade(IM_COL32(255, 255, 255, 230)), hints[i].action.c_str());
|
|
x += ImGui::CalcTextSize(hints[i].action.c_str()).x;
|
|
}
|
|
|
|
auto readout{track_readout()};
|
|
if (auto const *meaning{typed_meaning()}; meaning != nullptr && false == m_typed.empty())
|
|
readout += (readout.empty() ? "" : "\n") + std::string{"= "} + m_typed + "_ " + STR(meaning);
|
|
if (readout.empty() || ImGui::GetIO().WantCaptureMouse)
|
|
return;
|
|
auto *foreground{ImGui::GetForegroundDrawList(ImGui::GetMainViewport())};
|
|
auto const size{ImGui::CalcTextSize(readout.c_str())};
|
|
// right below the cursor, or on its other side where the view ends: it doesn't cover the panels by the view
|
|
auto const low{editor_ui::view_min()};
|
|
auto const high{editor_ui::view_max()};
|
|
ImVec2 at{io.MousePos.x + 20.0f, io.MousePos.y + 20.0f};
|
|
if (at.x + size.x + 10.0f > high.x)
|
|
at.x = io.MousePos.x - 20.0f - size.x;
|
|
if (at.y + size.y + 10.0f > high.y)
|
|
at.y = io.MousePos.y - 20.0f - size.y;
|
|
at.x = std::max(at.x, low.x + 10.0f);
|
|
at.y = std::max(at.y, low.y + 10.0f);
|
|
foreground->AddRectFilled(ImVec2(at.x - 6.0f, at.y - 4.0f), ImVec2(at.x + size.x + 6.0f, at.y + size.y + 4.0f), IM_COL32(0, 0, 0, 190), 4.0f);
|
|
foreground->AddRect(ImVec2(at.x - 6.0f, at.y - 4.0f), ImVec2(at.x + size.x + 6.0f, at.y + size.y + 4.0f), overlay_color::marked, 4.0f);
|
|
foreground->AddText(at, IM_COL32(255, 255, 255, 255), readout.c_str());
|
|
}
|
|
|
|
void editor_mode::draw_blade_tips() const
|
|
{
|
|
segment_data main;
|
|
double tip{0.0};
|
|
if (m_switch.placing && m_switch.connection < 0)
|
|
{
|
|
auto const preview{switch_preview()};
|
|
if (preview.size() < 2)
|
|
return;
|
|
main = preview[0];
|
|
tip = editor_track::blade_tip_of(preview[1]);
|
|
}
|
|
else if (auto const *selected{selected_track()}; selected != nullptr && selected->eType == tt_Switch && selected->m_paths.size() >= 2 && false == selected->m_editorremoved)
|
|
{
|
|
main = selected->m_paths[0];
|
|
tip = editor_track::blade_tip_of(*selected);
|
|
}
|
|
else
|
|
return;
|
|
// on the photo the tips of the blades are seen where the switch seems to begin, the joint before them isn't
|
|
screen_projection const projection;
|
|
auto *drawlist{ImGui::GetBackgroundDrawList(ImGui::GetMainViewport())};
|
|
geometry::bezier const curve{main};
|
|
auto const mark = [&](double const Distance, ImU32 const Colour, float const Width, char const *Label, int const Side) {
|
|
auto const t{curve.parameter(Distance)};
|
|
auto const at{curve.point(t)};
|
|
auto direction{plan_of(curve.first(t))};
|
|
if (glm::length(direction) < 1e-9)
|
|
return;
|
|
direction = glm::normalize(direction);
|
|
glm::dvec3 const across{-direction.y * 1.6, 0.0, direction.x * 1.6};
|
|
projection.line(drawlist, at - across, at + across, IM_COL32(0, 0, 0, 170), Width + 3.0f);
|
|
projection.line(drawlist, at - across, at + across, Colour, Width);
|
|
ImVec2 screen;
|
|
if (projection.project(at + across * static_cast<double>(Side), screen))
|
|
{
|
|
auto const size{ImGui::CalcTextSize(Label)};
|
|
ImVec2 const corner{Side > 0 ? screen.x + 6.0f : screen.x - 6.0f - size.x, screen.y - 0.5f * size.y};
|
|
drawlist->AddRectFilled({corner.x - 3.0f, corner.y - 1.0f}, {corner.x + size.x + 3.0f, corner.y + size.y + 1.0f}, IM_COL32(0, 0, 0, 160), 3.0f);
|
|
drawlist->AddText(corner, Colour, Label);
|
|
}
|
|
};
|
|
mark(0.0, IM_COL32(220, 220, 220, 230), 2.0f, STR_C("joint before the blades"), -1);
|
|
if (tip > 0.05)
|
|
mark(tip, IM_COL32(255, 170, 40, 255), 3.0f, STR_C("tips of the blades"), 1);
|
|
}
|
|
|
|
void editor_mode::draw_switch_problem(switch_problem const &Problem) const
|
|
{
|
|
screen_projection const projection;
|
|
auto *drawlist{ImGui::GetBackgroundDrawList(ImGui::GetMainViewport())};
|
|
// blinking twice a second, never out quite
|
|
auto const pulse{static_cast<float>(0.5 + 0.5 * std::cos(ImGui::GetTime() * 4.0 * glm::pi<double>()))};
|
|
auto const colour{(overlay_color::invalid & ~IM_COL32_A_MASK) | (static_cast<ImU32>(70.0f + 185.0f * pulse) << IM_COL32_A_SHIFT)};
|
|
for (auto const &path : Problem.paths)
|
|
for (auto const &piece : path.pieces.empty() ? std::vector<segment_data>{path} : path.pieces)
|
|
{
|
|
bezier const curve{piece};
|
|
auto previous{curve.point(0.0)};
|
|
for (int i = 1; i <= 24; ++i)
|
|
{
|
|
auto const next{curve.point(i / 24.0)};
|
|
projection.line(drawlist, previous, next, IM_COL32(0, 0, 0, 150), 10.0f);
|
|
projection.line(drawlist, previous, next, colour, 6.0f);
|
|
previous = next;
|
|
}
|
|
}
|
|
auto const label = [&](ImVec2 const &At, std::string const &Text) {
|
|
auto const size{ImGui::CalcTextSize(Text.c_str(), nullptr, false, 460.0f)};
|
|
drawlist->AddRectFilled({At.x - 5.0f, At.y - 3.0f}, {At.x + size.x + 5.0f, At.y + size.y + 3.0f}, IM_COL32(0, 0, 0, 200), 3.0f);
|
|
drawlist->AddText(ImGui::GetFont(), ImGui::GetFontSize(), At, overlay_color::invalid, Text.c_str(), nullptr, 460.0f);
|
|
};
|
|
for (auto const &[point, text] : Problem.marks)
|
|
{
|
|
ImVec2 screen;
|
|
if (false == projection.project(point, screen))
|
|
continue;
|
|
auto const radius{10.0f + 8.0f * pulse};
|
|
drawlist->AddCircle(screen, radius, IM_COL32(0, 0, 0, 150), 24, 6.0f);
|
|
drawlist->AddCircle(screen, radius, colour, 24, 3.0f);
|
|
if (false == text.empty())
|
|
label({screen.x + 26.0f, screen.y - 0.5f * ImGui::GetFontSize()}, text);
|
|
}
|
|
// why, by the cursor
|
|
if (auto const &io{ImGui::GetIO()}; false == Problem.text.empty() && ImGui::IsMousePosValid())
|
|
label({io.MousePos.x + 20.0f, io.MousePos.y + 26.0f}, Problem.text);
|
|
}
|
|
|
|
void editor_mode::draw_build_overlay() const
|
|
{
|
|
screen_projection const projection;
|
|
ImDrawList *drawlist = ImGui::GetBackgroundDrawList(ImGui::GetMainViewport());
|
|
// over a dark edge: the light colours of the tracks being built stay seen over the light base map of the top view too
|
|
auto const drawpath = [&](segment_data const &Path, ImU32 const Color) {
|
|
for (auto const &[colour, width] : {std::pair{IM_COL32(0, 0, 0, 170), 6.0f}, std::pair{Color, 3.0f}})
|
|
for (auto const &piece : Path.pieces.empty() ? std::vector<segment_data>{Path} : Path.pieces)
|
|
{
|
|
bezier const curve{piece};
|
|
auto previous{curve.point(0.0)};
|
|
for (int i = 1; i <= 24; ++i)
|
|
{
|
|
auto const next{curve.point(i / 24.0)};
|
|
projection.line(drawlist, previous, next, colour, width);
|
|
previous = next;
|
|
}
|
|
}
|
|
};
|
|
// the track being laid as its two rails: their axes 1.5 m apart, the gauge and the head of a rail, at the height of the path
|
|
auto const kRailAxes{1.5};
|
|
auto const drawrails = [&](segment_data const &Path, ImU32 const Color) {
|
|
for (auto const &[colour, width] : {std::pair{IM_COL32(0, 0, 0, 170), 4.0f}, std::pair{Color, 2.0f}})
|
|
for (auto const &piece : Path.pieces.empty() ? std::vector<segment_data>{Path} : Path.pieces)
|
|
{
|
|
bezier const curve{piece};
|
|
auto const rail_at = [&](double const T, double const Side) {
|
|
auto const tangent{plan_of(curve.first(T))};
|
|
if (glm::length(tangent) < 1e-9)
|
|
return curve.point(T);
|
|
auto const across{glm::normalize(glm::dvec2{-tangent.y, tangent.x}) * (Side * 0.5 * kRailAxes)};
|
|
return curve.point(T) + glm::dvec3{across.x, 0.0, across.y};
|
|
};
|
|
for (auto const side : {-1.0, 1.0})
|
|
{
|
|
auto previous{rail_at(0.0, side)};
|
|
for (int i = 1; i <= 24; ++i)
|
|
{
|
|
auto const next{rail_at(i / 24.0, side)};
|
|
projection.line(drawlist, previous, next, colour, width);
|
|
previous = next;
|
|
}
|
|
}
|
|
}
|
|
};
|
|
// a circle on the ground as wide as the rails are apart, around the point; a few pixels across at least, seen from far
|
|
auto const drawwidth = [&](glm::dvec3 const &Point, ImU32 const Color) {
|
|
ImVec2 centre;
|
|
if (false == projection.project(Point, centre))
|
|
return;
|
|
std::array<ImVec2, 24> outline;
|
|
auto seen{true};
|
|
for (std::size_t i = 0; i < outline.size() && seen; ++i)
|
|
{
|
|
auto const angle{2.0 * glm::pi<double>() * static_cast<double>(i) / outline.size()};
|
|
seen = projection.project(Point + glm::dvec3{std::cos(angle), 0.0, std::sin(angle)} * (0.5 * kRailAxes), outline[i]);
|
|
}
|
|
auto const dot{false == seen || std::hypot(outline[0].x - centre.x, outline[0].y - centre.y) < 4.0f};
|
|
for (auto const &[colour, width] : {std::pair{IM_COL32(0, 0, 0, 170), 4.0f}, std::pair{Color, 2.0f}})
|
|
{
|
|
if (dot)
|
|
drawlist->AddCircle(centre, 4.0f, colour, 16, width);
|
|
else
|
|
drawlist->AddPolyline(outline.data(), static_cast<int>(outline.size()), colour, ImDrawFlags_Closed, width);
|
|
}
|
|
};
|
|
// a slip is selected whole: all its tracks with the one picked
|
|
if (auto const *selected{selected_track()}; selected != nullptr && false == m_switch.slide.active)
|
|
if (auto const slip{slip_of(*selected)})
|
|
for (auto const *part : slip->parts)
|
|
for (auto const &path : part->m_paths)
|
|
drawpath(path, overlay_color::highlight);
|
|
// none while a point is dragged: there is nothing to split then
|
|
if (m_track_tab == track_tab::path && false == m_lay.active && false == m_track_gizmo_using && false == m_point_drag.active && false == m_handle_drag.active)
|
|
if (auto const spot{split_spot()}; spot.track != nullptr)
|
|
{
|
|
ImVec2 at;
|
|
if (projection.project(spot.point, at))
|
|
{
|
|
drawlist->AddCircle(at, 6.0f, overlay_color::highlight, 12, 1.5f);
|
|
drawlist->AddText({at.x + 9.0f, at.y - 18.0f}, overlay_color::highlight, STR_C("K: split here"));
|
|
}
|
|
}
|
|
auto const &display{ImGui::GetIO().DisplaySize};
|
|
// in the 3D view only near the camera, where they can be told apart; from above all of them
|
|
glm::dvec3 const eye{Global.pCamera.Pos};
|
|
auto const in_reach = [&](glm::dvec3 const &Point) { return Global.EditorOrtho || glm::distance(Point, eye) <= kDotsRange; };
|
|
// far out the joints of the pieces would cover the tracks, only the free ends are told
|
|
auto const joints{false == Global.EditorOrtho || display.y <= 0.0f || 2.0 * static_cast<double>(Global.EditorOrthoExtent) / display.y <= 1.0};
|
|
for (auto const *track : simulation::Paths.sequence())
|
|
{
|
|
if (false == joints)
|
|
break;
|
|
if (track == nullptr || track->m_editorremoved || track->m_paths.empty())
|
|
continue;
|
|
for (auto const &path : track->m_paths)
|
|
for (auto const point : {segment_data::point::start, segment_data::point::end})
|
|
{
|
|
ImVec2 screen;
|
|
if (in_reach(path.points[point]) && projection.project(path.points[point], screen) && screen.x >= 0.0f && screen.y >= 0.0f && screen.x <= display.x && screen.y <= display.y)
|
|
drawlist->AddCircleFilled(screen, 3.5f, kJointColor);
|
|
}
|
|
}
|
|
// the ends joined to nothing, where a train would run off
|
|
for (auto const &point : free_end_points(eye, Global.EditorOrtho ? std::max(kDotsRange, static_cast<double>(Global.EditorOrthoExtent) * 2.0) : kDotsRange))
|
|
{
|
|
ImVec2 screen;
|
|
if (in_reach(point) && projection.project(point, screen) && screen.x >= 0.0f && screen.y >= 0.0f && screen.x <= display.x && screen.y <= display.y)
|
|
{
|
|
drawlist->AddCircleFilled(screen, 5.0f, kFreeEndColor);
|
|
drawlist->AddCircle(screen, 5.0f, IM_COL32(0, 0, 0, 160), 12, 1.0f);
|
|
}
|
|
}
|
|
if (m_extend.active)
|
|
{
|
|
if (m_extend.track != nullptr)
|
|
draw_free_ends(m_extend.track, m_extend.track->iCategoryFlag & 15, {m_extend.track});
|
|
crossover_plan plan;
|
|
editor_track::snap_target target;
|
|
if (extend_snap(target))
|
|
{
|
|
ImVec2 screen;
|
|
if (projection.project(target.position, screen))
|
|
drawlist->AddCircle(screen, 14.0f, IM_COL32(255, 60, 255, 255), 20, 3.0f);
|
|
for (auto const &piece : extend_preview())
|
|
drawpath(piece, overlay_color::marked);
|
|
}
|
|
else if (plan_crossover(plan))
|
|
{
|
|
for (auto const &piece : plan.paths)
|
|
drawpath(piece, overlay_color::marked);
|
|
for (auto const &piece : plan.inserts)
|
|
drawpath(piece, overlay_color::grip);
|
|
}
|
|
else
|
|
{
|
|
for (auto const &piece : extend_preview())
|
|
drawpath(piece, overlay_color::marked);
|
|
}
|
|
}
|
|
// what letting go there makes, by the cursor
|
|
auto const connection_label = [&](std::string const &Text, ImU32 const Colour) {
|
|
ImVec2 screen;
|
|
if (false == projection.project(m_switch.mouse, screen))
|
|
return;
|
|
auto const size{ImGui::CalcTextSize(Text.c_str())};
|
|
drawlist->AddRectFilled(ImVec2(screen.x + 14.0f, screen.y + 10.0f), ImVec2(screen.x + 22.0f + size.x, screen.y + 14.0f + size.y), IM_COL32(0, 0, 0, 180), 3.0f);
|
|
drawlist->AddText(ImVec2(screen.x + 18.0f, screen.y + 12.0f), Colour, Text.c_str());
|
|
};
|
|
if (m_switch.placing && m_switch.connection >= 0 && m_switch.curved)
|
|
// along a curve it's worked out as the switch is let go
|
|
connection_label(connection_name(m_switch.connection), overlay_color::highlight);
|
|
if (m_switch.placing && m_switch.connection >= 0 && false == m_switch.curved)
|
|
{
|
|
connection::request request;
|
|
connection::result plan;
|
|
// over a crossover there already, the double or the scissors one made with it
|
|
auto const valid{m_switch.partner != nullptr ? plan_partner_connection(request, plan) : plan_connection(request, plan)};
|
|
if (valid)
|
|
{
|
|
for (auto const &entry : plan.switches)
|
|
for (auto const &path : entry.paths)
|
|
drawpath(path, overlay_color::marked);
|
|
for (auto const &insert : plan.inserts)
|
|
drawpath(insert, overlay_color::grip);
|
|
if (plan.crossing)
|
|
for (int i = 0; i < 4; i += 2)
|
|
{
|
|
segment_data path;
|
|
path.points[segment_data::point::start] = plan.ends[i];
|
|
path.points[segment_data::point::end] = plan.ends[i + 1];
|
|
drawpath(path, overlay_color::grip);
|
|
}
|
|
}
|
|
else
|
|
for (auto const &piece : switch_preview())
|
|
drawpath(piece, overlay_color::invalid);
|
|
auto const text{valid ? connection_readout(plan) : plan.error.empty() ? std::string{STR_C("Drag onto the other track")} : plan.error};
|
|
connection_label(text, valid ? (plan.warning.empty() ? overlay_color::highlight : overlay_color::warning) : overlay_color::invalid);
|
|
}
|
|
else if (auto const *selected{selected_track()}; false == m_switch.placing && m_track_tab == track_tab::turnout && m_switch.connection < 0 && m_switch.armed >= 0 && m_switch.armed < static_cast<int>(m_switch.templates.size()) &&
|
|
m_switch.templates[m_switch.armed].double_slip && selected != nullptr && selected == m_straights.current_for && false == m_straights.current.tracks.empty() &&
|
|
false == ImGui::GetIO().WantCaptureMouse)
|
|
{
|
|
// where the slip goes for a click there, before the click
|
|
auto const &line{m_straights.current};
|
|
auto const cursor{cursor_on_straight(line)};
|
|
auto const along{std::clamp(line.along(cursor), 0.0, line.length)};
|
|
if (plan_distance(line.start + glm::dvec3{line.direction.x, line.grade, line.direction.y} * along, cursor) <= kSwitchReach)
|
|
{
|
|
slip_plan plan;
|
|
auto const valid{plan_double_slip(line, cursor, m_switch.templates[m_switch.armed], plan)};
|
|
std::string text{plan.problem};
|
|
glm::dvec3 marker{cursor};
|
|
ImU32 colour{overlay_color::invalid};
|
|
// with nothing crossing here the slip is dragged out with its crossing track
|
|
if (false == valid && plan.lone)
|
|
{
|
|
colour = overlay_color::highlight;
|
|
text = STR_C("Press and drag: the slip with its crossing track, through the quarter of the cursor");
|
|
}
|
|
else if (valid && plan.replaces != nullptr)
|
|
{
|
|
marker = plan.replaces->location();
|
|
colour = overlay_color::highlight;
|
|
text = STR_C("Press and drag: this double slip is replaced by the one chosen");
|
|
}
|
|
else if (valid)
|
|
{
|
|
for (int i = 0; i < 4; i += 2)
|
|
{
|
|
segment_data path;
|
|
path.points[segment_data::point::start] = plan.points[i];
|
|
path.points[segment_data::point::end] = plan.points[i + 1];
|
|
drawpath(path, overlay_color::marked);
|
|
}
|
|
marker = {plan.crossing.x, line.start.y + line.grade * plan.alongfirst, plan.crossing.y};
|
|
colour = overlay_color::highlight;
|
|
text = plan.note.empty() ? std::string{STR_C("Press and drag: it goes here")} : plan.note;
|
|
}
|
|
ImVec2 screen;
|
|
if (projection.project(marker, screen))
|
|
{
|
|
drawlist->AddCircle(screen, 12.0f, colour, 20, 2.5f);
|
|
drawlist->AddText({screen.x + 16.0f, screen.y - 8.0f}, colour, text.c_str());
|
|
}
|
|
}
|
|
}
|
|
else if (m_switch.placing)
|
|
{
|
|
auto const preview{switch_preview()};
|
|
for (auto const &piece : preview)
|
|
drawpath(piece, overlay_color::marked);
|
|
// moved back onto the straight or into the curve, or too long for it: what's in the way blinks
|
|
if (auto const problem{switch_drag_problem()})
|
|
draw_switch_problem(*problem);
|
|
// the lines told of a switch bent, in a box beside the point
|
|
auto const readout_at = [&](glm::dvec3 const &Point, std::vector<std::pair<std::string, ImU32>> const &Lines) {
|
|
ImVec2 screen;
|
|
if (false == projection.project(Point, screen))
|
|
return;
|
|
auto const wrap{460.0f};
|
|
auto height{0.0f};
|
|
auto width{0.0f};
|
|
for (auto const &[text, colour] : Lines)
|
|
{
|
|
auto const size{ImGui::CalcTextSize(text.c_str(), nullptr, false, wrap)};
|
|
height += size.y + 2.0f;
|
|
width = std::max(width, size.x);
|
|
}
|
|
ImVec2 corner{screen.x + 24.0f, screen.y + 24.0f};
|
|
drawlist->AddRectFilled({corner.x - 6.0f, corner.y - 4.0f}, {corner.x + width + 6.0f, corner.y + height + 4.0f}, IM_COL32(10, 20, 30, 215), 4.0f);
|
|
for (auto const &[text, colour] : Lines)
|
|
{
|
|
drawlist->AddText(ImGui::GetFont(), ImGui::GetFontSize(), corner, colour, text.c_str(), nullptr, wrap);
|
|
corner.y += ImGui::CalcTextSize(text.c_str(), nullptr, false, wrap).y + 2.0f;
|
|
}
|
|
};
|
|
// a radius counted positive the way the line turns, the other way with a minus
|
|
auto const radius = [](double const Curvature) { return std::abs(Curvature) < 2e-5 ? std::string{STR_C("straight")} : format("%.0f m", 1.0 / Curvature); };
|
|
// laid on from a free end: bent, the radius of the main track and the way of the diverging one, the track into the free end the
|
|
// cursor is at, the norms; from an end of a switch, the change of the curvature from it
|
|
if (m_switch.free && preview.size() >= 2)
|
|
{
|
|
// few lines: the radii, the track into the free end, the warnings; what the keys do the bar at the bottom tells
|
|
std::vector<std::pair<std::string, ImU32>> lines;
|
|
if (free_bend bend; free_switch_bend(bend))
|
|
{
|
|
if (bend.radius > 0.0)
|
|
lines.emplace_back(format(bend.side == bend.turn ? STR_C("one-sided: main R %.0f m, diverging R %.0f m") : STR_C("two-sided: main R %.0f m, diverging R %.0f m"), bend.radius, editor_track::branch_radius(bend.paths[1])),
|
|
IM_COL32(255, 170, 40, 255));
|
|
if (bend.target.track != nullptr)
|
|
{
|
|
lines.emplace_back(bend.problem.empty() ? link_summary(bend.target, bend.link, editor_track::branch_radius(bend.paths[bend.diverging ? 1 : 0])) : bend.problem, bend.problem.empty() ? IM_COL32(255, 60, 255, 255) : overlay_color::invalid);
|
|
ImVec2 screen;
|
|
if (projection.project(bend.target.position, screen))
|
|
drawlist->AddCircle(screen, 14.0f, bend.problem.empty() ? IM_COL32(255, 60, 255, 255) : overlay_color::invalid, 20, 3.0f);
|
|
}
|
|
// what it breaks first: it isn't laid so
|
|
for (auto const &refusal : bend.report.refusals)
|
|
lines.emplace_back(refusal, overlay_color::invalid);
|
|
for (auto const &warning : bend.report.warnings)
|
|
lines.emplace_back(warning, overlay_color::invalid);
|
|
}
|
|
for (auto const &warning : free_switch_exits(preview))
|
|
lines.emplace_back(warning, overlay_color::invalid);
|
|
if (false == lines.empty())
|
|
readout_at(m_switch.point, lines);
|
|
}
|
|
// into a curve: the ends of the cant ramps, what the start was drawn to, the radii at the ends of the switch and the norms
|
|
if (auto const &tool{m_switch}; tool.curved && tool.connection < 0 && preview.size() >= 2)
|
|
{
|
|
auto const points{frame_points(tool.frame)};
|
|
for (auto const end : switch_curve::ramp_ends(points))
|
|
{
|
|
auto const sample{sample_at(tool.frame, end)};
|
|
glm::dvec3 const across{-sample.tangent.y * 2.5, 0.0, sample.tangent.x * 2.5};
|
|
projection.line(drawlist, sample.position - across, sample.position + across, IM_COL32(255, 170, 40, 255), 3.0f);
|
|
ImVec2 screen;
|
|
if (projection.project(sample.position + across, screen))
|
|
drawlist->AddText({screen.x + 4.0f, screen.y - 7.0f}, IM_COL32(255, 170, 40, 255), STR_C("ramp"));
|
|
}
|
|
int forward;
|
|
int side;
|
|
curved_switch_pose(forward, side);
|
|
std::string snapped;
|
|
std::vector<std::string> notes;
|
|
std::vector<std::string> warnings;
|
|
std::vector<std::pair<std::string, ImU32>> lines;
|
|
double station;
|
|
if (auto const &shape{tool.templates[tool.armed]}; shape.double_slip)
|
|
{
|
|
// a slip bent: the radii of its tracks and its slip curves, its middle where the station is
|
|
curved_slip plan;
|
|
plan_curved_slip(shape, forward, side, plan);
|
|
snapped = plan.snapped;
|
|
station = plan.middle;
|
|
auto const report{curved_slip_report(plan, shape.type)};
|
|
for (auto const &line : slip_report_lines(report))
|
|
lines.emplace_back(line, IM_COL32(255, 255, 255, 235));
|
|
notes = report.notes;
|
|
// what it breaks first: it isn't laid so
|
|
warnings = report.refusals;
|
|
warnings.insert(warnings.end(), report.warnings.begin(), report.warnings.end());
|
|
}
|
|
else
|
|
{
|
|
station = curved_switch_start(forward, &snapped);
|
|
auto const report{curved_switch_report(preview, m_switch.frame, station, forward, &m_switch.frame_tracks)};
|
|
if (report.curved)
|
|
{
|
|
lines.emplace_back(format(STR_C("main track R %s at the start, %s at the end"), radius(report.main_start).c_str(), radius(report.main_end).c_str()), IM_COL32(255, 255, 255, 235));
|
|
lines.emplace_back(format(STR_C("diverging track R %s at the start, %s at the end"), radius(report.branch_start).c_str(), radius(report.branch_end).c_str()), IM_COL32(255, 255, 255, 235));
|
|
}
|
|
lines.emplace_back(format(STR_C("cant %.0f mm at the start, %.0f mm at the end"), report.cant_start, report.cant_end), IM_COL32(255, 255, 255, 235));
|
|
notes = report.notes;
|
|
warnings = report.refusals;
|
|
warnings.insert(warnings.end(), report.warnings.begin(), report.warnings.end());
|
|
}
|
|
if (false == snapped.empty())
|
|
lines.emplace(lines.begin(), snapped, IM_COL32(255, 170, 40, 255));
|
|
for (auto const ¬e : notes)
|
|
lines.emplace_back(note, IM_COL32(170, 200, 230, 235));
|
|
for (auto const &warning : warnings)
|
|
lines.emplace_back(warning, overlay_color::invalid);
|
|
readout_at(sample_at(tool.frame, station).position, lines);
|
|
}
|
|
switch_link plan;
|
|
auto const linked{plan_switch_link(plan)};
|
|
ImVec2 screen;
|
|
if (plan.target.track != nullptr && projection.project(plan.target.position, screen))
|
|
{
|
|
drawlist->AddCircle(screen, 14.0f, linked ? IM_COL32(255, 60, 255, 255) : overlay_color::invalid, 20, 3.0f);
|
|
if (false == linked && false == plan.reason.empty())
|
|
drawlist->AddText({screen.x + 18.0f, screen.y - 8.0f}, overlay_color::invalid, plan.reason.c_str());
|
|
}
|
|
}
|
|
// a switch refused or laid elsewhere than dragged to: where and why, a while after it's let go
|
|
if (false == m_switch.placing && ImGui::GetTime() < m_switch_flash_until)
|
|
draw_switch_problem(m_switch_flash);
|
|
if (m_lay.active)
|
|
{
|
|
auto const &lay{m_lay};
|
|
auto const &plan{lay.plan};
|
|
auto const piece_colour = [&](segment_data const &Path) {
|
|
if (false == lay.preview_error.empty() && plan.shape.warnings.empty())
|
|
return overlay_color::warning;
|
|
return piece_plan_radius(Path) < 0.5 ? IM_COL32(255, 255, 255, 230) : overlay_color::marked;
|
|
};
|
|
for (auto const &piece : lay.preview)
|
|
drawrails(piece, piece_colour(piece));
|
|
auto const label_at = [&](glm::dvec3 const &Point, std::string const &Text, ImU32 const Colour) {
|
|
ImVec2 screen;
|
|
if (false == projection.project(Point, screen))
|
|
return;
|
|
auto const size{ImGui::CalcTextSize(Text.c_str())};
|
|
drawlist->AddRectFilled(ImVec2(screen.x + 6.0f, screen.y - 8.0f), ImVec2(screen.x + 14.0f + size.x, screen.y + 8.0f), IM_COL32(0, 0, 0, 180), 3.0f);
|
|
drawlist->AddText(ImVec2(screen.x + 10.0f, screen.y - 8.0f), Colour, Text.c_str());
|
|
};
|
|
// the straights the next bend slides along, dashed
|
|
for (auto const &[from, to] : plan.guides)
|
|
{
|
|
auto const length{plan_distance(from, to)};
|
|
auto const dashes{std::clamp(static_cast<int>(length / 4.0), 1, 400)};
|
|
for (int k = 0; k < dashes; k += 2)
|
|
projection.line(drawlist, glm::mix(from, to, static_cast<double>(k) / dashes), glm::mix(from, to, static_cast<double>(k + 1) / dashes), IM_COL32(255, 255, 255, 150), 1.5f);
|
|
}
|
|
// the curves of the line laid by the points: the bends eased, the curves traced, in the colour of a warning where they don't meet
|
|
// the norms; the length of the straights between them
|
|
if (plan.shape.valid)
|
|
{
|
|
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_label(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);
|
|
}
|
|
for (std::size_t i = 0, n = plan.shape.valid ? 0 : lay.preview.size(); i < n;)
|
|
{
|
|
auto const radius{piece_plan_radius(lay.preview[i])};
|
|
bool const curved{radius >= 0.5};
|
|
std::size_t j{i + 1};
|
|
double length{bezier{lay.preview[i]}.plan_length()};
|
|
double sharpest{radius};
|
|
for (; j < n; ++j)
|
|
{
|
|
auto const next{piece_plan_radius(lay.preview[j])};
|
|
if ((next >= 0.5) != curved)
|
|
break;
|
|
length += bezier{lay.preview[j]}.plan_length();
|
|
if (curved && next < sharpest)
|
|
sharpest = next;
|
|
}
|
|
double along{0.0};
|
|
glm::dvec3 middle{bezier{lay.preview[i]}.point(0.5)};
|
|
for (std::size_t k = i; k < j; ++k)
|
|
{
|
|
auto const piece{bezier{lay.preview[k]}.plan_length()};
|
|
if (along + piece >= length * 0.5)
|
|
{
|
|
middle = bezier{lay.preview[k]}.point(piece > 1e-6 ? std::clamp((length * 0.5 - along) / piece, 0.0, 1.0) : 0.5);
|
|
break;
|
|
}
|
|
along += piece;
|
|
}
|
|
ImVec2 screen;
|
|
if (projection.project(middle, screen))
|
|
{
|
|
auto const label{curved ? format("R %.0f", sharpest) : std::string{STR_C("straight")}};
|
|
auto const size{ImGui::CalcTextSize(label.c_str())};
|
|
drawlist->AddRectFilled(ImVec2(screen.x + 6.0f, screen.y - 8.0f), ImVec2(screen.x + 14.0f + size.x, screen.y + 8.0f), IM_COL32(0, 0, 0, 180), 3.0f);
|
|
drawlist->AddText(ImVec2(screen.x + 10.0f, screen.y - 8.0f), curved ? overlay_color::marked : overlay_color::highlight, label.c_str());
|
|
}
|
|
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)
|
|
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) {
|
|
for (auto const &trace : plan.traces)
|
|
for (std::size_t k = 0; k < trace.points.size() && k < trace.offsets.size(); ++k)
|
|
if (glm::distance(trace.points[k], Point) < 1e-6)
|
|
return std::abs(trace.offsets[k]);
|
|
return -1.0;
|
|
};
|
|
for (std::size_t i = 0; i < lay.points.size(); ++i)
|
|
{
|
|
ImVec2 screen;
|
|
if (false == projection.project(lay.points[i], screen))
|
|
continue;
|
|
// the start of the line as wide as the track
|
|
if (i == 0)
|
|
{
|
|
drawwidth(lay.points[i], overlay_color::grip);
|
|
continue;
|
|
}
|
|
if (i < lay.modes.size() && lay.modes[i] == lay_mode::curve)
|
|
{
|
|
auto const off{departure(lay.points[i])};
|
|
auto const colour{off < 0.0 ? overlay_color::grip : off <= 0.1 ? IM_COL32(90, 220, 110, 255) : off <= 0.3 ? IM_COL32(255, 200, 60, 255) : IM_COL32(255, 90, 70, 255)};
|
|
drawlist->AddCircleFilled(screen, 4.5f, colour);
|
|
drawlist->AddCircle(screen, 4.5f, IM_COL32(0, 0, 0, 170), 12, 1.5f);
|
|
continue;
|
|
}
|
|
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);
|
|
}
|
|
// 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))
|
|
{
|
|
auto const off{departure(lay.mouse)};
|
|
drawlist->AddCircle(cursor, 6.0f, off < 0.0 ? overlay_color::grip : off <= 0.1 ? IM_COL32(90, 220, 110, 255) : off <= 0.3 ? IM_COL32(255, 200, 60, 255) : IM_COL32(255, 90, 70, 255), 16, 2.0f);
|
|
}
|
|
ImVec2 screen;
|
|
if (lay.mouse_snap.track != nullptr && projection.project(lay.mouse_snap.position, screen))
|
|
drawlist->AddCircle(screen, 14.0f, IM_COL32(255, 60, 255, 255), 20, 3.0f);
|
|
if (lay.start.track != nullptr && projection.project(lay.start.position, screen))
|
|
drawlist->AddCircle(screen, 10.0f, IM_COL32(255, 60, 255, 255), 20, 2.0f);
|
|
if (lay.points.empty() && lay.mouse_snap.track == nullptr)
|
|
draw_cursor_ring(lay.mouse);
|
|
if (false == m_extend.active)
|
|
draw_free_ends(nullptr, kRailCategory, {});
|
|
}
|
|
if (false == m_straights.detour.empty())
|
|
{
|
|
auto const outline{detour_outline()};
|
|
for (std::size_t i = 0; i + 1 < outline.size(); ++i)
|
|
projection.line(drawlist, outline[i], outline[i + 1], overlay_color::marked, 3.0f);
|
|
for (std::size_t i = 0; i < outline.size() && i < m_straights.detour.size(); ++i)
|
|
{
|
|
ImVec2 screen;
|
|
if (projection.project(outline[i], screen))
|
|
drawlist->AddCircleFilled(screen, 6.0f, overlay_color::invalid);
|
|
}
|
|
}
|
|
if ((m_point_drag.moved || (m_track_gizmo_using && m_track_point.valid())) && editor_track::is_end(m_track_point.kind) && m_track_drag_points.empty())
|
|
if (auto const *track{selected_track()}; track != nullptr)
|
|
draw_free_ends(track, track->iCategoryFlag & 15, std::vector<TTrack const *>(m_track_drag.begin(), m_track_drag.end()));
|
|
}
|