00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #ifndef DL_DXF_H
00028 #define DL_DXF_H
00029
00030 #include <stdio.h>
00031 #include <stdlib.h>
00032 #include <string.h>
00033 #ifndef __GCC2x__
00034 #include <sstream>
00035 #endif
00036
00037 #include "dl_attributes.h"
00038 #include "dl_codes.h"
00039 #include "dl_entities.h"
00040 #include "dl_writer_ascii.h"
00041
00042 #ifdef _WIN32
00043 #undef M_PI
00044 #define M_PI 3.14159265358979323846
00045 #pragma warning(disable : 4800)
00046 #endif
00047
00048 #ifndef M_PI
00049 #define M_PI 3.1415926535897932384626433832795
00050 #endif
00051
00052 class DL_CreationInterface;
00053 class DL_WriterA;
00054
00055
00056 #define DL_VERSION "2.1.0.2"
00057
00058 #define DL_UNKNOWN 0
00059 #define DL_LAYER 10
00060 #define DL_BLOCK 11
00061 #define DL_ENDBLK 12
00062 #define DL_LINETYPE 13
00063 #define DL_SETTING 50
00064 #define DL_ENTITY_POINT 100
00065 #define DL_ENTITY_LINE 101
00066 #define DL_ENTITY_POLYLINE 102
00067 #define DL_ENTITY_LWPOLYLINE 103
00068 #define DL_ENTITY_VERTEX 104
00069 #define DL_ENTITY_SPLINE 105
00070 #define DL_ENTITY_KNOT 106
00071 #define DL_ENTITY_CONTROLPOINT 107
00072 #define DL_ENTITY_ARC 108
00073 #define DL_ENTITY_CIRCLE 109
00074 #define DL_ENTITY_ELLIPSE 110
00075 #define DL_ENTITY_INSERT 111
00076 #define DL_ENTITY_TEXT 112
00077 #define DL_ENTITY_MTEXT 113
00078 #define DL_ENTITY_DIMENSION 114
00079 #define DL_ENTITY_LEADER 115
00080 #define DL_ENTITY_HATCH 116
00081 #define DL_ENTITY_ATTRIB 117
00082 #define DL_ENTITY_IMAGE 118
00083 #define DL_ENTITY_IMAGEDEF 119
00084 #define DL_ENTITY_TRACE 120
00085 #define DL_ENTITY_SOLID 121
00086 #define DL_ENTITY_SEQEND 122
00087
00088
00106 class DL_Dxf {
00107 public:
00108 DL_Dxf();
00109 ~DL_Dxf();
00110
00111 bool in(const string& file,
00112 DL_CreationInterface* creationInterface);
00113 bool readDxfGroups(FILE* fp,
00114 DL_CreationInterface* creationInterface,
00115 int* errorCounter = NULL);
00116 static bool getChoppedLine(char* s, unsigned int size,
00117 FILE *stream);
00118
00119 #ifndef __GCC2x__
00120
00121 bool readDxfGroups(std::stringstream &stream,
00122 DL_CreationInterface* creationInterface,
00123 int* errorCounter = NULL);
00124 bool in(std::stringstream &stream,
00125 DL_CreationInterface* creationInterface);
00126 static bool getChoppedLine(char *s, unsigned int size,
00127 std::stringstream &stream);
00128 #endif
00129
00130 static bool stripWhiteSpace(char** s);
00131
00132 bool processDXFGroup(DL_CreationInterface* creationInterface,
00133 int groupCode, const char* groupValue);
00134 void addSetting(DL_CreationInterface* creationInterface);
00135 void addLayer(DL_CreationInterface* creationInterface);
00136 void addBlock(DL_CreationInterface* creationInterface);
00137 void endBlock(DL_CreationInterface* creationInterface);
00138
00139 void addPoint(DL_CreationInterface* creationInterface);
00140 void addLine(DL_CreationInterface* creationInterface);
00141
00142 void addPolyline(DL_CreationInterface* creationInterface);
00143 void addVertex(DL_CreationInterface* creationInterface);
00144
00145 void addSpline(DL_CreationInterface* creationInterface);
00146
00147
00148
00149 void addArc(DL_CreationInterface* creationInterface);
00150 void addCircle(DL_CreationInterface* creationInterface);
00151 void addEllipse(DL_CreationInterface* creationInterface);
00152 void addInsert(DL_CreationInterface* creationInterface);
00153
00154 void addTrace(DL_CreationInterface* creationInterface);
00155 void addSolid(DL_CreationInterface* creationInterface);
00156
00157 void addMText(DL_CreationInterface* creationInterface);
00158 bool handleMTextData(DL_CreationInterface* creationInterface);
00159 bool handleLWPolylineData(DL_CreationInterface* creationInterface);
00160 bool handleSplineData(DL_CreationInterface* creationInterface);
00161 bool handleLeaderData(DL_CreationInterface* creationInterface);
00162 bool handleHatchData(DL_CreationInterface* creationInterface);
00163
00164 void addText(DL_CreationInterface* creationInterface);
00165 void addAttrib(DL_CreationInterface* creationInterface);
00166 DL_DimensionData getDimData();
00167 void addDimLinear(DL_CreationInterface* creationInterface);
00168 void addDimAligned(DL_CreationInterface* creationInterface);
00169 void addDimRadial(DL_CreationInterface* creationInterface);
00170 void addDimDiametric(DL_CreationInterface* creationInterface);
00171 void addDimAngular(DL_CreationInterface* creationInterface);
00172 void addDimAngular3P(DL_CreationInterface* creationInterface);
00173 void addLeader(DL_CreationInterface* creationInterface);
00174 void addHatch(DL_CreationInterface* creationInterface);
00175 void addImage(DL_CreationInterface* creationInterface);
00176 void addImageDef(DL_CreationInterface* creationInterface);
00177
00178 void endEntity(DL_CreationInterface* creationInterface);
00179
00180 void endSequence(DL_CreationInterface* creationInterface);
00181
00182 int stringToInt(const char* s, bool* ok=NULL);
00183
00184 DL_WriterA* out(const char* file,
00185 DL_Codes::version version=VER_2000);
00186
00187 void writeHeader(DL_WriterA& dw);
00188
00189 void writePoint(DL_WriterA& dw,
00190 const DL_PointData& data,
00191 const DL_Attributes& attrib);
00192 void writeLine(DL_WriterA& dw,
00193 const DL_LineData& data,
00194 const DL_Attributes& attrib);
00195 void writePolyline(DL_WriterA& dw,
00196 const DL_PolylineData& data,
00197 const DL_Attributes& attrib);
00198 void writeVertex(DL_WriterA& dw,
00199 const DL_VertexData& data);
00200 void writePolylineEnd(DL_WriterA& dw);
00201 void writeSpline(DL_WriterA& dw,
00202 const DL_SplineData& data,
00203 const DL_Attributes& attrib);
00204 void writeControlPoint(DL_WriterA& dw,
00205 const DL_ControlPointData& data);
00206 void writeKnot(DL_WriterA& dw,
00207 const DL_KnotData& data);
00208 void writeCircle(DL_WriterA& dw,
00209 const DL_CircleData& data,
00210 const DL_Attributes& attrib);
00211 void writeArc(DL_WriterA& dw,
00212 const DL_ArcData& data,
00213 const DL_Attributes& attrib);
00214 void writeEllipse(DL_WriterA& dw,
00215 const DL_EllipseData& data,
00216 const DL_Attributes& attrib);
00217 void writeInsert(DL_WriterA& dw,
00218 const DL_InsertData& data,
00219 const DL_Attributes& attrib);
00220 void writeMText(DL_WriterA& dw,
00221 const DL_MTextData& data,
00222 const DL_Attributes& attrib);
00223 void writeText(DL_WriterA& dw,
00224 const DL_TextData& data,
00225 const DL_Attributes& attrib);
00226 void writeDimAligned(DL_WriterA& dw,
00227 const DL_DimensionData& data,
00228 const DL_DimAlignedData& edata,
00229 const DL_Attributes& attrib);
00230 void writeDimLinear(DL_WriterA& dw,
00231 const DL_DimensionData& data,
00232 const DL_DimLinearData& edata,
00233 const DL_Attributes& attrib);
00234 void writeDimRadial(DL_WriterA& dw,
00235 const DL_DimensionData& data,
00236 const DL_DimRadialData& edata,
00237 const DL_Attributes& attrib);
00238 void writeDimDiametric(DL_WriterA& dw,
00239 const DL_DimensionData& data,
00240 const DL_DimDiametricData& edata,
00241 const DL_Attributes& attrib);
00242 void writeDimAngular(DL_WriterA& dw,
00243 const DL_DimensionData& data,
00244 const DL_DimAngularData& edata,
00245 const DL_Attributes& attrib);
00246 void writeDimAngular3P(DL_WriterA& dw,
00247 const DL_DimensionData& data,
00248 const DL_DimAngular3PData& edata,
00249 const DL_Attributes& attrib);
00250 void writeLeader(DL_WriterA& dw,
00251 const DL_LeaderData& data,
00252 const DL_Attributes& attrib);
00253 void writeLeaderVertex(DL_WriterA& dw,
00254 const DL_LeaderVertexData& data);
00255 void writeHatch1(DL_WriterA& dw,
00256 const DL_HatchData& data,
00257 const DL_Attributes& attrib);
00258 void writeHatch2(DL_WriterA& dw,
00259 const DL_HatchData& data,
00260 const DL_Attributes& attrib);
00261 void writeHatchLoop1(DL_WriterA& dw,
00262 const DL_HatchLoopData& data);
00263 void writeHatchLoop2(DL_WriterA& dw,
00264 const DL_HatchLoopData& data);
00265 void writeHatchEdge(DL_WriterA& dw,
00266 const DL_HatchEdgeData& data);
00267
00268 int writeImage(DL_WriterA& dw,
00269 const DL_ImageData& data,
00270 const DL_Attributes& attrib);
00271
00272 void writeImageDef(DL_WriterA& dw, int handle,
00273 const DL_ImageData& data);
00274
00275 void writeLayer(DL_WriterA& dw,
00276 const DL_LayerData& data,
00277 const DL_Attributes& attrib);
00278
00279 void writeLineType(DL_WriterA& dw,
00280 const DL_LineTypeData& data);
00281
00282 void writeAppid(DL_WriterA& dw, const string& name);
00283
00284 void writeBlock(DL_WriterA& dw,
00285 const DL_BlockData& data);
00286 void writeEndBlock(DL_WriterA& dw, const string& name);
00287
00288 void writeVPort(DL_WriterA& dw);
00289 void writeStyle(DL_WriterA& dw);
00290 void writeView(DL_WriterA& dw);
00291 void writeUcs(DL_WriterA& dw);
00292 void writeDimStyle(DL_WriterA& dw,
00293 double dimasz, double dimexe, double dimexo,
00294 double dimgap, double dimtxt);
00295 void writeBlockRecord(DL_WriterA& dw);
00296 void writeBlockRecord(DL_WriterA& dw, const string& name);
00297 void writeObjects(DL_WriterA& dw);
00298 void writeObjectsEnd(DL_WriterA& dw);
00299
00304 static double toReal(const char* value, double def=0.0) {
00305 if (value!=NULL && value[0] != '\0') {
00306 double ret;
00307 if (strchr(value, ',') != NULL) {
00308 char* tmp = new char[strlen(value)+1];
00309 strcpy(tmp, value);
00310 DL_WriterA::strReplace(tmp, ',', '.');
00311 ret = atof(tmp);
00312 delete[] tmp;
00313 }
00314 else {
00315 ret = atof(value);
00316 }
00317 return ret;
00318 } else {
00319 return def;
00320 }
00321 }
00326 static int toInt(const char* value, int def=0) {
00327 if (value!=NULL && value[0] != '\0') {
00328 return atoi(value);
00329 } else {
00330 return def;
00331 }
00332 }
00337 static const char* toString(const char* value, const char* def="") {
00338 if (value!=NULL && value[0] != '\0') {
00339 return value;
00340 } else {
00341 return def;
00342 }
00343 }
00344
00345 static bool checkVariable(const char* var, DL_Codes::version version);
00346
00347 DL_Codes::version getVersion() {
00348 return version;
00349 }
00350
00351 int getLibVersion(const char* str);
00352
00353 static void test();
00354
00355 private:
00356 DL_Codes::version version;
00357 unsigned long styleHandleStd;
00358
00359 string polylineLayer;
00360 double* vertices;
00361 int maxVertices;
00362 int vertexIndex;
00363
00364 double* knots;
00365 int maxKnots;
00366 int knotIndex;
00367
00368 double* controlPoints;
00369 int maxControlPoints;
00370 int controlPointIndex;
00371
00372 double* leaderVertices;
00373 int maxLeaderVertices;
00374 int leaderVertexIndex;
00375
00376
00377 DL_HatchLoopData* hatchLoops;
00378 int maxHatchLoops;
00379 int hatchLoopIndex;
00380
00381 DL_HatchEdgeData** hatchEdges;
00382 int* maxHatchEdges;
00383 int* hatchEdgeIndex;
00384 bool dropEdges;
00385
00386
00387 double bulge;
00388
00389
00390 char groupCodeTmp[DL_DXF_MAXLINE+1];
00391
00392 unsigned int groupCode;
00393
00394 char groupValue[DL_DXF_MAXLINE+1];
00395
00396 int currentEntity;
00397
00398 char settingValue[DL_DXF_MAXLINE+1];
00399
00400 char settingKey[DL_DXF_MAXLINE+1];
00401
00402 char values[DL_DXF_MAXGROUPCODE][DL_DXF_MAXLINE+1];
00403
00404
00405 bool firstCall;
00406
00407 DL_Attributes attrib;
00408
00409 int libVersion;
00410 };
00411
00412 #endif
00413
00414