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 anot filled polygon item to the board file. More...
 
void writePcbZoneItem (GERBER_DRAW_ITEM *aGbrItem, LAYER_NUM aLayer)
 write a zone 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< wxPointm_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 159 of file export_to_pcbnew.cpp.

160 {
161  m_gerbview_frame = aFrame;
162  m_pcb_file_name = aFileName;
163  m_fp = NULL;
165 }
#define NULL
GERBVIEW_FRAME * m_gerbview_frame

References m_fp, m_gerbview_frame, m_pcb_file_name, m_pcbCopperLayersCount, and NULL.

◆ ~GBR_TO_PCB_EXPORTER()

GBR_TO_PCB_EXPORTER::~GBR_TO_PCB_EXPORTER ( )

Definition at line 168 of file export_to_pcbnew.cpp.

169 {
170 }

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

331 {
332  switch( aGbrItem->m_Shape )
333  {
334  case GBR_SPOT_CIRCLE:
335  case GBR_SPOT_RECT:
336  case GBR_SPOT_OVAL:
337  // replace spots with vias when possible
338  export_flashed_copper_item( aGbrItem );
339  break;
340 
341  case GBR_ARC:
342  export_segarc_copper_item( aGbrItem, aLayer );
343  break;
344 
345  case GBR_POLYGON:
346  // One can use a polygon or a zone to output a Gerber region.
347  // none are perfect.
348  // The current way is use a polygon, as the zone export
349  // is exprimental and only for tests.
350 #if 1
351  writePcbPolygonItem( aGbrItem, aLayer );
352 #else
353  // Only for tests:
354  writePcbZoneItem( aGbrItem, aLayer );
355 #endif
356  break;
357 
358  default:
359  export_segline_copper_item( aGbrItem, aLayer );
360  break;
361  }
362 }
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 writePcbZoneItem(GERBER_DRAW_ITEM *aGbrItem, LAYER_NUM aLayer)
write a zone item 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 anot filled 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, writePcbPolygonItem(), and writePcbZoneItem().

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

452 {
453  // First, explore already created vias, before creating a new via
454  for( unsigned ii = 0; ii < m_vias_coordinates.size(); ii++ )
455  {
456  if( m_vias_coordinates[ii] == aGbrItem->m_Start ) // Already created
457  return;
458  }
459 
460  m_vias_coordinates.push_back( aGbrItem->m_Start );
461 
462  wxPoint via_pos = aGbrItem->m_Start;
463  int width = (aGbrItem->m_Size.x + aGbrItem->m_Size.y) / 2;
464  // Reverse Y axis:
465  via_pos.y = -via_pos.y;
466 
467  // Layers are Front to Back
468  fprintf( m_fp, " (via (at %s %s) (size %s)",
469  Double2Str( MapToPcbUnits(via_pos.x) ).c_str(),
470  Double2Str( MapToPcbUnits(via_pos.y) ).c_str(),
471  Double2Str( MapToPcbUnits( width ) ).c_str() );
472 
473  fprintf( m_fp, " (layers %s %s))\n",
476 }
std::string Double2Str(double aValue)
Helper function Double2Str to print a float number without using scientific notation and no trailing ...
Definition: base_units.cpp:65
#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(), TO_UTF8, wxPoint::x, and wxPoint::y.

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

294 {
295  bool isArc = false;
296 
297  double angle = 0;
298  wxPoint seg_start = aGbrItem->m_Start;
299  wxPoint seg_end = aGbrItem->m_End;
300 
301  if( aGbrItem->m_Shape == GBR_POLYGON )
302  {
303  writePcbPolygonItem( aGbrItem, aLayer );
304  return;
305  }
306 
307  if( aGbrItem->m_Shape == GBR_ARC )
308  {
309  double a = atan2( (double) ( aGbrItem->m_Start.y - aGbrItem->m_ArcCentre.y),
310  (double) ( aGbrItem->m_Start.x - aGbrItem->m_ArcCentre.x ) );
311  double b = atan2( (double) ( aGbrItem->m_End.y - aGbrItem->m_ArcCentre.y ),
312  (double) ( aGbrItem->m_End.x - aGbrItem->m_ArcCentre.x ) );
313 
314  isArc = true;
315  angle = RAD2DEG(b - a);
316  seg_start = aGbrItem->m_ArcCentre;
317 
318  // Ensure arc orientation is CCW
319  if( angle < 0 )
320  angle += 360.0;
321  }
322 
323  // Reverse Y axis:
324  seg_start.y = -seg_start.y;
325  seg_end.y = -seg_end.y;
326  writePcbLineItem( isArc, seg_start, seg_end, aGbrItem->m_Size.x, aLayer, angle );
327 }
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 anot filled 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(), writePcbPolygonItem(), wxPoint::x, and wxPoint::y.

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

394 {
395  double a = atan2( (double) ( aGbrItem->m_Start.y - aGbrItem->m_ArcCentre.y ),
396  (double) ( aGbrItem->m_Start.x - aGbrItem->m_ArcCentre.x ) );
397  double b = atan2( (double) ( aGbrItem->m_End.y - aGbrItem->m_ArcCentre.y ),
398  (double) ( aGbrItem->m_End.x - aGbrItem->m_ArcCentre.x ) );
399 
400  wxPoint start = aGbrItem->m_Start;
401  wxPoint end = aGbrItem->m_End;
402 
403  /* Because Pcbnew does not know arcs in tracks,
404  * approximate arc by segments (SEG_COUNT__CIRCLE segment per 360 deg)
405  * The arc is drawn anticlockwise from the start point to the end point.
406  */
407  #define SEG_COUNT_CIRCLE 16
408  #define DELTA_ANGLE 2 * M_PI / SEG_COUNT_CIRCLE
409 
410  // calculate the number of segments from a to b.
411  // we want CNT_PER_360 segments fo a circle
412  if( a > b )
413  b += 2 * M_PI;
414 
415  wxPoint curr_start = start;
416  wxPoint seg_start, seg_end;
417 
418  int ii = 1;
419 
420  for( double rot = a; rot < (b - DELTA_ANGLE); rot += DELTA_ANGLE, ii++ )
421  {
422  seg_start = curr_start;
423  wxPoint curr_end = start;
424  RotatePoint( &curr_end, aGbrItem->m_ArcCentre,
425  -RAD2DECIDEG( DELTA_ANGLE * ii ) );
426  seg_end = curr_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  curr_start = curr_end;
432  }
433 
434  if( end != curr_start )
435  {
436  seg_start = curr_start;
437  seg_end = end;
438  // Reverse Y axis:
439  seg_start.y = -seg_start.y;
440  seg_end.y = -seg_end.y;
441  writeCopperLineItem( seg_start, seg_end, aGbrItem->m_Size.x, aLayer );
442  }
443 }
double RAD2DECIDEG(double rad)
Definition: trigo.h:215
#define DELTA_ANGLE
void RotatePoint(int *pX, int *pY, double angle)
Definition: trigo.cpp:208
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(), writeCopperLineItem(), wxPoint::x, and wxPoint::y.

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

366 {
367  wxPoint seg_start, seg_end;
368 
369  seg_start = aGbrItem->m_Start;
370  seg_end = aGbrItem->m_End;
371 
372  // Reverse Y axis:
373  seg_start.y = -seg_start.y;
374  seg_end.y = -seg_end.y;
375 
376  writeCopperLineItem( seg_start, seg_end, aGbrItem->m_Size.x, aLayer );
377 }
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, writeCopperLineItem(), and wxPoint::y.

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

227 {
228  LOCALE_IO toggle; // toggles on, then off, the C locale.
229 
230  m_fp = wxFopen( m_pcb_file_name, wxT( "wt" ) );
231 
232  if( m_fp == NULL )
233  {
234  wxString msg;
235  msg.Printf( _( "Cannot create file \"%s\"" ), GetChars( m_pcb_file_name ) );
237  return false;
238  }
239 
240  m_pcbCopperLayersCount = aCopperLayers;
241 
242  writePcbHeader( aLayerLookUpTable );
243 
244  // create an image of gerber data
245  // First: non copper layers:
246  const int pcbCopperLayerMax = 31;
248 
249  for( unsigned layer = 0; layer < images->ImagesMaxCount(); ++layer )
250  {
251  GERBER_FILE_IMAGE* gerber = images->GetGbrImage( layer );
252 
253  if( gerber == NULL ) // Graphic layer not yet used
254  continue;
255 
256  LAYER_NUM pcb_layer_number = aLayerLookUpTable[layer];
257 
258  if( !IsPcbLayer( pcb_layer_number ) )
259  continue;
260 
261  if( pcb_layer_number <= pcbCopperLayerMax ) // copper layer
262  continue;
263 
264  for( GERBER_DRAW_ITEM* gerb_item : gerber->GetItems() )
265  export_non_copper_item( gerb_item, pcb_layer_number );
266  }
267 
268  // Copper layers
269  for( unsigned layer = 0; layer < images->ImagesMaxCount(); ++layer )
270  {
271  GERBER_FILE_IMAGE* gerber = images->GetGbrImage( layer );
272 
273  if( gerber == NULL ) // Graphic layer not yet used
274  continue;
275 
276  LAYER_NUM pcb_layer_number = aLayerLookUpTable[layer];
277 
278  if( pcb_layer_number < 0 || pcb_layer_number > pcbCopperLayerMax )
279  continue;
280 
281  for( GERBER_DRAW_ITEM* gerb_item : gerber->GetItems() )
282  export_copper_item( gerb_item, pcb_layer_number );
283  }
284 
285  fprintf( m_fp, ")\n" );
286 
287  fclose( m_fp );
288  m_fp = NULL;
289  return true;
290 }
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:90
GERBER_DRAW_ITEMS & GetItems()
GERBER_FILE_IMAGE holds the Image data and parameters for one gerber file and layer parameters (TODO:...
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...
#define NULL
GERBER_FILE_IMAGE * GetGbrImage(int aIdx)
GERBVIEW_FRAME * m_gerbview_frame
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.
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
#define _(s)
Definition: 3d_actions.cpp:31
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::GetItems(), GERBER_FILE_IMAGE_LIST::ImagesMaxCount(), IsPcbLayer(), m_fp, m_gerbview_frame, m_pcb_file_name, m_pcbCopperLayersCount, NULL, 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 152 of file export_to_pcbnew.cpp.

153  {
154  return aValue / IU_PER_MM;
155  }

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

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

382 {
383  fprintf( m_fp, "(segment (start %s %s) (end %s %s) (width %s) (layer %s) (net 0))\n",
384  Double2Str( MapToPcbUnits(aStart.x) ).c_str(),
385  Double2Str( MapToPcbUnits(aStart.y) ).c_str(),
386  Double2Str( MapToPcbUnits(aEnd.x) ).c_str(),
387  Double2Str( MapToPcbUnits(aEnd.y) ).c_str(),
388  Double2Str( MapToPcbUnits( aWidth ) ).c_str(),
389  TO_UTF8( GetPCBDefaultLayerName( aLayer ) ) );
390 }
std::string Double2Str(double aValue)
Helper function Double2Str to print a float number without using scientific notation and no trailing ...
Definition: base_units.cpp:65
#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(), TO_UTF8, wxPoint::x, and wxPoint::y.

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

479 {
480  fprintf( m_fp, "(kicad_pcb (version 4) (host Gerbview \"%s\")\n\n",
481  TO_UTF8( GetBuildVersion() ) );
482 
483  // Write layers section
484  fprintf( m_fp, " (layers \n" );
485 
486  for( int ii = 0; ii < m_pcbCopperLayersCount; ii++ )
487  {
488  int id = ii;
489 
490  if( ii == m_pcbCopperLayersCount-1)
491  id = B_Cu;
492 
493  fprintf( m_fp, " (%d %s signal)\n", id, TO_UTF8( GetPCBDefaultLayerName( id ) ) );
494  }
495 
496  for( int ii = B_Adhes; ii < PCB_LAYER_ID_COUNT; ii++ )
497  {
498  if( GetPCBDefaultLayerName( ii ).IsEmpty() ) // Layer not available for export
499  continue;
500 
501  fprintf( m_fp, " (%d %s user)\n", ii, TO_UTF8( GetPCBDefaultLayerName( ii ) ) );
502  }
503 
504  fprintf( m_fp, " )\n\n" );
505 }
#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 508 of file export_to_pcbnew.cpp.

510 {
511  if( aIsArc && ( aAngle == 360.0 || aAngle == 0 ) )
512  {
513  fprintf( m_fp, "(gr_circle (center %s %s) (end %s %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  TO_UTF8( GetPCBDefaultLayerName( aLayer ) ),
519  Double2Str( MapToPcbUnits( aWidth ) ).c_str()
520  );
521  }
522  else if( aIsArc )
523  {
524  fprintf( m_fp, "(gr_arc (start %s %s) (end %s %s) (angle %s)(layer %s) (width %s))\n",
525  Double2Str( MapToPcbUnits(aStart.x) ).c_str(),
526  Double2Str( MapToPcbUnits(aStart.y) ).c_str(),
527  Double2Str( MapToPcbUnits(aEnd.x) ).c_str(),
528  Double2Str( MapToPcbUnits(aEnd.y) ).c_str(),
529  Double2Str( aAngle ).c_str(),
530  TO_UTF8( GetPCBDefaultLayerName( aLayer ) ),
531  Double2Str( MapToPcbUnits( aWidth ) ).c_str()
532  );
533  }
534  else
535  {
536  fprintf( m_fp, "(gr_line (start %s %s) (end %s %s)(layer %s) (width %s))\n",
537  Double2Str( MapToPcbUnits(aStart.x) ).c_str(),
538  Double2Str( MapToPcbUnits(aStart.y) ).c_str(),
539  Double2Str( MapToPcbUnits(aEnd.x) ).c_str(),
540  Double2Str( MapToPcbUnits(aEnd.y) ).c_str(),
541  TO_UTF8( GetPCBDefaultLayerName( aLayer ) ),
542  Double2Str( MapToPcbUnits( aWidth ) ).c_str()
543  );
544  }
545 }
std::string Double2Str(double aValue)
Helper function Double2Str to print a float number without using scientific notation and no trailing ...
Definition: base_units.cpp:65
#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(), TO_UTF8, wxPoint::x, and wxPoint::y.

Referenced by export_non_copper_item().

◆ writePcbPolygonItem()

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

write anot filled polygon item to the board file.

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

Definition at line 548 of file export_to_pcbnew.cpp.

549 {
550  SHAPE_POLY_SET polys = aGbrItem->m_Polygon;
551 
552  // Cleanup the polygon
554 
555  // Ensure the polygon is valid:
556  if( polys.OutlineCount() == 0 )
557  return;
558 
560 
561  SHAPE_LINE_CHAIN& poly = polys.Outline( 0 );
562 
563  fprintf( m_fp, "(gr_poly (pts " );
564 
565  #define MAX_COORD_CNT 4
566  int jj = MAX_COORD_CNT;
567  int cnt_max = poly.PointCount() -1;
568 
569  // Do not generate last corner, if it is the same point as the first point:
570  if( poly.CPoint( 0 ) == poly.CPoint( cnt_max ) )
571  cnt_max--;
572 
573  for( int ii = 0; ii <= cnt_max; ii++ )
574  {
575  if( --jj == 0 )
576  {
577  jj = MAX_COORD_CNT;
578  fprintf( m_fp, "\n" );
579  }
580 
581  fprintf( m_fp, " (xy %s %s)", Double2Str( MapToPcbUnits( poly.CPoint( ii ).x ) ).c_str(),
582  Double2Str( MapToPcbUnits( -poly.CPoint( ii ).y ) ).c_str() );
583  }
584 
585  fprintf( m_fp, ")" );
586 
587  if( jj != MAX_COORD_CNT )
588  fprintf( m_fp, "\n" );
589 
590  fprintf( m_fp, "(layer %s) (width 0) )\n",
591  TO_UTF8( GetPCBDefaultLayerName( aLayer ) ) );
592 }
int OutlineCount() const
Returns the number of outlines in the set
std::string Double2Str(double aValue)
Helper function Double2Str to print a float number without using scientific notation and no trailing ...
Definition: base_units.cpp:65
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
const VECTOR2I & CPoint(int aIndex) const
Function Point()
SHAPE_POLY_SET.
SHAPE_LINE_CHAIN & Outline(int aIndex)
Returns the reference to aIndex-th outline in the set
void Simplify(POLYGON_MODE aFastMode)
Simplifies the polyset (merges overlapping polys, eliminates degeneracy/self-intersections) For aFast...
void Fracture(POLYGON_MODE aFastMode)
Converts a set of polygons with holes to a singe outline with "slits"/"fractures" connecting the oute...
#define MAX_COORD_CNT
SHAPE_LINE_CHAIN.
const wxString GetPCBDefaultLayerName(LAYER_NUM aLayerNumber)
double MapToPcbUnits(int aValue)
In Pcbnew files units are mm for coordinates.

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

Referenced by export_copper_item(), and export_non_copper_item().

◆ writePcbZoneItem()

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

write a zone item to the board file.

Currently: only experimental, for tests

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

Definition at line 595 of file export_to_pcbnew.cpp.

596 {
597  SHAPE_POLY_SET polys = aGbrItem->m_Polygon;
599 
600  if( polys.OutlineCount() == 0 )
601  return;
602 
603  fprintf( m_fp, "(zone (net 0) (net_name \"\") (layer %s) (tstamp 0000000) (hatch edge 0.508)\n",
604  TO_UTF8( GetPCBDefaultLayerName( aLayer ) ) );
605 
606  fprintf( m_fp, " (connect_pads (clearance 0.0))\n" );
607 
608  fprintf( m_fp, " (min_thickness 0.1) (filled_areas_thickness no)\n"
609  " (fill (thermal_gap 0.3) (thermal_bridge_width 0.3))\n" );
610 
611  // Now, write the zone outlines with holes.
612  // first polygon is the main outline, next are holes
613  // One cannot know the initial zone outline.
614  // However most of (if not all) holes are just items with clearance,
615  // not really a hole in the initial zone outline.
616  // So we build a zone outline only with no hole.
617  fprintf( m_fp, " (polygon\n (pts" );
618 
619  SHAPE_LINE_CHAIN& poly = polys.Outline( 0 );
620 
621  #define MAX_COORD_CNT 4
622  int jj = MAX_COORD_CNT;
623  int cnt_max = poly.PointCount() -1;
624 
625  // Do not generate last corner, if it is the same point as the first point:
626  if( poly.CPoint( 0 ) == poly.CPoint( cnt_max ) )
627  cnt_max--;
628 
629  for( int ii = 0; ii <= cnt_max; ii++ )
630  {
631  if( --jj == 0 )
632  {
633  jj = MAX_COORD_CNT;
634  fprintf( m_fp, "\n " );
635  }
636 
637  fprintf( m_fp, " (xy %s %s)", Double2Str( MapToPcbUnits( poly.CPoint( ii ).x ) ).c_str(),
638  Double2Str( MapToPcbUnits( -poly.CPoint( ii ).y ) ).c_str() );
639  }
640 
641  fprintf( m_fp, ")\n" );
642 
643  fprintf( m_fp, " )\n)\n" );
644 }
int OutlineCount() const
Returns the number of outlines in the set
std::string Double2Str(double aValue)
Helper function Double2Str to print a float number without using scientific notation and no trailing ...
Definition: base_units.cpp:65
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
const VECTOR2I & CPoint(int aIndex) const
Function Point()
SHAPE_POLY_SET.
SHAPE_LINE_CHAIN & Outline(int aIndex)
Returns the reference to aIndex-th outline in the set
void Simplify(POLYGON_MODE aFastMode)
Simplifies the polyset (merges overlapping polys, eliminates degeneracy/self-intersections) For aFast...
#define MAX_COORD_CNT
SHAPE_LINE_CHAIN.
const wxString GetPCBDefaultLayerName(LAYER_NUM aLayerNumber)
double MapToPcbUnits(int aValue)
In Pcbnew files units are mm for coordinates.

References SHAPE_LINE_CHAIN::CPoint(), Double2Str(), GetPCBDefaultLayerName(), m_fp, GERBER_DRAW_ITEM::m_Polygon, MapToPcbUnits(), MAX_COORD_CNT, SHAPE_POLY_SET::Outline(), SHAPE_POLY_SET::OutlineCount(), SHAPE_POLY_SET::PM_STRICTLY_SIMPLE, 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 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: