HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
OP_Operator.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: OP_Operator.h (C++)
7  *
8  * COMMENTS:
9  * An OP_Operator instance defines an operator which is registered
10  * with an OP_Network and subsequently allows nodes of this type to
11  * be created in networks of the corresponding type. (This is the
12  * new equivalent of the old *_TableEntry class).
13  *
14  */
15 
16 #ifndef __OP_Operator_h__
17 #define __OP_Operator_h__
18 
19 #include "OP_API.h"
20 #include "OP_DataTypes.h"
21 #include "OP_OperatorPair.h"
22 #include "OP_OTLDefinition.h"
23 #include "OP_OTLLicenseType.h"
24 #include "OP_Value.h"
25 
26 #include <CH/CH_ExprLanguage.h>
27 
28 #include <VEX/VEX_RslTypes.h>
29 #include <VEX/VEX_VexTypes.h>
30 
31 #include <FS/FS_IndexFile.h>
32 
33 #include <UT/UT_Array.h>
34 #include <UT/UT_Color.h>
35 #include <UT/UT_DeepString.h>
36 #include <UT/UT_Defines.h>
37 #include <UT/UT_Lock.h>
38 #include <UT/UT_SharedPtr.h>
39 #include <UT/UT_StringArray.h>
40 #include <UT/UT_StringHolder.h>
41 #include <UT/UT_ValArray.h>
42 
43 #include <iosfwd>
44 
45 
46 // The VOPNET parameter name that defines the english name of
47 // the operator defined by that VOPNET and a flag that indicates
48 // whether the defined operator should be in the tab menu.
49 #define ENGLISH_NAME "englishname"
50 #define VOPNET_TAB_MENU_FLAG_NAME "tabmenuflag"
51 
52 class UT_FileUtil;
53 class UT_InfoTree;
54 class UT_IStream;
55 class UT_Options;
56 class UT_String;
57 template <typename ITEM_T> class UT_StringMap;
58 class UT_StringSet;
59 class UT_WorkBuffer;
61 class CH_LocalVariable;
62 class PRM_Default;
63 class PRM_Template;
64 class PRM_PresetInfo;
65 class PRM_ScriptImports;
66 class PRM_ScriptPage;
67 class DS_Stream;
68 class OP_ExtraInfoBuffer;
69 class OP_Network;
70 class OP_Node;
72 class OP_OperatorTable;
73 class OP_Operator;
74 class OP_OTLLibrary;
75 class OP_SpareParmCache;
76 class OP_SpareParms;
78 class OP_EventScriptPathCache;
79 
80 /// Flags passed to the contructor:
81 #define OP_FLAG_NETWORK 0x01
82 #define OP_FLAG_GENERATOR 0x02 /// Generates new data
83 #define OP_FLAG_UNORDERED 0x04 /// Unordered, variable inputs
84 #define OP_FLAG_SCRIPTDEF 0x08 /// Defined by a dialog script
85 #define OP_FLAG_MANAGER 0x10 /// This is a management node.
86 #define OP_FLAG_PRIMARYSUBNET 0x20 /// The primary "subnet" operator
87 #define OP_FLAG_OUTPUT 0x40 /// Output type. Only one per net
88 #define OP_FLAG_EDITABLE_INPUT_DATA 0x80 /// Enable editable input data
89 
90 // Maximum number of input labels that can be specified for non-HDAs:
91 #define OP_MAX_INPUT_LABELS 4
92 
93 // Default max value used for multi-inputs like Merge nodes
94 #define OP_MULTI_INPUT_MAX 9999
95 
96 // Maximum number of distinct indirect inputs shown until none are shown
97 // (all inputs are assumed to apply to the subnet).
98 #define OP_MAX_INDIRECT_INPUTS 500
99 
100 // Maximum number of outputs we allow for nodes that allow multiple outputs
101 #define OP_MULTI_OUTPUT_MAX 9999
102 
104 typedef OP_Node *(*OP_Constructor)(OP_Network *, const char *, OP_Operator *);
105 
106 // Event Script types
107 typedef enum {
112 
114 {
115 public:
117  virtual ~OP_SpecificData() { }
118 
119  virtual void saveToDialogScript(std::ostream &os) const = 0;
121 };
122 
124 {
125 public:
129 };
130 
132 {
133 public:
137 };
138 
140 {
141 public:
142  /// Note: The 'inputlabels' array is expected to be null-terminated.
143  OP_Operator(const char *name,
144  const char *english,
145  OP_Constructor construct,
146  PRM_Template *templates,
147  unsigned min_sources,
148  unsigned max_sources = 9999,
149  CH_LocalVariable *variables = 0,
150  unsigned flags = 0,
151  const char **inputlabels = 0,
152  int maxoutputs = 1,
153  const char *tab_submenu_path = 0);
154 
155  OP_Operator(const char *name,
156  const char *english,
157  OP_Constructor construct,
158  OP_TemplatePair *template_pair,
159  unsigned min_sources,
160  unsigned max_sources = 9999,
161  OP_VariablePair *variable_pair = 0,
162  unsigned flags = 0,
163  const char **inputlabels = 0,
164  int maxoutputs = 1,
165  const char *tab_submenu_path = 0);
166 
167  OP_Operator(const char *name,
168  const char *english,
169  OP_Constructor construct,
170  PRM_Template *templates,
171  const char *child_table_name,
172  unsigned min_sources,
173  unsigned max_sources = 9999,
174  CH_LocalVariable *variables = 0,
175  unsigned flags = 0,
176  const char **inputlabels = 0,
177  int maxoutputs = 1,
178  const char *tab_submenu_path = 0);
179 
180  OP_Operator(const char *name,
181  const char *english,
182  OP_Constructor construct,
183  OP_TemplatePair *template_pair,
184  const char *child_table_name,
185  unsigned min_sources,
186  unsigned max_sources = 9999,
187  OP_VariablePair *variable_pair = 0,
188  unsigned flags = 0,
189  const char **inputlabels = 0,
190  int maxoutputs = 1,
191  const char *tab_submenu_path = 0);
192 
193  virtual ~OP_Operator();
194 
195  OP_Node *constructNode(OP_Network *net, const char *name);
196  int getNumActiveNodes() const;
197  OP_Node *getActiveNode(int i) const;
198  void nodeDestroyed(OP_Node *node);
199 
200  // Because of sub-classing of this class, we require the ability to set
201  // "specific" data for different network types. For example, SHOPs are
202  // required to know the "rendermask" and "shader type" for each OP.
204  { return 0; }
205  virtual const OP_SpecificData *getOpSpecificData() const
206  { return 0; }
207 
208  const UT_StringHolder &getName() const
209  { return myOTLDefinition.getName(); }
210 
211  /// Get the op table name and the op name concatenated together to get a
212  /// unique name.
213  /// Returns full name with table, including namespace and version tags
214  /// if there are any, eg "artistA::table/op::2.0"
215  void getTableAndName(UT_WorkBuffer &name) const
216  { myOTLDefinition.getTableAndName(name); }
217  void getTableAndName(UT_String &name) const
218  { myOTLDefinition.getTableAndName(name); }
219 
221  { return myOTLDefinition.getLabel(); }
222  virtual UT_Color getDefaultColor() const;
223  virtual const UT_StringHolder &getDefaultShape() const;
224 
225  virtual bool getHDKHelp(UT_String & /*str*/) const
226  { return false; }
227 
228  virtual bool getOpHelpURL(UT_String &url);
229  virtual bool getOpTabSubMenuPath(UT_String &tab_submenu_path);
230  void setOpTabSubMenuPath(const char *tab_submenu_path);
231 
232  bool getOTLHelp(UT_String &str);
233  void getEditableSubNodes(UT_String &pattern);
234  void getMessageSubNodes(UT_String &pattern);
235  void getDiveTarget(UT_String &divetarget);
236  void getDescriptiveParmName(UT_String &descrparm);
237  void getDefaultState(UT_String &statename);
238  void getFunctionName(UT_String &function_name);
239  void getSecondaryFunctionsNames(
240  UT_StringMap<UT_StringHolder> &functions );
241 
242  void getComment(UT_String &comment);
243 
244  /// For HDAs, getVersion will return the version number defined by its HDA
245  /// definition, or the empty string if it does not exist. For non-HDA's
246  /// (ie. native or HDK node types), it will return the Houdini version
247  /// X.Y.Z.W string that we were compiled with. Subclasses may override this
248  /// to provide different numbering. One of the uses of this function to
249  /// determine if loading a node's parameters needs to be upgraded.
250  virtual bool getVersion(UT_String &version);
251 
252  void getHelpFileDirAndName(UT_String & script_dir,
253  UT_String & name);
254 
255  void getDefinitionSource(UT_String &defsource) const;
256 
258  { ourLastHelpOp = 0; }
259  OP_Node *getDefiningNetwork() const;
260 
261  // These functions are used by scripted ops.
262  // IndexPath is something like "subnet".
263  // IndexFile is something ike "SUBsop".
265  { return myOTLDefinition.getIndexPath(); }
267  { return myOTLDefinition.getIndexFile(); }
268  bool getScriptIsSubnet() const
269  { return myOTLDefinition.getIsSubnet(); }
270  bool getScriptIsVex() const
271  { return (myVexContextType != VEX_INVALID_CONTEXT); }
272  bool getScriptIsRsl() const
273  { return (myRslContextType != RSL_INVALID_CONTEXT); }
275  { return myVexContextType; }
277  { return myRslContextType; }
278  int getModTime() const
279  { return myOTLDefinition.getModTime(); }
280  bool getIsDummyDefinition() const
281  { return myOTLDefinition.getIsDummyDefinition(); }
282 
283  // Does this node type cook by running python code?
284  bool getScriptIsPython() const
285  { return myOTLDefinition.getIsPython(); }
286  void setScriptIsPython(bool is_python)
287  { myOTLDefinition.setIsPython(is_python); }
288 
289  // Returns the extra info string from our OTL definition
291  { return myOTLDefinition.getExtraInfo(); }
292 
293  // Get and set all our OTL Definition information.
294  void setOTLDefinition(const OP_OTLDefinition &definition);
296  { return myOTLDefinition; }
297 
298  // Get and set our OP_OTLLibrary.
300  { myOTLLibrary = library; }
302  { return myOTLLibrary; }
303 
304  virtual bool getSectionData(const UT_StringRef &name,
305  UT_StringHolder &value) const;
306  virtual bool hasSectionData(const UT_StringRef &name) const;
307 
308  bool hasContentsSection();
309 
310  // Get reference to our FS_IndexFile from myOTLLibrary.
311  FS_IndexFile *getOTLIndexFile(bool check_timestamp=true)
312  { return getOTLIndexFilePtr(check_timestamp).get(); }
313 
314  // Get underlying shared ptr of getOTLIndexFile().
315  // This not const because it updates myOTLIndexFile.
316  FS_IndexFileHandle getOTLIndexFilePtr(bool check_timestamp=true);
317 
318 
319  // Force the OTL-stored information for this operator to be cleared
320  // out and reloaded. We do this when the OTL has changed or we are
321  // changing the OTL that defines this operator.
322  virtual void clearOTLIndexFile();
323 
324  // Create a new FS_IndexFile that contains all the info we need about
325  // this operator. It is the responsibility of the caller to delete
326  // the return pointer.
327  FS_IndexFile *createDefaultOTLIndexFile() const;
328  FS_IndexFile *createOTLIndexFile(bool reservedsectionsonly,
329  UT_StringArray *externalfiles);
330 
331  /// Returns an official name of the library section that contains
332  /// the HDA definition eg "Object/hda".
333  void getDefinitionSectionName(UT_String &sectname) const;
334 
335  /// @{
336  /// Returns a path that refers to an index file section within
337  /// an OTL library or an HDA definition (depending on opdef_or_oplib prefix,
338  /// which should be either OTL_LIBRARY_PREFIX or OTL_DEFINITION_PREFIX).
339  /// The method version that takes a string array instead of a string
340  /// is intended for nested sections where the sections towards the end of
341  /// the array are innermost sections within sections earlier in the array
342  /// (that are themselves index files). For example, the path may be
343  /// "opdef:/Object/hda?section" or
344  /// "opdef:/artistA::Object/hda::2.0?section, or
345  /// "opdef:/Sop/hda?outer_section.idx?inner_section, etc
346  void constructIndexFileSectionPath(UT_String &path,
347  const char *opdef_or_oplib,
348  const char *section_name) const;
349  void constructIndexFileSectionPath(UT_String &path,
350  const char *opdef_or_oplib,
351  const UT_StringArray &section_names)
352  const;
353  /// @}
354 
355  /// List all operators found in the contents section
356  void listContainedOperators(UT_StringSet &contents_list);
357 
358  // The icon name is used to determine what the icon displayed is.
359  // Typically, this is the operator name preceded by the op type.
360  const char *getIconName() const;
361  void setIconName(const char *name);
362  void setDefaultIconName();
363 
364  unsigned minInputs() const
365  { return myOTLDefinition.getMinInputs(); }
366  unsigned maxInputs() const
367  { return myOTLDefinition.getMaxInputs(); }
368 
369  /// The number of ordered inputs on a node that remain separate even on
370  /// nodes that have a variable number of inputs. These separate inputs
371  /// always start at the beginning (variable input connectors are always
372  /// last).
373  /// @{
374  void setNumOrderedInputs(int inputs)
375  { myOTLDefinition.setNumOrderedInputs(inputs); }
376  int numOrderedInputs() const
377  { return myOTLDefinition.getNumOrderedInputs(); }
378  /// @}
379 
380  /// @{ Sets an array that maps an old input index to a new input name.
381  /// It is used for handling legacy H11 hip files, where nodes were saved
382  /// with indices only. If an operator definition is changed (ie, inputs
383  /// get inserted or reordered), it is necessary to provide this mapping,
384  /// to be able to load legacy hip files. If op definition does not change,
385  /// there is no need to define this mapping, since the default assignment
386  /// of input index will still work.
387  /// Also it is not needed for handling newer hip files that save the input
388  /// name information and can handle input order change in new op definition.
389  /// The map is given as a sequence of input names eg "name1 name2".
390  void setLegacyInputsMap(const char *map);
391  void getLegacyInputsMap(UT_String &map) const;
392  const UT_StringArray *getLegacyInputsIndexMap() const;
393  /// @}
394 
395  // Management operators can't have outputs. Otherwise the general
396  // procedure (except for VOPs) is one output.
397  virtual unsigned maxOutputs()
398  {
399  return isManagementOp()
400  ? 0
401  : myOTLDefinition.getMaxOutputs();
402  }
403 
404  OP_SpareParms *loadSpareParms(UT_IStream &is);
405 
406  virtual bool hasLoadedParmTemplates() const;
407  virtual int updateParmTemplates();
408 
409  // This function forces a reload of the operator's parm templates.
410  virtual void forceUpdateParmTemplates();
411 
412  /// Returns the operator's parameter templates with base parameters
413  /// appearing first (if they exist for script/HDA operators) followed by
414  /// non-base parameters.
415  ///
416  /// If getLayoutParmTemplates() returns nullptr, then getParmTemplates()
417  /// can be used for the parameter layout.
418  PRM_Template *getParmTemplates();
419  PRM_ScriptImports *getParmTemplateImports();
420 
421  /// Returns the operator's parameter templates in their final parameter
422  /// layout. This can return nullptr if the operator is not a script/HDA /
423  /// operator and if the operator's parameter layout is not overridden by a
424  /// custom dialog script.
425  PRM_Template *getLayoutParmTemplates();
426  PRM_ScriptImports *getLayoutParmTemplateImports();
427 
428  /// Exists only for script/HDA operators.
429  /// Returns the parm templates that are base to the HDA parameters.
430  virtual const PRM_Template *getBaseParmTemplates() { return myBase; }
431 
432  /// Returns the parm templates that are base to the final parameter layout
433  /// if the layout is overridden by a custom dialog script. Returns
434  /// nullptr if the parameter layout is not overridden.
436  { return myBaseOverrideLayout; }
437 
439  { return myObsoleteTemplates; }
441  { myObsoleteTemplates = tmpl; }
442 
443  /// Pass back the file path of the .ds file that was loaded
444  /// to override the operator's parameter templates. Return true if such a
445  /// file was found and loaded. Return false if no .ds override file was
446  /// found.
447  bool getOverrideLayoutParmTemplateFile(
448  UT_String &ds_path) const;
449 
450  CH_LocalVariable *getVariable(int i) const;
451  CH_LocalVariable *getVariable(const char *name) const;
452  CH_LocalVariable *getVariables() const { return myVariables; }
453  int getVariableCount() const { return myNvariables; }
454 
455  void resetVariables(OP_VariablePair *variable_pair);
456 
457  bool isNetwork() const
458  {
459  return (myFlags & OP_FLAG_NETWORK) != 0;
460  }
461  bool isGenerator() const
462  {
463  return (myFlags & OP_FLAG_GENERATOR) != 0;
464  }
465  bool isScriptedOp() const
466  {
467  return (myFlags & OP_FLAG_SCRIPTDEF) != 0;
468  }
469  bool isCustomDSO() const;
470  bool unorderedInputs() const
471  {
472  return (myFlags & OP_FLAG_UNORDERED) != 0;
473  }
474  bool isManagementOp() const
475  {
476  return (myFlags & OP_FLAG_MANAGER) != 0;
477  }
478  bool isOutputOp() const
479  {
480  return (myFlags & OP_FLAG_OUTPUT) != 0;
481  }
482  bool hasEditableInputData() const
483  {
484  return (myFlags&OP_FLAG_EDITABLE_INPUT_DATA) != 0;
485  }
486  /// Test to see if this is the primary "subnet" operator for the table.
487  /// This is the operator type which is used as a default container for
488  /// nodes. There should only be one of these defined.
490  {
491  return (myFlags & OP_FLAG_PRIMARYSUBNET) != 0;
492  }
493  bool isCreatingNode() const
494  {
495  return myCreatingNode;
496  }
498  {
499  return myChangingParmTemplates;
500  }
502  {
503  return myLoadingContentsSectionCount > 0;
504  }
506  {
507  myLoadingContentsSectionCount++;
508  }
510  {
511  myLoadingContentsSectionCount--;
512  }
513 
514 
515  /// Returns true if the operator should be preserved by op director,
516  /// when elimiating unused HDAs during a library refresh.
517  bool shouldPreserve() const
518  {
519  return getNumActiveNodes() > 0 || myRefreshingLib;
520  }
521 
523  OP_COMPARE_GEN_ENGLISH = 0, // Generators, then english
524  OP_COMPARE_GEN_NAME = 1, // Generators first, then name
525  OP_COMPARE_ENGLISH = 2, // By english solely
526  OP_COMPARE_NAME = 3 // By name solely
527  };
528 
529  // The method passed in is typically one of the enums. However,
530  // sub-classes of OP_Operator can add new comparison methods.
531  virtual int compareOperator(const OP_Operator *other,
532  int method) const;
533 
534  // Be very very carefull calling the change parm template functions...
535  void changeParmTemplate(PRM_Template *tp);
536 
537  /// @{ Accessing operator inputs name, label, and reference flag.
538  const UT_StringHolder &getInputName(int idx) const;
540  { return myInputNames; }
541  const UT_StringHolder &getInputLabel(int idx) const;
543  { return myInputLabels; }
544  bool getInputIsReference(int idx) const;
546  { return myInputReferences; }
547  virtual bool allowsInputNameEditing() const;
548  /// @}
549  /// @{ Accessing operator outputs label.
550  const UT_StringHolder &getOutputLabel(int idx) const;
552  { return myOutputLabels; }
553  /// @}
554 
555  unsigned getPermissionMask() const;
556 
557  // When our parm template changes, refresh all persistent handles to
558  // make sure they aren't attached to a non-existant parameter.
559  virtual void getRefreshPICommands(OP_Node *, std::ostream &) { }
560 
561  // This virtual function determines if we want animatable parameters.
562  // Used when creating parameters from a dialog script.
563  virtual bool wantsParametersAnimatable() const;
564  // This function determines if we want an input editor gadget in our
565  // parameter dialog if we have more than 4 inputs.
566  virtual bool wantsInputEditor() const;
567  // This function determines if we want the VOPNET parameter order
568  // editor in our parameter dialog. Obviously defaults to false.
569  virtual bool wantsParmOrderEditor() const;
570  // This function determines if we want the VOP subnet output name
571  // editor in our parameter dialog. Obviously defaults to false.
572  virtual bool wantsOutputNameEditor() const;
573  // Returns true if the network inside a node should have indirect inputs
574  // corresponding to that parent node's input connectors.
575  virtual bool wantsParentInputs() const;
576  // Returns a structure describing how the input data editor in the parm
577  // dialog should be configured.
579  { return myInputDataEditorConfig; }
581  const OP_InputDataEditorConfigEx &config)
582  { myInputDataEditorConfig = config; }
583  void setInputDataEditorConfig(
584  const OP_InputDataEditorConfig &config);
585 
586  // Appends a short help string to the provided buffer. Generally,
587  // This help string will be hard-coded.
588  virtual const char *getOperatorShortHelpString();
589 
590  // Get Info Text that is specific to this operator type. All
591  // implementations should call their base class version.
592  // Text should be appended to the provided buffer.
593  virtual void getOperatorSpecificInfoText(int verbose,
594  UT_WorkBuffer &text);
595 
596  /// Fill in 'tree' with details that are common to all operator types. Then
597  /// call fillInfoTreeOperatorSpecific() to get specific details about this
598  /// specific operator
599  void fillInfoTree(UT_InfoTree &tree,
600  const OP_NodeInfoTreeParms &parms);
601 
602  /// Triggered by 'fillInfoTree()', this virtual function adds all operator-
603  /// specific info to 'tree'. All child classes must create their own
604  /// branches under 'tree' to place their info
605  virtual void fillInfoTreeOperatorSpecific(UT_InfoTree &tree,
606  const OP_NodeInfoTreeParms &parms);
607 
608  // Load operators from .optype files...
609  static int loadFromOpType(const char *fname, const char *savedir);
610  static int uninstallOpType(const char *path,
611  const char *tablename, const char *opname,
612  const char *indexpath, const char *indexfile);
613  // Remove override files, wherever they might be hiding...
614  static void removeHelpCardOverrides(UT_FileUtil *fu,
615  const char *path, const char *tablename,
616  const char *opname, int flags);
617  static void removeRenameOverrides(UT_FileUtil *fu,
618  const char *path, const char *tablename,
619  const char *opname, int flags);
620  static void removeIconOverrides(UT_FileUtil *fu,
621  const char *path, const char *tablename,
622  const char *opname, int flags);
623  static void removeCmdOverrides(UT_FileUtil *fu,
624  const char *path, const char *tablename,
625  const char *opname, int flags);
626  // Constructs the default icon name for a given op and op table.
627  static void getDefaultIconName(const char *tablename,
628  const char *opname,
629  UT_String &iconname);
630 
631  // This returns a pointer to the table name.
632  // This is one of the *_TABLE_NAME defined in OP_Operator, from
633  // which any other prefix can be calculated.
634  const char *getTableName() const;
635 
636  // This returns a pointer to our actual operator table.
637  OP_OperatorTable *getTable() const;
638 
639  // Get the table name where this operator's children will go
640  const UT_StringHolder &getChildTableName() const;
641  OP_OperatorTable *getChildOperatorTable() const;
642 
643  // Query the license type associated with this operator.
644  OP_OTLLicenseType getLicense();
645 
646  // Sets the file where this operator is defined.
647  // If the definition starts with "op:", we alert the operator
648  // referred to by the rest of the path that we are now attached
649  // to it.
650  void setDefinition(const char *def);
651  // Change the English name of the operator.
652  void setEnglish(const char *english);
653 
654  // the tab menu flag changed, so inform the sinks of template update
655  // so that they can adjust their information about this op.
656  void informOfTabMenuFlagChange();
657 
658  // Change the name of this operator. We have to remove and re-add
659  // ourselves to the operator table to update our data properly.
660  virtual void setName(const char *name);
661 
662  // Set the minimum and maximum number of sources. Overrides the
663  // values that were passed into the constructor. These functions
664  // should only be called when reloading the parm template, so
665  // that changeParmTemplate will get called on OPs of this type.
666  // changeParmTemplate now deals with chaning numbers of inputs
667  // and outputs.
668  //
669  // If you want to set both, you should call setMin first as setMax
670  // will verify min <= max and decrease min if required.
671  void setMinInputs(int inputs);
672  void setMaxInputs(int inputs);
673  void setIsGenerator(bool isgen);
674 
675  // Functions to dirty and get the preset info for this operator.
676  // The get function creates the preset info if required.
677  void updatePresetInfo();
678  PRM_PresetInfo *getPresetInfo();
679 
680  /// Returns a file name corresponding to the operator name.
681  /// In most cases, the file name is the same as the operator name, but
682  /// since it has to be acceptable by all file systems, some invalid
683  /// characters may be converted to dashes
684  /// (eg, the namespace semicolons which cause problems on Windows).
685  /// @{
686  void getOpBasedFileName(UT_String &filename);
687  void getOpBasedFileName(UT_WorkBuffer &filename);
688  /// @}
689 
690  // This function runs one of the embedded scripts. It returns
691  // true if the script was found, even if it was empty. The
692  // nodedeletedbyscript parameter lets the caller know if the node
693  // passed in as nodearg was deleted while running the script.
694  bool runEventScript(
695  const char *event,
696  OP_Node *node_arg = nullptr,
697  bool full_path = false,
698  UT_Options *extra_args = nullptr,
699  bool *node_deleted_by_script = nullptr);
700 
701  // Digital assets can have a pair of Python dictionaries that store
702  // the contents of the asset's Python "module". For non-DA's, these
703  // dictionaries are empty.
705  { return myPythonModuleDicts; }
707  { return myHasLoadedPythonModuleSection; }
708  void loadPythonModuleSection(bool force=false);
709 
711  { return myViewerStateModuleDicts; }
713  { return myHasLoadedViewerStateModuleSection; }
714  void loadViewerStateModuleSection(bool force=false);
715 
717  { return myViewerHandleModuleDicts; }
719  { return myHasLoadedViewerHandleModuleSection; }
720  void loadViewerHandleModuleSection(bool force=false);
721 
722  // Clear all paths to event scripts cached for this operator.
723  void clearEventScriptPathCache();
724 
725  // Query all cached event script paths.
726  void getCachedEventScriptPaths(
727  UT_StringArray &events,
729  bool only_nonempty) const;
730 
731  /// Is this operator type thread-safe for cooking? OP_Node::cook() calls
732  /// this to determine if serialization is needed.
733  /// DEFAULT: false
734  bool isThreadSafe() const
735  { return myIsThreadSafe; }
736 
737  /// This function is used to specify whether a particular operator type
738  /// can be cooked in a multi-threaded manner.
739  void setIsThreadSafe(bool is_safe)
740  { myIsThreadSafe = is_safe; }
741 
742  static const char *getCurrentPythonModuleKey();
743  static const OP_Operator *mapSecurityKeyToOperator(const char *key);
744  static void registerPythonModuleKeyClient(void *client);
745  static bool verifyPythonModuleKeyClient(
746  const OP_Operator *op, void *client);
747 
748  static PRM_Template *getEmptyTemplateList();
749 
750  /// Returns true if this operator comes from a compiled OTL,
751  /// false otherwise.
752  bool isCompiled();
753 
754  /// Returns true if this operator is black boxed, and false otherwise.
755  bool isBlackBoxed();
756 
757  static int operatorNameCompare(const OP_Operator *a, const OP_Operator *b)
758  {
759  return (a ? (b ? (a->getName() < b->getName())
760  : false)
761  : true);
762  }
763 
764 protected:
765  // This function should be called from updateParmTemplates whenever
766  // that function would return a 1. Also called by setName and setEnglish.
767  void notifyUpdateTemplatesSinksOfUpdate();
768  // Called when the operator is deleted.
769  void notifyUpdateTemplatesSinksOfDelete();
770 
771  // Notify active nodes that the parameter templates have changed.
772  void notifyActiveNodesOfTemplatesUpdate();
773 
774  // For script operators - we need to make these methods protected.
775  static PRM_Template *addTemplates(OP_TemplatePair *);
776  static CH_LocalVariable *addVariables(OP_VariablePair *, int &);
777 
778  // This is currently only used temporarily to transfer from
779  // a DS file to a HDA.
781  { myDescriptiveParmName = parm; }
782 
783  void dirtyParmTemplatesLoaded();
784 
785  virtual bool loadParmTemplatesSubclass();
786 
787  /// Load parameter templates from the specified file stream.
788  bool loadAndCreateLayoutParmTemplates(
789  PRM_ScriptPage *page,
790  DS_Stream &ds_is,
791  PRM_Template *&base_tplates,
792  PRM_Template *&layout_tplates,
793  PRM_ScriptImports *&imports,
794  PRM_Template *&tplates,
795  int base_controls_switcher_index,
796  int base_controls_insert_index,
797  int base_controls_switcher_page_num,
798  PRM_Default *&base_controls_switcher_defaults,
799  bool hide_default_parms);
800 
817 
822  unsigned myFlags;
824 
825  // The script page used for storing the parsed override parameters
826  // if they exist. Though this class is the only owner of the page object
827  // we use a shared pointer as a way of controlling when the object
828  // actually gets deleted. For example, some methods will create a local
829  // shared pointer to the same object as a way of keeping it alive for the
830  // method scope.
832 
833 private:
834  unsigned operator<(const OP_Operator &);
835  void uniqueName(OP_Network *);
836  void addUpdateTemplatesSink(OP_UpdateTemplatesSink *);
837  void removeUpdateTemplatesSink(OP_UpdateTemplatesSink *);
838 
839  void getContentSectionTypeNames(UT_IStream &is,
840  UT_StringSet &contents_list) const;
841 
842  // When the VOPNET that defines us chages, we want to know about it...
843  static void handleDefiningNetworkChange(OP_Node *caller,
844  void *callee,
846  void *data);
847 
848  CH_ScriptLanguage eventScriptLanguage(
849  FS_IndexFile &def_file, const char *event);
850  bool runEventScript(
851  const char *event,
852  OP_Node *node_arg,
853  bool full_path,
854  UT_Options *extra_args,
855  bool &node_deleted_by_script,
856  OP_EventScriptType eventtype);
857  void runHscriptEventScript(
858  const char *script,
859  const char *script_path,
860  OP_Node *node,
861  bool full_path,
862  const char *extra_args);
863  void runPythonEventScript(
864  const char *script,
865  const char *script_path,
866  PY_EvaluationContext &evaluation_context,
867  const char *kwargs_dict,
868  OP_Node *node,
869  const char *script_source);
870 
871  void formatErrorSource(
872  UT_WorkBuffer &error_source,
873  OP_Node *node,
874  const UT_StringRef &script_source);
875 
876  // Get the script path cache for this operator, allocating it if
877  // necessary.
878  OP_EventScriptPathCache *getEventScriptPathCache();
879 
880  /// Attempt to load the custom override parameter layout
881  /// if it exists on disk.
882  void loadOverrideLayoutParmTemplates();
883 
884  void ensureParmTemplatesLoaded();
885 
886  OP_Constructor myConstructor;
887 
888  OP_NodeList myActiveNodes;
889 
890  OP_OTLLibrary *myOTLLibrary;
891  FS_IndexFileHandle myOTLIndexFile;
892  OP_OperatorTable *myOperatorTable;
893  OP_Node *myDefiningNetwork;
894  PRM_PresetInfo *myPresetInfo;
895  OP_SpareParmCache *mySpareParmCache;
896  OP_EventScriptPathCache *myEventScriptPathCache;
897  bool myCreatingNode;
898  bool myChangingParmTemplates;
899  bool myRefreshingLib;
900  bool myDestroyingSelf;
901  int myLoadingContentsSectionCount;
902 
903  UT_ValArray<OP_UpdateTemplatesSink *> myUpdateTemplatesSinks;
904 
905  PY_EvaluationContext *myPythonModuleDicts;
906  bool myHasLoadedPythonModuleSection;
907 
908  PY_EvaluationContext *myViewerStateModuleDicts;
909  bool myHasLoadedViewerStateModuleSection;
910 
911  PY_EvaluationContext *myViewerHandleModuleDicts;
912  bool myHasLoadedViewerHandleModuleSection;
913 
914  bool myIsThreadSafe;
915  int myIsCompiled;
916 
917  UT_StringArray myLegacyInputs;
918 
919  // We cannot assign descriptive parms when parsing dialog scripts
920  // as they are stored in .otl sections, but we need to hold onto
921  // it until buildotl finishes...
922  UT_StringHolder myDescriptiveParmName;
923 
924  friend class OP_OperatorTable;
925  friend class SHOP_ScriptOperator;
927 
928  static const OP_Operator *ourLastHelpOp;
929  static int ourLastHelpLevel;
930  static UT_String ourHelp;
931  static bool ourHelpIsHtml;
932 };
933 
935 {
936 public:
939  { removeAllTemplatesSinks(); }
940 
941  virtual void templatesUpdated(OP_Operator *op) = 0;
942  virtual void operatorDeleted(OP_Operator *op)
943  { removeUpdateTemplatesSink(op); }
944 
945 protected:
947  {
948  if( !op ) return;
949  op->addUpdateTemplatesSink(this);
950  myOperators.append(op, 1);
951  }
953  {
954  return myOperators.find(op) >= 0;
955  }
957  {
958  if( !op ) return;
959  op->removeUpdateTemplatesSink(this);
960  myOperators.findAndRemove(op);
961  }
963  {
964  for( int i = myOperators.entries(); i --> 0; )
965  removeUpdateTemplatesSink(myOperators(i));
966  }
967 
968 private:
969  OP_OperatorList myOperators;
970 };
971 
972 #endif
unsigned maxInputs() const
Definition: OP_Operator.h:366
virtual ~OP_SpecificData()
Definition: OP_Operator.h:117
GLboolean GLboolean GLboolean b
Definition: glcorearb.h:1221
unsigned minInputs() const
Definition: OP_Operator.h:364
PRM_ScriptImports * myLayoutParmImports
Definition: OP_Operator.h:804
int getVersion(int version)
Definition: ImfVersion.h:116
GT_API const UT_StringHolder filename
UT_StringArray myDataKeys
Definition: OP_Operator.h:134
virtual ~OP_UpdateTemplatesSink()
Definition: OP_Operator.h:938
bool getScriptIsSubnet() const
Definition: OP_Operator.h:268
UT_StringArray myInputLabels
Definition: OP_Operator.h:810
const OP_OTLDefinition & getOTLDefinition() const
Definition: OP_Operator.h:295
void setIsThreadSafe(bool is_safe)
Definition: OP_Operator.h:739
void getTableAndName(UT_String &name) const
Definition: OP_Operator.h:217
bool shouldPreserve() const
Definition: OP_Operator.h:517
int myNvariables
Definition: OP_Operator.h:815
static void clearOperatorHelpCache()
Definition: OP_Operator.h:257
CH_LocalVariable * myVariables
Definition: OP_Operator.h:814
bool getScriptIsRsl() const
Definition: OP_Operator.h:272
PRM_Template * myBaseOverrideLayout
Definition: OP_Operator.h:805
GLsizei const GLchar *const * path
Definition: glcorearb.h:3340
#define OP_FLAG_NETWORK
Flags passed to the contructor:
Definition: OP_Operator.h:81
const UT_StringHolder & getExtraInfo() const
Definition: OP_Operator.h:290
#define OP_FLAG_OUTPUT
Definition: OP_Operator.h:87
VEX_ContextType getVexContextType() const
Definition: OP_Operator.h:274
int getVariableCount() const
Definition: OP_Operator.h:453
OP_OTLDefinition myOTLDefinition
Definition: OP_Operator.h:818
virtual void getRefreshPICommands(OP_Node *, std::ostream &)
Definition: OP_Operator.h:559
bool isManagementOp() const
Definition: OP_Operator.h:474
#define OP_FLAG_GENERATOR
Definition: OP_Operator.h:82
void removeUpdateTemplatesSink(OP_Operator *op)
Definition: OP_Operator.h:956
GLuint const GLchar * name
Definition: glcorearb.h:785
void setNumOrderedInputs(int inputs)
Definition: OP_Operator.h:374
PY_EvaluationContext * getViewerHandleModuleDicts()
Definition: OP_Operator.h:716
UT_StringArray myInputNames
Definition: OP_Operator.h:809
UT_StringHolder myChildTableName
Definition: OP_Operator.h:816
#define OP_FLAG_PRIMARYSUBNET
Definition: OP_Operator.h:86
const UT_StringArray & getOutputLabels() const
Definition: OP_Operator.h:551
bool hasLoadedViewerStateModuleSection() const
Definition: OP_Operator.h:712
UT_Array< bool > myInputReferences
Definition: OP_Operator.h:813
const UT_StringHolder & getName() const
Definition: OP_Operator.h:208
struct _cl_event * event
Definition: glcorearb.h:2960
virtual void updateExtraInfoBuffer(OP_ExtraInfoBuffer &b) const
Definition: OP_Operator.h:120
bool myHasContentsSection
Definition: OP_Operator.h:823
bool isScriptedOp() const
Definition: OP_Operator.h:465
virtual bool getHDKHelp(UT_String &) const
Definition: OP_Operator.h:225
const UT_StringHolder & getIndexFile() const
Definition: OP_Operator.h:266
GLint GLint GLsizei GLint GLenum GLenum type
Definition: glcorearb.h:107
FS_IndexFile * getOTLIndexFile(bool check_timestamp=true)
Definition: OP_Operator.h:311
#define OP_FLAG_SCRIPTDEF
Definition: OP_Operator.h:84
virtual const OP_SpecificData * getOpSpecificData() const
Definition: OP_Operator.h:205
static int operatorNameCompare(const OP_Operator *a, const OP_Operator *b)
Definition: OP_Operator.h:757
std::shared_ptr< T > UT_SharedPtr
Wrapper around std::shared_ptr.
Definition: UT_SharedPtr.h:30
bool getIsPrimarySubnetType() const
Definition: OP_Operator.h:489
OP_EventScriptType
Definition: OP_Operator.h:107
bool isCreatingNode() const
Definition: OP_Operator.h:493
bool hasLoadedViewerHandleModuleSection() const
Definition: OP_Operator.h:718
UT_StringArray myDataDefaults
Definition: OP_Operator.h:136
int numOrderedInputs() const
Definition: OP_Operator.h:376
GLboolean GLboolean GLboolean GLboolean a
Definition: glcorearb.h:1221
void setInputDataEditorConfigEx(const OP_InputDataEditorConfigEx &config)
Definition: OP_Operator.h:580
UT_DeepString myTabSubmenuPath
Definition: OP_Operator.h:812
bool isOutputOp() const
Definition: OP_Operator.h:478
PRM_Template * myLayoutParmTemplates
Definition: OP_Operator.h:803
bool hasLoadedPythonModuleSection() const
Definition: OP_Operator.h:706
bool isChangingParmTemplates() const
Definition: OP_Operator.h:497
bool operator<(const GU_TetrahedronFacet &a, const GU_TetrahedronFacet &b)
PY_EvaluationContext * getViewerStateModuleDicts()
Definition: OP_Operator.h:710
void setScriptIsPython(bool is_python)
Definition: OP_Operator.h:286
UT_StringArray myOutputLabels
Definition: OP_Operator.h:811
bool isThreadSafe() const
Definition: OP_Operator.h:734
const UT_StringArray & getInputLabels() const
Accessing operator inputs name, label, and reference flag.
Definition: OP_Operator.h:542
GLbitfield flags
Definition: glcorearb.h:1595
RSL_ContextType getRslContextType() const
Definition: OP_Operator.h:276
void setDescriptiveParmName(const UT_StringHolder &parm)
Definition: OP_Operator.h:780
void setObsoleteTemplates(PRM_Template *tmpl)
Definition: OP_Operator.h:440
PRM_Template * getBaseOverrideLayoutParmTemplates()
Definition: OP_Operator.h:435
void beginLoadingContentsSectionForNode()
Definition: OP_Operator.h:505
OP_Node *(* OP_Constructor)(OP_Network *, const char *, OP_Operator *)
Definition: OP_Operator.h:104
#define OP_FLAG_MANAGER
Definition: OP_Operator.h:85
GT_API const UT_StringHolder version
PRM_Template * myObsoleteTemplates
Definition: OP_Operator.h:808
GLubyte * pattern
Definition: glew.h:5741
GLboolean * data
Definition: glcorearb.h:130
A map of string to various well defined value types.
Definition: UT_Options.h:84
void getTableAndName(UT_WorkBuffer &name) const
Definition: OP_Operator.h:215
const UT_StringArray & getInputNames() const
Accessing operator inputs name, label, and reference flag.
Definition: OP_Operator.h:539
Parameters for OP_Node::fillInfoTree()/OP_Node::fillInfoTreeNodeSpecific()
UT_ValArray< OP_Operator * > OP_OperatorList
Definition: OP_Operator.h:103
UT_StringArray myDataHeaders
Definition: OP_Operator.h:135
virtual unsigned maxOutputs()
Definition: OP_Operator.h:397
PRM_Template * myBase
Definition: OP_Operator.h:806
UT_StringHolder myDataKey
Definition: OP_Operator.h:126
bool hasTemplatesSink(OP_Operator *op)
Definition: OP_Operator.h:952
#define OP_FLAG_UNORDERED
Definition: OP_Operator.h:83
PRM_Template * myParmTemplates
Definition: OP_Operator.h:801
void endLoadingContentsSectionForNode()
Definition: OP_Operator.h:509
#define OP_API
Definition: OP_API.h:10
OP_OTLLicenseType
bool isGenerator() const
Definition: OP_Operator.h:461
VEX_ContextType myVexContextType
Definition: OP_Operator.h:820
OP_EventType
Definition: OP_Value.h:22
OP_OTLLibrary * getOTLLibrary()
Definition: OP_Operator.h:301
CH_LocalVariable * getVariables() const
Definition: OP_Operator.h:452
GLsizei const GLfloat * value
Definition: glcorearb.h:823
virtual OP_SpecificData * getOpSpecificData()
Definition: OP_Operator.h:203
const UT_StringHolder & getIndexPath() const
Definition: OP_Operator.h:264
unsigned myFlags
Definition: OP_Operator.h:822
bool getScriptIsVex() const
Definition: OP_Operator.h:270
bool isNetwork() const
Definition: OP_Operator.h:457
RSL_ContextType
RenderMan shader context types.
Definition: VEX_RslTypes.h:25
#define OP_FLAG_EDITABLE_INPUT_DATA
Definition: OP_Operator.h:88
bool myParmTemplatesLoaded
Definition: OP_Operator.h:807
UT_SharedPtr< PRM_ScriptPage > myOverrideLayoutParmScriptPage
Definition: OP_Operator.h:831
bool getIsDummyDefinition() const
Definition: OP_Operator.h:280
virtual void operatorDeleted(OP_Operator *op)
Definition: OP_Operator.h:942
VEX_ContextType
Definition: VEX_VexTypes.h:60
const UT_Array< bool > & getInputAreReferences() const
Accessing operator inputs name, label, and reference flag.
Definition: OP_Operator.h:545
PRM_ScriptImports * myImports
Definition: OP_Operator.h:802
virtual PRM_Template * getObsoleteTemplates()
Definition: OP_Operator.h:438
UT_StringHolder myDataDefault
Definition: OP_Operator.h:128
const OP_InputDataEditorConfigEx & getInputDataEditorConfigEx() const
Definition: OP_Operator.h:578
PY_EvaluationContext * getPythonModuleDicts()
Definition: OP_Operator.h:704
virtual const PRM_Template * getBaseParmTemplates()
Definition: OP_Operator.h:430
int getModTime() const
Definition: OP_Operator.h:278
void addUpdateTemplatesSink(OP_Operator *op)
Definition: OP_Operator.h:946
bool getScriptIsPython() const
Definition: OP_Operator.h:284
UT_StringHolder myDataHeader
Definition: OP_Operator.h:127
const UT_StringHolder & getEnglish() const
Definition: OP_Operator.h:220
OP_InputDataEditorConfigEx myInputDataEditorConfig
Definition: OP_Operator.h:819
RSL_ContextType myRslContextType
Definition: OP_Operator.h:821
CH_ScriptLanguage
bool hasNodeLoadingContentsSection() const
Definition: OP_Operator.h:501
GLenum const void * paths
Definition: glew.h:13872
bool unorderedInputs() const
Definition: OP_Operator.h:470
void setOTLLibrary(OP_OTLLibrary *library)
Definition: OP_Operator.h:299
bool hasEditableInputData() const
Definition: OP_Operator.h:482