Debian Codegraph @

ogr/ogrsf_frmts/dwg/ogr_dwg.h

raw
1 /******************************************************************************
2 *
3 * Project: DWG Translator
4 * Purpose: Definition of classes for OGR .dwg driver.
5 * Author: Frank Warmerdam, [email protected]
6 *
7 ******************************************************************************
8 * Copyright (c) 2011, Frank Warmerdam
9 *
10 * SPDX-License-Identifier: MIT
11 ****************************************************************************/
12
13 #ifndef OGR_DWG_H_INCLUDED
14 #define OGR_DWG_H_INCLUDED
15
16 #include "ogrsf_frmts.h"
17 #include "cpl_conv.h"
18 #include <vector>
19 #include <map>
20 #include <set>
21 #include <queue>
22
23 #include "ogr_autocad_services.h"
24 #include "dwg_headers.h"
25
26 class OGRDWGDataSource;
27 class OGRDWGServices;
28
29 /************************************************************************/
30 /* DWGBlockDefinition */
31 /* */
32 /* Container for info about a block. */
33 /************************************************************************/
34
35 class DWGBlockDefinition
36 {
37 public:
38 DWGBlockDefinition() : poGeometry(nullptr)
39 {
40 }
41
42 ~DWGBlockDefinition();
43
44 OGRGeometry *poGeometry;
45 std::vector<OGRFeature *> apoFeatures;
46
47 private:
48 CPL_DISALLOW_COPY_ASSIGN(DWGBlockDefinition)
49 };
50
51 /************************************************************************/
52 /* OGRDWGBlocksLayer() */
53 /************************************************************************/
54
55 class OGRDWGBlocksLayer final : public OGRLayer
56 {
57 OGRDWGDataSource *poDS;
58
59 OGRFeatureDefn *poFeatureDefn;
60
61 int iNextFID;
62 unsigned int iNextSubFeature;
63
64 std::map<CPLString, DWGBlockDefinition>::iterator oIt;
65
66 public:
67 explicit OGRDWGBlocksLayer(OGRDWGDataSource *poDS);
68 ~OGRDWGBlocksLayer() override;
69
70 void ResetReading() override;
71 OGRFeature *GetNextFeature() override;
72
73 const OGRFeatureDefn *GetLayerDefn() const override
74 {
75 return poFeatureDefn;
76 }
77
78 int TestCapability(const char *) const override;
79
80 OGRFeature *GetNextUnfilteredFeature();
81
82 GDALDataset *GetDataset() override;
83 };
84
85 /************************************************************************/
86 /* OGRDWGLayer */
87 /************************************************************************/
88 class OGRDWGLayer final : public OGRLayer
89 {
90 OGRDWGDataSource *poDS;
91
92 OGRFeatureDefn *poFeatureDefn;
93 int iNextFID;
94
95 std::set<CPLString> oIgnoredEntities;
96
97 std::queue<OGRFeature *> apoPendingFeatures;
98 void ClearPendingFeatures();
99
100 std::map<CPLString, CPLString> oStyleProperties;
101
102 void TranslateGenericProperties(OGRFeature *poFeature,
103 OdDbEntityPtr poEntity);
104 void PrepareLineStyle(OGRFeature *poFeature);
105 // void ApplyOCSTransformer( OGRGeometry * );
106
107 OGRFeature *TranslatePOINT(OdDbEntityPtr poEntity);
108 OGRFeature *TranslateLINE(OdDbEntityPtr poEntity);
109 OGRFeature *TranslateLWPOLYLINE(OdDbEntityPtr poEntity);
110 OGRFeature *Translate2DPOLYLINE(OdDbEntityPtr poEntity);
111 OGRFeature *Translate3DPOLYLINE(OdDbEntityPtr poEntity);
112 OGRFeature *TranslateELLIPSE(OdDbEntityPtr poEntity);
113 OGRFeature *TranslateARC(OdDbEntityPtr poEntity);
114 OGRFeature *TranslateMTEXT(OdDbEntityPtr poEntity);
115 OGRFeature *TranslateDIMENSION(OdDbEntityPtr poEntity);
116 OGRFeature *TranslateCIRCLE(OdDbEntityPtr poEntity);
117 OGRFeature *TranslateSPLINE(OdDbEntityPtr poEntity);
118 OGRFeature *TranslateHATCH(OdDbEntityPtr poEntity);
119 OGRFeature *TranslateTEXT(OdDbEntityPtr poEntity);
120 OGRFeature *TranslateINSERT(OdDbEntityPtr poEntity);
121 OGRFeature *Translate3DFACE(OdDbEntityPtr poEntity);
122
123 void FormatDimension(CPLString &osText, double dfValue);
124
125 CPLString TextUnescape(OdString oString, bool);
126
127 OdDbBlockTableRecordPtr m_poBlock;
128 OdDbObjectIteratorPtr poEntIter;
129
130 public:
131 explicit OGRDWGLayer(OGRDWGDataSource *poDS);
132 ~OGRDWGLayer() override;
133
134 void ResetReading() override;
135 OGRFeature *GetNextFeature() override;
136
137 const OGRFeatureDefn *GetLayerDefn() const override
138 {
139 return poFeatureDefn;
140 }
141
142 int TestCapability(const char *) const override;
143
144 OGRFeature *GetNextUnfilteredFeature();
145
146 // internal
147 void SetBlockTable(OdDbBlockTableRecordPtr);
148 static double AngleCorrect(double dfAngle, double dfRatio);
149
150 GDALDataset *GetDataset() override;
151 };
152
153 /************************************************************************/
154 /* OGRDWGDataSource */
155 /************************************************************************/
156
157 class OGRDWGDataSource final : public GDALDataset
158 {
159 std::vector<OGRLayer *> apoLayers;
160
161 std::set<CPLString> attributeFields;
162
163 std::map<CPLString, DWGBlockDefinition> oBlockMap;
164 std::map<CPLString, CPLString> oHeaderVariables;
165
166 CPLString osEncoding;
167
168 // indexed by layer name, then by property name.
169 std::map<CPLString, std::map<CPLString, CPLString>> oLayerTable;
170
171 std::map<CPLString, CPLString> oLineTypeTable;
172
173 int bInlineBlocks;
174 int bAttributes;
175 int bAllAttributes;
176
177 bool m_bClosedLineAsPolygon = false;
178
179 OGRDWGServices *poServices;
180 OdDbDatabasePtr poDb;
181
182 public:
183 OGRDWGDataSource();
184 ~OGRDWGDataSource() override;
185
186 OdDbDatabasePtr GetDB()
187 {
188 return poDb;
189 }
190
191 int Open(OGRDWGServices *poServices, const char *pszFilename,
192 int bHeaderOnly = FALSE);
193
194 int GetLayerCount() const override
195 {
196 return static_cast<int>(apoLayers.size());
197 }
198
199 const OGRLayer *GetLayer(int) const override;
200
201 // The following is only used by OGRDWGLayer
202
203 int InlineBlocks()
204 {
205 return bInlineBlocks;
206 }
207
208 int Attributes()
209 {
210 return bAttributes;
211 }
212
213 int AllAttributes()
214 {
215 return bAllAttributes;
216 }
217
218 bool ClosedLineAsPolygon() const
219 {
220 return m_bClosedLineAsPolygon;
221 }
222
223 void AddStandardFields(OGRFeatureDefn *poDef);
224
225 // Implemented in ogrdxf_blockmap.cpp
226 void ReadBlocksSection();
227 void ReadAttDefinitions();
228 static OGRGeometry *SimplifyBlockGeometry(OGRGeometryCollection *);
229 DWGBlockDefinition *LookupBlock(const char *pszName);
230
231 std::map<CPLString, DWGBlockDefinition> &GetBlockMap()
232 {
233 return oBlockMap;
234 }
235
236 std::set<CPLString> &GetAttributes()
237 {
238 return attributeFields;
239 }
240
241 // Layer and other Table Handling (ogrdatasource.cpp)
242 void ReadLayerDefinitions();
243 void ReadLineTypeDefinitions();
244 const char *LookupLayerProperty(const char *pszLayer,
245 const char *pszProperty);
246 const char *LookupLineType(const char *pszName);
247
248 // Header variables.
249 void ReadHeaderSection();
250 const char *GetVariable(const char *pszName,
251 const char *pszDefault = nullptr);
252
253 const char *GetEncoding()
254 {
255 return osEncoding;
256 }
257 };
258
259 /************************************************************************/
260 /* OGRDWGServices */
261 /* */
262 /* Services implementation for OGR. Eventually we should */
263 /* override the ExSystemServices IO to use VSI*L. */
264 /************************************************************************/
265 class OGRDWGServices : public ExSystemServices, public ExHostAppServices
266 {
267 protected:
268 ODRX_USING_HEAP_OPERATORS(ExSystemServices);
269 };
270
271 #endif /* ndef OGR_DWG_H_INCLUDED */