OMKSwitchAnimator.cpp

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 #include "OMKSwitchAnimator.h"
00022 
00023 #include "OMKOgreVis.h"
00024 #include "OMKOgreObject.h"
00025 #include "OgreMovableObject.h"
00026 #include "dotSceneInterface.h"
00027 #include "dotSceneLoader.h"
00028 #include "OMKParametersAccessor.h"
00029 
00030 using namespace OMK ;
00031 using namespace OMK::Vis ;
00032 using namespace OMK::Type ;
00033 
00034 REGISTER_ANIMATOR_FACTORY( SwitchAnimator, "SwitchAnimator" ) ;
00035 
00036 //-------------------------------------------------------------------------
00037 // constructor
00038 //-------------------------------------------------------------------------
00039 SwitchAnimator::SwitchAnimator( VisualObject& visualObject, 
00040                                 const Name& id, 
00041                                 const ConfigurationParameterDescriptor& node ) 
00042 : OgreAnimatorT< OMK::Type::IntType >( visualObject, id, node )
00043 {
00044   init( node ) ;
00045 }
00046 
00047 //-------------------------------------------------------------------------
00048 // init
00049 //-------------------------------------------------------------------------
00050 void SwitchAnimator::init( const ConfigurationParameterDescriptor& node )
00051 {
00052   Ogre::SceneNode* animeNode = dynamic_cast< Ogre::SceneNode *>( &getNode() );
00053   OMASSERT( animeNode != NULL );
00054   _defaultNode = animeNode->createChildSceneNode( getNodeName() + "_Switch defaut" ) ;
00055 
00056   //Ajout un Node au niveau du NodeName et decalage du contenu dans defaut
00057   for( size_t i = 0 ; i < animeNode->numAttachedObjects() ; i++ )
00058   {
00059     Ogre::MovableObject * move = animeNode->getAttachedObject(i);
00060     animeNode->detachObject(move);
00061     _defaultNode->attachObject(move);
00062   }  
00063   for( Ogre::Node::ChildNodeIterator iter = animeNode->getChildIterator() ;
00064        iter.hasMoreElements() ; )
00065   {
00066     Ogre::SceneNode * nodeToMove = static_cast< Ogre::SceneNode* >( iter.getNext() ) ;
00067     if ( nodeToMove->getName() != _defaultNode->getName())
00068     {
00069       animeNode->removeChild( nodeToMove );
00070       _defaultNode->addChild( nodeToMove );
00071     }
00072   }
00073   // Add the default node
00074   _vecNode.push_back( _defaultNode ) ;
00075   _defaultNode->setVisible( true );
00076 
00077   std::vector < std::string > fileTab ;
00078   ParametersAccessor::get( &node, "FileTab", fileTab ) ;
00079 
00080   Ogre::Root& root( getOgreObject().getOgreVis().touchRoot() ) ;
00081   for( size_t i = 0 ; i< fileTab.size() ; i++ )
00082   {
00083     Ogre::SceneNode* nodeToAdd = animeNode->createChildSceneNode( fileTab[i] );
00084     OBT::Singleton< Ogre::dsi::dotSceneLoader >::getInstance().load( fileTab[i], 
00085                                                                      "General", 
00086                                                                      root.getSceneManager( "sceneManager" ), 
00087                                                                      root.getAutoCreatedWindow(), 
00088                                                                      nodeToAdd, 
00089                                                                      false, 
00090                                                                      false, 
00091                                                                      true ) ;
00092     std::string errs ;
00093     for( Ogre::dsi::dotSceneInfo::itLoadLog it( Ogre::dsi::dotSceneInfo::getSceneLoadingLog() ) ; 
00094          it.hasMoreElements() ; )
00095     {
00096       errs += it.getNext() + "\n" ;
00097     }
00098     if ( !errs.empty() )
00099     {
00100       OMTRACEID( OMK_DEBUG_VIS, "Warning for object \"" << getId() << "\"" << std::endl
00101                              << " errors occured during scene loading\n" << errs ) ;
00102     }
00103     _vecNode.push_back( nodeToAdd ) ;
00104     nodeToAdd->setVisible( false ) ;  
00105   }
00106 
00107   // select the default node
00108   _oldNode = _defaultNode ;
00109 }
00110 //-------------------------------------------------------------------------
00111 // destructor
00112 //-------------------------------------------------------------------------
00113 SwitchAnimator::~SwitchAnimator()
00114 {
00115 }
00116 
00117 //-------------------------------------------------------------------------
00118 // selfProcessVis
00119 //-------------------------------------------------------------------------
00120 void SwitchAnimator::selfProcessVis( const IntType& value ) 
00121 {
00122   Ogre::SceneNode* newNode = _defaultNode ;
00123   if( 0 <= value.getValue() && value.getValue() < (int)_vecNode.size() ) 
00124   {
00125 
00126     newNode = _vecNode[ value.getValue() ];
00127   }
00128   else
00129   {
00130     OMERROR( "Warning for object \"" << getId() << "\", the value " 
00131            << value.getValue() << " is not in the range [ 0, " 
00132            << _vecNode.size() << " [ => use default scene" ) ;
00133   }
00134   if( newNode != _oldNode )
00135   {
00136     _oldNode->setVisible( false ) ;
00137     _oldNode = newNode ;
00138     _oldNode->setVisible( true );
00139   }
00140 }
00141 
00142 

logo OpenMask

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

Generated with doxygen by Dimitri van Heesch ,   1997-2007