Commit 40eb9c9c authored by jean-pierre charras's avatar jean-pierre charras

Pcbnew: First work to add a DXF file import to create board outlines. The DXF...

Pcbnew: First work to add a DXF file import to create board outlines. The DXF import is based on DXF lib import/export  from LibreCad.
parents e8ad48ad 55e9b4d1
...@@ -360,6 +360,7 @@ add_subdirectory( cvpcb ) ...@@ -360,6 +360,7 @@ add_subdirectory( cvpcb )
add_subdirectory( eeschema ) add_subdirectory( eeschema )
add_subdirectory( gerbview ) add_subdirectory( gerbview )
add_subdirectory( kicad ) add_subdirectory( kicad )
add_subdirectory( lib_dxf )
add_subdirectory( pcbnew ) add_subdirectory( pcbnew )
add_subdirectory( polygon ) add_subdirectory( polygon )
add_subdirectory( pagelayout_editor ) add_subdirectory( pagelayout_editor )
......
include_directories(intern)
set(LIBDXF_SRCS
libdxfrw.cpp
intern/dxfwriter.cpp
intern/drw_textcodec.cpp
intern/dxfreader.cpp
drw_objects.cpp
drw_entities.cpp
)
add_library(lib_dxf STATIC ${LIBDXF_SRCS})
This library comes from the LibreCAD project, a 2D CAD program.
see http://sourceforge.net/projects/libdxfrw/
the latest sources are on:
https://github.com/LibreCAD/LibreCAD/tree/master/libraries/libdxfrw/src
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
/******************************************************************************
** libDXFrw - Library to read/write DXF files (ascii & binary) **
** **
** Copyright (C) 2011 Rallaz, rallazz@gmail.com **
** **
** This library is free software, licensed under the terms of the GNU **
** General Public License as published by the Free Software Foundation, **
** either version 2 of the License, or (at your option) any later version. **
** You should have received a copy of the GNU General Public License **
** along with this program. If not, see <http://www.gnu.org/licenses/>. **
******************************************************************************/
#ifndef DRW_INTERFACE_H
#define DRW_INTERFACE_H
#include <string.h>
#include "drw_entities.h"
#include "drw_objects.h"
// #include "dl_extrusion.h"
/**
* Abstract class (interface) for comunicate dxfReader with the application.
* Inherit your class which takes care of the entities in the
* processed DXF file from this interface.
*
* @author Rallaz
*/
class DRW_Interface
{
public:
DRW_Interface()
{
// extrusion = new DL_Extrusion;
}
virtual ~DRW_Interface()
{
// delete extrusion;
}
/** Called when header is parsed. */
virtual void addHeader( const DRW_Header* data ) = 0;
/** Called for every line Type. */
virtual void addLType( const DRW_LType& data ) = 0;
/** Called for every layer. */
virtual void addLayer( const DRW_Layer& data ) = 0;
/** Called for every dim style. */
virtual void addDimStyle( const DRW_Dimstyle& data ) = 0;
/** Called for every VPORT table. */
virtual void addVport( const DRW_Vport& data ) = 0;
/** Called for every text style. */
virtual void addTextStyle( const DRW_Textstyle& data ) = 0;
/**
* Called for every block. Note: all entities added after this
* command go into this block until endBlock() is called.
*
* @see endBlock()
*/
virtual void addBlock( const DRW_Block& data ) = 0;
/**
* In DWG called when the following entities corresponding to a
* block different from the current. Note: all entities added after this
* command go into this block until setBlock() is called already.
*
* int handle are the value of DRW_Block::handleBlock added with addBlock()
*/
virtual void setBlock( const int handle ) = 0;
/** Called to end the current block */
virtual void endBlock() = 0;
/** Called for every point */
virtual void addPoint( const DRW_Point& data ) = 0;
/** Called for every line */
virtual void addLine( const DRW_Line& data ) = 0;
/** Called for every ray */
virtual void addRay( const DRW_Ray& data ) = 0;
/** Called for every xline */
virtual void addXline( const DRW_Xline& data ) = 0;
/** Called for every arc */
virtual void addArc( const DRW_Arc& data ) = 0;
/** Called for every circle */
virtual void addCircle( const DRW_Circle& data ) = 0;
/** Called for every ellipse */
virtual void addEllipse( const DRW_Ellipse& data ) = 0;
/** Called for every lwpolyline */
virtual void addLWPolyline( const DRW_LWPolyline& data ) = 0;
/** Called for every polyline start */
virtual void addPolyline( const DRW_Polyline& data ) = 0;
/** Called for every spline */
virtual void addSpline( const DRW_Spline* data ) = 0;
/** Called for every spline knot value */
virtual void addKnot( const DRW_Entity& data ) = 0;
/** Called for every insert. */
virtual void addInsert( const DRW_Insert& data ) = 0;
/** Called for every trace start */
virtual void addTrace( const DRW_Trace& data ) = 0;
/** Called for every 3dface start */
virtual void add3dFace( const DRW_3Dface& data ) = 0;
/** Called for every solid start */
virtual void addSolid( const DRW_Solid& data ) = 0;
/** Called for every Multi Text entity. */
virtual void addMText( const DRW_MText& data ) = 0;
/** Called for every Text entity. */
virtual void addText( const DRW_Text& data ) = 0;
/**
* Called for every aligned dimension entity.
*/
virtual void addDimAlign( const DRW_DimAligned* data ) = 0;
/**
* Called for every linear or rotated dimension entity.
*/
virtual void addDimLinear( const DRW_DimLinear* data ) = 0;
/**
* Called for every radial dimension entity.
*/
virtual void addDimRadial( const DRW_DimRadial* data ) = 0;
/**
* Called for every diametric dimension entity.
*/
virtual void addDimDiametric( const DRW_DimDiametric* data ) = 0;
/**
* Called for every angular dimension (2 lines version) entity.
*/
virtual void addDimAngular( const DRW_DimAngular* data ) = 0;
/**
* Called for every angular dimension (3 points version) entity.
*/
virtual void addDimAngular3P( const DRW_DimAngular3p* data ) = 0;
/**
* Called for every ordinate dimension entity.
*/
virtual void addDimOrdinate( const DRW_DimOrdinate* data ) = 0;
/**
* Called for every leader start.
*/
virtual void addLeader( const DRW_Leader* data ) = 0;
/**
* Called for every hatch entity.
*/
virtual void addHatch( const DRW_Hatch* data ) = 0;
/**
* Called for every viewport entity.
*/
virtual void addViewport( const DRW_Viewport& data ) = 0;
/**
* Called for every image entity.
*/
virtual void addImage( const DRW_Image* data ) = 0;
/**
* Called for every image definition.
*/
virtual void linkImage( const DRW_ImageDef* data ) = 0;
/**
* Called for every comment in the DXF file (code 999).
*/
virtual void addComment( const char* comment ) = 0;
/** Sets the current attributes for entities. */
/* void setExtrusion(double dx, double dy, double dz, double elevation) {
* extrusion->setDirection(dx, dy, dz);
* extrusion->setElevation(elevation);
* }*/
/** @return the current attributes used for new entities. */
// DL_Extrusion* getExtrusion() {
// return extrusion;
// }
virtual void writeHeader( DRW_Header& data ) = 0;
virtual void writeBlocks() = 0;
virtual void writeBlockRecords() = 0;
virtual void writeEntities() = 0;
virtual void writeLTypes() = 0;
virtual void writeLayers() = 0;
virtual void writeTextstyles() = 0;
virtual void writeVports() = 0;
virtual void writeDimstyles() = 0;
protected:
// DL_Attributes attributes;
// DL_Extrusion *extrusion;
};
#endif
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
#ifndef DRW_TEXTCODEC_H
#define DRW_TEXTCODEC_H
#include <string>
class DRW_Converter;
class DRW_TextCodec
{
public:
DRW_TextCodec();
~DRW_TextCodec();
std::string fromUtf8(std::string s);
std::string toUtf8(std::string s);
int getVersion(){return version;}
void setVersion(std::string *v);
void setVersion(int v){version = v;}
void setCodePage(std::string *c);
void setCodePage(std::string c){setCodePage(&c);}
std::string getCodePage(){return cp;}
private:
std::string correctCodePage(const std::string& s);
private:
int version;
std::string cp;
DRW_Converter *conv;
};
class DRW_Converter
{
public:
DRW_Converter(const int *t, int l){table = t;
cpLenght = l;}
virtual ~DRW_Converter(){}
virtual std::string fromUtf8(std::string *s) {return *s;}
virtual std::string toUtf8(std::string *s);
std::string encodeText(std::string stmp);
std::string decodeText(int c);
std::string encodeNum(int c);
int decodeNum(std::string s, int *b);
const int *table;
int cpLenght;
};
class DRW_ConvTable : public DRW_Converter {
public:
DRW_ConvTable(const int *t, int l):DRW_Converter(t, l) {}
virtual std::string fromUtf8(std::string *s);
virtual std::string toUtf8(std::string *s);
};
class DRW_ConvDBCSTable : public DRW_Converter {
public:
DRW_ConvDBCSTable(const int *t, const int *lt, const int dt[][2], int l):DRW_Converter(t, l) {
leadTable = lt;
doubleTable = dt;
}
virtual std::string fromUtf8(std::string *s);
virtual std::string toUtf8(std::string *s);
private:
const int *leadTable;
const int (*doubleTable)[2];
};
class DRW_Conv932Table : public DRW_Converter {
public:
DRW_Conv932Table(const int *t, const int *lt, const int dt[][2], int l):DRW_Converter(t, l) {
leadTable = lt;
doubleTable = dt;
}
virtual std::string fromUtf8(std::string *s);
virtual std::string toUtf8(std::string *s);
private:
const int *leadTable;
const int (*doubleTable)[2];
};
#endif // DRW_TEXTCODEC_H
This diff is collapsed.
/******************************************************************************
** libDXFrw - Library to read/write DXF files (ascii & binary) **
** **
** Copyright (C) 2011 Rallaz, rallazz@gmail.com **
** **
** This library is free software, licensed under the terms of the GNU **
** General Public License as published by the Free Software Foundation, **
** either version 2 of the License, or (at your option) any later version. **
** You should have received a copy of the GNU General Public License **
** along with this program. If not, see <http://www.gnu.org/licenses/>. **
******************************************************************************/
#ifndef DXFREADER_H
#define DXFREADER_H
#include "drw_textcodec.h"
class dxfReader {
public:
dxfReader(std::ifstream *stream){
filestr = stream;
#ifdef DRW_DBG
count =0;
#endif
}
virtual ~dxfReader(){}
virtual bool readCode(int *code) = 0; //return true if sucesful (not EOF)
virtual bool readString(std::string *text) = 0;
virtual bool readString() = 0;
bool readRec(int *code, bool skip);
virtual bool readInt() = 0;
virtual bool readInt32() = 0;
virtual bool readInt64() = 0;
virtual bool readDouble() = 0;
virtual bool readBool() = 0;
std::string getString() {return strData;}
int getHandleString();//Convert hex string to int
std::string toUtf8String(std::string t) {return decoder.toUtf8(t);}
std::string getUtf8String() {return decoder.toUtf8(strData);}
double getDouble() {return doubleData;}
int getInt32() {return intData;}
unsigned long long int getInt64() {return int64;}
bool getBool() { return (intData==0) ? false : true;}
int getVersion(){return decoder.getVersion();}
void setVersion(std::string *v){decoder.setVersion(v);}
void setCodePage(std::string *c){decoder.setCodePage(c);}
std::string getCodePage(){ return decoder.getCodePage();}
#ifdef DRW_DBG
int count;//DBG
#endif
protected:
std::ifstream *filestr;
std::string strData;
double doubleData;
signed short intData; //16 bits integer
unsigned long long int int64; //64 bits integer
private:
DRW_TextCodec decoder;
};
class dxfReaderBinary : public dxfReader {
public:
dxfReaderBinary(std::ifstream *stream):dxfReader(stream){ }
virtual ~dxfReaderBinary() {}
virtual bool readCode(int *code);
virtual bool readString(std::string *text);
virtual bool readString();
virtual bool readInt();
virtual bool readInt32();
virtual bool readInt64();
virtual bool readDouble();
virtual bool readBool();
};
class dxfReaderAscii : public dxfReader {
public:
dxfReaderAscii(std::ifstream *stream):dxfReader(stream){ }
virtual ~dxfReaderAscii(){}
virtual bool readCode(int *code);
virtual bool readString(std::string *text);
virtual bool readString();
virtual bool readInt();
virtual bool readDouble();
virtual bool readInt32();
virtual bool readInt64();
virtual bool readBool();
};
#endif // DXFREADER_H
This diff is collapsed.
/******************************************************************************
** libDXFrw - Library to read/write DXF files (ascii & binary) **
** **
** Copyright (C) 2011 Rallaz, rallazz@gmail.com **
** **
** This library is free software, licensed under the terms of the GNU **
** General Public License as published by the Free Software Foundation, **
** either version 2 of the License, or (at your option) any later version. **
** You should have received a copy of the GNU General Public License **
** along with this program. If not, see <http://www.gnu.org/licenses/>. **
******************************************************************************/
#ifndef DXFWRITER_H
#define DXFWRITER_H
#include "drw_textcodec.h"
class dxfWriter {
public:
dxfWriter(std::ofstream *stream){filestr = stream; /*count =0;*/}
virtual ~dxfWriter(){}
virtual bool writeString(int code, std::string text) = 0;
bool writeUtf8String(int code, std::string text);
bool writeUtf8Caps(int code, std::string text);
std::string fromUtf8String(std::string t) {return encoder.fromUtf8(t);}
virtual bool writeInt16(int code, int data) = 0;
virtual bool writeInt32(int code, int data) = 0;
virtual bool writeInt64(int code, unsigned long long int data) = 0;
virtual bool writeDouble(int code, double data) = 0;
virtual bool writeBool(int code, bool data) = 0;
void setVersion(std::string *v){encoder.setVersion(v);}
void setCodePage(std::string *c){encoder.setCodePage(c);}
std::string getCodePage(){return encoder.getCodePage();}
protected:
std::ofstream *filestr;
private:
DRW_TextCodec encoder;
};
class dxfWriterBinary : public dxfWriter {
public:
dxfWriterBinary(std::ofstream *stream):dxfWriter(stream){ }
virtual ~dxfWriterBinary() {}
virtual bool writeString(int code, std::string text);
virtual bool writeInt16(int code, int data);
virtual bool writeInt32(int code, int data);
virtual bool writeInt64(int code, unsigned long long int data);
virtual bool writeDouble(int code, double data);
virtual bool writeBool(int code, bool data);
};
class dxfWriterAscii : public dxfWriter {
public:
dxfWriterAscii(std::ofstream *stream):dxfWriter(stream){ }
virtual ~dxfWriterAscii(){}
virtual bool writeString(int code, std::string text);
virtual bool writeInt16(int code, int data);
virtual bool writeInt32(int code, int data);
virtual bool writeInt64(int code, unsigned long long int data);
virtual bool writeDouble(int code, double data);
virtual bool writeBool(int code, bool data);
};
#endif // DXFWRITER_H
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
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