KiCad PCB EDA Suite
Loading...
Searching...
No Matches
GBR_TO_PCB_EXPORTER Class Reference

A helper class to export a Gerber set of files to Pcbnew. More...

#include <export_to_pcbnew.h>

Public Member Functions

 GBR_TO_PCB_EXPORTER (GERBVIEW_FRAME *aFrame, const wxString &aFileName)
 
 ~GBR_TO_PCB_EXPORTER ()
 
bool ExportPcb (const int *aLayerLookUpTable, int aCopperLayers)
 Save a board from a set of Gerber images.
 

Private Member Functions

void collect_hole (const GERBER_DRAW_ITEM *aGbrItem)
 Collect holes from a drill layer.
 
void export_via (const EXPORT_VIA &aVia)
 Write a via to the board file.
 
void export_non_copper_item (const GERBER_DRAW_ITEM *aGbrItem, int aLayer)
 Write a non copper line or arc to the board file.
 
void writePcbPolygon (const SHAPE_POLY_SET &aPolys, int aLayer, const VECTOR2I &aOffset={ 0, 0 })
 Write a non-copper polygon to the board file.
 
void writePcbFilledCircle (const VECTOR2I &aCenterPosition, int aRadius, int aLayer)
 Write a filled circle to the board file (with line thickness = 0).
 
void writePcbZoneItem (const GERBER_DRAW_ITEM *aGbrItem, int aLayer)
 Write a zone item to the board file.
 
void export_copper_item (const GERBER_DRAW_ITEM *aGbrItem, int aLayer)
 Write a track (or via) to the board file.
 
void export_flashed_copper_item (const GERBER_DRAW_ITEM *aGbrItem, int aLayer)
 Write a synthetic pad to the board file.
 
void export_segline_copper_item (const GERBER_DRAW_ITEM *aGbrItem, int aLayer)
 Write a track (not via) to the board file.
 
void export_segarc_copper_item (const GERBER_DRAW_ITEM *aGbrItem, int aLayer)
 Write a set of tracks (arcs are approximated by track segments) to the board file.
 
void writeCopperLineItem (const VECTOR2I &aStart, const VECTOR2I &aEnd, int aWidth, int aLayer)
 Basic write function to write a a PCB_TRACK to the board file from a non flashed item.
 
void writePcbHeader (const int *aLayerLookUpTable)
 Write a very basic header to the board file.
 
double MapToPcbUnits (int aValue) const
 Map GerbView internal units to millimeters for Pcbnew board files.
 

Private Attributes

GERBVIEW_FRAMEm_gerbview_frame
 
wxString m_pcb_file_name
 
FILE * m_fp
 
int m_pcbCopperLayersCount
 
std::vector< EXPORT_VIAm_vias
 

Detailed Description

A helper class to export a Gerber set of files to Pcbnew.

Definition at line 50 of file export_to_pcbnew.h.

Constructor & Destructor Documentation

◆ GBR_TO_PCB_EXPORTER()

GBR_TO_PCB_EXPORTER::GBR_TO_PCB_EXPORTER ( GERBVIEW_FRAME aFrame,
const wxString &  aFileName 
)

Definition at line 45 of file export_to_pcbnew.cpp.

References m_fp, m_gerbview_frame, m_pcb_file_name, and m_pcbCopperLayersCount.

◆ ~GBR_TO_PCB_EXPORTER()

GBR_TO_PCB_EXPORTER::~GBR_TO_PCB_EXPORTER ( )

Definition at line 54 of file export_to_pcbnew.cpp.

Member Function Documentation

◆ collect_hole()

void GBR_TO_PCB_EXPORTER::collect_hole ( const GERBER_DRAW_ITEM aGbrItem)
private

Collect holes from a drill layer.

We'll use these later when writing pads & vias. Many holes will be pads, but we have no way to create those without footprints, and creating a footprint per pad is not really viable. We use vias to mimic holes, with the loss of any hole shape (as we only have round holes in vias at present). We start out with a via size minimally larger than the hole. We'll leave it this way if the pad gets drawn as a copper polygon, or increase it to the proper size if it has a circular, concentric copper flashing.

Definition at line 267 of file export_to_pcbnew.cpp.

References GERBER_DRAW_ITEM::m_Size, GERBER_DRAW_ITEM::m_Start, m_vias, VECTOR2< T >::x, and VECTOR2< T >::y.

Referenced by ExportPcb().

◆ export_copper_item()

void GBR_TO_PCB_EXPORTER::export_copper_item ( const GERBER_DRAW_ITEM aGbrItem,
int  aLayer 
)
private

◆ export_flashed_copper_item()

void GBR_TO_PCB_EXPORTER::export_flashed_copper_item ( const GERBER_DRAW_ITEM aGbrItem,
int  aLayer 
)
private

Write a synthetic pad to the board file.

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.

Parameters
aGbrItemis the flashed Gerber item to export.

Definition at line 431 of file export_to_pcbnew.cpp.

References D_CODE::ConvertShapeToPolygon(), GBR_SPOT_CIRCLE, GBR_SPOT_OVAL, GERBER_DRAW_ITEM::GetABPosition(), APERTURE_MACRO::GetApertureMacroShape(), GERBER_DRAW_ITEM::GetDcodeDescr(), D_CODE::GetMacro(), D_CODE::m_Polygon, GERBER_DRAW_ITEM::m_ShapeType, D_CODE::m_Size, GERBER_DRAW_ITEM::m_Size, GERBER_DRAW_ITEM::m_Start, m_vias, SHAPE_LINE_CHAIN::Mirror(), SHAPE_POLY_SET::Outline(), via, writePcbFilledCircle(), writePcbPolygon(), VECTOR2< T >::x, and VECTOR2< T >::y.

Referenced by export_copper_item().

◆ export_non_copper_item()

◆ export_segarc_copper_item()

void GBR_TO_PCB_EXPORTER::export_segarc_copper_item ( const GERBER_DRAW_ITEM aGbrItem,
int  aLayer 
)
private

Write a set of tracks (arcs are approximated by track segments) to the board file.

Parameters
aGbrItemis the Gerber item (arc only) to export.
aLayeris the copper layer to use

Definition at line 377 of file export_to_pcbnew.cpp.

References DELTA_ANGLE, GERBER_DRAW_ITEM::m_ArcCentre, GERBER_DRAW_ITEM::m_End, GERBER_DRAW_ITEM::m_Size, GERBER_DRAW_ITEM::m_Start, RADIANS_T, RotatePoint(), writeCopperLineItem(), VECTOR2< T >::x, and VECTOR2< T >::y.

Referenced by export_copper_item().

◆ export_segline_copper_item()

void GBR_TO_PCB_EXPORTER::export_segline_copper_item ( const GERBER_DRAW_ITEM aGbrItem,
int  aLayer 
)
private

Write a track (not via) to the board file.

Parameters
aGbrItemis the Gerber item (line only) to export.
aLayeris the copper layer to use.

Definition at line 349 of file export_to_pcbnew.cpp.

References GERBER_DRAW_ITEM::m_End, GERBER_DRAW_ITEM::m_Size, GERBER_DRAW_ITEM::m_Start, writeCopperLineItem(), VECTOR2< T >::x, and VECTOR2< T >::y.

Referenced by export_copper_item().

◆ export_via()

void GBR_TO_PCB_EXPORTER::export_via ( const EXPORT_VIA aVia)
private

Write a via to the board file.

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 info on how to group them into footprints.)

Definition at line 274 of file export_to_pcbnew.cpp.

References B_Cu, F_Cu, FormatDouble2Str(), GetPCBDefaultLayerName(), EXPORT_VIA::m_Drill, m_fp, EXPORT_VIA::m_Pos, EXPORT_VIA::m_Size, MapToPcbUnits(), TO_UTF8, VECTOR2< T >::x, and VECTOR2< T >::y.

Referenced by ExportPcb().

◆ ExportPcb()

◆ MapToPcbUnits()

double GBR_TO_PCB_EXPORTER::MapToPcbUnits ( int  aValue) const
inlineprivate

Map GerbView internal units to millimeters for Pcbnew board files.

Parameters
aValueis a coordinate value to convert in mm.

Definition at line 170 of file export_to_pcbnew.h.

References gerbIUScale, and EDA_IU_SCALE::IU_PER_MM.

Referenced by export_non_copper_item(), export_via(), writeCopperLineItem(), writePcbFilledCircle(), writePcbPolygon(), and writePcbZoneItem().

◆ writeCopperLineItem()

void GBR_TO_PCB_EXPORTER::writeCopperLineItem ( const VECTOR2I aStart,
const VECTOR2I aEnd,
int  aWidth,
int  aLayer 
)
private

Basic write function to write a a PCB_TRACK to the board file from a non flashed item.

Definition at line 364 of file export_to_pcbnew.cpp.

References FormatDouble2Str(), GetPCBDefaultLayerName(), m_fp, MapToPcbUnits(), TO_UTF8, VECTOR2< T >::x, and VECTOR2< T >::y.

Referenced by export_segarc_copper_item(), and export_segline_copper_item().

◆ writePcbFilledCircle()

void GBR_TO_PCB_EXPORTER::writePcbFilledCircle ( const VECTOR2I aCenterPosition,
int  aRadius,
int  aLayer 
)
private

Write a filled circle to the board file (with line thickness = 0).

Parameters
aCenterPositionis the actual position of the filled circle, given by <round_flashed_shape>->GetABPosition()
aRadiusis the circle radius.
aLayeris the layer to use.

Definition at line 486 of file export_to_pcbnew.cpp.

References FormatDouble2Str(), GetPCBDefaultLayerName(), m_fp, MapToPcbUnits(), TO_UTF8, VECTOR2< T >::x, and VECTOR2< T >::y.

Referenced by export_flashed_copper_item(), and export_non_copper_item().

◆ writePcbHeader()

void GBR_TO_PCB_EXPORTER::writePcbHeader ( const int *  aLayerLookUpTable)
private

Write a very basic header to the board file.

Definition at line 502 of file export_to_pcbnew.cpp.

References B_Adhes, B_Cu, GetMajorMinorVersion(), GetPCBDefaultLayerName(), m_fp, m_pcbCopperLayersCount, PCB_LAYER_ID_COUNT, and TO_UTF8.

Referenced by ExportPcb().

◆ writePcbPolygon()

void GBR_TO_PCB_EXPORTER::writePcbPolygon ( const SHAPE_POLY_SET aPolys,
int  aLayer,
const VECTOR2I aOffset = { 0, 0 } 
)
private

◆ writePcbZoneItem()

void GBR_TO_PCB_EXPORTER::writePcbZoneItem ( const GERBER_DRAW_ITEM aGbrItem,
int  aLayer 
)
private

Write a zone item to the board file.

Warning
This is experimental for tests only.
Parameters
aGbrItemis the Gerber item (line, arc) to export.
aLayeris the technical layer to use.

Definition at line 574 of file export_to_pcbnew.cpp.

References SHAPE_POLY_SET::CloneDropTriangulation(), SHAPE_LINE_CHAIN::CPoint(), FormatDouble2Str(), GetPCBDefaultLayerName(), m_fp, GERBER_DRAW_ITEM::m_ShapeAsPolygon, MapToPcbUnits(), MAX_COORD_CNT, SHAPE_POLY_SET::Outline(), SHAPE_POLY_SET::OutlineCount(), SHAPE_POLY_SET::PM_FAST, SHAPE_LINE_CHAIN::PointCount(), SHAPE_POLY_SET::Simplify(), TO_UTF8, VECTOR2< T >::x, and VECTOR2< T >::y.

Referenced by export_copper_item().

Member Data Documentation

◆ m_fp

◆ m_gerbview_frame

GERBVIEW_FRAME* GBR_TO_PCB_EXPORTER::m_gerbview_frame
private

Definition at line 176 of file export_to_pcbnew.h.

Referenced by ExportPcb(), and GBR_TO_PCB_EXPORTER().

◆ m_pcb_file_name

wxString GBR_TO_PCB_EXPORTER::m_pcb_file_name
private

Definition at line 177 of file export_to_pcbnew.h.

Referenced by ExportPcb(), and GBR_TO_PCB_EXPORTER().

◆ m_pcbCopperLayersCount

int GBR_TO_PCB_EXPORTER::m_pcbCopperLayersCount
private

Definition at line 179 of file export_to_pcbnew.h.

Referenced by ExportPcb(), GBR_TO_PCB_EXPORTER(), and writePcbHeader().

◆ m_vias

std::vector<EXPORT_VIA> GBR_TO_PCB_EXPORTER::m_vias
private

Definition at line 180 of file export_to_pcbnew.h.

Referenced by collect_hole(), export_flashed_copper_item(), and ExportPcb().


The documentation for this class was generated from the following files: