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