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...
 

Private Attributes

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

Detailed Description

Definition at line 53 of file export_to_pcbnew.cpp.

Constructor & Destructor Documentation

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

Definition at line 143 of file export_to_pcbnew.cpp.

References m_fp, m_gerbview_frame, m_pcb_file_name, and m_pcbCopperLayersCount.

144 {
145  m_gerbview_frame = aFrame;
146  m_pcb_file_name = aFileName;
147  m_fp = NULL;
149 }
GERBVIEW_FRAME * m_gerbview_frame
GBR_TO_PCB_EXPORTER::~GBR_TO_PCB_EXPORTER ( )

Definition at line 152 of file export_to_pcbnew.cpp.

153 {
154 }

Member Function Documentation

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

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().

319 {
320  switch( aGbrItem->m_Shape )
321  {
322  case GBR_SPOT_CIRCLE:
323  case GBR_SPOT_RECT:
324  case GBR_SPOT_OVAL:
325  // replace spots with vias when possible
326  export_flashed_copper_item( aGbrItem );
327  break;
328 
329  case GBR_ARC:
330  export_segarc_copper_item( aGbrItem, aLayer );
331  break;
332 
333  case GBR_POLYGON:
334  // Currently: Pcbnew does not really handle polygons on copper layers (no DRC test).
335  // However, we can export them if the purpose of this export is to help recreate a board
336  writePcbPolygonItem( aGbrItem, aLayer );
337  break;
338 
339  default:
340  export_segline_copper_item( aGbrItem, aLayer );
341  break;
342  }
343 }
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.
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 432 of file export_to_pcbnew.cpp.

References B_Cu, Double2Str(), F_Cu, GetPCBDefaultLayerName(), m_fp, GERBER_DRAW_ITEM::m_Size, GERBER_DRAW_ITEM::m_Start, m_vias_coordinates, TO_PCB_UNIT, TO_UTF8, wxPoint::x, and wxPoint::y.

Referenced by export_copper_item().

433 {
434  // First, explore already created vias, before creating a new via
435  for( unsigned ii = 0; ii < m_vias_coordinates.size(); ii++ )
436  {
437  if( m_vias_coordinates[ii] == aGbrItem->m_Start ) // Already created
438  return;
439  }
440 
441  m_vias_coordinates.push_back( aGbrItem->m_Start );
442 
443  wxPoint via_pos = aGbrItem->m_Start;
444  int width = (aGbrItem->m_Size.x + aGbrItem->m_Size.y) / 2;
445  // Reverse Y axis:
446  via_pos.y = -via_pos.y;
447 
448  // Layers are Front to Back
449  fprintf( m_fp, " (via (at %s %s) (size %s)",
450  Double2Str( TO_PCB_UNIT(via_pos.x) ).c_str(),
451  Double2Str( TO_PCB_UNIT(via_pos.y) ).c_str(),
452  Double2Str( TO_PCB_UNIT( width ) ).c_str() );
453 
454  fprintf( m_fp, " (layers %s %s))\n",
457 }
#define TO_PCB_UNIT(x)
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:47
std::vector< wxPoint > m_vias_coordinates
const wxString GetPCBDefaultLayerName(LAYER_NUM aLayerNumber)
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 281 of file export_to_pcbnew.cpp.

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(), writePcbPolygonItem(), wxPoint::x, and wxPoint::y.

Referenced by ExportPcb().

282 {
283  bool isArc = false;
284 
285  double angle = 0;
286  wxPoint seg_start = aGbrItem->m_Start;
287  wxPoint seg_end = aGbrItem->m_End;
288 
289  if( aGbrItem->m_Shape == GBR_POLYGON )
290  {
291  writePcbPolygonItem( aGbrItem, aLayer );
292  return;
293  }
294 
295  if( aGbrItem->m_Shape == GBR_ARC )
296  {
297  double a = atan2( (double) ( aGbrItem->m_Start.y - aGbrItem->m_ArcCentre.y),
298  (double) ( aGbrItem->m_Start.x - aGbrItem->m_ArcCentre.x ) );
299  double b = atan2( (double) ( aGbrItem->m_End.y - aGbrItem->m_ArcCentre.y ),
300  (double) ( aGbrItem->m_End.x - aGbrItem->m_ArcCentre.x ) );
301 
302  isArc = true;
303  angle = RAD2DEG(b - a);
304  seg_start = aGbrItem->m_ArcCentre;
305 
306  // Ensure arc orientation is CCW
307  if( angle < 0 )
308  angle += 360.0;
309  }
310 
311  // Reverse Y axis:
312  seg_start.y = -seg_start.y;
313  seg_end.y = -seg_end.y;
314  writePcbLineItem( isArc, seg_start, seg_end, aGbrItem->m_Size.x, aLayer, angle );
315 }
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:200
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)
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 374 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, RAD2DECIDEG(), RotatePoint(), writeCopperLineItem(), wxPoint::x, and wxPoint::y.

Referenced by export_copper_item().

375 {
376  double a = atan2( (double) ( aGbrItem->m_Start.y - aGbrItem->m_ArcCentre.y ),
377  (double) ( aGbrItem->m_Start.x - aGbrItem->m_ArcCentre.x ) );
378  double b = atan2( (double) ( aGbrItem->m_End.y - aGbrItem->m_ArcCentre.y ),
379  (double) ( aGbrItem->m_End.x - aGbrItem->m_ArcCentre.x ) );
380 
381  wxPoint start = aGbrItem->m_Start;
382  wxPoint end = aGbrItem->m_End;
383 
384  /* Because Pcbnew does not know arcs in tracks,
385  * approximate arc by segments (SEG_COUNT__CIRCLE segment per 360 deg)
386  * The arc is drawn anticlockwise from the start point to the end point.
387  */
388  #define SEG_COUNT_CIRCLE 16
389  #define DELTA_ANGLE 2 * M_PI / SEG_COUNT_CIRCLE
390 
391  // calculate the number of segments from a to b.
392  // we want CNT_PER_360 segments fo a circle
393  if( a > b )
394  b += 2 * M_PI;
395 
396  wxPoint curr_start = start;
397  wxPoint seg_start, seg_end;
398 
399  int ii = 1;
400 
401  for( double rot = a; rot < (b - DELTA_ANGLE); rot += DELTA_ANGLE, ii++ )
402  {
403  seg_start = curr_start;
404  wxPoint curr_end = start;
405  RotatePoint( &curr_end, aGbrItem->m_ArcCentre,
406  -RAD2DECIDEG( DELTA_ANGLE * ii ) );
407  seg_end = curr_end;
408  // Reverse Y axis:
409  seg_start.y = -seg_start.y;
410  seg_end.y = -seg_end.y;
411  writeCopperLineItem( seg_start, seg_end, aGbrItem->m_Size.x, aLayer );
412  curr_start = curr_end;
413  }
414 
415  if( end != curr_start )
416  {
417  seg_start = curr_start;
418  seg_end = end;
419  // Reverse Y axis:
420  seg_start.y = -seg_start.y;
421  seg_end.y = -seg_end.y;
422  writeCopperLineItem( seg_start, seg_end, aGbrItem->m_Size.x, aLayer );
423  }
424 }
double RAD2DECIDEG(double rad)
Definition: trigo.h:204
#define DELTA_ANGLE
void RotatePoint(int *pX, int *pY, double angle)
Definition: trigo.cpp:216
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...
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 346 of file export_to_pcbnew.cpp.

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

Referenced by export_copper_item().

347 {
348  wxPoint seg_start, seg_end;
349 
350  seg_start = aGbrItem->m_Start;
351  seg_end = aGbrItem->m_End;
352 
353  // Reverse Y axis:
354  seg_start.y = -seg_start.y;
355  seg_end.y = -seg_end.y;
356 
357  writeCopperLineItem( seg_start, seg_end, aGbrItem->m_Size.x, aLayer );
358 }
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...
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 210 of file export_to_pcbnew.cpp.

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().

211 {
212  LOCALE_IO toggle; // toggles on, then off, the C locale.
213 
214  m_fp = wxFopen( m_pcb_file_name, wxT( "wt" ) );
215 
216  if( m_fp == NULL )
217  {
218  wxString msg;
219  msg.Printf( _( "Cannot create file \"%s\"" ), GetChars( m_pcb_file_name ) );
221  return false;
222  }
223 
224  m_pcbCopperLayersCount = aCopperLayers;
225 
226  writePcbHeader( aLayerLookUpTable );
227 
228  // create an image of gerber data
229  // First: non copper layers:
230  const int pcbCopperLayerMax = 31;
232 
233  for( unsigned layer = 0; layer < images->ImagesMaxCount(); ++layer )
234  {
235  GERBER_FILE_IMAGE* gerber = images->GetGbrImage( layer );
236 
237  if( gerber == NULL ) // Graphic layer not yet used
238  continue;
239 
240  LAYER_NUM pcb_layer_number = aLayerLookUpTable[layer];
241 
242  if( !IsPcbLayer( pcb_layer_number ) )
243  continue;
244 
245  if( pcb_layer_number <= pcbCopperLayerMax ) // copper layer
246  continue;
247 
248  GERBER_DRAW_ITEM* gerb_item = gerber->GetItemsList();
249 
250  for( ; gerb_item; gerb_item = gerb_item->Next() )
251  export_non_copper_item( gerb_item, pcb_layer_number );
252  }
253 
254  // Copper layers
255  for( unsigned layer = 0; layer < images->ImagesMaxCount(); ++layer )
256  {
257  GERBER_FILE_IMAGE* gerber = images->GetGbrImage( layer );
258 
259  if( gerber == NULL ) // Graphic layer not yet used
260  continue;
261 
262  LAYER_NUM pcb_layer_number = aLayerLookUpTable[layer];
263 
264  if( pcb_layer_number < 0 || pcb_layer_number > pcbCopperLayerMax )
265  continue;
266 
267  GERBER_DRAW_ITEM* gerb_item = gerber->GetItemsList();
268 
269  for( ; gerb_item; gerb_item = gerb_item->Next() )
270  export_copper_item( gerb_item, pcb_layer_number );
271  }
272 
273  fprintf( m_fp, ")\n" );
274 
275  fclose( m_fp );
276  m_fp = NULL;
277  return true;
278 }
Instantiate the current locale within a scope in which you are expecting exceptions to be thrown...
Definition: common.h:179
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)
GERBER_DRAW_ITEM * Next() const
GERBVIEW_FRAME * m_gerbview_frame
GBR_LAYOUT * GetGerberLayout() const
int LAYER_NUM
Type LAYER_NUM can be replaced with int and removed.
void export_copper_item(GERBER_DRAW_ITEM *aGbrItem, LAYER_NUM aLayer)
write a track or via) to the board file.
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:92
GERBER_DRAW_ITEM * GetItemsList()
Function GetItemsList.
GERBER_FILE_IMAGE_LIST * GetImagesList() const
Definition: gbr_layout.cpp:50
bool IsPcbLayer(LAYER_NUM aLayer)
Function IsPcbLayer tests whether a layer is a valid layer for pcbnew.
void DisplayError(wxWindow *parent, const wxString &text, int displaytime)
Function DisplayError displays an error or warning message box with aMessage.
Definition: confirm.cpp:245
void writePcbHeader(LAYER_NUM *aLayerLookUpTable)
function writePcbHeader Write a very basic header to the board file
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 361 of file export_to_pcbnew.cpp.

References Double2Str(), GetPCBDefaultLayerName(), m_fp, TO_PCB_UNIT, TO_UTF8, wxPoint::x, and wxPoint::y.

Referenced by export_segarc_copper_item(), and export_segline_copper_item().

363 {
364  fprintf( m_fp, "(segment (start %s %s) (end %s %s) (width %s) (layer %s) (net 0))\n",
365  Double2Str( TO_PCB_UNIT(aStart.x) ).c_str(),
366  Double2Str( TO_PCB_UNIT(aStart.y) ).c_str(),
367  Double2Str( TO_PCB_UNIT(aEnd.x) ).c_str(),
368  Double2Str( TO_PCB_UNIT(aEnd.y) ).c_str(),
369  Double2Str( TO_PCB_UNIT( aWidth ) ).c_str(),
370  TO_UTF8( GetPCBDefaultLayerName( aLayer ) ) );
371 }
#define TO_PCB_UNIT(x)
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:47
const wxString GetPCBDefaultLayerName(LAYER_NUM aLayerNumber)
void GBR_TO_PCB_EXPORTER::writePcbHeader ( LAYER_NUM aLayerLookUpTable)
private

function writePcbHeader Write a very basic header to the board file

Definition at line 459 of file export_to_pcbnew.cpp.

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

Referenced by ExportPcb().

460 {
461  fprintf( m_fp, "(kicad_pcb (version 4) (host Gerbview \"%s\")\n\n",
462  TO_UTF8( GetBuildVersion() ) );
463 
464  // Write layers section
465  fprintf( m_fp, " (layers \n" );
466 
467  for( int ii = 0; ii < m_pcbCopperLayersCount; ii++ )
468  {
469  int id = ii;
470 
471  if( ii == m_pcbCopperLayersCount-1)
472  id = B_Cu;
473 
474  fprintf( m_fp, " (%d %s signal)\n", id, TO_UTF8( GetPCBDefaultLayerName( id ) ) );
475  }
476 
477  for( int ii = B_Adhes; ii < PCB_LAYER_ID_COUNT; ii++ )
478  {
479  fprintf( m_fp, " (%d %s user)\n", ii, TO_UTF8( GetPCBDefaultLayerName( ii ) ) );
480  }
481 
482  fprintf( m_fp, " )\n\n" );
483 }
#define TO_UTF8(wxstring)
Macro TO_UTF8 converts a wxString to a UTF8 encoded C string for all wxWidgets build modes...
Definition: macros.h:47
wxString GetBuildVersion()
Function GetBuildVersion Return the build version string.
const wxString GetPCBDefaultLayerName(LAYER_NUM aLayerNumber)
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 486 of file export_to_pcbnew.cpp.

References Double2Str(), GetPCBDefaultLayerName(), m_fp, TO_PCB_UNIT, TO_UTF8, wxPoint::x, and wxPoint::y.

Referenced by export_non_copper_item().

488 {
489  if( aIsArc && ( aAngle == 360.0 || aAngle == 0 ) )
490  {
491  fprintf( m_fp, "(gr_circle (center %s %s) (end %s %s)(layer %s) (width %s))\n",
492  Double2Str( TO_PCB_UNIT(aStart.x) ).c_str(),
493  Double2Str( TO_PCB_UNIT(aStart.y) ).c_str(),
494  Double2Str( TO_PCB_UNIT(aEnd.x) ).c_str(),
495  Double2Str( TO_PCB_UNIT(aEnd.y) ).c_str(),
496  TO_UTF8( GetPCBDefaultLayerName( aLayer ) ),
497  Double2Str( TO_PCB_UNIT( aWidth ) ).c_str()
498  );
499  }
500  else if( aIsArc )
501  {
502  fprintf( m_fp, "(gr_arc (start %s %s) (end %s %s) (angle %s)(layer %s) (width %s))\n",
503  Double2Str( TO_PCB_UNIT(aStart.x) ).c_str(),
504  Double2Str( TO_PCB_UNIT(aStart.y) ).c_str(),
505  Double2Str( TO_PCB_UNIT(aEnd.x) ).c_str(),
506  Double2Str( TO_PCB_UNIT(aEnd.y) ).c_str(),
507  Double2Str( aAngle ).c_str(),
508  TO_UTF8( GetPCBDefaultLayerName( aLayer ) ),
509  Double2Str( TO_PCB_UNIT( aWidth ) ).c_str()
510  );
511  }
512  else
513  {
514  fprintf( m_fp, "(gr_line (start %s %s) (end %s %s)(layer %s) (width %s))\n",
515  Double2Str( TO_PCB_UNIT(aStart.x) ).c_str(),
516  Double2Str( TO_PCB_UNIT(aStart.y) ).c_str(),
517  Double2Str( TO_PCB_UNIT(aEnd.x) ).c_str(),
518  Double2Str( TO_PCB_UNIT(aEnd.y) ).c_str(),
519  TO_UTF8( GetPCBDefaultLayerName( aLayer ) ),
520  Double2Str( TO_PCB_UNIT( aWidth ) ).c_str()
521  );
522  }
523 }
#define TO_PCB_UNIT(x)
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:47
const wxString GetPCBDefaultLayerName(LAYER_NUM aLayerNumber)
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 526 of file export_to_pcbnew.cpp.

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

Referenced by export_copper_item(), and export_non_copper_item().

527 {
528  fprintf( m_fp, "(gr_poly (pts " );
529 
530  SHAPE_POLY_SET polys = aGbrItem->m_Polygon;
531  SHAPE_LINE_CHAIN& poly = polys.Outline( 0 );
532 
533  #define MAX_COORD_CNT 4
534  int jj = MAX_COORD_CNT;
535  int cnt_max = poly.PointCount() -1;
536 
537  // Do not generate last corner, if it is the same point as the first point:
538  if( poly.Point( 0 ) == poly.Point( cnt_max ) )
539  cnt_max--;
540 
541  for( int ii = 0; ii <= cnt_max; ii++ )
542  {
543  if( --jj == 0 )
544  {
545  jj = MAX_COORD_CNT;
546  fprintf( m_fp, "\n" );
547  }
548 
549  fprintf( m_fp, " (xy %s %s)",
550  Double2Str( TO_PCB_UNIT( poly.Point( ii ).x ) ).c_str(),
551  Double2Str( TO_PCB_UNIT( -poly.Point( ii ).y ) ).c_str() );
552  }
553 
554  fprintf( m_fp, ")" );
555 
556  if( jj != MAX_COORD_CNT )
557  fprintf( m_fp, "\n" );
558 
559  fprintf( m_fp, "(layer %s) (width 0) )\n",
560  TO_UTF8( GetPCBDefaultLayerName( aLayer ) ) );
561 }
#define TO_PCB_UNIT(x)
int PointCount() const
Function PointCount()
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
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:47
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()

Member Data Documentation

GERBVIEW_FRAME* GBR_TO_PCB_EXPORTER::m_gerbview_frame
private

Definition at line 56 of file export_to_pcbnew.cpp.

Referenced by ExportPcb(), and GBR_TO_PCB_EXPORTER().

wxString GBR_TO_PCB_EXPORTER::m_pcb_file_name
private

Definition at line 57 of file export_to_pcbnew.cpp.

Referenced by ExportPcb(), and GBR_TO_PCB_EXPORTER().

int GBR_TO_PCB_EXPORTER::m_pcbCopperLayersCount
private

Definition at line 59 of file export_to_pcbnew.cpp.

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

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

Definition at line 60 of file export_to_pcbnew.cpp.

Referenced by export_flashed_copper_item().


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