GNode.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #ifndef SOFA_SIMULATION_TREE_GNODE_H
00026 #define SOFA_SIMULATION_TREE_GNODE_H
00027
00028 #include <sofa/simulation/common/Node.h>
00029 #include <sofa/simulation/tree/MutationListener.h>
00030 #include <sofa/simulation/tree/xml/NodeElement.h>
00031 #include <stdlib.h>
00032 #include <vector>
00033 #include <string>
00034 #include <iostream>
00035
00036
00037 using std::cout;
00038 using std::endl;
00039
00040 namespace sofa
00041 {
00042
00043 namespace simulation
00044 {
00045 class Visitor;
00046 class VisitorScheduler;
00047
00048 namespace tree
00049 {
00050
00051 class MutationListener;
00052
00055 class GNode : public simulation::Node, public core::objectmodel::BaseNode
00056 {
00057 public:
00058 GNode( const std::string& name="", GNode* parent=NULL );
00059
00060 virtual ~GNode();
00061
00062
00063 void reinit();
00064
00066 virtual void addChild(GNode* node);
00067
00069 virtual void removeChild(GNode* node);
00070
00072 virtual void addChild(BaseNode* node);
00073
00075 virtual void removeChild(BaseNode* node);
00076
00078 virtual void moveChild(GNode* obj);
00079
00080
00083
00085
00086
00088 core::objectmodel::BaseNode* getParent();
00089
00091 const core::objectmodel::BaseNode* getParent() const;
00092
00094 sofa::helper::vector< core::objectmodel::BaseNode* > getChildren();
00095
00097 const sofa::helper::vector< core::objectmodel::BaseNode* > getChildren() const;
00098
00099
00101 GNode* getChild(const std::string& name) const;
00102
00103
00105 GNode* getTreeNode(const std::string& name) const;
00106
00108
00111
00113 virtual bool addObject(core::objectmodel::BaseObject* obj){ return simulation::Node::addObject(obj); }
00114
00116 virtual bool removeObject(core::objectmodel::BaseObject* obj){ return simulation::Node::removeObject(obj); }
00117
00119 virtual void moveObject(core::objectmodel::BaseObject* obj){ simulation::Node::moveObject(obj); }
00120
00122 virtual core::objectmodel::BaseObject* getMechanicalState() const;
00123
00125 virtual core::componentmodel::topology::Topology* getTopology() const;
00126
00128 virtual core::componentmodel::topology::BaseMeshTopology* getMeshTopology() const;
00129
00131 virtual core::objectmodel::BaseObject* getShader() const;
00132
00133 const BaseContext* getContext() const { return simulation::Node::getContext(); }
00134 BaseContext* getContext() { return simulation::Node::getContext(); }
00135
00136
00138
00139
00141 virtual void initVisualContext();
00142
00144 virtual void updateContext();
00145
00147 virtual void updateVisualContext(int FILTER=0);
00148
00150 virtual void updateSimulationContext();
00151
00152
00154 void addTime(ctime_t t, const std::string& s, core::objectmodel::BaseObject* obj);
00155
00157 ctime_t endTime(ctime_t t0, const std::string& s, core::objectmodel::BaseObject* obj);
00158
00160 void addTime(ctime_t t, const std::string& s, core::objectmodel::BaseObject* obj, core::objectmodel::BaseObject* parent);
00161
00163 ctime_t endTime(ctime_t t0, const std::string& s, core::objectmodel::BaseObject* obj, core::objectmodel::BaseObject* parent);
00164
00165
00166
00167
00169 std::string getPathName() const;
00170
00174 virtual void* getObject(const sofa::core::objectmodel::ClassInfo& class_info, SearchDirection dir = SearchUp) const;
00175
00179 virtual void* getObject(const sofa::core::objectmodel::ClassInfo& class_info, const std::string& path) const;
00180
00184 virtual void getObjects(const sofa::core::objectmodel::ClassInfo& class_info, GetObjectsCallBack& container, SearchDirection dir = SearchUp) const;
00185
00186 void addListener(MutationListener* obj);
00187
00188 void removeListener(MutationListener* obj);
00189
00190
00191
00192 Single<GNode> parent;
00193 Sequence<GNode> child;
00194 typedef Sequence<GNode>::iterator ChildIterator;
00195
00196
00197
00198 static void create(GNode*& obj, xml::Element<core::objectmodel::BaseNode>* arg)
00199 {
00200 obj = new GNode();
00201 obj->parse(arg);
00202 }
00203
00204 protected:
00205
00206
00207 virtual void doAddChild(GNode* node);
00208 void doRemoveChild(GNode* node);
00209
00210 void notifyAddChild(GNode* node);
00211 void notifyRemoveChild(GNode* node);
00212 void notifyMoveChild(GNode* node, GNode* prev);
00213
00216 void doExecuteVisitor(simulation::Visitor* action);
00217
00218 friend class simulation::VisitorScheduler;
00219
00220 Sequence<MutationListener> listener;
00221
00222
00223 protected:
00224
00225
00226 void notifyAddObject(core::objectmodel::BaseObject* obj);
00227 void notifyRemoveObject(core::objectmodel::BaseObject* obj);
00228 void notifyMoveObject(core::objectmodel::BaseObject* obj, GNode* prev);
00229 };
00230
00231 }
00232
00233 }
00234
00235 }
00236
00237 #endif