HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
VOP_CustomContext.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2018
3  * Side Effects Software Inc. All rights reserved.
4  *
5  * Redistribution and use of Houdini Development Kit samples in source and
6  * binary forms, with or without modification, are permitted provided that the
7  * following conditions are met:
8  * 1. Redistributions of source code must retain the above copyright notice,
9  * this list of conditions and the following disclaimer.
10  * 2. The name of Side Effects Software may not be used to endorse or
11  * promote products derived from this software without specific prior
12  * written permission.
13  *
14  * THIS SOFTWARE IS PROVIDED BY SIDE EFFECTS SOFTWARE `AS IS' AND ANY EXPRESS
15  * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
16  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
17  * NO EVENT SHALL SIDE EFFECTS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
18  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
19  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
20  * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
21  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
22  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
23  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 */
25 
26 #ifndef __VOP_CustomContext_h__
27 #define __VOP_CustomContext_h__
28 
29 #include <SOP/SOP_Node.h>
30 #include <VOP/VOP_Node.h>
31 #include <OP/OP_OperatorTable.h>
32 #include <SYS/SYS_Types.h>
33 
34 /// @file
35 /// This example contains code which shows how to create a custom VOP SOP in
36 /// the HDK. The custom VOP nodes within can dynamically change their inputs
37 /// and outputs. For simplicity, the Custom VOP SOP does not generate any
38 /// geometry.
39 namespace HDK_Sample {
40 
42 {
43 public:
44  virtual bool allowOperatorAsChild(OP_Operator *op);
45 };
46 
47 /// C++ SOP node to provide the custom VOP context
48 class SOP_CustomVop : public SOP_Node
49 {
50 public:
51  /// Creates an instance of this node with the given name in the given
52  /// network.
53  static OP_Node * myConstructor(
54  OP_Network *net,
55  const char *name,
56  OP_Operator *entry);
57 
58  /// Our parameter templates.
60 
61  /// We override these to specify that our child network type is VOPs.
62  // @{
63  virtual const char * getChildType() const;
64  virtual OP_OpTypeId getChildTypeID() const;
65  // @}
66 
67  /// Override this to provide custom behaviour for what is allowed in the
68  /// tab menu.
70  { return &myOperatorFilter; }
71 
72  /// Override this to do VOP network evaluation
73  virtual OP_ERROR cookMySop(OP_Context &context);
74 
75  static const char *theChildTableName;
76 
77 protected:
79  OP_Network *net,
80  const char *name,
81  OP_Operator *entry);
82  virtual ~SOP_CustomVop();
83 
84 private:
85  OP_OperatorTable * createAndGetOperatorTable();
86 
87 private:
88  SOP_CustomVopOperatorFilter myOperatorFilter;
89 };
90 
91 /// C++ VOP node to select one of its inputs and feed it into the output.
92 class VOP_CustomVop : public VOP_Node
93 {
94 public:
95  /// Creates an instance of this node with the given name in the given
96  /// network.
97  static OP_Node * myConstructor(
98  OP_Network *net,
99  const char *name,
100  OP_Operator *entry);
101 
102  /// Our parameter templates.
104 
105  /// This function is called to run the creation script (if there is one).
106  /// The return value is false if the node was deleted while running the
107  /// script. In this case obviously the node pointer becomes invalid and
108  /// should not be used any more. It returns true if the node still exists.
109  ///
110  /// We override this in order to perform initial creation we are created
111  /// created for the first time in a .hip file. This function is NOT called
112  /// when being loaded from .hip files.
113  virtual bool runCreateScript();
114 
115  /// Provides the labels to appear on input and output buttons.
116  // @{
117  virtual const char * inputLabel(unsigned idx) const;
118  virtual const char * outputLabel(unsigned idx) const;
119  // @}
120 
121  /// Controls the number of input/output buttons visible on the node tile.
122  // @{
123  virtual unsigned getNumVisibleInputs() const;
124  virtual unsigned getNumVisibleOutputs() const;
125  // @}
126 
127  /// Returns the index of the first "unordered" input, meaning that inputs
128  /// before this one should not be collapsed when they are disconnected.
129  /// In this example, we don't need to implement this.
130  //virtual unsigned orderedInputs() const;
131 
132 protected:
134  OP_Network *net,
135  const char *name,
136  OP_Operator *entry);
137  virtual ~VOP_CustomVop();
138 
139  /// Returns the internal name of the supplied input. This input name is
140  /// used when the code generator substitutes variables return by getCode.
141  virtual void getInputNameSubclass(
142  UT_String &name,
143  int idx) const;
144  /// Reverse mapping of internal input names to an input index.
145  virtual int getInputFromNameSubclass(
146  const UT_String &name) const;
147  /// Fills in the info about the vop type connected to the idx-th input.
148  virtual void getInputTypeInfoSubclass(
149  VOP_TypeInfo &type_info, int idx);
150 
151  /// Returns the internal name of the supplied output. This name is used
152  /// when the code generator substitutes variables return by getCode.
153  virtual void getOutputNameSubclass(
154  UT_String &out,
155  int idx) const;
156  /// Fills out the info about data type of each output connector.
157  virtual void getOutputTypeInfoSubclass(
158  VOP_TypeInfo &type_info, int idx);
159 
160  /// This methods should be overriden in most VOP nodes. It should fill in
161  /// voptypes vector with vop types that are allowed to be connected to this
162  /// node at the input at index idx. Note that
163  /// this method should return valid vop types even
164  /// when nothing is connected to the corresponding input.
166  unsigned idx,
167  VOP_VopTypeInfoArray &type_infos);
168 
169 private:
170  static void nodeEventHandler(
171  OP_Node *caller,
172  void *callee,
174  void *data);
175 
176  void handleParmChanged(int parm_index);
177 
178 private:
179 
180 };
181 
182 } // End of HDK_Sample namespace
183 
184 #endif // __VOP_CustomContext_h__
static const char * theChildTableName
virtual OP_ERROR cookMySop(OP_Context &context)
Override this to do VOP network evaluation.
UT_ErrorSeverity
Definition: UT_Error.h:25
virtual void getOutputNameSubclass(UT_String &out, int idx) const
virtual const char * getChildType() const
We override these to specify that our child network type is VOPs.
virtual unsigned getNumVisibleOutputs() const
C++ VOP node to select one of its inputs and feed it into the output.
static OP_Node * myConstructor(OP_Network *net, const char *name, OP_Operator *entry)
virtual const char * inputLabel(unsigned idx) const
Provides the labels to appear on input and output buttons.
virtual void getOutputTypeInfoSubclass(VOP_TypeInfo &type_info, int idx)
Fills out the info about data type of each output connector.
static OP_Node * myConstructor(OP_Network *net, const char *name, OP_Operator *entry)
virtual OP_OpTypeId getChildTypeID() const
We override these to specify that our child network type is VOPs.
static PRM_Template myTemplateList[]
Our parameter templates.
VOP_CustomVop(OP_Network *net, const char *name, OP_Operator *entry)
GLboolean * data
Definition: glcorearb.h:130
GLuint const GLchar * name
Definition: glcorearb.h:785
virtual void getAllowedInputTypeInfosSubclass(unsigned idx, VOP_VopTypeInfoArray &type_infos)
OP_OpTypeId
Definition: OP_Node.h:263
virtual unsigned getNumVisibleInputs() const
Controls the number of input/output buttons visible on the node tile.
virtual void getInputTypeInfoSubclass(VOP_TypeInfo &type_info, int idx)
Fills in the info about the vop type connected to the idx-th input.
virtual const char * outputLabel(unsigned idx) const
Provides the labels to appear on input and output buttons.
static PRM_Template myTemplateList[]
Our parameter templates.
SOP_CustomVop(OP_Network *net, const char *name, OP_Operator *entry)
OP_EventType
Definition: OP_Value.h:22
virtual int getInputFromNameSubclass(const UT_String &name) const
Reverse mapping of internal input names to an input index.
virtual void getInputNameSubclass(UT_String &name, int idx) const
GLint GLint GLsizei GLint GLenum GLenum type
Definition: glcorearb.h:107
C++ SOP node to provide the custom VOP context.
virtual bool allowOperatorAsChild(OP_Operator *op)
virtual OP_OperatorFilter * getOperatorFilter()