OMKGenericKeyExtension.h

Go to the documentation of this file.
00001 #ifndef OMK_INP_GENERICKEYEXTENSION_H
00002 #define OMK_INP_GENERICKEYEXTENSION_H
00003 
00004 #include "OMKExtension.h"
00005 #include "OMKParametersAccessor.inl"
00006 #include "OMKKeyListener.h"
00007 #include "OMKEventListenerCallBack.h"
00008 #include "OMKInputExtension.h"
00009 #include "OMKAddInputKeyPrm.h"
00010 namespace OMK
00011 {
00012   namespace Vis
00013   {
00014 class OgreVis ;
00015   }
00016 
00017   namespace Inp
00018   {
00019 
00060     template< class OwnerClass >
00061 class GenericKeyExtension:  
00062   public OMK::ExtensionT< OwnerClass >
00063 {
00065 
00066 protected:
00069   GenericKeyExtension( ExtensibleSimulatedObject* owner, const Name& id, bool registerExtension, const std::string& defaultKey ) 
00070   : ExtensionT< OwnerClass >( owner, id ),
00071     _eventListenerPress( 0 ),
00072     _eventListenerRelease( 0 ),
00073     _defaultKey( defaultKey )
00074   {
00075   }
00076 public:
00077         virtual ~GenericKeyExtension()
00078   {
00079     delete _eventListenerPress ;
00080     delete _eventListenerRelease ;
00081   }
00083 
00084 protected:
00087 
00088 protected:
00089 
00091 
00092 
00093 
00094 
00095 
00096   virtual bool loadExtensionParameters( const ConfigurationParameterDescriptor * node ) 
00097   {
00098     bool ok = true ;
00099     std::string key( _defaultKey ) ;
00100     ParametersAccessor::get( node, "Key", key ) ;
00101     std::string visuName( "visualisation" ) ;
00102     ok = ok && ParametersAccessor::get( node, "VisuName", visuName, _owner ) ;
00103     // What kind of action
00104     bool press = true ;
00105     bool release = false ;
00106     std::string actionOn ;
00107     if( ParametersAccessor::get( node, "ActionOn", actionOn ) )
00108     {
00109       std::transform( actionOn.begin(), actionOn.end(), actionOn.begin(), toupper ) ;
00110       press = ( actionOn == "PRESS" ) || ( actionOn == "BOTH" ) ;
00111       release = ( actionOn == "RELEASE" ) || ( actionOn == "BOTH" ) ;
00112     }
00113     // initialisation of the listeners
00114     if( ok && press )
00115     {
00116       _eventListenerPress = new EventListenerCallBack< GenericKeyExtension< OwnerClass > >
00117           ( *_owner, this, 
00118             (typename EventListenerCallBack< GenericKeyExtension< OwnerClass > >::CallBackFct)&GenericKeyExtension< OwnerClass >::pressFct, 
00119             OMK::Inp::KeyListener::getKeyPressCode( key ) ) ;
00120       _owner->sendValuedEvent( visuName, OMK::Inp::InputExtension::ADD_KEY, OMK::Inp::AddInputKeyPrm( key, _owner->getName() ) ) ;
00121     }
00122     if( ok && release )
00123     {
00124       _eventListenerRelease = new EventListenerCallBack< GenericKeyExtension< OwnerClass > >
00125           ( *_owner, this, 
00126             (typename EventListenerCallBack< GenericKeyExtension< OwnerClass > >::CallBackFct)&GenericKeyExtension< OwnerClass >::releaseFct, 
00127             OMK::Inp::KeyListener::getKeyReleaseCode( key ) ) ;
00128       _owner->sendValuedEvent( visuName, OMK::Inp::InputExtension::ADD_KEY, OMK::Inp::AddInputKeyPrm( key, _owner->getName() ) ) ;
00129     }
00130     return ok ;
00131   }
00132 
00134 
00135 
00136 
00137   using OMK::ExtensionT< OwnerClass >::_owner ;
00142   EventListener* _eventListenerPress ;
00147   EventListener* _eventListenerRelease ;
00149   const std::string _defaultKey ;
00151   bool pressFct( Event * event )
00152   {
00153     action() ;
00154     // Returns false because may be another key listener wants to see the event
00155     return false ;
00156   }
00158   bool releaseFct( Event * event )
00159   {
00160     actionRelease() ;
00161     // Returns false because may be another key listener wants to see the event
00162     return false ;
00163   }
00165   virtual void action() {}
00167   virtual void actionRelease() {}
00168 };
00169   } // namespace Inp
00170 } // namespace OMK
00171 
00172 #endif // OMK_INP_GENERICKEYEXTENSION_H

logo OpenMask

Documentation generated on Mon Jun 9 11:45:56 2008

Generated with doxygen by Dimitri van Heesch ,   1997-2007