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