HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
VOP_ParmGenerator.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: ParmGenerator VOP operator.
9  *
10  */
11 
12 #ifndef __VOP_ParmGenerator_h__
13 #define __VOP_ParmGenerator_h__
14 
15 #include "VOP_API.h"
16 #include "VOP_Node.h"
17 #include <CH/CH_ExprLanguage.h>
18 
22 
24 {
25 public:
26  // Get the "isbound" code, if it's needed.
27  virtual void getCode(UT_String &codestr,
28  const VOP_CodeGenContext &context);
29 
30  virtual unsigned getNumVisibleInputs() const;
31  virtual bool forceCodeGenerationOfInputs(
32  const VOP_CodeGenContext &ctx,
33  bool check_shader_context) const;
34 
35  virtual const char *outputLabel(unsigned idx) const;
36  virtual bool areOutputVariablesFixed(
37  const VOP_CodeGenContext &context);
39  virtual void getFixedOutputVariable(UT_String &var,int idx);
40 
41  virtual bool getIsParmGenerator() const;
42  virtual const VOP_ParmGenerator *castToParmGenerator() const { return this;}
43  virtual VOP_ParmGenerator *castToParmGenerator() { return this; }
44 
45  virtual void initializeNode();
46  virtual VOP_Node *getRealDefinition();
47 
48  virtual void opChanged(OP_EventType reason, void *data=0);
49 
50  /// @{ Obtains the scope for this parameter.
51  static const char* const SCOPE_SHADER; // shader parm (on SHOP)
52  static const char* const SCOPE_CLASS; // class member variable
53  static const char* const SCOPE_METHOD; // method argument
54  static const char* const SCOPE_SUBNET; // subnet input (and output)
55  void getParmScope(UT_String &scope);
56  bool isSubnetParameterDefiner(VOP_Node *subnet = nullptr) const;
57  bool isSubnetInputOrOutputDefiner(VOP_Node *subnet = nullptr) const;
58  bool isSubnetInputDefiner( VOP_Node *subnet = nullptr,
59  bool allow_search = false) const;
60  bool isSubnetOutputDefiner( VOP_Node *subnet = nullptr,
61  bool allow_search = false) const;
62  bool isSubnetInputParm() const;
63  bool isSubnetOutputParm() const;
64  /// @}
65 
66  /// @{ Menu options for this parameter.
67  static const char* const NO_MENU;
68  static const char* const MENU_ITEMS;
69  static const char* const MENU_SCRIPT;
70  /// @}
71 
72  /// Returns true if parm node is used for shader argument.
73  bool isShaderParm() const;
74  bool isClassMemberParm() const;
75 
76  /// Gets the access level (public, private, etc) for this variable.
77  void getParmAccess( UT_String &access );
78 
79  /// Checks if this node is inside a shader of the given type.
80  bool isInsideShaderOfType( VOP_Type shader_type );
81 
82  /// Returns true if this node represents a subnet input.
83  virtual bool isSubnetInput() const;
84 
85  /// Returns the type of a subnet input represented by this node.
86  virtual VOP_TypeInfo getSubnetInputTypeInfo();
87 
88  /// Obtains a list of shader context types that this node is interested in
89  /// supporting.
90  virtual void getContextsForCodeGeneration(
91  UT_StringArray &context_names ) const;
92 
93  // Does a search through the network to find the node that defines
94  // the parameter for node. This function updates the local symbol
95  // table with the appropriate value.
96  void recalculateParmDefiner(bool sendchangeevents);
97 
98  // Calls PARMNAME() to make sure that our parm name cache value is
99  // up to date.
100  void cacheParmName();
101  // Returns ths cached evaluation of the parameter name parm. This
102  // is useful because this parameter is evaluated extremely often.
103  const UT_String &getParmNameCache() const;
104 
105  /// Get the variable name for this parameter, as it is used in code.
106  void getParmCodeName( UT_String &name ) const;
107 
108  /// Returns parm label.
109  void parmLabel(UT_String &str);
110 
111  /// Returns true if it's an exported parameter.
112  bool isExportParm() const
113  { return exportParm(); }
114 
115  /// Returns the real parameter definer for this node.
116  VOP_ParmGenerator *getParmDefiner() const;
117  VOP_ParmGenerator *getParmDefiner(const char *parm_name,
118  bool for_shader) const;
119 
120  // Fills the supplied array with a list of all channels that will be
121  // created for the parameter defined by this node.
122  void getParmChannels(UT_StringArray &channels);
123 
124  // Parm generators are special - they may or may not have an input,
125  // but even when it is being display, we may run into cases where
126  // the my inputs array is actually empty (even though we're showing
127  // an input).
128  virtual unsigned nInputs() const;
129 
130  // These methods, which must be implemented by the derived class, should
131  // not worry about whether the parameter id defined elsewhere:
132  virtual void PARMSCOPE(UT_String &str) const;
133  virtual void setPARMSCOPE(const char *str);
134  virtual void PARMACCESS(UT_String &str) const;
135  virtual void PARMNAME(UT_String &str) const = 0;
136  virtual void setPARMNAME(const UT_String &str);
137  virtual void PARMPREFIX(UT_String &str) const;
138  virtual void PARMPOSTFIX(UT_String &str) const;
139  virtual void PARMLABEL(UT_String &str) const = 0;
140  virtual int PARMTYPEINDEX() const = 0;
141  virtual void setPARMTYPEINDEX(int type);
142  virtual void PARMTYPENAME(UT_String &type_name) const;
143  virtual void setPARMSTORAGE(int type);
144  virtual void PARMMENUOPTION(UT_String &str) const;
145  virtual void setPARMMENUOPTION(const UT_String &menu_option);
146 
147  // Convenience method to set a parameter type
148  void setParmType( VOP_Type type );
149 
150  /// Return true if the promoted parameter is visible
151  /// on the VOPNET creator node.
152  virtual bool isParmVisible() const = 0;
153 
154  /// Copy settings from a source parameter generator
155  virtual void copySettingsFrom(VOP_ParmGenerator *pvop);
156 
157  /// Copy the default values from the given parameter and use them
158  /// as the default values for this node's generated parameter.
159  virtual void copyDefaultValuesFrom(
160  const PI_EditScriptedParm *parm);
161 
162  /// Get the type of the parameter (possibly filtered for a given language)
163  VOP_Type getParameterType(const VOP_Language *l=NULL);
164  VOP_TypeInfo getParameterTypeInfo(const VOP_Language *l=NULL);
165 
166  /// Get the name of the parameter that holds the current default value.
167  const char * getParameterDefaultValueParmName();
168 
169  /// Get the value of the parameter as an integer. This checks the owner
170  /// (i.e. network) for a parameter, then will evaluate the parameter as an
171  /// integer.
172  virtual bool evalIntegerValue(int &value);
173 
174  /// Return the exported parameters manager that is keeping track of this
175  /// parameter VOP.
176  VOP_ExportedParmsManager *ownerExportedParmsManager() const;
177 
178  /// Parm nodes may override definers notion of export context.
179  /// These are methods to determine if that's the case.
180  bool canForceExportInContext(const VOP_CodeGenContext &ctx) const;
181  bool shouldForceExportInContext(const VOP_CodeGenContext &ctx) const;
182  bool shouldCheckSecondaryDefinerInput(
183  const VOP_CodeGenContext &ctx) const;
184 
185  /// Returns a list of all parm generatos that define parm of a given name.
186  static void findAllShaderParmDefiners(
187  UT_Array<VOP_ParmGenerator*> &parm_gens,
188  OP_Network *root, const char *parmname);
189 protected:
190  VOP_ParmGenerator(OP_Network *parent, const char *name,
191  OP_Operator *entry);
192  virtual ~VOP_ParmGenerator();
193 
194  /// @{ Scope menu helpers for subclasses.
197  /// @}
198 
199  VOP_ParmGenerator * findParmDefinerInTable(const char *parm_name,
200  const VOP_ParmGeneratorMap *table ) const;
201  const VOP_ParmGeneratorMap *getShaderParmTable() const;
202  const VOP_ParmGeneratorMap *getSubnetParmTable() const;
203  void recalculateShaderParmDefiner(bool sendchangeevents);
204  void recalculateSubnetParmDefiner(bool sendchangeevents);
205  const VOP_ParmGenerator *getSubnetConnectorParmDefiner(bool search) const;
206 
207  virtual void getDescriptiveName(UT_String &name) const;
208  virtual void postOpChanged(OP_EventType reason, void *data);
209 
210  virtual void getInputNameSubclass(UT_String &in, int idx) const;
211  virtual int getInputFromNameSubclass(const UT_String &in) const;
212 
213  virtual void getOutputNameSubclass(UT_String &out, int idx) const;
214  virtual void getOutputTypeInfoSubclass(VOP_TypeInfo &type_info,
215  int idx);
216  virtual void getOutputVariableName(UT_String &var, int idx) const;
217 
218  // Helpers for dealing with variable name different than output name.
219  void getTmpParmCodeName( UT_String &name ) const;
220  bool usesTempOutputVar() const;
221 
222  /// Factored out helper that gets the parameter declaration.
223  bool getParameterDeclarationHelper(UT_String &parmdecl,
224  const VOP_Language *language,
225  const VOP_CodeGenContext &context);
226 
227  /// Pass back the declaration code for the parameters
228  /// defined by this VOP node.
229  virtual void getParmDeclarationCode(UT_String &parm_decl,
230  const VOP_CodeGenContext &codegen_ctx,
231  const VOP_Language *language=NULL,
232  bool export_parms=false);
233 
234  // These methods, which must be implemented by the derived class, should
235  // not worry about whether the parameter id defined elsewhere:
236  virtual bool USEASPARMDEFINER() const = 0;
237  virtual bool USEOWNEXPORTCONTEXT() const;
238  virtual bool SHOULDHAVECORRESPONDINGCONNECTOR() const;
239  virtual int UNIFORM() const= 0;
240  virtual int USEBOUND() const;
241  virtual int EXPORTPARM() const;
242  virtual void EXPORTSHADERCONTEXTS(
243  UT_StringArray &context_names) const;
244  virtual void MENUCHOICES(UT_String &str) const;
245  virtual void MENUSCRIPT(UT_String &str) const;
246  virtual CH_ScriptLanguage MENUSCRIPTLANGUAGE() const;
247 
248  virtual bool needsInput(void) = 0;
249 
250  // Build the code to be output when useBound() is true but the parameter
251  // is not actually bound:
252  virtual void getUnboundCode(UT_String &codestr,
253  const VOP_CodeGenContext &context);
254 
255  // Handles the case of having our parameter name changed. This
256  // implementation does nothing.
257  virtual void handleParmNameChange(
258  const UT_String &oldparmname,
259  const UT_String &newparmname);
260 
261  // Determines based on the parm index if the PARMNAME may be changed
262  // when this parm is changed.
263  virtual bool getParmCanAffectParmName(int pidx) const = 0;
264 
265  virtual void getNodeSpecificInfoText(
266  OP_Context &context,
267  OP_NodeInfoParms &iparms);
268  virtual void fillInfoTreeNodeSpecific(UT_InfoTree &tree,
269  const OP_NodeInfoTreeParms &parms);
270 
271  // These methods check if the parameter is defined elsewhere before calling
272  // the upper-case methods:
273  int useBound() const;
274  bool shouldHaveCorrespondingConnector() const;
275  int exportParm(bool check_connected = true) const;
276  void exportShaderContexts(
277  UT_StringArray &context_names) const;
278  int getParmTypeIndex();
279  void getParmTypeName(UT_String &type_name);
280  void getMenuOption(UT_String &menu_option);
281  void menuChoices(UT_String &str);
282 
283  VOP_Type getUniformType(int pidx,
284  bool conditioned = true,
285  const VOP_Language *language=0);
286 
287  /// Copy a single parameter's value from the source parameter
288  /// This is a convenience method for the copySettingsFrom() method
289  void copyParameterValue(const VOP_ParmGenerator *src,
290  const char *name,
291  bool just_value = true);
292 
293  virtual void preDelete();
294 
295 private:
296  // Sends change events to al parm nodes that have the changednode as
297  // their parm definer.
298  static void sendChangesForAllParmsDefinedBy(
299  OP_Node *changednode,
300  OP_Node *node);
301 
302  // Returns a pointer to the VOP_ParmGenerator within a given network
303  // that defines the parameter with the specified name.
304  static VOP_ParmGenerator *findParmDefiner(OP_Network *root,
305  const char *parmname,
306  bool subnet_parm);
307  // REcursive version of the above function.
308  static VOP_ParmGenerator *findParmDefiner(OP_Network *root,
309  const char *parmname,
310  bool &preferred,
311  bool subnet_parm);
312 
313  UT_String myParmNameCache;
314  mutable OP_VERSION myCachedIsShaderParmVersion;
315  mutable bool myCachedIsShaderParm;
316  bool myIsAlwaysUsedAsShaderParm;
317 };
318 
319 #endif
virtual int getInputFromNameSubclass(const UT_String &in) const
Reprsents a language for which VOPs can generate source code.
Definition: VOP_Language.h:27
virtual void getContextsForCodeGeneration(UT_StringArray &context_names) const
virtual bool areOutputVariablesFixed(const VOP_CodeGenContext &ctx)
uint64 OP_VERSION
Definition: OP_Version.h:6
virtual VOP_ParmGenerator * castToParmGenerator()
virtual bool forceCodeGenerationOfInputs(const VOP_CodeGenContext &context, bool check_shader_context) const
virtual unsigned getNumVisibleInputs() const
Parameters for OP_Node::getInfoText()/OP_Node::getNodeSpecificInfoText()
virtual void opChanged(OP_EventType reason, void *data=0)
static const char *const MENU_SCRIPT
Menu options for this parameter.
virtual void getFixedOutputVariable(UT_String &var, int idx)
virtual void fillInfoTreeNodeSpecific(UT_InfoTree &tree, const OP_NodeInfoTreeParms &parms)
static const char *const SCOPE_METHOD
Obtains the scope for this parameter.
virtual unsigned nInputs() const
virtual const VOP_ParmGenerator * castToParmGenerator() const
static PRM_Default theParmscopeDefault
Scope menu helpers for subclasses.
#define VOP_API
Definition: VOP_API.h:10
static const char *const MENU_ITEMS
Menu options for this parameter.
virtual void getOutputVariableName(UT_String &var, int idx) const
virtual void getNodeSpecificInfoText(OP_Context &context, OP_NodeInfoParms &iparms)
GLuint GLint GLboolean GLint GLenum access
Definition: glcorearb.h:2221
virtual void getDescriptiveName(UT_String &str) const
virtual bool isSubnetInput() const
Returns true if the node is considered a subnet's input node.
Definition: VOP_Node.h:888
GLboolean * data
Definition: glcorearb.h:130
GLuint const GLchar * name
Definition: glcorearb.h:785
static const char *const NO_MENU
Menu options for this parameter.
static const char *const SCOPE_SUBNET
Obtains the scope for this parameter.
virtual void initializeNode()
static PRM_ChoiceList theParmscopeMenu
Scope menu helpers for subclasses.
virtual void getCode(UT_String &codestr, const VOP_CodeGenContext &context)
Get the code fragment to be included in the shader code.
GLsizei const GLfloat * value
Definition: glcorearb.h:823
Parameters for OP_Node::fillInfoTree()/OP_Node::fillInfoTreeNodeSpecific()
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
static const char *const SCOPE_SHADER
Obtains the scope for this parameter.
bool isExportParm() const
Returns true if it's an exported parameter.
OP_EventType
Definition: OP_Value.h:22
VOP_Type
Definition: VOP_Types.h:24
virtual void getInputNameSubclass(UT_String &in, int idx) const
GLint GLint GLsizei GLint GLenum GLenum type
Definition: glcorearb.h:107
virtual void preDelete()
Definition: OP_Node.h:2515
virtual VOP_Node * getRealDefinition()
Definition: VOP_Node.h:994
virtual bool getIsParmGenerator() const
Returns true if this VOP is a VOP_ParmGenerator or subclass.
static const char *const SCOPE_CLASS
Obtains the scope for this parameter.
CH_ScriptLanguage
GLenum src
Definition: glcorearb.h:1792
virtual void postOpChanged(OP_EventType, void *)
Definition: VOP_Node.h:1324