GLC_lib  2.5.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
glc_3dxmltoworld.h
Go to the documentation of this file.
1 /****************************************************************************
2 
3  This file is part of the GLC-lib library.
4  Copyright (C) 2005-2008 Laurent Ribon (laumaya@users.sourceforge.net)
5  http://glc-lib.sourceforge.net
6 
7  GLC-lib is free software; you can redistribute it and/or modify
8  it under the terms of the GNU Lesser General Public License as published by
9  the Free Software Foundation; either version 3 of the License, or
10  (at your option) any later version.
11 
12  GLC-lib is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  GNU Lesser General Public License for more details.
16 
17  You should have received a copy of the GNU Lesser General Public License
18  along with GLC-lib; if not, write to the Free Software
19  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 
21 *****************************************************************************/
22 
24 
25 #ifndef GLC_3DXMLTOWORLD_H_
26 #define GLC_3DXMLTOWORLD_H_
27 
28 #include <QFile>
29 #include <QObject>
30 #include <QXmlStreamReader>
31 #include <QHash>
32 #include <QSet>
33 #include <QDateTime>
34 #include "../maths/glc_matrix4x4.h"
35 #include "../sceneGraph/glc_3dviewinstance.h"
36 
37 #include "../glc_config.h"
38 
39 class GLC_World;
40 class QGLContext;
41 class QuaZip;
42 class QuaZipFile;
44 class GLC_StructInstance;
46 class GLC_Mesh;
47 
50 
51 
52 class GLC_LIB_EXPORT GLC_3dxmlToWorld : public QObject
53 {
54  Q_OBJECT
55 
57 
58  struct AssyLink
59  {
60  unsigned int m_ParentRefId;
62  unsigned int m_InstanceId;
63  inline bool operator < (const AssyLink& l) const
64  {return m_InstanceId < l.m_InstanceId;}
65  };
67 
68  struct RepLink
69  {
70  unsigned int m_ReferenceId;
71  unsigned int m_RepId;
72  };
74 
75  struct MaterialRef
76  {
77  QString m_Id;
78  QString m_Name;
80  };
81 
83 
85  {
87  : m_IsVisible(true)
88  , m_pRenderProperties(NULL)
89  {}
91  {delete m_pRenderProperties;}
92 
97  };
98 
100 
102  {
104  : m_IsVisible(true)
105  , m_pRenderProperties(NULL)
106  , m_pMatrix(NULL)
107  , m_Path()
108  {}
110  {
111  delete m_pRenderProperties;
112  delete m_pMatrix;
113  }
114 
122  QList<unsigned int> m_Path;
123  };
124 
125  typedef QHash<unsigned int, GLC_StructReference*> ReferenceHash;
126  typedef QHash<GLC_StructInstance*, unsigned int> InstanceOfHash;
127  typedef QHash<GLC_StructInstance*, QString> InstanceOfExtRefHash;
128  typedef QSet<const QString> SetOfExtRef;
129  typedef QList<AssyLink> AssyLinkList;
130  typedef QList<RepLink> RepLinkList;
131  typedef QHash<const QString, GLC_StructReference*> ExternalReferenceHash;
132  typedef QHash<const QString, GLC_Material*> MaterialHash;
133  typedef QHash<const unsigned int, QString> ReferenceRepHash;
134 
136 
138 
139 public:
142 
143  virtual ~GLC_3dxmlToWorld();
145 
146 
148 
149 public:
151  GLC_World* createWorldFrom3dxml(QFile &, bool StructureOnly, bool getExternalRef= false);
152 
154  GLC_3DRep create3DrepFrom3dxmlRep(const QString&);
155 
157  inline QStringList listOfAttachedFileName() const
158  {return m_SetOfAttachedFileName.toList();}
159 
160 
162 
164 // Qt Signals
166  signals:
167  void currentQuantum(int);
168 
170 
172 
173 private:
175  void loadManifest();
176 
178  void clear();
179 
181  void goToRepId(const QString&);
182 
184  void gotToPolygonalRepType();
185 
187  QString readAttribute(const QString&, bool required= false);
188 
190  void readHeader();
191 
193  void loadProductStructure();
194 
196  void loadReference3D();
197 
199  void loadInstance3D();
200 
202  void loadReferenceRep();
203 
205  void loadInstanceRep();
206 
208  void loadExternalRef3D();
209 
211  GLC_StructReference* createReferenceRep(QString id, GLC_3DRep* pRep);
212 
214  GLC_Matrix4x4 loadMatrix(const QString&);
215 
217  void createUnfoldedTree();
218 
221  void checkForXmlError(const QString&);
222 
224  void loadFace(GLC_Mesh*, const int lod, double accuracy);
225 
227  void loadPolyline(GLC_Mesh*);
228 
230  void clearMaterialHash();
231 
233  GLC_Material* loadSurfaceAttributes();
234 
236  GLC_Material* getMaterial();
237 
239  bool setStreamReaderToFile(QString, bool test= false);
240 
242  void loadDefaultView();
243 
245  void loadV3DefaultViewProperty();
246 
248  void loadV4DefaultViewProperty();
249 
251  QList<unsigned int> loadOccurencePath();
252 
254  void loadGraphicProperties(V4OccurenceAttrib* pAttrib);
255 
257  void loadLocalRepresentations();
258 
260  void loadExternRepresentations();
261 
263  GLC_3DRep loadCurrentExtRep();
264 
266  void loadCatMaterialRef();
267 
269  void loadMaterialDef(const MaterialRef&);
270 
272  void loadCatRepImage();
273 
275  GLC_Texture* loadTexture(QString);
276 
278  void setRepresentationFileName(GLC_3DRep* pRep);
279 
281  inline QXmlStreamReader::TokenType readNext();
282 
284  inline bool goToElement(QXmlStreamReader* pReader, const QString& element);
285 
286  // Return the content of an element
287  inline QString getContent(QXmlStreamReader* pReader, const QString& element);
288 
290  inline QString readAttribute(QXmlStreamReader* pReader, const QString& attribute);
291 
293  inline bool endElementNotReached(QXmlStreamReader* pReader, const QString& element);
294 
296  inline bool startElementNotReached(QXmlStreamReader* pReader, const QString& element);
297 
299  inline void goToEndElement(QXmlStreamReader* pReader, const QString& element);
300 
302  void checkFileValidity(QIODevice* pIODevice);
303 
305  void applyV4Attribute(GLC_StructOccurence* pOccurence, V4OccurenceAttrib* pV4OccurenceAttrib, QHash<GLC_StructInstance*, unsigned int>& InstanceToIdHash);
306 
308  void loadRep(GLC_Mesh* pMesh);
309 
311  void loadVertexBuffer(GLC_Mesh* pMesh);
312 
314 
316 // Private members
318 private:
320  QXmlStreamReader* m_pStreamReader;
321 
323  QString m_FileName;
324 
327 
330 
332  QString m_RootName;
333 
336 
339 
342 
345 
348 
351 
354 
357 
360 
363 
366 
369 
372 
375 
377  QHash<QString, QString> m_TextureImagesHash;
378 
381 
383  QSet<QString> m_SetOfAttachedFileName;
384 
387 
389  QDateTime m_CurrentDateTime;
390 
392  QHash<unsigned int, V3OccurenceAttrib*> m_V3OccurenceAttribHash;
393 
395  QList<V4OccurenceAttrib*> m_V4OccurenceAttribList;
396 
399 
400  static QMutex m_ZipMutex;
401 
402  QList<QByteArray> m_ByteArrayList;
403 
406 
407 };
408 
409 QXmlStreamReader::TokenType GLC_3dxmlToWorld::readNext()
410 {
411  QXmlStreamReader::TokenType token= m_pStreamReader->readNext();
412  if (QXmlStreamReader::PrematureEndOfDocumentError == m_pStreamReader->error())
413  {
414  //qDebug() << "QXmlStreamReader::PrematureEndOfDocumentError == m_pStreamReader->error()";
415  if (!m_ByteArrayList.isEmpty())
416  {
417  m_pStreamReader->addData(m_ByteArrayList.takeFirst());
418  return readNext();
419  }
420  }
421  return token;
422 }
423 
424 bool GLC_3dxmlToWorld::goToElement(QXmlStreamReader* pReader, const QString& element)
425 {
426  while(!pReader->atEnd() && !pReader->hasError() && !(pReader->isStartElement() && (pReader->name() == element)))
427  {
428  readNext();
429  }
430  return !pReader->atEnd() && !pReader->hasError();
431 }
432 
433 QString GLC_3dxmlToWorld::getContent(QXmlStreamReader* pReader, const QString& element)
434 {
435  QString content;
436  while(endElementNotReached(pReader, element))
437  {
438  readNext();
439  if (pReader->isCharacters() && !pReader->text().isEmpty())
440  {
441  content+= pReader->text().toString();
442  }
443  }
444 
445  return content.trimmed();
446 }
447 
448 QString GLC_3dxmlToWorld::readAttribute(QXmlStreamReader* pReader, const QString& attribute)
449 {
450  return pReader->attributes().value(attribute).toString();
451 }
452 
453 bool GLC_3dxmlToWorld::endElementNotReached(QXmlStreamReader* pReader, const QString& element)
454 {
455  return !pReader->atEnd() && !pReader->hasError() && !(pReader->isEndElement() && (pReader->name() == element));
456 }
457 
458 bool GLC_3dxmlToWorld::startElementNotReached(QXmlStreamReader* pReader, const QString& element)
459 {
460  return !pReader->atEnd() && !pReader->hasError() && !(pReader->isStartElement() && (pReader->name() == element));
461 }
462 
463 void GLC_3dxmlToWorld::goToEndElement(QXmlStreamReader* pReader, const QString& element)
464 {
465  while(endElementNotReached(pReader, element))
466  {
467  readNext();
468  }
469 }
470 
471 
472 #endif /* GLC_3DXMLTOWORLD_H_ */

©2005-2013 Laurent Ribon