HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
DOP_Engine.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_Engine.h ( SOP Library, C++)
7  *
8  * COMMENTS:
9  */
10 
11 #ifndef __DOP_Engine_h__
12 #define __DOP_Engine_h__
13 
14 #include "DOP_API.h"
15 #include "DOP_Output.h"
16 #include <SIM/SIM_Engine.h>
17 #include <DEP/DEP_MicroNode.h>
18 #include <UT/UT_SymbolTable.h>
19 #include <UT/UT_ErrorManager.h>
20 
21 
22 class OP_Network;
23 class SIM_ObjectArray;
24 class DOP_Node;
25 class DOP_Output;
26 class DOP_OutputDependency;
27 
31 
32 /// This subclass of SIM_Engine is the one used to contain simulations
33 /// controlled by DOP_Node networks. It serves as the glue between the
34 /// pure simulation library and the DOP_Node interface given to simulations
35 /// in Houdini.
37 {
38 public:
39  /// Constructor is given a pointer to the network that owns the simulation.
40  DOP_Engine(OP_Node *owner);
41  /// Destructor destroys all data for the simulation.
42  ~DOP_Engine() override;
43 
44  /// Groups objects passed to a DOP_Node by the input they arrived in.
45  /// Each entry in the returned UT_ValArray represents an input to
46  /// the DOP_Node. If a particular input is not connected, the
47  /// corresponding entry in the array will by null. Generally this
48  /// function will be called from DOP_Node::processObjects() by nodes
49  /// which need to have objects coming through one input interact in
50  /// some way with objects coming through another input.
51  void getObjectsAtInputs(DOP_Node *node,
53  objectsatinputs) const;
54 
55  /// Gets the objects in the stream associated with the supplied node.
56  /// For nodes with multiple outputs, the result is the combination of all
57  /// objects on any output. This function does not do any cooking of the
58  /// networks, or call partitionObjects on any nodes. It only pulls
59  /// existing data from our set of outputs to process. This function
60  /// is for use by expression functions that want to know what objects
61  /// most recently passed through a particular node.
62  void getObjectsForNode(DOP_Node *node,
63  SIM_ConstObjectArray &objects) const;
64 
65  /// Adds the specified root data (cast to an object) as a sort of
66  /// "extra object" processed by a DOP node. These extra objects don't
67  /// affect cooking at all, but show up in the list of objects processed
68  /// by that node (in the MMB info and dopnodeobjs expression).
69  void addObjectForNode(DOP_Node *node,
70  SIM_RootData &rootdata);
71 
72  /// Gets a pointer to the node that is currently being processed by
73  /// the DOP_Engine. The return value will be null if the engine is not
74  /// currently in the preSimulationStep and inside a call to
75  /// DOP_Node::processObjects(). This function is used by subnet DOPs
76  /// to evaluate standard DOP local variables in the context of the node
77  /// that is being processed (since subnets have no context of their own).
78  DOP_Node *getDopNodeBeingProcessed() const;
79 
80  /// Explicitly dirty dependents of this simulation
81  void propagateSimDirty(bool send_event);
82 
83  /// Pass through to our parent's notification
85 
86  /// Returns whether resimulations is globally disabled.
87  static bool getWantResimulation()
88  { return theWantResimulation; }
89 
90  /// Globally disables resimulations caused by external node changes. This
91  /// is meant for internal use.
92  static void setWantResimulation(bool want_resimulation)
93  { theWantResimulation = want_resimulation; }
94 
95  /// Re-applies any errors cached locally to the given node.
96  /// Only applies errors with severity greater or equal to minimum.
97  /// If only_nodes_errors is false, will catch all errors and apply
98  /// them to sink.
99  /// @{
100  void applyErrorsToNode(OP_Node *sink,
101  OP_Node *sourcenode,
102  bool only_nodes_errors=true,
103  UT_ErrorSeverity minseverity = UT_ERROR_MESSAGE) const;
104  void applyErrorsToManager(UT_ErrorManager *sink,
105  OP_Node *sourcenode,
106  bool only_nodes_errors=true,
107  UT_ErrorSeverity minseverity = UT_ERROR_MESSAGE) const;
108  /// @}
109 
111  { return myErrorSeverity; }
112 
113  /// Registers an error against a specified node so it will be
114  /// resurrected every time that node recooks. Usually handled
115  /// transparently by addErrorSubclass, but required when the
116  /// error is added outside the simulation path.
117  void registerNodeError(OP_Node *node, const UT_StringHolder &errmsg, UT_ErrorSeverity sev) const;
118 
119 protected:
120  /// Overrides the base class method to make sure that all our internal
121  /// data related to the last timestep cook has been cleared away.
122  void resetSimulation() override;
123  /// Overrides the actions that occur before doing a simulation step.
124  /// This is where the network of DOP_Nodes is parsed. Each DOP_Node
125  /// has a chance to alter the simulation objects in the
126  /// DOP_Node::processObjects() function. Nodes can also specify
127  /// which objects are sent to each output of the node.
128  void preSimulationStep() override;
129  /// Overrides the actions that occur after a simulation step.
130  void postSimulationStep() override;
131  /// When the most recent simulation state is being deleted or
132  /// removed from memory, we have to clear all our references to
133  /// it. This basically means our lists of output objects to process.
134  void clearReferencesToMostRecentState() override;
135  /// Sets up custom data on a new object.
136  /// This implementation calls the base class implementation, then it
137  /// stores information about the DOP_Node that created the object.
138  void objectCreated(SIM_Object *object) override;
139  /// Overrides the default behavior when removing a simulation object.
140  /// This implementation eliminates all references to this object stored
141  /// in our internal data then calls the base class implementation.
142  void objectRemoved(SIM_Object *object) override;
143  /// Override this method to flag ourselves as requiring a resimulation
144  /// when any of our external referenced nodes changes in a significant
145  /// way.
147  OP_Node *changednode,
148  OP_EventType eventtype,
149  void *data,
150  bool isguide) override;
151  /// Uses the object and data arguments to put the error message on an
152  /// appropriate DOP_Node. First priority is given to the node that
153  /// created the data, then the node that created the object, then the
154  /// node with the display flag.
155  void addErrorSubclass(const SIM_RootData *rootdata,
156  const SIM_Data *data,
157  int errorcode,
158  const char *errorparm,
159  UT_ErrorSeverity severity) const override;
160  /// We keep track of all the accumulated errors so we can re-post
161  /// them every time the DOP nodes cook (as they cook independently
162  /// of simulating.) This will clear out all the cached errors.
163  void resetErrorsSubclass() override;
164  /// Returns the simulation time that corresponds to the given global time.
166  const SIM_Time &t) const override;
167  /// Returns the global time that corresponds to the given simulation time.
169  const SIM_Time &t) const override;
170 
171  /// Alerts our owner that we are simulating due to an internally
172  /// generated need. Returns the previous state
173  bool setIsSimulating(bool issimulating) const override;
174 
175 private:
176  void buildObjectListForOutput(DOP_OutputDependency &output) const;
177  void partitionObjectsForOutput(DOP_OutputDependency &output) const;
178  void createOutputsToProcess(DOP_Node *node, int outputidx,
179  const SIM_Time &optime);
180  void clearOutputsToProcess();
181  void assignObjectsToCreatorOutputs();
182  void removeAllUnusedObjects(const SIM_ObjectArray &usedobjs);
183 
184  template <typename SinkF>
185  void applyErrorsToSink(OP_Node *sourcenode,
186  bool only_nodes_errors,
187  UT_ErrorSeverity minseverity,
188  SinkF applyError) const;
189 
190  UT_ErrorSeverity myOwnerSeverity;
191  DOP_OutputArray myOutputsToProcess;
192  DOP_OutputMap myOutputsSymbolTable;
193  int myProcessingOutput;
194 
195  struct ErrorInfo
196  {
197  UT_StringHolder msg;
198  UT_ErrorSeverity sev;
199  };
200 
201  mutable UT_Lock myErrorManagerLock;
202  mutable UT_ArrayMap<int, UT_Array<ErrorInfo>> myNodeErrors;
203  mutable UT_ErrorSeverity myErrorSeverity;
204 
205  static bool theWantResimulation;
206 };
207 
208 #endif
virtual void preSimulationStep()
virtual void resetSimulation()
UT_ErrorSeverity
Definition: UT_Error.h:25
UT_ErrorSeverity getErrorSeverity() const
Definition: DOP_Engine.h:110
virtual void notifySimulationChangeSinksOfChange()
Definition: SIM_Engine.h:374
static void setWantResimulation(bool want_resimulation)
Definition: DOP_Engine.h:92
#define DOP_API
Definition: DOP_API.h:10
virtual void clearReferencesToMostRecentState()
Holds pointers to a number of SIM_Object objects.
UT_ValArray< DOP_OutputDependency * > DOP_OutputArray
Definition: DOP_Engine.h:26
virtual void postSimulationStep()
This function is run after all objects are processed by their solvers.
virtual void resetErrorsSubclass()
UT_Map< DOP_Output, DOP_OutputDependency * > DOP_OutputMap
Definition: DOP_Engine.h:29
GLenum GLenum severity
Definition: glcorearb.h:2539
Holds pointers to a number of const SIM_Object objects.
GLdouble t
Definition: glad.h:2397
virtual void addErrorSubclass(const SIM_RootData *rootdata, const SIM_Data *data, int errorcode, const char *errorparm, UT_ErrorSeverity severity) const
The default implementation of this function does nothing.
virtual void objectCreated(SIM_Object *object)
virtual void objectRemoved(SIM_Object *object)
OP_EventType
Definition: OP_Value.h:22
A global error manager scope.
DOP_OutputMap::const_iterator DOP_OutputMapConstIter
Definition: DOP_Engine.h:30
virtual const SIM_Time getEngineTimeSubclass(const SIM_Time &t) const
Returns the simulation time that corresponds to the given global time.
This is the base class for all DOP nodes.
Definition: DOP_Node.h:77
virtual void handleExternalNodeChangeSubclass(OP_Node *changednode, OP_EventType eventtype, void *data, bool isguide)
static bool getWantResimulation()
Returns whether resimulations is globally disabled.
Definition: DOP_Engine.h:87
virtual const SIM_Time getGlobalTimeSubclass(const SIM_Time &t) const
Returns the global time that corresponds to the given simulation time.
Definition: format.h:895
virtual bool setIsSimulating(bool issimulating) const