HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
VOP_SubnetScript.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 Library (C++)
7  *
8  */
9 
10 #ifndef __VOP_SubnetScript_h__
11 #define __VOP_SubnetScript_h__
12 
13 #include "VOP_API.h"
15 #include "VOP_ScriptNode.h"
16 class VOP_SubnetHelper;
17 
19 {
20 public:
21  static OP_Node *myConstructor(OP_Network *net,
22  const char *name,
23  OP_Operator *entry);
24  static PRM_Template myTemplateList[];
25 
27 
28  void getModulesToImport(UT_StringArray &modules,
29  const VOP_CodeGenContext &context) override;
30  void getOuterCode(UT_String &codestr,
31  const VOP_CodeGenContext &context) override;
32  void getCode(UT_String &codestr,
33  const VOP_CodeGenContext &context) override;
34 
36  const VOP_CodeGenContext &context,
37  bool check_shader_context) const override;
38 
39  bool canDefineShader() const override;
42  ) override;
43 
45  const char *parmname,
46  const VOP_TypeInfo &type_info,
47  UT_String &str,
48  bool expand_string,
49  const VOP_Language *l = nullptr) override;
50 
51  const char *inputLabel(unsigned idx) const override;
52  const char *outputLabel(unsigned idx) const override;
53 
54  unsigned maxInputs() const override;
55  unsigned getNumVisibleInputs() const override;
56  unsigned getNumVisibleOutputs() const override;
57  int getNumNodeDefinedOutputs() const override;
58  int getNumSubnetInputsForChildren() const override;
60  int index) const override;
61 
62  bool isConnected(int inputidx, bool recursive) override;
63 
65  bool create_if_needed=false) override;
66 
67  /// Updates the node so new inuts and outputs are taken into account.
68  /// If op_info argument is NULL, the current operator op info is queried.
69  void updateSubnetWithNewOp(const VOP_OperatorInfo *op_info);
70 
71  static const char *theChildTableName;
72 
73 protected:
74  VOP_SubnetScript(OP_Network *net, const char *name, OP_Operator *entry);
75  ~VOP_SubnetScript() override;
76 
79  void deleteArraysForLoadedInputAndOutputNames();
81 
82  void beginLoadingInNetwork() override;
83  void endLoadingInNetwork() override;
84  void loadStart() override;
86  bool is_child_call=false) override;
87  void setupConnectorsAfterLoad() override;
88  void changeParmTemplate(
89  PRM_Template *new_template) override;
90  void addNode(OP_Node *node, int notify=1,
91  int explicitly=1) override;
92  bool isOperatorAllowedInTabMenu(OP_Operator *op) override;
93 
94  /// Invalidates the cached list of contained shaders.
95  bool runCreateScript() override;
96  void dirtyShaderList() override;
97  void findAllShaders(
98  VOP_NodeList &shader_nodes,
99  VOP_ShaderTypeList &shader_types,
100  UT_StringArray &output_names) override;
101 
102  /// Returns true if subnet can be translated into Material or NodeGraph.
103  bool translatesDirectlyToUSD() const override;
104 
105  /// Overriding these virtuals to control how we create contents network
106  /// @{
107  void matchOTLDefinition() override;
108  void unmatchOTLDefinition() override;
109  void handleOTLIndexFileCleared() override;
110  /// @}
111 
112  /// Inherited from VOP_Node.
113  /// Generate the node errors.
114  /// Return true if an error was generated and false otherwise.
115  bool generateErrorsSubclass() override;
116 
117  /// Subnet declares own variables, so some types may need to be defined.
119  UT_Array<VOP_TypeInfo> &types) override;
120 
121  void opChanged(OP_EventType reason, void *data) override;
122  void postOpChanged(
123  OP_EventType reason, void *data) override;
124 
125  /// @{ Methods for handling inputs defined by a parm vop children in
126  /// unlocked assets.
127  void handleChildAdd( OP_Node *child );
128  void handleChildDelete( OP_Node *child );
129  void handleDescendentAdd( VOP_Node *descendent );
130  void handleDescendentDelete( VOP_Node *descendent );
131  static void handleParmNodeChange(OP_Node *caller, void *callee,
132  OP_EventType type, void *);
133  void updateConnectorDefiner( VOP_Node *node);
135  VOP_Node *grand_child) override;
137  VOP_Node *grand_child) override;
139  VOP_Node *grand_child) override;
140  void setupConnectorDefinersAfterLoadIfNeeded(
141  const VOP_OperatorInfo *op_info);
142  void setupConnectorDefinersAfterLoad(
143  const VOP_OperatorInfo *op_info);
144  void addConnectorDefinerAfterLoad(VOP_ParmGenerator *pg,
145  const VOP_OperatorInfo *op_info,
149  UT_Array< VOP_ParmGenerator* > &append_out );
150  int verifyOpInputIndexForNode(int idx) const;
151  /// @}
152 
154  UT_String &in, int idx) const override;
156  const UT_String &in) const override;
158  VOP_TypeInfo &type_info, int idx) override;
159  bool getIsInputDefinedByParmChild(int idx) const override;
160  bool getIsOutputDefinedByParmChild(int idx) const override;
161 
163  UT_String &out, int idx) const override;
165  VOP_TypeInfo &type_info, int idx) override;
167  int out_idx, VOP_Type shader_type) override;
169  int out_idx, VOP_Type shader_type) override;
171  VOP_Node * &output_vop,
172  int &input_idx,
173  int subnet_output_idx) const override;
174 
175  /// Returns true if output of a given index has an input by the same name.
176  bool hasCorrespondingInput(int output_idx) const override;
177 
179  {
182  .requiresUpdate(0.0))
183  {
186  }
187  }
188 
189  /// Returns true if the subnet script (HDA) is using cached code
190  /// rather than generating it from the children.
191  bool isUsingCachedCode() const
192  { return myIsUsingCachedCode; }
193 
194  /// @{ Helpers for managing script info object
195  virtual void loadMaterialInfo();
196  virtual void unloadMaterialInfo();
197  /// @}
198 
199 private:
200  struct vop_EncapsulatedMetaData
201  {
202  vop_EncapsulatedMetaData() : myIsValid(false) {}
203 
204  bool myIsValid;
205  UT_SortedStringMap<UT_String> myIsConnectedMap;
206  };
207 
208  bool parseMetaDataString(UT_String &str,
209  vop_EncapsulatedMetaData &md);
210  void parseEncapsulatedMetaData(const UT_WorkBuffer &code,
211  vop_EncapsulatedMetaData &md);
212 
213  void adjustChildrenForInputRemoval(int idx);
214  void adjustChildrenForInputInsertion(int idx);
215 
216 private:
217  /// Forward declaration of our embedded VOP_SubnetHelper::SubnetAPI
218  /// subclass.
219  class SubnetAPI;
220 
221  friend class SubnetAPI;
222 
223  /// Helper that factors out methods shared with regular subnetwork.
224  VOP_SubnetHelper *mySubnetHelper;
225 
226  /// Used during loading to find out input and output names just in case
227  /// we need to order Parameter VOP defined inputs/outputs in assets not
228  /// matching their definition.
229  UT_StringArray *myLoadedInputNames;
230  UT_StringArray *myLoadedOutputNames;
231 
232  /// A flag indicating if node is exclusively using cached vex/vfl code.
233  bool myIsUsingCachedCode;
234 
235  /// We're deleting a mass of nodes. We don't care about knowing whether
236  /// we just lost one.
237  bool myIsDeletingSubnetNodes;
238 
239  /// We're in setupConnectorDefinersAfterLoad().
240  unsigned myIsSettingUpConnectorDefinersAfterLoad : 1,
241  myIsLoadingNetwork : 1,
242  myAreConnectorsSetUp : 1;
243 };
244 
245 #endif
Reprsents a language for which VOPs can generate source code.
Definition: VOP_Language.h:29
virtual void endLoadingInNetwork()
void ensureSpareParmsAreUpdatedSubclass() override
virtual void dirtyShaderList()
Some material vops cache a list of shader that needs to be dirtied.
virtual void shaderParmGrandChildChanged(VOP_Node *grand_child)
virtual unsigned maxInputs() const
Maximum inputs that can be connected to a node.
static const char * theChildTableName
void getOuterCode(UT_String &codestr, const VOP_CodeGenContext &context) override
virtual void setupConnectorsAfterLoad()
virtual unsigned getNumVisibleInputs() const
virtual VOP_ParmGeneratorMap * getSubnetVariables()
void getInputTypeInfoSubclass(VOP_TypeInfo &type_info, int idx) override
virtual bool getIsOutputDefinedByParmChild(int idx) const
virtual bool getIsInputDefinedByParmChild(int idx) const
void getOutputTypeInfoSubclass(VOP_TypeInfo &type_info, int idx) override
void updateOwnerSpareParmLayout(bool allow_update_while_loading=false)
Update the owner network's spare parameter layout.
virtual unsigned getNumVisibleOutputs() const
virtual UT_StringArray * getArrayForLoadedOutputNames()
const char * inputLabel(unsigned idx) const override
virtual bool generateErrorsSubclass()
void finishedLoadingNetwork(bool is_child_call=false) override
virtual OP_OperatorFilter * getOperatorFilter()
virtual bool isConnected(int inputidx, bool recursive)
void changeParmTemplate(PRM_Template *new_template) override
virtual void handleOTLIndexFileCleared()
virtual void getSubnetOutputTerminalChild(VOP_Node *&output_vop, int &input_idx, int subnet_output_idx) const
void getInputNameSubclass(UT_String &in, int idx) const override
virtual void unmatchOTLDefinition()
Unmatches (unlocks) the node from the current HDA definition.
bool runCreateScript() override
bool getParmConstantString(const char *parmname, const VOP_TypeInfo &type_info, UT_String &str, bool expand_string, const VOP_Language *language=0) override
Get the constant code that encodes the value of the node parameter.
#define VOP_API
Definition: VOP_API.h:10
virtual UT_IntArray getShaderLayerExportsInputsToCopy(int out_idx, VOP_Type shader_type)
virtual bool canDefineShader() const
static OP_Node * myConstructor(OP_Network *net, const char *name, OP_Operator *op)
bool isUsingCachedCode() const
DEP_MicroNode & eventMicroNode(OP_EventType e)
virtual void shaderParmGrandChildAdded(VOP_Node *grand_child)
virtual int getNumSubnetInputsForChildren() const
virtual VOP_ExportedParmsManager * getVopExportedParmsManager(bool create_if_needed=false)
Definition: OP_Node.h:2710
GLuint const GLchar * name
Definition: glcorearb.h:786
virtual void getVopFunctionArgInfos(UT_Array< VOP_FunctionArgInfo > &arg_infos)
void getOutputNameSubclass(UT_String &out, int idx) const override
virtual void loadStart()
bool forceCodeGenerationOfInputs(const VOP_CodeGenContext &context, bool check_shader_context) const override
virtual void matchOTLDefinition()
virtual UT_StringArray * getArrayForLoadedInputNames()
int getInputFromNameSubclass(const UT_String &in) const override
virtual void beginLoadingInNetwork()
Called upon entering and exiting loadNetwork() method.
virtual void addNode(OP_Node *node, int notify=1, int explicitly=1)
void opChanged(OP_EventType reason, void *data=0) override
void getModulesToImport(UT_StringArray &modules, const VOP_CodeGenContext &context) override
If the node generates a shader call, get the modules names to import.
GLuint index
Definition: glcorearb.h:786
OP_EventType
Definition: OP_Value.h:22
void getCode(UT_String &codestr, const VOP_CodeGenContext &context) override
Get the code fragment to be included in the shader code.
VOP_Type
Enumeration of the built-in (basic) VOP data types.
Definition: VOP_Types.h:25
virtual bool isOperatorAllowedInTabMenu(OP_Operator *op)
Returns ture if the given op can show up in the Tab menu.
virtual void getExtraTypesToDefine(UT_Array< VOP_TypeInfo > &types)
virtual void findAllShaders(VOP_NodeList &shader_nodes, VOP_ShaderTypeList &shader_types, UT_StringArray &output_names)
virtual bool hasCorrespondingInput(int output_idx) const
Returns true if output of a given index has an input by the same name.
virtual int getSubnetInputIndexForChildren(int child_input) const
GLsizei GLenum GLenum * types
Definition: glcorearb.h:2542
virtual bool translatesDirectlyToUSD() const
type
Definition: core.h:1059
virtual void shaderParmGrandChildDeleted(VOP_Node *grand_child)
Definition: format.h:895
virtual int getNumNodeDefinedOutputs() const
const char * outputLabel(unsigned idx) const override
virtual UT_StringHolder getShaderLayerExportsToAdd(int out_idx, VOP_Type shader_type)
virtual void postOpChanged(OP_EventType, void *)
Definition: VOP_Node.h:1455