Commit 3e3869ed authored by jean-pierre charras's avatar jean-pierre charras

dxf import: minor enhancements in dialog. Update libdfxw from git, and...

dxf import: minor enhancements in dialog. Update libdfxw from git, and uncrustify it. add a test dfx file
parent f0b2565f
...@@ -18,8 +18,6 @@ ...@@ -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: ...@@ -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 @@ ...@@ -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: ...@@ -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: ...@@ -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: ...@@ -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: ...@@ -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: ...@@ -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: ...@@ -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 ) ...@@ -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 ) ...@@ -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 ) ...@@ -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 ) ...@@ -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 ) ...@@ -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 ) ...@@ -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 ) ...@@ -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 ) ...@@ -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 @@ ...@@ -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: ...@@ -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: ...@@ -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: ...@@ -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: ...@@ -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
}; };
......
This diff is collapsed.
...@@ -10,75 +10,89 @@ class DRW_TextCodec ...@@ -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);
void setVersion(int v){version = v;}
void setCodePage(std::string *c);
void setCodePage(std::string c){setCodePage(&c);}
std::string getCodePage(){return cp;}
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: private:
std::string correctCodePage(const std::string& s); std::string correctCodePage( const std::string& s );
private: private:
int version; int version;
std::string cp; std::string cp;
DRW_Converter *conv; DRW_Converter* conv;
}; };
class DRW_Converter class DRW_Converter
{ {
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: private:
const int *leadTable; const int* leadTable;
const int (*doubleTable)[2]; 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: private:
const int *leadTable; const int* leadTable;
const int (*doubleTable)[2]; const int (*doubleTable)[2];
}; };
#endif // DRW_TEXTCODEC_H #endif // DRW_TEXTCODEC_H
This diff is collapsed.
...@@ -15,75 +15,82 @@ ...@@ -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
This diff is collapsed.
...@@ -15,50 +15,55 @@ ...@@ -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 ) ...@@ -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 ) ...@@ -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() ...@@ -2129,8 +2134,13 @@ bool dxfRW::writeTables()
writer->writeInt16( 280, 1 ); writer->writeInt16( 280, 1 );
writer->writeInt16( 281, 0 ); writer->writeInt16( 281, 0 );
} }
}
/* allways call writeBlockRecords to iface for prepare unnamed blocks */
iface->writeBlockRecords();
iface->writeBlockRecords(); if( version > DRW::AC1009 )
{
writer->writeString( 0, "ENDTAB" ); writer->writeString( 0, "ENDTAB" );
} }
...@@ -2312,7 +2322,7 @@ bool dxfRW::writeObjects() ...@@ -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() ...@@ -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() ...@@ -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() ...@@ -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() ...@@ -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() ...@@ -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() ...@@ -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() ...@@ -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() ...@@ -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() ...@@ -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() ...@@ -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: ...@@ -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 @@ ...@@ -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 ) ...@@ -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 ) ...@@ -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() ...@@ -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();
......
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment