18
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-12-02 15:26:53 +01:00

fix(editor): the hand of a turnout commented as the code has it, an Apply with no edit adds no step, a profile opened drops the error of the one before, tests of the side

- The comments of layoutCommands.hpp and layoutNetwork.hpp give hand 1 as right and -1 as left, as the migration and the inspector
  have it since #464 (R of a switch record).
- The grade line of a line of the model applied with no edit: the breaks compared within a micrometre, the chainages having gone to
  the route and back; compared exactly, it added a step.
- profile_open() clears the error of the route opened before.
- Self-test expectations: modelpreview current (the preview worked out for the design as it is now, m_11), modelspacing signed by
  the side (m_13 to the right, -4.5 m), modelside of a switch (m_8 right, then left after the side is changed).
This commit is contained in:
maj00r
2026-11-29 23:01:16 +01:00
parent e4b90ce744
commit c383583afb
10 changed files with 68 additions and 16 deletions
+1
View File
@@ -3493,6 +3493,7 @@ class editor_mode : public application_mode, private editor_track::observer, pri
bool model_plan_commands(layout::line_id const Line, std::vector<layout::command> &Commands, std::string &Why) const;
// a handle of the route design dragged on a line of the model: tried as it goes, drawn by the line and the mouse
void model_plan_preview();
std::string model_plan_key() const; // the design of the route as the preview of the model was worked out for it
void draw_model_plan_preview() const;
bool m_model_delete_confirmed{false}; // the old delete let through, the scenarios looked through
selftest_result selftest_dispatch(std::string const &command, std::istringstream &words);
+38 -5
View File
@@ -1773,18 +1773,48 @@ editor_mode::selftest_result editor_mode::selftest_model(std::string const &comm
}
if (what == "modelspacing")
{
// how far the other line runs from the point of the line at the chainage, within the bounds
unsigned line{0}, other{0};
double chainage{0.0}, low{0.0}, high{0.0};
// how far the other line runs from the point of the line at the chainage, within the bounds: above 0 to the left of the line as it
// runs (left_of, as the offset of the parallel tool), below 0 to its right, so a line laid on the other side fails it
unsigned line{0};
unsigned other{0};
double chainage{0.0};
double low{0.0};
double high{0.0};
words >> line >> other >> chainage >> low >> high;
auto const *one{model_network().find(static_cast<layout::line_id>(line))};
auto const *two{model_network().find(static_cast<layout::line_id>(other))};
auto got{std::numeric_limits<double>::quiet_NaN()};
if (one != nullptr && two != nullptr && one->solved.valid() && two->solved.valid())
layout::chainage_of(two->solved, one->solved.position(std::clamp(chainage, 0.0, one->solved.length)), &got);
{
auto const at{std::clamp(chainage, 0.0, one->solved.length)};
auto const point{one->solved.position(at)};
auto const across{two->solved.position(layout::chainage_of(two->solved, point, &got))};
if (glm::dot(across - point, layout::left_of(glm::normalize(one->solved.tangent(at)))) < 0.0)
got = -got;
}
expectation(got >= low && got <= high, format("modelspacing %u %u %.1f", line, other, chainage), format("%.4f", got), format("%.4f .. %.4f", low, high));
return selftest_result::handled;
}
if (what == "modelside")
{
// the side the diverging track of the switch leaves its main track to, as the switch runs from its start: right where the
// cross product of the two in the plan is above 0, as a switch record has R (switch_store::classify), left below it
std::string name;
std::string wanted;
words >> name >> wanted;
auto const *track{simulation::Paths.find(name)};
std::string got{"none"};
if (track != nullptr && false == track->m_editorremoved && track->eType == tt_Switch && track->m_paths.size() >= 2)
{
auto const &main{track->m_paths[0].points};
auto const &diverging{track->m_paths[1].points};
auto const along{glm::dvec2{main[segment_data::point::end].x - main[segment_data::point::start].x, main[segment_data::point::end].z - main[segment_data::point::start].z}};
auto const off{glm::dvec2{diverging[segment_data::point::end].x - main[segment_data::point::start].x, diverging[segment_data::point::end].z - main[segment_data::point::start].z}};
got = along.x * off.y - along.y * off.x > 0.0 ? "right" : "left";
}
expectation(got == wanted, "modelside " + name, got, wanted);
return selftest_result::handled;
}
if (what == "modelnodes")
{
// the nodes of the model: a line laid on from the free end of another one shares the node there
@@ -1841,7 +1871,10 @@ editor_mode::selftest_result editor_mode::selftest_model(std::string const &comm
std::string wanted;
words >> wanted;
auto const &preview{model().preview};
auto const got{preview.key.empty() ? std::string{"none"} : std::string{"shown"}};
auto got{preview.key.empty() ? std::string{"none"} : std::string{"shown"}};
// current: worked out for the design as it is now, not left as the first frame of the drag showed it
if (wanted == "current" && false == preview.key.empty())
got = preview.key == model_plan_key() ? "current" : "stale";
expectation(got == wanted, "modelpreview " + wanted, got + (preview.key.empty() ? "" : (preview.refused ? " refused: " : ": ") + editor_selftest::one_line(preview.text)), wanted);
return selftest_result::handled;
}
+16 -4
View File
@@ -145,7 +145,13 @@ bool editor_mode::model_profile_apply()
state.error = model_shown();
return true;
}
if (command.grades == line->shape.grades)
// the same breaks, within what taking the chainages to the route and back changes of them: compared exactly, an Apply with no edit
// added a step
auto const unchanged{std::ranges::equal(command.grades, line->shape.grades, [](auto const &A, auto const &B) {
double constexpr kNear{1e-6};
return std::abs(A.chainage - B.chainage) < kNear && std::abs(A.elevation - B.elevation) < kNear && std::abs(A.vertical_radius - B.vertical_radius) < kNear * std::max(1.0, B.vertical_radius);
})};
if (unchanged)
{
state.status = STR_C("Nothing changed");
return true;
@@ -252,6 +258,14 @@ void editor_mode::model_plan_reload(layout::line_id const Line)
// a handle of the route design dragged on a line of the model: the line as the model lays it and the norms' line, before it's let go
std::string editor_mode::model_plan_key() const
{
std::string key;
for (auto const &vertex : m_route.design.vertices)
key += format("%.4f %.4f %.4f %.3f %.3f %.3f %.1f;", vertex.position.x, vertex.position.y, vertex.offset, vertex.radius, vertex.transition_in, vertex.transition_out, vertex.cant);
return key;
}
void editor_mode::model_plan_preview()
{
auto &preview{model().preview};
@@ -263,9 +277,7 @@ void editor_mode::model_plan_preview()
}
// the first and the last vertex of two or more are dragged along the tangents of the ends by their offsets, which their positions
// don't follow (model_plan_commands places them so): without the offset the preview stayed as its first frame showed it
std::string key;
for (auto const &vertex : m_route.design.vertices)
key += format("%.4f %.4f %.4f %.3f %.3f %.3f %.1f;", vertex.position.x, vertex.position.y, vertex.offset, vertex.radius, vertex.transition_in, vertex.transition_out, vertex.cant);
auto const key{model_plan_key()};
if (key == preview.key)
return;
preview = {};
+2
View File
@@ -776,6 +776,8 @@ void editor_mode::profile_open(TTrack *From, TTrack *To)
auto &state{m_profile};
state.open = true;
state.status.clear();
// what was wrong with the route opened before isn't of this one
state.error.clear();
editor_track::route route;
if (false == editor_track::find_route(From, To, route, state.error))
return;
+1 -1
View File
@@ -127,7 +127,7 @@ struct set_line_profile
};
// a turnout of the type of the catalogue laid into the line, its start at the chainage: the line cut at its legs, the part between them its
// main track, its diverging track leaving it to the hand (1 left, -1 right) as it runs from its start, along the line (direction 1) or
// main track, its diverging track leaving it to the hand (1 right, -1 left) as it runs from its start, along the line (direction 1) or
// against it (-1); bent as the line under it is. Refused with the reasons where a rule of the turnouts or a BLOCK limit of the norms is broken
struct insert_turnout
{
+1 -1
View File
@@ -113,7 +113,7 @@ struct turnout
{
turnout_id id{turnout_id::none};
std::string type; // of the catalogue, "Rz 60E1-500-1:12"
int hand{1}; // the side the diverging track leaves to as the turnout runs from its start: 1 left, -1 right
int hand{1}; // the side the diverging track leaves to as the turnout runs from its start: 1 right, -1 left (the R of a switch record)
int direction{1}; // 1: its main track runs as the line it was laid into does, from the start of the turnout; -1 against it
node_id start{node_id::none};
node_id main_end{node_id::none};
+3 -2
View File
@@ -119,8 +119,9 @@ tool's `parallel <spacing> <side>` lay turnouts, crossovers and lines of the mod
| `expect modelproposal <holds\|lacks> <text>` | the solver's best proposal for the crossover refused last |
| `expect modelgrades <line> <count>`, `expect modelvertices <line> <count>` | the breaks of the grade line / the vertices of a line of the model |
| `expect modelvertexat <line> <index> <x> <z> <tolerance>` | where the vertex of a line of the model is in the plan |
| `expect modelpreview <shown\|none>` | a handle of the route design dragged on a line of the model: the line as the model would lay it is tried and told |
| `expect modelspacing <line> <other> <m> <low> <high>` | how far the other line runs from the point of the line at the chainage |
| `expect modelpreview <shown\|none\|current>` | a handle of the route design dragged on a line of the model: the line as the model would lay it is tried and told; current: tried for the design as it is now |
| `expect modelspacing <line> <other> <m> <low> <high>` | how far the other line runs from the point of the line at the chainage: above 0 to its left as it runs, below 0 to its right |
| `expect modelside <switch> <left\|right>` | the side the diverging track of the switch leaves to as the switch runs from its start |
Files `scenery/autotest_editor.<part>.scn` are copied next to the copy of the fixture as `autotest_editor_<case>_<part>.scn`, the name of
the fixture in them made the name of its copy: scenarios of its map, for the scenario index (`autotest_editor.uses.scn`, a trainset on `s1`).
+1
View File
@@ -20,6 +20,7 @@ wait 2
glide 800 0 180 8 2
wait 2
expect modelpreview shown
expect modelpreview current
button left release
wait 5
expect modelrefused 0
+3 -3
View File
@@ -17,9 +17,9 @@ expect modellines 2
expect managed @2.0 2
expect modelends
expect steps 2
# 4.5 m on the straight and in the arc, concentric (no widening of the gauge in a curve of R 250 m or more)
expect modelspacing 1 2 10 4.4999 4.5001
expect modelspacing 1 2 400 4.498 4.502
# 4.5 m to its right on the straight and in the arc, concentric (no widening of the gauge in a curve of R 250 m or more)
expect modelspacing 1 2 10 -4.5001 -4.4999
expect modelspacing 1 2 400 -4.502 -4.498
undo
wait 2
expect modellines 1
+2
View File
@@ -18,6 +18,7 @@ expect steps 2
expect managed t1 any
expect switchpanel placed
expect modelends
expect modelside t1 right
undo
wait 2
expect modellines 1
@@ -45,6 +46,7 @@ wait 2
expect modelrefused 0
expect steps 5
expect modelends
expect modelside t1 left
modeltracks
# taken out by Del, once the scenarios of the map are looked through (none names it): the line one line again
modeldel t1