diff --git a/application/editormode.cpp b/application/editormode.cpp index 140bdb705..526723a90 100644 --- a/application/editormode.cpp +++ b/application/editormode.cpp @@ -1877,6 +1877,9 @@ void editor_mode::render_settings() ImGui::SetTooltip("%s", STR_C("A line laid in the straights, or applied by the route design, becomes a line of the model of the track geometry: its tracks are made by the model, " "its edits checked against the norms and refused with the reasons, the project of the map kept next to it.\n" "The tracks there were stay as they are, edited the old way. Off, the editor works as it did")); + // taken when a scenery is opened: changed meanwhile, the model and the scene would go out of step + if (model != model_taken()) + ImGui::TextDisabled("%s", STR_C("Takes effect with the next scenery opened")); if (auto const error{model_error()}; model && false == error.empty()) ImGui::TextColored(ImVec4(1.0f, 0.6f, 0.2f, 1.0f), "%s", format(STR_C("The project of the map can't be opened: %s"), error.c_str()).c_str()); } diff --git a/application/editormode.h b/application/editormode.h index 0d1602d37..3c830d0b9 100644 --- a/application/editormode.h +++ b/application/editormode.h @@ -3371,6 +3371,7 @@ class editor_mode : public application_mode, private editor_track::observer, pri glm::dvec3 offset{0.0}; // of the placement the coordinates of the text are in std::string baseline; // its own export as it was made: another one tells a change by the other tools std::string kind{"track"}; // "switch": a switch track of a turnout, kept by the main track of the turnout (line) + std::size_t of{0}; // the tracks the line was made of with it: fewer of them there, the others were taken away by another tool }; // how a run of commands goes on: the lines the user let write over, what's done after the last one struct model_context @@ -3379,6 +3380,7 @@ class editor_mode : public application_mode, private editor_track::observer, pri std::string surface; // of the tracks made, else the one of the tracks of the line, else the lay tool's std::function const &)> done; // with the tracks the last command made std::vector replaced; // old tracks the line made takes the place of, taken away in its step + bool joined{false}; // the step joined to the one before it: the commands of a batch after the first }; // the project, the managed tracks, the question waiting for an answer, the scenario index (editormodemodel.cpp); made as it's needed friend struct editor_model; @@ -3393,6 +3395,7 @@ class editor_mode : public application_mode, private editor_track::observer, pri void model_plan_drop(); // the setting is on and the project of the map is open bool model_on() const; + bool model_taken() const; // the setting as it was taken when the scenery was opened, for the session // opens the project of the map once the scenery is there, and looks after the questions waiting for the scenario index void model_update(); void model_open(); diff --git a/application/editormodemodel.cpp b/application/editormodemodel.cpp index 9ec2bcd5a..8cc24180f 100644 --- a/application/editormodemodel.cpp +++ b/application/editormodemodel.cpp @@ -103,9 +103,10 @@ std::optional &run_setting() return value; } +// a self-test which sets none edits the old way, whatever the tester ticked in their own editor: the older cases are written for it bool model_setting() { - return run_setting().value_or(EditorSettings.model_editing()); + return run_setting().value_or(selftest_script("EU07_EDITOR_SELFTEST") == nullptr && EditorSettings.model_editing()); } void expectation(bool const Passed, std::string const &What, std::string const &Got, std::string const &Wanted) @@ -293,15 +294,25 @@ void editor_mode::model_plan_drop() bool editor_mode::model_on() const { - return model_setting() && model().session.is_open(); + return model().on && model().session.is_open(); +} + +bool editor_mode::model_taken() const +{ + return model().on; } void editor_mode::model_update() { - if (false == model_setting()) - return; - if (false == model().tried && Global.editor_session && false == scene::Layers.empty()) - model_open(); + if (false == model().tried) + { + if (false == Global.editor_session || scene::Layers.empty()) + return; + model().tried = true; + model().on = model_setting(); + if (model().on) + model_open(); + } if (false == model_on()) return; // the index built is taken, and kept between the sessions @@ -346,10 +357,12 @@ void editor_mode::model_open() model().tracks.clear(); std::map> files; std::map counts; + std::map written; for (auto const &node : model().session.project().generated) { if (node.kind != "track" && node.kind != "switch") continue; + ++written[node.line]; auto *track{simulation::Paths.find(node.name)}; if (track == nullptr || track->m_editorremoved) continue; @@ -371,6 +384,9 @@ void editor_mode::model_open() entry.baseline = export_of(*track); model().tracks[track] = std::move(entry); } + // a track the files had and the scene hasn't is one of the line taken away, as one the user takes away later + for (auto &[node, entry] : model().tracks) + entry.of = written[entry.line]; scene::Layers.path_writer = [this](TTrack const &Track, glm::dvec3 const &Offset) { return model_path_text(Track, Offset); }; // the scenario index of the map built in the background, kept between the sessions (not for the self-tests, which leave nothing behind) auto &store{model().store}; @@ -414,12 +430,32 @@ std::vector editor_mode::model_line_tracks(layout::line_id const Line) std::set editor_mode::model_seen_changed() const { std::set result; + // a line short of tracks: some of the ones the model made taken away by another tool, a switch put in say. The model's own steps, + // their undos and redos with them, take a line's tracks away and bring them back all together + struct line_count + { + std::size_t there{0}; // the tracks of the line in the scene + std::size_t made{0}; // of how many the model made of it with them + bool known{false}; // tracks of it were made, all of them gone now where none is there + }; + std::map counts; for (auto const &[node, entry] : model().tracks) { auto const *track{dynamic_cast(node)}; - if (track != nullptr && false == track->m_editorremoved && false == result.contains(entry.line) && export_of(*track) != entry.baseline) + if (track == nullptr) + continue; + auto &line{counts[entry.line]}; + line.known = line.known || entry.of > 0; + if (track->m_editorremoved) + continue; + ++line.there; + line.made = std::max(line.made, entry.of); + if (false == result.contains(entry.line) && export_of(*track) != entry.baseline) result.insert(entry.line); } + for (auto const &[id, line] : counts) + if ((line.there < line.made || (line.there == 0 && line.known)) && model().session.network().find(id) != nullptr) + result.insert(id); return result; } @@ -518,10 +554,20 @@ void editor_mode::model_run(std::vector Commands, model_context return; } created = model_tracks_after(applied.token, before, applied.changed, applied.removed, Context); + // the commands of one batch after the first joined to it: one Ctrl+Z takes back all of it, none leaves the line half edited + Context.joined = true; std::string what{format(STR_C("%s: done"), STR_C(layout::command_name(command)))}; if (false == applied.changed.empty()) what = format(STR_P("%s: line %s, %zu track", "%s: line %s, %zu tracks", static_cast(created.size())), STR_C(layout::command_name(command)), line_name(*applied.changed.begin()).c_str(), created.size()); model_told(applied.outcome, false, what); + // what the generator couldn't make as the line has it, told with the outcome: the tracks are laid, a piece a few millimetres + // off the line say, so it isn't refused + for (auto const &error : model().made_errors) + if (std::ranges::find(model().notices, error) == model().notices.end()) + { + model().notices.push_back(error); + model().shown_notices.push_back(error); + } Commands.erase(Commands.begin()); } if (Context.done) @@ -556,6 +602,7 @@ std::vector editor_mode::model_tracks_after(std::uint64_t const Token, turnouts.insert(id); std::vector removed; auto surface{Context.surface}; + model().made_errors.clear(); for (auto const line : going) for (auto *track : model_line_tracks(line)) { @@ -602,7 +649,10 @@ std::vector editor_mode::model_tracks_after(std::uint64_t const Token, { auto const made{model().session.generate(line)}; for (auto const &error : made.errors) + { WriteLog("Editor: model: the tracks of line " + line_name(line) + ": " + error, logtype::generic); + model().made_errors.push_back(error); + } for (auto const &piece : made.pieces) put(line, piece.text, piece.name, "track"); } @@ -613,7 +663,10 @@ std::vector editor_mode::model_tracks_after(std::uint64_t const Token, continue; auto const made{model().session.generate(id)}; for (auto const &error : made.errors) + { WriteLog(format("Editor: model: the tracks of turnout %u: %s", layout::number(id), error.c_str()), logtype::generic); + model().made_errors.push_back(error); + } if (made.parts.empty()) put(turnout->main, made.text, made.name, "switch"); for (auto const &part : made.parts) @@ -630,6 +683,8 @@ std::vector editor_mode::model_tracks_after(std::uint64_t const Token, editor_track::commit(created); for (auto &[track, entry] : entries) { + // the tracks the line was made of, its turnouts' switch tracks among them + entry.of = indices[entry.line]; entry.baseline = export_of(*track); model().tracks[track] = std::move(entry); } @@ -646,6 +701,8 @@ std::vector editor_mode::model_tracks_after(std::uint64_t const Token, g_redo.clear(); } m_history.back().model_token = Token; + if (Context.joined) + m_history.back().joined = true; if (std::ranges::any_of(removed, [&](TTrack const *Track) { return Track == m_node; })) { m_node = created.empty() ? nullptr : created.back(); @@ -1361,8 +1418,13 @@ editor_mode::selftest_result editor_mode::selftest_model(std::string const &comm words >> on; // for this run, not kept in the settings of the editor run_setting() = on != 0; - if (on != 0 && false == model().tried && false == scene::Layers.empty()) - model_open(); + model().on = on != 0; + if (on != 0 && false == scene::Layers.empty()) + { + model().tried = true; + if (false == model().session.is_open()) + model_open(); + } WriteLog(format("SELFTEST modelediting %d: the project %s, %zu lines", on, model().session.is_open() ? "open" : "not open", model().session.network().lines().size())); return selftest_result::handled; } diff --git a/application/editormodemodel.h b/application/editormodemodel.h index 460f5d533..bf86a8099 100644 --- a/application/editormodemodel.h +++ b/application/editormodemodel.h @@ -50,7 +50,11 @@ struct model_question struct editor_model { project::session session; - bool tried{false}; // the project opened for the scenery, or failed to + bool tried{false}; // the setting taken for the scenery opened, the project opened if it's on, or failed to + // the setting as it was when the scenery was opened, kept for the session: turned on later, an edit made the old way before was + // written back as the file had it; turned off before a save, the scenery was saved without its project. A change of it takes + // effect with the next scenery opened + bool on{false}; std::string error; std::unordered_map tracks; project::index_cache index; @@ -75,6 +79,7 @@ struct editor_model glm::dvec3 offset{0.0}; }; std::vector written; + std::vector made_errors; // of the generator, by the tracks of the last command std::map marks; // the self-test's copies of the network, for expect modelsame std::string shown; // the message as the user reads it, in the language of the editor std::vector shown_notices; // the notices so diff --git a/application/editormodeselftest.cpp b/application/editormodeselftest.cpp index 8c295d8cf..ef152d15f 100644 --- a/application/editormodeselftest.cpp +++ b/application/editormodeselftest.cpp @@ -138,6 +138,8 @@ editor_mode::selftest_result editor_mode::selftest_dispatch(std::string const &c // angles at the joints, loops, the turning wasted and the sharpest curve logged; case: that one alone // layspeed the speed set for the laying, and whether it goes also on from a track with its own // laymode , laytrace as the panel of the laying sets them +// laysettings <0|1> the settings of the lay tool opened under the line of their summary, or folded into it, as a +// click on that line does while the points are clicked // endcurves logs every free end of the rails: where, the way out and the curvature its track goes on with // curvejoint logs the paths meeting at the end nearest the point, the curvature of each and its jump from the ones before to the ones after // cantcheck