HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
VOP_Switch.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_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  virtual bool updateParmsFlags();
51 
52  /// Generate the code for this operator.
53  virtual void getCode(UT_String &codestr,
54  const VOP_CodeGenContext &context);
55 
56  /// Provides the labels to appear on input and output buttons.
57  virtual const char *inputLabel(unsigned idx) const;
58  virtual const char *outputLabel(unsigned idx) const;
59 
60  /// Controls the number of input buttons visible on the node tile.
61  virtual unsigned getNumVisibleInputs() const;
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  virtual unsigned orderedInputs() const;
66 
67 protected:
68  VOP_Switch(OP_Network *net, const char *name, OP_Operator *entry);
69  virtual ~VOP_Switch();
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  virtual void getInputNameSubclass(UT_String &in, int idx) const;
74  /// Reverse mapping of internal input names to an input index.
75  virtual int getInputFromNameSubclass(const UT_String &in) const;
76  /// Fills in the info about the vop type connected to the idx-th input.
77  virtual void getInputTypeInfoSubclass(VOP_TypeInfo &type_info,
78  int idx);
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  virtual void getOutputNameSubclass(UT_String &out, int idx) const;
83  /// Fills out the info about the data type of each output connector.
84  virtual void getOutputTypeInfoSubclass(VOP_TypeInfo &type_info,
85  int idx);
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  virtual void getAllowedInputTypeInfosSubclass( unsigned idx,
93  VOP_VopTypeInfoArray &type_infos);
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
virtual void getOutputTypeInfoSubclass(VOP_TypeInfo &type_info, int idx)
Fills out the info about the data type of each output connector.
Definition: VOP_Switch.C:302
C++ VOP node to select one of its inputs and feed it into the output.
Definition: VOP_Switch.h:38
virtual void getOutputNameSubclass(UT_String &out, int idx) const
Definition: VOP_Switch.C:294
virtual unsigned getNumVisibleInputs() const
Controls the number of input buttons visible on the node tile.
Definition: VOP_Switch.C:312
virtual void getAllowedInputTypeInfosSubclass(unsigned idx, VOP_VopTypeInfoArray &type_infos)
Definition: VOP_Switch.C:263
VOP_Switch(OP_Network *net, const char *name, OP_Operator *entry)
Definition: VOP_Switch.C:96
virtual const char * outputLabel(unsigned idx) const
Definition: VOP_Switch.C:209
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
virtual void getCode(UT_String &codestr, const VOP_CodeGenContext &context)
Generate the code for this operator.
Definition: VOP_Switch.C:118
virtual int getInputFromNameSubclass(const UT_String &in) const
Reverse mapping of internal input names to an input index.
Definition: VOP_Switch.C:233
virtual void getInputNameSubclass(UT_String &in, int idx) const
Definition: VOP_Switch.C:217
GLuint const GLchar * name
Definition: glcorearb.h:785
virtual void getInputTypeInfoSubclass(VOP_TypeInfo &type_info, int idx)
Fills in the info about the vop type connected to the idx-th input.
Definition: VOP_Switch.C:249
static PRM_Template myTemplateList[]
Our parameter templates.
Definition: VOP_Switch.h:47
virtual bool updateParmsFlags()
Disable our parameters based on which inputs are connected.
Definition: VOP_Switch.C:106
virtual const char * inputLabel(unsigned idx) const
Provides the labels to appear on input and output buttons.
Definition: VOP_Switch.C:190
virtual unsigned orderedInputs() const
Definition: VOP_Switch.C:325