mirror of
https://github.com/SoftFever/OrcaSlicer.git
synced 2025-07-22 14:13:57 -06:00
Redo of the project state, implementation of Undo/Redo stack compression
This commit is contained in:
parent
96f4d71c71
commit
1f3b272d77
9 changed files with 222 additions and 376 deletions
|
@ -4,89 +4,32 @@
|
|||
#include "libslic3r/Preset.hpp"
|
||||
|
||||
namespace Slic3r {
|
||||
namespace UndoRedo {
|
||||
class Stack;
|
||||
struct Snapshot;
|
||||
} // namespace UndoRedo
|
||||
|
||||
namespace GUI {
|
||||
|
||||
class ProjectDirtyStateManager
|
||||
{
|
||||
public:
|
||||
enum class UpdateType : unsigned char
|
||||
{
|
||||
TakeSnapshot,
|
||||
UndoRedoTo
|
||||
};
|
||||
|
||||
struct DirtyState
|
||||
{
|
||||
struct Gizmos
|
||||
{
|
||||
struct Gizmo
|
||||
{
|
||||
std::vector<size_t> modified_timestamps;
|
||||
};
|
||||
|
||||
bool current{ false };
|
||||
std::map<std::string, Gizmo> used;
|
||||
|
||||
void add_used(const UndoRedo::Snapshot& snapshot);
|
||||
void remove_obsolete_used(const Slic3r::UndoRedo::Stack& main_stack);
|
||||
#if ENABLE_PROJECT_DIRTY_STATE_DEBUG_WINDOW
|
||||
bool any_used_modified() const;
|
||||
#endif // ENABLE_PROJECT_DIRTY_STATE_DEBUG_WINDOW
|
||||
bool is_used_and_modified(const UndoRedo::Snapshot& snapshot) const;
|
||||
void reset();
|
||||
};
|
||||
|
||||
bool plater{ false };
|
||||
bool presets{ false };
|
||||
Gizmos gizmos;
|
||||
|
||||
bool is_dirty() const { return plater || presets || gizmos.current; }
|
||||
void reset() {
|
||||
plater = false;
|
||||
presets = false;
|
||||
gizmos.current = false;
|
||||
}
|
||||
};
|
||||
|
||||
private:
|
||||
struct LastSaveTimestamps
|
||||
{
|
||||
size_t main{ 0 };
|
||||
size_t gizmo{ 0 };
|
||||
|
||||
void reset() {
|
||||
main = 0;
|
||||
gizmo = 0;
|
||||
}
|
||||
};
|
||||
|
||||
DirtyState m_state;
|
||||
LastSaveTimestamps m_last_save;
|
||||
|
||||
// keeps track of initial selected presets
|
||||
std::array<std::string, Preset::TYPE_COUNT> m_initial_presets;
|
||||
|
||||
public:
|
||||
bool is_dirty() const { return m_state.is_dirty(); }
|
||||
void update_from_undo_redo_stack(UpdateType type);
|
||||
public:
|
||||
void update_from_undo_redo_stack(bool dirty);
|
||||
void update_from_presets();
|
||||
void reset_after_save();
|
||||
void reset_initial_presets();
|
||||
|
||||
bool is_dirty() const { return m_plater_dirty || m_presets_dirty; }
|
||||
|
||||
#if ENABLE_PROJECT_DIRTY_STATE_DEBUG_WINDOW
|
||||
void render_debug_window() const;
|
||||
#endif // ENABLE_PROJECT_DIRTY_STATE_DEBUG_WINDOW
|
||||
|
||||
private:
|
||||
void update_from_undo_redo_main_stack(UpdateType type, const Slic3r::UndoRedo::Stack& stack);
|
||||
void update_from_undo_redo_gizmo_stack(UpdateType type, const Slic3r::UndoRedo::Stack& stack);
|
||||
// Does the Undo / Redo stack indicate the project is dirty?
|
||||
bool m_plater_dirty { false };
|
||||
// Do the presets indicate the project is dirty?
|
||||
bool m_presets_dirty { false };
|
||||
// Keeps track of preset names selected at the time of last project save.
|
||||
std::array<std::string, Preset::TYPE_COUNT> m_initial_presets;
|
||||
};
|
||||
|
||||
} // namespace GUI
|
||||
} // namespace Slic3r
|
||||
|
||||
#endif // slic3r_ProjectDirtyStateManager_hpp_
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue