H3D API  2.4.1
X3DBindableNode.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 __X3DBINDABLENODE_H__
30 #define __X3DBINDABLENODE_H__
31 
32 #include <iostream>
33 #include <deque>
34 #include <H3D/X3DChildNode.h>
35 #include <H3D/SFBool.h>
36 #include <H3D/SFTime.h>
37 
38 namespace H3D {
39 
108  class H3DAPI_API X3DBindableNode : public X3DChildNode {
109  public:
110  typedef std::deque< X3DBindableNode* > StackType;
111  typedef map< string, StackType> StackMapType;
112 
115  struct H3DAPI_API SFSetBind : public AutoUpdate< SFBool > {
116  virtual inline void update() {
117  SFBool::update();
118  if( value )
119  static_cast< X3DBindableNode * >( owner )->toStackTop();
120  else
121  static_cast< X3DBindableNode * >( owner )->removeFromStack();
122  }
123 
125  inline virtual void setValue( const bool &v, int _id = 0 ) {
126  SFBool::setValue( v, _id );
127  if( value )
128  static_cast< X3DBindableNode * >( owner )->toStackTop();
129  else
130  static_cast< X3DBindableNode * >( owner )->removeFromStack();
131  }
132  };
133 
134 
136  X3DBindableNode( const string &_bindable_stack_name,
137  Inst< SFSetBind > _set_bind = 0,
138  Inst< SFNode > _metadata = 0,
139  Inst< SFTime > _bindTime = 0,
140  Inst< SFBool > _isBound = 0 );
141 
143  virtual inline ~X3DBindableNode() {
144  removeFromStack();
145  }
146 
149  static X3DBindableNode * getActive( const string &bindable_stack_name ) {
150  if ( !stack[bindable_stack_name].empty() )
151  return stack[bindable_stack_name].front();
152  else
153  return 0;
154  }
155 
157  static const StackType &getStack( const string &bindable_stack_name );
158 
160  static const StackMapType &getStackMap();
161 
163  virtual void initialize();
164 
166  virtual void toStackTop();
167 
169  virtual void removeFromStack();
170 
172  inline bool isStackTop() {
173  const StackType &s = getStack( bindable_stack_name );
174  if( s.size() > 0 ) return this == s.front();
175  else return false;
176  }
177 
182  H3DUniquePtr< SFSetBind > set_bind;
183 
188  H3DUniquePtr< SFTime > bindTime;
189 
193  H3DUniquePtr< SFBool > isBound;
194 
197 
198  protected:
199  string bindable_stack_name;
201  static StackMapType stack;
202  };
203 }
204 
205 #endif
Contains the SFBool field class.
Contains the SFTime field class.
Header file for X3DChildNode, X3D scene-graph node.
virtual void setValue(const bool &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
X3DBindableNode is the abstract base type for all bindable children nodes, including Background,...
Definition: X3DBindableNode.h:108
H3DUniquePtr< SFSetBind > set_bind
Input field to bind or unbind the node.
Definition: X3DBindableNode.h:182
static X3DBindableNode * getActive(const string &bindable_stack_name)
Returns the active bindable instance, i.e.
Definition: X3DBindableNode.h:149
bool isStackTop()
Is this node at the top of the stack.
Definition: X3DBindableNode.h:172
static StackMapType stack
The bindable stack.
Definition: X3DBindableNode.h:201
static H3DNodeDatabase database
The H3DNodedatabase for this node.
Definition: X3DBindableNode.h:196
virtual ~X3DBindableNode()
Destructor.
Definition: X3DBindableNode.h:143
H3DUniquePtr< SFTime > bindTime
The bindTime field is the time at which the Viewpoint node is bound or unbound.
Definition: X3DBindableNode.h:188
H3DUniquePtr< SFBool > isBound
Output field telling if this node is bound or not.
Definition: X3DBindableNode.h:193
This abstract node type indicates that the concrete nodes which are instantiated based on it may be u...
Definition: X3DChildNode.h:42
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
The SFSetBind field calls toStackTop() and removeFromStack() on the X3DBindableNode it is in dependin...
Definition: X3DBindableNode.h:115
virtual void update()
Make the field up to date given that an event has occured.
Definition: X3DBindableNode.h:116
virtual void setValue(const bool &v, int _id=0)
Set the value of the field.
Definition: X3DBindableNode.h:125