7 #include "ctrlHistory/SCommandHistory.hpp" 9 #include <fwCom/Signal.hpp> 10 #include <fwCom/Signal.hxx> 11 #include <fwCom/Signals.hpp> 12 #include <fwCom/Slot.hpp> 13 #include <fwCom/Slot.hxx> 14 #include <fwCom/Slots.hpp> 15 #include <fwCom/Slots.hxx> 17 #include <fwData/mt/ObjectWriteLock.hpp> 19 #include <fwDataCamp/exception/ObjectNotFound.hpp> 20 #include <fwDataCamp/getObject.hpp> 29 static const ::fwCom::Signals::SignalKeyType s_CANUNDO_SIGNAL =
"canUndo";
30 static const ::fwCom::Signals::SignalKeyType s_CANREDO_SIGNAL =
"canRedo";
32 static const ::fwCom::Slots::SlotKeyType s_ENQUEUE_SLOT =
"enqueue";
33 static const ::fwCom::Slots::SlotKeyType s_UNDO_SLOT =
"undo";
34 static const ::fwCom::Slots::SlotKeyType s_REDO_SLOT =
"redo";
35 static const ::fwCom::Slots::SlotKeyType s_CLEAR_SLOT =
"clear";
41 newSlot(s_ENQUEUE_SLOT, &SCommandHistory::enqueue,
this);
42 newSlot(s_UNDO_SLOT, &SCommandHistory::undo,
this);
43 newSlot(s_REDO_SLOT, &SCommandHistory::redo,
this);
44 newSlot(s_CLEAR_SLOT, &SCommandHistory::clear,
this);
46 m_canUndoSig = newSignal< CanDoSignalType >( s_CANUNDO_SIGNAL );
47 m_canRedoSig = newSignal< CanDoSignalType >( s_CANREDO_SIGNAL );
60 ::fwServices::IService::ConfigType config = this->
getConfigTree();
62 auto maxCommands = config.get_optional<
size_t >(
"maxCommands");
63 auto maxMemory = config.get_optional<
size_t >(
"maxMemory");
65 if(maxCommands.is_initialized())
70 if(maxMemory.is_initialized())
95 m_undoRedoManager.
clear();
100 void SCommandHistory::enqueue(fwCommand::ICommand::sptr command)
102 m_undoRedoManager.
enqueue(command);
103 this->emitModifSig();
108 void SCommandHistory::undo()
110 m_undoRedoManager.
undo();
111 this->emitModifSig();
116 void SCommandHistory::redo()
118 m_undoRedoManager.
redo();
119 this->emitModifSig();
124 void SCommandHistory::clear()
126 m_undoRedoManager.
clear();
127 this->emitModifSig();
132 void SCommandHistory::emitModifSig()
const 134 m_canUndoSig->asyncEmit(m_undoRedoManager.
canUndo());
135 m_canRedoSig->asyncEmit(m_undoRedoManager.
canRedo());
Base class for all services.
virtual CTRLHISTORY_API void configuring() override
Set memory and command boundaries.
virtual CTRLHISTORY_API ~SCommandHistory()
Destructor.
FWCOMMAND_API bool canUndo() const
Return true if we can undo.
FWCOMMAND_API bool enqueue(ICommand::sptr cmd)
Push a command to the history.
virtual CTRLHISTORY_API void updating() override
Notify if undo or redo are possible.
CTRLHISTORY_API SCommandHistory()
Constructor.
The namespace ctrlHistory contains services handling command histories.
FWCOMMAND_API void setCommandCount(size_t cmdCount)
Set the maximum number of enqueued commands.
FWCOMMAND_API bool undo()
Execute the previous command if any.
FWCOMMAND_API bool canRedo() const
Return true if we can redo.
Base class for each data object.
This service manages a command history. The history is modified when receiving "undo", "redo", "enqueue" or "clear" signal.
FWCOMMAND_API bool redo()
Execute the next command if any.
virtual CTRLHISTORY_API void stopping() override
Clears the history.
virtual CTRLHISTORY_API void starting() override
Notify if undo or redo are possible.
FWCOMMAND_API void clear()
Remove all commands in history.
FWCOMMAND_API void setHistorySize(size_t histSize)
Set the maximum amount of memory used by the history.
FWSERVICES_API ConfigType getConfigTree() const
Return the configuration, in an boost property tree.