diff --git a/application/editormode.cpp b/application/editormode.cpp index f1619393d..7dfdefb25 100644 --- a/application/editormode.cpp +++ b/application/editormode.cpp @@ -1128,6 +1128,8 @@ void editor_mode::undo_one() } const restoring{m_nmt_state.restoring}; EditorSnapshot snap = m_history.back(); m_history.pop_back(); + // a command of the model: the model takes it back, the step the tracks it made + model_history(snap.model_token, true); if (snap.action == EditorSnapshot::Action::Terrain) { @@ -1304,6 +1306,7 @@ void editor_mode::redo_one() } const restoring{m_nmt_state.restoring}; EditorSnapshot snap = g_redo.back(); g_redo.pop_back(); + model_history(snap.model_token, false); if (snap.action == EditorSnapshot::Action::Terrain) { diff --git a/application/editormode.h b/application/editormode.h index d93193ecf..ffb51717f 100644 --- a/application/editormode.h +++ b/application/editormode.h @@ -186,6 +186,7 @@ class editor_mode : public application_mode, private editor_track::observer, pri std::optional kilometrage; // the kilometrage before the change (Action::Kilometrage) std::vector copies; // models an array added to the one it was made of bool joined{false}; // undone and redone together with the change before it + std::uint64_t model_token{0}; // a command of the model of the track geometry this step is, taken back and brought again with it std::shared_ptr terrain; // the heightmap terrain from before the change (Action::Terrain) std::uint64_t serial{next_serial()}; // of each step made, for the revision of the history static std::uint64_t next_serial() @@ -3347,9 +3348,9 @@ class editor_mode : public application_mode, private editor_track::observer, pri selftest_result selftest_model(std::string const &command, std::istringstream &words); // the track geometry edited through the model (editor-tracks-domain.md §3, §4, §8, §9; stage E4, editormodemodel.cpp), with the - // setting "Editing on the model (trial)" on: the project of the map opened with the scenery and written with it, the tracks the - // generator wrote marked as the tracks of their lines and written as it made them while nothing else changes them. Off, nothing of it - // runs + // setting "Editing on the model (trial)" on: the project of the map opened with the scenery and written with it, a line laid by the + // lay tool or the route design applied to old tracks a line of the model, its tracks made by the generator and marked as its, one step of + // the history. The old tracks stay as they are, edited by the old tools. Off, nothing of it runs struct managed_track { layout::line_id line{layout::line_id::none}; @@ -3358,10 +3359,22 @@ 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 }; + // how a run of commands goes on: the lines the user let write over, what's done after the last one + struct model_context + { + std::set overwrite; + 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 + }; // the project, the managed tracks (editormodemodel.cpp); made as it's needed friend struct editor_model; mutable std::unique_ptr m_model; editor_model &model() const; + // what the last command came to: refused, why; kept, what it did and what the norms tell of it + bool model_refused() const; + std::string model_message() const; + std::vector model_notices() const; std::string model_error() const; void model_forget(scene::basic_node const *Node); // the setting is on and the project of the map is open @@ -3371,11 +3384,27 @@ class editor_mode : public application_mode, private editor_track::observer, pri void model_open(); // the managed track, nullptr for an old one managed_track const *model_track(TTrack const *Track) const; + // the tracks of the line in the scene, from its start + std::vector model_line_tracks(layout::line_id const Line) const; // the lines whose tracks were changed by the other tools since they were made std::set model_seen_changed() const; + // the commands carried out one after another, each one step of the history: a refusal ends the run with its reasons + void model_run(std::vector Commands, model_context Context); + // the tracks of the lines the command changed made again, those of the lines gone taken away: one step of the history with its token + std::vector model_tracks_after(std::uint64_t const Token, std::set const &Changed, std::set const &Removed, model_context const &Context); + void model_told(layout::outcome const &Outcome, bool const Refused, std::string const &What = {}); + // the editor's step of a command taken back or brought again + void model_history(std::uint64_t const Token, bool const Undo); // the save: the text of a managed track as made, the project written after the scenery std::optional model_path_text(TTrack const &Track, glm::dvec3 const &Offset); void model_saved(bool const Success); + // the line the lay tool shows laid as a line of the model; false where it isn't one (not the straights, a curve the model doesn't lay + // yet), with why in Why, for the old way + bool model_lay(lay_line_plan const &Plan, editor_track::snap_target const &End, std::vector &Created, std::string &Why); + // the route design applied to old tracks made a line of the model in their place, where the model lays it; false where it doesn't, + // with why in Why, for the old way + bool model_plan_convert(std::string &Why); + std::string model_label(TTrack const *Track) const; selftest_result selftest_dispatch(std::string const &command, std::istringstream &words); void selftest_step(); // a value typed during a gesture, taken instead of the one the cursor gives diff --git a/application/editormodelay.cpp b/application/editormodelay.cpp index 83f8896c6..3d267ff7e 100644 --- a/application/editormodelay.cpp +++ b/application/editormodelay.cpp @@ -2070,6 +2070,41 @@ void editor_mode::lay_finish(editor_track::snap_target const &End) } return; } + // with the editing on the model, a line of the model: refused with the reasons, the points kept to be put right, or laid, its tracks + // made by the model and marked as its. What it doesn't lay yet is laid the old way, told why + std::string oldway; + if (std::vector made; model_lay(plan, End, made, oldway)) + { + if (model_refused() || made.empty()) + { + tool.laid_now = false; + tool.status = model_message(); + if (End.track != nullptr && false == tool.points.empty()) + { + tool.points.pop_back(); + lay_trim(); + } + WriteLog("Editor: " + tool.status, logtype::generic); + return; + } + first_step_done(first_step::laid); + if (End.track != nullptr) + first_step_done(first_step::join); + lay_told(length, made.size()); + tool.status += "\n" + model_message(); + for (auto const ¬ice : model_notices()) + tool.status += "\n" + notice; + m_node = made.back(); + ui()->set_node(m_node); + tool.laid = {made, length, {}}; + WriteLog("Editor: " + tool.status, logtype::generic); + tool.points.clear(); + tool.modes.clear(); + tool.start = {}; + tool.laid_step = m_history.size(); + straight_refresh(); + return; + } auto const *style{tool.start.track != nullptr ? tool.start.track : End.track}; if (style == nullptr && tool.copy_selected) style = selected_track(); @@ -2126,6 +2161,8 @@ void editor_mode::lay_finish(editor_track::snap_target const &End) } if (scene::Layers.active() == null_handle && style == nullptr) tool.status += "\n" + STR("The scenery isn't opened for editing: new track won't be saved"); + if (false == oldway.empty()) + tool.status += "\n" + oldway; m_node = created.back(); ui()->set_node(m_node); // what was laid, told in the inspector as long as the last track stays selected diff --git a/application/editormodemodel.cpp b/application/editormodemodel.cpp index af79b22ac..62e9aeed3 100644 --- a/application/editormodemodel.cpp +++ b/application/editormodemodel.cpp @@ -36,6 +36,7 @@ http://mozilla.org/MPL/2.0/. #include "imgui/imgui.h" #include +#include #include #include #include @@ -60,8 +61,37 @@ std::string export_of(TTrack const &Track) return text; } +std::vector words_of(std::string const &Text) +{ + std::istringstream stream{Text}; + std::vector result; + for (std::string word; stream >> word;) + result.push_back(std::move(word)); + return result; +} + // what the entry of the track has between its length and its path: the width, the friction, the sound distance, the quality, the damage, // the environment and the visibility with the materials; empty where it isn't a plain track +std::string surface_of(TTrack const &Track) +{ + auto const words{words_of(export_of(Track))}; + // node track normal ... [ ] + if (words.size() < 14 || words[4] != "track" || words[5] != "normal") + return {}; + auto const count{words[13] == "vis" ? std::size_t{13} : std::size_t{7}}; + if (words.size() < 7 + count) + return {}; + std::string result; + for (std::size_t i = 7; i < 7 + count; ++i) + result += (result.empty() ? "" : " ") + words[i]; + return result; +} + +bool bits_equal(glm::dvec3 const &A, glm::dvec3 const &B) +{ + return std::bit_cast(A.x) == std::bit_cast(B.x) && std::bit_cast(A.y) == std::bit_cast(B.y) && std::bit_cast(A.z) == std::bit_cast(B.z); +} + // the setting as a self-test sets it for its run, not kept in the settings of the editor; else the one of the settings std::optional &run_setting() { @@ -94,6 +124,9 @@ struct editor_model bool tried{false}; // the project opened for the scenery, or failed to std::string error; std::unordered_map tracks; + std::string message; // what the last command came to: why it was refused, or what the norms tell of it + bool refused{false}; + std::vector notices; std::vector> written; // by the save under way, the texts written }; @@ -109,6 +142,21 @@ editor_model &editor_mode::model() const return *m_model; } +bool editor_mode::model_refused() const +{ + return model().refused; +} + +std::string editor_mode::model_message() const +{ + return model().message; +} + +std::vector editor_mode::model_notices() const +{ + return model().notices; +} + std::string editor_mode::model_error() const { return model().error; @@ -194,6 +242,22 @@ editor_mode::managed_track const *editor_mode::model_track(TTrack const *Track) return &found->second; } +std::vector editor_mode::model_line_tracks(layout::line_id const Line) const +{ + std::vector> found; + for (auto const &[node, entry] : model().tracks) + { + auto *track{const_cast(dynamic_cast(node))}; + if (entry.line == Line && track != nullptr && false == track->m_editorremoved) + found.emplace_back(entry.index, track); + } + std::ranges::sort(found, [](auto const &A, auto const &B) { return A.first < B.first; }); + std::vector result; + for (auto const &entry : found) + result.push_back(entry.second); + return result; +} + std::set editor_mode::model_seen_changed() const { std::set result; @@ -206,6 +270,159 @@ std::set editor_mode::model_seen_changed() const return result; } +std::string editor_mode::model_label(TTrack const *Track) const +{ + auto const *managed{model_track(Track)}; + if (managed == nullptr) + return {}; + return format(STR_C("Line %s (managed)"), line_name(managed->line).c_str()); +} + +void editor_mode::model_told(layout::outcome const &Outcome, bool const Refused, std::string const &What) +{ + model().refused = Refused; + model().notices.clear(); + if (Refused) + { + model().message = STR("Refused, nothing changed:"); + for (auto const &reason : Outcome.reasons) + model().message += "\n" + reason; + WriteLog("Editor: model: " + editor_selftest::one_line(model().message), logtype::generic); + return; + } + model().message = What; + for (auto const ¬ice : Outcome.notices) + if (std::ranges::find(model().notices, notice.text) == model().notices.end()) + model().notices.push_back(notice.text); + WriteLog("Editor: model: " + What + (model().notices.empty() ? std::string{} : " · " + std::to_string(model().notices.size()) + " notices of the norms"), logtype::generic); +} + +void editor_mode::model_run(std::vector Commands, model_context Context) +{ + std::vector created; + auto &session{model().session}; + while (false == Commands.empty()) + { + auto const &command{Commands.front()}; + auto const effect{session.trial(command)}; + if (false == effect.outcome.done) + { + model_told(effect.outcome, true); + return; + } + std::set overwrite; + for (auto const *lines : {&effect.changed, &effect.removed}) + for (auto const line : *lines) + if (Context.overwrite.contains(line)) + overwrite.insert(line); + auto const applied{session.execute(command, overwrite)}; + if (false == applied.outcome.done) + { + model_told(applied.outcome, true); + return; + } + created = model_tracks_after(applied.token, applied.changed, applied.removed, Context); + 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); + Commands.erase(Commands.begin()); + } + if (Context.done) + Context.done(created); +} + +std::vector editor_mode::model_tracks_after(std::uint64_t const Token, std::set const &Changed, std::set const &Removed, model_context const &Context) +{ + std::vector removed; + auto surface{Context.surface}; + for (auto const *lines : {&Changed, &Removed}) + for (auto const line : *lines) + for (auto *track : model_line_tracks(line)) + { + if (surface.empty()) + surface = surface_of(*track); + removed.push_back(track); + } + // the old tracks the line takes the place of + for (auto *track : Context.replaced) + if (false == track->m_editorremoved && std::ranges::find(removed, track) == removed.end()) + removed.push_back(track); + // the old tracks go first: the new ones take their names + for (auto *track : removed) + editor_track::retire(*track); + if (surface.empty()) + surface = "1.435 0.15 25 20 0 flat vis " + m_lay.style.rail + " 6 " + m_lay.style.ballast + " 0.2 0.5 1.1"; + model().session.options().surface = surface; + std::vector created; + std::vector> entries; + for (auto const line : Changed) + { + 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); + std::size_t index{0}; + for (auto const &piece : made.pieces) + { + auto const at{piece.text.find(" track ")}; + if (at == std::string::npos) + continue; + auto *track{editor_track::load_entry(piece.text.substr(at + 7), piece.name)}; + if (track == nullptr) + continue; + managed_track entry; + entry.line = line; + entry.index = index++; + entry.text = piece.text; + if (track->name() != piece.name) + { + // another track has the name: the entry written under the one it got + WriteLog("Editor: model: the name " + piece.name + " is taken, the track is " + track->name(), logtype::generic); + entry.text = "node -1 0 " + track->name() + piece.text.substr(at); + } + created.push_back(track); + entries.emplace_back(track, std::move(entry)); + } + } + editor_track::commit(created); + for (auto &[track, entry] : entries) + { + entry.baseline = export_of(*track); + model().tracks[track] = std::move(entry); + } + auto const steps{m_history.size()}; + auto const serial{m_history.empty() ? std::uint64_t{0} : m_history.back().serial}; + push_track_snapshot({}, created, removed); + if (m_history.size() == steps && (m_history.empty() || m_history.back().serial == serial)) + { + // nothing of the scene changed: the step is the model's alone + trim_history(); + EditorSnapshot step; + step.action = EditorSnapshot::Action::Other; + m_history.push_back(std::move(step)); + g_redo.clear(); + } + m_history.back().model_token = Token; + if (std::ranges::any_of(removed, [&](TTrack const *Track) { return Track == m_node; })) + { + m_node = created.empty() ? nullptr : created.back(); + ui()->set_node(m_node); + } + return created; +} + +void editor_mode::model_history(std::uint64_t const Token, bool const Undo) +{ + if (Token == 0 || false == model().session.is_open()) + return; + auto const done{Undo ? model().session.undo(Token) : model().session.redo(Token)}; + if (false == done) + WriteLog(format("Editor: model: the step %llu can't be %s: the history of the model went out of step with the editor's", static_cast(Token), Undo ? "taken back" : "brought again"), logtype::generic); + model().message.clear(); + model().notices.clear(); + model().refused = false; +} + std::optional editor_mode::model_path_text(TTrack const &Track, glm::dvec3 const &Offset) { if (false == model_on() || Track.m_editorremoved) @@ -268,8 +485,145 @@ void editor_mode::model_saved(bool const Success) }()), logtype::generic); } +bool editor_mode::model_lay(lay_line_plan const &Plan, editor_track::snap_target const &End, std::vector &Created, std::string &Why) +{ + if (false == model_on()) + return false; + auto const &tool{m_lay}; + if (std::ranges::any_of(tool.modes, [](lay_mode const Mode) { return Mode != lay_mode::straights; })) + { + Why = STR("A curve traced is laid as an old track: the model lays the straights for now"); + return false; + } + auto const &design{Plan.design}; + if (false == Plan.shape.valid) + return false; + if (design.start_curved || design.end_curved) + { + Why = STR("A curve going on from the curve of a free end is laid as an old track: the model doesn't lay it yet"); + return false; + } + layout::create_line line; + line.start = design.start; + line.end = design.end; + for (std::size_t i = 0; i < design.vertices.size(); ++i) + { + auto const &vertex{design.vertices[i]}; + if (vertex.compound || vertex.spirals || vertex.own_ramps()) + { + Why = STR("A compound curve, or one with cant ramps of its own, is laid as an old track: the model doesn't lay it yet"); + return false; + } + layout::vertex made; + made.point = i < Plan.shape.vertices.size() ? Plan.shape.vertices[i] : vertex.position; + made.radius = vertex.radius; + made.transition_in = vertex.transition_in; + made.transition_out = vertex.transition_out; + made.cant = vertex.cant; + line.vertices.push_back(made); + } + line.transition = design.shape == alignment::transition_shape::clothoid ? layout::transition_shape::clothoid : layout::transition_shape::cubic_parabola; + line.category.vmax = design.speed; + model_context context; + auto const *style{tool.start.track != nullptr ? tool.start.track : End.track}; + if (style == nullptr && tool.copy_selected) + style = const_cast(this)->selected_track(); + if (style != nullptr) + context.surface = surface_of(*style); + context.done = [&Created](std::vector const &Made) { Created = Made; }; + model_run({line}, context); + return true; +} + +bool editor_mode::model_plan_convert(std::string &Why) +{ + if (false == model_on()) + return false; + auto &route{m_route}; + if (false == route.result.valid || route.chain.tracks.empty()) + return false; + auto const &design{route.design}; + auto const &chain{route.chain}; + auto const events = [](TTrack const &Track) { + return false == Track.m_events0.empty() || false == Track.m_events1.empty() || false == Track.m_events2.empty() || false == Track.m_events0all.empty() || false == Track.m_events1all.empty() || + false == Track.m_events2all.empty() || false == Track.Isolated.empty(); + }; + if (false == chain.switches.empty()) + Why = STR("A line through switches is applied to the old tracks: the switches go through the model later"); + else if (design.start_curved || design.end_curved) + Why = STR("A curve going on from the curve of the track beyond is applied to the old tracks: the model doesn't lay it yet"); + else if (std::ranges::any_of(design.vertices, [](alignment::vertex const &Vertex) { return Vertex.compound || Vertex.spirals || Vertex.own_ramps(); })) + Why = STR("A compound curve, or one with cant ramps of its own, is applied to the old tracks: the model doesn't lay it yet"); + else if (std::ranges::any_of(chain.tracks, [&](TTrack const *Track) { return Track->eType != tt_Normal || model_track(Track) != nullptr || events(*Track); })) + Why = STR("Tracks with events or in isolated circuits are applied as old tracks: their events would be lost"); + if (false == Why.empty()) + return false; + // the grade line is the model's in a later stage: an even grade from end to end, as the tracks have it, is taken over + { + auto const rise{design.end.y - design.start.y}; + auto previous{design.start}; + double along{0.0}; + auto const off = [&](glm::dvec3 const &Point) { return std::abs(Point.y - (design.start.y + rise * (chain.length > 0.0 ? std::clamp(along / chain.length, 0.0, 1.0) : 0.0))); }; + for (auto const *track : chain.tracks) + { + auto const &path{track->m_paths.front()}; + auto from{path.points[segment_data::point::start]}; + auto to{path.points[segment_data::point::end]}; + if (glm::distance(to, previous) < glm::distance(from, previous)) + std::swap(from, to); + auto const first{off(from)}; + along += track->Length(); + if (std::max(first, off(to)) > 0.01) + { + Why = STR("A line with a grade line of its own is applied to the old tracks: the model takes over the grade line later"); + return false; + } + previous = to; + } + } + layout::create_line line; + line.start = design.start; + line.end = design.end; + for (std::size_t i = 0; i < design.vertices.size(); ++i) + { + auto const &vertex{design.vertices[i]}; + layout::vertex made; + made.point = i < route.result.vertices.size() ? route.result.vertices[i] : vertex.position; + made.radius = vertex.radius; + made.transition_in = vertex.transition_in; + made.transition_out = vertex.transition_out; + made.cant = vertex.cant; + line.vertices.push_back(made); + } + line.transition = design.shape == alignment::transition_shape::clothoid ? layout::transition_shape::clothoid : layout::transition_shape::cubic_parabola; + line.category.vmax = design.speed; + auto const tracks{chain.tracks}; + { + model_context context; + context.replaced = tracks; + context.surface = surface_of(*tracks.front()); + context.done = [this](std::vector const &) { route_drop(); }; + model_run({line}, context); + } + return true; +} + editor_mode::selftest_result editor_mode::selftest_model(std::string const &command, std::istringstream &words) { + // a track by its name, or @.: the track of the line of the model at the index from its start + auto const resolve = [&](std::string const &Name) -> TTrack * { + if (false == Name.empty() && Name.front() == '@') + { + unsigned line{0}; + std::size_t index{0}; + if (std::sscanf(Name.c_str() + 1, "%u.%zu", &line, &index) != 2) + return nullptr; + auto const tracks{model_line_tracks(static_cast(line))}; + return index < tracks.size() ? tracks[index] : nullptr; + } + auto *track{simulation::Paths.find(Name)}; + return track != nullptr && false == track->m_editorremoved ? track : nullptr; + }; if (command == "modelediting") { int on{0}; @@ -281,11 +635,33 @@ editor_mode::selftest_result editor_mode::selftest_model(std::string const &comm 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; } + if (command == "modeltracks") + { + for (auto const &[id, line] : model().session.network().lines()) + { + std::string names; + for (auto const *track : model_line_tracks(id)) + names += " " + track->name(); + WriteLog(format("SELFTEST modeltracks %s: %.3f m, %zu vertices, tracks%s", line_name(id).c_str(), line.solved.length, line.shape.vertices.size(), names.c_str())); + } + return selftest_result::handled; + } if (command != "expect") return selftest_result::unhandled; auto const start{words.tellg()}; std::string what; words >> what; + if (what == "managed") + { + std::string name, line; + words >> name >> line; + auto const *track{resolve(name)}; + auto const *managed{model_track(track)}; + auto const got{track == nullptr ? std::string{"no track"} : managed == nullptr ? std::string{"none"} : std::to_string(layout::number(managed->line))}; + auto const label{model_label(track)}; + expectation(line == "any" ? managed != nullptr : got == line, "managed " + name, got + (label.empty() ? "" : " (" + label + ")"), line); + return selftest_result::handled; + } if (what == "modellines") { std::size_t count{0}; @@ -313,6 +689,46 @@ editor_mode::selftest_result editor_mode::selftest_model(std::string const &comm expectation(there == (wanted == "present"), "projectfile " + file.generic_string(), there ? "present" : "absent", wanted); return selftest_result::handled; } + if (what == "modelends") + { + // the tracks of each line from end to end with the numbers of its nodes, and from track to track, to the bit + std::string problems; + std::size_t checked{0}; + auto const &network{model().session.network()}; + for (auto const &[id, line] : network.lines()) + { + auto const tracks{model_line_tracks(id)}; + auto const *start{network.find(line.start)}; + auto const *end{network.find(line.end)}; + if (tracks.empty() || start == nullptr || end == nullptr) + { + problems += " " + line_name(id) + " has no tracks"; + continue; + } + auto const first{tracks.front()->m_paths.front().points[segment_data::point::start]}; + auto const last{tracks.back()->m_paths.front().points[segment_data::point::end]}; + if (false == bits_equal(first, start->position)) + problems += format(" %s start %.17g %.17g %.17g against %.17g %.17g %.17g", line_name(id).c_str(), first.x, first.y, first.z, start->position.x, start->position.y, start->position.z); + if (false == bits_equal(last, end->position)) + problems += format(" %s end %.17g %.17g %.17g against %.17g %.17g %.17g", line_name(id).c_str(), last.x, last.y, last.z, end->position.x, end->position.y, end->position.z); + for (std::size_t i = 1; i < tracks.size(); ++i) + if (false == bits_equal(tracks[i - 1]->m_paths.front().points[segment_data::point::end], tracks[i]->m_paths.front().points[segment_data::point::start])) + problems += " " + line_name(id) + " between " + tracks[i - 1]->name() + " and " + tracks[i]->name(); + ++checked; + } + expectation(problems.empty() && checked > 0, "modelends", problems.empty() ? std::to_string(checked) + " lines" : problems, "the ends at the nodes and between the tracks the same to the bit"); + return selftest_result::handled; + } + if (what == "hand") + { + unsigned line{0}; + int wanted{0}; + words >> line >> wanted; + auto const id{static_cast(line)}; + auto const marked{model().session.project().hand_changed.contains(id) || model_seen_changed().contains(id)}; + expectation(marked == (wanted != 0), format("hand %u", line), marked ? "1" : "0", std::to_string(wanted)); + return selftest_result::handled; + } words.clear(); words.seekg(start); return selftest_result::unhandled; diff --git a/application/editormoderoute.cpp b/application/editormoderoute.cpp index 83b9b2244..6e9be0c8b 100644 --- a/application/editormoderoute.cpp +++ b/application/editormoderoute.cpp @@ -659,7 +659,13 @@ bool editor_mode::route_from_line(TTrack &Track) void editor_mode::route_apply() { m_route.error.clear(); + // old tracks made a line of the model, with the editing on the model + std::string oldway; + if (model_plan_convert(oldway)) + return; route_lay(); + if (false == oldway.empty()) + m_route.status += (m_route.status.empty() ? "" : "\n") + oldway; if (false == m_route.error.empty()) refused(m_route.error); } @@ -1637,6 +1643,7 @@ void editor_mode::render_route_ui() ImGui::AlignTextToFramePadding(); ImGui::TextDisabled(STR_P("%zu path, %.2f m", "%zu paths, %.2f m", route.chain.tracks.size()), route.chain.tracks.size(), route.chain.length); + auto const reset{STR_C("Reset design")}; auto const reset_width{ImGui::CalcTextSize(reset).x + ImGui::GetStyle().FramePadding.x * 2.0f}; same_line_if_fits(reset_width); diff --git a/application/editormodetrack.cpp b/application/editormodetrack.cpp index 6fcea16bb..cfa7f7e57 100644 --- a/application/editormodetrack.cpp +++ b/application/editormodetrack.cpp @@ -878,6 +878,8 @@ void editor_mode::render_track_selection() { ImGui::TextUnformatted(name_of(*track).c_str()); ImGui::TextDisabled("%s, %.2f m", STR_C(track_type_name(*track)), track->Length()); + if (auto const label{model_label(track)}; false == label.empty()) + ImGui::TextColored(ImVec4(0.45f, 0.85f, 0.55f, 1.0f), "%s", label.c_str()); return; } render_path_ui(); @@ -1657,6 +1659,12 @@ void editor_mode::render_path_ui() } render_track_name(*track); ImGui::TextDisabled("%s, %.2f m", STR_C(track_type_name(*track)), track->Length()); + // a track the model made of its line: edited through the route design, the other tools change it by hand + if (auto const label{model_label(track)}; false == label.empty()) + { + ImGui::TextColored(ImVec4(0.45f, 0.85f, 0.55f, 1.0f), "%s", label.c_str()); + item_tooltip("Made by the model of the track geometry of its line: the route design edits the line, checked against the norms. Changed here, it's a change by hand, which the model asks about before it lays the line anew"); + } 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 diff --git a/editor/editorTrack.hpp b/editor/editorTrack.hpp index 26e4cc9e7..ad415b0a3 100644 --- a/editor/editorTrack.hpp +++ b/editor/editorTrack.hpp @@ -484,6 +484,9 @@ class editor_track // the switch of the scenery as a template of its own shape; none when its tracks don't start at one point static std::optional template_of_switch(TTrack *Track); static TTrack *load_path(std::string const &Text, TTrack const &Template, std::string const &Name = {}); + // a path of the entry as the scenery has it from its type on ("normal ... endtrack"), in the layer receiving the items created in the + // editor, under the name unless another path has it already; committed by the caller + static TTrack *load_entry(std::string const &Text, std::string const &Name) { return load_text(Text, nullptr, Name); } static TTrack *create_path(TTrack const &Style, segment_data const &Path, std::string const &Name = {}); // parameters of a path laid where there's no other path to copy them from struct path_style diff --git a/lang/editor_pl.po b/lang/editor_pl.po index 5fc04864a..9c64c00c1 100644 --- a/lang/editor_pl.po +++ b/lang/editor_pl.po @@ -14877,5 +14877,50 @@ msgstr "Nie można otworzyć projektu mapy: %s. Tory są edytowane po staremu" msgid "Editing on the model: the project of the map is %s, %zu lines of the model" msgstr "Edycja na modelu: projekt mapy to %s, linii modelu: %zu" +msgid "Line %s (managed)" +msgstr "Linia %s (zarządzana)" + +msgid "Made by the model of the track geometry of its line: the route design edits the line, checked against the norms. Changed here, it's a change by hand, which the model asks about before it lays the line anew" +msgstr "Utworzony przez model geometrii torów z jego linii: linię edytuje projekt trasy, ze sprawdzeniem norm. Zmiana tutaj to zmiana ręczna, o którą model zapyta, zanim ułoży linię od nowa" + +msgid "Refused, nothing changed:" +msgstr "Odmowa, nic się nie zmieniło:" + +msgid "%s: done" +msgstr "%s: wykonano" + +msgid "%s: line %s, %zu track" +msgid_plural "%s: line %s, %zu tracks" +msgstr[0] "%s: linia %s, %zu tor" +msgstr[1] "%s: linia %s, %zu tory" +msgstr[2] "%s: linia %s, %zu torów" + +msgid "create line" +msgstr "nowa linia" + msgid "The project of the map isn't saved: %s" msgstr "Projekt mapy nie został zapisany: %s" + +msgid "A curve traced is laid as an old track: the model lays the straights for now" +msgstr "Łuk po zdjęciu jest układany jako stary tor: model na razie układa proste" + +msgid "A curve going on from the curve of a free end is laid as an old track: the model doesn't lay it yet" +msgstr "Łuk przedłużający łuk wolnego końca jest układany jako stary tor: model jeszcze go nie układa" + +msgid "A compound curve, or one with cant ramps of its own, is laid as an old track: the model doesn't lay it yet" +msgstr "Łuk koszowy albo łuk z własnymi rampami przechyłki jest układany jako stary tor: model jeszcze go nie układa" + +msgid "A line through switches is applied to the old tracks: the switches go through the model later" +msgstr "Linia przez rozjazdy jest stosowana do starych torów: rozjazdy przejdą przez model później" + +msgid "A curve going on from the curve of the track beyond is applied to the old tracks: the model doesn't lay it yet" +msgstr "Łuk przedłużający łuk toru za końcem jest stosowany do starych torów: model jeszcze go nie układa" + +msgid "A compound curve, or one with cant ramps of its own, is applied to the old tracks: the model doesn't lay it yet" +msgstr "Łuk koszowy albo łuk z własnymi rampami przechyłki jest stosowany do starych torów: model jeszcze go nie układa" + +msgid "Tracks with events or in isolated circuits are applied as old tracks: their events would be lost" +msgstr "Tory z eventami albo w odcinkach izolowanych są zmieniane jako stare tory: ich eventy by przepadły" + +msgid "A line with a grade line of its own is applied to the old tracks: the model takes over the grade line later" +msgstr "Linia z własną niweletą jest stosowana do starych torów: model przejmie niweletę później" diff --git a/tests/editor/README.md b/tests/editor/README.md index 21dc02acf..8a8b1f7d4 100644 --- a/tests/editor/README.md +++ b/tests/editor/README.md @@ -93,6 +93,17 @@ The expectations (`expect ...`), each logged as `SELFTEST PASS ` or | `expect window <0\|1>` | the window of the shortcuts (F1), of the settings of the editor, of the weather and the time, of the settings of the orthophoto is open | | `expect selected ` | the node selected stands at the point | +With the editing on the model (`modelediting 1`, the setting for the run only), a track may be named `@.`: the track of +the line of the model at the index from its start; `modeltracks` logs the lines and their tracks. The expectations: + +| expectation | checks | +| --- | --- | +| `expect managed ` | the track is made by the model of the line, or isn't | +| `expect modellines ` | the lines of the model | +| `expect projectfile `, `expect projectfile lines ` | the project file next to the copy of the scenery, the lines it holds | +| `expect modelends` | the tracks of each line end at the numbers of its nodes and at each other, to the bit | +| `expect hand <0\|1>` | the line is taken for changed by hand | + A line `#> reopen` ends a run of the editor there (the part before it saves and ends with `quit`) and starts the editor again on the scenery as it was saved, for what has to be checked after a save and a load. The editor's own `openscenery` starts a new editor without the script, so it isn't for the cases. @@ -141,3 +152,11 @@ and the flow of the lay and the switch tools, a step at a time: | --- | --- | | `lf_1_lay_panel_states` | the panel of the lay tool goes from ready, its settings shown, to clicking, its settings folded to a line, to the line laid told over the settings, and back to ready when it's taken back; the same in the mode of a curve traced | | `lf_2_switch_panel_states` | the panel of the switch tool stays ready after a switch refused, is placed after a switch laid, and tells a switch selected again after another one was laid | + +and the editing on the model of the track geometry (E4a of the plan of the track editing), with the setting on: + +| case | checks | +| --- | --- | +| `m_0_setting_off` | the setting off, a line laid is an old track and no project file is written | +| `m_1_lay_managed` | a line laid in the straights is a line of the model, its tracks marked as its, the project file written with the scenery, the ends to the bit before and after a reopen | +| `m_7_plan_converts` | the route design applied to old tracks makes them a line of the model; Ctrl+Z brings the old tracks back | diff --git a/tests/editor/cases/m_0_setting_off.txt b/tests/editor/cases/m_0_setting_off.txt new file mode 100644 index 000000000..32351015c --- /dev/null +++ b/tests/editor/cases/m_0_setting_off.txt @@ -0,0 +1,11 @@ +# Editing on the model (E4a), the setting off: a line laid is an old track as before, no project file is written next to the scenery +# and none of the tracks is a line of the model. The empty ground east of k0..k3 (x 800..1100) +wait 5 +modelediting 0 +layclicks 0 600 800 -300 800 100 1100 400 +wait 2 +expect steps 1 +save +wait 5 +expect projectfile absent +quit diff --git a/tests/editor/cases/m_1_lay_managed.txt b/tests/editor/cases/m_1_lay_managed.txt new file mode 100644 index 000000000..203f6c805 --- /dev/null +++ b/tests/editor/cases/m_1_lay_managed.txt @@ -0,0 +1,32 @@ +# Editing on the model (E4a): a line laid with the lay tool in the straights is a line of the model, its tracks made by the generator +# and marked as its, one step of the history; the project file is written next to the copy of the scenery when the map is opened and +# with the scenery; the ends of the tracks are the numbers of the nodes, to the bit, before the save and after the scenery is opened +# again, and nothing is taken for a change by hand. The old tracks stay old. The empty ground east of k0..k3 (x 800..1100) +wait 5 +modelediting 1 +expect projectfile present +expect projectfile lines 0 +expect modellines 0 +layclicks 0 600 800 -300 800 100 1100 400 +wait 2 +modeltracks +expect modellines 1 +expect managed @1.0 1 +expect managed @1.2 1 +expect managed a1 none +expect modelends +expect steps 1 +expect hand 1 0 +save +wait 5 +expect projectfile lines 1 +quit +#> reopen +wait 5 +modelediting 1 +modeltracks +expect modellines 1 +expect managed @1.0 1 +expect modelends +expect hand 1 0 +quit diff --git a/tests/editor/cases/m_7_plan_converts.txt b/tests/editor/cases/m_7_plan_converts.txt new file mode 100644 index 000000000..04e1a4173 --- /dev/null +++ b/tests/editor/cases/m_7_plan_converts.txt @@ -0,0 +1,19 @@ +# Editing on the model (E4a): the route design applied to old tracks makes them a line of the model in their place, one step, the +# tracks made by the model marked as its. +# Ctrl+Z brings the old tracks back. The straight a1, a2, a3 along x 0, z 0..300 +wait 5 +modelediting 1 +route 0 150 0 +routeapply +wait 2 +expect modellines 1 +expect managed @1.0 1 +expect track a2 removed +expect modelends +expect steps 1 +undo +wait 2 +expect modellines 0 +expect track a2 present +expect managed a2 none +quit