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=0) override;
42 
43  void ensureParametersAreValid() override;
44 
45  const char *inputLabel(unsigned idx) const override;
46  const char *outputLabel(unsigned 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(OP_EventType reason, void *data=0) override;
93 
94  bool definesShaderExtraParameters() const override;
97  UT_IntArray &doexport,
98  UT_StringArray &names,
99  UT_StringArray &def,
100  VOP_Type shader_type = VOP_TYPE_UNDEF
101  ) const override;
102 protected:
103  void updateCurrentInputSet();
104 
105  bool updateParmsFlags() override;
106 
107  unsigned getNumScriptOpInputs() const;
108  const UT_StringHolder &getScriptOpInputName(int idx) const;
109  int findScriptOpInput(const char *input_name) const;
111  UT_String &in, int idx) const override;
113  const UT_String &in) const override;
115  VOP_TypeInfo &type_info, int idx) override;
116  bool getIsInputVisibleDefaultSubclass(int idx) override;
118  unsigned idx,
119  VOP_VopTypeInfoArray &voptypes) override;
120 
121  unsigned getNumScriptOutputs() const;
122  int findScriptOpOutput(
123  const UT_StringRef &output_name) const;
125  UT_String &out, int idx) const override;
127  VOP_TypeInfo &type_info, int idx) override;
128 
129  /// Returns true if output of a given index has an input by the same name.
130  virtual bool hasCorrespondingInput(int output_idx) const;
131 
132  void getVopFunctionName(
133  UT_String &function_name) const override;
134 
135 private:
136  bool getBestMatchingParameter(UT_WorkBuffer &parm,
137  const char *input, int inputidx) const;
138  bool getBestMatchingInput(int &input_index,
139  const UT_String &input_name) const;
140  bool shouldOutputNodeVariableDeclarations() const override;
141 
142  bool getHideInputsUsingParameterVisibleState() const;
143 
144 private:
145  VOP_ScriptOperator *myScript;
146  int myCurrentInputSet;
147  UT_IntArray myValidInputSets;
148  bool myUpdatingInputSetFlag;
149 };
150 
151 #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)
bool updateParmsFlags() override
virtual const char * inputLabel(unsigned idx) const
virtual void getSignatureName(UT_String &name, int index) const
virtual void getInputTypeInfoSubclass(VOP_TypeInfo &type_info, int idx)
virtual bool definesShaderExtraParameters() const
int VOP_ContextType
Definition: VOP_Types.h:177
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 const char * outputLabel(unsigned idx) const
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
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 void getAllowedInputTypeInfos(unsigned idx, VOP_VopTypeInfoArray &typeinfos)
virtual void ensureParametersAreValid()
Definition: format.h:895
void opChanged(OP_EventType reason, void *data=0) override