HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
CH_Collection.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: Channel library (C++)
7  *
8  * COMMENTS: Collection for channel library
9  *
10  */
11 
12 #ifndef __CH_Collection_h__
13 #define __CH_Collection_h__
14 
15 #include "CH_API.h"
16 #include "CH_EventManager.h"
17 #include "CH_Manager.h"
18 #include "CH_ExprLanguage.h"
19 #include <iosfwd>
20 #include <SYS/SYS_Types.h>
21 #include <UT/UT_String.h>
22 #include <UT/UT_ValArray.h>
23 #include <UT/UT_SymbolTable.h>
24 #include <UT/UT_Packet.h>
25 #include <EXPR/EX_Error.h>
26 
27 class CH_Channel;
28 class CH_Collection;
29 class CH_LocalVariable;
30 class CH_Segment;
31 
33 
35 
36 typedef enum {
57 
58 enum {
60 };
61 
62 // Forward declare of OP_Channels so that we can provide a mechanism to
63 // cast to it safely.
64 class OP_Channels;
65 
67 {
68 // Starting at the current input stream position, tries to load
69 // the information about the next collection from the chn or bchn file
70 // that the input stream represents.
71 public:
73  bool begin(UT_String &path);
74  bool end();
75  bool nextCollection(UT_String &path);
76 
77 private:
78  UT_IStream *curr_is;
79  int is_binary;
80 };
81 
83 {
84 public:
85  CH_Collection(CH_Manager *manager);
86  CH_Collection(CH_Manager *manager, const CH_Collection &from);
87  virtual ~CH_Collection();
88 
89  virtual int64 getMemoryUsage(bool inclusive) const;
90 
91  SETUPCLASSPACKETID("CH_Collection");
92 
93  CH_Manager *getManager() const { return myManager; }
94  fpreal getTolerance() const { return myManager->getTolerance(); }
95 
96  virtual int canAccess(uint mask) const;
97  virtual int canAccessChannel(uint mask, const CH_Channel *chp) const;
98 
99  exint entries() const { return myChannelMap.entries(); }
100 
101  //
102  // When getting channels, it's the channel name that is passed,
103  // NOT the path
104  //
105  const CH_Channel *getChannel(const char *name) const;
106  CH_Channel *getChannel(const char *name);
107  const CH_Channel *getChannel(int idx) const { return myChannels(idx); }
108  CH_Channel *getChannel(int idx) { return myChannels(idx); }
109  const CH_Channel *getChannel(const UT_String &name) const
110  {
111  return getChannel((const char *)name);
112  }
114  {
115  return getChannel((const char *)name);
116  }
117 
118  int getChannels(CH_ChannelList &chans,
119  int scope=0) const;
120 
121  int getChannels(CH_ChannelList &chans,
122  const char *pattern) const;
123 
124  int getChannelNames(CH_NameList &list, int scope=0) const;
125  int getChannelCount(int scoped = 0) const;
126 
127  //
128  // Get a collection or channel given a relative path from this collection
129  //
130  virtual CH_Collection *findCollection(const char *path) const = 0;
131  CH_Channel *findChannel (const char *path) const;
132  CH_Channel *findOrCreateChannel (const char *path);
133 
134 
135  //
136  // When adding a channel, adding by name is the safest method since
137  //
138  CH_Channel *addChannel(const char *name);
139  CH_Channel *addChannel(CH_Channel *chp);
140 
141  CH_Channel *dupChannel(const char *name);
142  virtual CH_Channel *dupChannel(const CH_Channel &from);
143 
144  // The following method will rename a channel. Only "spare" channels are
145  // allowed to be re-named. The renaming will fail if the channel is not a
146  // spare channel, or if the channel isn't found.
147  virtual int rename(const char *from_name, const char *to_name,
148  const char *to_alias);
149  virtual int rename(CH_Channel *from, const char *to_name,
150  const char *to_alias);
151 
152  void deleteChannel(CH_Channel *chp);
153  int deleteChannels();
154 
155  //
156  // Methods to get a channel evaluated
157  //
158  fpreal evaluate(CH_Channel *chp, fpreal time,
159  bool no_disabling /*=false*/, int thread);
160  void evaluate(CH_Channel *chp, fpreal from, fpreal to,
161  fpreal *vals, int nsamples,
162  bool no_disabling /*=false*/,
163  bool use_cache /*=false*/, int thread);
164  void evaluateString(UT_String &result,
165  CH_Channel *chp, fpreal time,
166  int thread);
167 
168  //
169  // Reparses all the expressions. Should be done if the local
170  // variables have changed.
171  //
172  void unresolveLocalVars(int thread);
173 
174  //
175  // Now, some common mirrors for system calls
176  //
177  virtual void getFullPath(UT_String &path) const = 0;
178  void getFullPath(const CH_Channel *chp, UT_String &p,
179  bool use_alias=false) const;
180 
181  //
182  // channelFind() & collectionFind() will traverse the channel tree
183  // for the given path, calling the callback on every match of the
184  // specified type. For example: /o*/g*/t?
185  //
186  void channelFind(const char *path, CHfindCallBack callback,
187  void *data = 0) const;
188 
189  // These methods will do word finding/replacement in all expressions of
190  // all channels.
191  void findString(const char *word, bool fullword,
192  bool usewildcards, CHfindCallBack callback,
193  void *data = 0);
194  int findString(const char *word, bool fullword,
195  bool usewildcards) const;
196  int changeString(const char *from, const char *to,
197  bool fullword, int thread);
198 
199  //
200  // The following pure virtuals must be defined by a sub-class.
201  // These provide the collection name and the channel hierarchy.
202  //
203  virtual const UT_String &getName() const = 0;
204 
205  virtual int getUniqueId() const;
206  virtual CH_Collection * lookupCollection(int id) const;
207 
208  virtual const CH_Collection *getParent() const = 0;
209  virtual CH_Collection *getParent() = 0;
210 
211  virtual const CH_Collection *getChild(const char *name) const = 0;
212  virtual CH_Collection *getChild(const char *name) = 0;
213 
214 
215  // This is a mean of accessing the node owner from CH library
216  // It's used only the know if the owner is valid and OP_Node isn't used
217  virtual const void *getOwner() const = 0;
218  virtual void *getOwner() = 0;
219 
220  //
221  // These methods only get child collections, not channels
222  virtual int getChildren(CH_NameList &names) const =0;
223  virtual int getChildren(CH_CollectionList &grps) const =0;
224 
225 
226  virtual bool getVariableValue(UT_String &str,
227  int table, int index,
228  int thread);
229  virtual bool getVariableValue(fpreal &val,
230  int table, int index,
231  int thread);
232 
233  virtual const CH_LocalVariable *resolveVariable(const char *name, int &tab);
234 
235  //
236  // I/O methods
237  //
238  int save(std::ostream &os, int binary, bool compiled,
239  int scope,
240  const CH_ChannelList *channels = NULL) const;
241  int saveToFile(const char *nm) const;
242 
243  template <typename FPREAL_TYPE>
244  bool load(UT_IStream &is, const char *path = 0,
245  const CH_LoadInfo *load_info = 0,
246  CH_ChannelList *loadedChannels = 0,
247  bool delete_keys = false);
248  int loadFromFile(const char *nm);
249 
250  //
251  // Keyframe management & convenience function
252  //
253  fpreal findKey(fpreal gtime, int dir) const;
254  virtual void saveKeyFrameForUndo(CH_Channel *chp, fpreal gtime) = 0;
255 
256  // int anyModified() const;
257  // void clearModified();
258 
259  int getChanged() const { return myModifiedFlag; }
260  virtual void setChanged(CH_CHANGE_TYPE how, void *data=0);
261 
262  void setExpose( bool onoff );
263  bool getExpose() const { return myExpose; }
264 
265  //
266  // Remove and delete all channels
267  //
268  void clearAndDestroy();
269 
270  void initManager(CH_Manager *manager);
271 
273  { return myManager->getGlobalStart(); }
275  { return myManager->getGlobalEnd(); }
276 
277  // returns the 'range' of the collection - the lowest start time and the
278  // highest end time. Returns false if the collection has no 'range'.
279  // Single expressions do not set the range, but will set the timedep
280  // flag if necessary. The timedep flag is set if even one of the channels
281  // is time dependent.
282  bool getCollectionRange(fpreal &start, fpreal &end,
283  bool &timedep, int thread);
284 
286  { myVariables[3] = table; }
287 
288 
289  // This method should only be called by CH_Manager. It signifies
290  // this collection is dependent on a param function and will be
291  // calledback on modification until removeParamDependency is called.
292 
293  void addedParamDependency();
294  void removeParamDependency();
295 
296  // Returns the xform order for this collection given a specific channel.
297  // This defaults to XYZ, but can be overridden by OP_Node types
298  // to handle their specific orders, such as with Objects.
299  virtual void getXformOrder(UT_XformOrder &xord, const CH_Channel *chp) const;
300 
301  // The "external" flag marks this CH_Collection object as not belonging to
302  // any node (ie. standalone).
303  // @{
304  bool getExternal() const
305  { return myExternal; }
306  void setExternal(bool yesno)
307  { myExternal = yesno; }
308  // @}
309 
310  // Set the alias on a channel -- returns true if the alias was
311  // successfully set and false otherwise
312  bool setChannelAlias(CH_Channel &chp, const char *alias);
313 
314  // Returns true if s represents a valid Channel name and false otherwise
315  static bool isValidChannelName(const char *s);
316 
317  // Returns a valid pointer if this instance is of an OP_Channel and
318  // NULL otherwise.
319  virtual OP_Channels *castToOPChannels() { return 0; }
320  virtual const OP_Channels *castToOPChannels() const { return 0; }
321 
322  // Overridden by OP_Channels to add dependencies for local variables
323  virtual void addLocalVarDependency(int table, int index,
324  void *ref_id);
325 
326  CH_ExprLanguage getExprLanguage() const;
327  void setExprLanguage(CH_ExprLanguage language);
328 
329  virtual void getLocalVariables(UT_StringArray &out_vars);
330 
331 protected:
332 
333  // checkExpressionError() is split up into a checking part and an actual
334  // error handling part, evaluationError() so that the checking part can
335  // be inlined.
336  SYS_FORCE_INLINE void
337  checkEvaluationError(const CH_Channel *chp, int thread) const
338  {
339  int err = ev_GetErrNo(thread);
340  if (err != EV_NOERROR)
341  evaluationError(chp, err, thread);
342  }
343 
345  { myVariables[2] = table; }
346  const CH_Collection *getRoot() const;
347  //
348  // Don't publicize our implementation:
349  //
350  const CH_ChannelList *getChannels() const { return &myChannels; }
351 
352  virtual void notifyChannelRenameDependents(const char *old_name,
353  const char *new_name);
354 
355 private:
356  CH_Manager *myManager;
357  CH_LocalVariable *myVariables[4]; // Local var tables
358  CH_ChannelMap myChannelMap;
359  CH_ChannelList myChannels; // For easy traversal
360  CH_ChannelMap *myChannelAliasesTable;
361 
362  int myModifiedFlag; // My modified flag
363 
364  CH_ExprLanguage myExprLanguage;
365 
366  char myParamDependent; // relies on param function
367 
368  bool myExternal;
369  bool myExpose;
370 
371  // evaluationError() generates the appropriate call to opError() and then
372  // clears the expression error state.
373  void evaluationError(const CH_Channel *chp, int err,
374  int thread) const;
375 
376  void deleteChannel(exint index); // Delete from array
377 
378  template <typename FPREAL_TYPE>
379  CH_Channel * loadChannelRange(UT_IStream &is, const char *name,
380  const CH_LoadInfo &load_info);
381 
382  friend class CH_Manager;
383 };
384 
385 CH_API extern void
386 CHcollectionsToOPchannels( CH_CollectionList const& collections,
387  UT_ValArray< OP_Channels* > &op_channels );
388 
389 #endif
CH_Manager * getManager() const
Definition: CH_Collection.h:93
#define SETUPCLASSPACKETID(classname)
Definition: UT_Packet.h:90
#define EV_NOERROR
Definition: EX_Error.h:18
int(* CHfindCallBack)(CH_Collection *grp, CH_Channel *chp, void *)
Definition: CH_Types.h:31
CH_ExprLanguage
GLuint start
Definition: glcorearb.h:474
void setExternal(bool yesno)
const GLuint GLenum const void * binary
Definition: glcorearb.h:1923
GLsizei const GLchar *const * path
Definition: glcorearb.h:3340
bool getExpose() const
GLint GLuint mask
Definition: glcorearb.h:123
void addLocalVariables(CH_LocalVariable *table)
void addDynamicVariables(CH_LocalVariable *table)
const CH_Channel * getChannel(int idx) const
long long int64
Definition: SYS_Types.h:100
fpreal getGlobalEnd() const
CH_CHANGE_TYPE
bool getExternal() const
CH_LOCAL_VARIABLE
Definition: CH_Collection.h:36
int64 exint
Definition: SYS_Types.h:109
GLuint GLuint end
Definition: glcorearb.h:474
#define SYS_FORCE_INLINE
Definition: SYS_Inline.h:45
CH_Channel * getChannel(int idx)
fpreal getTolerance() const
Definition: CH_Collection.h:94
GLboolean * data
Definition: glcorearb.h:130
const CH_ChannelList * getChannels() const
GLuint const GLchar * name
Definition: glcorearb.h:785
CH_API void CHcollectionsToOPchannels(CH_CollectionList const &collections, UT_ValArray< OP_Channels * > &op_channels)
virtual OP_Channels * castToOPChannels()
unsigned int uint
Definition: SYS_Types.h:33
SYS_FORCE_INLINE void checkEvaluationError(const CH_Channel *chp, int thread) const
fpreal getGlobalStart() const
double fpreal
Definition: SYS_Types.h:263
CH_Channel * getChannel(const UT_String &name)
#define CH_API
Definition: CH_API.h:10
GLuint index
Definition: glcorearb.h:785
UT_SymbolMap< CH_Channel * > CH_ChannelMap
Definition: CH_Collection.h:32
GLuint GLfloat * val
Definition: glcorearb.h:1607
const CH_Channel * getChannel(const UT_String &name) const
exint entries() const
Definition: CH_Collection.h:99
virtual const OP_Channels * castToOPChannels() const
int getChanged() const