OMKVisualObject.h

Go to the documentation of this file.
00001 /************************************************************************/
00002 /* This file is part of openMask(c) INRIA, CNRS, Universite de Rennes 1 */
00003 /* 1993-2002, thereinafter the Software                                 */
00004 /*                                                                      */
00005 /* The Software has been developped within the Siames Project.          */
00006 /* INRIA, the University of Rennes 1 and CNRS jointly hold intellectual */
00007 /* property rights                                                      */
00008 /*                                                                      */
00009 /* The Software has been registered with the Agence pour la Protection  */
00010 /* des Programmes (APP) under registration number                       */
00011 /* IDDN.FR.001.510008.00.S.P.2001.000.41200                             */
00012 /*                                                                      */
00013 /* This file may be distributed under the terms of the Q Public License */
00014 /* version 1.0 as defined by Trolltech AS of Norway and appearing in    */
00015 /* the file LICENSE.QPL included in the packaging of this file.         */
00016 /*                                                                      */
00017 /* Licensees holding valid specific licenses issued by INRIA, CNRS or   */
00018 /* Universite Rennes 1 for the software may use this file in            */
00019 /* acordance with that specific license                                 */
00020 /************************************************************************/
00021 #ifndef OMK_VIS_VISUALOBJECT_H
00022 #define OMK_VIS_VISUALOBJECT_H
00023 
00024 #include <vector>
00025 #include "OMKVisBase.h"
00026 #include "OMKAnimatorEventPlugT.h"
00027 #include "OMKAnimatorInputPlugT.h"
00028 #include "OMKTransform.h"
00029 #include "OBTPrototypeFactory.h"
00030 
00031 namespace OMK 
00032 {
00033 namespace Vis 
00034 {
00035 class Animator ;
00036 
00058 class OMKVIS_API VisualObject
00059 {
00060 public:
00061 
00063 
00064 
00065   VisualObject( VisBase& vis, const Name& id, const ConfigurationParameterDescriptor* node );
00066 
00070   virtual ~VisualObject() ;
00072 
00077   void update() ;
00078 
00080   const VisBase& getVis() const ;
00081 
00083   VisBase& touchVis() const ;
00084 
00086   const Name& getId() const ;
00087 
00089   const Type::Transform& getTransform() const ;
00090 
00092   void addAnimator( OMK::Vis::Animator* animator ) ;
00093 
00096   void deleteAnimator( const Name& id ) ;
00097 
00101   OMK::Vis::Animator* getAnimator( const Name& id ) const ;
00102 protected:
00103 
00108   virtual void visualise() = 0 ;
00109 
00113   typedef std::map< Name, OMK::Vis::Animator* > AnimatorsMap ;
00114   AnimatorsMap _animators ;
00115 
00116 
00117 private :
00118 
00120   void readConfigurationParameters( const ConfigurationParameterDescriptor* node ) ;
00121 
00123   VisBase& _vis ;
00124 
00126   Name _id ;
00127 
00129   Type::Transform _transform ;
00130 } ;
00131 
00140 #define DECLARE_VISUAL_OBJECT_FACTORY( VisualObjectClass ) \
00141 public: \
00142  \
00143   friend class OMK::Vis::VisualObjectCreatorT< VisualObjectClass > ; \
00144  \
00145   static OMK::Name OMK_CLASS_ID ; \
00146  \
00147   static const bool REGISTERED_IN_VISUAL_OBJECT_FACTORY ; \
00148 protected: \
00149  \
00151   VisualObjectClass( OMK::Vis::VisBase& vis, const OMK::Name& instanceId, const OMK::ConfigurationParameterDescriptor* node  ) ; \
00152 public: \
00153   virtual ~VisualObjectClass() 
00154 
00161 #define REGISTER_VISUAL_OBJECT_FACTORY( VisualObjectClass, Id )\
00162   /* Factory */ \
00163   OMK::Name VisualObjectClass::OMK_CLASS_ID( Id ) ; \
00164   const bool VisualObjectClass::REGISTERED_IN_VISUAL_OBJECT_FACTORY( OMK::Vis::VisualObjectFactory::getInstance().registerCreator< OMK::Vis::VisualObjectCreatorT< VisualObjectClass > >( Id ) )
00165 
00166 
00167 //-----------------------------------------------------------------------------
00168 
00170 class VisualObjectCreator
00171 {
00172 public:
00173   virtual ~VisualObjectCreator() {}
00174   virtual VisualObject* operator()
00175     (  VisBase& vis, 
00176       const Name& instanceId, 
00177       const ConfigurationParameterDescriptor* node  ) const
00178   {
00179     OMERROR( "Creator is not registered for\"" << instanceId << "\"" << std::endl << *node ) ;
00180     throw Exception( "Creator is not registered" ) ;
00181     return 0 ;
00182   }
00183 } ;
00184 
00186 template <class T>
00187 class VisualObjectCreatorT : public VisualObjectCreator
00188 {
00189 public:
00190   virtual ~VisualObjectCreatorT() {}
00191   typedef T object_to_create ;
00192 
00193   VisualObject* operator()
00194     ( VisBase& vis, 
00195       const Name& instanceId, 
00196       const ConfigurationParameterDescriptor* node ) const
00197   {
00198     return new T( vis, instanceId, node ) ;
00199   }
00200 } ;
00201 
00202 //-------------------------------------------------------------------------
00203 // getVis
00204 //-------------------------------------------------------------------------
00205 inline const VisBase& 
00206 VisualObject::getVis() const
00207 {
00208   return _vis ;
00209 }
00210 
00211 //-------------------------------------------------------------------------
00212 // touchVis
00213 //-------------------------------------------------------------------------
00214 inline VisBase& 
00215 VisualObject::touchVis() const
00216 {
00217   return _vis ;
00218 }
00219 
00220 //-------------------------------------------------------------------------
00221 // getId
00222 //-------------------------------------------------------------------------
00223 inline const Name& 
00224 VisualObject::getId() const 
00225 {
00226   return _id ;
00227 }
00228 
00229 //-------------------------------------------------------------------------
00230 // getTransform
00231 //-------------------------------------------------------------------------
00232 inline const Type::Transform& 
00233 VisualObject::getTransform() const
00234 {
00235   return _transform ;
00236 }
00237 
00242 std::string OMKVIS_API debugMsg( const Vis::VisualObject* visObj ) ;
00243 
00244 typedef OBT::Singleton< OBT::PrototypeFactory< OMK::Name, VisualObjectCreator > > VisualObjectFactory ;
00245 }// namespace Vis
00246 }// namespace OMK
00247 
00248 template class OMKVIS_API OBT::PrototypeFactory< OMK::Name, OMK::Vis::VisualObjectCreator > ;
00249 template class OMKVIS_API OBT::Singleton< OBT::PrototypeFactory< OMK::Name, OMK::Vis::VisualObjectCreator > > ;
00250 
00251 #endif // OMK_VIS_VISUALOBJECT_H

logo OpenMask

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

Generated with doxygen by Dimitri van Heesch ,   1997-2007