Main Page | Class Hierarchy | Class List | Directories | File List | Class Members | Related Pages

dl_writer.h

00001 /****************************************************************************
00002 ** $Id: dl_writer.h 2398 2005-06-06 18:12:14Z andrew $
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 [email protected] 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__)||defined(_WIN32)
00036 #define strcasecmp(s,t) stricmp(s,t)
00037 #endif
00038 
00039 #include <iostream>
00040 
00041 #include "dl_attributes.h"
00042 #include "dl_codes.h"
00043 
00044 
00045 
00056 class DL_Writer {
00057 public:
00061     DL_Writer(DL_Codes::version version) : m_handle(0x30) {
00062         this->version = version;
00063         modelSpaceHandle = 0;
00064         paperSpaceHandle = 0;
00065         paperSpace0Handle = 0;
00066     }
00067 
00068     virtual ~DL_Writer() {}
00069     ;
00070 
00080     void section(const char* name) const {
00081         dxfString(0, "SECTION");
00082         dxfString(2, name);
00083     }
00084 
00095     void sectionHeader() const {
00096         section("HEADER");
00097     }
00098 
00109     void sectionTables() const {
00110         section("TABLES");
00111     }
00112 
00123     void sectionBlocks() const {
00124         section("BLOCKS");
00125     }
00126 
00137     void sectionEntities() const {
00138         section("ENTITIES");
00139     }
00140 
00151     void sectionClasses() const {
00152         section("CLASSES");
00153     }
00154 
00165     void sectionObjects() const {
00166         section("OBJECTS");
00167     }
00168 
00177     void sectionEnd() const {
00178         dxfString(0, "ENDSEC");
00179     }
00180 
00193     void table(const char* name, int num, int handle) const {
00194         dxfString(0, "TABLE");
00195         dxfString(2, name);
00196         if (version>=VER_2000) {
00197             dxfHex(5, handle);
00198             dxfString(100, "AcDbSymbolTable");
00199         }
00200         dxfInt(70, num);
00201     }
00202 
00216     void tableLayers(int num) const {
00217         table("LAYER", num, 2);
00218     }
00219 
00233     void tableLineTypes(int num) const {
00234         //lineTypeHandle = 5;
00235         table("LTYPE", num, 5);
00236     }
00237 
00251     void tableAppid(int num) const {
00252         table("APPID", num, 9);
00253     }
00254 
00263     void tableEnd() const {
00264         dxfString(0, "ENDTAB");
00265     }
00266 
00275     void dxfEOF() const {
00276         dxfString(0, "EOF");
00277     }
00278 
00287     void comment(const char* text) const {
00288         dxfString(999, text);
00289     }
00290 
00301     void entity(const char* entTypeName) const {
00302         dxfString(0, entTypeName);
00303         if (version>=VER_2000) {
00304             handle();
00305         }
00306     }
00307 
00322     void entityAttributes(const DL_Attributes& attrib) const {
00323         
00324                 // layer name:
00325         dxfString(8, attrib.getLayer());
00326                 
00327                 // R12 doesn't accept BYLAYER values. The value has to be missing
00328                 //   in that case.
00329         if (version>=VER_2000 || 
00330                         attrib.getColor()!=256) {
00331                 dxfInt(62, attrib.getColor());
00332                 }
00333         if (version>=VER_2000) {
00334             dxfInt(370, attrib.getWidth());
00335         }
00336         if (version>=VER_2000 || 
00337                         strcasecmp(attrib.getLineType().c_str(), "BYLAYER")) {
00338                 dxfString(6, attrib.getLineType());
00339                 }
00340     }
00341 
00345     void subClass(const char* sub) const {
00346         dxfString(100, sub);
00347     }
00348 
00357     void tableLayerEntry(unsigned long int h=0)  const {
00358         dxfString(0, "LAYER");
00359         if (version>=VER_2000) {
00360             if (h==0) {
00361                 handle();
00362             } else {
00363                 dxfHex(5, h);
00364             }
00365             dxfString(100, "AcDbSymbolTableRecord");
00366             dxfString(100, "AcDbLayerTableRecord");
00367         }
00368     }
00369 
00378     void tableLineTypeEntry(unsigned long int h=0)  const {
00379         dxfString(0, "LTYPE");
00380         if (version>=VER_2000) {
00381             if (h==0) {
00382                 handle();
00383             } else {
00384                 dxfHex(5, h);
00385             }
00386             //dxfHex(330, 0x5);
00387             dxfString(100, "AcDbSymbolTableRecord");
00388             dxfString(100, "AcDbLinetypeTableRecord");
00389         }
00390     }
00391 
00400     void tableAppidEntry(unsigned long int h=0)  const {
00401         dxfString(0, "APPID");
00402         if (version>=VER_2000) {
00403             if (h==0) {
00404                 handle();
00405             } else {
00406                 dxfHex(5, h);
00407             }
00408             //dxfHex(330, 0x9);
00409             dxfString(100, "AcDbSymbolTableRecord");
00410             dxfString(100, "AcDbRegAppTableRecord");
00411         }
00412     }
00413 
00422     void sectionBlockEntry(unsigned long int h=0)  const {
00423         dxfString(0, "BLOCK");
00424         if (version>=VER_2000) {
00425             if (h==0) {
00426                 handle();
00427             } else {
00428                 dxfHex(5, h);
00429             }
00430             //dxfHex(330, blockHandle);
00431             dxfString(100, "AcDbEntity");
00432             if (h==0x1C) {
00433                 dxfInt(67, 1);
00434             }
00435             dxfString(8, "0");                 // TODO: Layer for block
00436             dxfString(100, "AcDbBlockBegin");
00437         }
00438     }
00439 
00448     void sectionBlockEntryEnd(unsigned long int h=0)  const {
00449         dxfString(0, "ENDBLK");
00450         if (version>=VER_2000) {
00451             if (h==0) {
00452                 handle();
00453             } else {
00454                 dxfHex(5, h);
00455             }
00456             //dxfHex(330, blockHandle);
00457             dxfString(100, "AcDbEntity");
00458             if (h==0x1D) {
00459                 dxfInt(67, 1);
00460             }
00461             dxfString(8, "0");                 // TODO: Layer for block
00462             dxfString(100, "AcDbBlockEnd");
00463         }
00464     }
00465 
00466     void color(int col=256) const {
00467         dxfInt(62, col);
00468     }
00469     void lineType(const char *lt) const {
00470         dxfString(6, lt);
00471     }
00472     void lineTypeScale(double scale) const {
00473         dxfReal(48, scale);
00474     }
00475     void lineWeight(int lw) const {
00476         dxfInt(370, lw);
00477     }
00478 
00479     void coord(int gc, double x, double y, double z=0) const {
00480         dxfReal(gc, x);
00481         dxfReal(gc+10, y);
00482         dxfReal(gc+20, z);
00483     }
00484 
00485     void coordTriplet(int gc, const double* value) const {
00486         if (value) {
00487             dxfReal(gc, *value++);
00488             dxfReal(gc+10, *value++);
00489             dxfReal(gc+20, *value++);
00490         }
00491     }
00492 
00493     void resetHandle() const {
00494         m_handle = 1;
00495     }
00496 
00500     unsigned long handle(int gc=5) const {
00501         // handle has to be hex
00502         dxfHex(gc, m_handle);
00503         return m_handle++;
00504     }
00505 
00509     unsigned long getNextHandle() const {
00510         return m_handle;
00511     }
00512         
00516     unsigned long incHandle() const {
00517         return m_handle++;
00518     }
00519 
00524     void setModelSpaceHandle(unsigned long h) {
00525         modelSpaceHandle = h;
00526     }
00527 
00528     unsigned long getModelSpaceHandle() {
00529         return modelSpaceHandle;
00530     }
00531 
00536     void setPaperSpaceHandle(unsigned long h) {
00537         paperSpaceHandle = h;
00538     }
00539 
00540     unsigned long getPaperSpaceHandle() {
00541         return paperSpaceHandle;
00542     }
00543 
00548     void setPaperSpace0Handle(unsigned long h) {
00549         paperSpace0Handle = h;
00550     }
00551 
00552     unsigned long getPaperSpace0Handle() {
00553         return paperSpace0Handle;
00554     }
00555 
00563     virtual void dxfReal(int gc, double value) const = 0;
00564 
00572     virtual void dxfInt(int gc, int value) const = 0;
00573 
00581     virtual void dxfHex(int gc, int value) const = 0;
00582 
00590     virtual void dxfString(int gc, const char* value) const = 0;
00591 
00599     virtual void dxfString(int gc, const string& value) const = 0;
00600 
00601 protected:
00602     mutable unsigned long m_handle;
00603     mutable unsigned long modelSpaceHandle;
00604     mutable unsigned long paperSpaceHandle;
00605     mutable unsigned long paperSpace0Handle;
00606 
00610     DL_Codes::version version;
00611 private:
00612 };
00613 
00614 #endif

Generated on Sat Jan 6 13:48:19 2007 for dxflib by  doxygen 1.4.4