glc_fileloader.cpp

Go to the documentation of this file.
00001 /****************************************************************************
00002 
00003  This file is part of the GLC-lib library.
00004  Copyright (C) 2011 Jrme Forrissier
00005  Copyright (C) 2005-2008 Laurent Ribon (laumaya@users.sourceforge.net)
00006  http://glc-lib.sourceforge.net
00007 
00008  GLC-lib is free software; you can redistribute it and/or modify
00009  it under the terms of the GNU Lesser General Public License as published by
00010  the Free Software Foundation; either version 3 of the License, or
00011  (at your option) any later version.
00012 
00013  GLC-lib is distributed in the hope that it will be useful,
00014  but WITHOUT ANY WARRANTY; without even the implied warranty of
00015  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016  GNU Lesser General Public License for more details.
00017 
00018  You should have received a copy of the GNU Lesser General Public License
00019  along with GLC-lib; if not, write to the Free Software
00020  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
00021 
00022 *****************************************************************************/
00023 
00025 
00026 
00027 #include "glc_fileloader.h"
00028 
00029 #include "glc_objtoworld.h"
00030 #include "glc_stltoworld.h"
00031 #include "glc_offtoworld.h"
00032 #include "glc_3dstoworld.h"
00033 #include "glc_3dxmltoworld.h"
00034 #include "glc_colladatoworld.h"
00035 #include "glc_bsreptoworld.h"
00036 
00037 #include "../sceneGraph/glc_world.h"
00038 #include "../glc_fileformatexception.h"
00039 #include "../glc_factory.h"
00040 #include "glc_worldreaderplugin.h"
00041 
00043 // Constructor
00045 GLC_FileLoader::GLC_FileLoader()
00046 {
00047 }
00048 
00049 GLC_FileLoader::~GLC_FileLoader()
00050 {
00051 }
00052 
00054 // Set Functions
00056 
00057 // Create an GLC_World from an input File
00058 GLC_World GLC_FileLoader::createWorldFromFile(QFile &file, QStringList* pAttachedFileName)
00059 {
00060 #if defined(Q_OS_WIN)
00061         // We need to force the connection type on Windows, not sure why:
00062         // Qt::DirectConnection should be selected automatically since
00063         // source and destination are in the same thread...
00064 #define connect(snd, sig, rcv, memb) \
00065         connect(snd, sig, rcv, memb, Qt::DirectConnection)
00066 #endif
00067 
00068         const QString suffix= QFileInfo(file).suffix();
00069         if (GLC_Factory::canBeLoaded(suffix))
00070         {
00071                 GLC_WorldReaderHandler* pReaderHandler= GLC_Factory::loadingHandler(file.fileName());
00072                 if (NULL != pReaderHandler)
00073                 {
00074                         qDebug() << "Use STL plugin";
00075                         QObject* pObject= dynamic_cast<QObject*>(pReaderHandler);
00076                         Q_ASSERT(NULL != pObject);
00077                         connect(pObject, SIGNAL(currentQuantum(int)), this, SIGNAL(currentQuantum(int)));
00078                         GLC_World resultWorld= pReaderHandler->read(&file);
00079                         if (NULL != pAttachedFileName)
00080                         {
00081                                 (*pAttachedFileName)= pReaderHandler->listOfAttachedFileName();
00082                         }
00083 
00084                         delete pReaderHandler;
00085                         return resultWorld;
00086                 }
00087         }
00088         GLC_World* pWorld= NULL;
00089         if (QFileInfo(file).suffix().toLower() == "obj")
00090         {
00091                 GLC_ObjToWorld objToWorld;
00092                 connect(&objToWorld, SIGNAL(currentQuantum(int)), this, SIGNAL(currentQuantum(int)));
00093                 pWorld= objToWorld.CreateWorldFromObj(file);
00094                 if (NULL != pAttachedFileName)
00095                 {
00096                         (*pAttachedFileName)= objToWorld.listOfAttachedFileName();
00097                 }
00098         }
00099         else if (QFileInfo(file).suffix().toLower() == "stl")
00100         {
00101                 GLC_StlToWorld stlToWorld;
00102                 connect(&stlToWorld, SIGNAL(currentQuantum(int)), this, SIGNAL(currentQuantum(int)));
00103                 pWorld= stlToWorld.CreateWorldFromStl(file);
00104         }
00105         else if (QFileInfo(file).suffix().toLower() == "off")
00106         {
00107                 GLC_OffToWorld offToWorld;
00108                 connect(&offToWorld, SIGNAL(currentQuantum(int)), this, SIGNAL(currentQuantum(int)));
00109                 pWorld= offToWorld.CreateWorldFromOff(file);
00110         }
00111         else if (QFileInfo(file).suffix().toLower() == "3ds")
00112         {
00113                 GLC_3dsToWorld studioToWorld;
00114                 connect(&studioToWorld, SIGNAL(currentQuantum(int)), this, SIGNAL(currentQuantum(int)));
00115                 pWorld= studioToWorld.CreateWorldFrom3ds(file);
00116                 if (NULL != pAttachedFileName)
00117                 {
00118                         (*pAttachedFileName)= studioToWorld.listOfAttachedFileName();
00119                 }
00120         }
00121         else if (QFileInfo(file).suffix().toLower() == "3dxml")
00122         {
00123                 GLC_3dxmlToWorld d3dxmlToWorld;
00124                 connect(&d3dxmlToWorld, SIGNAL(currentQuantum(int)), this, SIGNAL(currentQuantum(int)));
00125                 pWorld= d3dxmlToWorld.createWorldFrom3dxml(file, false);
00126                 if (NULL != pAttachedFileName)
00127                 {
00128                         (*pAttachedFileName)= d3dxmlToWorld.listOfAttachedFileName();
00129                 }
00130         }
00131         else if (QFileInfo(file).suffix().toLower() == "dae")
00132         {
00133                 GLC_ColladaToWorld colladaToWorld;
00134                 connect(&colladaToWorld, SIGNAL(currentQuantum(int)), this, SIGNAL(currentQuantum(int)));
00135                 pWorld= colladaToWorld.CreateWorldFromCollada(file);
00136                 if (NULL != pAttachedFileName)
00137                 {
00138                         (*pAttachedFileName)= colladaToWorld.listOfAttachedFileName();
00139                 }
00140         }
00141         else if (QFileInfo(file).suffix().toLower() == "bsrep")
00142         {
00143                 GLC_BSRepToWorld bsRepToWorld;
00144                 pWorld= bsRepToWorld.CreateWorldFromBSRep(file);
00145                 emit currentQuantum(100);
00146         }
00147 
00148         if (NULL == pWorld)
00149         {
00150                 // File extension not recognize or file not loaded
00151                 QString message(QString("GLC_Factory::createWorldFromFile File ") + file.fileName() + QString(" not loaded"));
00152                 GLC_FileFormatException fileFormatException(message, file.fileName(), GLC_FileFormatException::FileNotSupported);
00153                 throw(fileFormatException);
00154         }
00155         GLC_World resulWorld(*pWorld);
00156         delete pWorld;
00157 
00158         return resulWorld;
00159 }

SourceForge.net Logo

©2005-2011 Laurent Ribon