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