HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
PRM_Instance.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_Instance.h (Parameter Library)
7  *
8  * COMMENTS:
9  * A PRM_Instance contains all the variable data relating to
10  * parameters. In other words it contains the actual values
11  * of the parameter. The types and format of the values are
12  * specified in the PRM_Template portion of a parameter. A
13  * PRM_Instance is to a PRM_Template as an object is to a
14  * class in C++.
15  */
16 
17 #ifndef __PRM_Instance_h__
18 #define __PRM_Instance_h__
19 
20 #include "PRM_API.h"
21 #include "PRM_Callback.h"
22 #include "PRM_ChanState.h"
23 #include "PRM_Default.h"
24 #include "PRM_Error.h"
25 #include "PRM_KeySetType.h"
26 #include "PRM_Parm.h"
27 #include "PRM_ParmList.h"
28 #include "PRM_Template.h"
29 #include "PRM_Type.h"
30 
31 #include <CH/CH_Collection.h>
32 #include <CH/CH_ExprLanguage.h>
33 #include <CH/CH_Manager.h>
34 #include <CH/CH_Types.h>
35 #include <DEP/DEP_MicroNode.h>
36 
37 #include <EXPR/EX_Error.h>
38 #include <UT/UT_Array.h>
39 #include <UT/UT_Assert.h>
40 #include <UT/UT_Color.h>
41 #include <UT/UT_SmallObject.h>
42 #include <UT/UT_String.h>
43 #include <UT/UT_StringHolder.h>
44 #include <UT/UT_TBBSpinLock.h>
45 #include <UT/UT_UniquePtr.h>
46 #include <UT/UT_VectorTypes.h>
47 #include <SYS/SYS_Inline.h>
48 #include <SYS/SYS_Types.h>
49 
50 #include <iosfwd>
51 
52 
53 class PRM_ChoiceList;
54 class PRM_Multi;
55 class PRM_ConstMicroNode;
56 class PRM_ParmMicroNode;
57 class PRM_ParmOwner;
58 class PRM_Range;
59 class PRM_RefId;
60 class PRM_Value;
61 class CH_Channel;
62 class CH_FullKey;
63 class UT_IStream;
64 class UT_JSONValueMap;
65 class UT_Packet;
66 class UT_TokenString;
67 class UT_WorkBuffer;
68 
69 
70 class PRM_API PRM_Instance : public UT_SmallObject<PRM_Instance,
71  UT_SMALLOBJECT_CLEANPAGES_DEFAULT,
72  UT_SMALLOBJECT_PAGESIZE_DEFAULT,
73  UT_SMALLOBJECT_THREADSAFE_OFF>
74 {
75 public:
76  PRM_Instance(PRM_Template *thetemplateptr,
77  PRM_Parm *parm);
78  PRM_Instance(PRM_Instance *thesrcptr,
79  PRM_Parm *parm);
80  virtual ~PRM_Instance();
81 
82  virtual void adopt(PRM_Instance &thesrcinstance);
83  virtual void adoptOverrides(PRM_Instance &thesrcinstance);
84 
85  virtual PRM_Instance *duplicateSelf(PRM_Parm *node) = 0;
86 
87  virtual void setValueToDefault(fpreal time, int index,
88  PRM_AddKeyType add_key) = 0;
89  virtual void revertToDefault(int index) = 0;
90  virtual void revertToDefaults(bool clear_channels =true) = 0;
91  virtual void restoreFactoryDefault(int index) = 0;
92  virtual void overwriteDefault(fpreal time, int index) = 0;
93  virtual void overwriteDefaults(fpreal time) = 0;
94  virtual int isDefault(int index, enum PRM_DefaultType deftype,
95  bool basiccheck = true) const;
96  bool isAllDefault(enum PRM_DefaultType deftype) const;
97 
98  virtual void save(std::ostream &os, int binary, bool compiled) const=0;
99  virtual bool load(UT_IStream &is) = 0;
100 
101  virtual void saveUndoData(PRM_UndoDataHandle &data) const;
102  virtual bool loadUndoData(const PRM_UndoDataHandle &data);
103 
104  virtual void saveCommand(std::ostream &os, int values=0, int index = -1)
105  const = 0;
106  virtual int loadCommand(int argc, const char *const argv[],
107  int index,
108  bool values_only,
109  PRM_AddKeyType add_key,
110  PRM_KeySetType set_type) = 0;
111 
112  virtual void getValue(PRM_ParmList *parm_list, fpreal time,
113  int32 &value, int index,
114  int thread) const = 0;
115  virtual void getValue(PRM_ParmList *parm_list, fpreal time,
116  int64 &value, int index,
117  int thread) const = 0;
118  virtual void getValue(PRM_ParmList *parm_list, fpreal time,
119  fpreal &value, int index,
120  int thread) const = 0;
121  virtual void getValue(PRM_ParmList *parm_list, fpreal time,
122  UT_String &value, int index,
123  bool expand, int thread) const = 0;
124  virtual void getValue(PRM_ParmList *parm_list, fpreal time,
125  PRM_DataItemHandle &value, int index,
126  int thread) const = 0;
127  virtual void getValue(PRM_ParmList *parm_list, fpreal time,
128  UT_JSONValueMap &value, int index,
129  bool expand, int thread) const = 0;
130  virtual void getValues(PRM_ParmList *parm_list, fpreal time,
131  fpreal32 *value, int thread) const;
132  virtual void getValues(PRM_ParmList *parm_list, fpreal time,
133  fpreal64 *value, int thread) const;
134  virtual void getValues(PRM_ParmList *parm_list, fpreal time,
135  int32 *theints, int thread) const;
136  virtual void getValues(PRM_ParmList *parm_list, fpreal time,
137  int64 *theints, int thread) const;
138  virtual void getDefaultValue(fpreal &value, int index) const;
139  virtual void getDefaultValue(int32 &value, int index) const;
140  virtual void getDefaultValue(int64 &value, int index) const;
141  virtual void getDefaultValue(UT_String &value, int index) const;
142 
143  virtual void getExpressionStringForUI(fpreal time,
144  UT_String &value,
145  int index,
146  int thread) const = 0;
147  virtual void getExpression(fpreal time, UT_String &value,
148  int index, bool allow_value,
149  int thread) const = 0;
150  virtual void setExpression(fpreal time,
151  const char *value,
152  CH_ExprLanguage language,
153  int index, bool evaluate = true,
154  bool rmchannel = false);
155 
156  CH_StringMeaning getStringMeaning(fpreal time, int index) const;
157 
158  // If this parm contains an expression this function returns that
159  // expression's language. Otherwise, it returns the language that it
160  // would be if it was turned into an expression.
161  CH_ExprLanguage getExprLanguageIfMadeAnExpression(fpreal time,
162  int index) const;
163 
164  // If there is an expression, this function returns whether the
165  // expression's language for the segment at the given time is Old Expr.
166  // If there is no expression, this function returns true.
167  bool isLanguageOldExprOrLiteral(fpreal time, int index) const;
168 
169  // set value of a parameter
170  // setkey - determines how the value is set at keyframes.
171  // Whether the preference is used or always set as pending
172  virtual void setValue(fpreal time,
173  const char *value,
174  CH_StringMeaning meaning,
175  bool kill_expr = false,
176  int index = 0,
179 
180  virtual void setValue(fpreal time,
181  fpreal value,
182  bool kill_expr = false,
183  const int index = 0,
186 
187  virtual void setValue(fpreal time,
188  int32 value,
189  bool kill_expr = false,
190  const int index = 0,
193 
194  virtual void setValue(fpreal time,
195  int64 value,
196  bool kill_expr = false,
197  const int index = 0,
200 
201  virtual void setValue(fpreal time,
202  const PRM_DataItemHandle &value,
203  bool kill_expr = false,
204  const int index = 0,
207 
208  //
209  // The setValues methods set all entries in the vector...
210  //
211  virtual void setValues(fpreal time,
212  const fpreal *values,
213  bool kill_expr = false,
216 
217  virtual void setValues(fpreal time,
218  const int64 *values,
219  bool kill_expr = false,
222 
223  virtual void setDefaultChannelValue(CH_Channel *channelptr,
224  int index = 0) = 0;
225 
226  virtual bool isMultiParm() const;
227  virtual int getMultiParmNumItems() const;
228  virtual int getMultiParmInstancesPerItem() const;
229  virtual const char *getMultiParmToken(int p, int index) const;
230  // Only PRM_ParmList should directly call these insert/remove methods.
231  // All other users, should use the insert/remove methods in OP_Parameter.
232  virtual void insertMultiParmItem(int index);
233  virtual void removeMultiParmItem(int index);
234 
235  virtual void buildOpDependencies(const PRM_RefId &ref, int thread);
236  virtual void changeOpRef(const char *new_fullpath,
237  const char *old_fullpath,
238  const char *old_cwd,
239  const char *chan_name,
240  const char *old_chan_name,
241  void (*undo_callback)(void *),
242  void *undo_data,
243  int thread);
244 
245  fpreal findNextKey(fpreal theoldtime, int index=-1);
246  fpreal findPrevKey(fpreal theoldtime, int index=-1);
247 
248  virtual int findString(const char *str, bool fullword,
249  bool usewildcards) const;
250  virtual int changeString(const char *from, const char *to,
251  bool fullword);
252 
253  virtual bool notifyVarChange(int subindex, const char *varname);
254 
255  virtual bool getMagicString(UT_TokenString &magic,
256  PRM_ParmList *list, int size,
257  fpreal t, bool add_if_default /*=true*/,
258  int thread) = 0;
259 
260  unsigned getEnableState(int comp = -1) const;
261  bool setEnableState(bool f, int comp = -1);
262 
263  int getExpressionState() const
264  {
265  return myBitField & BITFLAG_EXPRESSIONSTATE;
266  }
267  void setExpressionState(int state)
268  {
269  if (state)
270  myBitField |= BITFLAG_EXPRESSIONSTATE;
271  else
272  myBitField &= ~BITFLAG_EXPRESSIONSTATE;
273  }
274  int getValueState() const
275  {
276  return myBitField & BITFLAG_VALUESTATE;
277  }
278  void setValueState(int state)
279  {
280  if (state)
281  myBitField |= BITFLAG_VALUESTATE;
282  else
283  myBitField &= ~BITFLAG_VALUESTATE;
284  }
285 
286  virtual bool isEditable(PRM_ParmList *thelist, fpreal time,
287  int index) const { return true; }
288  virtual bool isEditableByUI(PRM_ParmList *thelist, fpreal time,
289  int index) const { return true; }
290 
292  {
293  return getParmList()
294  ? getParmList()->getChannelGroupPtr()
295  : nullptr;
296  }
297  fpreal getEvalTime(int thread) const
298  {
299  CH_Collection *coll = getChannelGroupPtr();
300  if (!coll)
301  return 0.0;
302  return coll->getManager()
303  ->getEvaluateTime(thread);
304  }
306  {
307  CH_Collection *coll = getChannelGroupPtr();
308  if (!coll)
309  return 0.0;
310  return coll->getManager()->getGlobalStart();
311  }
312 
313  CH_Channel *getChannel(int subindex) const
314  {
315  UT_ASSERT(subindex >= 0
316  && subindex < getVectorSize());
317  return myChannelPtrs[subindex];
318  }
319  void setChannel(int subindex, CH_Channel *chp)
320  {
321  myChannelPtrs[subindex] = chp;
322  }
323 
324  void reloadChannelPtrs();
325  int channelPtrModified(const UT_StringRef &name);
326  void internalAddChannel(int index,
327  const char *theexpr,
328  CH_ExprLanguage language,
329  bool add_seg = true);
330  void addChannel(int index);
331  int addChannel(const UT_StringRef &name);
332  void addChannel(int index, const char *theexpr,
333  CH_ExprLanguage language);
334  int addChannel(const UT_StringRef &name, const char *expr,
335  CH_ExprLanguage language);
336  bool removeChannel(int index);
337  int getChannelCount() const;
338 
339  // Determine if a given component if time/data dependent. Use -1 if you
340  // want to know this for any of the components in the parm.
341  virtual bool isTimeDependent(int subindex) const;
342  virtual bool isDataDependent(fpreal gtime, int subindex) const;
343 
344  virtual void setTimeDependent(int subindex, bool timedep);
345  // Form for setTimeDependent() for the evaluation code path
346  void setTimeDependentForEval(int vi, bool timedep) const
347  { SYSconst_cast(this)->setTimeDependent(vi, timedep);}
348 
349  bool hasContextOptionDeps(int subindex) const;
350  const DEP_ContextOptionDeps &getContextOptionDeps(int subindex) const;
351  void addContextOptionDep(int subindex,
352  const UT_StringHolder &opt);
353 
354  int changePending(int index);
355  virtual PRM_ChanState getChanState(fpreal time, int index) const;
356  virtual PRM_ChanState getChanState(fpreal time) const;
357 
358  // add keyframes if changes are pending
359  virtual void hardenChanges(fpreal time,
360  int index,
361  bool theforceflag,
362  const char *patt = 0,
363  CH_ChannelRefList *list = 0) = 0;
364 
365  // sets a key even if no channel exists
366  void setKey(fpreal time, int index);
367  void setKey(fpreal time, int index, const char *expr,
368  CH_ExprLanguage language,
369  const char *patt = 0,
370  CH_ChannelRefList *list = 0);
371 
372  void setFullKey(fpreal gtime, int index,
373  CH_FullKey const& key,
374  bool accel_ratios = true);
375 
376  unsigned int getSaveFlags() const
377  { return myBitField & BITFLAG_SAVE_MASK; }
378  void setSaveFlags(unsigned int f)
379  { myBitField |= (f & BITFLAG_SAVE_MASK); }
380 
381  bool getActiveTakeFlag() const
382  { return myBitField & BITFLAG_ACTIVETAKE; }
383  bool getAlwaysTakeFlag() const
384  { return myBitField & BITFLAG_TAKEALWAYSACTIVE; }
385  void setActiveTakeFlag(int onoff)
386  {
387  if (onoff) myBitField |= BITFLAG_ACTIVETAKE;
388  else
389  {
390  if (!(myBitField & BITFLAG_TAKEALWAYSACTIVE))
391  myBitField &= ~BITFLAG_ACTIVETAKE;
392  else myBitField |= BITFLAG_ACTIVETAKE;
393  }
394  }
395 
396  bool getBypassFlag() const
397  { return myBitField & BITFLAG_BYPASS; }
398  void setBypassFlag(bool onoff)
399  {
400  // Only allow bypass on spare parameters
401  if (isSpareParm() && onoff)
402  myBitField |= BITFLAG_BYPASS;
403  else
404  myBitField &= ~BITFLAG_BYPASS;
405  }
406 
407  bool getVisibleState(int comp = -1) const;
408  void setVisibleState(bool f, int comp = -1);
409 
411  { return myBitField & BITFLAG_UNDOSAVED; }
412  void setUndoSavedFlag(bool f)
413  { if (f) myBitField |= BITFLAG_UNDOSAVED;
414  else myBitField &= ~BITFLAG_UNDOSAVED;}
416  { return myBitField & BITFLAG_AUTOTAKEUNDOSAVED; }
418  { if (f) myBitField |= BITFLAG_AUTOTAKEUNDOSAVED;
419  else myBitField &= ~BITFLAG_AUTOTAKEUNDOSAVED;}
420 
421  bool getSaveAutoScopeFlag() const
422  { return myBitField & BITFLAG_SAVEAUTOSCOPE; }
423 
425  { return myBitField & BITFLAG_SAVEAUTOSELECT; }
426 
427  void setSaveLabelFlag(bool f);
428  bool getSaveLabelFlag() const
429  { return myBitField & BITFLAG_SAVELABEL; }
430 
431  bool getLockedFlag(int vec_idx) const;
432  bool areAllComponentsLocked() const;
433  void setLockedFlag(int vec_idx, bool f);
434  bool getAutoScopedFlag(int vec_idx) const;
435  void setAutoScopedFlag(int vec_idx, bool f);
436 
437  bool getDefaultsInitFlag() const
438  { return (myBitField & BITFLAG_DEFAULTSINIT) != 0; }
439  void setDefaultsInitFlag(bool f)
440  { if (f) myBitField |= BITFLAG_DEFAULTSINIT;
441  else myBitField &= ~BITFLAG_DEFAULTSINIT;}
442 
443  unsigned int getLockField() const
444  { return myLockField; }
445  unsigned int getAutoScopeField() const
446  { return myAutoScopeField; }
447 
448  virtual int setOverride(int index, int data_idx,
449  const char *source,
451  virtual int setOverrideDisable(int index, int onoff);
452  virtual const char *getOverride(int index) const;
453  virtual bool getOverrideType(int index,
454  PRM_OverrideType& type) const;
455  virtual int getOverrideDataIndex(int index) const;
456 
457  ///Sometimes we may want to make an existing and enabled override
458  ///temporarily inactive, so that we can "shut off" the override without
459  ///losing any dependencies between the parm and the source of its exported
460  ///override values. (e.g. might want to temporarily change the parm's
461  ///display colour)
462  virtual int getIsOverrideActive(int index) const;
463 
464  virtual void destroyChildParms() { }
465 
466  // A parameter becomes dirty whenever its value is set.
467  bool isDirty(int vec_idx) const
468  { return getFieldBit(myDirtyParmFlags, vec_idx); }
469  bool areAllFlagsClean() const
470  { return !myDirtyParmFlags; }
472  { myDirtyParmFlags = 0; }
473  void setDirtyFlags(int vec_idx)
474  {
475  setFieldBit(myDirtyParmFlags, vec_idx, true);
476  setSendExtra(vec_idx);
477  }
478 
479  // mySendExtraFlags is a per-component bitfield that has its bit set
480  // if it needs to be dirty propagated.
481  bool isSendExtra(int vi) const
482  { return getFieldBit(mySendExtraFlags, vi); }
483  bool hasAnySendExtraFlags() const
484  { return (mySendExtraFlags != 0); }
485  void setSendExtra(int vi)
486  {
487  if (!getFieldBit(mySendExtraFlags, vi))
488  {
489  setFieldBit(mySendExtraFlags, vi, true);
490  getParmList()->bumpNumSendExtra(
491  vi < 0 ? getVectorSize() : +1);
492  }
493  }
494 
495  // The input notify value is not created by default. Call
496  // createInputNotifyValue when you need it. Handles use this
497  // notify value to add an interest in input fields so they can know
498  // when the input has changed. Op's trigger this notify value when
499  // they generate their input groups, if this value exists.
500  void createInputNotifyValue();
501  PRM_Value *inputNotifyValue() { return myNotifyValue; }
502  const PRM_Value *inputNotifyValue() const { return myNotifyValue; }
503 
504  const PRM_Type &getType() const
505  { return myTemplatePtr->getType(); }
507  { return myTemplatePtr->getTypeExtended(); }
509  { return myTemplatePtr->getMultiType(); }
511  { return myTemplatePtr->getMultiSize(); }
513  { return myTemplatePtr->getMultiStartOffset(); }
515  { return myTemplatePtr->getMultiParmTemplate(); }
517  { return myTemplatePtr->getMultiParmTemplate(); }
518  const char *getToken() const
519  { return myTemplatePtr->getToken(); }
520  const char *getLabel() const
521  { return myTemplatePtr->getLabel(); }
523  { return myTemplatePtr->getCallback(); }
524  int getVectorSize() const
525  { return myTemplatePtr->getVectorSize(); }
526  const PRM_Range * getRangePtr() const
527  { return myTemplatePtr->getRangePtr(); }
528  void getChannelToken(UT_String &chname, int i) const
529  { myTemplatePtr->getChannelToken(chname, i); }
530  const UT_StringHolder& getChannelToken(int i) const
531  { return myTemplatePtr->getChannelToken(i); }
533  { return myTemplatePtr->getChoiceListPtr(); }
534 
535  const PRM_Template *getTemplatePtr() const { return myTemplatePtr; }
536  PRM_Template *getTemplatePtr() { return myTemplatePtr; }
537 
538  // get/setChannelAlias allow the manipulation of channel aliases.
539  // setChannelAlias will return false if the operation fails and true
540  // otherwise. Do not use the set method directly, only PRM_ParmList should
541  // do that. To set a channel alias, use the OP_Node method.
542  bool hasChannelAlias(int index) const;
543  void getChannelAlias(UT_String &strref, int index) const;
544  const UT_StringHolder& getChannelAlias(int index) const;
545  bool setChannelAlias(const UT_StringHolder &token_alias,
546  int index);
547 
548  // Returns the sub-index of the parm given by the name thechannelname. If
549  // allow_alias is true, the channel name aliases are also searched,
550  // otherwise they are ignored.
551  int findSubIndex(const UT_StringRef &thechannelname,
552  bool allow_alias) const;
553 
555  { return myParm->getParmOwner(); }
557  { return myParm->getOwner(); }
558  PRM_Parm *getParm() const
559  { return myParm; }
560 
561  static bool isChanRefString(const char *str, bool is_expr,
562  UT_String *chref = 0);
563  static bool isObsoleteDirectChanRefString(const char *str,
564  UT_String *chref = 0);
565 
566  // Returns true if the channame is the token (or alias) of the channel at
567  // vec_index, and returns false otherwise.
568  // The length of channame can be given in channamelen to speed up rejections
569  // if the caller caches the string length.
570  bool hasChannelName(const UT_StringRef &s, int vi) const;
571 
572  // Methods for accessing and setting the active handle binding flag
573  bool isActive(const int index) const;
574  void setActive(const int index, const bool active);
575 
576  // Spare parameter flag
577  bool isSpareParm() const;
578  void setSpareParm(bool spare);
579 
580  // Multiparm instance information
581  const PRM_Instance *getMultiParmOwner() const;
582  void setMultiParmOwner(const PRM_Multi *multiparmowner);
583 
584  /// Returns the multi-parm template for this child parm. Returns nullptr
585  /// if this parm is not part of a multi-parm
586  const PRM_Template *findMultiParmTemplate() const;
587 
588  /// Return the list of instance indicies for this parameter.
589  /// If this parameter is part of a multi-parameter, then its index in the
590  /// multi-parm array will be inserted into the indices array. If the
591  /// multi-parm is nested in other multi-parms, then the indices array will
592  /// have multiple entries (with the outer multi-parm listed first, and the
593  /// inner-most multi-parm last in the array).
594  /// \param indices The list of index instances.
595  /// \param instance_index Each multi-parm can have multiple parameters in
596  /// each instance. If instance_index is true, the instance number will be
597  /// returned. Otherwise the raw offset into the multi-parm will be
598  /// extracted.
599  int getMultiInstanceIndex(UT_Array<int> &indices,
600  bool instance_index=true) const;
601 
602  bool validIndex(int index) const;
603 
604  virtual int64 getMemoryUsage(bool inclusive) const;
605 
606  virtual bool isRotationParm() const
607  { return false; }
608 
609  /// During loading we need to validate that the channels tied to the
610  /// parameter indices are correclty mapped.
611  void validateChannelNames(PRM_ParmList &list);
612 
613  /// Thread-safe access to get or create a micronode
614  DEP_MicroNode & microNode(int vi);
615 
616 
617  /// Thread-safe access to get micronodes
618  void getMicroNodes(DEP_MicroNodeList &micronodes) const;
619 
620  /// Return true if this parameter has micronodes, NOT thread-safe
621  bool hasMicroNodes() const
622  { return (myMicroNodes != nullptr); }
623 
624  void clearMicroNodeInputs();
625  void getMicroNodeInputList(DEP_MicroNodeList &inputs) const;
626  int getMicroNodeNumInputs() const;
627  void getMicroNodeOutputList(DEP_MicroNodeList &outputs) const;
628 
629  void propagateDirty(
630  DEP_MicroNode::Visitor client_visit,
631  DEP_MicroNode *parmlist_micronode,
632  bool force,
633  bool *dirtied_data = nullptr);
634  void dumpMicroNodes(
635  std::ostream &os,
636  bool as_DOT,
637  int indent_level) const;
638  int64 getMicroNodesMemoryUsage() const;
639 
640  /// Custom Channel Color
641  bool hasChannelCustomColor(int index) const;
642  const UT_Color &getChannelCustomColor(int index) const;
643  void setChannelCustomColor(int index, const UT_Color &c);
644  void resetChannelCustomColor(int index);
645 
646  bool getAutoSelectFlag(int vec_idx) const;
647  void setAutoSelectFlag(int vec_idx, bool f);
648  unsigned int getAutoSelectField() const
649  { return myAutoSelectField; }
650 
651  void setTimeDependentMicroNode(int subindex, bool timedep);
652 
653  /// Thread-safe access to get or create a const micronode
654  /// A const micro node gives the same dependencies as
655  /// microNode(), but the time dependent flag will always be
656  /// false.
657  /// It also creates missing base microNodes.
658  DEP_MicroNode & constMicroNode(int vi);
659 protected:
660  void clearAndDestroyChannels();
661 
662  void addParmWarning(PRM_ErrorCode code) const;
663  void indexError(int index);
664 
665  void setLockField(unsigned int locks)
666  { myLockField = locks; }
667  void setAutoScopeField(unsigned int field)
668  {
669  myAutoScopeField = field;
670  myBitField |= BITFLAG_SAVEAUTOSCOPE;
671  }
672 
673  void setAutoSelectField(unsigned int field)
674  {
675  myAutoSelectField = field;
676  myBitField |= BITFLAG_SAVEAUTOSELECT;
677  }
678 
679  SYS_FORCE_INLINE void
681  const PRM_ParmList *thelist, int vector_index, int thread) const
682  {
683  int err;
684  err = ev_GetErrNo(thread);
685  if (err != EV_NOERROR)
686  evaluationError(thelist, vector_index, err, thread);
687  }
688 
689  bool validateAccess();
690 
691  // This helper method is called by loadCommand() in derived classes to
692  // load the token either as a reference to our channel, or failing that,
693  // as an expression.
694  void loadTokenAsChannelNameOrExpression(
695  const UT_String &token, int index);
696 
697  // This method loads the options of the parm that are within '[]' before
698  // the parm value. The istream must be positioned after the first '['
699  // and this method will leave it after the ']' and return true. If it
700  // could not correctly parse the options, it will return false.
701  bool loadAsciiOptions(UT_IStream &is, uint &pending_mask);
702 
703  // This method checks the given binary packet id against the list of
704  // options it supports, if successful, it loads the packet and returns
705  // true, otherwise returns false.
706  bool loadBinaryOption(UT_IStream &is, short packet_id);
707 
708  // This method will save the options of the parm if there are any to set.
709  // Currently, only the locked flag is saved. If the parm is not locked,
710  // this method won't do anything in an effort to maintain forwards
711  // compatibility with older versions of Houdini.
712  // Returns true if anything was written to the stream.
713  void saveAsciiOptions(std::ostream &os) const;
714  bool saveBinaryOptions(int class_packet_id,
715  UT_Packet &packet,
716  std::ostream &os) const;
717 
718  CH_ExprLanguage stringMeaningToExprLanguage(
719  CH_StringMeaning meaning) const;
720 
732  PRM_IO_TOKEN_NUM
733  };
734 
735  // Returns the token used in parm IO.
736  static const char *getPacketIOToken(PRM_ParmIOToken token);
737  static int getPacketIOTokenLen(PRM_ParmIOToken token);
738  static int getPacketIOBinaryId(PRM_ParmIOToken token);
739 
740  // Compares if the given text matches a given token. You
741  // must provide the length of the text, which has the virtue
742  // of avoiding having to harden buffers!
743  static bool comparePacketIOToken(PRM_ParmIOToken token,
744  const char *text,
745  int textlen);
746 
747  // returns true if myData should be saved. Used for caching just within a
748  // session or preventing expensive copy/pastes.
749  bool shouldSaveData() const;
750 
751 private:
752 
753  inline bool getFieldBit(unsigned int field, int i) const
754  {
755  if (i < 0)
756  return (field != 0);
757  else
758  return ((field & (1 << (unsigned)i)) != 0);
759  }
760  inline void setFieldBit(unsigned int &field, int i, bool f)
761  {
762  if (i < 0)
763  {
764  if (f) // enable lowermost vector size bits
765  field = (1<<(unsigned)getVectorSize()) - 1;
766  else
767  field = 0;
768  }
769  else
770  {
771  if (f)
772  field |= (1 << (unsigned)i);
773  else
774  field &= ~(1 << (unsigned)i);
775  }
776  }
777 
778  void getFullParmPath(UT_WorkBuffer &path) const;
779 
780  /// When loading a file, it's possible that the channel mapping doesn't
781  /// match the expected channel name. In this case, we want to either
782  /// rename the channel, or delete the channel (if there are name
783  /// collisions).
784  void validateChannelName(PRM_ParmList &list, int subindex);
785 
786  void evaluationError(
787  const PRM_ParmList *thelist,
788  int vector_index, int err, int thread) const;
789 
790  // This method is *NOT* thread-safe wrt microNode() so do not access the
791  // source and destination PRM_Instance pointers from multiple threads when
792  // calling this.
793  void adoptMicroNodes(PRM_Instance &thesrcinstance);
794 
795  /// Thread-safe version of hasMicroNodes() that can be called at the same
796  /// time as microNode().
797  inline PRM_ParmMicroNode *threadSafeMicroNodes() const;
798 
799 private:
800 
801  enum { // bitflags for myBitField
802  /*BITFLAG_UNUSED_BIT = 0x0002,*/
803  /*BITFLAG_UNUSED_BIT = 0x0004,*/
804  BITFLAG_EXPRESSIONSTATE = 0x0008,
805  BITFLAG_UNDOSAVED = 0x0010,
806  BITFLAG_ACTIVETAKE = 0x0020,
807  BITFLAG_TAKEALWAYSACTIVE = 0x0040,
808  BITFLAG_SAVEAUTOSCOPE = 0x0080,
809  BITFLAG_SPAREPARM = 0x0100,
810  BITFLAG_AUTOTAKEUNDOSAVED = 0x0400,
811  BITFLAG_DEFAULTSINIT = 0x0800,
812  BITFLAG_VALUESTATE = 0x1000,
813  BITFLAG_BYPASS = 0x2000,
814  BITFLAG_SAVELABEL = 0x4000,
815  BITFLAG_SAVEAUTOSELECT = 0x8000,
816 
817  // Flags that should be saved
818  BITFLAG_SAVE_MASK = (BITFLAG_EXPRESSIONSTATE)
819  };
820 
821  unsigned int myBitField;
822  unsigned int myEnableField;
823  unsigned int myLockField;
824  unsigned int myAutoScopeField;
825  unsigned int myVisibleField;
826  unsigned int myAutoSelectField;
827 
828  // Flag to indicate that the handle binded to this parm is active
829  unsigned int myActiveField;
830 
831  PRM_Template *myTemplatePtr;
832 
833  PRM_Value *myNotifyValue;
834  unsigned myDirtyParmFlags;
835  unsigned mySendExtraFlags;
836 
837  CH_Channel **myChannelPtrs;
839  myChannelAliases;
840 
841  struct ChannelCustomColor
842  {
843  ChannelCustomColor()
844  { myHasCustomColor = false; }
845  UT_Color myColor;
846  bool myHasCustomColor;
847  };
848  ChannelCustomColor *myChannelColors;
849 
850  PRM_Parm *myParm;
851  const PRM_Multi *myMultiParmOwner;
852 
853  PRM_ParmMicroNode *myMicroNodes;
854  PRM_ConstMicroNode *myConstMicroNodes;
855  mutable UT_TBBSpinLock myMicroNodesLock;
856 };
857 
858 inline int
860  bool allow_alias) const
861 {
862  int size = myTemplatePtr->getVectorSize();
863  int retval = -1;
864  int i = 0;
865 
866  if (allow_alias && myChannelAliases)
867  {
868  for (i = 0; i < size; i++)
869  {
870  if (myChannelAliases[i] == thechannelname)
871  {
872  retval = i;
873  break;
874  }
875  }
876  }
877 
878  if (retval == -1)
879  retval = myTemplatePtr->findSubIndex(thechannelname);
880 
881  return retval;
882 }
883 
884 inline unsigned
886 {
887  if(comp < 0)
888  return myEnableField;
889 
890  return ( myEnableField & (1<<comp) ) ? 1 : 0;
891 }
892 
893 inline bool
895 {
896  // Separators, labels and headings have no values, so we use the entire
897  // visible field for them.
898  if (!getVectorSize())
899  return (myVisibleField != 0);
900 
901  return getFieldBit(myVisibleField, comp);
902 }
903 
904 inline void
906 {
907  if (getVectorSize())
908  setFieldBit(myVisibleField, comp, f);
909  else
910  myVisibleField = f ? SYS_UINT32_MAX : 0;
911 }
912 
913 #endif
CH_Manager * getManager() const
unsigned int getSaveFlags() const
Definition: PRM_Instance.h:376
bool getVisibleState(int comp=-1) const
Definition: PRM_Instance.h:894
PRM_OverrideType
Definition: PRM_Parm.h:69
PRM_AddKeyType
Definition: PRM_Parm.h:58
bool isSendExtra(int vi) const
Definition: PRM_Instance.h:481
#define EV_NOERROR
Definition: EX_Error.h:18
void setUndoSavedFlag(bool f)
Definition: PRM_Instance.h:412
GLsizei GLenum const void * indices
Definition: glcorearb.h:406
const PRM_Template * getTemplatePtr() const
Definition: PRM_Instance.h:535
UT_JSONValueMap stores a map/dictionary of UT_JSONValue objects.
int int32
Definition: SYS_Types.h:39
void setAutoScopeField(unsigned int field)
Definition: PRM_Instance.h:667
void setSaveFlags(unsigned int f)
Definition: PRM_Instance.h:378
CH_ExprLanguage
const UT_StringHolder & getChannelToken(int i) const
Definition: PRM_Instance.h:530
CH_StringMeaning
GT_API const UT_StringHolder time
UT_SharedPtr< PRM_UndoData > PRM_UndoDataHandle
Definition: PRM_Parm.h:128
const PRM_Template * getMultiParmTemplate() const
Definition: PRM_Template.h:275
bool isDirty(int vec_idx) const
Definition: PRM_Instance.h:467
const PRM_ChoiceList * getChoiceListPtr() const
Definition: PRM_Instance.h:532
const GLuint GLenum const void * binary
Definition: glcorearb.h:1924
UT_ConcurrentSet< UT_StringHolder > DEP_ContextOptionDeps
GLsizei const GLchar *const * path
Definition: glcorearb.h:3341
SYS_FORCE_INLINE T * SYSconst_cast(const T *foo)
Definition: SYS_Types.h:136
PRM_DefaultType
Definition: PRM_Default.h:19
int getExpressionState() const
Definition: PRM_Instance.h:263
bool getSaveAutoSelectFlag() const
Definition: PRM_Instance.h:424
PRM_KeySetType
GLdouble s
Definition: glad.h:3009
const char * getToken() const
Definition: PRM_Instance.h:518
int getVectorSize() const
Definition: PRM_Instance.h:524
unsigned getEnableState(int comp=-1) const
Definition: PRM_Instance.h:885
__hostdev__ void setValue(uint32_t offset, bool v)
Definition: NanoVDB.h:5750
const PRM_Value * inputNotifyValue() const
Definition: PRM_Instance.h:502
bool getSaveLabelFlag() const
Definition: PRM_Instance.h:428
bool hasAnySendExtraFlags() const
Definition: PRM_Instance.h:483
float fpreal32
Definition: SYS_Types.h:200
void setChannel(int subindex, CH_Channel *chp)
Definition: PRM_Instance.h:319
void setDefaultsInitFlag(bool f)
Definition: PRM_Instance.h:439
__hostdev__ float getValue(uint32_t i) const
Definition: NanoVDB.h:5578
std::unique_ptr< T, Deleter > UT_UniquePtr
A smart pointer for unique ownership of dynamically allocated objects.
Definition: UT_UniquePtr.h:39
virtual bool isRotationParm() const
Definition: PRM_Instance.h:606
double fpreal64
Definition: SYS_Types.h:201
PRM_TypeExtended getTypeExtended() const
Definition: PRM_Instance.h:506
CH_Channel * getChannel(int subindex) const
Definition: PRM_Instance.h:313
void clearAllDirtyFlags()
Definition: PRM_Instance.h:471
PRM_Template * getTemplatePtr()
Definition: PRM_Instance.h:536
int findSubIndex(const UT_StringRef &thechannelname, bool allow_alias) const
Definition: PRM_Instance.h:859
void setDirtyFlags(int vec_idx)
Definition: PRM_Instance.h:473
GLfloat f
Definition: glcorearb.h:1926
bool getDefaultsInitFlag() const
Definition: PRM_Instance.h:437
virtual bool isEditable(PRM_ParmList *thelist, fpreal time, int index) const
Definition: PRM_Instance.h:286
bool getBypassFlag() const
Definition: PRM_Instance.h:396
fpreal getGlobalStart() const
Definition: CH_Manager.h:1210
GLint ref
Definition: glcorearb.h:124
void setVisibleState(bool f, int comp=-1)
Definition: PRM_Instance.h:905
PRM_ChanState
Definition: PRM_ChanState.h:14
SYS_FORCE_INLINE void checkForExpressionErrors(const PRM_ParmList *thelist, int vector_index, int thread) const
Definition: PRM_Instance.h:680
PRM_Template * getMultiParmTemplate()
Definition: PRM_Instance.h:516
UT_Function< void(DEP_MicroNode &, DEP_MicroNode &) > Visitor
#define SYS_FORCE_INLINE
Definition: SYS_Inline.h:45
fpreal getMultiSize() const
Definition: PRM_Instance.h:510
GLsizei GLsizei GLchar * source
Definition: glcorearb.h:803
bool getUndoSavedFlag()
Definition: PRM_Instance.h:410
void setLockField(unsigned int locks)
Definition: PRM_Instance.h:665
void setActiveTakeFlag(int onoff)
Definition: PRM_Instance.h:385
PRM_ErrorCode
Definition: PRM_Error.h:21
const char * getLabel() const
Definition: PRM_Instance.h:520
long long int64
Definition: SYS_Types.h:116
void setBypassFlag(bool onoff)
Definition: PRM_Instance.h:398
GLuint const GLchar * name
Definition: glcorearb.h:786
bool getAlwaysTakeFlag() const
Definition: PRM_Instance.h:383
#define SYS_UINT32_MAX
Definition: SYS_Types.h:172
unsigned int getAutoScopeField() const
Definition: PRM_Instance.h:445
const PRM_Type & getType() const
Definition: PRM_Instance.h:504
that also have some descendant prim *whose name begins with which in turn has a child named baz where *the predicate active
virtual void destroyChildParms()
Definition: PRM_Instance.h:464
GLdouble t
Definition: glad.h:2397
unsigned int getLockField() const
Definition: PRM_Instance.h:443
PRM_Callback getCallback() const
Definition: PRM_Instance.h:522
fpreal getEvaluateTime(int thread) const
Functions for obtaining and setting the current evaluation time.
Definition: CH_Manager.h:1463
GLsizeiptr size
Definition: glcorearb.h:664
**Note that the tasks the is the thread number *for the or if it s being executed by a non pool thread(this *can happen in cases where the whole pool is occupied and the calling *thread contributes to running the work load).**Thread pool.Have fun
PRM_MultiType getMultiType() const
Definition: PRM_Instance.h:508
bool getSaveAutoScopeFlag() const
Definition: PRM_Instance.h:421
const PRM_Template * getMultiParmTemplate() const
Definition: PRM_Instance.h:514
virtual bool isEditableByUI(PRM_ParmList *thelist, fpreal time, int index) const
Definition: PRM_Instance.h:288
const PRM_Range * getRangePtr() const
Definition: PRM_Instance.h:526
SIM_API const UT_StringHolder force
GLenum GLsizei GLsizei GLint * values
Definition: glcorearb.h:1602
PRM_TypeExtended
Definition: PRM_Type.h:510
fpreal64 fpreal
Definition: SYS_Types.h:277
PRM_ParmOwner * getParmOwner() const
Definition: PRM_Instance.h:554
GLuint index
Definition: glcorearb.h:786
bool areAllFlagsClean() const
Definition: PRM_Instance.h:469
PRM_Parm * getParm() const
Definition: PRM_Instance.h:558
int getValueState() const
Definition: PRM_Instance.h:274
void setExpressionState(int state)
Definition: PRM_Instance.h:267
bool getAutoTakeUndoSavedFlag()
Definition: PRM_Instance.h:415
fpreal getGlobalStartTime() const
Definition: PRM_Instance.h:305
void getChannelToken(UT_String &chname, int i) const
Definition: PRM_Instance.h:528
void setTimeDependentForEval(int vi, bool timedep) const
Definition: PRM_Instance.h:346
void setSendExtra(int vi)
Definition: PRM_Instance.h:485
#define UT_ASSERT(ZZ)
Definition: UT_Assert.h:156
Definition: core.h:1131
unsigned int getAutoSelectField() const
Definition: PRM_Instance.h:648
type
Definition: core.h:1059
bool hasMicroNodes() const
Return true if this parameter has micronodes, NOT thread-safe.
Definition: PRM_Instance.h:621
CH_Collection * getChannelGroupPtr() const
Definition: PRM_Instance.h:291
void setAutoTakeUndoSavedFlag(bool f)
Definition: PRM_Instance.h:417
#define PRM_API
Definition: PRM_API.h:10
unsigned int uint
Definition: SYS_Types.h:45
int getMultiStartOffset() const
Definition: PRM_Instance.h:512
void setAutoSelectField(unsigned int field)
Definition: PRM_Instance.h:673
void setValueState(int state)
Definition: PRM_Instance.h:278
UT_SharedPtr< const PRM_DataItem > PRM_DataItemHandle
Definition: PRM_Parm.h:97
PRM_Value * inputNotifyValue()
Definition: PRM_Instance.h:501
Definition: format.h:895
PRM_MultiType
This type enum defines the different types of multi (dynamic) parameters.
Definition: PRM_Type.h:417
bool getActiveTakeFlag() const
Definition: PRM_Instance.h:381
fpreal getEvalTime(int thread) const
Definition: PRM_Instance.h:297
PRM_ParmList * getParmList() const
Definition: PRM_Instance.h:556