Open Inventor has a configuration database that stores information about the Open Inventor “environment.” The SoPreferences class handles the setting and querying of these configuration parameters.
The SoPreferences class manages a list of configuration parameters and their values. There are several ways that values are set into this list:
The SoPreferences configuration
mechanism is not restricted to Open Inventor parameters. Applications are welcome to use it
for their own parameters if appropriate.
When Open Inventor is initialized, two configuration files are automatically read (if available):
If a variable defined in the configuration file is already defined in the Open Inventor environment, the value in the configuration file overwrites the value currently in the environment.
If environment variable OIV_DEBUG_CONFIG is set, the files read and the values set are displayed to help debugging.
A configuration file can be very handy, for example, when you are running
your application from the VC++ IDE on Windows. Prior to Open Inventor 4.0, if you wanted to
experiment with various environment variable settings, you had to exit and restart VC++ every
time you changed a setting in the system environment. Now you can simply edit the values in
your configuration file, then rerun your application. The new settings in the config file will
be used.
C++ : The SoPreferences class has many “ set ” methods that you can use to set an individual configuration parameter in the Open Inventor environment. The setValue() method can be used for setting any parameter value. Internally, the character string value is parsed into a value of the appropriate type. The other methods (setBool(), setInt(), etc.) are used for setting a parameter value of a particular type.
C# : The SoPreferences class has many “ set ” methods that you can use to set an individual configuration parameter in the Open Inventor environment. The SetValue() method can be used for setting any parameter value. Internally, the character string value is parsed into a value of the appropriate type. The other methods (SetBool(), SetInt(), etc.) are used for setting a parameter value of a particular type.
Java : The SoPreferences class has a “ set ” method that you can use to set an individual configuration parameter in the Open Inventor environment. The setValue() method can be used for setting any parameter value. Internally, the character string value is parsed into a value of the appropriate type.
C++ :
C# :
Java :
C++ : These methods set a configuration parameter in the Open Inventor configuration database. As this value is set only in memory, it is local to the application process and can only be retrieved using SoPreferences::getValue() (or an equivalent method).
C# : These methods set a configuration parameter in the Open Inventor configuration database. As this value is set only in memory, it is local to the application process and can only be retrieved using SoPreferences.GetValue() (or an equivalent method).
Java : This method sets a configuration parameter in the Open Inventor configuration database. As this value is set only in memory, it is local to the application process and can only be retrieved using SoPreferences.getValue() (or an equivalent method).
Note that by prepending a “-” to the variable name it is possible to unset it in the configuration database.
Configuration parameters can also be set using system environment variables. For example, on Unix systems, the setenv/export command can be used to set environment variables and their values. On Windows, the set command can be used in a Command Prompt, or values can be set via the Control Panel.
A possible disadvantage of using system environment variables is that you have to be aware of the scope of their influence (which windows or applications are affected, when, and for how long). The configuration file and the “ **set**” methods described above are platform independent, so you don’t need to know this. The system environment may have limited size on some systems. It is much easier to edit an Open Inventor configuration file than to type and re-type variable names on the command line.
White space (blank, tab) is used to separate the variable name from its value. Each line can contain only one definition.
Note that by prepending a “-” to the variable name it is possible to unset it in the configuration database.
To query the value of a configuration parameter, the SoPreferences class provides convenience methods which convert values from string to integer, float, or vector. First, the value is searched for in the configuration database, and if not found, is searched for in the system environment. If the value is found only in the system environment, it is stored in the configuration database for faster access the next time it’s queried.
The basic method is C++ : SoPreferences::getValue() C# : SoPreferences.GetValue() Java : SoPreferences.getValue(), which takes a parameter name and returns the string associated with it (NULL if the parameter is not found). For example:
C++ :
C# :
Java :
However, for most parameters the application would have to check for a NULL return and either convert the string to some other data type (for example, int) or set a default value. SoPreferences provides convenience methods that encapsulate this common pattern:
C++ :
C# :
Java :
Each one takes a parameter name and a default value and returns either the appropriate conversion of the parameter value or the default value. For example:
C++ :
C# :
Java :
Open Inventor 4.0 added many new configuration parameters that make it easy to pre-configure Open Inventor to a desired initial state. (See SoPreferences for the complete list.) This can be useful to quickly experiment with how different settings affect performance, to set defaults for simple programs (e.g., demos) that do not have their own configuration file, etc. There are two general categories:
Equivalent to calling SoGLRenderAction::setTransparencyType().
Equivalent to calling SoXtRenderArea::setBackgroundColor().