MeVisLabToolboxReference
MeVisLab/Standard/Sources/ML/MLCSO/CSOBase/CSOUndoRedo/CSOUndoRedoManager.h
Go to the documentation of this file.
00001 // **InsertLicense** code
00002 //----------------------------------------------------------------------------------
00004 
00009 //----------------------------------------------------------------------------------
00010 
00011 #ifndef __CSOUndoRedoManager_H
00012 #define __CSOUndoRedoManager_H
00013 
00014 #include "CSOUndoRedoCommands.h"
00015 
00016 
00017 ML_START_NAMESPACE
00018 
00019 
00021 
00024 class MLCSO_EXPORT CSOUndoRedoManager
00025 {
00026 
00027 public:
00028 
00030   enum UNDO_MODE {
00031     MODE_UNDOING = 0, 
00032     MODE_REDOING = 1, 
00033     MODE_NORMAL  = 2  
00034   };
00035 
00036 
00038   CSOUndoRedoManager(CSOList* csoList);
00039 
00041   ~CSOUndoRedoManager();
00042 
00046   void addCommand(CSOCommand* command);
00049   void popUndoCommand();
00050 
00051 
00053   void undo();
00055   void redo();
00056 
00058   void openGroup();
00060   void closeGroup();
00061 
00063   void clearUndo();
00065   void clearRedo();
00067   void clearAll();
00068 
00069 
00071   void pushUndoCommand(CSOCommand* command);
00073   void pushRedoCommand(CSOCommand* command);
00074 
00075 
00077   bool canUndo() const;
00079   bool canRedo() const;
00080 
00082   inline int maxNumUndos() const { return _maxUndoSize; }
00084   void setMaxNumUndos(int maxNumUndos);
00085 
00086 
00088   int numUndos() const;
00090   int numRedos() const;
00091 
00093   bool isInUndoMode() const;
00095   bool isInRedoMode() const;
00096 
00098   inline void enableUndoRedo() { _isEnabled = true; }
00101   inline void disableUndoRedo() { _isEnabled = false;}
00102 
00104   inline bool isEnabled() { return _isEnabled; }
00105 
00106 private:
00107 
00109   void executeGroup(std::vector<CSOCommand*>& stack);
00110 
00111   void increaseUndoSize();
00112   void decreaseUndoSize();
00113 
00114   void removeFirstUndo();
00115 
00117   std::vector<CSOCommand*> _undoStack;
00118 
00120   std::vector<CSOCommand*> _redoStack;
00121 
00123   int _mode;
00124 
00125   int _maxUndoSize;
00126   int _currentUndoSize;
00127   int _currentRedoSize;
00128 
00129   int _currentGroupId;
00130   int _currentGroupDepth;
00131 
00133   bool _isEnabled;
00134 
00135   CSOList* _csoList;
00136 };
00137 
00139 
00140 
00141 
00142 ML_END_NAMESPACE
00143 
00144 
00145 #endif // __CSOUndoRedoManager_H_