dxf import: minor enhancements in dialog. Update libdfxw from git, and uncrustify it. add a test dfx file
This commit is contained in:
parent
f0b2565f12
commit
3e3869ed80
|
@ -18,8 +18,6 @@
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
|
|
||||||
using std::string;
|
|
||||||
|
|
||||||
#define UTF8STRING std::string
|
#define UTF8STRING std::string
|
||||||
#define DRW_UNUSED( x ) (void) x
|
#define DRW_UNUSED( x ) (void) x
|
||||||
|
|
||||||
|
@ -203,7 +201,7 @@ public:
|
||||||
// string codepage;
|
// string codepage;
|
||||||
private:
|
private:
|
||||||
// DRW_VarContent content;
|
// DRW_VarContent content;
|
||||||
string data;
|
std::string data;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -21,8 +21,6 @@
|
||||||
class dxfReader;
|
class dxfReader;
|
||||||
class DRW_Polyline;
|
class DRW_Polyline;
|
||||||
|
|
||||||
using std::string;
|
|
||||||
|
|
||||||
namespace DRW {
|
namespace DRW {
|
||||||
// ! Entity's type.
|
// ! Entity's type.
|
||||||
enum ETYPE {
|
enum ETYPE {
|
||||||
|
@ -123,7 +121,7 @@ public:
|
||||||
double ltypeScale; /*!< linetype scale, code 48 */
|
double ltypeScale; /*!< linetype scale, code 48 */
|
||||||
bool visible; /*!< entity visibility, code 60 */
|
bool visible; /*!< entity visibility, code 60 */
|
||||||
int color24; /*!< 24-bit color, code 420 */
|
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*/
|
int space; /*!< space indicator 0 = model, 1 paper, code 67*/
|
||||||
bool haveExtrusion; /*!< set to true if the entity have extrusion*/
|
bool haveExtrusion; /*!< set to true if the entity have extrusion*/
|
||||||
private:
|
private:
|
||||||
|
@ -891,17 +889,17 @@ public:
|
||||||
void parseCode( int code, dxfReader* reader );
|
void parseCode( int code, dxfReader* reader );
|
||||||
|
|
||||||
public:
|
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 vx; /*!< V-vector of single pixel, x coordinate, code 12 */
|
||||||
double vy; /*!< V-vector of single pixel, y coordinate, code 22 */
|
double vy; /*!< V-vector of single pixel, y coordinate, code 22 */
|
||||||
double vz; /*!< V-vector of single pixel, z coordinate, code 32 */
|
double vz; /*!< V-vector of single pixel, z coordinate, code 32 */
|
||||||
double sizeu; /*!< image size in pixels, U value, code 13 */
|
double sizeu; /*!< image size in pixels, U value, code 13 */
|
||||||
double sizev; /*!< image size in pixels, V value, code 23 */
|
double sizev; /*!< image size in pixels, V value, code 23 */
|
||||||
double dz; /*!< z coordinate, code 33 */
|
double dz; /*!< z coordinate, code 33 */
|
||||||
int clip; /*!< Clipping state, code 280, 0=off 1=on */
|
int clip; /*!< Clipping state, code 280, 0=off 1=on */
|
||||||
int brightness; /*!< Brightness value, code 281, (0-100) default 50 */
|
int brightness; /*!< Brightness value, code 281, (0-100) default 50 */
|
||||||
int contrast; /*!< Brightness value, code 282, (0-100) default 50 */
|
int contrast; /*!< Brightness value, code 282, (0-100) default 50 */
|
||||||
int fade; /*!< Brightness value, code 283, (0-100) default 0 */
|
int fade; /*!< Brightness value, code 283, (0-100) default 0 */
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -960,14 +958,14 @@ public:
|
||||||
void setDefPoint( const DRW_Coord p ) { defPoint = p; }
|
void setDefPoint( const DRW_Coord p ) { defPoint = p; }
|
||||||
DRW_Coord getTextPoint() const { return textPoint; } /*!< Middle point of text, code 11, 21 & 31 */
|
DRW_Coord getTextPoint() const { return textPoint; } /*!< Middle point of text, code 11, 21 & 31 */
|
||||||
void setTextPoint( const DRW_Coord p ) { textPoint = p; }
|
void setTextPoint( const DRW_Coord p ) { textPoint = p; }
|
||||||
string getStyle() const { return style; } /*!< Dimension style, code 3 */
|
std::string getStyle() const { return style; } /*!< Dimension style, code 3 */
|
||||||
void setStyle( const string s ) { style = s; }
|
void setStyle( const std::string s ) { style = s; }
|
||||||
int getAlign() const { return align; } /*!< attachment point, code 71 */
|
int getAlign() const { return align; } /*!< attachment point, code 71 */
|
||||||
void setAlign( const int a ) { align = a; }
|
void setAlign( const int a ) { align = a; }
|
||||||
int getTextLineStyle() const { return linesty; } /*!< Dimension text line spacing style, code 72, default 1 */
|
int getTextLineStyle() const { return linesty; } /*!< Dimension text line spacing style, code 72, default 1 */
|
||||||
void setTextLineStyle( const int l ) { linesty = l; }
|
void setTextLineStyle( const int l ) { linesty = l; }
|
||||||
string getText() const { return text; } /*!< Dimension text explicitly entered by the user, code 1 */
|
std::string getText() const { return text; } /*!< Dimension text explicitly entered by the user, code 1 */
|
||||||
void setText( const string t ) { text = t; }
|
void setText( const std::string t ) { text = t; }
|
||||||
double getTextLineFactor() const { return linefactor; } /*!< Dimension text line spacing factor, code 41, default 1? */
|
double getTextLineFactor() const { return linefactor; } /*!< Dimension text line spacing factor, code 41, default 1? */
|
||||||
void setTextLineFactor( const double l ) { linefactor = l; }
|
void setTextLineFactor( const double l ) { linefactor = l; }
|
||||||
double getDir() const { return rot; } /*!< rotation angle of the dimension text, code 53 (optional) default 0 */
|
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 */
|
DRW_Coord getExtrusion() { return extPoint; } /*!< extrusion, code 210, 220 & 230 */
|
||||||
void setExtrusion( const DRW_Coord p ) { extPoint = p; }
|
void setExtrusion( const DRW_Coord p ) { extPoint = p; }
|
||||||
string getName() { return name; } /*!< Name of the block that contains the entities, code 2 */
|
std::string getName() { return name; } /*!< Name of the block that contains the entities, code 2 */
|
||||||
void setName( const string s ) { name = s; }
|
void setName( const std::string s ) { name = s; }
|
||||||
// int getType(){ return type;} /*!< Dimension type, code 70 */
|
// int getType(){ return type;} /*!< Dimension type, code 70 */
|
||||||
protected:
|
protected:
|
||||||
DRW_Coord getPt2() const { return clonePoint; }
|
DRW_Coord getPt2() const { return clonePoint; }
|
||||||
|
@ -998,7 +996,7 @@ protected:
|
||||||
public:
|
public:
|
||||||
int type; /*!< Dimension type, code 70 */
|
int type; /*!< Dimension type, code 70 */
|
||||||
private:
|
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 defPoint; /*!< definition point, code 10, 20 & 30 (WCS) */
|
||||||
DRW_Coord textPoint; /*!< Middle point of text, code 11, 21 & 31 (OCS) */
|
DRW_Coord textPoint; /*!< Middle point of text, code 11, 21 & 31 (OCS) */
|
||||||
UTF8STRING text; /*!< Dimension text explicitly entered by the user, code 1 */
|
UTF8STRING text; /*!< Dimension text explicitly entered by the user, code 1 */
|
||||||
|
@ -1243,25 +1241,25 @@ public:
|
||||||
void parseCode( int code, dxfReader* reader );
|
void parseCode( int code, dxfReader* reader );
|
||||||
|
|
||||||
public:
|
public:
|
||||||
UTF8STRING style; /*!< Dimension style name, code 3 */
|
UTF8STRING style; /*!< Dimension style name, code 3 */
|
||||||
int arrow; /*!< Arrowhead flag, code 71, 0=Disabled; 1=Enabled */
|
int arrow; /*!< Arrowhead flag, code 71, 0=Disabled; 1=Enabled */
|
||||||
int leadertype; /*!< Leader path type, code 72, 0=Straight line segments; 1=Spline */
|
int leadertype; /*!< Leader path type, code 72, 0=Straight line segments; 1=Spline */
|
||||||
int flag; /*!< Leader creation flag, code 73, default 3 */
|
int flag; /*!< Leader creation flag, code 73, default 3 */
|
||||||
int hookline; /*!< Hook line direction flag, code 74, default 1 */
|
int hookline; /*!< Hook line direction flag, code 74, default 1 */
|
||||||
int hookflag; /*!< Hook line flag, code 75 */
|
int hookflag; /*!< Hook line flag, code 75 */
|
||||||
double textheight; /*!< Text annotation height, code 40 */
|
double textheight; /*!< Text annotation height, code 40 */
|
||||||
double textwidth; /*!< Text annotation width, code 41 */
|
double textwidth; /*!< Text annotation width, code 41 */
|
||||||
int vertnum; /*!< Number of vertices, code 76 */
|
int vertnum; /*!< Number of vertices, code 76 */
|
||||||
int coloruse; /*!< Color to use if leader's DIMCLRD = BYBLOCK, code 77 */
|
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 extrusionPoint; /*!< Normal vector, code 210, 220 & 230 */
|
||||||
DRW_Coord horizdir; /*!< "Horizontal" direction for leader, code 211, 221 & 231 */
|
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 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 */
|
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:
|
private:
|
||||||
DRW_Coord* vertexpoint; /*!< current control point to add data */
|
DRW_Coord* vertexpoint; /*!< current control point to add data */
|
||||||
};
|
};
|
||||||
|
|
||||||
// ! Class to handle viewport entity
|
// ! Class to handle viewport entity
|
||||||
|
|
|
@ -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() )
|
if( !comments.empty() )
|
||||||
comments += '\n';
|
comments += '\n';
|
||||||
|
@ -858,6 +858,9 @@ void DRW_Header::write( dxfWriter* writer, DRW::Version ver )
|
||||||
writer->writeString( 1, varStr );
|
writer->writeString( 1, varStr );
|
||||||
writer->setVersion( &varStr );
|
writer->setVersion( &varStr );
|
||||||
|
|
||||||
|
getStr( "$ACADVER", &varStr );
|
||||||
|
getStr( "$ACADMAINTVER", &varStr );
|
||||||
|
|
||||||
if( ver > DRW::AC1012 )
|
if( ver > DRW::AC1012 )
|
||||||
{
|
{
|
||||||
writer->writeString( 9, "$HANDSEED" );
|
writer->writeString( 9, "$HANDSEED" );
|
||||||
|
@ -970,6 +973,18 @@ void DRW_Header::write( dxfWriter* writer, DRW::Version ver )
|
||||||
else
|
else
|
||||||
writer->writeString( 7, "STANDARD" );
|
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" );
|
writer->writeString( 9, "$DIMASZ" );
|
||||||
|
|
||||||
if( getDouble( "$DIMASZ", &varDouble ) )
|
if( getDouble( "$DIMASZ", &varDouble ) )
|
||||||
|
@ -977,6 +992,13 @@ void DRW_Header::write( dxfWriter* writer, DRW::Version ver )
|
||||||
else
|
else
|
||||||
writer->writeDouble( 40, 2.5 );
|
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" );
|
writer->writeString( 9, "$DIMSCALE" );
|
||||||
|
|
||||||
if( getDouble( "$DIMSCALE", &varDouble ) )
|
if( getDouble( "$DIMSCALE", &varDouble ) )
|
||||||
|
@ -1210,16 +1232,20 @@ void DRW_Header::write( dxfWriter* writer, DRW::Version ver )
|
||||||
writer->writeDouble( 40, 0.0 );
|
writer->writeDouble( 40, 0.0 );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef DRW_DBG
|
||||||
std::map<std::string, DRW_Variant*>::const_iterator it;
|
std::map<std::string, DRW_Variant*>::const_iterator it;
|
||||||
|
|
||||||
for( it = vars.begin(); it != vars.end(); it++ )
|
for( it = vars.begin(); it != vars.end(); it++ )
|
||||||
{
|
{
|
||||||
|
// QString key = QString::fromStdString((*it).first);
|
||||||
std::cerr << (*it).first << std::endl;
|
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;
|
bool result = false;
|
||||||
std::map<std::string, DRW_Variant*>::iterator it;
|
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;
|
bool result = false;
|
||||||
std::map<std::string, DRW_Variant*>::iterator it;
|
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;
|
bool result = false;
|
||||||
std::map<std::string, DRW_Variant*>::iterator it;
|
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;
|
bool result = false;
|
||||||
std::map<std::string, DRW_Variant*>::iterator it;
|
std::map<std::string, DRW_Variant*>::iterator it;
|
||||||
|
|
|
@ -22,8 +22,6 @@
|
||||||
class dxfReader;
|
class dxfReader;
|
||||||
class dxfWriter;
|
class dxfWriter;
|
||||||
|
|
||||||
using std::string;
|
|
||||||
|
|
||||||
namespace DRW {
|
namespace DRW {
|
||||||
// ! Table entries type.
|
// ! Table entries type.
|
||||||
enum TTYPE {
|
enum TTYPE {
|
||||||
|
@ -241,8 +239,8 @@ public:
|
||||||
int color24; /*!< 24-bit color, code 420 */
|
int color24; /*!< 24-bit color, code 420 */
|
||||||
bool plotF; /*!< Plot flag, code 290 */
|
bool plotF; /*!< Plot flag, code 290 */
|
||||||
enum DRW_LW_Conv::lineWidth lWeight; /*!< layer lineweight, code 370 */
|
enum DRW_LW_Conv::lineWidth lWeight; /*!< layer lineweight, code 370 */
|
||||||
string handlePlotS; /*!< Hard-pointer ID/handle of plotstyle, code 390 */
|
std::string handlePlotS; /*!< Hard-pointer ID/handle of plotstyle, code 390 */
|
||||||
string handlePlotM; /*!< Hard-pointer ID/handle of materialstyle, code 347 */
|
std::string handlePlotM; /*!< Hard-pointer ID/handle of materialstyle, code 347 */
|
||||||
};
|
};
|
||||||
|
|
||||||
// ! Class to handle text style entries
|
// ! Class to handle text style entries
|
||||||
|
@ -359,7 +357,7 @@ public:
|
||||||
void parseCode( int code, dxfReader* reader );
|
void parseCode( int code, dxfReader* reader );
|
||||||
|
|
||||||
public:
|
public:
|
||||||
string handle; /*!< entity identifier, code 5 */
|
std::string handle; /*!< entity identifier, code 5 */
|
||||||
UTF8STRING name; /*!< File name of image, code 1 */
|
UTF8STRING name; /*!< File name of image, code 1 */
|
||||||
int version; /*!< class version, code 90, 0=R14 version */
|
int version; /*!< class version, code 90, 0=R14 version */
|
||||||
double u; /*!< image size in pixels U value, code 10 */
|
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 loaded; /*!< image is loaded flag, code 280, 0=unloaded, 1=loaded */
|
||||||
int resolution; /*!< resolution units, code 281, 0=no, 2=centimeters, 5=inch */
|
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 parseCode( int code, dxfReader* reader );
|
||||||
void write( dxfWriter* writer, DRW::Version ver );
|
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:
|
private:
|
||||||
bool getDouble( string key, double* varDouble );
|
bool getDouble( std::string key, double* varDouble );
|
||||||
bool getInt( string key, int* varInt );
|
bool getInt( std::string key, int* varInt );
|
||||||
bool getStr( string key, string* varStr );
|
bool getStr( std::string key, std::string* varStr );
|
||||||
bool getCoord( string key, DRW_Coord* varStr );
|
bool getCoord( std::string key, DRW_Coord* varStr );
|
||||||
|
|
||||||
public:
|
public:
|
||||||
std::map<string, DRW_Variant*> vars;
|
std::map<std::string, DRW_Variant*> vars;
|
||||||
private:
|
private:
|
||||||
string comments;
|
std::string comments;
|
||||||
string name;
|
std::string name;
|
||||||
DRW_Variant* curr;
|
DRW_Variant* curr;
|
||||||
int version; // to use on read
|
int version; // to use on read
|
||||||
};
|
};
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -10,75 +10,89 @@ class DRW_TextCodec
|
||||||
public:
|
public:
|
||||||
DRW_TextCodec();
|
DRW_TextCodec();
|
||||||
~DRW_TextCodec();
|
~DRW_TextCodec();
|
||||||
std::string fromUtf8(std::string s);
|
std::string fromUtf8( std::string s );
|
||||||
std::string toUtf8(std::string s);
|
std::string toUtf8( std::string s );
|
||||||
int getVersion(){return version;}
|
|
||||||
void setVersion(std::string *v);
|
int getVersion() { return version; }
|
||||||
void setVersion(int v){version = v;}
|
void setVersion( std::string* v );
|
||||||
void setCodePage(std::string *c);
|
|
||||||
void setCodePage(std::string c){setCodePage(&c);}
|
void setVersion( int v ) { version = v; }
|
||||||
std::string getCodePage(){return cp;}
|
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:
|
private:
|
||||||
std::string correctCodePage(const std::string& s);
|
int version;
|
||||||
|
std::string cp;
|
||||||
private:
|
DRW_Converter* conv;
|
||||||
int version;
|
|
||||||
std::string cp;
|
|
||||||
DRW_Converter *conv;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class DRW_Converter
|
class DRW_Converter
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
DRW_Converter(const int *t, int l){table = t;
|
DRW_Converter( const int* t, int l )
|
||||||
cpLenght = l;}
|
{
|
||||||
virtual ~DRW_Converter(){}
|
table = t;
|
||||||
virtual std::string fromUtf8(std::string *s) {return *s;}
|
cpLenght = l;
|
||||||
virtual std::string toUtf8(std::string *s);
|
}
|
||||||
std::string encodeText(std::string stmp);
|
|
||||||
std::string decodeText(int c);
|
virtual ~DRW_Converter() {}
|
||||||
std::string encodeNum(int c);
|
virtual std::string fromUtf8( std::string* s ) { return *s; }
|
||||||
int decodeNum(std::string s, int *b);
|
virtual std::string toUtf8( std::string* s );
|
||||||
const int *table;
|
std::string encodeText( std::string stmp );
|
||||||
int cpLenght;
|
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:
|
public:
|
||||||
DRW_ConvTable(const int *t, int l):DRW_Converter(t, l) {}
|
DRW_ConvTable( const int* t, int l ) : DRW_Converter( t, l ) {}
|
||||||
virtual std::string fromUtf8(std::string *s);
|
virtual std::string fromUtf8( std::string* s );
|
||||||
virtual std::string toUtf8(std::string *s);
|
virtual std::string toUtf8( std::string* s );
|
||||||
};
|
};
|
||||||
|
|
||||||
class DRW_ConvDBCSTable : public DRW_Converter {
|
class DRW_ConvDBCSTable : public DRW_Converter
|
||||||
|
{
|
||||||
public:
|
public:
|
||||||
DRW_ConvDBCSTable(const int *t, const int *lt, const int dt[][2], int l):DRW_Converter(t, l) {
|
DRW_ConvDBCSTable( const int* t, const int* lt, const int dt[][2], int l ) : DRW_Converter( t,
|
||||||
leadTable = lt;
|
l )
|
||||||
|
{
|
||||||
|
leadTable = lt;
|
||||||
doubleTable = dt;
|
doubleTable = dt;
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual std::string fromUtf8(std::string *s);
|
virtual std::string fromUtf8( std::string* s );
|
||||||
virtual std::string toUtf8(std::string *s);
|
virtual std::string toUtf8( std::string* s );
|
||||||
private:
|
|
||||||
const int *leadTable;
|
|
||||||
const int (*doubleTable)[2];
|
|
||||||
|
|
||||||
|
private:
|
||||||
|
const int* leadTable;
|
||||||
|
const int (*doubleTable)[2];
|
||||||
};
|
};
|
||||||
|
|
||||||
class DRW_Conv932Table : public DRW_Converter {
|
class DRW_Conv932Table : public DRW_Converter
|
||||||
|
{
|
||||||
public:
|
public:
|
||||||
DRW_Conv932Table(const int *t, const int *lt, const int dt[][2], int l):DRW_Converter(t, l) {
|
DRW_Conv932Table( const int* t, const int* lt, const int dt[][2], int l ) : DRW_Converter( t,
|
||||||
leadTable = lt;
|
l )
|
||||||
|
{
|
||||||
|
leadTable = lt;
|
||||||
doubleTable = dt;
|
doubleTable = dt;
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual std::string fromUtf8(std::string *s);
|
virtual std::string fromUtf8( std::string* s );
|
||||||
virtual std::string toUtf8(std::string *s);
|
virtual std::string toUtf8( std::string* s );
|
||||||
private:
|
|
||||||
const int *leadTable;
|
|
||||||
const int (*doubleTable)[2];
|
|
||||||
|
|
||||||
|
private:
|
||||||
|
const int* leadTable;
|
||||||
|
const int (*doubleTable)[2];
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // DRW_TEXTCODEC_H
|
#endif // DRW_TEXTCODEC_H
|
||||||
|
|
|
@ -18,246 +18,316 @@
|
||||||
#include "drw_textcodec.h"
|
#include "drw_textcodec.h"
|
||||||
|
|
||||||
#ifdef DRW_DBG
|
#ifdef DRW_DBG
|
||||||
#include <iostream> //for debug
|
#include <iostream> // for debug
|
||||||
#define DBG(a) std::cerr << a
|
#define DBG( a ) std::cerr << a
|
||||||
#else
|
#else
|
||||||
#define DBG(a)
|
#define DBG( a )
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
bool dxfReader::readRec(int *codeData, bool skip) {
|
bool dxfReader::readRec( int* codeData, bool skip )
|
||||||
// std::string text;
|
{
|
||||||
|
// std::string text;
|
||||||
int code;
|
int code;
|
||||||
|
|
||||||
#ifdef DRW_DBG
|
#ifdef DRW_DBG
|
||||||
count = count+2; //DBG
|
count = count + 2; // DBG
|
||||||
/* if (count > 10250)
|
/* if (count > 10250)
|
||||||
DBG("line 10256");*/
|
* DBG("line 10256");*/
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (!readCode(&code))
|
if( !readCode( &code ) )
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
*codeData = code;
|
*codeData = code;
|
||||||
|
|
||||||
if (code < 10)
|
if( code < 10 )
|
||||||
readString();
|
readString();
|
||||||
else if (code < 60)
|
else if( code < 60 )
|
||||||
readDouble();
|
readDouble();
|
||||||
else if (code < 80)
|
else if( code < 80 )
|
||||||
readInt();
|
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();
|
readInt32();
|
||||||
else if (code == 100 || code == 102 || code == 105)
|
else if( code == 100 || code == 102 || code == 105 )
|
||||||
readString();
|
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();
|
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();
|
readInt64();
|
||||||
else if (code < 180)
|
else if( code < 180 )
|
||||||
readInt();
|
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();
|
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();
|
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();
|
readBool();
|
||||||
else if (code < 370)
|
else if( code < 370 )
|
||||||
readString();
|
readString();
|
||||||
else if (code < 390)
|
else if( code < 390 )
|
||||||
readInt();
|
readInt();
|
||||||
else if (code < 400)
|
else if( code < 400 )
|
||||||
readString();
|
readString();
|
||||||
else if (code < 410)
|
else if( code < 410 )
|
||||||
readInt();
|
readInt();
|
||||||
else if (code < 420)
|
else if( code < 420 )
|
||||||
readString();
|
readString();
|
||||||
else if (code < 430) //TODO this is an int 32b
|
else if( code < 430 ) // TODO this is an int 32b
|
||||||
readInt32();
|
readInt32();
|
||||||
else if (code < 440)
|
else if( code < 440 )
|
||||||
readString();
|
readString();
|
||||||
else if (code < 450) //TODO this is an int 32b
|
else if( code < 450 ) // TODO this is an int 32b
|
||||||
readInt32();
|
readInt32();
|
||||||
else if (code < 460) //TODO this is long??
|
else if( code < 460 ) // TODO this is long??
|
||||||
readInt();
|
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();
|
readDouble();
|
||||||
else if (code < 481)
|
else if( code < 481 )
|
||||||
readString();
|
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();
|
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();
|
readDouble();
|
||||||
else if (code < 1071)
|
else if( code < 1071 )
|
||||||
readInt();
|
readInt();
|
||||||
else if (code == 1071) //TODO this is an int 32b
|
else if( code == 1071 ) // TODO this is an int 32b
|
||||||
readInt32();
|
readInt32();
|
||||||
else if (skip)
|
else if( skip )
|
||||||
//skip safely this dxf entry ( ok for ascii dxf)
|
// skip safely this dxf entry ( ok for ascii dxf)
|
||||||
readString();
|
readString();
|
||||||
else
|
else
|
||||||
//break in binary files because the conduct is unpredictable
|
// break in binary files because the conduct is unpredictable
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
return (filestr->good());
|
return filestr->good();
|
||||||
}
|
}
|
||||||
int dxfReader::getHandleString(){
|
|
||||||
|
|
||||||
|
int dxfReader::getHandleString()
|
||||||
|
{
|
||||||
int res;
|
int res;
|
||||||
|
|
||||||
#if defined(__APPLE__)
|
#if defined(__APPLE__)
|
||||||
int Succeeded = sscanf ( strData.c_str(), "%x", &res );
|
int Succeeded = sscanf( strData.c_str(), "%x", &res );
|
||||||
if ( !Succeeded || Succeeded == EOF )
|
|
||||||
|
if( !Succeeded || Succeeded == EOF )
|
||||||
res = 0;
|
res = 0;
|
||||||
|
|
||||||
#else
|
#else
|
||||||
std::istringstream Convert(strData);
|
std::istringstream Convert( strData );
|
||||||
if ( !(Convert >> std::hex >>res) )
|
|
||||||
|
if( !(Convert >> std::hex >> res) )
|
||||||
res = 0;
|
res = 0;
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool dxfReaderBinary::readCode(int *code) {
|
|
||||||
unsigned short *int16p;
|
bool dxfReaderBinary::readCode( int* code )
|
||||||
char buffer[2];
|
{
|
||||||
filestr->read(buffer,2);
|
unsigned short* int16p;
|
||||||
int16p = (unsigned short *) buffer;
|
char buffer[2];
|
||||||
//exist a 32bits int (code 90) with 2 bytes???
|
|
||||||
if ((*code == 90) && (*int16p>2000)){
|
filestr->read( buffer, 2 );
|
||||||
DBG(*code); DBG(" de 16bits\n");
|
int16p = (unsigned short*) buffer;
|
||||||
filestr->seekg(-4, std::ios_base::cur);
|
|
||||||
filestr->read(buffer,2);
|
// exist a 32bits int (code 90) with 2 bytes???
|
||||||
int16p = (unsigned short *) buffer;
|
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;
|
*code = *int16p;
|
||||||
DBG(*code); DBG("\n");
|
DBG( *code ); DBG( "\n" );
|
||||||
|
|
||||||
return (filestr->good());
|
return filestr->good();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool dxfReaderBinary::readString() {
|
|
||||||
std::getline(*filestr, strData, '\0');
|
bool dxfReaderBinary::readString()
|
||||||
DBG(strData); DBG("\n");
|
{
|
||||||
return (filestr->good());
|
std::getline( *filestr, strData, '\0' );
|
||||||
|
|
||||||
|
DBG( strData ); DBG( "\n" );
|
||||||
|
return filestr->good();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool dxfReaderBinary::readString(std::string *text) {
|
|
||||||
std::getline(*filestr, *text, '\0');
|
bool dxfReaderBinary::readString( std::string* text )
|
||||||
DBG(*text); DBG("\n");
|
{
|
||||||
return (filestr->good());
|
std::getline( *filestr, *text, '\0' );
|
||||||
|
|
||||||
|
DBG( *text ); DBG( "\n" );
|
||||||
|
return filestr->good();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool dxfReaderBinary::readInt() {
|
|
||||||
|
bool dxfReaderBinary::readInt()
|
||||||
|
{
|
||||||
char buffer[2];
|
char buffer[2];
|
||||||
filestr->read(buffer,2);
|
|
||||||
intData = (int)((buffer[1] << 8) | buffer[0]);
|
filestr->read( buffer, 2 );
|
||||||
DBG(intData); DBG("\n");
|
intData = (int) ( (buffer[1] << 8) | buffer[0] );
|
||||||
return (filestr->good());
|
DBG( intData ); DBG( "\n" );
|
||||||
|
return filestr->good();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool dxfReaderBinary::readInt32() {
|
|
||||||
unsigned int *int32p;
|
bool dxfReaderBinary::readInt32()
|
||||||
char buffer[4];
|
{
|
||||||
filestr->read(buffer,4);
|
unsigned int* int32p;
|
||||||
int32p = (unsigned int *) buffer;
|
char buffer[4];
|
||||||
|
|
||||||
|
filestr->read( buffer, 4 );
|
||||||
|
int32p = (unsigned int*) buffer;
|
||||||
intData = *int32p;
|
intData = *int32p;
|
||||||
DBG(intData); DBG("\n");
|
DBG( intData ); DBG( "\n" );
|
||||||
return (filestr->good());
|
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];
|
char buffer[8];
|
||||||
filestr->read(buffer,8);
|
|
||||||
int64p = (unsigned long long int *) buffer;
|
filestr->read( buffer, 8 );
|
||||||
int64 = *int64p;
|
int64p = (unsigned long long int*) buffer;
|
||||||
DBG(int64); DBG(" int64\n");
|
int64 = *int64p;
|
||||||
return (filestr->good());
|
DBG( int64 ); DBG( " int64\n" );
|
||||||
|
return filestr->good();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool dxfReaderBinary::readDouble() {
|
|
||||||
double *result;
|
bool dxfReaderBinary::readDouble()
|
||||||
char buffer[8];
|
{
|
||||||
filestr->read(buffer,8);
|
double* result;
|
||||||
result = (double *) buffer;
|
char buffer[8];
|
||||||
doubleData = *result;
|
|
||||||
DBG(doubleData); DBG("\n");
|
filestr->read( buffer, 8 );
|
||||||
return (filestr->good());
|
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];
|
char buffer[1];
|
||||||
filestr->read(buffer,1);
|
|
||||||
intData = (int)(buffer[0]);
|
filestr->read( buffer, 1 );
|
||||||
DBG(intData); DBG("\n");
|
intData = (int) (buffer[0]);
|
||||||
return (filestr->good());
|
DBG( intData ); DBG( "\n" );
|
||||||
|
return filestr->good();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool dxfReaderAscii::readCode(int *code) {
|
|
||||||
|
bool dxfReaderAscii::readCode( int* code )
|
||||||
|
{
|
||||||
std::string text;
|
std::string text;
|
||||||
std::getline(*filestr, text);
|
std::getline( *filestr, text );
|
||||||
*code = atoi(text.c_str());
|
|
||||||
DBG(*code); DBG("\n");
|
*code = atoi( text.c_str() );
|
||||||
return (filestr->good());
|
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());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool dxfReaderAscii::readString() {
|
|
||||||
std::getline(*filestr, strData);
|
bool dxfReaderAscii::readString( std::string* text )
|
||||||
if (!strData.empty() && strData.at(strData.size()-1) == '\r')
|
{
|
||||||
strData.erase(strData.size()-1);
|
std::getline( *filestr, *text );
|
||||||
DBG(strData); DBG("\n");
|
|
||||||
return (filestr->good());
|
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;
|
std::string text;
|
||||||
if (readString(&text)){
|
|
||||||
intData = atoi(text.c_str());
|
if( readString( &text ) )
|
||||||
DBG(intData); DBG("\n");
|
{
|
||||||
|
intData = atoi( text.c_str() );
|
||||||
|
DBG( intData ); DBG( "\n" );
|
||||||
return true;
|
return true;
|
||||||
} else
|
}
|
||||||
|
else
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool dxfReaderAscii::readInt32() {
|
|
||||||
|
bool dxfReaderAscii::readInt32()
|
||||||
|
{
|
||||||
return readInt();
|
return readInt();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool dxfReaderAscii::readInt64() {
|
|
||||||
|
bool dxfReaderAscii::readInt64()
|
||||||
|
{
|
||||||
return readInt();
|
return readInt();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool dxfReaderAscii::readDouble() {
|
|
||||||
|
bool dxfReaderAscii::readDouble()
|
||||||
|
{
|
||||||
std::string text;
|
std::string text;
|
||||||
if (readString(&text)){
|
|
||||||
|
if( readString( &text ) )
|
||||||
|
{
|
||||||
#if defined(__APPLE__)
|
#if defined(__APPLE__)
|
||||||
int succeeded=sscanf( & (text[0]), "%lg", &doubleData);
|
int succeeded = sscanf( &(text[0]), "%lg", &doubleData );
|
||||||
if(succeeded != 1) {
|
|
||||||
DBG("dxfReaderAscii::readDouble(): reading double error: ");
|
if( succeeded != 1 )
|
||||||
DBG(text);
|
{
|
||||||
DBG('\n');
|
DBG( "dxfReaderAscii::readDouble(): reading double error: " );
|
||||||
|
DBG( text );
|
||||||
|
DBG( '\n' );
|
||||||
}
|
}
|
||||||
|
|
||||||
#else
|
#else
|
||||||
std::istringstream sd(text);
|
std::istringstream sd( text );
|
||||||
sd >> doubleData;
|
sd >> doubleData;
|
||||||
DBG(doubleData); DBG('\n');
|
DBG( doubleData ); DBG( '\n' );
|
||||||
#endif
|
#endif
|
||||||
return true;
|
return true;
|
||||||
} else
|
}
|
||||||
|
else
|
||||||
return false;
|
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;
|
std::string text;
|
||||||
if (readString(&text)){
|
|
||||||
intData = atoi(text.c_str());
|
if( readString( &text ) )
|
||||||
DBG(intData); DBG("\n");
|
{
|
||||||
|
intData = atoi( text.c_str() );
|
||||||
|
DBG( intData ); DBG( "\n" );
|
||||||
return true;
|
return true;
|
||||||
} else
|
}
|
||||||
|
else
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -15,75 +15,82 @@
|
||||||
|
|
||||||
#include "drw_textcodec.h"
|
#include "drw_textcodec.h"
|
||||||
|
|
||||||
class dxfReader {
|
class dxfReader
|
||||||
|
{
|
||||||
public:
|
public:
|
||||||
dxfReader(std::ifstream *stream){
|
dxfReader( std::ifstream* stream )
|
||||||
|
{
|
||||||
filestr = stream;
|
filestr = stream;
|
||||||
#ifdef DRW_DBG
|
#ifdef DRW_DBG
|
||||||
count =0;
|
count = 0;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
virtual ~dxfReader(){}
|
|
||||||
virtual bool readCode(int *code) = 0; //return true if sucesful (not EOF)
|
virtual ~dxfReader() {}
|
||||||
virtual bool readString(std::string *text) = 0;
|
virtual bool readCode( int* code ) = 0; // return true if sucesful (not EOF)
|
||||||
virtual bool readString() = 0;
|
virtual bool readString( std::string* text ) = 0;
|
||||||
bool readRec(int *code, bool skip);
|
virtual bool readString() = 0;
|
||||||
virtual bool readInt() = 0;
|
bool readRec( int* code, bool skip );
|
||||||
virtual bool readInt32() = 0;
|
virtual bool readInt() = 0;
|
||||||
virtual bool readInt64() = 0;
|
virtual bool readInt32() = 0;
|
||||||
virtual bool readDouble() = 0;
|
virtual bool readInt64() = 0;
|
||||||
virtual bool readBool() = 0;
|
virtual bool readDouble() = 0;
|
||||||
std::string getString() {return strData;}
|
virtual bool readBool() = 0;
|
||||||
int getHandleString();//Convert hex string to int
|
|
||||||
std::string toUtf8String(std::string t) {return decoder.toUtf8(t);}
|
std::string getString() { return strData; }
|
||||||
std::string getUtf8String() {return decoder.toUtf8(strData);}
|
int getHandleString(); // Convert hex string to int
|
||||||
double getDouble() {return doubleData;}
|
|
||||||
int getInt32() {return intData;}
|
std::string toUtf8String( std::string t ) { return decoder.toUtf8( t ); }
|
||||||
unsigned long long int getInt64() {return int64;}
|
std::string getUtf8String() { return decoder.toUtf8( strData ); }
|
||||||
bool getBool() { return (intData==0) ? false : true;}
|
double getDouble() { return doubleData; }
|
||||||
int getVersion(){return decoder.getVersion();}
|
int getInt32() { return intData; }
|
||||||
void setVersion(std::string *v){decoder.setVersion(v);}
|
unsigned long long int getInt64() { return int64; }
|
||||||
void setCodePage(std::string *c){decoder.setCodePage(c);}
|
bool getBool() { return (intData==0) ? false : true; }
|
||||||
std::string getCodePage(){ return decoder.getCodePage();}
|
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
|
#ifdef DRW_DBG
|
||||||
int count;//DBG
|
int count; // DBG
|
||||||
#endif
|
#endif
|
||||||
protected:
|
protected:
|
||||||
std::ifstream *filestr;
|
std::ifstream* filestr;
|
||||||
std::string strData;
|
std::string strData;
|
||||||
double doubleData;
|
double doubleData;
|
||||||
signed short intData; //16 bits integer
|
signed int intData; // 32 bits integer
|
||||||
unsigned long long int int64; //64 bits integer
|
unsigned long long int int64; // 64 bits integer
|
||||||
private:
|
private:
|
||||||
DRW_TextCodec decoder;
|
DRW_TextCodec decoder;
|
||||||
};
|
};
|
||||||
|
|
||||||
class dxfReaderBinary : public dxfReader {
|
class dxfReaderBinary : public dxfReader
|
||||||
|
{
|
||||||
public:
|
public:
|
||||||
dxfReaderBinary(std::ifstream *stream):dxfReader(stream){ }
|
dxfReaderBinary( std::ifstream* stream ) : dxfReader( stream ) { }
|
||||||
virtual ~dxfReaderBinary() {}
|
virtual ~dxfReaderBinary() {}
|
||||||
virtual bool readCode(int *code);
|
virtual bool readCode( int* code );
|
||||||
virtual bool readString(std::string *text);
|
virtual bool readString( std::string* text );
|
||||||
virtual bool readString();
|
virtual bool readString();
|
||||||
virtual bool readInt();
|
virtual bool readInt();
|
||||||
virtual bool readInt32();
|
virtual bool readInt32();
|
||||||
virtual bool readInt64();
|
virtual bool readInt64();
|
||||||
virtual bool readDouble();
|
virtual bool readDouble();
|
||||||
virtual bool readBool();
|
virtual bool readBool();
|
||||||
};
|
};
|
||||||
|
|
||||||
class dxfReaderAscii : public dxfReader {
|
class dxfReaderAscii : public dxfReader
|
||||||
|
{
|
||||||
public:
|
public:
|
||||||
dxfReaderAscii(std::ifstream *stream):dxfReader(stream){ }
|
dxfReaderAscii( std::ifstream* stream ) : dxfReader( stream ) { }
|
||||||
virtual ~dxfReaderAscii(){}
|
virtual ~dxfReaderAscii() {}
|
||||||
virtual bool readCode(int *code);
|
virtual bool readCode( int* code );
|
||||||
virtual bool readString(std::string *text);
|
virtual bool readString( std::string* text );
|
||||||
virtual bool readString();
|
virtual bool readString();
|
||||||
virtual bool readInt();
|
virtual bool readInt();
|
||||||
virtual bool readDouble();
|
virtual bool readDouble();
|
||||||
virtual bool readInt32();
|
virtual bool readInt32();
|
||||||
virtual bool readInt64();
|
virtual bool readInt64();
|
||||||
virtual bool readBool();
|
virtual bool readBool();
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // DXFREADER_H
|
#endif // DXFREADER_H
|
||||||
|
|
|
@ -17,265 +17,303 @@
|
||||||
#include "dxfwriter.h"
|
#include "dxfwriter.h"
|
||||||
|
|
||||||
#ifdef DRW_DBG
|
#ifdef DRW_DBG
|
||||||
#include <iostream> //for debug
|
#include <iostream> // for debug
|
||||||
#define DBG(a) std::cerr << a
|
#define DBG( a ) std::cerr << a
|
||||||
#else
|
#else
|
||||||
#define DBG(a)
|
#define DBG( a )
|
||||||
#endif
|
#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) {
|
/*bool dxfWriter::readRec(int *codeData, bool skip) {
|
||||||
// std::string text;
|
* // std::string text;
|
||||||
int code;
|
* 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
|
bool dxfWriter::writeUtf8String( int code, std::string text )
|
||||||
count = count+2; //DBG
|
{
|
||||||
#endif
|
std::string t = encoder.fromUtf8( text );
|
||||||
|
|
||||||
if (!readCode(&code))
|
return writeString( code, t );
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool dxfWriter::writeUtf8Caps(int code, std::string text) {
|
|
||||||
|
bool dxfWriter::writeUtf8Caps( int code, std::string text )
|
||||||
|
{
|
||||||
std::string strname = text;
|
std::string strname = text;
|
||||||
std::transform(strname.begin(), strname.end(), strname.begin(),::toupper);
|
std::transform( strname.begin(), strname.end(), strname.begin(), ::toupper );
|
||||||
std::string t = encoder.fromUtf8(strname);
|
std::string t = encoder.fromUtf8( strname );
|
||||||
return writeString(code, t);
|
|
||||||
|
return writeString( code, t );
|
||||||
}
|
}
|
||||||
|
|
||||||
bool dxfWriterBinary::writeString(int code, std::string text) {
|
|
||||||
|
bool dxfWriterBinary::writeString( int code, std::string text )
|
||||||
|
{
|
||||||
char bufcode[2];
|
char bufcode[2];
|
||||||
bufcode[0] =code & 0xFF;
|
|
||||||
bufcode[1] =code >> 8;
|
bufcode[0] = code & 0xFF;
|
||||||
filestr->write(bufcode, 2);
|
bufcode[1] = code >> 8;
|
||||||
|
filestr->write( bufcode, 2 );
|
||||||
*filestr << text << '\0';
|
*filestr << text << '\0';
|
||||||
return (filestr->good());
|
return filestr->good();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*bool dxfWriterBinary::readCode(int *code) {
|
/*bool dxfWriterBinary::readCode(int *code) {
|
||||||
unsigned short *int16p;
|
* unsigned short *int16p;
|
||||||
char buffer[2];
|
* char buffer[2];
|
||||||
filestr->read(buffer,2);
|
* filestr->read(buffer,2);
|
||||||
int16p = (unsigned short *) buffer;
|
* int16p = (unsigned short *) buffer;
|
||||||
//exist a 32bits int (code 90) with 2 bytes???
|
* //exist a 32bits int (code 90) with 2 bytes???
|
||||||
if ((*code == 90) && (*int16p>2000)){
|
* if ((*code == 90) && (*int16p>2000)){
|
||||||
DBG(*code); DBG(" de 16bits\n");
|
* DBG(*code); DBG(" de 16bits\n");
|
||||||
filestr->seekg(-4, std::ios_base::cur);
|
* filestr->seekg(-4, std::ios_base::cur);
|
||||||
filestr->read(buffer,2);
|
* filestr->read(buffer,2);
|
||||||
int16p = (unsigned short *) buffer;
|
* int16p = (unsigned short *) buffer;
|
||||||
}
|
* }
|
||||||
*code = *int16p;
|
* code = *int16p;
|
||||||
DBG(*code); DBG("\n");
|
* DBG(*code); DBG("\n");
|
||||||
|
*
|
||||||
return (filestr->good());
|
* return (filestr->good());
|
||||||
}*/
|
* }*/
|
||||||
|
|
||||||
/*bool dxfWriterBinary::readString() {
|
/*bool dxfWriterBinary::readString() {
|
||||||
std::getline(*filestr, strData, '\0');
|
* std::getline(*filestr, strData, '\0');
|
||||||
DBG(strData); DBG("\n");
|
* DBG(strData); DBG("\n");
|
||||||
return (filestr->good());
|
* return (filestr->good());
|
||||||
}*/
|
* }*/
|
||||||
|
|
||||||
/*bool dxfWriterBinary::readString(std::string *text) {
|
/*bool dxfWriterBinary::readString(std::string *text) {
|
||||||
std::getline(*filestr, *text, '\0');
|
* std::getline(*filestr, *text, '\0');
|
||||||
DBG(*text); DBG("\n");
|
* DBG(*text); DBG("\n");
|
||||||
return (filestr->good());
|
* return (filestr->good());
|
||||||
}*/
|
* }*/
|
||||||
|
|
||||||
bool dxfWriterBinary::writeInt16(int code, int data) {
|
bool dxfWriterBinary::writeInt16( int code, int data )
|
||||||
char bufcode[2];
|
{
|
||||||
char buffer[2];
|
char bufcode[2];
|
||||||
bufcode[0] =code & 0xFF;
|
char buffer[2];
|
||||||
bufcode[1] =code >> 8;
|
|
||||||
buffer[0] =data & 0xFF;
|
bufcode[0] = code & 0xFF;
|
||||||
buffer[1] =data >> 8;
|
bufcode[1] = code >> 8;
|
||||||
filestr->write(bufcode, 2);
|
buffer[0] = data & 0xFF;
|
||||||
filestr->write(buffer, 2);
|
buffer[1] = data >> 8;
|
||||||
return (filestr->good());
|
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];
|
char buffer[4];
|
||||||
buffer[0] =code & 0xFF;
|
|
||||||
buffer[1] =code >> 8;
|
|
||||||
filestr->write(buffer, 2);
|
|
||||||
|
|
||||||
buffer[0] =data & 0xFF;
|
buffer[0] = code & 0xFF;
|
||||||
buffer[1] =data >> 8;
|
buffer[1] = code >> 8;
|
||||||
buffer[2] =data >> 16;
|
filestr->write( buffer, 2 );
|
||||||
buffer[3] =data >> 24;
|
|
||||||
filestr->write(buffer, 4);
|
buffer[0] = data & 0xFF;
|
||||||
return (filestr->good());
|
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;
|
bool dxfWriterBinary::writeInt64( int code, unsigned long long int data )
|
||||||
buffer[1] =data >> 8;
|
{
|
||||||
buffer[2] =data >> 16;
|
char buffer[8];
|
||||||
buffer[3] =data >> 24;
|
|
||||||
buffer[4] =data >> 32;
|
buffer[0] = code & 0xFF;
|
||||||
buffer[5] =data >> 40;
|
buffer[1] = code >> 8;
|
||||||
buffer[6] =data >> 48;
|
filestr->write( buffer, 2 );
|
||||||
buffer[7] =data >> 56;
|
|
||||||
filestr->write(buffer, 8);
|
buffer[0] = data & 0xFF;
|
||||||
return (filestr->good());
|
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;
|
bool dxfWriterBinary::writeDouble( int code, double data )
|
||||||
val = (unsigned char *) &data;
|
{
|
||||||
for (int i=0; i<8; i++) {
|
char bufcode[2];
|
||||||
buffer[i] =val[i];
|
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) {
|
// saved as int or add a bool member??
|
||||||
char buffer[1];
|
bool dxfWriterBinary::writeBool( int code, bool data )
|
||||||
char bufcode[2];
|
{
|
||||||
bufcode[0] =code & 0xFF;
|
char buffer[1];
|
||||||
bufcode[1] =code >> 8;
|
char bufcode[2];
|
||||||
filestr->write(bufcode, 2);
|
|
||||||
|
bufcode[0] = code & 0xFF;
|
||||||
|
bufcode[1] = code >> 8;
|
||||||
|
filestr->write( bufcode, 2 );
|
||||||
buffer[0] = data;
|
buffer[0] = data;
|
||||||
filestr->write(buffer, 1);
|
filestr->write( buffer, 1 );
|
||||||
return (filestr->good());
|
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');
|
/* std::getline(*filestr, strData, '\0');
|
||||||
DBG(strData); DBG("\n");*/
|
* DBG(strData); DBG("\n");*/
|
||||||
return (filestr->good());
|
return filestr->good();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*bool dxfWriterAscii::readCode(int *code) {
|
/*bool dxfWriterAscii::readCode(int *code) {
|
||||||
std::string text;
|
* std::string text;
|
||||||
std::getline(*filestr, text);
|
* std::getline(*filestr, text);
|
||||||
*code = atoi(text.c_str());
|
* code = atoi(text.c_str());
|
||||||
DBG(*code); DBG("\n");
|
* DBG(*code); DBG("\n");
|
||||||
return (filestr->good());
|
* return (filestr->good());
|
||||||
}*/
|
* }*/
|
||||||
/*bool dxfWriterAscii::readString(std::string *text) {
|
/*bool dxfWriterAscii::readString(std::string *text) {
|
||||||
std::getline(*filestr, *text);
|
* std::getline(*filestr, *text);
|
||||||
if (text->at(text->size()-1) == '\r')
|
* if (text->at(text->size()-1) == '\r')
|
||||||
text->erase(text->size()-1);
|
* text->erase(text->size()-1);
|
||||||
return (filestr->good());
|
* return (filestr->good());
|
||||||
}*/
|
* }*/
|
||||||
|
|
||||||
/*bool dxfWriterAscii::readString() {
|
/*bool dxfWriterAscii::readString() {
|
||||||
std::getline(*filestr, strData);
|
* std::getline(*filestr, strData);
|
||||||
if (strData.at(strData.size()-1) == '\r')
|
* if (strData.at(strData.size()-1) == '\r')
|
||||||
strData.erase(strData.size()-1);
|
* strData.erase(strData.size()-1);
|
||||||
DBG(strData); DBG("\n");
|
* DBG(strData); DBG("\n");
|
||||||
return (filestr->good());
|
* 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 << "\r\n" << data << "\r\n";
|
||||||
*filestr << code << std::endl << data << std::endl;
|
*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;
|
*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();
|
std::streamsize prec = filestr->precision();
|
||||||
filestr->precision(12);
|
|
||||||
|
filestr->precision( 12 );
|
||||||
*filestr << code << std::endl << data << std::endl;
|
*filestr << code << std::endl << data << std::endl;
|
||||||
filestr->precision(prec);
|
filestr->precision( prec );
|
||||||
return (filestr->good());
|
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();
|
||||||
|
}
|
||||||
|
|
|
@ -15,50 +15,55 @@
|
||||||
|
|
||||||
#include "drw_textcodec.h"
|
#include "drw_textcodec.h"
|
||||||
|
|
||||||
class dxfWriter {
|
class dxfWriter
|
||||||
|
{
|
||||||
public:
|
public:
|
||||||
dxfWriter(std::ofstream *stream){filestr = stream; /*count =0;*/}
|
dxfWriter( std::ofstream* stream ) { filestr = stream; /*count =0;*/ }
|
||||||
virtual ~dxfWriter(){}
|
virtual ~dxfWriter() {}
|
||||||
virtual bool writeString(int code, std::string text) = 0;
|
virtual bool writeString( int code, std::string text ) = 0;
|
||||||
bool writeUtf8String(int code, std::string text);
|
bool writeUtf8String( int code, std::string text );
|
||||||
bool writeUtf8Caps(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;
|
std::string fromUtf8String( std::string t ) { return encoder.fromUtf8( t ); }
|
||||||
virtual bool writeInt32(int code, int data) = 0;
|
virtual bool writeInt16( int code, int data ) = 0;
|
||||||
virtual bool writeInt64(int code, unsigned long long int data) = 0;
|
virtual bool writeInt32( int code, int data ) = 0;
|
||||||
virtual bool writeDouble(int code, double data) = 0;
|
virtual bool writeInt64( int code, unsigned long long int data ) = 0;
|
||||||
virtual bool writeBool(int code, bool data) = 0;
|
virtual bool writeDouble( int code, double data ) = 0;
|
||||||
void setVersion(std::string *v){encoder.setVersion(v);}
|
virtual bool writeBool( int code, bool data ) = 0;
|
||||||
void setCodePage(std::string *c){encoder.setCodePage(c);}
|
|
||||||
std::string getCodePage(){return encoder.getCodePage();}
|
void setVersion( std::string* v ) { encoder.setVersion( v ); }
|
||||||
|
void setCodePage( std::string* c ) { encoder.setCodePage( c ); }
|
||||||
|
std::string getCodePage() { return encoder.getCodePage(); }
|
||||||
protected:
|
protected:
|
||||||
std::ofstream *filestr;
|
std::ofstream* filestr;
|
||||||
private:
|
private:
|
||||||
DRW_TextCodec encoder;
|
DRW_TextCodec encoder;
|
||||||
};
|
};
|
||||||
|
|
||||||
class dxfWriterBinary : public dxfWriter {
|
class dxfWriterBinary : public dxfWriter
|
||||||
|
{
|
||||||
public:
|
public:
|
||||||
dxfWriterBinary(std::ofstream *stream):dxfWriter(stream){ }
|
dxfWriterBinary( std::ofstream* stream ) : dxfWriter( stream ) { }
|
||||||
virtual ~dxfWriterBinary() {}
|
virtual ~dxfWriterBinary() {}
|
||||||
virtual bool writeString(int code, std::string text);
|
virtual bool writeString( int code, std::string text );
|
||||||
virtual bool writeInt16(int code, int data);
|
virtual bool writeInt16( int code, int data );
|
||||||
virtual bool writeInt32(int code, int data);
|
virtual bool writeInt32( int code, int data );
|
||||||
virtual bool writeInt64(int code, unsigned long long int data);
|
virtual bool writeInt64( int code, unsigned long long int data );
|
||||||
virtual bool writeDouble(int code, double data);
|
virtual bool writeDouble( int code, double data );
|
||||||
virtual bool writeBool(int code, bool data);
|
virtual bool writeBool( int code, bool data );
|
||||||
};
|
};
|
||||||
|
|
||||||
class dxfWriterAscii : public dxfWriter {
|
class dxfWriterAscii : public dxfWriter
|
||||||
|
{
|
||||||
public:
|
public:
|
||||||
dxfWriterAscii(std::ofstream *stream):dxfWriter(stream){ }
|
dxfWriterAscii( std::ofstream* stream ) : dxfWriter( stream ) { }
|
||||||
virtual ~dxfWriterAscii(){}
|
virtual ~dxfWriterAscii() {}
|
||||||
virtual bool writeString(int code, std::string text);
|
virtual bool writeString( int code, std::string text );
|
||||||
virtual bool writeInt16(int code, int data);
|
virtual bool writeInt16( int code, int data );
|
||||||
virtual bool writeInt32(int code, int data);
|
virtual bool writeInt32( int code, int data );
|
||||||
virtual bool writeInt64(int code, unsigned long long int data);
|
virtual bool writeInt64( int code, unsigned long long int data );
|
||||||
virtual bool writeDouble(int code, double data);
|
virtual bool writeDouble( int code, double data );
|
||||||
virtual bool writeBool(int code, bool data);
|
virtual bool writeBool( int code, bool data );
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // DXFWRITER_H
|
#endif // DXFWRITER_H
|
||||||
|
|
|
@ -215,7 +215,7 @@ bool dxfRW::writeEntity( DRW_Entity* ent )
|
||||||
|
|
||||||
bool dxfRW::writeLineType( DRW_LType* ent )
|
bool dxfRW::writeLineType( DRW_LType* ent )
|
||||||
{
|
{
|
||||||
string strname = ent->name;
|
std::string strname = ent->name;
|
||||||
|
|
||||||
transform( strname.begin(), strname.end(), strname.begin(), ::toupper );
|
transform( strname.begin(), strname.end(), strname.begin(), ::toupper );
|
||||||
|
|
||||||
|
@ -1322,7 +1322,12 @@ bool dxfRW::writeDimension( DRW_Dimension* ent )
|
||||||
writer->writeString( 0, "DIMENSION" );
|
writer->writeString( 0, "DIMENSION" );
|
||||||
writeEntity( ent );
|
writeEntity( ent );
|
||||||
writer->writeString( 100, "AcDbDimension" );
|
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( 10, ent->getDefPoint().x );
|
||||||
writer->writeDouble( 20, ent->getDefPoint().y );
|
writer->writeDouble( 20, ent->getDefPoint().y );
|
||||||
writer->writeDouble( 30, ent->getDefPoint().z );
|
writer->writeDouble( 30, ent->getDefPoint().z );
|
||||||
|
@ -2129,8 +2134,13 @@ bool dxfRW::writeTables()
|
||||||
writer->writeInt16( 280, 1 );
|
writer->writeInt16( 280, 1 );
|
||||||
writer->writeInt16( 281, 0 );
|
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" );
|
writer->writeString( 0, "ENDTAB" );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2312,7 +2322,7 @@ bool dxfRW::writeObjects()
|
||||||
for( unsigned int i = 0; i<imageDef.size(); i++ )
|
for( unsigned int i = 0; i<imageDef.size(); i++ )
|
||||||
{
|
{
|
||||||
DRW_ImageDef* id = imageDef.at( 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++ )
|
for( it = id->reactors.begin(); it != id->reactors.end(); it++ )
|
||||||
{
|
{
|
||||||
|
@ -2356,7 +2366,7 @@ bool dxfRW::writeObjects()
|
||||||
}
|
}
|
||||||
|
|
||||||
writer->writeString( 102, "{ACAD_REACTORS" );
|
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++ )
|
for( it = id->reactors.begin(); it != id->reactors.end(); it++ )
|
||||||
{
|
{
|
||||||
|
@ -2390,9 +2400,9 @@ bool dxfRW::writeObjects()
|
||||||
bool dxfRW::processDxf()
|
bool dxfRW::processDxf()
|
||||||
{
|
{
|
||||||
DBG( "dxfRW::processDxf() start processing dxf\n" );
|
DBG( "dxfRW::processDxf() start processing dxf\n" );
|
||||||
int code;
|
int code;
|
||||||
bool more = true;
|
bool more = true;
|
||||||
string sectionstr;
|
std::string sectionstr;
|
||||||
|
|
||||||
// section = secUnknown;
|
// section = secUnknown;
|
||||||
while( reader->readRec( &code, !binary ) )
|
while( reader->readRec( &code, !binary ) )
|
||||||
|
@ -2468,8 +2478,8 @@ bool dxfRW::processDxf()
|
||||||
bool dxfRW::processHeader()
|
bool dxfRW::processHeader()
|
||||||
{
|
{
|
||||||
DBG( "dxfRW::processHeader\n" );
|
DBG( "dxfRW::processHeader\n" );
|
||||||
int code;
|
int code;
|
||||||
string sectionstr;
|
std::string sectionstr;
|
||||||
|
|
||||||
while( reader->readRec( &code, !binary ) )
|
while( reader->readRec( &code, !binary ) )
|
||||||
{
|
{
|
||||||
|
@ -2499,9 +2509,9 @@ bool dxfRW::processHeader()
|
||||||
bool dxfRW::processTables()
|
bool dxfRW::processTables()
|
||||||
{
|
{
|
||||||
DBG( "dxfRW::processTables\n" );
|
DBG( "dxfRW::processTables\n" );
|
||||||
int code;
|
int code;
|
||||||
string sectionstr;
|
std::string sectionstr;
|
||||||
bool more = true;
|
bool more = true;
|
||||||
|
|
||||||
while( reader->readRec( &code, !binary ) )
|
while( reader->readRec( &code, !binary ) )
|
||||||
{
|
{
|
||||||
|
@ -2579,7 +2589,7 @@ bool dxfRW::processLType()
|
||||||
{
|
{
|
||||||
DBG( "dxfRW::processLType\n" );
|
DBG( "dxfRW::processLType\n" );
|
||||||
int code;
|
int code;
|
||||||
string sectionstr;
|
std::string sectionstr;
|
||||||
bool reading = false;
|
bool reading = false;
|
||||||
DRW_LType ltype;
|
DRW_LType ltype;
|
||||||
|
|
||||||
|
@ -2620,7 +2630,7 @@ bool dxfRW::processLayer()
|
||||||
{
|
{
|
||||||
DBG( "dxfRW::processLayer\n" );
|
DBG( "dxfRW::processLayer\n" );
|
||||||
int code;
|
int code;
|
||||||
string sectionstr;
|
std::string sectionstr;
|
||||||
bool reading = false;
|
bool reading = false;
|
||||||
DRW_Layer layer;
|
DRW_Layer layer;
|
||||||
|
|
||||||
|
@ -2658,7 +2668,7 @@ bool dxfRW::processDimStyle()
|
||||||
{
|
{
|
||||||
DBG( "dxfRW::processDimStyle" );
|
DBG( "dxfRW::processDimStyle" );
|
||||||
int code;
|
int code;
|
||||||
string sectionstr;
|
std::string sectionstr;
|
||||||
bool reading = false;
|
bool reading = false;
|
||||||
DRW_Dimstyle dimSty;
|
DRW_Dimstyle dimSty;
|
||||||
|
|
||||||
|
@ -2696,7 +2706,7 @@ bool dxfRW::processTextStyle()
|
||||||
{
|
{
|
||||||
DBG( "dxfRW::processTextStyle" );
|
DBG( "dxfRW::processTextStyle" );
|
||||||
int code;
|
int code;
|
||||||
string sectionstr;
|
std::string sectionstr;
|
||||||
bool reading = false;
|
bool reading = false;
|
||||||
DRW_Textstyle TxtSty;
|
DRW_Textstyle TxtSty;
|
||||||
|
|
||||||
|
@ -2734,7 +2744,7 @@ bool dxfRW::processVports()
|
||||||
{
|
{
|
||||||
DBG( "dxfRW::processVports" );
|
DBG( "dxfRW::processVports" );
|
||||||
int code;
|
int code;
|
||||||
string sectionstr;
|
std::string sectionstr;
|
||||||
bool reading = false;
|
bool reading = false;
|
||||||
DRW_Vport vp;
|
DRW_Vport vp;
|
||||||
|
|
||||||
|
@ -2773,8 +2783,8 @@ bool dxfRW::processVports()
|
||||||
bool dxfRW::processBlocks()
|
bool dxfRW::processBlocks()
|
||||||
{
|
{
|
||||||
DBG( "dxfRW::processBlocks\n" );
|
DBG( "dxfRW::processBlocks\n" );
|
||||||
int code;
|
int code;
|
||||||
string sectionstr;
|
std::string sectionstr;
|
||||||
|
|
||||||
while( reader->readRec( &code, !binary ) )
|
while( reader->readRec( &code, !binary ) )
|
||||||
{
|
{
|
||||||
|
|
|
@ -127,7 +127,7 @@ private:
|
||||||
DRW_Interface* iface;
|
DRW_Interface* iface;
|
||||||
DRW_Header header;
|
DRW_Header header;
|
||||||
// int section;
|
// int section;
|
||||||
string nextentity;
|
std::string nextentity;
|
||||||
int entCount;
|
int entCount;
|
||||||
bool wlayer0;
|
bool wlayer0;
|
||||||
bool dimstyleStd;
|
bool dimstyleStd;
|
||||||
|
|
|
@ -27,16 +27,25 @@
|
||||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <appl_wxstruct.h>
|
||||||
#include <dxf2brd_items.h>
|
#include <dxf2brd_items.h>
|
||||||
#include <wxPcbStruct.h>
|
#include <wxPcbStruct.h>
|
||||||
#include <convert_from_iu.h>
|
#include <convert_from_iu.h>
|
||||||
#include <dialog_dxf_import_base.h>
|
#include <dialog_dxf_import_base.h>
|
||||||
#include <class_pcb_layer_box_selector.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
|
class DIALOG_DXF_IMPORT : public DIALOG_DXF_IMPORT_BASE
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
PCB_EDIT_FRAME * m_parent;
|
PCB_EDIT_FRAME * m_parent;
|
||||||
|
wxConfig* m_config; // Current config
|
||||||
|
|
||||||
static wxString m_dxfFilename;
|
static wxString m_dxfFilename;
|
||||||
static int m_offsetSelection;
|
static int m_offsetSelection;
|
||||||
static LAYER_NUM m_layer;
|
static LAYER_NUM m_layer;
|
||||||
|
@ -64,6 +73,15 @@ DIALOG_DXF_IMPORT::DIALOG_DXF_IMPORT( PCB_EDIT_FRAME* aParent )
|
||||||
: DIALOG_DXF_IMPORT_BASE( aParent )
|
: DIALOG_DXF_IMPORT_BASE( aParent )
|
||||||
{
|
{
|
||||||
m_parent = 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_textCtrlFileName->SetValue( m_dxfFilename );
|
||||||
m_rbOffsetOption->SetSelection( m_offsetSelection );
|
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->SetLayerMask( ALL_CU_LAYERS ); // Do not use copper layers
|
||||||
m_SelLayerBox->SetBoardFrame( m_parent );
|
m_SelLayerBox->SetBoardFrame( m_parent );
|
||||||
m_SelLayerBox->Resync();
|
m_SelLayerBox->Resync();
|
||||||
|
|
||||||
if( m_SelLayerBox->SetLayerSelection( m_layer ) < 0 )
|
if( m_SelLayerBox->SetLayerSelection( m_layer ) < 0 )
|
||||||
{
|
{
|
||||||
m_layer = DRAW_N;
|
m_layer = DRAW_N;
|
||||||
|
@ -88,14 +107,28 @@ DIALOG_DXF_IMPORT::~DIALOG_DXF_IMPORT()
|
||||||
{
|
{
|
||||||
m_offsetSelection = m_rbOffsetOption->GetSelection();
|
m_offsetSelection = m_rbOffsetOption->GetSelection();
|
||||||
m_layer = m_SelLayerBox->GetLayerSelection();
|
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 )
|
void DIALOG_DXF_IMPORT::OnBrowseDxfFiles( wxCommandEvent& event )
|
||||||
{
|
{
|
||||||
|
wxString path;
|
||||||
|
|
||||||
|
if( !m_dxfFilename.IsEmpty() )
|
||||||
|
{
|
||||||
|
wxFileName fn( m_dxfFilename );
|
||||||
|
path = fn.GetPath();
|
||||||
|
}
|
||||||
wxFileDialog dlg( m_parent,
|
wxFileDialog dlg( m_parent,
|
||||||
wxT( "Open File" ),
|
wxT( "Open File" ),
|
||||||
wxEmptyString, wxEmptyString,
|
path, m_dxfFilename,
|
||||||
wxT( "dxf Files (*.dxf)|*.dxf|*.DXF" ),
|
wxT( "dxf Files (*.dxf)|*.dxf|*.DXF" ),
|
||||||
wxFD_OPEN|wxFD_FILE_MUST_EXIST );
|
wxFD_OPEN|wxFD_FILE_MUST_EXIST );
|
||||||
dlg.ShowModal();
|
dlg.ShowModal();
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue