ACloudViewer  3.9.4
A Modern Library for 3D Data Processing
dl_dxf.h
Go to the documentation of this file.
1 /****************************************************************************
2 ** Copyright (C) 2001-2013 RibbonSoft, GmbH. All rights reserved.
3 **
4 ** This file is part of the dxflib project.
5 **
6 ** This file is free software; you can redistribute it and/or modify
7 ** it under the terms of the GNU General Public License as published by
8 ** the Free Software Foundation; either version 2 of the License, or
9 ** (at your option) any later version.
10 **
11 ** Licensees holding valid dxflib Professional Edition licenses may use
12 ** this file in accordance with the dxflib Commercial License
13 ** Agreement provided with the Software.
14 **
15 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
16 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
17 **
18 ** See http://www.ribbonsoft.com for further details.
19 **
20 ** Contact info@ribbonsoft.com if any conditions of this licensing are
21 ** not clear to you.
22 **
23 **********************************************************************/
24 
25 #ifndef DL_DXF_H
26 #define DL_DXF_H
27 
28 #include <stdio.h>
29 #include <stdlib.h>
30 
31 #include <limits>
32 #include <map>
33 #include <sstream>
34 #include <string>
35 
36 #include "dl_attributes.h"
37 #include "dl_codes.h"
38 #include "dl_entities.h"
39 #include "dl_global.h"
40 #include "dl_writer_ascii.h"
41 
42 #ifdef _WIN32
43 #undef M_PI
44 #define M_PI 3.14159265358979323846
45 #pragma warning(disable : 4800)
46 #endif
47 
48 #ifndef M_PI
49 #define M_PI 3.1415926535897932384626433832795
50 #endif
51 
52 #ifndef DL_NANDOUBLE
53 #define DL_NANDOUBLE std::numeric_limits<double>::quiet_NaN()
54 #endif
55 
57 class DL_WriterA;
58 
59 #define DL_VERSION "3.17.0.0"
60 
61 #define DL_VERSION_MAJOR 3
62 #define DL_VERSION_MINOR 17
63 #define DL_VERSION_REV 0
64 #define DL_VERSION_BUILD 0
65 
66 #define DL_UNKNOWN 0
67 #define DL_LAYER 10
68 #define DL_BLOCK 11
69 #define DL_ENDBLK 12
70 #define DL_LINETYPE 13
71 #define DL_STYLE 20
72 #define DL_SETTING 50
73 #define DL_ENTITY_POINT 100
74 #define DL_ENTITY_LINE 101
75 #define DL_ENTITY_POLYLINE 102
76 #define DL_ENTITY_LWPOLYLINE 103
77 #define DL_ENTITY_VERTEX 104
78 #define DL_ENTITY_SPLINE 105
79 #define DL_ENTITY_KNOT 106
80 #define DL_ENTITY_CONTROLPOINT 107
81 #define DL_ENTITY_ARC 108
82 #define DL_ENTITY_CIRCLE 109
83 #define DL_ENTITY_ELLIPSE 110
84 #define DL_ENTITY_INSERT 111
85 #define DL_ENTITY_TEXT 112
86 #define DL_ENTITY_MTEXT 113
87 #define DL_ENTITY_DIMENSION 114
88 #define DL_ENTITY_LEADER 115
89 #define DL_ENTITY_HATCH 116
90 #define DL_ENTITY_ATTRIB 117
91 #define DL_ENTITY_IMAGE 118
92 #define DL_ENTITY_IMAGEDEF 119
93 #define DL_ENTITY_TRACE 120
94 #define DL_ENTITY_SOLID 121
95 #define DL_ENTITY_3DFACE 122
96 #define DL_ENTITY_XLINE 123
97 #define DL_ENTITY_RAY 124
98 #define DL_ENTITY_ARCALIGNEDTEXT 125
99 #define DL_ENTITY_SEQEND 126
100 #define DL_XRECORD 200
101 #define DL_DICTIONARY 210
102 
121 public:
122  DL_Dxf();
123  ~DL_Dxf();
124 
125  bool in(const std::string& file, DL_CreationInterface* creationInterface);
126  bool readDxfGroups(FILE* fp, DL_CreationInterface* creationInterface);
127  static bool getStrippedLine(std::string& s,
128  unsigned int size,
129  FILE* stream,
130  bool stripSpace = true);
131 
132  bool readDxfGroups(std::stringstream& stream,
133  DL_CreationInterface* creationInterface);
134  bool in(std::stringstream& stream, DL_CreationInterface* creationInterface);
135  static bool getStrippedLine(std::string& s,
136  unsigned int size,
137  std::stringstream& stream,
138  bool stripSpace = true);
139 
140  static bool stripWhiteSpace(char** s, bool stripSpaces = true);
141 
142  bool processDXFGroup(DL_CreationInterface* creationInterface,
143  int groupCode,
144  const std::string& groupValue);
145  void addSetting(DL_CreationInterface* creationInterface);
146  void addLayer(DL_CreationInterface* creationInterface);
147  void addLinetype(DL_CreationInterface* creationInterface);
148  void addBlock(DL_CreationInterface* creationInterface);
149  void endBlock(DL_CreationInterface* creationInterface);
150  void addTextStyle(DL_CreationInterface* creationInterface);
151 
152  void addPoint(DL_CreationInterface* creationInterface);
153  void addLine(DL_CreationInterface* creationInterface);
154  void addXLine(DL_CreationInterface* creationInterface);
155  void addRay(DL_CreationInterface* creationInterface);
156 
157  void addPolyline(DL_CreationInterface* creationInterface);
158  void addVertex(DL_CreationInterface* creationInterface);
159 
160  void addSpline(DL_CreationInterface* creationInterface);
161 
162  void addArc(DL_CreationInterface* creationInterface);
163  void addCircle(DL_CreationInterface* creationInterface);
164  void addEllipse(DL_CreationInterface* creationInterface);
165  void addInsert(DL_CreationInterface* creationInterface);
166 
167  void addTrace(DL_CreationInterface* creationInterface);
168  void add3dFace(DL_CreationInterface* creationInterface);
169  void addSolid(DL_CreationInterface* creationInterface);
170 
171  void addMText(DL_CreationInterface* creationInterface);
172  void addText(DL_CreationInterface* creationInterface);
173  void addArcAlignedText(DL_CreationInterface* creationInterface);
174 
175  void addAttribute(DL_CreationInterface* creationInterface);
176 
177  DL_DimensionData getDimData();
178  void addDimLinear(DL_CreationInterface* creationInterface);
179  void addDimAligned(DL_CreationInterface* creationInterface);
180  void addDimRadial(DL_CreationInterface* creationInterface);
181  void addDimDiametric(DL_CreationInterface* creationInterface);
182  void addDimAngular(DL_CreationInterface* creationInterface);
183  void addDimAngular3P(DL_CreationInterface* creationInterface);
184  void addDimOrdinate(DL_CreationInterface* creationInterface);
185 
186  void addLeader(DL_CreationInterface* creationInterface);
187 
188  void addHatch(DL_CreationInterface* creationInterface);
189  void addHatchLoop();
190  void addHatchEdge();
191  bool handleHatchData(DL_CreationInterface* creationInterface);
192 
193  void addImage(DL_CreationInterface* creationInterface);
194  void addImageDef(DL_CreationInterface* creationInterface);
195 
196  void addComment(DL_CreationInterface* creationInterface,
197  const std::string& comment);
198 
199  void addDictionary(DL_CreationInterface* creationInterface);
200  void addDictionaryEntry(DL_CreationInterface* creationInterface);
201 
202  bool handleXRecordData(DL_CreationInterface* creationInterface);
203  bool handleDictionaryData(DL_CreationInterface* creationInterface);
204 
205  bool handleXData(DL_CreationInterface* creationInterface);
206  bool handleMTextData(DL_CreationInterface* creationInterface);
207  bool handleLWPolylineData(DL_CreationInterface* creationInterface);
208  bool handleSplineData(DL_CreationInterface* creationInterface);
209  bool handleLeaderData(DL_CreationInterface* creationInterface);
210  bool handleLinetypeData(DL_CreationInterface* creationInterface);
211 
212  void endEntity(DL_CreationInterface* creationInterface);
213 
214  void endSequence(DL_CreationInterface* creationInterface);
215 
216  // int stringToInt(const char* s, bool* ok=NULL);
217 
218  DL_WriterA* out(const char* file,
220 
221  void writeHeader(DL_WriterA& dw);
222 
223  void writePoint(DL_WriterA& dw,
224  const DL_PointData& data,
225  const DL_Attributes& attrib);
226  void writeLine(DL_WriterA& dw,
227  const DL_LineData& data,
228  const DL_Attributes& attrib);
229  void writeXLine(DL_WriterA& dw,
230  const DL_XLineData& data,
231  const DL_Attributes& attrib);
232  void writeRay(DL_WriterA& dw,
233  const DL_RayData& data,
234  const DL_Attributes& attrib);
235  void writePolyline(DL_WriterA& dw,
236  const DL_PolylineData& data,
237  const DL_Attributes& attrib);
238  void writeVertex(DL_WriterA& dw, const DL_VertexData& data);
239  void writePolylineEnd(DL_WriterA& dw);
240  void writeSpline(DL_WriterA& dw,
241  const DL_SplineData& data,
242  const DL_Attributes& attrib);
243  void writeControlPoint(DL_WriterA& dw, const DL_ControlPointData& data);
244  void writeFitPoint(DL_WriterA& dw, const DL_FitPointData& data);
245  void writeKnot(DL_WriterA& dw, const DL_KnotData& data);
246  void writeCircle(DL_WriterA& dw,
247  const DL_CircleData& data,
248  const DL_Attributes& attrib);
249  void writeArc(DL_WriterA& dw,
250  const DL_ArcData& data,
251  const DL_Attributes& attrib);
252  void writeEllipse(DL_WriterA& dw,
253  const DL_EllipseData& data,
254  const DL_Attributes& attrib);
255  void writeSolid(DL_WriterA& dw,
256  const DL_SolidData& data,
257  const DL_Attributes& attrib);
258  void writeTrace(DL_WriterA& dw,
259  const DL_TraceData& data,
260  const DL_Attributes& attrib);
261  void write3dFace(DL_WriterA& dw,
262  const DL_3dFaceData& data,
263  const DL_Attributes& attrib);
264  void writeInsert(DL_WriterA& dw,
265  const DL_InsertData& data,
266  const DL_Attributes& attrib);
267  void writeMText(DL_WriterA& dw,
268  const DL_MTextData& data,
269  const DL_Attributes& attrib);
270  void writeText(DL_WriterA& dw,
271  const DL_TextData& data,
272  const DL_Attributes& attrib);
273  void writeAttribute(DL_WriterA& dw,
274  const DL_AttributeData& data,
275  const DL_Attributes& attrib);
276  void writeDimStyleOverrides(DL_WriterA& dw, const DL_DimensionData& data);
277  void writeDimAligned(DL_WriterA& dw,
278  const DL_DimensionData& data,
279  const DL_DimAlignedData& edata,
280  const DL_Attributes& attrib);
281  void writeDimLinear(DL_WriterA& dw,
282  const DL_DimensionData& data,
283  const DL_DimLinearData& edata,
284  const DL_Attributes& attrib);
285  void writeDimRadial(DL_WriterA& dw,
286  const DL_DimensionData& data,
287  const DL_DimRadialData& edata,
288  const DL_Attributes& attrib);
289  void writeDimDiametric(DL_WriterA& dw,
290  const DL_DimensionData& data,
291  const DL_DimDiametricData& edata,
292  const DL_Attributes& attrib);
293  void writeDimAngular(DL_WriterA& dw,
294  const DL_DimensionData& data,
295  const DL_DimAngularData& edata,
296  const DL_Attributes& attrib);
297  void writeDimAngular3P(DL_WriterA& dw,
298  const DL_DimensionData& data,
299  const DL_DimAngular3PData& edata,
300  const DL_Attributes& attrib);
301  void writeDimOrdinate(DL_WriterA& dw,
302  const DL_DimensionData& data,
303  const DL_DimOrdinateData& edata,
304  const DL_Attributes& attrib);
305  void writeLeader(DL_WriterA& dw,
306  const DL_LeaderData& data,
307  const DL_Attributes& attrib);
308  void writeLeaderVertex(DL_WriterA& dw, const DL_LeaderVertexData& data);
309  void writeHatch1(DL_WriterA& dw,
310  const DL_HatchData& data,
311  const DL_Attributes& attrib);
312  void writeHatch2(DL_WriterA& dw,
313  const DL_HatchData& data,
314  const DL_Attributes& attrib);
315  void writeHatchLoop1(DL_WriterA& dw, const DL_HatchLoopData& data);
316  void writeHatchLoop2(DL_WriterA& dw, const DL_HatchLoopData& data);
317  void writeHatchEdge(DL_WriterA& dw, const DL_HatchEdgeData& data);
318 
319  int writeImage(DL_WriterA& dw,
320  const DL_ImageData& data,
321  const DL_Attributes& attrib);
322 
323  void writeImageDef(DL_WriterA& dw, int handle, const DL_ImageData& data);
324 
325  void writeLayer(DL_WriterA& dw,
326  const DL_LayerData& data,
327  const DL_Attributes& attrib);
328 
329  void writeLinetype(DL_WriterA& dw, const DL_LinetypeData& data);
330 
331  void writeAppid(DL_WriterA& dw, const std::string& name);
332 
333  void writeBlock(DL_WriterA& dw, const DL_BlockData& data);
334  void writeEndBlock(DL_WriterA& dw, const std::string& name);
335 
336  void writeVPort(DL_WriterA& dw);
337  void writeStyle(DL_WriterA& dw, const DL_StyleData& style);
338  void writeView(DL_WriterA& dw);
339  void writeUcs(DL_WriterA& dw);
340  void writeDimStyle(DL_WriterA& dw,
341  double dimasz,
342  double dimexe,
343  double dimexo,
344  double dimgap,
345  double dimtxt);
346  void writeBlockRecord(DL_WriterA& dw);
347  void writeBlockRecord(DL_WriterA& dw, const std::string& name);
348  void writeObjects(DL_WriterA& dw,
349  const std::string& appDictionaryName = "");
350  void writeAppDictionary(DL_WriterA& dw);
351  int writeDictionaryEntry(DL_WriterA& dw, const std::string& name);
352  void writeXRecord(DL_WriterA& dw, int handle, int value);
353  void writeXRecord(DL_WriterA& dw, int handle, double value);
354  void writeXRecord(DL_WriterA& dw, int handle, bool value);
355  void writeXRecord(DL_WriterA& dw, int handle, const std::string& value);
356  void writeObjectsEnd(DL_WriterA& dw);
357 
358  void writeComment(DL_WriterA& dw, const std::string& comment);
359 
364  // static double toReal(const char* value, double def=0.0);
365 
370  // static int toInt(const char* value, int def=0) {
371  // if (value!=NULL && value[0] != '\0') {
372  // return atoi(value);
373  // }
374 
375  // return def;
376  // }
377 
382  // static const char* toString(const char* value, const char* def="") {
383  // if (value!=NULL && value[0] != '\0') {
384  // return value;
385  // } else {
386  // return def;
387  // }
388  // }
389 
390  static bool checkVariable(const char* var, DL_Codes::version version);
391 
393 
394  int getLibVersion(const std::string& str);
395 
396  static void test();
397 
398  bool hasValue(int code) { return values.count(code) == 1; }
399 
400  int getIntValue(int code, int def) {
401  if (!hasValue(code)) {
402  return def;
403  }
404  return toInt(values[code]);
405  }
406 
407  int toInt(const std::string& str) {
408  char* p;
409  return strtol(str.c_str(), &p, 10);
410  }
411 
412  int getInt16Value(int code, int def) {
413  if (!hasValue(code)) {
414  return def;
415  }
416  return toInt16(values[code]);
417  }
418 
419  int toInt16(const std::string& str) {
420  char* p;
421  return strtol(str.c_str(), &p, 16);
422  }
423 
424  bool toBool(const std::string& str) {
425  char* p;
426  return (bool)strtol(str.c_str(), &p, 10);
427  }
428 
429  std::string getStringValue(int code, const std::string& def) {
430  if (!hasValue(code)) {
431  return def;
432  }
433  return values[code];
434  }
435 
436  double getRealValue(int code, double def) {
437  if (!hasValue(code)) {
438  return def;
439  }
440  return toReal(values[code]);
441  }
442 
443  double toReal(const std::string& str) {
444  double ret;
445  // make sure the real value uses '.' not ',':
446  std::string str2 = str;
447  std::replace(str2.begin(), str2.end(), ',', '.');
448  // make sure c++ expects '.' not ',':
449  std::istringstream istr(str2);
450  // istr.imbue(std::locale("C"));
451  istr >> ret;
452  return ret;
453  }
454 
455 private:
457 
458  std::string polylineLayer;
459  double* vertices;
460  int maxVertices;
461  int vertexIndex;
462 
463  double* knots;
464  int maxKnots;
465  int knotIndex;
466 
467  double* weights;
468  int weightIndex;
469 
470  double* controlPoints;
471  int maxControlPoints;
472  int controlPointIndex;
473 
474  double* fitPoints;
475  int maxFitPoints;
476  int fitPointIndex;
477 
478  double* leaderVertices;
479  int maxLeaderVertices;
480  int leaderVertexIndex;
481 
482  bool firstHatchLoop;
483  DL_HatchEdgeData hatchEdge;
484  std::vector<std::vector<DL_HatchEdgeData>> hatchEdges;
485 
486  std::string xRecordHandle;
487  bool xRecordValues;
488 
489  // Only the useful part of the group code
490  std::string groupCodeTmp;
491  // ...same as integer
492  unsigned int groupCode;
493  // Only the useful part of the group value
494  std::string groupValue;
495  // Current entity type
496  int currentObjectType;
497  // Value of the current setting
498  char settingValue[DL_DXF_MAXLINE + 1];
499  // Key of the current setting (e.g. "$ACADVER")
500  std::string settingKey;
501  // Stores the group codes
502  std::map<int, std::string> values;
503  // First call of this method. We initialize all group values in
504  // the first call.
505  bool firstCall;
506  // Attributes of the current entity (layer, color, width, line type)
507  DL_Attributes attrib;
508  // library version. hex: 0x20003001 = 2.0.3.1
509  int libVersion;
510  // app specific dictionary handle:
511  unsigned long appDictionaryHandle;
512  // handle of standard text style, referenced by dimstyle:
513  unsigned long styleHandleStd;
514 };
515 
516 #endif
517 
518 // EOF
int size
std::string version
std::string name
Definition: dl_dxf.h:120
double toReal(const std::string &str)
Definition: dl_dxf.h:443
DL_Codes::version getVersion()
Definition: dl_dxf.h:392
int toInt(const std::string &str)
Definition: dl_dxf.h:407
int getInt16Value(int code, int def)
Definition: dl_dxf.h:412
int toInt16(const std::string &str)
Definition: dl_dxf.h:419
bool hasValue(int code)
Definition: dl_dxf.h:398
int getIntValue(int code, int def)
Definition: dl_dxf.h:400
double getRealValue(int code, double def)
Definition: dl_dxf.h:436
bool toBool(const std::string &str)
Definition: dl_dxf.h:424
std::string getStringValue(int code, const std::string &def)
Definition: dl_dxf.h:429
#define DL_DXF_MAXLINE
Definition: dl_codes.h:57
#define DL_VERSION_2000
Definition: dl_codes.h:374
#define DXFLIB_EXPORT
Definition: dl_global.h:12
GraphType data
Definition: graph_cut.cc:138