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{
10
12inline void AppendHistory( std::shared_ptr<HistoryAction> action )
13{
14 if ( const auto & s = HistoryStore::getViewerInstance() )
15 s->appendAction( std::move( action ) );
16}
17
19template<class HistoryActionType, typename... Args>
20void AppendHistory( Args&&... args )
21{
22 static_assert( std::is_base_of_v<HistoryAction, HistoryActionType> );
23 // even if there is no HistoryStore::getViewerInstance(), we still need to make new action,
24 // because some actions make modifications visible outside in their constructors
25 AppendHistory( std::make_shared<HistoryActionType>( std::forward<Args>( args )... ) );
26}
27
28// if undo history is enabled, creates given action in the constructor;
29// and always mark the object as dirty in the destructor
30template<class HistoryActionType>
32{
33public:
34 static_assert( std::is_base_of_v<HistoryAction, HistoryActionType> );
35 using Obj = typename HistoryActionType::Obj;
36
37 template<typename... Args>
38 Historian( std::string name, std::shared_ptr<Obj> obj, Args&&... args ) : obj_( std::move( obj ) )
39 {
41 action_ = std::make_shared<HistoryActionType>( std::move( name ), obj_, std::forward<Args>( args )... );
42 }
43
45 {
46 if ( action_ )
47 {
48 action_->action( HistoryAction::Type::Undo );
49 action_.reset();
50 }
51 canceled_ = true;
52 }
53
55 {
56 if ( action_ )
57 AppendHistory( std::move( action_ ) );
58 if ( !canceled_ )
59 HistoryActionType::setObjectDirty( obj_ );
60 }
61private:
62 std::shared_ptr<Obj> obj_;
63 std::shared_ptr<HistoryActionType> action_;
64 bool canceled_{ false };
65};
66
69MRVIEWER_API void FilterHistoryByCondition( HistoryStackFilter filteringCondition, bool deepFiltering = true );
70
73{
74public:
76 MRVIEWER_API ScopeHistory( const std::string& name );
77
79 MRVIEWER_API ~ScopeHistory();
80
82 const std::shared_ptr<CombinedHistoryAction>& combinedAction() const { return combinedAction_; }
83
84private:
85 HistoryStore* store_{ nullptr };
86 std::shared_ptr<CombinedHistoryAction> combinedAction_;
87 HistoryActionsVector* parentScopePtr_{ nullptr };
88};
89
90#define SCOPED_HISTORY(name) MR::ScopeHistory __startScopedHistoryMode(name)
91
92}
Definition MRAppendHistory.h:32
Historian(std::string name, std::shared_ptr< Obj > obj, Args &&... args)
Definition MRAppendHistory.h:38
void cancelAction()
Definition MRAppendHistory.h:44
~Historian()
Definition MRAppendHistory.h:54
typename HistoryActionType::Obj Obj
Definition MRAppendHistory.h:35
This class stores history stack for undo/redo.
Definition MRHistoryStore.h:16
static MRVIEWER_API HistoryStore * getViewerInstance()
The purpose of this class is to combine all actions appended to global history store in one big actio...
Definition MRAppendHistory.h:73
MRVIEWER_API ScopeHistory(const std::string &name)
creates new CombinedHistoryAction, and setups global history store to append all new actions there du...
MRVIEWER_API ~ScopeHistory()
created before CombinedHistoryAction if not empty is appended (with all sub-actions) in the global hi...
const std::shared_ptr< CombinedHistoryAction > & combinedAction() const
returns the action being populated
Definition MRAppendHistory.h:82
Definition MRCameraOrientationPlugin.h:8
void AppendHistory(std::shared_ptr< HistoryAction > action)
Appends given history action to viewer's global history store.
Definition MRAppendHistory.h:12
MRVIEWER_API void FilterHistoryByCondition(HistoryStackFilter filteringCondition, bool deepFiltering=true)