Ensure object on bed after deletion of subpart

This commit is contained in:
Enrico Turri 2018-11-21 12:27:20 +01:00
parent 9996369e2c
commit ee99fa2c64
7 changed files with 46 additions and 0 deletions

View File

@ -2050,6 +2050,11 @@ void _3DScene::delete_selected(wxGLCanvas* canvas)
s_canvas_mgr.delete_selected(canvas);
}
void _3DScene::ensure_on_bed(wxGLCanvas* canvas, unsigned int object_idx)
{
s_canvas_mgr.ensure_on_bed(canvas, object_idx);
}
std::vector<double> _3DScene::get_current_print_zs(wxGLCanvas* canvas, bool active_only)
{
return s_canvas_mgr.get_current_print_zs(canvas, active_only);

View File

@ -634,6 +634,7 @@ public:
static void render(wxGLCanvas* canvas);
static void delete_selected(wxGLCanvas* canvas);
static void ensure_on_bed(wxGLCanvas* canvas, unsigned int object_idx);
static std::vector<double> get_current_print_zs(wxGLCanvas* canvas, bool active_only);
static void set_toolpaths_range(wxGLCanvas* canvas, double low, double high);

View File

@ -3692,6 +3692,34 @@ void GLCanvas3D::delete_selected()
m_selection.erase();
}
void GLCanvas3D::ensure_on_bed(unsigned int object_idx)
{
typedef std::map<std::pair<int, int>, double> InstancesToZMap;
InstancesToZMap instances_min_z;
for (GLVolume* volume : m_volumes.volumes)
{
if ((volume->object_idx() == object_idx) && !volume->is_modifier)
{
double min_z = volume->transformed_convex_hull_bounding_box().min(2);
std::pair<int, int> instance = std::make_pair(volume->object_idx(), volume->instance_idx());
InstancesToZMap::iterator it = instances_min_z.find(instance);
if (it == instances_min_z.end())
it = instances_min_z.insert(InstancesToZMap::value_type(instance, DBL_MAX)).first;
it->second = std::min(it->second, min_z);
}
}
for (GLVolume* volume : m_volumes.volumes)
{
std::pair<int, int> instance = std::make_pair(volume->object_idx(), volume->instance_idx());
InstancesToZMap::iterator it = instances_min_z.find(instance);
if (it != instances_min_z.end())
volume->set_instance_offset(Z, volume->get_instance_offset(Z) - it->second);
}
}
std::vector<double> GLCanvas3D::get_current_print_zs(bool active_only) const
{
return m_volumes.get_current_print_zs(active_only);

View File

@ -814,6 +814,7 @@ public:
void render();
void delete_selected();
void ensure_on_bed(unsigned int object_idx);
std::vector<double> get_current_print_zs(bool active_only) const;
void set_toolpaths_range(double low, double high);

View File

@ -461,6 +461,13 @@ void GLCanvas3DManager::delete_selected(wxGLCanvas* canvas)
it->second->delete_selected();
}
void GLCanvas3DManager::ensure_on_bed(wxGLCanvas* canvas, unsigned int object_idx)
{
CanvasesMap::const_iterator it = _get_canvas(canvas);
if (it != m_canvases.end())
it->second->ensure_on_bed(object_idx);
}
std::vector<double> GLCanvas3DManager::get_current_print_zs(wxGLCanvas* canvas, bool active_only) const
{
CanvasesMap::const_iterator it = _get_canvas(canvas);

View File

@ -131,6 +131,7 @@ public:
void render(wxGLCanvas* canvas) const;
void delete_selected(wxGLCanvas* canvas);
void ensure_on_bed(wxGLCanvas* canvas, unsigned int object_idx);
std::vector<double> get_current_print_zs(wxGLCanvas* canvas, bool active_only) const;
void set_toolpaths_range(wxGLCanvas* canvas, double low, double high);

View File

@ -1205,7 +1205,10 @@ void ObjectList::delete_from_model_and_list(const std::vector<ItemForDelete>& it
else {
del_subobject_from_object(item->obj_idx, item->sub_obj_idx, item->type);
if (item->type&itVolume)
{
m_objects_model->Delete(m_objects_model->GetItemByVolumeId(item->obj_idx, item->sub_obj_idx));
_3DScene::ensure_on_bed(wxGetApp().canvas3D(), item->obj_idx);
}
else
m_objects_model->Delete(m_objects_model->GetItemByInstanceId(item->obj_idx, item->sub_obj_idx));
}