From 10f2ac36f96d7e0d9ae6d1a2a0decc8daf789b7a Mon Sep 17 00:00:00 2001 From: maj00r <73280030+maj00r@users.noreply.github.com> Date: Fri, 27 Nov 2026 03:57:25 +0100 Subject: [PATCH] fix(editor): a switch laid gets the speed of its diverging track, one breaking a hard rule of ST-T1-A6 isn't laid (#454) * 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): 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 `: 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). --- application/editormode.h | 26 +- application/editormodeselftest.cpp | 4 + application/editormodeselftestexpect.cpp | 29 +- application/editormodeswitchplace.cpp | 359 +++++++++++++++++++- application/editormodeswitchslide.cpp | 29 +- application/editormodeswitchtemplate.cpp | 7 + application/editormodetrack.cpp | 12 +- editor/editorSwitchCurve.cpp | 104 ++++-- editor/editorSwitchCurve.hpp | 52 ++- tests/editor/README.md | 15 +- tests/editor/cases/q2_1_switch_speed.txt | 30 ++ tests/editor/cases/q2_2_switch_refusals.txt | 42 +++ tests/editor/cases/q2_3_switch_move.txt | 34 ++ tests/editor/scenery/autotest_editor.scn | 66 ++++ tests/unit/test_switch_curve.cpp | 177 +++++++++- 15 files changed, 928 insertions(+), 58 deletions(-) create mode 100644 tests/editor/cases/q2_1_switch_speed.txt create mode 100644 tests/editor/cases/q2_2_switch_refusals.txt create mode 100644 tests/editor/cases/q2_3_switch_move.txt diff --git a/application/editormode.h b/application/editormode.h index de6bdb7d8..16d85a4ae 100644 --- a/application/editormode.h +++ b/application/editormode.h @@ -1972,6 +1972,11 @@ class editor_mode : public application_mode, private editor_track::observer, pri std::string straight_end_note(editor_track::straight const &Line, bool const Far) const; std::optional switch_drag_problem() const; std::optional straight_switch_problem(editor_track::straight const &Line, double const Length, double const Along, int const Direction) const; + // the hard rules of ST-T1-A6 the switch breaks, for the status: not Laid, or kept as it is when moved or given another template + static std::string switch_refusal(std::vector const &Refusals, bool const Laid); + // the switch lying along the straight From to To, the cant of the line under it and near it (11.4 pkt 7, 9.6 pkt 16): what it breaks, + // empty for nothing. Moving: the tracks of the switch moved along the straight, which the line is taken without + std::string straight_switch_refusal(editor_track::straight const &Line, glm::dvec3 const &From, glm::dvec3 const &To, bool const Laid, std::vector const &Moving = {}) const; void flash_switch_problem(switch_problem Problem); void flash_switch_problem(std::string const &Text, std::vector Paths, std::vector> Marks = {}); void draw_switch_problem(switch_problem const &Problem) const; @@ -2002,13 +2007,30 @@ class editor_mode : public application_mode, private editor_track::observer, pri static curve_sample sample_at(std::vector const &Frame, double const Station); // the curve a switch goes into as the norms look at it: its headings and its cant along it std::vector frame_points(std::vector const &Frame) const; + // the line of the chain as the norms look at it, the first path of each track the way the chain runs, and on over the plain tracks + // joined past its ends as far as Beyond: the ends of the cant ramps near a switch; Offset: the station the chain starts at + std::vector line_points(editor_track::chain const &Chain, double const Beyond, double &Offset) const; + // the tracks of the frame as a chain, each run the way the frame goes + static editor_track::chain frame_chain(std::vector const &Frame, std::vector const &Tracks); + // the tracks of the straight along their first paths as a chain, from its start on + static editor_track::chain straight_chain(editor_track::straight const &Line); + // the speed on the diverging track of the switch as it lies, km/h: the basic switch of Radius and 1:Ratio bent as its main track is + // (table 11.8), the cant of its line with its sign, the cant deficiency its frog takes (formula 9.9, table 9.7), no more than the + // basic switch has (table 11.2); Why receives how, for the status + double branch_speed_of(TTrack const &Switch, double const Radius, double const Ratio, std::string *Why = nullptr) const; + // that speed written into the switch for its diverging track, a lower limit of the main track kept for both; returns how, for the + // status + std::string write_switch_speed(TTrack &Switch, double const Radius, double const Ratio, double const Main); + // a switch of the scenery bent into the curve of the Frame along its Tracks, its Paths where it's moved to, as ST-T1-A6 sees it + switch_curve::switch_report bent_switch_report(TTrack const &Switch, std::vector const &Frame, std::vector const &Tracks, std::vector const &Paths) const; // the way the switch being placed into a curve goes along it and the side its diverging track leaves to, from the drag void curved_switch_pose(int &Direction, int &Side) const; // the start of the switch being placed into a curve: where it was pressed, drawn to where the switch meets an end of a cant ramp or // keeps 6 m off it; What receives which double curved_switch_start(int const Direction, std::string *What = nullptr) const; - // the switch made of the paths, laid into the curve at the station, as ST-T1-A6 sees it - switch_curve::switch_report curved_switch_report(std::vector const &Paths, std::vector const &Frame, double const Station, int const Direction) const; + // the switch made of the paths, laid into the curve at the station, as ST-T1-A6 sees it; with the Tracks of the frame its cant is + // looked at on past the ends of the curve too + switch_curve::switch_report curved_switch_report(std::vector const &Paths, std::vector const &Frame, double const Station, int const Direction, std::vector const *Tracks = nullptr) const; static double nearest_station(std::vector const &Frame, glm::dvec3 const &Point); static std::vector curved_switch_paths(editor_track::switch_template const &Shape, std::vector const &Frame, double const Station, int const Direction, int const Side); // the path of a switch template laid into the curve: x of the template across the main track to the Side, z along it from the diff --git a/application/editormodeselftest.cpp b/application/editormodeselftest.cpp index 76173a58c..4fb336b0d 100644 --- a/application/editormodeselftest.cpp +++ b/application/editormodeselftest.cpp @@ -159,6 +159,8 @@ editor_mode::selftest_result editor_mode::selftest_dispatch(std::string const &c // splitkind , nudgekind the first path over an element of the kind split in two, or moved // switchplace