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