HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
PDG_NodeInterface.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  * COMMENTS:
7  */
8 
9 #ifndef __PDG_NODE_INTERFACE_H__
10 #define __PDG_NODE_INTERFACE_H__
11 
12 #include "PDG_API.h"
13 
14 #include "PDG_ApplicationShim.h"
15 #include "PDG_AttributeInfo.h"
16 #include "PDG_JobScriptInfo.h"
17 #include "PDG_NodePorts.h"
18 #include "PDG_Port.h"
19 
20 #include <PDGT/PDGT_ValueArgs.h>
21 
22 #include <UT/UT_Array.h>
23 #include <UT/UT_NonCopyable.h>
24 #include <UT/UT_StringArray.h>
25 #include <UT/UT_StringHolder.h>
26 #include <UT/UT_StringMap.h>
27 
28 #include <SYS/SYS_TypeDecorate.h>
29 
30 #define PDG_BUILTIN_PARAM_PREFIX "pdg_"
31 #define PDG_BUILTIN_TAG_PREFIX "pdg::"
32 
33 #define PDG_BUILTIN_PARAM(name) PDG_BUILTIN_PARAM_PREFIX name
34 #define PDG_SEP_PARAM(index) "sepparm" #index
35 #define PDG_BUILTIN_TAG(name) PDG_BUILTIN_TAG_PREFIX name
36 
37 class PDG_Node;
38 class PDG_WorkItem;
39 class UT_WorkBuffer;
40 
42 {
43 public:
45  {
47 
50 
51  bool multiparm;
52  };
53 
55 
57  {
61  };
62 
64 
65 public:
66 
67  /// UT_StringHolder instances for built in PDG parm/data field names. Since
68  /// some of these are used during the cook, it's advantageous to store them
69  /// as static instances and refer to them using PDG_NodeInterace::theXYZX
70  /// rather just referring to them with a const char* to avoid rehashing for
71  /// map lookups.
83 
86 
89 
94 
101 
107 
111 
117 
120 
122 
137 
145 
150 
152 
155 
156 public:
158  UT_StringHolder name = "",
159  UT_StringHolder data_type = "");
160  virtual ~PDG_NodeInterface();
161 
162  int64 getMemoryUsage(bool inclusive) const;
163 
164  /// Clones the template interface into the ports/parameters on this
165  /// interface.
166  void cloneFrom(const PDG_NodeInterface& interface);
167 
168  /// Adds builtin ports for the specified node type and subtype
169  void addBuiltinPorts(
171  PDG_NodeSubtype sub_type);
172 
173  /// Queries the work item data type associated with this node
175  { return myWorkItemDataType; }
177  { return myWorkItemDataType; }
178 
179  /// Resolves and caches the work item data type
180  bool resolveWorkItemDataType(UT_WorkBuffer& errors);
181 
182  /// Returns the list of all ports of the specified type
183  const PDG_PortArray& ports(PDG_PortType type) const;
184  const PDG_PortArray& inputPorts() const;
185  const PDG_PortArray& outputPorts() const;
186  const PDG_PortArray& parameters() const;
187 
188  /// Returns the list of parameter groups for the node
190  { return myParameterGroups; }
191 
192  /// Returns the list of parameters with the specified tag
193  bool parametersForTag(
194  const UT_StringHolder& tag,
195  PDG_PortArray& parameters) const;
196 
197  /// Returns the list of custom parameter ports.
198  const PDG_PortArray& customParameters() const;
199 
200  /// Find a port by type, index and/or name. If no matching port is found,
201  /// nullptr is returned.
202  PDG_Port* port(PDG_PortType type, int index) const;
203  PDG_Port* port(
205  const UT_StringHolder& name) const;
206  PDG_Port* port(const UT_StringHolder& name) const;
207 
208  /// Specialized functions for finding input ports by name or index
209  PDG_Port* inputPort(int index) const;
210  PDG_Port* inputPort(const UT_StringHolder& name) const;
211  bool inputPortsForNode(
212  PDG_Node* node,
213  PDG_PortArray& ports) const;
214  bool inputPortsForWorkItem(
215  const PDG_WorkItem* work_item,
216  PDG_PortArray& ports) const;
217  bool isWorkItemFromInputPort(
218  const PDG_WorkItem* work_item,
219  const UT_StringHolder& name) const;
220 
221  /// Sepcialized functions for finding output ports by name or index
222  PDG_Port* outputPort(int index) const;
223  PDG_Port* outputPort(const UT_StringHolder& name) const;
224 
225  /// Returns the parameter with the specified name, or nullptr if no such
226  /// parameter exists.
227  PDG_Port* parameter(
228  const UT_StringHolder& name,
229  int multi=-1) const;
230 
231  /// Returns the value and default value of the parameter with the
232  /// specified name and index. If no parameter is found or the index is
233  /// out of range, nullptr is returned.
234  PDGT_Value* paramValue(
235  const UT_StringHolder& name,
236  int index=0) const;
237  PDGT_Value* defaultParamValue(
238  const UT_StringHolder& name,
239  int index=0) const;
240 
241  /// Returns the numbers of ports with the specified type (input,
242  /// output, etc).
243  int portCount(PDG_PortType type) const;
244  int inputCount() const;
245  int outputCount() const;
246  int parameterCount() const;
247 
248  /// Returns information about the number of ordered vs. unordered input
249  /// ports on this node.
250  bool hasUnorderedPorts() const;
251  int numOrderedPorts() const;
252 
253  /// Adds the specified port, which can be an input, output or a parameter.
254  /// Returns the new port on success, else returns failure.
255  PDG_Port* addPort(
257  const PDG_WorkItemDataType* data_type,
258  const UT_StringHolder& name,
259  const UT_StringHolder& label,
260  const UT_StringArray& tags = UT_StringArray(),
261  int size = 0,
262  bool ordered = true,
263  bool custom = false);
264 
265  /// Adds a parameter with the specified data type, size, name, label and
266  /// tag list. Returns the parameter on success, or nullptr on failure.
267  PDG_Port* addParameter(
268  PDGT_Value::DataType data_type,
269  const UT_StringHolder& name,
270  const UT_StringHolder& label,
271  const UT_StringArray& tags,
272  int size = 1,
273  bool custom = false);
274 
275  /// Adds a parameter with a data type, name, label and optional size.
276  PDG_Port* addParameter(
277  PDGT_Value::DataType data_type,
278  const UT_StringHolder& name,
279  const UT_StringHolder& label,
280  int size = 1,
281  bool custom = false);
282 
283  /// Removes the specified parameter by name, and returns true if the
284  /// parameter was found and successfully removed.
285  bool removeParameter(const UT_StringHolder& name);
286 
287  /// Adds a new file dependency to the node interface
288  void addFileDependency(
289  const UT_StringHolder& file_path);
290 
291  /// Adds a new parameter group to the node interface
292  void addParameterGroup(
293  const UT_StringHolder& name,
294  bool root = true,
295  bool multiparm = false);
296 
297  /// Ends the current parameter group
298  void endParameterGroup();
299 
300  /// If this interface represents a template, returns the name of that
301  /// template
303  { return myTemplateName; }
304 
305  /// Returns the template interface that defined how this interface
306  /// was created
307  virtual const PDG_NodeInterface*
309  { return nullptr; }
310 
311  /// Returns true if the node interface is valid
312  bool isValid() const
313  { return myValidFlag; }
314 
315  /// Returns the list of external files that this node depends on.
317  { return myAutoDependencies; }
318 
319  /// Returns the list of common expression variables, available on all
320  /// parameters on this node interface.
322  commonVars() const
323  { return myCommonVars; }
324 
325  /// Returns the underlying application node associated with this PDG node,
326  /// for example a TOP node or TOP scheduler. This may be null.
328  { return myAppNode.get(); }
329 
330  /// Sets the underlying app node.
331  template <typename T, typename... Args>
332  void setAppNode(Args&&... args)
333  {
334  myAppNode = UTmakeUnique<T>(
335  std::forward<Args>(args)...);
336  }
337 
338  /// Returns the attribute info object for this node interface. If this is
339  /// a template loaded from .json, the attribute info object contains the
340  /// definition as it was specified in the template. Otherwise, if this is
341  /// a cooked node, then it contains the evaluated attribute info from the
342  /// last cook.
344  { return myAttributeInfo; }
345 
346  /// Clears and sets the attribute info for this interface
348  { myAttributeInfo = info; }
349 
350  /// Returns the script info for this node interface.
352  { return myScriptInfo; }
353 
354  /// Sets the script info for the interface
356  { myScriptInfo = info; }
357 
358  /// Adds a single entry to the job script info's service compatiblity
359  /// list
360  void setServiceCompatibility(
361  const UT_StringHolder& service_type_name,
362  bool compatible);
363 
364  /// Adds an error to the node interface -- implemented in subclasses
365  virtual void addError(const UT_StringHolder& message) const
366  {}
367 
368  /// Adds an error using a format string, instead of plain string
369  template <typename... Args>
371  const char* fmt,
372  Args&&... args) const
373  {
375  buffer.format(
376  fmt, std::forward<Args>(args)...);
377  addError(buffer.buffer());
378  }
379 
380  /// Adds a warning to the node interface -- implemented in subclasses
381  virtual void addWarning(const UT_StringHolder& message) const
382  {}
383 
384  /// Adds a warning using a format string, instead of plain string
385  template <typename... Args>
387  const char* fmt,
388  Args&&... args) const
389  {
391  buffer.format(
392  fmt, std::forward<Args>(args)...);
393  addWarning(buffer.buffer());
394  }
395 
396  /// Evaluates a parameter and reports errors if desired
397  template <typename T>
399  const UT_StringHolder& name,
400  const PDG_WorkItem* work_item=nullptr,
401  int index=0,
402  int multi=-1) const
403  {
404  PDG_Port* parm = parameter(name, multi);
405  if (!parm)
406  return false;
407 
408  UT_WorkBuffer errors;
409  if (parm->evaluate(index, result, work_item, errors))
410  return true;
411 
412  addError(errors.buffer());
413  return false;
414  }
415 
416  /// Evaluates a string parameter as a raw string, and reports errors if
417  /// desired.
420  const UT_StringHolder& name,
421  const PDG_WorkItem* work_item=nullptr,
422  int index=0,
423  int multi=-1) const
424  {
425  PDG_Port* parm = parameter(name, multi);
426  if (!parm)
427  return false;
428 
429  UT_WorkBuffer errors;
430  if (parm->evaluateRaw(index, result, work_item, errors))
431  return true;
432 
433  addError(errors.buffer());
434  return false;
435  }
436 
437  /// Evaluates a parameter as an array and reports errors if desired
438  template <typename T>
440  T& result,
441  const UT_StringHolder& name,
442  const PDG_WorkItem* work_item=nullptr,
443  int multi=-1) const
444  {
445  PDG_Port* parm = parameter(name, multi);
446  if (!parm)
447  return false;
448 
449  UT_WorkBuffer errors;
450  if (parm->evaluate(result, work_item, errors))
451  return true;
452 
453  addError(errors.buffer());
454  return false;
455  }
456 
457 protected:
460 
461 private:
462  PDG_Port* addPortInternal(
463  PDG_PortType type,
464  const PDG_WorkItemDataType* data_type,
465  const UT_StringHolder& name,
466  const UT_StringHolder& label,
467  int size = 0,
468  bool ordered = true,
469  bool custom = false,
470  bool builtin = false);
471 private:
472  friend class PDG_NodeTemplate;
473 
475 
476  PDG_NodePorts myPorts;
477  TaggedParameters myTaggedParameters;
478  PDG_PortArray myCustomParameters;
479  UT_StringArray myMultiEntries;
480  DependencyArray myAutoDependencies;
481  PDG_Port::ExpressionVars myCommonVars;
482 
483  ParameterGroupArray myParameterGroups;
484 
485  UT_StringHolder myTemplateName;
486  UT_StringHolder mySpecifiedWorkItemDataType;
487  mutable PDG_WorkItemDataType*
488  myWorkItemDataType;
490  myAppNode;
491 
492  int myCurrentParameterGroup;
493  int myNumOrderedPorts;
494 
495  bool myUnorderedFlag;
496  bool myValidFlag;
497  bool myNoSchedulerParams;
498  bool myHasCustomInputs;
499  bool myHasCustomOutputs;
500 };
501 
503 
504 #endif
static const UT_StringHolder thePartitionerMergeOpParm
GLuint GLsizei const GLchar * message
Definition: glcorearb.h:2543
static const UT_StringHolder theTagOpDepDirty
GLuint GLsizei const GLchar * label
Definition: glcorearb.h:2545
static const UT_StringHolder theProcessorCommandTypeParm
static const UT_StringHolder thePartitionerSplitAttributeParm
static const UT_StringHolder thePartitionerSortParm
static const UT_StringHolder theProcessorCookTypeParm
void setAttributeInfo(const PDG_AttributeInfo &info)
Clears and sets the attribute info for this interface.
static const UT_StringHolder theSchedulerRpcTimeout
void addWarningFmt(const char *fmt, Args &&...args) const
Adds a warning using a format string, instead of plain string.
static const UT_StringHolder thePartitionerSortDirectionParm
static const UT_StringHolder thePartitionerTargetParm
static const UT_StringHolder thePartitionerSplitDefaultParm
#define PDG_API
Definition: PDG_API.h:23
static const UT_StringHolder theTagOpDepRegen
static const UT_StringHolder theSchedulerDeleteTempDirParm
static const UT_StringHolder theProcessorUseServiceBlockParm
static const UT_StringHolder theSchedulerUseMaxTasksParm
int64 exint
Definition: SYS_Types.h:125
static const UT_StringHolder theProcessorCacheModeParm
SYS_FORCE_INLINE const char * buffer() const
static const UT_StringHolder theSchedulerMaxTasksParm
**But if you need a result
Definition: thread.h:613
virtual void addWarning(const UT_StringHolder &message) const
Adds a warning to the node interface – implemented in subclasses.
static const UT_StringHolder theSchedulerCompressWorkItemDataParm
static const UT_StringHolder theGenerateMenuScript
bool isValid() const
Returns true if the node interface is valid.
GLuint buffer
Definition: glcorearb.h:660
bool evaluateRaw(UT_StringHolder &result, const UT_StringHolder &name, const PDG_WorkItem *work_item=nullptr, int index=0, int multi=-1) const
PDG_WorkItemDataType * workItemDataType()
Queries the work item data type associated with this node.
const PDG_Port::ExpressionVars & commonVars() const
static const UT_StringHolder theProcessorServiceResetTypeParm
std::unique_ptr< T, Deleter > UT_UniquePtr
A smart pointer for unique ownership of dynamically allocated objects.
Definition: UT_UniquePtr.h:39
PDG_NodeType
Enumeration of node types in a PDG graph.
Definition: PDG_NodeTypes.h:95
static const UT_StringHolder theProcessorServiceResetWhenParm
static const UT_StringHolder theSchedulerUseMapZoneParm
static const UT_StringHolder theTagExtraInput
void addErrorFmt(const char *fmt, Args &&...args) const
Adds an error using a format string, instead of plain string.
static const UT_StringHolder theProcessorLabelTypeParm
static const UT_StringHolder thePartitionerSplitEnabledParm
static const UT_StringHolder theProcessorWorkItemGenerationParm
static const UT_StringHolder theProcessorServiceNameParm
static const UT_StringHolder thePartitionerMergeParm
static const UT_StringHolder thePartitionerMergePatternParm
static const UT_StringHolder thePartitionerStoreIDsParm
const UT_StringHolder & templateName() const
static const UT_StringHolder thePartitionerIDAttribParm
virtual void addError(const UT_StringHolder &message) const
Adds an error to the node interface – implemented in subclasses.
static const UT_StringHolder theSchedulerRpcBatch
static const UT_StringHolder theProcessorScheduleWhenParm
static const UT_StringHolder theFeedbackBeginParm
long long int64
Definition: SYS_Types.h:116
static const UT_StringHolder theSchedulerWaitForFailuresParm
bool evaluateArray(T &result, const UT_StringHolder &name, const PDG_WorkItem *work_item=nullptr, int multi=-1) const
Evaluates a parameter as an array and reports errors if desired.
static const UT_StringHolder theProcessorCommandParm
const PDG_WorkItemDataType * workItemDataType() const
const PDG_AttributeInfo & attributeInfo() const
PDG_ApplicationShim::Node * appNode() const
static const UT_StringHolder thePartitionerMergeOutputsParm
GLuint const GLchar * name
Definition: glcorearb.h:786
virtual const PDG_NodeInterface * templateInterface() const
SYS_DECLARE_LEGACY_TR(GU_Detail)
static const UT_StringHolder theSchedulerTickPeriodParm
static const UT_StringHolder theCacheModeMenuScript
static const UT_StringHolder thePartitionerMergePreserveParm
static const UT_StringHolder thePartitionerSplitMissingParm
static const UT_StringHolder theSchedulerMapModeParm
static const UT_StringHolder theSchedulerRpcIgnoreErrors
static const UT_StringHolder thePartitionerWhenParm
static const UT_StringHolder thePartitionerIgnoreFailures
void setScriptInfo(const PDG_JobScriptInfo &info)
Sets the script info for the interface.
static const UT_StringHolder theSchedulerValidateOutputsParm
static const UT_StringHolder thePartitionerSetFrameParm
static const UT_StringHolder theSchedulerMapZoneParm
GLsizeiptr size
Definition: glcorearb.h:664
static const UT_StringHolder theSchedulerRpcMaxErrors
static const UT_StringHolder theFeedbackFilesParm
size_t format(const char *fmt, const Args &...args)
static const UT_StringHolder theProcessorPriorityExpressionParm
void setAppNode(Args &&...args)
Sets the underlying app node.
static const UT_StringHolder theSchedulerWorkingDirParm
static const UT_StringHolder theTagExpandName
GLuint index
Definition: glcorearb.h:786
static const UT_StringHolder theFeedbackAttribPatternParm
static const UT_StringHolder thePartitionerMergeAttribsParm
static const UT_StringHolder theSeparatorLabel
**If you just want to fire and args
Definition: thread.h:609
const PDG_JobScriptInfo & scriptInfo() const
Returns the script info for this node interface.
static const UT_StringHolder theSchedulerMaxItemsParm
static const UT_StringHolder thePartitionerTargetTypeParm
static const UT_StringHolder theProcessorPriorityTypeParm
static const UT_StringHolder thePartitionerSortRequiredParm
PDG_NodeSubtype
Enumeration of node subtypes.
static const UT_StringHolder thePartitionerSortAttribParm
static const UT_StringHolder theSchedulerRpcRelease
static const UT_StringHolder thePartitionerSplitPartialParm
static const UT_StringHolder theFeedbackAttribsParm
static const UT_StringHolder theSchedulerCheckExpectedOutputsParm
const DependencyArray & autoDependencies() const
Returns the list of external files that this node depends on.
bool evaluate(int index, fpreal &result, const PDG_WorkItem *work_item, UT_WorkBuffer &errors) const
bool evaluateRaw(int index, UT_StringHolder &result, const PDG_WorkItem *work_item, UT_WorkBuffer &errors) const
static const UT_StringHolder theProcessorLabelExpressionParm
static const UT_StringHolder theSchedulerDataSourceParm
PDG_JobScriptInfo myScriptInfo
type
Definition: core.h:1059
static const UT_StringHolder theProcessorUseScheduleWhenParm
static const UT_StringHolder theSchedulerRpcBackoff
const ParameterGroupArray & parameterGroups() const
Returns the list of parameter groups for the node.
PDG_PortType
Enumeration of node port types.
PDG_AttributeInfo myAttributeInfo
bool evaluate(T &result, const UT_StringHolder &name, const PDG_WorkItem *work_item=nullptr, int index=0, int multi=-1) const
Evaluates a parameter and reports errors if desired.
static const UT_StringHolder theSchedulerRpcRetries