DXFLoader.h 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  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 DXFLoader.h
  34. * @brief Declaration of the .dxf importer class.
  35. */
  36. #ifndef AI_DXFLOADER_H_INCLUDED
  37. #define AI_DXFLOADER_H_INCLUDED
  38. #include "BaseImporter.h"
  39. namespace Assimp {
  40. // ---------------------------------------------------------------------------
  41. /** DXF importer class
  42. */
  43. class DXFImporter : public BaseImporter
  44. {
  45. friend class Importer;
  46. protected:
  47. /** Constructor to be privately used by Importer */
  48. DXFImporter();
  49. /** Destructor, private as well */
  50. ~DXFImporter();
  51. // describes a single layer in the DXF file
  52. struct LayerInfo
  53. {
  54. LayerInfo()
  55. {
  56. name[0] = '\0';
  57. }
  58. char name[4096];
  59. // face buffer - order is x,y,z v1,v2,v3,v4
  60. // if v2 = v3: line
  61. // elsif v3 = v2: triangle
  62. // else: polygon
  63. std::vector<aiVector3D> vPositions;
  64. std::vector<aiColor4D> vColors;
  65. };
  66. public:
  67. // -------------------------------------------------------------------
  68. /** Returns whether the class can handle the format of the given file.
  69. * See BaseImporter::CanRead() for details. */
  70. bool CanRead( const std::string& pFile, IOSystem* pIOHandler,
  71. bool checkSig) const;
  72. protected:
  73. // -------------------------------------------------------------------
  74. /** Called by Importer::GetExtensionList() for each loaded importer.
  75. * See BaseImporter::GetExtensionList() for details
  76. */
  77. void GetExtensionList(std::string& append);
  78. // -------------------------------------------------------------------
  79. /** Imports the given file into the given scene structure.
  80. * See BaseImporter::InternReadFile() for details
  81. */
  82. void InternReadFile( const std::string& pFile, aiScene* pScene,
  83. IOSystem* pIOHandler);
  84. // -------------------------------------------------------------------
  85. /** Get the next line from the file.
  86. * @return false if the end of the file was reached
  87. */
  88. bool GetNextLine();
  89. // -------------------------------------------------------------------
  90. /** Get the next token (group code + data line) from the file.
  91. * @return false if the end of the file was reached
  92. */
  93. bool GetNextToken();
  94. // -------------------------------------------------------------------
  95. /** Parses the ENTITIES section in the file
  96. * @return false if the end of the file was reached
  97. */
  98. bool ParseEntities();
  99. // -------------------------------------------------------------------
  100. /** Parses a 3DFACE section in the file
  101. * @return false if the end of the file was reached
  102. */
  103. bool Parse3DFace();
  104. // -------------------------------------------------------------------
  105. /** Parses a POLYLINE section in the file
  106. * @return false if the end of the file was reached
  107. */
  108. bool ParsePolyLine();
  109. // -------------------------------------------------------------------
  110. /** Sets the current layer - cursor must point to the name of it.
  111. * @param out Receives a handle to the layer
  112. */
  113. void SetLayer(LayerInfo*& out);
  114. // -------------------------------------------------------------------
  115. /** Creates a default layer.
  116. * @param out Receives a handle to the default layer
  117. */
  118. void SetDefaultLayer(LayerInfo*& out);
  119. // -------------------------------------------------------------------
  120. /** Parses a VERTEX element in a POLYLINE/POLYFACE
  121. * @param out Receives the output vertex.
  122. * @param clr Receives the output vertex color - won't be modified
  123. * if it is not existing.
  124. * @param outIdx Receives the output vertex indices, if present.
  125. * Wont't be modified otherwise. Size must be at least 4.
  126. * @return false if the end of the file was reached
  127. */
  128. bool ParsePolyLineVertex(aiVector3D& out, aiColor4D& clr,
  129. unsigned int* outIdx);
  130. private:
  131. // points to the next section
  132. const char* buffer;
  133. // specifies the current group code
  134. int groupCode;
  135. // contains the current data line
  136. char cursor[4096];
  137. // specifies whether the next call to GetNextToken()
  138. // should return the current token a second time
  139. bool bRepeat;
  140. // list of all loaded layers
  141. std::vector<LayerInfo> mLayers;
  142. LayerInfo* mDefaultLayer;
  143. };
  144. } // end of namespace Assimp
  145. #endif // AI_3DSIMPORTER_H_INC