HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
UT_Undo.h
Go to the documentation of this file.
1 /*
2  * PROPRIETARY INFORMATION. This software is proprietary to
3  * Side Effects Software Inc., and is not to be reproduced,
4  * transmitted, or disclosed in any way without written permission.
5  *
6  * NAME: UT_Undo.h ( Utility Library, C++)
7  *
8  * COMMENTS:
9  * This is a virtual base class defining an undoable operation
10  *
11  * Note: The destructor deletes the next undo as well.
12  */
13 
14 #ifndef __UT_Undo__
15 #define __UT_Undo__
16 
17 #include "UT_API.h"
18 
19 #include <SYS/SYS_Types.h>
20 
21 class UT_String;
22 
24 {
25 public:
26  UT_Undo();
27  virtual ~UT_Undo();
28 
29  virtual void undo() = 0;
30  virtual void redo() = 0;
31 
32  // If isValid() is false, then UT_UndoManager is able to free the undo.
33  virtual bool isValid() { return true; }
34 
35  // needToUndo/Redo return true if undoing/redoing this UT_Undo would
36  // actually change something, or false otherwise. For example, false would
37  // be returned if you try to undo a geometry selection after closing the
38  // SOP viewer you performed that selection in. (Without the SOP viewer up,
39  // you wouldn't see the selection being undone so the undo didn't actually
40  // do anything as far as the user is concerned). Basically, returning
41  // false is a hint to the UT_UndoManager that it should skip this undo and
42  // go on to undo the next thing on its stack (although calling undo/redo
43  // even if needTo returns false is still allowed)
44  virtual bool needToUndo() { return isValid(); }
45  virtual bool needToRedo() { return isValid(); }
46 
47  // isUndoBlock returns 1 if and only if this object is a UT_UndoBlock
48  // object.
49  virtual int isUndoBlock() const { return 0; }
50 
51  // In the case of DM-based undos, the UT_Undo constructor will
52  // set the memory usage size initially to the size of the object
53  // itself, and as each undo object in the class hierarchy gets
54  // gets initialized, it will increment this size using
55  // addToMemoryUsage() for additional memory that must be accounted for
56  // (data pointed to by members, etc.)
57  virtual int64 getMemoryUsage() { return myMemUsage; }
58  void addToMemoryUsage(int64 k) { myMemUsage += k; }
59  void setMemoryUsage(int64 k) { myMemUsage = k; }
60 
61  void setNextUndo(UT_Undo *nundo) { myNextUndo = nundo; }
62  UT_Undo *getNextUndo() { return myNextUndo; }
63 
64 protected:
65  // generate a unique filename in the HOUDINI_TMP_DIR. Note that only
66  // the first five chars of prefix are used, the rest are ignored.
67  void generateTmpFilename(const char *prefix,
68  UT_String &filename);
69 
70 private:
71  int64 myMemUsage;
72 
73  UT_Undo *myNextUndo;
74 };
75 
76 #endif
77 
void setNextUndo(UT_Undo *nundo)
Definition: UT_Undo.h:61
virtual bool needToRedo()
Definition: UT_Undo.h:45
void setMemoryUsage(int64 k)
Definition: UT_Undo.h:59
virtual int isUndoBlock() const
Definition: UT_Undo.h:49
virtual bool isValid()
Definition: UT_Undo.h:33
void addToMemoryUsage(int64 k)
Definition: UT_Undo.h:58
#define UT_API
Definition: UT_API.h:12
long long int64
Definition: SYS_Types.h:106
virtual int64 getMemoryUsage()
Definition: UT_Undo.h:57
UT_Undo * getNextUndo()
Definition: UT_Undo.h:62
virtual bool needToUndo()
Definition: UT_Undo.h:44