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 @@ ...@@ -13,7 +13,7 @@
#ifndef DRW_BASE_H #ifndef DRW_BASE_H
#define DRW_BASE_H #define DRW_BASE_H
#define DRW_VERSION "0.5.11" #define DRW_VERSION "0.5.13"
#include <string> #include <string>
#include <cmath> #include <cmath>
...@@ -42,7 +42,8 @@ ...@@ -42,7 +42,8 @@
namespace DRW { namespace DRW {
// ! Version numbers for the DXF Format. // ! Version numbers for the DXF Format.
enum Version { enum Version
{
UNKNOWNV, /*!< UNKNOWN VERSION. */ UNKNOWNV, /*!< UNKNOWN VERSION. */
AC1006, /*!< R10. */ AC1006, /*!< R10. */
AC1009, /*!< R11 & R12. */ AC1009, /*!< R11 & R12. */
...@@ -54,7 +55,8 @@ enum Version { ...@@ -54,7 +55,8 @@ enum Version {
AC1024 /*!< ACAD 2010. */ AC1024 /*!< ACAD 2010. */
}; };
enum error { enum error
{
BAD_NONE, /*!< No error. */ BAD_NONE, /*!< No error. */
BAD_UNKNOWN, /*!< UNKNOWN. */ BAD_UNKNOWN, /*!< UNKNOWN. */
BAD_OPEN, /*!< error opening file. */ BAD_OPEN, /*!< error opening file. */
...@@ -76,7 +78,7 @@ enum error { ...@@ -76,7 +78,7 @@ enum error {
class DRW_Coord class DRW_Coord
{ {
public: 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 ) DRW_Coord( double ix, double iy, double iz )
{ {
x = ix; y = iy; z = iz; x = ix; y = iy; z = iz;
...@@ -121,7 +123,7 @@ public: ...@@ -121,7 +123,7 @@ public:
DRW_Vertex2D() DRW_Vertex2D()
{ {
// eType = DRW::LWPOLYLINE; // eType = DRW::LWPOLYLINE;
stawidth = endwidth = bulge = 0; x = y = stawidth = endwidth = bulge = 0.0;
} }
DRW_Vertex2D( double sx, double sy, double b ) DRW_Vertex2D( double sx, double sy, double b )
...@@ -149,7 +151,8 @@ public: ...@@ -149,7 +151,8 @@ public:
class DRW_Variant class DRW_Variant
{ {
public: public:
enum TYPE { enum TYPE
{
STRING, STRING,
INTEGER, INTEGER,
DOUBLE, DOUBLE,
...@@ -162,29 +165,46 @@ public: ...@@ -162,29 +165,46 @@ public:
type = INVALID; type = INVALID;
} }
~DRW_Variant() DRW_Variant( const DRW_Variant& d )
{ {
if( type == COORD ) code = d.code;
delete content.v; 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 addInt( int i ) { setType( INTEGER ); content.i = i; }
void addDouble( double d ) { setType( DOUBLE ); content.d = d; } void addDouble( double d ) { setType( DOUBLE ); content.d = d; }
void addCoord( DRW_Coord* v ) { setType( COORD ); content.v = v; } void addCoord()
void setType( enum TYPE t )
{ {
if( type == COORD ) setType( COORD ); vdata.x = 0.0; vdata.y = 0.0; vdata.z = 0.0; content.v =
delete content.v; &vdata;
type = t;
} }
void setCoordX( double d ) { if( type == COORD ) content.v->x = d; } void addCoord( DRW_Coord v ) { setType( COORD ); vdata = v; content.v = &vdata; }
void setCoordY( double d ) { if( type == COORD ) content.v->y = d; } void setType( enum TYPE t ) { type = t; }
void setCoordZ( double d ) { if( type == COORD ) content.v->z = d; } 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: private:
typedef union typedef union
{ {
...@@ -193,15 +213,15 @@ private: ...@@ -193,15 +213,15 @@ private:
double d; double d;
DRW_Coord* v; DRW_Coord* v;
} DRW_VarContent; } DRW_VarContent;
public: public:
DRW_VarContent content; DRW_VarContent content;
public: enum TYPE type;
int code; int code; /*!< dxf code of this value*/
// string version;
// string codepage;
private: private:
// DRW_VarContent content; std::string sdata;
std::string data; DRW_Coord vdata;
}; };
...@@ -215,7 +235,8 @@ private: ...@@ -215,7 +235,8 @@ private:
class DRW_LW_Conv class DRW_LW_Conv
{ {
public: public:
enum lineWidth { enum lineWidth
{
width00 = 0, /*!< 0.00mm (dxf 0)*/ width00 = 0, /*!< 0.00mm (dxf 0)*/
width01 = 1, /*!< 0.05mm (dxf 5)*/ width01 = 1, /*!< 0.05mm (dxf 5)*/
width02 = 2, /*!< 0.09mm (dxf 9)*/ width02 = 2, /*!< 0.09mm (dxf 9)*/
......
...@@ -22,23 +22,33 @@ ...@@ -22,23 +22,33 @@
*/ */
void DRW_Entity::calculateAxis( DRW_Coord extPoint ) 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( 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.x = extPoint.z;
extAxisX.y = 0; extAxisX.y = 0;
extAxisX.z = -extPoint.x; extAxisX.z = -extPoint.x;
} }
else 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.x = -extPoint.y;
extAxisX.y = extPoint.x; extAxisX.y = extPoint.x;
extAxisX.z = 0; extAxisX.z = 0;
} }
extAxisX.unitize(); extAxisX.unitize();
// Ay = N x Ax
extAxisY.x = (extPoint.y * extAxisX.z) - (extAxisX.y * extPoint.z); extAxisY.x = (extPoint.y * extAxisX.z) - (extAxisX.y * extPoint.z);
extAxisY.y = (extPoint.z * extAxisX.x) - (extAxisX.z * extPoint.x); extAxisY.y = (extPoint.z * extAxisX.x) - (extAxisX.z * extPoint.x);
extAxisY.z = (extPoint.x * extAxisX.y) - (extAxisX.x * extPoint.y); extAxisY.z = (extPoint.x * extAxisX.y) - (extAxisX.x * extPoint.y);
extAxisY.unitize(); extAxisY.unitize();
} }
...@@ -110,6 +120,58 @@ void DRW_Entity::parseCode( int code, dxfReader* reader ) ...@@ -110,6 +120,58 @@ void DRW_Entity::parseCode( int code, dxfReader* reader )
space = reader->getInt32(); space = reader->getInt32();
break; 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: default:
break; break;
} }
...@@ -183,6 +245,8 @@ void DRW_Circle::applyExtrusion() ...@@ -183,6 +245,8 @@ void DRW_Circle::applyExtrusion()
{ {
if( haveExtrusion ) 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 ); calculateAxis( extPoint );
extrudePoint( extPoint, &basePoint ); extrudePoint( extPoint, &basePoint );
} }
...@@ -204,6 +268,30 @@ void DRW_Circle::parseCode( int code, dxfReader* reader ) ...@@ -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 ) void DRW_Arc::parseCode( int code, dxfReader* reader )
{ {
switch( code ) switch( code )
......
This diff is collapsed.
...@@ -57,6 +57,9 @@ public: ...@@ -57,6 +57,9 @@ public:
/** Called for every text style. */ /** Called for every text style. */
virtual void addTextStyle( const DRW_Textstyle& data ) = 0; 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 * Called for every block. Note: all entities added after this
* command go into this block until endBlock() is called. * command go into this block until endBlock() is called.
...@@ -214,6 +217,7 @@ public: ...@@ -214,6 +217,7 @@ public:
virtual void writeTextstyles() = 0; virtual void writeTextstyles() = 0;
virtual void writeVports() = 0; virtual void writeVports() = 0;
virtual void writeDimstyles() = 0; virtual void writeDimstyles() = 0;
virtual void writeAppId() = 0;
protected: protected:
// DL_Attributes attributes; // DL_Attributes attributes;
......
...@@ -41,6 +41,58 @@ void DRW_TableEntry::parseCode( int code, dxfReader* reader ) ...@@ -41,6 +41,58 @@ void DRW_TableEntry::parseCode( int code, dxfReader* reader )
flags = reader->getInt32(); flags = reader->getInt32();
break; 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: default:
break; break;
} }
...@@ -747,7 +799,7 @@ void DRW_Header::parseCode( int code, dxfReader* reader ) ...@@ -747,7 +799,7 @@ void DRW_Header::parseCode( int code, dxfReader* reader )
break; break;
case 10: case 10:
curr->addCoord( new DRW_Coord() ); curr->addCoord();
curr->setCoordX( reader->getDouble() ); curr->setCoordX( reader->getDouble() );
curr->code = code; curr->code = code;
break; break;
...@@ -970,6 +1022,8 @@ void DRW_Header::write( dxfWriter* writer, DRW::Version ver ) ...@@ -970,6 +1022,8 @@ void DRW_Header::write( dxfWriter* writer, DRW::Version ver )
writer->writeUtf8String( 7, varStr ); writer->writeUtf8String( 7, varStr );
else else
writer->writeString( 7, "STANDARD" ); writer->writeString( 7, "STANDARD" );
...@@ -982,6 +1036,8 @@ void DRW_Header::write( dxfWriter* writer, DRW::Version ver ) ...@@ -982,6 +1036,8 @@ void DRW_Header::write( dxfWriter* writer, DRW::Version ver )
writer->writeUtf8String( 8, varStr ); writer->writeUtf8String( 8, varStr );
else else
writer->writeString( 8, "0" ); writer->writeString( 8, "0" );
...@@ -1082,6 +1138,8 @@ void DRW_Header::write( dxfWriter* writer, DRW::Version ver ) ...@@ -1082,6 +1138,8 @@ void DRW_Header::write( dxfWriter* writer, DRW::Version ver )
writer->writeUtf8String( 2, varStr ); writer->writeUtf8String( 2, varStr );
else else
writer->writeString( 2, "STANDARD" ); writer->writeString( 2, "STANDARD" );
...@@ -1235,7 +1293,7 @@ void DRW_Header::write( dxfWriter* writer, DRW::Version ver ) ...@@ -1235,7 +1293,7 @@ void DRW_Header::write( dxfWriter* writer, DRW::Version ver )
#ifdef DRW_DBG #ifdef DRW_DBG
std::map<std::string, DRW_Variant*>::const_iterator it; 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); // QString key = QString::fromStdString((*it).first);
std::cerr << (*it).first << std::endl; std::cerr << (*it).first << std::endl;
...@@ -1245,6 +1303,42 @@ void DRW_Header::write( dxfWriter* writer, DRW::Version ver ) ...@@ -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 DRW_Header::getDouble( std::string key, double* varDouble )
{ {
bool result = false; bool result = false;
......
...@@ -24,14 +24,16 @@ class dxfWriter; ...@@ -24,14 +24,16 @@ class dxfWriter;
namespace DRW { namespace DRW {
// ! Table entries type. // ! Table entries type.
enum TTYPE { enum TTYPE
{
UNKNOWNT, UNKNOWNT,
LTYPE, LTYPE,
LAYER, LAYER,
STYLE, STYLE,
DIMSTYLE, DIMSTYLE,
VPORT, VPORT,
BLOCK_RECORD BLOCK_RECORD,
APPID
}; };
} }
...@@ -48,18 +50,42 @@ public: ...@@ -48,18 +50,42 @@ public:
{ {
tType = DRW::UNKNOWNT; tType = DRW::UNKNOWNT;
flags = 0; 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: protected:
void parseCode( int code, dxfReader* reader ); 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: public:
enum DRW::TTYPE tType; /*!< enum: entity type, code 0 */ enum DRW::TTYPE tType; /*!< enum: entity type, code 0 */
int handle; /*!< entity identifier, code 5 */ int handle; /*!< entity identifier, code 5 */
int handleBlock; /*!< Soft-pointer ID/handle to owner BLOCK_RECORD object, code 330 */ int handleBlock; /*!< Soft-pointer ID/handle to owner BLOCK_RECORD object, code 330 */
UTF8STRING name; /*!< entry name, code 2 */ UTF8STRING name; /*!< entry name, code 2 */
int flags; /*!< Flags relevant to entry, code 70 */ 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: ...@@ -96,6 +122,7 @@ public:
dimfit = dimatfit = 3; dimfit = dimatfit = 3;
dimdsep = '.'; dimdsep = '.';
dimlwd = dimlwe = -2; dimlwd = dimlwe = -2;
DRW_TableEntry::reset();
} }
void parseCode( int code, dxfReader* reader ); void parseCode( int code, dxfReader* reader );
...@@ -190,10 +217,7 @@ public: ...@@ -190,10 +217,7 @@ public:
size = 0; size = 0;
length = 0.0; length = 0.0;
pathIdx = 0; pathIdx = 0;
/* color = 256; // default BYLAYER (256) DRW_TableEntry::reset();
* plotF = true; // default TRUE (plot yes)
* lWeight = -1; // default BYLAYER (-1)*/
// align = 65; //always 65
} }
void parseCode( int code, dxfReader* reader ); void parseCode( int code, dxfReader* reader );
...@@ -206,6 +230,7 @@ public: ...@@ -206,6 +230,7 @@ public:
double length; /*!< total length of pattern, code 40 */ double length; /*!< total length of pattern, code 40 */
// int haveShape; /*!< complex linetype type, code 74 */ // int haveShape; /*!< complex linetype type, code 74 */
std::vector<double> path; /*!< trace, point or space length sequence, code 49 */ std::vector<double> path; /*!< trace, point or space length sequence, code 49 */
private: private:
int pathIdx; int pathIdx;
}; };
...@@ -229,6 +254,7 @@ public: ...@@ -229,6 +254,7 @@ public:
plotF = true; // default TRUE (plot yes) plotF = true; // default TRUE (plot yes)
lWeight = DRW_LW_Conv::widthDefault; // default BYDEFAULT (dxf -3, dwg 31) lWeight = DRW_LW_Conv::widthDefault; // default BYDEFAULT (dxf -3, dwg 31)
color24 = -1; // default -1 not set color24 = -1; // default -1 not set
DRW_TableEntry::reset();
} }
void parseCode( int code, dxfReader* reader ); void parseCode( int code, dxfReader* reader );
...@@ -261,6 +287,7 @@ public: ...@@ -261,6 +287,7 @@ public:
font = "txt"; font = "txt";
genFlag = 0; // 2= X mirror, 4= Y mirror genFlag = 0; // 2= X mirror, 4= Y mirror
fontFamily = 0; fontFamily = 0;
DRW_TableEntry::reset();
} }
void parseCode( int code, dxfReader* reader ); void parseCode( int code, dxfReader* reader );
...@@ -303,6 +330,7 @@ public: ...@@ -303,6 +330,7 @@ public:
circleZoom = 100; circleZoom = 100;
ucsIcon = 3; ucsIcon = 3;
gridBehavior = 7; gridBehavior = 7;
DRW_TableEntry::reset();
} }
void parseCode( int code, dxfReader* reader ); void parseCode( int code, dxfReader* reader );
...@@ -352,6 +380,9 @@ public: ...@@ -352,6 +380,9 @@ public:
DRW_ImageDef() DRW_ImageDef()
{ {
version = 0; version = 0;
u = v = up = vp = 0.0;
loaded = 0;
resolution = 0;
} }
void parseCode( int code, dxfReader* reader ); void parseCode( int code, dxfReader* reader );
...@@ -373,7 +404,9 @@ public: ...@@ -373,7 +404,9 @@ public:
// ! Class to handle header entries // ! 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 * @author Rallaz
*/ */
class DRW_Header class DRW_Header
...@@ -381,18 +414,29 @@ class DRW_Header ...@@ -381,18 +414,29 @@ class DRW_Header
public: public:
DRW_Header() DRW_Header()
{ {
version = 0;
curr = 0;
} }
~DRW_Header() ~DRW_Header()
{ {
for( std::map<std::string, DRW_Variant*>::iterator it = vars.begin(); it!=vars.end(); ++it )
delete it->second;
vars.clear(); 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 parseCode( int code, dxfReader* reader );
void write( dxfWriter* writer, DRW::Version ver ); void write( dxfWriter* writer, DRW::Version ver );
void addComment( std::string c ); void addComment( std::string c );
std::string getComments() const { return comments; }
private: private:
bool getDouble( std::string key, double* varDouble ); bool getDouble( std::string key, double* varDouble );
bool getInt( std::string key, int* varInt ); bool getInt( std::string key, int* varInt );
...@@ -401,6 +445,7 @@ private: ...@@ -401,6 +445,7 @@ private:
public: public:
std::map<std::string, DRW_Variant*> vars; std::map<std::string, DRW_Variant*> vars;
private: private:
std::string comments; std::string comments;
std::string name; std::string name;
...@@ -408,6 +453,26 @@ private: ...@@ -408,6 +453,26 @@ private:
int version; // to use on read 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 { namespace DRW {
// Extended color palette: // Extended color palette:
// The first entry is only for direct indexing starting with [1] // The first entry is only for direct indexing starting with [1]
......
...@@ -127,8 +127,7 @@ std::string DRW_Converter::toUtf8( std::string* s ) ...@@ -127,8 +127,7 @@ std::string DRW_Converter::toUtf8( std::string* s )
if( c < 0x80 ) // ascii check for /U+???? 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 += s->substr( j, i - j );
result += encodeText( s->substr( i, 7 ) ); result += encodeText( s->substr( i, 7 ) );
...@@ -204,7 +203,7 @@ std::string DRW_ConvTable::toUtf8( std::string* s ) ...@@ -204,7 +203,7 @@ std::string DRW_ConvTable::toUtf8( std::string* s )
std::string res; std::string res;
std::string::iterator it; std::string::iterator it;
for( it = s->begin(); it < s->end(); it++ ) for( it = s->begin(); it < s->end(); ++it )
{ {
unsigned char c = *it; unsigned char c = *it;
...@@ -395,7 +394,7 @@ std::string DRW_ConvDBCSTable::toUtf8( std::string* s ) ...@@ -395,7 +394,7 @@ std::string DRW_ConvDBCSTable::toUtf8( std::string* s )
std::string res; std::string res;
std::string::iterator it; std::string::iterator it;
for( it = s->begin(); it < s->end(); it++ ) for( it = s->begin(); it < s->end(); ++it )
{ {
bool notFound = true; bool notFound = true;
unsigned char c = *it; unsigned char c = *it;
...@@ -516,7 +515,7 @@ std::string DRW_Conv932Table::toUtf8( std::string* s ) ...@@ -516,7 +515,7 @@ std::string DRW_Conv932Table::toUtf8( std::string* s )
std::string res; std::string res;
std::string::iterator it; std::string::iterator it;
for( it = s->begin(); it < s->end(); it++ ) for( it = s->begin(); it < s->end(); ++it )
{ {
bool notFound = true; bool notFound = true;
unsigned char c = *it; unsigned char c = *it;
...@@ -661,7 +660,7 @@ std::string DRW_TextCodec::correctCodePage( const std::string& s ) ...@@ -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" else if( cp=="ANSI_936" || cp=="GBK" || cp=="GB2312" || cp=="CHINESE" || cp=="CN-GB"
|| cp=="CSGB2312" || cp=="CSGB231280" || cp=="CSISO58BG231280" || 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" ) || cp=="ISO-IR-58" || cp=="GB18030" )
{ {
return "ANSI_936"; return "ANSI_936";
......
...@@ -21,6 +21,7 @@ public: ...@@ -21,6 +21,7 @@ public:
void setCodePage( std::string c ) { setCodePage( &c ); } void setCodePage( std::string c ) { setCodePage( &c ); }
std::string getCodePage() { return cp; } std::string getCodePage() { return cp; }
private: private:
std::string correctCodePage( const std::string& s ); std::string correctCodePage( const std::string& s );
......
...@@ -21,6 +21,9 @@ public: ...@@ -21,6 +21,9 @@ public:
dxfReader( std::ifstream* stream ) dxfReader( std::ifstream* stream )
{ {
filestr = stream; filestr = stream;
doubleData = 0.0;
intData = 0;
int64 = 0;
#ifdef DRW_DBG #ifdef DRW_DBG
count = 0; count = 0;
#endif #endif
...@@ -53,12 +56,14 @@ public: ...@@ -53,12 +56,14 @@ public:
#ifdef DRW_DBG #ifdef DRW_DBG
int count; // DBG int count; // DBG
#endif #endif
protected: protected:
std::ifstream* filestr; std::ifstream* filestr;
std::string strData; std::string strData;
double doubleData; double doubleData;
signed int intData; // 32 bits integer signed int intData; // 32 bits integer
unsigned long long int int64; // 64 bits integer unsigned long long int int64; // 64 bits integer
private: private:
DRW_TextCodec decoder; DRW_TextCodec decoder;
}; };
...@@ -66,7 +71,7 @@ private: ...@@ -66,7 +71,7 @@ private:
class dxfReaderBinary : public dxfReader class dxfReaderBinary : public dxfReader
{ {
public: public:
dxfReaderBinary( std::ifstream* stream ) : dxfReader( stream ) { } dxfReaderBinary( std::ifstream* stream ) : dxfReader( stream ) {}
virtual ~dxfReaderBinary() {} virtual ~dxfReaderBinary() {}
virtual bool readCode( int* code ); virtual bool readCode( int* code );
virtual bool readString( std::string* text ); virtual bool readString( std::string* text );
...@@ -81,7 +86,7 @@ public: ...@@ -81,7 +86,7 @@ public:
class dxfReaderAscii : public dxfReader class dxfReaderAscii : public dxfReader
{ {
public: public:
dxfReaderAscii( std::ifstream* stream ) : dxfReader( stream ) { } dxfReaderAscii( std::ifstream* stream ) : dxfReader( stream ) {}
virtual ~dxfReaderAscii() {} virtual ~dxfReaderAscii() {}
virtual bool readCode( int* code ); virtual bool readCode( int* code );
virtual bool readString( std::string* text ); virtual bool readString( std::string* text );
......
...@@ -34,8 +34,10 @@ public: ...@@ -34,8 +34,10 @@ public:
void setVersion( std::string* v ) { encoder.setVersion( v ); } void setVersion( std::string* v ) { encoder.setVersion( v ); }
void setCodePage( std::string* c ) { encoder.setCodePage( c ); } void setCodePage( std::string* c ) { encoder.setCodePage( c ); }
std::string getCodePage() { return encoder.getCodePage(); } std::string getCodePage() { return encoder.getCodePage(); }
protected: protected:
std::ofstream* filestr; std::ofstream* filestr;
private: private:
DRW_TextCodec encoder; DRW_TextCodec encoder;
}; };
...@@ -43,7 +45,7 @@ private: ...@@ -43,7 +45,7 @@ private:
class dxfWriterBinary : public dxfWriter class dxfWriterBinary : public dxfWriter
{ {
public: public:
dxfWriterBinary( std::ofstream* stream ) : dxfWriter( stream ) { } dxfWriterBinary( std::ofstream* stream ) : dxfWriter( stream ) {}
virtual ~dxfWriterBinary() {} virtual ~dxfWriterBinary() {}
virtual bool writeString( int code, std::string text ); virtual bool writeString( int code, std::string text );
virtual bool writeInt16( int code, int data ); virtual bool writeInt16( int code, int data );
...@@ -56,7 +58,7 @@ public: ...@@ -56,7 +58,7 @@ public:
class dxfWriterAscii : public dxfWriter class dxfWriterAscii : public dxfWriter
{ {
public: public:
dxfWriterAscii( std::ofstream* stream ) : dxfWriter( stream ) { } dxfWriterAscii( std::ofstream* stream ) : dxfWriter( stream ) {}
virtual ~dxfWriterAscii() {} virtual ~dxfWriterAscii() {}
virtual bool writeString( int code, std::string text ); virtual bool writeString( int code, std::string text );
virtual bool writeInt16( int code, int data ); virtual bool writeInt16( int code, int data );
......
...@@ -45,6 +45,14 @@ dxfRW::dxfRW( const char* name ) ...@@ -45,6 +45,14 @@ dxfRW::dxfRW( const char* name )
writer = NULL; writer = NULL;
applyExt = false; applyExt = false;
elParts = 128; // parts munber when convert ellipse to polyline 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() ...@@ -52,6 +60,14 @@ dxfRW::~dxfRW()
{ {
if( reader != NULL ) if( reader != NULL )
delete reader; 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 ) ...@@ -322,6 +338,11 @@ bool dxfRW::writeLayer( DRW_Layer* ent )
else else
writer->writeUtf8Caps( 6, ent->lineType ); writer->writeUtf8Caps( 6, ent->lineType );
if( !ent->extData.empty() )
{
writeExtData( ent->extData );
}
// writer->writeString(347, "10012"); // writer->writeString(347, "10012");
return true; return true;
} }
...@@ -638,6 +659,33 @@ bool dxfRW::writeDimstyle( DRW_Dimstyle* ent ) ...@@ -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 ) bool dxfRW::writePoint( DRW_Point* ent )
{ {
writer->writeString( 0, "POINT" ); writer->writeString( 0, "POINT" );
...@@ -2045,6 +2093,7 @@ bool dxfRW::writeTables() ...@@ -2045,6 +2093,7 @@ bool dxfRW::writeTables()
writer->writeString( 2, "ACAD" ); writer->writeString( 2, "ACAD" );
writer->writeInt16( 70, 0 ); writer->writeInt16( 70, 0 );
iface->writeAppId();
writer->writeString( 0, "ENDTAB" ); writer->writeString( 0, "ENDTAB" );
writer->writeString( 0, "TABLE" ); writer->writeString( 0, "TABLE" );
...@@ -2324,7 +2373,7 @@ bool dxfRW::writeObjects() ...@@ -2324,7 +2373,7 @@ bool dxfRW::writeObjects()
DRW_ImageDef* id = imageDef.at( i ); DRW_ImageDef* id = imageDef.at( i );
std::map<std::string, std::string>::iterator it; 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( 0, "IMAGEDEF_REACTOR" );
writer->writeString( 5, (*it).first ); writer->writeString( 5, (*it).first );
...@@ -2368,7 +2417,7 @@ bool dxfRW::writeObjects() ...@@ -2368,7 +2417,7 @@ bool dxfRW::writeObjects()
writer->writeString( 102, "{ACAD_REACTORS" ); writer->writeString( 102, "{ACAD_REACTORS" );
std::map<std::string, std::string>::iterator it; 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 ); writer->writeString( 330, (*it).first );
} }
...@@ -2395,6 +2444,74 @@ bool dxfRW::writeObjects() ...@@ -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 *********/ /********* Reader Process *********/
bool dxfRW::processDxf() bool dxfRW::processDxf()
...@@ -2562,7 +2679,7 @@ bool dxfRW::processTables() ...@@ -2562,7 +2679,7 @@ bool dxfRW::processTables()
} }
else if( sectionstr == "APPID" ) else if( sectionstr == "APPID" )
{ {
// processAppId(); processAppId();
} }
else if( sectionstr == "DIMSTYLE" ) else if( sectionstr == "DIMSTYLE" )
{ {
...@@ -2778,6 +2895,44 @@ bool dxfRW::processVports() ...@@ -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 *********/ /********* Block Section *********/
bool dxfRW::processBlocks() bool dxfRW::processBlocks()
......
...@@ -45,6 +45,7 @@ public: ...@@ -45,6 +45,7 @@ public:
bool writeDimstyle( DRW_Dimstyle* ent ); bool writeDimstyle( DRW_Dimstyle* ent );
bool writeTextstyle( DRW_Textstyle* ent ); bool writeTextstyle( DRW_Textstyle* ent );
bool writeVport( DRW_Vport* ent ); bool writeVport( DRW_Vport* ent );
bool writeAppId( DRW_AppId* ent );
bool writePoint( DRW_Point* ent ); bool writePoint( DRW_Point* ent );
bool writeLine( DRW_Line* ent ); bool writeLine( DRW_Line* ent );
bool writeRay( DRW_Ray* ent ); bool writeRay( DRW_Ray* ent );
...@@ -70,6 +71,7 @@ public: ...@@ -70,6 +71,7 @@ public:
bool writeDimension( DRW_Dimension* ent ); bool writeDimension( DRW_Dimension* ent );
void setEllipseParts( int parts ) { elParts = parts; } /*!< set parts munber when convert ellipse to polyline */ void setEllipseParts( int parts ) { elParts = parts; } /*!< set parts munber when convert ellipse to polyline */
private: private:
/// used by read() to parse the content of the file /// used by read() to parse the content of the file
bool processDxf(); bool processDxf();
...@@ -85,6 +87,7 @@ private: ...@@ -85,6 +87,7 @@ private:
bool processDimStyle(); bool processDimStyle();
bool processTextStyle(); bool processTextStyle();
bool processVports(); bool processVports();
bool processAppId();
bool processPoint(); bool processPoint();
bool processLine(); bool processLine();
...@@ -115,6 +118,7 @@ private: ...@@ -115,6 +118,7 @@ private:
bool writeTables(); bool writeTables();
bool writeBlocks(); bool writeBlocks();
bool writeObjects(); bool writeObjects();
bool writeExtData( const std::vector<DRW_Variant*>& ed );
std::string toHexStr( int n ); std::string toHexStr( int n );
private: private:
......
...@@ -165,6 +165,9 @@ private: ...@@ -165,6 +165,9 @@ private:
void writeLine(); void writeLine();
void writeMtext(); void writeMtext();
virtual void addAppId( const DRW_AppId& data ) {}
virtual void writeAppId() {}
}; };
#endif // FILTERDXFRW_H #endif // FILTERDXFRW_H
...@@ -91,6 +91,8 @@ private: ...@@ -91,6 +91,8 @@ private:
virtual void writeTextstyles(){} virtual void writeTextstyles(){}
virtual void writeVports(){} virtual void writeVports(){}
virtual void writeDimstyles(){} virtual void writeDimstyles(){}
virtual void addAppId( const DRW_AppId& data ) {}
virtual void writeAppId() {}
}; };
#endif // DXF2IDF_H #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