HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
OP_Take.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: OP_Take.h ( OP Library, C++)
7  *
8  * COMMENTS:
9  */
10 
11 #ifndef __OP_Take__
12 #define __OP_Take__
13 
14 #include "OP_API.h"
15 #include "OP_Node.h"
16 #include <UT/UT_String.h>
17 #include <UT/UT_Functor.h>
18 #include <TAKE/TAKE_Manager.h>
19 #include <iosfwd>
20 
21 class OP_Node;
22 class PRM_Parm;
23 class TAKE_Take;
24 class UT_StringArray;
25 class UT_WorkBuffer;
26 class OP_UndoSync;
27 
28 #define OP_TAKE_FLAG_TOKEN ".flags."
29 #define OP_TAKE_CHANNEL_TOKEN ".chan"
30 
31 #define OP_TAKE_TAKESET_CPIO_PACKET ".cwd"
32 
33 class OP_API OP_Take : public TAKE_Manager {
34 public:
35  OP_Take();
36  ~OP_Take() override;
37 
38  // Methods called to store master take data
39  void storeTakeFlag(OP_Node *node, uchar flag);
40  void storeTakeParm(OP_Node *node, PRM_Parm *parm, bool join=1,
41  bool auto_take=false);
42 
43  void clearTakeFlag(OP_Node *node, uchar flag);
44  void clearTakeParm(OP_Node *node, PRM_Parm *parm);
45 
46  void clearTakeData(int id, const char *label);
47 
48  void switchToTake(TAKE_Take *take, bool force=false) override;
49 
50  void storeCurrentTake(OP_Node *root, bool force_master=false)
51  {
52  // We don't want to store the master take. Its data is
53  // always set by the other takes. When we recursively
54  // store the take data, we only care about branches which
55  // actually have active take data.
56  if (force_master || !isMasterTake())
57  recurseStoreCurrent(root, true);
58  }
59 
60  // Clear the active parameters for the current take
61  static void clearActiveFlags(OP_Node *root);
62 
63  // Utility method to check whether the current take manager is in
64  // a state which could automatically activate parameters in the
65  // current take.
66  static bool autoActivationActive();
67 
68  // Utility method to check whether the specified parameter needs to
69  // be auto activated.
70  static bool needsParmAutoActivation(PRM_Parm *parm);
71 
72  // Utility method to check whether the specified flag needs to
73  // be auto activated.
74  static bool needsFlagAutoActivation(OP_Node *node, uchar flag);
75 
76  // Utility method to extract nodes and tokens (parm and flag) from a given
77  // take. The caller must specify a mapping functor to convert flag chars
78  // into appropriate tokens.
79  static void getNodesAndTokens(const TAKE_Take *take,
81  OP_NodeList &nodes, UT_StringArray &tokens);
82 
83  TAKE_Data *dataFactory(const char *oppath, const char *label) override;
85  const char *name,
86  const TAKE_Take *take = 0) override;
87 
88  // Command callbacks
89  bool takeSet(const char *name);
90  bool takeMove(const char *name, const char *newparent,
91  bool skip_current_restore = false);
92  bool takeMerge(const char *dest, UT_StringArray &sources,
93  bool override, UT_StringArray *missed = 0);
94  bool takeRemove(const char *name, bool recursive);
95  bool takeRename(const char *oldname, const char *newname);
96  TAKE_Take *takeAdd(const char *name, const char *parent=0);
97  TAKE_Take *takeInsert(const char *name, const char *parent=0);
98  bool takeInfo(const char *takename, UT_WorkBuffer &buf,
99  int indent=0, bool contents=true,
100  bool memusage=true);
101  bool takeCommands(const char *takename, std::ostream &os);
102  bool takeCopy(const char *takename, std::ostream &os, bool recurse);
103  bool takePaste(UT_IStream &is, const char *parent=0,
104  UT_ValArray<TAKE_Take *> *created_list=0);
105 
106  void takeRestoreCurrent(TAKE_Take *take);
107 
108  void nodesDeleted(OP_NodeList &nodes);
109 
110  void removeSpareParm(OP_Node *node, const char *parmname);
111 
112  // A helper class to aid when merging in another hip file.
114  {
115  public:
116  MergeContext() : myDelayTakeSwitch(false) {}
117 
118  // The merge prefix is the string prepended to all merged takes.
119  const UT_String &getMergePrefix() const
120  { return myMergePrefix; }
121  void setMergePrefix(const char *s)
122  { harden(myMergePrefix, s); }
123 
124  // The merge master take string records the name of the master
125  // take from the merged file.
127  { return myMergeMasterTake; }
128  void setMergeMasterTake(const char *s)
129  { harden(myMergeMasterTake, s); }
130 
131  // A flag instructing OP_Take::takeSet() to delay any non-trivial
132  // take switch.
133  bool getDelayTakeSwitch() const
134  { return myDelayTakeSwitch; }
135  void setDelayTakeSwitch(bool flag)
136  { myDelayTakeSwitch = flag; }
137 
138  // A string recording the delayed take switch, if any.
139  const UT_String &getDelayedTake() const
140  { return myDelayedTake; }
141  void setDelayedTake(const char *s)
142  { harden(myDelayedTake, s); }
143  private:
144  void harden(UT_String &str, const char *s)
145  { if (s) str.harden(s); else str = 0; }
146 
147  UT_String myMergePrefix;
148  UT_String myMergeMasterTake;
149  UT_String myDelayedTake;
150  bool myDelayTakeSwitch;
151  };
152 
153  // The following method is used to copy the data in all the takes for
154  // a particular node to another another node, whenever possible. Note
155  // that this method does not actually change any parameters, and so it
156  // may be necessary to call the takeRestoreCurrent() method after calling
157  // this.
158  void copyDataFromNode(OP_Node *dest, const OP_Node *src);
159 
160  // The following method is used to merge in the takes loaded during the
161  // OP_Network::loadNetwork() call while merging. A new child take will
162  // be added to the master take to act as the root for all merged takes.
163  // All new takes are prefixed with a string derived from the supplied
164  // prefix string. The provided merge context is updated to store the
165  // prefix string used as well as the name of the master take from the
166  // merged hierarchy.
167  void networkLoadMerge(OP_Take &src, const char *prefix,
168  MergeContext &context);
169 
170  // Register/unregister a merge context to be used during the takeSet()
171  // method.
172  void setMergeContext(MergeContext *context);
173 
174  // The main idea behind the "Sync Contexts" is very simple. We have to
175  // be in the master take in order to properly synchronize an asset with
176  // its definition. These "Sync Contexts" allow us to potentially group
177  // multiple synchronizations together and minimize the number of context
178  // switches. As such, it is critical that any calls to syncingNode be
179  // made only while in a "Sync Context".
180  void pushSyncContext();
181  void syncingNode(OP_Node *node);
182  void popSyncContext();
183 
184  // Normally the take manager is not notified of node deletions during
185  // an undo/redo operation. The following methods can be used to override
186  // this behaviour.
187  void setHandleNodeDeletionDuringUndoFlag(bool flag);
189  { return myHandleNodeDeletionDuringUndoFlag; }
190 
191  // The following methods allow the user to set or query the current
192  // sync undo in which deletion of take data will be recorded if we
193  // are unable to add an undo ourselves. It is an error to attempt
194  // to set a sync undo while one is currently set.
195  void setSyncUndo(OP_UndoSync *);
196  OP_UndoSync *getSyncUndo() const { return mySyncUndo; }
197 
198  // The following method is used for internal changing of the current
199  // take, necessary during asset synchronization. It is only public
200  // because OP_UndoSync needs access to it.
201  bool internalTakeSetForSync(const char *name);
202  void renameTake(TAKE_Take *take, const char *name) override;
203 
204 protected:
205  void setACTIVETAKE(TAKE_Take *take);
206  void recurseStoreCurrent(OP_Node *node, bool partial_recurse);
207  void recursiveDestroy(TAKE_Take *take,
208  bool *cleaned_dead_data_from_master_take = 0);
209  bool recursiveNodeDeleted(TAKE_Take *take, OP_NodeList &node,
211 
212 
213 private:
214  int mySyncDepth;
215  UT_String mySyncTake;
216 
217  OP_UndoSync *mySyncUndo;
218  bool myHandleNodeDeletionDuringUndoFlag;
219 
220  MergeContext *myMergeContext;
221 };
222 
223 #endif
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glcorearb.h:2540
GLuint GLsizei const GLchar * label
Definition: glcorearb.h:2545
virtual void switchToTake(TAKE_Take *take, bool force_even_if_current=false)
void setMergeMasterTake(const char *s)
Definition: OP_Take.h:128
const UT_String & getDelayedTake() const
Definition: OP_Take.h:139
GLdouble s
Definition: glad.h:3009
bool handlesNodeDeletionDuringUndo() const
Definition: OP_Take.h:188
const UT_String & getMergePrefix() const
Definition: OP_Take.h:119
bool getDelayTakeSwitch() const
Definition: OP_Take.h:133
OP_UndoSync * getSyncUndo() const
Definition: OP_Take.h:196
GLsizei GLenum * sources
Definition: glcorearb.h:2542
void storeCurrentTake(OP_Node *root, bool force_master=false)
Definition: OP_Take.h:50
virtual void notifyObservers(TAKE_Event::TAKE_EventType type, const char *name, const TAKE_Take *take=0)
void setDelayedTake(const char *s)
Definition: OP_Take.h:141
void harden()
Take shallow copy and make it deep.
Definition: UT_String.h:215
GLuint const GLchar * name
Definition: glcorearb.h:786
virtual TAKE_Data * dataFactory(const char *oppath, const char *label)=0
bool isMasterTake()
Definition: TAKE_Manager.h:74
SIM_API const UT_StringHolder force
#define OP_API
Definition: OP_API.h:10
void setDelayTakeSwitch(bool flag)
Definition: OP_Take.h:135
void setMergePrefix(const char *s)
Definition: OP_Take.h:121
type
Definition: core.h:1059
const UT_String & getMergeMasterTake() const
Definition: OP_Take.h:126
unsigned char uchar
Definition: SYS_Types.h:42
auto join(It begin, Sentinel end, string_view sep) -> join_view< It, Sentinel >
Definition: format.h:2559
GLenum src
Definition: glcorearb.h:1793