00001 /* 00002 * PROPRIETARY INFORMATION. This software is proprietary to 00003 * Side Effects Software Inc., and is not to be reproduced, 00004 * transmitted, or disclosed in any way without written permission. 00005 * 00006 * Produced by: 00007 * Ramin Kamal 00008 * Side Effects Software Inc 00009 * 477 Richmond Street West 00010 * Toronto, Ontario 00011 * Canada M5V 3E7 00012 * 416-504-9876 00013 * 00014 * NAME: UT_Undo.h ( Utility Library, C++) 00015 * 00016 * COMMENTS: 00017 * This is a virtual base class defining an undoable operation 00018 * 00019 * Note: The destructor deletes the next undo as well. 00020 */ 00021 00022 #ifndef __UT_Undo__ 00023 #define __UT_Undo__ 00024 00025 #include "UT_API.h" 00026 00027 #include <SYS/SYS_Types.h> 00028 00029 class UT_String; 00030 00031 class UT_API UT_Undo 00032 { 00033 public: 00034 UT_Undo(); 00035 virtual ~UT_Undo(); 00036 00037 virtual void undo() = 0; 00038 virtual void redo() = 0; 00039 00040 // If isValid() is false, then UT_UndoManager is able to free the undo. 00041 virtual bool isValid() { return true; } 00042 00043 // needToUndo/Redo return true if undoing/redoing this UT_Undo would 00044 // actually change something, or false otherwise. For example, false would 00045 // be returned if you try to undo a geometry selection after closing the 00046 // SOP viewer you performed that selection in. (Without the SOP viewer up, 00047 // you wouldn't see the selection being undone so the undo didn't actually 00048 // do anything as far as the user is concerned). Basically, returning 00049 // false is a hint to the UT_UndoManager that it should skip this undo and 00050 // go on to undo the next thing on its stack (although calling undo/redo 00051 // even if needTo returns false is still allowed) 00052 virtual bool needToUndo() { return isValid(); } 00053 virtual bool needToRedo() { return isValid(); } 00054 00055 // isUndoBlock returns 1 if and only if this object is a UT_UndoBlock 00056 // object. 00057 virtual int isUndoBlock() const { return 0; } 00058 00059 // In the case of DM-based undos, the UT_Undo constructor will 00060 // set the memory usage size initially to the size of the object 00061 // itself, and as each undo object in the class hierarchy gets 00062 // gets initialized, it will increment this size using 00063 // addToMemoryUsage() for additional memory that must be accounted for 00064 // (data pointed to by members, etc.) 00065 virtual int64 getMemoryUsage() { return myMemUsage; } 00066 void addToMemoryUsage(int64 k) { myMemUsage += k; } 00067 void setMemoryUsage(int64 k) { myMemUsage = k; } 00068 00069 void setNextUndo(UT_Undo *nundo) { myNextUndo = nundo; } 00070 UT_Undo *getNextUndo() { return myNextUndo; } 00071 00072 protected: 00073 // generate a unique filename in the HOUDINI_TMP_DIR. Note that only 00074 // the first five chars of prefix are used, the rest are ignored. 00075 void generateTmpFilename(const char *prefix, 00076 UT_String &filename); 00077 00078 private: 00079 int64 myMemUsage; 00080 00081 UT_Undo *myNextUndo; 00082 }; 00083 00084 #endif 00085
1.5.9