DXFLoader.h 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. /*
  2. Open Asset Import Library (ASSIMP)
  3. ----------------------------------------------------------------------
  4. Copyright (c) 2006-2008, ASSIMP Development Team
  5. All rights reserved.
  6. Redistribution and use of this software in source and binary forms,
  7. with or without modification, are permitted provided that the
  8. following conditions are met:
  9. * Redistributions of source code must retain the above
  10. copyright notice, this list of conditions and the
  11. following disclaimer.
  12. * Redistributions in binary form must reproduce the above
  13. copyright notice, this list of conditions and the
  14. following disclaimer in the documentation and/or other
  15. materials provided with the distribution.
  16. * Neither the name of the ASSIMP team, nor the names of its
  17. contributors may be used to endorse or promote products
  18. derived from this software without specific prior
  19. written permission of the ASSIMP Development Team.
  20. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  21. "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  22. LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  23. A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  24. OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  25. SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  26. LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  27. DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  28. THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  29. (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  30. OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  31. ----------------------------------------------------------------------
  32. */
  33. /** @file Declaration of the .dxf importer class. */
  34. #ifndef AI_DXFLOADER_H_INCLUDED
  35. #define AI_DXFLOADER_H_INCLUDED
  36. namespace Assimp {
  37. // ---------------------------------------------------------------------------
  38. /** DXF importer class
  39. */
  40. class DXFImporter : public BaseImporter
  41. {
  42. friend class Importer;
  43. protected:
  44. /** Constructor to be privately used by Importer */
  45. DXFImporter();
  46. /** Destructor, private as well */
  47. ~DXFImporter();
  48. // describes a single layer in the DXF file
  49. struct LayerInfo
  50. {
  51. LayerInfo()
  52. {
  53. name[0] = '\0';
  54. }
  55. char name[4096];
  56. // face buffer - order is x,y,z v1,v2,v3,v4
  57. // if v2 = v3: line
  58. // elsif v3 = v2: triangle
  59. // else: polygon
  60. std::vector<aiVector3D> vPositions;
  61. std::vector<aiColor4D> vColors;
  62. };
  63. public:
  64. // -------------------------------------------------------------------
  65. /** Returns whether the class can handle the format of the given file.
  66. * See BaseImporter::CanRead() for details. */
  67. bool CanRead( const std::string& pFile, IOSystem* pIOHandler) const;
  68. protected:
  69. // -------------------------------------------------------------------
  70. /** Called by Importer::GetExtensionList() for each loaded importer.
  71. * See BaseImporter::GetExtensionList() for details
  72. */
  73. void GetExtensionList(std::string& append)
  74. {
  75. append.append("*.dxf");
  76. }
  77. // -------------------------------------------------------------------
  78. /** Imports the given file into the given scene structure.
  79. * See BaseImporter::InternReadFile() for details
  80. */
  81. void InternReadFile( const std::string& pFile, aiScene* pScene,
  82. IOSystem* pIOHandler);
  83. // -------------------------------------------------------------------
  84. /** Get the next line from the file.
  85. * @return false if the end of the file was reached
  86. */
  87. bool GetNextLine();
  88. // -------------------------------------------------------------------
  89. /** Get the next token (group code + data line) from the file.
  90. * @return false if the end of the file was reached
  91. */
  92. bool GetNextToken();
  93. // -------------------------------------------------------------------
  94. /** Parses the ENTITIES section in the file
  95. * @return false if the end of the file was reached
  96. */
  97. bool ParseEntities();
  98. // -------------------------------------------------------------------
  99. /** Parses a 3DFACE section in the file
  100. * @return false if the end of the file was reached
  101. */
  102. bool Parse3DFace();
  103. // -------------------------------------------------------------------
  104. /** Parses a POLYLINE section in the file
  105. * @return false if the end of the file was reached
  106. */
  107. bool ParsePolyLine();
  108. // -------------------------------------------------------------------
  109. /** Sets the current layer - cursor must point to the name of it.
  110. * @param out Receives a handle to the layer
  111. */
  112. void SetLayer(LayerInfo*& out);
  113. // -------------------------------------------------------------------
  114. /** Creates a default layer.
  115. * @param out Receives a handle to the default layer
  116. */
  117. void SetDefaultLayer(LayerInfo*& out);
  118. // -------------------------------------------------------------------
  119. /** Parses a VERTEX element in a POLYLINE/POLYFACE
  120. * @param out Receives the output vertex.
  121. * @param clr Receives the output vertex color - won't be modified
  122. * if it is not existing.
  123. * @param outIdx Receives the output vertex indices, if present.
  124. * Wont't be modified otherwise. Size must be at least 4.
  125. * @return false if the end of the file was reached
  126. */
  127. bool ParsePolyLineVertex(aiVector3D& out, aiColor4D& clr,
  128. unsigned int* outIdx);
  129. private:
  130. // points to the next section
  131. const char* buffer;
  132. // specifies the current group code
  133. int groupCode;
  134. // contains the current data line
  135. char cursor[4096];
  136. // specifies whether the next call to GetNextToken()
  137. // should return the current token a second time
  138. bool bRepeat;
  139. // list of all loaded layers
  140. std::vector<LayerInfo> mLayers;
  141. LayerInfo* mDefaultLayer;
  142. };
  143. } // end of namespace Assimp
  144. #endif // AI_3DSIMPORTER_H_INC