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,
29  const VOP_CodeGenContext &context
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 setPARMTYPENAME(const UT_StringRef &type_name);
156  virtual void setPARMSTORAGE(int type);
157  virtual void PARMMENUOPTION(UT_String &str) const;
158  virtual void setPARMMENUOPTION(const UT_String &menu_option);
159 
160  // Convenience method to set a parameter type
161  void setParmType( VOP_Type type );
162  void setParmTypeInfo(const VOP_TypeInfo &type_info);
163 
164  /// Return true if the promoted parameter is visible
165  /// on the VOPNET creator node.
166  virtual bool isParmVisible() const = 0;
167 
168  /// Copy settings from a source parameter generator
169  virtual void copySettingsFrom(VOP_ParmGenerator *pvop);
170 
171  /// Copy the default values from the given parameter and use them
172  /// as the default values for this node's generated parameter.
173  virtual void copyDefaultValuesFrom(
174  const PI_EditScriptedParm *parm);
175 
176  /// Get the type of the parameter (possibly filtered for a given language)
177  VOP_Type getParameterType(const VOP_Language *l=NULL);
178  VOP_TypeInfo getParameterTypeInfo(const VOP_Language *l=NULL);
179 
180  /// Get the name of the parameter that holds the current default value.
181  const char * getParameterDefaultValueParmName();
182 
183  /// Get the value of the parameter as an integer. This checks the owner
184  /// (i.e. network) for a parameter, then will evaluate the parameter as an
185  /// integer.
186  virtual bool evalIntegerValue(int &value);
187 
188  /// Return the exported parameters manager that is keeping track of this
189  /// parameter VOP.
190  VOP_ExportedParmsManager *ownerExportedParmsManager() const;
191 
192  /// Parm nodes may override definers notion of export context.
193  /// These are methods to determine if that's the case.
194  bool canForceExportInContext(const VOP_CodeGenContext &ctx) const;
195  bool shouldForceExportInContext(const VOP_CodeGenContext &ctx) const;
196  bool shouldCheckSecondaryDefinerInput(
197  const VOP_CodeGenContext &ctx) const;
198 
199  /// Returns a list of all parm generatos that define parm of a given name.
200  static void findAllShaderParmDefiners(
201  UT_Array<VOP_ParmGenerator*> &parm_gens,
202  OP_Network *root,
203  const UT_StringRef &parmname);
204 
205  // Parm generator has own micro-node for its parms, to notify export mgr.
206  const OP_DataMicroNode &
207  parmListMicroNodeConst() const override
208  { return myParmMicroNode; }
209 
210 protected:
211  VOP_ParmGenerator(OP_Network *parent, const char *name,
212  OP_Operator *entry);
213  ~VOP_ParmGenerator() override;
214 
215  /// @{ Scope menu helpers for subclasses.
218  /// @}
219 
220  VOP_ParmGenerator * findParmDefinerInTable(
221  const UT_StringRef &parm_name,
222  const VOP_ParmGeneratorMap *table ) const;
223  const VOP_ParmGeneratorMap *getShaderParmTable() const;
224  const VOP_ParmGeneratorMap *getSubnetParmTable() const;
225  void recalculateShaderParmDefiner(bool sendchangeevents);
226  void recalculateSubnetParmDefiner(bool sendchangeevents);
227  const VOP_ParmGenerator *getSubnetConnectorParmDefiner(bool search) const;
228 
229  void getDescriptiveName(UT_String &name) const override;
230  void postOpChanged(
231  OP_EventType reason, void *data) override;
232 
234  UT_String &in, int idx) const override;
236  const UT_String &in) const override;
237 
239  UT_String &out, int idx) const override;
241  VOP_TypeInfo &type_info, int idx) override;
243  UT_String &var, int idx) const override;
244 
245  // Helpers for dealing with variable name different than output name.
246  void getTmpParmCodeName( UT_String &name ) const;
247  bool usesTempOutputVar() const;
248 
249  /// Factored out helper that gets the parameter declaration.
250  bool getParameterDeclarationHelper(UT_String &parmdecl,
251  const VOP_Language *language,
252  const VOP_CodeGenContext &context);
253 
254  /// Pass back the declaration code for the parameters
255  /// defined by this VOP node.
256  virtual void getParmDeclarationCode(UT_String &parm_decl,
257  const VOP_CodeGenContext &codegen_ctx,
258  const VOP_Language *language=NULL,
259  bool export_parms=false);
260 
261  // These methods, which must be implemented by the derived class, should
262  // not worry about whether the parameter id defined elsewhere:
263  virtual bool USEASPARMDEFINER() const = 0;
264  virtual bool USEOWNEXPORTCONTEXT() const;
265  virtual bool SHOULDHAVECORRESPONDINGCONNECTOR() const;
266  virtual int UNIFORM() const= 0;
267  virtual int USEBOUND() const;
268  virtual int EXPORTPARM() const;
269  virtual void EXPORTSHADERCONTEXTS(
270  UT_StringArray &context_names) const;
271  virtual void MENUCHOICES(UT_String &str) const;
272  virtual void MENUSCRIPT(UT_String &str) const;
273  virtual CH_ScriptLanguage MENUSCRIPTLANGUAGE() const;
274 
275  virtual bool needsInput() = 0;
276 
277  // Build the code to be output when useBound() is true but the parameter
278  // is not actually bound:
279  virtual void getUnboundCode(UT_String &codestr,
280  const VOP_CodeGenContext &context);
281 
282  // Handles the case of having our parameter name changed. This
283  // implementation does nothing.
284  virtual void handleParmNameChange(
285  const UT_StringRef &oldparmname,
286  const UT_StringRef &newparmname);
287 
288  // Determines based on the parm index if the PARMNAME may be changed
289  // when this parm is changed.
290  virtual bool getParmCanAffectParmName(int pidx) const = 0;
291 
293  OP_Context &context,
294  OP_NodeInfoParms &iparms) override;
296  UT_InfoTree &tree,
297  const OP_NodeInfoTreeParms &parms
298  ) override;
299 
300  // These methods check if the parameter is defined elsewhere before calling
301  // the upper-case methods:
302  int useBound() const;
303  bool shouldHaveCorrespondingConnector() const;
304  int exportParm(bool check_connected = true) const;
305  void exportShaderContexts(
306  UT_StringArray &context_names) const;
307  int getParmTypeIndex();
308  void getParmTypeName(UT_String &type_name);
309  void getMenuOption(UT_String &menu_option);
310  void menuChoices(UT_String &str);
311 
312  VOP_Type getUniformType(int pidx,
313  bool conditioned = true,
314  const VOP_Language *language=0);
315 
316  /// Copy a single parameter's value from the source parameter
317  /// This is a convenience method for the copySettingsFrom() method
318  void copyParameterValue(const VOP_ParmGenerator *src,
319  const char *name,
320  bool just_value = true);
321 
322  void preDelete() override;
323 
324 private:
325  // Sends change events to al parm nodes that have the changednode as
326  // their parm definer.
327  static void sendChangesForAllParmsDefinedBy(
328  OP_Node *changednode,
329  OP_Node *node);
330 
331  // Returns a pointer to the VOP_ParmGenerator within a given network
332  // that defines the parameter with the specified name.
333  static VOP_ParmGenerator *findParmDefiner(VOP_ParmGenerator *vop,
334  OP_Network *root,
335  const UT_StringRef &parmname,
336  bool subnet_parm);
337  static VOP_ParmGenerator *findParmDefinerInNetwork(OP_Network *root,
338  const UT_StringRef &parmname,
339  bool subnet_parm);
340  static VOP_ParmGenerator *findParmDefinerInNetwork(OP_Network *root,
341  const UT_StringRef &parmname,
342  bool &preferred,
343  bool subnet_parm);
344 
345  /// Micro-node detemining if node's parms are dirty.
346  class vop_ParmMicroNode : public OP_DataMicroNode
347  {
348  public:
349  vop_ParmMicroNode(VOP_Node &node)
350  : OP_DataMicroNode(node) {}
351  const char *className() const override
352  { return "vop_ParmMicroNode"; }
353  void getOutputs(DEP_MicroNodeList &outputs) const override;
354  };
355 
356  UT_StringHolder myParmNameCache;
357  vop_ParmMicroNode myParmMicroNode;
358  mutable OP_VERSION myCachedIsShaderParmVersion;
359  mutable bool myCachedIsShaderParm;
360  bool myIsAlwaysUsedAsShaderParm;
361 };
362 
363 #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 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()
static const char *const MENU_SCRIPT
Menu options for this parameter.
GLuint const GLchar * name
Definition: glcorearb.h:786
virtual void getFixedOutputVariable(UT_String &var, int idx)
GLenum src
Definition: glcorearb.h:1793
GLuint in
Definition: glew.h:11552
static const char *const SCOPE_METHOD
Obtains the scope for this parameter.
GLdouble l
Definition: glew.h:9164
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
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:961
static const char *const NO_MENU
Menu options for this parameter.
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()
GLuint GLint GLboolean GLint GLenum access
Definition: glcorearb.h:2222
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
virtual void getInputNameSubclass(UT_String &in, int idx) const
virtual void preDelete()
Definition: OP_Node.h:2691
Definition: core.h:1131
virtual VOP_Node * getRealDefinition()
Definition: VOP_Node.h:1072
type
Definition: core.h:1059
virtual bool getIsParmGenerator() const
Returns true if this VOP is a VOP_ParmGenerator or subclass.
GLenum GLsizei GLenum GLenum const void * table
Definition: glew.h:4970
void fillInfoTreeNodeSpecific(UT_InfoTree &tree, const OP_NodeInfoTreeParms &parms) override
static const char *const SCOPE_CLASS
Obtains the scope for this parameter.
Definition: format.h:895
const OP_DataMicroNode & parmListMicroNodeConst() const override
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:1443