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