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