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
12template<class HistoryActionType, typename... Args>
13void AppendHistory( Args&&... args )
14{
15 static_assert( std::is_base_of_v<HistoryAction, HistoryActionType> );
16 if ( const auto & s = HistoryStore::getViewerInstance() )
17 s->appendAction( std::make_shared<HistoryActionType>( std::forward<Args>( args )... ) );
18}
19
21inline void AppendHistory( std::shared_ptr<HistoryAction> action )
22{
23 if ( const auto & s = HistoryStore::getViewerInstance() )
24 s->appendAction( std::move( action ) );
25}
26
27// if undo history is enabled, creates given action in the constructor;
28// and always mark the object as dirty in the destructor
29template<class HistoryActionType>
31{
32public:
33 static_assert( std::is_base_of_v<HistoryAction, HistoryActionType> );
34 using Obj = typename HistoryActionType::Obj;
35
36 template<typename... Args>
37 Historian( std::string name, std::shared_ptr<Obj> obj, Args&&... args ) : obj_( std::move( obj ) )
38 {
40 action_ = std::make_shared<HistoryActionType>( std::move( name ), obj_, std::forward<Args>( args )... );
41 }
42
44 {
45 if ( action_ )
46 {
47 action_->action( HistoryAction::Type::Undo );
48 action_.reset();
49 }
50 canceled_ = true;
51 }
52
54 {
55 if ( action_ )
56 AppendHistory( std::move( action_ ) );
57 if ( !canceled_ )
58 HistoryActionType::setObjectDirty( obj_ );
59 }
60private:
61 std::shared_ptr<Obj> obj_;
62 std::shared_ptr<HistoryActionType> action_;
63 bool canceled_{ false };
64};
65
68MRVIEWER_API void FilterHistoryByCondition( HistoryStackFilter filteringCondition, bool deepFiltering = true );
69
70// This class store history actions that are appended to global history stack all together as CombinedHistoryAction in destructor (if scoped stack is not empty)
72{
73public:
74 MRVIEWER_API ScopeHistory( const std::string& name );
75 MRVIEWER_API ~ScopeHistory();
76
77private:
78 std::string name_;
79 std::shared_ptr<HistoryStore> store_;
81 HistoryActionsVector* parentScopePtr_{ nullptr };
82};
83
84#define SCOPED_HISTORY(name) MR::ScopeHistory __startScopedHistoryMode(name)
85
86}
Definition MRAppendHistory.h:31
Historian(std::string name, std::shared_ptr< Obj > obj, Args &&... args)
Definition MRAppendHistory.h:37
void cancelAction()
Definition MRAppendHistory.h:43
~Historian()
Definition MRAppendHistory.h:53
typename HistoryActionType::Obj Obj
Definition MRAppendHistory.h:34
static MRVIEWER_API const std::shared_ptr< HistoryStore > & getViewerInstance()
returns the instance (if any) of HistoryStore from the viewer
Definition MRAppendHistory.h:72
MRVIEWER_API ScopeHistory(const std::string &name)
MRVIEWER_API ~ScopeHistory()
void AppendHistory(Args &&... args)
This function constructs history action and appends it to viewer's global history store.
Definition MRAppendHistory.h:13
std::function< bool(const std::shared_ptr< HistoryAction > &)> HistoryStackFilter
Definition MRHistoryAction.h:30
std::vector< std::shared_ptr< HistoryAction > > HistoryActionsVector
Definition MRHistoryAction.h:31
MRVIEWER_API void FilterHistoryByCondition(HistoryStackFilter filteringCondition, bool deepFiltering=true)