Modified logic to add snapshots to undo/redo stack using GLCanvas::do_xxxxxx() methods

This commit is contained in:
Enrico Turri 2019-07-09 10:18:57 +02:00
parent 7b6229289d
commit d4914441f3
5 changed files with 50 additions and 34 deletions

View file

@ -1799,7 +1799,7 @@ std::vector<int> GLCanvas3D::load_object(const Model& model, int obj_idx)
void GLCanvas3D::mirror_selection(Axis axis) void GLCanvas3D::mirror_selection(Axis axis)
{ {
m_selection.mirror(axis); m_selection.mirror(axis);
do_mirror(); do_mirror("Mirror Object");
wxGetApp().obj_manipul()->set_dirty(); wxGetApp().obj_manipul()->set_dirty();
} }
@ -2947,8 +2947,7 @@ void GLCanvas3D::on_mouse(wxMouseEvent& evt)
else if ((m_mouse.drag.move_volume_idx != -1) && m_mouse.dragging) else if ((m_mouse.drag.move_volume_idx != -1) && m_mouse.dragging)
{ {
m_regenerate_volumes = false; m_regenerate_volumes = false;
wxGetApp().plater()->take_snapshot(_(L("Move Object"))); do_move("Move Object");
do_move();
wxGetApp().obj_manipul()->set_dirty(); wxGetApp().obj_manipul()->set_dirty();
// Let the plater know that the dragging finished, so a delayed refresh // Let the plater know that the dragging finished, so a delayed refresh
// of the scene with the background processing data should be performed. // of the scene with the background processing data should be performed.
@ -3107,11 +3106,14 @@ void GLCanvas3D::set_tooltip(const std::string& tooltip) const
} }
void GLCanvas3D::do_move() void GLCanvas3D::do_move(const std::string& snapshot_type)
{ {
if (m_model == nullptr) if (m_model == nullptr)
return; return;
if (!snapshot_type.empty())
wxGetApp().plater()->take_snapshot(_(L(snapshot_type)));
std::set<std::pair<int, int>> done; // keeps track of modified instances std::set<std::pair<int, int>> done; // keeps track of modified instances
bool object_moved = false; bool object_moved = false;
Vec3d wipe_tower_origin = Vec3d::Zero(); Vec3d wipe_tower_origin = Vec3d::Zero();
@ -3162,13 +3164,18 @@ void GLCanvas3D::do_move()
if (wipe_tower_origin != Vec3d::Zero()) if (wipe_tower_origin != Vec3d::Zero())
post_event(Vec3dEvent(EVT_GLCANVAS_WIPETOWER_MOVED, std::move(wipe_tower_origin))); post_event(Vec3dEvent(EVT_GLCANVAS_WIPETOWER_MOVED, std::move(wipe_tower_origin)));
m_dirty = true;
} }
void GLCanvas3D::do_rotate() void GLCanvas3D::do_rotate(const std::string& snapshot_type)
{ {
if (m_model == nullptr) if (m_model == nullptr)
return; return;
if (!snapshot_type.empty())
wxGetApp().plater()->take_snapshot(_(L(snapshot_type)));
std::set<std::pair<int, int>> done; // keeps track of modified instances std::set<std::pair<int, int>> done; // keeps track of modified instances
Selection::EMode selection_mode = m_selection.get_mode(); Selection::EMode selection_mode = m_selection.get_mode();
@ -3217,13 +3224,18 @@ void GLCanvas3D::do_rotate()
if (!done.empty()) if (!done.empty())
post_event(SimpleEvent(EVT_GLCANVAS_INSTANCE_ROTATED)); post_event(SimpleEvent(EVT_GLCANVAS_INSTANCE_ROTATED));
m_dirty = true;
} }
void GLCanvas3D::do_scale() void GLCanvas3D::do_scale(const std::string& snapshot_type)
{ {
if (m_model == nullptr) if (m_model == nullptr)
return; return;
if (!snapshot_type.empty())
wxGetApp().plater()->take_snapshot(_(L(snapshot_type)));
std::set<std::pair<int, int>> done; // keeps track of modified instances std::set<std::pair<int, int>> done; // keeps track of modified instances
Selection::EMode selection_mode = m_selection.get_mode(); Selection::EMode selection_mode = m_selection.get_mode();
@ -3269,18 +3281,27 @@ void GLCanvas3D::do_scale()
if (!done.empty()) if (!done.empty())
post_event(SimpleEvent(EVT_GLCANVAS_INSTANCE_ROTATED)); post_event(SimpleEvent(EVT_GLCANVAS_INSTANCE_ROTATED));
m_dirty = true;
} }
void GLCanvas3D::do_flatten() void GLCanvas3D::do_flatten(const Vec3d& normal, const std::string& snapshot_type)
{ {
do_rotate(); if (!snapshot_type.empty())
wxGetApp().plater()->take_snapshot(_(L(snapshot_type)));
m_selection.flattening_rotate(normal);
do_rotate(""); // avoid taking another snapshot
} }
void GLCanvas3D::do_mirror() void GLCanvas3D::do_mirror(const std::string& snapshot_type)
{ {
if (m_model == nullptr) if (m_model == nullptr)
return; return;
if (!snapshot_type.empty())
wxGetApp().plater()->take_snapshot(_(L(snapshot_type)));
std::set<std::pair<int, int>> done; // keeps track of modified instances std::set<std::pair<int, int>> done; // keeps track of modified instances
Selection::EMode selection_mode = m_selection.get_mode(); Selection::EMode selection_mode = m_selection.get_mode();
@ -3319,6 +3340,8 @@ void GLCanvas3D::do_mirror()
} }
post_event(SimpleEvent(EVT_GLCANVAS_SCHEDULE_BACKGROUND_PROCESS)); post_event(SimpleEvent(EVT_GLCANVAS_SCHEDULE_BACKGROUND_PROCESS));
m_dirty = true;
} }
void GLCanvas3D::set_camera_zoom(double zoom) void GLCanvas3D::set_camera_zoom(double zoom)

View file

@ -599,11 +599,12 @@ public:
void set_tooltip(const std::string& tooltip) const; void set_tooltip(const std::string& tooltip) const;
void do_move(); // the following methods add a snapshot to the undo/redo stack, unless the given string is empty
void do_rotate(); void do_move(const std::string& snapshot_type);
void do_scale(); void do_rotate(const std::string& snapshot_type);
void do_flatten(); void do_scale(const std::string& snapshot_type);
void do_mirror(); void do_flatten(const Vec3d& normal, const std::string& snapshot_type);
void do_mirror(const std::string& snapshot_type);
void set_camera_zoom(double zoom); void set_camera_zoom(double zoom);

View file

@ -220,8 +220,7 @@ ObjectManipulation::ObjectManipulation(wxWindow* parent) :
selection.synchronize_unselected_instances(Selection::SYNC_ROTATION_GENERAL); selection.synchronize_unselected_instances(Selection::SYNC_ROTATION_GENERAL);
selection.synchronize_unselected_volumes(); selection.synchronize_unselected_volumes();
// Copy mirroring values from GLVolumes into Model (ModelInstance / ModelVolume), trigger background processing. // Copy mirroring values from GLVolumes into Model (ModelInstance / ModelVolume), trigger background processing.
canvas->do_mirror(); canvas->do_mirror("Set Mirror");
canvas->set_as_dirty();
UpdateAndShow(true); UpdateAndShow(true);
}); });
return sizer; return sizer;
@ -302,8 +301,7 @@ ObjectManipulation::ObjectManipulation(wxWindow* parent) :
selection.synchronize_unselected_instances(Selection::SYNC_ROTATION_GENERAL); selection.synchronize_unselected_instances(Selection::SYNC_ROTATION_GENERAL);
selection.synchronize_unselected_volumes(); selection.synchronize_unselected_volumes();
// Copy rotation values from GLVolumes into Model (ModelInstance / ModelVolume), trigger background processing. // Copy rotation values from GLVolumes into Model (ModelInstance / ModelVolume), trigger background processing.
wxGetApp().plater()->take_snapshot(_(L("Set Rotation"))); canvas->do_rotate("Set Rotation");
canvas->do_rotate();
UpdateAndShow(true); UpdateAndShow(true);
}); });
@ -656,8 +654,7 @@ void ObjectManipulation::change_position_value(int axis, double value)
Selection& selection = canvas->get_selection(); Selection& selection = canvas->get_selection();
selection.start_dragging(); selection.start_dragging();
selection.translate(position - m_cache.position, selection.requires_local_axes()); selection.translate(position - m_cache.position, selection.requires_local_axes());
wxGetApp().plater()->take_snapshot(_(L("Set Position"))); canvas->do_move("Set Position");
canvas->do_move();
m_cache.position = position; m_cache.position = position;
m_cache.position_rounded(axis) = DBL_MAX; m_cache.position_rounded(axis) = DBL_MAX;
@ -688,8 +685,7 @@ void ObjectManipulation::change_rotation_value(int axis, double value)
selection.rotate( selection.rotate(
(M_PI / 180.0) * (transformation_type.absolute() ? rotation : rotation - m_cache.rotation), (M_PI / 180.0) * (transformation_type.absolute() ? rotation : rotation - m_cache.rotation),
transformation_type); transformation_type);
wxGetApp().plater()->take_snapshot(_(L("Set Orientation"))); canvas->do_rotate("Set Orientation");
canvas->do_rotate();
m_cache.rotation = rotation; m_cache.rotation = rotation;
m_cache.rotation_rounded(axis) = DBL_MAX; m_cache.rotation_rounded(axis) = DBL_MAX;
@ -754,7 +750,7 @@ void ObjectManipulation::do_scale(int axis, const Vec3d &scale) const
selection.start_dragging(); selection.start_dragging();
selection.scale(scaling_factor * 0.01, transformation_type); selection.scale(scaling_factor * 0.01, transformation_type);
wxGetApp().plater()->canvas3D()->do_scale(); wxGetApp().plater()->canvas3D()->do_scale("Set Scale");
} }
void ObjectManipulation::on_change(t_config_option_key opt_key, const boost::any& value) void ObjectManipulation::on_change(t_config_option_key opt_key, const boost::any& value)

View file

@ -600,9 +600,7 @@ bool GLGizmosManager::on_mouse(wxMouseEvent& evt, GLCanvas3D& canvas)
if (m_current == Flatten) if (m_current == Flatten)
{ {
// Rotate the object so the normal points downward: // Rotate the object so the normal points downward:
wxGetApp().plater()->take_snapshot(_(L("Place on Face"))); canvas.do_flatten(get_flattening_normal(), "Place on Face");
selection.flattening_rotate(get_flattening_normal());
canvas.do_flatten();
wxGetApp().obj_manipul()->set_dirty(); wxGetApp().obj_manipul()->set_dirty();
} }
@ -674,20 +672,18 @@ bool GLGizmosManager::on_mouse(wxMouseEvent& evt, GLCanvas3D& canvas)
{ {
case Move: case Move:
{ {
wxGetApp().plater()->take_snapshot(_(L("Move Object")));
canvas.disable_regenerate_volumes(); canvas.disable_regenerate_volumes();
canvas.do_move(); canvas.do_move("Gizmo-Move Object");
break; break;
} }
case Scale: case Scale:
{ {
canvas.do_scale(); canvas.do_scale("Gizmo-Scale Object");
break; break;
} }
case Rotate: case Rotate:
{ {
wxGetApp().plater()->take_snapshot(_(L("Rotate Object"))); canvas.do_rotate("Gizmo-Rotate Object");
canvas.do_rotate();
break; break;
} }
default: default:

View file

@ -806,7 +806,7 @@ void Selection::scale_to_fit_print_volume(const DynamicPrintConfig& config)
double s = std::min(sx, std::min(sy, sz)); double s = std::min(sx, std::min(sy, sz));
if (s != 1.0) if (s != 1.0)
{ {
wxGetApp().plater()->take_snapshot(_(L("Scale To Fit"))); wxGetApp().plater()->take_snapshot(_(L("Scale To Fit")));
TransformationType type; TransformationType type;
type.set_world(); type.set_world();
@ -816,12 +816,12 @@ void Selection::scale_to_fit_print_volume(const DynamicPrintConfig& config)
// apply scale // apply scale
start_dragging(); start_dragging();
scale(s * Vec3d::Ones(), type); scale(s * Vec3d::Ones(), type);
wxGetApp().plater()->canvas3D()->do_scale(); wxGetApp().plater()->canvas3D()->do_scale(""); // avoid storing another snapshot
// center selection on print bed // center selection on print bed
start_dragging(); start_dragging();
translate(print_volume.center() - get_bounding_box().center()); translate(print_volume.center() - get_bounding_box().center());
wxGetApp().plater()->canvas3D()->do_move(); wxGetApp().plater()->canvas3D()->do_move(""); // avoid storing another snapshot
wxGetApp().obj_manipul()->set_dirty(); wxGetApp().obj_manipul()->set_dirty();
} }