MeshLib Documentation
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
16{
17public:
19 [[nodiscard]] MRVIEWER_API static const std::shared_ptr<HistoryStore>& getViewerInstance();
20
21 MRVIEWER_API virtual ~HistoryStore();
22
25 MRVIEWER_API virtual void appendAction( const std::shared_ptr<HistoryAction>& action );
26
28 [[nodiscard]] HistoryActionsVector* getScopeBlockPtr() const { return scopedBlock_; }
29
31 void setScopeBlockPtr( HistoryActionsVector* scopedBlock ) { scopedBlock_ = scopedBlock; }
32
34 [[nodiscard]] bool isSceneModified() const { return firstRedoIndex_ != savedSceneIndex_; }
35
37 void setSavedState() { savedSceneIndex_ = firstRedoIndex_; }
38
40 MRVIEWER_API void clear();
41
43 void setMemoryLimit( size_t limit ) { storageLimit_ = limit; }
44
46 [[nodiscard]] size_t getMemoryLimit() const { return storageLimit_; }
47
49 [[nodiscard]] MRVIEWER_API size_t calcUsedMemory() const;
50
52 [[nodiscard]] const HistoryActionsVector& getHistoryStack() const { return stack_; }
53
55 [[nodiscard]] size_t getStackPointer() const { return firstRedoIndex_; }
56
58 MRVIEWER_API void filterStack( HistoryStackFilter filteringCondition, bool deepFiltering = true );
59
60 MRVIEWER_API virtual bool undo();
61 MRVIEWER_API virtual bool redo();
62
64 [[nodiscard]] MRVIEWER_API std::vector<std::string> getNActions( unsigned n, HistoryAction::Type type ) const;
65
67 [[nodiscard]] MRVIEWER_API std::string getLastActionName( HistoryAction::Type type ) const;
68
70 enum class ChangeType
71 {
73 Undo,
74 Redo,
75 Clear,
76 PopAction,
77 Filter
78 };
79 using HistoryStoreChangedSignal = boost::signals2::signal<void( const HistoryStore& store, ChangeType )>;
81
82private:
84 HistoryActionsVector* scopedBlock_{ nullptr };
88 size_t firstRedoIndex_{ 0 };
91 size_t savedSceneIndex_{ 0 };
93 size_t storageLimit_{ size_t( ~0 ) };
94
96 void filterByMemoryLimit_();
97};
98
100
101}
Type
Definition MRHistoryAction.h:19
This class stores history stack for undo/redo.
Definition MRHistoryStore.h:16
virtual MRVIEWER_API bool undo()
virtual MRVIEWER_API ~HistoryStore()
MRVIEWER_API void filterStack(HistoryStackFilter filteringCondition, bool deepFiltering=true)
remove some actions according to condition
boost::signals2::signal< void(const HistoryStore &store, ChangeType)> HistoryStoreChangedSignal
Definition MRHistoryStore.h:79
HistoryActionsVector * getScopeBlockPtr() const
Returns current scope ptr.
Definition MRHistoryStore.h:28
size_t getMemoryLimit() const
Returns current memory limit for this store (by default uint64 max)
Definition MRHistoryStore.h:46
void setMemoryLimit(size_t limit)
Set memory limit for this store, if history stack exceed it - old actions are removed.
Definition MRHistoryStore.h:43
virtual MRVIEWER_API bool redo()
size_t getStackPointer() const
Returns index of first redo action in stack.
Definition MRHistoryStore.h:55
const HistoryActionsVector & getHistoryStack() const
Returns full history stack.
Definition MRHistoryStore.h:52
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.
static MRVIEWER_API const std::shared_ptr< HistoryStore > & getViewerInstance()
returns the instance (if any) of HistoryStore from the viewer
ChangeType
Signal is called after this store changed.
Definition MRHistoryStore.h:71
@ AppendAction
additions in scoped block does not provide signal
@ PopAction
called after removing action that exceeds memory limit
virtual MRVIEWER_API void appendAction(const std::shared_ptr< HistoryAction > &action)
void setSavedState()
Consider the current scene state as saved.
Definition MRHistoryStore.h:37
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:34
HistoryStoreChangedSignal changedSignal
Definition MRHistoryStore.h:80
void setScopeBlockPtr(HistoryActionsVector *scopedBlock)
Sets pointer to current scope block.
Definition MRHistoryStore.h:31
Definition MRCameraOrientationPlugin.h:8
std::function< bool(const std::shared_ptr< HistoryAction > &)> HistoryStackFilter
Definition MRHistoryAction.h:30
std::vector< std::shared_ptr< HistoryAction > > HistoryActionsVector
Definition MRHistoryAction.h:31