| 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_writer.h
Go to the documentation of this file.

    00001 /****************************************************************************
    00002 ** $Id: dl_writer.h 8171 2009-12-11 12:31:36Z fredbed $
    00003 **
    00004 ** Copyright (C) 2001-2003 RibbonSoft. All rights reserved.
    00005 ** Copyright (C) 2001 Robert J. Campbell Jr.
    00006 **
    00007 ** This file is part of the dxflib project.
    00008 **
    00009 ** This file may be distributed and/or modified under the terms of the
    00010 ** GNU General Public License version 2 as published by the Free Software
    00011 ** Foundation and appearing in the file LICENSE.GPL included in the
    00012 ** packaging of this file.
    00013 **
    00014 ** Licensees holding valid dxflib Professional Edition licenses may use
    00015 ** this file in accordance with the dxflib Commercial License
    00016 ** Agreement provided with the Software.
    00017 **
    00018 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
    00019 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
    00020 **
    00021 ** See http://www.ribbonsoft.com for further details.
    00022 **
    00023 ** Contact info@ribbonsoft.com if any conditions of this licensing are
    00024 ** not clear to you.
    00025 **
    00026 **********************************************************************/
    00027
    00028 #ifndef DL_WRITER_H
    00029 #define DL_WRITER_H
    00030
    00031 #if _MSC_VER > 1000
    00032 #pragma once
    00033 #endif // _MSC_VER > 1000
    00034
    00035 #if defined(__OS2__)||defined(__EMX__)
    00036 #define strcasecmp(s,t) stricmp(s,t)
    00037 #endif
    00038
    00039 #if defined(WIN32)
    00040 #define strcasecmp(s,t) _stricmp(s,t)
    00041 #endif
    00042
    00043 #include <iostream>
    00044
    00045 #include "dl_attributes.h"
    00046 #include "dl_codes.h"
    00047
    00048 #include <cstring>
    00049
    00060 class DL_Writer {
    00061 public:
    00065     DL_Writer(DL_Codes::version version) : m_handle(0x30) {
    00066         this->version = version;
    00067         modelSpaceHandle = 0;
    00068         paperSpaceHandle = 0;
    00069         paperSpace0Handle = 0;
    00070     }
    00071
    00072     virtual ~DL_Writer() {}
    00073     ;
    00074
    00084     void section(const char* name) const {
    00085         dxfString(0, "SECTION");
    00086         dxfString(2, name);
    00087     }
    00088
    00099     void sectionHeader() const {
    00100         section("HEADER");
    00101     }
    00102
    00113     void sectionTables() const {
    00114         section("TABLES");
    00115     }
    00116
    00127     void sectionBlocks() const {
    00128         section("BLOCKS");
    00129     }
    00130
    00141     void sectionEntities() const {
    00142         section("ENTITIES");
    00143     }
    00144
    00155     void sectionClasses() const {
    00156         section("CLASSES");
    00157     }
    00158
    00169     void sectionObjects() const {
    00170         section("OBJECTS");
    00171     }
    00172
    00181     void sectionEnd() const {
    00182         dxfString(0, "ENDSEC");
    00183     }
    00184
    00197     void table(const char* name, int num, int handle) const {
    00198         dxfString(0, "TABLE");
    00199         dxfString(2, name);
    00200         if (version>=VER_2000) {
    00201             dxfHex(5, handle);
    00202             dxfString(100, "AcDbSymbolTable");
    00203         }
    00204         dxfInt(70, num);
    00205     }
    00206
    00220     void tableLayers(int num) const {
    00221         table("LAYER", num, 2);
    00222     }
    00223
    00237     void tableLineTypes(int num) const {
    00238         //lineTypeHandle = 5;
    00239         table("LTYPE", num, 5);
    00240     }
    00241
    00255     void tableAppid(int num) const {
    00256         table("APPID", num, 9);
    00257     }
    00258
    00267     void tableEnd() const {
    00268         dxfString(0, "ENDTAB");
    00269     }
    00270
    00279     void dxfEOF() const {
    00280         dxfString(0, "EOF");
    00281     }
    00282
    00291     void comment(const char* text) const {
    00292         dxfString(999, text);
    00293     }
    00294
    00305     void entity(const char* entTypeName) const {
    00306         dxfString(0, entTypeName);
    00307         if (version>=VER_2000) {
    00308             handle();
    00309         }
    00310     }
    00311
    00326     void entityAttributes(const DL_Attributes& attrib) const {
    00327
    00328                       // layer name:
    00329         dxfString(8, attrib.getLayer());
    00330
    00331                       // R12 doesn't accept BYLAYER values. The value has to be missing
    00332                       //   in that case.
    00333         if (version>=VER_2000 ||
    00334                                  attrib.getColor()!=256) {
    00335            dxfInt(62, attrib.getColor());
    00336                       }
    00337         if (version>=VER_2000) {
    00338             dxfInt(370, attrib.getWidth());
    00339         }
    00340         if (version>=VER_2000 ||
    00341                                  strcasecmp(attrib.getLineType().c_str(), "BYLAYER")) {
    00342                    dxfString(6, attrib.getLineType());
    00343                       }
    00344     }
    00345
    00349     void subClass(const char* sub) const {
    00350         dxfString(100, sub);
    00351     }
    00352
    00361     void tableLayerEntry(unsigned long int h=0)  const {
    00362         dxfString(0, "LAYER");
    00363         if (version>=VER_2000) {
    00364             if (h==0) {
    00365                 handle();
    00366             } else {
    00367                 dxfHex(5, h);
    00368             }
    00369             dxfString(100, "AcDbSymbolTableRecord");
    00370             dxfString(100, "AcDbLayerTableRecord");
    00371         }
    00372     }
    00373
    00382     void tableLineTypeEntry(unsigned long int h=0)  const {
    00383         dxfString(0, "LTYPE");
    00384         if (version>=VER_2000) {
    00385             if (h==0) {
    00386                 handle();
    00387             } else {
    00388                 dxfHex(5, h);
    00389             }
    00390             //dxfHex(330, 0x5);
    00391             dxfString(100, "AcDbSymbolTableRecord");
    00392             dxfString(100, "AcDbLinetypeTableRecord");
    00393         }
    00394     }
    00395
    00404     void tableAppidEntry(unsigned long int h=0)  const {
    00405         dxfString(0, "APPID");
    00406         if (version>=VER_2000) {
    00407             if (h==0) {
    00408                 handle();
    00409             } else {
    00410                 dxfHex(5, h);
    00411             }
    00412             //dxfHex(330, 0x9);
    00413             dxfString(100, "AcDbSymbolTableRecord");
    00414             dxfString(100, "AcDbRegAppTableRecord");
    00415         }
    00416     }
    00417
    00426     void sectionBlockEntry(unsigned long int h=0)  const {
    00427         dxfString(0, "BLOCK");
    00428         if (version>=VER_2000) {
    00429             if (h==0) {
    00430                 handle();
    00431             } else {
    00432                 dxfHex(5, h);
    00433             }
    00434             //dxfHex(330, blockHandle);
    00435             dxfString(100, "AcDbEntity");
    00436             if (h==0x1C) {
    00437                 dxfInt(67, 1);
    00438             }
    00439             dxfString(8, "0");                 // TODO: Layer for block
    00440             dxfString(100, "AcDbBlockBegin");
    00441         }
    00442     }
    00443
    00452     void sectionBlockEntryEnd(unsigned long int h=0)  const {
    00453         dxfString(0, "ENDBLK");
    00454         if (version>=VER_2000) {
    00455             if (h==0) {
    00456                 handle();
    00457             } else {
    00458                 dxfHex(5, h);
    00459             }
    00460             //dxfHex(330, blockHandle);
    00461             dxfString(100, "AcDbEntity");
    00462             if (h==0x1D) {
    00463                 dxfInt(67, 1);
    00464             }
    00465             dxfString(8, "0");                 // TODO: Layer for block
    00466             dxfString(100, "AcDbBlockEnd");
    00467         }
    00468     }
    00469
    00470     void color(int col=256) const {
    00471         dxfInt(62, col);
    00472     }
    00473     void lineType(const char *lt) const {
    00474         dxfString(6, lt);
    00475     }
    00476     void lineTypeScale(double scale) const {
    00477         dxfReal(48, scale);
    00478     }
    00479     void lineWeight(int lw) const {
    00480         dxfInt(370, lw);
    00481     }
    00482
    00483     void coord(int gc, double x, double y, double z=0) const {
    00484         dxfReal(gc, x);
    00485         dxfReal(gc+10, y);
    00486         dxfReal(gc+20, z);
    00487     }
    00488
    00489     void coordTriplet(int gc, const double* value) const {
    00490         if (value) {
    00491             dxfReal(gc, *value++);
    00492             dxfReal(gc+10, *value++);
    00493             dxfReal(gc+20, *value++);
    00494         }
    00495     }
    00496
    00497     void resetHandle() const {
    00498         m_handle = 1;
    00499     }
    00500
    00504     unsigned long handle(int gc=5) const {
    00505         // handle has to be hex
    00506         dxfHex(gc, m_handle);
    00507         return m_handle++;
    00508     }
    00509
    00513     unsigned long getNextHandle() const {
    00514         return m_handle;
    00515     }
    00516
    00520     unsigned long incHandle() const {
    00521         return m_handle++;
    00522     }
    00523
    00528     void setModelSpaceHandle(unsigned long h) {
    00529         modelSpaceHandle = h;
    00530     }
    00531
    00532     unsigned long getModelSpaceHandle() {
    00533         return modelSpaceHandle;
    00534     }
    00535
    00540     void setPaperSpaceHandle(unsigned long h) {
    00541         paperSpaceHandle = h;
    00542     }
    00543
    00544     unsigned long getPaperSpaceHandle() {
    00545         return paperSpaceHandle;
    00546     }
    00547
    00552     void setPaperSpace0Handle(unsigned long h) {
    00553         paperSpace0Handle = h;
    00554     }
    00555
    00556     unsigned long getPaperSpace0Handle() {
    00557         return paperSpace0Handle;
    00558     }
    00559
    00567     virtual void dxfReal(int gc, double value) const = 0;
    00568
    00576     virtual void dxfInt(int gc, int value) const = 0;
    00577
    00585     virtual void dxfHex(int gc, int value) const = 0;
    00586
    00594     virtual void dxfString(int gc, const char* value) const = 0;
    00595
    00603     virtual void dxfString(int gc, const string& value) const = 0;
    00604
    00605 protected:
    00606     mutable unsigned long m_handle;
    00607     mutable unsigned long modelSpaceHandle;
    00608     mutable unsigned long paperSpaceHandle;
    00609     mutable unsigned long paperSpace0Handle;
    00610
    00614     DL_Codes::version version;
    00615 private:
    00616 };
    00617
    00618 #endif

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines