GLC_lib  2.5.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
glc_worldto3dxml.cpp
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  *****************************************************************************/
23 
24 #include "glc_worldto3dxml.h"
25 // Quazip library
26 #include "../3rdparty/quazip/quazip.h"
27 #include "../3rdparty/quazip/quazipfile.h"
28 #include "../glc_exception.h"
29 #include "../geometry/glc_mesh.h"
30 
31 #include <QFileInfo>
32 
33 GLC_WorldTo3dxml::GLC_WorldTo3dxml(const GLC_World& world, bool threaded)
34 : QObject()
35 , m_World(world)
36 , m_ExportType(Compressed3dxml)
37 , m_FileName()
38 , m_pOutStream(NULL)
39 , m_Generator("GLC_LIB")
40 , m_CurrentId(0)
41 , m_p3dxmlArchive(NULL)
42 , m_pCurrentZipFile(NULL)
43 , m_pCurrentFile(NULL)
44 , m_AbsolutePath()
45 , m_ReferenceToIdHash()
46 , m_InstanceToIdHash()
47 , m_ReferenceRepToIdHash()
48 , m_ReferenceRepTo3dxmlFileName()
49 , m_InstanceRep()
50 , m_MaterialIdToMaterialName()
51 , m_MaterialIdToMaterialId()
52 , m_MaterialIdToTexture3dxmlName()
53 , m_MaterialIdTo3dxmlImageId()
54 , m_ExportMaterial(true)
55 , m_3dxmlFileSet()
56 , m_FileNameIncrement(0)
57 , m_ListOfOverLoadedOccurence()
58 , m_pReadWriteLock(NULL)
59 , m_pIsInterupted(NULL)
60 , m_IsThreaded(threaded)
61 {
63 }
64 
66 {
67  delete m_p3dxmlArchive;
68  delete m_pCurrentZipFile;
69  delete m_pCurrentFile;
70 }
71 
72 bool GLC_WorldTo3dxml::exportTo3dxml(const QString& filename, GLC_WorldTo3dxml::ExportType exportType, bool exportMaterial)
73 {
74  m_3dxmlFileSet.clear();
77  m_ExportMaterial= exportMaterial;
78  m_FileName= filename;
79  m_ExportType= exportType;
80  bool isExported= false;
82  {
83  m_p3dxmlArchive= new QuaZip(m_FileName);
84  isExported= m_p3dxmlArchive->open(QuaZip::mdCreate);
85  // Add the manifest
86  addManifest();
87 
88  }
89  else
90  {
91  m_AbsolutePath= QFileInfo(m_FileName).absolutePath() + QDir::separator();
92  QFile exportFile(m_FileName);
93  isExported= exportFile.open(QIODevice::WriteOnly);
94  exportFile.close();
95  }
96  if (isExported)
97  {
99  {
101  }
102 
103  // Export the assembly structure from the list of structure reference
105 
107  {
108  int previousQuantumValue= 0;
109  int currentQuantumValue= 0;
110  emit currentQuantum(currentQuantumValue);
111 
112  int currentRepIndex= 0;
113  const int size= m_ReferenceRepTo3dxmlFileName.size();
114  // Export the representation
115  QHash<const GLC_3DRep*, QString>::const_iterator iRep= m_ReferenceRepTo3dxmlFileName.constBegin();
116  while ((m_ReferenceRepTo3dxmlFileName.constEnd() != iRep) && continu())
117  {
118  write3DRep(iRep.key(), iRep.value());
119  ++iRep;
120 
121  // Progrees bar indicator
122  ++currentRepIndex;
123  currentQuantumValue = static_cast<int>((static_cast<double>(currentRepIndex) / size) * 100);
124  if (currentQuantumValue > previousQuantumValue)
125  {
126  emit currentQuantum(currentQuantumValue);
127  }
128  previousQuantumValue= currentQuantumValue;
129  if (!m_IsThreaded)
130  {
131  QCoreApplication::processEvents(QEventLoop::ExcludeUserInputEvents);
132  }
133  }
134  }
135  }
136 
137  emit currentQuantum(100);
138  return isExported;
139 }
140 
141 bool GLC_WorldTo3dxml::exportReferenceTo3DRep(const GLC_3DRep* p3DRep, const QString& fullFileName)
142 {
143  m_3dxmlFileSet.clear();
146  m_ExportMaterial= false;
147 
148  m_AbsolutePath= QFileInfo(fullFileName).absolutePath() + QDir::separator();
149 
150  write3DRep(p3DRep, QFileInfo(fullFileName).fileName());
151 
152  return true;
153 }
154 
155 void GLC_WorldTo3dxml::setInterupt(QReadWriteLock* pReadWriteLock, bool* pInterupt)
156 {
157  m_pReadWriteLock= pReadWriteLock;
158  m_pIsInterupted= pInterupt;
159 }
160 
162 {
163  const QString title(QFileInfo(m_FileName).fileName());
164 
165  m_pOutStream->writeStartElement("Header");
166  m_pOutStream->writeTextElement("SchemaVersion", "4.0");
167  m_pOutStream->writeTextElement("Title", title);
168  m_pOutStream->writeTextElement("Generator", m_Generator);
169  m_pOutStream->writeTextElement("Created", QDate::currentDate().toString(Qt::ISODate));
170  m_pOutStream->writeEndElement();
171 }
172 
174 {
175  m_pOutStream->writeStartElement("Reference3D");
176  m_pOutStream->writeAttribute("xsi:type", "Reference3DType");
177  m_pOutStream->writeAttribute("id", QString::number(++m_CurrentId));
178  m_pOutStream->writeAttribute("name", pRef->name());
179  if (pRef->containsAttributes())
180  {
181  m_pOutStream->writeStartElement("Reference3DExtensionType");
183  m_pOutStream->writeEndElement(); // Reference3DExtensionType
184  }
185  m_pOutStream->writeEndElement(); // Reference3D
186 
187  m_ReferenceToIdHash.insert(pRef, m_CurrentId);
188 }
189 
191 {
192  const QString id(QString::number(++m_CurrentId));
193  m_ReferenceRepToIdHash.insert(p3DRep, m_CurrentId);
194  const QString associateFile(representationFileName(p3DRep));
195  m_ReferenceRepTo3dxmlFileName.insert(p3DRep, QString(associateFile).remove("urn:3DXML:"));
196 
197  m_pOutStream->writeStartElement("ReferenceRep");
198  m_pOutStream->writeAttribute("xsi:type", "ReferenceRepType");
199  m_pOutStream->writeAttribute("id", id);
200  m_pOutStream->writeAttribute("name", p3DRep->name());
201  m_pOutStream->writeAttribute("format", "TESSELLATED");
202  m_pOutStream->writeAttribute("version", "1.2");
203  m_pOutStream->writeAttribute("associatedFile", associateFile);
204  m_pOutStream->writeTextElement("PLM_ExternalID", p3DRep->name());
205  m_pOutStream->writeTextElement("V_discipline", "Design");
206  m_pOutStream->writeTextElement("V_usage", "3DShape");
207  m_pOutStream->writeTextElement("V_nature", "1");
208  m_pOutStream->writeEndElement();
209 
210 
211 }
212 void GLC_WorldTo3dxml::writeInstance3D(const GLC_StructInstance* pInstance, unsigned int parentId)
213 {
214  const GLC_StructReference* pRef= pInstance->structReference();
215  const unsigned int referenceId= m_ReferenceToIdHash.value(pRef);
216  const QString instanceMatrix(matrixString(pInstance->relativeMatrix()));
217 
218  m_pOutStream->writeStartElement("Instance3D");
219  m_pOutStream->writeAttribute("xsi:type", "Instance3DType");
220  m_pOutStream->writeAttribute("id", QString::number(++m_CurrentId));
221  m_pOutStream->writeAttribute("name", pInstance->name());
222  m_pOutStream->writeTextElement("IsAggregatedBy", QString::number(parentId));
223  m_pOutStream->writeTextElement("IsInstanceOf", QString::number(referenceId));
224  m_pOutStream->writeTextElement("RelativeMatrix", instanceMatrix);
225  if (pInstance->containsAttributes())
226  {
227  m_pOutStream->writeStartElement("Instance3DExtensionType");
229  m_pOutStream->writeEndElement(); // Instance3DExtensionType
230  }
231 
232  m_pOutStream->writeEndElement(); // Instance3D
233 
234  m_InstanceToIdHash.insert(pInstance, m_CurrentId);
235 }
236 
237 void GLC_WorldTo3dxml::writeInstanceRep(const GLC_3DRep* p3DRep, unsigned int parentId)
238 {
239  const unsigned int referenceId= m_ReferenceRepToIdHash.value(p3DRep);
240  m_pOutStream->writeStartElement("InstanceRep");
241  m_pOutStream->writeAttribute("xsi:type", "InstanceRepType");
242  m_pOutStream->writeAttribute("id", QString::number(++m_CurrentId));
243  m_pOutStream->writeAttribute("name", p3DRep->name());
244  m_pOutStream->writeTextElement("IsAggregatedBy", QString::number(parentId));
245  m_pOutStream->writeTextElement("IsInstanceOf", QString::number(referenceId));
246  m_pOutStream->writeEndElement();
247 
248  m_InstanceRep.insert(parentId);
249 
250 }
251 void GLC_WorldTo3dxml::setStreamWriterToFile(const QString& fileName)
252 {
253  delete m_pOutStream;
254  m_pOutStream= NULL;
255 
256  bool success= false;
257  if (NULL != m_p3dxmlArchive)
258  {
259  if (NULL != m_pCurrentZipFile)
260  {
261  m_pCurrentZipFile->close();
262  delete m_pOutStream;
263  delete m_pCurrentZipFile;
264  }
265  QuaZipNewInfo quazipNewInfo(fileName);
266  m_pCurrentZipFile= new QuaZipFile(m_p3dxmlArchive);
267  success= m_pCurrentZipFile->open(QIODevice::WriteOnly, quazipNewInfo);
268  if (success)
269  {
270  m_pOutStream= new QXmlStreamWriter(m_pCurrentZipFile);
271  }
272  }
273  else
274  {
275  delete m_pCurrentFile;
276  m_pCurrentFile= new QFile(m_AbsolutePath + fileName);
277  success= m_pCurrentFile->open(QIODevice::WriteOnly);
278  if (success)
279  {
280  m_pOutStream= new QXmlStreamWriter(m_pCurrentFile);
281  }
282  }
283 
284  if (NULL == m_pOutStream)
285  {
286  QString message(QString("GLC_WorldTo3dxml::setStreamWriterToFile Unable to create ") + fileName);
287  GLC_Exception fileException(message);
288  throw(fileException);
289  }
290  else
291  {
292  m_pOutStream->setAutoFormatting(true);
293  }
294 }
295 
297 {
298  setStreamWriterToFile("Manifest.xml");
299  m_pOutStream->writeStartDocument();
300 
301  m_pOutStream->writeStartElement("Manifest");
302  m_pOutStream->writeAttribute("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance");
303  m_pOutStream->writeAttribute("xsi:noNamespaceSchemaLocation", "Manifest.xsd");
304  m_pOutStream->writeTextElement("Root", QFileInfo(m_FileName).fileName());
305  m_pOutStream->writeEndElement();
306  m_pOutStream->writeEndElement();
307 
308  m_pOutStream->writeEndDocument();
309 }
310 
312 {
313  m_ReferenceToIdHash.clear();
314  m_InstanceToIdHash.clear();
315  m_ReferenceRepToIdHash.clear();
317  m_InstanceRep.clear();
318 
319  // Create the assembly file
320  setStreamWriterToFile(QFileInfo(m_FileName).fileName());
321  m_pOutStream->writeStartDocument();
322  m_pOutStream->writeStartElement("Model_3dxml");
323  m_pOutStream->writeAttribute("xmlns", "http://www.3ds.com/xsd/3DXML");
324  m_pOutStream->writeAttribute("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance");
325  m_pOutStream->writeAttribute("xmlns:xlink", "http://www.w3.org/1999/xlink");
326 
327  writeHeader();
328 
329  // Product Structure
330  m_pOutStream->writeStartElement("ProductStructure");
331  m_pOutStream->writeAttribute("root", "1");
333  m_pOutStream->writeEndElement(); // ProductStructure
334 
335  if (!m_ListOfOverLoadedOccurence.isEmpty())
336  {
337  m_pOutStream->writeStartElement("DefaultView");
338  const int size= m_ListOfOverLoadedOccurence.size();
339  for (int i= 0; i < size; ++i)
340  {
342  }
343  m_pOutStream->writeEndElement(); // DefaultView
344  }
345 
346  m_pOutStream->writeEndElement(); // Model_3dxml
347 
348  m_pOutStream->writeEndDocument();
349 }
350 
352 {
353  if (pOccurence->isOrphan())
354  {
355  writeReference3D(pOccurence->structReference());
356  }
357  else
358  {
359  // Reference 3D
360  GLC_StructReference* pCurrentRef= pOccurence->structReference();
361  if (!m_ReferenceToIdHash.contains(pCurrentRef))
362  {
363  writeReference3D(pCurrentRef);
364  // Reference Rep
365  if (pCurrentRef->hasRepresentation())
366  {
367  GLC_3DRep* pCurrentRep= dynamic_cast<GLC_3DRep*>(pCurrentRef->representationHandle());
368  if (NULL != pCurrentRep && !m_ReferenceRepToIdHash.contains(pCurrentRep))
369  {
370  writeReferenceRep(pCurrentRep);
371  }
372  }
373  }
374  // Instance 3D and instance rep
375  GLC_StructInstance* pCurrentInstance= pOccurence->structInstance();
376  if (!m_InstanceToIdHash.contains(pCurrentInstance))
377  {
378  // Instance 3D
379  const unsigned int parentId= m_ReferenceToIdHash.value(pOccurence->parent()->structReference());
380  writeInstance3D(pCurrentInstance, parentId);
381 
382  // Instance Rep
383  if (pCurrentRef->hasRepresentation())
384  {
385  GLC_3DRep* pCurrentRep= dynamic_cast<GLC_3DRep*>(pCurrentRef->representationHandle());
386  const unsigned int parentId= m_ReferenceToIdHash.value(pCurrentRef);
387  if (NULL != pCurrentRep && !m_InstanceRep.contains(parentId))
388  {
389  writeInstanceRep(pCurrentRep, parentId);
390  }
391  }
392  }
393  }
394 
395  // Process children
396  const int childCount= pOccurence->childCount();
397  for (int i= 0; i < childCount; ++i)
398  {
399  exportAssemblyFromOccurence(pOccurence->child(i));
400  }
401 
402  // Add occurence with Overload properties to a list
403  if (m_World.collection()->contains(pOccurence->id()))
404  {
405  GLC_3DViewInstance* pInstance= m_World.collection()->instanceHandle(pOccurence->id());
406  Q_ASSERT(NULL != pInstance);
407  const bool isVisible= pInstance->isVisible();
408 
409  // Test if render properties are overloaded
410  GLC_RenderProperties* pRenderProperties= pInstance->renderPropertiesHandle();
411  bool RenderOverloaded= !pRenderProperties->isDefault();
412  if (RenderOverloaded)
413  {
414  RenderOverloaded= false;
415  RenderOverloaded= (pRenderProperties->renderingMode() == glc::OverwriteMaterial);
416  RenderOverloaded= RenderOverloaded || (pRenderProperties->renderingMode() == glc::OverwriteTransparency);
417  RenderOverloaded= RenderOverloaded || (pRenderProperties->renderingMode() == glc::OverwriteTransparencyAndMaterial);
418  }
419 
420  const bool isOverload= !isVisible || RenderOverloaded || pOccurence->isFlexible();
421  if (isOverload)
422  {
423  m_ListOfOverLoadedOccurence.append(pOccurence);
424  }
425  }
426 
427 }
428 
430 {
431  QString resultMatrix;
432  const QChar spaceChar(' ');
433  // Rotation
434  resultMatrix+= QString::number(matrix.getData()[0], 'g', 16) + spaceChar;
435  resultMatrix+= QString::number(matrix.getData()[1], 'g', 16) + spaceChar;
436  resultMatrix+= QString::number(matrix.getData()[2], 'g', 16) + spaceChar;
437 
438  resultMatrix+= QString::number(matrix.getData()[4], 'g', 16) + spaceChar;
439  resultMatrix+= QString::number(matrix.getData()[5], 'g', 16) + spaceChar;
440  resultMatrix+= QString::number(matrix.getData()[6], 'g', 16) + spaceChar;
441 
442  resultMatrix+= QString::number(matrix.getData()[8], 'g', 16) + spaceChar;
443  resultMatrix+= QString::number(matrix.getData()[9], 'g', 16) + spaceChar;
444  resultMatrix+= QString::number(matrix.getData()[10], 'g', 16) + spaceChar;
445 
446  // Translation
447  resultMatrix+= QString::number(matrix.getData()[12], 'g', 16) + spaceChar;
448  resultMatrix+= QString::number(matrix.getData()[13], 'g', 16) + spaceChar;
449  resultMatrix+= QString::number(matrix.getData()[14], 'g', 16);
450 
451  return resultMatrix;
452 }
453 
454 void GLC_WorldTo3dxml::write3DRep(const GLC_3DRep* pRep, const QString& fileName)
455 {
456  setStreamWriterToFile(fileName);
457 
458  m_pOutStream->writeStartDocument();
459  m_pOutStream->writeStartElement("XMLRepresentation");
460  m_pOutStream->writeAttribute("version", "1.2");
461  m_pOutStream->writeAttribute("xmlns", "http://www.3ds.com/xsd/3DXML");
462  m_pOutStream->writeAttribute("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance");
463  m_pOutStream->writeAttribute("xmlns:xlink", "http://www.w3.org/1999/xlink");
464  m_pOutStream->writeAttribute("xsi:schemaLocation", "http://www.3ds.com/xsd/3DXML ./3DXMLMesh.xsd");
465 
466  m_pOutStream->writeStartElement("Root"); // Root
467  m_pOutStream->writeAttribute("xsi:type", "BagRepType");
468  m_pOutStream->writeAttribute("id", QString::number(++m_CurrentId));
469  const int bodyCount= pRep->numberOfBody();
470  for (int i= 0; i < bodyCount; ++i)
471  {
472  GLC_Mesh* pMesh= dynamic_cast<GLC_Mesh*>(pRep->geomAt(i));
473  if (NULL != pMesh)
474  {
475  writeGeometry(pMesh);
476  }
477  }
478  m_pOutStream->writeEndElement(); // Root
479 
480  m_pOutStream->writeEndElement(); // XMLRepresentation
481 
482  m_pOutStream->writeEndDocument();
483 }
484 
486 {
487  Q_ASSERT(m_ReferenceRepToIdHash.contains(pRep));
488  QString repName= pRep->name();
489  QString fileName;
491  {
492  QString newFileName= pRep->fileName();
493  // Test if the file name is encoded by GLC_Lib (Structure only loaded)
494  if (glc::isFileString(newFileName))
495  {
496  newFileName= glc::archiveEntryFileName(newFileName);
497  }
498  if (newFileName.isEmpty() || (glc::isArchiveString(newFileName)))
499  {
500  fileName= "urn:3DXML:NoFile_0.3DRep";
501  }
502  else
503  {
504  // Compute the relative fileName from the structure
505  QDir structureDir(m_AbsolutePath);
506  QString relativeFilePath= structureDir.relativeFilePath(newFileName);
507  fileName= "urn:3DXML:" + relativeFilePath;
508  }
509  }
510  else if (repName.isEmpty())
511  {
512  fileName= "urn:3DXML:Representation_0.3DRep";
513  }
514  else
515  {
516  fileName= "urn:3DXML:" + repName + ".3DRep";
517  }
518  return xmlFileName(fileName);
519 }
520 
522 {
523  // Get the list of material id
524  QList<GLC_uint> materialList= pMesh->materialIds();
525  const int materialCount= materialList.size();
526 
527  m_pOutStream->writeStartElement("Rep");
528  m_pOutStream->writeAttribute("xsi:type", "PolygonalRepType");
529  m_pOutStream->writeAttribute("id", QString::number(++m_CurrentId));
530  const double masterAccuracy= pMesh->getLodAccuracy(0);
531  m_pOutStream->writeAttribute("accuracy", QString::number(masterAccuracy));
532  m_pOutStream->writeAttribute("solid", "1");
533  const int lodCount= pMesh->lodCount();
534  if (lodCount > 1)
535  {
536  // The mesh contains LOD
537  for (int i= 1; i < lodCount; ++i)
538  {
539  const double lodAccuracy= pMesh->getLodAccuracy(i);
540  m_pOutStream->writeStartElement("PolygonalLOD");
541  m_pOutStream->writeAttribute("accuracy", QString::number(lodAccuracy));
542  m_pOutStream->writeStartElement("Faces");
543  for (int matIndex= 0; matIndex < materialCount; ++matIndex)
544  {
545  const GLC_uint materialId= materialList.at(matIndex);
546  if (pMesh->lodContainsMaterial(i, materialId))
547  {
548  writeGeometryFace(pMesh, i, materialId);
549  }
550  }
551  m_pOutStream->writeEndElement(); // Faces
552  m_pOutStream->writeEndElement(); // PolygonalLOD
553  }
554  }
555 
556  // Master LOD
557  m_pOutStream->writeStartElement("Faces");
558  for (int matIndex= 0; matIndex < materialCount; ++matIndex)
559  {
560  const GLC_uint materialId= materialList.at(matIndex);
561  if (pMesh->lodContainsMaterial(0, materialId))
562  {
563  writeGeometryFace(pMesh, 0, materialId);
564  }
565  }
566  m_pOutStream->writeEndElement(); // Faces
567  if (!pMesh->wireDataIsEmpty())
568  {
569  writeEdges(pMesh);
570  }
571 
572  // Save Bulk data
573  m_pOutStream->writeStartElement("VertexBuffer");
574  {
575  // Get positions
576  GLfloatVector positionVector= pMesh->positionVector();
577  QString positions;
578  const int size= positionVector.size();
579  for (int i= 0; i < size; i+=3)
580  {
581  positions.append(QString::number(positionVector.at(i)));
582  positions.append(' ');
583  positions.append(QString::number(positionVector.at(i + 1)));
584  positions.append(' ');
585  positions.append(QString::number(positionVector.at(i + 2)));
586  positions.append(", ");
587  }
588  positions.remove(positions.size() - 2, 2);
589  m_pOutStream->writeTextElement("Positions", positions);
590  }
591  {
592  // Get normals
593  GLfloatVector normalVector= pMesh->normalVector();
594  QString normals;
595  const int size= normalVector.size();
596  for (int i= 0; i < size; i+=3)
597  {
598  normals.append(QString::number(normalVector.at(i)));
599  normals.append(' ');
600  normals.append(QString::number(normalVector.at(i + 1)));
601  normals.append(' ');
602  normals.append(QString::number(normalVector.at(i + 2)));
603  normals.append(", ");
604  }
605  normals.remove(normals.size() - 2, 2);
606  m_pOutStream->writeTextElement("Normals", normals);
607  }
608  {
609  // Get texture coordinates
610  GLfloatVector texelVector= pMesh->texelVector();
611  if (!texelVector.isEmpty())
612  {
613  QString texels;
614  const int size= texelVector.size();
615  for (int i= 0; i < size; i+=2)
616  {
617  texels.append(QString::number(texelVector.at(i)));
618  texels.append(' ');
619  texels.append(QString::number(texelVector.at(i + 1)));
620  texels.append(", ");
621  }
622  texels.remove(texels.size() - 2, 2);
623 
624  m_pOutStream->writeStartElement("TextureCoordinates");
625  m_pOutStream->writeAttribute("dimension", "2D");
626  m_pOutStream->writeAttribute("channel", "0");
627  m_pOutStream->writeCharacters(texels);
628  m_pOutStream->writeEndElement(); // TexturesCoordinates
629  }
630  }
631 
632 
633  m_pOutStream->writeEndElement(); // VertexBuffer
634  m_pOutStream->writeEndElement(); // Rep
635 
636 }
637 void GLC_WorldTo3dxml::writeGeometryFace(const GLC_Mesh* pMesh, int lod, GLC_uint materialId)
638 {
639  m_pOutStream->writeStartElement("Face");
640  if (pMesh->containsTriangles(lod, materialId))
641  {
642  QVector<GLuint> triangleIndex= pMesh->getTrianglesIndex(lod, materialId);
643  QString indexString;
644  const int indexSize= triangleIndex.size();
645  for (int index= 0; index < indexSize; ++index)
646  {
647  indexString.append(QString::number(triangleIndex.at(index)));
648  indexString.append(' ');
649  }
650  indexString.remove(indexString.size() - 1, 1);
651  m_pOutStream->writeAttribute("triangles", indexString);
652  }
653  if (pMesh->containsStrips(lod, materialId))
654  {
655  QList<QVector<GLuint> > stripsIndex= pMesh->getStripsIndex(lod, materialId);
656  QString indexStrips;
657  const int stripCount= stripsIndex.size();
658  for (int stripIndex= 0; stripIndex < stripCount; ++stripIndex)
659  {
660  QVector<GLuint> currentStripIndex= stripsIndex.at(stripIndex);
661  QString currentIndex;
662  const int indexSize= currentStripIndex.size();
663  for (int index= 0; index < indexSize; ++index)
664  {
665  currentIndex.append(QString::number(currentStripIndex.at(index)));
666  currentIndex.append(' ');
667  }
668  currentIndex.remove(currentIndex.size() - 1, 1);
669  indexStrips.append(currentIndex);
670  indexStrips.append(',');
671  }
672  indexStrips.remove(indexStrips.size() - 1, 1);
673  m_pOutStream->writeAttribute("strips", indexStrips);
674  }
675  if (pMesh->containsFans(lod, materialId))
676  {
677  QList<QVector<GLuint> > fansIndex= pMesh->getFansIndex(lod, materialId);
678  QString indexFans;
679  const int fanCount= fansIndex.size();
680  for (int fanIndex= 0; fanIndex < fanCount; ++fanIndex)
681  {
682  QVector<GLuint> currentFanIndex= fansIndex.at(fanIndex);
683  QString currentIndex;
684  const int indexSize= currentFanIndex.size();
685  for (int index= 0; index < indexSize; ++index)
686  {
687  currentIndex.append(QString::number(currentFanIndex.at(index)));
688  currentIndex.append(' ');
689  }
690  currentIndex.remove(currentIndex.size() - 1, 1);
691  indexFans.append(currentIndex);
692  indexFans.append(',');
693  }
694  indexFans.remove(indexFans.size() - 1, 1);
695  m_pOutStream->writeAttribute("fans", indexFans);
696  }
697 
698  writeSurfaceAttributes(pMesh->material(materialId));
699 
700  m_pOutStream->writeEndElement(); // Face
701 
702 }
703 
705 {
706  QColor diffuseColor= pMaterial->diffuseColor();
707  m_pOutStream->writeStartElement("SurfaceAttributes");
708  if (m_ExportMaterial)
709  {
710  const QString material3dxmlId=(QString::number(m_MaterialIdToMaterialId.value(pMaterial->id())));
711  m_pOutStream->writeStartElement("MaterialApplication");
712  m_pOutStream->writeAttribute("xsi:type", "MaterialApplicationType");
713  m_pOutStream->writeAttribute("mappingChannel", "0");
714  m_pOutStream->writeStartElement("MaterialId");
715  m_pOutStream->writeAttribute("id", "urn:3DXML:CATMaterialRef.3dxml#" + material3dxmlId);
716  m_pOutStream->writeEndElement(); // MaterialId
717  m_pOutStream->writeEndElement(); // MaterialApplication
718  }
719  else
720  {
721  m_pOutStream->writeStartElement("Color");
722  m_pOutStream->writeAttribute("xsi:type", "RGBAColorType");
723  m_pOutStream->writeAttribute("red", QString::number(diffuseColor.redF()));
724  m_pOutStream->writeAttribute("green", QString::number(diffuseColor.greenF()));
725  m_pOutStream->writeAttribute("blue", QString::number(diffuseColor.blueF()));
726  m_pOutStream->writeAttribute("alpha", QString::number(diffuseColor.alphaF()));
727  m_pOutStream->writeEndElement(); // Color
728  }
729  m_pOutStream->writeEndElement(); // SurfaceAttributes
730 }
731 
733 {
734  m_pOutStream->writeStartElement("Edges");
735  writeLineAttributes(pMesh->wireColor());
736 
737  GLfloatVector positionVector= pMesh->wirePositionVector();
738  const int polylineCount= pMesh->wirePolylineCount();
739  for (int i= 0; i < polylineCount; ++i)
740  {
741  m_pOutStream->writeStartElement("Polyline");
742  QString polylinePosition;
743  const GLuint offset= pMesh->wirePolylineOffset(i);
744  const GLsizei size= pMesh->wirePolylineSize(i);
745  for (GLsizei index= 0; index < size; ++index)
746  {
747  const int startIndex= 3 * (offset + index);
748  polylinePosition.append(QString::number(positionVector.at(startIndex)));
749  polylinePosition.append(' ');
750  polylinePosition.append(QString::number(positionVector.at(startIndex + 1)));
751  polylinePosition.append(' ');
752  polylinePosition.append(QString::number(positionVector.at(startIndex + 2)));
753  polylinePosition.append(',');
754  }
755  polylinePosition.remove(polylinePosition.size() - 1, 1);
756  m_pOutStream->writeAttribute("vertices", polylinePosition);
757  m_pOutStream->writeEndElement(); // Polyline
758  }
759  m_pOutStream->writeEndElement(); // Edges
760 }
761 
762 void GLC_WorldTo3dxml::writeLineAttributes(const QColor& color)
763 {
764  m_pOutStream->writeStartElement("LineAttributes");
765  m_pOutStream->writeAttribute("lineType", "SOLID");
766  m_pOutStream->writeAttribute("thickness", "1");
767  m_pOutStream->writeStartElement("Color");
768  m_pOutStream->writeAttribute("xsi:type", "RGBAColorType");
769  m_pOutStream->writeAttribute("red", QString::number(color.redF()));
770  m_pOutStream->writeAttribute("green", QString::number(color.greenF()));
771  m_pOutStream->writeAttribute("blue", QString::number(color.blueF()));
772  m_pOutStream->writeAttribute("alpha", QString::number(color.alphaF()));
773  m_pOutStream->writeEndElement(); // Color
774  m_pOutStream->writeEndElement(); // LineAttributes
775 }
776 
778 {
779  const GLC_uint materialId= pMaterial->id();
780  QString materialName;
781  if (pMaterial->name().isEmpty())
782  {
783  materialName= "Material_0" + QString::number(materialId);
784  }
785  else
786  {
787  materialName= symplifyName(pMaterial->name());
788 
789  // If the materialName is already uses append material id to the name
790  QSet<QString> materialsName= QSet<QString>::fromList(m_MaterialIdToMaterialName.values());
791  while (materialsName.contains(materialName))
792  {
793  materialName= materialName + '_' + QString::number(materialId);
794  }
795  }
796 
797  m_MaterialIdToMaterialName.insert(materialId, materialName);
798 
799  const QString fileName= xmlFileName(materialName + "_Rendering.3DRep");
800  setStreamWriterToFile(fileName);
801 
802  // Begin to write the material file
803  m_pOutStream->writeStartDocument();
804  m_pOutStream->writeStartElement("Osm");
805  m_pOutStream->writeAttribute("xmlns", "http://www.3ds.com/xsd/osm.xsd");
806  m_pOutStream->writeAttribute("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance");
807  m_pOutStream->writeAttribute("xmlns:xlink", "http://www.w3.org/1999/xlink");
808  m_pOutStream->writeAttribute("xsi:schemaLocation", "http://www.3ds.com/xsd/3DXML ./osm.xsd");
809  m_pOutStream->writeStartElement("Feature");
810  m_pOutStream->writeAttribute("Alias", "RenderingRootFeature");
811  m_pOutStream->writeAttribute("Id", "1");
812  m_pOutStream->writeAttribute("StartUp", "RenderingRootFeature");
813  m_pOutStream->writeEndElement(); // Feature
814  m_pOutStream->writeStartElement("Feature");
815  m_pOutStream->writeAttribute("Alias", "RenderingFeature");
816  m_pOutStream->writeAttribute("Id", "2");
817  m_pOutStream->writeAttribute("StartUp", "RenderingFeature");
818  m_pOutStream->writeAttribute("Aggregating", "1");
819 
820  writeMaterialAttributtes("Filtering", "int", "1");
821  writeMaterialAttributtes("Rotation", "double", "0");
822  writeMaterialAttributtes("PreviewType", "int", "1");
823  writeMaterialAttributtes("AmbientCoef", "double", "1");
824  writeMaterialAttributtes("DiffuseCoef", "double", "1");
825  writeMaterialAttributtes("SpecularCoef", "double", "1");
826  writeMaterialAttributtes("EmissiveCoef", "double", "0");
827  writeMaterialAttributtes("AlphaTest", "boolean", "false");
828  writeMaterialAttributtes("TextureFunction", "int", "0");
829  writeMaterialAttributtes("MappingType", "int", "2");
830  writeMaterialAttributtes("Refraction", "double", "1");
831  writeMaterialAttributtes("TextureDimension", "int", "2");
832  writeMaterialAttributtes("TranslationU", "double", "0");
833  writeMaterialAttributtes("TranslationV", "double", "0");
834  writeMaterialAttributtes("FlipU", "boolean", "false");
835  writeMaterialAttributtes("FlipV", "boolean", "false");
836  writeMaterialAttributtes("WrappingModeU", "int", "1");
837  writeMaterialAttributtes("WrappingModeV", "int", "1");
838  writeMaterialAttributtes("ScaleU", "double", "1");
839  writeMaterialAttributtes("ScaleV", "double", "1");
840  writeMaterialAttributtes("Reflectivity", "double", "0.1");
841  writeMaterialAttributtes("BlendColor", "double", "[1,1,1]");
842 
843  writeMaterialAttributtes("Transparency", "double", QString::number(1.0 - pMaterial->opacity()));
844  double specularExponent= pMaterial->shininess() / 128.0;
845  writeMaterialAttributtes("SpecularExponent", "double", QString::number(specularExponent));
846  writeMaterialAttributtes("DiffuseColor", "double", colorToString(pMaterial->diffuseColor()));
847  writeMaterialAttributtes("SpecularColor", "double", colorToString(pMaterial->specularColor()));
848  writeMaterialAttributtes("AmbientColor", "double", colorToString(pMaterial->ambientColor()));
849  writeMaterialAttributtes("EmissiveColor", "double", colorToString(pMaterial->emissiveColor()));
850  if (pMaterial->hasTexture())
851  {
852  Q_ASSERT(m_MaterialIdTo3dxmlImageId.contains(pMaterial->id()));
853  const QString imageId(QString::number(m_MaterialIdTo3dxmlImageId.value(pMaterial->id())));
854 
855  writeMaterialAttributtes("TextureImage", "external", "urn:3DXML:CATRepImage.3dxml#" + imageId);
856  }
857  m_pOutStream->writeEndElement(); // Feature
858  m_pOutStream->writeEndElement(); // Osm
859  m_pOutStream->writeEndDocument();
860 }
861 
862 void GLC_WorldTo3dxml::writeMaterialAttributtes(const QString& name, const QString& type, const QString& value)
863 {
864  m_pOutStream->writeStartElement("Attr");
865  m_pOutStream->writeAttribute("Name", name);
866  m_pOutStream->writeAttribute("Type", type);
867  m_pOutStream->writeAttribute("Value", value);
868  m_pOutStream->writeEndElement(); // Attr
869 }
870 
871 QString GLC_WorldTo3dxml::colorToString(const QColor& color)
872 {
873  return QString('[' + QString::number(color.redF()) + ',' + QString::number(color.greenF()) + ',' + QString::number(color.blueF()) + ']');
874 }
875 
876 void GLC_WorldTo3dxml::writeCatRepImageFile(const QList<GLC_Material*>& materialList)
877 {
878  unsigned int currentId= 0;
879  const QString fileName("CATRepImage.3dxml");
880  setStreamWriterToFile(fileName);
881 
882  // Begin to write the rep image file
883  m_pOutStream->writeStartDocument();
884  m_pOutStream->writeStartElement("Model_3dxml");
885  m_pOutStream->writeAttribute("xmlns", "http://www.3ds.com/xsd/3DXML");
886  m_pOutStream->writeAttribute("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance");
887  m_pOutStream->writeAttribute("xmlns:xlink", "http://www.w3.org/1999/xlink");
888  m_pOutStream->writeAttribute("xsi:schemaLocation", "http://www.3ds.com/xsd/3DXML ./3DXML.xsd");
889  writeHeader();
890  m_pOutStream->writeStartElement("CATRepImage");
891  m_pOutStream->writeAttribute("root", QString::number(currentId));
892  const int size= materialList.size();
893  for (int i= 0; i < size; ++i)
894  {
895  writeCATRepresentationImage(materialList.at(i), ++currentId);
896  }
897  m_pOutStream->writeEndElement(); // CATRepImage
898  m_pOutStream->writeEndElement(); // Model_3dxml
899  m_pOutStream->writeEndDocument();
900 }
901 
903 {
904  Q_ASSERT(pMat->hasTexture());
905  m_MaterialIdTo3dxmlImageId.insert(pMat->id(), id);
906 
907  const QString imageName= pMat->name();
908  QString imageFileName;
909  QString imageFormat;
910  const QString textureFileName= pMat->textureHandle()->fileName();
911  if (textureFileName.isEmpty())
912  {
913  imageFormat= "jpg";
914  if (imageName.isEmpty())
915  {
916  imageFileName= xmlFileName("textureImage." + imageFormat);
917  }
918  else
919  {
920  imageFileName= xmlFileName(imageName + '.' + imageFormat);
921  }
922  }
923  else
924  {
925  imageFormat= QFileInfo(textureFileName).suffix();
926  imageFileName= xmlFileName(QFileInfo(textureFileName).fileName());
927  }
928  m_MaterialIdToTexture3dxmlName.insert(pMat->id(), imageFileName);
929 
930  m_pOutStream->writeStartElement("CATRepresentationImage");
931  m_pOutStream->writeAttribute("xsi:type", "CATRepresentationImageType");
932  m_pOutStream->writeAttribute("id", QString::number(id));
933  m_pOutStream->writeAttribute("name", imageName);
934  m_pOutStream->writeAttribute("format", imageFormat);
935  m_pOutStream->writeAttribute("associatedFile", QString("urn:3DXML:" + imageFileName));
936 
937  m_pOutStream->writeTextElement("PLM_ExternalID", imageName);
938  m_pOutStream->writeTextElement("V_PrimaryMimeType", imageFormat);
939  m_pOutStream->writeTextElement("V_PrimaryFileName", imageFileName);
940  m_pOutStream->writeEndElement(); // CATRepresentationImage
941 }
942 
944 {
946  m_MaterialIdToMaterialId.clear();
949 
950  // Get the list of material
951  QList<GLC_Material*> materialList= m_World.listOfMaterials();
952 
953  // Create the list of textured material and modified material list
954  QList<GLC_Material*> texturedMaterial;
955  const int size= materialList.size();
956  for (int i= 0; i < size; ++i)
957  {
958  if (materialList.at(i)->hasTexture())
959  {
960  texturedMaterial.append(materialList.at(i));
961  }
962  }
963 
964  if (!texturedMaterial.isEmpty())
965  {
966  writeCatRepImageFile(texturedMaterial);
967  writeImageFileIn3dxml(texturedMaterial);
968  }
969 
970 
971  // Write material 3DRep in the 3DXML
972  for (int i= 0; i < size; ++i)
973  {
974  writeMaterial(materialList.at(i));
975  }
976 
977  writeCatMaterialRef(materialList);
978 
979 
980 
981 }
982 void GLC_WorldTo3dxml::writeImageFileIn3dxml(const QList<GLC_Material*>& materialList)
983 {
984  const int size= materialList.size();
985  Q_ASSERT(size == m_MaterialIdToTexture3dxmlName.size());
986  for (int i= 0; i < size; ++i)
987  {
988  const GLC_Material* pCurrentMaterial= materialList.at(i);
989  const GLC_Texture* pTexture= pCurrentMaterial->textureHandle();
990  const QString imageName(m_MaterialIdToTexture3dxmlName.value(pCurrentMaterial->id()));
991  // Get the texture image
992  if (!pTexture->fileName().isEmpty())
993  {
994  // Try to load the texture
995  QImage textureImage(pTexture->fileName());
996  if (! textureImage.isNull())
997  {
998  addImageTextureTo3dxml(textureImage, imageName);
999  }
1000  else
1001  {
1002  addImageTextureTo3dxml(pTexture->imageOfTexture(), imageName);
1003  }
1004  }
1005  else
1006  {
1007  addImageTextureTo3dxml(pTexture->imageOfTexture(), imageName);
1008  }
1009  }
1010 
1011 }
1012 
1013 void GLC_WorldTo3dxml::writeCatMaterialRef(const QList<GLC_Material*>& materialList)
1014 {
1015  const QString fileName("CATMaterialRef.3dxml");
1016 
1017  setStreamWriterToFile(fileName);
1018 
1019  unsigned int currentId= 0;
1020 
1021  // Begin to write the rep image file
1022  m_pOutStream->writeStartDocument();
1023  m_pOutStream->writeStartElement("Model_3dxml");
1024  m_pOutStream->writeAttribute("xmlns", "http://www.3ds.com/xsd/3DXML");
1025  m_pOutStream->writeAttribute("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance");
1026  m_pOutStream->writeAttribute("xmlns:xlink", "http://www.w3.org/1999/xlink");
1027  m_pOutStream->writeAttribute("xsi:schemaLocation", "http://www.3ds.com/xsd/3DXML ./3DXML.xsd");
1028  writeHeader();
1029  m_pOutStream->writeStartElement("CATMaterialRef");
1030  m_pOutStream->writeAttribute("root", QString::number(currentId));
1031  const int size= materialList.size();
1032  for (int i= 0; i < size; ++i)
1033  {
1034  writeMaterialToCatMaterialRef(materialList.at(i), &(++currentId));
1035  }
1036  m_pOutStream->writeEndElement(); // CATMaterialRef
1037  m_pOutStream->writeEndElement(); // Model_3dxml
1038  m_pOutStream->writeEndDocument();
1039 }
1040 
1042 {
1043  const QString materialName= m_MaterialIdToMaterialName.value(pMat->id());
1044  m_MaterialIdToMaterialId.insert(pMat->id(), *id);
1045 
1046  m_pOutStream->writeStartElement("CATMatReference");
1047  m_pOutStream->writeAttribute("xsi:type", "CATMatReferenceType");
1048  m_pOutStream->writeAttribute("id", QString::number(*id));
1049  m_pOutStream->writeAttribute("name", materialName);
1050  m_pOutStream->writeTextElement("PLM_ExternalID", materialName);
1051  m_pOutStream->writeEndElement(); // CATMatReference
1052 
1053  const QString domainName= materialName + "_Rendering";
1054  m_pOutStream->writeStartElement("MaterialDomain");
1055  m_pOutStream->writeAttribute("xsi:type", "MaterialDomainType");
1056  m_pOutStream->writeAttribute("id", QString::number(++(*id)));
1057  m_pOutStream->writeAttribute("name", domainName);
1058  m_pOutStream->writeAttribute("format", "TECHREP");
1059  const QString associatedFileName("urn:3DXML:" + domainName + ".3DRep");
1060  m_pOutStream->writeAttribute("associatedFile", associatedFileName);
1061  m_pOutStream->writeAttribute("version", "1.0");
1062  m_pOutStream->writeTextElement("PLM_ExternalID", domainName);
1063  if (pMat->hasTexture())
1064  {
1065  m_pOutStream->writeStartElement("PLMRelation");
1066  m_pOutStream->writeTextElement("C_Semantics", "Reference");
1067  m_pOutStream->writeTextElement("C_Role", "CATMaterialReferenceToTextureLink");
1068  m_pOutStream->writeStartElement("Ids");
1069  const QString imageId(QString::number(m_MaterialIdTo3dxmlImageId.value(pMat->id())));
1070  m_pOutStream->writeTextElement("id", "urn:3DXML:CATRepImage.3dxml#" + imageId);
1071  m_pOutStream->writeEndElement(); // Ids
1072  m_pOutStream->writeEndElement(); // PLMRelation
1073  }
1074  m_pOutStream->writeTextElement("V_MatDomain", "Rendering");
1075  m_pOutStream->writeEndElement(); // MaterialDomain
1076 
1077  m_pOutStream->writeStartElement("MaterialDomainInstance");
1078  m_pOutStream->writeAttribute("xsi:type", "MaterialDomainInstanceType");
1079  m_pOutStream->writeAttribute("id", QString::number(++(*id)));
1080  m_pOutStream->writeAttribute("name", materialName + ".1");
1081  m_pOutStream->writeTextElement("PLM_ExternalID", materialName + ".1");
1082  m_pOutStream->writeTextElement("IsAggregatedBy", QString::number((*id) - 2));
1083  m_pOutStream->writeTextElement("IsInstanceOf", QString::number((*id) - 1));
1084  m_pOutStream->writeEndElement(); // MaterialDomainInstance
1085 }
1086 
1087 void GLC_WorldTo3dxml::addImageTextureTo3dxml(const QImage& image, const QString& fileName)
1088 {
1089  delete m_pOutStream;
1090  m_pOutStream= NULL;
1091 
1092  bool success= false;
1093  if (NULL != m_p3dxmlArchive)
1094  {
1095  if (NULL != m_pCurrentZipFile)
1096  {
1097  m_pCurrentZipFile->close();
1098  delete m_pOutStream;
1099  delete m_pCurrentZipFile;
1100  }
1101  QuaZipNewInfo quazipNewInfo(fileName);
1102  m_pCurrentZipFile= new QuaZipFile(m_p3dxmlArchive);
1103  success= m_pCurrentZipFile->open(QIODevice::WriteOnly, quazipNewInfo);
1104  if (success)
1105  {
1106  image.save(m_pCurrentZipFile, QFileInfo(fileName).suffix().toLatin1().constData());
1107  m_pCurrentZipFile->close();
1108  delete m_pCurrentZipFile;
1109  m_pCurrentZipFile= NULL;
1110  }
1111  }
1112  else
1113  {
1114  delete m_pCurrentFile;
1115  m_pCurrentFile= new QFile(m_AbsolutePath + fileName);
1116  success= m_pCurrentFile->open(QIODevice::WriteOnly);
1117  if (success)
1118  {
1119  image.save(m_pCurrentFile, QFileInfo(fileName).suffix().toLatin1().constData());
1120  delete m_pCurrentFile;
1121  m_pCurrentFile= NULL;
1122  }
1123  }
1124 }
1125 
1126 QString GLC_WorldTo3dxml::xmlFileName(QString fileName)
1127 {
1128  QString prefix;
1129  if (fileName.contains("urn:3DXML:"))
1130  {
1131  prefix= "urn:3DXML:";
1132  fileName.remove(prefix);
1133  }
1134 
1135  if (m_ExportType != StructureOnly)
1136  {
1137  fileName= symplifyName(fileName);
1138  }
1139 
1140  QString newName;
1141  if (!m_3dxmlFileSet.contains(prefix + fileName))
1142  {
1143  fileName.prepend(prefix);
1144  m_3dxmlFileSet << fileName;
1145  newName= fileName;
1146  }
1147  else
1148  {
1149  newName= QFileInfo(fileName).completeBaseName() + QString::number(++m_FileNameIncrement) + '.' + QFileInfo(fileName).suffix();
1150  newName.prepend(prefix);
1151  }
1152  return newName;
1153 }
1154 
1156 {
1157  QList<QString> attributesNames= pAttributes->names();
1158  const int size= attributesNames.size();
1159  for (int i= 0; i < size; ++i)
1160  {
1161  const QString name= attributesNames.at(i);
1162  QString value= pAttributes->value(name);
1163  m_pOutStream->writeStartElement("Attribute");
1164  m_pOutStream->writeAttribute("name", name);
1165  if (name == "FILEPATH")
1166  {
1167  QDir thisPath(m_AbsolutePath);
1168  value= thisPath.relativeFilePath(value);
1169  }
1170  m_pOutStream->writeAttribute("value", value);
1171  m_pOutStream->writeEndElement(); // Attribute
1172  }
1173 }
1174 
1176 {
1177  QList<unsigned int> path= instancePath(pOccurence);
1178 
1179  GLC_3DViewInstance* pInstance= m_World.collection()->instanceHandle(pOccurence->id());
1180  Q_ASSERT(NULL != pInstance);
1181  const bool isVisible= pOccurence->isVisible();
1182  m_pOutStream->writeStartElement("DefaultViewProperty");
1183  m_pOutStream->writeStartElement("OccurenceId");
1184  const QString prefix= "urn:3DXML:" + QFileInfo(m_FileName).fileName() + "#";
1185  const int pathSize= path.size();
1186  for (int i= 0; i < pathSize; ++i)
1187  {
1188  m_pOutStream->writeTextElement("id", prefix + QString::number(path.at(i)));
1189  }
1190  m_pOutStream->writeEndElement(); // OccurenceId
1191 
1192  if (pOccurence->isFlexible())
1193  {
1194  m_pOutStream->writeTextElement("RelativePosition", matrixString(pOccurence->occurrenceRelativeMatrix()));
1195  }
1196 
1197  if (!isVisible || !pInstance->renderPropertiesHandle()->isDefault())
1198  {
1199  qDebug() << "(!isVisible || !pInstance->renderPropertiesHandle()->isDefault())";
1200  m_pOutStream->writeStartElement("GraphicProperties");
1201  m_pOutStream->writeAttribute("xsi:type", "GraphicPropertiesType");
1202  if (! isVisible)
1203  {
1204  m_pOutStream->writeStartElement("GeneralAttributes");
1205  m_pOutStream->writeAttribute("xsi:type", "GeneralAttributesType");
1206  m_pOutStream->writeAttribute("visible", "false");
1207  m_pOutStream->writeAttribute("selectable", "true");
1208  m_pOutStream->writeEndElement(); // GeneralAttributes
1209  }
1210  if (!pInstance->renderPropertiesHandle()->isDefault())
1211  {
1212  const GLC_RenderProperties* pProperties= pInstance->renderPropertiesHandle();
1213  if ((pProperties->renderingMode() == glc::OverwriteTransparency))
1214  {
1215  m_pOutStream->writeStartElement("SurfaceAttributes");
1216  m_pOutStream->writeAttribute("xsi:type", "SurfaceAttributesType");
1217  m_pOutStream->writeStartElement("Color");
1218  m_pOutStream->writeAttribute("xsi:type", "RGBAColorType");
1219  m_pOutStream->writeAttribute("red", "-1");
1220  m_pOutStream->writeAttribute("green", "-1");
1221  m_pOutStream->writeAttribute("blue", "-1");
1222  m_pOutStream->writeAttribute("alpha", QString::number(pProperties->overwriteTransparency()));
1223  m_pOutStream->writeEndElement(); // Color
1224  m_pOutStream->writeEndElement(); // SurfaceAttributes
1225  }
1226  else if ((pProperties->renderingMode() == glc::OverwriteTransparencyAndMaterial))
1227  {
1228  GLC_Material* pMaterial= pProperties->overwriteMaterial();
1229  m_pOutStream->writeStartElement("SurfaceAttributes");
1230  m_pOutStream->writeAttribute("xsi:type", "SurfaceAttributesType");
1231  m_pOutStream->writeStartElement("Color");
1232  m_pOutStream->writeAttribute("xsi:type", "RGBAColorType");
1233  m_pOutStream->writeAttribute("red", QString::number(pMaterial->diffuseColor().redF()));
1234  m_pOutStream->writeAttribute("green", QString::number(pMaterial->diffuseColor().greenF()));
1235  m_pOutStream->writeAttribute("blue", QString::number(pMaterial->diffuseColor().blueF()));
1236  m_pOutStream->writeAttribute("alpha", QString::number(pProperties->overwriteTransparency()));
1237  m_pOutStream->writeEndElement(); // Color
1238  m_pOutStream->writeEndElement(); // SurfaceAttributes
1239  }
1240  else if ((pProperties->renderingMode() == glc::OverwriteMaterial))
1241  {
1242  GLC_Material* pMaterial= pProperties->overwriteMaterial();
1243  m_pOutStream->writeStartElement("SurfaceAttributes");
1244  m_pOutStream->writeAttribute("xsi:type", "SurfaceAttributesType");
1245  m_pOutStream->writeStartElement("Color");
1246  m_pOutStream->writeAttribute("xsi:type", "RGBAColorType");
1247  m_pOutStream->writeAttribute("red", QString::number(pMaterial->diffuseColor().redF()));
1248  m_pOutStream->writeAttribute("green", QString::number(pMaterial->diffuseColor().greenF()));
1249  m_pOutStream->writeAttribute("blue", QString::number(pMaterial->diffuseColor().blueF()));
1250  m_pOutStream->writeAttribute("alpha", QString::number(pMaterial->opacity()));
1251  m_pOutStream->writeEndElement(); // Color
1252  m_pOutStream->writeEndElement(); // SurfaceAttributes
1253  }
1254 
1255  }
1256  m_pOutStream->writeEndElement(); // GraphicProperties
1257  }
1258  m_pOutStream->writeEndElement(); // DefaultViewProperty
1259 }
1260 
1262 {
1263  bool continuValue= true;
1264  if (NULL != m_pReadWriteLock)
1265  {
1266  Q_ASSERT(NULL != m_pIsInterupted);
1267  m_pReadWriteLock->lockForRead();
1268  continuValue= !(*m_pIsInterupted);
1269  m_pReadWriteLock->unlock();
1270  }
1271  return continuValue;
1272 }
1273 
1274 QString GLC_WorldTo3dxml::symplifyName(QString name)
1275 {
1276  const int nameSize= name.size();
1277  for (int i= 0; i < nameSize; ++i)
1278  {
1279  const QChar curChar= name.at(i);
1280  bool simplifyCharacter= !curChar.isLetterOrNumber() && (curChar != '.');
1281  simplifyCharacter= simplifyCharacter && (curChar != '/') && (curChar != '\\');
1282  if (simplifyCharacter)
1283  {
1284  name.replace(i, 1, '_');
1285  }
1286  }
1287 
1288  return name;
1289 }
1290 
1291 QList<unsigned int> GLC_WorldTo3dxml::instancePath(const GLC_StructOccurence* pOccurence)
1292 {
1293  QList<unsigned int> path;
1294  if (!pOccurence->isOrphan())
1295  {
1296  GLC_StructInstance* pInstance= pOccurence->structInstance();
1297  Q_ASSERT(m_InstanceToIdHash.contains(pInstance));
1298  path.prepend(m_InstanceToIdHash.value(pInstance));
1299  QList<unsigned int> subPath(instancePath(pOccurence->parent()));
1300  subPath.append(path);
1301  path= subPath;
1302  }
1303  return path;
1304 }

©2005-2013 Laurent Ribon