Umasoft
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Groups Pages
DxfParser.h
1 //
2 // DxfParser.h
3 //
4 // Class for parsing a DXF File.
5 //
6 // Copyright (c) 2004-2007 Virtual Terrain Project
7 // Free for all uses, see license.txt for details.
8 //
9 
10 #ifndef DXFPARSER_H
11 #define DXFPARSER_H
12 
13 #include <deque>
14 #include <vector>
15 #include <set>
16 #include "vtString.h"
17 #include "MathTypes.h"
18 
19 enum DxfEntityType
20 {
21  DET_Point,
22  DET_Polyline,
23  DET_Polygon,
24  DET_3DFace
25 };
26 
27 class DxfLayer
28 {
29 public:
30  DxfLayer() {};
31  vtString m_name;
32  RGBi m_color;
33 };
34 
35 class DxfEntity
36 {
37 public:
38  DxfEntity() {};
39  std::vector<DPoint3> m_points;
40  DxfEntityType m_iType;
41  vtString m_label;
42  int m_iLayer;
43 };
44 
46 {
47 public:
48  DxfCodeValue() { m_iCode = -1; }
49  int m_iCode;
50  vtString m_sValue;
51 };
52 
70 class DxfParser
71 {
72 public:
73  DxfParser(const vtString &sFileName,
74  std::vector<DxfEntity> &entities,
75  std::vector<DxfLayer> &layers);
76  bool RetrieveEntities(bool progress_callback(int) = NULL);
77  vtString GetFileName() { return m_sFileName; }
78  void SetFileName(const vtString & sFileName) { m_sFileName = sFileName; }
79  vtString GetLastError() { return m_strMessage; }
80 
81 protected:
82  std::vector<DxfEntity> & m_entities;
83  std::vector<DxfLayer> & m_layers;
84  vtString m_sFileName;
85  FILE * m_pFile;
86  size_t m_iLine;
87  size_t m_iLineCount;
88  int m_iCounter;
89  long m_iEndPosition;
90  vtString m_strMessage;
91 
92  bool ParseSection();
93  bool ReadCodeValue(DxfCodeValue &);
94  void SkipSection();
95  void ReadTableSection(bool progress_callback(int));
96  void ReadEntitySection(bool progress_callback(int));
97  void ReadLayer();
98  void ReadPoint();
99  void ReadText();
100  void ReadPolyline();
101  void ReadLine();
102  void ReadVertex(std::vector<DPoint3> &);
103  int GetLayerIndex(const vtString &);
104  void ReadLWPolyline();
105  void Read3DFace();
106 };
107 
108 #endif // DXFPARSER_H
109