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