HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
PI_ResourceManager.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_ResourceManager.h ( Direct Manipulation Library, C++)
7  *
8  * COMMENTS:
9  * This class maintains a table of all states, handles, op-handle links,
10  * and input selectors. All state, handle, and op-handle link objects
11  * are created and deleted through a PI_ResourceManager. The active one
12  * is obtained via the global function BMgetResourceManager().
13  */
14 
15 #ifndef __PI_ResourceManager_H__
16 #define __PI_ResourceManager_H__
17 
18 #include "PI_API.h"
19 #include "PI_ResourceTemplate.h"
20 #include "PI_SettingList.h"
21 #include "PI_PythonState.h"
22 
23 #include <OP/OP_Error.h>
24 #include <OP/OP_OperatorTable.h>
25 #include <UT/UT_Array.h>
26 #include <UT/UT_Pair.h>
27 #include <UT/UT_String.h>
28 #include <UT/UT_StringMap.h>
29 #include <UT/UT_SymbolTable.h>
30 #include <UT/UT_ValArray.h>
31 #include <SYS/SYS_Hash.h>
32 
33 class CPP_Manager;
34 class PRM_Template;
35 class OP_Operator;
36 class OP_OperatorTable;
37 class OP_Node;
38 class CMD_Args;
39 class PI_OpHandleLink;
40 class pi_OpHandleBinding;
41 class pi_OpSelectorBinding;
42 
43 
44 /// Error codes retured by PI_ResourceManager bind methods
45 /// @{
46 #define PI_BIND_OK 1
47 #define PI_NO_TEMPLATE_FOR_HANDLE -2
48 #define PI_INVALID_OP_PARM -3
49 #define PI_INVALID_PI_PARM -4
50 #define PI_BINDING_EXISTS -5
51 #define PI_INVALID_OP_FOR_PI -6
52 /// @}
53 
54 typedef void (*PI_SaveCallback)(void *data);
55 
57 {
58 public:
60 
61  // Note this is the channel name: the receiver should do a
62  // PRM_ParmList::getParmPtrFromChannel to get the parm.
63  const UT_String &getOpParm() const
64  { return myOpParm; }
65  const UT_String &getPIParm() const
66  { return myPIParm; }
67  int operator==(const PI_BindingParmInfo &i) const
68  { return (this == &i); }
69 
70 private:
71  UT_String myOpParm;
72  UT_String myPIParm;
73  friend class pi_OpHandleBinding;
74 };
75 
80 
82 {
83 public:
85 
86  const UT_String &getPIName() const
87  { return myPIName; }
88  const UT_String &getPIDescription() const
89  { return myPIDescription; }
91  { return myDefaultSettings; }
92  int getId() const
93  { return myId; }
95  { return myBindings; }
96  int operator==(const PI_BindingHandleInfo &i) const
97  { return (this == &i); }
98 
99 private:
100  UT_String myPIName;
101  UT_String myPIDescription;
102  PI_SettingList myDefaultSettings;
103  int myId;
104  PI_BindingParmArray myBindings;
105  friend class pi_OpHandleBinding;
106 };
108 
109 // See the bindSelector function for a description of all the data
110 // members of this class. They map directly to the bindSelector parameters.
112 {
113 public:
115 
116  const UT_String &getName() const
117  { return myName; }
118  const UT_String &getDescription() const
119  { return myDescription; }
120  const UT_String &getPrompt() const
121  { return myPrompt; }
122  const UT_String &getOpParm() const
123  { return myOpParm; }
124  const UT_String &getMenu() const
125  { return myMenu; }
126  const UT_String &getPrimMask() const
127  { return myPrimMask; }
128  int getOpInput() const
129  { return myOpInput; }
130  bool getOpInputReq() const
131  { return myOpInputReq; }
132  bool getAllowDrag() const
133  { return myAllowDrag; }
134  bool getAstSelAll() const
135  { return myAstSelAll; }
136  const UT_String &getExtraInfo() const
137  { return myExtraInfo; }
139  { return (this == &i); }
140 
141 private:
142  UT_String myName;
143  UT_String myDescription;
144  UT_String myPrompt;
145  UT_String myOpParm;
146  UT_String myMenu;
147  UT_String myPrimMask;
148  int myOpInput;
149  bool myOpInputReq;
150  bool myAllowDrag;
151  bool myAstSelAll;
152  UT_String myExtraInfo;
153  friend class pi_OpSelectorBinding;
154 };
156 
159 {
160 public:
162  virtual ~PI_ResourceManager();
163 
164  // Return 1 on success and 0 if the state/handle/op-handle link
165  // is already registered.
166  virtual int registerState(PI_StateTemplate *type);
167  virtual int registerHandle(PI_HandleTemplate *type);
168  virtual int registerOpHandleLink(PI_PITemplate *type);
169  virtual int registerSelector(PI_SelectorTemplate *type);
170 
171  bool containsState(const char *name,
172  PI_ViewerType viewer_type,
173  unsigned netmask) const;
174  bool containsHandle(const char *name) const;
175  bool containsOpHandleLink(const char *name) const;
176  bool containsSelector(const char *name) const;
177 
178  // Get all the bound handles and parms for a given op type.
180  *getBindingHandles(OP_Operator *op) const;
181  // Get all the bound selectors for a given op type.
183  *getBindingSelectors(OP_Operator *op) const;
184 
185  // Return the list of states that can be used in a viewer for the
186  // specified network type.
188  &stateList(PI_ViewerType viewer_type,
189  const char *network_type) const;
191  &stateList(PI_ViewerType viewer_type,
192  PI_NetworkType net_type) const;
193  PI_StateTemplate *getStateTemplate(const char *name,
194  PI_ViewerType viewer_type,
195  const char *type) const;
196  PI_StateTemplate *getStateTemplate(OP_Operator *op,
197  PI_ViewerType viewer_type,
198  const char *type) const;
199 
200  // Return the registration status of a state template.
201  //
202  virtual PI_PythonState::RegisterStatus getViewerStateRegisterStatus(
203  const char *state_name,
204  PI_ViewerType viewer_type,
205  const char *type) const;
206 
207  // return true if the state name is valid
208  bool validStateTemplateName(const char* name) const;
209 
210  // These are functions which are called from commands that allow
211  // for dynamic binding of handles to parameters
212  int unbind(OP_Operator *op, const char *pidescription,
213  const UT_String &opparm);
214  int bind(OP_Operator *op, const char *piname,
215  const char *pidescription,
216  const UT_String &opparm,
217  const UT_String &piparm,
218  const char *default_settings);
219  // this API is typically used for handle late-binding e.g. python states
220  // would provide functions for binding handle parms
221  int bind(OP_Operator *op, const char *piname,
222  const char *pidescription,
223  const char *default_settings);
224  int bindScriptOp(OP_Operator *op, const char *piname,
225  const char *pidescription,
226  const UT_String &opparm,
227  const UT_String &piparm,
228  const char *default_settings);
229 
230  // Used for binding node operators to registered viewer states (i..e. python states)
231  // returns true if the operation succeeded
232  virtual bool bindOperatorToViewerState(const char* state_name, OP_Operator* op);
233 
234  /// Unbind the given selector from an operator. Uses the short description
235  /// when bound using bindSelector()
236  int unbindSelector(OP_Operator *op,
237  const char *seldescription);
238 
239  /// Dynamic binding of a selector to an operator
240  ///
241  /// @param op Operator type that we want to bind a selector to
242  /// @param sname Selector type
243  /// @param seldescription Short description that identifies this selector
244  /// in the context of a one operator (used to
245  /// unbind the selector).
246  /// @param prompt Text in the status area when the selector is
247  /// active.
248  /// @param opparm Operator parameter where the selection string
249  /// is put.
250  /// @param opinput Wire input index where the op owning the
251  /// selected geometry is attached to our op.
252  /// @param opinputreq Is an input is required?
253  /// @param primmask Mask of which primitive types can be in the
254  /// selection. This uses the *_FILEID enum in
255  /// GEO_PrimTypeCompat.h. A regular
256  /// GEO_PrimTypeCompat mask can be used if you
257  /// first convert it using
258  /// GEO_PrimTypeCompat::convertToFileFromMask()
259  /// @param allowdrag Determines if click-and-drag operations are
260  /// allowed.
261  /// @param menu Operator menu parameter where we choose the
262  /// selection type.
263  /// @param astselall If an asterisk is required in the selection
264  /// string to indicate selecting all the input.
265  /// Otherwise we assume an empty string indicates
266  /// that the whole geometry is selected.
267  /// @param extrainfo String that is passed to the selector,
268  /// particular selectors may need specific
269  /// parameters that can be passed through this
270  /// mechanism.
271  /// @param fromScriptOp Used by our dialog script parser to avoid
272  /// infinite recursion. Setting this flag decreases
273  /// the error checking we do.
274  ///
275  /// @return PI_BIND_OK upon success, else see of one of the other potential
276  /// error codes at the top of PI_ResourceManager.h
277  int bindSelector(OP_Operator *op, const char *sname,
278  const char *seldescription,
279  const char *prompt, const char *opparm,
280  int opinput, int opinputreq,
281  const char *primmask, int allowdrag,
282  const char *menu, int astselall,
283  const char *extrainfo, bool fromScriptOp);
284 
285  //Helper functions for the above
286  PRM_Template *getTemplateAndVecId(const UT_String &,
287  OP_Operator *,
288  int &) const;
289 
290  // This is for converting old style "t 2" into new style "tz". It
291  // only works if the operator has the template already, else it
292  // assumes channel name == parmname. Thus, it won't work on
293  // multiparms that only exist with OP_Node, not OP_Operator.
294  void getChannelNameFromParmAndVec(UT_String &chan,
295  OP_Operator *op, const char *parmname,
296  int vecidx);
297 
298  int checkForPIName( const char *pi_name,
299  const char *pi_parm ) const;
300 
301  OP_Operator *findOperator(PI_NetworkType net_type,
302  const char *op_name,
303  bool display_warning = true) const;
304  OP_Operator *findOperator(const char *opbindname,
305  UT_String *optype = 0) const;
306 
307  virtual void findVolatileKeys(const char *volatile_hotkey_name,
308  UT_Array<int> &volatile_keys,
309  UT_Array<int> &keys_modifiers)
310  const;
311  virtual void updateViewports(int id, const char *opname,
312  bool open_only = false) const;
313 
314  //These methods are used in PI_ResourceManagerCommand.C.
315  const PI_OpHandleLinkMap &getOpHandleLinks() const { return myOpHandleLinks; }
316  PI_PITemplate *getOpHandleLinkTemplate(const char *pi_name) const;
317  const PI_SelectorTemplateMap &getSelectors() const { return mySelectors; }
318  PI_SelectorTemplate *getSelectorTemplate(const char *selector_name) const;
319 
320  // The following method is used by builddialogs
321  const PI_HandleTemplateMap &getHandles() const { return myHandles; }
322 
323  // Tell us if the pi with the given name is an invisible PI by nature.
324  // Optionally return the type of the pi in isfloat (int or float assumed)
325  bool isPIEthereal(const char *piname,
326  bool *isfloat = 0) const;
327 
328  // Because the order of callbacks for OP_UpdateTableSink is
329  // undefined, some callbacks rely on the resource manager's table of states
330  // to be accurate. Since the resource manager's callback can happen
331  // after the other callbacks, they can call these methods to ensure the
332  // resource manager's table is accurate.
333  void ensureStatesExistForAllOperators(const char *net_type_name);
334  virtual void ensureStatesExistForAllOperators(PI_NetworkType net_type);
335 
336  // Map a viewer type token to a PI_ViewerType, or vice-versa.
337  static bool getViewerType(const char *viewer_type_token,
338  PI_ViewerType &type);
339  static void getViewerTypeToken(PI_ViewerType type,
340  UT_String &viewer_type_token);
341 
342  // Map the network name returned by OP_Node::getOpType() to a
343  // PI_NetworkType, or vice-versa.
344  static bool getNetworkType(const char *network_type_name,
345  PI_NetworkType &type);
346  static const UT_StringHolder &getNetworkTypeName(PI_NetworkType type);
347  static OP_OperatorTable *getOpTableFromOperator(const OP_Operator *op);
348 
349  // Choose the first network type from a mask that contains multiple ones.
350  static PI_NetworkType getFirstNetworkType(unsigned int network_mask);
351 
352  static PRM_Template *findParmTemplate(OP_Operator &op,
353  const char *op_Parm_name,
354  int vec_idx, int *parm_idx);
355 
356  // Write out our bindings information to a file.
357  int writeBindingsFile(const char *fname) const;
358 
359  // Load/save/remove the settings for a particular PI and a node that's
360  // linked to it.
361  void loadPISettingsFromTables(PI_OpHandleLink &pi,
362  bool okay_to_use_last_settings) const;
363  void savePISettingsToTables(PI_OpHandleLink &pi);
364  virtual void removePISettingsFromTables(OP_Operator &op_type);
365  void removePISettingsFromTables(const PI_OpHandleLink &pi);
366 
367  // Record settings for a particular PI. This method should only be
368  // called by the omparm command.
369  void recordPISettings(const char *pi_description,
370  const char *pi_type,
371  const OP_Node &op_node,
372  const char *settings);
373 
374  // Objects may add callbacks that are called just before the resource
375  // manager saves its data to the hip file. These callbacks update
376  // the resource manager to make sure the data it saves is current.
377  void addSaveCallback(PI_SaveCallback callback, void *data);
378  void removeSaveCallback(PI_SaveCallback callback,
379  void *data);
380 
381 protected:
382  static void startParmsCache();
383  static void stopParmsCache();
384  static void getParmsCache(UT_ValArray<OP_Node *> *&ops,
385  UT_ValArray<PRM_Parm *> *&parms,
386  UT_IntArray *&vec_indices);
387  static void getParmsCacheBehaviour( bool &set_keys,
388  bool &do_scope,
389  bool &append_scope );
390 public:
391  static int cacheParms();
392  static void appendToParmsCache(OP_Node *op, PRM_Parm *parm,
393  int vi);
394  static void setParmsCacheBehaviour( bool set_keys, bool do_scope,
395  bool append_scope );
396 
398  { return theHideLockedHandleParts; }
399  static void setHideLockedHandleParts( bool hide )
400  { theHideLockedHandleParts = hide; }
401  static bool getScopeChannelsOnKey()
402  { return theScopeChannelsOnKey; }
403  static void setScopeChannelsOnKey( bool scope )
404  { theScopeChannelsOnKey = scope; }
405  static bool getAddScopedChannels()
406  { return theAddScopedChannels; }
407  static void setAddScopedChannels( bool add )
408  { theAddScopedChannels = add; }
410  { return theOpenChannelEditorOnScope; }
411  static void setOpenChannelEditorOnScope( bool do_open )
412  { theOpenChannelEditorOnScope = do_open; }
413  static void getChannelScopeCommandPrefix( UT_String &str );
414 
415 
416 protected:
417  // Classes:
418 
420  {
421  public:
422  PI_OpPIKey(const char *pi_name_in_setting_table, const char *pi_type,
423  int op_id) :
424  myPINameInSettingTable(pi_name_in_setting_table),
425  myPIType(pi_type),
426  myOpId(op_id) {}
427 
428  bool operator==(const PI_OpPIKey &o) const
429  {
430  // myPIType is not used.
431  return myPINameInSettingTable == o.myPINameInSettingTable &&
432  myOpId == o.myOpId;
433  }
434 
436  {
437  // myPIType is not used.
438  SYS_HashType hash = myPINameInSettingTable.hash();
439  SYShashCombine(hash, myOpId);
440  return hash;
441  }
442 
443  UT_StringHolder piNameInSettingTable() const { return myPINameInSettingTable; }
444  UT_StringHolder piType() const { return myPIType; }
445  int opId() const { return myOpId; }
446 
447  struct Hasher
448  {
449  size_t operator()(const PI_OpPIKey &pk) const { return size_t(pk.hash()); }
450  };
451 
452  private:
453  UT_StringHolder myPINameInSettingTable;
454  UT_StringHolder myPIType;
455  int myOpId;
456  };
457 
458  // Methods:
459 
460  void installCommands();
461  void registerOpHandleLinks();
462  void registerCopHandleLinks();
463  void registerOpHandleBindings();
464  void registerOpHandleConstructors();
465  void registerSelectors();
466  void registerSelectorConstructors();
467 
468  // Functions used by registerOpHandleLinks for loading the OPbindings file.
469  bool isValidPiParmName( const UT_String &pi_name,
470  const UT_String &pi_parm);
471  void loadHandle(CPP_Manager &cppman, OP_Operator *op,
472  pi_OpHandleBinding *binding);
473  void loadSelector(CPP_Manager &cppman,
474  const UT_String &selname,
475  const UT_String &seldescription,
476  pi_OpSelectorBinding *binding);
477  void loadOperator(CPP_Manager &cppman,
478  const UT_String &oppath);
479  void loadOperator(CPP_Manager &cppman,
480  const UT_String &optype,
481  OP_Operator *op,
482  pi_OpHandleBinding *hbinding,
483  pi_OpSelectorBinding *sbinding);
484 
485  virtual void addAutomaticStates(PI_NetworkType net_type);
486  virtual void tableUpdated(OP_OperatorTable *table);
487  virtual void tableDeleted(OP_OperatorTable *table);
488  virtual void templatesUpdated(OP_Operator *op);
489  virtual void operatorDeleted(OP_Operator *op);
490  void ensureTableInterestExists(PI_NetworkType net_type,
491  OP_OperatorTable *table);
492 
493  PI_HandleTemplate *getHandleTemplate(const char *handle_name) const;
494 
495  // Save all the PI settings to a stream.
496  static OP_ERROR savePIResourceManagerCallback(std::ostream &os,
497  void *data);
498  OP_ERROR saveSettings(std::ostream &os) const;
499 
500  // We need the non-const version of getDefaultPISettings() because we
501  // might need to sort the default settings.
502  const PI_SettingList *getDefaultPISettings(OP_Operator &op_type,
503  const char *type_name,
504  const char *description) const;
505  PI_SettingList *getDefaultPISettings(OP_Operator &op_type,
506  const char *type_name,
507  const char *description);
508 
509 
510  // Data:
512 
517 
520 
523 
527 
529 
530  static bool ourSetKeyOnParms;
531  static bool ourScopeParmChannels;
532  static bool ourAppendToScope;
533  static int ourCacheParms;
537 
540  static bool theAddScopedChannels;
542 };
543 
545 PI_API extern void PIcreateResourceManager(bool verbose=true);
546 PI_API extern bool PIresourceManagerExists();
547 
548 #endif
int operator==(const PI_BindingSelectorInfo &i) const
int operator==(const PI_BindingHandleInfo &i) const
const UT_String & getPrompt() const
UT_StringHolder piNameInSettingTable() const
Unsorted map container.
Definition: UT_Map.h:83
const PI_OpHandleLinkMap & getOpHandleLinks() const
UT_Array< PI_SaveCallbackInfo > mySaveCallbacks
PI_HandleTemplateMap myHandles
static bool theOpenChannelEditorOnScope
const PI_SelectorTemplateMap & getSelectors() const
static UT_ValArray< OP_Node * > ourParmNodes
UT_SymbolMap< pi_OpHandleBinding * > myOpHandleBindings
PI_API void PIcreateResourceManager(bool verbose=true)
static void setScopeChannelsOnKey(bool scope)
PI_OpHandleLinkMap myOpHandleLinks
typedef void(APIENTRYP PFNGLCULLFACEPROC)(GLenum mode)
PI_NetworkType
static bool getAddScopedChannels()
PI_ViewerType
PI_OpPIKey(const char *pi_name_in_setting_table, const char *pi_type, int op_id)
std::size_t SYS_HashType
Define the type for hash values.
Definition: SYS_Hash.h:19
UT_ErrorSeverity
Definition: UT_Error.h:25
const PI_SettingList & getDefaultSettings() const
#define PI_API
Definition: PI_API.h:10
static void setOpenChannelEditorOnScope(bool do_open)
PI_API bool PIresourceManagerExists()
UT_StringHolder piType() const
png_uint_32 i
Definition: png.h:2877
void(* PI_SaveCallback)(void *data)
PI_SelectorTemplateMap mySelectors
const UT_String & getPIDescription() const
static bool theHideLockedHandleParts
bool operator==(const PI_OpPIKey &o) const
static bool theScopeChannelsOnKey
UT_SymbolMap< PI_NetworkType > myNetworkTypeTable
static UT_IntArray ourParmVecIndices
static bool ourScopeParmChannels
const UT_String & getOpParm() const
size_t operator()(const PI_OpPIKey &pk) const
static bool getHideLockedHandleParts()
const UT_String & getPrimMask() const
static bool getOpenChannelEditorOnScope()
static void setAddScopedChannels(bool add)
const UT_String & getExtraInfo() const
GLboolean * data
Definition: glcorearb.h:130
GLuint const GLchar * name
Definition: glcorearb.h:785
UT_Map< PI_OpPIKey, PI_SettingList *, PI_OpPIKey::Hasher > myPISettingsForOps
static bool getScopeChannelsOnKey()
PI_API PI_ResourceManager * PIgetResourceManager()
static void setHideLockedHandleParts(bool hide)
static bool theAddScopedChannels
const UT_String & getPIName() const
const PI_HandleTemplateMap & getHandles() const
const PI_BindingParmArray & getBindings() const
const UT_String & getMenu() const
static bool ourSetKeyOnParms
const UT_String & getDescription() const
GLint GLint GLsizei GLint GLenum GLenum type
Definition: glcorearb.h:107
UT_SymbolMap< pi_OpSelectorBinding * > myOpSelectorBindings
static UT_ValArray< PRM_Parm * > ourParms
int operator==(const PI_BindingParmInfo &i) const
static bool ourAppendToScope
const UT_String & getName() const
UT_StringMap< PI_SettingList * > myLastPISettings
const UT_String & getPIParm() const
const UT_String & getOpParm() const