| TerraLib 4.1

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files
- Examples

- File List
- File Members

E:/Projetos_Primeiro_Semestre_2012/TerraView/terralib/src/dxflib/dl_dxf.h
Go to the documentation of this file.

    00001 /****************************************************************************
    00002 ** $Id: dl_dxf.h 9525 2011-05-13 18:45:30Z frederico.bede $
    00003 **
    00004 ** Copyright (C) 2001-2003 RibbonSoft. All rights reserved.
    00005 **
    00006 ** This file is part of the dxflib project.
    00007 **
    00008 ** This file may be distributed and/or modified under the terms of the
    00009 ** GNU General Public License version 2 as published by the Free Software
    00010 ** Foundation and appearing in the file LICENSE.GPL included in the
    00011 ** packaging of this file.
    00012 **
    00013 ** Licensees holding valid dxflib Professional Edition licenses may use
    00014 ** this file in accordance with the dxflib Commercial License
    00015 ** Agreement provided with the Software.
    00016 **
    00017 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
    00018 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
    00019 **
    00020 ** See http://www.ribbonsoft.com for further details.
    00021 **
    00022 ** Contact info@ribbonsoft.com if any conditions of this licensing are
    00023 ** not clear to you.
    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 #if defined(_MSC_VER) /* MSVC Compiler */
    00046 #pragma warning(disable: 4800)
    00047 #endif
    00048 #endif
    00049
    00050 #ifndef M_PI
    00051 #define M_PI 3.1415926535897932384626433832795
    00052 #endif
    00053
    00054 class DL_CreationInterface;
    00055 class DL_WriterA;
    00056
    00057
    00058 #define DL_VERSION     "2.2.0.0"
    00059
    00060 #define DL_UNKNOWN               0
    00061 #define DL_LAYER                10
    00062 #define DL_BLOCK                11
    00063 #define DL_ENDBLK               12
    00064 #define DL_LINETYPE             13
    00065 #define DL_SETTING              50
    00066 #define DL_ENTITY_POINT        100
    00067 #define DL_ENTITY_LINE         101
    00068 #define DL_ENTITY_POLYLINE     102
    00069 #define DL_ENTITY_LWPOLYLINE   103
    00070 #define DL_ENTITY_VERTEX       104
    00071 #define DL_ENTITY_SPLINE       105
    00072 #define DL_ENTITY_KNOT         106
    00073 #define DL_ENTITY_CONTROLPOINT 107
    00074 #define DL_ENTITY_ARC          108
    00075 #define DL_ENTITY_CIRCLE       109
    00076 #define DL_ENTITY_ELLIPSE      110
    00077 #define DL_ENTITY_INSERT       111
    00078 #define DL_ENTITY_TEXT         112
    00079 #define DL_ENTITY_MTEXT        113
    00080 #define DL_ENTITY_DIMENSION    114
    00081 #define DL_ENTITY_LEADER       115
    00082 #define DL_ENTITY_HATCH        116
    00083 #define DL_ENTITY_ATTRIB       117
    00084 #define DL_ENTITY_IMAGE        118
    00085 #define DL_ENTITY_IMAGEDEF     119
    00086 #define DL_ENTITY_TRACE        120
    00087 #define DL_ENTITY_SOLID        121
    00088 #define DL_ENTITY_3DFACE       122
    00089 #define DL_ENTITY_SEQEND       123
    00090
    00091
    00109 class DL_Dxf {
    00110 public:
    00111     DL_Dxf();
    00112     ~DL_Dxf();
    00113
    00114     bool in(const string& file,
    00115             DL_CreationInterface* creationInterface);
    00116     bool readDxfGroups(FILE* fp,
    00117                        DL_CreationInterface* creationInterface,
    00118                                                           int* errorCounter = NULL);
    00119     static bool getChoppedLine(char* s, unsigned int size,
    00120                                FILE *stream);
    00121
    00122 #ifndef __GCC2x__
    00123     bool readDxfGroups(std::stringstream &stream,
    00124                        DL_CreationInterface* creationInterface,
    00125                                                           int* errorCounter = NULL);
    00126     bool in(std::stringstream &stream,
    00127             DL_CreationInterface* creationInterface);
    00128     static bool getChoppedLine(char *s, unsigned int size,
    00129                                std::stringstream &stream);
    00130 #endif
    00131
    00132     static bool stripWhiteSpace(char** s);
    00133
    00134     bool processDXFGroup(DL_CreationInterface* creationInterface,
    00135                          int groupCode, const char* groupValue);
    00136     void addSetting(DL_CreationInterface* creationInterface);
    00137     void addLayer(DL_CreationInterface* creationInterface);
    00138     void addBlock(DL_CreationInterface* creationInterface);
    00139     void endBlock(DL_CreationInterface* creationInterface);
    00140
    00141     void addPoint(DL_CreationInterface* creationInterface);
    00142     void addLine(DL_CreationInterface* creationInterface);
    00143
    00144     void addPolyline(DL_CreationInterface* creationInterface);
    00145     void addVertex(DL_CreationInterface* creationInterface);
    00146
    00147     void addSpline(DL_CreationInterface* creationInterface);
    00148     //void addKnot(DL_CreationInterface* creationInterface);
    00149     //void addControlPoint(DL_CreationInterface* creationInterface);
    00150
    00151     void addArc(DL_CreationInterface* creationInterface);
    00152     void addCircle(DL_CreationInterface* creationInterface);
    00153     void addEllipse(DL_CreationInterface* creationInterface);
    00154     void addInsert(DL_CreationInterface* creationInterface);
    00155
    00156     void addTrace(DL_CreationInterface* creationInterface);
    00157     void add3dFace(DL_CreationInterface* creationInterface);
    00158     void addSolid(DL_CreationInterface* creationInterface);
    00159
    00160     void addMText(DL_CreationInterface* creationInterface);
    00161            bool handleMTextData(DL_CreationInterface* creationInterface);
    00162            bool handleLWPolylineData(DL_CreationInterface* creationInterface);
    00163            bool handleSplineData(DL_CreationInterface* creationInterface);
    00164            bool handleLeaderData(DL_CreationInterface* creationInterface);
    00165            bool handleHatchData(DL_CreationInterface* creationInterface);
    00166
    00167     void addText(DL_CreationInterface* creationInterface);
    00168     void addAttrib(DL_CreationInterface* creationInterface);
    00169     DL_DimensionData getDimData();
    00170     void addDimLinear(DL_CreationInterface* creationInterface);
    00171     void addDimAligned(DL_CreationInterface* creationInterface);
    00172     void addDimRadial(DL_CreationInterface* creationInterface);
    00173     void addDimDiametric(DL_CreationInterface* creationInterface);
    00174     void addDimAngular(DL_CreationInterface* creationInterface);
    00175     void addDimAngular3P(DL_CreationInterface* creationInterface);
    00176     void addDimOrdinate(DL_CreationInterface* creationInterface);
    00177     void addLeader(DL_CreationInterface* creationInterface);
    00178     void addHatch(DL_CreationInterface* creationInterface);
    00179     void addImage(DL_CreationInterface* creationInterface);
    00180     void addImageDef(DL_CreationInterface* creationInterface);
    00181
    00182     void addComment(DL_CreationInterface* creationInterface, const char* comment);
    00183
    00184            void endEntity(DL_CreationInterface* creationInterface);
    00185
    00186     void endSequence(DL_CreationInterface* creationInterface);
    00187
    00188            int  stringToInt(const char* s, bool* ok=NULL);
    00189
    00190     DL_WriterA* out(const char* file,
    00191                     DL_Codes::version version=VER_2000);
    00192
    00193     void writeHeader(DL_WriterA& dw);
    00194
    00195     void writePoint(DL_WriterA& dw,
    00196                     const DL_PointData& data,
    00197                     const DL_Attributes& attrib);
    00198     void writeLine(DL_WriterA& dw,
    00199                    const DL_LineData& data,
    00200                    const DL_Attributes& attrib);
    00201     void writePolyline(DL_WriterA& dw,
    00202                        const DL_PolylineData& data,
    00203                        const DL_Attributes& attrib);
    00204     void writeVertex(DL_WriterA& dw,
    00205                      const DL_VertexData& data);
    00206     void writePolylineEnd(DL_WriterA& dw);
    00207     void writeSpline(DL_WriterA& dw,
    00208                        const DL_SplineData& data,
    00209                        const DL_Attributes& attrib);
    00210     void writeControlPoint(DL_WriterA& dw,
    00211                      const DL_ControlPointData& data);
    00212     void writeKnot(DL_WriterA& dw,
    00213                      const DL_KnotData& data);
    00214     void writeCircle(DL_WriterA& dw,
    00215                      const DL_CircleData& data,
    00216                      const DL_Attributes& attrib);
    00217     void writeArc(DL_WriterA& dw,
    00218                   const DL_ArcData& data,
    00219                   const DL_Attributes& attrib);
    00220     void writeEllipse(DL_WriterA& dw,
    00221                       const DL_EllipseData& data,
    00222                       const DL_Attributes& attrib);
    00223     void writeSolid(DL_WriterA& dw,
    00224                    const DL_SolidData& data,
    00225                    const DL_Attributes& attrib);
    00226     void write3dFace(DL_WriterA& dw,
    00227                    const DL_3dFaceData& data,
    00228                    const DL_Attributes& attrib);
    00229     void writeInsert(DL_WriterA& dw,
    00230                      const DL_InsertData& data,
    00231                      const DL_Attributes& attrib);
    00232     void writeMText(DL_WriterA& dw,
    00233                     const DL_MTextData& data,
    00234                     const DL_Attributes& attrib);
    00235     void writeText(DL_WriterA& dw,
    00236                     const DL_TextData& data,
    00237                     const DL_Attributes& attrib);
    00238     void writeDimAligned(DL_WriterA& dw,
    00239                          const DL_DimensionData& data,
    00240                          const DL_DimAlignedData& edata,
    00241                          const DL_Attributes& attrib);
    00242     void writeDimLinear(DL_WriterA& dw,
    00243                         const DL_DimensionData& data,
    00244                         const DL_DimLinearData& edata,
    00245                         const DL_Attributes& attrib);
    00246     void writeDimRadial(DL_WriterA& dw,
    00247                         const DL_DimensionData& data,
    00248                         const DL_DimRadialData& edata,
    00249                         const DL_Attributes& attrib);
    00250     void writeDimDiametric(DL_WriterA& dw,
    00251                            const DL_DimensionData& data,
    00252                            const DL_DimDiametricData& edata,
    00253                            const DL_Attributes& attrib);
    00254     void writeDimAngular(DL_WriterA& dw,
    00255                          const DL_DimensionData& data,
    00256                          const DL_DimAngularData& edata,
    00257                          const DL_Attributes& attrib);
    00258     void writeDimAngular3P(DL_WriterA& dw,
    00259                            const DL_DimensionData& data,
    00260                            const DL_DimAngular3PData& edata,
    00261                            const DL_Attributes& attrib);
    00262     void writeDimOrdinate(DL_WriterA& dw,
    00263                          const DL_DimensionData& data,
    00264                          const DL_DimOrdinateData& edata,
    00265                          const DL_Attributes& attrib);
    00266     void writeLeader(DL_WriterA& dw,
    00267                      const DL_LeaderData& data,
    00268                      const DL_Attributes& attrib);
    00269     void writeLeaderVertex(DL_WriterA& dw,
    00270                            const DL_LeaderVertexData& data);
    00271     void writeHatch1(DL_WriterA& dw,
    00272                      const DL_HatchData& data,
    00273                      const DL_Attributes& attrib);
    00274     void writeHatch2(DL_WriterA& dw,
    00275                      const DL_HatchData& data,
    00276                      const DL_Attributes& attrib);
    00277     void writeHatchLoop1(DL_WriterA& dw,
    00278                          const DL_HatchLoopData& data);
    00279     void writeHatchLoop2(DL_WriterA& dw,
    00280                          const DL_HatchLoopData& data);
    00281     void writeHatchEdge(DL_WriterA& dw,
    00282                         const DL_HatchEdgeData& data);
    00283
    00284     int writeImage(DL_WriterA& dw,
    00285                    const DL_ImageData& data,
    00286                    const DL_Attributes& attrib);
    00287
    00288     void writeImageDef(DL_WriterA& dw, int handle,
    00289                        const DL_ImageData& data);
    00290
    00291     void writeLayer(DL_WriterA& dw,
    00292                     const DL_LayerData& data,
    00293                     const DL_Attributes& attrib);
    00294
    00295     void writeLineType(DL_WriterA& dw,
    00296                        const DL_LineTypeData& data);
    00297
    00298     void writeAppid(DL_WriterA& dw, const string& name);
    00299
    00300     void writeBlock(DL_WriterA& dw,
    00301                     const DL_BlockData& data);
    00302     void writeEndBlock(DL_WriterA& dw, const string& name);
    00303
    00304     void writeVPort(DL_WriterA& dw);
    00305     void writeStyle(DL_WriterA& dw);
    00306     void writeView(DL_WriterA& dw);
    00307     void writeUcs(DL_WriterA& dw);
    00308     void writeDimStyle(DL_WriterA& dw,
    00309                               double dimasz, double dimexe, double dimexo,
    00310                                                           double dimgap, double dimtxt);
    00311     void writeBlockRecord(DL_WriterA& dw);
    00312     void writeBlockRecord(DL_WriterA& dw, const string& name);
    00313     void writeObjects(DL_WriterA& dw);
    00314     void writeObjectsEnd(DL_WriterA& dw);
    00315
    00316     void writeComment(DL_WriterA& dw, const string& comment);
    00317
    00322     static double toReal(const char* value, double def=0.0) {
    00323        if (value!=NULL && value[0] != '\0') {
    00324             double ret;
    00325             if (strchr(value, ',') != NULL) {
    00326                char* tmp = new char[strlen(value)+1];
    00327                strcpy(tmp, value);
    00328                DL_WriterA::strReplace(tmp, ',', '.');
    00329                ret = atof(tmp);
    00330                          delete[] tmp;
    00331             }
    00332             else {
    00333                ret = atof(value);
    00334             }
    00335                                  return ret;
    00336         } else {
    00337             return def;
    00338         }
    00339     }
    00344     static int toInt(const char* value, int def=0) {
    00345         if (value!=NULL && value[0] != '\0') {
    00346             return atoi(value);
    00347         } else {
    00348             return def;
    00349         }
    00350     }
    00355     static const char* toString(const char* value, const char* def="") {
    00356         if (value!=NULL && value[0] != '\0') {
    00357             return value;
    00358         } else {
    00359             return def;
    00360         }
    00361     }
    00362
    00363            static bool checkVariable(const char* var, DL_Codes::version version);
    00364
    00365            DL_Codes::version getVersion() {
    00366                       return version;
    00367            }
    00368
    00369            int getLibVersion(const char* str);
    00370
    00371            static void test();
    00372
    00373 private:
    00374     DL_Codes::version version;
    00375     unsigned long styleHandleStd;
    00376
    00377            string polylineLayer;
    00378     double* vertices;
    00379     int maxVertices;
    00380     int vertexIndex;
    00381
    00382     double* knots;
    00383     int maxKnots;
    00384     int knotIndex;
    00385
    00386     double* controlPoints;
    00387     int maxControlPoints;
    00388     int controlPointIndex;
    00389
    00390     double* leaderVertices;
    00391     int maxLeaderVertices;
    00392     int leaderVertexIndex;
    00393
    00394     // array of hatch loops
    00395     DL_HatchLoopData* hatchLoops;
    00396     int maxHatchLoops;
    00397     int hatchLoopIndex;
    00398     // array in format [loop#][edge#]
    00399     DL_HatchEdgeData** hatchEdges;
    00400     int* maxHatchEdges;
    00401     int* hatchEdgeIndex;
    00402     bool dropEdges;
    00403
    00404     // Bulge for the next vertex.
    00405     double bulge;
    00406
    00407     // Only the useful part of the group code
    00408     char groupCodeTmp[DL_DXF_MAXLINE+1];
    00409     // ...same as integer
    00410     unsigned int groupCode;
    00411     // Only the useful part of the group value
    00412     char groupValue[DL_DXF_MAXLINE+1];
    00413     // Current entity type
    00414     int currentEntity;
    00415     // Value of the current setting
    00416     char settingValue[DL_DXF_MAXLINE+1];
    00417     // Key of the current setting (e.g. "$ACADVER")
    00418     char settingKey[DL_DXF_MAXLINE+1];
    00419     // Stores the group codes
    00420     char values[DL_DXF_MAXGROUPCODE][DL_DXF_MAXLINE+1];
    00421     // First call of this method. We initialize all group values in
    00422     //  the first call.
    00423     bool firstCall;
    00424     // Attributes of the current entity (layer, color, width, line type)
    00425     DL_Attributes attrib;
    00426            // library version. hex: 0x20003001 = 2.0.3.1
    00427            int libVersion;
    00428 };
    00429
    00430 #endif
    00431
    00432 // EOF

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines