diff --git a/application/editormode.h b/application/editormode.h index 0cb28532a..2515df723 100644 --- a/application/editormode.h +++ b/application/editormode.h @@ -326,6 +326,8 @@ class editor_mode : public application_mode, private editor_track::observer, pri bool m_setup_read{false}; // read for the scenery open bool m_setup_changed{false}; // to be written with the scenery bool m_setup_marked{false}; // the scenery holds //$u lines + bool m_setup_moving{false}; // the assumptions given to the project of the model, which isn't saved yet + bool m_setup_unsaved{false}; // the project of the model failed to be saved with them: the scenery keeps them till it is bool m_setup_window{false}; std::string m_setup_told; // what the change of them found among the lines laid before bool m_setup_checking{false}; // the lines of the scenery being checked against the assumptions changed @@ -339,6 +341,9 @@ class editor_mode : public application_mode, private editor_track::observer, pri // the norms checked against, the rail and the usual switch of the switch tool void setup_defaults(project_setup::setup const &Setup); void setup_store(); + void setup_keep_in_scenery(); + // the project of the model saved, or not, after the scenery: where the assumptions are kept + void setup_project_saved(bool const Saved); bool render_setup_card(); void render_setup_window(); void render_setup_line(); diff --git a/application/editormodemodel.cpp b/application/editormodemodel.cpp index b5158699b..8916f05a3 100644 --- a/application/editormodemodel.cpp +++ b/application/editormodemodel.cpp @@ -708,6 +708,7 @@ void editor_mode::model_saved(bool const Success) if (false == Success) { model().written.clear(); + setup_project_saved(false); return; } // the tracks written, by their lines, each with the file it went into @@ -733,8 +734,10 @@ void editor_mode::model_saved(bool const Success) { ui()->set_status(format(STR_C("The project of the map isn't saved: %s"), error.c_str()), true); WriteLog("Editor: the project of the map isn't saved: " + error, logtype::generic); + setup_project_saved(false); return; } + setup_project_saved(true); WriteLog(format("Editor: the project of the map saved, %zu lines, %zu tracks of them written now", model().session.network().lines().size(), [&] { std::size_t count{0}; for (auto const &entry : lines) diff --git a/application/editormodesetup.cpp b/application/editormodesetup.cpp index 63aae84e1..a3f4997cc 100644 --- a/application/editormodesetup.cpp +++ b/application/editormodesetup.cpp @@ -154,15 +154,15 @@ void editor_mode::setup_store() scene::Layers.mark(scene::layer_handle{1}, "//$u", {}); m_setup_marked = false; }; - auto const kept_in_scenery = [this, &line]() { - scene::Layers.mark(scene::layer_handle{1}, "//$u", {"# the assumptions of the project: what the editor lays the tracks to", line}); - m_setup_marked = true; - }; if (model_setup()) { - // the project of the model is written after the scenery, and may fail to be: the scenery keeps the line as well, the project's - // one read first. Taken out of it, the assumptions were gone with a project not saved - kept_in_scenery(); + // the project of the model is written after the scenery, and may fail to be: model_saved() puts them back into the scenery then, + // and they stay there till the project is saved + m_setup_moving = true; + if (m_setup_unsaved) + setup_keep_in_scenery(); + else + moved_out(); return; } std::error_code error; @@ -182,7 +182,29 @@ void editor_mode::setup_store() WriteLog("Editor: the assumptions of the project not written into its file: " + why, logtype::generic); } } - kept_in_scenery(); + setup_keep_in_scenery(); +} + +void editor_mode::setup_keep_in_scenery() +{ + if (false == m_setup.has_value()) + return; + scene::Layers.mark(scene::layer_handle{1}, "//$u", {"# the assumptions of the project: what the editor lays the tracks to", project_setup::record(*m_setup)}); + m_setup_marked = true; +} + +void editor_mode::setup_project_saved(bool const Saved) +{ + if (false == m_setup_moving) + return; + m_setup_moving = false; + m_setup_unsaved = false == Saved; + // not saved: the assumptions go back into the scenery, written with its next save, rather than be in neither of them; saved while the + // scenery holds them still: taken out of it with the next save + if (false == Saved) + setup_keep_in_scenery(); + if (false == Saved || m_setup_marked) + m_setup_changed = true; } bool editor_mode::render_setup_card()