HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
DOP_Node.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: DOP_Node.h ( DOP Library, C++)
7  *
8  * COMMENTS: Dynamics OPs. These are nodes which are used for setting
9  * up and controlling dynamic simulations.
10  */
11 
12 #ifndef __DOP_Node__
13 #define __DOP_Node__
14 
15 #include "DOP_API.h"
16 #include "DOP_Error.h"
17 #include <OP/OP_Network.h>
18 #include <OP/OP_OperatorPair.h>
19 #include <OP/OP_PreDefRules.h>
20 #include <SIM/SIM_Utils.h>
21 
22 
23 class OP_Operator;
24 class OP_OperatorTable;
25 class SIM_Data;
26 class SIM_Object;
27 class SIM_ObjectArray;
28 class SIM_RootData;
29 class SIM_Options;
30 class SIM_Relationship;
31 class DOP_InOutInfo;
32 class DOP_Output;
33 class DOP_Engine;
34 
35 /// This declaration allows HDK users to write custom DOP operators.
36 extern "C" {
38 };
39 
40 /// This enumeration contains all the standard DOP local variables.
41 /// Any DOPs which create their own variables must start their variable
42 /// indices at NUM_DOP_VARS. They must also call the
43 /// DOP_Node::evalVariableValue() in their own override of this function.
44 enum {
74 };
75 
76 /// This is the base class for all DOP nodes.
77 class DOP_API DOP_Node : public OP_Network
78 {
79 public:
80  /// Constructor to allocate a new DOP_Node.
81  DOP_Node(OP_Network *dad, const char *name,
82  OP_Operator *entry);
83  /// Destructor.
84  ~DOP_Node() override;
85 
86  /// The standard DOP local variables. These get added to all DOP nodes
87  /// automatically by the DOP_Operator constructor.
89  static CH_LocalVariable theVariables[];
90 
91  /// This function builds a menu of all the rules in the
92  /// DOPActivationRules file.
93  static void buildActivationRules(void *data,
94  PRM_Name* menu,
95  int maxSize,
96  const PRM_SpareData*,
97  const PRM_Parm *);
98  /// This function responds to a selection of the adtivation rule menu
99  /// by setting the activation parameter.
100  static int setActivationCallback(void *data,
101  int index,
102  fpreal t,
103  const PRM_Template *);
104 
105  /// This function applies SIM_Data from one of our inputs to some
106  /// parent data. This is done by calling applyOutputData() for the
107  /// DOP_Node that is connected to the specfiied input index.
108  void applyDataFromInput(fpreal time, int inputidx,
109  int inputidxforsuffix,
110  SIM_RootData &rootdata,
111  const char *parentdataname,
112  DOP_Engine &engine,
113  UT_StringArray *datanames,
114  bool changeuniquenamesuffix);
115 
116  /// Returns information about which DOP_Node outputs are required
117  /// to process this node. This function calls getRequiredOutputsSubclass()
118  /// to do the real work.
119  void getRequiredOutputs(fpreal time, int foroutputidx,
120  UT_Array<DOP_Output> &outputs,
121  const DOP_Engine &engine);
122  /// Divides incoming objects among the various outputs from this node.
123  /// This function calls partitionObjectSubclass() to do the real work.
124  void partitionObjects(fpreal time,
125  const SIM_ObjectArray &objects,
127  const DOP_Engine &engine);
128  /// Processes incoming objects by adding, removing, or modifying data.
129  /// This function calls processObjectSubclass() to do the real work.
130  void processObjects(fpreal time, int foroutputidx,
131  const SIM_ObjectArray &objects,
132  DOP_Engine &engine);
133  /// Adds the data corresponding to the specified output to the object.
134  /// This function calls applyOutputDataSubclass() to do real
135  /// work.
136  void applyOutputData(fpreal time, int outputidx,
137  SIM_RootData &rootdata,
138  const char *parentdataname,
139  DOP_Engine &engine,
140  UT_StringArray *datanames);
141  /// This function gets called on all nodes before a timestep starts.
142  /// This function calls preNetworkProcessingSubclass() on this node, and
143  /// calls preNetworkProcessing() on all our child DOP_Nodes.
144  void preNetworkProcessing(DOP_Engine &engine, bool firstframe);
145  /// This function gets called on all nodes after a timestep completes.
146  /// This function calls postNetworkProcessingSubclass() on this node, and
147  /// calls postNetworkProcessing() on all our child DOP_Nodes.
148  void postNetworkProcessing(DOP_Engine &engine);
149  /// Gets information about the specified input.
150  /// This function calls getInputInfoSubclass() to do the real work.
151  void getInputInfo(int inputidx, DOP_InOutInfo &info) const;
152  /// Gets information about the specified output.
153  /// This function calls getOutputInfoSubclass() to do the real work.
154  void getOutputInfo(int outputidx, DOP_InOutInfo &info) const;
155 
156  /// Adds an error from the DOP error file.
157  void addError(int code, const char *msg = 0)
158  { UTaddError("DOP", code, msg);}
159  /// Adds a message from the DOP error file.
160  void addMessage(DOP_ErrorCode code, const char *msg = 0)
161  { UTaddMessage("DOP", code, msg);}
162  /// Adds a warning from the DOP error file.
163  void addWarning(DOP_ErrorCode code, const char *msg = 0)
164  { UTaddWarning("DOP", code, msg);}
165  /// Adds a fatal error from the DOP error file.
166  void addFatal(DOP_ErrorCode code, const char *msg = 0)
167  { UTaddFatal("DOP", code, msg);}
168 
169  static const char *theChildTableName;
170  /// Returns "DOP" because our child nodes will be DOP_Nodes.
171  const char *getChildType() const override;
172  /// Returns "DOP" because we are a DOP_Node.
173  const char *getOpType() const override;
174 
175  /// Returns DOP_OPTYPE_ID because our child nodes will be DOP_Nodes.
176  OP_OpTypeId getChildTypeID() const override;
177  /// Returns DOP_OPTYPE_ID because we are a DOP_Node.
178  OP_OpTypeId getOpTypeID() const override;
179 
180  /// Override this method to always return null.
181  /// DOP_Nodes are only interested in the display node, not the render
182  /// node.
183  OP_Node *getRenderNodePtr() override;
184 
185  /// REturn text describing a particular input.
186  const char *inputLabel(unsigned idx) const override;
187 
188  /// Override the opChanged method. Whenever a DOP node parameter changes,
189  /// we need to notify the simulation engine that it needs to recook the
190  /// last timestep to reflect the changed DOP values.
191  void opChanged(OP_EventType reason, void *data=0) override;
192 
193  /// Handle changes to a parameter that is referenced by one of our
194  /// parameters. DOP Nodes want to treat this the same as a parm change.
195  void referencedParmChanged(int pi) override;
196 
197  /// Handle the evaluation of standard local variables.
198  bool evalVariableValue(fpreal &v, int index,
199  int thread) override;
200  /// Handle the evaluation of standards string local variables.
201  bool evalVariableValue(UT_String &v, int index,
202  int thread) override;
203 
204  /// Adds DOP_Operators to teh DOP operator table.
205  static void buildOperatorTable(OP_OperatorTable &table);
206  /// Adds the DOP specific expression functions.
207  static void initializeExpressions();
208  /// Adss Dop specific hscript commands.
209  static void installCommands();
210 
211  /// Return the absolute width of the tile for this node.
212  fpreal getW() const override;
213  /// Return the absolute height of the tile for this node.
214  fpreal getH() const override;
215 
216  /// The display and render ops of a DOP Network are always equal.
217  int getDandROpsEqual() override;
218  int updateDandROpsEqual(int check_inputs = 1) override;
219 
220  // Override clearInterrupted so that we don't invalidate the whole cache
221  // when the user interrupts a cook.
222  void clearInterrupted() override;
223 
224  /// Get the MMB info text for this node.
226  OP_NodeInfoParms &iparms) override;
227  /// Get the info tree specific to this node.
229  const OP_NodeInfoTreeParms &parms) override;
230 
231  /// Return the DOP_Parent pointer associated with this node.
232  /// To cast a DOP_Node to a DOP_Parent, just cast our creator node.
233  DOP_Parent *castToDOPParent() override;
234  /// Return the const DOP_Parent pointer associated with this node.
235  /// To cast a DOP_Node to a DOP_Parent, just cast our creator node.
236  const DOP_Parent *castToDOPParent() const override;
237 
238  /// Return the number of ordered inputs by looking at our DOP_InOutInfo.
239  unsigned orderedInputs() const override;
240 
241  /// Override the setInput functions so that we can send notification to
242  /// the nodes that are our inputs when we disconnect from them. This lets
243  /// then adjust their tile UI if necessary.
244  OP_ERROR setInput(unsigned idx, OP_Node *op,
245  unsigned outputIdx = 0) override;
246  OP_ERROR setInputReference(unsigned idx, const char *label,
247  int keeppos, unsigned outputIdx = 0) override;
248 
249  OP_ERROR setNamedInput(const OP_ConnectorId& input_name,
250  OP_Node *op,
251  const OP_ConnectorId* output_name = NULL
252  ) override;
253 
255  const OP_ConnectorId& input_name,
256  const char *label, int,
257  const OP_ConnectorId* output_name = NULL
258  ) override;
259 
260  bool hasDifferentMultiInputs() const override;
261 
262  /// This functions sets the evaluation object index and the current
263  /// object pointer that is used for local variable evaluation.
264  /// It clears the current relationship information.
265  void setCurrentObject(int objectindex,
266  int objectcount,
267  const SIM_Object *object);
268  /// This functions sets the evaluation relationship index and the current
269  /// relationship pointer that is used for local variable evaluation.
270  /// It clears the current object information.
271  void setCurrentRel(const SIM_Relationship *rel);
272  /// This function copies the current object information from this
273  /// node into another destination node.
274  void copyCurrentObjectAndRelInto(DOP_Node *dest) const;
275  /// Clears the current object and relationship information.
276  void clearCurrentObjectAndRel();
277 
278 protected:
279  /// Cooking a DOP_Node just performs some basic error checks.
280  OP_ERROR cookMe(OP_Context &) override;
281  /// Bypassing a DOP_Node does nothing.
282  OP_ERROR bypassMe(OP_Context &, int &) override;
283  /// Returns the file extension to use for opsave commands on a DOP_Node.
284  const char *getFileExtension(int binary) const override;
285  /// Handle changes to our child node display and render flags.
286  void childFlagChange(OP_Node *) override;
287  /// Checks that the input types match the output types connected to them.
288  OP_ERROR checkInputValidity();
289 
290  /// A DOP_Node has no data, so do nothing.
291  OP_DataType getCookedDataType() const override;
292  /// A DOP_Node has no data, so do nothing.
293  void deleteCookedData() override;
294  /// A DOP_Node has no data, so do nothing.
295  int saveCookedData(const char *, OP_Context &) override;
296  /// A DOP_Node has no data, so do nothing.
297  int saveCookedData(std::ostream &, OP_Context &,
298  int) override;
299 
300  /// DOP Nodes always return their parent's transform, making it
301  /// easy to do stuff like optransform() from within a dopnetwork.
302  bool getWorldTransform(UT_DMatrix4 &xform,
303  OP_Context &context) override;
304  bool getIWorldTransform(UT_DMatrix4 &xform,
305  OP_Context &context) override;
307  OP_Context &context) override;
308 
309  /// Returns whether the DOP should do any processing. This function
310  /// checks the bypass flag and the "activation" parameter if there is
311  /// one. This function should only be called from
312  /// getRequiredOutputsSubclass(), partitionObjectsSubclass(),
313  /// processObjectsSubclass(), and applyOutputDataSubclass().
314  bool isActive(fpreal time);
315 
316  /// This default implementation indicates that all inputs are required.
317  virtual void getRequiredOutputsSubclass(fpreal time,
318  int foroutputidx,
319  UT_Array<DOP_Output> &outputs,
320  const DOP_Engine &engine);
321  /// This default implementation sends all objects to the first output.
322  virtual void partitionObjectsSubclass(fpreal time,
323  const SIM_ObjectArray &objects,
325  const DOP_Engine &engine);
326  /// This default implementation does not affect incoming objects.
327  virtual void processObjectsSubclass(fpreal time,
328  int foroutputidx,
329  const SIM_ObjectArray &objects,
330  DOP_Engine &engine);
331  /// This default implementation does nothing because DOP_Node doesn't
332  /// have any data outputs.
333  virtual void applyOutputDataSubclass(fpreal time, int outputidx,
334  SIM_RootData &rootdata,
335  const char *parentdataname,
336  DOP_Engine &engine,
337  UT_StringArray *datanames);
338  /// This function gets called on all nodes before a timestep starts.
339  /// The default implementation does nothing.
340  virtual void preNetworkProcessingSubclass(DOP_Engine &engine, bool firstframe);
341  /// This function gets called on all nodes after a timestep completes.
342  /// The default implementation does nothing.
343  virtual void postNetworkProcessingSubclass(DOP_Engine &engine);
344  /// This default implementation specifies the input accepts objects.
345  virtual void getInputInfoSubclass(int inputidx,
346  DOP_InOutInfo &info) const;
347  /// This default implementation specifies the output sends out objects.
348  virtual void getOutputInfoSubclass(int outputidx,
349  DOP_InOutInfo &info) const;
350 
351  /// Prefixes the supplied data name with the root name. This utility
352  /// function is often used to concatenate data paths.
353  void makeFullDataName(const char *root,
354  UT_String &name) const;
355  /// Prefixes & suffixes the data name to form a aunique name.
356  void makeUniqueDataName(UT_String &dataname,
357  const char *parentdataname,
358  bool uniquename,
359  bool usenodepath) const;
360  /// Appends the name and index number of the node that is applying data.
361  /// This is used to generate a unique data name.
362  void appendUniqueDataNameSuffix(UT_WorkBuffer &dataname,
363  bool usenodepath) const;
364 
365  /// Steals the global errors, applies them to this node to set
366  /// the local error severity, and then passes it on to the DOP_Engine
367  /// that will be able to re-apply these errors in future cook()
368  /// calls.
369  void moveGlobalErrorsToEngine();
370 
371 private:
372  class DOP_CookData
373  {
374  public:
375  UT_WorkBuffer myUniqueNamePrefix;
376  };
377 
378  DOP_CookData &getCookData() const;
379  void handleNodeChange(OP_EventType reason, void *data);
380 
381  const SIM_ObjectArray *myCurrentObjects;
382  int myCurrentObjectIndex;
383  int myCurrentObjectCount;
384  const SIM_Object *myCurrentObject;
385  const SIM_Relationship *myCurrentRel;
386  bool myIsBusy;
387  mutable UT_StringHolder myUnderscorePathCache;
388  static UT_String theApplyingDataToInput;
389 
390  friend class DOP_Parent;
391 };
392 
393 #endif
virtual int saveCookedData(std::ostream &os, OP_Context &, int binary=0)=0
fpreal getH() const override
Node position/scale is used by the UI.
fpreal getW() const override
Node position/scale is used by the UI.
GLuint const GLchar * name
Definition: glew.h:1814
virtual bool getWorldTransform(UT_Matrix4D &xform, OP_Context &)
GLenum mode
Definition: glew.h:2163
#define SYS_VISIBILITY_EXPORT
GT_API const UT_StringHolder time
GLuint index
Definition: glew.h:1814
virtual bool getTransform(TransformMode mode, UT_Matrix4D &xform, OP_Context &)
virtual OP_OpTypeId getOpTypeID() const =0
UT_API UT_ErrorSeverity UTaddFatal(const char *type, int code, const char *msg=0, const UT_SourceLocation *loc=0)
GLenum GLsizei GLenum GLenum const void * table
Definition: glew.h:4940
virtual const char * inputLabel(unsigned idx) const
UT_ErrorSeverity
Definition: UT_Error.h:25
Parameters for OP_Node::getInfoText()/OP_Node::getNodeSpecificInfoText()
const GLdouble * v
Definition: glew.h:1391
virtual DOP_Parent * castToDOPParent()
Definition: OP_Node.h:2636
int getDandROpsEqual() override
virtual void getNodeSpecificInfoText(OP_Context &context, OP_NodeInfoParms &parms)
UT_API UT_ErrorSeverity UTaddMessage(const char *type, int code, const char *msg=0, const UT_SourceLocation *loc=0)
virtual OP_ERROR cookMe(OP_Context &context)=0
virtual void childFlagChange(OP_Node *)
void addWarning(DOP_ErrorCode code, const char *msg=0)
Adds a warning from the DOP error file.
Definition: DOP_Node.h:163
virtual void clearInterrupted()
Definition: OP_Node.h:2427
virtual const char * getOpType() const =0
#define DOP_API
Definition: DOP_API.h:10
GLint GLenum GLsizei GLint GLsizei const void * data
Definition: glew.h:1379
virtual OP_ERROR setInput(unsigned idx, OP_Node *op, unsigned outputIdx=0)
Sets a given input to connect to an output of a particular node.
const GLuint GLenum const void * binary
Definition: glew.h:3502
Holds pointers to a number of SIM_Object objects.
virtual bool hasDifferentMultiInputs() const
virtual OP_ERROR setNamedInput(const OP_ConnectorId &input_name, OP_Node *op, const OP_ConnectorId *output_name=nullptr)
New input functions that use names instead of indices.
void opChanged(OP_EventType reason, void *data=0) override
virtual bool getIWorldTransform(UT_Matrix4D &xform, OP_Context &)
virtual unsigned orderedInputs() const
int updateDandROpsEqual(int check_inputs=1) override
OP_OpTypeId
Definition: OP_OpTypeId.h:18
virtual OP_Node * getRenderNodePtr()
*Note that the tasks the is the thread number *for the or if it s being executed by a non pool thread(this *can happen in cases where the whole pool is occupied and the calling *thread contributes to running the work load).**Thread pool.Have fun
virtual OP_DataType getCookedDataType() const =0
GLuint GLsizei GLsizei GLchar * label
Definition: glew.h:8986
static const char * theChildTableName
Definition: DOP_Node.h:169
virtual OP_ERROR setNamedInputReference(const OP_ConnectorId &input_name, const char *label, int, const OP_ConnectorId *output_name=nullptr)
virtual const char * getChildType() const
GLfloat GLfloat p
Definition: glew.h:16321
virtual const char * getFileExtension(int binary) const =0
Parameters for OP_Node::fillInfoTree()/OP_Node::fillInfoTreeNodeSpecific()
virtual void fillInfoTreeNodeSpecific(UT_InfoTree &tree, const OP_NodeInfoTreeParms &parms)
void addFatal(DOP_ErrorCode code, const char *msg=0)
Adds a fatal error from the DOP error file.
Definition: DOP_Node.h:166
fpreal64 fpreal
Definition: SYS_Types.h:277
DOP_ErrorCode
Definition: DOP_Error.h:13
virtual void referencedParmChanged(int pi)
UT_API UT_ErrorSeverity UTaddWarning(const char *type, int code, const char *msg=0, const UT_SourceLocation *loc=0)
TransformMode
Definition: OP_Node.h:1119
OP_EventType
Definition: OP_Value.h:22
OP_DataType
Definition: OP_DataTypes.h:28
virtual OP_OpTypeId getChildTypeID() const =0
virtual bool evalVariableValue(UT_String &val, int index, int thread)
constexpr T pi()
Pi constant taken from Boost to match old behaviour.
Definition: Math.h:81
void addMessage(DOP_ErrorCode code, const char *msg=0)
Adds a message from the DOP error file.
Definition: DOP_Node.h:160
This is the base class for all DOP nodes.
Definition: DOP_Node.h:77
void addError(int code, const char *msg=0)
Adds an error from the DOP error file.
Definition: DOP_Node.h:157
SYS_VISIBILITY_EXPORT void newDopOperator(OP_OperatorTable *table)
This declaration allows HDK users to write custom DOP operators.
virtual OP_ERROR bypassMe(OP_Context &context, int &copied_input)=0
GLdouble GLdouble t
Definition: glew.h:1398
UT_API UT_ErrorSeverity UTaddError(const char *type, int code, const char *msg=0, const UT_SourceLocation *loc=0)
virtual void deleteCookedData()=0
static OP_VariablePair theVariablePair
Definition: DOP_Node.h:88
virtual OP_ERROR setInputReference(unsigned idx, const char *label, int keeppos, unsigned outputIdx=0)
Connects an input to particular node by name in the network.