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 <UT/UT_String.h>
21 #include <UT/UT_DeepString.h>
22 #include <UT/UT_SharedPtr.h>
23 #include <UT/UT_ValArray.h>
24 #include <UT/UT_StringArray.h>
25 #include <FS/FS_IndexFile.h>
26 #include <VEX/VEX_VexTypes.h>
27 #include <VEX/VEX_RslTypes.h>
28 #include <PRM/DS_Stream.h>
29 #include <PRM/PRM_ScriptPage.h>
30 #include <iosfwd>
31 #include "OP_OTLDefinition.h"
32 #include "OP_OTLLicenseType.h"
33 #include "OP_Value.h"
34 #include "OP_Node.h"
35 
36 // The VOPNET parameter name that defines the english name of
37 // the operator defined by that VOPNET and a flag that indicates
38 // whether the defined operator should be in the tab menu.
39 #define ENGLISH_NAME "englishname"
40 #define VOPNET_TAB_MENU_FLAG_NAME "tabmenuflag"
41 
42 class UT_FileUtil;
43 class UT_StringArray;
44 class UT_InfoTree;
45 class UT_WorkBuffer;
46 class UT_Options;
48 class PY_CompiledCode;
49 class FS_IndexFile;
50 class CH_LocalVariable;
51 class PRM_Template;
52 class PRM_SimpleParm;
53 class PRM_PresetInfo;
54 class PRM_ScriptImports;
55 class OP_ExtraInfoBuffer;
56 class OP_Network;
57 class OP_Node;
58 class OP_OperatorTable;
59 class OP_Operator;
60 class OP_OTLLibrary;
61 class OP_SpareParmCache;
62 class OP_SpareParms;
64 class OP_EventScriptPathCache;
65 
66 /// Flags passed to the contructor:
67 #define OP_FLAG_NETWORK 0x01
68 #define OP_FLAG_GENERATOR 0x02 /// Generates new data
69 #define OP_FLAG_UNORDERED 0x04 /// Unordered, variable inputs
70 #define OP_FLAG_SCRIPTDEF 0x08 /// Defined by a dialog script
71 #define OP_FLAG_MANAGER 0x10 /// This is a management node.
72 #define OP_FLAG_PRIMARYSUBNET 0x20 /// The primary "subnet" operator
73 #define OP_FLAG_OUTPUT 0x40 /// Output type. Only one per net
74 #define OP_FLAG_EDITABLE_INPUT_DATA 0x80 /// Enable editable input data
75 
76 // Maximum number of input labels that can be specified for non-HDAs:
77 #define OP_MAX_INPUT_LABELS 4
78 
79 // Default max value used for multi-inputs like Merge nodes
80 #define OP_MULTI_INPUT_MAX 9999
81 
82 // Maximum number of distinct indirect inputs shown until none are shown
83 // (all inputs are assumed to apply to the subnet).
84 #define OP_MAX_INDIRECT_INPUTS 500
85 
86 // Maximum number of outputs we allow for nodes that allow multiple outputs
87 #define OP_MULTI_OUTPUT_MAX 99999
88 
90 typedef OP_Node *(*OP_Constructor)(OP_Network *, const char *, OP_Operator *);
91 
92 // Event Script types
93 typedef enum {
98 
100 {
101 public:
103  virtual ~OP_SpecificData() { }
104 
105  virtual void saveToDialogScript(std::ostream &os) const = 0;
107 };
108 
110 {
111 public:
113  OP_TemplatePair *parent_pair = 0)
114  {
115  myTemplate = templates;
116  myBaseTemplatePair = parent_pair;
117  }
118  PRM_Template *myTemplate; // Could be zero
120 };
121 
123 {
124 public:
126  OP_VariablePair *parent_pair = 0)
127  {
128  myVariables = variables;
129  myBaseVariablePair = parent_pair;
130  }
131  CH_LocalVariable *myVariables; // Could be zero
133 };
134 
136 {
137 public:
141 };
142 
144 {
145 public:
146  /// Note: The 'inputlabels' array is expected to be null-terminated.
147  OP_Operator(const char *name,
148  const char *english,
149  OP_Constructor construct,
150  PRM_Template *templates,
151  unsigned min_sources,
152  unsigned max_sources = 9999,
153  CH_LocalVariable *variables = 0,
154  unsigned flags = 0,
155  const char **inputlabels = 0,
156  int maxoutputs = 1,
157  const char *tab_submenu_path = 0);
158 
159  OP_Operator(const char *name,
160  const char *english,
161  OP_Constructor construct,
162  OP_TemplatePair *template_pair,
163  unsigned min_sources,
164  unsigned max_sources = 9999,
165  OP_VariablePair *variable_pair = 0,
166  unsigned flags = 0,
167  const char **inputlabels = 0,
168  int maxoutputs = 1,
169  const char *tab_submenu_path = 0);
170 
171  OP_Operator(const char *name,
172  const char *english,
173  OP_Constructor construct,
174  PRM_Template *templates,
175  const char *child_table_name,
176  unsigned min_sources,
177  unsigned max_sources = 9999,
178  CH_LocalVariable *variables = 0,
179  unsigned flags = 0,
180  const char **inputlabels = 0,
181  int maxoutputs = 1,
182  const char *tab_submenu_path = 0);
183 
184  OP_Operator(const char *name,
185  const char *english,
186  OP_Constructor construct,
187  OP_TemplatePair *template_pair,
188  const char *child_table_name,
189  unsigned min_sources,
190  unsigned max_sources = 9999,
191  OP_VariablePair *variable_pair = 0,
192  unsigned flags = 0,
193  const char **inputlabels = 0,
194  int maxoutputs = 1,
195  const char *tab_submenu_path = 0);
196 
197  virtual ~OP_Operator();
198 
199  OP_Node *constructNode(OP_Network *net, const char *name);
200  int getNumActiveNodes() const;
201  OP_Node *getActiveNode(int i) const;
202  void nodeDestroyed(OP_Node *node);
203 
204  // Because of sub-classing of this class, we require the ability to set
205  // "specific" data for different network types. For example, SHOPs are
206  // required to know the "rendermask" and "shader type" for each OP.
208  { return 0; }
209  virtual const OP_SpecificData *getOpSpecificData() const
210  { return 0; }
211 
212  const UT_StringHolder &getName() const
213  { return myOTLDefinition.getName(); }
214 
215  /// Get the op table name and the op name concatenated together to get a
216  /// unique name.
217  /// Returns full name with table, including namespace and version tags
218  /// if there are any, eg "artistA::table/op::2.0"
219  void getTableAndName(UT_WorkBuffer &name) const
220  { myOTLDefinition.getTableAndName(name); }
221  void getTableAndName(UT_String &name) const
222  { myOTLDefinition.getTableAndName(name); }
223 
225  { return myOTLDefinition.getLabel(); }
226  UT_Color getDefaultColor() const;
227  const UT_StringHolder &getDefaultShape() const;
228 
229  virtual bool getHDKHelp(UT_String & /*str*/) const
230  { return false; }
231 
232  virtual bool getOpHelpURL(UT_String &url);
233  virtual bool getOpTabSubMenuPath(UT_String &tab_submenu_path);
234  void setOpTabSubMenuPath(const char *tab_submenu_path);
235 
236  bool getOTLHelp(UT_String &str);
237  void getEditableSubNodes(UT_String &pattern);
238  void getMessageSubNodes(UT_String &pattern);
239  void getDiveTarget(UT_String &divetarget);
240  void getDescriptiveParmName(UT_String &descrparm);
241  void getDefaultState(UT_String &statename);
242  void getFunctionName(UT_String &function_name);
243  void getSecondaryFunctionsNames(
244  UT_StringMap<UT_StringHolder> &functions );
245 
246  void getComment(UT_String &comment);
247 
248  /// For HDAs, getVersion will return the version number defined by its HDA
249  /// definition, or the empty string if it does not exist. For non-HDA's
250  /// (ie. native or HDK node types), it will return the Houdini version
251  /// X.Y.Z.W string that we were compiled with. Subclasses may override this
252  /// to provide different numbering. One of the uses of this function to
253  /// determine if loading a node's parameters needs to be upgraded.
254  virtual bool getVersion(UT_String &version);
255 
256  void getHelpFileDirAndName(UT_String & script_dir,
257  UT_String & name);
258 
259  void getDefinitionSource(UT_String &defsource) const;
260 
262  { ourLastHelpOp = 0; }
263  OP_Node *getDefiningNetwork() const;
264 
265  // These functions are used by scripted ops.
266  // IndexPath is something like "subnet".
267  // IndexFile is something ike "SUBsop".
269  { return myOTLDefinition.getIndexPath(); }
271  { return myOTLDefinition.getIndexFile(); }
272  bool getScriptIsSubnet() const
273  { return myOTLDefinition.getIsSubnet(); }
274  bool getScriptIsVex() const
275  { return (myVexContextType != VEX_INVALID_CONTEXT); }
276  bool getScriptIsRsl() const
277  { return (myRslContextType != RSL_INVALID_CONTEXT); }
279  { return myVexContextType; }
281  { return myRslContextType; }
282  int getModTime() const
283  { return myOTLDefinition.getModTime(); }
284  bool getIsDummyDefinition() const
285  { return myOTLDefinition.getIsDummyDefinition(); }
286 
287  // Does this node type cook by running python code?
288  bool getScriptIsPython() const
289  { return myOTLDefinition.getIsPython(); }
290  void setScriptIsPython(bool is_python)
291  { myOTLDefinition.setIsPython(is_python); }
292 
293  // Returns the extra info string from our OTL definition
295  { return myOTLDefinition.getExtraInfo(); }
296 
297  // Get and set all our OTL Definition information.
298  void setOTLDefinition(const OP_OTLDefinition &definition);
300  { return myOTLDefinition; }
301 
302  // Get and set our OP_OTLLibrary.
304  { myOTLLibrary = library; }
306  { return myOTLLibrary; }
307 
308  bool hasContentsSection();
309 
310  // Get reference to our FS_IndexFile from myOTLLibrary.
312  { return getOTLIndexFilePtr().get(); }
313 
314  // Get underlying shared ptr of getOTLIndexFile().
315  // This not const because it updates myOTLIndexFile.
316  FS_IndexFileHandle getOTLIndexFilePtr();
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_InputDataEditorConfig &config)
571  { myInputDataEditorConfig = config; }
572 
573  // Appends a short help string to the provided buffer. Generally,
574  // This help string will be hard-coded.
575  virtual const char *getOperatorShortHelpString();
576 
577  // Get Info Text that is specific to this operator type. All
578  // implementations should call their base class version.
579  // Text should be appended to the provided buffer.
580  virtual void getOperatorSpecificInfoText(int verbose,
581  UT_WorkBuffer &text);
582 
583  /// Fill in 'tree' with details that are common to all operator types. Then
584  /// call fillInfoTreeOperatorSpecific() to get specific details about this
585  /// specific operator
586  void fillInfoTree(UT_InfoTree &tree,
587  const OP_NodeInfoTreeParms &parms);
588 
589  /// Triggered by 'fillInfoTree()', this virtual function adds all operator-
590  /// specific info to 'tree'. All child classes must create their own
591  /// branches under 'tree' to place their info
592  virtual void fillInfoTreeOperatorSpecific(UT_InfoTree &tree,
593  const OP_NodeInfoTreeParms &parms);
594 
595  // Load operators from .optype files...
596  static int loadFromOpType(const char *fname, const char *savedir);
597  static int uninstallOpType(const char *path,
598  const char *tablename, const char *opname,
599  const char *indexpath, const char *indexfile);
600  // Remove override files, wherever they might be hiding...
601  static void removeHelpCardOverrides(UT_FileUtil *fu,
602  const char *path, const char *tablename,
603  const char *opname, int flags);
604  static void removeRenameOverrides(UT_FileUtil *fu,
605  const char *path, const char *tablename,
606  const char *opname, int flags);
607  static void removeIconOverrides(UT_FileUtil *fu,
608  const char *path, const char *tablename,
609  const char *opname, int flags);
610  static void removeCmdOverrides(UT_FileUtil *fu,
611  const char *path, const char *tablename,
612  const char *opname, int flags);
613  // Constructs the default icon name for a given op and op table.
614  static void getDefaultIconName(const char *tablename,
615  const char *opname,
616  UT_String &iconname);
617 
618  // This returns a pointer to the table name.
619  // This is one of the *_TABLE_NAME defined in OP_Operator, from
620  // which any other prefix can be calculated.
621  const char *getTableName() const;
622 
623  // This returns a pointer to our actual operator table.
624  OP_OperatorTable *getTable() const;
625 
626  // Get the table name where this operator's children will go
627  const UT_StringHolder &getChildTableName() const;
628  OP_OperatorTable *getChildOperatorTable() const;
629 
630  // Query the license type associated with this operator.
631  OP_OTLLicenseType getLicense();
632 
633  // Sets the file where this operator is defined.
634  // If the definition starts with "op:", we alert the operator
635  // referred to by the rest of the path that we are now attached
636  // to it.
637  void setDefinition(const char *def);
638  // Change the English name of the operator.
639  void setEnglish(const char *english);
640 
641  // the tab menu flag changed, so inform the sinks of template update
642  // so that they can adjust their information about this op.
643  void informOfTabMenuFlagChange();
644 
645  // Change the name of this operator. We have to remove and re-add
646  // ourselves to the operator table to update our data properly.
647  virtual void setName(const char *name);
648 
649  // Set the minimum and maximum number of sources. Overrides the
650  // values that were passed into the constructor. These functions
651  // should only be called when reloading the parm template, so
652  // that changeParmTemplate will get called on OPs of this type.
653  // changeParmTemplate now deals with chaning numbers of inputs
654  // and outputs.
655  //
656  // If you want to set both, you should call setMin first as setMax
657  // will verify min <= max and decrease min if required.
658  void setMinInputs(int inputs);
659  void setMaxInputs(int inputs);
660  void setIsGenerator(bool isgen);
661 
662  // Functions to dirty and get the preset info for this operator.
663  // The get function creates the preset info if required.
664  void updatePresetInfo();
665  PRM_PresetInfo *getPresetInfo();
666 
667  /// Returns a file name corresponding to the operator name.
668  /// In most cases, the file name is the same as the operator name, but
669  /// since it has to be acceptable by all file systems, some invalid
670  /// characters may be converted to dashes
671  /// (eg, the namespace semicolons which cause problems on Windows).
672  /// @{
673  void getOpBasedFileName(UT_String &filename);
674  void getOpBasedFileName(UT_WorkBuffer &filename);
675  /// @}
676 
677  // This function runs one of the embedded scripts. It returns
678  // true if the script was found, even if it was empty. The
679  // nodedeletedbyscript parameter lets the caller know if the node
680  // passed in as nodearg was deleted while running the script.
681  bool runEventScript(
682  const char *event,
683  OP_Node *node_arg = NULL,
684  bool full_path = false,
685  UT_Options *extra_args = NULL,
686  bool *node_deleted_by_script = NULL);
687 
688  // Digital assets can have a pair of Python dictionaries that store
689  // the contents of the asset's Python "module". For non-DA's, these
690  // dictionaries are empty.
692  { return myPythonModuleDicts; }
694  { return myHasLoadedPythonModuleSection; }
695  void loadPythonModuleSection(bool force=false);
696 
697  // Clear all paths to event scripts cached for this operator.
698  void clearEventScriptPathCache();
699 
700  // Query all cached event script paths.
701  void getCachedEventScriptPaths(
702  UT_StringArray &events,
703  UT_StringArray &paths,
704  bool only_nonempty) const;
705 
706  /// Is this operator type thread-safe for cooking? OP_Node::cook() calls
707  /// this to determine if serialization is needed.
708  /// DEFAULT: false
709  bool isThreadSafe() const
710  { return myIsThreadSafe; }
711 
712  /// This function is used to specify whether a particular operator type
713  /// can be cooked in a multi-threaded manner.
714  void setIsThreadSafe(bool is_safe)
715  { myIsThreadSafe = is_safe; }
716 
717  static const char *getCurrentPythonModuleKey();
718  static const OP_Operator *mapSecurityKeyToOperator(const char *key);
719  static void registerPythonModuleKeyClient(void *client);
720  static bool verifyPythonModuleKeyClient(
721  const OP_Operator *op, void *client);
722 
723  static PRM_Template *getEmptyTemplateList();
724 
725  /// Returns true if this operator comes from a compiled OTL,
726  /// false otherwise.
727  bool isCompiled();
728 
729  /// Returns true if this operator is black boxed, and false otherwise.
730  bool isBlackBoxed();
731 
732  static int operatorNameCompare(const OP_Operator *a, const OP_Operator *b)
733  {
734  return (a ? (b ? (a->getName() < b->getName())
735  : false)
736  : true);
737  }
738 
739 protected:
740  // This function should be called from updateParmTemplates whenever
741  // that function would return a 1. Also called by setName and setEnglish.
742  void notifyUpdateTemplatesSinksOfUpdate();
743  // Called when the operator is deleted.
744  void notifyUpdateTemplatesSinksOfDelete();
745 
746  // Notify active nodes that the parameter templates have changed.
747  void notifyActiveNodesOfTemplatesUpdate();
748 
749  // For script operators - we need to make these methods protected.
750  static PRM_Template *addTemplates(OP_TemplatePair *);
751  static CH_LocalVariable *addVariables(OP_VariablePair *, int &);
752 
753  // This is currently only used temporarily to transfer from
754  // a DS file to a HDA.
756  { myDescriptiveParmName = parm; }
757 
758  void dirtyParmTemplatesLoaded();
759 
760  virtual bool loadParmTemplatesSubclass();
761 
762  /// Load parameter templates from the specified file stream.
763  bool loadAndCreateLayoutParmTemplates(
764  PRM_ScriptPage *page,
765  DS_Stream &ds_is,
766  PRM_Template *&base_tplates,
767  PRM_Template *&layout_tplates,
768  PRM_ScriptImports *&imports,
769  PRM_Template *&tplates,
770  int base_controls_switcher_index,
771  int base_controls_insert_index,
772  int base_controls_switcher_page_num,
773  PRM_Default *&base_controls_switcher_defaults,
774  bool hide_default_parms);
775 
792 
797  unsigned myFlags;
799 
800  // The script page used for storing the parsed override parameters
801  // if they exist. Though this class is the only owner of the page object
802  // we use a shared pointer as a way of controlling when the object
803  // actually gets deleted. For example, some methods will create a local
804  // shared pointer to the same object as a way of keeping it alive for the
805  // method scope.
807 
808 private:
809  unsigned operator<(const OP_Operator &);
810  void uniqueName(OP_Network *);
811  void addUpdateTemplatesSink(OP_UpdateTemplatesSink *);
812  void removeUpdateTemplatesSink(OP_UpdateTemplatesSink *);
813 
814  void getContentSectionTypeNames(UT_IStream &is,
815  UT_StringSet &contents_list) const;
816 
817  // When the VOPNET that defines us chages, we want to know about it...
818  static void handleDefiningNetworkChange(OP_Node *caller,
819  void *callee,
821  void *data);
822 
823  CH_ScriptLanguage eventScriptLanguage(
824  FS_IndexFile &def_file, const char *event);
825  bool runEventScript(
826  const char *event,
827  OP_Node *node_arg,
828  bool full_path,
829  UT_Options *extra_args,
830  bool &node_deleted_by_script,
831  OP_EventScriptType eventtype);
832  void runHscriptEventScript(
833  const char *script,
834  const char *script_path,
835  OP_Node *node,
836  bool full_path,
837  const char *extra_args);
838  void runPythonEventScript(
839  const char *script,
840  const char *script_path,
841  PY_EvaluationContext &evaluation_context,
842  const char *kwargs_dict, OP_Node *node);
843 
844  // Get the script path cache for this operator, allocating it if
845  // necessary.
846  OP_EventScriptPathCache *getEventScriptPathCache();
847 
848  /// Attempt to load the custom override parameter layout
849  /// if it exists on disk.
850  void loadOverrideLayoutParmTemplates();
851 
852  void ensureParmTemplatesLoaded();
853 
854  OP_Constructor myConstructor;
855 
856  OP_NodeList myActiveNodes;
857 
858  OP_OTLLibrary *myOTLLibrary;
859  FS_IndexFileHandle myOTLIndexFile;
860  OP_OperatorTable *myOperatorTable;
861  OP_Node *myDefiningNetwork;
862  PRM_PresetInfo *myPresetInfo;
863  OP_SpareParmCache *mySpareParmCache;
864  OP_EventScriptPathCache *myEventScriptPathCache;
865  bool myCreatingNode;
866  bool myChangingParmTemplates;
867  bool myRefreshingLib;
868  bool myDestroyingSelf;
869  int myLoadingContentsSectionCount;
870 
871  UT_ValArray<OP_UpdateTemplatesSink *> myUpdateTemplatesSinks;
872 
873  PY_EvaluationContext *myPythonModuleDicts;
874  bool myHasLoadedPythonModuleSection;
875 
876  bool myIsThreadSafe;
877  int myIsCompiled;
878 
879  UT_StringArray myLegacyInputs;
880 
881  // We cannot assign descriptive parms when parsing dialog scripts
882  // as they are stored in .otl sections, but we need to hold onto
883  // it until buildotl finishes...
884  UT_StringHolder myDescriptiveParmName;
885 
886  friend class OP_OperatorTable;
887  friend class SHOP_ScriptOperator;
889 
890  static const OP_Operator *ourLastHelpOp;
891  static int ourLastHelpLevel;
892  static UT_String ourHelp;
893  static bool ourHelpIsHtml;
894 };
895 
897 {
898 public:
901  { removeAllTemplatesSinks(); }
902 
903  virtual void templatesUpdated(OP_Operator *op) = 0;
904  virtual void operatorDeleted(OP_Operator *op)
905  { removeUpdateTemplatesSink(op); }
906 
907 protected:
909  {
910  if( !op ) return;
911  op->addUpdateTemplatesSink(this);
912  myOperators.append(op, 1);
913  }
915  {
916  return myOperators.find(op) >= 0;
917  }
919  {
920  if( !op ) return;
921  op->removeUpdateTemplatesSink(this);
922  myOperators.findAndRemove(op);
923  }
925  {
926  for( int i = myOperators.entries(); i --> 0; )
927  removeUpdateTemplatesSink(myOperators(i));
928  }
929 
930 private:
931  OP_OperatorList myOperators;
932 };
933 
934 #endif
unsigned maxInputs() const
Definition: OP_Operator.h:366
virtual ~OP_SpecificData()
Definition: OP_Operator.h:103
unsigned minInputs() const
Definition: OP_Operator.h:364
PRM_ScriptImports * myLayoutParmImports
Definition: OP_Operator.h:779
int getVersion(int version)
Definition: ImfVersion.h:116
FS_IndexFile * getOTLIndexFile()
Definition: OP_Operator.h:311
GT_API const UT_StringHolder filename
virtual ~OP_UpdateTemplatesSink()
Definition: OP_Operator.h:900
bool getScriptIsSubnet() const
Definition: OP_Operator.h:272
UT_StringArray myInputLabels
Definition: OP_Operator.h:785
const OP_OTLDefinition & getOTLDefinition() const
Definition: OP_Operator.h:299
unsigned unorderedInputs() const
Definition: OP_Operator.h:459
void setIsThreadSafe(bool is_safe)
Definition: OP_Operator.h:714
void getTableAndName(UT_String &name) const
Definition: OP_Operator.h:221
bool shouldPreserve() const
Definition: OP_Operator.h:506
void setInputDataEditorConfig(const OP_InputDataEditorConfig &config)
Definition: OP_Operator.h:569
int myNvariables
Definition: OP_Operator.h:790
static void clearOperatorHelpCache()
Definition: OP_Operator.h:261
CH_LocalVariable * myVariables
Definition: OP_Operator.h:789
bool getScriptIsRsl() const
Definition: OP_Operator.h:276
PRM_Template * myBaseOverrideLayout
Definition: OP_Operator.h:780
GLsizei const GLchar *const * path
Definition: glcorearb.h:3340
#define OP_FLAG_NETWORK
Flags passed to the contructor:
Definition: OP_Operator.h:67
const UT_StringHolder & getExtraInfo() const
Definition: OP_Operator.h:294
unsigned isOutputOp() const
Definition: OP_Operator.h:467
#define OP_FLAG_OUTPUT
Definition: OP_Operator.h:73
VEX_ContextType getVexContextType() const
Definition: OP_Operator.h:278
int getVariableCount() const
Definition: OP_Operator.h:442
OP_OTLDefinition myOTLDefinition
Definition: OP_Operator.h:793
virtual void getRefreshPICommands(OP_Node *, std::ostream &)
Definition: OP_Operator.h:548
#define OP_FLAG_GENERATOR
Definition: OP_Operator.h:68
GLboolean GLboolean GLboolean GLboolean a
Definition: glcorearb.h:1221
GLbitfield flags
Definition: glcorearb.h:1595
void removeUpdateTemplatesSink(OP_Operator *op)
Definition: OP_Operator.h:918
OP_TemplatePair(PRM_Template *templates, OP_TemplatePair *parent_pair=0)
Definition: OP_Operator.h:112
UT_StringArray myInputNames
Definition: OP_Operator.h:784
png_uint_32 i
Definition: png.h:2877
UT_StringHolder myChildTableName
Definition: OP_Operator.h:791
#define OP_FLAG_PRIMARYSUBNET
Definition: OP_Operator.h:72
const UT_StringArray & getOutputLabels() const
Definition: OP_Operator.h:540
UT_Array< bool > myInputReferences
Definition: OP_Operator.h:788
const UT_StringHolder & getName() const
Definition: OP_Operator.h:212
OP_TemplatePair * myBaseTemplatePair
Definition: OP_Operator.h:119
struct _cl_event * event
Definition: glcorearb.h:2960
virtual void updateExtraInfoBuffer(OP_ExtraInfoBuffer &b) const
Definition: OP_Operator.h:106
bool myHasContentsSection
Definition: OP_Operator.h:798
CH_LocalVariable * myVariables
Definition: OP_Operator.h:131
virtual bool getHDKHelp(UT_String &) const
Definition: OP_Operator.h:229
const UT_StringHolder & getIndexFile() const
Definition: OP_Operator.h:270
OP_InputDataEditorConfig myInputDataEditorConfig
Definition: OP_Operator.h:794
#define OP_FLAG_SCRIPTDEF
Definition: OP_Operator.h:70
virtual const OP_SpecificData * getOpSpecificData() const
Definition: OP_Operator.h:209
static int operatorNameCompare(const OP_Operator *a, const OP_Operator *b)
Definition: OP_Operator.h:732
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
OP_EventScriptType
Definition: OP_Operator.h:93
bool isCreatingNode() const
Definition: OP_Operator.h:482
int method
Definition: png.h:1924
UT_DeepString myTabSubmenuPath
Definition: OP_Operator.h:787
unsigned isNetwork() const
Definition: OP_Operator.h:446
PRM_Template * myLayoutParmTemplates
Definition: OP_Operator.h:778
bool hasLoadedPythonModuleSection() const
Definition: OP_Operator.h:693
bool isChangingParmTemplates() const
Definition: OP_Operator.h:486
bool operator<(const GU_TetrahedronFacet &a, const GU_TetrahedronFacet &b)
void setScriptIsPython(bool is_python)
Definition: OP_Operator.h:290
UT_StringArray myOutputLabels
Definition: OP_Operator.h:786
GLboolean * data
Definition: glcorearb.h:130
bool isThreadSafe() const
Definition: OP_Operator.h:709
GLuint const GLchar * name
Definition: glcorearb.h:785
const UT_StringArray & getInputLabels() const
Accessing operator inputs name, label, and reference flag.
Definition: OP_Operator.h:531
const OP_InputDataEditorConfig & getInputDataEditorConfig() const
Definition: OP_Operator.h:567
RSL_ContextType getRslContextType() const
Definition: OP_Operator.h:280
GLboolean GLboolean GLboolean b
Definition: glcorearb.h:1221
void setDescriptiveParmName(const UT_StringHolder &parm)
Definition: OP_Operator.h:755
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:90
#define OP_FLAG_MANAGER
Definition: OP_Operator.h:71
GT_API const UT_StringHolder version
PRM_Template * myObsoleteTemplates
Definition: OP_Operator.h:783
OP_VariablePair * myBaseVariablePair
Definition: OP_Operator.h:132
PRM_Template * myTemplate
Definition: OP_Operator.h:118
OP_VariablePair(CH_LocalVariable *variables, OP_VariablePair *parent_pair=0)
Definition: OP_Operator.h:125
A map of string to various well defined value types.
Definition: UT_Options.h:42
void getTableAndName(UT_WorkBuffer &name) const
Definition: OP_Operator.h:219
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:89
virtual unsigned maxOutputs()
Definition: OP_Operator.h:386
PRM_Template * myBase
Definition: OP_Operator.h:781
UT_StringHolder myDataKey
Definition: OP_Operator.h:138
bool hasTemplatesSink(OP_Operator *op)
Definition: OP_Operator.h:914
#define OP_FLAG_UNORDERED
Definition: OP_Operator.h:69
unsigned isScriptedOp() const
Definition: OP_Operator.h:454
PRM_Template * myParmTemplates
Definition: OP_Operator.h:776
void endLoadingContentsSectionForNode()
Definition: OP_Operator.h:498
#define OP_API
Definition: OP_API.h:10
OP_OTLLicenseType
VEX_ContextType myVexContextType
Definition: OP_Operator.h:795
OP_EventType
Definition: OP_Value.h:22
OP_OTLLibrary * getOTLLibrary()
Definition: OP_Operator.h:305
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:207
GLint GLint GLsizei GLint GLenum GLenum type
Definition: glcorearb.h:107
const UT_StringHolder & getIndexPath() const
Definition: OP_Operator.h:268
unsigned myFlags
Definition: OP_Operator.h:797
bool getScriptIsVex() const
Definition: OP_Operator.h:274
RSL_ContextType
RenderMan shader context types.
Definition: VEX_RslTypes.h:25
#define OP_FLAG_EDITABLE_INPUT_DATA
Definition: OP_Operator.h:74
bool myParmTemplatesLoaded
Definition: OP_Operator.h:782
UT_SharedPtr< PRM_ScriptPage > myOverrideLayoutParmScriptPage
Definition: OP_Operator.h:806
bool getIsDummyDefinition() const
Definition: OP_Operator.h:284
virtual void operatorDeleted(OP_Operator *op)
Definition: OP_Operator.h:904
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:777
virtual PRM_Template * getObsoleteTemplates()
Definition: OP_Operator.h:427
UT_StringHolder myDataDefault
Definition: OP_Operator.h:140
PY_EvaluationContext * getPythonModuleDicts()
Definition: OP_Operator.h:691
virtual const PRM_Template * getBaseParmTemplates()
Definition: OP_Operator.h:419
int getModTime() const
Definition: OP_Operator.h:282
void addUpdateTemplatesSink(OP_Operator *op)
Definition: OP_Operator.h:908
bool getScriptIsPython() const
Definition: OP_Operator.h:288
UT_StringHolder myDataHeader
Definition: OP_Operator.h:139
const UT_StringHolder & getEnglish() const
Definition: OP_Operator.h:224
RSL_ContextType myRslContextType
Definition: OP_Operator.h:796
CH_ScriptLanguage
bool hasNodeLoadingContentsSection() const
Definition: OP_Operator.h:490
void setOTLLibrary(OP_OTLLibrary *library)
Definition: OP_Operator.h:303
bool hasEditableInputData() const
Definition: OP_Operator.h:471