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.
This commit is contained in:
jean-pierre charras 2015-02-24 10:07:40 +01:00
parent d5e70c93d9
commit ede0daf9db
15 changed files with 1615 additions and 1128 deletions

View File

@ -13,7 +13,7 @@
#ifndef DRW_BASE_H
#define DRW_BASE_H
#define DRW_VERSION "0.5.11"
#define DRW_VERSION "0.5.13"
#include <string>
#include <cmath>
@ -42,7 +42,8 @@
namespace DRW {
// ! Version numbers for the DXF Format.
enum Version {
enum Version
{
UNKNOWNV, /*!< UNKNOWN VERSION. */
AC1006, /*!< R10. */
AC1009, /*!< R11 & R12. */
@ -54,7 +55,8 @@ enum Version {
AC1024 /*!< ACAD 2010. */
};
enum error {
enum error
{
BAD_NONE, /*!< No error. */
BAD_UNKNOWN, /*!< UNKNOWN. */
BAD_OPEN, /*!< error opening file. */
@ -76,7 +78,7 @@ enum error {
class DRW_Coord
{
public:
DRW_Coord() { x = 0; y = 0; z = 0; }
DRW_Coord(): x(0), y(0), z(0) {}
DRW_Coord( double ix, double iy, double iz )
{
x = ix; y = iy; z = iz;
@ -121,7 +123,7 @@ public:
DRW_Vertex2D()
{
// eType = DRW::LWPOLYLINE;
stawidth = endwidth = bulge = 0;
x = y = stawidth = endwidth = bulge = 0.0;
}
DRW_Vertex2D( double sx, double sy, double b )
@ -149,7 +151,8 @@ public:
class DRW_Variant
{
public:
enum TYPE {
enum TYPE
{
STRING,
INTEGER,
DOUBLE,
@ -162,29 +165,46 @@ public:
type = INVALID;
}
DRW_Variant( const DRW_Variant& d )
{
code = d.code;
type = d.type;
if( d.type == COORD ) vdata = d.vdata;
if( d.type == STRING ) sdata = d.sdata;
content = d.content;
}
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;
}
~DRW_Variant()
{
if( type == COORD )
delete content.v;
}
enum TYPE type;
void addString( UTF8STRING s ) { setType( STRING ); data = s; content.s = &data; }
void addString( UTF8STRING s ) { setType( STRING ); sdata = s; content.s = &sdata; }
void addInt( int i ) { setType( INTEGER ); content.i = i; }
void addDouble( double d ) { setType( DOUBLE ); content.d = d; }
void addCoord( DRW_Coord* v ) { setType( COORD ); content.v = v; }
void setType( enum TYPE t )
void addCoord()
{
if( type == COORD )
delete content.v;
type = t;
setType( COORD ); vdata.x = 0.0; vdata.y = 0.0; vdata.z = 0.0; content.v =
&vdata;
}
void setCoordX( double d ) { if( type == COORD ) content.v->x = d; }
void setCoordY( double d ) { if( type == COORD ) content.v->y = d; }
void setCoordZ( double d ) { if( type == COORD ) content.v->z = d; }
void addCoord( DRW_Coord v ) { setType( COORD ); vdata = v; content.v = &vdata; }
void setType( enum TYPE t ) { type = t; }
void setCoordX( double d ) { if( type == COORD ) vdata.x = d; }
void setCoordY( double d ) { if( type == COORD ) vdata.y = d; }
void setCoordZ( double d ) { if( type == COORD ) vdata.z = d; }
private:
typedef union
{
@ -193,15 +213,15 @@ private:
double d;
DRW_Coord* v;
} DRW_VarContent;
public:
DRW_VarContent content;
public:
int code;
// string version;
// string codepage;
enum TYPE type;
int code; /*!< dxf code of this value*/
private:
// DRW_VarContent content;
std::string data;
std::string sdata;
DRW_Coord vdata;
};
@ -215,7 +235,8 @@ private:
class DRW_LW_Conv
{
public:
enum lineWidth {
enum lineWidth
{
width00 = 0, /*!< 0.00mm (dxf 0)*/
width01 = 1, /*!< 0.05mm (dxf 5)*/
width02 = 2, /*!< 0.09mm (dxf 9)*/

View File

@ -22,23 +22,33 @@
*/
void DRW_Entity::calculateAxis( DRW_Coord extPoint )
{
// Follow the arbitrary DXF definitions for extrusion axes.
if( fabs( extPoint.x ) < 0.015625 && fabs( extPoint.y ) < 0.015625 )
{
// If we get here, implement Ax = Wy x N where Wy is [0,1,0] per the DXF spec.
// The cross product works out to Wy.y*N.z-Wy.z*N.y, Wy.z*N.x-Wy.x*N.z, Wy.x*N.y-Wy.y*N.x
// Factoring in the fixed values for Wy gives N.z,0,-N.x
extAxisX.x = extPoint.z;
extAxisX.y = 0;
extAxisX.z = -extPoint.x;
}
else
{
// Otherwise, implement Ax = Wz x N where Wz is [0,0,1] per the DXF spec.
// The cross product works out to Wz.y*N.z-Wz.z*N.y, Wz.z*N.x-Wz.x*N.z, Wz.x*N.y-Wz.y*N.x
// Factoring in the fixed values for Wz gives -N.y,N.x,0.
extAxisX.x = -extPoint.y;
extAxisX.y = extPoint.x;
extAxisX.z = 0;
}
extAxisX.unitize();
// Ay = N x Ax
extAxisY.x = (extPoint.y * extAxisX.z) - (extAxisX.y * extPoint.z);
extAxisY.y = (extPoint.z * extAxisX.x) - (extAxisX.z * extPoint.x);
extAxisY.z = (extPoint.x * extAxisX.y) - (extAxisX.x * extPoint.y);
extAxisY.unitize();
}
@ -110,6 +120,58 @@ void DRW_Entity::parseCode( int code, dxfReader* reader )
space = reader->getInt32();
break;
case 1000:
case 1001:
case 1002:
case 1003:
case 1004:
case 1005:
extData.push_back( new DRW_Variant( code, reader->getString() ) );
break;
case 1010:
case 1011:
case 1012:
case 1013:
curr = new DRW_Variant();
curr->addCoord();
curr->setCoordX( reader->getDouble() );
curr->code = code;
extData.push_back( curr );
break;
case 1020:
case 1021:
case 1022:
case 1023:
if( curr )
curr->setCoordY( reader->getDouble() );
break;
case 1030:
case 1031:
case 1032:
case 1033:
if( curr )
curr->setCoordZ( reader->getDouble() );
curr = NULL;
break;
case 1040:
case 1041:
case 1042:
extData.push_back( new DRW_Variant( code, reader->getDouble() ) );
break;
case 1070:
case 1071:
extData.push_back( new DRW_Variant( code, reader->getInt32() ) );
break;
default:
break;
}
@ -183,6 +245,8 @@ void DRW_Circle::applyExtrusion()
{
if( haveExtrusion )
{
// NOTE: Commenting these out causes the the arcs being tested to be located
// on the other side of the y axis (all x dimensions are negated).
calculateAxis( extPoint );
extrudePoint( extPoint, &basePoint );
}
@ -204,6 +268,30 @@ void DRW_Circle::parseCode( int code, dxfReader* reader )
}
void DRW_Arc::applyExtrusion()
{
DRW_Circle::applyExtrusion();
if( haveExtrusion )
{
// If the extrusion vector has a z value less than 0, the angles for the arc
// have to be mirrored since DXF files use the right hand rule.
// Note that the following code only handles the special case where there is a 2D
// drawing with the z axis heading into the paper (or rather screen). An arbitrary
// extrusion axis (with x and y values greater than 1/64) may still have issues.
if( fabs( extPoint.x ) < 0.015625 && fabs( extPoint.y ) < 0.015625 && extPoint.z < 0.0 )
{
staangle = M_PI - staangle;
endangle = M_PI - endangle;
double temp = staangle;
staangle = endangle;
endangle = temp;
}
}
}
void DRW_Arc::parseCode( int code, dxfReader* reader )
{
switch( code )

View File

@ -23,7 +23,8 @@ class DRW_Polyline;
namespace DRW {
// ! Entity's type.
enum ETYPE {
enum ETYPE
{
POINT,
LINE,
CIRCLE,
@ -82,9 +83,17 @@ public:
handleBlock = space = 0; // default ModelSpace (0) & handleBlock = no handle (0)
haveExtrusion = false;
color24 = -1; // default -1 not set
handle = 0;
curr = NULL;
}
virtual ~DRW_Entity() {}
virtual ~DRW_Entity()
{
for( std::vector<DRW_Variant*>::iterator it = extData.begin(); it!=extData.end(); ++it )
delete *it;
extData.clear();
}
DRW_Entity( const DRW_Entity& d )
{
@ -101,6 +110,7 @@ public:
lWeight = d.lWeight;
space = d.space;
haveExtrusion = d.haveExtrusion;
curr = NULL;
}
virtual void applyExtrusion() = 0;
@ -124,9 +134,12 @@ public:
std::string colorName; /*!< color name, code 430 */
int space; /*!< space indicator 0 = model, 1 paper, code 67*/
bool haveExtrusion; /*!< set to true if the entity have extrusion*/
std::vector<DRW_Variant*> extData; /*!< FIFO list of extended data, codes 1000 to 1071*/
private:
DRW_Coord extAxisX;
DRW_Coord extAxisY;
DRW_Variant* curr;
};
@ -216,6 +229,7 @@ public:
DRW_Circle()
{
eType = DRW::CIRCLE;
radious = 0.0;
}
virtual void applyExtrusion();
@ -237,9 +251,11 @@ public:
{
eType = DRW::ARC;
isccw = 1;
staangle = 0.0;
endangle = 0.0;
}
virtual void applyExtrusion() { DRW_Circle::applyExtrusion(); }
virtual void applyExtrusion();
void parseCode( int code, dxfReader* reader );
public:
@ -262,6 +278,8 @@ public:
{
eType = DRW::ELLIPSE;
isccw = 1;
ratio = 1.0;
staparam = endparam = 0;
}
void parseCode( int code, dxfReader* reader );
@ -413,6 +431,7 @@ public:
extPoint.x = extPoint.y = 0;
extPoint.z = 1;
vertex = NULL;
vertexnum = 0;
}
~DRW_LWPolyline()
@ -470,7 +489,8 @@ class DRW_Text : public DRW_Line
{
public:
// ! Vertical alignments.
enum VAlign {
enum VAlign
{
VBaseLine = 0, /*!< Top = 0 */
VBottom, /*!< Bottom = 1 */
VMiddle, /*!< Middle = 2 */
@ -478,7 +498,8 @@ public:
};
// ! Horizontal alignments.
enum HAlign {
enum HAlign
{
HLeft = 0, /*!< Left = 0 */
HCenter, /*!< Centered = 1 */
HRight, /*!< Right = 2 */
@ -497,6 +518,7 @@ public:
textgen = 0;
alignH = HLeft;
alignV = VBaseLine;
height = 0.0;
}
virtual void applyExtrusion() {} // RLZ TODO
@ -523,7 +545,8 @@ class DRW_MText : public DRW_Text
{
public:
// ! Attachments.
enum Attach {
enum Attach
{
TopLeft = 1,
TopCenter,
TopRight,
@ -549,6 +572,7 @@ public:
public:
double interlin; /*!< width factor, code 44 */
private:
bool haveXAxis;
};
@ -567,6 +591,7 @@ public:
stawidth = endwidth = bulge = 0;
vindex1 = vindex2 = vindex3 = vindex4 = 0;
flags = identifier = 0;
tgdir = 0.0;
}
DRW_Vertex( double sx, double sy, double sz, double b )
@ -578,6 +603,7 @@ public:
basePoint.y = sy;
basePoint.z = sz;
bulge = b;
tgdir = 0.0;
}
void parseCode( int code, dxfReader* reader );
@ -670,6 +696,10 @@ public:
ex = ey = 0.0;
ez = 1.0;
tolknot = tolcontrol = tolfit = 0.0000001;
tgsx = tgsy = tgsz = tgex = tgey = tgez = 0.0;
degree = 0;
controlpoint = 0;
fitpoint = 0;
}
~DRW_Spline()
@ -711,6 +741,7 @@ public:
std::vector<double> knotslist; /*!< knots list, code 40 */
std::vector<DRW_Coord*> controllist; /*!< control points list, code 10, 20 & 30 */
std::vector<DRW_Coord*> fitlist; /*!< fit points list, code 11, 21 & 31 */
private:
DRW_Coord* controlpoint; /*!< current control point to add data */
DRW_Coord* fitpoint; /*!< current fit point to add data */
@ -773,6 +804,7 @@ public:
deflines = doubleflag = 0;
loop = NULL;
clearEntities();
ispol = false;
}
~DRW_Hatch()
@ -804,6 +836,7 @@ public:
int deflines; /*!< number of pattern definition lines, code 78 */
std::vector<DRW_HatchLoop*> looplist; /*!< polyline list */
private:
void clearEntities()
{
@ -884,6 +917,7 @@ public:
eType = DRW::IMAGE;
vz = fade = clip = 0;
brightness = contrast = 50;
vx = vy = sizeu = sizev = dz = 0.0;
}
void parseCode( int code, dxfReader* reader );
@ -922,6 +956,8 @@ public:
defPoint.z = extPoint.x = extPoint.y = 0;
textPoint.z = rot = 0;
clonePoint.x = clonePoint.y = clonePoint.z = 0;
type = 0;
length = 0.0;
}
DRW_Dimension( const DRW_Dimension& d ) : DRW_Entity( d )
@ -955,46 +991,49 @@ public:
virtual void applyExtrusion() {}
DRW_Coord getDefPoint() const { return defPoint; } /*!< Definition point, code 10, 20 & 30 */
void setDefPoint( const DRW_Coord p ) { defPoint = p; }
void setDefPoint( const DRW_Coord& p ) { defPoint = p; }
DRW_Coord getTextPoint() const { return textPoint; } /*!< Middle point of text, code 11, 21 & 31 */
void setTextPoint( const DRW_Coord p ) { textPoint = p; }
void setTextPoint( const DRW_Coord& p ) { textPoint = p; }
std::string getStyle() const { return style; } /*!< Dimension style, code 3 */
void setStyle( const std::string s ) { style = s; }
void setStyle( const std::string& s ) { style = s; }
int getAlign() const { return align; } /*!< attachment point, code 71 */
void setAlign( const int a ) { align = a; }
int getTextLineStyle() const { return linesty; } /*!< Dimension text line spacing style, code 72, default 1 */
void setTextLineStyle( const int l ) { linesty = l; }
std::string getText() const { return text; } /*!< Dimension text explicitly entered by the user, code 1 */
void setText( const std::string t ) { text = t; }
void setText( const std::string& t ) { text = t; }
double getTextLineFactor() const { return linefactor; } /*!< Dimension text line spacing factor, code 41, default 1? */
void setTextLineFactor( const double l ) { linefactor = l; }
double getDir() const { return rot; } /*!< rotation angle of the dimension text, code 53 (optional) default 0 */
void setDir( const double d ) { rot = d; }
DRW_Coord getExtrusion() { return extPoint; } /*!< extrusion, code 210, 220 & 230 */
void setExtrusion( const DRW_Coord p ) { extPoint = p; }
void setExtrusion( const DRW_Coord& p ) { extPoint = p; }
std::string getName() { return name; } /*!< Name of the block that contains the entities, code 2 */
void setName( const std::string s ) { name = s; }
void setName( const std::string& s ) { name = s; }
// int getType(){ return type;} /*!< Dimension type, code 70 */
protected:
DRW_Coord getPt2() const { return clonePoint; }
void setPt2( const DRW_Coord p ) { clonePoint = p; }
void setPt2( const DRW_Coord& p ) { clonePoint = p; }
DRW_Coord getPt3() const { return def1; }
void setPt3( const DRW_Coord p ) { def1 = p; }
void setPt3( const DRW_Coord& p ) { def1 = p; }
DRW_Coord getPt4() const { return def2; }
void setPt4( const DRW_Coord p ) { def2 = p; }
void setPt4( const DRW_Coord& p ) { def2 = p; }
DRW_Coord getPt5() const { return circlePoint; }
void setPt5( const DRW_Coord p ) { circlePoint = p; }
void setPt5( const DRW_Coord& p ) { circlePoint = p; }
DRW_Coord getPt6() const { return arcPoint; }
void setPt6( const DRW_Coord p ) { arcPoint = p; }
void setPt6( const DRW_Coord& p ) { arcPoint = p; }
double getAn50() const { return angle; } /*!< Angle of rotated, horizontal, or vertical dimensions, code 50 */
void setAn50( const double d ) { angle = d; }
double getOb52() const { return oblique; } /*!< oblique angle, code 52 */
void setOb52( const double d ) { oblique = d; }
double getRa40() const { return length; } /*!< Leader length, code 40 */
void setRa40( const double d ) { length = d; }
public:
int type; /*!< Dimension type, code 70 */
private:
std::string name; /*!< Name of the block that contains the entities, code 2 */
DRW_Coord defPoint; /*!< definition point, code 10, 20 & 30 (WCS) */
@ -1039,14 +1078,14 @@ public:
}
DRW_Coord getClonepoint() const { return getPt2(); } /*!< Insertion for clones (Baseline & Continue), 12, 22 & 32 */
void setClonePoint( DRW_Coord c ) { setPt2( c ); }
void setClonePoint( DRW_Coord& c ) { setPt2( c ); }
DRW_Coord getDimPoint() const { return getDefPoint(); } /*!< dim line location point, code 10, 20 & 30 */
void setDimPoint( const DRW_Coord p ) { setDefPoint( p ); }
void setDimPoint( const DRW_Coord& p ) { setDefPoint( p ); }
DRW_Coord getDef1Point() const { return getPt3(); } /*!< Definition point 1, code 13, 23 & 33 */
void setDef1Point( const DRW_Coord p ) { setPt3( p ); }
void setDef1Point( const DRW_Coord& p ) { setPt3( p ); }
DRW_Coord getDef2Point() const { return getPt4(); } /*!< Definition point 2, code 14, 24 & 34 */
void setDef2Point( const DRW_Coord p ) { setPt4( p ); }
void setDef2Point( const DRW_Coord& p ) { setPt4( p ); }
};
// ! Class to handle linear or rotated dimension entity
@ -1092,9 +1131,9 @@ public:
}
DRW_Coord getCenterPoint() const { return getDefPoint(); } /*!< center point, code 10, 20 & 30 */
void setCenterPoint( const DRW_Coord p ) { setDefPoint( p ); }
void setCenterPoint( const DRW_Coord& p ) { setDefPoint( p ); }
DRW_Coord getDiameterPoint() const { return getPt5(); } /*!< Definition point for radius, code 15, 25 & 35 */
void setDiameterPoint( const DRW_Coord p ) { setPt5( p ); }
void setDiameterPoint( const DRW_Coord& p ) { setPt5( p ); }
double getLeaderLength() const { return getRa40(); } /*!< Leader length, code 40 */
void setLeaderLength( const double d ) { setRa40( d ); }
};
@ -1118,9 +1157,9 @@ public:
}
DRW_Coord getDiameter1Point() const { return getPt5(); } /*!< First definition point for diameter, code 15, 25 & 35 */
void setDiameter1Point( const DRW_Coord p ) { setPt5( p ); }
void setDiameter1Point( const DRW_Coord& p ) { setPt5( p ); }
DRW_Coord getDiameter2Point() const { return getDefPoint(); } /*!< Oposite point for diameter, code 10, 20 & 30 */
void setDiameter2Point( const DRW_Coord p ) { setDefPoint( p ); }
void setDiameter2Point( const DRW_Coord& p ) { setDefPoint( p ); }
double getLeaderLength() const { return getRa40(); } /*!< Leader length, code 40 */
void setLeaderLength( const double d ) { setRa40( d ); }
};
@ -1144,15 +1183,15 @@ public:
}
DRW_Coord getFirstLine1() const { return getPt3(); } /*!< Definition point line 1-1, code 13, 23 & 33 */
void setFirstLine1( const DRW_Coord p ) { setPt3( p ); }
void setFirstLine1( const DRW_Coord& p ) { setPt3( p ); }
DRW_Coord getFirstLine2() const { return getPt4(); } /*!< Definition point line 1-2, code 14, 24 & 34 */
void setFirstLine2( const DRW_Coord p ) { setPt4( p ); }
void setFirstLine2( const DRW_Coord& p ) { setPt4( p ); }
DRW_Coord getSecondLine1() const { return getPt5(); } /*!< Definition point line 2-1, code 15, 25 & 35 */
void setSecondLine1( const DRW_Coord p ) { setPt5( p ); }
void setSecondLine1( const DRW_Coord& p ) { setPt5( p ); }
DRW_Coord getSecondLine2() const { return getDefPoint(); } /*!< Definition point line 2-2, code 10, 20 & 30 */
void setSecondLine2( const DRW_Coord p ) { setDefPoint( p ); }
void setSecondLine2( const DRW_Coord& p ) { setDefPoint( p ); }
DRW_Coord getDimPoint() const { return getPt6(); } /*!< Dimension definition point, code 16, 26 & 36 */
void setDimPoint( const DRW_Coord p ) { setPt6( p ); }
void setDimPoint( const DRW_Coord& p ) { setPt6( p ); }
};
@ -1175,13 +1214,13 @@ public:
}
DRW_Coord getFirstLine() const { return getPt3(); } /*!< Definition point line 1, code 13, 23 & 33 */
void setFirstLine( const DRW_Coord p ) { setPt3( p ); }
void setFirstLine( const DRW_Coord& p ) { setPt3( p ); }
DRW_Coord getSecondLine() const { return getPt4(); } /*!< Definition point line 2, code 14, 24 & 34 */
void setSecondLine( const DRW_Coord p ) { setPt4( p ); }
void setSecondLine( const DRW_Coord& p ) { setPt4( p ); }
DRW_Coord getVertexPoint() const { return getPt5(); } /*!< Vertex point, code 15, 25 & 35 */
void SetVertexPoint( const DRW_Coord p ) { setPt5( p ); }
void SetVertexPoint( const DRW_Coord& p ) { setPt5( p ); }
DRW_Coord getDimPoint() const { return getDefPoint(); } /*!< Dimension definition point, code 10, 20 & 30 */
void setDimPoint( const DRW_Coord p ) { setDefPoint( p ); }
void setDimPoint( const DRW_Coord& p ) { setDefPoint( p ); }
};
// ! Class to handle ordinate dimension entity
@ -1203,11 +1242,11 @@ public:
}
DRW_Coord getOriginPoint() const { return getDefPoint(); } /*!< Origin definition point, code 10, 20 & 30 */
void setOriginPoint( const DRW_Coord p ) { setDefPoint( p ); }
void setOriginPoint( const DRW_Coord& p ) { setDefPoint( p ); }
DRW_Coord getFirstLine() const { return getPt3(); } /*!< Feature location point, code 13, 23 & 33 */
void setFirstLine( const DRW_Coord p ) { setPt3( p ); }
void setFirstLine( const DRW_Coord& p ) { setPt3( p ); }
DRW_Coord getSecondLine() const { return getPt4(); } /*!< Leader end point, code 14, 24 & 34 */
void setSecondLine( const DRW_Coord p ) { setPt4( p ); }
void setSecondLine( const DRW_Coord& p ) { setPt4( p ); }
};
@ -1227,6 +1266,10 @@ public:
extrusionPoint.x = extrusionPoint.y = 0.0;
arrow = 1;
extrusionPoint.z = 1.0;
hookline = 0;
textheight = textwidth = 0.0;
coloruse = 0;
vertexpoint = NULL;
}
~DRW_Leader()
@ -1258,6 +1301,7 @@ public:
DRW_Coord offsettext; /*!< Offset of last leader vertex from annotation, code 213, 223 & 233 */
std::vector<DRW_Coord*> vertexlist; /*!< vertex points list, code 10, 20 & 30 */
private:
DRW_Coord* vertexpoint; /*!< current control point to add data */
};
@ -1273,7 +1317,7 @@ public:
DRW_Viewport()
{
eType = DRW::VIEWPORT;
vpstatus = 0;
vpID = vpstatus = 0;
pswidth = 205;
psheight = 156;
centerPX = 128.5;

View File

@ -57,6 +57,9 @@ public:
/** Called for every text style. */
virtual void addTextStyle( const DRW_Textstyle& data ) = 0;
/** Called for every AppId entry. */
virtual void addAppId( const DRW_AppId& data ) = 0;
/**
* Called for every block. Note: all entities added after this
* command go into this block until endBlock() is called.
@ -214,6 +217,7 @@ public:
virtual void writeTextstyles() = 0;
virtual void writeVports() = 0;
virtual void writeDimstyles() = 0;
virtual void writeAppId() = 0;
protected:
// DL_Attributes attributes;

View File

@ -41,6 +41,58 @@ void DRW_TableEntry::parseCode( int code, dxfReader* reader )
flags = reader->getInt32();
break;
case 1000:
case 1001:
case 1002:
case 1003:
case 1004:
case 1005:
extData.push_back( new DRW_Variant( code, reader->getString() ) );
break;
case 1010:
case 1011:
case 1012:
case 1013:
curr = new DRW_Variant();
curr->addCoord();
curr->setCoordX( reader->getDouble() );
curr->code = code;
extData.push_back( curr );
break;
case 1020:
case 1021:
case 1022:
case 1023:
if( curr )
curr->setCoordY( reader->getDouble() );
break;
case 1030:
case 1031:
case 1032:
case 1033:
if( curr )
curr->setCoordZ( reader->getDouble() );
curr = NULL;
break;
case 1040:
case 1041:
case 1042:
extData.push_back( new DRW_Variant( code, reader->getDouble() ) );
break;
case 1070:
case 1071:
extData.push_back( new DRW_Variant( code, reader->getInt32() ) );
break;
default:
break;
}
@ -747,7 +799,7 @@ void DRW_Header::parseCode( int code, dxfReader* reader )
break;
case 10:
curr->addCoord( new DRW_Coord() );
curr->addCoord();
curr->setCoordX( reader->getDouble() );
curr->code = code;
break;
@ -970,6 +1022,8 @@ void DRW_Header::write( dxfWriter* writer, DRW::Version ver )
writer->writeUtf8String( 7, varStr );
else
writer->writeString( 7, "STANDARD" );
@ -982,6 +1036,8 @@ void DRW_Header::write( dxfWriter* writer, DRW::Version ver )
writer->writeUtf8String( 8, varStr );
else
writer->writeString( 8, "0" );
@ -1082,6 +1138,8 @@ void DRW_Header::write( dxfWriter* writer, DRW::Version ver )
writer->writeUtf8String( 2, varStr );
else
writer->writeString( 2, "STANDARD" );
@ -1235,7 +1293,7 @@ void DRW_Header::write( dxfWriter* writer, DRW::Version ver )
#ifdef DRW_DBG
std::map<std::string, DRW_Variant*>::const_iterator it;
for( it = vars.begin(); it != vars.end(); it++ )
for( it = vars.begin(); it != vars.end(); ++it )
{
// QString key = QString::fromStdString((*it).first);
std::cerr << (*it).first << std::endl;
@ -1245,6 +1303,42 @@ void DRW_Header::write( dxfWriter* writer, DRW::Version ver )
}
void DRW_Header::addDouble( std::string key, double value, int code )
{
curr = new DRW_Variant();
curr->addDouble( value );
curr->code = code;
vars[key] = curr;
}
void DRW_Header::addInt( std::string key, int value, int code )
{
curr = new DRW_Variant();
curr->addInt( value );
curr->code = code;
vars[key] = curr;
}
void DRW_Header::addStr( std::string key, std::string value, int code )
{
curr = new DRW_Variant();
curr->addString( value );
curr->code = code;
vars[key] = curr;
}
void DRW_Header::addCoord( std::string key, DRW_Coord value, int code )
{
curr = new DRW_Variant();
curr->addCoord( value );
curr->code = code;
vars[key] = curr;
}
bool DRW_Header::getDouble( std::string key, double* varDouble )
{
bool result = false;

View File

@ -24,14 +24,16 @@ class dxfWriter;
namespace DRW {
// ! Table entries type.
enum TTYPE {
enum TTYPE
{
UNKNOWNT,
LTYPE,
LAYER,
STYLE,
DIMSTYLE,
VPORT,
BLOCK_RECORD
BLOCK_RECORD,
APPID
};
}
@ -48,18 +50,42 @@ public:
{
tType = DRW::UNKNOWNT;
flags = 0;
curr = NULL;
handle = 0;
handleBlock = 0;
}
virtual ~DRW_TableEntry()
{
for( std::vector<DRW_Variant*>::iterator it = extData.begin(); it!=extData.end(); ++it )
delete *it;
extData.clear();
}
virtual ~DRW_TableEntry() {}
protected:
void parseCode( int code, dxfReader* reader );
void reset()
{
flags = 0;
for( std::vector<DRW_Variant*>::iterator it = extData.begin(); it!=extData.end(); ++it )
delete *it;
extData.clear();
}
public:
enum DRW::TTYPE tType; /*!< enum: entity type, code 0 */
int handle; /*!< entity identifier, code 5 */
int handleBlock; /*!< Soft-pointer ID/handle to owner BLOCK_RECORD object, code 330 */
UTF8STRING name; /*!< entry name, code 2 */
int flags; /*!< Flags relevant to entry, code 70 */
std::vector<DRW_Variant*> extData; /*!< FIFO list of extended data, codes 1000 to 1071*/
private:
DRW_Variant* curr;
};
@ -96,6 +122,7 @@ public:
dimfit = dimatfit = 3;
dimdsep = '.';
dimlwd = dimlwe = -2;
DRW_TableEntry::reset();
}
void parseCode( int code, dxfReader* reader );
@ -190,10 +217,7 @@ public:
size = 0;
length = 0.0;
pathIdx = 0;
/* color = 256; // default BYLAYER (256)
* plotF = true; // default TRUE (plot yes)
* lWeight = -1; // default BYLAYER (-1)*/
// align = 65; //always 65
DRW_TableEntry::reset();
}
void parseCode( int code, dxfReader* reader );
@ -206,6 +230,7 @@ public:
double length; /*!< total length of pattern, code 40 */
// int haveShape; /*!< complex linetype type, code 74 */
std::vector<double> path; /*!< trace, point or space length sequence, code 49 */
private:
int pathIdx;
};
@ -229,6 +254,7 @@ public:
plotF = true; // default TRUE (plot yes)
lWeight = DRW_LW_Conv::widthDefault; // default BYDEFAULT (dxf -3, dwg 31)
color24 = -1; // default -1 not set
DRW_TableEntry::reset();
}
void parseCode( int code, dxfReader* reader );
@ -261,6 +287,7 @@ public:
font = "txt";
genFlag = 0; // 2= X mirror, 4= Y mirror
fontFamily = 0;
DRW_TableEntry::reset();
}
void parseCode( int code, dxfReader* reader );
@ -303,6 +330,7 @@ public:
circleZoom = 100;
ucsIcon = 3;
gridBehavior = 7;
DRW_TableEntry::reset();
}
void parseCode( int code, dxfReader* reader );
@ -352,6 +380,9 @@ public:
DRW_ImageDef()
{
version = 0;
u = v = up = vp = 0.0;
loaded = 0;
resolution = 0;
}
void parseCode( int code, dxfReader* reader );
@ -373,7 +404,9 @@ public:
// ! Class to handle header entries
/*!
* Class to handle layer symbol table entries
* Class to handle header vars, to read iterate over "std::map vars"
* to write add a DRW_Variant* into "std::map vars" (do not delete it, are cleared in dtor)
* or use add* helper functions.
* @author Rallaz
*/
class DRW_Header
@ -381,18 +414,29 @@ class DRW_Header
public:
DRW_Header()
{
version = 0;
curr = 0;
}
~DRW_Header()
{
for( std::map<std::string, DRW_Variant*>::iterator it = vars.begin(); it!=vars.end(); ++it )
delete it->second;
vars.clear();
}
void addDouble( std::string key, double value, int code );
void addInt( std::string key, int value, int code );
void addStr( std::string key, std::string value, int code );
void addCoord( std::string key, DRW_Coord value, int code );
std::string getComments() const { return comments; }
void parseCode( int code, dxfReader* reader );
void write( dxfWriter* writer, DRW::Version ver );
void addComment( std::string c );
std::string getComments() const { return comments; }
private:
bool getDouble( std::string key, double* varDouble );
bool getInt( std::string key, int* varInt );
@ -401,6 +445,7 @@ private:
public:
std::map<std::string, DRW_Variant*> vars;
private:
std::string comments;
std::string name;
@ -408,6 +453,26 @@ private:
int version; // to use on read
};
// ! Class to handle AppId entries
/*!
* Class to handle AppId symbol table entries
* @author Rallaz
*/
class DRW_AppId : public DRW_TableEntry
{
public:
DRW_AppId() { reset(); }
void reset()
{
tType = DRW::APPID;
flags = 0;
name = "";
}
void parseCode( int code, dxfReader* reader ) { DRW_TableEntry::parseCode( code, reader ); }
};
namespace DRW {
// Extended color palette:
// The first entry is only for direct indexing starting with [1]

View File

@ -127,8 +127,7 @@ std::string DRW_Converter::toUtf8( std::string* s )
if( c < 0x80 ) // ascii check for /U+????
{
if( c == '\\' && i + 6 < s->length() && s->at( i + 1 ) == 'U' && s->at( i + 2 ) ==
'+' )
if( c == '\\' && i + 6 < s->length() && s->at( i + 1 ) == 'U' && s->at( i + 2 ) == '+' )
{
result += s->substr( j, i - j );
result += encodeText( s->substr( i, 7 ) );
@ -204,7 +203,7 @@ std::string DRW_ConvTable::toUtf8( std::string* s )
std::string res;
std::string::iterator it;
for( it = s->begin(); it < s->end(); it++ )
for( it = s->begin(); it < s->end(); ++it )
{
unsigned char c = *it;
@ -395,7 +394,7 @@ std::string DRW_ConvDBCSTable::toUtf8( std::string* s )
std::string res;
std::string::iterator it;
for( it = s->begin(); it < s->end(); it++ )
for( it = s->begin(); it < s->end(); ++it )
{
bool notFound = true;
unsigned char c = *it;
@ -516,7 +515,7 @@ std::string DRW_Conv932Table::toUtf8( std::string* s )
std::string res;
std::string::iterator it;
for( it = s->begin(); it < s->end(); it++ )
for( it = s->begin(); it < s->end(); ++it )
{
bool notFound = true;
unsigned char c = *it;
@ -661,7 +660,7 @@ std::string DRW_TextCodec::correctCodePage( const std::string& s )
}
else if( cp=="ANSI_936" || cp=="GBK" || cp=="GB2312" || cp=="CHINESE" || cp=="CN-GB"
|| cp=="CSGB2312" || cp=="CSGB231280" || cp=="CSISO58BG231280"
|| cp=="GB_2312-80" || cp=="GB231280" || cp=="GB2312-80" || cp=="GBK"
|| cp=="GB_2312-80" || cp=="GB231280" || cp=="GB2312-80"
|| cp=="ISO-IR-58" || cp=="GB18030" )
{
return "ANSI_936";

View File

@ -21,6 +21,7 @@ public:
void setCodePage( std::string c ) { setCodePage( &c ); }
std::string getCodePage() { return cp; }
private:
std::string correctCodePage( const std::string& s );

View File

@ -21,6 +21,9 @@ public:
dxfReader( std::ifstream* stream )
{
filestr = stream;
doubleData = 0.0;
intData = 0;
int64 = 0;
#ifdef DRW_DBG
count = 0;
#endif
@ -53,12 +56,14 @@ public:
#ifdef DRW_DBG
int count; // DBG
#endif
protected:
std::ifstream* filestr;
std::string strData;
double doubleData;
signed int intData; // 32 bits integer
unsigned long long int int64; // 64 bits integer
private:
DRW_TextCodec decoder;
};
@ -66,7 +71,7 @@ private:
class dxfReaderBinary : public dxfReader
{
public:
dxfReaderBinary( std::ifstream* stream ) : dxfReader( stream ) { }
dxfReaderBinary( std::ifstream* stream ) : dxfReader( stream ) {}
virtual ~dxfReaderBinary() {}
virtual bool readCode( int* code );
virtual bool readString( std::string* text );
@ -81,7 +86,7 @@ public:
class dxfReaderAscii : public dxfReader
{
public:
dxfReaderAscii( std::ifstream* stream ) : dxfReader( stream ) { }
dxfReaderAscii( std::ifstream* stream ) : dxfReader( stream ) {}
virtual ~dxfReaderAscii() {}
virtual bool readCode( int* code );
virtual bool readString( std::string* text );

View File

@ -34,8 +34,10 @@ public:
void setVersion( std::string* v ) { encoder.setVersion( v ); }
void setCodePage( std::string* c ) { encoder.setCodePage( c ); }
std::string getCodePage() { return encoder.getCodePage(); }
protected:
std::ofstream* filestr;
private:
DRW_TextCodec encoder;
};
@ -43,7 +45,7 @@ private:
class dxfWriterBinary : public dxfWriter
{
public:
dxfWriterBinary( std::ofstream* stream ) : dxfWriter( stream ) { }
dxfWriterBinary( std::ofstream* stream ) : dxfWriter( stream ) {}
virtual ~dxfWriterBinary() {}
virtual bool writeString( int code, std::string text );
virtual bool writeInt16( int code, int data );
@ -56,7 +58,7 @@ public:
class dxfWriterAscii : public dxfWriter
{
public:
dxfWriterAscii( std::ofstream* stream ) : dxfWriter( stream ) { }
dxfWriterAscii( std::ofstream* stream ) : dxfWriter( stream ) {}
virtual ~dxfWriterAscii() {}
virtual bool writeString( int code, std::string text );
virtual bool writeInt16( int code, int data );

View File

@ -45,6 +45,14 @@ dxfRW::dxfRW( const char* name )
writer = NULL;
applyExt = false;
elParts = 128; // parts munber when convert ellipse to polyline
binary = false;
iface = NULL;
entCount = 0;
wlayer0 = false;
dimstyleStd = false;
writingBlock = false;
currHandle = 0;
}
@ -52,6 +60,14 @@ dxfRW::~dxfRW()
{
if( reader != NULL )
delete reader;
if( writer != NULL )
delete writer;
for( std::vector<DRW_ImageDef*>::iterator it = imageDef.begin(); it!=imageDef.end(); ++it )
delete *it;
imageDef.clear();
}
@ -322,6 +338,11 @@ bool dxfRW::writeLayer( DRW_Layer* ent )
else
writer->writeUtf8Caps( 6, ent->lineType );
if( !ent->extData.empty() )
{
writeExtData( ent->extData );
}
// writer->writeString(347, "10012");
return true;
}
@ -638,6 +659,33 @@ bool dxfRW::writeDimstyle( DRW_Dimstyle* ent )
}
bool dxfRW::writeAppId( DRW_AppId* ent )
{
writer->writeString( 0, "APPID" );
if( version > DRW::AC1009 )
{
writer->writeString( 5, toHexStr( ++entCount ) );
if( version > DRW::AC1014 )
{
writer->writeString( 330, "9" );
}
writer->writeString( 100, "AcDbSymbolTableRecord" );
writer->writeString( 100, "AcDbRegAppTableRecord" );
writer->writeUtf8String( 2, ent->name );
}
else
{
writer->writeUtf8Caps( 2, ent->name );
}
writer->writeInt16( 70, ent->flags );
return true;
}
bool dxfRW::writePoint( DRW_Point* ent )
{
writer->writeString( 0, "POINT" );
@ -2045,6 +2093,7 @@ bool dxfRW::writeTables()
writer->writeString( 2, "ACAD" );
writer->writeInt16( 70, 0 );
iface->writeAppId();
writer->writeString( 0, "ENDTAB" );
writer->writeString( 0, "TABLE" );
@ -2324,7 +2373,7 @@ bool dxfRW::writeObjects()
DRW_ImageDef* id = imageDef.at( i );
std::map<std::string, std::string>::iterator it;
for( it = id->reactors.begin(); it != id->reactors.end(); it++ )
for( it = id->reactors.begin(); it != id->reactors.end(); ++it )
{
writer->writeString( 0, "IMAGEDEF_REACTOR" );
writer->writeString( 5, (*it).first );
@ -2368,7 +2417,7 @@ bool dxfRW::writeObjects()
writer->writeString( 102, "{ACAD_REACTORS" );
std::map<std::string, std::string>::iterator it;
for( it = id->reactors.begin(); it != id->reactors.end(); it++ )
for( it = id->reactors.begin(); it != id->reactors.end(); ++it )
{
writer->writeString( 330, (*it).first );
}
@ -2395,6 +2444,74 @@ bool dxfRW::writeObjects()
}
bool dxfRW::writeExtData( const std::vector<DRW_Variant*>& ed )
{
for( std::vector<DRW_Variant*>::const_iterator it = ed.begin(); it!=ed.end(); ++it )
{
switch( (*it)->code )
{
case 1000:
case 1001:
case 1002:
case 1003:
case 1004:
case 1005:
{
int cc = (*it)->code;
if( (*it)->type == DRW_Variant::STRING )
writer->writeUtf8String( cc, *(*it)->content.s );
// writer->writeUtf8String((*it)->code, (*it)->content.s);
break;
}
case 1010:
case 1011:
case 1012:
case 1013:
if( (*it)->type == DRW_Variant::COORD )
{
writer->writeDouble( (*it)->code, (*it)->content.v->x );
writer->writeDouble( (*it)->code + 10, (*it)->content.v->y );
writer->writeDouble( (*it)->code + 20, (*it)->content.v->z );
}
break;
case 1040:
case 1041:
case 1042:
if( (*it)->type == DRW_Variant::DOUBLE )
writer->writeDouble( (*it)->code, (*it)->content.d );
break;
case 1070:
if( (*it)->type == DRW_Variant::INTEGER )
writer->writeInt16( (*it)->code, (*it)->content.i );
break;
case 1071:
if( (*it)->type == DRW_Variant::INTEGER )
writer->writeInt32( (*it)->code, (*it)->content.i );
break;
default:
break;
}
}
return true;
}
/********* Reader Process *********/
bool dxfRW::processDxf()
@ -2562,7 +2679,7 @@ bool dxfRW::processTables()
}
else if( sectionstr == "APPID" )
{
// processAppId();
processAppId();
}
else if( sectionstr == "DIMSTYLE" )
{
@ -2778,6 +2895,44 @@ bool dxfRW::processVports()
}
bool dxfRW::processAppId()
{
DBG( "dxfRW::processAppId" );
int code;
std::string sectionstr;
bool reading = false;
DRW_AppId vp;
while( reader->readRec( &code, !binary ) )
{
DBG( code ); DBG( "\n" );
if( code == 0 )
{
if( reading )
iface->addAppId( vp );
sectionstr = reader->getString();
DBG( sectionstr ); DBG( "\n" );
if( sectionstr == "APPID" )
{
reading = true;
vp.reset();
}
else if( sectionstr == "ENDTAB" )
{
return true; // found ENDTAB terminate
}
}
else if( reading )
vp.parseCode( code, reader );
}
return true;
}
/********* Block Section *********/
bool dxfRW::processBlocks()

View File

@ -45,6 +45,7 @@ public:
bool writeDimstyle( DRW_Dimstyle* ent );
bool writeTextstyle( DRW_Textstyle* ent );
bool writeVport( DRW_Vport* ent );
bool writeAppId( DRW_AppId* ent );
bool writePoint( DRW_Point* ent );
bool writeLine( DRW_Line* ent );
bool writeRay( DRW_Ray* ent );
@ -70,6 +71,7 @@ public:
bool writeDimension( DRW_Dimension* ent );
void setEllipseParts( int parts ) { elParts = parts; } /*!< set parts munber when convert ellipse to polyline */
private:
/// used by read() to parse the content of the file
bool processDxf();
@ -85,6 +87,7 @@ private:
bool processDimStyle();
bool processTextStyle();
bool processVports();
bool processAppId();
bool processPoint();
bool processLine();
@ -115,6 +118,7 @@ private:
bool writeTables();
bool writeBlocks();
bool writeObjects();
bool writeExtData( const std::vector<DRW_Variant*>& ed );
std::string toHexStr( int n );
private:

View File

@ -165,6 +165,9 @@ private:
void writeLine();
void writeMtext();
virtual void addAppId( const DRW_AppId& data ) {}
virtual void writeAppId() {}
};
#endif // FILTERDXFRW_H

View File

@ -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