HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
VOP_SubnetBase.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  * COMMENTS: The base class for all subnet VOP operators
9  *
10  */
11 
12 #ifndef __VOP_SubnetBase_h__
13 #define __VOP_SubnetBase_h__
14 
15 #include "VOP_API.h"
16 #include "VOP_Node.h"
18 #include <UT/UT_StringArray.h>
19 
20 class VOP_SubnetHelper;
21 
23 {
24 public:
26 
27  void getCode(UT_String &codestr,
28  const VOP_CodeGenContext &context) override;
29 
30  const char *inputLabel(unsigned idx) const override;
31  const char *outputLabel(unsigned idx) const override;
32 
33  unsigned getNumVisibleInputs() const override;
34  unsigned getNumRealInputs() const;
35  unsigned getNumVisibleOutputs() const override;
36  unsigned orderedInputs() const override;
37 
39  OP_Context &context,
40  OP_NodeInfoParms &iparms) override;
41 
42  // When one of our inputs changes, we may want to rearrange things on
43  // our subnet input and subnet output nodes.
44  OP_ERROR setInput(unsigned idx, OP_Node *op,
45  unsigned outputIdx = 0) override;
47  unsigned idx,
48  const char *label,
49  int keeppos,
50  unsigned outputIdx = 0) override;
52  const OP_ConnectorId& input_name,
53  OP_Node *op,
54  const OP_ConnectorId* output_name = nullptr
55  ) override;
57  const OP_ConnectorId& input_name,
58  const char *label,
59  int,
60  const OP_ConnectorId* output_name = nullptr
61  ) override;
62 
63 
64  bool isConnected(int inputidx, bool recursive) override;
65 
66  const VOP_SubnetBase *castToSubnetBase() const override { return this; }
67  VOP_SubnetBase *castToSubnetBase() override { return this; }
68 
70  const VOP_CodeGenContext &context,
71  bool check_shader_context) const override;
72  bool getIsAdjustForInputChanged();
73 
75  bool create_if_needed=false) override;
76 
77  static const char *theChildTableName;
78 
79 protected:
80  VOP_SubnetBase(OP_Network *parent, const char *name, OP_Operator *entry);
81  ~VOP_SubnetBase() override;
82 
83  bool updateParmsFlags() override;
84  virtual bool shouldShowInputNext() const;
85 
89  void beginLoadingInNetwork() override;
90  void endLoadingInNetwork() override;
91  void loadStart() override;
93  bool is_child_call=false) override;
94  void setupConnectorsAfterLoad() override;
95  void addNode(OP_Node *node, int notify=1,
96  int explicitly=1) override;
97  bool isOperatorAllowedInTabMenu(OP_Operator *op) override;
98 
99  /// Inherited from VOP_Node.
100  /// Generate the node errors.
101  /// Return true if an error was generated and false otherwise.
102  bool generateErrorsSubclass() override;
103 
104  void preOpChanged(OP_EventType reason, void *data) override;
105  void postOpChanged(
106  OP_EventType reason, void *data) override;
107 
108  /// @{ Methods for handling inputs defined by a parm vop children
109  void handleChildAdd( OP_Node *child );
110  void handleChildDelete( OP_Node *child );
111  void handleDescendentAdd( VOP_Node *descendent );
112  void handleDescendentDelete( VOP_Node *descendent );
113  static void handleParmNodeChange(OP_Node *caller, void *callee,
114  OP_EventType type, void *);
115  void updateConnectorDefiner( VOP_Node *node );
117  VOP_Node *grand_child) override;
119  VOP_Node *grand_child) override;
121  VOP_Node *grand_child) override;
122  void setupConnectorDefinersAfterLoadIfNeeded();
123  void setupConnectorDefinersAfterLoad();
124  void addConnectorDefinerAfterLoad(VOP_ParmGenerator *pg);
125  /// @}
126 
127  virtual void getInternalInputName(UT_String &in, int idx) const;
128 
129  virtual int getNumDefinedInputs() const;
130  virtual void getDefinedInputDefault(UT_String &def, int idx) const;
132  UT_String &def, int idx) const override;
133 
135  UT_String &in, int idx) const override;
137  const UT_String &in) const override;
139  VOP_TypeInfo &type_info, int idx) override;
141  unsigned idx,
142  VOP_VopTypeArray &voptypes) override;
143  bool allowConsolidatingInput(int idx) override;
144 
145  /// Invalidates the cached list of contained shaders.
146  bool runCreateScript() override;
147  void dirtyShaderList() override;
148  void findAllShaders(
149  VOP_NodeList &shader_nodes,
150  VOP_ShaderTypeList &shader_types,
151  UT_StringArray &output_names) override;
152 
153  /// Returns true if subnet can be translated into Material or NodeGraph.
154  bool translatesDirectlyToUSD() const override;
155 
156  /// Number of extra outputs a subnet subclass may want to provide, in
157  /// addition to outputs defined by this base class (and sub output child).
158  virtual int getNumCustomOutputs() const;
159 
160  /// Number of extra outputs on the subnet node in addition to the
161  /// outputs defined by the Subnet Output child vop inside.
162  int getNumNodeDefinedOutputs() const override;
163  int getNumSubnetInputsForChildren() const override;
165  int index) const override;
167  UT_String &out, int idx) const override;
169  VOP_TypeInfo &type_info, int idx) override;
171  int out_idx, VOP_Type shader_type) override;
173  int out_idx, VOP_Type shader_type) override;
175  VOP_Node * &output_vop,
176  int &input_idx,
177  int subnet_output_idx) const override;
178 
179  /// Returns true if output of a given index has an input by the same name.
180  bool hasCorrespondingInput(int output_idx) const;
181 
183  int input_idx) const override;
185  const OP_ConnectorId& input_name
186  ) const override;
187 
188  /// Subnet declares own variables, so some types may need to be defined.
190  UT_Array<VOP_TypeInfo> &types ) override;
191 
192  /// Virtuals for handling input order editing.
193  int getInputEditorInputs() override;
195  UT_String &label, int idx ) override;
196  void moveInput(
197  int srcidx,
198  int dstidx,
199  bool forcesubnet = false) override;
200  void doDeleteInput(int idx) override;
201 
202 
204  {
207  .requiresUpdate(0.0))
208  {
211  }
212  }
213 
214 private:
215  /// inputnull is true if the input is about to become null, and false if it
216  /// is about to be connected.
217  void adjustChildrenForInputChange(int idx,
218  int child_input_idx,
219  bool inputnull, bool force,
220  bool allow_disconnection,
221  bool allow_connection);
222  int preSetSubnetInput(int idx, bool inputnull);
223  void postSetSubnetInput(int idx, bool inputnull,
224  int child_input_idx);
225  void findSafeBase(UT_String &in) const;
226  bool isConnectedInside(int idx,
227  bool include_outputs,
228  bool include_parm_definers) const;
229  // Note that this expects a subnet input name, i.e. the name not yet
230  // prefixed with VOP_SUBNET_VARIABLE_PREFIX.
231  bool isConnectedInsideNamed(
232  const OP_ConnectorId& input_name,
233  bool include_parm_definers) const;
234  void deleteArraysForLoadedInputAndOutputNames();
235 
236 private:
237  /// Forward declaration of our embedded VOP_SubnetHelper::SubnetAPI
238  /// subclass.
239  class SubnetAPI;
240 
241  friend class SubnetAPI;
242 
243  UT_StringArray myInputNames;
244  unsigned myIsAdjustingForInputChange : 1,
245  myIsAppendingDefinedInput : 1,
246  myIsSettingUpConnectorDefinersAfterLoad : 1,
247  myIsLoadingNetwork : 1,
248  myAreConnectorsSetUp : 1;
249 
250  /// Helper that factors out methods shared with regular subnetwork.
251  VOP_SubnetHelper *mySubnetHelper;
252 
253  /// Used during loading to find out input and output names.
254  UT_StringArray *myLoadedInputNames;
255  UT_StringArray *myLoadedOutputNames;
256 };
257 
258 #endif
virtual int getInputFromNameSubclass(const UT_String &in) const
virtual void endLoadingInNetwork()
void moveInput(int srcidx, int dstidx, bool forcesubnet=false) override
virtual void dirtyShaderList()
Some material vops cache a list of shader that needs to be dirtied.
GLuint GLsizei const GLchar * label
Definition: glcorearb.h:2545
virtual void getAllowedInputTypesSubclass(unsigned idx, VOP_VopTypeArray &voptypes)
OP_ERROR setNamedInputReference(const OP_ConnectorId &input_name, const char *label, int, const OP_ConnectorId *output_name=nullptr) override
virtual void shaderParmGrandChildChanged(VOP_Node *grand_child)
VOP_SubnetBase * castToSubnetBase() override
virtual void setupConnectorsAfterLoad()
virtual void doDeleteInput(int idx)
Performs actual removal from the member input array.
virtual bool forceCodeGenerationOfInputs(const VOP_CodeGenContext &context, bool check_shader_context) const
virtual unsigned getNumVisibleInputs() const
virtual VOP_ParmGeneratorMap * getSubnetVariables()
bool updateParmsFlags() override
virtual const char * inputLabel(unsigned idx) const
OP_ERROR setInput(unsigned idx, OP_Node *op, unsigned outputIdx=0) override
UT_ErrorSeverity
Definition: UT_Error.h:25
Parameters for OP_Node::getInfoText()/OP_Node::getNodeSpecificInfoText()
void updateOwnerSpareParmLayout(bool allow_update_while_loading=false)
Update the owner network's spare parameter layout.
virtual unsigned getNumVisibleOutputs() const
virtual UT_StringArray * getArrayForLoadedOutputNames()
OP_ERROR setInputReference(unsigned idx, const char *label, int keeppos, unsigned outputIdx=0) override
Connects an input to particular node by name in the network.
virtual bool generateErrorsSubclass()
void finishedLoadingNetwork(bool is_child_call=false) override
virtual void getInputTypeInfoSubclass(VOP_TypeInfo &type_info, int idx)
virtual OP_OperatorFilter * getOperatorFilter()
virtual bool isConnected(int inputidx, bool recursive)
virtual void getSubnetOutputTerminalChild(VOP_Node *&output_vop, int &input_idx, int subnet_output_idx) const
static const char * theChildTableName
void getNodeSpecificInfoText(OP_Context &context, OP_NodeInfoParms &iparms) override
bool runCreateScript() override
#define VOP_API
Definition: VOP_API.h:10
virtual bool isNamedInputConnectedInsideSubnet(const OP_ConnectorId &input_name) const
virtual UT_IntArray getShaderLayerExportsInputsToCopy(int out_idx, VOP_Type shader_type)
virtual bool allowConsolidatingInput(int idx)
void ensureSpareParmsAreUpdatedSubclass() override
virtual void preOpChanged(OP_EventType, void *)
Definition: VOP_Node.h:1453
DEP_MicroNode & eventMicroNode(OP_EventType e)
virtual void shaderParmGrandChildAdded(VOP_Node *grand_child)
virtual bool getInputEditorInputLabel(UT_String &label, int idx)
virtual int getNumSubnetInputsForChildren() const
virtual VOP_ExportedParmsManager * getVopExportedParmsManager(bool create_if_needed=false)
Definition: OP_Node.h:2731
virtual unsigned orderedInputs() const
GLuint const GLchar * name
Definition: glcorearb.h:786
virtual void loadStart()
virtual UT_StringArray * getArrayForLoadedInputNames()
virtual int getInputEditorInputs()
virtual void getCode(UT_String &codestr, const VOP_CodeGenContext &context)
Get the code fragment to be included in the shader code.
virtual void beginLoadingInNetwork()
Called upon entering and exiting loadNetwork() method.
virtual void addNode(OP_Node *node, int notify=1, int explicitly=1)
SIM_API const UT_StringHolder force
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 getInputNameSubclass(UT_String &in, int idx) const
virtual bool isOperatorAllowedInTabMenu(OP_Operator *op)
Returns true 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 void getInputDefaultValue(UT_String &def, int idx) const
Gets a default value of an explicitly defined input (applies to subnets)
const VOP_SubnetBase * castToSubnetBase() const override
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 bool isInputConnectedInsideSubnet(int input_idx) const
virtual void shaderParmGrandChildDeleted(VOP_Node *grand_child)
Definition: format.h:895
OP_ERROR setNamedInput(const OP_ConnectorId &input_name, OP_Node *op, const OP_ConnectorId *output_name=nullptr) override
New input functions that use names instead of indices.
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:1455