00001 #ifndef OMK_INP_PLUSMINUSEXTENSION_H 00002 #define OMK_INP_PLUSMINUSEXTENSION_H 00003 00004 #include "OMKGenericKeyExtension.h" 00005 #include "OMKExtensibleSimulatedObject.inl" 00006 #include "OMKBaseType.h" 00007 #include "OMKTransformType.h" 00008 #include "OMKIAccessor.h" 00009 namespace OMK 00010 { 00011 namespace Inp 00012 { 00013 00060 template< typename T > 00061 class PlusMinusExtension: 00062 public OMK::Inp::GenericKeyExtension< ExtensibleSimulatedObject > 00063 { 00064 public: 00066 friend class OMK::ExtensionCreatorT< PlusMinusExtension< T > > ; 00068 static Name OMK_CLASS_ID ; 00070 static const bool REGISTERED_IN_EXTENSION_FACTORY ; 00071 protected: 00074 PlusMinusExtension( OMK::ExtensibleSimulatedObject* owner, const Name& id, bool registerExtension = true ) ; 00075 public: 00077 virtual ~PlusMinusExtension() ; 00078 protected: 00080 virtual bool loadExtensionParameters( const ConfigurationParameterDescriptor * node ) 00081 { 00082 bool ok = OMK::Inp::GenericKeyExtension< ExtensibleSimulatedObject >::loadExtensionParameters( node ) ; 00083 T inc ; 00084 ok = ok && ParametersAccessor::get( node, "Increment", inc, _owner ) ; 00085 _increment.set( inc ) ; 00086 Name attributeName ; 00087 ok = ok && ParametersAccessor::get( node, "Attribute", attributeName, _owner ) ; 00088 if( ok ) 00089 { 00090 _attributeAccessor = _owner->getBaseAttribute< T >( attributeName ) ; 00091 ok = _attributeAccessor != 0 ; 00092 if( !ok ) 00093 { 00094 OMERROR( "Unable to find the associated attribute \"" << attributeName << "\" of type \"" << typeid( T ).name() 00095 << ( _owner->getAttribute( attributeName ) ? 00096 "\", the attribute with this name is not of this type (\"" + std::string( _owner->getAttribute( attributeName )->getTypeId().name() ) + "\")." 00097 : "\"." ) ) ; 00098 } 00099 } 00100 return ok ; 00101 } 00103 AttributeT< T > _increment ; 00105 bool _doIncrementation ; 00107 IAccessorT< T >* _attributeAccessor ; 00110 virtual void action() 00111 { 00112 if( !_eventListenerRelease ) increment() ; 00113 else _doIncrementation = true ; 00114 } 00117 virtual void actionRelease() 00118 { 00119 if( !_eventListenerPress ) increment() ; 00120 else _doIncrementation = false ; 00121 } 00123 virtual void postComputeParameters() 00124 { 00125 if( _doIncrementation ) increment() ; 00126 } 00128 void increment() 00129 { 00130 _attributeAccessor->set( _attributeAccessor->get() + _increment ) ; 00131 } 00132 }; 00133 00134 template< typename T > 00135 PlusMinusExtension< T >::PlusMinusExtension( ExtensibleSimulatedObject* owner, const Name& id, bool registerExtension ) 00136 : GenericKeyExtension< ExtensibleSimulatedObject >( owner, id, registerExtension, "ADD" ), 00137 _increment( id, 0 ), 00138 _doIncrementation( false ), 00139 _attributeAccessor( 0 ) 00140 { 00141 _owner->addAttribute( _increment ) ; 00142 } 00143 template< typename T > 00144 PlusMinusExtension< T >::~PlusMinusExtension() {} 00145 00146 00147 template class OMKINPUTS_API PlusMinusExtension<float> ; 00148 typedef PlusMinusExtension< float > PlusMinusFloatExtension ; 00149 template class OMKINPUTS_API PlusMinusExtension<int> ; 00150 typedef PlusMinusExtension< int > PlusMinusIntExtension ; 00151 00152 //------------------------------------------------------------------------- 00153 // Specific implementation for OMK::TypeTransform 00154 template<> 00155 PlusMinusExtension< OMK::Type::Transform >::PlusMinusExtension( ExtensibleSimulatedObject* owner, const Name& id, bool registerExtension ) 00156 : GenericKeyExtension< ExtensibleSimulatedObject >( owner, id, registerExtension, "ADD" ), 00157 _increment( id, Wm4::Vector3f::ZERO ), 00158 _doIncrementation( false ), 00159 _attributeAccessor( 0 ) 00160 { 00161 _owner->addAttribute( _increment ) ; 00162 } 00163 //------------------------------------------------------------------------- 00164 // Specific implementation for OMK::TypeTransform 00165 template<> void 00166 PlusMinusExtension< OMK::Type::Transform >::increment() 00167 { 00168 _attributeAccessor->set( product( _attributeAccessor->get(), _increment.get() ) ) ; 00169 } 00170 //------------------------------------------------------------------------- 00171 template class OMKINPUTS_API PlusMinusExtension<OMK::Type::Transform> ; 00172 typedef PlusMinusExtension< OMK::Type::Transform > PlusMinusTransformExtension ; 00173 //------------------------------------------------------------------------- 00174 } // namespace Inp 00175 } // namespace OMK 00176 00177 #endif // OMK_INP_PLUSMINUSEXTENSION_H
Documentation generated on Mon Jun 9 11:45:57 2008 |
Generated with doxygen by Dimitri van Heesch , 1997-2007 |