| 1 |
NAME SoDB "" "" { scene graph database class } |
| 2 |
|
| 3 |
INCLUDE SoDB.h |
| 4 |
|
| 5 |
DESC { |
| 6 |
The \cSoDB\. class holds all scene graphs, each representing a 3D |
| 7 |
scene used by an application. A scene graph is a collection of SoNode |
| 8 |
objects which come in several varieties (see \cSoNode\.). |
| 9 |
Application programs must initialize the database by calling |
| 10 |
\m\+SoDB::init()\.\-SoDBInit()\.\. |
| 11 |
before calling any other database routines and before constructing any |
| 12 |
nodes, paths, functions, or actions. Note that |
| 13 |
\m\+SoDB::init()\.\-SoDBInit()\.\. is called by |
| 14 |
\m\+SoInteraction::init()\.\-SoInteractionInit()\.\., |
| 15 |
\m\+SoNodeKit::init()\.\-SoNodeKitInit()\.\., and |
| 16 |
\m\+SoXt::init()\.\-SoXtInit()\.\., so if you are calling any of these |
| 17 |
\+methods\.\-functions\., you do not need to call |
| 18 |
\m\+SoDB::init()\.\-SoDBInit()\.\. directly. |
| 19 |
\+All methods on this class are static.\. |
| 20 |
\p |
| 21 |
Typical program database initialization and scene reading is as follows: |
| 22 |
\k\b\+ |
| 23 |
#include <Inventor/SoDB.h> |
| 24 |
#include <Inventor/SoInput.h> |
| 25 |
#include <Inventor/nodes/SoSeparator.h> |
| 26 |
|
| 27 |
SoSeparator *rootSep; |
| 28 |
SoInput in; |
| 29 |
|
| 30 |
SoDB::init(); |
| 31 |
rootSep = SoDB::readAll(&in); |
| 32 |
if (rootSep == NULL) |
| 33 |
printf("Error on read...\\n"); |
| 34 |
...\.\-#include <Inventor_c/SoDB.h> |
| 35 |
#include <Inventor_c/SoInput.h> |
| 36 |
#include <Inventor_c/nodes/SoSeparator.h> |
| 37 |
|
| 38 |
SoSeparator *rootSep; |
| 39 |
SoInput *in; |
| 40 |
|
| 41 |
SoDBInit(); |
| 42 |
in = SoInCreate(); |
| 43 |
rootSep = SoDBReadAll(in); |
| 44 |
if (rootSep == NULL) |
| 45 |
printf("Error on read...\\n"); |
| 46 |
... |
| 47 |
\.\.\. |
| 48 |
} |
| 49 |
|
| 50 |
TYPEDEF void SoDBHeaderCB "(void *userData, SoInput *in)" |
| 51 |
|
| 52 |
METHOD "" static void init() { |
| 53 |
Initializes the database. This must be called before calling any |
| 54 |
other database routines, including the construction of any nodes, |
| 55 |
paths, engines, or actions. |
| 56 |
} |
| 57 |
|
| 58 |
METHOD "" static const char *getVersion() { |
| 59 |
Returns a character string identifying the version of the Inventor |
| 60 |
library in use. |
| 61 |
} |
| 62 |
|
| 63 |
METHOD "" static SbBool read(SoInput *in, SoNode *&rootNode) {} |
| 64 |
METHOD ReadPath static SbBool read(SoInput *in, SoPath *&path) { |
| 65 |
Reads a graph from the file specified by the given \cSoInput\., |
| 66 |
returning a pointer to the resulting root node in \arootNode\., or a |
| 67 |
pointer to the resulting path in \apath\.. The programmer is |
| 68 |
responsible for determining which routine to use, based on the contents |
| 69 |
of the input. These routines return FALSE if any error occurred during |
| 70 |
reading. |
| 71 |
\p |
| 72 |
If the passed \cSoInput\. was used to open a file and the name of the |
| 73 |
file contains a directory, \cSoDB\. automatically adds the directory |
| 74 |
to the end of the current directory search path in the \cSoInput\.. |
| 75 |
This means that nested files named in \cSoFile\. nodes may be found |
| 76 |
relative to that directory. The directory is removed from the search |
| 77 |
path when reading is complete. |
| 78 |
} |
| 79 |
|
| 80 |
METHOD "" static SoSeparator *readAll(SoInput *in) { |
| 81 |
Reads all graphs and paths from the file specified by the given \cSoInput\.. If |
| 82 |
there is only one graph in the file and its root is an |
| 83 |
\cSoSeparator\., a pointer to the root is returned. In all other |
| 84 |
cases, this creates an \cSoSeparator\., adds the root nodes of all |
| 85 |
graphs read as children of it, and returns a pointer to it. This |
| 86 |
returns NULL on error. This processes directory paths in the same way |
| 87 |
as the other reading routines. |
| 88 |
} |
| 89 |
|
| 90 |
METHOD "" static SbBool isValidHeader(const char *testString) { |
| 91 |
This returns TRUE if the given character string is one of the valid |
| 92 |
Inventor file headers, (e.g. \k"#Inventor V2.0 binary"\.), or if |
| 93 |
the string has been registered as a valid header through the |
| 94 |
\cregisterHeader\. method. |
| 95 |
} |
| 96 |
|
| 97 |
METHOD "" static SbBool registerHeader(const SbString &headerString, |
| 98 |
SbBool isBinary, float ivVersion, SoDBHeaderCB *preCB, |
| 99 |
SoDBHeaderCB *postCB, void *userData) { |
| 100 |
Registers the given string as a valid header for input files. |
| 101 |
The string must be 80 characters or less, and start with the |
| 102 |
comment character \k'#'\.. |
| 103 |
If the passed \cisBinary\. flag is true, any file with this header |
| 104 |
will be read as a binary file. |
| 105 |
Usually, a user-defined header represents a file format that is |
| 106 |
a superset of the Inventor file format. |
| 107 |
The \civVersion\. number indicates which Inventor file version |
| 108 |
this header corresponds to. |
| 109 |
The user-defined callback functions \cpreCB\. and \cpostCB\. are |
| 110 |
called before and after a file with this header is read. |
| 111 |
The \cuserData\. is passed to both callback functions. |
| 112 |
The method returns TRUE if the header is successfully registered. |
| 113 |
Note, nothing prevents you from registering the |
| 114 |
same string multiple times. |
| 115 |
} |
| 116 |
|
| 117 |
METHOD "" static SbBool getHeaderData(const SbString &headerString, |
| 118 |
SbBool &isBinary, float &ivVersion, |
| 119 |
SoDBHeaderCB *&preCB, SoDBHeaderCB *&postCB, |
| 120 |
void *&userData, SbBool substringOK = FALSE) { |
| 121 |
Passes back the data registered with the given header string, |
| 122 |
including the flag specifying whether the string is for a binary |
| 123 |
file, pointers to the callback functions invoked before and |
| 124 |
after reading the file, and a pointer to the user data passed |
| 125 |
to the callback functions. |
| 126 |
If the given header string does not match any of the registered |
| 127 |
headers, and the \csubstringOK\. flag is TRUE, then the method |
| 128 |
will search for a registered header that is a substring of |
| 129 |
the given string. |
| 130 |
The method returns TRUE if a matching registered header, or |
| 131 |
subheader, was found. |
| 132 |
} |
| 133 |
|
| 134 |
METHOD "" static int getNumHeaders() { |
| 135 |
Returns the number of valid headers, including standard Inventor |
| 136 |
headers, and user-registered headers. |
| 137 |
} |
| 138 |
|
| 139 |
METHOD "" static SbString getHeaderString(int i) { |
| 140 |
Returns the i'th header. |
| 141 |
} |
| 142 |
|
| 143 |
METHOD "" static SoField * createGlobalField(const SbName &name, SoType type) { |
| 144 |
|
| 145 |
The database maintains a namespace for global fields, making sure that |
| 146 |
there is at most one instance of a global field with any given name in |
| 147 |
the database. This routine is used to create new global fields. If |
| 148 |
there is no global field with the given name, it will create a new |
| 149 |
global field with the given name and type. If there is already a |
| 150 |
global field with the given name and type, it will return it. If there |
| 151 |
is already a global field with the given name but a different type, |
| 152 |
this returns NULL. |
| 153 |
\p |
| 154 |
All global fields must be derived from \cSoField\.; typically the result |
| 155 |
of this routine is cast into the appropriate type; for example: |
| 156 |
\b\k\+ |
| 157 |
SoSFInt32 *longField = |
| 158 |
(SoSFInt32 *) SoDB::createGlobalField("Frame", |
| 159 |
SoSFInt32::getClassTypeId());\.\-SoSInt32 *longField = |
| 160 |
(SoSInt32 *) SoDBCreateGlobalField("Frame", |
| 161 |
SoSInt32GetClassTypeId()); |
| 162 |
\.\.\. |
| 163 |
} |
| 164 |
|
| 165 |
METHOD "" static SoField * getGlobalField(const SbName &name) { |
| 166 |
Returns the global field with the given name, or NULL if there is |
| 167 |
none. The type of the field may be checked using the |
| 168 |
\+\mSoField::isOfType()\., \mSoField::getClassTypeId()\., |
| 169 |
and \mSoField::getTypeId()\. |
| 170 |
methods.\.\-\mSoFieldIsOfType()\., \mSoFieldGetClassTypeId()\., |
| 171 |
and \mSoFieldGetTypeId()\. functions.\. |
| 172 |
} |
| 173 |
|
| 174 |
METHOD "" static void renameGlobalField(const SbName &oldName, |
| 175 |
const SbName &newName) { |
| 176 |
Renames the global field named \aoldName\.. Renaming a global field to |
| 177 |
an empty name ("") deletes it. If there is already a global field |
| 178 |
with the new name, that field will be deleted (the |
| 179 |
\+\mgetGlobalField\. method\.\-\mSoDBGetGlobalField\. function\. |
| 180 |
can be used to guard against this). |
| 181 |
} |
| 182 |
|
| 183 |
METHOD "" static void setRealTimeInterval(const SbTime &deltaT) { |
| 184 |
The database automatically creates one global field when |
| 185 |
\+\mSoDB::init()\.\.\-\mSoDBInit()\.\. |
| 186 |
is called. The \vrealTime\. global field, which is of type |
| 187 |
\cSoSFTime\., can be connected to engines and nodes for real-time |
| 188 |
animation. The database will automatically update the \vrealTime\. global |
| 189 |
field 12 times per second, using a timer sensor. Typically, there |
| 190 |
will be a node sensor on the root of the scene graph which schedules a |
| 191 |
redraw whenever the scene graph changes; by updating the \vrealTime\. |
| 192 |
global field periodically, scene graphs that are connected to |
| 193 |
\vrealTime\. (and are therefore animating) will be redrawn. The rate |
| 194 |
at which the database updates \vrealTime\. can be controlled with this |
| 195 |
routine. Passing in a zero time will disable automatic update of |
| 196 |
\vrealTime\.. If there are no enabled connections from the |
| 197 |
\vrealTime\. field to any other field, the sensor is automatically |
| 198 |
disabled. |
| 199 |
.p |
| 200 |
Note that the SoSceneManager class automatically updates |
| 201 |
realTime immediately after redrawing, which will result in as high a |
| 202 |
frame rate as possible if the scene is continuously animating. The |
| 203 |
SoDB::setRealTimeInterval method ensures that engines that do not |
| 204 |
continuously animate (such as SoTimeCounter) will eventually be |
| 205 |
scheduled. |
| 206 |
} |
| 207 |
|
| 208 |
METHOD "" static const SbTime & getRealTimeInterval() { |
| 209 |
Returns how often the database is updating \vrealTime\.. |
| 210 |
} |
| 211 |
|
| 212 |
METHOD "" static void setDelaySensorTimeout(const SbTime &t) { |
| 213 |
This sets the timeout value for sensors that are delay queue sensors |
| 214 |
(one-shot sensors, data sensors). Delay queue sensors are |
| 215 |
triggered whenever there is idle time. If a long period of time |
| 216 |
elapses without any idle time (as when there are continuous events to |
| 217 |
process), these sensors may not be triggered. Setting this timeout |
| 218 |
value ensures that if the specified length of time elapses without any |
| 219 |
idle time, the delay queue sensors will be processed anyway. |
| 220 |
} |
| 221 |
|
| 222 |
METHOD "" static const SbTime & getDelaySensorTimeout() { |
| 223 |
Returns the current delay queue timeout value. |
| 224 |
} |
| 225 |
|
| 226 |
METHOD "" static int doSelect(int nfds, fd_set *readfds, fd_set *writefds, |
| 227 |
fd_set *exceptfds, struct timeval *userTimeOut) { |
| 228 |
In order to keep timer and idle sensors running as expected, it is |
| 229 |
necessary that an Inventor application not block waiting for input. If |
| 230 |
the Inventor application uses the Xt utility library, this can be |
| 231 |
handled automatically. However, if the application is using its own |
| 232 |
event loop, this function is provided as a wrapper around |
| 233 |
\xselect(2)\. that will handle Inventor tasks if necessary instead of |
| 234 |
blocking. |
| 235 |
} |
| 236 |
|
| 237 |
ALSO { SoBase, SoNode, SoEngine, SoField, SoInput, SoFile, SoPath, |
| 238 |
SoOneShotSensor, SoDataSensor, SoXt } |
| 239 |
|
| 240 |
|