// Return true if the binary rep is up to date bool BSRep::isUsable(const QDateTime& timeStamp) { bool isUpToDate= false; if (open(QIODevice::ReadOnly)) { if (headerIsOk()) { isUpToDate= timeStampOk(timeStamp); isUpToDate= isUpToDate && close(); } } else { std::string message(std::string("BSRep::loadRep Enable to open the file ") + m_FileInfo.fileName()); FileFormatException fileFormatException(message, m_FileInfo.fileName(), FileFormatException::FileNotFound); close(); throw(fileFormatException); } if (!isUpToDate && TraceLog::isEnable()) { std::stringList stringList("BSRep::isUsable"); stringList.append("File " + m_FileInfo.filePath() + " not Usable"); TraceLog::addTrace(stringList); } return isUpToDate; }
GLC_World* GLC_BSRepToWorld::CreateWorldFromBSRep(QFile &file) { ////////////////////////////////////////////////////////////////// // Test if the file exist and can be opened ////////////////////////////////////////////////////////////////// if (!file.open(QIODevice::ReadOnly)) { QString fileName(file.fileName()); QString message(QString("GLC_BSRepToWorld::CreateWorldFromBSRep File ") + fileName + QString(" doesn't exist")); GLC_FileFormatException fileFormatException(message, fileName, GLC_FileFormatException::FileNotFound); throw(fileFormatException); } file.close(); GLC_BSRep bsRep(file.fileName()); GLC_3DRep rep(bsRep.loadRep()); GLC_World* pWorld= new GLC_World(); pWorld->rootOccurrence()->addChild(new GLC_StructOccurrence(new GLC_3DRep(rep))); return pWorld; }
////////////////////////////////////////////////////////////////////// // name Get Functions ////////////////////////////////////////////////////////////////////// // Load the binary rep GLC_3DRep GLC_BSRep::loadRep() { GLC_3DRep loadedRep; if (open(QIODevice::ReadOnly)) { if (headerIsOk()) { timeStampOk(QDateTime()); GLC_BoundingBox boundingBox; m_DataStream >> boundingBox; bool useCompression; m_DataStream >> useCompression; if (useCompression) { QByteArray CompresseBuffer; m_DataStream >> CompresseBuffer; QByteArray uncompressedBuffer= qUncompress(CompresseBuffer); uncompressedBuffer.squeeze(); CompresseBuffer.clear(); CompresseBuffer.squeeze(); QDataStream bufferStream(uncompressedBuffer); bufferStream >> loadedRep; } else { m_DataStream >> loadedRep; } loadedRep.setFileName(m_FileInfo.filePath()); if (!close()) { QString message(QString("GLC_BSRep::loadRep An error occur when loading file ") + m_FileInfo.fileName()); GLC_FileFormatException fileFormatException(message, m_FileInfo.fileName(), GLC_FileFormatException::WrongFileFormat); throw(fileFormatException); } } else {
// Create an GLC_World from an input 3DS File GLC_World* GLC_3dsToWorld::CreateWorldFrom3ds(QFile &file) { clear(); m_FileName= file.fileName(); ////////////////////////////////////////////////////////////////// // Test if the file exist and can be opened ////////////////////////////////////////////////////////////////// if (!file.open(QIODevice::ReadOnly)) { QString message(QString("GLC_3dsToWorld::CreateWorldFrom3ds File ") + m_FileName + QString(" doesn't exist")); GLC_FileFormatException fileFormatException(message, m_FileName, GLC_FileFormatException::FileNotFound); throw(fileFormatException); } // Close the file before open it with lib3ds file.close(); ////////////////////////////////////////////////////////////////// // Init member ////////////////////////////////////////////////////////////////// m_pWorld= new GLC_World; //Load 3ds File m_pLib3dsFile=lib3ds_file_load(m_FileName.toLocal8Bit().data()); if (!m_pLib3dsFile) { QString message= "GLC_3dsToWorld::CreateWorldFrom3ds : Loading Failed"; GLC_FileFormatException fileFormatException(message, m_FileName, GLC_FileFormatException::FileNotSupported); clear(); throw(fileFormatException); } // Evaluate Nodes Matrix for the first frame (Needed by instances) lib3ds_file_eval(m_pLib3dsFile, 0.0); m_CurrentQuantumValue= m_InitQuantumValue; m_PreviousQuantumValue= m_CurrentQuantumValue; emit currentQuantum(m_CurrentQuantumValue); // Count the number of meshes for(Lib3dsMesh *pMesh= m_pLib3dsFile->meshes; pMesh != NULL; pMesh = pMesh->next) { ++m_NumberOfMeshes; } // Check if there is some meshes in the 3ds file if (0 == m_NumberOfMeshes) { QString message= "GLC_3dsToWorld::CreateWorldFrom3ds : No mesh found !"; GLC_FileFormatException fileFormatException(message, m_FileName, GLC_FileFormatException::NoMeshFound); clear(); throw(fileFormatException); } // Create GLC_3DViewInstance with Node for (Lib3dsNode *pNode=m_pLib3dsFile->nodes; pNode!=0; pNode=pNode->next) { createMeshes(m_pWorld->rootOccurence(), pNode); } // Load unloaded mesh name for(Lib3dsMesh *pMesh= m_pLib3dsFile->meshes; pMesh != NULL; pMesh = pMesh->next) { if (!m_LoadedMeshes.contains(QString(pMesh->name))) { //qDebug() << "Mesh without parent found" << QString(pMesh->name); Lib3dsNode *pNode= lib3ds_node_new_object(); strcpy(pNode->name, pMesh->name); pNode->parent_id= LIB3DS_NO_PARENT; lib3ds_file_insert_node(m_pLib3dsFile, pNode); createMeshes(m_pWorld->rootOccurence(), pNode); } } // Free Lib3dsFile and all its ressources lib3ds_file_free(m_pLib3dsFile); m_pLib3dsFile= NULL; emit currentQuantum(100); // Create the world bounding box m_pWorld->collection()->boundingBox(); return m_pWorld; }