HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
VOP_ScriptNode.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: VOP_ScriptNode.h ( VOP Library, C++)
7  *
8  * COMMENTS: This is the meat & potatoes. Here we have an operator which is
9  * defined by a script.
10  */
11 
12 #ifndef __VOP_ScriptNode__
13 #define __VOP_ScriptNode__
14 
15 #include "VOP_API.h"
16 #include "VOP_Node.h"
17 
18 class VOP_ScriptOperator;
19 
21 public:
22  VOP_ScriptNode(OP_Network *dad, const char *name, OP_Operator *op);
23  ~VOP_ScriptNode() override;
24 
25  static OP_Node *myConstructor(OP_Network *net, const char *name,
26  OP_Operator *op);
27  static PRM_Template myMultiInputSetTemplateList[];
28 
29  void initMaterialFlag() override;
30  void getModulesToImport(UT_StringArray &modules,
31  const VOP_CodeGenContext &context) override;
32  void getOuterCode(UT_String &codestr,
33  const VOP_CodeGenContext &context) override;
34  void getCode(UT_String &codestr,
35  const VOP_CodeGenContext &context) override;
37  const char *parmname,
38  const VOP_TypeInfo &type_info,
39  UT_String &str,
40  bool expand_string,
41  const VOP_Language *language=nullptr) override;
42 
43  void ensureParametersAreValid() override;
44 
45  const char *inputLabel(OP_InputIdx idx) const override;
46  const char *outputLabel(OP_OutputIdx idx) const override;
47 
48  int getSignatureCount() const override;
49  void getSignatureName(
50  UT_String &name, int index) const override;
51  void setCurrentSignature(const char *name) override;
52  bool getCurrentSignatureName(UT_String &name) override;
54  const UT_StringRef &signature) const override;
55 
56  bool allowUSDShaderParm(PRM_Parm &parm) override;
57 
59  unsigned idx,
60  VOP_VopTypeInfoArray &voptypes) override;
61 
62  bool isShader() const override;
63  bool isShader(VOP_Type shader_type) const override;
64  bool isCachedShader() const override;
66  std::ostream &os,
67  VOP_ContextType context_type) const override;
69  const VOP_CodeGenContext &context,
70  bool check_shader_context) const override;
71 
72  void getParmNameFromInput(UT_String &parmname,
73  int inputidx) const override;
74 
75  static void buildInputSetMenu(void *, PRM_Name *, int,
76  const PRM_SpareData *,
77  const PRM_Parm *);
78  int getCurrentInputSet() const;
79 
80  /// Updates the opeartor information about inputs and outputs based on the
81  /// current state of the script node.
82  /// If 'keep_info' is true, most of the op_info is preserved (eg, input
83  /// order, input visibility flags, etc), and this method updates the data
84  /// that can be specifed only by the node itself (and not op type
85  /// properties editor). Otherwise, if false, node inptus will dictate
86  /// the saved order and flags.
87  void updateInputsAndOutputsInfo(VOP_OperatorInfo *op_info,
88  bool keep_info = false);
89  virtual bool getIsInputDefinedByParmChild(int idx) const;
90  virtual bool getIsOutputDefinedByParmChild(int idx) const;
91 
92  void opChanged(
93  OP_EventType reason,
94  void *data = nullptr) override;
95 
96  bool definesShaderExtraParameters() const override;
99  UT_IntArray &doexport,
100  UT_StringArray &names,
101  UT_StringArray &def,
102  VOP_Type shader_type = VOP_TYPE_UNDEF
103  ) const override;
104 protected:
105  void updateCurrentInputSet();
106 
107  bool updateParmsFlags() override;
108 
109  unsigned getNumScriptOpInputs() const;
110  const UT_StringHolder &getScriptOpInputName(int idx) const;
111  int findScriptOpInput(const char *input_name) const;
113  UT_String &in, int idx) const override;
115  const UT_String &in) const override;
117  VOP_TypeInfo &type_info, int idx) override;
118  bool getIsInputVisibleDefaultSubclass(int idx) override;
120  unsigned idx,
121  VOP_VopTypeInfoArray &voptypes) override;
122 
123  unsigned getNumScriptOutputs() const;
124  int findScriptOpOutput(
125  const UT_StringRef &output_name) const;
127  UT_String &out, int idx) const override;
129  VOP_TypeInfo &type_info, int idx) override;
130 
131  /// Returns true if output of a given index has an input by the same name.
132  virtual bool hasCorrespondingInput(int output_idx) const;
133 
134  void getVopFunctionName(
135  UT_String &function_name) const override;
136 
137 private:
138  bool getBestMatchingParameter(UT_WorkBuffer &parm,
139  const char *input, int inputidx) const;
140  bool getBestMatchingInput(int &input_index,
141  const UT_String &input_name) const;
142  bool shouldOutputNodeVariableDeclarations() const override;
143 
144  bool getHideInputsUsingParameterVisibleState() const;
145 
146 private:
147  VOP_ScriptOperator *myScript;
148  int myCurrentInputSet;
149  UT_IntArray myValidInputSets;
150  bool myUpdatingInputSetFlag;
151 };
152 
153 #endif
virtual int getInputFromNameSubclass(const UT_String &in) const
Reprsents a language for which VOPs can generate source code.
Definition: VOP_Language.h:29
virtual void getOuterCode(UT_String &codestr, const VOP_CodeGenContext &context)
virtual void getVopFunctionName(UT_String &function_name) const
virtual void initMaterialFlag()
virtual UT_StringHolder getShaderNameForSignature(const UT_StringRef &signature) const
Returns the name, type, and render mask of the VOP shader.
virtual bool getCurrentSignatureName(UT_String &name)
Obtains the current signature name.
virtual void setCurrentSignature(const char *name)
virtual bool getParmConstantString(const char *parmname, const VOP_TypeInfo &type_info, UT_String &str, bool expand_string, const VOP_Language *l=0)
Get the constant code that encodes the value of the node parameter.
virtual bool isCachedShader() const
virtual bool forceCodeGenerationOfInputs(const VOP_CodeGenContext &context, bool check_shader_context) const
virtual int getShaderExtraParameters(UT_Array< VOP_Type > &types, UT_IntArray &doexport, UT_StringArray &names, UT_StringArray &def, VOP_Type shader_type=VOP_TYPE_UNDEF) const
virtual bool getIsInputVisibleDefaultSubclass(int idx)
int OP_InputIdx
Definition: OP_DataTypes.h:184
bool updateParmsFlags() override
virtual void getSignatureName(UT_String &name, int index) const
virtual void getInputTypeInfoSubclass(VOP_TypeInfo &type_info, int idx)
constexpr auto in(type t, int set) -> bool
Definition: core.h:611
virtual bool definesShaderExtraParameters() const
int VOP_ContextType
Definition: VOP_Types.h:177
virtual const char * inputLabel(OP_InputIdx idx) const
virtual bool isShader() const
#define VOP_API
Definition: VOP_API.h:10
virtual bool shouldOutputNodeVariableDeclarations() const
virtual void getParmNameFromInput(UT_String &parmname, int inputidx) const
virtual int getSignatureCount() const
GLuint const GLchar * name
Definition: glcorearb.h:786
virtual void getCode(UT_String &codestr, const VOP_CodeGenContext &context)
Get the code fragment to be included in the shader code.
virtual bool allowUSDShaderParm(PRM_Parm &parm)
virtual void getOutputTypeInfoSubclass(VOP_TypeInfo &type_info, int idx)
virtual void getOutputNameSubclass(UT_String &out, int idx) const
GLuint index
Definition: glcorearb.h:786
OP_EventType
Definition: OP_Value.h:22
VOP_Type
Enumeration of the built-in (basic) VOP data types.
Definition: VOP_Types.h:25
virtual void getModulesToImport(UT_StringArray &modules, const VOP_CodeGenContext &context)
If the node generates a shader call, get the modules names to import.
virtual void getInputNameSubclass(UT_String &in, int idx) const
int OP_OutputIdx
Definition: OP_DataTypes.h:185
virtual bool getCachedShaderCode(std::ostream &os, VOP_ContextType context_type) const
virtual void getAllowedInputTypeInfosSubclass(unsigned idx, VOP_VopTypeInfoArray &infos)
GLsizei GLenum GLenum * types
Definition: glcorearb.h:2542
virtual const char * outputLabel(OP_OutputIdx idx) const
virtual void getAllowedInputTypeInfos(unsigned idx, VOP_VopTypeInfoArray &typeinfos)
virtual void ensureParametersAreValid()
Definition: format.h:1821
void opChanged(OP_EventType reason, void *data=0) override