BaseObject.cpp
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
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
00049
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
00063 return context_;
00064 }
00065
00066 BaseContext* BaseObject::getContext()
00067 {
00068 return (context_==NULL)?BaseContext::getDefault():context_;
00069
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
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130 double BaseObject::getTime() const
00131 {
00132 return getContext()->getTime();
00133 }
00134
00135
00136 }
00137
00138 }
00139
00140 }
00141