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