HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
PI_OpHandleLink.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: PI_OpHandleLink.h (PI Library, C++)
7  *
8  * COMMENTS:
9  *
10  * PI base class.
11  */
12 
13 #ifndef __PI_OpHandleLink__
14 #define __PI_OpHandleLink__
15 
16 #include "PI_API.h"
17 #include <OP/OP_Value.h>
18 #include <PRM/PRM_ChanState.h>
19 #include <PRM/PRM_Value.h>
20 #include <CH/CH_ExprLanguage.h>
21 
22 #include <UT/UT_Color.h>
23 #include <UT/UT_Function.h>
24 #include <UT/UT_IntArray.h>
25 #include <UT/UT_String.h>
26 #include <UT/UT_StringArray.h>
27 #include <UT/UT_SymbolTable.h>
28 #include <UT/UT_UndoManager.h>
29 #include <UT/UT_ValArray.h>
30 #include <UT/UT_VectorTypes.h>
31 
32 #include <iosfwd>
33 
34 
35 #define PI_SETTING_SHOWOPPATH "showoppath"
36 #define PI_SETTING_COLOR "color"
37 #define PI_SETTING_OWNEROP "ownerop"
38 #define PI_SETTING_OWNEROPGROUP "owneropgroup"
39 
40 class OP_Node;
41 class OP_Operator;
42 class CMD_Args;
43 class PI_SettingList;
44 class PI_PITemplate;
45 
47 {
48 public:
51 
52  struct LateBinding
53  {
54  // Interface to define the protocol for implementing handle late bindings
55  LateBinding() = default;
56  virtual ~LateBinding() = default;
57 
58  // Called when a handle change has started
59  virtual void beginHandleChange(PI_OpHandleLink const* pi, void* ui_event)
60  {
61  }
62 
63  // Called when a handle change has ended
64  virtual void endHandleChange(PI_OpHandleLink const* pi, void* ui_event)
65  {
66  }
67 
68  // read/write parm values
69  virtual bool toStateValues(PI_OpHandleLink*, void* ui_event) = 0;
70  virtual bool toHandleValues(PI_OpHandleLink*) = 0;
71 
72  // data accessors
73  virtual int getParmValue(PI_OpHandleLink const* pi, int pindex, int &val, int d=0) const = 0;
74  virtual int getParmValue(PI_OpHandleLink const* pi, int pindex, fpreal &val, fpreal d) const = 0;
75  virtual int getParmValue(PI_OpHandleLink const* pi, int pindex, UT_String &val, UT_String d=0) const = 0;
76  virtual int setParmValue(PI_OpHandleLink const* pi, int pindex, fpreal value, bool setkey) = 0;
77  virtual int setParmValue(PI_OpHandleLink const* pi, int pindex, int value, bool setkey) = 0;
78  virtual int setParmValue(PI_OpHandleLink const* pi, int pindex, UT_StringRef const& value) = 0;
79 
80  // Return true if the parm id refers to an enabled parm. False otherwise.
81  virtual bool isParmEnabled(PI_OpHandleLink const* pi, int pindex) const = 0;
82  };
83 
84  PI_OpHandleLink(const PI_PITemplate &templ);
85  virtual ~PI_OpHandleLink();
86 
87  // Methods to link a handle's parameter with an op's parameter.
88  // Return 1 on success, 0 if parm name is invalid. op_type_name tells the
89  // type of operator. Do not call these methods from the class c-tor.
90  int linkOpParmToHandleParm(const char *op_type,
91  const char *handle_parm_name,
92  const char *op_parm_name);
93 
94  // Activate the underlying handle parm, typically used when dynamic handle
95  // binding is in effect (see PI_OpHandleLink::HandleBinding)
96  int activateHandleParm(int pindex);
97 
98  // Disable the underlying handle parm
99  void disableHandleParm(int pindex);
100 
101  virtual int attach(OP_Node &node);
102  virtual int detach(OP_Node &node);
103  virtual void detachAll();
104 
105  void attachForKeyframe(OP_Node &node);
106  void detachForKeyframe(OP_Node &node);
107  void detachAllForKeyframe();
108 
109  // Hide all handle parameter parts except for the ones from handle_parms
110  // (starting from index `beg`).
111  void isolateHandleParms(int beg,
112  const UT_StringArray& handle_parms);
113 
114  void setShowOpPath(bool onoff);
115  virtual bool getShowOpPath() const;
116 
117  // The root description is the description for the PI that is set
118  // in the binding. Then the name of the first attached operator may
119  // be appended by the buildDecription function (which calls
120  // the virtual descriptionChanged in case a subclass needs to do
121  // something in responds to a description change).
122  void setRootDescription(const char *description);
123  const char *getRootDescription() const;
124  void buildDescription();
125  const char *getDescription() const;
126  virtual void descriptionChanged(const char* old_description);
127 
128  // The time overrides are used by the Motion Path PI to manipulate other PIs
129  // to modify parm values at a given time instead of at the current time
130  // in the animation timeline.
131  void setIsTimeOverride(bool is_time_override);
132  void setTimeOverrideTime(fpreal t);
133 
134  bool getIsTimeOverride() const
135  { return myIsTimeOverride; }
137  { return myTimeOverrideTime; }
138 
139  // Does this PI allow saving/loading from the per-op and/or last settings
140  // tables? By default, it allows using both tables.
142  { return myAllowUsingPerOpSettingsTable; }
144  { return myAllowUsingLastSettingsTable; }
146  { return myAllowUsingOpTypeSettings; }
148  { return myAllowUsingLastVisibilitySetting; }
149 
150  // When saving settings for this PI to the last settings table, we
151  // often only want PI's of this type to use these settings when they're
152  // attached to a specific type of operator. For example, the "xform"
153  // PI can be attached to many different types of sops. However, we
154  // don't want the last "xform" settings for the "copy" sop to be used
155  // the next time we put down an "xform" sop. This method returns that
156  // type of operator, if there are any restrictions, or null if there are
157  // no restrictions. The PI must be attached to at least one op when
158  // this method is called. By default, it returns null if this PI is
159  // attached to more than one op, or the type of the op if it is attached
160  // to exactly one. This method will also always return null if the
161  // myAllowUsingOpTypeSettings flag is false.
162  OP_Operator *lastSettingsOperatorTypeRestriction() const;
163 
164  // Return the op to which we're attached, or nil if we're detached.
165  OP_Node *getOpNode(int opnum = 0) const;
166  int getNumOps() const;
167  OP_Node *getKeyframeOpNode(int opnum = 0) const;
168  int getKeyframeNumOps() const;
169 
170  // Find out if we contain this node:
171  int hasOpNode(const OP_Node &node) const;
172  int hasKeyframeOpNode(const OP_Node &node) const;
173  OP_Node *findOpNode(int op_type, const char *op_name) const;
174 
175  // Update ourselves (and our handles) based on our ops parm values.
176  void doUpdateFromOpParms();
177  virtual void forceUpdateFromOpParms();
178 
179  // Respond to a parameter change in the op. Called from the above
180  // function.
181  virtual void handleOpNodeChange(OP_Node &node);
182  virtual void handleOpUIChange(OP_Node & /*node*/)
183  { }
184  virtual int wantsOpNodeChange(const OP_Node & /*node*/) const
185  { return 0; }
186  virtual bool flagOpNodeChangeNeeded(OP_Node & /*node*/)
187  { return false; }
188 
189  // The user can dynamically change the bindings from the textport.
190  // We need to refresh the current handle link in the viewports
191  // because it could be affected. Return 0 if this handle has no bindings
192  // left.
193  virtual int refreshBindings(int op_type, const char *op_name);
194 
195  // These id values are used by the linking mechanism to determine if
196  // the pi for a particular linked parm exists already or not.
197  void id(int i);
198  int id() const;
199 
200  bool hasLinkedParms() const
201  { return myParmNames.entries() > 0; }
202 
203  // Returns a list of all parms bound to this handle.
204  const UT_StringArray &linkedParmNames(int opnum) const
205  { return *myParmNames(opnum); }
206  // These virtuals are similar to the linked... functions below.
207  // The difference is that these versions are used by the Key
208  // functions above. By ovrriding these, subclasses can make the
209  // above functions work for OP parms that are not linked to
210  // PI parms.
211  virtual const UT_StringArray &allParmNames(int opnum) const
212  { return *myParmNames(opnum); }
213 
214  // This gets the index of the operator that is actually bound
215  // to the specified index. If none is bound, -1 is returned.
216  int getOpnumForHandleParmIndex(int idx) const;
217 
218  // Query or set the active color of the PI:
219  const UT_Color &getActiveColor() const;
220  virtual void setActiveColor(const UT_Color &c);
221 
222  // Set accessibility state of the binding
223  void setBindingState(const bool active);
224 
225  virtual int isEqual(const PI_OpHandleLink &pi) const;
226  virtual int setEqual(const PI_OpHandleLink &pi);
227 
228  // An ethereal handle link is one that is invisible by nature.
229  bool ethereal() const;
230  const PI_PITemplate &getTemplate() const;
231  PI_PITemplate &getTemplate();
232 
233  int writeOptions(std::ostream &os, const char *baseCommand);
234  int runBindCommand(CMD_Args &args);
235  int runUnbindCommand(CMD_Args &args);
236 
237  // Functions used to handle menu functionality
238  void editChannels(int append_channels, int opnum=-1);
239  void findKey(int direction, int opnum=-1);
240  void setKeys(int opnum = -1,
241  int pindex_start = -1,
242  int pined_stop = -1,
243  const char *undo_str = 0);
244  void removeKeys(int opnum=-1);
245  void deleteChannels(int opnum=-1);
246  void lockParms(int opnum=-1);
247  void revertToDefaults(int opnum=-1);
248  void revertToFactoryDefaults(int opnum=-1);
249  void overwriteDefaults(int opnum=-1);
250 
251  // Load or save the settings for this PI. If specific_to_op is true
252  // in saveSettings() then the PI's settings will be saved in the per-op
253  // settings table instead of the last settings table.
254  virtual void loadSettings(const PI_SettingList &settings);
255  virtual void saveSettings(PI_SettingList &settings,
256  bool specific_to_op) const;
257 
258  // Save the settings for this PI.
259  virtual void saveSettingsToAppropriateLocation();
260 
261  // Load the settings for this PI from the per-op or last setting table.
262  // The PI _must_ be attached to its nodes when this method is called.
263  void loadSettingsFromTables(bool okay_to_use_last_settings);
264 
265  // Remove any settings this PI may have stored from the per-op and
266  // last setting tables.
267  void removeSettingsFromTables();
268 
270  {
271  public:
272  int myIndex;
274  };
275 
276  // This extracts the projection associated with this binding, if any,
277  // from the parmname. channel is set to the name of the channel
278  // which is bound.
279  static void extractProjection(UT_String &channel,
280  const char *parmname, fpreal &a, fpreal &b,
281  fpreal &c, fpreal &d);
282  static void extractChannelName(UT_String &channel,
283  const char *parmname)
284  {
285  fpreal dummy;
286  extractProjection(channel, parmname,
287  dummy, dummy,
288  dummy, dummy);
289  }
290 
291  void setLateBinding(LateBinding * binding);
292  bool hasLateBinding() const;
293  bool hasLateBinding(LateBinding const * binding) const;
294 
295  // Map a handle parm name to an index, or retrieve the index by the name.
296  // Indices must be non-negative. If the parm has not been mapped,
297  // findHandleParmIndex returns -1.
298  int findHandleParmIndex(const char *h_parm_name) const;
299 
300  // Allows the PI to react before being deleted.
301  virtual void onDeletion();
302 
303  // Returns the proxy pointer id that is used by other classes if they need
304  // to hold a pointer to an instance PI_OpHandleLink.
305  // (e.g. Use of BM_OpHandleLink by MPI_MotionPath)
306  int getProxyIndex() const { return myProxyIndex; }
307 
308  // Update the PI settings with a new set of setting values
309  void updateSettings(char const* setting_string);
310 
311  // Call these methods to customize how their settings are saved.
313  { myAllowUsingPerOpSettingsTable = onoff; }
315  { myAllowUsingLastSettingsTable = onoff; }
317  { myAllowUsingOpTypeSettings = onoff; }
319  { myAllowUsingLastVisibilitySetting = onoff; }
320 
321  // Iterate over all parms
322  int iterateParms(int opnum, ReadParmFunc func) const;
323  int iterateParms(int opnum, ModifyParmFunc func, bool modify_locked=false);
324 
325 protected:
326 
327  // Update ourselves (and our handles) based on our ops parm values.
328  virtual void updateFromOpParms();
329 
330  // Override this function to help decide which handles should be
331  // active when this PI is attached to an operator. This will be
332  // called if we successfully link to the given pindex.
333  //
334  // You should call the base class first and only proceed if it
335  // returns 1. I don't know the semantics of that - it's just how
336  // the old linkOpParm worked.
337  virtual int justLinked(int pindex);
338  virtual void justUnlinked(int pindex);
339 
340  virtual PI_Interest *getInputGroupInterests() const;
341 
342  // These methods add/remove interests in all of a PI's input group
343  // parameters. These methods are called when a node is attached or
344  // detached from the PI. They use the array of PI_Interests
345  // returned by getInputGroupInterests().
346  void addAllInputGroupInterests(int opnum);
347  void removeAllInputGroupInterests(int opnum);
348 
349  // Convenience method for descendants to get the current time.
350  virtual fpreal getTime() const;
351 
352  // Methods to get/set the op's parameter values. If the parameter has
353  // not been linked to an op parameter, these methods return 0. Otherwise,
354  // they return 1.
355  int getParmValue(int pindex, int &val, int d=0) const;
356  int getParmValue(int pindex, fpreal &val, fpreal d=0) const;
357  int getParmValue(int pindex, UT_String &val,
358  UT_String d=0) const;
359  // Get the [pindex, pindex+3) parm values into a UT_Vector3R
360  void getParmVector3(int pindex, UT_Vector3R &v,
361  fpreal def = 0.0) const;
362 
363  int getParmInstValue(int pindex, const int *inst,
364  int &val, int d=0,
365  int nestlevel=1) const;
366  int getParmInstValue(int pindex, const int *inst,
367  fpreal &val, fpreal d=0,
368  int nestlevel=1) const;
369  int getParmInstValue(int pindex, const int *inst,
370  UT_String &val, UT_String d=0,
371  int nestlevel=1) const;
372  // Get the [pindex, pindex+3) parm values into a UT_Vector3R
373  void getParmInstVector3(int pindex, const int *inst,
374  UT_Vector3R &v,
375  fpreal def = 0.0) const;
376 
377  int setParmValue(int pindex, int val, bool addkey=false);
378  int setParmValue(int pindex, fpreal val, bool addkey=false);
379  int setParmValue(int pindex, const UT_String &val,
380  CH_StringMeaning meaning);
381  // Get the [pindex, pindex+3) parm values into a UT_Vector3R
382  void setParmVector3(int pindex, const UT_Vector3R &v);
383 
384  int setParmInstValue(int pindex, const int *inst,
385  int val, bool addkey=false,
386  int nestlevel=1);
387  int setParmInstValue(int pindex, const int *inst,
388  fpreal val, bool addkey=false,
389  int nestlevel=1);
390  int setParmInstValue(int pindex, const int *inst,
391  const UT_String &val,
392  CH_StringMeaning meaning,
393  int nestlevel=1);
394  void setParmInstVector3(int pindex, const int *inst,
395  const UT_Vector3R &v);
396 
397  int performParmCallback(int pindex, int theitem);
398 
399  int setOpParmValue(OP_Node *op, PRM_Parm *parm, int vecidx,
400  int val, bool addkey=false);
401  int setOpParmValue(OP_Node *op, PRM_Parm *parm, int vecidx,
402  fpreal val, bool addkey=false);
403  int setOpParmValue(OP_Node *op, PRM_Parm *parm, int vecidx,
404  const UT_String &val,
405  CH_StringMeaning meaning);
406 
407  // Methods to read or modify parm values given a pindex without adding keys
408  // Returns true if parm is read/modified, otherwise false
409  bool readParm(int pindex, ReadParmFunc f) const;
410  bool modifyParm(int pindex, ModifyParmFunc f, bool modify_locked=false);
411 
412  // copies the keyframe structure of pindex_from to pindex_dest, while
413  // leaving the value of pindex_dest constant.
414  void copyKeyStructure(int pindex_dest, int pindex_from);
415 
416  // returns true if the parameter is enabled (a la disableParms())
417  bool isParmEnabled(int pindex, int opnum = 0) const;
418 
419  // returns the parameter animation state.
420  PRM_ChanState getParmState(int pindex, int opnum = 0) const;
421 
422  // Functions to access the parameter index arrays.
423  int getLinkedParmCount() const
424  { return myParmNames.entries(); }
425 
426  // This function determines whether or not we should do an
427  // updateFromOpParms when the time changes.
428  // Returns true unless we have an input group interest, in which
429  // case the input group interest is enough to force the update,
430  // so we return false.
431  virtual int hasTimeInterest() const;
432  virtual void handleTimeChange();
433 
434  // These two functions are provided for all the PI based operations
435  // that need to manage an undo block that begins in one function
436  // but ends in another function (or another instance of the same
437  // function).
438  //
439  // However, they can only handle ONE block at a time. No nesting
440  // of calls to beginDistributedUndo!
441  void beginDistributedUndoBlock(const char *operation,
442  UT_UndoBlockType blocktype);
443  void endDistributedUndoBlock();
444 
445  // Returns true if we have called beginDistributedUndoBlock but have
446  // not yet called endDistributedUndoBlock; returns false otherwise.
447  bool inDistributedUndoBlock();
448 
449  // This virtual callback is called whenever one of our attached
450  // or attached-for-keyframe nodes is changed.
451  virtual void handleOpChange(OP_Node *op,
452  OP_EventType etype,
453  void *data);
454 
455  // Some functions for getting and setting our owner operator information.
456  // The owner operator is the operator that defines what space our handles
457  // should appear in and what SOP/group field we should be interested in.
458  virtual void setOwnerOp(const char *owner_op);
459  const UT_String &getOwnerOp() const;
460  OP_Node *getOwnerOpRelativeTo(OP_Node *node) const;
461  virtual void setOwnerOpGroup(const char *owner_op_group);
462  const UT_String &getOwnerOpGroup() const;
463 
464  // Return the channel name for our first input group interest.
465  const UT_StringHolder &getFirstInputGroupInterestName() const;
466 
467  // This helper function returns true if the parm channel_name is locked and
468  // false otherwise. This function will follow any channel references that
469  // this parm might have to determine the "true" locked status.
470  static bool isOpParmLocked(
471  const char *channel_name, OP_Node &op, fpreal time,
472  const PRM_Parm **ret_parm = NULL,
473  const OP_Node **ret_node = NULL);
474 
475  // Called by derived class to update the state values bind to a handle
476  void updateStateValues(void* ui_event);
477 
478  // Called when a handle change has started
479  void beginHandleChange(void* ui_event);
480 
481  // Called when a handle change has ended
482  void endHandleChange(void* ui_event);
483 
484  // Typically called from a derived class to allocate a proxy
485  void allocProxy(void* ptr);
486 
487  // Called from a derived class to free the PI proxy previously allocated
488  // with allocProxy().
489  void freeProxy();
490 
491  // Return the op parm label linked to pi_index
492  UT_StringHolder getOpParmLabel(int pi_index) const;
493 
494 private:
495  int linkOpParm(const char *op_type,
496  int pindex, const char *parmname);
497  void updateParmLockStatus( OP_Node &op );
498  UT_StringArray &opParmNames(const char *op_type);
499  void addParmNames(int opnum);
500  void removeParmNames(int opnum);
501 
502  void setKeysSingleOp(int opnum, int pindex = -1,
503  UT_String *names = NULL,
504  const char *name_prefix = NULL);
505  void removeKeysSingleOp(int opnum);
506  void deleteChannelsSingleOp(int opnum);
507  void lockParmsSingleOp(int opnum);
508  void revertToDefaultsSingleOp(int opnum);
509  void revertToFactoryDefaultsSingleOp(int opnum);
510  void overwriteDefaultsSingleOp(int opnum);
511 
512  // For a given pindex, add/remove interest's in the corresponding
513  // parameter's PRM_Value.
514  int addInputGroupInterest(int pindex,
515  PRM_ValueCallback callback,
516  int opnum);
517  int removeInputGroupInterest(int pindex,
518  PRM_ValueCallback callback,
519  int opnum);
520 
521  // Callback function to make sure we always know when one of our
522  // nodes is being deleted.
523  static void handleOpChangeCallback(OP_Node *op, void *callee,
524  OP_EventType etype, void *data);
525 
526  void clearOpTypeParmNamesMap();
527 
528  // used for updating handle values from a dynamic handle binding
529  void updateHandleValues();
530 
531  const PI_PITemplate &myTemplate;
532  // This symbol table has as it's index the optype name, and as it's
533  // contents the cached UT_StringArrays which would correspond to that
534  // op's ParmNames.
535  UT_SymbolMap<UT_StringArray *> myOpTypeParmNames;
536 
537  // This is a translation from our PI parm index into the opnum.
538  UT_IntArray myOpnumForParmIndex;
539 
540  // This is indexed by the opnum and has the string array of op parms
541  // that correspond to that opnum. The index on the string array is
542  // the index into our PI parms.
543  UT_ValArray<UT_StringArray *> myParmNames;
544  UT_ValArray<OP_Node *> myOpNodes;
545  UT_ValArray<OP_Node *> myKeyframeOpNodes;
546  UT_StringArray myInputGroupInterests;
547  int myId;
548  const PI_Interest *myInterests;
549  UT_String myRootDescription;
550  UT_String myDescription;
551  UT_String myOwnerOp;
552  UT_String myOwnerOpGroup;
553 
554  UT_Color myActiveColor;
555 
556  int myDistributedUndoBlockLevel;
557  bool myAllowUsingPerOpSettingsTable;
558  bool myAllowUsingLastSettingsTable;
559  bool myAllowUsingOpTypeSettings;
560  bool myAllowUsingLastVisibilitySetting;
561  bool myShowOpPath;
562 
563  bool myIsTimeOverride;
564  fpreal myTimeOverrideTime;
565  LateBinding* myLateBinding;
566  int myProxyIndex;
567 };
568 
569 #endif
570 
PXL_API const char * getDescription(const ColorSpace *space)
Return the description of the color space.
CH_StringMeaning
GT_API const UT_StringHolder time
const GLdouble * v
Definition: glcorearb.h:837
IMF_EXPORT IMATH_NAMESPACE::V3f direction(const IMATH_NAMESPACE::Box2i &dataWindow, const IMATH_NAMESPACE::V2f &pixelPosition)
GLboolean GLboolean GLboolean GLboolean a
Definition: glcorearb.h:1222
#define PI_API
Definition: PI_API.h:10
GLfloat f
Definition: glcorearb.h:1926
PRM_ChanState
Definition: PRM_ChanState.h:14
UT_UndoBlockType
constexpr enabler dummy
An instance to use in EnableIf.
Definition: CLI11.h:985
GLuint id
Definition: glcorearb.h:655
std::function< T > UT_Function
Definition: UT_Function.h:37
GLboolean GLboolean GLboolean b
Definition: glcorearb.h:1222
void(* PRM_ValueCallback)(void *callee, void *value)
Definition: PRM_Value.h:21
that also have some descendant prim *whose name begins with which in turn has a child named baz where *the predicate active
GLdouble t
Definition: glad.h:2397
GLenum func
Definition: glcorearb.h:783
__hostdev__ constexpr T pi()
Pi constant taken from Boost to match old behaviour.
Definition: NanoVDB.h:976
fpreal64 fpreal
Definition: SYS_Types.h:277
auto ptr(T p) -> const void *
Definition: format.h:2448
GLuint GLfloat * val
Definition: glcorearb.h:1608
OP_EventType
Definition: OP_Value.h:22
**If you just want to fire and args
Definition: thread.h:609
Definition: core.h:1131
Definition: format.h:895