H3D API  2.4.1
BooleanToggle.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 __BOOLEANTOGGLE_H__
30 #define __BOOLEANTOGGLE_H__
31 
32 #include <H3D/X3DChildNode.h>
33 #include <H3D/SFBool.h>
34 
35 namespace H3D {
36 
52  class H3DAPI_API BooleanToggle : public X3DChildNode {
53  public:
54 
57  class H3DAPI_API SetBoolean: public AutoUpdate< SFBool > {
58  public:
59  // Negates the toggle field if true.
60  virtual void setValue( const bool &b, int _id = 0 ) {
61  SFBool::setValue( b, _id );
62  BooleanToggle *bf =
63  static_cast< BooleanToggle * >( getOwner() );
64  if( value )
65  bf->toggle->setValue( !( bf->toggle->getValue() ) );
66  }
67  protected:
68  // Negates the vaule of the toggle field if true.
69  virtual void update() {
71  BooleanToggle *bf =
72  static_cast< BooleanToggle * >( getOwner() );
73  if( value )
74  bf->toggle->setValue( !( bf->toggle->getValue() ) );
75  }
76  };
77 #ifdef __BORLANDC__
78  friend class SetBoolean;
79 #endif
80 
82  BooleanToggle( Inst< SFNode > _metadata = 0,
83  Inst< SetBoolean > _set_boolean = 0,
84  Inst< SFBool > _toggle = 0 );
85 
91  H3DUniquePtr< SetBoolean > set_boolean;
92 
99  H3DUniquePtr< SFBool > toggle;
100 
103  };
104 }
105 
106 #endif
Contains the SFBool field class.
Header file for X3DChildNode, X3D scene-graph node.
The SetBoolean class is specialize to negate the value of the toggle field if a true event is given.
Definition: BooleanToggle.h:57
virtual void update()
Make the field up to date given that an event has occured.
Definition: BooleanToggle.h:69
BooleanToggle stores a boolean value for toggling on/off.
Definition: BooleanToggle.h:52
static H3DNodeDatabase database
The H3DNodedatabase for this node.
Definition: BooleanToggle.h:102
H3DUniquePtr< SFBool > toggle
The boolean field to toggle.
Definition: BooleanToggle.h:99
H3DUniquePtr< SetBoolean > set_boolean
Negates the value of the toggle field.
Definition: BooleanToggle.h:91
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
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