GNode.h

Go to the documentation of this file.
00001 /******************************************************************************
00002 *       SOFA, Simulation Open-Framework Architecture, version 1.0 beta 3      *
00003 *                (c) 2006-2008 MGH, INRIA, USTL, UJF, CNRS                    *
00004 *                                                                             *
00005 * This library is free software; you can redistribute it and/or modify it     *
00006 * under the terms of the GNU Lesser General Public License as published by    *
00007 * the Free Software Foundation; either version 2.1 of the License, or (at     *
00008 * your option) any later version.                                             *
00009 *                                                                             *
00010 * This library is distributed in the hope that it will be useful, but WITHOUT *
00011 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or       *
00012 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License *
00013 * for more details.                                                           *
00014 *                                                                             *
00015 * You should have received a copy of the GNU Lesser General Public License    *
00016 * along with this library; if not, write to the Free Software Foundation,     *
00017 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301 USA.          *
00018 *******************************************************************************
00019 *                               SOFA :: Modules                               *
00020 *                                                                             *
00021 * Authors: The SOFA Team and external contributors (see Authors.txt)          *
00022 *                                                                             *
00023 * Contact information: contact@sofa-framework.org                             *
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     //virtual const char* getTypeName() const { return "GNODE"; }
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 //    virtual void executeVisitor(Visitor* action);
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     // should this be public ?
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     // VisitorScheduler can use doExecuteVisitor() method
00218     friend class simulation::VisitorScheduler;
00219 
00220     Sequence<MutationListener> listener;
00221 
00222     
00223 protected:
00224 /*    virtual void doAddObject(core::objectmodel::BaseObject* obj);
00225     virtual void doRemoveObject(core::objectmodel::BaseObject* obj);*/
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 } // namespace tree
00232 
00233 } // namespace simulation
00234 
00235 } // namespace sofa
00236 
00237 #endif

Generated on Sun Nov 23 04:05:48 2008 for Sofa by  doxygen 1.5.7.1