Skip to content

Commit 52db12d

Browse files
authored
Introduce more signals in history store (#5658)
1 parent 14cd308 commit 52db12d

File tree

6 files changed

+47
-27
lines changed

6 files changed

+47
-27
lines changed

source/MRViewer/MRAncillaryLabels.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include "MRViewer.h"
66
#include "MRViewport.h"
77
#include "ImGuiMenu.h"
8+
#include "MRImGuiMultiViewport.h"
89
#include "imgui.h"
910

1011
namespace MR
@@ -141,9 +142,9 @@ void AncillaryImGuiLabel::preDraw_()
141142
Vector3f coord = vp.projectToViewportSpace( labelData_.position );
142143
auto viewerCoord = getViewerInstance().viewportToScreen( coord, vp.id );
143144

144-
params.list->PushClipRect( minRect, maxRect );
145+
params.list->PushClipRect( ImGuiMV::Window2ScreenSpaceImVec2( minRect ), ImGuiMV::Window2ScreenSpaceImVec2( maxRect ) );
145146
ImGuiMeasurementIndicators::text( ImGuiMeasurementIndicators::Element::both, params,
146-
ImVec2( viewerCoord.x, viewerCoord.y ), sWithI, {}, {}, pivot_ );
147+
ImGuiMV::Window2ScreenSpaceImVec2( ImVec2( viewerCoord.x, viewerCoord.y ) ), sWithI, {}, {}, pivot_ );
147148
params.list->PopClipRect();
148149
}
149150
}

source/MRViewer/MRHistoryStore.cpp

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,11 @@ void HistoryStore::appendAction( std::shared_ptr<HistoryAction> action )
2525
return;
2626
if ( !action )
2727
return;
28+
changedSignal( *this, ChangeType::PreAppendAction, action );
2829
if ( scopedBlock_ )
2930
{
3031
scopedBlock_->push_back( std::move( action ) );
32+
changedSignal( *this, ChangeType::PostAppendAction, scopedBlock_->back() );
3133
return;
3234
}
3335
spdlog::info( "History action append: \"{}\"", action->name() );
@@ -37,7 +39,7 @@ void HistoryStore::appendAction( std::shared_ptr<HistoryAction> action )
3739
stack_[firstRedoIndex_] = std::move( action );
3840
++firstRedoIndex_;
3941

40-
changedSignal( *this, ChangeType::AppendAction );
42+
changedSignal( *this, ChangeType::PostAppendAction, stack_.back() );
4143

4244
filterByMemoryLimit_();
4345
}
@@ -52,7 +54,7 @@ void HistoryStore::clear()
5254
spdlog::info( "History store clear" );
5355
stack_.clear();
5456
firstRedoIndex_ = 0;
55-
changedSignal( *this, ChangeType::Clear );
57+
changedSignal( *this, ChangeType::Clear, {} );
5658
}
5759

5860
void HistoryStore::filterStack( HistoryStackFilter filteringCondition, bool deepFiltering /*= true*/ )
@@ -63,7 +65,7 @@ void HistoryStore::filterStack( HistoryStackFilter filteringCondition, bool deep
6365
const auto [needSignal, redoDecrease] = filterHistoryActionsVector( stack_, filteringCondition, firstRedoIndex_, deepFiltering );
6466
firstRedoIndex_ -= redoDecrease;
6567
if ( needSignal )
66-
changedSignal( *this, ChangeType::Filter );
68+
changedSignal( *this, ChangeType::Filter, {} );
6769
}
6870

6971
bool HistoryStore::undo()
@@ -80,11 +82,11 @@ bool HistoryStore::undo()
8082
if ( stack_[firstRedoIndex_ - 1] )
8183
{
8284
spdlog::info( "History action undo: \"{}\"", stack_[firstRedoIndex_ - 1]->name() );
83-
changedSignal( *this, ChangeType::PreUndo );
85+
changedSignal( *this, ChangeType::PreUndo, stack_[firstRedoIndex_ - 1] );
8486
stack_[firstRedoIndex_ - 1]->action( HistoryAction::Type::Undo );
8587
}
8688
--firstRedoIndex_;
87-
changedSignal( *this, ChangeType::PostUndo );
89+
changedSignal( *this, ChangeType::PostUndo, stack_[firstRedoIndex_] );
8890
return true;
8991
}
9092

@@ -101,11 +103,11 @@ bool HistoryStore::redo()
101103
if ( stack_[firstRedoIndex_] )
102104
{
103105
spdlog::info( "History action redo: \"{}\"", stack_[firstRedoIndex_]->name() );
104-
changedSignal( *this, ChangeType::PreRedo );
106+
changedSignal( *this, ChangeType::PreRedo, stack_[firstRedoIndex_] );
105107
stack_[firstRedoIndex_]->action( HistoryAction::Type::Redo );
106108
}
107109
++firstRedoIndex_;
108-
changedSignal( *this, ChangeType::PostRedo );
110+
changedSignal( *this, ChangeType::PostRedo, stack_[firstRedoIndex_ - 1] );
109111
return true;
110112
}
111113

@@ -167,7 +169,7 @@ void HistoryStore::filterByMemoryLimit_()
167169
stack_.erase( stack_.begin() );
168170
--firstRedoIndex_;
169171
--savedSceneIndex_;
170-
changedSignal( *this, ChangeType::PopAction );
172+
changedSignal( *this, ChangeType::PopAction, nullptr );
171173
}
172174
}
173175

source/MRViewer/MRHistoryStore.h

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -81,16 +81,17 @@ class MRVIEWER_CLASS HistoryStore
8181
/// Signal is called after this store changed
8282
enum class ChangeType
8383
{
84-
AppendAction, ///< additions in scoped block does not provide signal
85-
PreUndo,
86-
PostUndo,
87-
PreRedo,
88-
PostRedo,
89-
Clear,
90-
PopAction, ///< called after removing action that exceeds memory limit
91-
Filter
84+
PreAppendAction, ///< called before action is appended (allows to decorate raw actions with scopes): action - that is about to be added
85+
PostAppendAction, ///< called after action is appended either to store or to current scope: action - one that was just added
86+
PreUndo, ///< called right before action is undone: action - the that will be undone
87+
PostUndo, ///< called right after action is undone: action - the that have been undone
88+
PreRedo, ///< called right before action is redone: action - the that will be redone
89+
PostRedo, ///< called right after action is redone: action - the that have been redone
90+
Clear, ///< called when this store is cleaned: action - nullptr
91+
PopAction, ///< called after removing action that exceeds memory limit: action - nullptr
92+
Filter ///< called after this store is filtered: action - nullptr
9293
};
93-
using HistoryStoreChangedSignal = boost::signals2::signal<void( const HistoryStore& store, ChangeType )>;
94+
using HistoryStoreChangedSignal = boost::signals2::signal<void( const HistoryStore& store, ChangeType, std::shared_ptr<HistoryAction> action )>;
9495
HistoryStoreChangedSignal changedSignal;
9596

9697
private:

source/MRViewer/MRSceneControlMenuItems.cpp

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ UndoMenuItem::UndoMenuItem() :
4444
if ( !historyStoreConnection_.connected() )
4545
{
4646
historyStoreConnection_ = history->changedSignal.connect( MAKE_SLOT( &UndoMenuItem::updateUndoListCache_ ) );
47-
updateUndoListCache_( *history, HistoryStore::ChangeType::AppendAction ); // can by any type
47+
updateUndoListCache_( *history, HistoryStore::ChangeType::PostUndo, {} );
4848
}
4949
} );
5050
}
@@ -73,8 +73,16 @@ std::string UndoMenuItem::getDynamicTooltip() const
7373
return res;
7474
}
7575

76-
void UndoMenuItem::updateUndoListCache_( const HistoryStore& store, HistoryStore::ChangeType )
76+
void UndoMenuItem::updateUndoListCache_( const HistoryStore& store, HistoryStore::ChangeType type, std::shared_ptr<HistoryAction> )
7777
{
78+
if ( type == HistoryStore::ChangeType::PreRedo ||
79+
type == HistoryStore::ChangeType::PreUndo ||
80+
type == HistoryStore::ChangeType::PreAppendAction )
81+
return; // no need to update cache in this case
82+
83+
if ( type == HistoryStore::ChangeType::PostAppendAction && bool( store.getScopeBlockPtr() ) )
84+
return; // no need to update cache for actions in scope
85+
7886
auto lastUndos = store.getNActions( cMaxNumActionsInList, HistoryAction::Type::Undo );
7987
if ( lastUndos.empty() )
8088
{
@@ -109,7 +117,7 @@ RedoMenuItem::RedoMenuItem() :
109117
if ( !historyStoreConnection_.connected() )
110118
{
111119
historyStoreConnection_ = history->changedSignal.connect( MAKE_SLOT( &RedoMenuItem::updateRedoListCache_ ) );
112-
updateRedoListCache_( *history, HistoryStore::ChangeType::AppendAction ); // can by any type
120+
updateRedoListCache_( *history, HistoryStore::ChangeType::PostRedo, {} );
113121
}
114122
} );
115123
}
@@ -137,8 +145,16 @@ std::string RedoMenuItem::getDynamicTooltip() const
137145
return res;
138146
}
139147

140-
void RedoMenuItem::updateRedoListCache_( const HistoryStore& store, HistoryStore::ChangeType )
148+
void RedoMenuItem::updateRedoListCache_( const HistoryStore& store, HistoryStore::ChangeType type, std::shared_ptr<HistoryAction> )
141149
{
150+
if ( type == HistoryStore::ChangeType::PreRedo ||
151+
type == HistoryStore::ChangeType::PreUndo ||
152+
type == HistoryStore::ChangeType::PreAppendAction )
153+
return; // no need to update cache in this case
154+
155+
if ( type == HistoryStore::ChangeType::PostAppendAction && bool( store.getScopeBlockPtr() ) )
156+
return; // no need to update cache for actions in scope
157+
142158
auto lastRedos = store.getNActions( cMaxNumActionsInList, HistoryAction::Type::Redo );
143159
if ( lastRedos.empty() )
144160
{

source/MRViewer/MRSceneControlMenuItems.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class UndoMenuItem : public RibbonMenuItem
1414
virtual std::string getDynamicTooltip() const override;
1515

1616
private:
17-
void updateUndoListCache_( const HistoryStore& store, HistoryStore::ChangeType type );
17+
void updateUndoListCache_( const HistoryStore& store, HistoryStore::ChangeType, std::shared_ptr<HistoryAction> );
1818

1919
boost::signals2::scoped_connection historyStoreConnection_;
2020
};
@@ -28,7 +28,7 @@ class RedoMenuItem : public RibbonMenuItem
2828
virtual std::string getDynamicTooltip() const override;
2929

3030
private:
31-
void updateRedoListCache_( const HistoryStore& store, HistoryStore::ChangeType type );
31+
void updateRedoListCache_( const HistoryStore& store, HistoryStore::ChangeType, std::shared_ptr<HistoryAction> );
3232

3333
boost::signals2::scoped_connection historyStoreConnection_;
3434
};

source/MRViewer/MRViewer.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2813,11 +2813,11 @@ void Viewer::enableGlobalHistory( bool on )
28132813
if ( on )
28142814
{
28152815
globalHistoryStore_ = std::make_unique<HistoryStore>();
2816-
globalHistoryStore_->changedSignal.connect( [this]( const HistoryStore&, HistoryStore::ChangeType type )
2816+
globalHistoryStore_->changedSignal.connect( [this] ( const HistoryStore& st, HistoryStore::ChangeType type, std::shared_ptr<HistoryAction> )
28172817
{
28182818
if ( type == HistoryStore::ChangeType::PostUndo ||
28192819
type == HistoryStore::ChangeType::PostRedo ||
2820-
type == HistoryStore::ChangeType::AppendAction )
2820+
( type == HistoryStore::ChangeType::PostAppendAction && !st.getScopeBlockPtr() ) )
28212821
makeTitleFromSceneRootPath();
28222822
} );
28232823
}

0 commit comments

Comments
 (0)