BaseContext.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 :: Framework                              *
00020 *                                                                             *
00021 * Authors: M. Adam, J. Allard, B. Andre, P-J. Bensoussan, S. Cotin, C. Duriez,*
00022 * H. Delingette, F. Falipou, F. Faure, S. Fonteneau, L. Heigeas, C. Mendoza,  *
00023 * M. Nesme, P. Neumann, J-P. de la Plata Alcade, F. Poyer and F. Roy          *
00024 *                                                                             *
00025 * Contact information: contact@sofa-framework.org                             *
00026 ******************************************************************************/
00027 #ifndef SOFA_CORE_OBJECTMODEL_BASECONTEXT_H
00028 #define SOFA_CORE_OBJECTMODEL_BASECONTEXT_H
00029 
00030 #include <sofa/core/objectmodel/Base.h>
00031 #include <sofa/core/objectmodel/ClassInfo.h>
00032 #include <sofa/defaulttype/SolidTypes.h>
00033 #include <set>
00034 
00035 namespace sofa
00036 {
00037   namespace simulation
00038   {
00039       class Visitor;
00040   }
00041 
00042   namespace core
00043   {
00044 
00045     // forward declaration of classes accessible from the context
00046     namespace componentmodel
00047     {
00048       namespace topology
00049       {
00050     class Topology;
00051     class BaseTopology;
00052     class BaseMeshTopology;
00053       }
00054     }
00055 
00056     namespace objectmodel
00057     {
00058 
00059       class BaseObject;
00060       class Event;
00061 
00073       class BaseContext : public virtual Base
00074       {
00075       public:
00076 
00079 #ifdef SOFA_FLOAT
00080     typedef defaulttype::SolidTypes<float> SolidTypes;
00081 #else
00082     typedef defaulttype::SolidTypes<double> SolidTypes;
00083 #endif
00084     typedef SolidTypes::Transform Frame;
00085     typedef SolidTypes::Vec Vec3;
00086     typedef SolidTypes::Rot Quat;
00087     typedef SolidTypes::Mat Mat33;
00088     typedef SolidTypes::SpatialVector SpatialVector;
00090 
00091     BaseContext();
00092     virtual ~BaseContext();
00093 
00096     static BaseContext* getDefault();
00097 
00099     enum SearchDirection { SearchUp = -1, Local = 0, SearchDown = 1, SearchRoot = 2 };
00100 
00103 
00105     virtual bool isActive() const;
00106 
00108     virtual void setActive(bool){};
00109 
00111     virtual double getTime() const;
00112 
00114     virtual double getDt() const;
00115 
00117     virtual bool getAnimate() const;
00118 
00120     virtual bool getMultiThreadSimulation() const;
00121 
00123     virtual bool getShowCollisionModels() const;
00124 
00126     virtual bool getShowBoundingCollisionModels() const;
00127 
00129     virtual bool getShowBehaviorModels() const;
00130 
00132     virtual bool getShowVisualModels() const;
00133 
00135     virtual bool getShowMappings() const;
00136 
00138     virtual bool getShowMechanicalMappings() const;
00139 
00141     virtual bool getShowForceFields() const;
00142 
00144     virtual bool getShowInteractionForceFields() const;
00145 
00147     virtual bool getShowWireFrame() const;
00148 
00150     virtual bool getShowNormals() const;
00151 
00153     virtual int getCurrentLevel() const;
00154     
00156     virtual int getCoarsestLevel() const;
00157     
00159     virtual int getFinestLevel() const;
00160     
00162     //     virtual unsigned int nbLevels() const;
00163 
00165 
00166 
00170     virtual const Frame& getPositionInWorld() const;
00172     virtual void setPositionInWorld(const Frame&)
00173     {}
00174 
00176     virtual const SpatialVector& getVelocityInWorld() const;
00178     virtual void setVelocityInWorld(const SpatialVector&)
00179     {}
00180 
00182     virtual const Vec3& getVelocityBasedLinearAccelerationInWorld() const;
00184     virtual void setVelocityBasedLinearAccelerationInWorld(const Vec3& )
00185     {}
00187 
00188 
00190     virtual Vec3 getLocalGravity() const;
00192     //virtual void setGravity( const Vec3& ) { }
00194     virtual const Vec3& getGravityInWorld() const;
00196     virtual void setGravityInWorld( const Vec3& )
00197     { }
00198 
00201 
00203     virtual BaseObject* getMechanicalState() const;
00204 
00206     virtual core::componentmodel::topology::Topology* getTopology() const;
00207     
00209     virtual core::componentmodel::topology::BaseMeshTopology* getMeshTopology() const;
00210     
00212     virtual BaseObject* getMass() const;
00213 
00215     virtual BaseObject* getShader() const;
00216 
00220     virtual void* getObject(const ClassInfo& class_info, SearchDirection dir = SearchUp) const;
00221 
00225     virtual void* getObject(const ClassInfo& class_info, const std::string& path) const;
00226 
00227     class GetObjectsCallBack
00228     {
00229     public:
00230       virtual ~GetObjectsCallBack() {}
00231       virtual void operator()(void* ptr) = 0;
00232     };
00233 
00237     virtual void getObjects(const ClassInfo& class_info, GetObjectsCallBack& container, SearchDirection dir = SearchUp) const;
00238 
00240     template<class T>
00241       T* get(SearchDirection dir = SearchUp) const
00242       {
00243         return reinterpret_cast<T*>(this->getObject(classid(T), dir));
00244       }
00245 
00247     template<class T>
00248       void get(T*& ptr, SearchDirection dir = SearchUp) const
00249       {
00250         ptr = this->get<T>(dir);
00251       }
00252 
00254     template<class T>
00255       T* get(const std::string& path) const
00256       {
00257         return reinterpret_cast<T*>(this->getObject(classid(T), path));
00258       }
00259 
00261     template<class T>
00262       void get(T*& ptr, const std::string& path) const
00263       {
00264         ptr = this->get<T>(path);
00265       }
00266 
00267     template<class T, class Container>
00268       class GetObjectsCallBackT : public GetObjectsCallBack
00269     {
00270     public:
00271       Container* dest;
00272     GetObjectsCallBackT(Container* d) : dest(d) {}
00273       virtual void operator()(void* ptr)
00274       {
00275         dest->push_back(reinterpret_cast<T*>(ptr));
00276       }
00277     };
00278 
00280     template<class T, class Container>
00281       void get(Container* list, SearchDirection dir = SearchUp) const
00282     {
00283       GetObjectsCallBackT<T,Container> cb(list);
00284       this->getObjects(classid(T), cb, dir);
00285     }
00286 
00287 
00289 
00292 
00293 
00295     virtual void setDt( double /*dt*/ )
00296     { }
00297 
00299     virtual void setAnimate(bool /*val*/)
00300     { }
00301 
00303     virtual void setMultiThreadSimulation(bool /*val*/)
00304     { }
00305 
00307     virtual void setShowCollisionModels(bool /*val*/)
00308     { }
00309 
00311     virtual void setShowBoundingCollisionModels(bool /*val*/)
00312     { }
00313 
00315     virtual void setShowBehaviorModels(bool /*val*/)
00316     { }
00317 
00319     virtual void setShowVisualModels(bool /*val*/)
00320     { }
00321 
00323     virtual void setShowMappings(bool /*val*/)
00324     { }
00325 
00327     virtual void setShowMechanicalMappings(bool /*val*/)
00328     { }
00329 
00331     virtual void setShowForceFields(bool /*val*/)
00332     { }
00333 
00335     virtual void setShowInteractionForceFields(bool /*val*/)
00336     { }
00337 
00339     virtual void setShowWireFrame(bool /*val*/)
00340     { }
00341 
00343     virtual void setShowNormals(bool /*val*/)
00344     { }
00345     
00347     virtual bool setCurrentLevel(int )
00348     {
00349       return false;
00350     }
00351     
00353     virtual void setCoarsestLevel(int ){}
00354     
00356     virtual void setFinestLevel(int ){}
00357 
00359 
00362 
00364     virtual void setMechanicalState( BaseObject* )
00365     { }
00366 
00368     virtual void setTopology( BaseObject* )
00369     { }
00370 
00372 
00375 
00377     virtual bool addObject( BaseObject* /*obj*/ )
00378     {
00379       return false;
00380     }
00381 
00383     virtual bool removeObject( BaseObject* /*obj*/ )
00384     {
00385       return false;
00386     }
00387 
00389 
00392 
00394     virtual void executeVisitor( simulation::Visitor* );
00395 
00397     virtual void propagateEvent( Event* );
00398 
00400 
00401       };
00402 
00403     } // namespace objectmodel
00404 
00405   } // namespace core
00406 
00407 } // namespace sofa
00408 
00409 #endif
00410 
00411 

Generated on Sun Nov 23 02:29:25 2008 for Sofa by  doxygen 1.5.7.1