H3D API  2.4.1
SAIFunctions.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 //
28 //
30 #ifndef __SAIFUNCTIONS_H__
31 #define __SAIFUNCTIONS_H__
32 
33 
34 #include <H3D/H3DApi.h>
35 #include <H3D/H3DTypes.h>
36 #include <H3D/Node.h>
37 #include <H3D/X3DGroupingNode.h>
38 #include <H3D/X3D.h>
39 #include <H3D/MFNode.h>
40 #include <H3D/MFString.h>
41 
42 #include <vector>
43 
44 namespace H3D{
45 
47  class Scene;
48  namespace SAI {
49 
54 
55  class H3DAPI_API SAIError: public H3DUtil::Exception::H3DException {
56  public:
58  typedef enum {
65 
73 
78 
84 
89 
95 
100 
107 
112 
116 
120 
124 
132 
139 
145 
150 
156 
160 
167 
171  SAI_URL_UNAVAILABLE
172  } ErrorType;
173 
178  const string &_message = "" ) :
179  H3DUtil::Exception::H3DException( _message ),
180  type(_type) {}
181 
183  inline ErrorType getErrorType() const {
184  return type;
185  }
186 
188  inline const string & getErrorMessage() const {
189  return message;
190  }
191 
192  protected:
193  ErrorType type;
194  };
195 
196  struct H3DAPI_API DOMNode {
197 
198  };
199 
200 
201  struct H3DAPI_API ExecutionContext: public H3DUtil::RefCountedClass {
202  ExecutionContext( bool _clean_up = false ) :
203  clean_up( _clean_up ) {
204  DEFNODES_DEBUG_NAME( named_nodes, "SAI::ExecutionContext::named_nodes")
205  DEFNODES_DEBUG_NAME( exported_nodes, "SAI::ExecutionContext::exported_nodes")
206  AUTOREF_DEBUG_NAME( root_node, "SAI::ExecutionContext::root_node")
207 
208  instances.push_back( this );
209  }
210 
211  virtual ~ExecutionContext() {
212  instances.remove( this );
213  }
214 
215  static list< ExecutionContext * > instances;
216 
217  static void cleanUp() {
218  for( list< ExecutionContext * >::iterator i = instances.begin();
219  i != instances.end(); i++ ) {
220  if( (*i)->clean_up ) {
221  (*i)->root_node.reset( NULL );
222  (*i)->named_nodes.clear();
223  (*i)->exported_nodes.clear();
224  (*i)->protos.clear();
225  (*i)->world_url = "";
226  }
227  }
228  }
229 
230  //const string &getSpecificationVersion();
231  //const string &getEncoding();
232 
233  // const ProfileInfo &getProfileInfo();
234  // const ComponentInfo
235  // ...
236 
237  /* X3DRoute *addRoute( Node *from_node, const string &from_field,
238  Node *to_node, const string &to_field ) { return NULL;}
239 
240  void deleteRoute( X3DRoute * ){}
241  */
242  Node *createNode( const string &node_name );
243  // Returns a new MFNode object with all the root nodes. Ownership of
244  // new object is given to the caller.
245  MFNode *getRootNodes();
246  /*
247  Node *createProto( const string &node_name ){return NULL;}
248 
249  Node *getImportedNode( const string &node_name ) { return NULL;}
250  void updateImportedNode( const string &node_name, Node * ){}
251  void removeImportedNode( const string &node_name ){}
252 
253  Node *getNamedNode( const string &node_name ) {return NULL; }
254  void updateNamedNode( const string &node_name, Node * ) {}
255  void removeNamedNode( const string &node_name ) {} */
256 
257  AutoRef< X3DGroupingNode > root_node;
258  X3D::DEFNodes named_nodes;
259  X3D::DEFNodes exported_nodes;
260  X3D::PrototypeVector protos;
261  string world_url;
262  bool clean_up;
263  };
264 
265  struct H3DAPI_API SAIScene: public ExecutionContext {
266  // void setMetaData( const string &key, const string &value );
267  // string getMetaData( const string &key );
268 
269  // const string &getSpecificationVersion();
270 
271  // Node *getExportedNode( const string &node_name );
272  // void updateExportedNode( const string &node_name, Node * );
273  // void removeExportedNode( const string &node_name );
274 
275  };
276 
277 
278  //struct H3DAPI_API X3DField {
279 
280  // Field *field;
281  //};
282 
287  struct H3DAPI_API ComponentInfo {
289  string name;
293  string title;
297  string providerUrl;
298  };
299 
301  struct ProfileInfo {
303  string name;
308  string title;
312  string providerUrl;
315  vector< ComponentInfo > components;
316  };
317 
318  class H3DAPI_API Browser {
319  public:
321  Browser( Scene *s );
322 
324  inline string getName() {
325  return name;
326  }
327 
329  inline void setName( const string &n) {
330  name = n;
331  }
332 
336  inline string getVersion() {
337  return version;
338  }
339 
341  inline void setVersion( const string &n) {
342  version = n;
343  }
344 
350  H3DFloat getCurrentSpeed();
351 
355  H3DFloat getCurrentFrameRate();
356 
362  const std::vector< ProfileInfo > &getSupportedProfiles();
363 
372  const ProfileInfo &getProfile( const string &profile );
373 
377  const std::vector< ComponentInfo > &getSupportedComponents();
378 
389  const ComponentInfo &getComponent( const string &component,
390  H3DUInt32 level );
391 
404  ExecutionContext *getExecutionContext();
405 
416  SAIScene *createScene( ProfileInfo *pi = NULL,
417  const vector< ComponentInfo > &cis =
418  std::vector< ComponentInfo>() );
419 
439  void replaceWorld( SAIScene *scene );
440 
464  SAIScene *importDocument( DOMNode *node );
465 
493  void loadURL( const string &url,
494  const std::vector< string > &property_list =
495  std::vector< string >() );
496 
502  void setDescription( const string &description );
503 
522  SAIScene *createX3DFromString( const string &s );
523 
540  SAIScene *createX3DFromStream( const istream &s );
541 
547  SAIScene *createX3DFromURL( MFString *urls );
548 
549  //void updateControl(
550  // registerBrowserInterest
551 
552 
562 
569  const vector< string > &getRenderingProperties();
570 
594  const vector< string > &getBrowserProperties();
595 
628  void nextViewpoint( H3DInt32 layer = 0 );
629  void previousViewpoint( H3DInt32 layer = 0 );
630  void firstViewpoint( H3DInt32 layer = 0 );
631  void lastViewpoint( H3DInt32 layer = 0 );
632 
644  void print( const string &s );
645 
655  void dispose();
656 
665 
666  protected:
667  string name, version;
668  AutoRef< SAIScene > SAI_scene;
669  Scene *scene;
670  };
671  }
672 }
673 
674 #endif
Base header file that handles all configuration related settings.
Include this file to include the H3D specific types.
Contains the MFNode class.
Contains the MFString field class.
Node base class.
Header file for X3DGroupingNode, X3D scene-graph node.
This file contains functions for creating H3D nodes from X3D input.
This section defines the error types that may be generated in response to service requests.
Definition: SAIFunctions.h:55
ErrorType
SAIERROR error types.
Definition: SAIFunctions.h:58
@ SAI_INVALID_DOCUMENT
When the user has attempted to import a W3C DOM document into an X3D scene and the document cannot be...
Definition: SAIFunctions.h:106
@ SAI_INVALID_URL
The instance of SAIURL data type provided as part of the parameters to this service request is invali...
Definition: SAIFunctions.h:138
@ SAI_IMPORTED_NODE
An operation was attempted that used an imported node when it is not permitted as defined in 4....
Definition: SAIFunctions.h:83
@ SAI_INVALID_NAME
The name provided to a service request is invalid or cannot be found in the context of that object.
Definition: SAIFunctions.h:119
@ SAI_INVALID_FIELD
The instance of field data type provided as part of the parameters to this service request has been d...
Definition: SAIFunctions.h:115
@ SAI_NODE_IN_USE
Indication that a named node handling action has attempted to re-use a name that is already defined e...
Definition: SAIFunctions.h:149
@ SAI_INVALID_EXECUTION_CONTEXT
The instance of ExecutionContext data type provided as part of the parameters to this service request...
Definition: SAIFunctions.h:111
@ SAI_INVALID_NODE
The instance of the node type provided as part of the parameters to this service request has been dis...
Definition: SAIFunctions.h:123
@ SAI_NODE_NOT_AVAILABLE
An error condition used for IMPORTed nodes.
Definition: SAIFunctions.h:155
@ SAI_NOT_SHARED
A service request was made that assumed the browser was currently participating in a shared scene gra...
Definition: SAIFunctions.h:159
@ SAI_INVALID_BROWSER
The instance of browser data type provided as part of the parameters to the service request has been ...
Definition: SAIFunctions.h:99
@ SAI_DISPOSED
The request made of the current SAINode, SAIField or SAIBrowserRef reference is being made to an obje...
Definition: SAIFunctions.h:77
@ SAI_INVALID_ACCESS_TYPE
The attempt to perform an operation of a field failed because it is an invalid action for that field ...
Definition: SAIFunctions.h:94
@ SAI_INVALID_X3D
The SAIString or X3D file (for example as a result of the fetching of a URL reference) passed to this...
Definition: SAIFunctions.h:144
@ SAI_BROWSER_UNAVAILABLE
This error type appear in the errors definition of a service request.
Definition: SAIFunctions.h:64
@ SAI_INSUFFICIENT_CAPABILITIES
The user is attempting to add a node to an execution context that is greater than the capabilities de...
Definition: SAIFunctions.h:88
@ SAI_NOT_SUPPORTED
Generalised error for when a service request is made for a capability that is not available in this b...
Definition: SAIFunctions.h:166
@ SAI_CONNECTION_ERROR
An error has occurred that resulted in the connection between the browser and external application be...
Definition: SAIFunctions.h:72
@ SAI_INVALID_OPERATION_TIMING
The user is attempting to make a service request that is performed outside of the context that such o...
Definition: SAIFunctions.h:131
const string & getErrorMessage() const
Returns the error message of the SAIError.
Definition: SAIFunctions.h:188
ErrorType getErrorType() const
Returns the SAI error type.
Definition: SAIFunctions.h:183
SAIError(ErrorType _type, const string &_message="")
Constructor.
Definition: SAIFunctions.h:177
The Scene node is topmost node that takes care of the rendering of the scene graph both haptically an...
Definition: Scene.h:56
int H3DInt32
unsigned int H3DUInt32
float H3DFloat
H3DAPI_API Group * createX3DFromStream(istream &in, DEFNodes *dn=NULL, DEFNodes *exported_nodes=NULL, PrototypeVector *prototypes=NULL, const string &system_id="<stream input>")
Create H3D nodes given X3D data as a istream.
Definition: X3D.cpp:242
H3DAPI_API Group * createX3DFromURL(const string &urn, DEFNodes *dn=NULL, DEFNodes *exported_nodes=NULL, PrototypeVector *prototypes=NULL, bool change_base_path_during_parsing=true)
Create H3D nodes given X3D data as a URL.
Definition: X3D.cpp:74
H3DAPI_API Group * createX3DFromString(const string &str, DEFNodes *dn=NULL, DEFNodes *exported_nodes=NULL, PrototypeVector *prototypes=NULL)
Create H3D nodes given X3D data as a string.
Definition: X3D.cpp:51
H3D API namespace.
Definition: Anchor.h:38
The ComponentInfo object stores information about a particular X3D component.
Definition: SAIFunctions.h:287
H3DUInt32 level
The level of support of this instance.
Definition: SAIFunctions.h:291
string providerUrl
If provided, The URL to the entity that wrote this component.
Definition: SAIFunctions.h:297
string name
The formal name of the component.
Definition: SAIFunctions.h:289
string title
A generic, freeform title string provided by the browser manufacturer.
Definition: SAIFunctions.h:293
This object stores information about a particular X3D profile.
Definition: SAIFunctions.h:301
vector< ComponentInfo > components
An array of the ComponentInfo object instances that make up this profile.
Definition: SAIFunctions.h:315
H3DUInt32 level
The level of support of this instance.
Definition: SAIFunctions.h:305
string providerUrl
If provided, the URL to the entity that wrote this component.
Definition: SAIFunctions.h:312
string title
A generic, freeform title string provided by the browser manufacturer.
Definition: SAIFunctions.h:308
string name
The formal name as defined in part 1 of ISO/IEC 19775.
Definition: SAIFunctions.h:303