Class SoDB


  • public class SoDB
    extends Inventor
    Scene graph database class. The SoDB class holds all scene graphs, each representing a 3D scene used by an application. A scene graph is a collection of SoNode objects which come in several varieties (see SoNode).

    All methods in this class are static.

    Data Files:

    SoDB also provides convenient methods for reading data files, for example:

     String filename = "$OIVHOME/data/models/bird.iv";
     SoSeparator rootSep = null;
     SoInput input = new SoInput();
     if (input.openFile(filename))
     {
         rootSep = SoDB.readAll(input);
         input.closeFile();
     }

    Open Inventor has built-in support for reading the following file formats:

    Open Inventor also supports many standard CAD file formats. See SoCADInputReader for the current list. Also see SoCADFileFormat.

    See Also:
    SoBase, SoNode, SoEngine, SoField, SoInput, SoFile, SoPath, SoOneShotSensor, SoDataSensor, SoWin
    • Method Summary

      All Methods Static Methods Concrete Methods Deprecated Methods 
      Modifier and Type Method Description
      static void addConverter​(java.lang.Class<? extends Inventor> fromField, java.lang.Class<? extends Inventor> toField, java.lang.Class<? extends Inventor> converterEngine)
      Registers a field conversion engine that can be used to convert from one type of field to another.
      static boolean addPlugin​(java.lang.String fileName)
      Loads a plugin library.
      static boolean addPluginsDirectory​(java.lang.String dirName)
      Adds a directory to search for libraries defining new Open Inventor plugins.
      static SoField createGlobalField​(java.lang.String name, java.lang.Class<? extends Inventor> type)
      The database maintains a namespace for global fields, making sure that there is at most one instance of a global field with any given name in the database.
      static java.lang.Class<? extends Inventor> getConverter​(java.lang.Class<? extends Inventor> fromField, java.lang.Class<? extends Inventor> toField)
      Returns the field conversion engine registered for the two given field types.
      static SbTime getCurrentTime()
      Returns the current time.
      static SbTime getDelaySensorTimeout()
      Returns the current delay queue timeout value.
      static SoField getGlobalField​(java.lang.String name)
      Returns the global field with the given name, or NULL if there is none.
      static java.lang.String getHeaderString​(int i)
      Returns the i'th header.
      static boolean getIvTuneAllowed()
      Returns true if IvTune can be launched interactively using the keyboard shortcut.
      static int getNumHeaders()
      Returns the number of valid headers, including standard Open Inventor headers, and user-registered headers.
      static int getNumRenderCaches()
      Deprecated.
      As of Open Inventor 10300.
      static SbTime getRealTimeInterval()
      Returns how often the database is updating the realTime global field.
      static SoDB.RenderCacheModes getRenderCacheMode()
      Deprecated.
      As of Open Inventor 10300.
      static boolean isMultiThread()
      Deprecated.
      As of Open Inventor 10000.
      static boolean isValidHeader​(java.lang.String testString)
      This returns true if the given character string is one of the valid Open Inventor file headers, (e.g., "#Inventor V2.0 binary"), or if the string has been registered as a valid header through the registerHeader() method.
      static void processEvents()
      Process Open Inventor sensor queues (TimerQueue and DelayQueue).
      static SoNode read​(SoInput in)
      Reads a graph from the file specified by the given SoInput, returning the resulting root node.
      static SoSeparator readAll​(SoInput in)
      Reads all graphs and paths from the file specified by the given SoInput.
      static void readlock()
      Acquire a non-exclusive global scene graph read-lock.
      static SoNode readNode​(SoInput in)  
      static SoPath readPath​(SoInput in)
      Reads a graph from the file specified by the given SoInput, returning the resulting path.
      static void readunlock()
      Release a non-exclusive global scene graph read-lock.
      static void removeConverter​(java.lang.Class<? extends Inventor> fromField, java.lang.Class<? extends Inventor> toField)
      Remove a previously added converter.
      static boolean removePlugin​(java.lang.String fileName)
      Unloads the specified plugin library.
      static boolean removePluginsDirectory​(java.lang.String dirName)
      Remove directory from the list of search directories for plugin loading.
      static void renameGlobalField​(java.lang.String oldName, java.lang.String newName)
      Renames the global field named oldName.
      static void setDelaySensorTimeout​(SbTime t)
      This sets the timeout value for sensors that are delay queue sensors (one-shot sensors, data sensors).
      static void setIvTuneAllowed​(boolean ivTuneAllowed)
      Specifies if launching IvTune interactively using the keyboard shortcut is allowed.
      static void setNumRenderCaches​(int name_11459)
      Deprecated.
      As of Open Inventor 10300.
      static void setRealTimeInterval​(SbTime deltaT)
      The database automatically creates one global field when SoDB.init() is called.
      static void setRenderCacheMode​(SoDB.RenderCacheModes mode)
      Deprecated.
      As of Open Inventor 10300.
      static void setSystemTimer​(SoSystemTimer timer)
      The system dependent timer allows Inventor to manage its sensor queue (for timers, animation) when creating custom viewers.
      static void writelock()
      Acquire the global scene graph write-lock.
      static void writeunlock()
      Release the global scene graph write-lock.
      • Methods inherited from class java.lang.Object

        equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • createGlobalField

        public static SoField createGlobalField​(java.lang.String name,
                                                java.lang.Class<? extends Inventor> type)
        The database maintains a namespace for global fields, making sure that there is at most one instance of a global field with any given name in the database. This routine is used to create new global fields. If there is no global field with the given name, it will create a new global field with the given name and type. If there is already a global field with the given name and type, it will return it. If there is already a global field with the given name but a different type, this returns NULL.

        All global fields must be derived from SoField; typically the result of this routine is cast into the appropriate type. For example:

         SoSFInt32 intField = (SoSFInt32)SoDB.createGlobalField("Frame", SoSFInt32.class);
      • isValidHeader

        public static boolean isValidHeader​(java.lang.String testString)
        This returns true if the given character string is one of the valid Open Inventor file headers, (e.g., "#Inventor V2.0 binary"), or if the string has been registered as a valid header through the registerHeader() method.
      • readlock

        public static void readlock()
        Acquire a non-exclusive global scene graph read-lock. The calling thread will block until a read-lock is available (no thread is holding the global write-lock). Multiple threads may hold global read-locks at the same time. While holding a read-lock it is safe to traverse the scene graph and to query values of fields, but not to modify the scene graph (see method SoDB.writelock). See readunlock().
      • getCurrentTime

        public static SbTime getCurrentTime()
        Returns the current time.
      • getRenderCacheMode

        @Deprecated
        public static SoDB.RenderCacheModes getRenderCacheMode()
        Deprecated.
        As of Open Inventor 10300. Render caches are no longer used, this method always return AUTO_RENDER_CACHE.
        See setRenderCacheMode().

        Warning Deprecated since Open Inventor 10300. Render caches are no longer used, this method always return AUTO_RENDER_CACHE.

      • getGlobalField

        public static SoField getGlobalField​(java.lang.String name)
        Returns the global field with the given name, or NULL if there is none. See createGlobalField(). The type of the field may be checked using the SoField.isOfType(), SoField.getClassTypeId(), and SoField.getTypeId() methods.
      • readunlock

        public static void readunlock()
        Release a non-exclusive global scene graph read-lock. See readunlock().
      • getHeaderString

        public static java.lang.String getHeaderString​(int i)
        Returns the i'th header. See registerHeader().
      • read

        public static SoNode read​(SoInput in)
        Reads a graph from the file specified by the given SoInput, returning the resulting root node. There is an alternate read routine that returns the resulting path. The programmer is responsible for determining which routine to use, based on the contents of the input. These routines return null if any error occurred during reading.

        If the passed SoInput was used to open a file and the name of the file contains a directory, SoDB automatically adds the directory to the end of the current directory search path in the SoInput. This means that nested files named in SoFile nodes may be found relative to that directory. The directory is removed from the search path when reading is complete.

      • readPath

        public static SoPath readPath​(SoInput in)
        Reads a graph from the file specified by the given SoInput, returning the resulting path. There is an alternate read routine that returns the resulting root node. The programmer is responsible for determining which routine to use, based on the contents of the input. These routines return null if any error occurred during reading.

        If the passed SoInput was used to open a file and the name of the file contains a directory, SoDB automatically adds the directory to the end of the current directory search path in the SoInput. This means that nested files named in SoFile nodes may be found relative to that directory. The directory is removed from the search path when reading is complete.

      • setSystemTimer

        public static void setSystemTimer​(SoSystemTimer timer)
        The system dependent timer allows Inventor to manage its sensor queue (for timers, animation) when creating custom viewers. Typically, this method could be called in the constructor of the first interactive render area created. Calling this method more than once, does nothing. This method is mandatory to create viewers based on viewer components like SoRenderAreaCore.
      • setNumRenderCaches

        @Deprecated
        public static void setNumRenderCaches​(int name_11459)
        Deprecated.
        As of Open Inventor 10300. NumRenderCaches has no meaning anymore.
        Since Open Inventor 10.3, this method has no effect because render caches are automatically managed.

        Warning Deprecated since Open Inventor 10300. NumRenderCaches has no meaning anymore.

      • setRenderCacheMode

        @Deprecated
        public static void setRenderCacheMode​(SoDB.RenderCacheModes mode)
        Deprecated.
        As of Open Inventor 10300. Display lists are no longer used, this method has no effect.
        Since Open Inventor 10.3, this method has no effect because render caches are automatically managed.

        Warning Deprecated since Open Inventor 10300. Display lists are no longer used, this method has no effect.

      • getNumHeaders

        public static int getNumHeaders()
        Returns the number of valid headers, including standard Open Inventor headers, and user-registered headers. See registerHeader().
      • getNumRenderCaches

        @Deprecated
        public static int getNumRenderCaches()
        Deprecated.
        As of Open Inventor 10300. NumRenderCaches has no meaning anymore, this method will always return 1.
        See method setNumRenderCaches().

        Warning Deprecated since Open Inventor 10300. NumRenderCaches has no meaning anymore, this method will always return 1.

      • readAll

        public static SoSeparator readAll​(SoInput in)
        Reads all graphs and paths from the file specified by the given SoInput. If there is only one graph in the file and its root is an SoSeparator, the root is returned. In all other cases, this creates an SoSeparator, adds the root nodes of all graphs read as children of it, and returns it. This returns NULL on error. This processes directory paths in the same way as the other reading routines.

        Reading a DXF file into Open Inventor is just like reading in an Open Inventor format file. Open Inventor will open the file and automatically detect that it is a DXF file. Optionally, you can tell Open Inventor explicitly that the file type is DXF. See SoInput for details about support of the DXF format.

      • setDelaySensorTimeout

        public static void setDelaySensorTimeout​(SbTime t)
        This sets the timeout value for sensors that are delay queue sensors (one-shot sensors, data sensors). Delay queue sensors are triggered whenever there is idle time. If a long period of time elapses without any idle time (as when there are continuous events to process), these sensors may not be triggered. Setting this timeout value ensures that if the specified length of time elapses without any idle time, the delay queue sensors will be processed anyway.

        The default timeout for delay queue sensors is 0.083 seconds. So if delay queue sensors are only triggered by the timeout, then by default the viewer animation can only run at about 12 frames per second. To trigger the delay queue sensors at, for example, 30 frames per second, make this call:

        SoDB.setDelaySensorTimeout( 0.03f );

      • removeConverter

        public static void removeConverter​(java.lang.Class<? extends Inventor> fromField,
                                           java.lang.Class<? extends Inventor> toField)
        Remove a previously added converter. See addConverter().
      • getDelaySensorTimeout

        public static SbTime getDelaySensorTimeout()
        Returns the current delay queue timeout value. See setDelaySensorTimeout().
      • getConverter

        public static java.lang.Class<? extends Inventor> getConverter​(java.lang.Class<? extends Inventor> fromField,
                                                                       java.lang.Class<? extends Inventor> toField)
        Returns the field conversion engine registered for the two given field types. If no such engine exists, SoType.badType() is returned. See addConverter().
      • getRealTimeInterval

        public static SbTime getRealTimeInterval()
        Returns how often the database is updating the realTime global field. See also setRealTimeInterval(). The realTime global field can be accessed like this:
         SoSFTime* realTimeField = (SoSFTime*)SoDB.getGlobalField( "realTime" );
      • renameGlobalField

        public static void renameGlobalField​(java.lang.String oldName,
                                             java.lang.String newName)
        Renames the global field named oldName. Renaming a global field to an empty name ("") deletes it. If there is already a global field with the new name, that field will be deleted (the getGlobalField() method can be used to guard against this). See createGlobalField().
      • getIvTuneAllowed

        public static boolean getIvTuneAllowed()
        Returns true if IvTune can be launched interactively using the keyboard shortcut. See setIvTuneAllowed().
      • setIvTuneAllowed

        public static void setIvTuneAllowed​(boolean ivTuneAllowed)
        Specifies if launching IvTune interactively using the keyboard shortcut is allowed. See SoIvTune to set the keyboard shortcut.
      • setRealTimeInterval

        public static void setRealTimeInterval​(SbTime deltaT)
        The database automatically creates one global field when SoDB.init() is called. The realTime global field, which is of type SoSFTime, can be connected to engines and nodes for real-time animation. The database will automatically update the realTime global field 12 times per second, using a timer sensor. Typically, there will be a node sensor on the root of the scene graph which schedules a redraw whenever the scene graph changes; by updating the realTime global field periodically, scene graphs that are connected to realTime (and are therefore animating) will be redrawn. The rate at which the database updates realTime can be controlled with this routine. Passing in a zero time will disable automatic update of realTime . If there are no enabled connections from the realTime field to any other field, the sensor is automatically disabled. Note that the SoSceneManager class automatically updates realTime immediately after redrawing, which will result in as high a frame rate as possible if the scene is continuously animating. This method ensures that engines that do not continuously animate (such as SoTimeCounter) will eventually be scheduled. See also getRealTimeInterval(). The realTime global field can be accessed like this:
         SoSFTime realTimeField = (SoSFTime)SoDB.getGlobalField( "realTime" );
      • writelock

        public static void writelock()
        Acquire the global scene graph write-lock.

        The calling thread will block until the write-lock is available (no threads hold a global read-lock). The global write-lock is exclusive. Only a single thread can hold this lock and while it is held, no thread can acquire a global read-lock. While holding the global write-lock it is safe to modify the scene graph including adding/removing nodes, modifying field values, etc. Do not hold the global write-lock longer than necessary. See writeunlock().

        Note: Be sure the global write-lock is always released or there is a good chance the application will "dead lock" because all standard actions automatically attempt to acquire a global read-lock.

      • removePlugin

        public static boolean removePlugin​(java.lang.String fileName)
        Unloads the specified plugin library. See addPlugin(). Returns true if plugin was successfully unloaded.
      • writeunlock

        public static void writeunlock()
        Release the global scene graph write-lock. See writelock().
      • addPlugin

        public static boolean addPlugin​(java.lang.String fileName)
        Loads a plugin library. A plugin library may implement one or more classes extending Open Inventor classes. For example a custom node or a custom file reader derived from SoInputReader.

        A plugin library must implement the initPlugin() and exitPlugin() C-formatted entry-points. The initPlugin() function is responsible for registering the new class (or classes) in the Open Inventor database through the standard SoType type creation mechanism. The exitPlugin() function is used to disable the use of the custom class(s) by removing the corresponding type(s) from the Open Inventor database.

        By default, Open Inventor attempts to load all files that may be plugins (files with the extension .dll or .so depending on the platform) from the following locations:

        • Application specified directories,
          defined using the OIV_PLUGINS_DIRECTORY environment variable, or the SoDB.addPluginsDirectory() method.
        • The current application working directory.
        • The directory containing the Open Inventor libraries.

        Specific plugin libraries can be loaded and unloaded by direct calls to the SoDB.addPlugin() and SoDB.removePlugin() methods.

        Different plugins can be designed depending on their usage. Please refer to the Open Inventor plugin section in the documentation

      • isMultiThread

        @Deprecated
        public static boolean isMultiThread()
        Deprecated.
        As of Open Inventor 10000. Not used anymore. You can safely assume the value is true.
        Returns whether multi-thread support is enabled in Open Inventor.

        Warning Deprecated since Open Inventor 10000. Not used anymore. You can safely assume the value is true.

      • processEvents

        public static void processEvents()
        Process Open Inventor sensor queues (TimerQueue and DelayQueue). Normally this is handled automatically by the viewer.
      • addConverter

        public static void addConverter​(java.lang.Class<? extends Inventor> fromField,
                                        java.lang.Class<? extends Inventor> toField,
                                        java.lang.Class<? extends Inventor> converterEngine)
        Registers a field conversion engine that can be used to convert from one type of field to another. The type id's of the two fields are passed in, as is the type id of the field converter engine (derived from SoFieldConverter).
      • addPluginsDirectory

        public static boolean addPluginsDirectory​(java.lang.String dirName)
        Adds a directory to search for libraries defining new Open Inventor plugins. See addPlugin(). Returns true if directory has been successfully added.
      • removePluginsDirectory

        public static boolean removePluginsDirectory​(java.lang.String dirName)
        Remove directory from the list of search directories for plugin loading. See addPlugin(). Returns true if directory has been successfully removed.