glc_3dxmltoworld.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00024
00025 #ifndef GLC_3DXMLTOWORLD_H_
00026 #define GLC_3DXMLTOWORLD_H_
00027
00028 #include <QFile>
00029 #include <QObject>
00030 #include <QXmlStreamReader>
00031 #include <QHash>
00032 #include <QSet>
00033 #include <QDateTime>
00034 #include "../maths/glc_matrix4x4.h"
00035 #include "../sceneGraph/glc_3dviewinstance.h"
00036
00037 #include "../glc_config.h"
00038
00039 class GLC_World;
00040 class QGLContext;
00041 class QuaZip;
00042 class QuaZipFile;
00043 class GLC_StructReference;
00044 class GLC_StructInstance;
00045 class GLC_Mesh;
00046
00049
00050
00051 class GLC_LIB_EXPORT GLC_3dxmlToWorld : public QObject
00052 {
00053 Q_OBJECT
00054
00056
00057 struct AssyLink
00058 {
00059 unsigned int m_ParentRefId;
00060 GLC_StructInstance* m_pChildInstance;
00061 unsigned int m_InstanceId;
00062 inline bool operator < (const AssyLink& l) const
00063 {return m_InstanceId < l.m_InstanceId;}
00064 };
00066
00067 struct RepLink
00068 {
00069 unsigned int m_ReferenceId;
00070 unsigned int m_RepId;
00071 };
00073
00074 struct MaterialRef
00075 {
00076 QString m_Id;
00077 QString m_Name;
00078 QString m_AssociatedFile;
00079 };
00080
00082
00083 struct OccurenceAttrib
00084 {
00085 inline OccurenceAttrib()
00086 : m_IsVisible(true)
00087 , m_pRenderProperties(NULL)
00088 {}
00089 inline ~OccurenceAttrib()
00090 {delete m_pRenderProperties;}
00091
00093 bool m_IsVisible;
00095 GLC_RenderProperties* m_pRenderProperties;
00096 };
00097
00098 typedef QHash<unsigned int, GLC_StructReference*> ReferenceHash;
00099 typedef QHash<GLC_StructInstance*, unsigned int> InstanceOfHash;
00100 typedef QHash<GLC_StructInstance*, QString> InstanceOfExtRefHash;
00101 typedef QSet<const QString> SetOfExtRef;
00102 typedef QList<AssyLink> AssyLinkList;
00103 typedef QList<RepLink> RepLinkList;
00104 typedef QHash<const QString, GLC_StructReference*> ExternalReferenceHash;
00105 typedef QHash<const QString, GLC_Material*> MaterialHash;
00106 typedef QHash<const unsigned int, QString> ReferenceRepHash;
00107
00109
00111
00112 public:
00114 GLC_3dxmlToWorld();
00115
00116 virtual ~GLC_3dxmlToWorld();
00118
00119
00121
00122 public:
00124 GLC_World* createWorldFrom3dxml(QFile &, bool StructureOnly, bool getExternalRef= false);
00125
00127 GLC_3DRep create3DrepFrom3dxmlRep(const QString&);
00128
00130 inline QStringList listOfAttachedFileName() const
00131 {return m_SetOfAttachedFileName.toList();}
00132
00133
00135
00137
00139 signals:
00140 void currentQuantum(int);
00141
00143
00145
00146 private:
00148 void loadManifest();
00149
00151 void clear();
00152
00154 void goToRepId(const QString&);
00155
00157 void gotToPolygonalRepType();
00158
00160 QString readAttribute(const QString&, bool required= false);
00161
00163 void loadProductStructure();
00164
00166 void loadReference3D();
00167
00169 void loadInstance3D();
00170
00172 void loadReferenceRep();
00173
00175 void loadInstanceRep();
00176
00178 void loadExternalRef3D();
00179
00181 GLC_StructReference* createReferenceRep(QString id, GLC_3DRep* pRep);
00182
00184 GLC_Matrix4x4 loadMatrix(const QString&);
00185
00187 void createUnfoldedTree();
00188
00191 void checkForXmlError(const QString&);
00192
00194 void loadLOD(GLC_Mesh*);
00195
00197 void loadFace(GLC_Mesh*, const int lod, double accuracy);
00198
00200 void loadPolyline(GLC_Mesh*);
00201
00203 void clearMaterialHash();
00204
00206 GLC_Material* loadSurfaceAttributes();
00207
00209 GLC_Material* getMaterial();
00210
00212 bool setStreamReaderToFile(QString, bool test= false);
00213
00215 void loadGraphicsProperties();
00216
00218 void loadDefaultViewProperty();
00219
00221 void loadLocalRepresentations();
00222
00224 void loadExternRepresentations();
00225
00227 GLC_3DRep loadCurrentExtRep();
00228
00230 void loadCatMaterialRef();
00231
00233 void loadMaterialDef(const MaterialRef&);
00234
00236 void loadCatRepImage();
00237
00239 GLC_Texture* loadTexture(QString);
00240
00242 void factorizeMaterial(GLC_3DRep*);
00243
00245 void setRepresentationFileName(GLC_3DRep* pRep);
00246
00248 inline QXmlStreamReader::TokenType readNext();
00249
00251 inline bool goToElement(QXmlStreamReader* pReader, const QString& element);
00252
00253
00254 inline QString getContent(QXmlStreamReader* pReader, const QString& element);
00255
00257 inline QString readAttribute(QXmlStreamReader* pReader, const QString& attribute);
00258
00260 inline bool endElementNotReached(QXmlStreamReader* pReader, const QString& element);
00261
00263 inline bool startElementNotReached(QXmlStreamReader* pReader, const QString& element);
00264
00266 inline void goToEndElement(QXmlStreamReader* pReader, const QString& element);
00267
00269 void checkFileValidity(QIODevice* pIODevice);
00270
00272
00274
00276 private:
00278 QXmlStreamReader* m_pStreamReader;
00279
00281 QString m_FileName;
00282
00284 QuaZip* m_p3dxmlArchive;
00285
00287 QFile* m_pCurrentFile;
00288
00290 QString m_RootName;
00291
00293 GLC_World* m_pWorld;
00294
00296 ReferenceHash m_ReferenceHash;
00297
00299 AssyLinkList m_AssyLinkList;
00300
00302 InstanceOfHash m_InstanceOf;
00303
00305 SetOfExtRef m_SetOfExtRef;
00306
00308 InstanceOfExtRefHash m_InstanceOfExtRefHash;
00309
00311 ExternalReferenceHash m_ExternalReferenceHash;
00312
00314 MaterialHash m_MaterialHash;
00315
00317 bool m_IsInArchive;
00318
00320 ReferenceRepHash m_ReferenceRepHash;
00321
00323 RepLinkList m_LocalRepLinkList;
00324
00326 RepLinkList m_ExternRepLinkList;
00327
00329 SetOfExtRef m_SetOfExtRep;
00330
00332 GLC_Material* m_pCurrentMaterial;
00333
00335 QHash<QString, QString> m_TextureImagesHash;
00336
00338 bool m_LoadStructureOnly;
00339
00341 QSet<QString> m_SetOfAttachedFileName;
00342
00344 QString m_CurrentFileName;
00345
00347 QDateTime m_CurrentDateTime;
00348
00350 QHash<unsigned int, OccurenceAttrib*> m_OccurenceAttrib;
00351
00353 bool m_GetExternalRef3DName;
00354
00355 static QMutex m_ZipMutex;
00356
00357 QList<QByteArray> m_ByteArrayList;
00358
00359 };
00360
00361 QXmlStreamReader::TokenType GLC_3dxmlToWorld::readNext()
00362 {
00363 QXmlStreamReader::TokenType token= m_pStreamReader->readNext();
00364 if (QXmlStreamReader::PrematureEndOfDocumentError == m_pStreamReader->error())
00365 {
00366
00367 if (!m_ByteArrayList.isEmpty())
00368 {
00369 m_pStreamReader->addData(m_ByteArrayList.takeFirst());
00370 return readNext();
00371 }
00372 }
00373 return token;
00374 }
00375
00376 bool GLC_3dxmlToWorld::goToElement(QXmlStreamReader* pReader, const QString& element)
00377 {
00378 while(!pReader->atEnd() && !pReader->hasError() && !(pReader->isStartElement() && (pReader->name() == element)))
00379 {
00380 readNext();
00381 }
00382 return !pReader->atEnd() && !pReader->hasError();
00383 }
00384
00385 QString GLC_3dxmlToWorld::getContent(QXmlStreamReader* pReader, const QString& element)
00386 {
00387 QString content;
00388 while(endElementNotReached(pReader, element))
00389 {
00390 readNext();
00391 if (pReader->isCharacters() && !pReader->text().isEmpty())
00392 {
00393 content+= pReader->text().toString();
00394 }
00395 }
00396
00397 return content.trimmed();
00398 }
00399
00400 QString GLC_3dxmlToWorld::readAttribute(QXmlStreamReader* pReader, const QString& attribute)
00401 {
00402 return pReader->attributes().value(attribute).toString();
00403 }
00404
00405 bool GLC_3dxmlToWorld::endElementNotReached(QXmlStreamReader* pReader, const QString& element)
00406 {
00407 return !pReader->atEnd() && !pReader->hasError() && !(pReader->isEndElement() && (pReader->name() == element));
00408 }
00409
00410 bool GLC_3dxmlToWorld::startElementNotReached(QXmlStreamReader* pReader, const QString& element)
00411 {
00412 return !pReader->atEnd() && !pReader->hasError() && !(pReader->isStartElement() && (pReader->name() == element));
00413 }
00414
00415 void GLC_3dxmlToWorld::goToEndElement(QXmlStreamReader* pReader, const QString& element)
00416 {
00417 while(endElementNotReached(pReader, element))
00418 {
00419 readNext();
00420 }
00421 }
00422
00423
00424 #endif