After gizmo snapshots are compacted, rename the last one to something generic

This commit is contained in:
Lukas Matena 2021-09-30 10:21:19 +02:00
parent aeb18e729d
commit c61a5d234e
10 changed files with 34 additions and 12 deletions

View file

@ -136,6 +136,7 @@ public:
bool is_selectable() const { return on_is_selectable(); }
CommonGizmosDataID get_requirements() const { return on_get_requirements(); }
virtual bool wants_enter_leave_snapshots() const { return false; }
virtual std::string get_action_snapshot_name() { return _u8L("Gizmo action"); }
void set_common_data_pool(CommonGizmosDataPool* ptr) { m_c = ptr; }
unsigned int get_sprite_id() const { return m_sprite_id; }

View file

@ -8,6 +8,7 @@
#include "slic3r/GUI/ImGuiWrapper.hpp"
#include "slic3r/GUI/Plater.hpp"
#include "slic3r/GUI/GUI_ObjectList.hpp"
#include "slic3r/Utils/UndoRedo.hpp"
#include <GL/glew.h>
@ -165,7 +166,8 @@ void GLGizmoFdmSupports::on_render_input_window(float x, float y, float bottom_l
ImGui::Separator();
if (m_imgui->button(m_desc.at("remove_all"))) {
Plater::TakeSnapshot snapshot(wxGetApp().plater(), wxString(_L("Reset selection")));
Plater::TakeSnapshot snapshot(wxGetApp().plater(), _L("Reset selection"),
UndoRedo::SnapshotType::GizmoAction);
ModelObject* mo = m_c->selection_info()->model_object();
int idx = -1;
for (ModelVolume* mv : mo->volumes) {

View file

@ -21,6 +21,8 @@ protected:
std::string get_gizmo_entering_text() const override { return _u8L("Entering Paint-on supports"); }
std::string get_gizmo_leaving_text() const override { return _u8L("Leaving Paint-on supports"); }
std::string get_action_snapshot_name() override { return _u8L("Paint-on supports editing"); }
private:
bool on_init() override;

View file

@ -11,6 +11,7 @@
#include "slic3r/GUI/NotificationManager.hpp"
#include "libslic3r/PresetBundle.hpp"
#include "libslic3r/Model.hpp"
#include "slic3r/Utils/UndoRedo.hpp"
#include <GL/glew.h>
@ -503,7 +504,8 @@ void GLGizmoMmuSegmentation::on_render_input_window(float x, float y, float bott
ImGui::Separator();
if (m_imgui->button(m_desc.at("remove_all"))) {
Plater::TakeSnapshot snapshot(wxGetApp().plater(), wxString(_L("Reset selection")));
Plater::TakeSnapshot snapshot(wxGetApp().plater(), _L("Reset selection"),
UndoRedo::SnapshotType::GizmoAction);
ModelObject * mo = m_c->selection_info()->model_object();
int idx = -1;
for (ModelVolume *mv : mo->volumes)

View file

@ -130,6 +130,7 @@ protected:
std::string get_gizmo_entering_text() const override { return _u8L("Entering Multimaterial painting"); }
std::string get_gizmo_leaving_text() const override { return _u8L("Leaving Multimaterial painting"); }
std::string get_action_snapshot_name() override { return _u8L("Multimaterial painting editing"); }
size_t m_first_selected_extruder_idx = 0;
size_t m_second_selected_extruder_idx = 1;

View file

@ -8,6 +8,7 @@
#include "slic3r/GUI/ImGuiWrapper.hpp"
#include "slic3r/GUI/Plater.hpp"
#include "slic3r/GUI/GUI_ObjectList.hpp"
#include "slic3r/Utils/UndoRedo.hpp"
#include <GL/glew.h>
@ -121,7 +122,8 @@ void GLGizmoSeam::on_render_input_window(float x, float y, float bottom_limit)
m_imgui->text("");
if (m_imgui->button(m_desc.at("remove_all"))) {
Plater::TakeSnapshot snapshot(wxGetApp().plater(), wxString(_L("Reset selection")));
Plater::TakeSnapshot snapshot(wxGetApp().plater(), _L("Reset selection"),
UndoRedo::SnapshotType::GizmoAction);
ModelObject* mo = m_c->selection_info()->model_object();
int idx = -1;
for (ModelVolume* mv : mo->volumes) {

View file

@ -22,6 +22,7 @@ protected:
std::string get_gizmo_entering_text() const override { return _u8L("Entering Seam painting"); }
std::string get_gizmo_leaving_text() const override { return _u8L("Leaving Seam painting"); }
std::string get_action_snapshot_name() override { return _u8L("Paint-on seam editing"); }
private:
bool on_init() override;

View file

@ -4695,12 +4695,22 @@ void Plater::priv::take_snapshot(const std::string& snapshot_name, const UndoRed
model.wipe_tower.position = Vec2d(config.opt_float("wipe_tower_x"), config.opt_float("wipe_tower_y"));
model.wipe_tower.rotation = config.opt_float("wipe_tower_rotation_angle");
}
const GLGizmosManager& gizmos = view3D->get_canvas3d()->get_gizmos_manager();
if (snapshot_type == UndoRedo::SnapshotType::ProjectSeparator && wxGetApp().app_config->get("clear_undo_redo_stack_on_new_project") == "1")
this->undo_redo_stack().clear();
this->undo_redo_stack().take_snapshot(snapshot_name, model, view3D->get_canvas3d()->get_selection(), view3D->get_canvas3d()->get_gizmos_manager(), snapshot_data);
if (snapshot_type == UndoRedo::SnapshotType::LeavingGizmoWithAction)
this->undo_redo_stack().take_snapshot(snapshot_name, model, view3D->get_canvas3d()->get_selection(), gizmos, snapshot_data);
if (snapshot_type == UndoRedo::SnapshotType::LeavingGizmoWithAction) {
// Filter all but the last UndoRedo::SnapshotType::GizmoAction in a row between the last UndoRedo::SnapshotType::EnteringGizmo and UndoRedo::SnapshotType::LeavingGizmoWithAction.
this->undo_redo_stack().reduce_noisy_snapshots();
// The remaining snapshot will be renamed to a more generic name,
// depending on what gizmo is being left.
assert(gizmos.get_current() != nullptr);
std::string new_name = gizmos.get_current()->get_action_snapshot_name();
this->undo_redo_stack().reduce_noisy_snapshots(new_name);
} else if (snapshot_type == UndoRedo::SnapshotType::ProjectSeparator) {
// Reset the "dirty project" flag.
m_undo_redo_stack_main.mark_current_as_saved();
}
this->undo_redo_stack().release_least_recently_used();
dirty_state.update_from_undo_redo_stack(m_undo_redo_stack_main.project_modified());

View file

@ -576,7 +576,7 @@ public:
// Store the current application state onto the Undo / Redo stack, remove all snapshots after m_active_snapshot_time.
void take_snapshot(const std::string& snapshot_name, const Slic3r::Model& model, const Slic3r::GUI::Selection& selection, const Slic3r::GUI::GLGizmosManager& gizmos, const SnapshotData &snapshot_data);
void reduce_noisy_snapshots();
void reduce_noisy_snapshots(const std::string& new_name);
void load_snapshot(size_t timestamp, Slic3r::Model& model, Slic3r::GUI::GLGizmosManager& gizmos);
bool has_undo_snapshot() const;
@ -934,7 +934,7 @@ void StackImpl::take_snapshot(const std::string& snapshot_name, const Slic3r::Mo
#endif /* SLIC3R_UNDOREDO_DEBUG */
}
void StackImpl::reduce_noisy_snapshots()
void StackImpl::reduce_noisy_snapshots(const std::string& new_name)
{
// Preceding snapshot must be a "leave gizmo" snapshot.
assert(! m_snapshots.empty() && m_snapshots.back().is_topmost() && m_snapshots.back().timestamp == m_active_snapshot_time);
@ -944,7 +944,8 @@ void StackImpl::reduce_noisy_snapshots()
if (it_last->snapshot_data.snapshot_type == SnapshotType::LeavingGizmoWithAction) {
for (-- it_last; it_last->snapshot_data.snapshot_type != SnapshotType::EnteringGizmo; -- it_last) {
if (it_last->snapshot_data.snapshot_type == SnapshotType::GizmoAction) {
auto it = it_last;
it_last->name = new_name;
auto it = it_last;
for (-- it; it->snapshot_data.snapshot_type == SnapshotType::GizmoAction; -- it) ;
if (++ it < it_last) {
// Drop (it, it_last>
@ -1248,7 +1249,7 @@ size_t Stack::memsize() const { return pimpl->memsize(); }
void Stack::release_least_recently_used() { pimpl->release_least_recently_used(); }
void Stack::take_snapshot(const std::string& snapshot_name, const Slic3r::Model& model, const Slic3r::GUI::Selection& selection, const Slic3r::GUI::GLGizmosManager& gizmos, const SnapshotData &snapshot_data)
{ pimpl->take_snapshot(snapshot_name, model, selection, gizmos, snapshot_data); }
void Stack::reduce_noisy_snapshots() { pimpl->reduce_noisy_snapshots(); }
void Stack::reduce_noisy_snapshots(const std::string& new_name) { pimpl->reduce_noisy_snapshots(new_name); }
bool Stack::has_undo_snapshot() const { return pimpl->has_undo_snapshot(); }
bool Stack::has_undo_snapshot(size_t time_to_load) const { return pimpl->has_undo_snapshot(time_to_load); }
bool Stack::has_redo_snapshot() const { return pimpl->has_redo_snapshot(); }

View file

@ -8,6 +8,7 @@
#include <cassert>
#include <libslic3r/ObjectID.hpp>
#include <libslic3r/Config.hpp>
typedef double coordf_t;
typedef std::pair<coordf_t, coordf_t> t_layer_height_range;
@ -15,7 +16,6 @@ typedef std::pair<coordf_t, coordf_t> t_layer_height_range;
namespace Slic3r {
class Model;
enum PrinterTechnology : unsigned char;
namespace GUI {
class Selection;
@ -122,7 +122,7 @@ public:
void take_snapshot(const std::string& snapshot_name, const Slic3r::Model& model, const Slic3r::GUI::Selection& selection, const Slic3r::GUI::GLGizmosManager& gizmos, const SnapshotData &snapshot_data);
// To be called just after take_snapshot() when leaving a gizmo, inside which small edits like support point add / remove events or paiting actions were allowed.
// Remove all but the last edit between the gizmo enter / leave snapshots.
void reduce_noisy_snapshots();
void reduce_noisy_snapshots(const std::string& new_name);
// To be queried to enable / disable the Undo / Redo buttons at the UI.
bool has_undo_snapshot() const;