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,7 +889,7 @@ public:
void parseCode( int code, dxfReader* reader );
public:
string ref; /*!< Hard reference to imagedef object, code 340 */
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 */
@ -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 */
@ -1253,7 +1251,7 @@ public:
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 */
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 */

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
};

View File

@ -9,241 +9,332 @@
#include "drw_cptable949.h"
#include "drw_cptable950.h"
DRW_TextCodec::DRW_TextCodec() {
DRW_TextCodec::DRW_TextCodec()
{
version = DRW::AC1021;
conv = new DRW_Converter(NULL, 0);
conv = new DRW_Converter( NULL, 0 );
}
DRW_TextCodec::~DRW_TextCodec() {
DRW_TextCodec::~DRW_TextCodec()
{
delete conv;
}
void DRW_TextCodec::setVersion(std::string *v){
void DRW_TextCodec::setVersion( std::string* v )
{
std::string versionStr = *v;
if (versionStr == "AC1009" || versionStr == "AC1006") {
if( versionStr == "AC1009" || versionStr == "AC1006" )
{
version = DRW::AC1009;
cp = "ANSI_1252";
setCodePage(&cp);
} else if (versionStr == "AC1012" || versionStr == "AC1014"
|| versionStr == "AC1015" || versionStr == "AC1018") {
version = DRW::AC1015;
if (cp.empty()) { //codepage not set, initialize
cp = "ANSI_1252";
setCodePage(&cp);
setCodePage( &cp );
}
} else {
else if( versionStr == "AC1012" || versionStr == "AC1014"
|| versionStr == "AC1015" || versionStr == "AC1018" )
{
version = DRW::AC1015;
if( cp.empty() ) // codepage not set, initialize
{
cp = "ANSI_1252";
setCodePage( &cp );
}
}
else
{
version = DRW::AC1021;
cp = "ANSI_1252";
}
}
void DRW_TextCodec::setCodePage(std::string *c){
cp = correctCodePage(*c);
void DRW_TextCodec::setCodePage( std::string* c )
{
cp = correctCodePage( *c );
delete conv;
if (version == DRW::AC1009 || version == DRW::AC1015) {
if (cp == "ANSI_874")
conv = new DRW_ConvTable(DRW_Table874, CPLENGHTCOMMON);
else if (cp == "ANSI_932")
conv = new DRW_Conv932Table(DRW_Table932, DRW_LeadTable932,
DRW_DoubleTable932, CPLENGHT932);
else if (cp == "ANSI_936")
conv = new DRW_ConvDBCSTable(DRW_Table936, DRW_LeadTable936,
DRW_DoubleTable936, CPLENGHT936);
else if (cp == "ANSI_949")
conv = new DRW_ConvDBCSTable(DRW_Table949, DRW_LeadTable949,
DRW_DoubleTable949, CPLENGHT949);
else if (cp == "ANSI_950")
conv = new DRW_ConvDBCSTable(DRW_Table950, DRW_LeadTable950,
DRW_DoubleTable950, CPLENGHT950);
else if (cp == "ANSI_1250")
conv = new DRW_ConvTable(DRW_Table1250, CPLENGHTCOMMON);
else if (cp == "ANSI_1251")
conv = new DRW_ConvTable(DRW_Table1251, CPLENGHTCOMMON);
else if (cp == "ANSI_1253")
conv = new DRW_ConvTable(DRW_Table1253, CPLENGHTCOMMON);
else if (cp == "ANSI_1254")
conv = new DRW_ConvTable(DRW_Table1254, CPLENGHTCOMMON);
else if (cp == "ANSI_1255")
conv = new DRW_ConvTable(DRW_Table1255, CPLENGHTCOMMON);
else if (cp == "ANSI_1256")
conv = new DRW_ConvTable(DRW_Table1256, CPLENGHTCOMMON);
else if (cp == "ANSI_1257")
conv = new DRW_ConvTable(DRW_Table1257, CPLENGHTCOMMON);
else if (cp == "ANSI_1258")
conv = new DRW_ConvTable(DRW_Table1258, CPLENGHTCOMMON);
else if (cp == "UTF-8") { //DXF older than 2007 are write in win codepages
if( version == DRW::AC1009 || version == DRW::AC1015 )
{
if( cp == "ANSI_874" )
conv = new DRW_ConvTable( DRW_Table874, CPLENGHTCOMMON );
else if( cp == "ANSI_932" )
conv = new DRW_Conv932Table( DRW_Table932, DRW_LeadTable932,
DRW_DoubleTable932, CPLENGHT932 );
else if( cp == "ANSI_936" )
conv = new DRW_ConvDBCSTable( DRW_Table936, DRW_LeadTable936,
DRW_DoubleTable936, CPLENGHT936 );
else if( cp == "ANSI_949" )
conv = new DRW_ConvDBCSTable( DRW_Table949, DRW_LeadTable949,
DRW_DoubleTable949, CPLENGHT949 );
else if( cp == "ANSI_950" )
conv = new DRW_ConvDBCSTable( DRW_Table950, DRW_LeadTable950,
DRW_DoubleTable950, CPLENGHT950 );
else if( cp == "ANSI_1250" )
conv = new DRW_ConvTable( DRW_Table1250, CPLENGHTCOMMON );
else if( cp == "ANSI_1251" )
conv = new DRW_ConvTable( DRW_Table1251, CPLENGHTCOMMON );
else if( cp == "ANSI_1253" )
conv = new DRW_ConvTable( DRW_Table1253, CPLENGHTCOMMON );
else if( cp == "ANSI_1254" )
conv = new DRW_ConvTable( DRW_Table1254, CPLENGHTCOMMON );
else if( cp == "ANSI_1255" )
conv = new DRW_ConvTable( DRW_Table1255, CPLENGHTCOMMON );
else if( cp == "ANSI_1256" )
conv = new DRW_ConvTable( DRW_Table1256, CPLENGHTCOMMON );
else if( cp == "ANSI_1257" )
conv = new DRW_ConvTable( DRW_Table1257, CPLENGHTCOMMON );
else if( cp == "ANSI_1258" )
conv = new DRW_ConvTable( DRW_Table1258, CPLENGHTCOMMON );
else if( cp == "UTF-8" ) // DXF older than 2007 are write in win codepages
{
cp = "ANSI_1252";
conv = new DRW_Converter(NULL, 0);
} else
conv = new DRW_ConvTable(DRW_Table1252, CPLENGHTCOMMON);
} else {
conv = new DRW_Converter(NULL, 0);
conv = new DRW_Converter( NULL, 0 );
}
else
conv = new DRW_ConvTable( DRW_Table1252, CPLENGHTCOMMON );
}
else
{
conv = new DRW_Converter( NULL, 0 );
}
}
std::string DRW_TextCodec::toUtf8(std::string s) {
return conv->toUtf8(&s);
std::string DRW_TextCodec::toUtf8( std::string s )
{
return conv->toUtf8( &s );
}
std::string DRW_TextCodec::fromUtf8(std::string s) {
return conv->fromUtf8(&s);
std::string DRW_TextCodec::fromUtf8( std::string s )
{
return conv->fromUtf8( &s );
}
std::string DRW_Converter::toUtf8(std::string *s) {
std::string DRW_Converter::toUtf8( std::string* s )
{
std::string result;
int j = 0;
unsigned int i= 0;
for (i=0; i < s->length(); i++) {
unsigned char c = s->at(i);
if (c < 0x80) { //ascii check for /U+????
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));
i +=6;
j = i+1;
unsigned int i = 0;
for( i = 0; i < s->length(); i++ )
{
unsigned char c = s->at( i );
if( c < 0x80 ) // ascii check for /U+????
{
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 ) );
i += 6;
j = i + 1;
}
} else if (c < 0xE0 ) {//2 bits
}
else if( c < 0xE0 ) // 2 bits
{
i++;
} else if (c < 0xF0 ) {//3 bits
i +=2;
} else if (c < 0xF8 ) {//4 bits
i +=3;
}
else if( c < 0xF0 ) // 3 bits
{
i += 2;
}
else if( c < 0xF8 ) // 4 bits
{
i += 3;
}
}
result += s->substr(j);
result += s->substr( j );
return result;
}
std::string DRW_ConvTable::fromUtf8(std::string *s) {
std::string DRW_ConvTable::fromUtf8( std::string* s )
{
std::string result;
bool notFound;
int code;
int j = 0;
for (unsigned int i=0; i < s->length(); i++) {
unsigned char c = s->at(i);
if (c > 0x7F) { //need to decode
result += s->substr(j,i-j);
std::string part1 = s->substr(i,4);
for( unsigned int i = 0; i < s->length(); i++ )
{
unsigned char c = s->at( i );
if( c > 0x7F ) // need to decode
{
result += s->substr( j, i - j );
std::string part1 = s->substr( i, 4 );
int l;
code = decodeNum(part1, &l);
j = i+l;
code = decodeNum( part1, &l );
j = i + l;
i = j - 1;
notFound = true;
for (int k=0; k<cpLenght; k++){
if(table[k] == code) {
result += CPOFFSET + k; //translate from table
for( int k = 0; k<cpLenght; k++ )
{
if( table[k] == code )
{
result += CPOFFSET + k; // translate from table
notFound = false;
break;
}
}
if (notFound)
result += decodeText(code);
if( notFound )
result += decodeText( code );
}
}
result += s->substr(j);
result += s->substr( j );
return result;
}
std::string DRW_ConvTable::toUtf8(std::string *s) {
std::string DRW_ConvTable::toUtf8( std::string* s )
{
std::string res;
string::iterator it;
for ( it=s->begin() ; it < s->end(); it++ ) {
std::string::iterator it;
for( it = s->begin(); it < s->end(); it++ )
{
unsigned char c = *it;
if (c < 0x80) {
//check for \U+ encoded text
if (c == '\\') {
if (it+6 < s->end() && *(it+1) == 'U' && *(it+2) == '+') {
res += encodeText(std::string(it, it+7));
it +=6;
} else {
res +=c; //no \U+ encoded text write
if( c < 0x80 )
{
// check for \U+ encoded text
if( c == '\\' )
{
if( it + 6 < s->end() && *(it + 1) == 'U' && *(it + 2) == '+' )
{
res += encodeText( std::string( it, it + 7 ) );
it += 6;
}
} else
res +=c; //c!='\' ascii char write
} else {//end c < 0x80
res += encodeNum(table[c-0x80]); //translate from table
else
{
res += c; // no \U+ encoded text write
}
} //end for
}
else
res += c; // c!='\' ascii char write
}
else // end c < 0x80
{
res += encodeNum( table[c - 0x80] ); // translate from table
}
} // end for
return res;
}
std::string DRW_Converter::encodeText(std::string stmp){
std::string DRW_Converter::encodeText( std::string stmp )
{
int code;
#if defined(__APPLE__)
int Succeeded = sscanf (&( stmp.substr(3,4)[0]), "%x", &code );
if ( !Succeeded || Succeeded == EOF )
int Succeeded = sscanf( &( stmp.substr( 3, 4 )[0]), "%x", &code );
if( !Succeeded || Succeeded == EOF )
code = 0;
#else
std::istringstream sd(stmp.substr(3,4));
std::istringstream sd( stmp.substr( 3, 4 ) );
sd >> std::hex >> code;
#endif
return encodeNum(code);
return encodeNum( code );
}
std::string DRW_Converter::decodeText(int c){
std::string DRW_Converter::decodeText( int c )
{
std::string res = "\\U+";
std::string num;
#if defined(__APPLE__)
std::string str(16, '\0');
snprintf (&(str[0]), 16, "%04X", c );
std::string str( 16, '\0' );
snprintf( &(str[0]), 16, "%04X", c );
num = str;
#else
std::stringstream ss;
ss << std::uppercase << std::setfill('0') << std::setw(4) << std::hex << c;
ss << std::uppercase << std::setfill( '0' ) << std::setw( 4 ) << std::hex << c;
ss >> num;
#endif
res += num;
return res;
}
std::string DRW_Converter::encodeNum(int c){
std::string DRW_Converter::encodeNum( int c )
{
unsigned char ret[5];
if (c < 128) { // 0-7F US-ASCII 7 bits
if( c < 128 ) // 0-7F US-ASCII 7 bits
{
ret[0] = c;
ret[1] = 0;
} else if (c < 0x800) { //80-07FF 2 bytes
}
else if( c < 0x800 ) // 80-07FF 2 bytes
{
ret[0] = 0xC0 | (c >> 6);
ret[1] = 0x80 | (c & 0x3f);
ret[2] = 0;
} else if (c< 0x10000) { //800-FFFF 3 bytes
}
else if( c< 0x10000 ) // 800-FFFF 3 bytes
{
ret[0] = 0xe0 | (c >> 12);
ret[1] = 0x80 | ((c >> 6) & 0x3f);
ret[1] = 0x80 | ( (c >> 6) & 0x3f );
ret[2] = 0x80 | (c & 0x3f);
ret[3] = 0;
} else { //10000-10FFFF 4 bytes
}
else // 10000-10FFFF 4 bytes
{
ret[0] = 0xf0 | (c >> 18);
ret[1] = 0x80 | ((c >> 12) & 0x3f);
ret[2] = 0x80 | ((c >> 6) & 0x3f);
ret[1] = 0x80 | ( (c >> 12) & 0x3f );
ret[2] = 0x80 | ( (c >> 6) & 0x3f );
ret[3] = 0x80 | (c & 0x3f);
ret[4] = 0;
}
return std::string((char*)ret);
return std::string( (char*) ret );
}
/** 's' is a string with at least 4 bytes lenght
** returned 'b' is byte lenght of encoded char: 2,3 or 4
**/
int DRW_Converter::decodeNum(std::string s, int *b){
int code= 0;
unsigned char c = s.at(0);
if ( (c& 0xE0) == 0xC0) { //2 bytes
code = ( c&0x1F)<<6;
code = (s.at(1) &0x3F) | code;
int DRW_Converter::decodeNum( std::string s, int* b )
{
int code = 0;
unsigned char c = s.at( 0 );
if( (c & 0xE0) == 0xC0 ) // 2 bytes
{
code = ( c & 0x1F) << 6;
code = (s.at( 1 ) & 0x3F) | code;
*b = 2;
} else if ( (c& 0xF0) == 0xE0) { //3 bytes
code = ( c&0x0F)<<12;
code = ((s.at(1) &0x3F)<<6) | code;
code = (s.at(2) &0x3F) | code;
}
else if( (c & 0xF0) == 0xE0 ) // 3 bytes
{
code = ( c & 0x0F) << 12;
code = ( (s.at( 1 ) & 0x3F) << 6 ) | code;
code = (s.at( 2 ) & 0x3F) | code;
*b = 3;
} else if ( (c& 0xF8) == 0xF0) { //4 bytes
code = ( c&0x07)<<18;
code = ((s.at(1) &0x3F)<<12) | code;
code = ((s.at(2) &0x3F)<<6) | code;
code = (s.at(3) &0x3F) | code;
}
else if( (c & 0xF8) == 0xF0 ) // 4 bytes
{
code = ( c & 0x07) << 18;
code = ( (s.at( 1 ) & 0x3F) << 12 ) | code;
code = ( (s.at( 2 ) & 0x3F) << 6 ) | code;
code = (s.at( 3 ) & 0x3F) | code;
*b = 4;
}
@ -251,246 +342,351 @@ 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;
bool notFound;
int code;
int j = 0;
for (unsigned int i=0; i < s->length(); i++) {
unsigned char c = s->at(i);
if (c > 0x7F) { //need to decode
result += s->substr(j,i-j);
std::string part1 = s->substr(i,4);
for( unsigned int i = 0; i < s->length(); i++ )
{
unsigned char c = s->at( i );
if( c > 0x7F ) // need to decode
{
result += s->substr( j, i - j );
std::string part1 = s->substr( i, 4 );
int l;
code = decodeNum(part1, &l);
j = i+l;
code = decodeNum( part1, &l );
j = i + l;
i = j - 1;
notFound = true;
for (int k=0; k<cpLenght; k++){
if(doubleTable[k][1] == code) {
for( int k = 0; k<cpLenght; k++ )
{
if( doubleTable[k][1] == code )
{
int data = doubleTable[k][0];
char d[3];
d[0] = data >> 8;
d[1] = data & 0xFF;
d[2]= '\0';
result += d; //translate from table
d[2] = '\0';
result += d; // translate from table
notFound = false;
break;
}
}
if (notFound)
result += decodeText(code);
} //direct conversion
if( notFound )
result += decodeText( code );
} // direct conversion
}
result += s->substr(j);
result += s->substr( j );
return result;
}
std::string DRW_ConvDBCSTable::toUtf8(std::string *s) {
std::string DRW_ConvDBCSTable::toUtf8( std::string* s )
{
std::string res;
string::iterator it;
for ( it=s->begin() ; it < s->end(); it++ ) {
std::string::iterator it;
for( it = s->begin(); it < s->end(); it++ )
{
bool notFound = true;
unsigned char c = *it;
if (c < 0x80) {
if( c < 0x80 )
{
notFound = false;
//check for \U+ encoded text
if (c == '\\') {
if (it+6 < s->end() && *(it+1) == 'U' && *(it+2) == '+') {
res += encodeText(std::string(it, it+7));
it +=6;
} else {
res +=c; //no \U+ encoded text write
// check for \U+ encoded text
if( c == '\\' )
{
if( it + 6 < s->end() && *(it + 1) == 'U' && *(it + 2) == '+' )
{
res += encodeText( std::string( it, it + 7 ) );
it += 6;
}
} else
res +=c; //c!='\' ascii char write
} else if(c == 0x80 ){//1 byte table
else
{
res += c; // no \U+ encoded text write
}
}
else
res += c; // c!='\' ascii char write
}
else if( c == 0x80 ) // 1 byte table
{
notFound = false;
res += encodeNum(0x20AC);//euro sign
} else {//2 bytes
res += encodeNum( 0x20AC ); // euro sign
}
else // 2 bytes
{
++it;
int code = (c << 8) | (unsigned char )(*it);
int sta = leadTable[c-0x81];
int end = leadTable[c-0x80];
for (int k=sta; k<end; k++){
if(doubleTable[k][0] == code) {
res += encodeNum(doubleTable[k][1]); //translate from table
int code = (c << 8) | (unsigned char) (*it);
int sta = leadTable[c - 0x81];
int end = leadTable[c - 0x80];
for( int k = sta; k<end; k++ )
{
if( doubleTable[k][0] == code )
{
res += encodeNum( doubleTable[k][1] ); // translate from table
notFound = false;
break;
}
}
}
//not found
if (notFound) res += encodeNum(NOTFOUND936);
} //end for
// not found
if( notFound )
res += encodeNum( NOTFOUND936 );
} // end for
return res;
}
std::string DRW_Conv932Table::fromUtf8(std::string *s) {
std::string DRW_Conv932Table::fromUtf8( std::string* s )
{
std::string result;
bool notFound;
int code;
int j = 0;
for (unsigned int i=0; i < s->length(); i++) {
unsigned char c = s->at(i);
if (c > 0x7F) { //need to decode
result += s->substr(j,i-j);
std::string part1 = s->substr(i,4);
for( unsigned int i = 0; i < s->length(); i++ )
{
unsigned char c = s->at( i );
if( c > 0x7F ) // need to decode
{
result += s->substr( j, i - j );
std::string part1 = s->substr( i, 4 );
int l;
code = decodeNum(part1, &l);
j = i+l;
code = decodeNum( part1, &l );
j = i + l;
i = j - 1;
notFound = true;
// 1 byte table
if (code > 0xff60 && code < 0xFFA0) {
result += code - CPOFFSET932; //translate from table
if( code > 0xff60 && code < 0xFFA0 )
{
result += code - CPOFFSET932; // translate from table
notFound = false;
}
if (notFound && ( code<0xF8 || (code>0x390 && code<0x542) ||
(code>0x200F && code<0x9FA1) || code>0xF928 )) {
for (int k=0; k<cpLenght; k++){
if(doubleTable[k][1] == code) {
if( notFound && ( code<0xF8 || (code>0x390 && code<0x542)
|| (code>0x200F && code<0x9FA1) || code>0xF928 ) )
{
for( int k = 0; k<cpLenght; k++ )
{
if( doubleTable[k][1] == code )
{
int data = doubleTable[k][0];
char d[3];
d[0] = data >> 8;
d[1] = data & 0xFF;
d[2]= '\0';
result += d; //translate from table
d[2] = '\0';
result += d; // translate from table
notFound = false;
break;
}
}
}
if (notFound)
result += decodeText(code);
} //direct conversion
if( notFound )
result += decodeText( code );
} // direct conversion
}
result += s->substr(j);
result += s->substr( j );
return result;
}
std::string DRW_Conv932Table::toUtf8(std::string *s) {
std::string DRW_Conv932Table::toUtf8( std::string* s )
{
std::string res;
string::iterator it;
for ( it=s->begin() ; it < s->end(); it++ ) {
std::string::iterator it;
for( it = s->begin(); it < s->end(); it++ )
{
bool notFound = true;
unsigned char c = *it;
if (c < 0x80) {
if( c < 0x80 )
{
notFound = false;
//check for \U+ encoded text
if (c == '\\') {
if (it+6 < s->end() && *(it+1) == 'U' && *(it+2) == '+') {
res += encodeText(std::string(it, it+7));
it +=6;
} else {
res +=c; //no \U+ encoded text write
// check for \U+ encoded text
if( c == '\\' )
{
if( it + 6 < s->end() && *(it + 1) == 'U' && *(it + 2) == '+' )
{
res += encodeText( std::string( it, it + 7 ) );
it += 6;
}
} else
res +=c; //c!='\' ascii char write
} else if(c > 0xA0 && c < 0xE0 ){//1 byte table
else
{
res += c; // no \U+ encoded text write
}
}
else
res += c; // c!='\' ascii char write
}
else if( c > 0xA0 && c < 0xE0 ) // 1 byte table
{
notFound = false;
res += encodeNum(c + CPOFFSET932); //translate from table
} else {//2 bytes
res += encodeNum( c + CPOFFSET932 ); // translate from table
}
else // 2 bytes
{
++it;
int code = (c << 8) | (unsigned char )(*it);
int code = (c << 8) | (unsigned char) (*it);
int sta;
int end=0;
if (c > 0x80 && c < 0xA0) {
sta = DRW_LeadTable932[c-0x81];
end = DRW_LeadTable932[c-0x80];
} else if (c > 0xDF && c < 0xFD){
sta = DRW_LeadTable932[c-0xC1];
end = DRW_LeadTable932[c-0xC0];
int end = 0;
if( c > 0x80 && c < 0xA0 )
{
sta = DRW_LeadTable932[c - 0x81];
end = DRW_LeadTable932[c - 0x80];
}
if (end > 0) {
for (int k=sta; k<end; k++){
if(DRW_DoubleTable932[k][0] == code) {
res += encodeNum(DRW_DoubleTable932[k][1]); //translate from table
else if( c > 0xDF && c < 0xFD )
{
sta = DRW_LeadTable932[c - 0xC1];
end = DRW_LeadTable932[c - 0xC0];
}
if( end > 0 )
{
for( int k = sta; k<end; k++ )
{
if( DRW_DoubleTable932[k][0] == code )
{
res += encodeNum( DRW_DoubleTable932[k][1] ); // translate from table
notFound = false;
break;
}
}
}
}
//not found
if (notFound) res += encodeNum(NOTFOUND932);
} //end for
// not found
if( notFound )
res += encodeNum( NOTFOUND932 );
} // end for
return res;
}
std::string DRW_TextCodec::correctCodePage(const std::string& s) {
//stringstream cause crash in OS/X, bug#3597944
std::string cp=s;
transform(cp.begin(), cp.end(), cp.begin(), toupper);
//Latin/Thai
if (cp=="ANSI_874" || cp=="CP874" || cp=="ISO8859-11" || cp=="TIS-620") {
std::string DRW_TextCodec::correctCodePage( const std::string& s )
{
// stringstream cause crash in OS/X, bug#3597944
std::string cp = s;
transform( cp.begin(), cp.end(), cp.begin(), toupper );
// Latin/Thai
if( cp=="ANSI_874" || cp=="CP874" || cp=="ISO8859-11" || cp=="TIS-620" )
{
return "ANSI_874";
//Central Europe and Eastern Europe
} else if (cp=="ANSI_1250" || cp=="CP1250" || cp=="ISO8859-2") {
// Central Europe and Eastern Europe
}
else if( cp=="ANSI_1250" || cp=="CP1250" || cp=="ISO8859-2" )
{
return "ANSI_1250";
//Cyrillic script
} else if (cp=="ANSI_1251" || cp=="CP1251" || cp=="ISO8859-5" || cp=="KOI8-R" ||
cp=="KOI8-U" || cp=="IBM 866") {
// Cyrillic script
}
else if( cp=="ANSI_1251" || cp=="CP1251" || cp=="ISO8859-5" || cp=="KOI8-R"
|| cp=="KOI8-U" || cp=="IBM 866" )
{
return "ANSI_1251";
//Western Europe
} else if (cp=="ANSI_1252" || cp=="CP1252" || cp=="LATIN1" || cp=="ISO-8859-1" ||
cp=="CP819" || cp=="CSISO" || cp=="IBM819" || cp=="ISO_8859-1" || cp=="APPLE ROMAN" ||
cp=="ISO8859-1" || cp=="ISO8859-15" || cp=="ISO-IR-100" || cp=="L1" || cp=="IBM 850") {
// Western Europe
}
else if( cp=="ANSI_1252" || cp=="CP1252" || cp=="LATIN1" || cp=="ISO-8859-1"
|| cp=="CP819" || cp=="CSISO" || cp=="IBM819" || cp=="ISO_8859-1" || cp=="APPLE ROMAN"
|| cp=="ISO8859-1" || cp=="ISO8859-15" || cp=="ISO-IR-100" || cp=="L1" || cp==
"IBM 850" )
{
return "ANSI_1252";
//Greek
} else if (cp=="ANSI_1253" || cp=="CP1253" || cp=="iso8859-7") {
// Greek
}
else if( cp=="ANSI_1253" || cp=="CP1253" || cp=="iso8859-7" )
{
return "ANSI_1253";
//Turkish
} else if (cp=="ANSI_1254" || cp=="CP1254" || cp=="iso8859-9" || cp=="iso8859-3") {
// Turkish
}
else if( cp=="ANSI_1254" || cp=="CP1254" || cp=="iso8859-9" || cp=="iso8859-3" )
{
return "ANSI_1254";
//Hebrew
} else if (cp=="ANSI_1255" || cp=="CP1255" || cp=="iso8859-8") {
// Hebrew
}
else if( cp=="ANSI_1255" || cp=="CP1255" || cp=="iso8859-8" )
{
return "ANSI_1255";
//Arabic
} else if (cp=="ANSI_1256" || cp=="CP1256" || cp=="ISO8859-6") {
// Arabic
}
else if( cp=="ANSI_1256" || cp=="CP1256" || cp=="ISO8859-6" )
{
return "ANSI_1256";
//Baltic
} else if (cp=="ANSI_1257" || cp=="CP1257" || cp=="ISO8859-4" || cp=="ISO8859-10" || cp=="ISO8859-13") {
// Baltic
}
else if( cp=="ANSI_1257" || cp=="CP1257" || cp=="ISO8859-4" || cp=="ISO8859-10" || cp==
"ISO8859-13" )
{
return "ANSI_1257";
//Vietnamese
} else if (cp=="ANSI_1258" || cp=="CP1258") {
// Vietnamese
}
else if( cp=="ANSI_1258" || cp=="CP1258" )
{
return "ANSI_1258";
//Japanese
} else if (cp=="ANSI_932" || cp=="SHIFT-JIS" || cp=="SHIFT_JIS" || cp=="CSSHIFTJIS" ||
cp=="CSWINDOWS31J" || cp=="MS_KANJI" || cp=="X-MS-CP932" || cp=="X-SJIS" ||
cp=="EUCJP" || cp=="EUC-JP" || cp=="CSEUCPKDFMTJAPANESE" || cp=="X-EUC" ||
cp=="X-EUC-JP" || cp=="JIS7") {
// Japanese
}
else if( cp=="ANSI_932" || cp=="SHIFT-JIS" || cp=="SHIFT_JIS" || cp=="CSSHIFTJIS"
|| cp=="CSWINDOWS31J" || cp=="MS_KANJI" || cp=="X-MS-CP932" || cp=="X-SJIS"
|| cp=="EUCJP" || cp=="EUC-JP" || cp=="CSEUCPKDFMTJAPANESE" || cp=="X-EUC"
|| cp=="X-EUC-JP" || cp=="JIS7" )
{
return "ANSI_932";
//Chinese PRC GBK (XGB) simplified
} 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=="ISO-IR-58" || cp=="GB18030") {
// Chinese PRC GBK (XGB) simplified
}
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=="ISO-IR-58" || cp=="GB18030" )
{
return "ANSI_936";
//Korean
} else if (cp=="ANSI_949" || cp=="EUCKR") {
// Korean
}
else if( cp=="ANSI_949" || cp=="EUCKR" )
{
return "ANSI_949";
//Chinese Big5 (Taiwan, Hong Kong SAR)
} else if (cp=="ANSI_950" || cp=="BIG5" || cp=="CN-BIG5" || cp=="CSBIG5" ||
cp=="X-X-BIG5" || cp=="BIG5-HKSCS") {
// Chinese Big5 (Taiwan, Hong Kong SAR)
}
else if( cp=="ANSI_950" || cp=="BIG5" || cp=="CN-BIG5" || cp=="CSBIG5"
|| cp=="X-X-BIG5" || cp=="BIG5-HKSCS" )
{
return "ANSI_950";
//celtic
// celtic
/* } else if (cp=="ISO8859-14") {
return "ISO8859-14";
} else if (cp=="TSCII") {
return "TSCII"; //tamil
} else if (cp=="UTF16") {
return "UTF16"; */
} else if (cp=="UTF-8" || cp=="UTF8" || cp=="UTF88-BIT") {
* return "ISO8859-14";
* } else if (cp=="TSCII") {
* return "TSCII"; //tamil
* } else if (cp=="UTF16") {
* return "UTF16"; */
}
else if( cp=="UTF-8" || cp=="UTF8" || cp=="UTF88-BIT" )
{
return "UTF-8";
}

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);
std::string correctCodePage( const std::string& s );
private:
int version;
std::string cp;
DRW_Converter *conv;
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;
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) {
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) {
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

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) {
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;
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;
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;
bool dxfReaderBinary::readInt32()
{
unsigned int* int32p;
char buffer[4];
filestr->read(buffer,4);
int32p = (unsigned int *) buffer;
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;
filestr->read( buffer, 8 );
int64p = (unsigned long long int*) buffer;
int64 = *int64p;
DBG(int64); DBG(" int64\n");
return (filestr->good());
DBG( int64 ); DBG( " int64\n" );
return filestr->good();
}
bool dxfReaderBinary::readDouble() {
double *result;
bool dxfReaderBinary::readDouble()
{
double* result;
char buffer[8];
filestr->read(buffer,8);
result = (double *) buffer;
filestr->read( buffer, 8 );
result = (double*) buffer;
doubleData = *result;
DBG(doubleData); DBG("\n");
return (filestr->good());
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,55 +15,61 @@
#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 ~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);
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();}
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::ifstream* filestr;
std::string strData;
double doubleData;
signed short intData; //16 bits integer
unsigned long long int int64; //64 bits integer
signed int intData; // 32 bits integer
unsigned long long int int64; // 64 bits integer
private:
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 readCode( int* code );
virtual bool readString( std::string* text );
virtual bool readString();
virtual bool readInt();
virtual bool readInt32();
@ -72,12 +78,13 @@ public:
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);
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();

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) {
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());
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) {
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());
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) {
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];
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) {
// 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);
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) {
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;
};
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

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 );
}
}
/* 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++ )
{
@ -2392,7 +2402,7 @@ bool dxfRW::processDxf()
DBG( "dxfRW::processDxf() start processing dxf\n" );
int code;
bool more = true;
string sectionstr;
std::string sectionstr;
// section = secUnknown;
while( reader->readRec( &code, !binary ) )
@ -2469,7 +2479,7 @@ bool dxfRW::processHeader()
{
DBG( "dxfRW::processHeader\n" );
int code;
string sectionstr;
std::string sectionstr;
while( reader->readRec( &code, !binary ) )
{
@ -2500,7 +2510,7 @@ bool dxfRW::processTables()
{
DBG( "dxfRW::processTables\n" );
int code;
string sectionstr;
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;
@ -2774,7 +2784,7 @@ bool dxfRW::processBlocks()
{
DBG( "dxfRW::processBlocks\n" );
int code;
string sectionstr;
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