KiCad PCB EDA Suite
GBR_TO_PCB_EXPORTER Class Reference

Public Member Functions

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

Private Member Functions

void export_non_copper_item (GERBER_DRAW_ITEM *aGbrItem, LAYER_NUM aLayer)
 write a non copper line or arc to the board file. More...
 
void writePcbPolygonItem (GERBER_DRAW_ITEM *aGbrItem, LAYER_NUM aLayer)
 write a non copper polygon item to the board file. More...
 
void export_copper_item (GERBER_DRAW_ITEM *aGbrItem, LAYER_NUM aLayer)
 write a track or via) to the board file. More...
 
void export_flashed_copper_item (GERBER_DRAW_ITEM *aGbrItem)
 Function export_flashed_copper_item write a via to the board file (always uses a via through). More...
 
void export_segline_copper_item (GERBER_DRAW_ITEM *aGbrItem, LAYER_NUM aLayer)
 Function export_segline_copper_item write a track (not via) to the board file. More...
 
void export_segarc_copper_item (GERBER_DRAW_ITEM *aGbrItem, LAYER_NUM aLayer)
 Function export_segarc_copper_item write a set of tracks (arcs are approximated by track segments) to the board file. More...
 
void writePcbLineItem (bool aIsArc, wxPoint &aStart, wxPoint &aEnd, int aWidth, LAYER_NUM aLayer, double aAngle=0)
 function writePcbLineItem basic write function to write a DRAWSEGMENT item or a TRACK item to the board file, from a non flashed item More...
 
void writeCopperLineItem (wxPoint &aStart, wxPoint &aEnd, int aWidth, LAYER_NUM aLayer)
 function writeCopperLineItem basic write function to write a a TRACK item to the board file, from a non flashed item More...
 
void writePcbHeader (LAYER_NUM *aLayerLookUpTable)
 function writePcbHeader Write a very basic header to the board file More...
 
double MapToPcbUnits (int aValue)
 In Pcbnew files units are mm for coordinates. More...
 

Private Attributes

GERBVIEW_FRAMEm_gerbview_frame
 
wxString m_pcb_file_name
 
FILE * m_fp
 
int m_pcbCopperLayersCount
 
std::vector< wxPoint > m_vias_coordinates
 

Detailed Description

Definition at line 52 of file export_to_pcbnew.cpp.

Constructor & Destructor Documentation

◆ GBR_TO_PCB_EXPORTER()

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

Definition at line 151 of file export_to_pcbnew.cpp.

152 {
153  m_gerbview_frame = aFrame;
154  m_pcb_file_name = aFileName;
155  m_fp = NULL;
157 }
GERBVIEW_FRAME * m_gerbview_frame

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 160 of file export_to_pcbnew.cpp.

161 {
162 }

Member Function Documentation

◆ export_copper_item()

void GBR_TO_PCB_EXPORTER::export_copper_item ( GERBER_DRAW_ITEM aGbrItem,
LAYER_NUM  aLayer 
)
private

write a track or via) to the board file.

Parameters
aGbrItem= the Gerber item (line, arc, flashed) to export
aLayer= the copper layer to use

Definition at line 326 of file export_to_pcbnew.cpp.

327 {
328  switch( aGbrItem->m_Shape )
329  {
330  case GBR_SPOT_CIRCLE:
331  case GBR_SPOT_RECT:
332  case GBR_SPOT_OVAL:
333  // replace spots with vias when possible
334  export_flashed_copper_item( aGbrItem );
335  break;
336 
337  case GBR_ARC:
338  export_segarc_copper_item( aGbrItem, aLayer );
339  break;
340 
341  case GBR_POLYGON:
342  // Currently: Pcbnew does not really handle polygons on copper layers (no DRC test).
343  // However, we can export them if the purpose of this export is to help recreate a board
344  writePcbPolygonItem( aGbrItem, aLayer );
345  break;
346 
347  default:
348  export_segline_copper_item( aGbrItem, aLayer );
349  break;
350  }
351 }
void export_segline_copper_item(GERBER_DRAW_ITEM *aGbrItem, LAYER_NUM aLayer)
Function export_segline_copper_item write a track (not via) to the board file.
void export_flashed_copper_item(GERBER_DRAW_ITEM *aGbrItem)
Function export_flashed_copper_item write a via to the board file (always uses a via through).
void export_segarc_copper_item(GERBER_DRAW_ITEM *aGbrItem, LAYER_NUM aLayer)
Function export_segarc_copper_item write a set of tracks (arcs are approximated by track segments) to...
void writePcbPolygonItem(GERBER_DRAW_ITEM *aGbrItem, LAYER_NUM aLayer)
write a non copper polygon item to the board file.

References export_flashed_copper_item(), export_segarc_copper_item(), export_segline_copper_item(), GBR_ARC, GBR_POLYGON, GBR_SPOT_CIRCLE, GBR_SPOT_OVAL, GBR_SPOT_RECT, GERBER_DRAW_ITEM::m_Shape, and writePcbPolygonItem().

Referenced by ExportPcb().

◆ export_flashed_copper_item()

void GBR_TO_PCB_EXPORTER::export_flashed_copper_item ( GERBER_DRAW_ITEM aGbrItem)
private

Function export_flashed_copper_item write a via to the board file (always uses a via through).

Parameters
aGbrItem= the flashed Gerber item to export

Definition at line 440 of file export_to_pcbnew.cpp.

441 {
442  // First, explore already created vias, before creating a new via
443  for( unsigned ii = 0; ii < m_vias_coordinates.size(); ii++ )
444  {
445  if( m_vias_coordinates[ii] == aGbrItem->m_Start ) // Already created
446  return;
447  }
448 
449  m_vias_coordinates.push_back( aGbrItem->m_Start );
450 
451  wxPoint via_pos = aGbrItem->m_Start;
452  int width = (aGbrItem->m_Size.x + aGbrItem->m_Size.y) / 2;
453  // Reverse Y axis:
454  via_pos.y = -via_pos.y;
455 
456  // Layers are Front to Back
457  fprintf( m_fp, " (via (at %s %s) (size %s)",
458  Double2Str( MapToPcbUnits(via_pos.x) ).c_str(),
459  Double2Str( MapToPcbUnits(via_pos.y) ).c_str(),
460  Double2Str( MapToPcbUnits( width ) ).c_str() );
461 
462  fprintf( m_fp, " (layers %s %s))\n",
465 }
std::string Double2Str(double aValue)
Helper function Double2Str to print a float number without using scientific notation and no trailing ...
Definition: base_units.cpp:63
#define TO_UTF8(wxstring)
Macro TO_UTF8 converts a wxString to a UTF8 encoded C string for all wxWidgets build modes.
Definition: macros.h:48
std::vector< wxPoint > m_vias_coordinates
const wxString GetPCBDefaultLayerName(LAYER_NUM aLayerNumber)
double MapToPcbUnits(int aValue)
In Pcbnew files units are mm for coordinates.

References B_Cu, Double2Str(), F_Cu, GetPCBDefaultLayerName(), m_fp, GERBER_DRAW_ITEM::m_Size, GERBER_DRAW_ITEM::m_Start, m_vias_coordinates, MapToPcbUnits(), and TO_UTF8.

Referenced by export_copper_item().

◆ export_non_copper_item()

void GBR_TO_PCB_EXPORTER::export_non_copper_item ( GERBER_DRAW_ITEM aGbrItem,
LAYER_NUM  aLayer 
)
private

write a non copper line or arc to the board file.

Parameters
aGbrItem= the Gerber item (line, arc) to export
aLayer= the technical layer to use

Definition at line 289 of file export_to_pcbnew.cpp.

290 {
291  bool isArc = false;
292 
293  double angle = 0;
294  wxPoint seg_start = aGbrItem->m_Start;
295  wxPoint seg_end = aGbrItem->m_End;
296 
297  if( aGbrItem->m_Shape == GBR_POLYGON )
298  {
299  writePcbPolygonItem( aGbrItem, aLayer );
300  return;
301  }
302 
303  if( aGbrItem->m_Shape == GBR_ARC )
304  {
305  double a = atan2( (double) ( aGbrItem->m_Start.y - aGbrItem->m_ArcCentre.y),
306  (double) ( aGbrItem->m_Start.x - aGbrItem->m_ArcCentre.x ) );
307  double b = atan2( (double) ( aGbrItem->m_End.y - aGbrItem->m_ArcCentre.y ),
308  (double) ( aGbrItem->m_End.x - aGbrItem->m_ArcCentre.x ) );
309 
310  isArc = true;
311  angle = RAD2DEG(b - a);
312  seg_start = aGbrItem->m_ArcCentre;
313 
314  // Ensure arc orientation is CCW
315  if( angle < 0 )
316  angle += 360.0;
317  }
318 
319  // Reverse Y axis:
320  seg_start.y = -seg_start.y;
321  seg_end.y = -seg_end.y;
322  writePcbLineItem( isArc, seg_start, seg_end, aGbrItem->m_Size.x, aLayer, angle );
323 }
void writePcbLineItem(bool aIsArc, wxPoint &aStart, wxPoint &aEnd, int aWidth, LAYER_NUM aLayer, double aAngle=0)
function writePcbLineItem basic write function to write a DRAWSEGMENT item or a TRACK item to the boa...
double RAD2DEG(double rad)
Definition: trigo.h:211
void writePcbPolygonItem(GERBER_DRAW_ITEM *aGbrItem, LAYER_NUM aLayer)
write a non copper polygon item to the board file.
static DIRECTION_45::AngleType angle(const VECTOR2I &a, const VECTOR2I &b)

References PNS::angle(), GBR_ARC, GBR_POLYGON, GERBER_DRAW_ITEM::m_ArcCentre, GERBER_DRAW_ITEM::m_End, GERBER_DRAW_ITEM::m_Shape, GERBER_DRAW_ITEM::m_Size, GERBER_DRAW_ITEM::m_Start, RAD2DEG(), writePcbLineItem(), and writePcbPolygonItem().

Referenced by ExportPcb().

◆ export_segarc_copper_item()

void GBR_TO_PCB_EXPORTER::export_segarc_copper_item ( GERBER_DRAW_ITEM aGbrItem,
LAYER_NUM  aLayer 
)
private

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

Parameters
aGbrItem= the Gerber item (arc only) to export
aLayer= the copper layer to use

Definition at line 382 of file export_to_pcbnew.cpp.

383 {
384  double a = atan2( (double) ( aGbrItem->m_Start.y - aGbrItem->m_ArcCentre.y ),
385  (double) ( aGbrItem->m_Start.x - aGbrItem->m_ArcCentre.x ) );
386  double b = atan2( (double) ( aGbrItem->m_End.y - aGbrItem->m_ArcCentre.y ),
387  (double) ( aGbrItem->m_End.x - aGbrItem->m_ArcCentre.x ) );
388 
389  wxPoint start = aGbrItem->m_Start;
390  wxPoint end = aGbrItem->m_End;
391 
392  /* Because Pcbnew does not know arcs in tracks,
393  * approximate arc by segments (SEG_COUNT__CIRCLE segment per 360 deg)
394  * The arc is drawn anticlockwise from the start point to the end point.
395  */
396  #define SEG_COUNT_CIRCLE 16
397  #define DELTA_ANGLE 2 * M_PI / SEG_COUNT_CIRCLE
398 
399  // calculate the number of segments from a to b.
400  // we want CNT_PER_360 segments fo a circle
401  if( a > b )
402  b += 2 * M_PI;
403 
404  wxPoint curr_start = start;
405  wxPoint seg_start, seg_end;
406 
407  int ii = 1;
408 
409  for( double rot = a; rot < (b - DELTA_ANGLE); rot += DELTA_ANGLE, ii++ )
410  {
411  seg_start = curr_start;
412  wxPoint curr_end = start;
413  RotatePoint( &curr_end, aGbrItem->m_ArcCentre,
414  -RAD2DECIDEG( DELTA_ANGLE * ii ) );
415  seg_end = curr_end;
416  // Reverse Y axis:
417  seg_start.y = -seg_start.y;
418  seg_end.y = -seg_end.y;
419  writeCopperLineItem( seg_start, seg_end, aGbrItem->m_Size.x, aLayer );
420  curr_start = curr_end;
421  }
422 
423  if( end != curr_start )
424  {
425  seg_start = curr_start;
426  seg_end = end;
427  // Reverse Y axis:
428  seg_start.y = -seg_start.y;
429  seg_end.y = -seg_end.y;
430  writeCopperLineItem( seg_start, seg_end, aGbrItem->m_Size.x, aLayer );
431  }
432 }
double RAD2DECIDEG(double rad)
Definition: trigo.h:215
#define DELTA_ANGLE
void RotatePoint(int *pX, int *pY, double angle)
Definition: trigo.cpp:206
void writeCopperLineItem(wxPoint &aStart, wxPoint &aEnd, int aWidth, LAYER_NUM aLayer)
function writeCopperLineItem basic write function to write a a TRACK item to the board file,...

References DELTA_ANGLE, GERBER_DRAW_ITEM::m_ArcCentre, GERBER_DRAW_ITEM::m_End, GERBER_DRAW_ITEM::m_Size, GERBER_DRAW_ITEM::m_Start, RAD2DECIDEG(), RotatePoint(), and writeCopperLineItem().

Referenced by export_copper_item().

◆ export_segline_copper_item()

void GBR_TO_PCB_EXPORTER::export_segline_copper_item ( GERBER_DRAW_ITEM aGbrItem,
LAYER_NUM  aLayer 
)
private

Function export_segline_copper_item write a track (not via) to the board file.

Parameters
aGbrItem= the Gerber item (line only) to export
aLayer= the copper layer to use

Definition at line 354 of file export_to_pcbnew.cpp.

355 {
356  wxPoint seg_start, seg_end;
357 
358  seg_start = aGbrItem->m_Start;
359  seg_end = aGbrItem->m_End;
360 
361  // Reverse Y axis:
362  seg_start.y = -seg_start.y;
363  seg_end.y = -seg_end.y;
364 
365  writeCopperLineItem( seg_start, seg_end, aGbrItem->m_Size.x, aLayer );
366 }
void writeCopperLineItem(wxPoint &aStart, wxPoint &aEnd, int aWidth, LAYER_NUM aLayer)
function writeCopperLineItem basic write function to write a a TRACK item to the board file,...

References GERBER_DRAW_ITEM::m_End, GERBER_DRAW_ITEM::m_Size, GERBER_DRAW_ITEM::m_Start, and writeCopperLineItem().

Referenced by export_copper_item().

◆ ExportPcb()

bool GBR_TO_PCB_EXPORTER::ExportPcb ( LAYER_NUM aLayerLookUpTable,
int  aCopperLayers 
)

Function ExportPcb saves a board from a set of Gerber images.

Definition at line 218 of file export_to_pcbnew.cpp.

219 {
220  LOCALE_IO toggle; // toggles on, then off, the C locale.
221 
222  m_fp = wxFopen( m_pcb_file_name, wxT( "wt" ) );
223 
224  if( m_fp == NULL )
225  {
226  wxString msg;
227  msg.Printf( _( "Cannot create file \"%s\"" ), GetChars( m_pcb_file_name ) );
229  return false;
230  }
231 
232  m_pcbCopperLayersCount = aCopperLayers;
233 
234  writePcbHeader( aLayerLookUpTable );
235 
236  // create an image of gerber data
237  // First: non copper layers:
238  const int pcbCopperLayerMax = 31;
240 
241  for( unsigned layer = 0; layer < images->ImagesMaxCount(); ++layer )
242  {
243  GERBER_FILE_IMAGE* gerber = images->GetGbrImage( layer );
244 
245  if( gerber == NULL ) // Graphic layer not yet used
246  continue;
247 
248  LAYER_NUM pcb_layer_number = aLayerLookUpTable[layer];
249 
250  if( !IsPcbLayer( pcb_layer_number ) )
251  continue;
252 
253  if( pcb_layer_number <= pcbCopperLayerMax ) // copper layer
254  continue;
255 
256  GERBER_DRAW_ITEM* gerb_item = gerber->GetItemsList();
257 
258  for( ; gerb_item; gerb_item = gerb_item->Next() )
259  export_non_copper_item( gerb_item, pcb_layer_number );
260  }
261 
262  // Copper layers
263  for( unsigned layer = 0; layer < images->ImagesMaxCount(); ++layer )
264  {
265  GERBER_FILE_IMAGE* gerber = images->GetGbrImage( layer );
266 
267  if( gerber == NULL ) // Graphic layer not yet used
268  continue;
269 
270  LAYER_NUM pcb_layer_number = aLayerLookUpTable[layer];
271 
272  if( pcb_layer_number < 0 || pcb_layer_number > pcbCopperLayerMax )
273  continue;
274 
275  GERBER_DRAW_ITEM* gerb_item = gerber->GetItemsList();
276 
277  for( ; gerb_item; gerb_item = gerb_item->Next() )
278  export_copper_item( gerb_item, pcb_layer_number );
279  }
280 
281  fprintf( m_fp, ")\n" );
282 
283  fclose( m_fp );
284  m_fp = NULL;
285  return true;
286 }
void DisplayError(wxWindow *aParent, const wxString &aText, int aDisplayTime)
Display an error or warning message box with aMessage.
Definition: confirm.cpp:236
Instantiate the current locale within a scope in which you are expecting exceptions to be thrown.
Definition: common.h:154
Class GERBER_FILE_IMAGE holds the Image data and parameters for one gerber file and layer parameters ...
void export_non_copper_item(GERBER_DRAW_ITEM *aGbrItem, LAYER_NUM aLayer)
write a non copper line or arc to the board file.
GERBER_FILE_IMAGE_LIST is a helper class to handle a list of GERBER_FILE_IMAGE files which are loaded...
GERBER_FILE_IMAGE * GetGbrImage(int aIdx)
GERBVIEW_FRAME * m_gerbview_frame
#define _(s)
int LAYER_NUM
Type LAYER_NUM can be replaced with int and removed.
GBR_LAYOUT * GetGerberLayout() const
void export_copper_item(GERBER_DRAW_ITEM *aGbrItem, LAYER_NUM aLayer)
write a track or via) to the board file.
GERBER_DRAW_ITEM * Next() const
static const wxChar * GetChars(const wxString &s)
Function GetChars returns a wxChar* to the actual wxChar* data within a wxString, and is helpful for ...
Definition: macros.h:101
GERBER_DRAW_ITEM * GetItemsList()
Function GetItemsList.
GERBER_FILE_IMAGE_LIST * GetImagesList() const
Definition: gbr_layout.cpp:44
bool IsPcbLayer(LAYER_NUM aLayer)
Function IsPcbLayer tests whether a layer is a valid layer for pcbnew.
void writePcbHeader(LAYER_NUM *aLayerLookUpTable)
function writePcbHeader Write a very basic header to the board file

References _, DisplayError(), export_copper_item(), export_non_copper_item(), GetChars(), GERBER_FILE_IMAGE_LIST::GetGbrImage(), GERBVIEW_FRAME::GetGerberLayout(), GBR_LAYOUT::GetImagesList(), GERBER_FILE_IMAGE::GetItemsList(), GERBER_FILE_IMAGE_LIST::ImagesMaxCount(), IsPcbLayer(), m_fp, m_gerbview_frame, m_pcb_file_name, m_pcbCopperLayersCount, GERBER_DRAW_ITEM::Next(), and writePcbHeader().

Referenced by GERBVIEW_FRAME::ExportDataInPcbnewFormat().

◆ MapToPcbUnits()

double GBR_TO_PCB_EXPORTER::MapToPcbUnits ( int  aValue)
inlineprivate

In Pcbnew files units are mm for coordinates.

So MapToPcbUnits converts internal gerbview to mm any pcbnew value

Parameters
aValueis a coordinate value to convert in mm

Definition at line 144 of file export_to_pcbnew.cpp.

145  {
146  return aValue / IU_PER_MM;
147  }

Referenced by export_flashed_copper_item(), writeCopperLineItem(), writePcbLineItem(), and writePcbPolygonItem().

◆ writeCopperLineItem()

void GBR_TO_PCB_EXPORTER::writeCopperLineItem ( wxPoint &  aStart,
wxPoint &  aEnd,
int  aWidth,
LAYER_NUM  aLayer 
)
private

function writeCopperLineItem basic write function to write a a TRACK item to the board file, from a non flashed item

Definition at line 369 of file export_to_pcbnew.cpp.

371 {
372  fprintf( m_fp, "(segment (start %s %s) (end %s %s) (width %s) (layer %s) (net 0))\n",
373  Double2Str( MapToPcbUnits(aStart.x) ).c_str(),
374  Double2Str( MapToPcbUnits(aStart.y) ).c_str(),
375  Double2Str( MapToPcbUnits(aEnd.x) ).c_str(),
376  Double2Str( MapToPcbUnits(aEnd.y) ).c_str(),
377  Double2Str( MapToPcbUnits( aWidth ) ).c_str(),
378  TO_UTF8( GetPCBDefaultLayerName( aLayer ) ) );
379 }
std::string Double2Str(double aValue)
Helper function Double2Str to print a float number without using scientific notation and no trailing ...
Definition: base_units.cpp:63
#define TO_UTF8(wxstring)
Macro TO_UTF8 converts a wxString to a UTF8 encoded C string for all wxWidgets build modes.
Definition: macros.h:48
const wxString GetPCBDefaultLayerName(LAYER_NUM aLayerNumber)
double MapToPcbUnits(int aValue)
In Pcbnew files units are mm for coordinates.

References Double2Str(), GetPCBDefaultLayerName(), m_fp, MapToPcbUnits(), and TO_UTF8.

Referenced by export_segarc_copper_item(), and export_segline_copper_item().

◆ writePcbHeader()

void GBR_TO_PCB_EXPORTER::writePcbHeader ( LAYER_NUM aLayerLookUpTable)
private

function writePcbHeader Write a very basic header to the board file

Definition at line 467 of file export_to_pcbnew.cpp.

468 {
469  fprintf( m_fp, "(kicad_pcb (version 4) (host Gerbview \"%s\")\n\n",
470  TO_UTF8( GetBuildVersion() ) );
471 
472  // Write layers section
473  fprintf( m_fp, " (layers \n" );
474 
475  for( int ii = 0; ii < m_pcbCopperLayersCount; ii++ )
476  {
477  int id = ii;
478 
479  if( ii == m_pcbCopperLayersCount-1)
480  id = B_Cu;
481 
482  fprintf( m_fp, " (%d %s signal)\n", id, TO_UTF8( GetPCBDefaultLayerName( id ) ) );
483  }
484 
485  for( int ii = B_Adhes; ii < PCB_LAYER_ID_COUNT; ii++ )
486  {
487  if( GetPCBDefaultLayerName( ii ).IsEmpty() ) // Layer not available for export
488  continue;
489 
490  fprintf( m_fp, " (%d %s user)\n", ii, TO_UTF8( GetPCBDefaultLayerName( ii ) ) );
491  }
492 
493  fprintf( m_fp, " )\n\n" );
494 }
#define TO_UTF8(wxstring)
Macro TO_UTF8 converts a wxString to a UTF8 encoded C string for all wxWidgets build modes.
Definition: macros.h:48
wxString GetBuildVersion()
Function GetBuildVersion Return the build version string.
const wxString GetPCBDefaultLayerName(LAYER_NUM aLayerNumber)

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

Referenced by ExportPcb().

◆ writePcbLineItem()

void GBR_TO_PCB_EXPORTER::writePcbLineItem ( bool  aIsArc,
wxPoint &  aStart,
wxPoint &  aEnd,
int  aWidth,
LAYER_NUM  aLayer,
double  aAngle = 0 
)
private

function writePcbLineItem basic write function to write a DRAWSEGMENT item or a TRACK item to the board file, from a non flashed item

Definition at line 497 of file export_to_pcbnew.cpp.

499 {
500  if( aIsArc && ( aAngle == 360.0 || aAngle == 0 ) )
501  {
502  fprintf( m_fp, "(gr_circle (center %s %s) (end %s %s)(layer %s) (width %s))\n",
503  Double2Str( MapToPcbUnits(aStart.x) ).c_str(),
504  Double2Str( MapToPcbUnits(aStart.y) ).c_str(),
505  Double2Str( MapToPcbUnits(aEnd.x) ).c_str(),
506  Double2Str( MapToPcbUnits(aEnd.y) ).c_str(),
507  TO_UTF8( GetPCBDefaultLayerName( aLayer ) ),
508  Double2Str( MapToPcbUnits( aWidth ) ).c_str()
509  );
510  }
511  else if( aIsArc )
512  {
513  fprintf( m_fp, "(gr_arc (start %s %s) (end %s %s) (angle %s)(layer %s) (width %s))\n",
514  Double2Str( MapToPcbUnits(aStart.x) ).c_str(),
515  Double2Str( MapToPcbUnits(aStart.y) ).c_str(),
516  Double2Str( MapToPcbUnits(aEnd.x) ).c_str(),
517  Double2Str( MapToPcbUnits(aEnd.y) ).c_str(),
518  Double2Str( aAngle ).c_str(),
519  TO_UTF8( GetPCBDefaultLayerName( aLayer ) ),
520  Double2Str( MapToPcbUnits( aWidth ) ).c_str()
521  );
522  }
523  else
524  {
525  fprintf( m_fp, "(gr_line (start %s %s) (end %s %s)(layer %s) (width %s))\n",
526  Double2Str( MapToPcbUnits(aStart.x) ).c_str(),
527  Double2Str( MapToPcbUnits(aStart.y) ).c_str(),
528  Double2Str( MapToPcbUnits(aEnd.x) ).c_str(),
529  Double2Str( MapToPcbUnits(aEnd.y) ).c_str(),
530  TO_UTF8( GetPCBDefaultLayerName( aLayer ) ),
531  Double2Str( MapToPcbUnits( aWidth ) ).c_str()
532  );
533  }
534 }
std::string Double2Str(double aValue)
Helper function Double2Str to print a float number without using scientific notation and no trailing ...
Definition: base_units.cpp:63
#define TO_UTF8(wxstring)
Macro TO_UTF8 converts a wxString to a UTF8 encoded C string for all wxWidgets build modes.
Definition: macros.h:48
const wxString GetPCBDefaultLayerName(LAYER_NUM aLayerNumber)
double MapToPcbUnits(int aValue)
In Pcbnew files units are mm for coordinates.

References Double2Str(), GetPCBDefaultLayerName(), m_fp, MapToPcbUnits(), and TO_UTF8.

Referenced by export_non_copper_item().

◆ writePcbPolygonItem()

void GBR_TO_PCB_EXPORTER::writePcbPolygonItem ( GERBER_DRAW_ITEM aGbrItem,
LAYER_NUM  aLayer 
)
private

write a non copper polygon item to the board file.

Parameters
aGbrItem= the Gerber item (line, arc) to export
aLayer= the technical layer to use

Definition at line 537 of file export_to_pcbnew.cpp.

538 {
539  fprintf( m_fp, "(gr_poly (pts " );
540 
541  SHAPE_POLY_SET polys = aGbrItem->m_Polygon;
542  SHAPE_LINE_CHAIN& poly = polys.Outline( 0 );
543 
544  #define MAX_COORD_CNT 4
545  int jj = MAX_COORD_CNT;
546  int cnt_max = poly.PointCount() -1;
547 
548  // Do not generate last corner, if it is the same point as the first point:
549  if( poly.Point( 0 ) == poly.Point( cnt_max ) )
550  cnt_max--;
551 
552  for( int ii = 0; ii <= cnt_max; ii++ )
553  {
554  if( --jj == 0 )
555  {
556  jj = MAX_COORD_CNT;
557  fprintf( m_fp, "\n" );
558  }
559 
560  fprintf( m_fp, " (xy %s %s)",
561  Double2Str( MapToPcbUnits( poly.Point( ii ).x ) ).c_str(),
562  Double2Str( MapToPcbUnits( -poly.Point( ii ).y ) ).c_str() );
563  }
564 
565  fprintf( m_fp, ")" );
566 
567  if( jj != MAX_COORD_CNT )
568  fprintf( m_fp, "\n" );
569 
570  fprintf( m_fp, "(layer %s) (width 0) )\n",
571  TO_UTF8( GetPCBDefaultLayerName( aLayer ) ) );
572 }
std::string Double2Str(double aValue)
Helper function Double2Str to print a float number without using scientific notation and no trailing ...
Definition: base_units.cpp:63
int PointCount() const
Function PointCount()
SHAPE_POLY_SET m_Polygon
#define TO_UTF8(wxstring)
Macro TO_UTF8 converts a wxString to a UTF8 encoded C string for all wxWidgets build modes.
Definition: macros.h:48
Class SHAPE_POLY_SET.
SHAPE_LINE_CHAIN & Outline(int aIndex)
Returns the reference to aIndex-th outline in the set
#define MAX_COORD_CNT
Class SHAPE_LINE_CHAIN.
const wxString GetPCBDefaultLayerName(LAYER_NUM aLayerNumber)
VECTOR2I & Point(int aIndex)
Function Point()
double MapToPcbUnits(int aValue)
In Pcbnew files units are mm for coordinates.

References Double2Str(), GetPCBDefaultLayerName(), m_fp, GERBER_DRAW_ITEM::m_Polygon, MapToPcbUnits(), MAX_COORD_CNT, SHAPE_POLY_SET::Outline(), SHAPE_LINE_CHAIN::Point(), SHAPE_LINE_CHAIN::PointCount(), TO_UTF8, VECTOR2< T >::x, and VECTOR2< T >::y.

Referenced by export_copper_item(), and export_non_copper_item().

Member Data Documentation

◆ m_fp

◆ m_gerbview_frame

GERBVIEW_FRAME* GBR_TO_PCB_EXPORTER::m_gerbview_frame
private

Definition at line 55 of file export_to_pcbnew.cpp.

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 56 of file export_to_pcbnew.cpp.

Referenced by ExportPcb(), and GBR_TO_PCB_EXPORTER().

◆ m_pcbCopperLayersCount

int GBR_TO_PCB_EXPORTER::m_pcbCopperLayersCount
private

Definition at line 58 of file export_to_pcbnew.cpp.

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

◆ m_vias_coordinates

std::vector<wxPoint> GBR_TO_PCB_EXPORTER::m_vias_coordinates
private

Definition at line 59 of file export_to_pcbnew.cpp.

Referenced by export_flashed_copper_item().


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