Fix: custom G-codes and wipe tower for plate not moved after using move plate to front and undo (#17569)

Custom G-codes and wipe tower positions are stored by plate index, and reordering plates left them at the old index.

- Moving a plate reorders `wipe_tower_x` and `wipe_tower_y` with it.
- `PartPlateList::remap_custom_gcodes()` re-keys `plates_custom_gcodes` by plate ID after a plate move, a plate deletion and an undo/redo jump. Entries of a plate that an undo removes are kept and restored when the plate comes back.
- Undo/redo restores every changed wipe tower position instead of only the first.
This commit is contained in:
yw4z authored and GitHub committed 2026-11-22 19:35:38 -06:00
1 parent 1281de4cdc
commit a31c95e273
3 files changed
+70 -1

No files matched your search

+60
View File
@@ -6719,6 +6719,7 @@ int PartPlateList::delete_plate(int index)
return -1;
}
const std::string plate_name = plate->get_plate_name();
const std::vector<ObjectID> plate_ids_before = get_plate_ids();
if (m_plater) {
// In GUI mode
@@ -6739,6 +6740,8 @@ int PartPlateList::delete_plate(int index)
int old_cols = compute_colum_count(m_plate_list.size());
m_plate_list.erase(m_plate_list.begin() + index);
// Orca: custom G-codes are keyed by plate index, so re-key them for the plates after it.
remap_custom_gcodes(plate_ids_before);
update_plate_cols();
//update this plate
//move this plate's instance to the end
@@ -7090,6 +7093,24 @@ int PartPlateList::move_plate_to_index(int old_index, int new_index)
delta = -1;
}
const std::vector<ObjectID> plate_ids_before = get_plate_ids();
// Orca: wipe tower positions are stored per plate index, so move them with the plate.
if (m_plater) {
DynamicConfig& proj_cfg = wxGetApp().preset_bundle->project_config;
for (const char* key : { "wipe_tower_x", "wipe_tower_y" }) {
ConfigOptionFloats* opt = proj_cfg.opt<ConfigOptionFloats>(key);
if (opt->empty())
continue;
// Missing entries fall back to the first one; resize() fills them in with it.
if (opt->size() < m_plate_list.size())
opt->resize(m_plate_list.size());
const double moved = opt->values[old_index];
opt->values.erase(opt->values.begin() + old_index);
opt->values.insert(opt->values.begin() + new_index, moved);
}
}
PartPlate* plate = m_plate_list[old_index];
//update the plates between old_index and new_index
for (unsigned int i = (unsigned int)old_index; i != (unsigned int)new_index; i = i + delta)
@@ -7108,9 +7129,48 @@ int PartPlateList::move_plate_to_index(int old_index, int new_index)
//update the new plate index
m_current_plate = new_index;
remap_custom_gcodes(plate_ids_before);
return ret;
}
std::vector<ObjectID> PartPlateList::get_plate_ids() const
{
std::vector<ObjectID> ids;
for (const PartPlate* plate : m_plate_list)
ids.push_back(plate->id());
return ids;
}
void PartPlateList::remap_custom_gcodes(const std::vector<ObjectID>& plate_ids_before)
{
if (!m_model)
return;
// Move each plate's entry into the map keyed by plate ID; entries without a plate keep their index.
std::map<int, CustomGCode::Info> remapped;
for (auto& [idx, info] : m_model->plates_custom_gcodes) {
if (idx >= 0 && idx < (int)plate_ids_before.size())
m_custom_gcodes_by_plate_id[plate_ids_before[idx]] = std::move(info);
else
remapped[idx] = std::move(info);
}
// Put back the entries of plates that exist now.
for (auto it = m_custom_gcodes_by_plate_id.begin(); it != m_custom_gcodes_by_plate_id.end();) {
const ObjectID plate_id = it->first;
auto plate = std::find_if(m_plate_list.begin(), m_plate_list.end(), [plate_id](const PartPlate* p) { return p->id() == plate_id; });
if (plate == m_plate_list.end()) {
++it;
continue;
}
remapped[int(plate - m_plate_list.begin())] = std::move(it->second);
it = m_custom_gcodes_by_plate_id.erase(it);
}
m_model->plates_custom_gcodes = std::move(remapped);
}
//lock plate
int PartPlateList::lock_plate(int index, bool state)
{
+6
View File
@@ -13,6 +13,7 @@
#include "libslic3r/Color.hpp"
#include "libslic3r/GCode/ThumbnailData.hpp"
#include "libslic3r/PrintBase.hpp"
#include "libslic3r/CustomGCode.hpp"
#include <map>
#include <cstddef>
#include <cereal/access.hpp>
@@ -790,6 +791,8 @@ class PartPlateList : public ObjectBase
PrinterTechnology printer_technology;
std::vector<PartPlate*> m_plate_list;
// Orca: custom G-codes of plates removed by undo / redo, restored if the plate comes back.
std::map<ObjectID, CustomGCode::Info> m_custom_gcodes_by_plate_id;
std::map<int, PrintBase*> m_print_list;
std::map<int, GCodeResult*> m_gcode_result_list;
std::mutex m_plates_mutex;
@@ -1017,6 +1020,9 @@ public:
//move the plate to position index
int move_plate_to_index(int old_index, int new_index);
// Orca: custom G-codes are keyed by plate index; re-key them by plate ID after plates are reordered.
std::vector<ObjectID> get_plate_ids() const;
void remap_custom_gcodes(const std::vector<ObjectID>& plate_ids_before);
//lock plate
int lock_plate(int index, bool state);
+4 -1
View File
@@ -15827,10 +15827,13 @@ void Plater::priv::undo_redo_to(std::vector<UndoRedo::Snapshot>::const_iterator
// Make a copy of the snapshot, undo/redo could invalidate the iterator
const UndoRedo::Snapshot snapshot_copy = *it_snapshot;
// Orca: custom G-codes are not in the snapshot, so remap them by plate ID after the jump.
const std::vector<ObjectID> plate_ids_before = this->partplate_list.get_plate_ids();
// Do the jump in time.
if (it_snapshot->timestamp < this->undo_redo_stack().active_snapshot_time() ?
this->undo_redo_stack().undo(model, get_current_canvas3D()->get_canvas_type() == GLCanvas3D::CanvasAssembleView ? assemble_view->get_canvas3d()->get_selection() : this->view3D->get_canvas3d()->get_selection(), get_current_canvas3D()->get_canvas_type() == GLCanvas3D::CanvasAssembleView ? assemble_view->get_canvas3d()->get_gizmos_manager() : this->view3D->get_canvas3d()->get_gizmos_manager(), this->partplate_list, top_snapshot_data, it_snapshot->timestamp) :
this->undo_redo_stack().redo(model, get_current_canvas3D()->get_canvas_type() == GLCanvas3D::CanvasAssembleView ? assemble_view->get_canvas3d()->get_gizmos_manager() : this->view3D->get_canvas3d()->get_gizmos_manager(), this->partplate_list, it_snapshot->timestamp)) {
this->partplate_list.remap_custom_gcodes(plate_ids_before);
if (printer_technology_changed) {
// Switch to the other printer technology. Switch to the last printer active for that particular technology.
AppConfig *app_config = wxGetApp().app_config;
@@ -15877,7 +15880,7 @@ void Plater::priv::undo_redo_to(std::vector<UndoRedo::Snapshot>::const_iterator
tower_x_opt->set_at(&tower_x_new, plate_idx, 0);
tower_y_opt->set_at(&tower_y_new, plate_idx, 0);
need_update = true;
break;
// Orca: restore every plate, moving a plate changes several positions
}
}