MeshLib Documentation
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
11// This function appends history action to viewers global history store
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
20template<class HistoryActionType>
21void AppendHistory( std::shared_ptr<HistoryActionType> action )
22{
23 static_assert( std::is_base_of_v<HistoryAction, HistoryActionType> );
24 if ( const auto & s = HistoryStore::getViewerInstance() )
25 s->appendAction( action );
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
71// This class store history actions that are appended to global history stack all together as CombinedHistoryAction in destructor (if scoped stack is not empty)
73{
74public:
75 MRVIEWER_API ScopeHistory( const std::string& name );
76 MRVIEWER_API ~ScopeHistory();
77
78private:
79 std::string name_;
80 std::shared_ptr<HistoryStore> store_;
82 HistoryActionsVector* parentScopePtr_{ nullptr };
83};
84
85#define SCOPED_HISTORY(name) MR::ScopeHistory __startScopedHistoryMode(name)
86
87}
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
static MRVIEWER_API const std::shared_ptr< HistoryStore > & getViewerInstance()
returns the instance (if any) of HistoryStore from the viewer
Definition MRAppendHistory.h:73
MRVIEWER_API ScopeHistory(const std::string &name)
MRVIEWER_API ~ScopeHistory()
Definition MRCameraOrientationPlugin.h:8
void AppendHistory(Args &&... args)
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)