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