1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203
|
/******************************************************************************
** libDXFrw - Library to read/write DXF files (ascii & binary) **
** **
** Copyright (C) 2011-2015 José F. Soriano, rallazz@gmail.com **
** **
** This library is free software, licensed under the terms of the GNU **
** General Public License as published by the Free Software Foundation, **
** either version 2 of the License, or (at your option) any later version. **
** You should have received a copy of the GNU General Public License **
** along with this program. If not, see <http://www.gnu.org/licenses/>. **
******************************************************************************/
#ifndef DWGREADER_H
#define DWGREADER_H
#include <map>
#include <list>
#include "drw_textcodec.h"
#include "dwgutil.h"
#include "dwgbuffer.h"
#include "../libdwgr.h"
class objHandle{
public:
objHandle(){ handle = type = loc = 0; }
objHandle(duint32 t, duint32 h, duint32 l){
type = t;
handle = h;
loc = l;
}
duint32 type;
duint32 handle;
duint32 loc;
};
//until 2000 = 2000-
//since 2004 except 2007 = 2004+
// 2007 = 2007
// pages of section
/* 2000-: No pages, only sections
* 2004+: Id, page number (index)
* size, size of page in file stream
* address, address in file stream
* dataSize, data size for this page
* startOffset, start offset for this page
* cSize, compressed size of data
* uSize, uncompressed size of data
* 2007: page Id, pageCount & pages
* size, size in file
* dataSize
* startOffset, start position in decompressed data stream
* cSize, compressed size of data
* uSize, uncompressed size of data
* address, address in file stream
* */
class dwgPageInfo {
public:
dwgPageInfo(){}
dwgPageInfo(duint64 i, duint64 ad, duint32 sz){
Id=i; address=ad; size=sz;
}
~dwgPageInfo(){}
duint64 Id;
duint64 address; //in file stream, for rd18, rd21
duint64 size; //in file stream, for rd18, rd21
duint64 dataSize; //for rd18, rd21
duint32 startOffset; //for rd18, rd21
duint64 cSize; //compressed page size, for rd21
duint64 uSize; //uncompressed page size, for rd21
};
// sections of file
/* 2000-: No pages, only section Id, size & address in file
* 2004+: Id, Section Id
* size, total size of uncompressed data
* pageCount & pages, number of pages in section
* maxSize, max decompressed Size per page
* compressed, (1 = no, 2 = yes, normally 2)
* encrypted, (0 = no, 1 = yes, 2 = unknown)
* name, read & stored but not used
* 2007: same as 2004+ except encoding, saved in compressed field
* */
class dwgSectionInfo {
public:
dwgSectionInfo(){
compressed = 1;//1=no, 2=yes
encrypted = 0;//???
pageCount = 0;
Id=-1;
}
~dwgSectionInfo(){}
dint32 Id; //section Id, 2000- rd15 rd18
std::string name; //section name rd18
duint32 compressed;//is compressed? 1=no, 2=yes rd18, rd21(encoding)
duint32 encrypted;//encrypted (doc: 0=no, 1=yes, 2=unkn) on read: objects 0 and encrypted yes rd18
std::map<duint32, dwgPageInfo >pages;//index, size, offset
duint64 size;//size of section, 2000- rd15, rd18, rd21 (data size)
duint64 pageCount; //number of pages (dwgPageInfo) in section rd18, rd21
duint64 maxSize; //max decompressed size (needed??) rd18 rd21
duint64 address; //address (seek) , 2000-
};
//! Class to handle dwg obj control entries
/*!
* Class to handle dwg obj control entries
* @author Rallaz
*/
class DRW_ObjControl : public DRW_TableEntry {
public:
DRW_ObjControl() { reset();}
void reset(){
}
bool parseDwg(DRW::Version version, dwgBuffer *buf, duint32 bs=0);
std::list<duint32>hadlesList;
};
class dwgReader {
friend class dwgR;
public:
dwgReader(std::istream *stream, dwgR *p){
fileBuf = new dwgBuffer(stream);
parent = p;
decoder.setVersion(DRW::AC1021, false);//default 2007 in utf8(no convert)
decoder.setCodePage("UTF-16", false);
// blockCtrl=0; //RLZ: temporary
// blockCtrl=layerCtrl=styleCtrl=linetypeCtrl=viewCtrl=0;
// ucsCtrl=vportCtrl=appidCtrl=dimstyleCtrl=vpEntHeaderCtrl=0;
nextEntLink = prevEntLink = 0;
maintenanceVersion=0;
}
virtual ~dwgReader();
protected:
virtual bool readMetaData() = 0;
virtual bool readPreview(){return false;}
virtual bool readFileHeader() = 0;
virtual bool readDwgHeader(DRW_Header& hdr)=0;
virtual bool readDwgClasses() = 0;
virtual bool readDwgHandles() = 0;
virtual bool readDwgTables(DRW_Header& hdr)=0;
virtual bool readDwgBlocks(DRW_Interface& intfa) = 0;
virtual bool readDwgEntities(DRW_Interface& intfa) = 0;
virtual bool readDwgObjects(DRW_Interface& intfa) = 0;
virtual bool readDwgEntity(dwgBuffer *dbuf, objHandle& obj, DRW_Interface& intfa);
bool readDwgObject(dwgBuffer *dbuf, objHandle& obj, DRW_Interface& intfa);
void parseAttribs(DRW_Entity* e);
std::string findTableName(DRW::TTYPE table, dint32 handle);
void setCodePage(std::string *c){decoder.setCodePage(c, false);}
std::string getCodePage(){ return decoder.getCodePage();}
bool readDwgHeader(DRW_Header& hdr, dwgBuffer *buf, dwgBuffer *hBuf);
bool readDwgHandles(dwgBuffer *dbuf, duint32 offset, duint32 size);
bool readDwgTables(DRW_Header& hdr, dwgBuffer *dbuf);
bool checkSentinel(dwgBuffer *buf, enum secEnum::DWGSection, bool start);
bool readDwgBlocks(DRW_Interface& intfa, dwgBuffer *dbuf);
bool readDwgEntities(DRW_Interface& intfa, dwgBuffer *dbuf);
bool readDwgObjects(DRW_Interface& intfa, dwgBuffer *dbuf);
bool readPlineVertex(DRW_Polyline& pline, dwgBuffer *dbuf);
public:
std::map<duint32, objHandle>ObjectMap;
std::map<duint32, objHandle>objObjectMap; //stores the objects & entities not read in readDwgEntities
std::map<duint32, objHandle>remainingMap; //stores the objects & entities not read in all processes, for debug only
std::map<duint32, DRW_LType*> ltypemap;
std::map<duint32, DRW_Layer*> layermap;
std::map<duint32, DRW_Block*> blockmap;
std::map<duint32, DRW_Textstyle*> stylemap;
std::map<duint32, DRW_Dimstyle*> dimstylemap;
std::map<duint32, DRW_Vport*> vportmap;
std::map<duint32, DRW_Block_Record*> blockRecordmap;
std::map<duint32, DRW_AppId*> appIdmap;
// duint32 currBlock;
duint8 maintenanceVersion;
protected:
dwgBuffer *fileBuf;
dwgR *parent;
DRW::Version version;
//seeker (position) for the beginning sentinel of the image data (R13 to R15)
duint32 previewImagePos;
//sections map
std::map<enum secEnum::DWGSection, dwgSectionInfo >sections;
std::map<duint32, DRW_Class*> classesmap;
protected:
DRW_TextCodec decoder;
protected:
// duint32 blockCtrl;
duint32 nextEntLink;
duint32 prevEntLink;
};
#endif // DWGREADER_H
|