HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups 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 #include "UT_NonCopyable.h"
19 #include <SYS/SYS_Types.h>
20 
21 class UT_String;
22 
24 {
25 public:
26  UT_Undo();
27  virtual ~UT_Undo();
28 
30 
31  virtual void undo() = 0;
32  virtual void redo() = 0;
33 
34  // If isValid() is false, then UT_UndoManager is able to free the undo.
35  virtual bool isValid() { return true; }
36 
37  // needToUndo/Redo return true if undoing/redoing this UT_Undo would
38  // actually change something, or false otherwise. For example, false would
39  // be returned if you try to undo a geometry selection after closing the
40  // SOP viewer you performed that selection in. (Without the SOP viewer up,
41  // you wouldn't see the selection being undone so the undo didn't actually
42  // do anything as far as the user is concerned). Basically, returning
43  // false is a hint to the UT_UndoManager that it should skip this undo and
44  // go on to undo the next thing on its stack (although calling undo/redo
45  // even if needTo returns false is still allowed)
46  virtual bool needToUndo() { return isValid(); }
47  virtual bool needToRedo() { return isValid(); }
48 
49  // isUndoBlock returns 1 if and only if this object is a UT_UndoBlock
50  // object.
51  virtual int isUndoBlock() const { return 0; }
52 
53  // In the case of DM-based undos, the UT_Undo constructor will
54  // set the memory usage size initially to the size of the object
55  // itself, and as each undo object in the class hierarchy gets
56  // gets initialized, it will increment this size using
57  // addToMemoryUsage() for additional memory that must be accounted for
58  // (data pointed to by members, etc.)
59  virtual int64 getMemoryUsage() { return myMemUsage; }
60  void addToMemoryUsage(int64 k) { myMemUsage += k; }
61  void setMemoryUsage(int64 k) { myMemUsage = k; }
62 
63  void setNextUndo(UT_Undo *nundo) { myNextUndo = nundo; }
64  UT_Undo *getNextUndo() { return myNextUndo; }
65 
66 protected:
67  // generate a unique filename in the HOUDINI_TMP_DIR. Note that only
68  // the first five chars of prefix are used, the rest are ignored.
69  void generateTmpFilename(const char *prefix,
71 
72 private:
73  int64 myMemUsage;
74 
75  UT_Undo *myNextUndo;
76 };
77 
78 #endif
79 
void setNextUndo(UT_Undo *nundo)
Definition: UT_Undo.h:63
virtual bool needToRedo()
Definition: UT_Undo.h:47
void setMemoryUsage(int64 k)
Definition: UT_Undo.h:61
GT_API const UT_StringHolder filename
virtual int isUndoBlock() const
Definition: UT_Undo.h:51
virtual bool isValid()
Definition: UT_Undo.h:35
void addToMemoryUsage(int64 k)
Definition: UT_Undo.h:60
#define UT_API
Definition: UT_API.h:14
#define UT_NON_COPYABLE(CLASS)
Define deleted copy constructor and assignment operator inside a class.
long long int64
Definition: SYS_Types.h:116
virtual int64 getMemoryUsage()
Definition: UT_Undo.h:59
UT_Undo * getNextUndo()
Definition: UT_Undo.h:64
virtual bool needToUndo()
Definition: UT_Undo.h:46