KiCad PCB EDA Suite
export_to_pcbnew.h
Go to the documentation of this file.
1 /*
2  * This program source code file is part of KiCad, a free EDA CAD application.
3  *
4  * Copyright (C) 2007-2014 Jean-Pierre Charras jp.charras at wanadoo.fr
5  * Copyright (C) 1992-2021 KiCad Developers, see AUTHORS.txt for contributors.
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, you may find one here:
19  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
20  * or you may search the http://www.gnu.org website for the version 2 license,
21  * or you may write to the Free Software Foundation, Inc.,
22  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
23  */
24 
25 #include <convert_to_biu.h>
27 #include <layer_ids.h>
28 
29 
30 struct EXPORT_VIA
31 {
32  EXPORT_VIA( const wxPoint& aPos, int aSize, int aDrill ) :
33  m_Pos( aPos ),
34  m_Size( aSize ),
35  m_Drill( aDrill )
36  { }
37 
38  wxPoint m_Pos;
39  int m_Size;
40  int m_Drill;
41 };
42 
43 
44 class GERBER_DRAW_ITEM;
45 class GERBVIEW_FRAME;
46 
47 
52 {
53 public:
54  GBR_TO_PCB_EXPORTER( GERBVIEW_FRAME* aFrame, const wxString& aFileName );
56 
60  bool ExportPcb( const LAYER_NUM* aLayerLookUpTable, int aCopperLayers );
61 
62 private:
73  void collect_hole( const GERBER_DRAW_ITEM* aGbrItem );
74 
82  void export_via( const EXPORT_VIA& aVia );
83 
90  void export_non_copper_item( const GERBER_DRAW_ITEM* aGbrItem, LAYER_NUM aLayer );
91 
97  void writePcbPolygon( const SHAPE_POLY_SET& aPolys, LAYER_NUM aLayer,
98  const wxPoint& aOffset = { 0, 0 } );
99 
108  void writePcbFilledCircle( const VECTOR2I& aCenterPosition, int aRadius,
109  LAYER_NUM aLayer );
110 
119  void writePcbZoneItem( const GERBER_DRAW_ITEM* aGbrItem, LAYER_NUM aLayer );
120 
127  void export_copper_item( const GERBER_DRAW_ITEM* aGbrItem, LAYER_NUM aLayer );
128 
138  void export_flashed_copper_item( const GERBER_DRAW_ITEM* aGbrItem, LAYER_NUM aLayer );
139 
146  void export_segline_copper_item( const GERBER_DRAW_ITEM* aGbrItem, LAYER_NUM aLayer );
147 
154  void export_segarc_copper_item( const GERBER_DRAW_ITEM* aGbrItem, LAYER_NUM aLayer );
155 
159  void writeCopperLineItem( const wxPoint& aStart, const wxPoint& aEnd,
160  int aWidth, LAYER_NUM aLayer );
161 
165  void writePcbHeader( const LAYER_NUM* aLayerLookUpTable );
166 
172  double MapToPcbUnits( int aValue ) const
173  {
174  return aValue / IU_PER_MM;
175  }
176 
177 private:
178  GERBVIEW_FRAME* m_gerbview_frame; // the main gerber frame
179  wxString m_pcb_file_name; // BOARD file to write to
180  FILE* m_fp; // the board file
182  std::vector<EXPORT_VIA> m_vias;
183 };
double MapToPcbUnits(int aValue) const
Map GerbView internal units to millimeters for Pcbnew board files.
std::vector< EXPORT_VIA > m_vias
void writePcbPolygon(const SHAPE_POLY_SET &aPolys, LAYER_NUM aLayer, const wxPoint &aOffset={ 0, 0 })
Write a non-copper polygon to the board file.
static constexpr double IU_PER_MM
Mock up a conversion function.
GBR_TO_PCB_EXPORTER(GERBVIEW_FRAME *aFrame, const wxString &aFileName)
EXPORT_VIA(const wxPoint &aPos, int aSize, int aDrill)
int LAYER_NUM
This can be replaced with int and removed.
Definition: layer_ids.h:41
void export_via(const EXPORT_VIA &aVia)
Write a via to the board file.
Represent a set of closed polygons.
void export_copper_item(const GERBER_DRAW_ITEM *aGbrItem, LAYER_NUM aLayer)
Write a track (or via) to the board file.
GERBVIEW_FRAME * m_gerbview_frame
void collect_hole(const GERBER_DRAW_ITEM *aGbrItem)
Collect holes from a drill layer.
void export_flashed_copper_item(const GERBER_DRAW_ITEM *aGbrItem, LAYER_NUM aLayer)
Write a synthetic pad to the board file.
void export_segline_copper_item(const GERBER_DRAW_ITEM *aGbrItem, LAYER_NUM aLayer)
Write a track (not via) to the board file.
void export_segarc_copper_item(const GERBER_DRAW_ITEM *aGbrItem, LAYER_NUM aLayer)
Write a set of tracks (arcs are approximated by track segments) to the board file.
void writePcbZoneItem(const GERBER_DRAW_ITEM *aGbrItem, LAYER_NUM aLayer)
Write a zone item to the board file.
void export_non_copper_item(const GERBER_DRAW_ITEM *aGbrItem, LAYER_NUM aLayer)
Write a non copper line or arc to the board file.
void writeCopperLineItem(const wxPoint &aStart, const wxPoint &aEnd, int aWidth, LAYER_NUM aLayer)
Basic write function to write a a PCB_TRACK to the board file from a non flashed item.
void writePcbFilledCircle(const VECTOR2I &aCenterPosition, int aRadius, LAYER_NUM aLayer)
Write a filled circle to the board file (with line thickness = 0).
bool ExportPcb(const LAYER_NUM *aLayerLookUpTable, int aCopperLayers)
Save a board from a set of Gerber images.
A helper class to export a Gerber set of files to Pcbnew.
void writePcbHeader(const LAYER_NUM *aLayerLookUpTable)
Write a very basic header to the board file.