mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-12-01 12:57:06 +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:
@@ -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());
|
||||
}
|
||||
|
||||
@@ -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<void(std::vector<TTrack *> const &)> done; // with the tracks the last command made
|
||||
std::vector<TTrack *> 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();
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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<scene::basic_node const *, editor_mode::managed_track> tracks;
|
||||
project::index_cache index;
|
||||
@@ -75,6 +79,7 @@ struct editor_model
|
||||
glm::dvec3 offset{0.0};
|
||||
};
|
||||
std::vector<written_track> written;
|
||||
std::vector<std::string> made_errors; // of the generator, by the tracks of the last command
|
||||
std::map<std::string, layout::network> 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<std::string> shown_notices; // the notices so
|
||||
|
||||
@@ -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 <km/h> <own 0|1> the speed set for the laying, and whether it goes also on from a track with its own
|
||||
// laymode <straights|curve>, laytrace <radii 0..3> <straights between 0|1> 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 <x> <z> 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 <label> logs each jump of the cant at a joint of plain tracks, and the steepest ramp of the cant on a path
|
||||
|
||||
@@ -485,6 +485,15 @@ editor_mode::selftest_result editor_mode::selftest_join(std::string const &comma
|
||||
WriteLog("SELFTEST laymode: " + std::string{m_lay.mode == lay_mode::curve ? "curve" : "straights"});
|
||||
return selftest_result::handled;
|
||||
}
|
||||
if (command == "laysettings")
|
||||
{
|
||||
// as a click on the line of their summary while the points are clicked: the settings shown under it, or folded into it again
|
||||
int open{0};
|
||||
words >> open;
|
||||
m_lay.settings_open = open != 0;
|
||||
WriteLog(format("SELFTEST laysettings %d", open));
|
||||
return selftest_result::handled;
|
||||
}
|
||||
if (command == "laytrace")
|
||||
{
|
||||
int straights{1};
|
||||
|
||||
@@ -148,8 +148,8 @@ editor_mode::selftest_result editor_mode::selftest_terrain(std::string const &co
|
||||
}
|
||||
if (command == "nmtsettings")
|
||||
{
|
||||
// as the terrain panel changes them, kept with the editor the next frame (keep_nmt_settings); the terrain while laying at
|
||||
// once, as its chip keeps it
|
||||
// as the terrain panel changes them, kept with the editor the next frame (keep_nmt_settings); the terrain while laying and
|
||||
// the area for the run only, the settings of the tester's own editor left as they are
|
||||
auto &state{m_nmt_state};
|
||||
std::string key;
|
||||
double value{0.0};
|
||||
@@ -170,11 +170,7 @@ editor_mode::selftest_result editor_mode::selftest_terrain(std::string const &co
|
||||
else if (key == "fitted")
|
||||
state.fitted = value != 0.0;
|
||||
else if (key == "grow")
|
||||
{
|
||||
state.grow = value != 0.0;
|
||||
EditorSettings.terrain_while_laying(state.grow);
|
||||
EditorSettings.save();
|
||||
}
|
||||
state.grow = value != 0.0; // for the run only, as area: the setting isn't touched, so the tester's own file stays as it was
|
||||
else if (key == "area")
|
||||
m_area_terrain.run_only = value != 0.0; // for the run only: the setting isn't touched, so no save keeps it
|
||||
}
|
||||
|
||||
@@ -323,6 +323,19 @@ void anchor_again(network const &Network, anchor &Anchor, placement const &Where
|
||||
Anchor.points[i] = point_along(*found);
|
||||
}
|
||||
|
||||
// the anchor's line is gone, or ends before the anchor or one of its points now: split, its head part keeping its id (split_at,
|
||||
// insert_turnout), the anchor is on the line beyond it. Kept at its chainage, it was clamped onto the end of the head part
|
||||
bool lost(network const &After, anchor const &Anchor)
|
||||
{
|
||||
auto const *line{After.find(Anchor.line)};
|
||||
if (line == nullptr)
|
||||
return true;
|
||||
if (false == line->solved.valid())
|
||||
return false;
|
||||
auto const beyond = [line](anchor_point const &Point) { return Point.chainage > line->solved.length + 1e-6; };
|
||||
return beyond(Anchor.at) || std::ranges::any_of(Anchor.points, beyond);
|
||||
}
|
||||
|
||||
bool same_place(placement const &A, placement const &B)
|
||||
{
|
||||
if (glm::distance(A.location, B.location) > 1e-4 || std::abs(circular(A.yaw - B.yaw)) > 1e-6 || A.points.size() != B.points.size())
|
||||
@@ -375,7 +388,7 @@ std::vector<moved> follow(network const &Before, network const &After, std::vect
|
||||
{
|
||||
auto &each{Anchors[i]};
|
||||
auto const was{place(Before, each)};
|
||||
if (After.find(each.line) == nullptr && was.has_value())
|
||||
if (was.has_value() && lost(After, each))
|
||||
anchor_again(After, each, *was);
|
||||
auto const now{place(After, each)};
|
||||
if (now.has_value() && (false == was.has_value() || false == same_place(*was, *now)))
|
||||
|
||||
@@ -92,9 +92,9 @@ struct placement
|
||||
};
|
||||
std::optional<placement> place(network const &Network, anchor const &Anchor);
|
||||
|
||||
// the anchors following a change of the network from Before to After: an anchor whose line is there still keeps its chainage (on the
|
||||
// length the line has now); one whose line is gone (split, joined, taken by a turnout) is anchored again where it stood before, to the line
|
||||
// there now. The anchors whose objects move, with where to, in the order of the anchors; the anchors updated
|
||||
// the anchors following a change of the network from Before to After: an anchor whose line is there still keeps its chainage; one whose
|
||||
// line is gone (joined, taken by a turnout), or ends before it now (split, the head part keeping the id), is anchored again where it stood
|
||||
// before, to the line there now. The anchors whose objects move, with where to, in the order of the anchors; the anchors updated
|
||||
struct moved
|
||||
{
|
||||
std::size_t anchor{0};
|
||||
|
||||
@@ -452,6 +452,10 @@ bool merge_at(transaction &Change, node_id const Node)
|
||||
merged.end_continues = second->end_continues;
|
||||
for (auto const &point : second->shape.grades)
|
||||
merged.shape.grades.push_back({point.chainage + a.length, point.elevation, point.vertical_radius});
|
||||
// the part of a line with no old track where it starts stays out of the old tracks: else the last old track of the first line ran
|
||||
// on over it, its name and its isolated circuit with it
|
||||
if (false == first->hard_splits.empty() && (second->hard_splits.empty() || second->hard_splits.front().chainage > 1e-6))
|
||||
merged.hard_splits.push_back({a.length, old_track{}});
|
||||
for (auto const &split : second->hard_splits)
|
||||
merged.hard_splits.push_back({split.chainage + a.length, split.track});
|
||||
auto const &before{first->shape.vertices};
|
||||
@@ -1599,18 +1603,21 @@ outcome model::execute(command const &Command, edit_policy const Policy)
|
||||
std::optional<network> earlier;
|
||||
if (Policy == edit_policy::no_new_block)
|
||||
earlier = m_network;
|
||||
// the line laid as it was, for its joints of old tracks to follow it
|
||||
auto const line{reshaped(Command)};
|
||||
std::optional<solved_line> before;
|
||||
if (auto const *shaped{line.has_value() ? m_network.find(*line) : nullptr}; shaped != nullptr && false == shaped->hard_splits.empty())
|
||||
before = shaped->solved;
|
||||
// the lines with joints of old tracks laid as they were, for the joints to follow them: the one the command reshapes, and the ones
|
||||
// settle() lays again with it, a line going on from the diverging end of a turnout on it say
|
||||
std::map<line_id, solved_line> before;
|
||||
if (reshaped(Command).has_value())
|
||||
for (auto const &[id, each] : m_network.lines())
|
||||
if (false == each.hard_splits.empty())
|
||||
before.emplace(id, each.solved);
|
||||
transaction change{m_network};
|
||||
auto why{std::visit([&](auto const &Each) { return propose(change, result, Each); }, Command)};
|
||||
if (why.empty())
|
||||
{
|
||||
settle(change);
|
||||
if (before.has_value())
|
||||
follow_joints(change, *line, *before);
|
||||
for (auto const id : change.touched_lines())
|
||||
if (auto const laid{before.find(id)}; laid != before.end())
|
||||
follow_joints(change, id, laid->second);
|
||||
auto judged{check(m_network, change.touched_lines(), change.touched_nodes(), change.touched_turnouts())};
|
||||
if (earlier.has_value() && judged.reasons.empty() && false == judged.blocks.empty())
|
||||
{
|
||||
|
||||
@@ -18,6 +18,7 @@ http://mozilla.org/MPL/2.0/.
|
||||
#include <format>
|
||||
#include <iterator>
|
||||
#include <optional>
|
||||
#include <set>
|
||||
#include <string>
|
||||
|
||||
namespace layout
|
||||
@@ -471,9 +472,32 @@ std::string without_events(std::string_view const Attributes)
|
||||
// the pieces of the stretches of the old tracks named and written as each old track was: its name on the piece it ran into first, with
|
||||
// its events, <name>_2... on the others, its surface and its attributes, the path the way it ran; a piece out of any stretch as the generator
|
||||
// names and writes it
|
||||
// the letters made small, as the simulator makes the names
|
||||
std::string small_letters(std::string_view const Text)
|
||||
{
|
||||
std::string result;
|
||||
std::ranges::transform(Text, std::back_inserter(result), [](char const C) { return static_cast<char>(std::tolower(static_cast<unsigned char>(C))); });
|
||||
return result;
|
||||
}
|
||||
|
||||
// the name of a piece of an old track after its first one, <name>_<number>, the number on past the names taken: by an old track of the
|
||||
// line called so, or by a piece named before
|
||||
std::string piece_name(std::string const &Name, std::size_t Number, std::set<std::string> &Taken)
|
||||
{
|
||||
auto name{std::format("{}_{}", Name, Number)};
|
||||
while (Taken.contains(small_letters(name)))
|
||||
name = std::format("{}_{}", Name, ++Number);
|
||||
Taken.insert(small_letters(name));
|
||||
return name;
|
||||
}
|
||||
|
||||
void keep_old_tracks(line const &Line, std::vector<generated_piece> &Pieces, generator_options const &Options)
|
||||
{
|
||||
auto const &splits{Line.hard_splits};
|
||||
std::set<std::string> taken;
|
||||
for (auto const &split : splits)
|
||||
if (false == split.track.name.empty())
|
||||
taken.insert(small_letters(split.track.name));
|
||||
auto const stretch_of = [&splits](generated_piece const &Piece) {
|
||||
auto const after{std::ranges::upper_bound(splits, Piece.from + 1e-6, {}, &hard_split::chainage)};
|
||||
return after == splits.begin() ? splits.size() : static_cast<std::size_t>(after - splits.begin()) - 1;
|
||||
@@ -495,7 +519,7 @@ void keep_old_tracks(line const &Line, std::vector<generated_piece> &Pieces, gen
|
||||
// 0 at the Point1 of the old track
|
||||
auto const order{old.reversed ? last - 1 - i : i - first};
|
||||
if (false == old.name.empty() && false == old.continued)
|
||||
piece.name = order == 0 ? old.name : std::format("{}_{}", old.name, order + 1);
|
||||
piece.name = order == 0 ? old.name : piece_name(old.name, order + 1, taken);
|
||||
if (old.reversed)
|
||||
piece.path = geometry::reversed(piece.path);
|
||||
auto attributes{old.continued ? without_events(old.attributes) : attributes_of_piece(old.attributes, {true, order == 0, order + 1 == count})};
|
||||
|
||||
@@ -164,7 +164,7 @@ double legacy_track::velocity() const
|
||||
std::istringstream words{attributes};
|
||||
std::string word;
|
||||
while (words >> word)
|
||||
if (word == "velocity")
|
||||
if (lowered(word) == "velocity")
|
||||
{
|
||||
double value{0.0};
|
||||
if (words >> value)
|
||||
@@ -304,7 +304,7 @@ takeover_plan plan_takeover(std::vector<legacy_track> const &Tracks, std::vector
|
||||
auto const &track{Tracks[chain.links[k].track]};
|
||||
fastest = std::max(fastest, std::abs(track.velocity()));
|
||||
old_track old;
|
||||
old.name = track.name == "none" ? std::string{} : track.name;
|
||||
old.name = lowered(track.name) == "none" ? std::string{} : track.name;
|
||||
old.surface = track.surface;
|
||||
old.attributes = track.attributes;
|
||||
old.reversed = false == chain.links[k].forward;
|
||||
|
||||
@@ -14,6 +14,7 @@ http://mozilla.org/MPL/2.0/.
|
||||
#include <algorithm>
|
||||
#include <array>
|
||||
#include <charconv>
|
||||
#include <cmath>
|
||||
#include <cstdio>
|
||||
#include <filesystem>
|
||||
#include <format>
|
||||
@@ -209,13 +210,16 @@ class record
|
||||
fail(std::format("'{}' isn't a profile of the norms", text));
|
||||
return norms::profile_id::plk;
|
||||
}
|
||||
// the rest of the line as it is written, the blanks between the words kept as one
|
||||
// the rest of the line as it is written, from its next word to its last, the blanks between the words as they are: joined with one
|
||||
// blank, a reason of two blanks came back changed after a save and a load
|
||||
std::string rest()
|
||||
{
|
||||
std::string result;
|
||||
for (; false == done(); ++m_at)
|
||||
result += (result.empty() ? "" : " ") + std::string{m_words[m_at]};
|
||||
return result;
|
||||
if (done())
|
||||
return {};
|
||||
auto const first{m_words[m_at]};
|
||||
auto const last{m_words.back()};
|
||||
m_at = m_words.size();
|
||||
return std::string(first.data(), static_cast<std::size_t>(last.data() + last.size() - first.data()));
|
||||
}
|
||||
void finish()
|
||||
{
|
||||
@@ -703,6 +707,9 @@ read_result read(std::string_view const Text)
|
||||
words.expect("attributes");
|
||||
split.track.attributes = unword(words.next("the attributes"));
|
||||
words.finish();
|
||||
// the joints along the line in their order: the generator looks them up so
|
||||
if (false == words.failed() && (false == std::isfinite(split.chainage) || split.chainage < 0.0 || (false == line->hard_splits.empty() && split.chainage < line->hard_splits.back().chainage)))
|
||||
words.fail(std::format("the old track {} at {} m is off the line, or out of the order of the ones before it", split.track.name, split.chainage));
|
||||
line->hard_splits.push_back(std::move(split));
|
||||
}
|
||||
else if (keyword == "end")
|
||||
|
||||
@@ -219,7 +219,15 @@ class reader
|
||||
m_output.files.push_back(std::move(file));
|
||||
return;
|
||||
}
|
||||
// a file including itself, on its own or through others, would never end
|
||||
// a file including itself, on its own or through others, would never end: not read again while it's being read
|
||||
if (auto const reading{std::ranges::find_if(m_frames, [this, &file](frame const &Frame) { return same_file(m_output.files[Frame.file].name, file.name); })};
|
||||
reading != m_frames.end())
|
||||
{
|
||||
file.missing = true;
|
||||
m_output.problems.push_back(file.name + " includes itself, included from " + m_output.files[Parent].name + " line " + std::to_string(Line));
|
||||
m_output.files.push_back(std::move(file));
|
||||
return;
|
||||
}
|
||||
if (m_frames.size() >= kDepth)
|
||||
{
|
||||
file.missing = true;
|
||||
|
||||
@@ -14865,6 +14865,9 @@ msgstr "Rozjazd %s: przeciągnij go wzdłuż toru, aby przesunąć"
|
||||
msgid "Editing on the model (trial)"
|
||||
msgstr "Edycja na modelu (wersja próbna)"
|
||||
|
||||
msgid "Takes effect with the next scenery opened"
|
||||
msgstr "Zadziała od następnej otwartej scenerii"
|
||||
|
||||
msgid "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.\nThe tracks there were stay as they are, edited the old way. Off, the editor works as it did"
|
||||
msgstr "Linia ułożona prostymi albo zastosowana w projekcie trasy staje się linią modelu geometrii torów: jej tory tworzy model, jej zmiany są sprawdzane z normami i odrzucane z podaniem powodów, a projekt mapy leży obok niej.\nTory, które już były, zostają bez zmian i są edytowane po staremu. Wyłączone: edytor działa jak dotąd"
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
# Laying flow: the panel of the lay tool goes through its states, each with its step at its top. Nothing clicked: its settings shown.
|
||||
# Points clicked: the settings folded to the line of their summary. The line laid with Enter: told in one line over the settings
|
||||
# Points clicked: the settings folded to the line of their summary, opened by a click on it and folded again. The line laid with Enter: told in one line over the settings
|
||||
# shown again. Taken back with Ctrl+Z: ready, the line laid no more told. The same in the mode of a curve traced. The points go on
|
||||
# the empty ground between the turntable tt1 and the curves (x 220..270), the camera straight above them
|
||||
wait 5
|
||||
@@ -16,6 +16,12 @@ expect laypanel clicking folded
|
||||
layp 235 165 250 185
|
||||
wait 2
|
||||
expect laypanel clicking folded
|
||||
laysettings 1
|
||||
wait 2
|
||||
expect laypanel clicking shown
|
||||
laysettings 0
|
||||
wait 2
|
||||
expect laypanel clicking folded
|
||||
layenter
|
||||
wait 2
|
||||
expect laypanel laid shown
|
||||
|
||||
@@ -145,6 +145,13 @@ TEST_CASE("project file: the golden file read and written back comes out the sam
|
||||
CHECK(project.anchors.empty());
|
||||
REQUIRE(project.legacy.size() == 3);
|
||||
CHECK(project.legacy[1].why == "a compound curve");
|
||||
// the reason as it was written, its blanks kept, read and written back the same
|
||||
auto spaced{golden};
|
||||
spaced.replace(spaced.find("why a compound curve"), 20, "why a compound curve");
|
||||
auto const reason{project::read(spaced)};
|
||||
REQUIRE_MESSAGE(reason.project.has_value(), notes_of(reason));
|
||||
CHECK(reason.project->legacy[1].why == "a compound curve");
|
||||
CHECK(project::write(*reason.project) == spaced);
|
||||
CHECK(project.legacy[1].lines == std::vector<std::string>{"alignment 1.0000 2.0000 3.0000 4.0000 5.0000 6.0000", "", "end"});
|
||||
CHECK(project.legacy[2].mark == 'r');
|
||||
// the line ends of windows read the same
|
||||
|
||||
@@ -8,10 +8,13 @@
|
||||
#include "scratch.h"
|
||||
#include "editor/editorAlignment.hpp"
|
||||
#include "editor/editorRecords.hpp"
|
||||
#include "editor/editorSwitchDesign.hpp"
|
||||
#include "editor/project/projectMigration.hpp"
|
||||
#include "layout_fixture.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <filesystem>
|
||||
#include <format>
|
||||
#include <fstream>
|
||||
#include <iterator>
|
||||
#include <map>
|
||||
@@ -333,3 +336,60 @@ TEST_CASE("project migration: the //$r switches on the lines made of the alignme
|
||||
CHECK(editor_records::read_switches(kept.lines, {}, 0).size() == 3);
|
||||
round_trip(project);
|
||||
}
|
||||
|
||||
// the first alignment of data/records with a //$r block of the switches, up to the end of its record
|
||||
std::string alignment_with(std::vector<std::string> const &Switches) {
|
||||
auto alignment{file_text(std::string{EU07_UNIT_TESTS_DATA} + "/records/alignment.scn")};
|
||||
auto const end{alignment.find("//$h end\r\n") != std::string::npos ? alignment.find("//$h end\r\n") : alignment.find("//$h end\n")};
|
||||
REQUIRE(end != std::string::npos);
|
||||
std::string text{alignment.substr(0, end + 8) + "\n//$r # switches placed in the track editor, the simulation skips these lines\n"};
|
||||
for (auto const &line : Switches) {
|
||||
text += "//$r " + line + "\n";
|
||||
}
|
||||
return text;
|
||||
}
|
||||
|
||||
TEST_CASE("project migration: a switch bent into a curve, written as Rlj by the editor, is taken for the Rz of the catalogue it's bent from") {
|
||||
// as switch_store::classify() writes a bent switch: Rlj with the radius of the ordinary one; on the straight of the alignment
|
||||
std::vector<std::string> const switches{
|
||||
"switch z5 Rlj 60E1 500.000 12.000 L 20.797 20.797 0.000 parts 1 z5 start 0.0000 0.0000 200.0000 dir 0.000000000 1.000000000 km - number - source designed"};
|
||||
auto const migrated{project::migrate({{"bent.scn", {}, project::marked_lines(alignment_with(switches))}})};
|
||||
CAPTURE(notes_of(migrated.notes));
|
||||
auto const &network{migrated.project.network};
|
||||
REQUIRE(network.turnouts().size() == 1);
|
||||
auto const &turnout{network.turnouts().begin()->second};
|
||||
CHECK(turnout.type == "Rz 60E1-500-1:12");
|
||||
CHECK(turnout.hand == -1);
|
||||
test::layout_fixture::check_structure(network);
|
||||
round_trip(migrated.project);
|
||||
}
|
||||
|
||||
TEST_CASE("project migration: a switch record two types of the catalogue fit isn't taken for either of them, why kept with it") {
|
||||
// two entries of the catalogue the record can't tell apart: the double switches of one geometry with their seconds staggered
|
||||
// otherwise, say; the ordinary frog is taken over the movable nose, so two with the same frog
|
||||
auto const &entries{switch_design::catalogue_entries()};
|
||||
switch_design::design const *first{nullptr};
|
||||
switch_design::design const *second{nullptr};
|
||||
for (auto const &one : entries) {
|
||||
for (auto const &other : entries) {
|
||||
if (&one != &other && one.type == "Rpd" && other.type == one.type && one.rail == other.rail && one.movable == other.movable && std::abs(one.ratio - other.ratio) <= 0.01 &&
|
||||
std::abs(one.radius - other.radius) <= 0.5 && std::abs(one.a - other.a) <= 0.002 && first == nullptr) {
|
||||
first = &one;
|
||||
second = &other;
|
||||
}
|
||||
}
|
||||
}
|
||||
REQUIRE_MESSAGE(first != nullptr, "the catalogue has no two Rpd alike in what a record tells");
|
||||
CAPTURE(first->name);
|
||||
CAPTURE(second->name);
|
||||
std::vector<std::string> const switches{std::format("switch z6 Rpd {} {:.3f} {:.3f} L {:.3f} {:.3f} 0.000 parts 1 z6 start 0.0000 0.0000 200.0000 dir 0.000000000 1.000000000 km - number - source designed",
|
||||
first->rail, first->radius, first->ratio, first->a, first->b)};
|
||||
auto const migrated{project::migrate({{"double.scn", {}, project::marked_lines(alignment_with(switches))}})};
|
||||
CAPTURE(notes_of(migrated.notes));
|
||||
CHECK(migrated.project.network.turnouts().empty());
|
||||
auto const *kept{legacy_of(migrated.project, 'r')};
|
||||
REQUIRE(kept != nullptr);
|
||||
CAPTURE(kept->why);
|
||||
CHECK(kept->why.find("z6: Rpd fits ") != std::string::npos);
|
||||
CHECK(kept->lines.back() == switches.front());
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
#include "doctest.h"
|
||||
#include "editor/project/scenarioIndex.hpp"
|
||||
#include "editor/project/sceneryText.hpp"
|
||||
#include "scratch.h"
|
||||
|
||||
#include <format>
|
||||
#include <string>
|
||||
@@ -114,6 +115,18 @@ TEST_CASE("scenario index: the scenery read as the simulator reads it, the inclu
|
||||
CHECK_FALSE(missing.uses_map());
|
||||
}
|
||||
|
||||
TEST_CASE("scenario index: a file including itself, on its own or through another one, is told and not read again") {
|
||||
test::scratch_folder const folder{"scenery_text_cycle"};
|
||||
folder.write("petla.scn", "node -1 0 a memcell 0 0 0 endmemcell\ninclude petla/druga.scm end\n");
|
||||
folder.write("petla/druga.scm", "node -1 0 b memcell 0 0 0 endmemcell\ninclude PETLA.scn end\n");
|
||||
auto const scenery{scenery_text::read(folder.root(), "petla.scn")};
|
||||
REQUIRE(scenery.problems.size() == 1);
|
||||
CHECK(scenery.problems.front() == "PETLA.scn includes itself, included from petla/druga.scm line 2");
|
||||
REQUIRE(scenery.files.size() == 3);
|
||||
CHECK(scenery.files[2].missing);
|
||||
CHECK(std::ranges::count(scenery.statements, std::string{"node"}, &scenery_text::statement::keyword) == 2);
|
||||
}
|
||||
|
||||
TEST_CASE("scenario index: the words of the text as the parser splits them") {
|
||||
auto const tokens{scenery_text::split("node -1 0 a;track // a comment\n\"two words\" /* a\ncomment */ endtrack//glued\nx")};
|
||||
REQUIRE(tokens.size() == 8);
|
||||
|
||||
@@ -292,3 +292,58 @@ TEST_CASE("takeover scenery: the anchors of the lineside objects, with their con
|
||||
CHECK(read.project->anchors.size() == anchors.size());
|
||||
CHECK(project::write(*read.project) == project::write(document));
|
||||
}
|
||||
|
||||
TEST_CASE("takeover scenery: an object past where its line is split goes onto the part beyond, not onto the end of the part before") {
|
||||
// a straight of 500 m, a signal 3 m beside it at 300 m; split at 100 m, the part before it keeping the id of the line
|
||||
layout::model model;
|
||||
layout::create_line straight;
|
||||
straight.start = {0.0, 100.0, 0.0};
|
||||
straight.end = {500.0, 100.0, 0.0};
|
||||
straight.category.vmax = 80.0;
|
||||
auto const made{model.execute(straight)};
|
||||
REQUIRE(made.done);
|
||||
auto const line{made.lines.front()};
|
||||
layout::anchor signal;
|
||||
signal.id = 1;
|
||||
signal.kind = "model";
|
||||
signal.name = "sem";
|
||||
signal.line = line;
|
||||
signal.at.chainage = 300.0;
|
||||
signal.at.offset = 3.0;
|
||||
auto const was{layout::place(model.state(), signal)};
|
||||
REQUIRE(was.has_value());
|
||||
std::vector<layout::anchor> anchors{signal};
|
||||
auto const before{model.state()};
|
||||
REQUIRE(model.execute(layout::split_line{line, 100.0}).done);
|
||||
auto const moved{layout::follow(before, model.state(), anchors)};
|
||||
// where it stood, along the part beyond the split: clamped to the end of the part before, it went 200 m back
|
||||
CHECK(moved.empty());
|
||||
CHECK(anchors.front().line != line);
|
||||
CHECK(anchors.front().at.chainage == doctest::Approx(200.0).epsilon(1e-6));
|
||||
auto const now{layout::place(model.state(), anchors.front())};
|
||||
REQUIRE(now.has_value());
|
||||
CHECK(glm::distance(now->location, was->location) < 1e-6);
|
||||
}
|
||||
|
||||
TEST_CASE("takeover scenery: the joints of the old tracks read back on their line and in their order") {
|
||||
layout::model model;
|
||||
layout::create_line straight;
|
||||
straight.start = {0.0, 100.0, 0.0};
|
||||
straight.end = {500.0, 100.0, 0.0};
|
||||
straight.category.vmax = 80.0;
|
||||
REQUIRE(model.execute(straight).done);
|
||||
project::document document;
|
||||
document.network = model.state();
|
||||
auto const text{project::write(document)};
|
||||
auto const with = [&text](std::string const &Joints) {
|
||||
auto changed{text};
|
||||
auto const at{changed.find("\nend\n")};
|
||||
REQUIRE(at != std::string::npos);
|
||||
changed.insert(at + 1, Joints);
|
||||
return project::read(changed);
|
||||
};
|
||||
CHECK(with("old 0 a reversed 0 continued 0 surface - attributes -\nold 120 b reversed 0 continued 0 surface - attributes -\n").project.has_value());
|
||||
CHECK_FALSE(with("old 120 a reversed 0 continued 0 surface - attributes -\nold 20 b reversed 0 continued 0 surface - attributes -\n").project.has_value());
|
||||
CHECK_FALSE(with("old -5 a reversed 0 continued 0 surface - attributes -\n").project.has_value());
|
||||
CHECK_FALSE(with("old nan a reversed 0 continued 0 surface - attributes -\n").project.has_value());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user