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