mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-12-02 09:36:48 +01:00
Merge branch 'feat/editor-legacy-takeover' into feat/editor-model-turnouts-ui
editor_model is in editormodemodel.h here: the setting taken at the open and the errors of the generator go there. A managed track of a turnout counts among the tracks of the main track of the turnout, as indices[] numbers them; the errors of the turnouts are told with the notices too, shown as they are.
This commit is contained in:
@@ -103,9 +103,10 @@ std::optional<bool> &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<std::string, std::optional<std::string>> files;
|
||||
std::map<layout::line_id, std::size_t> counts;
|
||||
std::map<layout::line_id, std::size_t> 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<TTrack *> editor_mode::model_line_tracks(layout::line_id const Line)
|
||||
std::set<layout::line_id> editor_mode::model_seen_changed() const
|
||||
{
|
||||
std::set<layout::line_id> 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<layout::line_id, line_count> counts;
|
||||
for (auto const &[node, entry] : model().tracks)
|
||||
{
|
||||
auto const *track{dynamic_cast<TTrack const *>(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<layout::command> 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<long long>(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<TTrack *> editor_mode::model_tracks_after(std::uint64_t const Token,
|
||||
turnouts.insert(id);
|
||||
std::vector<TTrack *> 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<TTrack *> 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<TTrack *> 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<TTrack *> 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<TTrack *> 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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user