H3D API  2.4.1
VirtualHandGloveSensor.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 __VIRTUALHANDGLOVESENSOR_H__
30 #define __VIRTUALHANDGLOVESENSOR_H__
31 
32 // H3D includes
33 #include <H3D/X3DSensorNode.h>
34 #include <H3D/SFString.h>
35 #include <H3D/SFInt32.h>
36 #include <H3D/MFDouble.h>
37 
38 #ifdef HAVE_VIRTUAL_HAND_SDK
39 // Virtual Hand SDK includes
40 #include <vhandtk/vhtGlove.h>
41 #endif
42 
43 namespace H3D {
44 
49  class H3DAPI_API VirtualHandGloveSensor : public X3DSensorNode {
50  public:
51 
52  // Connects or disconnects the device depending on the value of the enabled
53  // field.
54  class OnEnable : public AutoUpdate< OnValueChangeSField< SFBool > > {
55  protected:
56  virtual void onValueChange( const bool &new_value) {
57  VirtualHandGloveSensor * vhgs =
58  static_cast< VirtualHandGloveSensor * >( owner );
59  if( vhgs->isInitialized() ) {
60  if( new_value ) {
61  if( vhgs->connect() )
62  vhgs->isActive->setValue( true, vhgs->id );
63 
64  } else {
65  vhgs->disconnect();
66  vhgs->isActive->setValue( false, vhgs->id );
67  }
68  }
69  }
70  };
71 
73  VirtualHandGloveSensor( Inst< OnEnable > _enabled = 0,
74  Inst< SFNode > _metadata = 0,
75  Inst< SFBool > _isActive = 0,
76  Inst< SFString > _host = 0,
77  Inst< SFString > _port = 0 );
78 
81 #ifdef HAVE_VIRTUAL_HAND_SDK
82  if( glove ) {
83  delete glove;
84  glove = 0;
85  }
86 #endif
87  }
88 
92  virtual void initialize();
93 
94 #ifdef HAVE_VIRTUAL_HAND_SDK
96  inline vhtGlove * getGlove() { return glove; }
97 #endif
98 
101  inline void resetGlove() {
102 #ifdef HAVE_VIRTUAL_HAND_SDK
103  glove = 0;
104 #endif
105  }
106 
113  H3DUniquePtr< SFString> host;
114 
121  H3DUniquePtr< SFString> port;
122 
125 
126  protected:
128  virtual void updateValues() = 0;
129 
131  virtual bool connect() = 0;
132 
134  virtual void disconnect() = 0;
135 
136 #ifdef HAVE_VIRTUAL_HAND_SDK
137  // vhtGlove instance
138  vhtGlove * glove;
139 #endif
140 
141  private:
142  // Calls the updateValues function whenever it gets an event.
143  // Scene::time will be routed to this field.
144  struct H3DAPI_API Update
145  : AutoUpdate<Field> {
146  void update(){
147  static_cast<VirtualHandGloveSensor*>
148  (owner)->updateValues();
149  }
150  };
151 
152  H3DUniquePtr< Update > update;
153  };
154 }
155 
156 #endif
Contains the MFDouble field class.
Contains the SFInt32 field class.
Contains the SFString field class.
Header file for X3DSensorNode, X3D scene-graph node.
This is the base class for all sensors that handles connection to the vhtGlove class in Virtual Hand ...
Definition: VirtualHandGloveSensor.h:49
virtual void disconnect()=0
Virtual function that disconnects the vhtGlove.
~VirtualHandGloveSensor()
Destructor.
Definition: VirtualHandGloveSensor.h:80
vhtGlove * getGlove()
Return reference to the contained vhtGlove.
Definition: VirtualHandGloveSensor.h:96
H3DUniquePtr< SFString > host
Adress of the host running the VTIDM daemon process.
Definition: VirtualHandGloveSensor.h:113
H3DUniquePtr< SFString > port
The port number specified in the the Device Manager of Virtual Hand SDK.
Definition: VirtualHandGloveSensor.h:121
static H3DNodeDatabase database
The H3DNodeDatabase for this node.
Definition: VirtualHandGloveSensor.h:124
virtual void updateValues()=0
Virtual function used to update field values in subclasses.
virtual bool connect()=0
Virtual function that connects the vhtGlove.
void resetGlove()
Reset glove to 0, needed in cleanup phase to not accidently try to delete instance of vhtGlove twice.
Definition: VirtualHandGloveSensor.h:101
This abstract node type is the base type for all sensors.
Definition: X3DSensorNode.h:40
H3DUniquePtr< SFBool > isActive
A sensor is active when some special conditions are fulfilled and it will then generate extra output.
Definition: X3DSensorNode.h:59
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