/*! * Reads the scene saved on the file with given \a filename and return a pointer to the scene. * * Returns null on any error. */ TSceneKit* Document::GetSceneKitFromFile( const QString& fileName ) { SoInput sceneInput; if ( !sceneInput.openFile( fileName.toLatin1().constData() ) ) { QString message = QString( "Cannot open file %1." ).arg( fileName ); emit Warning( message ); return 0; } if( !sceneInput.isValidFile() ) { QString message = QString( "Error reading file %1.\n" ).arg( fileName ); emit Warning( message ); return 0; } SoSeparator* graphSeparator = SoDB::readAll( &sceneInput ); sceneInput.closeFile(); if ( !graphSeparator ) { QString message = QString( "Error reading file %1.\n" ).arg( fileName ); emit Warning( message ); return 0; } return static_cast< TSceneKit* >( graphSeparator->getChild(0) ); return 0; }
SoSeparator* loadModel(const char* fileName) { SoSeparator *root = new SoSeparator; SoInput myScene; //try to open the file if (!myScene.openFile(fileName)) { printf("Could not open %s\n",fileName) ; return NULL; } //check if the file is valid if (!myScene.isValidFile()) { printf("%s is not a valid Inventor file\n",fileName) ; return NULL; } //try to read the file root = SoDB::readAll(&myScene) ; if (root == NULL) { printf("Problem reading %s\n",fileName) ; myScene.closeFile() ; return NULL; } //close the file myScene.closeFile() ; return root ; }
void SoFileSubgraph::readFile(const char *fileName){ // open the input file SoInput sceneInput; if (!sceneInput.openFile(fileName)) { SoDebugError::post("SoFileSubgraph::readFile()", "Cannot open file '%s'", fileName); return; } if (!sceneInput.isValidFile()){ SoDebugError::post("SoFileSubgraph::readFile()", "file '%s' is not a valid Inventor file", fileName); return; } else{ SoDebugError::postInfo("SoFileSubgraph::readFile()", "file '%s' read successfully", fileName); } // read the whole file into the database SoSeparator *subgraph=SoDB::readAll(&sceneInput); subgraph->ref(); if (subgraph ==NULL) { SoDebugError::post("SoFileSubgraph::readFile()", "problem reading contents of file '%s'", fileName); return; } SoSeparator *graphRoot=SO_GET_ANY_PART(this,"root",SoSeparator); graphRoot->addChild(subgraph); sceneInput.closeFile(); }