HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups 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  /// In rare cases it is necessary to prevent the update until all
153  /// changes have been completed.
155  { myInhibitSpareParmLayoutUpdate = flag; }
156 
157  /// Update the owner network's spare parameter layout using the layout
158  /// that is passed in (i.e. new_parm_layout). The new layout can contain a
159  /// mix of exported parameters and regular parameters. Use `old_parms` to
160  /// supply a list of parameters that are to be renamed/deleted from the
161  /// layout. Optionally set `apply_changes_to_parm_vops` to true if you
162  /// want to apply the changes from `old_parms` to the defining
163  /// Parameter VOPs.
164  void updateOwnerSpareParmLayout(
165  const PI_EditScriptedParms &new_parm_layout,
166  const PI_OldParms &old_parms,
167  bool apply_changes_to_parm_vops=false);
168 
169  /// Update the parameters on the owner network's internal operator
170  /// (VOPNETs only).
171  void updateInternalOpParms(
172  bool force_ds_generation=false,
173  bool allow_update_while_loading=false);
174 
175  /// Add the given parameter layout as a template for the next
176  /// update to the owner VOP network's spare parameter layout.
177  void addParmLayoutTemplate(
178  const PI_EditScriptedParms &ref_parms);
179 
180  /// Micro node that represents cached the exported parameter layout.
182  { return myParmLayoutMicroNode; }
183 
184  /// Micro node that represents cached exported parameters and dialog
185  /// script.
187  { return myParmsMicroNode; }
188 
189  /// Dirty the exported parameters.
190  void dirtyParms();
191 
192 private:
193  /// Initialize the manager. This is called from the constructor.
194  void initialize_();
195 
196  /// Return the code generator that owns this exported parameters manager.
197  /// Return NULL if there is no owning code generator.
198  inline VOP_CodeGenerator * ownerCodeGen_() const;
199 
200  /// Return the owning subnet VOP. Return NULL if there is no owning subnet.
201  inline VOP_Node * ownerSubnet_() const;
202 
203  /// Return true if the owner is an HDA node.
204  inline bool isOwnerHDANode_() const;
205 
206  /// Make sure that the exported parameter layout dialog script
207  /// is up-to-date and update it if needed.
208  void ensureParmLayoutIsUpdated_();
209 
210  /// Make sure that the exported parameters list and dialog script
211  /// are up-to-date and update them if needed.
212  void ensureParmsAreUpdated_();
213 
214  /// Generate a dialog script for the defining VOP network,
215  /// the Parameter VOP nodes, and the parameter layout set by
216  /// the user on the owning VOPNET node. The dialog script also
217  /// includes spare parameters created on the owning node.
218  void generateParmLayoutDialogScript_(
219  UT_String &definition);
220 
221  /// Generate the exported parameters list and dialog script
222  /// and pass them back to the caller.
223  void generateParms_(
224  VOP_ExportedParmList &parms,
225  UT_String &definition);
226 
227  /// Output the owner node's information in dialog script format.
228  void outputOwnerNodeInfoAsDS_(std::ostream &os);
229 
230  /// Return the name to use for the owner network's parameter dialog
231  /// script.
232  const char * ownerParmDSName_() const;
233 
234  /// Return the label to use for the owner network's parameter dialog
235  /// script.
236  const char * ownerParmDSLabel_() const;
237 
238  /// Return the list of exported parameters.
239  const VOP_ExportedParmList &getParms_(bool use_cached_value=false) const;
240 
241  /// Return the dialog script for the exported parameters.
242  const char * getParmsDialogScript_() const;
243 
244  /// Compare the old and new list of parameters.
245  /// Record any parameters that have been renamed or deleted
246  /// and pass them back in `old_parms`.
247  void getRenamedAndDeletedParms_(
248  const VOP_ExportedParmList &old_code_parms,
249  const VOP_ExportedParmList &new_code_parms,
250  PI_OldParms &old_parms) const;
251 
252  /// Return the list of old parameters that have been renamed or deleted
253  /// since the last exported parameter layout update.
254  const PI_OldParms & getOldParms_() const;
255 
256  /// Return the list of old HDA parameters that have been renamed or deleted
257  /// since the last HDA dialog script update.
258  const PI_OldParms & getOldHDAParms_() const;
259 
260  /// Clear out the list of old parameters.
261  /// This should only be called after the exported parameter layout
262  /// has been updated.
263  void clearOldParms_();
264 
265  /// Clear out the list of old HDA parameters.
266  /// This should only be called after the exported parameter layout
267  /// has been pushed to the owner's HDA's dialog script section.
268  void clearOldHDAParms_();
269 
270  /// Obtains a list of all parameter nodes for the material (if it is
271  /// a material vopnet) or for the shader (if it is just a shader)
272  void getParmNodes_(
273  OP_Network *net,
274  VOP_ExportedParmList &list,
275  std::ostream *os,
276  bool includeInvisible,
277  const VOP_ParmContextInfo &info);
278  void getParmNodes_(
279  VOP_ExportedParmList &list,
280  std::ostream *os,
281  bool includeInvisible);
282 
283  /// Add the Parameter VOP to the given list and output its string to the
284  /// given stream if it applies and is not empty, that is, if it contains
285  /// information that should be added or outputted.
286  void addParmVOPIfApplicable_(
287  VOP_ParmGenerator *vop,
288  const VOP_ParmContextInfo &info,
289  bool include_invisible,
290  VOP_ExportedParmList &parms,
291  std::ostream *os) const;
292 
293  /// Builds an information about which parameters belong to which contexts.
294  void buildParmContextInfo_(
295  VOP_ParmContextInfo &info);
296  void buildParmClassContextInfo_(
297  VOP_ParmContextInfo &info,
298  const VOP_CodeGenContext &codegen_ctx);
299  void buildParmShaderContextInfo_(
300  VOP_ParmContextInfo &info,
301  const VOP_CodeGenContext &codegen_ctx);
302 
303  /// Propagate parameter changes down to the Parameter VOPs.
304  void propagateChangesToParmVOPs_(
305  const PI_OldParms &old_parms) const;
306 
307  /// Merge two sets of spare parameters into one.
308  /// The merged set is passed back as `merge_to`.
309  void mergeSpareParms_(
310  PI_EditScriptedParms &merge_to,
311  PI_EditScriptedParms &merge_from) const;
312 
313  /// Merge the group start parameter into the specified layout, `merge_to`.
314  void mergeSpareGroupStartParm_(
315  PI_EditScriptedParms &merge_to,
316  const PI_EditScriptedParm *parm,
317  UT_StringArray &folder_labels,
318  UT_IntArray &group_end_indices) const;
319 
320  /// Merge the group end parameter into the specified layout, `merge_to`.
321  void mergeSpareGroupEndParm_(
322  PI_EditScriptedParms &merge_to,
323  const PI_EditScriptedParm *parm,
324  UT_StringArray &folder_labels,
325  UT_IntArray &group_end_indices) const;
326 
327  /// Merge the regular parameter into the specified layout, `merge_to`.
328  void mergeSpareRegularParm_(
329  PI_EditScriptedParms &merge_to,
330  const PI_EditScriptedParm *parm,
331  UT_IntArray &group_end_indices) const;
332 
333  /// Return the index of the parameter that best matches the specified
334  /// folder group parameter. Return -1 if no such parameter exists.
335  int findMatchingGroupStartParm_(
336  PI_EditScriptedParms &parms,
337  const UT_StringArray &folder_labels,
338  const PI_EditScriptedParm &group_parm)
339  const;
340 
341  /// Update the given parameter layout with the changes stored in the old
342  /// parameters (i.e. deleted parms, renamed parms).
343  void updateLayoutWithOldParms_(
344  PI_EditScriptedParms &parm_layout,
345  const PI_OldParms &old_parms) const;
346 
347  /// Return the spare parameter layout of the exported parameters.
348  /// The caller takes ownership of the returned PI_EditScriptedParms and is
349  /// responsible for its deletion.
351  createSpareParms_(bool skip_reserved);
352 
353  /// Set dependency links from dependent micro nodes
354  /// to the exported parameter layout micro node.
355  void setParmLayoutMicroNodeDependents_();
356 
357  /// Generate and pass back the parameter layout either for the
358  /// owner's spare parameters or the owner's HDA's dialog script.
359  void getOwnerParmLayout_(
360  PI_EditScriptedParms &parm_layout,
361  bool for_hda_ds,
362  bool use_incoming_layout);
363 
364  /// The exported parameter layout dialog script, the micro node
365  /// that represents it and the sets of parameters to use as layout
366  /// templates for the next update to the exported parameter layout.
367  UT_String myParmLayoutDialogScript;
368  VOP_ExportedParmLayoutMicroNode myParmLayoutMicroNode;
369  UT_ValArray<PI_EditScriptedParms *> myParmLayoutTemplates;
370 
371  /// The exported parameters, its dialog script and the micro node that
372  /// represents them.
373  VOP_ExportedParmList myParms;
374  UT_String myParmsDialogScript;
375  VOP_ParmDSMicroNode myParmsMicroNode;
376 
377  /// Stores renamed and deleted parameters for the owner's spare parameter
378  /// layout and the owner's HDA definition's dialog script section.
379  PI_OldParms myOldParms;
380  PI_OldParms myOldHDAParms;
381 
382  // Locked compiled dialog scripts for compiled owner nodes.
383  UT_WorkBuffer myLockedCompiledDialogScript;
384 
385  /// Cached data used to reduce the amount of updates propagated to the
386  /// internal operator's parameter templates.
387  UT_String myCachedDialogScript;
388  int myCachedMinInputs;
389  int myCachedMaxInputs;
390 
391  /// Flag indicating whether the parm tag should be updated or not.
392  bool myContextParmTagDirty;
393 
394  /// Flag indicating whether we are currently updating the owner network's
395  /// spare parameter layout.
396  bool myIsChangingOwnerSpareParms;
397 
398 
399  /// Flag indicating whether we are currently updating the parameters.
400  bool myIsUpdatingParms;
401 
402  /// Code generator that owns this manager.
403  VOP_CodeGenerator * myOwnerCodeGen;
404 
405  /// Subnet VOP that owns this manager.
406  VOP_Node * myOwnerSubnet;
407 
408  /// Set to true if the owner node's spare parm layout needs to be updated
409  /// when the node is finished loading.
410  bool myLoadPendingSpareParmLayoutUpdate = false;
411 
412  /// Yet another flag to avoid updating layout in some cases.
413  bool myInhibitSpareParmLayoutUpdate = false;
414 };
415 
416 
417 // ===========================================================================
418 // Inline method implementations.
419 // ===========================================================================
420 
421 OP_Network *
423 {
424  OP_Network *owner = NULL;
425  if (ownerCodeGen_())
426  owner = ownerCodeGen_()->ownerNetwork();
427  else
428  owner = (OP_Network *)ownerSubnet_();
429 
430  UT_ASSERT(owner);
431  return owner;
432 }
433 
435 VOP_ExportedParmsManager::ownerCodeGen_() const
436 {
437  return myOwnerCodeGen;
438 }
439 
440 VOP_Node *
441 VOP_ExportedParmsManager::ownerSubnet_() const
442 {
443  return myOwnerSubnet;
444 }
445 
446 bool
447 VOP_ExportedParmsManager::isOwnerHDANode_() const
448 {
449  OP_Network *owner = ownerNetwork();
450  if (owner && owner->getOperator()
452  return true;
453 
454  return false;
455 }
456 
457 #endif
OP_Network * ownerNetwork() const
void inhibitSpareParmLayoutUpdate(bool flag)
void setContextParmTagDirty(bool tag_dirty=true)
VOP_ParmDSMicroNode & parmsMicroNode()
std::unique_ptr< T, Deleter > UT_UniquePtr
A smart pointer for unique ownership of dynamically allocated objects.
Definition: UT_UniquePtr.h:33
FS_IndexFile * getOTLIndexFile(bool check_timestamp=true)
Definition: OP_Operator.h:311
#define VOP_API
Definition: VOP_API.h:10
OP_Network * ownerNetwork() const
Return the network that owns the exported parameters.
VOP_ExportedParmLayoutMicroNode & parmLayoutMicroNode()
Micro node that represents cached the exported parameter layout.
#define UT_ASSERT(ZZ)
Definition: UT_Assert.h:135
OP_Operator * getOperator() const
VOP_API VOP_ExportedParmsManager * VOPgetExportedParmsManager(OP_Node *node)