glc_3dxmltoworld.cpp

Go to the documentation of this file.
00001 /****************************************************************************
00002 
00003  This file is part of the GLC-lib library.
00004  Copyright (C) 2005-2008 Laurent Ribon (laumaya@users.sourceforge.net)
00005  http://glc-lib.sourceforge.net
00006 
00007  GLC-lib is free software; you can redistribute it and/or modify
00008  it under the terms of the GNU Lesser General Public License as published by
00009  the Free Software Foundation; either version 3 of the License, or
00010  (at your option) any later version.
00011 
00012  GLC-lib is distributed in the hope that it will be useful,
00013  but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  GNU Lesser General Public License for more details.
00016 
00017  You should have received a copy of the GNU Lesser General Public License
00018  along with GLC-lib; if not, write to the Free Software
00019  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
00020 
00021 *****************************************************************************/
00022 
00024 
00025 #include "glc_3dxmltoworld.h"
00026 #include "../sceneGraph/glc_world.h"
00027 #include "../glc_fileformatexception.h"
00028 #include "../geometry/glc_mesh.h"
00029 #include "../geometry/glc_3drep.h"
00030 #include "glc_xmlutil.h"
00031 
00032 // Quazip library
00033 #include "../3rdparty/quazip/quazip.h"
00034 #include "../3rdparty/quazip/quazipfile.h"
00035 
00036 #include <QString>
00037 #include <QGLContext>
00038 #include <QFileInfo>
00039 #include <QSet>
00040 #include <QMutexLocker>
00041 
00042 //using namespace glcXmlUtil;
00043 
00044 QMutex GLC_3dxmlToWorld::m_ZipMutex;
00045 
00046 static qint64 chunckSize= 10000000;
00047 
00048 GLC_3dxmlToWorld::GLC_3dxmlToWorld()
00049 : QObject()
00050 , m_pStreamReader(NULL)
00051 , m_FileName()
00052 , m_p3dxmlArchive(NULL)
00053 , m_pCurrentFile(NULL)
00054 , m_RootName()
00055 , m_pWorld(NULL)
00056 , m_ReferenceHash()
00057 , m_AssyLinkList()
00058 , m_InstanceOf()
00059 , m_SetOfExtRef()
00060 , m_InstanceOfExtRefHash()
00061 , m_ExternalReferenceHash()
00062 , m_MaterialHash()
00063 , m_IsInArchive(false)
00064 , m_ReferenceRepHash()
00065 , m_LocalRepLinkList()
00066 , m_ExternRepLinkList()
00067 , m_SetOfExtRep()
00068 , m_pCurrentMaterial(NULL)
00069 , m_TextureImagesHash()
00070 , m_LoadStructureOnly(false)
00071 , m_SetOfAttachedFileName()
00072 , m_CurrentFileName()
00073 , m_CurrentDateTime()
00074 , m_V3OccurenceAttribHash()
00075 , m_V4OccurenceAttribList()
00076 , m_GetExternalRef3DName(false)
00077 , m_ByteArrayList()
00078 , m_IsVersion3(false)
00079 {
00080 
00081 }
00082 
00083 GLC_3dxmlToWorld::~GLC_3dxmlToWorld()
00084 {
00085         delete m_pStreamReader;
00086         m_pStreamReader= NULL;
00087 
00088         delete m_pCurrentFile;
00089         delete m_p3dxmlArchive;
00090 
00091         clearMaterialHash();
00092 
00093         // Clear specific attributes hash table
00094         QHash<unsigned int, V3OccurenceAttrib*>::iterator iAttrib= m_V3OccurenceAttribHash.begin();
00095         while (m_V3OccurenceAttribHash.constEnd() != iAttrib)
00096         {
00097                 delete iAttrib.value();
00098                 ++iAttrib;
00099         }
00100 
00101         const int v4OccurenceAttribCount= m_V4OccurenceAttribList.count();
00102         for (int i= 0; i < v4OccurenceAttribCount; ++i)
00103         {
00104                 delete m_V4OccurenceAttribList.at(i);
00105         }
00106 }
00107 
00109 // Set Functions
00111 
00112 // Create an GLC_World from an input 3DXML File
00113 GLC_World* GLC_3dxmlToWorld::createWorldFrom3dxml(QFile &file, bool structureOnly, bool getExternalRef)
00114 {
00115         clear();
00116         m_pWorld= new GLC_World();
00117         m_GetExternalRef3DName= getExternalRef;
00118         m_LoadStructureOnly= structureOnly;
00119         m_FileName= file.fileName();
00120 
00121         // Create the 3dxml Zip archive
00122         m_p3dxmlArchive= new QuaZip(m_FileName);
00123         // Trying to load archive
00124         if(!m_p3dxmlArchive->open(QuaZip::mdUnzip))
00125         {
00126           // In this case, the 3dxml is not compressed or is not valid
00127           m_RootName= m_FileName;
00128           delete m_p3dxmlArchive;
00129           m_p3dxmlArchive= NULL;
00130         }
00131         else
00132         {
00133                 // Get the 3DXML time stamp
00134                 m_CurrentDateTime= QFileInfo(m_FileName).lastModified();
00135 
00136                 m_IsInArchive= true;
00137                 // Set the file Name Codec
00138                 //m_p3dxmlArchive->setFileNameCodec("IBM866");
00139 
00140                 // Load the manifest
00141                 loadManifest();
00142         }
00143 
00144         if (!m_LoadStructureOnly)
00145         {
00146                 // Trying to Load CATRepImage file
00147                 loadCatRepImage();
00148 
00149                 // Trying to Load CATRefMaterial File
00150                 loadCatMaterialRef();
00151         }
00152 
00153         // Read the header
00154         readHeader();
00155 
00156         // Load the product structure
00157         loadProductStructure();
00158 
00159 
00160         emit currentQuantum(100);
00161         return m_pWorld;
00162 }
00163 
00164 // Create 3DRep from an 3DXML rep
00165 GLC_3DRep GLC_3dxmlToWorld::create3DrepFrom3dxmlRep(const QString& fileName)
00166 {
00167         GLC_3DRep resultRep;
00168         if (glc::isArchiveString(fileName))
00169         {
00170                 m_FileName= glc::archiveFileName(fileName);
00171 
00172                 // Create the 3dxml Zip archive
00173                 m_ZipMutex.lock();
00174                 m_p3dxmlArchive= new QuaZip(m_FileName);
00175                 // Trying to load archive
00176                 if(!m_p3dxmlArchive->open(QuaZip::mdUnzip))
00177                 {
00178                   delete m_p3dxmlArchive;
00179                   return GLC_3DRep();
00180                 }
00181                 else
00182                 {
00183                         m_IsInArchive= true;
00184                         // Set the file Name Codec
00185                         //m_p3dxmlArchive->setFileNameCodec("IBM866");
00186                 }
00187                 m_ZipMutex.unlock();
00188                 m_CurrentFileName= glc::archiveEntryFileName(fileName);
00189 
00190                 // Get the 3DXML time stamp
00191                 m_CurrentDateTime= QFileInfo(QFileInfo(m_FileName)).lastModified();
00192         }
00193         else if (glc::isFileString(fileName))
00194         {
00195                 m_FileName= glc::archiveFileName(fileName);
00196                 m_CurrentFileName= glc::archiveEntryFileName(fileName);
00197 
00198                 // Get the rep time stamp
00199                 m_CurrentDateTime= QFileInfo(m_CurrentFileName).lastModified();
00200 
00201                 // Keep only the file name
00202                 QDir structureDir(QFileInfo(m_FileName).absolutePath() + QDir::separator());
00203                 m_CurrentFileName= structureDir.relativeFilePath(m_CurrentFileName);
00204 
00205         }
00206         else
00207         {
00208                 return resultRep;
00209         }
00210 
00211 
00212         setRepresentationFileName(&resultRep);
00213 
00214         if (QFileInfo(m_CurrentFileName).suffix().toLower() == "3dxml")
00215         {
00216                 if (GLC_State::cacheIsUsed() && GLC_State::currentCacheManager().isUsable(m_CurrentDateTime, QFileInfo(m_FileName).baseName(), QFileInfo(m_CurrentFileName).fileName()))
00217                 {
00218                         GLC_CacheManager cacheManager = GLC_State::currentCacheManager();
00219 
00220                         GLC_BSRep binaryRep = cacheManager.binary3DRep(QFileInfo(m_FileName).baseName(), QFileInfo(m_CurrentFileName).fileName());
00221                         resultRep = binaryRep.loadRep();
00222                 }
00223                 else
00224                 {
00225                         if (setStreamReaderToFile(m_CurrentFileName, true))
00226                         {
00227                                 GLC_StructReference* pStructRef = createReferenceRep(QString(), NULL);
00228                                 GLC_3DRep* pRep = NULL;
00229                                 if ((NULL != pStructRef) && pStructRef->hasRepresentation())
00230                                 {
00231                                         pRep= dynamic_cast<GLC_3DRep*> (pStructRef->representationHandle());
00232 
00233                                         if (NULL != pRep)
00234                                         {
00235                                                 resultRep = GLC_3DRep(*pRep);
00236                                                 resultRep.setName(pStructRef->name());
00237                                         }
00238                                 }
00239                                 delete pStructRef;
00240                         }
00241                 }
00242         }
00243         else if ((QFileInfo(m_CurrentFileName).suffix().toLower() == "3drep") || (QFileInfo(m_CurrentFileName).suffix().toLower() == "xml"))
00244         {
00245         if (GLC_State::cacheIsUsed() && GLC_State::currentCacheManager().isUsable(m_CurrentDateTime, QFileInfo(m_FileName).baseName(), QFileInfo(m_CurrentFileName).fileName()))
00246                 {
00247                         GLC_CacheManager cacheManager = GLC_State::currentCacheManager();
00248                         GLC_BSRep binaryRep = cacheManager.binary3DRep(QFileInfo(m_FileName).baseName(), QFileInfo(m_CurrentFileName).fileName());
00249                         resultRep = binaryRep.loadRep();
00250                 }
00251                 else
00252                 {
00253                         if (setStreamReaderToFile(m_CurrentFileName, true))
00254                         {
00255                                 resultRep = loadCurrentExtRep();
00256                         }
00257                 }
00258         }
00259         resultRep.clean();
00260 
00261         return resultRep;
00262 }
00263 
00265 // Private services functions
00267 // Load the 3dxml's manifest
00268 void GLC_3dxmlToWorld::loadManifest()
00269 {
00270         setStreamReaderToFile("Manifest.xml");
00271         m_RootName= getContent(m_pStreamReader, "Root");
00272 
00273         if (m_pStreamReader->atEnd() || m_pStreamReader->hasError())
00274         {
00275                 QString message(QString("GLC_3dxmlToWorld::loadManifest Manifest file ") + m_FileName + " doesn't contains Root Element");
00276                 GLC_FileFormatException fileFormatException(message, m_FileName, GLC_FileFormatException::WrongFileFormat);
00277                 clear();
00278                 throw(fileFormatException);
00279         }
00280 
00281         delete m_pStreamReader;
00282         m_pStreamReader= NULL;
00283 }
00284 
00286 void GLC_3dxmlToWorld::clear()
00287 {
00288         delete m_pWorld;
00289         m_pWorld= NULL;
00290 
00291         delete m_pStreamReader;
00292         m_pStreamReader= NULL;
00293 
00294         m_ByteArrayList.clear();
00295         // Clear current file
00296         if (NULL != m_pCurrentFile)
00297         {
00298                 m_pCurrentFile->close();
00299                 delete m_pCurrentFile;
00300                 m_pCurrentFile= NULL;
00301         }
00302 
00303         // Clear the 3dxml archive
00304         if (NULL != m_p3dxmlArchive)
00305         {
00306                 m_p3dxmlArchive->close();
00307                 delete m_p3dxmlArchive;
00308                 m_p3dxmlArchive= NULL;
00309         }
00310 
00311         m_SetOfAttachedFileName.clear();
00312 
00313         clearMaterialHash();
00314 }
00315 
00316 // Go to a Rep of a xml
00317 void GLC_3dxmlToWorld::goToRepId(const QString& id)
00318 {
00319         while(!m_pStreamReader->atEnd() && !((QXmlStreamReader::StartElement == m_pStreamReader->tokenType()) && (m_pStreamReader->name() == "Representation")
00320                         && (m_pStreamReader->attributes().value("id").toString() == id)))
00321         {
00322                 readNext();
00323         }
00324 
00325 }
00326 
00327 // Go to Polygonal Rep Type
00328 void GLC_3dxmlToWorld::gotToPolygonalRepType()
00329 {
00330         while(endElementNotReached(m_pStreamReader, "Representation") && !m_pStreamReader->atEnd() && !((QXmlStreamReader::StartElement == m_pStreamReader->tokenType())
00331                         && ((m_pStreamReader->name() == "Rep") || (m_pStreamReader->name() == "Root"))
00332                         && (m_pStreamReader->attributes().value("xsi:type").toString() == "PolygonalRepType")))
00333         {
00334                 //qDebug() << m_pStreamReader->name();
00335                 //qDebug() << m_pStreamReader->attributes().value("xsi:type").toString();
00336                 readNext();
00337         }
00338 
00339 }
00340 
00341 // Read the specified attribute
00342 QString GLC_3dxmlToWorld::readAttribute(const QString& name, bool required)
00343 {
00344         QString attributeValue;
00345         if (required && !m_pStreamReader->attributes().hasAttribute(name))
00346         {
00347                 QString message(QString("required attribute ") + name + QString(" Not found"));
00348                 GLC_FileFormatException fileFormatException(message, m_FileName, GLC_FileFormatException::WrongFileFormat);
00349                 clear();
00350                 throw(fileFormatException);
00351         }
00352         else
00353         {
00354                 attributeValue= m_pStreamReader->attributes().value(name).toString();
00355         }
00356         return attributeValue;
00357 }
00358 
00359 void GLC_3dxmlToWorld::readHeader()
00360 {
00361         setStreamReaderToFile(m_RootName);
00362 
00363         goToElement(m_pStreamReader, "Header");
00364         if (m_pStreamReader->atEnd() || m_pStreamReader->hasError())
00365         {
00366                 QString message(QString("GLC_3dxmlToWorld::readHeader Element Header Not found in ") + m_FileName);
00367                 GLC_FileFormatException fileFormatException(message, m_FileName, GLC_FileFormatException::WrongFileFormat);
00368                 clear();
00369                 throw(fileFormatException);
00370         }
00371 
00372         while(endElementNotReached(m_pStreamReader, "Header"))
00373         {
00374                 if ((QXmlStreamReader::StartElement == m_pStreamReader->tokenType()) && (m_pStreamReader->name() == "SchemaVersion"))
00375                 {
00376                         QString version= getContent(m_pStreamReader, "SchemaVersion");
00377                         m_IsVersion3= version.startsWith('3');
00378                 }
00379                 readNext();
00380         }
00381 }
00382 
00383 // Load the product structure
00384 void GLC_3dxmlToWorld::loadProductStructure()
00385 {
00386 
00387         goToElement(m_pStreamReader, "ProductStructure");
00388         if (m_pStreamReader->atEnd() || m_pStreamReader->hasError())
00389         {
00390                 QString message(QString("GLC_3dxmlToWorld::loadProductStructure Element ProctStructure Not found in ") + m_FileName);
00391                 GLC_FileFormatException fileFormatException(message, m_FileName, GLC_FileFormatException::WrongFileFormat);
00392                 clear();
00393                 throw(fileFormatException);
00394         }
00395 
00396         // Load the structure
00397         while(endElementNotReached(m_pStreamReader, "ProductStructure"))
00398         {
00399                 if ((QXmlStreamReader::StartElement == m_pStreamReader->tokenType())
00400                                 && ((m_pStreamReader->name() == "Reference3D") || (m_pStreamReader->name() == "Instance3D")
00401                                                 || (m_pStreamReader->name() == "ReferenceRep") || (m_pStreamReader->name() == "InstanceRep")))
00402                 {
00403                         if (m_pStreamReader->name() == "Reference3D") loadReference3D();
00404                         else if (m_pStreamReader->name() == "Instance3D") loadInstance3D();
00405                         else if (m_pStreamReader->name() == "ReferenceRep") loadReferenceRep();
00406                         else loadInstanceRep();
00407                 }
00408 
00409                 readNext();
00410         }
00411 
00412         // Load Default view properties
00413         while(endElementNotReached(m_pStreamReader, "Model_3dxml"))
00414         {
00415                 if ((QXmlStreamReader::StartElement == m_pStreamReader->tokenType())
00416                                 && ((m_pStreamReader->name() == "DefaultView") || (m_pStreamReader->name() == "GeometricRepresentationSet")))
00417                 {
00418                         if (m_pStreamReader->name() == "DefaultView") loadDefaultView();
00419                         else if (m_pStreamReader->name() == "GeometricRepresentationSet") loadLocalRepresentations();
00420 
00421                 }
00422                 readNext();
00423         }
00424 
00425         // Check if an error Occur
00426         if (m_pStreamReader->hasError())
00427         {
00428                 QString message(QString("GLC_3dxmlToWorld::loadProductStructure An error occur in ") + m_FileName);
00429                 GLC_FileFormatException fileFormatException(message, m_FileName, GLC_FileFormatException::WrongFileFormat);
00430                 clear();
00431                 throw(fileFormatException);
00432         }
00433 
00434         // Load external ref (3DXML V3)
00435         loadExternalRef3D();
00436 
00437         // Load extern representations (3DXML V4)
00438         loadExternRepresentations();
00439 
00440         { // Link locals instance with reference
00441                 InstanceOfHash::iterator iInstance= m_InstanceOf.begin();
00442                 while (iInstance != m_InstanceOf.constEnd())
00443                 {
00444                         GLC_StructInstance* pInstance= iInstance.key();
00445                         GLC_StructReference* pRef= m_ReferenceHash.value(iInstance.value());
00446                         if (NULL == pRef)
00447                         {
00448                                 QString message(QString("GLC_3dxmlToWorld::loadProductStructure a instance reference a non existing reference"));
00449                                 message.append(" Instance name " + pInstance->name());
00450                                 GLC_FileFormatException fileFormatException(message, m_FileName, GLC_FileFormatException::WrongFileFormat);
00451                                 clear();
00452                                 throw(fileFormatException);
00453                         }
00454                         pInstance->setReference(pRef);
00455 
00456                         ++iInstance;
00457                 }
00458                 m_InstanceOf.clear();
00459 
00460         }
00461         //qDebug() << "Local instance linked with reference";
00462 
00463         { // Link external instance with reference
00464 
00465                 InstanceOfExtRefHash::iterator iInstance= m_InstanceOfExtRefHash.begin();
00466                 while (iInstance != m_InstanceOfExtRefHash.constEnd())
00467                 {
00468                         GLC_StructInstance* pInstance= iInstance.key();
00469                         GLC_StructReference* pRef;
00470                         if (m_ExternalReferenceHash.contains(iInstance.value()))
00471                         {
00472                                 pRef= m_ExternalReferenceHash.value(iInstance.value());
00473                         }
00474                         else
00475                         {
00476                                 QString referenceName= pInstance->name();
00477                                 referenceName= referenceName.left(pInstance->name().lastIndexOf('.'));
00478                                 QStringList stringList(m_FileName);
00479                                 stringList.append("Reference not found : " + referenceName);
00480                                 GLC_ErrorLog::addError(stringList);
00481                                 pRef= new GLC_StructReference(referenceName);
00482                         }
00483 
00484                         pInstance->setReference(pRef);
00485 
00486                         ++iInstance;
00487                 }
00488 
00489                 // Check usage of reference in the external reference hash
00490                 ExternalReferenceHash::const_iterator iRef= m_ExternalReferenceHash.constBegin();
00491                 while (m_ExternalReferenceHash.constEnd() != iRef)
00492                 {
00493                         GLC_StructReference* pRef= iRef.value();
00494                         if (! pRef->hasStructInstance())
00495                         {
00496                                 QStringList stringList(m_FileName);
00497                                 stringList.append("Orphan reference : " + pRef->name());
00498                                 GLC_ErrorLog::addError(stringList);
00499                                 delete pRef;
00500                         }
00501                         ++iRef;
00502                 }
00503                 m_ExternalReferenceHash.clear();
00504 
00505         }
00506         //qDebug() << "external instance linked with reference";
00507 
00508         // Create the unfolded tree
00509         createUnfoldedTree();
00510 
00511         // Update occurence number
00512         m_pWorld->rootOccurence()->updateOccurenceNumber(1);
00513 
00514         // Change occurence attributes for 3DXML V3
00515         if (! m_V3OccurenceAttribHash.isEmpty())
00516         {
00517                 //qDebug() << "Not visible occurence= " << m_V3OccurenceAttribHash.size();
00518                 QList<GLC_StructOccurence*> occurenceList= m_pWorld->listOfOccurence();
00519                 const int size= occurenceList.size();
00520                 for (int i= 0; i < size; ++i)
00521                 {
00522                         if (m_V3OccurenceAttribHash.contains(occurenceList.at(i)->occurenceNumber()))
00523                         {
00524                                 V3OccurenceAttrib* pOccurenceAttrib= m_V3OccurenceAttribHash.value(occurenceList.at(i)->occurenceNumber());
00525                                 occurenceList.at(i)->setVisibility(pOccurenceAttrib->m_IsVisible);
00526                                 if (NULL != pOccurenceAttrib->m_pRenderProperties)
00527                                 {
00528                                         occurenceList.at(i)->setRenderProperties(*(pOccurenceAttrib->m_pRenderProperties));
00529                                 }
00530                         }
00531                 }
00532         }
00533 
00534         // Change occurence attributes for 3DXML V4
00535         if (!m_V4OccurenceAttribList.isEmpty())
00536         {
00537                 QHash<GLC_StructInstance*, unsigned int> instanceToIdHash;
00538                 const int assyCount= m_AssyLinkList.count();
00539                 for (int i= 0; i < assyCount; ++i)
00540                 {
00541                         AssyLink assyLink= m_AssyLinkList.at(i);
00542                         instanceToIdHash.insert(assyLink.m_pChildInstance, assyLink.m_InstanceId);
00543                 }
00544 
00545                 const int attribCount= m_V4OccurenceAttribList.count();
00546                 for (int i= 0; i < attribCount; ++i)
00547                 {
00548                         V4OccurenceAttrib* pCurrentV4OccurenceAttrib= m_V4OccurenceAttribList.at(i);
00549                         //qDebug() << pCurrentV4OccurenceAttrib->m_Path;
00550                         applyV4Attribute(m_pWorld->rootOccurence(), pCurrentV4OccurenceAttrib, instanceToIdHash);
00551                 }
00552         }
00553 
00554         // Check usage of Instance
00555         InstanceOfExtRefHash::const_iterator iInstance= m_InstanceOfExtRefHash.constBegin();
00556         while (m_InstanceOfExtRefHash.constEnd() != iInstance)
00557         {
00558                 GLC_StructInstance* pInstance= iInstance.key();
00559                 if (!pInstance->hasStructOccurence())
00560                 {
00561                         QStringList stringList(m_FileName);
00562                         stringList.append("Orphan Instance : " + pInstance->name());
00563                         GLC_ErrorLog::addError(stringList);
00564                         delete pInstance;
00565                 }
00566                 else
00567                 {
00568                         QList<GLC_StructOccurence*> occurences= pInstance->listOfStructOccurences();
00569                         const int size= occurences.size();
00570                         for (int i= 0; i < size; ++i)
00571                         {
00572                                 const GLC_StructOccurence* pOccurence= occurences.at(i);
00573                                 if (pOccurence->isOrphan())
00574                                 {
00575                                         QStringList stringList(m_FileName);
00576                                         stringList.append("Orphan occurence : " + pOccurence->name());
00577                                         GLC_ErrorLog::addError(stringList);
00578                                         delete pOccurence;
00579                                 }
00580                         }
00581                 }
00582                 ++iInstance;
00583         }
00584 
00585         m_InstanceOfExtRefHash.clear();
00586 
00587 
00588         //qDebug() << "Unfolded tree created";
00589 
00590 }
00591 
00592 // Load a Reference3D
00593 void GLC_3dxmlToWorld::loadReference3D()
00594 {
00595         const unsigned int id= readAttribute("id", true).toUInt();
00596         const QString refName(readAttribute("name", true));
00597         GLC_StructReference* pStructReference;
00598 
00599         if (id == 1) // This is the root reference.
00600         {
00601                 m_pWorld->setRootName(refName);
00602                 pStructReference= m_pWorld->rootOccurence()->structInstance()->structReference();
00603                 pStructReference->setName(refName);
00604         }
00605         else
00606         {
00607                 pStructReference= new GLC_StructReference(refName);
00608         }
00609         // Try to find extension
00610         GLC_Attributes userAttributes;
00611         while (endElementNotReached(m_pStreamReader, "Reference3D"))
00612         {
00613                 if (m_pStreamReader->isStartElement() && (m_pStreamReader->name() == "Reference3DExtensionType"))
00614                 {
00615                         while (endElementNotReached(m_pStreamReader, "Reference3DExtensionType"))
00616                         {
00617                                 if ((QXmlStreamReader::StartElement == m_pStreamReader->tokenType()) && (m_pStreamReader->name() == "Attribute"))
00618                                 {
00619                                         QString name= readAttribute("name", true);
00620                                         QString value= readAttribute("value", true);
00621                                         if (name == "FILEPATH" && QDir(value).isRelative())
00622                                         {
00623                                                 value= QFileInfo(m_FileName).absolutePath() + QDir::separator() + value;
00624                                         }
00625                                         userAttributes.insert(name, value);
00626                                 }
00627                                 readNext();
00628                         }
00629                 }
00630                 readNext();
00631         }
00632         if (!userAttributes.isEmpty())
00633         {
00634                 pStructReference->setAttributes(userAttributes);
00635         }
00636 
00637         m_ReferenceHash.insert(id, pStructReference);
00638 }
00639 
00640 // Load a Instance3D
00641 void GLC_3dxmlToWorld::loadInstance3D()
00642 {
00643         const QString local= "urn:3DXML:Reference:loc:";
00644         const QString externRef= "urn:3DXML:Reference:ext:";
00645 
00646         const unsigned int instanceId= readAttribute("id", true).toUInt();
00647         const QString instName(readAttribute("name", false));
00648         goToElement(m_pStreamReader, "IsAggregatedBy");
00649         const unsigned int aggregatedById= getContent(m_pStreamReader, "IsAggregatedBy").toUInt();
00650         QString instanceOf= getContent(m_pStreamReader, "IsInstanceOf");
00651         const QString matrixString= getContent(m_pStreamReader, "RelativeMatrix");
00652         GLC_Matrix4x4 instanceMatrix= loadMatrix(matrixString);
00653 
00654 
00655         GLC_StructInstance* pStructInstance= new GLC_StructInstance(instName);
00656         pStructInstance->move(instanceMatrix);
00657 
00658         // Try to find extension
00659         GLC_Attributes userAttributes;
00660         while (endElementNotReached(m_pStreamReader, "Instance3D"))
00661         {
00662                 if (m_pStreamReader->isStartElement() && (m_pStreamReader->name() == "Instance3DExtensionType"))
00663                 {
00664                         while (endElementNotReached(m_pStreamReader, "Instance3DExtensionType"))
00665                         {
00666                                 if ((QXmlStreamReader::StartElement == m_pStreamReader->tokenType()) && (m_pStreamReader->name() == "Attribute"))
00667                                 {
00668                                         QString name= readAttribute("name", true);
00669                                         QString value= readAttribute("value", true);
00670                                         userAttributes.insert(name, value);
00671                                 }
00672                                 readNext();
00673                         }
00674                 }
00675                 readNext();
00676         }
00677         if (!userAttributes.isEmpty())
00678         {
00679                 pStructInstance->setAttributes(userAttributes);
00680         }
00681         if (instanceOf.contains(externRef))
00682         {
00683 
00684                 const QString extRefId= instanceOf.remove(externRef).remove("#1");
00685                 m_SetOfExtRef << extRefId;
00686                 m_InstanceOfExtRefHash.insert(pStructInstance, extRefId);
00687         }
00688         else if (instanceOf.contains(local))
00689         {
00690                 const unsigned int refId= instanceOf.remove(local).toUInt();
00691                 m_InstanceOf.insert(pStructInstance, refId);
00692         }
00693         else
00694         {
00695                 // 3dvia 3dxml
00696                 const unsigned int refId= instanceOf.toUInt();
00697                 m_InstanceOf.insert(pStructInstance, refId);
00698         }
00699 
00700         AssyLink assyLink;
00701         assyLink.m_ParentRefId= aggregatedById;
00702         assyLink.m_pChildInstance= pStructInstance;
00703         assyLink.m_InstanceId= instanceId;
00704         m_AssyLinkList.append(assyLink);
00705 }
00706 
00707 // Load a Reference representation
00708 void GLC_3dxmlToWorld::loadReferenceRep()
00709 {
00710         const QString local= "urn:3DXML:Representation:loc:";
00711         const QString externName= "urn:3DXML:";
00712 
00713         const unsigned int id= readAttribute("id", true).toUInt();
00714         //const QString refName(readAttribute("name", true));
00715         const QString format= readAttribute("format", false);
00716         QString associatedFile(readAttribute("associatedFile", true));
00717         if (format == "TESSELLATED")
00718         {
00719                 if (associatedFile.contains(local))
00720                 {
00721                         const QString repId= associatedFile.remove(local);
00722                         m_ReferenceRepHash.insert(id, repId);
00723                 }
00724                 else if (associatedFile.contains(externName))
00725                 {
00726                         const QString repId= associatedFile.remove(externName);
00727                         m_ReferenceRepHash.insert(id, repId);
00728                 }
00729         }
00730         else if (format == "UVR")
00731         {
00732                 QString message(QString("GLC_3dxmlToWorld::loadReferenceRep in file ") + m_CurrentFileName + " format " + format + " not supported");
00733                 GLC_FileFormatException fileFormatException(message, m_FileName, GLC_FileFormatException::FileNotSupported);
00734                 clear();
00735                 throw(fileFormatException);
00736 
00737         }
00738 }
00739 
00740 // Load a Instance representation
00741 void GLC_3dxmlToWorld::loadInstanceRep()
00742 {
00743         const QString local= "urn:3DXML:Reference:loc:";
00744 
00745         goToElement(m_pStreamReader, "IsAggregatedBy");
00746         const unsigned int aggregatedById= getContent(m_pStreamReader, "IsAggregatedBy").toUInt();
00747         QString instanceOf= getContent(m_pStreamReader, "IsInstanceOf");
00748 
00749         if (instanceOf.contains(local))
00750         {
00751                 // The 3dxml is a 3dxml rep from CATIA V5
00752                 const unsigned int refId= instanceOf.remove(local).toUInt();
00753 
00754                 RepLink repLink;
00755                 repLink.m_ReferenceId= aggregatedById;
00756                 repLink.m_RepId= refId;
00757 
00758                 m_LocalRepLinkList.append(repLink);
00759         }
00760         else
00761         {
00762                 // The 3dxml is a 3dvia 3dxml
00763                 const unsigned int refId= instanceOf.toUInt();
00764                 RepLink repLink;
00765                 repLink.m_ReferenceId= aggregatedById;
00766                 repLink.m_RepId= refId;
00767 
00768                 m_ExternRepLinkList.append(repLink);
00769         }
00770 }
00771 
00772 // Load External Ref
00773 void GLC_3dxmlToWorld::loadExternalRef3D()
00774 {
00775         if (m_SetOfExtRef.isEmpty()) return;
00776 
00777         const int size= m_SetOfExtRef.size();
00778         int previousQuantumValue= 0;
00779         int currentQuantumValue= 0;
00780         int currentFileIndex= 0;
00781         emit currentQuantum(currentQuantumValue);
00782 
00783         SetOfExtRef::iterator iExtRef= m_SetOfExtRef.begin();
00784         while (iExtRef != m_SetOfExtRef.constEnd())
00785         {
00786 
00787                 m_CurrentFileName= (*iExtRef);
00788 
00789                 if (! m_IsInArchive)
00790                 {
00791                         // Get the representation time stamp
00792                         m_CurrentDateTime= QFileInfo(QFileInfo(m_FileName).absolutePath() + QDir::separator() + QFileInfo(m_CurrentFileName).fileName()).lastModified();
00793                 }
00794 
00795                 if (!m_LoadStructureOnly && GLC_State::cacheIsUsed() && GLC_State::currentCacheManager().isUsable(m_CurrentDateTime, QFileInfo(m_FileName).baseName(), m_CurrentFileName))
00796                 {
00797                         GLC_CacheManager cacheManager= GLC_State::currentCacheManager();
00798 
00799                         GLC_BSRep binaryRep= cacheManager.binary3DRep(QFileInfo(m_FileName).baseName(), m_CurrentFileName);
00800                         GLC_3DRep* pRep= new GLC_3DRep(binaryRep.loadRep());
00801 
00802                         setRepresentationFileName(pRep);
00803 
00804                         GLC_StructReference* pCurrentRef= new GLC_StructReference(pRep);
00805                         pCurrentRef->setName(QFileInfo(m_CurrentFileName).baseName());
00806                         m_ExternalReferenceHash.insert(m_CurrentFileName, pCurrentRef);
00807 
00808                 }
00809                 else if (!m_LoadStructureOnly && setStreamReaderToFile(m_CurrentFileName))
00810                 {
00811 
00812                         // Avoid recursive call off createReferenceRep
00813                         const QString localFileName= m_CurrentFileName;
00814 
00815                         GLC_StructReference* pCurrentRef= createReferenceRep(QString(), NULL);
00816                         if (NULL != pCurrentRef)
00817                         {
00818                                 m_ExternalReferenceHash.insert(localFileName, pCurrentRef);
00819                         }
00820                         else
00821                         {
00822                                 QStringList stringList(m_FileName);
00823                                 stringList.append("GLC_3dxmlToWorld::loadExternalRef3D");
00824                                 stringList.append("Failed to load " + m_CurrentFileName);
00825                                 GLC_ErrorLog::addError(stringList);
00826                         }
00827                 }
00828                 else if(m_LoadStructureOnly)
00829                 {
00830                         GLC_3DRep* pRep= new GLC_3DRep();
00831                         if (m_IsInArchive)
00832                         {
00833                                 pRep->setFileName(glc::builtArchiveString(m_FileName, m_CurrentFileName));
00834                         }
00835                         else
00836                         {
00837                                 const QString repFileName= glc::builtFileString(m_FileName, m_CurrentFileName);
00838                                 pRep->setFileName(repFileName);
00839                                 m_SetOfAttachedFileName << glc::archiveEntryFileName(repFileName);
00840                         }
00841 
00842                         if (m_GetExternalRef3DName && setStreamReaderToFile(m_CurrentFileName))
00843                         {
00844                                 const QString localFileName= m_CurrentFileName;
00845                                 GLC_StructReference* pCurrentRef= createReferenceRep(QString(), pRep);
00846                                 m_ExternalReferenceHash.insert(localFileName, pCurrentRef);
00847                         }
00848                         else
00849                         {
00850                                 GLC_StructReference* pCurrentRef= new GLC_StructReference(pRep);
00851                                 pCurrentRef->setName(QFileInfo(m_CurrentFileName).baseName());
00852                                 m_ExternalReferenceHash.insert(m_CurrentFileName, pCurrentRef);
00853                         }
00854                 }
00855                 else
00856                 {
00857                         qDebug() << "GLC_3dxmlToWorld::loadExternalRef3D No File Found";
00858                 }
00859 
00860                 ++currentFileIndex;
00861                 // Progrees bar indicator
00862                 currentQuantumValue = static_cast<int>((static_cast<double>(currentFileIndex) / size) * 100);
00863                 if (currentQuantumValue > previousQuantumValue)
00864                 {
00865                         emit currentQuantum(currentQuantumValue);
00866                 }
00867                 previousQuantumValue= currentQuantumValue;
00868 
00869                 ++iExtRef;
00870         }
00871         m_SetOfExtRef.clear();
00872 
00873 }
00874 
00875 // Create Instance from 3DXML Rep
00876 GLC_StructReference* GLC_3dxmlToWorld::createReferenceRep(QString repId, GLC_3DRep* pRep)
00877 {
00878         //qDebug() << "GLC_3dxmlToWorld::createReferenceRep :" << repId;
00879 
00880         QString refName;
00881 
00882         if (repId.isEmpty())
00883         {
00884                 goToElement(m_pStreamReader, "ProductStructure");
00885                 checkForXmlError("Element ProductStructure not found");
00886 
00887                 goToElement(m_pStreamReader, "Reference3D");
00888                 checkForXmlError("Element Reference3D not found");
00889                 refName= readAttribute("name", true);
00890 
00891                 if (pRep != NULL)
00892                 {
00893                         pRep->setName(refName);
00894                         return new GLC_StructReference(pRep);
00895                 }
00896 
00897                 goToElement(m_pStreamReader, "ReferenceRep");
00898                 if (m_pStreamReader->atEnd())
00899                 {
00900                         QStringList stringList(m_FileName);
00901                         stringList.append("Element ReferenceRep not found in  file " + m_CurrentFileName);
00902                         GLC_ErrorLog::addError(stringList);
00903                         return NULL;
00904                 }
00905                 checkForXmlError("Element ReferenceRep contains error");
00906 
00907                 const QString format(readAttribute("format", true));
00908                 if (format != "TESSELLATED")
00909                 {
00910                         QString message(QString("GLC_3dxmlToWorld::addExtenalRef 3D rep format ") + format + " Not Supported");
00911                         GLC_FileFormatException fileFormatException(message, m_FileName, GLC_FileFormatException::FileNotSupported);
00912                         clear();
00913                         throw(fileFormatException);
00914                 }
00915 
00916                 repId= readAttribute("associatedFile");
00917 
00918                 const QString local= "urn:3DXML:Representation:loc:";
00919                 const QString ext= "urn:3DXML:Representation:ext:";
00920                 if (repId.contains(ext))
00921                 {
00922                         repId.remove(ext);
00923                         repId.resize(repId.size() - 2);
00924                         if (setStreamReaderToFile(repId))
00925                         {
00926                                 return createReferenceRep(QString(), NULL);
00927                         }
00928                         else
00929                         {
00930                                 return NULL;
00931                         }
00932                 }
00933                 else
00934                 {
00935                         repId.remove(local);
00936                 }
00937 
00938                 checkForXmlError("attribute associatedFile not found");
00939                 goToRepId(repId);
00940                 checkForXmlError("repId not found");
00941         }
00942 
00943         GLC_Mesh* pMesh= new GLC_Mesh();
00944         pMesh->setName(refName);
00945         GLC_3DRep currentMesh3DRep(pMesh);
00946         // Add time Stamp and file name to the 3D rep
00947 
00948         if (repId.contains("3DXML_Local_"))
00949         {
00950                 QString saveCurrentFileName= m_CurrentFileName;
00951                 m_CurrentFileName= repId;
00952                 setRepresentationFileName(&currentMesh3DRep);
00953                 m_CurrentFileName= saveCurrentFileName;
00954         }
00955         else
00956         {
00957                 setRepresentationFileName(&currentMesh3DRep);
00958         }
00959 
00960         currentMesh3DRep.setLastModified(m_CurrentDateTime);
00961 
00962         int numberOfMesh= 1;
00963         while (endElementNotReached(m_pStreamReader, "Representation"))
00964         {
00965                 gotToPolygonalRepType();
00966                 if (!endElementNotReached(m_pStreamReader, "Representation") || m_pStreamReader->atEnd() || m_pStreamReader->hasError())
00967                 {
00968                         if (m_pStreamReader->hasError() || m_pStreamReader->atEnd())
00969                         {
00970                                 QString message(QString("An element have not been found in file ") + m_FileName);
00971                                 GLC_FileFormatException fileFormatException(message, m_FileName, GLC_FileFormatException::WrongFileFormat);
00972                                 clear();
00973                                 throw(fileFormatException);
00974                         }
00975                         else
00976                         {
00977                                 pMesh->finish();
00978                                 currentMesh3DRep.clean();
00979                                 if (!currentMesh3DRep.isEmpty())
00980                                 {
00981                                         if (GLC_State::cacheIsUsed())
00982                                         {
00983                                                 GLC_CacheManager currentManager= GLC_State::currentCacheManager();
00984                                                 if (!currentManager.addToCache(QFileInfo(m_FileName).baseName(), currentMesh3DRep))
00985                                                 {
00986                                                         QStringList stringList("GLC_3dxmlToWorld::createReferenceRep");
00987                                                         stringList.append(m_FileName);
00988                                                         stringList.append("File " + currentMesh3DRep.fileName() + " Not Added to cache");
00989                                                         GLC_ErrorLog::addError(stringList);
00990                                                 }
00991                                         }
00992 
00993                                         return new GLC_StructReference(new GLC_3DRep(currentMesh3DRep));
00994                                 }
00995                                 else
00996                                 {
00997                                         return new GLC_StructReference("Empty Rep");
00998                                 }
00999                         }
01000                 }
01001                 if (numberOfMesh > 1)
01002                 {
01003                         pMesh->finish();
01004                         pMesh = new GLC_Mesh();
01005                         pMesh->setName(refName);
01006                         currentMesh3DRep.addGeom(pMesh);
01007                 }
01008 
01009                 loadRep(pMesh);
01010 
01011                 ++numberOfMesh;
01012         }
01013 
01014         pMesh->finish();
01015 
01016         currentMesh3DRep.clean();
01017         if (!currentMesh3DRep.isEmpty())
01018         {
01019                 if (GLC_State::cacheIsUsed())
01020                 {
01021                         GLC_CacheManager currentManager= GLC_State::currentCacheManager();
01022                         currentManager.addToCache(QFileInfo(m_FileName).baseName(), currentMesh3DRep);
01023                 }
01024 
01025                 return new GLC_StructReference(new GLC_3DRep(currentMesh3DRep));
01026         }
01027         else
01028         {
01029                 return new GLC_StructReference("Empty Rep");
01030         }
01031 }
01032 
01033 // Load Matrix
01034 GLC_Matrix4x4 GLC_3dxmlToWorld::loadMatrix(const QString& stringMatrix)
01035 {
01036 
01037         QStringList stringValues(stringMatrix.split(" "));
01038 
01039         if (stringValues.size() != 12) return GLC_Matrix4x4();
01040 
01041         QVector<double> values(16);
01042         // Rotation
01043         values[0]= stringValues[0].toDouble();
01044         values[1]= stringValues[1].toDouble();
01045         values[2]= stringValues[2].toDouble();
01046         values[3]= 0.0;
01047         values[4]= stringValues[3].toDouble();
01048         values[5]= stringValues[4].toDouble();
01049         values[6]= stringValues[5].toDouble();
01050         values[7]= 0.0;
01051         values[8]= stringValues[6].toDouble();
01052         values[9]= stringValues[7].toDouble();
01053         values[10]= stringValues[8].toDouble();
01054         values[11]= 0.0;
01055         // Translation
01056         values[12]= stringValues[9].toDouble();
01057         values[13]= stringValues[10].toDouble();
01058         values[14]= stringValues[11].toDouble();
01059         values[15]= 1.0;
01060 
01061         GLC_Matrix4x4 resultMatrix(values.data());
01062         resultMatrix.optimise();
01063 
01064         return resultMatrix;
01065 }
01066 
01067 // Create the unfolded  tree
01068 void GLC_3dxmlToWorld::createUnfoldedTree()
01069 {
01070         //qDebug() << "createUnfoldedTree";
01071         // Run throw all link in the list of link
01072 
01073         qSort(m_AssyLinkList.begin(), m_AssyLinkList.end());
01074         AssyLinkList::iterator iLink= m_AssyLinkList.begin();
01075         while(iLink != m_AssyLinkList.constEnd())
01076         {
01077                 GLC_StructInstance* pChildInstance= (*iLink).m_pChildInstance;
01078                 if (pChildInstance->structReference() == NULL)
01079                 {
01080                         QStringList stringList(m_FileName);
01081                         stringList.append("Instance without reference");
01082                         GLC_ErrorLog::addError(stringList);
01083                         pChildInstance->setReference(new GLC_StructReference("Part"));
01084                 }
01085                 Q_ASSERT(m_ReferenceHash.contains((*iLink).m_ParentRefId));
01086                 GLC_StructReference* pRef= m_ReferenceHash.value((*iLink).m_ParentRefId);
01087                 // Attach pInstance at all Occurence of pRef
01088                 QList<GLC_StructInstance*> instanceList= pRef->listOfStructInstances();
01089                 const int instanceNumber= instanceList.size();
01090                 for (int i= 0; i < instanceNumber; ++i)
01091                 {
01092                         if (instanceList.at(i)->hasStructOccurence())
01093                         {
01094                                 QList<GLC_StructOccurence*> occurenceList= instanceList.at(i)->listOfStructOccurences();
01095                                 const int occurenceNumber= occurenceList.size();
01096                                 for (int j= 0; j < occurenceNumber; ++j)
01097                                 {
01098                                         if (pChildInstance->hasStructOccurence() && pChildInstance->firstOccurenceHandle()->isOrphan())
01099                                         {
01100                                                 Q_ASSERT(pChildInstance->listOfStructOccurences().size() == 1);
01101                                                 occurenceList.at(j)->addChild(pChildInstance->firstOccurenceHandle());
01102                                         }
01103                                         else
01104                                         {
01105                                                 occurenceList.at(j)->addChild(pChildInstance);
01106                                         }
01107                                 }
01108                         }
01109                         else
01110                         {
01111                                 GLC_StructOccurence* pOccurence= new GLC_StructOccurence(instanceList.at(i), m_pWorld->worldHandle());
01112                                 if (pChildInstance->hasStructOccurence() && pChildInstance->firstOccurenceHandle()->isOrphan())
01113                                 {
01114                                         Q_ASSERT(pChildInstance->listOfStructOccurences().size() == 1);
01115                                         pOccurence->addChild(pChildInstance->firstOccurenceHandle());
01116                                 }
01117                                 else
01118                                 {
01119                                         pOccurence->addChild(pChildInstance);
01120                                 }
01121                         }
01122                 }
01123 
01124                 ++iLink;
01125         }
01126 
01127         // Check the assembly structure occurence
01128         ReferenceHash::const_iterator iRef= m_ReferenceHash.constBegin();
01129         while (m_ReferenceHash.constEnd() != iRef)
01130         {
01131                 if (iRef.key() != 1)
01132                 {
01133                         GLC_StructReference* pReference= iRef.value();
01134                         if (!pReference->hasStructInstance())
01135                         {
01136                                 QStringList stringList(m_FileName);
01137                                 stringList.append("GLC_3dxmlToWorld::createUnfoldedTree() : Orphan reference: " + pReference->name());
01138                                 GLC_ErrorLog::addError(stringList);
01139                                 delete pReference;
01140                         }
01141                         else
01142                         {
01143                                 QList<GLC_StructInstance*> instances= pReference->listOfStructInstances();
01144                                 const int size= instances.size();
01145                                 for (int i= 0; i < size; ++i)
01146                                 {
01147                                         GLC_StructInstance* pInstance= instances.at(i);
01148                                         if (!pInstance->hasStructOccurence())
01149                                         {
01150                                                 QStringList stringList(m_FileName);
01151                                                 stringList.append("GLC_3dxmlToWorld::createUnfoldedTree() : Orphan Instance: " + pInstance->name());
01152                                                 GLC_ErrorLog::addError(stringList);
01153                                                 delete pInstance;
01154                                         }
01155                                         else
01156                                         {
01157                                                 QList<GLC_StructOccurence*> occurences= pInstance->listOfStructOccurences();
01158                                                 const int occurencesSize= occurences.size();
01159                                                 for (int j= 0; j < occurencesSize; ++j)
01160                                                 {
01161                                                         GLC_StructOccurence* pOcc= occurences.at(j);
01162                                                         if (pOcc->isOrphan())
01163                                                         {
01164                                                                 QStringList stringList(m_FileName);
01165                                                                 stringList.append("GLC_3dxmlToWorld::createUnfoldedTree(): Orphan occurence: " + pOcc->name());
01166                                                                 GLC_ErrorLog::addError(stringList);
01167                                                                 delete pOcc;
01168                                                         }
01169                                                 }
01170                                         }
01171                                 }
01172                         }
01173                 }
01174                 ++iRef;
01175         }
01176         m_ReferenceHash.clear();
01177 
01178         // Update position
01179         m_pWorld->rootOccurence()->updateChildrenAbsoluteMatrix();
01180 
01181 }
01182 // Check for XML error
01183 void GLC_3dxmlToWorld::checkForXmlError(const QString& info)
01184 {
01185         if (m_pStreamReader->atEnd() || m_pStreamReader->hasError())
01186         {
01187                 QString message(QString("An element have not been found in file ") + m_CurrentFileName);
01188 
01189                 QStringList stringList(info + " " + m_pStreamReader->errorString());
01190                 stringList.append(message);
01191                 GLC_ErrorLog::addError(stringList);
01192 
01193                 GLC_FileFormatException fileFormatException(message, m_FileName, GLC_FileFormatException::WrongFileFormat);
01194                 clear();
01195                 throw(fileFormatException);
01196         }
01197 }
01198 
01199 // Load a face
01200 void GLC_3dxmlToWorld::loadFace(GLC_Mesh* pMesh, const int lod, double accuracy)
01201 {
01202         //qDebug() << "GLC_3dxmlToWorld::loadFace" << m_pStreamReader->name();
01203         // List of index declaration
01204         QString triangles= readAttribute("triangles", false).trimmed();
01205         QString strips= readAttribute("strips", false).trimmed();
01206         QString fans= readAttribute("fans", false).trimmed();
01207 
01208         if (triangles.isEmpty() && strips.isEmpty() && fans.isEmpty())
01209         {
01210                 QStringList stringList(m_CurrentFileName);
01211                 stringList.append("GLC_3dxmlToWorld::loadFace : Empty face found");
01212                 GLC_ErrorLog::addError(stringList);
01213                 return;
01214         }
01215 
01216         GLC_Material* pCurrentMaterial= NULL;
01217 
01218         while(endElementNotReached(m_pStreamReader, "Face"))
01219         {
01220                 if ((QXmlStreamReader::StartElement == m_pStreamReader->tokenType()) && (m_pStreamReader->name() == "SurfaceAttributes"))
01221                 {
01222                         pCurrentMaterial= loadSurfaceAttributes();
01223                 }
01224                 readNext();
01225         }
01226         if (NULL == pCurrentMaterial)
01227         {
01228                 pCurrentMaterial= m_pCurrentMaterial;
01229         }
01230 
01231         // Trying to find triangles
01232         if (!triangles.isEmpty())
01233         {
01234                 // For 3dvia mesh
01235                 if (triangles.contains(','))
01236                 {
01237                         triangles.remove(',');
01238                 }
01239                 QTextStream trianglesStream(&triangles);
01240                 IndexList trianglesIndex;
01241                 QString buff;
01242                 while ((!trianglesStream.atEnd()))
01243                 {
01244                         trianglesStream >> buff;
01245                         trianglesIndex.append(buff.toUInt());
01246                 }
01247                 pMesh->addTriangles(pCurrentMaterial, trianglesIndex, lod, accuracy);
01248         }
01249         // Trying to find trips
01250         if (!strips.isEmpty())
01251         {
01252 
01253                 QStringList stripsList(strips.split(","));
01254                 const int size= stripsList.size();
01255                 for (int i= 0; i < size; ++i)
01256                 {
01257                         //qDebug() << "Strip " << stripsList.at(i);
01258                         QTextStream stripsStream(&stripsList[i]);
01259                         IndexList stripsIndex;
01260                         QString buff;
01261                         while ((!stripsStream.atEnd()))
01262                         {
01263                                 stripsStream >> buff;
01264                                 stripsIndex.append(buff.toUInt());
01265                         }
01266                         pMesh->addTrianglesStrip(pCurrentMaterial, stripsIndex, lod, accuracy);
01267                 }
01268         }
01269         // Trying to find fans
01270         if (!fans.isEmpty())
01271         {
01272                 QStringList fansList(fans.split(","));
01273                 const int size= fansList.size();
01274                 for (int i= 0; i < size; ++i)
01275                 {
01276                         QTextStream fansStream(&fansList[i]);
01277                         IndexList fansIndex;
01278                         QString buff;
01279                         while ((!fansStream.atEnd()))
01280                         {
01281                                 fansStream >> buff;
01282                                 fansIndex.append(buff.toUInt());
01283                         }
01284                         pMesh->addTrianglesFan(pCurrentMaterial, fansIndex, lod, accuracy);
01285                 }
01286         }
01287 
01288 }
01289 
01290 // Load polyline
01291 void GLC_3dxmlToWorld::loadPolyline(GLC_Mesh* pMesh)
01292 {
01293         QString data= readAttribute("vertices", true);
01294 
01295         data.replace(',', ' ');
01296         QTextStream dataStream(&data);
01297         QList<GLfloat> values;
01298         QString buff;
01299         while ((!dataStream.atEnd()))
01300         {
01301                 dataStream >> buff;
01302                 values.append(buff.toFloat());
01303         }
01304         if ((values.size() % 3) == 0)
01305         {
01306                 pMesh->addVerticeGroup(values.toVector());
01307         }
01308         else
01309         {
01310                 QString message(QString("polyline buffer is not a multiple of 3 ") + m_CurrentFileName);
01311 
01312                 QStringList stringList(message);
01313                 GLC_ErrorLog::addError(stringList);
01314 
01315                 GLC_FileFormatException fileFormatException(message, m_FileName, GLC_FileFormatException::WrongFileFormat);
01316                 clear();
01317                 throw(fileFormatException);
01318         }
01319 
01320 
01321 }
01322 
01323 // Clear material hash
01324 void GLC_3dxmlToWorld::clearMaterialHash()
01325 {
01326         MaterialHash::iterator iMaterial= m_MaterialHash.begin();
01327         while (m_MaterialHash.constEnd() != iMaterial)
01328         {
01329                 if (iMaterial.value()->isUnused())
01330                 {
01331                         delete iMaterial.value();
01332                 }
01333                 ++iMaterial;
01334         }
01335 
01336         m_MaterialHash.clear();
01337 }
01338 
01339 GLC_Material* GLC_3dxmlToWorld::loadSurfaceAttributes()
01340 {
01341         GLC_Material* pMaterial= NULL;
01342         while(endElementNotReached(m_pStreamReader, "SurfaceAttributes"))
01343         {
01344                 if ((QXmlStreamReader::StartElement == m_pStreamReader->tokenType()) && (m_pStreamReader->name() == "Color"))
01345                 {
01346                         pMaterial= getMaterial();
01347                 }
01348                 else if ((QXmlStreamReader::StartElement == m_pStreamReader->tokenType()) && (m_pStreamReader->name() == "MaterialApplication"))
01349                 {
01350                         while (endElementNotReached(m_pStreamReader, "MaterialApplication"))
01351                         {
01352                                 readNext();
01353                                 if ((QXmlStreamReader::StartElement == m_pStreamReader->tokenType()) && (m_pStreamReader->name() == "MaterialId"))
01354                                 {
01355                                         checkForXmlError("Material ID not found");
01356                                         QString materialId= readAttribute("id", true).remove("urn:3DXML:CATMaterialRef.3dxml#");
01357                                         pMaterial= m_MaterialHash.value(materialId);
01358                                 }
01359                         }
01360 
01361                 }
01362                 readNext();
01363         }
01364 
01365         return pMaterial;
01366 }
01367 
01368 GLC_Material* GLC_3dxmlToWorld::getMaterial()
01369 {
01370         GLC_Material* pMaterial= NULL;
01371         const QString red(readAttribute("red", true));
01372         const QString green(readAttribute("green", true));
01373         const QString blue(readAttribute("blue", true));
01374         const QString alpha(readAttribute("alpha", true));
01375 
01376         qreal redReal= red.toDouble();
01377         qreal greenReal= green.toDouble();
01378         qreal blueReal= blue.toDouble();
01379         qreal alphaReal= alpha.toDouble();
01380         QColor diffuse;
01381         diffuse.setRgbF(redReal, greenReal, blueReal);
01382         pMaterial= new GLC_Material(diffuse);
01383         pMaterial->setName("Material_" + QString::number(m_MaterialHash.size()));
01384         pMaterial->setAmbientColor(QColor(50, 50, 50));
01385         pMaterial->setSpecularColor(QColor(70, 70, 70));
01386         pMaterial->setShininess(35.0);
01387         pMaterial->setOpacity(alphaReal);
01388 
01389         const QString matKey= QString::number(pMaterial->hashCode());
01390         if (m_MaterialHash.contains(matKey))
01391         {
01392                 delete pMaterial;
01393                 pMaterial= m_MaterialHash.value(matKey);
01394         }
01395         else
01396         {
01397                 m_MaterialHash.insert(matKey, pMaterial);
01398         }
01399 
01400         return pMaterial;
01401 }
01402 
01403 // Set the stream reader to the specified file
01404 bool GLC_3dxmlToWorld::setStreamReaderToFile(QString fileName, bool test)
01405 {
01406         m_CurrentFileName= fileName;
01407         if (m_IsInArchive)
01408         {
01409                 QMutexLocker locker(&m_ZipMutex);
01410                 m_ByteArrayList.clear();
01411                 // Create QuaZip File
01412                 QuaZipFile* p3dxmlFile= new QuaZipFile(m_p3dxmlArchive);
01413 
01414                 // Get the file of the 3dxml
01415                 if (!m_p3dxmlArchive->setCurrentFile(fileName, QuaZip::csInsensitive))
01416                 {
01417                         if (!test)
01418                         {
01419                                 QString message(QString("GLC_3dxmlToWorld::setStreamReaderToFile File ") + m_FileName + " doesn't contains " + fileName);
01420                                 GLC_FileFormatException fileFormatException(message, m_FileName, GLC_FileFormatException::WrongFileFormat);
01421                                 clear();
01422                                 throw(fileFormatException);
01423                         }
01424                         else return false;
01425                 }
01426 
01427                 // Open the file of the 3dxml
01428                 if(!p3dxmlFile->open(QIODevice::ReadOnly))
01429             {
01430                         QString message(QString("GLC_3dxmlToWorld::setStreamReaderToFile Unable to Open ") + fileName);
01431                         GLC_FileFormatException fileFormatException(message, fileName, GLC_FileFormatException::FileNotSupported);
01432                         clear();
01433                         throw(fileFormatException);
01434             }
01435 
01436                 // Test if the file is a binary
01437                 checkFileValidity(p3dxmlFile);
01438                 {
01439                         delete p3dxmlFile;
01440                         p3dxmlFile= new QuaZipFile(m_p3dxmlArchive);
01441                         m_p3dxmlArchive->setCurrentFile(fileName, QuaZip::csInsensitive);
01442                         p3dxmlFile->open(QIODevice::ReadOnly);
01443                 }
01444 
01445                 // Set the stream reader
01446                 delete m_pStreamReader;
01447 
01448                 QByteArray currentByteArray;
01449                 while (!currentByteArray.isEmpty() || m_ByteArrayList.isEmpty())
01450                 {
01451                         currentByteArray= p3dxmlFile->read(chunckSize);
01452                         m_ByteArrayList.append(currentByteArray);
01453                 }
01454                 m_pStreamReader= new QXmlStreamReader(m_ByteArrayList.takeFirst());
01455                 delete p3dxmlFile;
01456         }
01457         else
01458         {
01459                 delete m_pCurrentFile;
01460                 // Create the file to load
01461                 if (fileName != m_FileName && !m_FileName.isEmpty())
01462                 {
01463                         fileName= QFileInfo(m_FileName).absolutePath() + QDir::separator() + fileName;
01464                 }
01465                 // Get the 3DXML time stamp
01466                 m_CurrentDateTime= QFileInfo(fileName).lastModified();
01467 
01468                 m_pCurrentFile= new QFile(fileName);
01469                 if (!m_pCurrentFile->open(QIODevice::ReadOnly))
01470                 {
01471                         QString message(QString("GLC_3dxmlToWorld::setStreamReaderToFile File ") + fileName + QString(" not found"));
01472                         QStringList stringList(message);
01473                         GLC_ErrorLog::addError(stringList);
01474                         return false;
01475                 }
01476                 else if (m_FileName != fileName)
01477                 {
01478                         m_SetOfAttachedFileName << fileName;
01479                 }
01480 
01481                 // Test if the file is a binary
01482                 checkFileValidity(m_pCurrentFile);
01483 
01484                 // Set the stream reader
01485                 delete m_pStreamReader;
01486                 m_pStreamReader= new QXmlStreamReader(m_pCurrentFile);
01487         }
01488         return true;
01489 }
01490 
01491 // Load the local representation
01492 void GLC_3dxmlToWorld::loadLocalRepresentations()
01493 {
01494         qDebug() << "GLC_3dxmlToWorld::loadLocalRepresentations()";
01495 
01496         if (m_LocalRepLinkList.isEmpty()) return;
01497         QHash<const QString, GLC_3DRep> repHash;
01498 
01499         // Load all local ref
01500         goToElement(m_pStreamReader, "GeometricRepresentationSet");
01501         while (endElementNotReached(m_pStreamReader, "GeometricRepresentationSet"))
01502         {
01503                 if (m_pStreamReader->name() == "Representation")
01504                 {
01505                         QString id= readAttribute("id", true);
01506                         GLC_StructReference* pRef= createReferenceRep("3DXML_Local_" + id, NULL);
01507                         if (pRef->hasRepresentation())
01508                         {
01509                                 GLC_3DRep representation(*(dynamic_cast<GLC_3DRep*>(pRef->representationHandle())));
01510                                 repHash.insert(id, representation);
01511                         }
01512                         delete pRef;
01513                 }
01514                 readNext();
01515         }
01516         //qDebug() << "Local rep loaded";
01517 
01518         // Attach the ref to the structure reference
01519         RepLinkList::iterator iLocalRep= m_LocalRepLinkList.begin();
01520         while (iLocalRep != m_LocalRepLinkList.constEnd())
01521         {
01522                 unsigned int referenceId= (*iLocalRep).m_ReferenceId;
01523                 unsigned int refId= (*iLocalRep).m_RepId;
01524 
01525                 GLC_StructReference* pReference= m_ReferenceHash.value(referenceId);
01526                 const QString representationID= m_ReferenceRepHash.value(refId);
01527                 pReference->setRepresentation(repHash.value(representationID));
01528                 pReference->setRepresentationName(pReference->name());
01529 
01530                 ++iLocalRep;
01531         }
01532 }
01533 
01534 void GLC_3dxmlToWorld::loadDefaultView()
01535 {
01536         if (m_pStreamReader->atEnd() || m_pStreamReader->hasError())
01537         {
01538                 QString message(QString("GLC_3dxmlToWorld::loadGraphicsProperties Element DefaultView Not found in ") + m_FileName);
01539                 GLC_FileFormatException fileFormatException(message, m_FileName, GLC_FileFormatException::WrongFileFormat);
01540                 clear();
01541                 throw(fileFormatException);
01542         }
01543 
01544         // Load the graphics properties
01545         while(endElementNotReached(m_pStreamReader, "DefaultView"))
01546         {
01547                 if ((QXmlStreamReader::StartElement == m_pStreamReader->tokenType()) && (m_pStreamReader->name() == "DefaultViewProperty"))
01548                 {
01549                         if (m_IsVersion3) loadV3DefaultViewProperty();
01550                         else loadV4DefaultViewProperty();
01551                 }
01552 
01553                 readNext();
01554         }
01555 
01556         // Check if an error Occur
01557         if (m_pStreamReader->hasError())
01558         {
01559                 QString message(QString("GLC_3dxmlToWorld::loadGraphicsProperties An error occur in ") + m_FileName);
01560                 GLC_FileFormatException fileFormatException(message, m_FileName, GLC_FileFormatException::WrongFileFormat);
01561                 clear();
01562                 throw(fileFormatException);
01563         }
01564 
01565 }
01566 
01567 void GLC_3dxmlToWorld::loadV3DefaultViewProperty()
01568 {
01569         goToElement(m_pStreamReader, "OccurenceId");
01570         unsigned int occurenceId= getContent(m_pStreamReader, "OccurenceId").toUInt();
01571 
01572         // Load the graphics properties
01573         while(endElementNotReached(m_pStreamReader, "DefaultViewProperty"))
01574         {
01575                 if ((QXmlStreamReader::StartElement == m_pStreamReader->tokenType()) && (m_pStreamReader->name() == "GraphicProperties"))
01576                 {
01577                         while(endElementNotReached(m_pStreamReader, "GraphicProperties"))
01578                         {
01579                                 if ((QXmlStreamReader::StartElement == m_pStreamReader->tokenType()) && (m_pStreamReader->name() == "GeneralAttributes"))
01580                                 {
01581                                         QString visibleString= readAttribute("visible", true);
01582                                         if (visibleString != "true")
01583                                         {
01584                                                 if (!m_V3OccurenceAttribHash.contains(occurenceId))
01585                                                 {
01586                                                         V3OccurenceAttrib* pOccurenceAttrib= new V3OccurenceAttrib();
01587                                                         pOccurenceAttrib->m_IsVisible= false;
01588                                                         m_V3OccurenceAttribHash.insert(occurenceId, pOccurenceAttrib);
01589                                                 }
01590                                                 else m_V3OccurenceAttribHash.value(occurenceId)->m_IsVisible= false;
01591                                         }
01592                                 }
01593                                 else if ((QXmlStreamReader::StartElement == m_pStreamReader->tokenType()) && (m_pStreamReader->name() == "SurfaceAttributes"))
01594                                 {
01595                                         goToElement(m_pStreamReader, "Color");
01596                                         const double red= readAttribute("red", true).toDouble();
01597                                         const double green= readAttribute("green", true).toDouble();
01598                                         const double blue= readAttribute("blue", true).toDouble();
01599                                         double alpha= 1.0;
01600                                         QString alphaString= readAttribute("alpha", false);
01601                                         if (!alphaString.isEmpty()) alpha= alphaString.toDouble();
01602 
01603                                         GLC_RenderProperties* pRenderProperties= new GLC_RenderProperties();
01604                                         if (red != -1.0f)
01605                                         {
01606                                                 QColor diffuseColor;
01607                                                 diffuseColor.setRgbF(red, green, blue, alpha);
01608                                                 GLC_Material* pMaterial= new GLC_Material();
01609                                                 pMaterial->setDiffuseColor(diffuseColor);
01610                                                 pRenderProperties->setOverwriteMaterial(pMaterial);
01611                                                 pRenderProperties->setRenderingMode(glc::OverwriteMaterial);
01612                                         }
01613                                         else if (alpha < 1.0f)
01614                                         {
01615                                                 pRenderProperties->setOverwriteTransparency(static_cast<float>(alpha));
01616                                                 pRenderProperties->setRenderingMode(glc::OverwriteTransparency);
01617                                         }
01618                                         if (!m_V3OccurenceAttribHash.contains(occurenceId))
01619                                         {
01620                                                 V3OccurenceAttrib* pOccurenceAttrib= new V3OccurenceAttrib();
01621                                                 pOccurenceAttrib->m_pRenderProperties= pRenderProperties;
01622                                                 m_V3OccurenceAttribHash.insert(occurenceId, pOccurenceAttrib);
01623                                         }
01624                                         else m_V3OccurenceAttribHash.value(occurenceId)->m_pRenderProperties= pRenderProperties;
01625                                 }
01626 
01627                                 readNext();
01628                         }
01629 
01630                 }
01631 
01632                 readNext();
01633         }
01634 
01635         // Check if an error Occur
01636         if (m_pStreamReader->hasError())
01637         {
01638                 QString message(QString("GLC_3dxmlToWorld::loadDefaultViewProperty An error occur in ") + m_FileName);
01639                 GLC_FileFormatException fileFormatException(message, m_FileName, GLC_FileFormatException::WrongFileFormat);
01640                 clear();
01641                 throw(fileFormatException);
01642         }
01643 
01644 }
01645 
01646 void GLC_3dxmlToWorld::loadV4DefaultViewProperty()
01647 {
01648         V4OccurenceAttrib* pV4OccurenceAttrib= new V4OccurenceAttrib();
01649 
01650         while(endElementNotReached(m_pStreamReader, "DefaultViewProperty"))
01651         {
01652                 if ((QXmlStreamReader::StartElement == m_pStreamReader->tokenType()) && (m_pStreamReader->name() == "OccurenceId"))
01653                 {
01654                         pV4OccurenceAttrib->m_Path= loadOccurencePath();
01655                 }
01656                 else if ((QXmlStreamReader::StartElement == m_pStreamReader->tokenType()) && (m_pStreamReader->name() == "RelativePosition"))
01657                 {
01658                         const QString matrix= getContent(m_pStreamReader, "RelativePosition");
01659                         pV4OccurenceAttrib->m_pMatrix= new GLC_Matrix4x4(loadMatrix(matrix));
01660                 }
01661                 else if ((QXmlStreamReader::StartElement == m_pStreamReader->tokenType()) && (m_pStreamReader->name() == "GraphicProperties"))
01662                 {
01663                         loadGraphicProperties(pV4OccurenceAttrib);
01664                 }
01665                 readNext();
01666         }
01667 
01668         if(!pV4OccurenceAttrib->m_Path.isEmpty())
01669         {
01670                 m_V4OccurenceAttribList.append(pV4OccurenceAttrib);
01671         }
01672         else
01673         {
01674                 delete pV4OccurenceAttrib;
01675         }
01676 
01677         // Check if an error Occur
01678         if (m_pStreamReader->hasError())
01679         {
01680                 QString message(QString("GLC_3dxmlToWorld::loadV4DefaultViewProperty An error occur in ") + m_FileName);
01681                 GLC_FileFormatException fileFormatException(message, m_FileName, GLC_FileFormatException::WrongFileFormat);
01682                 clear();
01683                 throw(fileFormatException);
01684         }
01685 
01686 }
01687 
01688 QList<unsigned int> GLC_3dxmlToWorld::loadOccurencePath()
01689 {
01690         QList<unsigned int> path;
01691         while(endElementNotReached(m_pStreamReader, "OccurenceId"))
01692         {
01693                 if ((QXmlStreamReader::StartElement == m_pStreamReader->tokenType()) && (m_pStreamReader->name() == "id"))
01694                 {
01695                         QString instanceId= getContent(m_pStreamReader, "id");
01696                         instanceId= instanceId.right(instanceId.length() - 1 - instanceId.indexOf('#'));
01697                         path.append(instanceId.toUInt());
01698                 }
01699                 readNext();
01700         }
01701 
01702         // Check if an error Occur
01703         if (m_pStreamReader->hasError() || path.contains(0))
01704         {
01705                 QString message(QString("GLC_3dxmlToWorld::loadOccurencePath An error occur in ") + m_FileName);
01706                 GLC_FileFormatException fileFormatException(message, m_FileName, GLC_FileFormatException::WrongFileFormat);
01707                 clear();
01708                 throw(fileFormatException);
01709         }
01710 
01711         return path;
01712 }
01713 
01714 void GLC_3dxmlToWorld::loadGraphicProperties(V4OccurenceAttrib* pAttrib)
01715 {
01716         while(endElementNotReached(m_pStreamReader, "GraphicProperties"))
01717         {
01718                 if ((QXmlStreamReader::StartElement == m_pStreamReader->tokenType()) && (m_pStreamReader->name() == "GeneralAttributes"))
01719                 {
01720                         QString visibleString= readAttribute("visible", true);
01721                         if (visibleString != "true")
01722                         {
01723                                 pAttrib->m_IsVisible= false;
01724                         }
01725                 }
01726                 else if ((QXmlStreamReader::StartElement == m_pStreamReader->tokenType()) && (m_pStreamReader->name() == "SurfaceAttributes"))
01727                 {
01728                         goToElement(m_pStreamReader, "Color");
01729                         const double red= readAttribute("red", true).toDouble();
01730                         const double green= readAttribute("green", true).toDouble();
01731                         const double blue= readAttribute("blue", true).toDouble();
01732                         double alpha= 1.0;
01733                         QString alphaString= readAttribute("alpha", false);
01734                         if (!alphaString.isEmpty()) alpha= alphaString.toDouble();
01735 
01736                         GLC_RenderProperties* pRenderProperties= new GLC_RenderProperties();
01737                         if (red != -1.0f)
01738                         {
01739                                 QColor diffuseColor;
01740                                 diffuseColor.setRgbF(red, green, blue, alpha);
01741                                 GLC_Material* pMaterial= new GLC_Material();
01742                                 pMaterial->setDiffuseColor(diffuseColor);
01743                                 pRenderProperties->setOverwriteMaterial(pMaterial);
01744                                 pRenderProperties->setRenderingMode(glc::OverwriteMaterial);
01745                         }
01746                         else if (alpha < 1.0f)
01747                         {
01748                                 pRenderProperties->setOverwriteTransparency(static_cast<float>(alpha));
01749                                 pRenderProperties->setRenderingMode(glc::OverwriteTransparency);
01750                         }
01751 
01752                         pAttrib->m_pRenderProperties= pRenderProperties;
01753                 }
01754 
01755                 readNext();
01756         }
01757 }
01758 
01759 // Load the extern representation
01760 void GLC_3dxmlToWorld::loadExternRepresentations()
01761 {
01762 
01763         if (m_ExternRepLinkList.isEmpty()) return;
01764 
01765         QHash<const unsigned int, GLC_3DRep> repHash;
01766 
01767         // Progress bar variables
01768         const int size= m_ReferenceRepHash.size();
01769         int previousQuantumValue= 0;
01770         int currentQuantumValue= 0;
01771         int currentFileIndex= 0;
01772         emit currentQuantum(currentQuantumValue);
01773 
01774         // Load all external rep
01775         ReferenceRepHash::iterator iRefRep= m_ReferenceRepHash.begin();
01776         while (iRefRep != m_ReferenceRepHash.constEnd())
01777         {
01778                 m_CurrentFileName= iRefRep.value();
01779                 const unsigned int id= iRefRep.key();
01780 
01781                 if (!m_IsInArchive)
01782                 {
01783                         // Get the 3DXML time stamp
01784                         m_CurrentDateTime= QFileInfo(QFileInfo(m_FileName).absolutePath() + QDir::separator() + QFileInfo(m_CurrentFileName).fileName()).lastModified();
01785                 }
01786 
01787 
01788                 if (!m_LoadStructureOnly && setStreamReaderToFile(m_CurrentFileName))
01789                 {
01790                         GLC_3DRep representation;
01791                         if (GLC_State::cacheIsUsed() && GLC_State::currentCacheManager().isUsable(m_CurrentDateTime, QFileInfo(m_FileName).baseName(), m_CurrentFileName))
01792                         {
01793                                 GLC_CacheManager cacheManager= GLC_State::currentCacheManager();
01794                                 GLC_BSRep binaryRep= cacheManager.binary3DRep(QFileInfo(m_FileName).baseName(), m_CurrentFileName);
01795                                 representation= binaryRep.loadRep();
01796                                 setRepresentationFileName(&representation);
01797                         }
01798                         else
01799                         {
01800                                 representation= loadCurrentExtRep();
01801                                 representation.clean();
01802                         }
01803                         if (!representation.isEmpty())
01804                         {
01805                                 repHash.insert(id, representation);
01806                         }
01807                 }
01808                 else if (m_LoadStructureOnly)
01809                 {
01810                         GLC_3DRep representation;
01811                         if (m_IsInArchive)
01812                         {
01813                                 representation.setFileName(glc::builtArchiveString(m_FileName, m_CurrentFileName));
01814                         }
01815                         else
01816                         {
01817                                 const QString repFileName= glc::builtFileString(m_FileName, m_CurrentFileName);
01818                                 representation.setFileName(repFileName);
01819                                 m_SetOfAttachedFileName << glc::archiveEntryFileName(repFileName);
01820                         }
01821 
01822                         repHash.insert(id, representation);
01823                 }
01824 
01825                 // Progrees bar indicator
01826                 ++currentFileIndex;
01827                 currentQuantumValue = static_cast<int>((static_cast<double>(currentFileIndex) / size) * 100);
01828                 if (currentQuantumValue > previousQuantumValue)
01829                 {
01830                         emit currentQuantum(currentQuantumValue);
01831                 }
01832                 previousQuantumValue= currentQuantumValue;
01833 
01834                 ++iRefRep;
01835         }
01836 
01837         // Attach the ref to the structure reference
01838         RepLinkList::iterator iExtRep= m_ExternRepLinkList.begin();
01839         while (iExtRep != m_ExternRepLinkList.constEnd())
01840         {
01841                 unsigned int referenceId= (*iExtRep).m_ReferenceId;
01842                 unsigned int refId= (*iExtRep).m_RepId;
01843 
01844                 GLC_StructReference* pReference= m_ReferenceHash.value(referenceId);
01845                 if (pReference->hasRepresentation())
01846                 {
01847                         GLC_3DRep* pRep= dynamic_cast<GLC_3DRep*>(pReference->representationHandle());
01848                         if (NULL != pRep)
01849                         {
01850                                 GLC_3DRep newRep(repHash.value(refId));
01851                                 pRep->take(&newRep);
01852                         }
01853                 }
01854                 else
01855                 {
01856                         pReference->setRepresentation(repHash.value(refId));
01857                 }
01858                 // If representation hasn't a name. Set his name to reference name
01859                 if (pReference->representationName().isEmpty())
01860                 {
01861                         pReference->setRepresentationName(pReference->name());
01862                 }
01863 
01864                 ++iExtRep;
01865         }
01866 
01867 }
01868 
01869 // Return the instance of the current extern representation
01870 GLC_3DRep GLC_3dxmlToWorld::loadCurrentExtRep()
01871 {
01872         GLC_Mesh* pMesh= new GLC_Mesh();
01873         GLC_3DRep currentMeshRep(pMesh);
01874         currentMeshRep.setName(QString());
01875         // Set rep file name and time stamp
01876         setRepresentationFileName(&currentMeshRep);
01877 
01878         currentMeshRep.setLastModified(m_CurrentDateTime);
01879 
01880         int numberOfMesh= 1;
01881         while (!m_pStreamReader->atEnd())
01882         {
01883                 m_pCurrentMaterial= NULL;
01884                 gotToPolygonalRepType();
01885                 if (m_pStreamReader->atEnd() || m_pStreamReader->hasError())
01886                 {
01887                         if (m_pStreamReader->hasError())
01888                         {
01889                                 QString message(QString("An element have not been found in file ") + m_FileName);
01890                                 GLC_FileFormatException fileFormatException(message, m_FileName, GLC_FileFormatException::WrongFileFormat);
01891                                 clear();
01892                                 throw(fileFormatException);
01893                         }
01894                         else
01895                         {
01896                                 pMesh->finish();
01897                                 currentMeshRep.clean();
01898 
01899                                 if (GLC_State::cacheIsUsed())
01900                                 {
01901                                         GLC_CacheManager currentManager= GLC_State::currentCacheManager();
01902                                         currentManager.addToCache(QFileInfo(m_FileName).baseName(), currentMeshRep);
01903                                 }
01904 
01905                                 return currentMeshRep;
01906                         }
01907                 }
01908                 if (numberOfMesh > 1)
01909                 {
01910                         pMesh->finish();
01911                         pMesh = new GLC_Mesh();
01912                         currentMeshRep.addGeom(pMesh);
01913                 }
01914 
01915                 loadRep(pMesh);
01916 
01917                 ++numberOfMesh;
01918         }
01919 
01920         pMesh->finish();
01921         currentMeshRep.clean();
01922 
01923         if (GLC_State::cacheIsUsed())
01924         {
01925                 GLC_CacheManager currentManager= GLC_State::currentCacheManager();
01926                 currentManager.addToCache(QFileInfo(m_FileName).baseName(), currentMeshRep);
01927         }
01928 
01929         return currentMeshRep;
01930 }
01931 // Load CatMaterial Ref if present
01932 void GLC_3dxmlToWorld::loadCatMaterialRef()
01933 {
01934 
01935         QList<MaterialRef> materialRefList;
01936 
01937         // Load material Name, Id and associated File
01938         if (setStreamReaderToFile("CATMaterialRef.3dxml", true))
01939         {
01940                 // Load the material file
01941                 //qDebug() << "CATMaterialRef.3dxml found and current";
01942                 goToElement(m_pStreamReader, "CATMaterialRef");
01943                 checkForXmlError("Element CATMaterialRef not found in CATMaterialRef.3dxml");
01944                 while (endElementNotReached(m_pStreamReader, "CATMaterialRef"))
01945                 {
01946                         if (QXmlStreamReader::StartElement == m_pStreamReader->tokenType())
01947                         {
01948                                 const QStringRef currentElementName= m_pStreamReader->name();
01949                                 if (currentElementName == "CATMatReference")
01950                                 {
01951                                         MaterialRef currentMaterial;
01952                                         currentMaterial.m_Id= readAttribute("id", true);
01953                                         currentMaterial.m_Name= readAttribute("name", true);
01954                                         goToElement(m_pStreamReader, "MaterialDomain");
01955                                         checkForXmlError("Element MaterialDomain not found after CATMatReference Element");
01956                                         currentMaterial.m_AssociatedFile= readAttribute("associatedFile", true).remove("urn:3DXML:");
01957                                         materialRefList.append(currentMaterial);
01958                                         //qDebug() << "Material " << currentMaterial.m_Name << " Added";
01959                                 }
01960                         }
01961                         readNext();
01962                 }
01963         }
01964         // Load material files
01965         const int size= materialRefList.size();
01966         for (int i= 0; i < size; ++i)
01967         {
01968                 if (setStreamReaderToFile(materialRefList.at(i).m_AssociatedFile, true))
01969                 {
01970                         //qDebug() << "Load MaterialDef : " << materialRefList.at(i).m_AssociatedFile;
01971                         loadMaterialDef(materialRefList.at(i));
01972                 }
01973         }
01974 }
01975 
01976 // Create material from material def file
01977 void GLC_3dxmlToWorld::loadMaterialDef(const MaterialRef& materialRef)
01978 {
01979         GLC_Material* pMaterial= new GLC_Material();
01980         goToElement(m_pStreamReader, "Osm");
01981         checkForXmlError(QString("Element Osm not found in file : ") + materialRef.m_AssociatedFile);
01982         while (endElementNotReached(m_pStreamReader, "Osm"))
01983         {
01984                 readNext();
01985                 if ((QXmlStreamReader::StartElement == m_pStreamReader->tokenType()) && m_pStreamReader->name() == "Attr")
01986                 {
01987                         const QString currentName= readAttribute("Name", true);
01988                         if (currentName == "DiffuseColor")
01989                         {
01990                                 QString color= m_pStreamReader->attributes().value("Value").toString();
01991                                 color.remove('[');
01992                                 color.remove(']');
01993                                 QStringList colors(color.split(","));
01994                                 QColor diffuseColor;
01995                                 diffuseColor.setRedF(colors.at(0).toDouble());
01996                                 diffuseColor.setGreenF(colors.at(1).toDouble());
01997                                 diffuseColor.setBlueF(colors.at(2).toDouble());
01998                                 pMaterial->setDiffuseColor(diffuseColor);
01999                         }
02000                         else if (currentName == "Transparency")
02001                         {
02002                                 double opacity= readAttribute("Value", true).toDouble();
02003                                 opacity= 1.0 - opacity;
02004                                 pMaterial->setOpacity(opacity);
02005                         }
02006                         else if (currentName == "SpecularExponent")
02007                         {
02008                                 double SpecularExponent= readAttribute("Value", true).toDouble() * 128.0;
02009                                 pMaterial->setShininess(SpecularExponent);
02010                         }
02011                         else if (currentName == "TextureImage")
02012                         {
02013                                 //qDebug() << "TextureImage";
02014                                 QString imageId= readAttribute("Value", true).remove("urn:3DXML:CATRepImage.3dxml#");
02015                                 if (m_TextureImagesHash.contains(imageId))
02016                                 {
02017                                         QString imageName= m_TextureImagesHash.value(imageId);
02018                                         GLC_Texture* pTexture= loadTexture(imageName);
02019                                         if (NULL != pTexture)
02020                                         {
02021                                                 pMaterial->setTexture(pTexture);
02022                                         }
02023                                 }
02024                         }
02025                         else if (currentName == "EmissiveCoef")
02026                         {
02027 
02028                         }
02029                         else if (currentName == "SpecularColor")
02030                         {
02031                                 QString color= readAttribute("Value", true);
02032                                 color.remove('[');
02033                                 color.remove(']');
02034                                 QStringList colors(color.split(","));
02035                                 QColor specularColor;
02036                                 specularColor.setRedF(colors.at(0).toDouble());
02037                                 specularColor.setGreenF(colors.at(1).toDouble());
02038                                 specularColor.setBlueF(colors.at(2).toDouble());
02039                                 pMaterial->setSpecularColor(specularColor);
02040                         }
02041                         else if (currentName == "AmbientColor")
02042                         {
02043                                 QString color= readAttribute("Value", true);
02044                                 color.remove('[');
02045                                 color.remove(']');
02046                                 QStringList colors(color.split(","));
02047                                 QColor ambientColor;
02048                                 ambientColor.setRedF(colors.at(0).toDouble());
02049                                 ambientColor.setGreenF(colors.at(1).toDouble());
02050                                 ambientColor.setBlueF(colors.at(2).toDouble());
02051                                 pMaterial->setAmbientColor(ambientColor);
02052                         }
02053 
02054                 }
02055         }
02056         pMaterial->setName(materialRef.m_Name);
02057         m_MaterialHash.insert(materialRef.m_Id, pMaterial);
02058 }
02059 
02060 // Load CATRepIage if present
02061 void GLC_3dxmlToWorld::loadCatRepImage()
02062 {
02063         // Load texture image name
02064         if (setStreamReaderToFile("CATRepImage.3dxml", true))
02065         {
02066                 //qDebug() << "CATRepImage.3dxml Found";
02067                 goToElement(m_pStreamReader, "CATRepImage");
02068                 checkForXmlError("Element CATRepImage not found in CATRepImage.3dxml");
02069                 while (endElementNotReached(m_pStreamReader, "CATRepImage"))
02070                 {
02071                         if (QXmlStreamReader::StartElement == m_pStreamReader->tokenType())
02072                         {
02073                                 const QStringRef currentElementName= m_pStreamReader->name();
02074                                 if (currentElementName == "CATRepresentationImage")
02075                                 {
02076                                         QString id= readAttribute("id", true);
02077                                         QString associatedFile= readAttribute("associatedFile", true).remove("urn:3DXML:");
02078                                         m_TextureImagesHash.insert(id,associatedFile);
02079                                 }
02080                         }
02081                         readNext();
02082                 }
02083                 //qDebug() << "CATRepImage.3dxml Load";
02084         }
02085 }
02086 
02087 // try to load the specified image
02088 GLC_Texture* GLC_3dxmlToWorld::loadTexture(QString fileName)
02089 {
02090         QString format= QFileInfo(fileName).suffix().toUpper();
02091         QImage resultImage;
02092         QString resultImageFileName;
02093         if (m_IsInArchive)
02094         {
02095                 // Create QuaZip File
02096                 QuaZipFile* p3dxmlFile= new QuaZipFile(m_p3dxmlArchive);
02097 
02098                 // Get the file of the 3dxml
02099                 if (!m_p3dxmlArchive->setCurrentFile(fileName, QuaZip::csInsensitive))
02100                 {
02101                         return NULL;
02102                 }
02103 
02104                 // Open the file of the 3dxml
02105                 if(!p3dxmlFile->open(QIODevice::ReadOnly))
02106             {
02107                         delete p3dxmlFile;
02108                         QString message(QString("GLC_3dxmlToWorld::loadImage Unable to Open ") + fileName);
02109                         GLC_FileFormatException fileFormatException(message, fileName, GLC_FileFormatException::FileNotSupported);
02110                         clear();
02111                         throw(fileFormatException);
02112             }
02113                 resultImage.load(p3dxmlFile, format.toLocal8Bit());
02114                 p3dxmlFile->close();
02115                 delete p3dxmlFile;
02116                 resultImageFileName= glc::builtArchiveString(m_FileName, fileName);
02117         }
02118         else
02119         {
02120                 // Create the file to load
02121                 if (fileName != m_FileName)
02122                 {
02123                         resultImageFileName= QFileInfo(m_FileName).absolutePath() + QDir::separator() + fileName;
02124                 }
02125                 QFile* pCurrentFile= new QFile(resultImageFileName);
02126                 if (!pCurrentFile->open(QIODevice::ReadOnly))
02127                 {
02128                         delete pCurrentFile;
02129                         QString message(QString("GLC_3dxmlToWorld::loadImage File ") + resultImageFileName + QString(" not found"));
02130                         QStringList stringList(m_CurrentFileName);
02131                         stringList.append(message);
02132                         GLC_ErrorLog::addError(stringList);
02133                         return NULL;
02134                 }
02135                 else
02136                 {
02137                         m_SetOfAttachedFileName << resultImageFileName;
02138                 }
02139                 resultImage.load(pCurrentFile, format.toLocal8Bit());
02140                 pCurrentFile->close();
02141                 delete pCurrentFile;
02142         }
02143 
02144         GLC_Texture* pTexture= NULL;
02145         if (!resultImage.isNull())
02146         {
02147                 pTexture= new GLC_Texture(resultImage, resultImageFileName);
02148         }
02149         else
02150         {
02151                 QStringList stringList(m_CurrentFileName);
02152                 stringList.append("Unable to load " + resultImageFileName);
02153                 GLC_ErrorLog::addError(stringList);
02154         }
02155 
02156         return pTexture;
02157 }
02158 
02159 void GLC_3dxmlToWorld::setRepresentationFileName(GLC_3DRep* pRep)
02160 {
02161         if (m_IsInArchive)
02162         {
02163                 pRep->setFileName(glc::builtArchiveString(m_FileName, m_CurrentFileName));
02164         }
02165         else
02166         {
02167                 pRep->setFileName(QFileInfo(m_FileName).absolutePath() + QDir::separator() + m_CurrentFileName);
02168         }
02169 }
02170 
02171 void GLC_3dxmlToWorld::checkFileValidity(QIODevice* pIODevice)
02172 {
02173         QByteArray begining= pIODevice->read(2);
02174         if (begining == "V5")
02175         {
02176                 QString message(QString("GLC_3dxmlToWorld::setStreamReaderToFile : File ") + m_CurrentFileName + " is binary");
02177                 GLC_FileFormatException fileFormatException(message, m_CurrentFileName, GLC_FileFormatException::FileNotSupported);
02178                 clear();
02179                 throw(fileFormatException);
02180         }
02181         else
02182         {
02183                 pIODevice->seek(0);
02184         }
02185 }
02186 
02187 void GLC_3dxmlToWorld::applyV4Attribute(GLC_StructOccurence* pOccurence, V4OccurenceAttrib* pV4OccurenceAttrib, QHash<GLC_StructInstance*, unsigned int>& instanceToIdHash)
02188 {
02189         Q_ASSERT(pOccurence->hasChild() && !pV4OccurenceAttrib->m_Path.isEmpty());
02190         unsigned int id= pV4OccurenceAttrib->m_Path.takeFirst();
02191 
02192         const int childCount= pOccurence->childCount();
02193         bool occurenceFound= false;
02194         int i= 0;
02195         while (!occurenceFound && (i < childCount))
02196         {
02197                 GLC_StructOccurence* pChildOccurence= pOccurence->child(i);
02198                 if (instanceToIdHash.contains(pChildOccurence->structInstance()) && (instanceToIdHash.value(pChildOccurence->structInstance()) == id))
02199                 {
02200                         Q_ASSERT(id == instanceToIdHash.value(pChildOccurence->structInstance()));
02201                         occurenceFound= true;
02202 
02203                         if (pV4OccurenceAttrib->m_Path.isEmpty())
02204                         {
02205                                 pChildOccurence->setVisibility(pV4OccurenceAttrib->m_IsVisible);
02206                                 if (NULL != pV4OccurenceAttrib->m_pRenderProperties)
02207                                 {
02208                                         pChildOccurence->setRenderProperties(*(pV4OccurenceAttrib->m_pRenderProperties));
02209                                 }
02210                                 if (pV4OccurenceAttrib->m_pMatrix != NULL)
02211                                 {
02212                                         pChildOccurence->makeFlexible(*(pV4OccurenceAttrib->m_pMatrix));
02213                                 }
02214                         }
02215                         else
02216                         {
02217                                 applyV4Attribute(pChildOccurence, pV4OccurenceAttrib, instanceToIdHash);
02218                         }
02219                 }
02220                 else
02221                 {
02222                         ++i;
02223                 }
02224         }
02225         if (!occurenceFound)
02226         {
02227                 qDebug() << "GLC_3dxmlToWorld::applyV4Attribute Occurrence not found" << id;
02228         }
02229 
02230 }
02231 
02232 void GLC_3dxmlToWorld::loadRep(GLC_Mesh* pMesh)
02233 {
02234         double masteLodAccuracy= readAttribute("accuracy", false).toDouble();
02235         int lodIndex= 1;
02236 
02237         bool masterLodFound= false;
02238         bool vertexBufferFound= false;
02239 
02240         while (endElementNotReached(m_pStreamReader, "Rep") && endElementNotReached(m_pStreamReader, "Root"))
02241         {
02242                 if ((QXmlStreamReader::StartElement == m_pStreamReader->tokenType()))
02243                 {
02244                         if (m_pStreamReader->name() == "SurfaceAttributes")
02245                         {
02246                                 m_pCurrentMaterial= loadSurfaceAttributes();
02247                         }
02248                         else if (m_pStreamReader->name() == "PolygonalLOD")
02249                         {
02250                                 double accuracy= readAttribute("accuracy", true).toDouble();
02251                                 while (endElementNotReached(m_pStreamReader, "Faces"))
02252                                 {
02253                                         readNext();
02254                                         if ( m_pStreamReader->name() == "Face")
02255                                         {
02256                                                 loadFace(pMesh, lodIndex, accuracy);
02257                                         }
02258                                 }
02259                                 checkForXmlError("End of Faces not found");
02260                                 ++lodIndex;
02261                         }
02262                         else if (m_pStreamReader->name() == "Faces")
02263                         {
02264                                 masterLodFound= true;
02265                                 while (endElementNotReached(m_pStreamReader, "Faces"))
02266                                 {
02267                                         readNext();
02268                                         if ( m_pStreamReader->name() == "Face")
02269                                         {
02270                                                 loadFace(pMesh, 0, masteLodAccuracy);
02271                                         }
02272                                 }
02273                                 checkForXmlError("End of Faces not found");
02274                         }
02275                         else if (m_pStreamReader->name() == "Edges")
02276                         {
02277                                 while (endElementNotReached(m_pStreamReader, "Edges"))
02278                                 {
02279                                         readNext();
02280                                         if ( m_pStreamReader->name() == "Polyline")
02281                                         {
02282                                                 loadPolyline(pMesh);
02283                                                 readNext();
02284                                         }
02285                                 }
02286                         }
02287                         else if (m_pStreamReader->name() == "VertexBuffer")
02288                         {
02289                                 vertexBufferFound= true;
02290                                 loadVertexBuffer(pMesh);
02291                         }
02292                         else readNext();
02293                 }
02294                 else
02295                 {
02296                         readNext();
02297                 }
02298         }
02299         checkForXmlError("End of Rep or Root not found");
02300 
02301         if (!masterLodFound || !vertexBufferFound)
02302         {
02303                 QString message;
02304                 if (!masterLodFound)
02305                 {
02306                         message= QString("Master LOD not found in file ") + m_FileName;
02307                 }
02308                 else
02309                 {
02310                         message= QString("Vertex Buffer not found in file ") + m_FileName;
02311                 }
02312                 GLC_FileFormatException fileFormatException(message, m_FileName, GLC_FileFormatException::WrongFileFormat);
02313                 clear();
02314                 throw(fileFormatException);
02315         }
02316 
02317 
02318 }
02319 
02320 void GLC_3dxmlToWorld::loadVertexBuffer(GLC_Mesh* pMesh)
02321 {
02322         {
02323                 QString verticePosition= getContent(m_pStreamReader, "Positions").replace(',', ' ');
02324                 //qDebug() << "Position " << verticePosition;
02325                 checkForXmlError("Error while retrieving Position ContentVertexBuffer");
02326                 // Load Vertice position
02327                 QTextStream verticeStream(&verticePosition);
02328                 QList<GLfloat> verticeValues;
02329                 QString buff;
02330                 while ((!verticeStream.atEnd()))
02331                 {
02332                         verticeStream >> buff;
02333                         verticeValues.append(buff.toFloat());
02334                 }
02335                 if ((verticeValues.size() % 3) == 0)
02336                 {
02337                         pMesh->addVertice(verticeValues.toVector());
02338                 }
02339                 else
02340                 {
02341                         QString message(QString("Vertice buffer is not a multiple of 3 ") + m_CurrentFileName);
02342 
02343                         QStringList stringList(message);
02344                         GLC_ErrorLog::addError(stringList);
02345 
02346                         GLC_FileFormatException fileFormatException(message, m_FileName, GLC_FileFormatException::WrongFileFormat);
02347                         clear();
02348                         throw(fileFormatException);
02349                 }
02350         }
02351 
02352         {
02353                 QString normals= getContent(m_pStreamReader, "Normals").replace(',', ' ');
02354                 //qDebug() << "Normals " << normals;
02355                 checkForXmlError("Error while retrieving Normals values");
02356                 // Load Vertice Normals
02357                 QTextStream normalsStream(&normals);
02358                 QList<GLfloat> normalValues;
02359                 QString buff;
02360                 while ((!normalsStream.atEnd()))
02361                 {
02362                         normalsStream >> buff;
02363                         normalValues.append(buff.toFloat());
02364                 }
02365                 if ((normalValues.size() % 3) == 0)
02366                 {
02367                         pMesh->addNormals(normalValues.toVector());
02368                 }
02369                 else
02370                 {
02371                         QString message(QString("Normal buffer is not a multiple of 3 ") + m_CurrentFileName);
02372 
02373                         QStringList stringList(message);
02374                         GLC_ErrorLog::addError(stringList);
02375 
02376                         GLC_FileFormatException fileFormatException(message, m_FileName, GLC_FileFormatException::WrongFileFormat);
02377                         clear();
02378                         throw(fileFormatException);
02379                 }
02380 
02381         }
02382         // Try to find texture coordinate
02383         while (endElementNotReached(m_pStreamReader, "VertexBuffer"))
02384         {
02385                 if ((QXmlStreamReader::StartElement == m_pStreamReader->tokenType()) && (m_pStreamReader->name() == "TextureCoordinates"))
02386                 {
02387                         QString texels= getContent(m_pStreamReader, "TextureCoordinates").replace(',', ' ');
02388                         checkForXmlError("Error while retrieving Texture coordinates");
02389                         QTextStream texelStream(&texels);
02390                         QList<GLfloat> texelValues;
02391                         QString buff;
02392                         while ((!texelStream.atEnd()))
02393                         {
02394                                 texelStream >> buff;
02395                                 texelValues.append(buff.toFloat());
02396                         }
02397 
02398                         if ((texelValues.size() % 2) == 0)
02399                         {
02400                                 pMesh->addTexels(texelValues.toVector());
02401                         }
02402                         else
02403                         {
02404                                 QString message(QString("Texel buffer is not a multiple of 2 ") + m_CurrentFileName);
02405 
02406                                 QStringList stringList(message);
02407                                 GLC_ErrorLog::addError(stringList);
02408 
02409                                 GLC_FileFormatException fileFormatException(message, m_FileName, GLC_FileFormatException::WrongFileFormat);
02410                                 clear();
02411                                 throw(fileFormatException);
02412                         }
02413                 }
02414                 readNext();
02415         }
02416         checkForXmlError("VertexBuffer not found");
02417 }

SourceForge.net Logo

©2005-2011 Laurent Ribon