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