diff --git a/src/slic3r/GUI/Selection.cpp b/src/slic3r/GUI/Selection.cpp index 58d5e15fe3..4d7f1591ee 100644 --- a/src/slic3r/GUI/Selection.cpp +++ b/src/slic3r/GUI/Selection.cpp @@ -474,17 +474,14 @@ void Selection::add_curr_plate() if (!m_valid) return; + std::vector volume_idxs = get_volume_idxs_from_plate(wxGetApp().plater()->get_partplate_list().get_curr_plate_index()); + if (volume_idxs.empty()) + return; + wxGetApp().plater()->take_snapshot(std::string("Selection-Add Curr Plate All!")); m_mode = Instance; clear(); - - PartPlate* plate = wxGetApp().plater()->get_partplate_list().get_curr_plate(); - for (int obj_idx = 0; obj_idx < m_model->objects.size(); obj_idx++) { - if (plate && plate->contain_instance_totally(obj_idx, 0)) { - std::vector volume_idxs = get_volume_idxs_from_object(obj_idx); - do_add_volumes(volume_idxs); - } - } + do_add_volumes(volume_idxs); update_type(); this->set_bounding_boxes_dirty(); @@ -511,20 +508,14 @@ void Selection::remove_curr_plate() if (!m_valid) return; - PartPlate* plate = wxGetApp().plater()->get_partplate_list().get_curr_plate(); - if (plate->empty()) + std::vector volume_idxs = get_volume_idxs_from_plate(wxGetApp().plater()->get_partplate_list().get_curr_plate_index()); + if (volume_idxs.empty()) return; wxGetApp().plater()->take_snapshot(std::string("Selection-Delete Curr Plate All")); m_mode = Instance; clear(); - - for (int obj_idx = 0; obj_idx < m_model->objects.size(); obj_idx++) { - if (plate && plate->contain_instance(obj_idx, 0)) { - std::vector volume_idxs = get_volume_idxs_from_object(obj_idx); - do_add_volumes(volume_idxs); - } - } + do_add_volumes(volume_idxs); update_type(); this->set_bounding_boxes_dirty(); @@ -2270,6 +2261,27 @@ std::vector Selection::get_volume_idxs_from_volume(unsigned int ob return idxs; } +std::vector Selection::get_volume_idxs_from_plate(const int plate_idx) const +{ + PartPlate* plate = wxGetApp().plater()->get_partplate_list().get_plate(plate_idx); + std::vector idxs; + if (!plate) + return idxs; + + for (int obj_idx = 0; obj_idx < (int)m_model->objects.size(); obj_idx++) { + const ModelObject* obj = m_model->objects[obj_idx]; + for (int inst_idx = 0; inst_idx < (int)obj->instances.size(); inst_idx++) { + // on this plate or overlapping it in some way (fully inside, oversized or partly outside) + if (plate->contain_instance(obj_idx, inst_idx) || plate->intersect_instance(obj_idx, inst_idx)) { + std::vector inst_idxs = get_volume_idxs_from_instance(obj_idx, inst_idx); + idxs.insert(idxs.end(), inst_idxs.begin(), inst_idxs.end()); + } + } + } + + return idxs; +} + std::vector Selection::get_missing_volume_idxs_from(const std::vector& volume_idxs) const { std::vector idxs; diff --git a/src/slic3r/GUI/Selection.hpp b/src/slic3r/GUI/Selection.hpp index dcee38a813..a02f01da00 100644 --- a/src/slic3r/GUI/Selection.hpp +++ b/src/slic3r/GUI/Selection.hpp @@ -409,6 +409,8 @@ public: std::vector get_volume_idxs_from_instance(unsigned int object_idx, unsigned int instance_idx) const; // returns the idx of the volume corresponding to the volume with the given idxs std::vector get_volume_idxs_from_volume(unsigned int object_idx, unsigned int instance_idx, unsigned int volume_idx) const; + // returns the list of idxs of the volumes of all instances on the given plate or overlapping it. (fully inside, oversized or partly outside) + std::vector get_volume_idxs_from_plate(const int plate_idx) const; // returns the list of idxs of the volumes contained in the selection but not in the given list std::vector get_missing_volume_idxs_from(const std::vector& volume_idxs) const; // returns the list of idxs of the volumes contained in the given list but not in the selection