HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
VOP_ExportedParmsManager.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_ExportedParmsManager.h (VOP Library, C++)
7  *
8  * COMMENTS:
9  *
10  * Manages the exported parameters and layout for the owning code
11  * generator or subnet.
12  */
13 
14 #ifndef __VOP_ExportedParmsManager_h__
15 #define __VOP_ExportedParmsManager_h__
16 
17 #include "VOP_API.h"
18 
19 #include "VOP_CodeGenerator.h"
21 #include "VOP_ExportedParms.h"
22 #include "VOP_Node.h"
23 #include "VOP_ParmDSMicroNode.h"
24 
25 #include <PI/PI_OldParms.h>
26 #include <UT/UT_Assert.h>
27 #include <UT/UT_UniquePtr.h>
28 #include <UT/UT_WorkBuffer.h>
29 
30 class UT_StringArray;
31 class OP_Network;
32 class VOP_CodeGenContext;
34 class VOP_ParmContextInfo;
35 class VOP_ParmGenerator;
36 
37 /// Helper function for returning the exported parms manager for a give node.
38 /// Returns NULL if the node does not have a manager.
40 
41 /// Manager of parameters exported by parameter VOPs contained in the owner
42 /// network.
44 {
45 public:
46  explicit VOP_ExportedParmsManager(VOP_CodeGenerator *code_gen);
47  explicit VOP_ExportedParmsManager(VOP_Node *owner_subnet);
48  virtual ~VOP_ExportedParmsManager();
49 
50  /// Return the network that owns the exported parameters.
51  inline OP_Network * ownerNetwork() const;
52 
53  /// Return true if the manager is for code parameters
54  /// and false otherwise (i.e. for subnet-scoped parameters).
55  bool isForCodeParms() const
56  { return ownerCodeGen_() != NULL; }
57 
58  // Get a list of all Parameter type VOPs.
59  void getParmNodes(
60  VOP_ExportedParmList &list,
61  bool includeInvisible);
62 
63  /// Obtains a list of all parameter nodes for the material (if it is
64  /// a material vopnet) or for the shader (if it is just a shader)
65  void getParticipatingParametersAndDeclarations(
66  const VOP_NodeList &nodes,
67  const VOP_CodeGenContext &codegen_ctx,
68  const char * scope,
69  UT_StringArray *declarations,
70  UT_StringArray *comments,
71  VOP_ExportedParmList *parms);
72 
73  /// Get a list of Parameter VOPs that define class member variables.
74  void getClassMemberVariableParameterNodes(
76  UT_StringArray *declarations=NULL,
77  UT_StringArray *comments=NULL,
78  UT_StringArray *access_level=NULL);
79 
80  /// Returns parm nodes that define shader class parameters.
81  void getClassShaderParameterNodes(
82  VOP_NodeList &parms);
83 
84  /// Return the dialog script for the code generator's
85  /// exported parameter layout. The layout DS differs from the
86  /// regular parm DS because it contains the owner node's complete
87  /// parameter layout including spare parameters, folders and separators.
88  const char * getParmLayoutDialogScript() const;
89 
90  /// Return true if there is a VOP node which defines a parameter
91  /// with the given name.
92  bool hasParmNode(
93  const char *parm_name,
94  bool use_cached_parms=false) const;
95 
96  /// Return a pointer to the Parameter VOP node that corresponds
97  /// to the given parameter name. Return NULL if no such node
98  /// exists.
99  VOP_ParmGenerator * getParmNode(
100  const char *parm_name,
101  bool use_cached_parms=false) const;
102 
103  /// @{
104  /// A flag to indicate if the cached parameters may have outdated parm
105  /// tag that specifies parameter's shading contexts. Only shop clerk
106  /// is interested in this tag and currently manages the updating itself.
107  /// TODO: Remove tag_dirty argument.
108  void setContextParmTagDirty(bool tag_dirty=true)
109  {
110  myContextParmTagDirty = tag_dirty;
111  }
113  {
114  return myContextParmTagDirty;
115  }
116  /// @}
117 
118  /// Set the locked compiled dialog script. When set, the locked dialog
119  /// script causes the manager ignore the VOP nodes in the owner network
120  /// and always return the locked value.
121  void setLockedCompiledDS(const char *dialog_script);
122 
123  /// This must be called when the owner network has finished loading
124  /// (i.e. VOP_CodeGenerator::ownerFinishedLoadingNetwork()
125  /// or VOP_SubnetBase::ownerFinishedLoadingNetwork()).
126  void ownerFinishedLoadingNetwork();
127 
128  /// Return the spare parameter layout that is exported to the owner network.
129  /// The layout contains a mix of exported and regular parameters.
130  void getOwnerSpareParmLayout(
131  PI_EditScriptedParms &parm_layout);
132 
133  /// Return the parameter layout to be used for the owner's HDA's dialog
134  /// script.
135  ///
136  /// You can optionally set `use_incoming_layout` to true if you want
137  /// to use the layout already defined by `parm_layout` instead of
138  /// the parameter layout stored in the owner network. In that case,
139  /// the exported parameters are merged into the incoming layout with new
140  /// parameters added to the end.
141  void getOwnerHDADialogScriptLayout(
142  PI_EditScriptedParms &parm_layout,
143  bool use_incoming_layout=false);
144 
145  /// Output the dialog script of the owner network's spare parameter layout.
146  void outputOwnerSpareParmLayout(std::ostream &os);
147 
148  /// Update the owner network's spare parameter layout.
149  void updateOwnerSpareParmLayout(
150  bool allow_update_while_loading=false);
151 
152  /// Update the owner network's spare parameter layout using the layout
153  /// that is passed in (i.e. new_parm_layout). The new layout can contain a
154  /// mix of exported parameters and regular parameters. Use `old_parms` to
155  /// supply a list of parameters that are to be renamed/deleted from the
156  /// layout. Optionally set `apply_changes_to_parm_vops` to true if you
157  /// want to apply the changes from `old_parms` to the defining
158  /// Parameter VOPs.
159  void updateOwnerSpareParmLayout(
160  const PI_EditScriptedParms &new_parm_layout,
161  const PI_OldParms &old_parms,
162  bool apply_changes_to_parm_vops=false);
163 
164  /// Update the parameters on the owner network's internal operator
165  /// (VOPNETs only).
166  void updateInternalOpParms(
167  bool force_ds_generation=false,
168  bool allow_update_while_loading=false);
169 
170  /// Add the given parameter layout as a template for the next
171  /// update to the owner VOP network's spare parameter layout.
172  void addParmLayoutTemplate(
173  const PI_EditScriptedParms &ref_parms);
174 
175  /// Micro node that represents cached the exported parameter layout.
177  { return myParmLayoutMicroNode; }
178 
179  /// Micro node that represents cached exported parameters and dialog
180  /// script.
182  { return myParmsMicroNode; }
183 
184  /// Dirty the exported parameters.
185  void dirtyParms();
186 
187 private:
188  /// Initialize the manager. This is called from the constructor.
189  void initialize_();
190 
191  /// Return the code generator that owns this exported parameters manager.
192  /// Return NULL if there is no owning code generator.
193  inline VOP_CodeGenerator * ownerCodeGen_() const;
194 
195  /// Return the owning subnet VOP. Return NULL if there is no owning subnet.
196  inline VOP_Node * ownerSubnet_() const;
197 
198  /// Return true if the owner is an HDA node.
199  inline bool isOwnerHDANode_() const;
200 
201  /// Make sure that the exported parameter layout dialog script
202  /// is up-to-date and update it if needed.
203  void ensureParmLayoutIsUpdated_();
204 
205  /// Make sure that the exported parameters list and dialog script
206  /// are up-to-date and update them if needed.
207  void ensureParmsAreUpdated_();
208 
209  /// Generate a dialog script for the defining VOP network,
210  /// the Parameter VOP nodes, and the parameter layout set by
211  /// the user on the owning VOPNET node. The dialog script also
212  /// includes spare parameters created on the owning node.
213  void generateParmLayoutDialogScript_(
214  UT_String &definition);
215 
216  /// Generate the exported parameters list and dialog script
217  /// and pass them back to the caller.
218  void generateParms_(
219  VOP_ExportedParmList &parms,
220  UT_String &definition);
221 
222  /// Output the owner node's information in dialog script format.
223  void outputOwnerNodeInfoAsDS_(std::ostream &os);
224 
225  /// Return the name to use for the owner network's parameter dialog
226  /// script.
227  const char * ownerParmDSName_() const;
228 
229  /// Return the label to use for the owner network's parameter dialog
230  /// script.
231  const char * ownerParmDSLabel_() const;
232 
233  /// Return the list of exported parameters.
234  const VOP_ExportedParmList &getParms_(bool use_cached_value=false) const;
235 
236  /// Return the dialog script for the exported parameters.
237  const char * getParmsDialogScript_() const;
238 
239  /// Compare the old and new list of parameters.
240  /// Record any parameters that have been renamed or deleted
241  /// and pass them back in `old_parms`.
242  void getRenamedAndDeletedParms_(
243  const VOP_ExportedParmList &old_code_parms,
244  const VOP_ExportedParmList &new_code_parms,
245  PI_OldParms &old_parms) const;
246 
247  /// Return the list of old parameters that have been renamed or deleted
248  /// since the last exported parameter layout update.
249  const PI_OldParms & getOldParms_() const;
250 
251  /// Return the list of old HDA parameters that have been renamed or deleted
252  /// since the last HDA dialog script update.
253  const PI_OldParms & getOldHDAParms_() const;
254 
255  /// Clear out the list of old parameters.
256  /// This should only be called after the exported parameter layout
257  /// has been updated.
258  void clearOldParms_();
259 
260  /// Clear out the list of old HDA parameters.
261  /// This should only be called after the exported parameter layout
262  /// has been pushed to the owner's HDA's dialog script section.
263  void clearOldHDAParms_();
264 
265  /// Obtains a list of all parameter nodes for the material (if it is
266  /// a material vopnet) or for the shader (if it is just a shader)
267  void getParmNodes_(
268  OP_Network *net,
269  VOP_ExportedParmList &list,
270  std::ostream *os,
271  bool includeInvisible,
272  const VOP_ParmContextInfo &info);
273  void getParmNodes_(
274  VOP_ExportedParmList &list,
275  std::ostream *os,
276  bool includeInvisible);
277 
278  /// Add the Parameter VOP to the given list and output its string to the
279  /// given stream if it applies and is not empty, that is, if it contains
280  /// information that should be added or outputted.
281  void addParmVOPIfApplicable_(
282  VOP_ParmGenerator *vop,
283  const VOP_ParmContextInfo &info,
284  bool include_invisible,
285  VOP_ExportedParmList &parms,
286  std::ostream *os) const;
287 
288  /// Builds an information about which parameters belong to which contexts.
289  void buildParmContextInfo_(
290  VOP_ParmContextInfo &info);
291  void buildParmClassContextInfo_(
292  VOP_ParmContextInfo &info,
293  const VOP_CodeGenContext &codegen_ctx);
294  void buildParmShaderContextInfo_(
295  VOP_ParmContextInfo &info,
296  const VOP_CodeGenContext &codegen_ctx);
297 
298  /// Propagate parameter changes down to the Parameter VOPs.
299  void propagateChangesToParmVOPs_(
300  const PI_OldParms &old_parms) const;
301 
302  /// Merge two sets of spare parameters into one.
303  /// The merged set is passed back as `merge_to`.
304  void mergeSpareParms_(
305  PI_EditScriptedParms &merge_to,
306  PI_EditScriptedParms &merge_from) const;
307 
308  /// Merge the group start parameter into the specified layout, `merge_to`.
309  void mergeSpareGroupStartParm_(
310  PI_EditScriptedParms &merge_to,
311  const PI_EditScriptedParm *parm,
312  UT_StringArray &folder_labels,
313  UT_IntArray &group_end_indices) const;
314 
315  /// Merge the group end parameter into the specified layout, `merge_to`.
316  void mergeSpareGroupEndParm_(
317  PI_EditScriptedParms &merge_to,
318  const PI_EditScriptedParm *parm,
319  UT_StringArray &folder_labels,
320  UT_IntArray &group_end_indices) const;
321 
322  /// Merge the regular parameter into the specified layout, `merge_to`.
323  void mergeSpareRegularParm_(
324  PI_EditScriptedParms &merge_to,
325  const PI_EditScriptedParm *parm,
326  UT_IntArray &group_end_indices) const;
327 
328  /// Return the index of the parameter that best matches the specified
329  /// folder group parameter. Return -1 if no such parameter exists.
330  int findMatchingGroupStartParm_(
331  PI_EditScriptedParms &parms,
332  const UT_StringArray &folder_labels,
333  const PI_EditScriptedParm &group_parm)
334  const;
335 
336  /// Update the given parameter layout with the changes stored in the old
337  /// parameters (i.e. deleted parms, renamed parms).
338  void updateLayoutWithOldParms_(
339  PI_EditScriptedParms &parm_layout,
340  const PI_OldParms &old_parms) const;
341 
342  /// Return the spare parameter layout of the exported parameters.
343  /// The caller takes ownership of the returned PI_EditScriptedParms and is
344  /// responsible for its deletion.
346  createSpareParms_(bool skip_reserved);
347 
348  /// Set dependency links from dependent micro nodes
349  /// to the exported parameter layout micro node.
350  void setParmLayoutMicroNodeDependents_();
351 
352  /// Generate and pass back the parameter layout either for the
353  /// owner's spare parameters or the owner's HDA's dialog script.
354  void getOwnerParmLayout_(
355  PI_EditScriptedParms &parm_layout,
356  bool for_hda_ds,
357  bool use_incoming_layout);
358 
359  /// The exported parameter layout dialog script, the micro node
360  /// that represents it and the sets of parameters to use as layout
361  /// templates for the next update to the exported parameter layout.
362  UT_String myParmLayoutDialogScript;
363  VOP_ExportedParmLayoutMicroNode myParmLayoutMicroNode;
364  UT_ValArray<PI_EditScriptedParms *> myParmLayoutTemplates;
365 
366  /// The exported parameters, its dialog script and the micro node that
367  /// represents them.
368  VOP_ExportedParmList myParms;
369  UT_String myParmsDialogScript;
370  VOP_ParmDSMicroNode myParmsMicroNode;
371 
372  /// Stores renamed and deleted parameters for the owner's spare parameter
373  /// layout and the owner's HDA definition's dialog script section.
374  PI_OldParms myOldParms;
375  PI_OldParms myOldHDAParms;
376 
377  // Locked compiled dialog scripts for compiled owner nodes.
378  UT_WorkBuffer myLockedCompiledDialogScript;
379 
380  /// Cached data used to reduce the amount of updates propagated to the
381  /// internal operator's parameter templates.
382  UT_String myCachedDialogScript;
383  int myCachedMinInputs;
384  int myCachedMaxInputs;
385 
386  /// Flag indicating whether the parm tag should be updated or not.
387  bool myContextParmTagDirty;
388 
389  /// Flag indicating whether we are currently updating the owner network's
390  /// spare parameter layout.
391  bool myIsChangingOwnerSpareParms;
392 
393 
394  /// Flag indicating whether we are currently updating the parameters.
395  bool myIsUpdatingParms;
396 
397  /// Code generator that owns this manager.
398  VOP_CodeGenerator * myOwnerCodeGen;
399 
400  /// Subnet VOP that owns this manager.
401  VOP_Node * myOwnerSubnet;
402 
403  /// Set to true if the owner node's spare parm layout needs to be updated
404  /// when the node is finished loading.
405  bool myLoadPendingSpareParmLayoutUpdate = false;
406 };
407 
408 
409 // ===========================================================================
410 // Inline method implementations.
411 // ===========================================================================
412 
413 OP_Network *
415 {
416  OP_Network *owner = NULL;
417  if (ownerCodeGen_())
418  owner = ownerCodeGen_()->ownerNetwork();
419  else
420  owner = (OP_Network *)ownerSubnet_();
421 
422  UT_ASSERT(owner);
423  return owner;
424 }
425 
427 VOP_ExportedParmsManager::ownerCodeGen_() const
428 {
429  return myOwnerCodeGen;
430 }
431 
432 VOP_Node *
433 VOP_ExportedParmsManager::ownerSubnet_() const
434 {
435  return myOwnerSubnet;
436 }
437 
438 bool
439 VOP_ExportedParmsManager::isOwnerHDANode_() const
440 {
441  OP_Network *owner = ownerNetwork();
442  if (owner && owner->getOperator()
444  return true;
445 
446  return false;
447 }
448 
449 #endif
OP_Network * ownerNetwork() const
FS_IndexFile * getOTLIndexFile()
void setContextParmTagDirty(bool tag_dirty=true)
VOP_ParmDSMicroNode & parmsMicroNode()
#define VOP_API
Definition: VOP_API.h:10
#define UT_ASSERT(ZZ)
Definition: UT_Assert.h:102
OP_Network * ownerNetwork() const
Return the network that owns the exported parameters.
VOP_ExportedParmLayoutMicroNode & parmLayoutMicroNode()
Micro node that represents cached the exported parameter layout.
A smart pointer for unique ownership of dynamically allocated objects.
Definition: UT_UniquePtr.h:47
OP_Operator * getOperator() const
VOP_API VOP_ExportedParmsManager * VOPgetExportedParmsManager(OP_Node *node)