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,15 +123,15 @@ 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 )
{
stawidth = endwidth = 0;
x = sx;
y = sy;
bulge = b;
x = sx;
y = sy;
bulge = b;
}
public:
......@@ -149,7 +151,8 @@ public:
class DRW_Variant
{
public:
enum TYPE {
enum TYPE
{
STRING,
INTEGER,
DOUBLE,
......@@ -162,46 +165,63 @@ 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
{
UTF8STRING* s;
int i;
double d;
DRW_Coord* v;
int i;
double d;
DRW_Coord* v;
} DRW_VarContent;
public:
DRW_VarContent content;
public:
int code;
// string version;
// string codepage;
DRW_VarContent content;
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;
}
......@@ -137,8 +199,8 @@ void DRW_Point::parseCode( int code, dxfReader* reader )
break;
case 210:
haveExtrusion = true;
extPoint.x = reader->getDouble();
haveExtrusion = true;
extPoint.x = reader->getDouble();
break;
case 220:
......@@ -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 )
......@@ -309,9 +397,9 @@ void DRW_Ellipse::toPolyline( DRW_Polyline* pol, int parts )
radMajor = sqrt( secPoint.x * secPoint.x + secPoint.y * secPoint.y );
radMinor = radMajor * ratio;
// calculate sin & cos of included angle
incAngle = atan2( secPoint.y, secPoint.x );
cosRot = cos( incAngle );
sinRot = sin( incAngle );
incAngle = atan2( secPoint.y, secPoint.x );
cosRot = cos( incAngle );
sinRot = sin( incAngle );
incAngle = M_PIx2 / parts;
curAngle = staparam;
int i = curAngle / incAngle;
......@@ -336,9 +424,9 @@ void DRW_Ellipse::toPolyline( DRW_Polyline* pol, int parts )
pol->flags = 1;
}
pol->layer = this->layer;
pol->lineType = this->lineType;
pol->color = this->color;
pol->layer = this->layer;
pol->lineType = this->lineType;
pol->color = this->color;
pol->lWeight = this->lWeight;
pol->extPoint = this->extPoint;
}
......@@ -487,8 +575,8 @@ void DRW_LWPolyline::applyExtrusion()
for( unsigned int i = 0; i<vertlist.size(); i++ )
{
DRW_Vertex2D* vert = vertlist.at( i );
DRW_Coord v( vert->x, vert->y, elevation );
DRW_Vertex2D* vert = vertlist.at( i );
DRW_Coord v( vert->x, vert->y, elevation );
extrudePoint( extPoint, &v );
vert->x = v.x;
vert->y = v.y;
......@@ -502,12 +590,12 @@ void DRW_LWPolyline::parseCode( int code, dxfReader* reader )
switch( code )
{
case 10:
{
vertex = new DRW_Vertex2D();
vertlist.push_back( vertex );
vertex->x = reader->getDouble();
break;
}
{
vertex = new DRW_Vertex2D();
vertlist.push_back( vertex );
vertex->x = reader->getDouble();
break;
}
case 20:
......@@ -559,8 +647,8 @@ void DRW_LWPolyline::parseCode( int code, dxfReader* reader )
break;
case 210:
haveExtrusion = true;
extPoint.x = reader->getDouble();
haveExtrusion = true;
extPoint.x = reader->getDouble();
break;
case 220:
......@@ -779,19 +867,19 @@ void DRW_Hatch::parseCode( int code, dxfReader* reader )
{
break;
}
else if( reader->getInt32() == 1 ) // line
else if( reader->getInt32() == 1 ) // line
{
addLine();
}
else if( reader->getInt32() == 2 ) // arc
else if( reader->getInt32() == 2 ) // arc
{
addArc();
}
else if( reader->getInt32() == 3 ) // elliptic arc
else if( reader->getInt32() == 3 ) // elliptic arc
{
addEllipse();
}
else if( reader->getInt32() == 4 ) // spline
else if( reader->getInt32() == 4 ) // spline
{
addSpline();
}
......@@ -804,8 +892,8 @@ void DRW_Hatch::parseCode( int code, dxfReader* reader )
pt->basePoint.x = reader->getDouble();
else if( pline )
{
plvert = pline->addVertex();
plvert->x = reader->getDouble();
plvert = pline->addVertex();
plvert->x = reader->getDouble();
}
break;
......@@ -1018,12 +1106,12 @@ void DRW_Spline::parseCode( int code, dxfReader* reader )
break;
case 10:
{
controlpoint = new DRW_Coord();
controllist.push_back( controlpoint );
controlpoint->x = reader->getDouble();
break;
}
{
controlpoint = new DRW_Coord();
controllist.push_back( controlpoint );
controlpoint->x = reader->getDouble();
break;
}
case 20:
......@@ -1040,12 +1128,12 @@ void DRW_Spline::parseCode( int code, dxfReader* reader )
break;
case 11:
{
fitpoint = new DRW_Coord();
fitlist.push_back( fitpoint );
fitpoint->x = reader->getDouble();
break;
}
{
fitpoint = new DRW_Coord();
fitlist.push_back( fitpoint );
fitpoint->x = reader->getDouble();
break;
}
case 21:
......@@ -1312,12 +1400,12 @@ void DRW_Leader::parseCode( int code, dxfReader* reader )
break;
case 10:
{
vertexpoint = new DRW_Coord();
vertexlist.push_back( vertexpoint );
vertexpoint->x = reader->getDouble();
break;
}
{
vertexpoint = new DRW_Coord();
vertexlist.push_back( vertexpoint );
vertexpoint->x = reader->getDouble();
break;
}
case 20:
......@@ -1413,10 +1501,10 @@ void DRW_Viewport::parseCode( int code, dxfReader* reader )
break;
case 12:
{
centerPX = reader->getDouble();
break;
}
{
centerPX = reader->getDouble();
break;
}
case 22:
centerPY = reader->getDouble();
......
This diff is collapsed.
......@@ -40,22 +40,25 @@ public:
}
/** Called when header is parsed. */
virtual void addHeader( const DRW_Header* data ) = 0;
virtual void addHeader( const DRW_Header* data ) = 0;
/** Called for every line Type. */
virtual void addLType( const DRW_LType& data ) = 0;
virtual void addLType( const DRW_LType& data ) = 0;
/** Called for every layer. */
virtual void addLayer( const DRW_Layer& data ) = 0;
virtual void addLayer( const DRW_Layer& data ) = 0;
/** Called for every dim style. */
virtual void addDimStyle( const DRW_Dimstyle& data ) = 0;
virtual void addDimStyle( const DRW_Dimstyle& data ) = 0;
/** Called for every VPORT table. */
virtual void addVport( const DRW_Vport& data ) = 0;
virtual void addVport( const DRW_Vport& data ) = 0;
/** 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
......@@ -63,7 +66,7 @@ public:
*
* @see endBlock()
*/
virtual void addBlock( const DRW_Block& data ) = 0;
virtual void addBlock( const DRW_Block& data ) = 0;
/**
* In DWG called when the following entities corresponding to a
......@@ -72,127 +75,127 @@ public:
*
* int handle are the value of DRW_Block::handleBlock added with addBlock()
*/
virtual void setBlock( const int handle ) = 0;
virtual void setBlock( const int handle ) = 0;
/** Called to end the current block */
virtual void endBlock() = 0;
virtual void endBlock() = 0;
/** Called for every point */
virtual void addPoint( const DRW_Point& data ) = 0;
virtual void addPoint( const DRW_Point& data ) = 0;
/** Called for every line */
virtual void addLine( const DRW_Line& data ) = 0;
virtual void addLine( const DRW_Line& data ) = 0;
/** Called for every ray */
virtual void addRay( const DRW_Ray& data ) = 0;
virtual void addRay( const DRW_Ray& data ) = 0;
/** Called for every xline */
virtual void addXline( const DRW_Xline& data ) = 0;
virtual void addXline( const DRW_Xline& data ) = 0;
/** Called for every arc */
virtual void addArc( const DRW_Arc& data ) = 0;
virtual void addArc( const DRW_Arc& data ) = 0;
/** Called for every circle */
virtual void addCircle( const DRW_Circle& data ) = 0;
virtual void addCircle( const DRW_Circle& data ) = 0;
/** Called for every ellipse */
virtual void addEllipse( const DRW_Ellipse& data ) = 0;
virtual void addEllipse( const DRW_Ellipse& data ) = 0;
/** Called for every lwpolyline */
virtual void addLWPolyline( const DRW_LWPolyline& data ) = 0;
virtual void addLWPolyline( const DRW_LWPolyline& data ) = 0;
/** Called for every polyline start */
virtual void addPolyline( const DRW_Polyline& data ) = 0;
virtual void addPolyline( const DRW_Polyline& data ) = 0;
/** Called for every spline */
virtual void addSpline( const DRW_Spline* data ) = 0;
virtual void addSpline( const DRW_Spline* data ) = 0;
/** Called for every spline knot value */
virtual void addKnot( const DRW_Entity& data ) = 0;
virtual void addKnot( const DRW_Entity& data ) = 0;
/** Called for every insert. */
virtual void addInsert( const DRW_Insert& data ) = 0;
virtual void addInsert( const DRW_Insert& data ) = 0;
/** Called for every trace start */
virtual void addTrace( const DRW_Trace& data ) = 0;
virtual void addTrace( const DRW_Trace& data ) = 0;
/** Called for every 3dface start */
virtual void add3dFace( const DRW_3Dface& data ) = 0;
virtual void add3dFace( const DRW_3Dface& data ) = 0;
/** Called for every solid start */
virtual void addSolid( const DRW_Solid& data ) = 0;
virtual void addSolid( const DRW_Solid& data ) = 0;
/** Called for every Multi Text entity. */
virtual void addMText( const DRW_MText& data ) = 0;
virtual void addMText( const DRW_MText& data ) = 0;
/** Called for every Text entity. */
virtual void addText( const DRW_Text& data ) = 0;
virtual void addText( const DRW_Text& data ) = 0;
/**
* Called for every aligned dimension entity.
*/
virtual void addDimAlign( const DRW_DimAligned* data ) = 0;
virtual void addDimAlign( const DRW_DimAligned* data ) = 0;
/**
* Called for every linear or rotated dimension entity.
*/
virtual void addDimLinear( const DRW_DimLinear* data ) = 0;
virtual void addDimLinear( const DRW_DimLinear* data ) = 0;
/**
* Called for every radial dimension entity.
*/
virtual void addDimRadial( const DRW_DimRadial* data ) = 0;
virtual void addDimRadial( const DRW_DimRadial* data ) = 0;
/**
* Called for every diametric dimension entity.
*/
virtual void addDimDiametric( const DRW_DimDiametric* data ) = 0;
virtual void addDimDiametric( const DRW_DimDiametric* data ) = 0;
/**
* Called for every angular dimension (2 lines version) entity.
*/
virtual void addDimAngular( const DRW_DimAngular* data ) = 0;
virtual void addDimAngular( const DRW_DimAngular* data ) = 0;
/**
* Called for every angular dimension (3 points version) entity.
*/
virtual void addDimAngular3P( const DRW_DimAngular3p* data ) = 0;
virtual void addDimAngular3P( const DRW_DimAngular3p* data ) = 0;
/**
* Called for every ordinate dimension entity.
*/
virtual void addDimOrdinate( const DRW_DimOrdinate* data ) = 0;
virtual void addDimOrdinate( const DRW_DimOrdinate* data ) = 0;
/**
* Called for every leader start.
*/
virtual void addLeader( const DRW_Leader* data ) = 0;
virtual void addLeader( const DRW_Leader* data ) = 0;
/**
* Called for every hatch entity.
*/
virtual void addHatch( const DRW_Hatch* data ) = 0;
virtual void addHatch( const DRW_Hatch* data ) = 0;
/**
* Called for every viewport entity.
*/
virtual void addViewport( const DRW_Viewport& data ) = 0;
virtual void addViewport( const DRW_Viewport& data ) = 0;
/**
* Called for every image entity.
*/
virtual void addImage( const DRW_Image* data ) = 0;
virtual void addImage( const DRW_Image* data ) = 0;
/**
* Called for every image definition.
*/
virtual void linkImage( const DRW_ImageDef* data ) = 0;
virtual void linkImage( const DRW_ImageDef* data ) = 0;
/**
* Called for every comment in the DXF file (code 999).
*/
virtual void addComment( const char* comment ) = 0;
virtual void addComment( const char* comment ) = 0;
/** Sets the current attributes for entities. */
/* void setExtrusion(double dx, double dy, double dz, double elevation) {
......@@ -208,12 +211,13 @@ public:
virtual void writeHeader( DRW_Header& data ) = 0;
virtual void writeBlocks() = 0;
virtual void writeBlockRecords() = 0;
virtual void writeEntities() = 0;
virtual void writeLTypes() = 0;
virtual void writeLayers() = 0;
virtual void writeTextstyles() = 0;
virtual void writeVports() = 0;
virtual void writeDimstyles() = 0;
virtual void writeEntities() = 0;
virtual void writeLTypes() = 0;
virtual void writeLayers() = 0;
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;
......@@ -815,8 +867,8 @@ void DRW_Header::parseCode( int code, dxfReader* reader )
void DRW_Header::write( dxfWriter* writer, DRW::Version ver )
{
/*RLZ: TODO complete all vars to AC1024*/
double varDouble;
int varInt;
double varDouble;
int varInt;
std::string varStr;
DRW_Coord varCoord;
......@@ -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;
......@@ -1258,8 +1352,8 @@ bool DRW_Header::getDouble( std::string key, double* varDouble )
if( var->type == DRW_Variant::DOUBLE )
{
*varDouble = var->content.d;
result = true;
*varDouble = var->content.d;
result = true;
}
vars.erase( it );
......@@ -1330,8 +1424,8 @@ bool DRW_Header::getCoord( std::string key, DRW_Coord* varCoord )
if( var->type == DRW_Variant::COORD )
{
*varCoord = *var->content.v;
result = true;
*varCoord = *var->content.v;
result = true;
}
vars.erase( it );
......
This diff is collapsed.
......@@ -12,7 +12,7 @@
DRW_TextCodec::DRW_TextCodec()
{
version = DRW::AC1021;
conv = new DRW_Converter( NULL, 0 );
conv = new DRW_Converter( NULL, 0 );
}
......@@ -62,16 +62,16 @@ void DRW_TextCodec::setCodePage( std::string* c )
conv = new DRW_ConvTable( DRW_Table874, CPLENGHTCOMMON );
else if( cp == "ANSI_932" )
conv = new DRW_Conv932Table( DRW_Table932, DRW_LeadTable932,
DRW_DoubleTable932, CPLENGHT932 );
DRW_DoubleTable932, CPLENGHT932 );
else if( cp == "ANSI_936" )
conv = new DRW_ConvDBCSTable( DRW_Table936, DRW_LeadTable936,
DRW_DoubleTable936, CPLENGHT936 );
DRW_DoubleTable936, CPLENGHT936 );
else if( cp == "ANSI_949" )
conv = new DRW_ConvDBCSTable( DRW_Table949, DRW_LeadTable949,
DRW_DoubleTable949, CPLENGHT949 );
DRW_DoubleTable949, CPLENGHT949 );
else if( cp == "ANSI_950" )
conv = new DRW_ConvDBCSTable( DRW_Table950, DRW_LeadTable950,
DRW_DoubleTable950, CPLENGHT950 );
DRW_DoubleTable950, CPLENGHT950 );
else if( cp == "ANSI_1250" )
conv = new DRW_ConvTable( DRW_Table1250, CPLENGHTCOMMON );
else if( cp == "ANSI_1251" )
......@@ -117,9 +117,9 @@ std::string DRW_TextCodec::fromUtf8( std::string s )
std::string DRW_Converter::toUtf8( std::string* s )
{
std::string result;
int j = 0;
unsigned int i = 0;
std::string result;
int j = 0;
unsigned int i = 0;
for( i = 0; i < s->length(); i++ )
{
......@@ -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 ) );
......@@ -159,10 +158,10 @@ std::string DRW_Converter::toUtf8( std::string* s )
std::string DRW_ConvTable::fromUtf8( std::string* s )
{
std::string result;
bool notFound;
int code;
bool notFound;
int code;
int j = 0;
int j = 0;
for( unsigned int i = 0; i < s->length(); i++ )
{
......@@ -172,17 +171,17 @@ std::string DRW_ConvTable::fromUtf8( std::string* s )
{
result += s->substr( j, i - j );
std::string part1 = s->substr( i, 4 );
int l;
int l;
code = decodeNum( part1, &l );
j = i + l;
i = j - 1;
j = i + l;
i = j - 1;
notFound = true;
for( int k = 0; k<cpLenght; k++ )
{
if( table[k] == code )
{
result += CPOFFSET + k; // translate from table
result += CPOFFSET + k; // translate from table
notFound = false;
break;
}
......@@ -201,10 +200,10 @@ std::string DRW_ConvTable::fromUtf8( std::string* s )
std::string DRW_ConvTable::toUtf8( std::string* s )
{
std::string res;
std::string::iterator it;
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;
......@@ -313,21 +312,21 @@ std::string DRW_Converter::encodeNum( int c )
**/
int DRW_Converter::decodeNum( std::string s, int* b )
{
int code = 0;
unsigned char c = s.at( 0 );
int code = 0;
unsigned char c = s.at( 0 );
if( (c & 0xE0) == 0xC0 ) // 2 bytes
{
code = ( c & 0x1F) << 6;
code = (s.at( 1 ) & 0x3F) | code;
*b = 2;
*b = 2;
}
else if( (c & 0xF0) == 0xE0 ) // 3 bytes
{
code = ( c & 0x0F) << 12;
code = ( (s.at( 1 ) & 0x3F) << 6 ) | code;
code = (s.at( 2 ) & 0x3F) | code;
*b = 3;
*b = 3;
}
else if( (c & 0xF8) == 0xF0 ) // 4 bytes
{
......@@ -335,7 +334,7 @@ int DRW_Converter::decodeNum( std::string s, int* b )
code = ( (s.at( 1 ) & 0x3F) << 12 ) | code;
code = ( (s.at( 2 ) & 0x3F) << 6 ) | code;
code = (s.at( 3 ) & 0x3F) | code;
*b = 4;
*b = 4;
}
return code;
......@@ -345,10 +344,10 @@ int DRW_Converter::decodeNum( std::string s, int* b )
std::string DRW_ConvDBCSTable::fromUtf8( std::string* s )
{
std::string result;
bool notFound;
int code;
bool notFound;
int code;
int j = 0;
int j = 0;
for( unsigned int i = 0; i < s->length(); i++ )
{
......@@ -358,21 +357,21 @@ std::string DRW_ConvDBCSTable::fromUtf8( std::string* s )
{
result += s->substr( j, i - j );
std::string part1 = s->substr( i, 4 );
int l;
int l;
code = decodeNum( part1, &l );
j = i + l;
i = j - 1;
j = i + l;
i = j - 1;
notFound = true;
for( int k = 0; k<cpLenght; k++ )
{
if( doubleTable[k][1] == code )
{
int data = doubleTable[k][0];
char d[3];
d[0] = data >> 8;
d[1] = data & 0xFF;
d[2] = '\0';
int data = doubleTable[k][0];
char d[3];
d[0] = data >> 8;
d[1] = data & 0xFF;
d[2] = '\0';
result += d; // translate from table
notFound = false;
break;
......@@ -392,13 +391,13 @@ std::string DRW_ConvDBCSTable::fromUtf8( std::string* s )
std::string DRW_ConvDBCSTable::toUtf8( std::string* s )
{
std::string res;
std::string::iterator it;
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;
bool notFound = true;
unsigned char c = *it;
if( c < 0x80 )
{
......@@ -455,10 +454,10 @@ std::string DRW_ConvDBCSTable::toUtf8( std::string* s )
std::string DRW_Conv932Table::fromUtf8( std::string* s )
{
std::string result;
bool notFound;
int code;
bool notFound;
int code;
int j = 0;
int j = 0;
for( unsigned int i = 0; i < s->length(); i++ )
{
......@@ -468,16 +467,16 @@ std::string DRW_Conv932Table::fromUtf8( std::string* s )
{
result += s->substr( j, i - j );
std::string part1 = s->substr( i, 4 );
int l;
int l;
code = decodeNum( part1, &l );
j = i + l;
i = j - 1;
j = i + l;
i = j - 1;
notFound = true;
// 1 byte table
if( code > 0xff60 && code < 0xFFA0 )
{
result += code - CPOFFSET932; // translate from table
result += code - CPOFFSET932; // translate from table
notFound = false;
}
......@@ -488,12 +487,12 @@ std::string DRW_Conv932Table::fromUtf8( std::string* s )
{
if( doubleTable[k][1] == code )
{
int data = doubleTable[k][0];
char d[3];
d[0] = data >> 8;
d[1] = data & 0xFF;
d[2] = '\0';
result += d; // translate from table
int data = doubleTable[k][0];
char d[3];
d[0] = data >> 8;
d[1] = data & 0xFF;
d[2] = '\0';
result += d; // translate from table
notFound = false;
break;
}
......@@ -513,13 +512,13 @@ std::string DRW_Conv932Table::fromUtf8( std::string* s )
std::string DRW_Conv932Table::toUtf8( std::string* s )
{
std::string res;
std::string::iterator it;
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;
bool notFound = true;
unsigned char c = *it;
if( c < 0x80 )
{
......@@ -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";
......
......@@ -14,20 +14,21 @@ public:
std::string toUtf8( std::string s );
int getVersion() { return version; }
void setVersion( std::string* v );
void setVersion( std::string* v );
void setVersion( int v ) { version = v; }
void setCodePage( std::string* c );
void setCodePage( std::string* c );
void setCodePage( std::string c ) { setCodePage( &c ); }
std::string getCodePage() { return cp; }
private:
std::string correctCodePage( const std::string& s );
private:
int version;
std::string cp;
DRW_Converter* conv;
int version;
std::string cp;
DRW_Converter* conv;
};
class DRW_Converter
......@@ -47,8 +48,8 @@ public:
std::string encodeNum( int c );
int decodeNum( std::string s, int* b );
const int* table;
int cpLenght;
const int* table;
int cpLenght;
};
class DRW_ConvTable : public DRW_Converter
......@@ -63,9 +64,9 @@ class DRW_ConvDBCSTable : public DRW_Converter
{
public:
DRW_ConvDBCSTable( const int* t, const int* lt, const int dt[][2], int l ) : DRW_Converter( t,
l )
l )
{
leadTable = lt;
leadTable = lt;
doubleTable = dt;
}
......@@ -81,9 +82,9 @@ class DRW_Conv932Table : public DRW_Converter
{
public:
DRW_Conv932Table( const int* t, const int* lt, const int dt[][2], int l ) : DRW_Converter( t,
l )
l )
{
leadTable = lt;
leadTable = lt;
doubleTable = dt;
}
......
......@@ -127,7 +127,7 @@ int dxfReader::getHandleString()
bool dxfReaderBinary::readCode( int* code )
{
unsigned short* int16p;
char buffer[2];
char buffer[2];
filestr->read( buffer, 2 );
int16p = (unsigned short*) buffer;
......@@ -179,8 +179,8 @@ bool dxfReaderBinary::readInt()
bool dxfReaderBinary::readInt32()
{
unsigned int* int32p;
char buffer[4];
unsigned int* int32p;
char buffer[4];
filestr->read( buffer, 4 );
int32p = (unsigned int*) buffer;
......@@ -206,11 +206,11 @@ bool dxfReaderBinary::readInt64()
bool dxfReaderBinary::readDouble()
{
double* result;
char buffer[8];
char buffer[8];
filestr->read( buffer, 8 );
result = (double*) buffer;
doubleData = *result;
result = (double*) buffer;
doubleData = *result;
DBG( doubleData ); DBG( "\n" );
return filestr->good();
}
......
......@@ -21,6 +21,9 @@ public:
dxfReader( std::ifstream* stream )
{
filestr = stream;
doubleData = 0.0;
intData = 0;
int64 = 0;
#ifdef DRW_DBG
count = 0;
#endif
......@@ -31,14 +34,14 @@ public:
virtual bool readString( std::string* text ) = 0;
virtual bool readString() = 0;
bool readRec( int* code, bool skip );
virtual bool readInt() = 0;
virtual bool readInt() = 0;
virtual bool readInt32() = 0;
virtual bool readInt64() = 0;
virtual bool readDouble() = 0;
virtual bool readBool() = 0;
virtual bool readBool() = 0;
std::string getString() { return strData; }
int getHandleString(); // Convert hex string to int
int getHandleString(); // Convert hex string to int
std::string toUtf8String( std::string t ) { return decoder.toUtf8( t ); }
std::string getUtf8String() { return decoder.toUtf8( strData ); }
......@@ -51,22 +54,24 @@ public:
void setCodePage( std::string* c ) { decoder.setCodePage( c ); }
std::string getCodePage() { return decoder.getCodePage(); }
#ifdef DRW_DBG
int count; // 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
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;
DRW_TextCodec decoder;
};
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 );
......
......@@ -28,22 +28,24 @@ public:
virtual bool writeInt16( int code, int data ) = 0;
virtual bool writeInt32( int code, int data ) = 0;
virtual bool writeInt64( int code, unsigned long long int data ) = 0;
virtual bool writeDouble( int code, double data ) = 0;
virtual bool writeBool( int code, bool data ) = 0;
virtual bool writeDouble( int code, double data ) = 0;
virtual bool writeBool( int code, bool data ) = 0;
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;
std::ofstream* filestr;
private:
DRW_TextCodec encoder;
DRW_TextCodec encoder;
};
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 );
......
This diff is collapsed.
......@@ -35,7 +35,7 @@ public:
* @param ext should the extrusion be applied to convert in 2D?
* @return true for success
*/
bool read( DRW_Interface* interface_, bool ext );
bool read( DRW_Interface* interface_, bool ext );
void setBinary( bool b ) { binary = b; }
......@@ -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,74 +71,77 @@ 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();
bool processHeader();
bool processTables();
bool processBlocks();
bool processBlock();
bool processEntities( bool isblock );
bool processObjects();
bool processDxf();
bool processHeader();
bool processTables();
bool processBlocks();
bool processBlock();
bool processEntities( bool isblock );
bool processObjects();
bool processLType();
bool processLayer();
bool processDimStyle();
bool processTextStyle();
bool processVports();
bool processLType();
bool processLayer();
bool processDimStyle();
bool processTextStyle();
bool processVports();
bool processAppId();
bool processPoint();
bool processLine();
bool processRay();
bool processXline();
bool processCircle();
bool processArc();
bool processEllipse();
bool processTrace();
bool processSolid();
bool processInsert();
bool processLWPolyline();
bool processPolyline();
bool processVertex( DRW_Polyline* pl );
bool processText();
bool processMText();
bool processHatch();
bool processSpline();
bool process3dface();
bool processViewport();
bool processImage();
bool processImageDef();
bool processDimension();
bool processLeader();
bool processPoint();
bool processLine();
bool processRay();
bool processXline();
bool processCircle();
bool processArc();
bool processEllipse();
bool processTrace();
bool processSolid();
bool processInsert();
bool processLWPolyline();
bool processPolyline();
bool processVertex( DRW_Polyline* pl );
bool processText();
bool processMText();
bool processHatch();
bool processSpline();
bool process3dface();
bool processViewport();
bool processImage();
bool processImageDef();
bool processDimension();
bool processLeader();
// bool writeHeader();
bool writeEntity( DRW_Entity* ent );
bool writeTables();
bool writeBlocks();
bool writeObjects();
std::string toHexStr( int n );
bool writeEntity( DRW_Entity* ent );
bool writeTables();
bool writeBlocks();
bool writeObjects();
bool writeExtData( const std::vector<DRW_Variant*>& ed );
std::string toHexStr( int n );
private:
DRW::Version version;
std::string fileName;
std::string codePage;
bool binary;
dxfReader* reader;
dxfWriter* writer;
DRW_Interface* iface;
DRW_Header header;
DRW::Version version;
std::string fileName;
std::string codePage;
bool binary;
dxfReader* reader;
dxfWriter* writer;
DRW_Interface* iface;
DRW_Header header;
// int section;
std::string nextentity;
int entCount;
bool wlayer0;
bool dimstyleStd;
bool applyExt;
bool writingBlock;
int elParts; /*!< parts munber when convert ellipse to polyline */
std::string nextentity;
int entCount;
bool wlayer0;
bool dimstyleStd;
bool applyExt;
bool writingBlock;
int elParts; /*!< parts munber when convert ellipse to polyline */
std::map<std::string, int> blockMap;
std::vector<DRW_ImageDef*> imageDef; /*!< imageDef list */
int currHandle;
int currHandle;
};
#endif // LIBDXFRW_H
......@@ -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