2020-10-08 22:59:16 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2007-2014 Jean-Pierre Charras jp.charras at wanadoo.fr
|
2021-06-03 18:32:24 +00:00
|
|
|
* Copyright (C) 1992-2021 KiCad Developers, see AUTHORS.txt for contributors.
|
2020-10-08 22:59:16 +00:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it 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.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, you may find one here:
|
|
|
|
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
|
|
|
* or you may search the http://www.gnu.org website for the version 2 license,
|
|
|
|
* or you may write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <convert_to_biu.h>
|
|
|
|
#include <geometry/shape_poly_set.h>
|
|
|
|
#include <layers_id_colors_and_visibility.h>
|
|
|
|
|
|
|
|
|
|
|
|
struct EXPORT_VIA
|
|
|
|
{
|
|
|
|
EXPORT_VIA( const wxPoint& aPos, int aSize, int aDrill ) :
|
|
|
|
m_Pos( aPos ),
|
|
|
|
m_Size( aSize ),
|
|
|
|
m_Drill( aDrill )
|
|
|
|
{ }
|
|
|
|
|
|
|
|
wxPoint m_Pos;
|
|
|
|
int m_Size;
|
|
|
|
int m_Drill;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class GERBER_DRAW_ITEM;
|
|
|
|
class GERBVIEW_FRAME;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2021-06-03 18:32:24 +00:00
|
|
|
* A helper class to export a Gerber set of files to Pcbnew.
|
2020-10-08 22:59:16 +00:00
|
|
|
*/
|
|
|
|
class GBR_TO_PCB_EXPORTER
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
GBR_TO_PCB_EXPORTER( GERBVIEW_FRAME* aFrame, const wxString& aFileName );
|
|
|
|
~GBR_TO_PCB_EXPORTER();
|
|
|
|
|
|
|
|
/**
|
2021-06-03 18:32:24 +00:00
|
|
|
* Save a board from a set of Gerber images.
|
2020-10-08 22:59:16 +00:00
|
|
|
*/
|
2020-11-18 19:50:36 +00:00
|
|
|
bool ExportPcb( const LAYER_NUM* aLayerLookUpTable, int aCopperLayers );
|
2020-10-08 22:59:16 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
/**
|
2021-06-03 18:32:24 +00:00
|
|
|
* Collect holes from a drill layer.
|
|
|
|
*
|
2020-10-08 22:59:16 +00:00
|
|
|
* We'll use these later when writing pads & vias.
|
|
|
|
*/
|
2020-11-18 19:50:36 +00:00
|
|
|
void collect_hole( const GERBER_DRAW_ITEM* aGbrItem );
|
2020-10-08 22:59:16 +00:00
|
|
|
|
|
|
|
/**
|
2021-06-03 18:32:24 +00:00
|
|
|
* Write a via to the board file.
|
|
|
|
*
|
2020-10-08 22:59:16 +00:00
|
|
|
* Some of these will represent actual vias while others are used to represent
|
|
|
|
* holes in pads. (We can't generate actual pads because the Gerbers don't contain
|
2020-10-21 03:48:06 +00:00
|
|
|
* info on how to group them into footprints.)
|
2020-10-08 22:59:16 +00:00
|
|
|
*/
|
|
|
|
void export_via( const EXPORT_VIA& aVia );
|
|
|
|
|
|
|
|
/**
|
2021-06-03 18:32:24 +00:00
|
|
|
* Write a non copper line or arc to the board file.
|
|
|
|
*
|
|
|
|
* @param aGbrItem is the Gerber item (line, arc) to export.
|
|
|
|
* @param aLayer is the technical layer to use.
|
2020-10-08 22:59:16 +00:00
|
|
|
*/
|
2020-11-18 19:50:36 +00:00
|
|
|
void export_non_copper_item( const GERBER_DRAW_ITEM* aGbrItem, LAYER_NUM aLayer );
|
2020-10-08 22:59:16 +00:00
|
|
|
|
|
|
|
/**
|
2021-06-03 18:32:24 +00:00
|
|
|
* Write a non-copper polygon to the board file.
|
|
|
|
*
|
|
|
|
* @param aLayer is the technical layer to use.
|
2020-10-08 22:59:16 +00:00
|
|
|
*/
|
|
|
|
void writePcbPolygon( const SHAPE_POLY_SET& aPolys, LAYER_NUM aLayer,
|
|
|
|
const wxPoint& aOffset = { 0, 0 } );
|
|
|
|
|
2021-06-12 07:18:48 +00:00
|
|
|
/**
|
|
|
|
* Write a filled circle to the board file (with line thickness = 0).
|
|
|
|
*
|
|
|
|
* @param aCenterPosition is the actual position of the filled circle,
|
|
|
|
* given by <round_flashed_shape>->GetABPosition()
|
|
|
|
* @param aRadius is the circle radius.
|
|
|
|
* @param aLayer is the layer to use.
|
|
|
|
*/
|
|
|
|
void writePcbFilledCircle( const VECTOR2I& aCenterPosition, int aRadius,
|
|
|
|
LAYER_NUM aLayer );
|
|
|
|
|
2020-10-08 22:59:16 +00:00
|
|
|
/**
|
2021-06-03 18:32:24 +00:00
|
|
|
* Write a zone item to the board file.
|
|
|
|
*
|
|
|
|
* @warning This is experimental for tests only.
|
|
|
|
*
|
|
|
|
* @param aGbrItem is the Gerber item (line, arc) to export.
|
|
|
|
* @param aLayer is the technical layer to use.
|
2020-10-08 22:59:16 +00:00
|
|
|
*/
|
2020-11-18 19:50:36 +00:00
|
|
|
void writePcbZoneItem( const GERBER_DRAW_ITEM* aGbrItem, LAYER_NUM aLayer );
|
2020-10-08 22:59:16 +00:00
|
|
|
|
|
|
|
/**
|
2021-06-03 18:32:24 +00:00
|
|
|
* Write a track (or via) to the board file.
|
|
|
|
*
|
|
|
|
* @param aGbrItem is the Gerber item (line, arc, flashed) to export.
|
|
|
|
* @param aLayer is the copper layer to use.
|
2020-10-08 22:59:16 +00:00
|
|
|
*/
|
2020-11-18 19:50:36 +00:00
|
|
|
void export_copper_item( const GERBER_DRAW_ITEM* aGbrItem, LAYER_NUM aLayer );
|
2020-10-08 22:59:16 +00:00
|
|
|
|
|
|
|
/**
|
2021-06-03 18:32:24 +00:00
|
|
|
* Write a synthetic pad to the board file.
|
|
|
|
*
|
2020-10-08 22:59:16 +00:00
|
|
|
* We can't create real pads because the Gerbers don't store grouping/footprint info.
|
|
|
|
* So we synthesize a pad with a via for the hole (if present) and a copper polygon for
|
|
|
|
* the pad.
|
2021-06-03 18:32:24 +00:00
|
|
|
*
|
|
|
|
* @param aGbrItem is the flashed Gerber item to export.
|
2020-10-08 22:59:16 +00:00
|
|
|
*/
|
2020-11-18 19:50:36 +00:00
|
|
|
void export_flashed_copper_item( const GERBER_DRAW_ITEM* aGbrItem, LAYER_NUM aLayer );
|
2020-10-08 22:59:16 +00:00
|
|
|
|
|
|
|
/**
|
2021-06-03 18:32:24 +00:00
|
|
|
* Write a track (not via) to the board file.
|
|
|
|
*
|
|
|
|
* @param aGbrItem is the Gerber item (line only) to export.
|
|
|
|
* @param aLayer is the copper layer to use.
|
2020-10-08 22:59:16 +00:00
|
|
|
*/
|
2020-11-18 19:50:36 +00:00
|
|
|
void export_segline_copper_item( const GERBER_DRAW_ITEM* aGbrItem, LAYER_NUM aLayer );
|
2020-10-08 22:59:16 +00:00
|
|
|
|
|
|
|
/**
|
2021-06-03 18:32:24 +00:00
|
|
|
* Write a set of tracks (arcs are approximated by track segments) to the board file.
|
|
|
|
*
|
|
|
|
* @param aGbrItem is the Gerber item (arc only) to export.
|
|
|
|
* @param aLayer is the copper layer to use
|
2020-10-08 22:59:16 +00:00
|
|
|
*/
|
2020-11-18 19:50:36 +00:00
|
|
|
void export_segarc_copper_item( const GERBER_DRAW_ITEM* aGbrItem, LAYER_NUM aLayer );
|
2020-10-08 22:59:16 +00:00
|
|
|
|
|
|
|
/**
|
2021-06-11 21:07:02 +00:00
|
|
|
* Basic write function to write a a #PCB_TRACK to the board file from a non flashed item.
|
2020-10-08 22:59:16 +00:00
|
|
|
*/
|
2021-06-03 18:32:24 +00:00
|
|
|
void writeCopperLineItem( const wxPoint& aStart, const wxPoint& aEnd,
|
2020-10-08 22:59:16 +00:00
|
|
|
int aWidth, LAYER_NUM aLayer );
|
|
|
|
|
|
|
|
/**
|
2021-06-03 18:32:24 +00:00
|
|
|
* Write a very basic header to the board file.
|
2020-10-08 22:59:16 +00:00
|
|
|
*/
|
2020-11-18 19:50:36 +00:00
|
|
|
void writePcbHeader( const LAYER_NUM* aLayerLookUpTable );
|
2020-10-08 22:59:16 +00:00
|
|
|
|
2021-06-03 18:32:24 +00:00
|
|
|
/**
|
|
|
|
* Map GerbView internal units to millimeters for Pcbnew board files.
|
|
|
|
*
|
|
|
|
* @param aValue is a coordinate value to convert in mm.
|
2020-10-08 22:59:16 +00:00
|
|
|
*/
|
2020-11-18 19:50:36 +00:00
|
|
|
double MapToPcbUnits( int aValue ) const
|
2020-10-08 22:59:16 +00:00
|
|
|
{
|
|
|
|
return aValue / IU_PER_MM;
|
|
|
|
}
|
2021-06-03 18:32:24 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
GERBVIEW_FRAME* m_gerbview_frame; // the main gerber frame
|
|
|
|
wxString m_pcb_file_name; // BOARD file to write to
|
|
|
|
FILE* m_fp; // the board file
|
|
|
|
int m_pcbCopperLayersCount;
|
|
|
|
std::vector<EXPORT_VIA> m_vias;
|
2020-10-08 22:59:16 +00:00
|
|
|
};
|