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_useModuleItems; // Use module items instead of board items when true.
54 
55 public:
58 
59  bool IsUsingModuleItems() const { return m_useModuleItems; }
60  void UseModuleItems( bool aUseModuleItems = true ) { m_useModuleItems = aUseModuleItems; }
61 
70  void SetOffset( double aOffsetX, double aOffsetY )
71  {
72  m_xOffset = aOffsetX;
73  m_yOffset = aOffsetY;
74  }
75 
80  void SetBrdLayer( int aBrdLayer ) { m_brdLayer = aBrdLayer; }
81 
88  bool ImportDxfFile( const wxString& aFile );
89 
93  const std::list<BOARD_ITEM*>& GetItemsList() const
94  {
95  return m_newItemsList;
96  }
97 
98 private:
99  // coordinate conversions from dxf to internal units
100  int mapX( double aDxfCoordX );
101  int mapY( double aDxfCoordY );
102  int mapDim( double aDxfValue );
103 
104  // Functions to aid in the creation of a LWPolyline
105  void insertLine( const wxRealPoint& aSegStart, const wxRealPoint& aSegEnd, int aWidth );
106  void insertArc( const wxRealPoint& aSegStart, const wxRealPoint& aSegEnd,
107  double aBulge, int aWidth );
108 
109  // Methods from DRW_CreationInterface:
110  // They are "call back" fonctions, called when the corresponding object
111  // is read in dxf file
112  // Depending of the application, they can do something or not
113  virtual void addHeader( const DRW_Header* aData ) override;
114  virtual void addLType( const DRW_LType& aData ) override {}
115  virtual void addLayer( const DRW_Layer& aData ) override;
116  virtual void addDimStyle( const DRW_Dimstyle& aData ) override {}
117  virtual void addBlock( const DRW_Block& aData ) override {}
118  virtual void endBlock() override {}
119  virtual void addPoint( const DRW_Point& aData ) override {}
120  virtual void addLine( const DRW_Line& aData) override;
121  virtual void addRay( const DRW_Ray& aData ) override {}
122  virtual void addXline( const DRW_Xline& aData ) override {}
123  virtual void addCircle( const DRW_Circle& aData ) override;
124  virtual void addArc( const DRW_Arc& aData ) override;
125  virtual void addEllipse( const DRW_Ellipse& aData ) override {}
126  virtual void addLWPolyline( const DRW_LWPolyline& aData ) override;
127  virtual void addText( const DRW_Text& aData ) override;
128  virtual void addPolyline( const DRW_Polyline& aData ) override;
129  virtual void addSpline( const DRW_Spline* aData ) override {}
130  virtual void addKnot( const DRW_Entity&) override {}
131  virtual void addInsert( const DRW_Insert& aData ) override {}
132  virtual void addTrace( const DRW_Trace& aData ) override {}
133  virtual void addSolid( const DRW_Solid& aData ) override {}
134  virtual void addMText( const DRW_MText& aData) override;
135  virtual void addDimAlign( const DRW_DimAligned* aData ) override {}
136  virtual void addDimLinear( const DRW_DimLinear* aData ) override {}
137  virtual void addDimRadial( const DRW_DimRadial* aData ) override {}
138  virtual void addDimDiametric( const DRW_DimDiametric* aData ) override {}
139  virtual void addDimAngular( const DRW_DimAngular* aData ) override {}
140  virtual void addDimAngular3P( const DRW_DimAngular3p* aData ) override {}
141  virtual void addDimOrdinate( const DRW_DimOrdinate* aData ) override {}
142  virtual void addLeader( const DRW_Leader* aData ) override {}
143  virtual void addHatch( const DRW_Hatch* aData ) override {}
144  virtual void addImage( const DRW_Image* aData ) override {}
145  virtual void linkImage( const DRW_ImageDef* aData ) override {}
146 
147  virtual void add3dFace( const DRW_3Dface& aData ) override {}
148  virtual void addComment( const char*) override {}
149 
150  virtual void addVport( const DRW_Vport& aData ) override {}
151 
152  virtual void addTextStyle( const DRW_Textstyle& aData ) override;
153 
154  virtual void addViewport( const DRW_Viewport& aData ) override {}
155 
156  virtual void setBlock( const int aHandle ) override {}
157 
166  static wxString toDxfString( const wxString& aStr );
167 
171  static wxString toNativeString( const wxString& aData );
172 
173  // These functions are not used in Kicad.
174  // But because they are virtual pure in DRW_Interface, they should be defined
175  virtual void writeTextstyles() override {}
176  virtual void writeVports() override {}
177  virtual void writeHeader( DRW_Header& aData ) override {}
178  virtual void writeEntities() override {}
179  virtual void writeLTypes() override {}
180  virtual void writeLayers() override {}
181  virtual void writeBlockRecords() override {}
182  virtual void writeBlocks() override {}
183  virtual void writeDimstyles() override {}
184 
185  void writeLine();
186  void writeMtext();
187 
188  virtual void addAppId( const DRW_AppId& data ) override {}
189  virtual void writeAppId() override {}
190 };
191 
192 #endif // FILTERDXFRW_H
virtual void addLWPolyline(const DRW_LWPolyline &aData) override
virtual void writeAppId() override
virtual void writeTextstyles() override
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
Definition: dxf2brd_items.h:93
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 UseModuleItems(bool aUseModuleItems=true)
Definition: dxf2brd_items.h:60
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
bool IsUsingModuleItems() const
Definition: dxf2brd_items.h:59
virtual void writeDimstyles() override
void SetOffset(double aOffsetX, double aOffsetY)
Set the coordinate offset between the importede dxf items and Pcbnew.
Definition: dxf2brd_items.h:70
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.
Definition: dxf2brd_items.h:80
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:166
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
virtual void addSpline(const DRW_Spline *aData) override
double m_defaultThickness
Definition: dxf2brd_items.h:48
virtual void addDimStyle(const DRW_Dimstyle &aData) override