Open Inventor Release 2023.2.1
 
Loading...
Searching...
No Matches
SoInput Class Reference

Used to read Open Inventor data files. More...

#include <Inventor/SoInput.h>

Public Member Functions

 SoInput ()
 Constructor.
 
virtual ~SoInput ()
 The destructor closes any files opened by the SoInput.
 
virtual void setFilePointer (FILE *newFP)
 Sets file pointer to read from.
 
virtual FILE * getFilePointer ()
 Gets the file pointer read.
 
virtual SoNONUNICODE SbBool openFile (const char *fileName, SbBool okIfNotFound=FALSE, SbBool aSync=FALSE)
 Opens named file, sets file pointer to result.
 
virtual SbBool openFile (const SbString &fileName, SbBool okIfNotFound=FALSE, SbBool aSync=FALSE)
 Opens named file, sets file pointer to result.
 
virtual SoNONUNICODE SbBool pushFile (const char *fileName)
 Opens named file, pushing the resulting file pointer onto the stack.
 
virtual SbBool pushFile (const SbString &fileName)
 Opens named file, pushing the resulting file pointer onto the stack.
 
virtual void closeFile ()
 Closes all files on stack opened with openFile() or pushFile().
 
virtual SbBool isValidFile ()
 Returns TRUE if the currently open file is a valid Open Inventor file.
 
virtual SbBool isValidBuffer ()
 Returns TRUE if the current buffer is valid.
 
virtual FILE * getCurFile () const
 Returns the current file.
 
virtual SoNONUNICODE const char * getCurFileName () const
 Returns full name (including directory path) of current file.
 
virtual SbString getCurStringFileName () const
 Returns full name (including directory path) of current file.
 
virtual void setBuffer (void *buffer, size_t bufSize)
 Sets an in-memory buffer to read from, along with its size.
 
virtual int getNumBytesRead () const
 Returns the number of bytes read.
 
virtual SbString getHeader ()
 Returns the header of the file being read.
 
virtual float getIVVersion ()
 Returns the Open Inventor file version of the file being read (2.1).
 
virtual void updateReadPercent (double readPercentage)
 Reports the percentage of bytes read from the file.
 
void setInputParameters (SoInputParameters *parameters)
 Specify parameters to modify/control actions during the read of a file.
 
SoInputParametersgetInputParameters () const
 Return the current SoInputParameters.
 

Static Public Member Functions

static SoNONUNICODE void addDirectoryFirst (const char *dirName)
 The SoInput class maintains a global list of directories that is searched to find files when opening them.
 
static void addDirectoryFirst (const SbString &dirName)
 The SoInput class maintains a global list of directories that is searched to find files when opening them.
 
static SoNONUNICODE void addDirectoryLast (const char *dirName)
 The SoInput class maintains a global list of directories that is searched to find files when opening them.
 
static void addDirectoryLast (const SbString &dirName)
 The SoInput class maintains a global list of directories that is searched to find files when opening them.
 
static SoNONUNICODE void addEnvDirectoriesFirst (const char *envVarName, const char *dirSep=DIRECTORIES_SEPARATOR)
 The SoInput class maintains a global list of directories that is searched to find files when opening them.
 
static void addEnvDirectoriesFirst (const SbString &envVarName, const SbString &dirSep=DIRECTORIES_SEPARATOR)
 The SoInput class maintains a global list of directories that is searched to find files when opening them.
 
static SoNONUNICODE void addEnvDirectoriesLast (const char *envVarName, const char *dirSep=DIRECTORIES_SEPARATOR)
 The SoInput class maintains a global list of directories that is searched to find files when opening them.
 
static void addEnvDirectoriesLast (const SbString &envVarName, const SbString &dirSep=DIRECTORIES_SEPARATOR)
 The SoInput class maintains a global list of directories that is searched to find files when opening them.
 
static SoNONUNICODE void removeDirectory (const char *dirName)
 Removes named directory from the list.
 
static void removeDirectory (const SbString &dirName)
 Removes named directory from the list.
 
static void clearDirectories ()
 Clears the list of directories (including the current directory).
 
static const SbStringListgetDirectories ()
 Returns the list of directories as an SbStringList.
 
static SbBool findAbsolutePath (const SbString &fileName, SbString &fullName)
 Returns absolute path of given file by looking in SoInput standard directories.
 

Detailed Description

Used to read Open Inventor data files.

This class is used by the SoDB reading routines when reading Open Inventor (.iv) format data or various geometry data formats that can be converted into an Open Inventor scene graph. The input source can be the standard input stream (default), a file (see openFile) or a buffer in memory (see setBuffer).
SoInput can search for a file in a list of directories (see addDirectoryFirst etc). SoInput can report progress during the input operation (see updateReadPercent).

SoInput is typically used with SoDB::read or SoDB::readAll to load data and create a scene graph. There is an example code fragment on the SoDB page.

NOTE: Applications should always check the result of calling the openFile() method. If the call fails, the SoInput object itself is still valid and remains in the default state. Calling SoDB::readAll(), or methods like getHeader() and isValidFile(), with a default SoInput object will make the application appear to "hang" because it is waiting for data on standard input. To check if a file exists, get file properties, etc see SbFileHelper.

File formats

SoInput supports ASCII (default) and binary Open Inventor formats. Since Open Inventor 8.1, both the ASCII and binary formats can be compressed using the gz format (e.g. using gzip). The file extension 'ivz' is recognized for compressed Open Inventor files, but is not mandatory. In fact the initial bytes of the file are checked when the file is opened to automatically determine if it is compressed or not. This feature uses the module IvDLZlib.

SoInput also has built-in support for:

  • VRML97 format (.wrl)
  • X3D Classic VRML format (.x3dv) See VRML_LIMITATIONS for details.

Additional input readers are provided as plugins for:

  • DXF format (.dxf)
  • STL format (.stl)

These formats require redistributing the corresponding plugin library with the application.

  • DXF : fei_inventor_io_dxf (e.g. fei_inventor_io_dxf.dll on Windows).
  • STL : fei_inventor_io_stl (e.g. fei_inventor_io_stl.dll on Windows).

Open Inventor also supports many standard CAD file formats. See SoCADInputReader for the current list. These formats also require redistributing the corresponding plugin library (fei_inventor_io_cad) with the application.

SoInput can also be extended with custom file format readers. Input readers are defined as new classes inheriting from the SoInputReader class.. See SoInputReader class for more information about defining and loading new readers

For Open Inventor format files, users can also register additional valid file headers. When reading, SoInput skips over Open Inventor comments (from '#' to end of line) and can stack input files. When EOF is reached, the stack is popped.

Directory List

SoInput maintains a list of directories (initially empty). Generally Open Inventor classes that need to open a named file will search for the file in each of these directories in order. This includes SoInput (the openFile() method), SoTexture2, SoFragmentShader and other nodes that have a "filename" field.

Note: SoInput is not currently used for loading volume data files in VolumeViz. SoDataSet and its subclasses (SoVolumeData etc) do not search the list of directories maintained by SoInput when attempting to open a file. However the directory list is searched to find volume shader files (SoVolumeShader, SoVolumeRenderingQuality, etc).

The SoInput directory list is initialized from the environnment variable OIV_FILE_SEARCH_PATHS. This variable may be set to a semi-colon separated list of directory paths. The specified paths may use variables in $name format, e.g. "$OIVHOME", which will be replaced by the value returned by SoPreferences for that name. Additional directories may be added to the directory list using the static methods addDirectoryLast etc.

Static utility method findAbsolutePath() returns the full path of a file if it can be found in one of the directories in the list.

DXF Input Limitations:

The supported DXF file format release is 14.

The limitations are:

  • CLASSES, OBJECTS and THUMBNAILIMAGE sections are ignored.
  • TABLES section: APPID, BLOCK_RECORD,DIMSTYLE, LTYPE, LAYER, STYLE, UCS, VIEW, VIEWPORT are ignored.
  • ENTITIES section: ARCALIGNEDTEXT, DIMENSION, IMAGE, REGION, WIPEOUT are ignored.

VRML Input Limitations:

Starting from OIV10, it is no more possible to create VRML nodes. However, import of .vrml file is till supported but node are automatically converted to OIV nodes. Not all nodes are supported when reading VRML files. Here is list of supported nodes and their corresponding OIV nodes. Some VRML nodes will be converter to more or less complexe scenegraph. In this case, VRML node may be converted to an SoSeparator or an SoGroup containing scene graph.

GeoVRML nodes:

Special Group nodes:

Common nodes:

Geometry nodes:

Geometry properties:

Geometry appearance:

Group nodes:

Special nodes:

SEE ALSO

SoDB, SoOutput, SoTranReceiver, SoInputParameters, SoInputReader, SoCADInputReaderParameters

Definition at line 362 of file SoInput.h.

Constructor & Destructor Documentation

◆ SoInput()

SoInput::SoInput ( )

Constructor.

The default SoInput reads from stdin.

◆ ~SoInput()

virtual SoInput::~SoInput ( )
virtual

The destructor closes any files opened by the SoInput.

Member Function Documentation

◆ addDirectoryFirst() [1/2]

static SoNONUNICODE void SoInput::addDirectoryFirst ( const char *  dirName)
static

The SoInput class maintains a global list of directories that is searched to find files when opening them.

Directories are searched in order. This routine adds a directory to the beginning of the list.

Non Unicode: This function should not be used in a Unicode application.

◆ addDirectoryFirst() [2/2]

static void SoInput::addDirectoryFirst ( const SbString dirName)
static

The SoInput class maintains a global list of directories that is searched to find files when opening them.

Directories are searched in order. This routine adds a directory to the beginning of the list.

◆ addDirectoryLast() [1/2]

static SoNONUNICODE void SoInput::addDirectoryLast ( const char *  dirName)
static

The SoInput class maintains a global list of directories that is searched to find files when opening them.

Directories are searched in order. This routine adds a directory to the end of the list.

Non Unicode: This function should not be used in a Unicode application.

◆ addDirectoryLast() [2/2]

static void SoInput::addDirectoryLast ( const SbString dirName)
static

The SoInput class maintains a global list of directories that is searched to find files when opening them.

Directories are searched in order. This routine adds a directory to the end of the list.

◆ addEnvDirectoriesFirst() [1/2]

static SoNONUNICODE void SoInput::addEnvDirectoriesFirst ( const char *  envVarName,
const char *  dirSep = DIRECTORIES_SEPARATOR 
)
static

The SoInput class maintains a global list of directories that is searched to find files when opening them.

Directories are searched in order. This routine adds directories named in the value of the given environment variable to the beginning of the list.

Parameters
envVarNameThe name of the environment variable.
dirSepA string containing zero or more directory separator characters.

The default value of dirSep is ":;", in other words either a colon or an a semicolon character will be interpreted as separating directory paths. Directory paths in an environment variable are normally separated by semicolon characters on Microsoft Windows platforms and by colon (or whitespace) on UNIX/Linux systems.

NOTE: On Microsoft Windows systems the default dirSep value causes a problem. For example, the string "C:/myDir" will be interpreted as two different directories "C/" and "/myDir".. To avoid this problem explicitly set dirSep to ";" (semicolon).

Non Unicode: This function should not be used in a Unicode application.

◆ addEnvDirectoriesFirst() [2/2]

static void SoInput::addEnvDirectoriesFirst ( const SbString envVarName,
const SbString dirSep = DIRECTORIES_SEPARATOR 
)
static

The SoInput class maintains a global list of directories that is searched to find files when opening them.

Directories are searched in order. This routine adds directories named in the value of the given environment variable to the beginning of the list.

NOTE: On Microsoft Windows systems the default dirSep value causes a problem. For example, the string "C:/myDir" will be interpreted as two different directories "C/" and "/myDir".. To avoid this problem explicitly set dirSep to ";" (semicolon).

Parameters
envVarNameThe name of the environment variable.
dirSepA string containing zero or more directory separator characters.

◆ addEnvDirectoriesLast() [1/2]

static SoNONUNICODE void SoInput::addEnvDirectoriesLast ( const char *  envVarName,
const char *  dirSep = DIRECTORIES_SEPARATOR 
)
static

The SoInput class maintains a global list of directories that is searched to find files when opening them.

Directories are searched in order. This routine adds directories named in the value of the given environment variable to the end of the list.

NOTE: On Microsoft Windows systems the default dirSep value causes a problem. For example, the string "C:/myDir" will be interpreted as two different directories "C/" and "/myDir".. To avoid this problem explicitly set dirSep to ";" (semicolon).

Parameters
envVarNameThe name of the environment variable.
dirSepA string containing zero or more directory separator characters.

Non Unicode: This function should not be used in a Unicode application.

◆ addEnvDirectoriesLast() [2/2]

static void SoInput::addEnvDirectoriesLast ( const SbString envVarName,
const SbString dirSep = DIRECTORIES_SEPARATOR 
)
static

The SoInput class maintains a global list of directories that is searched to find files when opening them.

Directories are searched in order. This routine adds directories named in the value of the given environment variable to the end of the list.

NOTE: On Microsoft Windows systems the default dirSep value causes a problem. For example, the string "C:/myDir" will be interpreted as two different directories "C/" and "/myDir".. To avoid this problem explicitly set dirSep to ";" (semicolon).

Parameters
envVarNameThe name of the environment variable.
dirSepA string containing zero or more directory separator characters.

◆ clearDirectories()

static void SoInput::clearDirectories ( )
static

Clears the list of directories (including the current directory).

◆ closeFile()

virtual void SoInput::closeFile ( )
virtual

Closes all files on stack opened with openFile() or pushFile().

◆ findAbsolutePath()

static SbBool SoInput::findAbsolutePath ( const SbString fileName,
SbString fullName 
)
static

Returns absolute path of given file by looking in SoInput standard directories.

Returns true on success.

The file name may contain variables in $name format, e.g. "$OIVHOME", which will be replaced by the value returned by SoPreferences for that name.

◆ getCurFile()

virtual FILE * SoInput::getCurFile ( ) const
virtual

Returns the current file.

Returns standard input (stdin) if no file or buffer is open. Returns NULL if reading from a buffer.

◆ getCurFileName()

virtual SoNONUNICODE const char * SoInput::getCurFileName ( ) const
virtual

Returns full name (including directory path) of current file.

Returns NULL if no file is open or if reading from a buffer.

Non Unicode: This function should not be used in a Unicode application.

◆ getCurStringFileName()

virtual SbString SoInput::getCurStringFileName ( ) const
virtual

Returns full name (including directory path) of current file.

Returns an empty string (isEmpty() will be true) if no file is open or if reading from a buffer.

◆ getDirectories()

static const SbStringList & SoInput::getDirectories ( )
static

Returns the list of directories as an SbStringList.

◆ getFilePointer()

virtual FILE * SoInput::getFilePointer ( )
virtual

Gets the file pointer read.

◆ getHeader()

virtual SbString SoInput::getHeader ( )
virtual

Returns the header of the file being read.

Note that by default (when no file or buffer is open), SoInput reads from standard input, which may make the application appear to "hang".

◆ getInputParameters()

SoInputParameters * SoInput::getInputParameters ( ) const

Return the current SoInputParameters.

◆ getIVVersion()

virtual float SoInput::getIVVersion ( )
inlinevirtual

Returns the Open Inventor file version of the file being read (2.1).

If the file has a header registered through SoDB::registerHeader(), the returned version is the Open Inventor version registered with the header. Returns 0.0 if no file or buffer is open.

Definition at line 655 of file SoInput.h.

◆ getNumBytesRead()

virtual int SoInput::getNumBytesRead ( ) const
virtual

Returns the number of bytes read.

◆ isValidBuffer()

virtual SbBool SoInput::isValidBuffer ( )
virtual

Returns TRUE if the current buffer is valid.

Buffer must begin with a standard Open Inventor header or one that has been registered with SoDB::registerHeader(). Note that by default (when no file or buffer is open), SoInput reads from standard input, which may make the application appear to "hang".

◆ isValidFile()

virtual SbBool SoInput::isValidFile ( )
virtual

Returns TRUE if the currently open file is a valid Open Inventor file.

File must begin with a standard Open Inventor header or one that has been registered with SoDB::registerHeader(). Note that by default (when no file or buffer is open), SoInput reads from standard input, which may make the application appear to "hang".

◆ openFile() [1/2]

virtual SoNONUNICODE SbBool SoInput::openFile ( const char *  fileName,
SbBool  okIfNotFound = FALSE,
SbBool  aSync = FALSE 
)
virtual

Opens named file, sets file pointer to result.

Clears the stack of input files if necessary. Returns FALSE on error. If okIfNotFound is FALSE (the default), prints an error message if the file could not be found. If aSync is true (FALSE by default) the file is read asynchronously (the reading starts immediately although it isn't fully buffered).

The file name may contain variables in $name format, e.g. "$OIVHOME", which will be replaced by the value returned by SoPreferences for that name.

Non Unicode: This function should not be used in a Unicode application.

◆ openFile() [2/2]

virtual SbBool SoInput::openFile ( const SbString fileName,
SbBool  okIfNotFound = FALSE,
SbBool  aSync = FALSE 
)
virtual

Opens named file, sets file pointer to result.

Clears the stack of input files if necessary. If okIfNotFound is FALSE (the default), prints an error message if the file could not be found. If aSync is true (FALSE by default) the file is read asynchronously (the reading starts immediately although it isn't fully buffered).

The file name may contain variables in $name format, e.g. "$OIVHOME", which will be replaced by the value returned by SoPreferences for that name.

◆ pushFile() [1/2]

virtual SoNONUNICODE SbBool SoInput::pushFile ( const char *  fileName)
virtual

Opens named file, pushing the resulting file pointer onto the stack.

Returns FALSE on error. When EOF is reached, the stack is popped.

The file name may contain variables in $name format, e.g. "$OIVHOME", which will be replaced by the value returned by SoPreferences for that name.

Non Unicode: This function should not be used in a Unicode application.

◆ pushFile() [2/2]

virtual SbBool SoInput::pushFile ( const SbString fileName)
virtual

Opens named file, pushing the resulting file pointer onto the stack.

Returns FALSE on error. When EOF is reached, the stack is popped.

The file name may contain variables in $name format, e.g. "$OIVHOME", which will be replaced by the value returned by SoPreferences for that name.

◆ removeDirectory() [1/2]

static SoNONUNICODE void SoInput::removeDirectory ( const char *  dirName)
static

Removes named directory from the list.

Non Unicode: This function should not be used in a Unicode application.

◆ removeDirectory() [2/2]

static void SoInput::removeDirectory ( const SbString dirName)
static

Removes named directory from the list.

◆ setBuffer()

virtual void SoInput::setBuffer ( void *  buffer,
size_t  bufSize 
)
virtual

Sets an in-memory buffer to read from, along with its size.

◆ setFilePointer()

virtual void SoInput::setFilePointer ( FILE *  newFP)
virtual

Sets file pointer to read from.

Clears the stack of input files if necessary.

◆ setInputParameters()

void SoInput::setInputParameters ( SoInputParameters parameters)

Specify parameters to modify/control actions during the read of a file.

For example, use an instance of SoCADInputReaderParameters for file formats handled by the SoCADFileFormat module (IGES, STEP, CATIA, ...).

◆ updateReadPercent()

virtual void SoInput::updateReadPercent ( double  readPercentage)
virtual

Reports the percentage of bytes read from the file.


Derive a new class and override this method if you want to implement a progress bar.


The documentation for this class was generated from the following file: