diff --git a/src/slic3r/GUI/PartPlate.cpp b/src/slic3r/GUI/PartPlate.cpp index 6de7d0c94d..43aa398d8b 100644 --- a/src/slic3r/GUI/PartPlate.cpp +++ b/src/slic3r/GUI/PartPlate.cpp @@ -6719,6 +6719,7 @@ int PartPlateList::delete_plate(int index) return -1; } const std::string plate_name = plate->get_plate_name(); + const std::vector 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 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(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 PartPlateList::get_plate_ids() const +{ + std::vector ids; + for (const PartPlate* plate : m_plate_list) + ids.push_back(plate->id()); + return ids; +} + +void PartPlateList::remap_custom_gcodes(const std::vector& 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 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) { diff --git a/src/slic3r/GUI/PartPlate.hpp b/src/slic3r/GUI/PartPlate.hpp index 32b344774b..d008f44ef6 100644 --- a/src/slic3r/GUI/PartPlate.hpp +++ b/src/slic3r/GUI/PartPlate.hpp @@ -13,6 +13,7 @@ #include "libslic3r/Color.hpp" #include "libslic3r/GCode/ThumbnailData.hpp" #include "libslic3r/PrintBase.hpp" +#include "libslic3r/CustomGCode.hpp" #include #include #include @@ -790,6 +791,8 @@ class PartPlateList : public ObjectBase PrinterTechnology printer_technology; std::vector m_plate_list; + // Orca: custom G-codes of plates removed by undo / redo, restored if the plate comes back. + std::map m_custom_gcodes_by_plate_id; std::map m_print_list; std::map 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 get_plate_ids() const; + void remap_custom_gcodes(const std::vector& plate_ids_before); //lock plate int lock_plate(int index, bool state); diff --git a/src/slic3r/GUI/Plater.cpp b/src/slic3r/GUI/Plater.cpp index fecac3a46f..f2af419807 100644 --- a/src/slic3r/GUI/Plater.cpp +++ b/src/slic3r/GUI/Plater.cpp @@ -15827,10 +15827,13 @@ void Plater::priv::undo_redo_to(std::vector::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 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::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 } }