QCAD Application Framework
CAD Application Development and Automation.
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
dl_dxf.h
Go to the documentation of this file.
1 /****************************************************************************
2 ** Copyright (C) 2001-2011 RibbonSoft. All rights reserved.
3 **
4 ** This file is part of the dxflib project.
5 **
6 ** This file may be distributed and/or modified under the terms of the
7 ** GNU General Public License version 2 as published by the Free Software
8 ** Foundation and appearing in the file LICENSE.GPL included in the
9 ** packaging of this file.
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 #include <string.h>
31 #ifndef __GCC2x__
32 #include <sstream>
33 #endif
34 
35 #include "dl_attributes.h"
36 #include "dl_codes.h"
37 #include "dl_entities.h"
38 #include "dl_writer_ascii.h"
39 
40 #ifdef _WIN32
41 #undef M_PI
42 #define M_PI 3.14159265358979323846
43 #pragma warning(disable : 4800)
44 #endif
45 
46 #ifndef M_PI
47 #define M_PI 3.1415926535897932384626433832795
48 #endif
49 
51 class DL_WriterA;
52 
53 
54 #define DL_VERSION "2.5.0.0"
55 
56 #define DL_UNKNOWN 0
57 #define DL_LAYER 10
58 #define DL_BLOCK 11
59 #define DL_ENDBLK 12
60 #define DL_LINETYPE 13
61 #define DL_SETTING 50
62 #define DL_ENTITY_POINT 100
63 #define DL_ENTITY_LINE 101
64 #define DL_ENTITY_POLYLINE 102
65 #define DL_ENTITY_LWPOLYLINE 103
66 #define DL_ENTITY_VERTEX 104
67 #define DL_ENTITY_SPLINE 105
68 #define DL_ENTITY_KNOT 106
69 #define DL_ENTITY_CONTROLPOINT 107
70 #define DL_ENTITY_ARC 108
71 #define DL_ENTITY_CIRCLE 109
72 #define DL_ENTITY_ELLIPSE 110
73 #define DL_ENTITY_INSERT 111
74 #define DL_ENTITY_TEXT 112
75 #define DL_ENTITY_MTEXT 113
76 #define DL_ENTITY_DIMENSION 114
77 #define DL_ENTITY_LEADER 115
78 #define DL_ENTITY_HATCH 116
79 #define DL_ENTITY_ATTRIB 117
80 #define DL_ENTITY_IMAGE 118
81 #define DL_ENTITY_IMAGEDEF 119
82 #define DL_ENTITY_TRACE 120
83 #define DL_ENTITY_SOLID 121
84 #define DL_ENTITY_3DFACE 122
85 #define DL_ENTITY_SEQEND 123
86 
87 
105 class DL_Dxf {
106 public:
107  DL_Dxf();
108  ~DL_Dxf();
109 
110  bool in(const string& file,
111  DL_CreationInterface* creationInterface);
112  bool readDxfGroups(FILE* fp,
113  DL_CreationInterface* creationInterface,
114  int* errorCounter = NULL);
115  static bool getChoppedLine(char* s, unsigned int size,
116  FILE *stream);
117 
118 #ifndef __GCC2x__
119  bool readDxfGroups(std::stringstream &stream,
120  DL_CreationInterface* creationInterface,
121  int* errorCounter = NULL);
122  bool in(std::stringstream &stream,
123  DL_CreationInterface* creationInterface);
124  static bool getChoppedLine(char *s, unsigned int size,
125  std::stringstream &stream);
126 #endif
127 
128  static bool stripWhiteSpace(char** s);
129 
130  bool processDXFGroup(DL_CreationInterface* creationInterface,
131  int groupCode, const char* groupValue);
132  void addSetting(DL_CreationInterface* creationInterface);
133  void addLayer(DL_CreationInterface* creationInterface);
134  void addBlock(DL_CreationInterface* creationInterface);
135  void endBlock(DL_CreationInterface* creationInterface);
136 
137  void addPoint(DL_CreationInterface* creationInterface);
138  void addLine(DL_CreationInterface* creationInterface);
139 
140  void addPolyline(DL_CreationInterface* creationInterface);
141  void addVertex(DL_CreationInterface* creationInterface);
142 
143  void addSpline(DL_CreationInterface* creationInterface);
144  //void addKnot(DL_CreationInterface* creationInterface);
145  //void addControlPoint(DL_CreationInterface* creationInterface);
146 
147  void addArc(DL_CreationInterface* creationInterface);
148  void addCircle(DL_CreationInterface* creationInterface);
149  void addEllipse(DL_CreationInterface* creationInterface);
150  void addInsert(DL_CreationInterface* creationInterface);
151 
152  void addTrace(DL_CreationInterface* creationInterface);
153  void add3dFace(DL_CreationInterface* creationInterface);
154  void addSolid(DL_CreationInterface* creationInterface);
155 
156  void addMText(DL_CreationInterface* creationInterface);
157  bool handleMTextData(DL_CreationInterface* creationInterface);
158  bool handleLWPolylineData(DL_CreationInterface* creationInterface);
159  bool handleSplineData(DL_CreationInterface* creationInterface);
160  bool handleLeaderData(DL_CreationInterface* creationInterface);
161  bool handleHatchData(DL_CreationInterface* creationInterface);
162 
163  void addText(DL_CreationInterface* creationInterface);
164  void addAttrib(DL_CreationInterface* creationInterface);
166  void addDimLinear(DL_CreationInterface* creationInterface);
167  void addDimAligned(DL_CreationInterface* creationInterface);
168  void addDimRadial(DL_CreationInterface* creationInterface);
169  void addDimDiametric(DL_CreationInterface* creationInterface);
170  void addDimAngular(DL_CreationInterface* creationInterface);
171  void addDimAngular3P(DL_CreationInterface* creationInterface);
172  void addDimOrdinate(DL_CreationInterface* creationInterface);
173  void addLeader(DL_CreationInterface* creationInterface);
174  void addHatch(DL_CreationInterface* creationInterface);
175  void addImage(DL_CreationInterface* creationInterface);
176  void addImageDef(DL_CreationInterface* creationInterface);
177 
178  void addComment(DL_CreationInterface* creationInterface, const char* comment);
179 
180  void endEntity(DL_CreationInterface* creationInterface);
181 
182  void endSequence(DL_CreationInterface* creationInterface);
183 
184  int stringToInt(const char* s, bool* ok=NULL);
185 
186  DL_WriterA* out(const char* file,
188 
189  void writeHeader(DL_WriterA& dw);
190 
191  void writePoint(DL_WriterA& dw,
192  const DL_PointData& data,
193  const DL_Attributes& attrib);
194  void writeLine(DL_WriterA& dw,
195  const DL_LineData& data,
196  const DL_Attributes& attrib);
197  void writePolyline(DL_WriterA& dw,
198  const DL_PolylineData& data,
199  const DL_Attributes& attrib);
200  void writeVertex(DL_WriterA& dw,
201  const DL_VertexData& data);
202  void writePolylineEnd(DL_WriterA& dw);
203  void writeSpline(DL_WriterA& dw,
204  const DL_SplineData& data,
205  const DL_Attributes& attrib);
206  void writeControlPoint(DL_WriterA& dw,
207  const DL_ControlPointData& data);
208  void writeKnot(DL_WriterA& dw,
209  const DL_KnotData& data);
210  void writeCircle(DL_WriterA& dw,
211  const DL_CircleData& data,
212  const DL_Attributes& attrib);
213  void writeArc(DL_WriterA& dw,
214  const DL_ArcData& data,
215  const DL_Attributes& attrib);
216  void writeEllipse(DL_WriterA& dw,
217  const DL_EllipseData& data,
218  const DL_Attributes& attrib);
219  void writeSolid(DL_WriterA& dw,
220  const DL_SolidData& data,
221  const DL_Attributes& attrib);
222  void write3dFace(DL_WriterA& dw,
223  const DL_3dFaceData& data,
224  const DL_Attributes& attrib);
225  void writeInsert(DL_WriterA& dw,
226  const DL_InsertData& data,
227  const DL_Attributes& attrib);
228  void writeMText(DL_WriterA& dw,
229  const DL_MTextData& data,
230  const DL_Attributes& attrib);
231  void writeText(DL_WriterA& dw,
232  const DL_TextData& data,
233  const DL_Attributes& attrib);
234  void writeDimAligned(DL_WriterA& dw,
235  const DL_DimensionData& data,
236  const DL_DimAlignedData& edata,
237  const DL_Attributes& attrib);
238  void writeDimLinear(DL_WriterA& dw,
239  const DL_DimensionData& data,
240  const DL_DimLinearData& edata,
241  const DL_Attributes& attrib);
242  void writeDimRadial(DL_WriterA& dw,
243  const DL_DimensionData& data,
244  const DL_DimRadialData& edata,
245  const DL_Attributes& attrib);
246  void writeDimDiametric(DL_WriterA& dw,
247  const DL_DimensionData& data,
248  const DL_DimDiametricData& edata,
249  const DL_Attributes& attrib);
250  void writeDimAngular(DL_WriterA& dw,
251  const DL_DimensionData& data,
252  const DL_DimAngularData& edata,
253  const DL_Attributes& attrib);
254  void writeDimAngular3P(DL_WriterA& dw,
255  const DL_DimensionData& data,
256  const DL_DimAngular3PData& edata,
257  const DL_Attributes& attrib);
258  void writeDimOrdinate(DL_WriterA& dw,
259  const DL_DimensionData& data,
260  const DL_DimOrdinateData& edata,
261  const DL_Attributes& attrib);
262  void writeLeader(DL_WriterA& dw,
263  const DL_LeaderData& data,
264  const DL_Attributes& attrib);
265  void writeLeaderVertex(DL_WriterA& dw,
266  const DL_LeaderVertexData& data);
267  void writeHatch1(DL_WriterA& dw,
268  const DL_HatchData& data,
269  const DL_Attributes& attrib);
270  void writeHatch2(DL_WriterA& dw,
271  const DL_HatchData& data,
272  const DL_Attributes& attrib);
273  void writeHatchLoop1(DL_WriterA& dw,
274  const DL_HatchLoopData& data);
275  void writeHatchLoop2(DL_WriterA& dw,
276  const DL_HatchLoopData& data);
277  void writeHatchEdge(DL_WriterA& dw,
278  const DL_HatchEdgeData& data);
279 
280  int writeImage(DL_WriterA& dw,
281  const DL_ImageData& data,
282  const DL_Attributes& attrib);
283 
284  void writeImageDef(DL_WriterA& dw, int handle,
285  const DL_ImageData& data);
286 
287  void writeLayer(DL_WriterA& dw,
288  const DL_LayerData& data,
289  const DL_Attributes& attrib);
290 
291  void writeLineType(DL_WriterA& dw,
292  const DL_LineTypeData& data);
293 
294  void writeAppid(DL_WriterA& dw, const string& name);
295 
296  void writeBlock(DL_WriterA& dw,
297  const DL_BlockData& data);
298  void writeEndBlock(DL_WriterA& dw, const string& name);
299 
300  void writeVPort(DL_WriterA& dw);
301  void writeStyle(DL_WriterA& dw);
302  void writeView(DL_WriterA& dw);
303  void writeUcs(DL_WriterA& dw);
304  void writeDimStyle(DL_WriterA& dw,
305  double dimasz, double dimexe, double dimexo,
306  double dimgap, double dimtxt);
307  void writeBlockRecord(DL_WriterA& dw);
308  void writeBlockRecord(DL_WriterA& dw, const string& name);
309  void writeObjects(DL_WriterA& dw);
310  void writeObjectsEnd(DL_WriterA& dw);
311 
312  void writeComment(DL_WriterA& dw, const string& comment);
313 
318  static double toReal(const char* value, double def=0.0) {
319  if (value!=NULL && value[0] != '\0') {
320  double ret;
321  if (strchr(value, ',') != NULL) {
322  char* tmp = new char[strlen(value)+1];
323  strcpy(tmp, value);
324  DL_WriterA::strReplace(tmp, ',', '.');
325  ret = atof(tmp);
326  delete[] tmp;
327  }
328  else {
329  ret = atof(value);
330  }
331  return ret;
332  } else {
333  return def;
334  }
335  }
340  static int toInt(const char* value, int def=0) {
341  if (value!=NULL && value[0] != '\0') {
342  return atoi(value);
343  }
344 
345  return def;
346  }
351  static const char* toString(const char* value, const char* def="") {
352  if (value!=NULL && value[0] != '\0') {
353  return value;
354  } else {
355  return def;
356  }
357  }
358 
359  static bool checkVariable(const char* var, DL_Codes::version version);
360 
362  return version;
363  }
364 
365  int getLibVersion(const char* str);
366 
367  static void test();
368 
369 private:
371  unsigned long styleHandleStd;
372 
374  double* vertices;
377 
378  double* knots;
379  int maxKnots;
381 
382  double* weights;
383  double* controlPoints;
387 
388  double* leaderVertices;
391 
392  // array of hatch loops
396  // array in format [loop#][edge#]
400  bool dropEdges;
401 
402  // Bulge for the next vertex.
403  double bulge;
404 
405  // Only the useful part of the group code
407  // ...same as integer
408  unsigned int groupCode;
409  // Only the useful part of the group value
410  char groupValue[DL_DXF_MAXLINE+1];
411  // Current entity type
413  // Value of the current setting
415  // Key of the current setting (e.g. "$ACADVER")
417  // Stores the group codes
419  // First call of this method. We initialize all group values in
420  // the first call.
421  bool firstCall;
422  // Attributes of the current entity (layer, color, width, line type)
424  // library version. hex: 0x20003001 = 2.0.3.1
426 };
427 
428 #endif
429 
430 // EOF