Commit ede0daf9 authored by jean-pierre charras's avatar jean-pierre charras

lib_dxf: Update to version 0.5.13 (previous: 0.5.11) due to a bug (memory...

lib_dxf: Update to version 0.5.13 (previous: 0.5.11) due to a bug (memory leak) fixed in 0.5.13, which has also more comments, and try to fix most of coverity warnings (not initialized class members).
These members are now initialized, which also fix some other more serious coverity issues.
parent d5e70c93
......@@ -13,7 +13,7 @@
#ifndef DRW_BASE_H
#define DRW_BASE_H
#define DRW_VERSION "0.5.11"
#define DRW_VERSION "0.5.13"
#include <string>
#include <cmath>
......@@ -42,7 +42,8 @@
namespace DRW {
// ! Version numbers for the DXF Format.
enum Version {
enum Version
{
UNKNOWNV, /*!< UNKNOWN VERSION. */
AC1006, /*!< R10. */
AC1009, /*!< R11 & R12. */
......@@ -54,7 +55,8 @@ enum Version {
AC1024 /*!< ACAD 2010. */
};
enum error {
enum error
{
BAD_NONE, /*!< No error. */
BAD_UNKNOWN, /*!< UNKNOWN. */
BAD_OPEN, /*!< error opening file. */
......@@ -76,7 +78,7 @@ enum error {
class DRW_Coord
{
public:
DRW_Coord() { x = 0; y = 0; z = 0; }
DRW_Coord(): x(0), y(0), z(0) {}
DRW_Coord( double ix, double iy, double iz )
{
x = ix; y = iy; z = iz;
......@@ -121,7 +123,7 @@ public:
DRW_Vertex2D()
{
// eType = DRW::LWPOLYLINE;
stawidth = endwidth = bulge = 0;
x = y = stawidth = endwidth = bulge = 0.0;
}
DRW_Vertex2D( double sx, double sy, double b )
......@@ -149,7 +151,8 @@ public:
class DRW_Variant
{
public:
enum TYPE {
enum TYPE
{
STRING,
INTEGER,
DOUBLE,
......@@ -162,29 +165,46 @@ public:
type = INVALID;
}
~DRW_Variant()
DRW_Variant( const DRW_Variant& d )
{
if( type == COORD )
delete content.v;
code = d.code;
type = d.type;
if( d.type == COORD ) vdata = d.vdata;
if( d.type == STRING ) sdata = d.sdata;
content = d.content;
}
enum TYPE type;
DRW_Variant( int c, UTF8STRING s ) { addString( s ); code = c; }
DRW_Variant( int c, int i ) { addInt( i ); code = c; }
DRW_Variant( int c, double d ) { addDouble( d ); code = c; }
DRW_Variant( int c, double x, double y, double z )
{
setType( COORD ); vdata.x = x; vdata.y = y;
vdata.z = z; content.v = &vdata; code = c;
}
void addString( UTF8STRING s ) { setType( STRING ); data = s; content.s = &data; }
~DRW_Variant()
{
}
void addString( UTF8STRING s ) { setType( STRING ); sdata = s; content.s = &sdata; }
void addInt( int i ) { setType( INTEGER ); content.i = i; }
void addDouble( double d ) { setType( DOUBLE ); content.d = d; }
void addCoord( DRW_Coord* v ) { setType( COORD ); content.v = v; }
void setType( enum TYPE t )
void addCoord()
{
if( type == COORD )
delete content.v;
type = t;
setType( COORD ); vdata.x = 0.0; vdata.y = 0.0; vdata.z = 0.0; content.v =
&vdata;
}
void setCoordX( double d ) { if( type == COORD ) content.v->x = d; }
void setCoordY( double d ) { if( type == COORD ) content.v->y = d; }
void setCoordZ( double d ) { if( type == COORD ) content.v->z = d; }
void addCoord( DRW_Coord v ) { setType( COORD ); vdata = v; content.v = &vdata; }
void setType( enum TYPE t ) { type = t; }
void setCoordX( double d ) { if( type == COORD ) vdata.x = d; }
void setCoordY( double d ) { if( type == COORD ) vdata.y = d; }
void setCoordZ( double d ) { if( type == COORD ) vdata.z = d; }
private:
typedef union
{
......@@ -193,15 +213,15 @@ private:
double d;
DRW_Coord* v;
} DRW_VarContent;
public:
DRW_VarContent content;
public:
int code;
// string version;
// string codepage;
enum TYPE type;
int code; /*!< dxf code of this value*/
private:
// DRW_VarContent content;
std::string data;
std::string sdata;
DRW_Coord vdata;
};
......@@ -215,7 +235,8 @@ private:
class DRW_LW_Conv
{
public:
enum lineWidth {
enum lineWidth
{
width00 = 0, /*!< 0.00mm (dxf 0)*/
width01 = 1, /*!< 0.05mm (dxf 5)*/
width02 = 2, /*!< 0.09mm (dxf 9)*/
......
......@@ -22,23 +22,33 @@
*/
void DRW_Entity::calculateAxis( DRW_Coord extPoint )
{
// Follow the arbitrary DXF definitions for extrusion axes.
if( fabs( extPoint.x ) < 0.015625 && fabs( extPoint.y ) < 0.015625 )
{
// If we get here, implement Ax = Wy x N where Wy is [0,1,0] per the DXF spec.
// The cross product works out to Wy.y*N.z-Wy.z*N.y, Wy.z*N.x-Wy.x*N.z, Wy.x*N.y-Wy.y*N.x
// Factoring in the fixed values for Wy gives N.z,0,-N.x
extAxisX.x = extPoint.z;
extAxisX.y = 0;
extAxisX.z = -extPoint.x;
}
else
{
// Otherwise, implement Ax = Wz x N where Wz is [0,0,1] per the DXF spec.
// The cross product works out to Wz.y*N.z-Wz.z*N.y, Wz.z*N.x-Wz.x*N.z, Wz.x*N.y-Wz.y*N.x
// Factoring in the fixed values for Wz gives -N.y,N.x,0.
extAxisX.x = -extPoint.y;
extAxisX.y = extPoint.x;
extAxisX.z = 0;
}
extAxisX.unitize();
// Ay = N x Ax
extAxisY.x = (extPoint.y * extAxisX.z) - (extAxisX.y * extPoint.z);
extAxisY.y = (extPoint.z * extAxisX.x) - (extAxisX.z * extPoint.x);
extAxisY.z = (extPoint.x * extAxisX.y) - (extAxisX.x * extPoint.y);
extAxisY.unitize();
}
......@@ -110,6 +120,58 @@ void DRW_Entity::parseCode( int code, dxfReader* reader )
space = reader->getInt32();
break;
case 1000:
case 1001:
case 1002:
case 1003:
case 1004:
case 1005:
extData.push_back( new DRW_Variant( code, reader->getString() ) );
break;
case 1010:
case 1011:
case 1012:
case 1013:
curr = new DRW_Variant();
curr->addCoord();
curr->setCoordX( reader->getDouble() );
curr->code = code;
extData.push_back( curr );
break;
case 1020:
case 1021:
case 1022:
case 1023:
if( curr )
curr->setCoordY( reader->getDouble() );
break;
case 1030:
case 1031:
case 1032:
case 1033:
if( curr )
curr->setCoordZ( reader->getDouble() );
curr = NULL;
break;
case 1040:
case 1041:
case 1042:
extData.push_back( new DRW_Variant( code, reader->getDouble() ) );
break;
case 1070:
case 1071:
extData.push_back( new DRW_Variant( code, reader->getInt32() ) );
break;
default:
break;
}
......@@ -183,6 +245,8 @@ void DRW_Circle::applyExtrusion()
{
if( haveExtrusion )
{
// NOTE: Commenting these out causes the the arcs being tested to be located
// on the other side of the y axis (all x dimensions are negated).
calculateAxis( extPoint );
extrudePoint( extPoint, &basePoint );
}
......@@ -204,6 +268,30 @@ void DRW_Circle::parseCode( int code, dxfReader* reader )
}
void DRW_Arc::applyExtrusion()
{
DRW_Circle::applyExtrusion();
if( haveExtrusion )
{
// If the extrusion vector has a z value less than 0, the angles for the arc
// have to be mirrored since DXF files use the right hand rule.
// Note that the following code only handles the special case where there is a 2D
// drawing with the z axis heading into the paper (or rather screen). An arbitrary
// extrusion axis (with x and y values greater than 1/64) may still have issues.
if( fabs( extPoint.x ) < 0.015625 && fabs( extPoint.y ) < 0.015625 && extPoint.z < 0.0 )
{
staangle = M_PI - staangle;
endangle = M_PI - endangle;
double temp = staangle;
staangle = endangle;
endangle = temp;
}
}
}
void DRW_Arc::parseCode( int code, dxfReader* reader )
{
switch( code )
......
This diff is collapsed.
......@@ -57,6 +57,9 @@ public:
/** Called for every text style. */
virtual void addTextStyle( const DRW_Textstyle& data ) = 0;
/** Called for every AppId entry. */
virtual void addAppId( const DRW_AppId& data ) = 0;
/**
* Called for every block. Note: all entities added after this
* command go into this block until endBlock() is called.
......@@ -214,6 +217,7 @@ public:
virtual void writeTextstyles() = 0;
virtual void writeVports() = 0;
virtual void writeDimstyles() = 0;
virtual void writeAppId() = 0;
protected:
// DL_Attributes attributes;
......
......@@ -41,6 +41,58 @@ void DRW_TableEntry::parseCode( int code, dxfReader* reader )
flags = reader->getInt32();
break;
case 1000:
case 1001:
case 1002:
case 1003:
case 1004:
case 1005:
extData.push_back( new DRW_Variant( code, reader->getString() ) );
break;
case 1010:
case 1011:
case 1012:
case 1013:
curr = new DRW_Variant();
curr->addCoord();
curr->setCoordX( reader->getDouble() );
curr->code = code;
extData.push_back( curr );
break;
case 1020:
case 1021:
case 1022:
case 1023:
if( curr )
curr->setCoordY( reader->getDouble() );
break;
case 1030:
case 1031:
case 1032:
case 1033:
if( curr )
curr->setCoordZ( reader->getDouble() );
curr = NULL;
break;
case 1040:
case 1041:
case 1042:
extData.push_back( new DRW_Variant( code, reader->getDouble() ) );
break;
case 1070:
case 1071:
extData.push_back( new DRW_Variant( code, reader->getInt32() ) );
break;
default:
break;
}
......@@ -747,7 +799,7 @@ void DRW_Header::parseCode( int code, dxfReader* reader )
break;
case 10:
curr->addCoord( new DRW_Coord() );
curr->addCoord();
curr->setCoordX( reader->getDouble() );
curr->code = code;
break;
......@@ -970,6 +1022,8 @@ void DRW_Header::write( dxfWriter* writer, DRW::Version ver )
writer->writeUtf8String( 7, varStr );
else
writer->writeString( 7, "STANDARD" );
......@@ -982,6 +1036,8 @@ void DRW_Header::write( dxfWriter* writer, DRW::Version ver )
writer->writeUtf8String( 8, varStr );
else
writer->writeString( 8, "0" );
......@@ -1082,6 +1138,8 @@ void DRW_Header::write( dxfWriter* writer, DRW::Version ver )
writer->writeUtf8String( 2, varStr );
else
writer->writeString( 2, "STANDARD" );
......@@ -1235,7 +1293,7 @@ void DRW_Header::write( dxfWriter* writer, DRW::Version ver )
#ifdef DRW_DBG
std::map<std::string, DRW_Variant*>::const_iterator it;
for( it = vars.begin(); it != vars.end(); it++ )
for( it = vars.begin(); it != vars.end(); ++it )
{
// QString key = QString::fromStdString((*it).first);
std::cerr << (*it).first << std::endl;
......@@ -1245,6 +1303,42 @@ void DRW_Header::write( dxfWriter* writer, DRW::Version ver )
}
void DRW_Header::addDouble( std::string key, double value, int code )
{
curr = new DRW_Variant();
curr->addDouble( value );
curr->code = code;
vars[key] = curr;
}
void DRW_Header::addInt( std::string key, int value, int code )
{
curr = new DRW_Variant();
curr->addInt( value );
curr->code = code;
vars[key] = curr;
}
void DRW_Header::addStr( std::string key, std::string value, int code )
{
curr = new DRW_Variant();
curr->addString( value );
curr->code = code;
vars[key] = curr;
}
void DRW_Header::addCoord( std::string key, DRW_Coord value, int code )
{
curr = new DRW_Variant();
curr->addCoord( value );
curr->code = code;
vars[key] = curr;
}
bool DRW_Header::getDouble( std::string key, double* varDouble )
{
bool result = false;
......
......@@ -24,14 +24,16 @@ class dxfWriter;
namespace DRW {
// ! Table entries type.
enum TTYPE {
enum TTYPE
{
UNKNOWNT,
LTYPE,
LAYER,
STYLE,
DIMSTYLE,
VPORT,
BLOCK_RECORD
BLOCK_RECORD,
APPID
};
}
......@@ -48,18 +50,42 @@ public:
{
tType = DRW::UNKNOWNT;
flags = 0;
curr = NULL;
handle = 0;
handleBlock = 0;
}
virtual ~DRW_TableEntry()
{
for( std::vector<DRW_Variant*>::iterator it = extData.begin(); it!=extData.end(); ++it )
delete *it;
extData.clear();
}
virtual ~DRW_TableEntry() {}
protected:
void parseCode( int code, dxfReader* reader );
void reset()
{
flags = 0;
for( std::vector<DRW_Variant*>::iterator it = extData.begin(); it!=extData.end(); ++it )
delete *it;
extData.clear();
}
public:
enum DRW::TTYPE tType; /*!< enum: entity type, code 0 */
int handle; /*!< entity identifier, code 5 */
int handleBlock; /*!< Soft-pointer ID/handle to owner BLOCK_RECORD object, code 330 */
UTF8STRING name; /*!< entry name, code 2 */
int flags; /*!< Flags relevant to entry, code 70 */
std::vector<DRW_Variant*> extData; /*!< FIFO list of extended data, codes 1000 to 1071*/
private:
DRW_Variant* curr;
};
......@@ -96,6 +122,7 @@ public:
dimfit = dimatfit = 3;
dimdsep = '.';
dimlwd = dimlwe = -2;
DRW_TableEntry::reset();
}
void parseCode( int code, dxfReader* reader );
......@@ -190,10 +217,7 @@ public:
size = 0;
length = 0.0;
pathIdx = 0;
/* color = 256; // default BYLAYER (256)
* plotF = true; // default TRUE (plot yes)
* lWeight = -1; // default BYLAYER (-1)*/
// align = 65; //always 65
DRW_TableEntry::reset();
}
void parseCode( int code, dxfReader* reader );
......@@ -206,6 +230,7 @@ public:
double length; /*!< total length of pattern, code 40 */
// int haveShape; /*!< complex linetype type, code 74 */
std::vector<double> path; /*!< trace, point or space length sequence, code 49 */
private:
int pathIdx;
};
......@@ -229,6 +254,7 @@ public:
plotF = true; // default TRUE (plot yes)
lWeight = DRW_LW_Conv::widthDefault; // default BYDEFAULT (dxf -3, dwg 31)
color24 = -1; // default -1 not set
DRW_TableEntry::reset();
}
void parseCode( int code, dxfReader* reader );
......@@ -261,6 +287,7 @@ public:
font = "txt";
genFlag = 0; // 2= X mirror, 4= Y mirror
fontFamily = 0;
DRW_TableEntry::reset();
}
void parseCode( int code, dxfReader* reader );
......@@ -303,6 +330,7 @@ public:
circleZoom = 100;
ucsIcon = 3;
gridBehavior = 7;
DRW_TableEntry::reset();
}
void parseCode( int code, dxfReader* reader );
......@@ -352,6 +380,9 @@ public:
DRW_ImageDef()
{
version = 0;
u = v = up = vp = 0.0;
loaded = 0;
resolution = 0;
}
void parseCode( int code, dxfReader* reader );
......@@ -373,7 +404,9 @@ public:
// ! Class to handle header entries
/*!
* Class to handle layer symbol table entries
* Class to handle header vars, to read iterate over "std::map vars"
* to write add a DRW_Variant* into "std::map vars" (do not delete it, are cleared in dtor)
* or use add* helper functions.
* @author Rallaz
*/
class DRW_Header
......@@ -381,18 +414,29 @@ class DRW_Header
public:
DRW_Header()
{
version = 0;
curr = 0;
}
~DRW_Header()
{
for( std::map<std::string, DRW_Variant*>::iterator it = vars.begin(); it!=vars.end(); ++it )
delete it->second;
vars.clear();
}
void addDouble( std::string key, double value, int code );
void addInt( std::string key, int value, int code );
void addStr( std::string key, std::string value, int code );
void addCoord( std::string key, DRW_Coord value, int code );
std::string getComments() const { return comments; }
void parseCode( int code, dxfReader* reader );
void write( dxfWriter* writer, DRW::Version ver );
void addComment( std::string c );
std::string getComments() const { return comments; }
private:
bool getDouble( std::string key, double* varDouble );
bool getInt( std::string key, int* varInt );
......@@ -401,6 +445,7 @@ private:
public:
std::map<std::string, DRW_Variant*> vars;
private:
std::string comments;
std::string name;
......@@ -408,6 +453,26 @@ private:
int version; // to use on read
};
// ! Class to handle AppId entries
/*!
* Class to handle AppId symbol table entries
* @author Rallaz
*/
class DRW_AppId : public DRW_TableEntry
{
public:
DRW_AppId() { reset(); }
void reset()
{
tType = DRW::APPID;
flags = 0;
name = "";
}
void parseCode( int code, dxfReader* reader ) { DRW_TableEntry::parseCode( code, reader ); }
};
namespace DRW {
// Extended color palette:
// The first entry is only for direct indexing starting with [1]
......
......@@ -127,8 +127,7 @@ std::string DRW_Converter::toUtf8( std::string* s )
if( c < 0x80 ) // ascii check for /U+????
{
if( c == '\\' && i + 6 < s->length() && s->at( i + 1 ) == 'U' && s->at( i + 2 ) ==
'+' )
if( c == '\\' && i + 6 < s->length() && s->at( i + 1 ) == 'U' && s->at( i + 2 ) == '+' )
{
result += s->substr( j, i - j );
result += encodeText( s->substr( i, 7 ) );
......@@ -204,7 +203,7 @@ std::string DRW_ConvTable::toUtf8( std::string* s )
std::string res;
std::string::iterator it;
for( it = s->begin(); it < s->end(); it++ )
for( it = s->begin(); it < s->end(); ++it )
{
unsigned char c = *it;
......@@ -395,7 +394,7 @@ std::string DRW_ConvDBCSTable::toUtf8( std::string* s )
std::string res;
std::string::iterator it;
for( it = s->begin(); it < s->end(); it++ )
for( it = s->begin(); it < s->end(); ++it )
{
bool notFound = true;
unsigned char c = *it;
......@@ -516,7 +515,7 @@ std::string DRW_Conv932Table::toUtf8( std::string* s )
std::string res;
std::string::iterator it;
for( it = s->begin(); it < s->end(); it++ )
for( it = s->begin(); it < s->end(); ++it )
{
bool notFound = true;
unsigned char c = *it;
......@@ -661,7 +660,7 @@ std::string DRW_TextCodec::correctCodePage( const std::string& s )
}
else if( cp=="ANSI_936" || cp=="GBK" || cp=="GB2312" || cp=="CHINESE" || cp=="CN-GB"
|| cp=="CSGB2312" || cp=="CSGB231280" || cp=="CSISO58BG231280"
|| cp=="GB_2312-80" || cp=="GB231280" || cp=="GB2312-80" || cp=="GBK"
|| cp=="GB_2312-80" || cp=="GB231280" || cp=="GB2312-80"
|| cp=="ISO-IR-58" || cp=="GB18030" )
{
return "ANSI_936";
......
......@@ -21,6 +21,7 @@ public:
void setCodePage( std::string c ) { setCodePage( &c ); }
std::string getCodePage() { return cp; }
private:
std::string correctCodePage( const std::string& s );
......
......@@ -21,6 +21,9 @@ public:
dxfReader( std::ifstream* stream )
{
filestr = stream;
doubleData = 0.0;
intData = 0;
int64 = 0;
#ifdef DRW_DBG
count = 0;
#endif
......@@ -53,12 +56,14 @@ public:
#ifdef DRW_DBG
int count; // DBG
#endif
protected:
std::ifstream* filestr;
std::string strData;
double doubleData;
signed int intData; // 32 bits integer
unsigned long long int int64; // 64 bits integer
private:
DRW_TextCodec decoder;
};
......@@ -66,7 +71,7 @@ private:
class dxfReaderBinary : public dxfReader
{
public:
dxfReaderBinary( std::ifstream* stream ) : dxfReader( stream ) { }
dxfReaderBinary( std::ifstream* stream ) : dxfReader( stream ) {}
virtual ~dxfReaderBinary() {}
virtual bool readCode( int* code );
virtual bool readString( std::string* text );
......@@ -81,7 +86,7 @@ public:
class dxfReaderAscii : public dxfReader
{
public:
dxfReaderAscii( std::ifstream* stream ) : dxfReader( stream ) { }
dxfReaderAscii( std::ifstream* stream ) : dxfReader( stream ) {}
virtual ~dxfReaderAscii() {}
virtual bool readCode( int* code );
virtual bool readString( std::string* text );
......
......@@ -34,8 +34,10 @@ public:
void setVersion( std::string* v ) { encoder.setVersion( v ); }
void setCodePage( std::string* c ) { encoder.setCodePage( c ); }
std::string getCodePage() { return encoder.getCodePage(); }
protected:
std::ofstream* filestr;
private:
DRW_TextCodec encoder;
};
......@@ -43,7 +45,7 @@ private:
class dxfWriterBinary : public dxfWriter
{
public:
dxfWriterBinary( std::ofstream* stream ) : dxfWriter( stream ) { }
dxfWriterBinary( std::ofstream* stream ) : dxfWriter( stream ) {}
virtual ~dxfWriterBinary() {}
virtual bool writeString( int code, std::string text );
virtual bool writeInt16( int code, int data );
......@@ -56,7 +58,7 @@ public:
class dxfWriterAscii : public dxfWriter
{
public:
dxfWriterAscii( std::ofstream* stream ) : dxfWriter( stream ) { }
dxfWriterAscii( std::ofstream* stream ) : dxfWriter( stream ) {}
virtual ~dxfWriterAscii() {}
virtual bool writeString( int code, std::string text );
virtual bool writeInt16( int code, int data );
......
......@@ -45,6 +45,14 @@ dxfRW::dxfRW( const char* name )
writer = NULL;
applyExt = false;
elParts = 128; // parts munber when convert ellipse to polyline
binary = false;
iface = NULL;
entCount = 0;
wlayer0 = false;
dimstyleStd = false;
writingBlock = false;
currHandle = 0;
}
......@@ -52,6 +60,14 @@ dxfRW::~dxfRW()
{
if( reader != NULL )
delete reader;
if( writer != NULL )
delete writer;
for( std::vector<DRW_ImageDef*>::iterator it = imageDef.begin(); it!=imageDef.end(); ++it )
delete *it;
imageDef.clear();
}
......@@ -322,6 +338,11 @@ bool dxfRW::writeLayer( DRW_Layer* ent )
else
writer->writeUtf8Caps( 6, ent->lineType );
if( !ent->extData.empty() )
{
writeExtData( ent->extData );
}
// writer->writeString(347, "10012");
return true;
}
......@@ -638,6 +659,33 @@ bool dxfRW::writeDimstyle( DRW_Dimstyle* ent )
}
bool dxfRW::writeAppId( DRW_AppId* ent )
{
writer->writeString( 0, "APPID" );
if( version > DRW::AC1009 )
{
writer->writeString( 5, toHexStr( ++entCount ) );
if( version > DRW::AC1014 )
{
writer->writeString( 330, "9" );
}
writer->writeString( 100, "AcDbSymbolTableRecord" );
writer->writeString( 100, "AcDbRegAppTableRecord" );
writer->writeUtf8String( 2, ent->name );
}
else
{
writer->writeUtf8Caps( 2, ent->name );
}
writer->writeInt16( 70, ent->flags );
return true;
}
bool dxfRW::writePoint( DRW_Point* ent )
{
writer->writeString( 0, "POINT" );
......@@ -2045,6 +2093,7 @@ bool dxfRW::writeTables()
writer->writeString( 2, "ACAD" );
writer->writeInt16( 70, 0 );
iface->writeAppId();
writer->writeString( 0, "ENDTAB" );
writer->writeString( 0, "TABLE" );
......@@ -2324,7 +2373,7 @@ bool dxfRW::writeObjects()
DRW_ImageDef* id = imageDef.at( i );
std::map<std::string, std::string>::iterator it;
for( it = id->reactors.begin(); it != id->reactors.end(); it++ )
for( it = id->reactors.begin(); it != id->reactors.end(); ++it )
{
writer->writeString( 0, "IMAGEDEF_REACTOR" );
writer->writeString( 5, (*it).first );
......@@ -2368,7 +2417,7 @@ bool dxfRW::writeObjects()
writer->writeString( 102, "{ACAD_REACTORS" );
std::map<std::string, std::string>::iterator it;
for( it = id->reactors.begin(); it != id->reactors.end(); it++ )
for( it = id->reactors.begin(); it != id->reactors.end(); ++it )
{
writer->writeString( 330, (*it).first );
}
......@@ -2395,6 +2444,74 @@ bool dxfRW::writeObjects()
}
bool dxfRW::writeExtData( const std::vector<DRW_Variant*>& ed )
{
for( std::vector<DRW_Variant*>::const_iterator it = ed.begin(); it!=ed.end(); ++it )
{
switch( (*it)->code )
{
case 1000:
case 1001:
case 1002:
case 1003:
case 1004:
case 1005:
{
int cc = (*it)->code;
if( (*it)->type == DRW_Variant::STRING )
writer->writeUtf8String( cc, *(*it)->content.s );
// writer->writeUtf8String((*it)->code, (*it)->content.s);
break;
}
case 1010:
case 1011:
case 1012:
case 1013:
if( (*it)->type == DRW_Variant::COORD )
{
writer->writeDouble( (*it)->code, (*it)->content.v->x );
writer->writeDouble( (*it)->code + 10, (*it)->content.v->y );
writer->writeDouble( (*it)->code + 20, (*it)->content.v->z );
}
break;
case 1040:
case 1041:
case 1042:
if( (*it)->type == DRW_Variant::DOUBLE )
writer->writeDouble( (*it)->code, (*it)->content.d );
break;
case 1070:
if( (*it)->type == DRW_Variant::INTEGER )
writer->writeInt16( (*it)->code, (*it)->content.i );
break;
case 1071:
if( (*it)->type == DRW_Variant::INTEGER )
writer->writeInt32( (*it)->code, (*it)->content.i );
break;
default:
break;
}
}
return true;
}
/********* Reader Process *********/
bool dxfRW::processDxf()
......@@ -2562,7 +2679,7 @@ bool dxfRW::processTables()
}
else if( sectionstr == "APPID" )
{
// processAppId();
processAppId();
}
else if( sectionstr == "DIMSTYLE" )
{
......@@ -2778,6 +2895,44 @@ bool dxfRW::processVports()
}
bool dxfRW::processAppId()
{
DBG( "dxfRW::processAppId" );
int code;
std::string sectionstr;
bool reading = false;
DRW_AppId vp;
while( reader->readRec( &code, !binary ) )
{
DBG( code ); DBG( "\n" );
if( code == 0 )
{
if( reading )
iface->addAppId( vp );
sectionstr = reader->getString();
DBG( sectionstr ); DBG( "\n" );
if( sectionstr == "APPID" )
{
reading = true;
vp.reset();
}
else if( sectionstr == "ENDTAB" )
{
return true; // found ENDTAB terminate
}
}
else if( reading )
vp.parseCode( code, reader );
}
return true;
}
/********* Block Section *********/
bool dxfRW::processBlocks()
......
......@@ -45,6 +45,7 @@ public:
bool writeDimstyle( DRW_Dimstyle* ent );
bool writeTextstyle( DRW_Textstyle* ent );
bool writeVport( DRW_Vport* ent );
bool writeAppId( DRW_AppId* ent );
bool writePoint( DRW_Point* ent );
bool writeLine( DRW_Line* ent );
bool writeRay( DRW_Ray* ent );
......@@ -70,6 +71,7 @@ public:
bool writeDimension( DRW_Dimension* ent );
void setEllipseParts( int parts ) { elParts = parts; } /*!< set parts munber when convert ellipse to polyline */
private:
/// used by read() to parse the content of the file
bool processDxf();
......@@ -85,6 +87,7 @@ private:
bool processDimStyle();
bool processTextStyle();
bool processVports();
bool processAppId();
bool processPoint();
bool processLine();
......@@ -115,6 +118,7 @@ private:
bool writeTables();
bool writeBlocks();
bool writeObjects();
bool writeExtData( const std::vector<DRW_Variant*>& ed );
std::string toHexStr( int n );
private:
......
......@@ -165,6 +165,9 @@ private:
void writeLine();
void writeMtext();
virtual void addAppId( const DRW_AppId& data ) {}
virtual void writeAppId() {}
};
#endif // FILTERDXFRW_H
......@@ -91,6 +91,8 @@ private:
virtual void writeTextstyles(){}
virtual void writeVports(){}
virtual void writeDimstyles(){}
virtual void addAppId( const DRW_AppId& data ) {}
virtual void writeAppId() {}
};
#endif // DXF2IDF_H
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment