GLC_lib  2.5.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
glc_fileloader.cpp
Go to the documentation of this file.
1 /****************************************************************************
2 
3  This file is part of the GLC-lib library.
4  Copyright (C) 2011 Jrme Forrissier
5  Copyright (C) 2005-2008 Laurent Ribon (laumaya@users.sourceforge.net)
6  http://glc-lib.sourceforge.net
7 
8  GLC-lib is free software; you can redistribute it and/or modify
9  it under the terms of the GNU Lesser General Public License as published by
10  the Free Software Foundation; either version 3 of the License, or
11  (at your option) any later version.
12 
13  GLC-lib is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  GNU Lesser General Public License for more details.
17 
18  You should have received a copy of the GNU Lesser General Public License
19  along with GLC-lib; if not, write to the Free Software
20  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 
22 *****************************************************************************/
23 
25 
26 
27 #include "glc_fileloader.h"
28 
29 #include "glc_objtoworld.h"
30 #include "glc_stltoworld.h"
31 #include "glc_offtoworld.h"
32 #include "glc_3dstoworld.h"
33 #include "glc_3dxmltoworld.h"
34 #include "glc_colladatoworld.h"
35 #include "glc_bsreptoworld.h"
36 
37 #include "../sceneGraph/glc_world.h"
38 #include "../glc_fileformatexception.h"
39 #include "../glc_factory.h"
40 #include "glc_worldreaderplugin.h"
41 
43 // Constructor
46 {
47 }
48 
50 {
51 }
52 
54 // Set Functions
56 
57 // Create an GLC_World from an input File
58 GLC_World GLC_FileLoader::createWorldFromFile(QFile &file, QStringList* pAttachedFileName)
59 {
60 #if defined(Q_OS_WIN)
61  // We need to force the connection type on Windows, not sure why:
62  // Qt::DirectConnection should be selected automatically since
63  // source and destination are in the same thread...
64 #define connect(snd, sig, rcv, memb) \
65  connect(snd, sig, rcv, memb, Qt::DirectConnection)
66 #endif
67 
68  const QString suffix= QFileInfo(file).suffix();
69  if (GLC_Factory::canBeLoaded(suffix))
70  {
71  GLC_WorldReaderHandler* pReaderHandler= GLC_Factory::loadingHandler(file.fileName());
72  if (NULL != pReaderHandler)
73  {
74  qDebug() << "Use STL plugin";
75  QObject* pObject= dynamic_cast<QObject*>(pReaderHandler);
76  Q_ASSERT(NULL != pObject);
77  connect(pObject, SIGNAL(currentQuantum(int)), this, SIGNAL(currentQuantum(int)));
78  GLC_World resultWorld= pReaderHandler->read(&file);
79  if (NULL != pAttachedFileName)
80  {
81  (*pAttachedFileName)= pReaderHandler->listOfAttachedFileName();
82  }
83 
84  delete pReaderHandler;
85  return resultWorld;
86  }
87  }
88  GLC_World* pWorld= NULL;
89  if (QFileInfo(file).suffix().toLower() == "obj")
90  {
91  GLC_ObjToWorld objToWorld;
92  connect(&objToWorld, SIGNAL(currentQuantum(int)), this, SIGNAL(currentQuantum(int)));
93  pWorld= objToWorld.CreateWorldFromObj(file);
94  if (NULL != pAttachedFileName)
95  {
96  (*pAttachedFileName)= objToWorld.listOfAttachedFileName();
97  }
98  }
99  else if (QFileInfo(file).suffix().toLower() == "stl")
100  {
101  GLC_StlToWorld stlToWorld;
102  connect(&stlToWorld, SIGNAL(currentQuantum(int)), this, SIGNAL(currentQuantum(int)));
103  pWorld= stlToWorld.CreateWorldFromStl(file);
104  }
105  else if (QFileInfo(file).suffix().toLower() == "off")
106  {
107  GLC_OffToWorld offToWorld;
108  connect(&offToWorld, SIGNAL(currentQuantum(int)), this, SIGNAL(currentQuantum(int)));
109  pWorld= offToWorld.CreateWorldFromOff(file);
110  }
111  else if (QFileInfo(file).suffix().toLower() == "3ds")
112  {
113  GLC_3dsToWorld studioToWorld;
114  connect(&studioToWorld, SIGNAL(currentQuantum(int)), this, SIGNAL(currentQuantum(int)));
115  pWorld= studioToWorld.CreateWorldFrom3ds(file);
116  if (NULL != pAttachedFileName)
117  {
118  (*pAttachedFileName)= studioToWorld.listOfAttachedFileName();
119  }
120  }
121  else if (QFileInfo(file).suffix().toLower() == "3dxml")
122  {
123  GLC_3dxmlToWorld d3dxmlToWorld;
124  connect(&d3dxmlToWorld, SIGNAL(currentQuantum(int)), this, SIGNAL(currentQuantum(int)));
125  pWorld= d3dxmlToWorld.createWorldFrom3dxml(file, false);
126  if (NULL != pAttachedFileName)
127  {
128  (*pAttachedFileName)= d3dxmlToWorld.listOfAttachedFileName();
129  }
130  }
131  else if (QFileInfo(file).suffix().toLower() == "dae")
132  {
133  GLC_ColladaToWorld colladaToWorld;
134  connect(&colladaToWorld, SIGNAL(currentQuantum(int)), this, SIGNAL(currentQuantum(int)));
135  pWorld= colladaToWorld.CreateWorldFromCollada(file);
136  if (NULL != pAttachedFileName)
137  {
138  (*pAttachedFileName)= colladaToWorld.listOfAttachedFileName();
139  }
140  }
141  else if (QFileInfo(file).suffix().toLower() == "bsrep")
142  {
143  GLC_BSRepToWorld bsRepToWorld;
144  pWorld= bsRepToWorld.CreateWorldFromBSRep(file);
145  emit currentQuantum(100);
146  }
147 
148  if (NULL == pWorld)
149  {
150  // File extension not recognize or file not loaded
151  QString message(QString("GLC_Factory::createWorldFromFile File ") + file.fileName() + QString(" not loaded"));
152  GLC_FileFormatException fileFormatException(message, file.fileName(), GLC_FileFormatException::FileNotSupported);
153  throw(fileFormatException);
154  }
155  GLC_World resulWorld(*pWorld);
156  delete pWorld;
157 
158  return resulWorld;
159 }

©2005-2013 Laurent Ribon