dxf import: minor enhancements in dialog. Update libdfxw from git, and uncrustify it. add a test dfx file

This commit is contained in:
jean-pierre charras 2013-10-28 09:06:38 +01:00
parent f0b2565f12
commit 3e3869ed80
14 changed files with 8541 additions and 884 deletions

View File

@ -18,8 +18,6 @@
#include <string>
#include <cmath>
using std::string;
#define UTF8STRING std::string
#define DRW_UNUSED( x ) (void) x
@ -203,7 +201,7 @@ public:
// string codepage;
private:
// DRW_VarContent content;
string data;
std::string data;
};

View File

@ -21,8 +21,6 @@
class dxfReader;
class DRW_Polyline;
using std::string;
namespace DRW {
// ! Entity's type.
enum ETYPE {
@ -123,7 +121,7 @@ public:
double ltypeScale; /*!< linetype scale, code 48 */
bool visible; /*!< entity visibility, code 60 */
int color24; /*!< 24-bit color, code 420 */
string colorName; /*!< color name, code 430 */
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*/
private:
@ -891,17 +889,17 @@ public:
void parseCode( int code, dxfReader* reader );
public:
string ref; /*!< Hard reference to imagedef object, code 340 */
double vx; /*!< V-vector of single pixel, x coordinate, code 12 */
double vy; /*!< V-vector of single pixel, y coordinate, code 22 */
double vz; /*!< V-vector of single pixel, z coordinate, code 32 */
double sizeu; /*!< image size in pixels, U value, code 13 */
double sizev; /*!< image size in pixels, V value, code 23 */
double dz; /*!< z coordinate, code 33 */
int clip; /*!< Clipping state, code 280, 0=off 1=on */
int brightness; /*!< Brightness value, code 281, (0-100) default 50 */
int contrast; /*!< Brightness value, code 282, (0-100) default 50 */
int fade; /*!< Brightness value, code 283, (0-100) default 0 */
std::string ref; /*!< Hard reference to imagedef object, code 340 */
double vx; /*!< V-vector of single pixel, x coordinate, code 12 */
double vy; /*!< V-vector of single pixel, y coordinate, code 22 */
double vz; /*!< V-vector of single pixel, z coordinate, code 32 */
double sizeu; /*!< image size in pixels, U value, code 13 */
double sizev; /*!< image size in pixels, V value, code 23 */
double dz; /*!< z coordinate, code 33 */
int clip; /*!< Clipping state, code 280, 0=off 1=on */
int brightness; /*!< Brightness value, code 281, (0-100) default 50 */
int contrast; /*!< Brightness value, code 282, (0-100) default 50 */
int fade; /*!< Brightness value, code 283, (0-100) default 0 */
};
@ -960,14 +958,14 @@ public:
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; }
string getStyle() const { return style; } /*!< Dimension style, code 3 */
void setStyle( const string s ) { style = s; }
std::string getStyle() const { return style; } /*!< Dimension style, code 3 */
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; }
string getText() const { return text; } /*!< Dimension text explicitly entered by the user, code 1 */
void setText( const string t ) { text = t; }
std::string getText() const { return text; } /*!< Dimension text explicitly entered by the user, code 1 */
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 */
@ -975,8 +973,8 @@ public:
DRW_Coord getExtrusion() { return extPoint; } /*!< extrusion, code 210, 220 & 230 */
void setExtrusion( const DRW_Coord p ) { extPoint = p; }
string getName() { return name; } /*!< Name of the block that contains the entities, code 2 */
void setName( const string s ) { name = s; }
std::string getName() { return name; } /*!< Name of the block that contains the entities, code 2 */
void setName( const std::string s ) { name = s; }
// int getType(){ return type;} /*!< Dimension type, code 70 */
protected:
DRW_Coord getPt2() const { return clonePoint; }
@ -998,7 +996,7 @@ protected:
public:
int type; /*!< Dimension type, code 70 */
private:
string name; /*!< Name of the block that contains the entities, code 2 */
std::string name; /*!< Name of the block that contains the entities, code 2 */
DRW_Coord defPoint; /*!< definition point, code 10, 20 & 30 (WCS) */
DRW_Coord textPoint; /*!< Middle point of text, code 11, 21 & 31 (OCS) */
UTF8STRING text; /*!< Dimension text explicitly entered by the user, code 1 */
@ -1243,25 +1241,25 @@ public:
void parseCode( int code, dxfReader* reader );
public:
UTF8STRING style; /*!< Dimension style name, code 3 */
int arrow; /*!< Arrowhead flag, code 71, 0=Disabled; 1=Enabled */
int leadertype; /*!< Leader path type, code 72, 0=Straight line segments; 1=Spline */
int flag; /*!< Leader creation flag, code 73, default 3 */
int hookline; /*!< Hook line direction flag, code 74, default 1 */
int hookflag; /*!< Hook line flag, code 75 */
double textheight; /*!< Text annotation height, code 40 */
double textwidth; /*!< Text annotation width, code 41 */
int vertnum; /*!< Number of vertices, code 76 */
int coloruse; /*!< Color to use if leader's DIMCLRD = BYBLOCK, code 77 */
string handle; /*!< Hard reference to associated annotation, code 340 */
DRW_Coord extrusionPoint; /*!< Normal vector, code 210, 220 & 230 */
DRW_Coord horizdir; /*!< "Horizontal" direction for leader, code 211, 221 & 231 */
DRW_Coord offsetblock; /*!< Offset of last leader vertex from block, code 212, 222 & 232 */
DRW_Coord offsettext; /*!< Offset of last leader vertex from annotation, code 213, 223 & 233 */
UTF8STRING style; /*!< Dimension style name, code 3 */
int arrow; /*!< Arrowhead flag, code 71, 0=Disabled; 1=Enabled */
int leadertype; /*!< Leader path type, code 72, 0=Straight line segments; 1=Spline */
int flag; /*!< Leader creation flag, code 73, default 3 */
int hookline; /*!< Hook line direction flag, code 74, default 1 */
int hookflag; /*!< Hook line flag, code 75 */
double textheight; /*!< Text annotation height, code 40 */
double textwidth; /*!< Text annotation width, code 41 */
int vertnum; /*!< Number of vertices, code 76 */
int coloruse; /*!< Color to use if leader's DIMCLRD = BYBLOCK, code 77 */
std::string handle; /*!< Hard reference to associated annotation, code 340 */
DRW_Coord extrusionPoint; /*!< Normal vector, code 210, 220 & 230 */
DRW_Coord horizdir; /*!< "Horizontal" direction for leader, code 211, 221 & 231 */
DRW_Coord offsetblock; /*!< Offset of last leader vertex from block, code 212, 222 & 232 */
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 */
std::vector<DRW_Coord*> vertexlist; /*!< vertex points list, code 10, 20 & 30 */
private:
DRW_Coord* vertexpoint; /*!< current control point to add data */
DRW_Coord* vertexpoint; /*!< current control point to add data */
};
// ! Class to handle viewport entity

View File

@ -679,7 +679,7 @@ void DRW_ImageDef::parseCode( int code, dxfReader* reader )
}
void DRW_Header::addComment( string c )
void DRW_Header::addComment( std::string c )
{
if( !comments.empty() )
comments += '\n';
@ -858,6 +858,9 @@ void DRW_Header::write( dxfWriter* writer, DRW::Version ver )
writer->writeString( 1, varStr );
writer->setVersion( &varStr );
getStr( "$ACADVER", &varStr );
getStr( "$ACADMAINTVER", &varStr );
if( ver > DRW::AC1012 )
{
writer->writeString( 9, "$HANDSEED" );
@ -970,6 +973,18 @@ void DRW_Header::write( dxfWriter* writer, DRW::Version ver )
else
writer->writeString( 7, "STANDARD" );
writer->writeString( 9, "$CLAYER" );
if( getStr( "$CLAYER", &varStr ) )
if( ver == DRW::AC1009 )
writer->writeUtf8Caps( 8, varStr );
else
writer->writeUtf8String( 8, varStr );
else
writer->writeString( 8, "0" );
writer->writeString( 9, "$DIMASZ" );
if( getDouble( "$DIMASZ", &varDouble ) )
@ -977,6 +992,13 @@ void DRW_Header::write( dxfWriter* writer, DRW::Version ver )
else
writer->writeDouble( 40, 2.5 );
writer->writeString( 9, "$DIMLFAC" );
if( getDouble( "$DIMLFAC", &varDouble ) )
writer->writeDouble( 40, varDouble );
else
writer->writeDouble( 40, 1.0 );
writer->writeString( 9, "$DIMSCALE" );
if( getDouble( "$DIMSCALE", &varDouble ) )
@ -1210,16 +1232,20 @@ void DRW_Header::write( dxfWriter* writer, DRW::Version ver )
writer->writeDouble( 40, 0.0 );
}
#ifdef DRW_DBG
std::map<std::string, DRW_Variant*>::const_iterator it;
for( it = vars.begin(); it != vars.end(); it++ )
{
// QString key = QString::fromStdString((*it).first);
std::cerr << (*it).first << std::endl;
}
#endif
}
bool DRW_Header::getDouble( string key, double* varDouble )
bool DRW_Header::getDouble( std::string key, double* varDouble )
{
bool result = false;
std::map<std::string, DRW_Variant*>::iterator it;
@ -1243,7 +1269,7 @@ bool DRW_Header::getDouble( string key, double* varDouble )
}
bool DRW_Header::getInt( string key, int* varInt )
bool DRW_Header::getInt( std::string key, int* varInt )
{
bool result = false;
std::map<std::string, DRW_Variant*>::iterator it;
@ -1267,7 +1293,7 @@ bool DRW_Header::getInt( string key, int* varInt )
}
bool DRW_Header::getStr( string key, std::string* varStr )
bool DRW_Header::getStr( std::string key, std::string* varStr )
{
bool result = false;
std::map<std::string, DRW_Variant*>::iterator it;
@ -1291,7 +1317,7 @@ bool DRW_Header::getStr( string key, std::string* varStr )
}
bool DRW_Header::getCoord( string key, DRW_Coord* varCoord )
bool DRW_Header::getCoord( std::string key, DRW_Coord* varCoord )
{
bool result = false;
std::map<std::string, DRW_Variant*>::iterator it;

View File

@ -22,8 +22,6 @@
class dxfReader;
class dxfWriter;
using std::string;
namespace DRW {
// ! Table entries type.
enum TTYPE {
@ -241,8 +239,8 @@ public:
int color24; /*!< 24-bit color, code 420 */
bool plotF; /*!< Plot flag, code 290 */
enum DRW_LW_Conv::lineWidth lWeight; /*!< layer lineweight, code 370 */
string handlePlotS; /*!< Hard-pointer ID/handle of plotstyle, code 390 */
string handlePlotM; /*!< Hard-pointer ID/handle of materialstyle, code 347 */
std::string handlePlotS; /*!< Hard-pointer ID/handle of plotstyle, code 390 */
std::string handlePlotM; /*!< Hard-pointer ID/handle of materialstyle, code 347 */
};
// ! Class to handle text style entries
@ -359,7 +357,7 @@ public:
void parseCode( int code, dxfReader* reader );
public:
string handle; /*!< entity identifier, code 5 */
std::string handle; /*!< entity identifier, code 5 */
UTF8STRING name; /*!< File name of image, code 1 */
int version; /*!< class version, code 90, 0=R14 version */
double u; /*!< image size in pixels U value, code 10 */
@ -369,7 +367,7 @@ public:
int loaded; /*!< image is loaded flag, code 280, 0=unloaded, 1=loaded */
int resolution; /*!< resolution units, code 281, 0=no, 2=centimeters, 5=inch */
std::map<string, string> reactors;
std::map<std::string, std::string> reactors;
};
@ -392,20 +390,20 @@ public:
void parseCode( int code, dxfReader* reader );
void write( dxfWriter* writer, DRW::Version ver );
void addComment( string c );
void addComment( std::string c );
string getComments() const { return comments; }
std::string getComments() const { return comments; }
private:
bool getDouble( string key, double* varDouble );
bool getInt( string key, int* varInt );
bool getStr( string key, string* varStr );
bool getCoord( string key, DRW_Coord* varStr );
bool getDouble( std::string key, double* varDouble );
bool getInt( std::string key, int* varInt );
bool getStr( std::string key, std::string* varStr );
bool getCoord( std::string key, DRW_Coord* varStr );
public:
std::map<string, DRW_Variant*> vars;
std::map<std::string, DRW_Variant*> vars;
private:
string comments;
string name;
std::string comments;
std::string name;
DRW_Variant* curr;
int version; // to use on read
};

File diff suppressed because it is too large Load Diff

View File

@ -10,75 +10,89 @@ class DRW_TextCodec
public:
DRW_TextCodec();
~DRW_TextCodec();
std::string fromUtf8(std::string s);
std::string toUtf8(std::string s);
int getVersion(){return version;}
void setVersion(std::string *v);
void setVersion(int v){version = v;}
void setCodePage(std::string *c);
void setCodePage(std::string c){setCodePage(&c);}
std::string getCodePage(){return cp;}
std::string fromUtf8( std::string s );
std::string toUtf8( std::string s );
int getVersion() { return version; }
void setVersion( std::string* v );
void setVersion( int v ) { version = v; }
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:
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
{
public:
DRW_Converter(const int *t, int l){table = t;
cpLenght = l;}
virtual ~DRW_Converter(){}
virtual std::string fromUtf8(std::string *s) {return *s;}
virtual std::string toUtf8(std::string *s);
std::string encodeText(std::string stmp);
std::string decodeText(int c);
std::string encodeNum(int c);
int decodeNum(std::string s, int *b);
const int *table;
int cpLenght;
DRW_Converter( const int* t, int l )
{
table = t;
cpLenght = l;
}
virtual ~DRW_Converter() {}
virtual std::string fromUtf8( std::string* s ) { return *s; }
virtual std::string toUtf8( std::string* s );
std::string encodeText( std::string stmp );
std::string decodeText( int c );
std::string encodeNum( int c );
int decodeNum( std::string s, int* b );
const int* table;
int cpLenght;
};
class DRW_ConvTable : public DRW_Converter {
class DRW_ConvTable : public DRW_Converter
{
public:
DRW_ConvTable(const int *t, int l):DRW_Converter(t, l) {}
virtual std::string fromUtf8(std::string *s);
virtual std::string toUtf8(std::string *s);
DRW_ConvTable( const int* t, int l ) : DRW_Converter( t, l ) {}
virtual std::string fromUtf8( std::string* s );
virtual std::string toUtf8( std::string* s );
};
class DRW_ConvDBCSTable : public DRW_Converter {
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) {
leadTable = lt;
DRW_ConvDBCSTable( const int* t, const int* lt, const int dt[][2], int l ) : DRW_Converter( t,
l )
{
leadTable = lt;
doubleTable = dt;
}
virtual std::string fromUtf8(std::string *s);
virtual std::string toUtf8(std::string *s);
private:
const int *leadTable;
const int (*doubleTable)[2];
virtual std::string fromUtf8( std::string* s );
virtual std::string toUtf8( std::string* s );
private:
const int* leadTable;
const int (*doubleTable)[2];
};
class DRW_Conv932Table : public DRW_Converter {
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) {
leadTable = lt;
DRW_Conv932Table( const int* t, const int* lt, const int dt[][2], int l ) : DRW_Converter( t,
l )
{
leadTable = lt;
doubleTable = dt;
}
virtual std::string fromUtf8(std::string *s);
virtual std::string toUtf8(std::string *s);
private:
const int *leadTable;
const int (*doubleTable)[2];
virtual std::string fromUtf8( std::string* s );
virtual std::string toUtf8( std::string* s );
private:
const int* leadTable;
const int (*doubleTable)[2];
};
#endif // DRW_TEXTCODEC_H
#endif // DRW_TEXTCODEC_H

View File

@ -18,246 +18,316 @@
#include "drw_textcodec.h"
#ifdef DRW_DBG
#include <iostream> //for debug
#define DBG(a) std::cerr << a
#include <iostream> // for debug
#define DBG( a ) std::cerr << a
#else
#define DBG(a)
#define DBG( a )
#endif
bool dxfReader::readRec(int *codeData, bool skip) {
// std::string text;
bool dxfReader::readRec( int* codeData, bool skip )
{
// std::string text;
int code;
#ifdef DRW_DBG
count = count+2; //DBG
count = count + 2; // DBG
/* if (count > 10250)
DBG("line 10256");*/
* DBG("line 10256");*/
#endif
if (!readCode(&code))
if( !readCode( &code ) )
return false;
*codeData = code;
if (code < 10)
if( code < 10 )
readString();
else if (code < 60)
else if( code < 60 )
readDouble();
else if (code < 80)
else if( code < 80 )
readInt();
else if (code > 89 && code < 100) //TODO this is an int 32b
else if( code > 89 && code < 100 ) // TODO this is an int 32b
readInt32();
else if (code == 100 || code == 102 || code == 105)
else if( code == 100 || code == 102 || code == 105 )
readString();
else if (code > 109 && code < 150) //skip not used at the v2012
else if( code > 109 && code < 150 ) // skip not used at the v2012
readDouble();
else if (code > 159 && code < 170) //skip not used at the v2012
else if( code > 159 && code < 170 ) // skip not used at the v2012
readInt64();
else if (code < 180)
else if( code < 180 )
readInt();
else if (code > 209 && code < 240) //skip not used at the v2012
else if( code > 209 && code < 240 ) // skip not used at the v2012
readDouble();
else if (code > 269 && code < 290) //skip not used at the v2012
else if( code > 269 && code < 290 ) // skip not used at the v2012
readInt();
else if (code < 300) //TODO this is a boolean indicator, int in Binary?
else if( code < 300 ) // TODO this is a boolean indicator, int in Binary?
readBool();
else if (code < 370)
else if( code < 370 )
readString();
else if (code < 390)
else if( code < 390 )
readInt();
else if (code < 400)
else if( code < 400 )
readString();
else if (code < 410)
else if( code < 410 )
readInt();
else if (code < 420)
else if( code < 420 )
readString();
else if (code < 430) //TODO this is an int 32b
else if( code < 430 ) // TODO this is an int 32b
readInt32();
else if (code < 440)
else if( code < 440 )
readString();
else if (code < 450) //TODO this is an int 32b
else if( code < 450 ) // TODO this is an int 32b
readInt32();
else if (code < 460) //TODO this is long??
else if( code < 460 ) // TODO this is long??
readInt();
else if (code < 470) //TODO this is a floating point double precision??
else if( code < 470 ) // TODO this is a floating point double precision??
readDouble();
else if (code < 481)
else if( code < 481 )
readString();
else if (code > 998 && code < 1009) //skip not used at the v2012
else if( code > 998 && code < 1009 ) // skip not used at the v2012
readString();
else if (code < 1060) //TODO this is a floating point double precision??
else if( code < 1060 ) // TODO this is a floating point double precision??
readDouble();
else if (code < 1071)
else if( code < 1071 )
readInt();
else if (code == 1071) //TODO this is an int 32b
else if( code == 1071 ) // TODO this is an int 32b
readInt32();
else if (skip)
//skip safely this dxf entry ( ok for ascii dxf)
else if( skip )
// skip safely this dxf entry ( ok for ascii dxf)
readString();
else
//break in binary files because the conduct is unpredictable
// break in binary files because the conduct is unpredictable
return false;
return (filestr->good());
return filestr->good();
}
int dxfReader::getHandleString(){
int dxfReader::getHandleString()
{
int res;
#if defined(__APPLE__)
int Succeeded = sscanf ( strData.c_str(), "%x", &res );
if ( !Succeeded || Succeeded == EOF )
int Succeeded = sscanf( strData.c_str(), "%x", &res );
if( !Succeeded || Succeeded == EOF )
res = 0;
#else
std::istringstream Convert(strData);
if ( !(Convert >> std::hex >>res) )
std::istringstream Convert( strData );
if( !(Convert >> std::hex >> res) )
res = 0;
#endif
return res;
}
bool dxfReaderBinary::readCode(int *code) {
unsigned short *int16p;
char buffer[2];
filestr->read(buffer,2);
int16p = (unsigned short *) buffer;
//exist a 32bits int (code 90) with 2 bytes???
if ((*code == 90) && (*int16p>2000)){
DBG(*code); DBG(" de 16bits\n");
filestr->seekg(-4, std::ios_base::cur);
filestr->read(buffer,2);
int16p = (unsigned short *) buffer;
bool dxfReaderBinary::readCode( int* code )
{
unsigned short* int16p;
char buffer[2];
filestr->read( buffer, 2 );
int16p = (unsigned short*) buffer;
// exist a 32bits int (code 90) with 2 bytes???
if( (*code == 90) && (*int16p>2000) )
{
DBG( *code ); DBG( " de 16bits\n" );
filestr->seekg( -4, std::ios_base::cur );
filestr->read( buffer, 2 );
int16p = (unsigned short*) buffer;
}
*code = *int16p;
DBG(*code); DBG("\n");
DBG( *code ); DBG( "\n" );
return (filestr->good());
return filestr->good();
}
bool dxfReaderBinary::readString() {
std::getline(*filestr, strData, '\0');
DBG(strData); DBG("\n");
return (filestr->good());
bool dxfReaderBinary::readString()
{
std::getline( *filestr, strData, '\0' );
DBG( strData ); DBG( "\n" );
return filestr->good();
}
bool dxfReaderBinary::readString(std::string *text) {
std::getline(*filestr, *text, '\0');
DBG(*text); DBG("\n");
return (filestr->good());
bool dxfReaderBinary::readString( std::string* text )
{
std::getline( *filestr, *text, '\0' );
DBG( *text ); DBG( "\n" );
return filestr->good();
}
bool dxfReaderBinary::readInt() {
bool dxfReaderBinary::readInt()
{
char buffer[2];
filestr->read(buffer,2);
intData = (int)((buffer[1] << 8) | buffer[0]);
DBG(intData); DBG("\n");
return (filestr->good());
filestr->read( buffer, 2 );
intData = (int) ( (buffer[1] << 8) | buffer[0] );
DBG( intData ); DBG( "\n" );
return filestr->good();
}
bool dxfReaderBinary::readInt32() {
unsigned int *int32p;
char buffer[4];
filestr->read(buffer,4);
int32p = (unsigned int *) buffer;
bool dxfReaderBinary::readInt32()
{
unsigned int* int32p;
char buffer[4];
filestr->read( buffer, 4 );
int32p = (unsigned int*) buffer;
intData = *int32p;
DBG(intData); DBG("\n");
return (filestr->good());
DBG( intData ); DBG( "\n" );
return filestr->good();
}
bool dxfReaderBinary::readInt64() {
unsigned long long int *int64p; //64 bits integer pointer
bool dxfReaderBinary::readInt64()
{
unsigned long long int* int64p; // 64 bits integer pointer
char buffer[8];
filestr->read(buffer,8);
int64p = (unsigned long long int *) buffer;
int64 = *int64p;
DBG(int64); DBG(" int64\n");
return (filestr->good());
filestr->read( buffer, 8 );
int64p = (unsigned long long int*) buffer;
int64 = *int64p;
DBG( int64 ); DBG( " int64\n" );
return filestr->good();
}
bool dxfReaderBinary::readDouble() {
double *result;
char buffer[8];
filestr->read(buffer,8);
result = (double *) buffer;
doubleData = *result;
DBG(doubleData); DBG("\n");
return (filestr->good());
bool dxfReaderBinary::readDouble()
{
double* result;
char buffer[8];
filestr->read( buffer, 8 );
result = (double*) buffer;
doubleData = *result;
DBG( doubleData ); DBG( "\n" );
return filestr->good();
}
//saved as int or add a bool member??
bool dxfReaderBinary::readBool() {
// saved as int or add a bool member??
bool dxfReaderBinary::readBool()
{
char buffer[1];
filestr->read(buffer,1);
intData = (int)(buffer[0]);
DBG(intData); DBG("\n");
return (filestr->good());
filestr->read( buffer, 1 );
intData = (int) (buffer[0]);
DBG( intData ); DBG( "\n" );
return filestr->good();
}
bool dxfReaderAscii::readCode(int *code) {
bool dxfReaderAscii::readCode( int* code )
{
std::string text;
std::getline(*filestr, text);
*code = atoi(text.c_str());
DBG(*code); DBG("\n");
return (filestr->good());
}
bool dxfReaderAscii::readString(std::string *text) {
std::getline(*filestr, *text);
if (!text->empty() && text->at(text->size()-1) == '\r')
text->erase(text->size()-1);
return (filestr->good());
std::getline( *filestr, text );
*code = atoi( text.c_str() );
DBG( *code ); DBG( "\n" );
return filestr->good();
}
bool dxfReaderAscii::readString() {
std::getline(*filestr, strData);
if (!strData.empty() && strData.at(strData.size()-1) == '\r')
strData.erase(strData.size()-1);
DBG(strData); DBG("\n");
return (filestr->good());
bool dxfReaderAscii::readString( std::string* text )
{
std::getline( *filestr, *text );
if( !text->empty() && text->at( text->size() - 1 ) == '\r' )
text->erase( text->size() - 1 );
return filestr->good();
}
bool dxfReaderAscii::readInt() {
bool dxfReaderAscii::readString()
{
std::getline( *filestr, strData );
if( !strData.empty() && strData.at( strData.size() - 1 ) == '\r' )
strData.erase( strData.size() - 1 );
DBG( strData ); DBG( "\n" );
return filestr->good();
}
bool dxfReaderAscii::readInt()
{
std::string text;
if (readString(&text)){
intData = atoi(text.c_str());
DBG(intData); DBG("\n");
if( readString( &text ) )
{
intData = atoi( text.c_str() );
DBG( intData ); DBG( "\n" );
return true;
} else
}
else
return false;
}
bool dxfReaderAscii::readInt32() {
bool dxfReaderAscii::readInt32()
{
return readInt();
}
bool dxfReaderAscii::readInt64() {
bool dxfReaderAscii::readInt64()
{
return readInt();
}
bool dxfReaderAscii::readDouble() {
bool dxfReaderAscii::readDouble()
{
std::string text;
if (readString(&text)){
if( readString( &text ) )
{
#if defined(__APPLE__)
int succeeded=sscanf( & (text[0]), "%lg", &doubleData);
if(succeeded != 1) {
DBG("dxfReaderAscii::readDouble(): reading double error: ");
DBG(text);
DBG('\n');
int succeeded = sscanf( &(text[0]), "%lg", &doubleData );
if( succeeded != 1 )
{
DBG( "dxfReaderAscii::readDouble(): reading double error: " );
DBG( text );
DBG( '\n' );
}
#else
std::istringstream sd(text);
std::istringstream sd( text );
sd >> doubleData;
DBG(doubleData); DBG('\n');
DBG( doubleData ); DBG( '\n' );
#endif
return true;
} else
}
else
return false;
}
//saved as int or add a bool member??
bool dxfReaderAscii::readBool() {
// saved as int or add a bool member??
bool dxfReaderAscii::readBool()
{
std::string text;
if (readString(&text)){
intData = atoi(text.c_str());
DBG(intData); DBG("\n");
if( readString( &text ) )
{
intData = atoi( text.c_str() );
DBG( intData ); DBG( "\n" );
return true;
} else
}
else
return false;
}

View File

@ -15,75 +15,82 @@
#include "drw_textcodec.h"
class dxfReader {
class dxfReader
{
public:
dxfReader(std::ifstream *stream){
dxfReader( std::ifstream* stream )
{
filestr = stream;
#ifdef DRW_DBG
count =0;
count = 0;
#endif
}
virtual ~dxfReader(){}
virtual bool readCode(int *code) = 0; //return true if sucesful (not EOF)
virtual bool readString(std::string *text) = 0;
virtual bool readString() = 0;
bool readRec(int *code, bool skip);
virtual bool readInt() = 0;
virtual bool readInt32() = 0;
virtual bool readInt64() = 0;
virtual bool readDouble() = 0;
virtual bool readBool() = 0;
std::string getString() {return strData;}
int getHandleString();//Convert hex string to int
std::string toUtf8String(std::string t) {return decoder.toUtf8(t);}
std::string getUtf8String() {return decoder.toUtf8(strData);}
double getDouble() {return doubleData;}
int getInt32() {return intData;}
unsigned long long int getInt64() {return int64;}
bool getBool() { return (intData==0) ? false : true;}
int getVersion(){return decoder.getVersion();}
void setVersion(std::string *v){decoder.setVersion(v);}
void setCodePage(std::string *c){decoder.setCodePage(c);}
std::string getCodePage(){ return decoder.getCodePage();}
virtual ~dxfReader() {}
virtual bool readCode( int* code ) = 0; // return true if sucesful (not EOF)
virtual bool readString( std::string* text ) = 0;
virtual bool readString() = 0;
bool readRec( int* code, bool skip );
virtual bool readInt() = 0;
virtual bool readInt32() = 0;
virtual bool readInt64() = 0;
virtual bool readDouble() = 0;
virtual bool readBool() = 0;
std::string getString() { return strData; }
int getHandleString(); // Convert hex string to int
std::string toUtf8String( std::string t ) { return decoder.toUtf8( t ); }
std::string getUtf8String() { return decoder.toUtf8( strData ); }
double getDouble() { return doubleData; }
int getInt32() { return intData; }
unsigned long long int getInt64() { return int64; }
bool getBool() { return (intData==0) ? false : true; }
int getVersion() { return decoder.getVersion(); }
void setVersion( std::string* v ) { decoder.setVersion( v ); }
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 short intData; //16 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 {
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);
virtual bool readString();
virtual bool readInt();
virtual bool readInt32();
virtual bool readInt64();
virtual bool readDouble();
virtual bool readBool();
virtual bool readCode( int* code );
virtual bool readString( std::string* text );
virtual bool readString();
virtual bool readInt();
virtual bool readInt32();
virtual bool readInt64();
virtual bool readDouble();
virtual bool readBool();
};
class dxfReaderAscii : public dxfReader {
class dxfReaderAscii : public dxfReader
{
public:
dxfReaderAscii(std::ifstream *stream):dxfReader(stream){ }
virtual ~dxfReaderAscii(){}
virtual bool readCode(int *code);
virtual bool readString(std::string *text);
virtual bool readString();
virtual bool readInt();
virtual bool readDouble();
virtual bool readInt32();
virtual bool readInt64();
virtual bool readBool();
dxfReaderAscii( std::ifstream* stream ) : dxfReader( stream ) { }
virtual ~dxfReaderAscii() {}
virtual bool readCode( int* code );
virtual bool readString( std::string* text );
virtual bool readString();
virtual bool readInt();
virtual bool readDouble();
virtual bool readInt32();
virtual bool readInt64();
virtual bool readBool();
};
#endif // DXFREADER_H
#endif // DXFREADER_H

View File

@ -17,265 +17,303 @@
#include "dxfwriter.h"
#ifdef DRW_DBG
#include <iostream> //for debug
#define DBG(a) std::cerr << a
#include <iostream> // for debug
#define DBG( a ) std::cerr << a
#else
#define DBG(a)
#define DBG( a )
#endif
//RLZ TODO change std::endl to x0D x0A (13 10)
// RLZ TODO change std::endl to x0D x0A (13 10)
/*bool dxfWriter::readRec(int *codeData, bool skip) {
// std::string text;
int code;
* // std::string text;
* int code;
*
* #ifdef DRW_DBG
* count = count+2; //DBG
* #endif
*
* if (!readCode(&code))
* return false;
* codeData = code;
*
* if (code < 10)
* readString();
* else if (code < 60)
* readDouble();
* else if (code < 80)
* readInt();
* else if (code > 89 && code < 100) //TODO this is an int 32b
* readInt32();
* else if (code == 100 || code == 102 || code == 105)
* readString();
* else if (code > 109 && code < 150) //skip not used at the v2012
* readDouble();
* else if (code > 159 && code < 170) //skip not used at the v2012
* readInt64();
* else if (code < 180)
* readInt();
* else if (code > 209 && code < 240) //skip not used at the v2012
* readDouble();
* else if (code > 269 && code < 290) //skip not used at the v2012
* readInt();
* else if (code < 300) //TODO this is a boolean indicator, int in Binary?
* readBool();
* else if (code < 370)
* readString();
* else if (code < 390)
* readInt();
* else if (code < 400)
* readString();
* else if (code < 410)
* readInt();
* else if (code < 420)
* readString();
* else if (code < 430) //TODO this is an int 32b
* readInt32();
* else if (code < 440)
* readString();
* else if (code < 450) //TODO this is an int 32b
* readInt32();
* else if (code < 460) //TODO this is long??
* readInt();
* else if (code < 470) //TODO this is a floating point double precision??
* readDouble();
* else if (code < 481)
* readString();
* else if (code > 998 && code < 1009) //skip not used at the v2012
* readString();
* else if (code < 1060) //TODO this is a floating point double precision??
* readDouble();
* else if (code < 1071)
* readInt();
* else if (code == 1071) //TODO this is an int 32b
* readInt32();
* else if (skip)
* //skip safely this dxf entry ( ok for ascii dxf)
* readString();
* else
* //break in binary files because the conduct is unpredictable
* return false;
*
* return (filestr->good());
* }*/
#ifdef DRW_DBG
count = count+2; //DBG
#endif
bool dxfWriter::writeUtf8String( int code, std::string text )
{
std::string t = encoder.fromUtf8( text );
if (!readCode(&code))
return false;
*codeData = code;
if (code < 10)
readString();
else if (code < 60)
readDouble();
else if (code < 80)
readInt();
else if (code > 89 && code < 100) //TODO this is an int 32b
readInt32();
else if (code == 100 || code == 102 || code == 105)
readString();
else if (code > 109 && code < 150) //skip not used at the v2012
readDouble();
else if (code > 159 && code < 170) //skip not used at the v2012
readInt64();
else if (code < 180)
readInt();
else if (code > 209 && code < 240) //skip not used at the v2012
readDouble();
else if (code > 269 && code < 290) //skip not used at the v2012
readInt();
else if (code < 300) //TODO this is a boolean indicator, int in Binary?
readBool();
else if (code < 370)
readString();
else if (code < 390)
readInt();
else if (code < 400)
readString();
else if (code < 410)
readInt();
else if (code < 420)
readString();
else if (code < 430) //TODO this is an int 32b
readInt32();
else if (code < 440)
readString();
else if (code < 450) //TODO this is an int 32b
readInt32();
else if (code < 460) //TODO this is long??
readInt();
else if (code < 470) //TODO this is a floating point double precision??
readDouble();
else if (code < 481)
readString();
else if (code > 998 && code < 1009) //skip not used at the v2012
readString();
else if (code < 1060) //TODO this is a floating point double precision??
readDouble();
else if (code < 1071)
readInt();
else if (code == 1071) //TODO this is an int 32b
readInt32();
else if (skip)
//skip safely this dxf entry ( ok for ascii dxf)
readString();
else
//break in binary files because the conduct is unpredictable
return false;
return (filestr->good());
}*/
bool dxfWriter::writeUtf8String(int code, std::string text) {
std::string t = encoder.fromUtf8(text);
return writeString(code, t);
return writeString( code, t );
}
bool dxfWriter::writeUtf8Caps(int code, std::string text) {
bool dxfWriter::writeUtf8Caps( int code, std::string text )
{
std::string strname = text;
std::transform(strname.begin(), strname.end(), strname.begin(),::toupper);
std::string t = encoder.fromUtf8(strname);
return writeString(code, t);
std::transform( strname.begin(), strname.end(), strname.begin(), ::toupper );
std::string t = encoder.fromUtf8( strname );
return writeString( code, t );
}
bool dxfWriterBinary::writeString(int code, std::string text) {
bool dxfWriterBinary::writeString( int code, std::string text )
{
char bufcode[2];
bufcode[0] =code & 0xFF;
bufcode[1] =code >> 8;
filestr->write(bufcode, 2);
bufcode[0] = code & 0xFF;
bufcode[1] = code >> 8;
filestr->write( bufcode, 2 );
*filestr << text << '\0';
return (filestr->good());
return filestr->good();
}
/*bool dxfWriterBinary::readCode(int *code) {
unsigned short *int16p;
char buffer[2];
filestr->read(buffer,2);
int16p = (unsigned short *) buffer;
//exist a 32bits int (code 90) with 2 bytes???
if ((*code == 90) && (*int16p>2000)){
DBG(*code); DBG(" de 16bits\n");
filestr->seekg(-4, std::ios_base::cur);
filestr->read(buffer,2);
int16p = (unsigned short *) buffer;
}
*code = *int16p;
DBG(*code); DBG("\n");
return (filestr->good());
}*/
* unsigned short *int16p;
* char buffer[2];
* filestr->read(buffer,2);
* int16p = (unsigned short *) buffer;
* //exist a 32bits int (code 90) with 2 bytes???
* if ((*code == 90) && (*int16p>2000)){
* DBG(*code); DBG(" de 16bits\n");
* filestr->seekg(-4, std::ios_base::cur);
* filestr->read(buffer,2);
* int16p = (unsigned short *) buffer;
* }
* code = *int16p;
* DBG(*code); DBG("\n");
*
* return (filestr->good());
* }*/
/*bool dxfWriterBinary::readString() {
std::getline(*filestr, strData, '\0');
DBG(strData); DBG("\n");
return (filestr->good());
}*/
* std::getline(*filestr, strData, '\0');
* DBG(strData); DBG("\n");
* return (filestr->good());
* }*/
/*bool dxfWriterBinary::readString(std::string *text) {
std::getline(*filestr, *text, '\0');
DBG(*text); DBG("\n");
return (filestr->good());
}*/
* std::getline(*filestr, *text, '\0');
* DBG(*text); DBG("\n");
* return (filestr->good());
* }*/
bool dxfWriterBinary::writeInt16(int code, int data) {
char bufcode[2];
char buffer[2];
bufcode[0] =code & 0xFF;
bufcode[1] =code >> 8;
buffer[0] =data & 0xFF;
buffer[1] =data >> 8;
filestr->write(bufcode, 2);
filestr->write(buffer, 2);
return (filestr->good());
bool dxfWriterBinary::writeInt16( int code, int data )
{
char bufcode[2];
char buffer[2];
bufcode[0] = code & 0xFF;
bufcode[1] = code >> 8;
buffer[0] = data & 0xFF;
buffer[1] = data >> 8;
filestr->write( bufcode, 2 );
filestr->write( buffer, 2 );
return filestr->good();
}
bool dxfWriterBinary::writeInt32(int code, int data) {
bool dxfWriterBinary::writeInt32( int code, int data )
{
char buffer[4];
buffer[0] =code & 0xFF;
buffer[1] =code >> 8;
filestr->write(buffer, 2);
buffer[0] =data & 0xFF;
buffer[1] =data >> 8;
buffer[2] =data >> 16;
buffer[3] =data >> 24;
filestr->write(buffer, 4);
return (filestr->good());
buffer[0] = code & 0xFF;
buffer[1] = code >> 8;
filestr->write( buffer, 2 );
buffer[0] = data & 0xFF;
buffer[1] = data >> 8;
buffer[2] = data >> 16;
buffer[3] = data >> 24;
filestr->write( buffer, 4 );
return filestr->good();
}
bool dxfWriterBinary::writeInt64(int code, unsigned long long int data) {
char buffer[8];
buffer[0] =code & 0xFF;
buffer[1] =code >> 8;
filestr->write(buffer, 2);
buffer[0] =data & 0xFF;
buffer[1] =data >> 8;
buffer[2] =data >> 16;
buffer[3] =data >> 24;
buffer[4] =data >> 32;
buffer[5] =data >> 40;
buffer[6] =data >> 48;
buffer[7] =data >> 56;
filestr->write(buffer, 8);
return (filestr->good());
bool dxfWriterBinary::writeInt64( int code, unsigned long long int data )
{
char buffer[8];
buffer[0] = code & 0xFF;
buffer[1] = code >> 8;
filestr->write( buffer, 2 );
buffer[0] = data & 0xFF;
buffer[1] = data >> 8;
buffer[2] = data >> 16;
buffer[3] = data >> 24;
buffer[4] = data >> 32;
buffer[5] = data >> 40;
buffer[6] = data >> 48;
buffer[7] = data >> 56;
filestr->write( buffer, 8 );
return filestr->good();
}
bool dxfWriterBinary::writeDouble(int code, double data) {
char bufcode[2];
char buffer[8];
bufcode[0] =code & 0xFF;
bufcode[1] =code >> 8;
filestr->write(bufcode, 2);
unsigned char *val;
val = (unsigned char *) &data;
for (int i=0; i<8; i++) {
buffer[i] =val[i];
bool dxfWriterBinary::writeDouble( int code, double data )
{
char bufcode[2];
char buffer[8];
bufcode[0] = code & 0xFF;
bufcode[1] = code >> 8;
filestr->write( bufcode, 2 );
unsigned char* val;
val = (unsigned char*) &data;
for( int i = 0; i<8; i++ )
{
buffer[i] = val[i];
}
filestr->write(buffer, 8);
return (filestr->good());
filestr->write( buffer, 8 );
return filestr->good();
}
//saved as int or add a bool member??
bool dxfWriterBinary::writeBool(int code, bool data) {
char buffer[1];
char bufcode[2];
bufcode[0] =code & 0xFF;
bufcode[1] =code >> 8;
filestr->write(bufcode, 2);
// saved as int or add a bool member??
bool dxfWriterBinary::writeBool( int code, bool data )
{
char buffer[1];
char bufcode[2];
bufcode[0] = code & 0xFF;
bufcode[1] = code >> 8;
filestr->write( bufcode, 2 );
buffer[0] = data;
filestr->write(buffer, 1);
return (filestr->good());
filestr->write( buffer, 1 );
return filestr->good();
}
bool dxfWriterAscii::writeString(int code, std::string text) {
*filestr << code << std::endl << text << std::endl ;
bool dxfWriterAscii::writeString( int code, std::string text )
{
*filestr << code << std::endl << text << std::endl;
/* std::getline(*filestr, strData, '\0');
DBG(strData); DBG("\n");*/
return (filestr->good());
* DBG(strData); DBG("\n");*/
return filestr->good();
}
/*bool dxfWriterAscii::readCode(int *code) {
std::string text;
std::getline(*filestr, text);
*code = atoi(text.c_str());
DBG(*code); DBG("\n");
return (filestr->good());
}*/
* std::string text;
* std::getline(*filestr, text);
* code = atoi(text.c_str());
* DBG(*code); DBG("\n");
* return (filestr->good());
* }*/
/*bool dxfWriterAscii::readString(std::string *text) {
std::getline(*filestr, *text);
if (text->at(text->size()-1) == '\r')
text->erase(text->size()-1);
return (filestr->good());
}*/
* std::getline(*filestr, *text);
* if (text->at(text->size()-1) == '\r')
* text->erase(text->size()-1);
* return (filestr->good());
* }*/
/*bool dxfWriterAscii::readString() {
std::getline(*filestr, strData);
if (strData.at(strData.size()-1) == '\r')
strData.erase(strData.size()-1);
DBG(strData); DBG("\n");
return (filestr->good());
}*/
* std::getline(*filestr, strData);
* if (strData.at(strData.size()-1) == '\r')
* strData.erase(strData.size()-1);
* DBG(strData); DBG("\n");
* return (filestr->good());
* }*/
bool dxfWriterAscii::writeInt16(int code, int data) {
// *filestr << code << "\r\n" << data << "\r\n";
bool dxfWriterAscii::writeInt16( int code, int data )
{
// *filestr << code << "\r\n" << data << "\r\n";
*filestr << code << std::endl << data << std::endl;
return (filestr->good());
return filestr->good();
}
bool dxfWriterAscii::writeInt32(int code, int data) {
return writeInt16(code, data);
bool dxfWriterAscii::writeInt32( int code, int data )
{
return writeInt16( code, data );
}
bool dxfWriterAscii::writeInt64(int code, unsigned long long int data) {
bool dxfWriterAscii::writeInt64( int code, unsigned long long int data )
{
*filestr << code << std::endl << data << std::endl;
return (filestr->good());
return filestr->good();
}
bool dxfWriterAscii::writeDouble(int code, double data) {
bool dxfWriterAscii::writeDouble( int code, double data )
{
std::streamsize prec = filestr->precision();
filestr->precision(12);
filestr->precision( 12 );
*filestr << code << std::endl << data << std::endl;
filestr->precision(prec);
return (filestr->good());
filestr->precision( prec );
return filestr->good();
}
//saved as int or add a bool member??
bool dxfWriterAscii::writeBool(int code, bool data) {
*filestr << code << std::endl << data << std::endl;
return (filestr->good());
}
// saved as int or add a bool member??
bool dxfWriterAscii::writeBool( int code, bool data )
{
*filestr << code << std::endl << data << std::endl;
return filestr->good();
}

View File

@ -15,50 +15,55 @@
#include "drw_textcodec.h"
class dxfWriter {
class dxfWriter
{
public:
dxfWriter(std::ofstream *stream){filestr = stream; /*count =0;*/}
virtual ~dxfWriter(){}
virtual bool writeString(int code, std::string text) = 0;
bool writeUtf8String(int code, std::string text);
bool writeUtf8Caps(int code, std::string text);
std::string fromUtf8String(std::string t) {return encoder.fromUtf8(t);}
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;
void setVersion(std::string *v){encoder.setVersion(v);}
void setCodePage(std::string *c){encoder.setCodePage(c);}
std::string getCodePage(){return encoder.getCodePage();}
dxfWriter( std::ofstream* stream ) { filestr = stream; /*count =0;*/ }
virtual ~dxfWriter() {}
virtual bool writeString( int code, std::string text ) = 0;
bool writeUtf8String( int code, std::string text );
bool writeUtf8Caps( int code, std::string text );
std::string fromUtf8String( std::string t ) { return encoder.fromUtf8( t ); }
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;
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 {
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);
virtual bool writeInt32(int code, int data);
virtual bool writeInt64(int code, unsigned long long int data);
virtual bool writeDouble(int code, double data);
virtual bool writeBool(int code, bool data);
virtual bool writeString( int code, std::string text );
virtual bool writeInt16( int code, int data );
virtual bool writeInt32( int code, int data );
virtual bool writeInt64( int code, unsigned long long int data );
virtual bool writeDouble( int code, double data );
virtual bool writeBool( int code, bool data );
};
class dxfWriterAscii : public dxfWriter {
class dxfWriterAscii : public dxfWriter
{
public:
dxfWriterAscii(std::ofstream *stream):dxfWriter(stream){ }
virtual ~dxfWriterAscii(){}
virtual bool writeString(int code, std::string text);
virtual bool writeInt16(int code, int data);
virtual bool writeInt32(int code, int data);
virtual bool writeInt64(int code, unsigned long long int data);
virtual bool writeDouble(int code, double data);
virtual bool writeBool(int code, bool data);
dxfWriterAscii( std::ofstream* stream ) : dxfWriter( stream ) { }
virtual ~dxfWriterAscii() {}
virtual bool writeString( int code, std::string text );
virtual bool writeInt16( int code, int data );
virtual bool writeInt32( int code, int data );
virtual bool writeInt64( int code, unsigned long long int data );
virtual bool writeDouble( int code, double data );
virtual bool writeBool( int code, bool data );
};
#endif // DXFWRITER_H
#endif // DXFWRITER_H

View File

@ -215,7 +215,7 @@ bool dxfRW::writeEntity( DRW_Entity* ent )
bool dxfRW::writeLineType( DRW_LType* ent )
{
string strname = ent->name;
std::string strname = ent->name;
transform( strname.begin(), strname.end(), strname.begin(), ::toupper );
@ -1322,7 +1322,12 @@ bool dxfRW::writeDimension( DRW_Dimension* ent )
writer->writeString( 0, "DIMENSION" );
writeEntity( ent );
writer->writeString( 100, "AcDbDimension" );
// writer->writeString(2, ent->name);
if( !ent->getName().empty() )
{
writer->writeString( 2, ent->getName() );
}
writer->writeDouble( 10, ent->getDefPoint().x );
writer->writeDouble( 20, ent->getDefPoint().y );
writer->writeDouble( 30, ent->getDefPoint().z );
@ -2129,8 +2134,13 @@ bool dxfRW::writeTables()
writer->writeInt16( 280, 1 );
writer->writeInt16( 281, 0 );
}
}
iface->writeBlockRecords();
/* allways call writeBlockRecords to iface for prepare unnamed blocks */
iface->writeBlockRecords();
if( version > DRW::AC1009 )
{
writer->writeString( 0, "ENDTAB" );
}
@ -2312,7 +2322,7 @@ bool dxfRW::writeObjects()
for( unsigned int i = 0; i<imageDef.size(); i++ )
{
DRW_ImageDef* id = imageDef.at( i );
std::map<string, string>::iterator it;
std::map<std::string, std::string>::iterator it;
for( it = id->reactors.begin(); it != id->reactors.end(); it++ )
{
@ -2356,7 +2366,7 @@ bool dxfRW::writeObjects()
}
writer->writeString( 102, "{ACAD_REACTORS" );
std::map<string, string>::iterator it;
std::map<std::string, std::string>::iterator it;
for( it = id->reactors.begin(); it != id->reactors.end(); it++ )
{
@ -2390,9 +2400,9 @@ bool dxfRW::writeObjects()
bool dxfRW::processDxf()
{
DBG( "dxfRW::processDxf() start processing dxf\n" );
int code;
bool more = true;
string sectionstr;
int code;
bool more = true;
std::string sectionstr;
// section = secUnknown;
while( reader->readRec( &code, !binary ) )
@ -2468,8 +2478,8 @@ bool dxfRW::processDxf()
bool dxfRW::processHeader()
{
DBG( "dxfRW::processHeader\n" );
int code;
string sectionstr;
int code;
std::string sectionstr;
while( reader->readRec( &code, !binary ) )
{
@ -2499,9 +2509,9 @@ bool dxfRW::processHeader()
bool dxfRW::processTables()
{
DBG( "dxfRW::processTables\n" );
int code;
string sectionstr;
bool more = true;
int code;
std::string sectionstr;
bool more = true;
while( reader->readRec( &code, !binary ) )
{
@ -2579,7 +2589,7 @@ bool dxfRW::processLType()
{
DBG( "dxfRW::processLType\n" );
int code;
string sectionstr;
std::string sectionstr;
bool reading = false;
DRW_LType ltype;
@ -2620,7 +2630,7 @@ bool dxfRW::processLayer()
{
DBG( "dxfRW::processLayer\n" );
int code;
string sectionstr;
std::string sectionstr;
bool reading = false;
DRW_Layer layer;
@ -2658,7 +2668,7 @@ bool dxfRW::processDimStyle()
{
DBG( "dxfRW::processDimStyle" );
int code;
string sectionstr;
std::string sectionstr;
bool reading = false;
DRW_Dimstyle dimSty;
@ -2696,7 +2706,7 @@ bool dxfRW::processTextStyle()
{
DBG( "dxfRW::processTextStyle" );
int code;
string sectionstr;
std::string sectionstr;
bool reading = false;
DRW_Textstyle TxtSty;
@ -2734,7 +2744,7 @@ bool dxfRW::processVports()
{
DBG( "dxfRW::processVports" );
int code;
string sectionstr;
std::string sectionstr;
bool reading = false;
DRW_Vport vp;
@ -2773,8 +2783,8 @@ bool dxfRW::processVports()
bool dxfRW::processBlocks()
{
DBG( "dxfRW::processBlocks\n" );
int code;
string sectionstr;
int code;
std::string sectionstr;
while( reader->readRec( &code, !binary ) )
{

View File

@ -127,7 +127,7 @@ private:
DRW_Interface* iface;
DRW_Header header;
// int section;
string nextentity;
std::string nextentity;
int entCount;
bool wlayer0;
bool dimstyleStd;

View File

@ -27,16 +27,25 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
#include <appl_wxstruct.h>
#include <dxf2brd_items.h>
#include <wxPcbStruct.h>
#include <convert_from_iu.h>
#include <dialog_dxf_import_base.h>
#include <class_pcb_layer_box_selector.h>
// Keys to store setup in config
#define DXF_IMPORT_LAYER_OPTION_KEY wxT("DxfImportBrdLayer")
#define DXF_IMPORT_COORD_ORIGIN_KEY wxT("DxfImportCoordOrigin")
#define DXF_IMPORT_LAST_FILE_KEY wxT("DxfImportLastFile")
class DIALOG_DXF_IMPORT : public DIALOG_DXF_IMPORT_BASE
{
private:
PCB_EDIT_FRAME * m_parent;
wxConfig* m_config; // Current config
static wxString m_dxfFilename;
static int m_offsetSelection;
static LAYER_NUM m_layer;
@ -64,6 +73,15 @@ DIALOG_DXF_IMPORT::DIALOG_DXF_IMPORT( PCB_EDIT_FRAME* aParent )
: DIALOG_DXF_IMPORT_BASE( aParent )
{
m_parent = aParent;
m_config = wxGetApp().GetSettings();
if( m_config )
{
m_layer = m_config->Read( DXF_IMPORT_LAYER_OPTION_KEY, (long)DRAW_N );
m_offsetSelection = m_config->Read( DXF_IMPORT_COORD_ORIGIN_KEY, 3 );
m_dxfFilename = m_config->Read( DXF_IMPORT_LAST_FILE_KEY, wxEmptyString );
}
m_textCtrlFileName->SetValue( m_dxfFilename );
m_rbOffsetOption->SetSelection( m_offsetSelection );
@ -72,6 +90,7 @@ DIALOG_DXF_IMPORT::DIALOG_DXF_IMPORT( PCB_EDIT_FRAME* aParent )
m_SelLayerBox->SetLayerMask( ALL_CU_LAYERS ); // Do not use copper layers
m_SelLayerBox->SetBoardFrame( m_parent );
m_SelLayerBox->Resync();
if( m_SelLayerBox->SetLayerSelection( m_layer ) < 0 )
{
m_layer = DRAW_N;
@ -88,14 +107,28 @@ DIALOG_DXF_IMPORT::~DIALOG_DXF_IMPORT()
{
m_offsetSelection = m_rbOffsetOption->GetSelection();
m_layer = m_SelLayerBox->GetLayerSelection();
if( m_config )
{
m_config->Write( DXF_IMPORT_LAYER_OPTION_KEY, (long)m_layer );
m_config->Write( DXF_IMPORT_COORD_ORIGIN_KEY, m_offsetSelection );
m_config->Write( DXF_IMPORT_LAST_FILE_KEY, m_dxfFilename );
}
}
void DIALOG_DXF_IMPORT::OnBrowseDxfFiles( wxCommandEvent& event )
{
wxString path;
if( !m_dxfFilename.IsEmpty() )
{
wxFileName fn( m_dxfFilename );
path = fn.GetPath();
}
wxFileDialog dlg( m_parent,
wxT( "Open File" ),
wxEmptyString, wxEmptyString,
path, m_dxfFilename,
wxT( "dxf Files (*.dxf)|*.dxf|*.DXF" ),
wxFD_OPEN|wxFD_FILE_MUST_EXIST );
dlg.ShowModal();

File diff suppressed because it is too large Load Diff