HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
VOP_Switch.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2022
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_Switch_h__
27 #define __VOP_Switch_h__
28 
29 #include <VOP/VOP_Node.h>
30 
31 /// @file
32 /// This example contains code which shows how to perform some of the most
33 /// common tasks when writing a custom VEX code operator. It produces code
34 /// which selects one of the inputs to feed to the output.
35 namespace HDK_Sample {
36 
37 /// C++ VOP node to select one of its inputs and feed it into the output.
38 class VOP_Switch : public VOP_Node
39 {
40 public:
41  /// Creates an instance of this node with the given name in the given network.
42  static OP_Node *myConstructor(OP_Network *net,
43  const char *name,
44  OP_Operator *entry);
45 
46  /// Our parameter templates.
48 
49  /// Disable our parameters based on which inputs are connected.
50  bool updateParmsFlags() override;
51 
52  /// Generate the code for this operator.
53  void getCode(UT_String &codestr,
54  const VOP_CodeGenContext &context) override;
55 
56  /// Provides the labels to appear on input and output buttons.
57  const char *inputLabel(unsigned idx) const override;
58  const char *outputLabel(unsigned idx) const override;
59 
60  /// Controls the number of input buttons visible on the node tile.
61  unsigned getNumVisibleInputs() const override;
62 
63  /// Returns the index of the first "unordered" input, meaning that inputs
64  /// before this one should not be collapsed when they are disconnected.
65  unsigned orderedInputs() const override;
66 
67 protected:
68  VOP_Switch(OP_Network *net, const char *name, OP_Operator *entry);
69  ~VOP_Switch() override;
70 
71  /// Returns the internal name of the supplied input. This input name is
72  /// used when the code generator substitutes variables return by getCode.
73  void getInputNameSubclass(UT_String &in, int idx) const override;
74  /// Reverse mapping of internal input names to an input index.
75  int getInputFromNameSubclass(const UT_String &in) const override;
76  /// Fills in the info about the vop type connected to the idx-th input.
77  void getInputTypeInfoSubclass(VOP_TypeInfo &type_info,
78  int idx) override;
79 
80  /// Returns the internal name of the supplied output. This name is used
81  /// when the code generator substitutes variables return by getCode.
82  void getOutputNameSubclass(UT_String &out, int idx) const override;
83  /// Fills out the info about the data type of each output connector.
84  void getOutputTypeInfoSubclass(VOP_TypeInfo &type_info,
85  int idx) override;
86 
87  /// This methods should be overriden in most VOP nodes. It should fill
88  /// in voptypes vector with vop types that are allowed to be connected
89  /// to this node at the input at index idx. Note that
90  /// this method should return valid vop types even when nothing is
91  /// connected to the corresponding input.
92  void getAllowedInputTypeInfosSubclass(unsigned idx,
93  VOP_VopTypeInfoArray &type_infos) override;
94 
95  /// Accesses the parameter that controls how out of bounds switch indices
96  /// are handled.
97  int OUTOFBOUNDS();
98 };
99 
100 } // End of HDK_Sample namespace
101 
102 #endif
void getOutputNameSubclass(UT_String &out, int idx) const override
Definition: VOP_Switch.C:294
C++ VOP node to select one of its inputs and feed it into the output.
Definition: VOP_Switch.h:38
VOP_Switch(OP_Network *net, const char *name, OP_Operator *entry)
Definition: VOP_Switch.C:96
void getInputNameSubclass(UT_String &in, int idx) const override
Definition: VOP_Switch.C:217
GLuint const GLchar * name
Definition: glcorearb.h:786
const char * outputLabel(unsigned idx) const override
Definition: VOP_Switch.C:209
void getAllowedInputTypeInfosSubclass(unsigned idx, VOP_VopTypeInfoArray &type_infos) override
Definition: VOP_Switch.C:263
GLuint in
Definition: glew.h:11552
~VOP_Switch() override
Definition: VOP_Switch.C:101
void getOutputTypeInfoSubclass(VOP_TypeInfo &type_info, int idx) override
Fills out the info about the data type of each output connector.
Definition: VOP_Switch.C:302
unsigned getNumVisibleInputs() const override
Controls the number of input buttons visible on the node tile.
Definition: VOP_Switch.C:312
static OP_Node * myConstructor(OP_Network *net, const char *name, OP_Operator *entry)
Creates an instance of this node with the given name in the given network.
Definition: VOP_Switch.C:82
void getInputTypeInfoSubclass(VOP_TypeInfo &type_info, int idx) override
Fills in the info about the vop type connected to the idx-th input.
Definition: VOP_Switch.C:249
bool updateParmsFlags() override
Disable our parameters based on which inputs are connected.
Definition: VOP_Switch.C:106
void getCode(UT_String &codestr, const VOP_CodeGenContext &context) override
Generate the code for this operator.
Definition: VOP_Switch.C:118
unsigned orderedInputs() const override
Definition: VOP_Switch.C:325
const char * inputLabel(unsigned idx) const override
Provides the labels to appear on input and output buttons.
Definition: VOP_Switch.C:190
static PRM_Template myTemplateList[]
Our parameter templates.
Definition: VOP_Switch.h:47
int getInputFromNameSubclass(const UT_String &in) const override
Reverse mapping of internal input names to an input index.
Definition: VOP_Switch.C:233