00001 00002 /************************************************************************/ 00003 /* This file is part of openMask(c) INRIA, CNRS, Universite de Rennes 1 */ 00004 /* 1993-2002, thereinafter the Software */ 00005 /* */ 00006 /* The Software has been developped within the Siames Project. */ 00007 /* INRIA, the University of Rennes 1 and CNRS jointly hold intellectual */ 00008 /* property rights */ 00009 /* */ 00010 /* The Software has been registered with the Agence pour la Protection */ 00011 /* des Programmes (APP) under registration number */ 00012 /* IDDN.FR.001.510008.00.S.P.2001.000.41200 */ 00013 /* */ 00014 /* This file may be distributed under the terms of the Q Public License */ 00015 /* version 1.0 as defined by Trolltech AS of Norway and appearing in */ 00016 /* the file LICENSE.QPL included in the packaging of this file. */ 00017 /* */ 00018 /* Licensees holding valid specific licenses issued by INRIA, CNRS or */ 00019 /* Universite Rennes 1 for the software may use this file in */ 00020 /* acordance with that specific license */ 00021 /************************************************************************/ 00022 00023 #if !defined OMK_ATTRIBUTEANIMATOR_H 00024 #define OMK_ATTRIBUTEANIMATOR_H 00025 00026 #include "OMKAttribute.h" 00027 #include "OMKAddAnimatorPrm.h" 00028 #include "OMKVisBase.h" 00029 namespace OMK 00030 { 00031 00032 //----------------------------------------------------------------- 00101 template< typename PrmType, typename ModelType, typename AccessorType > 00102 class IAttributeAnimatorT : public IAttributeT< PrmType, ModelType, AccessorType > 00103 { 00104 public: 00105 using IAttributeT< PrmType, ModelType, AccessorType >::getId; 00106 using IAttributeT< PrmType, ModelType, AccessorType >::get; 00107 using IAttributeT< PrmType, ModelType, AccessorType >::isUpdated; 00108 using IAttributeT< PrmType, ModelType, AccessorType >::sendValueTo; 00109 using IAttributeT< PrmType, ModelType, AccessorType >::sendValueOf; 00110 using IAttributeT< PrmType, ModelType, AccessorType >::fireValueTo; 00111 using IAttributeT< PrmType, ModelType, AccessorType >::fireValueOf; 00112 using IAttributeT< PrmType, ModelType, AccessorType >::_output; 00113 using IAttributeT< PrmType, ModelType, AccessorType >::_owner; 00115 00116 protected: 00125 IAttributeAnimatorT( const Name& id, const AccessorType& init ) ; 00126 public: 00130 virtual ~IAttributeAnimatorT() ; 00132 00134 00135 protected: 00140 virtual bool loadParameters( const ConfigurationParameterDescriptor* node, const std::string* aliasName ) ; 00141 public: 00142 bool initAnimator( const ConfigurationParameterDescriptor* node = 0 ) { return initAnimator( node, 0 ) ; } 00143 bool initAnimator( const ConfigurationParameterDescriptor* node, const std::string& aliasName ) { return initAnimator( node, &aliasName ) ; } 00144 protected: 00145 virtual bool initAnimator( const ConfigurationParameterDescriptor* node, const std::string* aliasName ) ; 00147 00149 00150 public: 00154 virtual void setValueToOutput() ; 00156 protected: 00157 Name _localVisu ; 00158 EventIdentifier _eventId ; 00159 Name _eventBaseId ; 00160 enum 00161 { 00162 TYPE_UNINITIALISED = 0, 00163 TYPE_OUTPUT, 00164 TYPE_EVENT_LOCAL_VISU, 00165 TYPE_SIGNAL_ALL_VISU 00166 } _type ; 00167 } ; 00168 00169 //----------------------------------------------------------------- 00184 template< typename PrmType > 00185 class AttributeAnimatorT : public IAttributeAnimatorT< PrmType, OMK::Type::SimpleTypeT< PrmType >, AccessorT< PrmType > > 00186 { 00188 00189 public: 00192 AttributeAnimatorT( const Name& id, const PrmType& value ) 00193 : IAttributeAnimatorT< PrmType, OMK::Type::SimpleTypeT< PrmType >, AccessorT< PrmType > >( id, AccessorT< PrmType >( value ) ) {} 00195 virtual ~AttributeAnimatorT() {} 00197 00198 00199 00200 00201 00202 00203 00204 00205 00206 PrmType& getRef() { return this->_accessor.operator PrmType&() ; } 00207 } ; 00208 00209 //----------------------------------------------------------------- 00222 template< typename PrmType > 00223 class AttributeAnimatorTypeT : public IAttributeAnimatorT< PrmType, PrmType, AccessorT< PrmType > > 00224 { 00226 00227 public: 00230 AttributeAnimatorTypeT( const Name& id, const PrmType& value ) 00231 : IAttributeAnimatorT< PrmType, PrmType, AccessorT< PrmType > >( id, AccessorT< PrmType >( value ) ) {} 00233 virtual ~AttributeAnimatorTypeT() {} 00235 00236 PrmType& getRef() { return this->_accessor.operator PrmType&() ; } 00237 } ; 00238 00239 00240 //----------------------------------------------------------------- 00272 template< typename PrmType, typename PrmAccType > 00273 class AttributeAnimatorAccT : public IAttributeAnimatorT< PrmType, OMK::Type::SimpleTypeT< PrmType >, AccessorAccT< PrmType, PrmAccType > > 00274 { 00276 00277 public: 00280 AttributeAnimatorAccT( const Name& id, IAccessorT< PrmAccType >* accessor ) 00281 : IAttributeAnimatorT< PrmType, OMK::Type::SimpleTypeT< PrmType >, AccessorAccT< PrmType, PrmAccType > >( id, AccessorAccT< PrmType, PrmAccType >( accessor ) ) {} 00283 virtual ~AttributeAnimatorAccT() {} 00285 00286 00287 00288 00289 00290 00291 00292 void setAccessor( IAccessorT< PrmAccType >* accessor ) 00293 { 00294 this->_accessor.setAccessor( accessor ) ; 00295 } 00296 } ; 00297 00298 //----------------------------------------------------------------- 00310 template< typename PrmType, typename PrmAccType > 00311 class AttributeAnimatorAccTypeT : public IAttributeAnimatorT< PrmType, PrmType, AccessorAccT< PrmType, PrmAccType > > 00312 { 00314 00315 public: 00318 AttributeAnimatorAccTypeT( const Name& id, IAccessorT< PrmAccType >* accessor ) 00319 : IAttributeAnimatorT< PrmType, PrmType, AccessorAccT< PrmType, PrmAccType > >( id, AccessorAccT< PrmType, PrmAccType >( accessor ) ) {} 00321 virtual ~AttributeAnimatorAccTypeT() {} 00323 00324 00325 00326 00327 00328 00329 00330 void setAccessor( IAccessorT< PrmAccType >* accessor ) 00331 { 00332 this->_accessor.setAccessor( accessor ) ; 00333 } 00334 } ; 00335 00336 00337 00338 //----------------------------------------------------------------- 00378 template< typename PrmType, typename ObjectType > 00379 class AttributeAnimatorFctT : public IAttributeAnimatorT< PrmType, OMK::Type::SimpleTypeT< PrmType >, AccessorFctT< PrmType, ObjectType > > 00380 { 00382 00383 public: 00386 AttributeAnimatorFctT( const Name& id, ObjectType *object, 00387 typename AccessorFctT< PrmType, ObjectType >::SetMethod setMethod, 00388 typename AccessorFctT< PrmType, ObjectType >::GetMethod getMethod ) 00389 : IAttributeAnimatorT< PrmType, OMK::Type::SimpleTypeT< PrmType >, AccessorFctT< PrmType, ObjectType > > 00390 ( id, AccessorAccT< PrmType, ObjectType >( object, setMethod, getMethod ) ) {} 00392 virtual ~AttributeAnimatorFctT() {} 00394 } ; 00395 00396 //----------------------------------------------------------------- 00409 template< typename PrmType, typename ObjectType > 00410 class AttributeAnimatorFctTypeT : public IAttributeAnimatorT< PrmType, PrmType, AccessorFctT< PrmType, ObjectType > > 00411 { 00413 00414 public: 00417 AttributeAnimatorFctTypeT( const Name& id, ObjectType *object, 00418 typename AccessorFctT< PrmType, ObjectType >::SetMethod setMethod, 00419 typename AccessorFctT< PrmType, ObjectType >::GetMethod getMethod ) 00420 : IAttributeAnimatorT< PrmType, PrmType, AccessorFctT< PrmType, ObjectType > > 00421 ( id, AccessorAccT< PrmType, ObjectType >( object, setMethod, getMethod ) ) {} 00423 virtual ~AttributeAnimatorFctTypeT() {} 00425 } ; 00426 00427 00428 //================================================================= 00429 00430 template< typename Type, typename ModelType, typename AccessorType > 00431 IAttributeAnimatorT< Type, ModelType, AccessorType >::IAttributeAnimatorT( const Name& id, const AccessorType& init ) 00432 : IAttributeT< Type, ModelType, AccessorType >( id, init ), 00433 _localVisu(), 00434 _type( TYPE_UNINITIALISED ) 00435 { 00436 } 00437 //----------------------------------------------------------------- 00438 00439 template< typename Type, typename ModelType, typename AccessorType > 00440 IAttributeAnimatorT< Type, ModelType, AccessorType >::~IAttributeAnimatorT() 00441 { 00442 } 00443 //----------------------------------------------------------------- 00444 00445 template< typename PrmType, typename ModelType, typename AccessorType > 00446 bool IAttributeAnimatorT< PrmType, ModelType, AccessorType > 00447 ::loadParameters( const ConfigurationParameterDescriptor * node, const std::string* aliasName ) 00448 { 00449 std::string strId( aliasName ? *aliasName : getId().getCString() ) ; 00450 bool ok = true ; 00451 const ConfigurationParameterDescriptor * animatorNode = 0 ; 00452 ok = ok && ParametersAccessor::get( node, strId + "Animator", animatorNode ) ; 00453 ok = ok && animatorNode != 0 ; 00454 00455 // Set the type of connection with the animator 00456 // Look for visualisation name (the same as AddAnimatorPrm::loadParameters) 00457 bool localVisu = ParametersAccessor::get( animatorNode, "VisuName", _localVisu ) ; 00458 // If there is an output => force to output 00459 _type = _output ? TYPE_OUTPUT : ( localVisu ? TYPE_EVENT_LOCAL_VISU : TYPE_SIGNAL_ALL_VISU ) ; 00460 00461 _eventBaseId = _owner->getName().getString() + "_" + getId().getString() + "_animator" ; 00462 _eventId = OMK::EventId::getCurrentValueEventId( _eventBaseId.getString() ) ; 00463 // Load the parameters to create the connection for the animator 00464 ConfigurationParameterDescriptor * modifiedAnimatorNode = const_cast< ConfigurationParameterDescriptor* >( animatorNode ) ; 00465 switch( _type ) 00466 { 00467 case TYPE_OUTPUT: 00468 ParametersAccessor::set( modifiedAnimatorNode, "ConnectTo", std::pair< Name, Name >( _owner->getName(), _output->getName() )) ; 00469 break ; 00470 case TYPE_EVENT_LOCAL_VISU : 00471 ParametersAccessor::set( modifiedAnimatorNode, "ListenedEvent", _eventId ) ; 00472 break ; 00473 case TYPE_SIGNAL_ALL_VISU : 00474 ParametersAccessor::set( modifiedAnimatorNode, "ListenedEvent", _eventId ) ; 00475 ParametersAccessor::set( modifiedAnimatorNode, "Emitter", _owner->getName() ) ; 00476 break ; 00477 default: 00478 OMASSERTM( false, "Cannot create the animator" ) ; 00479 } 00480 return ok && IAttributeT< PrmType, ModelType, AccessorType >::loadParameters( node, aliasName ) ; 00481 } 00482 //----------------------------------------------------------------- 00483 template< typename PrmType, typename ModelType, typename AccessorType > 00484 bool IAttributeAnimatorT< PrmType, ModelType, AccessorType > 00485 ::initAnimator( const ConfigurationParameterDescriptor * node, const std::string* aliasName ) 00486 { 00487 node = node ? node : _owner->getConfigurationParameters() ; 00488 std::string strId( aliasName ? *aliasName : getId().getCString() ) ; 00489 bool ok = true ; 00490 const ConfigurationParameterDescriptor * animatorNode = 0 ; 00491 ok = ok && ParametersAccessor::get( node, strId + "Animator", animatorNode ) ; 00492 // OMMESSAGE( "Config " << *animatorNode); 00493 ok = ok && animatorNode != 0 ; 00494 00495 00496 OMK::Type::AddAnimatorPrm animatorPrm ; 00497 animatorPrm.loadParameters( animatorNode ) ; 00498 animatorPrm.setConfigParam( animatorNode->clone() ); 00499 // if name is not defined, defines one 00500 if( animatorPrm.getObjectName() == Name() ) animatorPrm.setObjectName( _eventBaseId.getString() ) ; 00501 00502 if( ok ) 00503 { 00504 //Don't send a signal if it's a local object ie on only one visu 00505 if( Name() != _localVisu ) 00506 { 00507 _owner->sendValuedEvent( _localVisu, 00508 OMK::Vis::VisBase::ADD_ANIMATOR_EVENT_ID, animatorPrm ) ; 00509 } 00510 else 00511 { 00512 _owner->fireValuedSignal( OMK::Vis::VisBase::ADD_ANIMATOR_EVENT_ID, animatorPrm ) ; 00513 } 00514 } 00515 else 00516 { 00517 OMASSERTM(false, "Unable to create the animator, have you forget some parameters?" << *animatorNode ) ; 00518 } 00519 return ok; 00520 00521 } 00522 00523 template< typename Type, typename ModelType, typename AccessorType > 00524 void IAttributeAnimatorT< Type, ModelType, AccessorType >::setValueToOutput() 00525 { 00526 if ( isUpdated() ) 00527 OMTRACEID("Attribute","Attr Updated " << EventId::getCurrentValueEventId( this->_id.getCString()) << " current :"<< _eventBaseId); 00528 00529 switch( _type ) 00530 { 00531 case TYPE_OUTPUT: 00532 _output->set( ModelType( get() ) ) ; 00533 break ; 00534 case TYPE_EVENT_LOCAL_VISU : 00535 if( isUpdated() ) sendValueTo( _localVisu, _eventBaseId, false ) ; 00536 break ; 00537 case TYPE_SIGNAL_ALL_VISU : 00538 if( isUpdated() ) fireValueTo( _eventBaseId, false ) ; 00539 break ; 00540 case TYPE_UNINITIALISED : 00541 OMERROR( "The attribute is not initialised, call loadParameters()" ) ; 00542 if ( _output ) 00543 _output->set( ModelType( get() ) ) ; 00544 break; 00545 default: 00546 OMASSERTM( false, "Cannot update the animator" ) ; 00547 } 00548 } 00549 //----------------------------------------------------------------- 00550 00551 } //namespace OMK 00552 00553 #endif 00554 00555
Documentation generated on Mon Jun 9 11:45:55 2008 |
Generated with doxygen by Dimitri van Heesch , 1997-2007 |