MeshLib C++ Docs
Loading...
Searching...
No Matches
MRAppendHistory.h
Go to the documentation of this file.
1#pragma once
2
3#include "MRHistoryStore.h"
5#include <string>
6#include <memory>
7
8namespace MR
9{
12
13
15inline void AppendHistory( std::shared_ptr<HistoryAction> action )
16{
17 if ( const auto & s = HistoryStore::getViewerInstance() )
18 s->appendAction( std::move( action ) );
19}
20
22template<class HistoryActionType, typename... Args>
23void AppendHistory( Args&&... args )
24{
25 static_assert( std::is_base_of_v<HistoryAction, HistoryActionType> );
28 AppendHistory( std::make_shared<HistoryActionType>( std::forward<Args>( args )... ) );
29}
30
42template<class HistoryActionType>
44{
45public:
46 static_assert( std::is_base_of_v<HistoryAction, HistoryActionType> );
47 using Obj = typename HistoryActionType::Obj;
48
49 template<typename... Args>
50 [[nodiscard]] Historian( std::string name, std::shared_ptr<Obj> obj, Args&&... args ) : obj_( std::move( obj ) )
51 {
53 action_ = std::make_shared<HistoryActionType>( std::move( name ), obj_, std::forward<Args>( args )... );
54 }
55
57 {
58 if ( action_ )
59 {
60 action_->action( HistoryAction::Type::Undo );
61 action_.reset();
62 }
63 canceled_ = true;
64 }
65
67 {
68 if ( action_ )
69 AppendHistory( std::move( action_ ) );
70 if ( !canceled_ )
71 HistoryActionType::setObjectDirty( obj_ );
72 }
73private:
74 std::shared_ptr<Obj> obj_;
75 std::shared_ptr<HistoryActionType> action_;
76 bool canceled_{ false };
77};
78
81MRVIEWER_API void FilterHistoryByCondition( HistoryStackFilter filteringCondition, bool deepFiltering = true );
82
85{
86public:
88 MRVIEWER_API ScopeHistory( const std::string& name, const std::function<std::string ()>& dynamicNameFunc = {} );
89
91 MRVIEWER_API ~ScopeHistory();
92
94 const std::shared_ptr<CombinedHistoryAction>& combinedAction() const { return combinedAction_; }
95
96private:
97 HistoryStore* store_{ nullptr };
98 std::shared_ptr<CombinedHistoryAction> combinedAction_;
99 HistoryActionsVector* parentScopePtr_{ nullptr };
100};
101
102#define SCOPED_HISTORY( ... ) MR::ScopeHistory __startScopedHistoryMode( __VA_ARGS__ )
103
104}
This class stores history stack for undo/redo.
Definition MRHistoryStore.h:16
static HistoryStore * getViewerInstance()
ScopeHistory(const std::string &name, const std::function< std::string()> &dynamicNameFunc={})
creates new CombinedHistoryAction, and setups global history store to append all new actions there du...
void FilterHistoryByCondition(HistoryStackFilter filteringCondition, bool deepFiltering=true)
void AppendHistory(std::shared_ptr< HistoryAction > action)
Appends given history action to viewer's global history store.
Definition MRAppendHistory.h:15
Historian(std::string name, std::shared_ptr< Obj > obj, Args &&... args)
Definition MRAppendHistory.h:50
void cancelAction()
Definition MRAppendHistory.h:56
~Historian()
Definition MRAppendHistory.h:66
std::function< bool(const std::shared_ptr< HistoryAction > &)> HistoryStackFilter
Definition MRHistoryAction.h:38
std::vector< std::shared_ptr< HistoryAction > > HistoryActionsVector
Definition MRHistoryAction.h:39
const std::shared_ptr< CombinedHistoryAction > & combinedAction() const
returns the action being populated
Definition MRAppendHistory.h:94
~ScopeHistory()
created before CombinedHistoryAction if not empty is appended (with all sub-actions) in the global hi...
typename HistoryActionType::Obj Obj
Definition MRAppendHistory.h:47
@ Undo
Definition MRHistoryAction.h:28
only for bindings generation
Definition MRCameraOrientationPlugin.h:8