diff --git a/src/slic3r/GUI/3DScene.cpp b/src/slic3r/GUI/3DScene.cpp index e381cb854..d6790abe1 100644 --- a/src/slic3r/GUI/3DScene.cpp +++ b/src/slic3r/GUI/3DScene.cpp @@ -2065,6 +2065,11 @@ void _3DScene::render(wxGLCanvas* canvas) s_canvas_mgr.render(canvas); } +void _3DScene::delete_selected(wxGLCanvas* canvas) +{ + s_canvas_mgr.delete_selected(canvas); +} + std::vector _3DScene::get_current_print_zs(wxGLCanvas* canvas, bool active_only) { return s_canvas_mgr.get_current_print_zs(canvas, active_only); diff --git a/src/slic3r/GUI/3DScene.hpp b/src/slic3r/GUI/3DScene.hpp index 9761ba3b6..e54532cd5 100644 --- a/src/slic3r/GUI/3DScene.hpp +++ b/src/slic3r/GUI/3DScene.hpp @@ -618,6 +618,8 @@ public: static void render(wxGLCanvas* canvas); + static void delete_selected(wxGLCanvas* canvas); + static std::vector get_current_print_zs(wxGLCanvas* canvas, bool active_only); static void set_toolpaths_range(wxGLCanvas* canvas, double low, double high); diff --git a/src/slic3r/GUI/GLCanvas3D.cpp b/src/slic3r/GUI/GLCanvas3D.cpp index 6d089b5b2..3e405ffe1 100644 --- a/src/slic3r/GUI/GLCanvas3D.cpp +++ b/src/slic3r/GUI/GLCanvas3D.cpp @@ -28,6 +28,8 @@ #include "libslic3r/Print.hpp" #include "libslic3r/SLAPrint.hpp" +#include "wxExtensions.hpp" + #include #include @@ -1770,6 +1772,65 @@ void GLCanvas3D::Selection::translate(unsigned int object_idx, unsigned int inst m_bounding_box_dirty = true; } +void GLCanvas3D::Selection::erase() +{ + if (!m_valid) + return; + + if (is_single_full_object()) + wxGetApp().obj_list()->delete_from_model_and_list(ItemType::itObject, get_object_idx(), 0); + else if (is_multiple_full_object()) + { + std::vector items; + items.reserve(m_cache.content.size()); + for (ObjectIdxsToInstanceIdxsMap::iterator it = m_cache.content.begin(); it != m_cache.content.end(); ++it) + { + items.emplace_back(ItemType::itObject, it->first, 0); + } + wxGetApp().obj_list()->delete_from_model_and_list(items); + } + else if (is_single_full_instance()) + wxGetApp().obj_list()->delete_from_model_and_list(ItemType::itInstance, get_object_idx(), get_instance_idx()); + else if (is_multiple_full_instance()) + { + std::set> instances_idxs; + for (ObjectIdxsToInstanceIdxsMap::iterator obj_it = m_cache.content.begin(); obj_it != m_cache.content.end(); ++obj_it) + { + for (InstanceIdxsList::reverse_iterator inst_it = obj_it->second.rbegin(); inst_it != obj_it->second.rend(); ++inst_it) + { + instances_idxs.insert(std::make_pair(obj_it->first, *inst_it)); + } + } + + std::vector items; + items.reserve(instances_idxs.size()); + for (const std::pair& i : instances_idxs) + { + items.emplace_back(ItemType::itInstance, i.first, i.second); + } + + wxGetApp().obj_list()->delete_from_model_and_list(items); + } + else + { + std::set> volumes_idxs; + for (unsigned int i : m_list) + { + const GLVolume* v = (*m_volumes)[i]; + volumes_idxs.insert(std::make_pair(v->object_idx(), v->volume_idx())); + } + + std::vector items; + items.reserve(volumes_idxs.size()); + for (const std::pair& v : volumes_idxs) + { + items.emplace_back(ItemType::itVolume, v.first, v.second); + } + + wxGetApp().obj_list()->delete_from_model_and_list(items); + } +} + void GLCanvas3D::Selection::render() const { if (is_empty()) @@ -3612,6 +3673,11 @@ void GLCanvas3D::render() m_canvas->SwapBuffers(); } +void GLCanvas3D::delete_selected() +{ + m_selection.erase(); +} + std::vector GLCanvas3D::get_current_print_zs(bool active_only) const { return m_volumes.get_current_print_zs(active_only); @@ -4442,7 +4508,7 @@ void GLCanvas3D::on_key_down(wxKeyEvent& evt) { #ifdef __WXOSX__ if (key == WXK_BACK) - post_event(SimpleEvent(EVT_GLCANVAS_REMOVE_OBJECT)); + post_event(SimpleEvent(EVT_GLCANVAS_REMOVE_OBJECT)); #endif evt.Skip(); } diff --git a/src/slic3r/GUI/GLCanvas3D.hpp b/src/slic3r/GUI/GLCanvas3D.hpp index eb45bddb5..ab051229f 100644 --- a/src/slic3r/GUI/GLCanvas3D.hpp +++ b/src/slic3r/GUI/GLCanvas3D.hpp @@ -536,6 +536,8 @@ public: void translate(unsigned int object_idx, const Vec3d& displacement); void translate(unsigned int object_idx, unsigned int instance_idx, const Vec3d& displacement); + void erase(); + void render() const; private: @@ -815,6 +817,8 @@ public: void render(); + void delete_selected(); + std::vector get_current_print_zs(bool active_only) const; void set_toolpaths_range(double low, double high); diff --git a/src/slic3r/GUI/GLCanvas3DManager.cpp b/src/slic3r/GUI/GLCanvas3DManager.cpp index d38b2f193..062360041 100644 --- a/src/slic3r/GUI/GLCanvas3DManager.cpp +++ b/src/slic3r/GUI/GLCanvas3DManager.cpp @@ -500,6 +500,13 @@ void GLCanvas3DManager::render(wxGLCanvas* canvas) const it->second->render(); } +void GLCanvas3DManager::delete_selected(wxGLCanvas* canvas) +{ + CanvasesMap::const_iterator it = _get_canvas(canvas); + if (it != m_canvases.end()) + it->second->delete_selected(); +} + std::vector GLCanvas3DManager::get_current_print_zs(wxGLCanvas* canvas, bool active_only) const { CanvasesMap::const_iterator it = _get_canvas(canvas); diff --git a/src/slic3r/GUI/GLCanvas3DManager.hpp b/src/slic3r/GUI/GLCanvas3DManager.hpp index 232c928f3..89f0d48fc 100644 --- a/src/slic3r/GUI/GLCanvas3DManager.hpp +++ b/src/slic3r/GUI/GLCanvas3DManager.hpp @@ -140,6 +140,8 @@ public: void render(wxGLCanvas* canvas) const; + void delete_selected(wxGLCanvas* canvas); + std::vector get_current_print_zs(wxGLCanvas* canvas, bool active_only) const; void set_toolpaths_range(wxGLCanvas* canvas, double low, double high); diff --git a/src/slic3r/GUI/GUI_ObjectList.cpp b/src/slic3r/GUI/GUI_ObjectList.cpp index 77cd1c440..1d8463e92 100644 --- a/src/slic3r/GUI/GUI_ObjectList.cpp +++ b/src/slic3r/GUI/GUI_ObjectList.cpp @@ -1180,9 +1180,9 @@ void ObjectList::delete_from_model_and_list(const ItemType type, const int obj_i } } -void ObjectList::delete_from_model_and_list(const std::vector * items_for_delete) +void ObjectList::delete_from_model_and_list(const std::vector& items_for_delete) { - for (auto& item : *items_for_delete) + for (auto& item : items_for_delete) { if ( !(item.type&(itObject|itVolume|itInstance)) ) continue; diff --git a/src/slic3r/GUI/GUI_ObjectList.hpp b/src/slic3r/GUI/GUI_ObjectList.hpp index c06cf6e51..31ae5f5ed 100644 --- a/src/slic3r/GUI/GUI_ObjectList.hpp +++ b/src/slic3r/GUI/GUI_ObjectList.hpp @@ -27,6 +27,10 @@ struct ItemForDelete ItemType type; int obj_idx; int sub_obj_idx; + + ItemForDelete(ItemType type, int obj_idx, int sub_obj_idx) + : type(type), obj_idx(obj_idx), sub_obj_idx(sub_obj_idx) + {} }; class ObjectList : public wxDataViewCtrl @@ -128,7 +132,7 @@ public: void delete_volume_from_list(const size_t obj_idx, const size_t vol_idx); void delete_instance_from_list(const size_t obj_idx, const size_t inst_idx); void delete_from_model_and_list(const ItemType type, const int obj_idx, const int sub_obj_idx); - void delete_from_model_and_list(const std::vector * items_for_delete); + void delete_from_model_and_list(const std::vector& items_for_delete); // Delete all objects from the list void delete_all_objects_from_list(); // Increase instances count diff --git a/src/slic3r/GUI/Plater.cpp b/src/slic3r/GUI/Plater.cpp index 6e30c6794..3715843fb 100644 --- a/src/slic3r/GUI/Plater.cpp +++ b/src/slic3r/GUI/Plater.cpp @@ -2121,9 +2121,7 @@ void Plater::delete_object_from_model(size_t obj_idx) { p->delete_object_from_mo void Plater::remove_selected() { - int obj_idx = p->get_selected_object_idx(); - if (obj_idx != -1) - remove((size_t)obj_idx); + _3DScene::delete_selected(canvas3D()); } void Plater::increase_instances(size_t num)