KiCad PCB EDA Suite
export_to_pcbnew.cpp
Go to the documentation of this file.
1 /*
2  * This program source code file is part of KiCad, a free EDA CAD application.
3  *
4  * Copyright (C) 2007-2014 Jean-Pierre Charras jp.charras at wanadoo.fr
5  * Copyright (C) 1992-2017 KiCad Developers, see change_log.txt for contributors.
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, you may find one here:
19  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
20  * or you may search the http://www.gnu.org website for the version 2 license,
21  * or you may write to the Free Software Foundation, Inc.,
22  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
23  */
24 
30 #include <vector>
31 
32 #include <fctsys.h>
33 #include <common.h>
34 #include <confirm.h>
35 #include <macros.h>
36 #include <trigo.h>
37 #include <gerbview_frame.h>
38 #include <gerber_file_image.h>
39 #include <gerber_file_image_list.h>
40 #include <select_layers_to_pcb.h>
41 #include <build_version.h>
43 #include "excellon_image.h"
44 
45 // Imported function
46 extern const wxString GetPCBDefaultLayerName( LAYER_NUM aLayerNumber );
47 
48 
49 struct EXPORT_VIA
50 {
51  EXPORT_VIA( const wxPoint& aPos, int aSize, int aDrill ) :
52  m_Pos( aPos ),
53  m_Size( aSize ),
54  m_Drill( aDrill )
55  { }
56 
58  int m_Size;
59  int m_Drill;
60 };
61 
62 
63 /* A helper class to export a Gerber set of files to Pcbnew
64  */
66 {
67 private:
68  GERBVIEW_FRAME* m_gerbview_frame; // the main gerber frame
69  wxString m_pcb_file_name; // BOARD file to write to
70  FILE* m_fp; // the board file
72  std::vector<EXPORT_VIA> m_vias;
73 public:
74  GBR_TO_PCB_EXPORTER( GERBVIEW_FRAME* aFrame, const wxString& aFileName );
76 
81  bool ExportPcb( LAYER_NUM* aLayerLookUpTable, int aCopperLayers );
82 
83 private:
89  void collect_hole( GERBER_DRAW_ITEM* aGbrItem );
90 
98  void export_via( const EXPORT_VIA& aVia );
99 
105  void export_non_copper_item( GERBER_DRAW_ITEM* aGbrItem, LAYER_NUM aLayer );
106 
111  void writePcbPolygon( const SHAPE_POLY_SET& aPolys, LAYER_NUM aLayer,
112  const wxPoint& aOffset = { 0, 0 } );
113 
120  void writePcbZoneItem( GERBER_DRAW_ITEM* aGbrItem, LAYER_NUM aLayer );
121 
127  void export_copper_item( GERBER_DRAW_ITEM* aGbrItem, LAYER_NUM aLayer );
128 
137  void export_flashed_copper_item( GERBER_DRAW_ITEM* aGbrItem, LAYER_NUM aLayer );
138 
145  void export_segline_copper_item( GERBER_DRAW_ITEM* aGbrItem, LAYER_NUM aLayer );
146 
154  void export_segarc_copper_item( GERBER_DRAW_ITEM* aGbrItem, LAYER_NUM aLayer );
155 
161  void writeCopperLineItem( wxPoint& aStart, wxPoint& aEnd,
162  int aWidth, LAYER_NUM aLayer );
163 
168  void writePcbHeader( LAYER_NUM* aLayerLookUpTable );
169 
174  double MapToPcbUnits( int aValue )
175  {
176  return aValue / IU_PER_MM;
177  }
178 };
179 
180 
181 GBR_TO_PCB_EXPORTER::GBR_TO_PCB_EXPORTER( GERBVIEW_FRAME* aFrame, const wxString& aFileName )
182 {
183  m_gerbview_frame = aFrame;
184  m_pcb_file_name = aFileName;
185  m_fp = NULL;
187 }
188 
189 
191 {
192 }
193 
194 
195 /* Export data in Pcbnew format
196  * remember Pcbnew uses a Y reversed axis, so we must negate all Y coordinates
197  */
198 void GERBVIEW_FRAME::ExportDataInPcbnewFormat( wxCommandEvent& event )
199 {
200  int layercount = 0;
201 
203 
204  // Count the Gerber layers which are actually currently used
205  for( LAYER_NUM ii = 0; ii < (LAYER_NUM)images->ImagesMaxCount(); ++ii )
206  {
207  if( images->GetGbrImage( ii ) )
208  layercount++;
209  }
210 
211  if( layercount == 0 )
212  {
213  DisplayInfoMessage( this, _( "None of the Gerber layers contain any data" ) );
214  return;
215  }
216 
217  wxString fileDialogName( wxT( "noname." ) + KiCadPcbFileExtension );
218  wxString path = m_mruPath;
219 
220  wxFileDialog filedlg( this, _( "Board File Name" ),
221  path, fileDialogName, PcbFileWildcard(),
222  wxFD_SAVE | wxFD_OVERWRITE_PROMPT );
223 
224  if( filedlg.ShowModal() == wxID_CANCEL )
225  return;
226 
227  wxFileName fileName = filedlg.GetPath();
228 
229  /* Install a dialog frame to choose the mapping
230  * between gerber layers and Pcbnew layers
231  */
232  LAYERS_MAP_DIALOG* layerdlg = new LAYERS_MAP_DIALOG( this );
233  int ok = layerdlg->ShowModal();
234  layerdlg->Destroy();
235 
236  if( ok != wxID_OK )
237  return;
238 
239  // If no extension was entered, then force the extension to be a KiCad PCB file
240  if( !fileName.HasExt() )
241  fileName.SetExt( KiCadPcbFileExtension );
242 
243  m_mruPath = fileName.GetPath();
244 
245  GBR_TO_PCB_EXPORTER gbr_exporter( this, fileName.GetFullPath() );
246 
247  gbr_exporter.ExportPcb( layerdlg->GetLayersLookUpTable(), layerdlg->GetCopperLayersCount() );
248 }
249 
250 
251 bool GBR_TO_PCB_EXPORTER::ExportPcb( LAYER_NUM* aLayerLookUpTable, int aCopperLayers )
252 {
253  LOCALE_IO toggle; // toggles on, then off, the C locale.
254 
255  m_fp = wxFopen( m_pcb_file_name, wxT( "wt" ) );
256 
257  if( m_fp == NULL )
258  {
259  wxString msg;
260  msg.Printf( _( "Cannot create file \"%s\"" ), m_pcb_file_name );
262  return false;
263  }
264 
265  m_pcbCopperLayersCount = aCopperLayers;
266 
267  writePcbHeader( aLayerLookUpTable );
268 
269  // create an image of gerber data
270  const int pcbCopperLayerMax = 31;
272 
273  // First collect all the holes. We'll use these to generate pads, vias, etc.
274  for( unsigned layer = 0; layer < images->ImagesMaxCount(); ++layer )
275  {
276  EXCELLON_IMAGE* excellon = dynamic_cast<EXCELLON_IMAGE*>( images->GetGbrImage( layer ) );
277 
278  if( excellon == NULL ) // Layer not yet used or not a drill image
279  continue;
280 
281  for( GERBER_DRAW_ITEM* gerb_item : excellon->GetItems() )
282  collect_hole( gerb_item );
283  }
284 
285  // Next: non copper layers:
286  for( unsigned layer = 0; layer < images->ImagesMaxCount(); ++layer )
287  {
288  GERBER_FILE_IMAGE* gerber = images->GetGbrImage( layer );
289 
290  if( gerber == NULL ) // Graphic layer not yet used
291  continue;
292 
293  LAYER_NUM pcb_layer_number = aLayerLookUpTable[layer];
294 
295  if( !IsPcbLayer( pcb_layer_number ) )
296  continue;
297 
298  if( pcb_layer_number <= pcbCopperLayerMax ) // copper layer
299  continue;
300 
301  for( GERBER_DRAW_ITEM* gerb_item : gerber->GetItems() )
302  export_non_copper_item( gerb_item, pcb_layer_number );
303  }
304 
305  // Copper layers
306  for( unsigned layer = 0; layer < images->ImagesMaxCount(); ++layer )
307  {
308  GERBER_FILE_IMAGE* gerber = images->GetGbrImage( layer );
309 
310  if( gerber == NULL ) // Graphic layer not yet used
311  continue;
312 
313  LAYER_NUM pcb_layer_number = aLayerLookUpTable[layer];
314 
315  if( pcb_layer_number < 0 || pcb_layer_number > pcbCopperLayerMax )
316  continue;
317 
318  for( GERBER_DRAW_ITEM* gerb_item : gerber->GetItems() )
319  export_copper_item( gerb_item, pcb_layer_number );
320  }
321 
322  // Now write out the holes we collected earlier as vias
323  for( const EXPORT_VIA& via : m_vias )
324  export_via( via );
325 
326  fprintf( m_fp, ")\n" );
327 
328  fclose( m_fp );
329  m_fp = NULL;
330  return true;
331 }
332 
333 
335 {
336  // used when a D_CODE is not found. default D_CODE to draw a flashed item
337  static D_CODE dummyD_CODE( 0 );
338 
339  wxPoint seg_start = aGbrItem->m_Start;
340  wxPoint seg_end = aGbrItem->m_End;
341  D_CODE* d_codeDescr = aGbrItem->GetDcodeDescr();
342  SHAPE_POLY_SET polygon;
343 
344  if( d_codeDescr == NULL )
345  d_codeDescr = &dummyD_CODE;
346 
347  switch( aGbrItem->m_Shape )
348  {
349  case GBR_POLYGON:
350  writePcbPolygon( aGbrItem->m_Polygon, aLayer );
351  break;
352 
353  case GBR_SPOT_CIRCLE:
354  case GBR_SPOT_RECT:
355  case GBR_SPOT_OVAL:
356  case GBR_SPOT_POLY:
357  case GBR_SPOT_MACRO:
358  d_codeDescr->ConvertShapeToPolygon();
359  writePcbPolygon( d_codeDescr->m_Polygon, aLayer, aGbrItem->GetABPosition( seg_start ) );
360  break;
361 
362  case GBR_ARC:
363  {
364  double a = atan2( (double) ( aGbrItem->m_Start.y - aGbrItem->m_ArcCentre.y ),
365  (double) ( aGbrItem->m_Start.x - aGbrItem->m_ArcCentre.x ) );
366  double b = atan2( (double) ( aGbrItem->m_End.y - aGbrItem->m_ArcCentre.y ),
367  (double) ( aGbrItem->m_End.x - aGbrItem->m_ArcCentre.x ) );
368 
369  double angle = RAD2DEG(b - a);
370  seg_start = aGbrItem->m_ArcCentre;
371 
372  // Ensure arc orientation is CCW
373  if( angle < 0 )
374  angle += 360.0;
375 
376  // Reverse Y axis:
377  seg_start.y = -seg_start.y;
378  seg_end.y = -seg_end.y;
379 
380  if( angle == 360.0 || angle == 0 )
381  {
382  fprintf( m_fp, "(gr_circle (center %s %s) (end %s %s) (layer %s) (width %s))\n",
383  Double2Str( MapToPcbUnits(seg_start.x) ).c_str(),
384  Double2Str( MapToPcbUnits(seg_start.y) ).c_str(),
385  Double2Str( MapToPcbUnits(seg_end.x) ).c_str(),
386  Double2Str( MapToPcbUnits(seg_end.y) ).c_str(),
387  TO_UTF8( GetPCBDefaultLayerName( aLayer ) ),
388  Double2Str( MapToPcbUnits( aGbrItem->m_Size.x ) ).c_str()
389  );
390  }
391  else
392  {
393  fprintf( m_fp, "(gr_arc (start %s %s) (end %s %s) (angle %s) (layer %s) (width %s))\n",
394  Double2Str( MapToPcbUnits(seg_start.x) ).c_str(),
395  Double2Str( MapToPcbUnits(seg_start.y) ).c_str(),
396  Double2Str( MapToPcbUnits(seg_end.x) ).c_str(),
397  Double2Str( MapToPcbUnits(seg_end.y) ).c_str(),
398  Double2Str( angle ).c_str(),
399  TO_UTF8( GetPCBDefaultLayerName( aLayer ) ),
400  Double2Str( MapToPcbUnits( aGbrItem->m_Size.x ) ).c_str()
401  );
402  }
403  }
404  break;
405 
406  case GBR_CIRCLE:
407  // Reverse Y axis:
408  seg_start.y = -seg_start.y;
409  seg_end.y = -seg_end.y;
410 
411  fprintf( m_fp, "(gr_circle (start %s %s) (end %s %s) (layer %s) (width %s))\n",
412  Double2Str( MapToPcbUnits( seg_start.x ) ).c_str(),
413  Double2Str( MapToPcbUnits( seg_start.y ) ).c_str(),
414  Double2Str( MapToPcbUnits( seg_end.x ) ).c_str(),
415  Double2Str( MapToPcbUnits( seg_end.y ) ).c_str(),
416  TO_UTF8( GetPCBDefaultLayerName( aLayer ) ),
417  Double2Str( MapToPcbUnits( aGbrItem->m_Size.x ) ).c_str() );
418  break;
419 
420  case GBR_SEGMENT:
421  // Reverse Y axis:
422  seg_start.y = -seg_start.y;
423  seg_end.y = -seg_end.y;
424 
425  fprintf( m_fp, "(gr_line (start %s %s) (end %s %s) (layer %s) (width %s))\n",
426  Double2Str( MapToPcbUnits( seg_start.x ) ).c_str(),
427  Double2Str( MapToPcbUnits( seg_start.y ) ).c_str(),
428  Double2Str( MapToPcbUnits( seg_end.x ) ).c_str(),
429  Double2Str( MapToPcbUnits( seg_end.y ) ).c_str(),
430  TO_UTF8( GetPCBDefaultLayerName( aLayer ) ),
431  Double2Str( MapToPcbUnits( aGbrItem->m_Size.x ) ).c_str() );
432  break;
433  }
434 }
435 
436 
437 /*
438  * Many holes will be pads, but we have no way to create those without modules, and creating
439  * a module per pad is not really viable.
440  *
441  * So we use vias to mimic holes, with the loss of any hole shape (as we only have round holes
442  * in vias at present).
443  *
444  * We start out with a via size minimally larger than the hole. We'll leave it this way if
445  * the pad gets drawn as a copper polygon, or increase it to the proper size if it has a
446  * circular, concentric copper flashing.
447  */
449 {
450  int size = std::min( aGbrItem->m_Size.x, aGbrItem->m_Size.y );
451  m_vias.emplace_back( aGbrItem->m_Start, size + 1, size );
452 }
453 
454 
456 {
457  wxPoint via_pos = aVia.m_Pos;
458 
459  // Reverse Y axis:
460  via_pos.y = -via_pos.y;
461 
462  // Layers are Front to Back
463  fprintf( m_fp, " (via (at %s %s) (size %s) (drill %s)",
464  Double2Str( MapToPcbUnits( via_pos.x ) ).c_str(),
465  Double2Str( MapToPcbUnits( via_pos.y ) ).c_str(),
466  Double2Str( MapToPcbUnits( aVia.m_Size ) ).c_str(),
467  Double2Str( MapToPcbUnits( aVia.m_Drill ) ).c_str() );
468 
469  fprintf( m_fp, " (layers %s %s))\n",
472 }
473 
474 
476 {
477  switch( aGbrItem->m_Shape )
478  {
479  case GBR_SPOT_CIRCLE:
480  case GBR_SPOT_RECT:
481  case GBR_SPOT_OVAL:
482  export_flashed_copper_item( aGbrItem, aLayer );
483  break;
484 
485  case GBR_ARC:
486  export_segarc_copper_item( aGbrItem, aLayer );
487  break;
488 
489  case GBR_POLYGON:
490  // One can use a polygon or a zone to output a Gerber region.
491  // none are perfect.
492  // The current way is use a polygon, as the zone export
493  // is exprimental and only for tests.
494 #if 1
495  writePcbPolygon( aGbrItem->m_Polygon, aLayer );
496 #else
497  // Only for tests:
498  writePcbZoneItem( aGbrItem, aLayer );
499 #endif
500  break;
501 
502  default:
503  export_segline_copper_item( aGbrItem, aLayer );
504  break;
505  }
506 }
507 
508 
510 {
511  wxPoint seg_start, seg_end;
512 
513  seg_start = aGbrItem->m_Start;
514  seg_end = aGbrItem->m_End;
515 
516  // Reverse Y axis:
517  seg_start.y = -seg_start.y;
518  seg_end.y = -seg_end.y;
519 
520  writeCopperLineItem( seg_start, seg_end, aGbrItem->m_Size.x, aLayer );
521 }
522 
523 
525  int aWidth, LAYER_NUM aLayer )
526 {
527  fprintf( m_fp, "(segment (start %s %s) (end %s %s) (width %s) (layer %s) (net 0))\n",
528  Double2Str( MapToPcbUnits(aStart.x) ).c_str(),
529  Double2Str( MapToPcbUnits(aStart.y) ).c_str(),
530  Double2Str( MapToPcbUnits(aEnd.x) ).c_str(),
531  Double2Str( MapToPcbUnits(aEnd.y) ).c_str(),
532  Double2Str( MapToPcbUnits( aWidth ) ).c_str(),
533  TO_UTF8( GetPCBDefaultLayerName( aLayer ) ) );
534 }
535 
536 
538 {
539  double a = atan2( (double) ( aGbrItem->m_Start.y - aGbrItem->m_ArcCentre.y ),
540  (double) ( aGbrItem->m_Start.x - aGbrItem->m_ArcCentre.x ) );
541  double b = atan2( (double) ( aGbrItem->m_End.y - aGbrItem->m_ArcCentre.y ),
542  (double) ( aGbrItem->m_End.x - aGbrItem->m_ArcCentre.x ) );
543 
544  wxPoint start = aGbrItem->m_Start;
545  wxPoint end = aGbrItem->m_End;
546 
547  /* Because Pcbnew does not know arcs in tracks,
548  * approximate arc by segments (SEG_COUNT__CIRCLE segment per 360 deg)
549  * The arc is drawn anticlockwise from the start point to the end point.
550  */
551  #define SEG_COUNT_CIRCLE 16
552  #define DELTA_ANGLE 2 * M_PI / SEG_COUNT_CIRCLE
553 
554  // calculate the number of segments from a to b.
555  // we want CNT_PER_360 segments fo a circle
556  if( a > b )
557  b += 2 * M_PI;
558 
559  wxPoint curr_start = start;
560  wxPoint seg_start, seg_end;
561 
562  int ii = 1;
563 
564  for( double rot = a; rot < (b - DELTA_ANGLE); rot += DELTA_ANGLE, ii++ )
565  {
566  seg_start = curr_start;
567  wxPoint curr_end = start;
568  RotatePoint( &curr_end, aGbrItem->m_ArcCentre,
569  -RAD2DECIDEG( DELTA_ANGLE * ii ) );
570  seg_end = curr_end;
571  // Reverse Y axis:
572  seg_start.y = -seg_start.y;
573  seg_end.y = -seg_end.y;
574  writeCopperLineItem( seg_start, seg_end, aGbrItem->m_Size.x, aLayer );
575  curr_start = curr_end;
576  }
577 
578  if( end != curr_start )
579  {
580  seg_start = curr_start;
581  seg_end = end;
582  // Reverse Y axis:
583  seg_start.y = -seg_start.y;
584  seg_end.y = -seg_end.y;
585  writeCopperLineItem( seg_start, seg_end, aGbrItem->m_Size.x, aLayer );
586  }
587 }
588 
589 
590 /*
591  * Flashed items are usually pads or vias. Pads are problematic because we have no way to
592  * represent one in Pcbnew outside of a module (and creating a module per pad isn't really
593  * viable).
594  * If we've already created a via from a hole, and the flashed copper item is a simple circle
595  * then we'll enlarge the via to the proper size. Otherwise we create a copper polygon to
596  * represent the flashed item (which is presumably a pad).
597  */
599  LAYER_NUM aLayer )
600 {
601  static D_CODE flashed_item_D_CODE( 0 );
602 
603  D_CODE* d_codeDescr = aGbrItem->GetDcodeDescr();
604  SHAPE_POLY_SET polygon;
605 
606  if( d_codeDescr == NULL )
607  d_codeDescr = &flashed_item_D_CODE;
608 
609  if( aGbrItem->m_Shape == GBR_SPOT_CIRCLE )
610  {
611  // See if there's a via that we can enlarge to fit this flashed item
612  for( EXPORT_VIA& via : m_vias )
613  {
614  if( via.m_Pos == aGbrItem->m_Start )
615  {
616  via.m_Size = std::max( via.m_Size, aGbrItem->m_Size.x );
617  return;
618  }
619  }
620  }
621 
622  d_codeDescr->ConvertShapeToPolygon();
623  wxPoint offset = aGbrItem->GetABPosition( aGbrItem->m_Start );
624 
625  writePcbPolygon( d_codeDescr->m_Polygon, aLayer, offset );
626 }
627 
628 
630 {
631  fprintf( m_fp, "(kicad_pcb (version 4) (host Gerbview \"%s\")\n\n",
632  TO_UTF8( GetBuildVersion() ) );
633 
634  // Write layers section
635  fprintf( m_fp, " (layers \n" );
636 
637  for( int ii = 0; ii < m_pcbCopperLayersCount; ii++ )
638  {
639  int id = ii;
640 
641  if( ii == m_pcbCopperLayersCount-1)
642  id = B_Cu;
643 
644  fprintf( m_fp, " (%d %s signal)\n", id, TO_UTF8( GetPCBDefaultLayerName( id ) ) );
645  }
646 
647  for( int ii = B_Adhes; ii < PCB_LAYER_ID_COUNT; ii++ )
648  {
649  if( GetPCBDefaultLayerName( ii ).IsEmpty() ) // Layer not available for export
650  continue;
651 
652  fprintf( m_fp, " (%d %s user)\n", ii, TO_UTF8( GetPCBDefaultLayerName( ii ) ) );
653  }
654 
655  fprintf( m_fp, " )\n\n" );
656 }
657 
658 
660  const wxPoint& aOffset )
661 {
662  SHAPE_POLY_SET polys = aPolys;
663 
664  // Cleanup the polygon
666 
667  // Ensure the polygon is valid:
668  if( polys.OutlineCount() == 0 )
669  return;
670 
672 
673  SHAPE_LINE_CHAIN& poly = polys.Outline( 0 );
674 
675  fprintf( m_fp, "(gr_poly (pts " );
676 
677  #define MAX_COORD_CNT 4
678  int jj = MAX_COORD_CNT;
679  int cnt_max = poly.PointCount() -1;
680 
681  // Do not generate last corner, if it is the same point as the first point:
682  if( poly.CPoint( 0 ) == poly.CPoint( cnt_max ) )
683  cnt_max--;
684 
685  for( int ii = 0; ii <= cnt_max; ii++ )
686  {
687  if( --jj == 0 )
688  {
689  jj = MAX_COORD_CNT;
690  fprintf( m_fp, "\n" );
691  }
692 
693  fprintf( m_fp, " (xy %s %s)",
694  Double2Str( MapToPcbUnits( poly.CPoint( ii ).x + aOffset.x ) ).c_str(),
695  Double2Str( MapToPcbUnits( -poly.CPoint( ii ).y + aOffset.y ) ).c_str() );
696  }
697 
698  fprintf( m_fp, ")" );
699 
700  if( jj != MAX_COORD_CNT )
701  fprintf( m_fp, "\n" );
702 
703  fprintf( m_fp, "(layer %s) (width 0) )\n",
704  TO_UTF8( GetPCBDefaultLayerName( aLayer ) ) );
705 }
706 
707 
709 {
710  SHAPE_POLY_SET polys = aGbrItem->m_Polygon;
712 
713  if( polys.OutlineCount() == 0 )
714  return;
715 
716  fprintf( m_fp, "(zone (net 0) (net_name \"\") (layer %s) (tstamp 0000000) (hatch edge 0.508)\n",
717  TO_UTF8( GetPCBDefaultLayerName( aLayer ) ) );
718 
719  fprintf( m_fp, " (connect_pads (clearance 0.0))\n" );
720 
721  fprintf( m_fp, " (min_thickness 0.1) (filled_areas_thickness no)\n"
722  " (fill (thermal_gap 0.3) (thermal_bridge_width 0.3))\n" );
723 
724  // Now, write the zone outlines with holes.
725  // first polygon is the main outline, next are holes
726  // One cannot know the initial zone outline.
727  // However most of (if not all) holes are just items with clearance,
728  // not really a hole in the initial zone outline.
729  // So we build a zone outline only with no hole.
730  fprintf( m_fp, " (polygon\n (pts" );
731 
732  SHAPE_LINE_CHAIN& poly = polys.Outline( 0 );
733 
734  #define MAX_COORD_CNT 4
735  int jj = MAX_COORD_CNT;
736  int cnt_max = poly.PointCount() -1;
737 
738  // Do not generate last corner, if it is the same point as the first point:
739  if( poly.CPoint( 0 ) == poly.CPoint( cnt_max ) )
740  cnt_max--;
741 
742  for( int ii = 0; ii <= cnt_max; ii++ )
743  {
744  if( --jj == 0 )
745  {
746  jj = MAX_COORD_CNT;
747  fprintf( m_fp, "\n " );
748  }
749 
750  fprintf( m_fp, " (xy %s %s)", Double2Str( MapToPcbUnits( poly.CPoint( ii ).x ) ).c_str(),
751  Double2Str( MapToPcbUnits( -poly.CPoint( ii ).y ) ).c_str() );
752  }
753 
754  fprintf( m_fp, ")\n" );
755 
756  fprintf( m_fp, " )\n)\n" );
757 }
void DisplayError(wxWindow *aParent, const wxString &aText, int aDisplayTime)
Display an error or warning message box with aMessage.
Definition: confirm.cpp:239
std::vector< EXPORT_VIA > m_vias
D_CODE * GetDcodeDescr() const
Function GetDcodeDescr returns the GetDcodeDescr of this object, or NULL.
int OutlineCount() const
Returns the number of outlines in the set
wxString m_mruPath
Instantiate the current locale within a scope in which you are expecting exceptions to be thrown.
Definition: common.h:216
void writePcbPolygon(const SHAPE_POLY_SET &aPolys, LAYER_NUM aLayer, const wxPoint &aOffset={ 0, 0 })
write a non-copper polygon to the board file.
GERBER_DRAW_ITEMS & GetItems()
This file is part of the common library.
wxSize m_Size
Horizontal and vertical dimensions.
Definition: dcode.h:94
static constexpr double IU_PER_MM
Mock up a conversion function.
GBR_TO_PCB_EXPORTER(GERBVIEW_FRAME *aFrame, const wxString &aFileName)
EXPORT_VIA(const wxPoint &aPos, int aSize, int aDrill)
double RAD2DEG(double rad)
Definition: trigo.h:220
GERBER_FILE_IMAGE holds the Image data and parameters for one gerber file and layer parameters (TODO:...
LAYER_NUM * GetLayersLookUpTable()
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.
double RAD2DECIDEG(double rad)
Definition: trigo.h:224
void export_non_copper_item(GERBER_DRAW_ITEM *aGbrItem, LAYER_NUM aLayer)
write a non copper line or arc to the board file.
std::string Double2Str(double aValue)
Helper function Double2Str to print a float number without using scientific notation and no trailing ...
Definition: base_units.cpp:62
void export_via(const EXPORT_VIA &aVia)
write a via to the board file.
#define DELTA_ANGLE
const std::string KiCadPcbFileExtension
void RotatePoint(int *pX, int *pY, double angle)
Definition: trigo.cpp:208
GERBER_FILE_IMAGE_LIST is a helper class to handle a list of GERBER_FILE_IMAGE files which are loaded...
int PointCount() const
Function PointCount()
SHAPE_POLY_SET m_Polygon
static int GetCopperLayersCount()
This file contains miscellaneous commonly used macros and functions.
#define TO_UTF8(wxstring)
Macro TO_UTF8 converts a wxString to a UTF8 encoded C string for all wxWidgets build modes.
Definition: macros.h:100
const VECTOR2I & CPoint(int aIndex) const
Function Point()
void writePcbZoneItem(GERBER_DRAW_ITEM *aGbrItem, LAYER_NUM aLayer)
write a zone item to the board file.
wxPoint GetABPosition(const wxPoint &aXYPosition) const
Function GetABPosition returns the image position of aPosition for this object.
#define NULL
GERBER_FILE_IMAGE * GetGbrImage(int aIdx)
wxString GetBuildVersion()
Get the full KiCad version string.
bool ExportPcb(LAYER_NUM *aLayerLookUpTable, int aCopperLayers)
Function ExportPcb saves a board from a set of Gerber images.
SHAPE_POLY_SET.
SHAPE_LINE_CHAIN & Outline(int aIndex)
Returns the reference to aIndex-th outline in the set
GERBVIEW_FRAME * m_gerbview_frame
Definition of file extensions used in Kicad.
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 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...
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.
void ExportDataInPcbnewFormat(wxCommandEvent &event)
D_CODE holds a gerber DCODE (also called Aperture) definition.
Definition: dcode.h:82
#define MAX_COORD_CNT
#define _(s)
Definition: 3d_actions.cpp:33
SHAPE_LINE_CHAIN.
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...
static DIRECTION_45::AngleType angle(const VECTOR2I &a, const VECTOR2I &b)
const wxString GetPCBDefaultLayerName(LAYER_NUM aLayerNumber)
GERBER_FILE_IMAGE_LIST * GetImagesList() const
Definition: gbr_layout.cpp:44
wxString PcbFileWildcard()
SHAPE_POLY_SET m_Polygon
Definition: dcode.h:107
The common library.
void export_flashed_copper_item(GERBER_DRAW_ITEM *aGbrItem, LAYER_NUM aLayer)
Function export_flashed_copper_item write a synthetic pad to the board file.
void ConvertShapeToPolygon()
Function ConvertShapeToPolygon convert a shape to an equivalent polygon.
Definition: dcode.cpp:301
bool IsPcbLayer(LAYER_NUM aLayer)
Function IsPcbLayer tests whether a layer is a valid layer for pcbnew.
void DisplayInfoMessage(wxWindow *aParent, const wxString &aMessage, const wxString &aExtraInfo)
Display an informational message box with aMessage.
Definition: confirm.cpp:267
void collect_hole(GERBER_DRAW_ITEM *aGbrItem)
collect holes from a drill layer.
double MapToPcbUnits(int aValue)
In Pcbnew files units are mm for coordinates.
void writePcbHeader(LAYER_NUM *aLayerLookUpTable)
function writePcbHeader Write a very basic header to the board file