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