H3D API  2.4.1
X3DTimeDependentNode.h
Go to the documentation of this file.
1 // Copyright 2004-2019, SenseGraphics AB
3 //
4 // This file is part of H3D API.
5 //
6 // H3D API is free software; you can redistribute it and/or modify
7 // it under the terms of the GNU General Public License as published by
8 // the Free Software Foundation; either version 2 of the License, or
9 // (at your option) any later version.
10 //
11 // H3D API is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
15 //
16 // You should have received a copy of the GNU General Public License
17 // along with H3D API; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 //
20 // A commercial license is also available. Please contact us at
21 // www.sensegraphics.com for more information.
22 //
23 //
27 //
29 #ifndef __X3DTIMEDEPENDENTNODE_H__
30 #define __X3DTIMEDEPENDENTNODE_H__
31 
32 #include <H3D/X3DChildNode.h>
33 #include <H3D/SFTime.h>
34 #include <H3D/SFBool.h>
35 
36 namespace H3D {
37 
41  class H3DAPI_API X3DTimeDependentNode : public X3DChildNode {
42  public:
43 
50  class H3DAPI_API TimeHandler: public AutoUpdate< SFTime > {
51  public:
52 
54  virtual void activate( H3DTime time );
55 
58  virtual void deactivate( H3DTime time );
59 
60  protected:
65  virtual void update();
66  };
67 #ifdef __BORLANDC__
68  friend class TimeHandler;
69 #endif
70 
75  class StartTime: public SFTime {
76  public:
79  virtual void setValue( const H3DDouble &time, int _id = 0 ) {
80  X3DTimeDependentNode *time_node =
81  static_cast< X3DTimeDependentNode * >( getOwner() );
82  if( !time_node->isActive->getValue() ) {
83  SFTime::setValue( time, _id );
84  }
85  }
86 
87  protected:
90  virtual void propagateEvent( Event e ) {
91  X3DTimeDependentNode *time_node =
92  static_cast< X3DTimeDependentNode * >( getOwner() );
93  if( !time_node->isActive->getValue() ) {
94  SFTime::propagateEvent( e );
95  }
96  }
97  };
98 
99 
103  class StopTime: public SFTime {
104  public:
105 
108  virtual void update() {
109  SFTime::update();
110  X3DTimeDependentNode *time_node =
111  static_cast< X3DTimeDependentNode * >( getOwner() );
112  if( time_node->isActive->getValue() &&
113  time_node->timeHandler->getValue() == value ) {
114  time_node->timeHandler->deactivate( value );
115  }
116  }
117  };
118 #ifdef __BORLANDC__
119  friend class StopTime;
120 #endif
121 
123  X3DTimeDependentNode( Inst< SFNode > _metadata = 0,
124  Inst< SFBool > _loop = 0,
125  Inst< SFTime > _pauseTime = 0,
126  Inst< SFTime > _resumeTime = 0,
127  Inst< StartTime > _startTime = 0,
128  Inst< StopTime > _stopTime = 0,
129  Inst< SFTime > _elapsedTime = 0,
130  Inst< SFBool > _isActive = 0,
131  Inst< SFBool > _isPaused = 0,
132  Inst< TimeHandler > _timeHandler = 0 );
133 
136  virtual void initialize();
137 
139  virtual void onPause() {}
140 
143  virtual void onResume() {}
144 
146  virtual void onStart() {}
147 
149  virtual void onStop() {}
150 
156  H3DUniquePtr< SFBool > loop;
157 
167  H3DUniquePtr< SFTime > pauseTime;
168 
174  H3DUniquePtr< SFTime > resumeTime;
175 
183  H3DUniquePtr< StartTime > startTime;
184 
191  H3DUniquePtr< StopTime > stopTime;
192 
199  H3DUniquePtr< SFTime > elapsedTime;
200 
208  H3DUniquePtr< SFBool > isActive;
209 
214  H3DUniquePtr< SFBool > isPaused;
215 
218 
219  protected:
220  H3DUniquePtr< TimeHandler > timeHandler;
221  };
222 }
223 
224 #endif
Contains the SFBool field class.
Contains the SFTime field class.
Header file for X3DChildNode, X3D scene-graph node.
The SFTime field contains a single time value.
Definition: SFTime.h:39
virtual void setValue(const H3DDouble &v, int id=0)
Set the value of the field.
Definition: SField.h:215
virtual void update()
Make the field up to date given that an event has occured.
Definition: SField.h:181
This abstract node type indicates that the concrete nodes which are instantiated based on it may be u...
Definition: X3DChildNode.h:42
The StartTime field is a specialization of the SFTime field so that the value cannot be changed when ...
Definition: X3DTimeDependentNode.h:75
virtual void setValue(const H3DDouble &time, int _id=0)
Overrides the setValue function so that the value is only changed if the owner X3DTimeDependentNode i...
Definition: X3DTimeDependentNode.h:79
virtual void propagateEvent(Event e)
Overrides the propagateEvent function so that the event is only propagated if the owner X3DTimeDepend...
Definition: X3DTimeDependentNode.h:90
The StopTime field is a specialization of the SFTime field so that the value is ignored if the X3DTim...
Definition: X3DTimeDependentNode.h:103
virtual void update()
Update is overriden to deactivate the time node if the value of the field updates to the to the curre...
Definition: X3DTimeDependentNode.h:108
The TimeHandler field updates once per scene-graph loop to monitor the current time and updates the f...
Definition: X3DTimeDependentNode.h:50
This abstract node type is the base node type from which all time-dependent nodes are derived.
Definition: X3DTimeDependentNode.h:41
H3DUniquePtr< SFBool > isActive
An isActive TRUE event is generated when the node becomes active and an isActive FALSE event is gener...
Definition: X3DTimeDependentNode.h:208
virtual void onResume()
This function will be called when the node is resumed after it has been in paused state.
Definition: X3DTimeDependentNode.h:143
virtual void onStart()
This function will be called when the time node is started.
Definition: X3DTimeDependentNode.h:146
H3DUniquePtr< SFBool > isPaused
An isPaused TRUE event is generated when the node becomes paused and an isPaused FALSE event is gener...
Definition: X3DTimeDependentNode.h:214
H3DUniquePtr< StopTime > stopTime
An active time-dependent node will become inactive when stopTime is reached if stopTime > startTime.
Definition: X3DTimeDependentNode.h:191
virtual void onStop()
This function will be called when the time node is stopped.
Definition: X3DTimeDependentNode.h:149
H3DUniquePtr< SFTime > resumeTime
A time at which to start generating events again after being paused.
Definition: X3DTimeDependentNode.h:174
static H3DNodeDatabase database
The H3DNodeDatabase for this node.
Definition: X3DTimeDependentNode.h:217
H3DUniquePtr< SFTime > elapsedTime
The elapsedTime outputOnly field delivers the current elapsed time since the X3DTimeDependentNode was...
Definition: X3DTimeDependentNode.h:199
H3DUniquePtr< StartTime > startTime
A time-dependent node is inactive until its startTime is reached.
Definition: X3DTimeDependentNode.h:183
H3DUniquePtr< SFBool > loop
If loop is TRUE at the end of a cycle, execution continues into the next cycle, otherwise it stops.
Definition: X3DTimeDependentNode.h:156
virtual void onPause()
This function will be called when the node is paused.
Definition: X3DTimeDependentNode.h:139
H3DUniquePtr< SFTime > pauseTime
A time at which to pause and stop generating events.
Definition: X3DTimeDependentNode.h:167
double H3DDouble
double H3DTime
H3D API namespace.
Definition: Anchor.h:38
The AutoUpdate field is a template to force the BaseField to update itself as soon as an event is rec...
Definition: FieldTemplates.h:130
The H3DNodeDatabase contains a mapping between a name of a Node and the constructor for the Node with...
Definition: H3DNodeDatabase.h:194