X3DTimeDependentNode.h

Go to the documentation of this file.
00001 
00002 //    Copyright 2004, SenseGraphics AB
00003 //
00004 //    This file is part of H3D API.
00005 //
00006 //    H3D API is free software; you can redistribute it and/or modify
00007 //    it under the terms of the GNU General Public License as published by
00008 //    the Free Software Foundation; either version 2 of the License, or
00009 //    (at your option) any later version.
00010 //
00011 //    H3D API is distributed in the hope that it will be useful,
00012 //    but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 //    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014 //    GNU General Public License for more details.
00015 //
00016 //    You should have received a copy of the GNU General Public License
00017 //    along with H3D API; if not, write to the Free Software
00018 //    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00019 //
00020 //    A commercial license is also available. Please contact us at 
00021 //    www.sensegraphics.com for more information.
00022 //
00023 //
00027 //
00029 #ifndef __X3DTIMEDEPENDENTNODE_H__
00030 #define __X3DTIMEDEPENDENTNODE_H__
00031 
00032 #include "X3DChildNode.h"
00033 #include "SFTime.h"
00034 #include "SFBool.h"
00035 
00036 namespace H3D {
00037 
00041   class H3DAPI_API X3DTimeDependentNode : public X3DChildNode {
00042   public:
00043     
00050     class H3DAPI_API TimeHandler: public AutoUpdate< SFTime > {
00051     public:
00052 
00054       virtual void activate( H3DDouble time );
00055 
00058       virtual void deactivate( H3DDouble time );
00059 
00060     protected:
00065       virtual void update();
00066     };
00067 
00072     class StartTime: public SFTime {
00073     public:
00076       virtual void setValue( const H3DDouble &time, int id = 0 ) {
00077         X3DTimeDependentNode *time_node = 
00078           static_cast< X3DTimeDependentNode * >( getOwner() );
00079         if( !time_node->isActive->getValue() ) {
00080           SFTime::setValue( time, id );
00081         }
00082       } 
00083 
00084     protected:
00087       virtual void propagateEvent( Event e ) {
00088         X3DTimeDependentNode *time_node = 
00089           static_cast< X3DTimeDependentNode * >( getOwner() );
00090         if( !time_node->isActive->getValue() ) {
00091           SFTime::propagateEvent( e );
00092         }
00093       }
00094     };
00095 
00096 
00100     class StopTime: public SFTime {
00101     public:
00105       virtual void setValue( const H3DDouble &time, int id = 0 ) {
00106         X3DTimeDependentNode *time_node = 
00107           static_cast< X3DTimeDependentNode * >( getOwner() );
00108         if( !time_node->isActive->getValue() ||
00109             time > 
00110             time_node->startTime->getValue()) {
00111           SFTime::setValue( time, id );
00112           // Setting the time to the current time on an active time node
00113           // will cause it to deactivate.
00114           if( time_node->isActive->getValue() &&
00115               time_node->timeHandler->getValue() == time ) {
00116             time_node->timeHandler->deactivate( time );
00117           } 
00118         }
00119       }
00120 
00121     protected:
00125       virtual void propagateEvent( Event e ) {
00126         X3DTimeDependentNode *time_node = 
00127           static_cast< X3DTimeDependentNode * >( getOwner() );
00128         if( !time_node->isActive->getValue() ||
00129             time_node->stopTime->getValue() > time_node->startTime->getValue()) {
00130           SFTime::propagateEvent( e );
00131         }
00132       }
00133 
00136       virtual void update() {
00137         SFTime::update();
00138         X3DTimeDependentNode *time_node = 
00139           static_cast< X3DTimeDependentNode * >( getOwner() );
00140         if( time_node->isActive->getValue() &&
00141             time_node->timeHandler->getValue() == value ) {
00142           time_node->timeHandler->deactivate( value );
00143         } 
00144       }
00145     };
00146 
00148     X3DTimeDependentNode( Inst< SFNode > _metadata    = 0,
00149                           Inst< SFBool > _loop        = 0,
00150                           Inst< SFTime > _pauseTime   = 0,
00151                           Inst< SFTime > _resumeTime  = 0,
00152                           Inst< StartTime > _startTime   = 0,
00153                           Inst< StopTime  > _stopTime    = 0,
00154                           Inst< SFTime > _elapsedTime = 0,
00155                           Inst< SFBool > _isActive    = 0,
00156                           Inst< SFBool > _isPaused    = 0,
00157                           Inst< TimeHandler > _timeHandler = 0 );
00158     
00161     virtual void initialize();
00162 
00164     virtual void onPause() {}
00165 
00168     virtual void onResume() {}
00169 
00171     virtual void onStart() {}
00172 
00174     virtual void onStop() {}
00175 
00181     auto_ptr< SFBool > loop;
00182 
00192     auto_ptr< SFTime > pauseTime;
00193 
00199     auto_ptr< SFTime > resumeTime;
00200 
00208     auto_ptr< StartTime > startTime;
00209 
00216     auto_ptr< StopTime > stopTime;
00217 
00224     auto_ptr< SFTime > elapsedTime;
00225 
00233     auto_ptr< SFBool > isActive;
00234 
00239     auto_ptr< SFBool > isPaused;
00240 
00242     static H3DNodeDatabase database;
00243 
00244   protected:
00245     auto_ptr< TimeHandler > timeHandler;
00246   };
00247 }
00248 
00249 #endif

Generated on Thu Aug 24 12:38:35 2006 for H3D API by  doxygen 1.4.5