HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
TAKE_Manager.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: TAKE_Manager.h ( TAK Library, C++)
7  *
8  * COMMENTS: Manage all layers
9  */
10 
11 #ifndef __TAKE_Manager__
12 #define __TAKE_Manager__
13 
14 #include "TAKE_API.h"
15 #include "TAKE_Event.h"
16 #include <UT/UT_Array.h>
17 #include <UT/UT_String.h>
18 #include <UT/UT_SymbolTable.h>
19 #include <iosfwd>
20 
21 class UT_String;
22 class UT_StringArray;
23 class TAKE_Data;
24 class TAKE_DataId;
25 class TAKE_Take;
26 class TAKE_StringSaver;
27 
29 public:
30  TAKE_Manager();
31  virtual ~TAKE_Manager();
32 
33  static TAKE_Manager *getCurrentManager();
34  static void setCurrentManager(TAKE_Manager *mgr);
35 
36  static bool getAutoIncludeModeFlag()
37  { return ourAutoIncludeModeFlag; }
38  static void setAutoIncludeModeFlag(bool state)
39  { ourAutoIncludeModeFlag = state; }
40 
42  { return ourAutoIncludeLockedAssetsFlag; }
43  static void setAutoIncludeLockedAssetsFlag(bool state)
44  { ourAutoIncludeLockedAssetsFlag = state; }
45 
46  TAKE_Take *getMasterTake() { return myMasterTake; }
47  // Destroy the specified take, and, if cleaned_dead_data_from_master_take
48  // is provided, set it to true if we've cleaned dead data from the master
49  // take.
50  void destroyTake(TAKE_Take *take,
51  bool *cleaned_dead_data_from_master_take = 0);
52 
53  void clear();
54 
55  TAKE_Take *findTake(const char *name);
56 
57  void getTakes(UT_Array<TAKE_Take *> &takes) const;
58 
59  virtual void switchToTake(TAKE_Take *take,
60  bool force_even_if_current=false);
61 
62  bool isSwitching() const { return mySwitching; }
63 
64  // Re-apply all the take data for a particular take data id
65  void reApplyTake(const TAKE_DataId &id);
66 
67  // Insert a layer with the current layer as a parent layer. All children
68  // of the current layer will inherit values from the new layer. If the
69  // parent is null, then the take will be added as a child of the current
70  // take.
71  TAKE_Take *insertTake(const char *name, const char *parent = 0);
72 
73  TAKE_Take *getCurrentTake() { return myCurrentTake; }
74  bool isMasterTake() { return myCurrentTake==myMasterTake; }
75 
76  int globTakes(UT_Array<TAKE_Take *> &list, const char *pattern);
77 
78  virtual void renameTake(TAKE_Take *take, const char *newname);
79  bool reparentTake(TAKE_Take *take, TAKE_Take *parent);
80 
81  // Find the take in the tree which defines the data entity. If from_which
82  // is 0, the definition will be found by scanning from the current take.
83  // If a null ptr is returned, the parameter is defined in the take
84  // specified.
85  TAKE_Take *findDefinition(const TAKE_DataId &id, TAKE_Take *from_which=0);
86 
87  int getListSerial() const { return myListSerial; }
88 
89  const char *getDefaultTakeName() { return myTakeName; }
90  void setDefaultTakeName(const char *s);
91 
92  //
93  // Merge the take data from the source take into the destination take. If
94  // the override is set, then any data in the destination will be
95  // overwritten by the source take.
96  bool mergeTake(TAKE_Take *dest, TAKE_Take *src,
97  bool overwrite_dest=false);
98 
99  // Saving and loading the master take.
100  virtual int save(std::ostream &os, int binary) const;
101  virtual bool load(UT_IStream &is);
102 
103  int saveTake(TAKE_StringSaver &strings, TAKE_Take *take,
104  std::ostream &os, int bin, bool recurse) const;
105  bool loadTake(UT_StringArray &strings, TAKE_Take *parent,
106  UT_IStream &is,
107  UT_Array<TAKE_Take *> *createdTakes);
108 
109  int copyTake(std::ostream &os, TAKE_Take *take,
110  bool binary, bool recurse) const;
111  bool pasteTake(UT_IStream &is,
112  UT_Array<TAKE_Take *> &createdTakes,
113  TAKE_Take *under = 0);
114 
115  // Stashes the specified layer and all the inherited layers
116  int stashTakeForUndo(TAKE_Take *layer,
117  std::ostream &os, int binary) const;
118  // Restore a layer from a stash
119  bool restoreTakeForUndo(UT_IStream &is);
120 
121  // During the loading process, we need to create data of arbitrary types.
122  // The dataFactory() us used to build the data for us. The path/label of
123  // the data id must be sufficient information to construct the data.
124  virtual TAKE_Data *dataFactory(const char *oppath, const char *label) = 0;
125 
126  virtual void notifyObservers(TAKE_Event::TAKE_EventType type,
127  const char *name,
128  const TAKE_Take *take=0);
129 
131 
132 protected:
133  // Build a list of all the takes (in reverse order) from the specified take
134  // to the root.
135  int buildTakeTree(TAKE_Take *take,
136  UT_Array<TAKE_Take *> &list);
137  bool generateName(const char *name, UT_String &result);
138  bool generateUniquePrefix(const char *name, UT_String &result);
139 
143 
144  // A method to allow a derived class to query whether the current take
145  // is pending activation.
147  { return myCurrentActivationPendingFlag; }
148 
149  // A method to allow a derived class to perform the pending activation of
150  // the current take.
151  void handlePendingTakeActivation();
152 
153  // Absorb the specified external take hierachy, rooting it at a new top
154  // level child take. The return value is the newly created root take
155  // for the merged hierarchy, or 0 if the external hierarchy is empty, as
156  // no root take is created.
157  //
158  // A common (unique) prefix, derived from prefix_base, is used for this
159  // new root and all merged takes. The current_take_to_require_activation
160  // argument, if true, indicates that if the next processed take switch is
161  // to the current take (i.e. a null op), we must still activate the current
162  // take. This will typically only be necessary if the current take is the
163  // master take as we're otherwise only adding new takes, not modifying
164  // existing take data.
165  // TODO: src argument is not const because of TAKE_Take::getChild().
166  TAKE_Take *mergeExternal(TAKE_Manager &src,
167  const char *prefix_base,
168  bool current_take_to_require_activation,
169  UT_String &prefix);
170 
171 private:
172  TAKE_Take *createTake(TAKE_Take *parent, const char *name);
173  void createMasterTake();
174  void destroyMasterTake();
175  bool saveMagic(std::ostream &os) const;
176  bool loadMagic(UT_IStream &is,
177  int &vmajor, int &vminor) const;
178 
179  void mergeExternal(TAKE_Take *parent, TAKE_Take *src,
180  const char *prefix, bool recurse);
181 
182  int myListSerial;
183  UT_NotifierImpl<TAKE_Event &> myEventNotifier;
184  UT_String myTakeName;
185  bool mySwitching;
186 
187  // This flag is used to indicate that, while we may have a current take
188  // set, it has not been properly activated.
189  bool myCurrentActivationPendingFlag;
190 
191  static bool ourAutoIncludeModeFlag;
192  static bool ourAutoIncludeLockedAssetsFlag;
193 };
194 
195 #endif
const char * getDefaultTakeName()
Definition: TAKE_Manager.h:89
GLuint GLsizei const GLchar * label
Definition: glcorearb.h:2545
bool isSwitching() const
Definition: TAKE_Manager.h:62
static bool getAutoIncludeModeFlag()
Definition: TAKE_Manager.h:36
const GLuint GLenum const void * binary
Definition: glcorearb.h:1924
GLdouble s
Definition: glad.h:3009
static void setAutoIncludeModeFlag(bool state)
Definition: TAKE_Manager.h:38
**But if you need a result
Definition: thread.h:613
UT_NotifierImpl< TAKE_Event & > & getEventNotifier()
Definition: TAKE_Manager.h:130
static void setAutoIncludeLockedAssetsFlag(bool state)
Definition: TAKE_Manager.h:43
GLenum GLuint GLint GLint layer
Definition: glcorearb.h:1299
bool isCurrentTakeActivationPending() const
Definition: TAKE_Manager.h:146
static bool getAutoIncludeLockedAssetsFlag()
Definition: TAKE_Manager.h:41
GLuint const GLchar * name
Definition: glcorearb.h:786
GLushort pattern
Definition: glad.h:2583
GLsizei const GLchar *const * strings
Definition: glcorearb.h:1933
bool isMasterTake()
Definition: TAKE_Manager.h:74
Attempt to access an object that no longer exists in Houdini Invalid output Invalid type The attempted operation failed Node initialization script failed Failed to modify node or parameter because of a permission error Possible causes include locked takes
Definition: HOM_Errors.h:191
TAKE_Take * getCurrentTake()
Definition: TAKE_Manager.h:73
TAKE_Take * myMasterTake
Definition: TAKE_Manager.h:141
TAKE_Take * myCurrentTake
Definition: TAKE_Manager.h:142
UT_SymbolMap< TAKE_Take * > myNameSpace
Definition: TAKE_Manager.h:140
TAKE_Take * getMasterTake()
Definition: TAKE_Manager.h:46
int getListSerial() const
Definition: TAKE_Manager.h:87
type
Definition: core.h:1059
#define TAKE_API
Definition: TAKE_API.h:10
GLenum src
Definition: glcorearb.h:1793