mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-11-06 18:38:36 +01:00
feat(editor): a track deleted cuts the design kept for its line down to the tracks left along it, in the same step of the undo history: a design keeps the stretch of its line it stands for (//$h kept <from> <to>), a track deleted in the middle parts it in two, one at an end shortens it, a design with no track left is forgotten. The geometry stays as designed, only its reach changes. A design cut down isn't taken whole by the route plan nor merged with a new one nor carried along by a switch slid, and gives no designed curve to the tracks left of a curve it cut, which are recognized as they lie: a track laid by hand into the gap is never pulled back to the old shape. The status tells of it. The //$h click lines are the editor's own now: read back with their design, and written once on save instead of staying behind and piling up. Selftests on a copy of wgr.scn: a track of a compound curve deleted in the middle, undone and redone, one at an end, all of a piece, saved and read back
This commit is contained in:
@@ -1780,6 +1780,7 @@ class editor_mode : public application_mode, private editor_track::observer, pri
|
||||
void render_straight_ui();
|
||||
track_tab m_track_tab{track_tab::path};
|
||||
void delete_selected_track();
|
||||
std::string designs_trimmed(std::vector<TTrack *> const &Removed);
|
||||
void start_straight_gesture(int const Tool);
|
||||
void finish_straight_gesture();
|
||||
void toggle_straight_set(TTrack &Track);
|
||||
|
||||
@@ -536,12 +536,12 @@ bool editor_mode::digitize_chain(editor_track::chain const &Chain, std::string *
|
||||
for (auto const index : covered)
|
||||
{
|
||||
auto const &old{records[index]};
|
||||
auto const start{alignment_store::chainage_on(result, old.design.start)};
|
||||
auto const end{alignment_store::chainage_on(result, old.design.end)};
|
||||
auto const start{alignment_store::chainage_on(result, alignment_store::kept_start(old))};
|
||||
auto const end{alignment_store::chainage_on(result, alignment_store::kept_end(old))};
|
||||
if (false == start.has_value() || false == end.has_value())
|
||||
return false;
|
||||
if (index == *covered.begin() && *end > *start)
|
||||
origin = old.origin - *start;
|
||||
origin = old.origin + old.from - *start;
|
||||
}
|
||||
auto const layer{covered.empty() ? alignment_store::layer_of(*Chain.tracks.front()) : records[*covered.begin()].layer};
|
||||
for (auto index{covered.rbegin()}; index != covered.rend(); ++index)
|
||||
|
||||
@@ -398,7 +398,8 @@ editor_mode::selftest_result editor_mode::selftest_track(std::string const &comm
|
||||
for (std::size_t r = 0; r < records.size(); ++r)
|
||||
{
|
||||
auto const &entry{records[r]};
|
||||
WriteLog(format("SELFTEST alignment %zu in %s: km %.3f, %zu vertices, %zu elements, consistent %d, length %.3f", r, scene::Layers.layer(entry.layer).name.c_str(), entry.origin / 1000.0, entry.design.vertices.size(), entry.elements.size(), entry.consistent ? 1 : 0, entry.result.length));
|
||||
WriteLog(format("SELFTEST alignment %zu in %s: km %.3f, %zu vertices, %zu elements, consistent %d, length %.3f, kept %.3f - %.3f, %zu clicks", r, scene::Layers.layer(entry.layer).name.c_str(), entry.origin / 1000.0, entry.design.vertices.size(), entry.elements.size(), entry.consistent ? 1 : 0, entry.result.length,
|
||||
entry.from, entry.kept_to(), entry.clicks.size()));
|
||||
for (auto const &e : entry.elements)
|
||||
WriteLog(format("SELFTEST element %s vertex %d km %.3f L %.3f R %.3f -> %.3f cant %.1f", e.kind.c_str(), e.vertex, (entry.origin + e.chainage) / 1000.0, e.length, e.radius_start, e.radius_end, e.cant));
|
||||
}
|
||||
|
||||
@@ -436,6 +436,8 @@ void editor_mode::lay_switch_branch(switch_branch const &Branch, editor_track::e
|
||||
for (std::size_t i = 0; i < records.size(); ++i)
|
||||
{
|
||||
auto const &record{records[i]};
|
||||
if (false == record.whole())
|
||||
continue;
|
||||
auto const atstart{plan_distance(record.design.start, from) < geometry::same_point};
|
||||
if (false == atstart && plan_distance(record.design.end, from) >= geometry::same_point)
|
||||
continue;
|
||||
|
||||
@@ -1596,6 +1596,14 @@ void editor_mode::render_path_ui()
|
||||
|
||||
|
||||
|
||||
// the designs kept for the lines the tracks deleted lay along cut down to the tracks left, in the same step of the undo history: what
|
||||
// the status tells of it
|
||||
std::string editor_mode::designs_trimmed(std::vector<TTrack *> const &Removed)
|
||||
{
|
||||
auto const cut{alignment_store::trim(Removed)};
|
||||
return cut > 0 ? std::string{STR_P("The design kept for the line is cut down to the tracks left along it", "The designs kept for the lines are cut down to the tracks left along them", static_cast<long long>(cut))} : std::string{};
|
||||
}
|
||||
|
||||
void editor_mode::delete_selected_track()
|
||||
{
|
||||
auto *track{selected_track()};
|
||||
@@ -1630,6 +1638,8 @@ void editor_mode::delete_selected_track()
|
||||
created.push_back(straight);
|
||||
ui()->set_status(STR_C("The double switch is replaced by its main track, Shift+Del removes all of it"), false);
|
||||
}
|
||||
if (auto const note{designs_trimmed({set->first, set->link, set->second})}; false == note.empty())
|
||||
ui()->set_status(note, false);
|
||||
push_track_snapshot({}, created, {set->first, set->link, set->second});
|
||||
if (std::any_of(m_route.chain.tracks.begin(), m_route.chain.tracks.end(), [&](TTrack const *Each) { return Each == set->first || Each == set->link || Each == set->second; }))
|
||||
m_route = {};
|
||||
@@ -1653,6 +1663,8 @@ void editor_mode::delete_selected_track()
|
||||
created.push_back(main);
|
||||
ui()->set_status(STR_C("The switch is replaced by its main track, Shift+Del removes all of it"), false);
|
||||
}
|
||||
if (auto const note{designs_trimmed({track})}; false == note.empty())
|
||||
ui()->set_status(note, false);
|
||||
push_track_snapshot({}, created, {track});
|
||||
// the model and the events of a turntable can't stay without its track
|
||||
if (track->eType == tt_Table)
|
||||
|
||||
@@ -1829,6 +1829,7 @@ void editor_mode::track_set_delete()
|
||||
if (std::find(m_route.chain.tracks.begin(), m_route.chain.tracks.end(), track) != m_route.chain.tracks.end())
|
||||
m_route = {};
|
||||
}
|
||||
auto const designs{designs_trimmed(removed)};
|
||||
push_track_snapshot({}, {}, removed);
|
||||
m_track_set.clear();
|
||||
m_node = nullptr;
|
||||
@@ -1838,6 +1839,8 @@ void editor_mode::track_set_delete()
|
||||
auto status{format(STR_P("%zu track deleted, Ctrl+Z brings it back", "%zu tracks deleted, Ctrl+Z brings them back", static_cast<long long>(removed.size())), removed.size())};
|
||||
if (kept > 0)
|
||||
status += format(STR_C(", %zu with vehicles on them or in the files which can't be changed are left"), kept);
|
||||
if (false == designs.empty())
|
||||
status += "\n" + designs;
|
||||
ui()->set_status(status, false);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user