From bc2e6819323ce114a92e63381980517543838ffc Mon Sep 17 00:00:00 2001 From: enricoturri1966 Date: Thu, 20 Apr 2023 14:00:19 +0200 Subject: [PATCH] SPE-1669 and follow-up of c1e145b86c6da0fedf257f39c79934d2d80b46d4 - Fixed crash introduced with the previous commit and extend the new functionality to multi-objects selections --- src/slic3r/GUI/Plater.cpp | 22 +++++++++++++++++----- src/slic3r/GUI/Plater.hpp | 2 +- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/src/slic3r/GUI/Plater.cpp b/src/slic3r/GUI/Plater.cpp index 5808b196d0..6adabb7d68 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 fa2ec65080..a76ef6f1cb 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();