BaseObject.cpp

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 #include <sofa/core/objectmodel/BaseObject.h>
00028 #include <sofa/core/objectmodel/Event.h>
00029 #include <sofa/core/objectmodel/KeypressedEvent.h>
00030 #include <iostream>
00031 using std::cerr;
00032 using std::endl;
00033 
00034 namespace sofa
00035 {
00036 
00037 namespace core
00038 {
00039 
00040 namespace objectmodel
00041 {
00042 
00043 BaseObject::BaseObject()
00044         : Base()
00045         , f_listening(initData( &f_listening, false, "listening", "if true, handle the events, otherwise ignore the events"))
00046         , f_printLog(initData( &f_printLog, false, "printLog", "if true, print logs at run-time"))
00047         , context_(NULL)
00048 /*        , m_isListening(false)
00049         , m_printLog(false)*/
00050 {}
00051 
00052 BaseObject::~BaseObject()
00053 {}
00054 
00055 void BaseObject::setContext(BaseContext* n)
00056 {
00057     context_ = n;
00058 }
00059 
00060 const BaseContext* BaseObject::getContext() const
00061 {
00062     //return (context_==NULL)?BaseContext::getDefault():context_;
00063     return context_;
00064 }
00065 
00066 BaseContext* BaseObject::getContext()
00067 {
00068     return (context_==NULL)?BaseContext::getDefault():context_;
00069     //return context_;
00070 }
00071 
00072 void BaseObject::init()
00073 { }
00074 
00075 void BaseObject::bwdInit()
00076 { }
00077 
00079 void BaseObject::reinit()
00080 { std::cout<<"WARNING: for this object, the reinit method does nothing.\n\n";}
00081 
00083 void BaseObject::storeResetState()
00084 { }
00085 
00087 void BaseObject::reset()
00088 { }
00089 
00090 void BaseObject::writeState( std::ostream& )
00091 { }
00092 
00096 void BaseObject::cleanup()
00097 { }
00098 
00100 void BaseObject::handleEvent( Event* e )
00101 {
00102     cerr<<"BaseObject "<<getName()<<" ("<<getTypeName()<<") gets an event"<<endl;
00103     if( KeypressedEvent* ke = dynamic_cast<KeypressedEvent*>( e ) )
00104     {
00105         cerr<<"BaseObject "<<getName()<<" gets a key event: "<<ke->getKey()<<endl;
00106     }
00107 }
00108 
00109 // void BaseObject::setListening( bool b )
00110 // {
00111 //     m_isListening = b;
00112 // }
00113 //
00114 // bool BaseObject::isListening() const
00115 // {
00116 //     return m_isListening;
00117 // }
00118 //
00119 // BaseObject* BaseObject::setPrintLog( bool b )
00120 // {
00121 //     m_printLog = b;
00122 //     return this;
00123 // }
00124 //
00125 // bool BaseObject::printLog() const
00126 // {
00127 //     return m_printLog;
00128 // }
00129 
00130 double BaseObject::getTime() const
00131 {
00132     return getContext()->getTime();
00133 }
00134 
00135 
00136 } // namespace objectmodel
00137 
00138 } // namespace core
00139 
00140 } // namespace sofa
00141 

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