HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
PRM_ParmList.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: PRM_ParmList.h (Parameter Library)
7  *
8  * COMMENTS:
9  * This class is in charge of organizing PRM_Parms.
10  * It also handles variables associated with a group
11  * of parameters.
12  */
13 
14 #ifndef __PRM_ParmList__
15 #define __PRM_ParmList__
16 
17 #include "PRM_API.h"
18 #include "PRM_ChanState.h"
19 #include "PRM_Parm.h"
20 #include "PRM_Template.h"
21 #include <CH/CH_EventManager.h>
22 #include <CH/CH_Types.h>
23 #include <UT/UT_SymbolTable.h>
24 
25 #include <iosfwd>
26 
27 
28 class UT_TokenString;
29 class UT_StringArray;
30 class CH_Collection;
31 class PRM_Multi;
32 class PRM_Name;
33 class PRM_PresetInfo;
34 class PRM_ParmNameMap;
35 class PRM_OpSharedInfo;
36 
37 typedef enum {
38  PRM_RALL = 0004, /// Read, write, execute all
39  PRM_WALL = 0002,
40  PRM_XALL = 0001,
41  PRM_RGRP = 0040, /// Read, write, execute group
42  PRM_WGRP = 0020,
43  PRM_XGRP = 0010,
44  PRM_RUSR = 0400, /// Read, write, execute user
45  PRM_WUSR = 0200,
46  PRM_XUSR = 0100,
47 
48  PRM_RWXALL = 0007,
49  PRM_RWXGRP = 0070,
50  PRM_RWXUSR = 0700,
51  PRM_RWX = 0777,
52 
57 
59 {
60 public:
61  virtual ~PRM_ORCallback() {}
62 
63  virtual fpreal getFloatOverride( int data_idx, fpreal time, int *tdepend, int *enable ) = 0;
64  virtual bool setFloatOverride( int data_idx, fpreal time, int *tdepend, int *enable, fpreal newvalue ) = 0;
65 
66  virtual exint getIntOverride( int data_idx, fpreal time, int *tdepend, int *enable ) = 0;
67  virtual bool setIntOverride( int data_idx, fpreal time, int *tdepend, int *enable, exint newvalue ) = 0;
68 
69  virtual UT_StringHolder getStringOverride( int data_idx, fpreal time, int *tdepend, int *enable ) = 0;
70  virtual bool setStringOverride( int data_idx, fpreal time, int *tdepend, int *enable, const UT_StringHolder &newvalue ) = 0;
71 };
72 
74 {
75 public:
76  PRM_ParmList(PRM_Template *thetemplates,
77  CH_Collection *thechgroupptr,
78  PRM_ParmOwner *node,
79  PRM_PresetInfo *presetinfo,
80  char *optype,
81  bool clear_channels);
82  /// Constructor used to make a new parm list when
83  /// loading a new PRM_Template. This assumes that the
84  /// channel collection and variables remains the same.
85  PRM_ParmList(PRM_ParmList *thesrcptr,
86  PRM_Template *thenewtemplate,
87  PRM_ParmOwner *node,
88  PRM_PresetInfo *presetinfo,
89  char *optype,
90  bool leavedefaultsunchanged);
91  ~PRM_ParmList();
92 
93 
94  int getEntries() const { return myParms.entries(); }
95 
96  // These two must be redundant now that the constructor has
97  // the channel collection in it.
98  void setChannelGroupPtr(CH_Collection *thechgroupptr)
99  { myChannelGroupPtr = thechgroupptr; }
101  { return myChannelGroupPtr; }
102 
103  fpreal getEvalTime(int thread) const;
104 
105  fpreal findNextKey(fpreal theoldtime);
106  fpreal findPrevKey(fpreal theoldtime);
107 
108  /// returns 1 if all the parms in the list are at their default values
109  /// returns 0 otherwise
110  int allDefaults() const;
111 
112  // This will call revertToDefaults on parms which haven't had their
113  // defaults set, thereby delaying the creation of multiparm entries until
114  // after we have built all our templates.
115  void buildDelayedDefaults( bool clear_channels = true );
116 
117  PRM_Parm *getParmPtr(const char *theparmname, int &theparmidx);
118  PRM_Parm *getParmPtr(const char *theparmname);
119  const PRM_Parm *getParmPtr(const char *theparmname) const;
120  PRM_Parm *getParmPtr(const PRM_Name &name);
121  const PRM_Parm *getParmPtr(const PRM_Name &name) const;
122 
123  PRM_Parm *getParmPtr(const int theindex)
124  {
125  return (theindex >= 0 && theindex < myParms.entries())
126  ? myParms(theindex)
127  : 0;
128  }
129  const PRM_Parm *getParmPtr(const int theindex) const
130  {
131  return (theindex >= 0 && theindex < myParms.entries())
132  ? myParms(theindex)
133  : 0;
134  }
135 
136 
137  int getParmIndex(const PRM_Parm *parm) const;
138  int getParmIndex(const char *parmname) const;
139  PRM_Parm *getParmPtrFromChannel(const char *channel,
140  int *vecidx = 0) const;
141  int getParmIndex(const char *channel_name, int &subidx,
142  bool allow_alias = true) const
143  {
144  return getParmIndexFromChannel(
145  channel_name, &subidx, allow_alias);
146  }
147  int getParmIndexFromChannel(const char *channel,
148  int *vecidx,
149  bool allow_alias) const;
150 
151  // Clear the dirty flags for all parameters, or query if all dirty flags
152  // are clear.
153  void clearAllDirtyFlags();
154  int areAllFlagsClean() const;
155  void clearAllUndoSavedFlags();
156 
157  void revertToDefaults(fpreal time);
158 
159  void revertValuesToFactoryDefaults();
160 
161  // When the PRM_Template changes (i.e. reloading a new operator
162  // definition), the new PRM_ParmList is created and then this method is
163  // called to copy over any pertinent information from the old PRM_ParmList.
164  void updateFromOldTemplate(PRM_ParmList *oldlist);
165  // When the spare parameter definitions for a node changes, this function
166  // is called to update the parameters to be in line with the new set of
167  // templates. The old templates must still exist at this point.
168  void updateSpareParmTemplates(PRM_Template *newtemplates,
169  bool leavedefaultsunchanged);
170 
171  void saveSingle(PRM_Parm *, std::ostream &os, int binary) const;
172  void save(std::ostream &os, int binary, bool compiled) const;
173  bool load(UT_IStream &is, const char *path,
174  PRM_ParmList *obsoleteparms);
175 
176  void saveUndoData(PRM_UndoDataList &data);
177  void saveSingleUndoData(PRM_Parm *parm,
179  void loadUndoData(const PRM_UndoDataList &data,
180  const char *path,
181  PRM_ParmList *obsoleteparms);
182 
183  /// Methods to load and save channel aliases
184  /// @{
185  void saveChannelAliases(std::ostream &os, int binary);
186  bool loadChannelAliases(UT_IStream &is, const char *path);
187  /// @}
188  /// Returns true if any of our parms have an alias and false otherwise
189  bool hasChannelAliases() const;
190 
191  void clearAndDestroyChannels();
192  int hasAnyChannels();
193  int addChannel(const char *name);
194  void reloadChannelPtrs();
195  int channelPtrModified(const char *name);
196 
197  unsigned getUserMask() const { return myUserMask; }
198  void setUserMask(unsigned m)
199  { myUserMask = m & PRM_RWX; }
200  unsigned getPermissions() const { return myPermissions; }
201  void setPermissions(unsigned mask)
202  { mask &= PRM_RWX;
203  if (mask != myPermissions)
204  {
205  myPermissions = mask;
206  sendChangeEvent(CH_PERMISSION_CHANGED);
207  }
208  }
209  unsigned getAssetPermissionMask() const
210  { return myAssetPermissionMask; }
212  { mask &= PRM_RWX;
213  if (mask != myAssetPermissionMask)
214  {
215  myAssetPermissionMask = mask;
216  sendChangeEvent(CH_PERMISSION_CHANGED);
217  }
218  }
219 
220  // By default, the canAccess method just tests to see if the OP is
221  // writeable.
222  int canAccess(unsigned mask=PRM_WRITE_OK,
223  const PRM_Type &type=PRM_TYPE_ZERO) const;
224  int canAccessIgnoringAssetMask(
225  unsigned mask=PRM_WRITE_OK,
226  const PRM_Type &type=PRM_TYPE_ZERO) const;
227  int canAccessCheckingOnlyAssetMask(
228  unsigned mask=PRM_WRITE_OK,
229  const PRM_Type &type=PRM_TYPE_ZERO) const;
230 
231  static void beginLoading();
232  static void endLoading();
233  static bool isLoading();
234 
235  void hardenChanges(fpreal time, bool forceflag = 0,
236  const char *patt=0,
237  CH_ChannelRefList *list=0);
238 
239  PRM_ChanState getChanState(fpreal time);
240  void sendChangeEvent(CH_CHANGE_TYPE what, PRM_Parm *who=0);
241  void setEventHandler(void *data,
242  void (*handler)(void *, CH_CHANGE_TYPE, int))
243  {
244  myEventObject = data;
245  myEventHandler = handler;
246  }
247 
248  /// If the parm list is not already flagged as time dependent then
249  /// checkTimeDependence will scan the parms for time dependencies and
250  /// return the new time dependence flag.
251  /// @note Expressions will not be flagged as time dependent until
252  /// they're evaluated. So, if it's possible that the channels have not
253  /// been evaluated, set evaluate_channels to true.
254  int checkTimeDependence(bool evaluate_channels = false);
255 
256  void setTimeDependent(int onOff)
257  { myTimeDependent=onOff;}
258  void setCookTimeDependent(int onOff)
259  { myCookTimeDependent=onOff;}
260 
261  int getTimeDependent() const { return myTimeDependent; }
262  int getCookTimeDependent() const { return myCookTimeDependent; }
263 
264  // the override callback is static
265  static PRM_ORCallback *getORCallback(void) { return theORCallback; }
266  static void setORCallback(PRM_ORCallback *impl)
267  { theORCallback = impl; }
268 
269  void pushVariables(); // These should only be used
270  void popVariables(); // by PSI for syntax reasons
271 
272  int findString(const char *str, bool fullword,
273  bool usewildcards) const;
274  int changeString(const char *from, const char *to,
275  bool fullword);
276 
277  bool notifyVarChange(const char *varname);
278 
279  int getSendExtraEvent() { return mySendExtraEvent; }
280  void setSendExtraEvent() { mySendExtraEvent = 1; }
281  void clearSendExtraEvent() { mySendExtraEvent = 0; }
282 
283  /// Return a unique identifier for the current parameter settings. If this
284  /// is called outside of a cook, place a PRM_AutoBlockErrors around the
285  /// call.
286  void getMagicString(UT_TokenString &string,
287  fpreal t, int parm_group = 1);
288 
289  void setUndoSavedFlag() { myUndoSavedFlag = 1; }
291  { myAutoTakeUndoSavedFlag = 1; }
292 
293  // Appends a block of multiparm instance parameters.
294  void appendMultiParms(const PRM_Multi *multiparmowner,
295  PRM_Template *templ, int num, bool spare,
296  const UT_IntArray &instance,
297  UT_ValArray<PRM_Parm *> &newparms);
298 
299  void removeAndDestroyParm(int index);
300 
301  void insertMultiParmItem(int index, int i);
302  void removeMultiParmItem(int index, int i);
303 
304  PRM_ParmOwner *getParmOwner() const { return myParmOwner; }
305  PRM_PresetInfo *getPresetInfo() const { return myPresetInfo; }
306  void clearParmOwner();
307 
308  /// checkMultiParmInstance() will return true if the given parm name matches
309  /// a multi-parm instance name. If the multi-parm instance isn't created
310  /// yet, then it will be created before this function returns. In that case,
311  /// do_owner_init specifies if the new instance should be initialized.
312  bool checkMultiParmInstance(const char *parmname,
313  bool do_owner_init);
314 
315  /// This method is used to alias a channel name to a another name
316  /// Returns true if successful and false otherwise.
317  /// NOTE: you should not need to use this directly, you should instead
318  /// call the OP_Node version.
319  bool setChannelAlias(PRM_Parm &parm, int subindex,
320  const char *chan_alias);
321 
322  int64 getMemoryUsage(bool inclusive) const;
323 
324  unsigned long getAddRemoveCount() const
325  { return myAddRemoveCount; }
326  void setAddRemoveCount(unsigned long count)
327  { myAddRemoveCount = count; }
328 
329  /// Convenience functions for evaluating and setting parameters
330  /// @{
331  void evalStringRaw(UT_String &value,
332  const char *pn, int vi, fpreal t);
333  void evalString(UT_String &value,
334  const char *pn, int vi, fpreal t);
335  void setString(const UT_String &value,
336  CH_StringMeaning meaning,
337  const char *pn, int vi, fpreal t,
338  bool propagate);
339  int evalInt(const char *pn, int vi, fpreal t);
340  void setInt(int value, const char *pn, int vi, fpreal t,
341  bool propagate);
342  fpreal evalFloat(const char *pn, int vi, fpreal t);
343  void setFloat(fpreal value, const char *pn, int vi, fpreal t,
344  bool propagate);
345  /// @}
346 
347 
348  DEP_MicroNode & parmMicroNode(int parm_idx, int vi);
349  bool hasParmMicroNode(int parm_idx) const;
350 
351  /// Get all parm micronodes for the entire parm list
352  void getParmMicroNodes(DEP_MicroNodeList &micronodes) const;
353 
354  void propagateDirtyParmMicroNodes(
355  int parm_index, // can be -1 for all
356  DEP_MicroNode::Visitor client_visit,
357  DEP_MicroNode *parmlist_micronode,
358  bool force);
359 
360  void clearMicroNodeInputs();
361  void getParmInputList(
362  DEP_MicroNodeList &inputs,
363  bool cooking_only = false) const;
364  int getNumParmInputs() const;
365  void getParmOutputList(
366  DEP_MicroNodeList &outputs,
367  bool cooking_only = false) const;
368 
369  void dumpMicroNodes(
370  std::ostream &os,
371  bool as_DOT,
372  int indent_level=0) const;
373  int64 getMicroNodesMemoryUsage() const;
374 
375  // This function removes the shared parmhash info for the specified
376  // operator from the shared info table. The data will get deleted
377  // as soon as the last PRM_ParmList with a pointer to the shared
378  // info gets deleted.
379  static void removeOpSharedInfo(const char *optoken);
380  // This functions changes the name under which some shred parm
381  // hash info is stored in our table. This is done when the name
382  // of an operator type changes.
383  static void renameOpSharedInfo(const char *oldoptoken,
384  const char *newoptoken);
385 
386  PRM_Parm *getParmPtrInst(const char *theparmname, const int *instance, int nest_level) const;
387  PRM_Parm *getParmPtrInst(const char *theparmname, const int *instance, int nest_level, int &theparmidx) const;
388 
389 private: // forbid usage of these functions
390  PRM_ParmList(const PRM_ParmList &copy);
391  PRM_ParmList &operator =(const PRM_ParmList &copy);
392 
393 private: // functions
394 
395  void moveMultiParmAlias(int index, int i, bool up);
396  void loadUnknownParmNames(UT_IStream &is,
397  UT_StringArray &names,
398  PRM_ParmList *obsoleteparms);
399  PRM_Parm *findLoadParm(const char *name,
400  PRM_ParmList *obsoleteparms,
401  PRM_ParmNameMap *nmap,
402  bool try_again=true);
403 
404  // Adopt the common parms (including animating parms) from the source.
405  // Note that the source parm list will be changed.
406  void adoptParmList(
407  PRM_ParmList &thesource,
408  bool leavedefaultsunchanged);
409 
410  static bool shouldCopyOnAdopt(
411  PRM_Template &dst_template,
412  PRM_Parm &srcparm,
413  bool leavedefaultsunchanged);
414 
415  // Adopt the values and other important information from one parm into
416  // another. The parms don't have to be from the same PRM_ParmList, but
417  // they can be. This allows this function to be used from the adopt()
418  // function above, or from updateSpareParms(). Note that the source
419  // parm will be changed.
420  void adoptParm(
421  PRM_Parm &dstparm,
422  PRM_Parm &srcparm,
423  bool leavedefaultsunchanged);
424 
425  void adoptChannelAlias(
426  PRM_Parm &dst_parm,
427  const PRM_Parm &src_parm);
428 
429  PRM_Parm *appendParm(
430  PRM_Parm *parm,
431  bool spare,
432  const PRM_Multi *multiparmowner);
433  PRM_Parm *createParm(
434  PRM_Template *temp,
435  bool spare,
436  const PRM_Multi *multiparmowner);
437  PRM_Parm *createParm(
438  PRM_Parm *parm_to_clone,
439  bool spare,
440  const PRM_Multi *multiparmowner);
441  void initHashTable(const char *optype);
442 
443 
444  // Decrements the reference count for the specified shared parm hash
445  // info,and deletes the data if it is the last reference.
446  static void removeOpSharedInfoReference(PRM_OpSharedInfo *info);
447 
448 
449 private: // data
450 
451  UT_ValArray<PRM_Parm *> myParms;
452 
453  unsigned long myAddRemoveCount;
454 
455  // The following member data holds a pointer to shared hash tables.
456  // This is a hash table of all the parameters for this op type. This
457  // table is shared by all operators of this type. This implies two
458  // things. First, it doesn't contain spare parms or multiparm instances.
459  // Second, all operators must keep their "standard" parms always at
460  // the start of myParms (before any spare or multi parms). Otherwise
461  // The indexes for these parms would be different for each node.
462  // NOTE: The channel table is not a list of active animated channels,
463  // but a list of all possible channel names.
464  PRM_OpSharedInfo *myOpSharedInfo;
465  // This is the hash table for holding the parm indices of spare parms
466  // and multiparm instances for this node. It is not shared, obviously.
467  // NOTE: The channel table is not a list of active animated channels,
468  // but a list of all possible channel names.
469  UT_SymbolMap<int> mySpareAndMultiParmHashTable;
470  UT_SymbolMap<int> mySpareAndMultiChannelTable;
471  // This is the symbol table of channel aliases. It is also not shared,
472  // as channel aliases are per-node not per-type. Because channel aliases
473  // are always per-node, we don't need separate tables for regular parms
474  // and spare/multi parms.
475  UT_SymbolMap<PRM_Parm *> myChannelAliasesTable;
476 
477  unsigned myPermissions;
478  unsigned myUserMask;
479  unsigned myAssetPermissionMask;
480 
481  CH_Collection *myChannelGroupPtr;
482  PRM_ParmOwner *myParmOwner;
483  PRM_PresetInfo *myPresetInfo;
484 
485  void (*myEventHandler)(void *, CH_CHANGE_TYPE, int);
486  void *myEventObject;
487 
488  // mySendExtraEvent is set whenever a parameter that has its dirty and
489  // sendExtra flags set. It should be set from the PRM_Parm::setValue
490  // code paths and it should be cleared after a OP_PRM_CHANGED or equivalent
491  // event has been sent out.
492  bool myTimeDependent:1,
493  myCookTimeDependent:1,
494  mySendExtraEvent:1,
495  myUndoSavedFlag:1,
496  myAutoTakeUndoSavedFlag:1;
497 
498  static PRM_ORCallback *theORCallback;
499  static fpreal32 theFileVersion;
501  theOpHashTable;
502  static int thePRMLoadCount;
503 };
504 
505 #endif
hboost::function2< void, DEP_MicroNode &, DEP_MicroNode & > Visitor
void setChannelGroupPtr(CH_Collection *thechgroupptr)
Definition: PRM_ParmList.h:98
const PRM_Parm * getParmPtr(const int theindex) const
Definition: PRM_ParmList.h:129
void setUserMask(unsigned m)
Definition: PRM_ParmList.h:198
int getTimeDependent() const
Definition: PRM_ParmList.h:261
void setUndoSavedFlag()
Definition: PRM_ParmList.h:289
CH_StringMeaning
int getCookTimeDependent() const
Definition: PRM_ParmList.h:262
typedef void(APIENTRYP PFNGLCULLFACEPROC)(GLenum mode)
const GLuint GLenum const void * binary
Definition: glcorearb.h:1923
void setEventHandler(void *data, void(*handler)(void *, CH_CHANGE_TYPE, int))
Definition: PRM_ParmList.h:241
int getParmIndex(const char *channel_name, int &subidx, bool allow_alias=true) const
Definition: PRM_ParmList.h:141
GLsizei const GLchar *const * path
Definition: glcorearb.h:3340
void setCookTimeDependent(int onOff)
Definition: PRM_ParmList.h:258
static void setORCallback(PRM_ORCallback *impl)
Definition: PRM_ParmList.h:266
GLint GLuint mask
Definition: glcorearb.h:123
int getSendExtraEvent()
Definition: PRM_ParmList.h:279
unsigned getAssetPermissionMask() const
Definition: PRM_ParmList.h:209
png_uint_32 i
Definition: png.h:2877
void setTimeDependent(int onOff)
Definition: PRM_ParmList.h:256
unsigned getPermissions() const
Definition: PRM_ParmList.h:200
unsigned long getAddRemoveCount() const
Definition: PRM_ParmList.h:324
Read, write, execute user.
Definition: PRM_ParmList.h:45
void setAddRemoveCount(unsigned long count)
Definition: PRM_ParmList.h:326
long long int64
Definition: SYS_Types.h:106
PRM_ParmOwner * getParmOwner() const
Definition: PRM_ParmList.h:304
CH_CHANGE_TYPE
PRM_API const PRM_Type PRM_TYPE_ZERO
int64 exint
Definition: SYS_Types.h:115
PRM_ChanState
Definition: PRM_ChanState.h:14
PRM_Parm * getParmPtr(const int theindex)
Definition: PRM_ParmList.h:123
void clearSendExtraEvent()
Definition: PRM_ParmList.h:281
PRM_PresetInfo * getPresetInfo() const
Definition: PRM_ParmList.h:305
void setSendExtraEvent()
Definition: PRM_ParmList.h:280
virtual ~PRM_ORCallback()
Definition: PRM_ParmList.h:61
GLboolean * data
Definition: glcorearb.h:130
GLuint const GLchar * name
Definition: glcorearb.h:785
GLint GLsizei count
Definition: glcorearb.h:404
void setPermissions(unsigned mask)
Definition: PRM_ParmList.h:201
void setAutoTakeUndoSavedFlag()
Definition: PRM_ParmList.h:290
GLsizei const GLfloat * value
Definition: glcorearb.h:823
double fpreal
Definition: SYS_Types.h:269
typedef int
Definition: png.h:1175
void setAssetPermissionMask(unsigned mask)
Definition: PRM_ParmList.h:211
GA_API const UT_StringHolder up
GLuint index
Definition: glcorearb.h:785
Read, write, execute all.
Definition: PRM_ParmList.h:39
PRM_Permission
Definition: PRM_ParmList.h:37
Read, write, execute group.
Definition: PRM_ParmList.h:42
GLint GLint GLsizei GLint GLenum GLenum type
Definition: glcorearb.h:107
png_infop png_uint_32 int num
Definition: png.h:2158
unsigned getUserMask() const
Definition: PRM_ParmList.h:197
CH_Collection * getChannelGroupPtr() const
Definition: PRM_ParmList.h:100
#define PRM_API
Definition: PRM_API.h:10
static PRM_ORCallback * getORCallback(void)
Definition: PRM_ParmList.h:265
float fpreal32
Definition: SYS_Types.h:190
int getEntries() const
Definition: PRM_ParmList.h:94