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