HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros 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 <UT/UT_Color.h>
18 #include <UT/UT_String.h>
19 #include <UT/UT_StringArray.h>
20 #include <UT/UT_IntArray.h>
21 #include <UT/UT_SymbolTable.h>
22 #include <UT/UT_ValArray.h>
23 #include <UT/UT_VectorTypes.h>
24 #include <UT/UT_UndoManager.h>
25 #include <PRM/PRM_ChanState.h>
26 #include <PRM/PRM_Value.h>
27 #include <OP/OP_Value.h>
28 #include <iosfwd>
29 
30 #include <functional>
31 
32 #include "PI_ResourceTemplate.h"
33 #include "PI_ResourceManager.h"
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 
46 {
47 public:
48  PI_OpHandleLink(const PI_PITemplate &templ);
49  virtual ~PI_OpHandleLink();
50 
51  // Methods to link a handle's parameter with an op's parameter.
52  // Return 1 on success, 0 if parm name is invalid. op_type_name tells the
53  // type of operator. Do not call these methods from the class c-tor.
54  int linkOpParmToHandleParm(const char *op_type,
55  const char *handle_parm_name,
56  const char *op_parm_name);
57 
58  virtual int attach(OP_Node &node);
59  virtual int detach(OP_Node &node);
60  virtual void detachAll();
61 
62  void attachForKeyframe(OP_Node &node);
63  void detachForKeyframe(OP_Node &node);
64  void detachAllForKeyframe();
65 
66  // Hide all handle parameter parts except for the ones from handle_parms
67  // (starting from index `beg`).
68  void isolateHandleParms(int beg,
69  const UT_StringArray& handle_parms);
70 
71  void setShowOpPath(bool onoff);
72  virtual bool getShowOpPath() const;
73 
74  // The root description is the description for the PI that is set
75  // in the binding. Then the name of the first attached operator may
76  // be appended by the buildDecription function (which calls
77  // the virtual descriptionChanged in case a subclass needs to do
78  // something in responds to a description change).
79  void setRootDescription(const char *description);
80  const char *getRootDescription() const;
81  void buildDescription();
82  const char *getDescription() const;
83  virtual void descriptionChanged();
84 
85  // The time overrides are used by the Motion Path PI to manipulate other PIs
86  // to modify parm values at a given time instead of at the current time
87  // in the animation timeline.
88  void setIsTimeOverride(bool is_time_override);
89  void setTimeOverrideTime(fpreal t);
90 
91  bool getIsTimeOverride() const
92  { return myIsTimeOverride; }
94  { return myTimeOverrideTime; }
95 
96  // Does this PI allow saving/loading from the per-op and/or last settings
97  // tables? By default, it allows using both tables.
99  { return myAllowUsingPerOpSettingsTable; }
101  { return myAllowUsingLastSettingsTable; }
103  { return myAllowUsingOpTypeSettings; }
105  { return myAllowUsingLastVisibilitySetting; }
106 
107  // When saving settings for this PI to the last settings table, we
108  // often only want PI's of this type to use these settings when they're
109  // attached to a specific type of operator. For example, the "xform"
110  // PI can be attached to many different types of sops. However, we
111  // don't want the last "xform" settings for the "copy" sop to be used
112  // the next time we put down an "xform" sop. This method returns that
113  // type of operator, if there are any restrictions, or null if there are
114  // no restrictions. The PI must be attached to at least one op when
115  // this method is called. By default, it returns null if this PI is
116  // attached to more than one op, or the type of the op if it is attached
117  // to exactly one. This method will also always return null if the
118  // myAllowUsingOpTypeSettings flag is false.
119  OP_Operator *lastSettingsOperatorTypeRestriction() const;
120 
121  // Return the op to which we're attached, or nil if we're detached.
122  OP_Node *getOpNode(int opnum = 0) const;
123  int getNumOps() const;
124  OP_Node *getKeyframeOpNode(int opnum = 0) const;
125  int getKeyframeNumOps() const;
126 
127  bool stealthMode() const
128  { return myStealthMode; }
129  void setStealthMode(bool onoff)
130  { myStealthMode = onoff; }
132  { return myStealthNode; }
134  { myStealthNode = node; }
135  bool stealthVisibility() const
136  { return myStealthVisibility; }
137  void setStealthVisibility(bool visible)
138  { myStealthVisibility = visible; }
139 
140  // Find out if we contain this node:
141  int hasOpNode(const OP_Node &node) const;
142  int hasKeyframeOpNode(const OP_Node &node) const;
143  OP_Node *findOpNode(int op_type, const char *op_name) const;
144 
145  // Update ourselves (and our handles) based on our ops parm values.
146  void doUpdateFromOpParms();
147 
148  // Respond to a parameter change in the op. Called from the above
149  // function.
150  virtual void handleOpNodeChange(OP_Node &node);
151  virtual void handleOpUIChange(OP_Node & /*node*/)
152  { }
153  virtual int wantsOpNodeChange(const OP_Node & /*node*/) const
154  { return 0; }
155  virtual bool flagOpNodeChangeNeeded(OP_Node & /*node*/)
156  { return false; }
157 
158  // The user can dynamically change the bindings from the textport.
159  // We need to refresh the current handle link in the viewports
160  // because it could be affected. Return 0 if this handle has no bindings
161  // left.
162  virtual int refreshBindings(int op_type, const char *op_name);
163 
164  // These id values are used by the linking mechanism to determine if
165  // the pi for a particular linked parm exists already or not.
166  void id(int i);
167  int id() const;
168 
169  // Returns a list of all parms bound to this handle.
170  const UT_StringArray &linkedParmNames(int opnum) const
171  { return *myParmNames(opnum); }
172  // These virtuals are similar to the linked... functions below.
173  // The difference is that these versions are used by the Key
174  // functions above. By ovrriding these, subclasses can make the
175  // above functions work for OP parms that are not linked to
176  // PI parms.
177  virtual const UT_StringArray &allParmNames(int opnum) const
178  { return *myParmNames(opnum); }
179 
180  // This gets the index of the operator that is actually bound
181  // to the specified index. If none is bound, -1 is returned.
182  int getOpnumForHandleParmIndex(int idx) const;
183 
184  // Query or set the active color of the PI:
185  const UT_Color &getActiveColor() const;
186  virtual void setActiveColor(const UT_Color &c);
187 
188  // Set accessibility state of the binding
189  void setBindingState(const bool active);
190 
191  virtual int isEqual(const PI_OpHandleLink &pi) const;
192  virtual int setEqual(const PI_OpHandleLink &pi);
193 
194  // An ethereal handle link is one that is invisible by nature.
195  bool ethereal(void) const;
196  const PI_PITemplate &getTemplate() const;
197 
198  int writeOptions(std::ostream &os, const char *baseCommand);
199  int runBindCommand(CMD_Args &args);
200  int runUnbindCommand(CMD_Args &args);
201 
202  // Functions used to handle menu functionality
203  void editChannels(int append_channels, int opnum=-1);
204  void findKey(int direction, int opnum=-1);
205  void setKeys(int opnum = -1,
206  int pindex_start = -1,
207  int pined_stop = -1,
208  const char *undo_str = 0);
209  void removeKeys(int opnum=-1);
210  void deleteChannels(int opnum=-1);
211  void lockParms(int opnum=-1);
212  void revertToDefaults(int opnum=-1);
213  void revertToFactoryDefaults(int opnum=-1);
214  void overwriteDefaults(int opnum=-1);
215 
216  // Load or save the settings for this PI. If specific_to_op is true
217  // in saveSettings() then the PI's settings will be saved in the per-op
218  // settings table instead of the last settings table.
219  virtual void loadSettings(const PI_SettingList &settings);
220  virtual void saveSettings(PI_SettingList &settings,
221  bool specific_to_op) const;
222 
223  // Save the settings for this PI.
224  virtual void saveSettingsToAppropriateLocation();
225 
226  // Load the settings for this PI from the per-op or last setting table.
227  // The PI _must_ be attached to its nodes when this method is called.
228  void loadSettingsFromTables(bool okay_to_use_last_settings);
229 
230  // Remove any settings this PI may have stored from the per-op and
231  // last setting tables.
232  void removeSettingsFromTables();
233 
235  {
236  public:
237  int myIndex;
239  };
240 
241  // This extracts the projection associated with this binding, if any,
242  // from the parmname. channel is set to the name of the channel
243  // which is bound.
244  static void extractProjection(UT_String &channel,
245  const char *parmname, fpreal &a, fpreal &b,
246  fpreal &c, fpreal &d);
247  static void extractChannelName(UT_String &channel,
248  const char *parmname)
249  {
250  fpreal dummy;
251  extractProjection(channel, parmname,
252  dummy, dummy,
253  dummy, dummy);
254  }
255 
256 protected:
257 
258  // Update ourselves (and our handles) based on our ops parm values.
259  virtual void updateFromOpParms(void);
260 
261  // Override this function to help decide which handles should be
262  // active when this PI is attached to an operator. This will be
263  // called if we successfully link to the given pindex.
264  //
265  // You should call the base class first and only proceed if it
266  // returns 1. I don't know the semantics of that - it's just how
267  // the old linkOpParm worked.
268  virtual int justLinked(int pindex);
269  virtual void justUnlinked(int pindex);
270 
271  virtual PI_Interest *getInputGroupInterests() const;
272 
273  // Map a handle parm name to an index, or retrieve the index by the name.
274  // Indices must be non-negative. If the parm has not been mapped,
275  // findHandleParmIndex returns -1.
276  int findHandleParmIndex(const char *h_parm_name) const;
277 
278  // These methods add/remove interests in all of a PI's input group
279  // parameters. These methods are called when a node is attached or
280  // detached from the PI. They use the array of PI_Interests
281  // returned by getInputGroupInterests().
282  void addAllInputGroupInterests(int opnum);
283  void removeAllInputGroupInterests(int opnum);
284 
285  // Convenience method for descendents to get the current time.
286  virtual fpreal getTime() const;
287 
288  // Methods to get/set the op's parameter values. If the parameter has
289  // not been linked to an op parameter, these methods return 0. Otherwise,
290  // they return 1.
291  int getParmValue(int pindex, int &val, int d=0) const;
292  int getParmValue(int pindex, fpreal &val, fpreal d=0) const;
293  int getParmValue(int pindex, UT_String &val,
294  UT_String d=0) const;
295  // Get the [pindex, pindex+3) parm values into a UT_Vector3R
296  void getParmVector3(int pindex, UT_Vector3R &v,
297  fpreal def = 0.0) const;
298 
299  int getParmInstValue(int pindex, const int *inst,
300  int &val, int d=0,
301  int nestlevel=1) const;
302  int getParmInstValue(int pindex, const int *inst,
303  fpreal &val, fpreal d=0,
304  int nestlevel=1) const;
305  int getParmInstValue(int pindex, const int *inst,
306  UT_String &val, UT_String d=0,
307  int nestlevel=1) const;
308  // Get the [pindex, pindex+3) parm values into a UT_Vector3R
309  void getParmInstVector3(int pindex, const int *inst,
310  UT_Vector3R &v,
311  fpreal def = 0.0) const;
312 
313  int setParmValue(int pindex, int val, bool addkey=false);
314  int setParmValue(int pindex, fpreal val, bool addkey=false);
315  int setParmValue(int pindex, const UT_String &val,
316  CH_StringMeaning meaning);
317  // Get the [pindex, pindex+3) parm values into a UT_Vector3R
318  void setParmVector3(int pindex, const UT_Vector3R &v);
319 
320  int setParmInstValue(int pindex, const int *inst,
321  int val, bool addkey=false,
322  int nestlevel=1);
323  int setParmInstValue(int pindex, const int *inst,
324  fpreal val, bool addkey=false,
325  int nestlevel=1);
326  int setParmInstValue(int pindex, const int *inst,
327  const UT_String &val,
328  CH_StringMeaning meaning,
329  int nestlevel=1);
330  void setParmInstVector3(int pindex, const int *inst,
331  const UT_Vector3R &v);
332 
333  int performParmCallback(int pindex, int theitem);
334 
335  int setOpParmValue(OP_Node *op, PRM_Parm *parm, int vecidx,
336  int val, bool addkey=false);
337  int setOpParmValue(OP_Node *op, PRM_Parm *parm, int vecidx,
338  fpreal val, bool addkey=false);
339  int setOpParmValue(OP_Node *op, PRM_Parm *parm, int vecidx,
340  const UT_String &val,
341  CH_StringMeaning meaning);
342 
343  // Methods to read or modify parm values given a pindex without adding keys
344  // Returns true if Parim is read/modified, otherwise false
345  bool readParm(int pindex, std::function<void(const PRM_Parm &parm,
346  int vecidx)> f);
347 
348  bool modifyParm(int pindex, std::function<void(PRM_Parm &parm,
349  int vecidx)> f);
350 
351 
352  // copies the keyframe structure of pindex_from to pindex_dest, while
353  // leaving the value of pindex_dest constant.
354  void copyKeyStructure(int pindex_dest, int pindex_from);
355 
356  // returns true if the parameter is enabled (a la disableParms())
357  bool isParmEnabled(int pindex, int opnum = 0) const;
358 
359  // returns the parameter animation state.
360  PRM_ChanState getParmState(int pindex, int opnum = 0) const;
361 
362  // Functions to access the parameter index arrays.
363  int getLinkedParmCount() const
364  { return myParmNames.entries(); }
365 
366  // This function determines whether or not we should do an
367  // updateFromOpParms when the time changes.
368  // Returns true unless we have an input group interest, in which
369  // case the input group interest is enough to force the update,
370  // so we return false.
371  virtual int hasTimeInterest() const;
372  virtual void handleTimeChange();
373 
374  // These two functions are provided for all the PI based operations
375  // that need to manage an undo block that begins in one function
376  // but ends in another function (or another instance of the same
377  // function).
378  //
379  // However, they can only handle ONE block at a time. No nesting
380  // of calls to beginDistributedUndo!
381  void beginDistributedUndoBlock(const char *operation,
382  UT_UndoBlockType blocktype);
383  void endDistributedUndoBlock();
384 
385  // Returns true if we have called beginDistributedUndoBlock but have
386  // not yet called endDistributedUndoBlock; returns false otherwise.
387  bool inDistributedUndoBlock();
388 
389  // This virtual callback is called whenever one of our attached
390  // or attached-for-keyframe nodes is changed.
391  virtual void handleOpChange(OP_Node *op,
392  OP_EventType etype,
393  void *data);
394 
395  // Subclasses may call these methods to customize how their settings
396  // are saved.
398  { myAllowUsingPerOpSettingsTable = onoff; }
400  { myAllowUsingLastSettingsTable = onoff; }
402  { myAllowUsingOpTypeSettings = onoff; }
404  { myAllowUsingLastVisibilitySetting = onoff; }
405 
406  // Some functions for getting and setting our owner operator information.
407  // The owner operator is the operator that defines what space our handles
408  // should appear in and what SOP/group field we should be interested in.
409  virtual void setOwnerOp(const char *owner_op);
410  const UT_String &getOwnerOp() const;
411  OP_Node *getOwnerOpRelativeTo(OP_Node *node) const;
412  virtual void setOwnerOpGroup(const char *owner_op_group);
413  const UT_String &getOwnerOpGroup() const;
414 
415  // Return the channel name for our first input group interest.
416  const UT_StringHolder &getFirstInputGroupInterestName() const;
417 
418  // This helper function returns true if the parm channel_name is locked and
419  // false otherwise. This function will follow any channel references that
420  // this parm might have to determine the "true" locked status.
421  static bool isOpParmLocked(
422  const char *channel_name, OP_Node &op, fpreal time,
423  const PRM_Parm **ret_parm = NULL,
424  const OP_Node **ret_node = NULL);
425 
426 private:
427  int linkOpParm(const char *op_type,
428  int pindex, const char *parmname);
429  void updateParmLockStatus( OP_Node &op );
430  UT_StringArray &opParmNames(const char *op_type);
431  void addParmNames(int opnum);
432  void removeParmNames(int opnum);
433 
434  void setKeysSingleOp(int opnum, int pindex = -1,
435  UT_String *names = NULL,
436  const char *name_prefix = NULL);
437  void removeKeysSingleOp(int opnum);
438  void deleteChannelsSingleOp(int opnum);
439  void lockParmsSingleOp(int opnum);
440  void revertToDefaultsSingleOp(int opnum);
441  void revertToFactoryDefaultsSingleOp(int opnum);
442  void overwriteDefaultsSingleOp(int opnum);
443 
444  // For a given pindex, add/remove interest's in the corresponding
445  // parameter's PRM_Value.
446  int addInputGroupInterest(int pindex,
447  PRM_ValueCallback callback,
448  int opnum);
449  int removeInputGroupInterest(int pindex,
450  PRM_ValueCallback callback,
451  int opnum);
452 
453  // Callback function to make sure we always know when one of our
454  // nodes is being deleted.
455  static void handleOpChangeCallback(OP_Node *op, void *callee,
456  OP_EventType etype, void *data);
457 
458  void clearOpTypeParmNamesMap();
459 
460  const PI_PITemplate &myTemplate;
461  // This symbol table has as it's index the optype name, and as it's
462  // contents the cached UT_StringArrays which would correspond to that
463  // op's ParmNames.
464  UT_SymbolMap<UT_StringArray *> myOpTypeParmNames;
465 
466  // This is a translation from our PI parm index into the opnum.
467  UT_IntArray myOpnumForParmIndex;
468 
469  // This is indexed by the opnum and has the string array of op parms
470  // that correspond to that opnum. The index on the string array is
471  // the index into our PI parms.
472  UT_ValArray<UT_StringArray *> myParmNames;
473  UT_ValArray<OP_Node *> myOpNodes;
474  UT_ValArray<OP_Node *> myKeyframeOpNodes;
475  UT_StringArray myInputGroupInterests;
476  int myId;
477  const PI_Interest *myInterests;
478  UT_String myRootDescription;
479  UT_String myDescription;
480  UT_String myOwnerOp;
481  UT_String myOwnerOpGroup;
482 
483  UT_Color myActiveColor;
484 
485  int myDistributedUndoBlockLevel;
486  bool myAllowUsingPerOpSettingsTable;
487  bool myAllowUsingLastSettingsTable;
488  bool myAllowUsingOpTypeSettings;
489  bool myAllowUsingLastVisibilitySetting;
490  bool myShowOpPath;
491 
492  bool myStealthMode;
493  bool myStealthVisibility;
494  OP_Node *myStealthNode;
495 
496  bool myIsTimeOverride;
497  fpreal myTimeOverrideTime;
498 };
499 
500 #endif
501 
CH_StringMeaning
const GLdouble * v
Definition: glcorearb.h:836
IMF_EXPORT IMATH_NAMESPACE::V3f direction(const IMATH_NAMESPACE::Box2i &dataWindow, const IMATH_NAMESPACE::V2f &pixelPosition)
GLboolean GLboolean GLboolean GLboolean a
Definition: glcorearb.h:1221
#define PI_API
Definition: PI_API.h:10
png_uint_32 i
Definition: png.h:2877
GLuint id
Definition: glcorearb.h:654
GLfloat f
Definition: glcorearb.h:1925
PRM_ChanState
Definition: PRM_ChanState.h:14
UT_UndoBlockType
GLboolean * data
Definition: glcorearb.h:130
GLboolean GLboolean GLboolean b
Definition: glcorearb.h:1221
void(* PRM_ValueCallback)(void *callee, void *value)
Definition: PRM_Value.h:22
double fpreal
Definition: SYS_Types.h:269
GLuint GLfloat * val
Definition: glcorearb.h:1607
OP_EventType
Definition: OP_Value.h:22