Deletion of instances and volumes from 3D scene
This commit is contained in:
parent
3858fecf0c
commit
3613a54e03
9 changed files with 95 additions and 7 deletions
|
@ -2065,6 +2065,11 @@ void _3DScene::render(wxGLCanvas* canvas)
|
||||||
s_canvas_mgr.render(canvas);
|
s_canvas_mgr.render(canvas);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void _3DScene::delete_selected(wxGLCanvas* canvas)
|
||||||
|
{
|
||||||
|
s_canvas_mgr.delete_selected(canvas);
|
||||||
|
}
|
||||||
|
|
||||||
std::vector<double> _3DScene::get_current_print_zs(wxGLCanvas* canvas, bool active_only)
|
std::vector<double> _3DScene::get_current_print_zs(wxGLCanvas* canvas, bool active_only)
|
||||||
{
|
{
|
||||||
return s_canvas_mgr.get_current_print_zs(canvas, active_only);
|
return s_canvas_mgr.get_current_print_zs(canvas, active_only);
|
||||||
|
|
|
@ -618,6 +618,8 @@ public:
|
||||||
|
|
||||||
static void render(wxGLCanvas* canvas);
|
static void render(wxGLCanvas* canvas);
|
||||||
|
|
||||||
|
static void delete_selected(wxGLCanvas* canvas);
|
||||||
|
|
||||||
static std::vector<double> get_current_print_zs(wxGLCanvas* canvas, bool active_only);
|
static std::vector<double> get_current_print_zs(wxGLCanvas* canvas, bool active_only);
|
||||||
static void set_toolpaths_range(wxGLCanvas* canvas, double low, double high);
|
static void set_toolpaths_range(wxGLCanvas* canvas, double low, double high);
|
||||||
|
|
||||||
|
|
|
@ -28,6 +28,8 @@
|
||||||
#include "libslic3r/Print.hpp"
|
#include "libslic3r/Print.hpp"
|
||||||
#include "libslic3r/SLAPrint.hpp"
|
#include "libslic3r/SLAPrint.hpp"
|
||||||
|
|
||||||
|
#include "wxExtensions.hpp"
|
||||||
|
|
||||||
#include <tbb/parallel_for.h>
|
#include <tbb/parallel_for.h>
|
||||||
#include <tbb/spin_mutex.h>
|
#include <tbb/spin_mutex.h>
|
||||||
|
|
||||||
|
@ -1770,6 +1772,65 @@ void GLCanvas3D::Selection::translate(unsigned int object_idx, unsigned int inst
|
||||||
m_bounding_box_dirty = true;
|
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<ItemForDelete> 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<std::pair<int, int>> 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<ItemForDelete> items;
|
||||||
|
items.reserve(instances_idxs.size());
|
||||||
|
for (const std::pair<int, int>& i : instances_idxs)
|
||||||
|
{
|
||||||
|
items.emplace_back(ItemType::itInstance, i.first, i.second);
|
||||||
|
}
|
||||||
|
|
||||||
|
wxGetApp().obj_list()->delete_from_model_and_list(items);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
std::set<std::pair<int, int>> 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<ItemForDelete> items;
|
||||||
|
items.reserve(volumes_idxs.size());
|
||||||
|
for (const std::pair<int, int>& 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
|
void GLCanvas3D::Selection::render() const
|
||||||
{
|
{
|
||||||
if (is_empty())
|
if (is_empty())
|
||||||
|
@ -3612,6 +3673,11 @@ void GLCanvas3D::render()
|
||||||
m_canvas->SwapBuffers();
|
m_canvas->SwapBuffers();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void GLCanvas3D::delete_selected()
|
||||||
|
{
|
||||||
|
m_selection.erase();
|
||||||
|
}
|
||||||
|
|
||||||
std::vector<double> GLCanvas3D::get_current_print_zs(bool active_only) const
|
std::vector<double> GLCanvas3D::get_current_print_zs(bool active_only) const
|
||||||
{
|
{
|
||||||
return m_volumes.get_current_print_zs(active_only);
|
return m_volumes.get_current_print_zs(active_only);
|
||||||
|
@ -4442,7 +4508,7 @@ void GLCanvas3D::on_key_down(wxKeyEvent& evt)
|
||||||
{
|
{
|
||||||
#ifdef __WXOSX__
|
#ifdef __WXOSX__
|
||||||
if (key == WXK_BACK)
|
if (key == WXK_BACK)
|
||||||
post_event(SimpleEvent(EVT_GLCANVAS_REMOVE_OBJECT));
|
post_event(SimpleEvent(EVT_GLCANVAS_REMOVE_OBJECT));
|
||||||
#endif
|
#endif
|
||||||
evt.Skip();
|
evt.Skip();
|
||||||
}
|
}
|
||||||
|
|
|
@ -536,6 +536,8 @@ public:
|
||||||
void translate(unsigned int object_idx, const Vec3d& displacement);
|
void translate(unsigned int object_idx, const Vec3d& displacement);
|
||||||
void translate(unsigned int object_idx, unsigned int instance_idx, const Vec3d& displacement);
|
void translate(unsigned int object_idx, unsigned int instance_idx, const Vec3d& displacement);
|
||||||
|
|
||||||
|
void erase();
|
||||||
|
|
||||||
void render() const;
|
void render() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -815,6 +817,8 @@ public:
|
||||||
|
|
||||||
void render();
|
void render();
|
||||||
|
|
||||||
|
void delete_selected();
|
||||||
|
|
||||||
std::vector<double> get_current_print_zs(bool active_only) const;
|
std::vector<double> get_current_print_zs(bool active_only) const;
|
||||||
void set_toolpaths_range(double low, double high);
|
void set_toolpaths_range(double low, double high);
|
||||||
|
|
||||||
|
|
|
@ -500,6 +500,13 @@ void GLCanvas3DManager::render(wxGLCanvas* canvas) const
|
||||||
it->second->render();
|
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<double> GLCanvas3DManager::get_current_print_zs(wxGLCanvas* canvas, bool active_only) const
|
std::vector<double> GLCanvas3DManager::get_current_print_zs(wxGLCanvas* canvas, bool active_only) const
|
||||||
{
|
{
|
||||||
CanvasesMap::const_iterator it = _get_canvas(canvas);
|
CanvasesMap::const_iterator it = _get_canvas(canvas);
|
||||||
|
|
|
@ -140,6 +140,8 @@ public:
|
||||||
|
|
||||||
void render(wxGLCanvas* canvas) const;
|
void render(wxGLCanvas* canvas) const;
|
||||||
|
|
||||||
|
void delete_selected(wxGLCanvas* canvas);
|
||||||
|
|
||||||
std::vector<double> get_current_print_zs(wxGLCanvas* canvas, bool active_only) const;
|
std::vector<double> get_current_print_zs(wxGLCanvas* canvas, bool active_only) const;
|
||||||
void set_toolpaths_range(wxGLCanvas* canvas, double low, double high);
|
void set_toolpaths_range(wxGLCanvas* canvas, double low, double high);
|
||||||
|
|
||||||
|
|
|
@ -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<ItemForDelete> * items_for_delete)
|
void ObjectList::delete_from_model_and_list(const std::vector<ItemForDelete>& items_for_delete)
|
||||||
{
|
{
|
||||||
for (auto& item : *items_for_delete)
|
for (auto& item : items_for_delete)
|
||||||
{
|
{
|
||||||
if ( !(item.type&(itObject|itVolume|itInstance)) )
|
if ( !(item.type&(itObject|itVolume|itInstance)) )
|
||||||
continue;
|
continue;
|
||||||
|
|
|
@ -27,6 +27,10 @@ struct ItemForDelete
|
||||||
ItemType type;
|
ItemType type;
|
||||||
int obj_idx;
|
int obj_idx;
|
||||||
int sub_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
|
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_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_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 ItemType type, const int obj_idx, const int sub_obj_idx);
|
||||||
void delete_from_model_and_list(const std::vector<ItemForDelete> * items_for_delete);
|
void delete_from_model_and_list(const std::vector<ItemForDelete>& items_for_delete);
|
||||||
// Delete all objects from the list
|
// Delete all objects from the list
|
||||||
void delete_all_objects_from_list();
|
void delete_all_objects_from_list();
|
||||||
// Increase instances count
|
// Increase instances count
|
||||||
|
|
|
@ -2121,9 +2121,7 @@ void Plater::delete_object_from_model(size_t obj_idx) { p->delete_object_from_mo
|
||||||
|
|
||||||
void Plater::remove_selected()
|
void Plater::remove_selected()
|
||||||
{
|
{
|
||||||
int obj_idx = p->get_selected_object_idx();
|
_3DScene::delete_selected(canvas3D());
|
||||||
if (obj_idx != -1)
|
|
||||||
remove((size_t)obj_idx);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Plater::increase_instances(size_t num)
|
void Plater::increase_instances(size_t num)
|
||||||
|
|
Loading…
Reference in a new issue