MeshLib C++ Docs
Loading...
Searching...
No Matches
MRHistoryStore.h
Go to the documentation of this file.
1#pragma once
2
3#include "MRViewerFwd.h"
5#include "MRMesh/MRSignal.h"
6#include <memory>
7
8namespace MR
9{
10
13
15class MRVIEWER_CLASS HistoryStore
16{
17public:
20 [[nodiscard]] MRVIEWER_API static HistoryStore* getViewerInstance();
21
22 MRVIEWER_API virtual ~HistoryStore();
23
26 MRVIEWER_API virtual void appendAction( std::shared_ptr<HistoryAction> action );
27
29 [[nodiscard]] HistoryActionsVector* getScopeBlockPtr() const { return scopedBlock_; }
30
32 void setScopeBlockPtr( HistoryActionsVector* scopedBlock ) { scopedBlock_ = scopedBlock; }
33
35 [[nodiscard]] bool isSceneModified() const { return firstRedoIndex_ != savedSceneIndex_; }
36
38 void setSavedState() { savedSceneIndex_ = firstRedoIndex_; }
39
41 MRVIEWER_API void clear();
42
44 void setMemoryLimit( size_t limit ) { storageLimit_ = limit; }
45
47 [[nodiscard]] size_t getMemoryLimit() const { return storageLimit_; }
48
50 [[nodiscard]] MRVIEWER_API size_t calcUsedMemory() const;
51
53 [[nodiscard]] const HistoryActionsVector& getHistoryStack() const { return stack_; }
54
56 [[nodiscard]] size_t getStackPointer() const { return firstRedoIndex_; }
57
59 MRVIEWER_API void filterStack( HistoryStackFilter filteringCondition, bool deepFiltering = true );
60
63 MRVIEWER_API virtual bool undo();
64
67 MRVIEWER_API virtual bool redo();
68
70 [[nodiscard]] bool undoRedoInProgress() const { return undoRedoInProgress_; }
71
73 [[nodiscard]] MRVIEWER_API std::vector<std::string> getNActions( unsigned n, HistoryAction::Type type ) const;
74
76 [[nodiscard]] MRVIEWER_API std::shared_ptr<HistoryAction> getLastAction( HistoryAction::Type type ) const;
77
79 [[nodiscard]] MRVIEWER_API std::string getLastActionName( HistoryAction::Type type ) const;
80
82 enum class ChangeType
83 {
84 PreAppendAction,
85 PostAppendAction,
86 PreUndo,
87 PostUndo,
88 PreRedo,
89 PostRedo,
90 Clear,
91 PopAction,
92 Filter
93 };
94 using HistoryStoreChangedSignal = boost::signals2::signal<void( HistoryStore& store, ChangeType, std::shared_ptr<HistoryAction> action )>;
96
97private:
99 HistoryActionsVector* scopedBlock_{ nullptr };
100
103
105 size_t firstRedoIndex_{ 0 };
106
109 size_t savedSceneIndex_{ 0 };
110
112 size_t storageLimit_{ size_t( ~0 ) };
113
115 bool undoRedoInProgress_{ false };
116
118 void filterByMemoryLimit_();
119};
120
122
123}
This class stores history stack for undo/redo.
Definition MRHistoryStore.h:16
boost::signals2::signal< void(HistoryStore &store, ChangeType, std::shared_ptr< HistoryAction > action)> HistoryStoreChangedSignal
Definition MRHistoryStore.h:94
virtual MRVIEWER_API bool undo()
virtual MRVIEWER_API ~HistoryStore()
MRVIEWER_API void filterStack(HistoryStackFilter filteringCondition, bool deepFiltering=true)
remove some actions according to condition
HistoryActionsVector * getScopeBlockPtr() const
Returns current scope ptr.
Definition MRHistoryStore.h:29
size_t getMemoryLimit() const
Returns current memory limit for this store (by default uint64 max)
Definition MRHistoryStore.h:47
void setMemoryLimit(size_t limit)
Set memory limit for this store, if history stack exceed it - old actions are removed.
Definition MRHistoryStore.h:44
virtual MRVIEWER_API bool redo()
size_t getStackPointer() const
Returns index of first redo action in stack.
Definition MRHistoryStore.h:56
const HistoryActionsVector & getHistoryStack() const
Returns full history stack.
Definition MRHistoryStore.h:53
bool undoRedoInProgress() const
true only during Undo or Redo ongoing operation
Definition MRHistoryStore.h:70
static MRVIEWER_API HistoryStore * getViewerInstance()
MRVIEWER_API std::vector< std::string > getNActions(unsigned n, HistoryAction::Type type) const
Returns names of last N undo actions or first N redo actions.
MRVIEWER_API std::shared_ptr< HistoryAction > getLastAction(HistoryAction::Type type) const
Returns the last undo or redo action based on requested type or empty pointer if corresponding stack ...
virtual MRVIEWER_API void appendAction(std::shared_ptr< HistoryAction > action)
ChangeType
Signal is called after this store changed.
Definition MRHistoryStore.h:83
void setSavedState()
Consider the current scene state as saved.
Definition MRHistoryStore.h:38
MRVIEWER_API size_t calcUsedMemory() const
Compute amount of memory occupied by all actions in this store.
MRVIEWER_API std::string getLastActionName(HistoryAction::Type type) const
Returns the name of last undo or redo action (or empty string if there is no such action)
MRVIEWER_API void clear()
Clears this HistoryStore.
bool isSceneModified() const
Returns true if the current scene state does not match the saved state.
Definition MRHistoryStore.h:35
HistoryStoreChangedSignal changedSignal
Definition MRHistoryStore.h:95
void setScopeBlockPtr(HistoryActionsVector *scopedBlock)
Sets pointer to current scope block.
Definition MRHistoryStore.h:32
std::function< bool(const std::shared_ptr< HistoryAction > &)> HistoryStackFilter
Definition MRHistoryAction.h:33
std::vector< std::shared_ptr< HistoryAction > > HistoryActionsVector
Definition MRHistoryAction.h:34
Type
Definition MRHistoryAction.h:22
only for bindings generation
Definition MRCameraOrientationPlugin.h:8