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