KiCad PCB EDA Suite
dxf2brd_items.h
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** This file comes from the LibreCAD project, a 2D CAD program
4 **
5 ** Copyright (C) 2011 Rallaz, rallazz@gmail.com
6 ** Copyright (C) 2010 R. van Twisk (librecad@rvt.dds.nl)
7 **
8 **
9 ** This file may be distributed and/or modified under the terms of the
10 ** GNU General Public License as published by the Free Software
11 ** Foundation either version 2 of the License, or (at your option)
12 ** any later version.
13 **
14 ** This program is distributed in the hope that it will be useful,
15 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
16 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 ** GNU General Public License for more details.
18 **
19 ** You should have received a copy of the GNU General Public License
20 ** along with this program; if not, write to the Free Software
21 ** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22 **
23 **********************************************************************/
24 
25 
26 #ifndef FILTERDXFRW_H
27 #define FILTERDXFRW_H
28 
29 #include "drw_interface.h"
30 #include "wx/wx.h"
31 #include <list>
32 
33 class BOARD;
34 class BOARD_ITEM;
35 
42 class DXF2BRD_CONVERTER : public DRW_Interface
43 {
44 private:
45  std::list<BOARD_ITEM*> m_newItemsList; // The list of new items added to the board
46  double m_xOffset; // X coord offset for conversion (in mm)
47  double m_yOffset; // Y coord offset for conversion (in mm)
48  double m_defaultThickness; // default line thickness for conversion (in mm)
49  double m_DXF2mm; // The scale factor to convert DXF units to mm
50  int m_brdLayer; // The board layer to place imported DXF items
51  int m_version; // the dxf version, not used here
52  std::string m_codePage; // The code page, not used here
53  bool m_importAsfootprintGraphicItems; // Use module items instead of board items when true.
54  // true when the items are imported in the footprint editor
55 
56 public:
59 
65  void ImportAsFootprintGraphic( bool aImportAsFootprintGraphic )
66  {
67  m_importAsfootprintGraphicItems = aImportAsFootprintGraphic;
68  }
69 
70 
77  void SetDefaultLineWidthMM( double aWidth )
78  {
79  m_defaultThickness = aWidth;
80  }
81 
90  void SetOffset( double aOffsetX, double aOffsetY )
91  {
92  m_xOffset = aOffsetX;
93  m_yOffset = aOffsetY;
94  }
95 
100  void SetBrdLayer( int aBrdLayer ) { m_brdLayer = aBrdLayer; }
101 
108  bool ImportDxfFile( const wxString& aFile );
109 
113  const std::list<BOARD_ITEM*>& GetItemsList() const
114  {
115  return m_newItemsList;
116  }
117 
118 private:
119  // coordinate conversions from dxf to internal units
120  int mapX( double aDxfCoordX );
121  int mapY( double aDxfCoordY );
122  int mapDim( double aDxfValue );
123  // mapWidth returns ( in internal units) the aDxfValue if aDxfWidth > 0
124  // or m_defaultThickness
125  int mapWidth( double aDxfWidth );
126 
127  // Functions to aid in the creation of a LWPolyline
128  void insertLine( const wxRealPoint& aSegStart, const wxRealPoint& aSegEnd, int aWidth );
129  void insertArc( const wxRealPoint& aSegStart, const wxRealPoint& aSegEnd,
130  double aBulge, int aWidth );
131 
132  // Methods from DRW_CreationInterface:
133  // They are "call back" fonctions, called when the corresponding object
134  // is read in dxf file
135  // Depending of the application, they can do something or not
136  virtual void addHeader( const DRW_Header* aData ) override;
137  virtual void addLType( const DRW_LType& aData ) override {}
138  virtual void addLayer( const DRW_Layer& aData ) override;
139  virtual void addDimStyle( const DRW_Dimstyle& aData ) override {}
140  virtual void addBlock( const DRW_Block& aData ) override {}
141  virtual void endBlock() override {}
142  virtual void addPoint( const DRW_Point& aData ) override {}
143  virtual void addLine( const DRW_Line& aData) override;
144  virtual void addRay( const DRW_Ray& aData ) override {}
145  virtual void addXline( const DRW_Xline& aData ) override {}
146  virtual void addCircle( const DRW_Circle& aData ) override;
147  virtual void addArc( const DRW_Arc& aData ) override;
148  virtual void addEllipse( const DRW_Ellipse& aData ) override {}
149  virtual void addLWPolyline( const DRW_LWPolyline& aData ) override;
150  virtual void addText( const DRW_Text& aData ) override;
151  virtual void addPolyline( const DRW_Polyline& aData ) override;
152  virtual void addSpline( const DRW_Spline* aData ) override {}
153  virtual void addKnot( const DRW_Entity&) override {}
154  virtual void addInsert( const DRW_Insert& aData ) override {}
155  virtual void addTrace( const DRW_Trace& aData ) override {}
156  virtual void addSolid( const DRW_Solid& aData ) override {}
157  virtual void addMText( const DRW_MText& aData) override;
158  virtual void addDimAlign( const DRW_DimAligned* aData ) override {}
159  virtual void addDimLinear( const DRW_DimLinear* aData ) override {}
160  virtual void addDimRadial( const DRW_DimRadial* aData ) override {}
161  virtual void addDimDiametric( const DRW_DimDiametric* aData ) override {}
162  virtual void addDimAngular( const DRW_DimAngular* aData ) override {}
163  virtual void addDimAngular3P( const DRW_DimAngular3p* aData ) override {}
164  virtual void addDimOrdinate( const DRW_DimOrdinate* aData ) override {}
165  virtual void addLeader( const DRW_Leader* aData ) override {}
166  virtual void addHatch( const DRW_Hatch* aData ) override {}
167  virtual void addImage( const DRW_Image* aData ) override {}
168  virtual void linkImage( const DRW_ImageDef* aData ) override {}
169 
170  virtual void add3dFace( const DRW_3Dface& aData ) override {}
171  virtual void addComment( const char*) override {}
172 
173  virtual void addVport( const DRW_Vport& aData ) override {}
174 
175  virtual void addTextStyle( const DRW_Textstyle& aData ) override;
176 
177  virtual void addViewport( const DRW_Viewport& aData ) override {}
178 
179  virtual void setBlock( const int aHandle ) override {}
180 
189  static wxString toDxfString( const wxString& aStr );
190 
194  static wxString toNativeString( const wxString& aData );
195 
196  // These functions are not used in Kicad.
197  // But because they are virtual pure in DRW_Interface, they should be defined
198  virtual void writeTextstyles() override {}
199  virtual void writeVports() override {}
200  virtual void writeHeader( DRW_Header& aData ) override {}
201  virtual void writeEntities() override {}
202  virtual void writeLTypes() override {}
203  virtual void writeLayers() override {}
204  virtual void writeBlockRecords() override {}
205  virtual void writeBlocks() override {}
206  virtual void writeDimstyles() override {}
207 
208  void writeLine();
209  void writeMtext();
210 
211  virtual void addAppId( const DRW_AppId& data ) override {}
212  virtual void writeAppId() override {}
213 };
214 
215 #endif // FILTERDXFRW_H
virtual void addLWPolyline(const DRW_LWPolyline &aData) override
virtual void writeAppId() override
virtual void writeTextstyles() override
bool m_importAsfootprintGraphicItems
Definition: dxf2brd_items.h:53
virtual void addDimLinear(const DRW_DimLinear *aData) override
virtual void addArc(const DRW_Arc &aData) override
virtual void addTextStyle(const DRW_Textstyle &aData) override
virtual void addBlock(const DRW_Block &aData) override
virtual void setBlock(const int aHandle) override
Class BOARD_ITEM is a base class for any item which can be embedded within the BOARD container class...
virtual void addLeader(const DRW_Leader *aData) override
virtual void writeBlockRecords() override
virtual void addCircle(const DRW_Circle &aData) override
std::string m_codePage
Definition: dxf2brd_items.h:52
virtual void addComment(const char *) override
const std::list< BOARD_ITEM * > & GetItemsList() const
static wxString toDxfString(const wxString &aStr)
Converts a native unicode string into a DXF encoded string.
void insertArc(const wxRealPoint &aSegStart, const wxRealPoint &aSegEnd, double aBulge, int aWidth)
virtual void addInsert(const DRW_Insert &aData) override
static wxString toNativeString(const wxString &aData)
Converts a DXF encoded string into a native Unicode string.
virtual void addMText(const DRW_MText &aData) override
virtual void writeLayers() override
virtual void writeVports() override
virtual void addDimAngular(const DRW_DimAngular *aData) override
virtual void addViewport(const DRW_Viewport &aData) override
virtual void addDimRadial(const DRW_DimRadial *aData) override
virtual void addKnot(const DRW_Entity &) override
int mapDim(double aDxfValue)
virtual void addText(const DRW_Text &aData) override
void ImportAsFootprintGraphic(bool aImportAsFootprintGraphic)
Allows the import DXF items converted to board graphic items or footprint graphic items...
Definition: dxf2brd_items.h:65
virtual void addRay(const DRW_Ray &aData) override
virtual void addImage(const DRW_Image *aData) override
virtual void writeHeader(DRW_Header &aData) override
virtual void endBlock() override
virtual void addPoint(const DRW_Point &aData) override
int mapY(double aDxfCoordY)
This format filter class can import and export DXF files.
Definition: dxf2brd_items.h:42
virtual void addPolyline(const DRW_Polyline &aData) override
virtual void writeBlocks() override
std::list< BOARD_ITEM * > m_newItemsList
Definition: dxf2brd_items.h:45
bool ImportDxfFile(const wxString &aFile)
Implementation of the method used for communicate with this filter.
virtual void addTrace(const DRW_Trace &aData) override
int mapX(double aDxfCoordX)
virtual void addVport(const DRW_Vport &aData) override
virtual void addLine(const DRW_Line &aData) override
virtual void addEllipse(const DRW_Ellipse &aData) override
virtual void addDimAngular3P(const DRW_DimAngular3p *aData) override
virtual void addDimDiametric(const DRW_DimDiametric *aData) override
virtual void addHeader(const DRW_Header *aData) override
virtual void addDimOrdinate(const DRW_DimOrdinate *aData) override
virtual void writeDimstyles() override
void SetOffset(double aOffsetX, double aOffsetY)
Set the coordinate offset between the imported dxf items and Pcbnew.
Definition: dxf2brd_items.h:90
virtual void linkImage(const DRW_ImageDef *aData) override
void insertLine(const wxRealPoint &aSegStart, const wxRealPoint &aSegEnd, int aWidth)
virtual void add3dFace(const DRW_3Dface &aData) override
virtual void addDimAlign(const DRW_DimAligned *aData) override
void SetBrdLayer(int aBrdLayer)
Set the layer number to import dxf items.
virtual void addXline(const DRW_Xline &aData) override
virtual void addHatch(const DRW_Hatch *aData) override
Class BOARD holds information pertinent to a Pcbnew printed circuit board.
Definition: class_board.h:169
virtual void addAppId(const DRW_AppId &data) override
virtual void addLayer(const DRW_Layer &aData) override
virtual void addLType(const DRW_LType &aData) override
virtual void addSolid(const DRW_Solid &aData) override
virtual void writeLTypes() override
virtual void writeEntities() override
int mapWidth(double aDxfWidth)
virtual void addSpline(const DRW_Spline *aData) override
void SetDefaultLineWidthMM(double aWidth)
Set the default line width when importing dxf items like lines to Pcbnew.
Definition: dxf2brd_items.h:77
double m_defaultThickness
Definition: dxf2brd_items.h:48
virtual void addDimStyle(const DRW_Dimstyle &aData) override