HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros 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  virtual void getModulesToImport(UT_StringArray &modules,
29  const VOP_CodeGenContext &context);
30  virtual void getOuterCode(UT_String &codestr,
31  const VOP_CodeGenContext &context);
32  virtual void getCode(UT_String &codestr,
33  const VOP_CodeGenContext &context);
34 
35  virtual bool forceCodeGenerationOfInputs(
36  const VOP_CodeGenContext &context,
37  bool check_shader_context) const;
38 
39  virtual bool canDefineShader() const;
40  virtual void getVopFunctionArgInfos(
42 
43  virtual bool getParmConstantString(const char *parmname,
44  const VOP_TypeInfo &type_info,
45  UT_String &str,
46  bool expand_string,
47  const VOP_Language *l=0);
48 
49  virtual const char *inputLabel(unsigned idx) const;
50  virtual const char *outputLabel(unsigned idx) const;
51 
52  virtual unsigned maxInputs() const;
53  virtual unsigned getNumVisibleInputs() const;
54  virtual unsigned getNumVisibleOutputs() const;
55  virtual int getNumNodeDefinedOutputs() const;
56  virtual int getNumSubnetInputsForChildren() const;
57  virtual int getSubnetInputIndexForChildren(int index) const;
58 
59  virtual bool isConnected(int inputidx, bool recursive);
60 
62  bool create_if_needed=false);
63 
64  /// Updates the node so new inuts and outputs are taken into account.
65  /// If op_info argument is NULL, the current operator op info is queried.
66  void updateSubnetWithNewOp(const VOP_OperatorInfo *op_info);
67 
68  static const char *theChildTableName;
69 
70 protected:
71  VOP_SubnetScript(OP_Network *net, const char *name, OP_Operator *entry);
72  virtual ~VOP_SubnetScript();
73 
76  void deleteArraysForLoadedInputAndOutputNames();
78 
79  virtual void beginLoadingInNetwork();
80  virtual void endLoadingInNetwork();
81  virtual void loadStart();
82  virtual void finishedLoadingNetwork(bool is_child_call=false);
83  virtual void setupConnectorsAfterLoad();
84  virtual void changeParmTemplate(PRM_Template *new_template);
85  virtual void addNode(OP_Node *node, int notify=1, int explicitly=1);
86 
87  /// Invalidates the cached list of contained shaders.
88  virtual void dirtyShaderList();
89 
90  /// Overriding these virtuals to control how we create contents network
91  /// @{
92  virtual void matchOTLDefinition();
93  virtual void unmatchOTLDefinition();
94  virtual void handleOTLIndexFileCleared();
95  /// @}
96 
97  /// Inherited from VOP_Node.
98  /// Generate the node errors.
99  /// Return true if an error was generated and false otherwise.
100  virtual bool generateErrorsSubclass();
101 
102  /// Subnet declares own variables, so some types may need to be defined.
104 
105  virtual void opChanged(OP_EventType reason, void *data);
106  virtual void postOpChanged(OP_EventType reason, void *data);
107 
108  /// @{ Methods for handling inputs defined by a parm vop children in
109  /// unlocked assets.
110  void handleChildAdd( OP_Node *child );
111  void handleChildDelete( OP_Node *child );
112  void handleDescendentAdd( VOP_Node *descendent );
113  void handleDescendentDelete( VOP_Node *descendent );
114  static void handleParmNodeChange(OP_Node *caller, void *callee,
115  OP_EventType type, void *);
116  void updateConnectorDefiner( VOP_Node *node);
117  virtual void shaderParmGrandChildAdded(VOP_Node *grand_child);
118  virtual void shaderParmGrandChildDeleted(VOP_Node *grand_child);
119  virtual void shaderParmGrandChildChanged(VOP_Node *grand_child);
120  void setupConnectorDefinersAfterLoadIfNeeded(
121  const VOP_OperatorInfo *op_info);
122  void setupConnectorDefinersAfterLoad(
123  const VOP_OperatorInfo *op_info);
124  void addConnectorDefinerAfterLoad(VOP_ParmGenerator *pg,
125  const VOP_OperatorInfo *op_info,
129  UT_Array< VOP_ParmGenerator* > &append_out );
130  int verifyOpInputIndexForNode(int idx) const;
131  /// @}
132 
133  virtual void getInputNameSubclass(UT_String &in, int idx) const;
134  virtual int getInputFromNameSubclass(const UT_String &in) const;
135  virtual void getInputTypeInfoSubclass(
136  VOP_TypeInfo &type_info, int idx);
137  virtual bool getIsInputDefinedByParmChild(int idx) const;
138  virtual bool getIsOutputDefinedByParmChild(int idx) const;
139 
140  virtual void getOutputNameSubclass(UT_String &out, int idx) const;
141  virtual void getOutputTypeInfoSubclass(VOP_TypeInfo &type_info,
142  int idx);
144  VOP_Type shader_type);
145  virtual UT_StringHolder getShaderLayerExportsToAdd(int out_idx,
146  VOP_Type shader_type);
147 
148  /// Returns true if output of a given index has an input by the same name.
149  virtual bool hasCorrespondingInput(int output_idx) const;
150 
152  {
155  .requiresUpdate(0.0))
156  {
159  }
160  }
161 
162  /// Returns true if the subnet script (HDA) is using cached code
163  /// rather than generating it from the children.
164  bool isUsingCachedCode() const
165  { return myIsUsingCachedCode; }
166 
167  /// @{ Helpers for managing script info object
168  virtual void loadMaterialInfo();
169  virtual void unloadMaterialInfo();
170  /// @}
171 
172 private:
173  struct vop_EncapsulatedMetaData
174  {
175  vop_EncapsulatedMetaData() : myIsValid(false) {}
176 
177  bool myIsValid;
178  UT_SortedStringMap<UT_String> myIsConnectedMap;
179  };
180 
181  bool parseMetaDataString(UT_String &str,
182  vop_EncapsulatedMetaData &md);
183  void parseEncapsulatedMetaData(const UT_WorkBuffer &code,
184  vop_EncapsulatedMetaData &md);
185 
186  void adjustChildrenForInputRemoval(int idx);
187  void adjustChildrenForInputInsertion(int idx);
188 
189 private:
190  /// Forward declaration of our embedded VOP_SubnetHelper::SubnetAPI
191  /// subclass.
192  class SubnetAPI;
193 
194  friend class SubnetAPI;
195 
196  /// Helper that factors out methods shared with regular subnetwork.
197  VOP_SubnetHelper *mySubnetHelper;
198 
199  /// Used during loading to find out input and output names just in case
200  /// we need to order Parameter VOP defined inputs/outputs in assets not
201  /// matching their definition.
202  UT_StringArray *myLoadedInputNames;
203  UT_StringArray *myLoadedOutputNames;
204 
205  /// A flag indicating if node is exclusively using cached vex/vfl code.
206  bool myIsUsingCachedCode;
207 
208  /// We're deleting a mass of nodes. We don't care about knowing whether
209  /// we just lost one.
210  bool myIsDeletingSubnetNodes;
211 
212  /// We're in setupConnectorDefinersAfterLoad().
213  unsigned myIsSettingUpConnectorDefinersAfterLoad : 1,
214  myIsLoadingNetwork : 1,
215  myAreConnectorsSetUp : 1;
216 };
217 
218 #endif
Reprsents a language for which VOPs can generate source code.
Definition: VOP_Language.h:27
virtual void endLoadingInNetwork()
virtual void getOutputTypeInfoSubclass(VOP_TypeInfo &type_info, int idx)
virtual void ensureSpareParmsAreUpdatedSubclass()
virtual void dirtyShaderList()
Some material vops cache a list of shader that needs to be dirtied.
virtual void getCode(UT_String &codestr, const VOP_CodeGenContext &context)
Get the code fragment to be included in the shader code.
virtual void shaderParmGrandChildChanged(VOP_Node *grand_child)
virtual unsigned maxInputs() const
Maximum inputs that can be connected to a node.
virtual bool forceCodeGenerationOfInputs(const VOP_CodeGenContext &context, bool check_shader_context) const
static const char * theChildTableName
virtual void setupConnectorsAfterLoad()
virtual void opChanged(OP_EventType reason, void *data=0)
virtual unsigned getNumVisibleInputs() const
virtual VOP_ParmGeneratorMap * getSubnetVariables()
virtual bool getIsOutputDefinedByParmChild(int idx) const
virtual bool getIsInputDefinedByParmChild(int idx) const
void updateOwnerSpareParmLayout(bool allow_update_while_loading=false)
Update the owner network's spare parameter layout.
virtual unsigned getNumVisibleOutputs() const
virtual UT_StringArray * getArrayForLoadedOutputNames()
virtual bool generateErrorsSubclass()
virtual const char * inputLabel(unsigned idx) const
virtual bool getParmConstantString(const char *parmname, const VOP_TypeInfo &type_info, UT_String &str, bool expand_string, const VOP_Language *language=0)
Get the constant code that encodes the value of the node parameter.
virtual void getInputTypeInfoSubclass(VOP_TypeInfo &type_info, int idx)
virtual OP_OperatorFilter * getOperatorFilter()
virtual bool isConnected(int inputidx, bool recursive)
virtual void handleOTLIndexFileCleared()
virtual int getInputFromNameSubclass(const UT_String &in) const
virtual void unmatchOTLDefinition()
Unmatches (unlocks) the node from the current HDA definition.
#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)
Definition: OP_Node.h:1544
virtual void shaderParmGrandChildAdded(VOP_Node *grand_child)
virtual int getNumSubnetInputsForChildren() const
virtual void getModulesToImport(UT_StringArray &modules, const VOP_CodeGenContext &context)
If the node generates a shader call, get the modules names to import.
virtual VOP_ExportedParmsManager * getVopExportedParmsManager(bool create_if_needed=false)
Definition: OP_Node.h:2539
GLboolean * data
Definition: glcorearb.h:130
virtual void getVopFunctionArgInfos(UT_Array< VOP_FunctionArgInfo > &arg_infos)
GLuint const GLchar * name
Definition: glcorearb.h:785
virtual const char * outputLabel(unsigned idx) const
virtual void loadStart()
virtual void matchOTLDefinition()
virtual UT_StringArray * getArrayForLoadedInputNames()
virtual void beginLoadingInNetwork()
Called upon entering and exiting loadNetwork() method.
virtual void addNode(OP_Node *node, int notify=1, int explicitly=1)
virtual void changeParmTemplate(PRM_Template *new_template)
GLuint index
Definition: glcorearb.h:785
virtual void getInputNameSubclass(UT_String &in, int idx) const
virtual void finishedLoadingNetwork(bool is_child_call=false)
OP_EventType
Definition: OP_Value.h:22
VOP_Type
Definition: VOP_Types.h:24
GLint GLint GLsizei GLint GLenum GLenum type
Definition: glcorearb.h:107
virtual void getExtraTypesToDefine(UT_Array< VOP_TypeInfo > &types)
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:2541
virtual void getOutputNameSubclass(UT_String &out, int idx) const
virtual void getOuterCode(UT_String &codestr, const VOP_CodeGenContext &context)
virtual void shaderParmGrandChildDeleted(VOP_Node *grand_child)
virtual int getNumNodeDefinedOutputs() const
virtual UT_StringHolder getShaderLayerExportsToAdd(int out_idx, VOP_Type shader_type)
virtual void postOpChanged(OP_EventType, void *)
Definition: VOP_Node.h:1324