glc_3dxmltoworld.h

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  Version 2.0.0 Beta 1, packaged on April 2010.
00006 
00007  http://glc-lib.sourceforge.net
00008 
00009  GLC-lib is free software; you can redistribute it and/or modify
00010  it under the terms of the GNU General Public License as published by
00011  the Free Software Foundation; either version 2 of the License, or
00012  (at your option) any later version.
00013 
00014  GLC-lib is distributed in the hope that it will be useful,
00015  but WITHOUT ANY WARRANTY; without even the implied warranty of
00016  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017  GNU General Public License for more details.
00018 
00019  You should have received a copy of the GNU General Public License
00020  along with GLC-lib; if not, write to the Free Software
00021  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
00022 
00023 *****************************************************************************/
00024 
00026 
00027 #ifndef GLC_3DXMLTOWORLD_H_
00028 #define GLC_3DXMLTOWORLD_H_
00029 
00030 #include <QFile>
00031 #include <QObject>
00032 #include <QXmlStreamReader>
00033 #include <QHash>
00034 #include <QSet>
00035 #include <QDateTime>
00036 #include "../maths/glc_matrix4x4.h"
00037 #include "../sceneGraph/glc_3dviewinstance.h"
00038 
00039 #include "glc_config.h"
00040 
00041 class GLC_World;
00042 class QGLContext;
00043 class QuaZip;
00044 class QuaZipFile;
00045 class GLC_StructReference;
00046 class GLC_StructInstance;
00047 class GLC_Mesh;
00048 
00051 
00052 
00053 class GLC_LIB_EXPORT GLC_3dxmlToWorld : public QObject
00054 {
00055         Q_OBJECT
00056 
00058 
00059         struct AssyLink
00060         {
00061                 unsigned int m_ParentRefId;
00062                 GLC_StructInstance* m_pChildInstance;
00063                 unsigned int m_InstanceId;
00064                 inline bool operator < (const AssyLink& l) const
00065                 {return m_InstanceId < l.m_InstanceId;}
00066         };
00068 
00069         struct RepLink
00070         {
00071                 unsigned int m_ReferenceId;
00072                 unsigned int  m_RepId;
00073         };
00075 
00076         struct MaterialRef
00077         {
00078                 QString m_Id;
00079                 QString m_Name;
00080                 QString m_AssociatedFile;
00081         };
00082 
00084 
00085         struct OccurenceAttrib
00086         {
00087                 inline OccurenceAttrib()
00088                 : m_IsVisible(true)
00089                 , m_pRenderProperties(NULL)
00090                 {}
00091                 inline ~OccurenceAttrib()
00092                 {delete m_pRenderProperties;}
00093 
00095                 bool m_IsVisible;
00097                 GLC_RenderProperties* m_pRenderProperties;
00098         };
00099 
00100         typedef QHash<unsigned int, GLC_StructReference*> ReferenceHash;
00101         typedef QHash<GLC_StructInstance*, unsigned int> InstanceOfHash;
00102         typedef QHash<GLC_StructInstance*, QString> InstanceOfExtRefHash;
00103         typedef QSet<const QString> SetOfExtRef;
00104         typedef QList<AssyLink> AssyLinkList;
00105         typedef QList<RepLink> RepLinkList;
00106         typedef QHash<const QString, GLC_StructReference*> ExternalReferenceHash;
00107         typedef QHash<const QString, GLC_Material*> MaterialHash;
00108         typedef QHash<const unsigned int, QString> ReferenceRepHash;
00109 
00111 
00113 
00114 public:
00116         GLC_3dxmlToWorld(const QGLContext*);
00117 
00118         virtual ~GLC_3dxmlToWorld();
00120 
00121 
00123 
00124 public:
00126         GLC_World* createWorldFrom3dxml(QFile &, bool StructureOnly);
00127 
00129         GLC_3DRep create3DrepFrom3dxmlRep(const QString&);
00130 
00132         inline QStringList listOfAttachedFileName() const
00133         {return m_ListOfAttachedFileName.toList();}
00134 
00135 
00137 
00139 // Qt Signals
00141         signals:
00142         void currentQuantum(int);
00143 
00145 
00147 
00148 private:
00150         void loadManifest();
00151 
00153         void clear();
00154 
00156         void goToElement(const QString&);
00157 
00159         void goToRepId(const QString&);
00160 
00162         void gotToPolygonalRepType();
00163 
00164         // Return the content of an element
00165         QString getContent(const QString&);
00166 
00168         QString readAttribute(const QString&, bool required= false);
00169 
00171         void loadProductStructure();
00172 
00174         void loadReference3D();
00175 
00177         void loadInstance3D();
00178 
00180         void loadReferenceRep();
00181 
00183         void loadInstanceRep();
00184 
00186         void loadExternalRef3D();
00187 
00189         GLC_StructReference* createReferenceRep(QString id= QString());
00190 
00192         GLC_Matrix4x4 loadMatrix(const QString&);
00193 
00195         void createUnfoldedTree();
00196 
00199         void checkForXmlError(const QString&);
00200 
00202         void loadLOD(GLC_Mesh*);
00203 
00205         inline bool endElementNotReached(const QString& element)
00206         {return !m_pStreamReader->atEnd() && !(m_pStreamReader->isEndElement() && (m_pStreamReader->name() == element));}
00207 
00209         inline bool startElementNotReached(const QString& element)
00210         {return !m_pStreamReader->atEnd() && !(m_pStreamReader->isStartElement() && (m_pStreamReader->name() == element));}
00211 
00213         void loadFace(GLC_Mesh*, const int lod, double accuracy);
00214 
00216         void loadPolyline(GLC_Mesh*);
00217 
00219         void clearMaterialHash();
00220 
00222         GLC_Material* loadSurfaceAttributes();
00223 
00225         GLC_Material* getMaterial();
00226 
00228         bool setStreamReaderToFile(QString, bool test= false);
00229 
00231         void loadGraphicsProperties();
00232 
00234         void loadDefaultViewProperty();
00235 
00237         void loadLocalRepresentations();
00238 
00240         void loadExternRepresentations();
00241 
00243         GLC_3DRep loadCurrentExtRep();
00244 
00246         void loadCatMaterialRef();
00247 
00249         void loadMaterialDef(const MaterialRef&);
00250 
00252         void loadCatRepImage();
00253 
00255         GLC_Texture* loadTexture(QString);
00256 
00258         void factorizeMaterial(GLC_3DRep*);
00259 
00261 
00263 // Private members
00265 private:
00267         const QGLContext* m_pQGLContext;
00268 
00270         QXmlStreamReader* m_pStreamReader;
00271 
00273         QString m_FileName;
00274 
00276         QuaZip* m_p3dxmlArchive;
00277 
00279         QuaZipFile* m_p3dxmlFile;
00280 
00282         QFile* m_pCurrentFile;
00283 
00285         QString m_RootName;
00286 
00288         GLC_World* m_pWorld;
00289 
00291         ReferenceHash m_ReferenceHash;
00292 
00294         AssyLinkList m_AssyLinkList;
00295 
00297         InstanceOfHash m_InstanceOf;
00298 
00300         SetOfExtRef m_SetOfExtRef;
00301 
00303         InstanceOfExtRefHash m_InstanceOfExtRefHash;
00304 
00306         ExternalReferenceHash m_ExternalReferenceHash;
00307 
00309         MaterialHash m_MaterialHash;
00310 
00312         bool m_IsInArchive;
00313 
00315         ReferenceRepHash m_ReferenceRepHash;
00316 
00318         RepLinkList m_LocalRepLinkList;
00319 
00321         RepLinkList m_ExternRepLinkList;
00322 
00324         SetOfExtRef m_SetOfExtRep;
00325 
00327         GLC_Material* m_pCurrentMaterial;
00328 
00330         QHash<QString, QString> m_TextureImagesHash;
00331 
00333         bool m_LoadStructureOnly;
00334 
00336         QSet<QString> m_ListOfAttachedFileName;
00337 
00339         QString m_CurrentFileName;
00340 
00342         QDateTime m_CurrentDateTime;
00343 
00345         QHash<unsigned int, OccurenceAttrib*> m_OccurenceAttrib;
00346 
00347 
00348 };
00349 
00350 #endif /* GLC_3DXMLTOWORLD_H_ */

SourceForge.net Logo

©2005 Laurent Ribon