diff --git a/src/slic3r/GUI/Plater.cpp b/src/slic3r/GUI/Plater.cpp index 5808b196d..6adabb7d6 100644 --- a/src/slic3r/GUI/Plater.cpp +++ b/src/slic3r/GUI/Plater.cpp @@ -6057,7 +6057,7 @@ void Plater::remove_selected() p->view3D->delete_selected(); } -void Plater::increase_instances(size_t num, int obj_idx/* = -1*/) +void Plater::increase_instances(size_t num, int obj_idx, std::optional selection_map) { if (! can_increase_instances()) { return; } @@ -6067,14 +6067,26 @@ void Plater::increase_instances(size_t num, int obj_idx/* = -1*/) obj_idx = p->get_selected_object_idx(); if (obj_idx < 0) { - if (const auto obj_idxs = get_selection().get_object_idxs(); !obj_idxs.empty()) - for (const size_t obj_id : obj_idxs) - increase_instances(1, int(obj_id)); + if (const auto obj_idxs = get_selection().get_object_idxs(); !obj_idxs.empty()) { + // we need a copy made here because the selection changes at every call of increase_instances() + const Selection::ObjectIdxsToInstanceIdxsMap content = selection_map.has_value() ? *selection_map : p->get_selection().get_content(); + for (const size_t obj_id : obj_idxs) { + increase_instances(1, int(obj_id), content); + } + } return; } ModelObject* model_object = p->model.objects[obj_idx]; - const int inst_idx = p->get_selected_instance_idx(); + int inst_idx = -1; + if (selection_map.has_value()) { + auto obj_it = selection_map->find(obj_idx); + if (obj_it != selection_map->end() && obj_it->second.size() == 1) + inst_idx = *obj_it->second.begin(); + } + else + inst_idx = p->get_selected_instance_idx(); + ModelInstance* model_instance = (inst_idx >= 0) ? model_object->instances[inst_idx] : model_object->instances.back(); bool was_one_instance = model_object->instances.size()==1; diff --git a/src/slic3r/GUI/Plater.hpp b/src/slic3r/GUI/Plater.hpp index fa2ec6508..a76ef6f1c 100644 --- a/src/slic3r/GUI/Plater.hpp +++ b/src/slic3r/GUI/Plater.hpp @@ -250,7 +250,7 @@ public: void reset_with_confirm(); bool delete_object_from_model(size_t obj_idx); void remove_selected(); - void increase_instances(size_t num = 1, int obj_idx = -1); + void increase_instances(size_t num = 1, int obj_idx = -1, std::optional selection_map = std::nullopt); void decrease_instances(size_t num = 1, int obj_idx = -1); void set_number_of_copies(); void fill_bed_with_instances();