KiCad PCB EDA Suite
Loading...
Searching...
No Matches
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-2023 Jean-Pierre Charras jp.charras at wanadoo.fr
5 * Copyright The KiCad Developers, see AUTHORS.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
25#include <vector>
26
27#include <export_to_pcbnew.h>
28
29#include <confirm.h>
30#include <string_utils.h>
31#include <locale_io.h>
32#include <lset.h>
33#include <macros.h>
34#include <trigo.h>
35#include <gerbview_frame.h>
36#include <gerber_file_image.h>
38#include <build_version.h>
40#include "excellon_image.h"
41#include <wx/log.h>
42
43
44GBR_TO_PCB_EXPORTER::GBR_TO_PCB_EXPORTER( GERBVIEW_FRAME* aFrame, const wxString& aFileName )
45{
46 m_gerbview_frame = aFrame;
47 m_pcb_file_name = aFileName;
48 m_fp = nullptr;
50}
51
52
54{
55}
56
57
58bool GBR_TO_PCB_EXPORTER::ExportPcb( const int* aLayerLookUpTable, int aCopperLayers )
59{
60 LOCALE_IO toggle; // toggles on, then off, the C locale.
61
62 m_fp = wxFopen( m_pcb_file_name, wxT( "wt" ) );
63
64 if( m_fp == nullptr )
65 {
66 wxString msg;
67 msg.Printf( _( "Failed to create file '%s'." ), m_pcb_file_name );
69 return false;
70 }
71
72 m_pcbCopperLayersCount = aCopperLayers;
73
74 writePcbHeader( aLayerLookUpTable );
75
76 // create an image of gerber data
78
79 // First collect all the holes. We'll use these to generate pads, vias, etc.
80 for( unsigned layer = 0; layer < images->ImagesMaxCount(); ++layer )
81 {
82 int pcb_layer_number = aLayerLookUpTable[layer];
83 EXCELLON_IMAGE* excellon = dynamic_cast<EXCELLON_IMAGE*>( images->GetGbrImage( layer ) );
84 GERBER_FILE_IMAGE* gerb = dynamic_cast<GERBER_FILE_IMAGE*>( images->GetGbrImage( layer ) );
85
86 if( excellon )
87 {
88 for( GERBER_DRAW_ITEM* gerb_item : excellon->GetItems() )
89 collect_hole( gerb_item );
90 }
91 else if( gerb && pcb_layer_number == UNDEFINED_LAYER ) // PCB_LAYER_ID doesn't have an entry for Hole Data,
92 // but the dialog returns UNDEFINED_LAYER for it
93 {
94 for( GERBER_DRAW_ITEM* gerb_item : gerb->GetItems() )
95 collect_hole( gerb_item );
96 }
97 else
98 {
99 continue;
100 }
101 }
102
103 // Next: non copper layers:
104 for( unsigned layer = 0; layer < images->ImagesMaxCount(); ++layer )
105 {
106 GERBER_FILE_IMAGE* gerber = images->GetGbrImage( layer );
107
108 if( gerber == nullptr ) // Graphic layer not yet used
109 continue;
110
111 int pcb_layer_number = aLayerLookUpTable[layer];
112
113 if( !IsPcbLayer( pcb_layer_number ) || IsCopperLayer( pcb_layer_number ) )
114 continue;
115
116 for( GERBER_DRAW_ITEM* gerb_item : gerber->GetItems() )
117 export_non_copper_item( gerb_item, pcb_layer_number );
118 }
119
120 // Copper layers
121 for( unsigned layer = 0; layer < images->ImagesMaxCount(); ++layer )
122 {
123 GERBER_FILE_IMAGE* gerber = images->GetGbrImage( layer );
124
125 if( gerber == nullptr ) // Graphic layer not yet used
126 continue;
127
128 int pcb_layer_number = aLayerLookUpTable[layer];
129
130 if( !IsCopperLayer( pcb_layer_number ) )
131 continue;
132
133 for( GERBER_DRAW_ITEM* gerb_item : gerber->GetItems() )
134 export_copper_item( gerb_item, pcb_layer_number );
135 }
136
137 // Now write out the holes we collected earlier as vias
138 for( const EXPORT_VIA& via : m_vias )
139 export_via( via );
140
141 fprintf( m_fp, ")\n" );
142
143 fclose( m_fp );
144 m_fp = nullptr;
145 return true;
146}
147
148
150{
151 if( aGbrItem->GetLayerPolarity() )
152 return;
153
154 // used when a D_CODE is not found. default D_CODE to draw a flashed item
155 static D_CODE dummyD_CODE( 0 );
156
157 VECTOR2I seg_start = aGbrItem->m_Start;
158 VECTOR2I seg_end = aGbrItem->m_End;
159 D_CODE* d_codeDescr = aGbrItem->GetDcodeDescr();
160 SHAPE_POLY_SET polygon;
161
162 if( d_codeDescr == nullptr )
163 d_codeDescr = &dummyD_CODE;
164
165 switch( aGbrItem->m_ShapeType )
166 {
167 case GBR_POLYGON:
168 writePcbPolygon( aGbrItem->m_ShapeAsPolygon, aLayer );
169 break;
170
171 case GBR_SPOT_CIRCLE:
172 {
173 VECTOR2I center = aGbrItem->GetABPosition( seg_start );
174 int radius = d_codeDescr->m_Size.x / 2;
176 }
177 break;
178
179 case GBR_SPOT_RECT:
180 case GBR_SPOT_OVAL:
181 case GBR_SPOT_POLY:
182 case GBR_SPOT_MACRO:
183 d_codeDescr->ConvertShapeToPolygon( aGbrItem );
184 {
185 SHAPE_POLY_SET polyshape = d_codeDescr->m_Polygon;
186
187 // Compensate the Y axis orientation ( writePcbPolygon invert the Y coordinate )
188 polyshape.Outline( 0 ).Mirror( { 0, 0 }, FLIP_DIRECTION::TOP_BOTTOM );
189 writePcbPolygon( polyshape, aLayer, aGbrItem->GetABPosition( seg_start ) );
190 }
191 break;
192
193 case GBR_ARC:
194 export_non_copper_arc( aGbrItem, aLayer );
195 break;
196
197 case GBR_CIRCLE:
198 // Reverse Y axis:
199 seg_start.y = -seg_start.y;
200 seg_end.y = -seg_end.y;
201
202 fprintf( m_fp, "\t(gr_circle (start %s %s) (end %s %s) (layer %s)\n",
203 FormatDouble2Str( MapToPcbUnits( seg_start.x ) ).c_str(),
204 FormatDouble2Str( MapToPcbUnits( seg_start.y ) ).c_str(),
205 FormatDouble2Str( MapToPcbUnits( seg_end.x ) ).c_str(),
206 FormatDouble2Str( MapToPcbUnits( seg_end.y ) ).c_str(),
207 LSET::Name( PCB_LAYER_ID( aLayer ) ).ToStdString().c_str() );
208 export_stroke_info( aGbrItem->m_Size.x );
209 fprintf( m_fp, "\t)\n" );
210 break;
211
212 case GBR_SEGMENT:
213 if( d_codeDescr->m_ApertType == APT_RECT )
214 {
215 // Using a rectangular aperture to draw a line is deprecated since 2020
216 // However old gerber file can use it (rare case) and can generate
217 // strange shapes, because the rect aperture is not rotated to match the
218 // line orientation.
219 // So draw this line as polygon
220 SHAPE_POLY_SET polyshape;
221 aGbrItem->ConvertSegmentToPolygon( &polyshape );
222 writePcbPolygon( polyshape, aLayer );
223 }
224 else
225 {
226 // Reverse Y axis:
227 seg_start.y = -seg_start.y;
228 seg_end.y = -seg_end.y;
229
230 fprintf( m_fp, "\t(gr_line\n\t\t(start %s %s) (end %s %s) (layer %s)\n",
231 FormatDouble2Str( MapToPcbUnits( seg_start.x ) ).c_str(),
232 FormatDouble2Str( MapToPcbUnits( seg_start.y ) ).c_str(),
233 FormatDouble2Str( MapToPcbUnits( seg_end.x ) ).c_str(),
234 FormatDouble2Str( MapToPcbUnits( seg_end.y ) ).c_str(),
235 LSET::Name( PCB_LAYER_ID( aLayer ) ).ToStdString().c_str() );
236
237 export_stroke_info( aGbrItem->m_Size.x );
238 fprintf( m_fp, "\t)\n" );
239 }
240 break;
241 }
242}
243
244
246{
247 double a = atan2( (double) ( aGbrItem->m_Start.y - aGbrItem->m_ArcCentre.y ),
248 (double) ( aGbrItem->m_Start.x - aGbrItem->m_ArcCentre.x ) );
249 double b = atan2( (double) ( aGbrItem->m_End.y - aGbrItem->m_ArcCentre.y ),
250 (double) ( aGbrItem->m_End.x - aGbrItem->m_ArcCentre.x ) );
251
252 VECTOR2I arc_center = aGbrItem->m_ArcCentre;
253 VECTOR2I seg_start = aGbrItem->m_Start;
254 VECTOR2I seg_end = aGbrItem->m_End;
255
256 if( a > b )
257 b += 2 * M_PI;
258
259 if( seg_start == seg_end )
260 {
261 // Reverse Y axis:
262 arc_center.y = -arc_center.y;
263 seg_end.y = -seg_end.y;
264
265 fprintf( m_fp, "\t(gr_circle\n\t\t(center %s %s) (end %s %s) (layer %s)\n",
266 FormatDouble2Str( MapToPcbUnits( arc_center.x ) ).c_str(),
267 FormatDouble2Str( MapToPcbUnits( arc_center.y ) ).c_str(),
268 FormatDouble2Str( MapToPcbUnits( seg_end.x ) ).c_str(),
269 FormatDouble2Str( MapToPcbUnits( seg_end.y ) ).c_str(),
270 LSET::Name( PCB_LAYER_ID( aLayer ) ).ToStdString().c_str() );
271 export_stroke_info( aGbrItem->m_Size.x );
272 fprintf( m_fp, "\t)\n" );
273 }
274 else
275 {
276 VECTOR2I seg_middle = GetRotated( seg_start, arc_center,
277 -EDA_ANGLE( (b-a)/2, RADIANS_T ));
278
279 // Reverse Y axis:
280 seg_middle.y = -seg_middle.y;
281 seg_start.y = -seg_start.y;
282 seg_end.y = -seg_end.y;
283
284 fprintf( m_fp, "\t(gr_arc\n\t\t(start %s %s) (mid %s %s) (end %s %s) (layer %s)\n",
285 FormatDouble2Str( MapToPcbUnits( seg_start.x ) ).c_str(),
286 FormatDouble2Str( MapToPcbUnits( seg_start.y ) ).c_str(),
287 FormatDouble2Str( MapToPcbUnits( seg_middle.x ) ).c_str(),
288 FormatDouble2Str( MapToPcbUnits( seg_middle.y ) ).c_str(),
289 FormatDouble2Str( MapToPcbUnits( seg_end.x ) ).c_str(),
290 FormatDouble2Str( MapToPcbUnits( seg_end.y ) ).c_str(),
291 LSET::Name( PCB_LAYER_ID( aLayer ) ).ToStdString().c_str() );
292
293 export_stroke_info( aGbrItem->m_Size.x );
294 fprintf( m_fp, "\t)\n" );
295 }
296}
297
298
300{
301 int size = std::min( aGbrItem->m_Size.x, aGbrItem->m_Size.y );
302 m_vias.emplace_back( aGbrItem->m_Start, size + 1, size );
303}
304
305
307{
308 VECTOR2I via_pos = aVia.m_Pos;
309
310 // Reverse Y axis:
311 via_pos.y = -via_pos.y;
312
313 // Layers are Front to Back
314 fprintf( m_fp, " (via (at %s %s) (size %s) (drill %s)",
315 FormatDouble2Str( MapToPcbUnits( via_pos.x ) ).c_str(),
316 FormatDouble2Str( MapToPcbUnits( via_pos.y ) ).c_str(),
317 FormatDouble2Str( MapToPcbUnits( aVia.m_Size ) ).c_str(),
318 FormatDouble2Str( MapToPcbUnits( aVia.m_Drill ) ).c_str() );
319
320 fprintf( m_fp, " (layers %s %s))\n",
321 LSET::Name( F_Cu ).ToStdString().c_str(),
322 LSET::Name( B_Cu ).ToStdString().c_str() );
323}
324
325
327{
328 if( aGbrItem->GetLayerPolarity() )
329 return;
330
331 switch( aGbrItem->m_ShapeType )
332 {
333 case GBR_SPOT_CIRCLE:
334 case GBR_SPOT_RECT:
335 case GBR_SPOT_OVAL:
336 case GBR_SPOT_POLY:
337 case GBR_SPOT_MACRO:
338 export_flashed_copper_item( aGbrItem, aLayer );
339 break;
340
341 case GBR_CIRCLE:
342 case GBR_ARC:
343 export_segarc_copper_item( aGbrItem, aLayer );
344 break;
345
346 case GBR_POLYGON:
347 // One can use a polygon or a zone to output a Gerber region.
348 // none are perfect.
349 // The current way is use a polygon, as the zone export
350 // is experimental and only for tests.
351#if 1
352 writePcbPolygon( aGbrItem->m_ShapeAsPolygon, aLayer );
353#else
354 // Only for tests:
355 writePcbZoneItem( aGbrItem, aLayer );
356#endif
357 break;
358
359 case GBR_SEGMENT:
360 {
361 D_CODE* code = aGbrItem->GetDcodeDescr();
362
363 if( code && code->m_ApertType == APT_RECT )
364 {
365 if( aGbrItem->m_ShapeAsPolygon.OutlineCount() == 0 )
366 const_cast<GERBER_DRAW_ITEM*>( aGbrItem )->ConvertSegmentToPolygon();
367
368 writePcbPolygon( aGbrItem->m_ShapeAsPolygon, aLayer );
369 }
370 else
371 {
372 export_segline_copper_item( aGbrItem, aLayer );
373 }
374
375 break;
376 }
377
378 default:
379 break;
380 }
381}
382
383
385{
386 VECTOR2I seg_start, seg_end;
387
388 seg_start = aGbrItem->m_Start;
389 seg_end = aGbrItem->m_End;
390
391 // Reverse Y axis:
392 seg_start.y = -seg_start.y;
393 seg_end.y = -seg_end.y;
394
395 writeCopperLineItem( seg_start, seg_end, aGbrItem->m_Size.x, aLayer );
396}
397
398
400 int aWidth, int aLayer )
401{
402 fprintf( m_fp, "\t(segment (start %s %s) (end %s %s) (width %s) (layer %s) (net 0))\n",
403 FormatDouble2Str( MapToPcbUnits(aStart.x) ).c_str(),
404 FormatDouble2Str( MapToPcbUnits(aStart.y) ).c_str(),
405 FormatDouble2Str( MapToPcbUnits(aEnd.x) ).c_str(),
406 FormatDouble2Str( MapToPcbUnits(aEnd.y) ).c_str(),
407 FormatDouble2Str( MapToPcbUnits( aWidth ) ).c_str(),
408 LSET::Name( PCB_LAYER_ID( aLayer ) ).ToStdString().c_str() );
409}
410
411
413{
414 fprintf( m_fp, "\t\t(stroke (width %s) (type solid))\n",
415 FormatDouble2Str( MapToPcbUnits( aWidth ) ).c_str() );
416}
417
418
420{
421 double a = atan2( (double) ( aGbrItem->m_Start.y - aGbrItem->m_ArcCentre.y ),
422 (double) ( aGbrItem->m_Start.x - aGbrItem->m_ArcCentre.x ) );
423 double b = atan2( (double) ( aGbrItem->m_End.y - aGbrItem->m_ArcCentre.y ),
424 (double) ( aGbrItem->m_End.x - aGbrItem->m_ArcCentre.x ) );
425
426 if( a > b )
427 b += 2 * M_PI;
428
429 VECTOR2I arc_center = aGbrItem->m_ArcCentre;
430 VECTOR2I seg_end = aGbrItem->m_End;
431 VECTOR2I seg_start = aGbrItem->m_Start;
432
433 VECTOR2I seg_middle = GetRotated( seg_start, arc_center,
434 -EDA_ANGLE( (b-a)/2, RADIANS_T ));
435
436 // Reverse Y axis:
437 seg_end.y = -seg_end.y;
438 seg_start.y = -seg_start.y;
439 seg_middle.y = -seg_middle.y;
440
441 fprintf( m_fp, "\t(arc\n\t\t(start %s %s) (mid %s %s) (end %s %s) (layer %s)\n",
442 FormatDouble2Str( MapToPcbUnits( seg_start.x ) ).c_str(),
443 FormatDouble2Str( MapToPcbUnits( seg_start.y ) ).c_str(),
444 FormatDouble2Str( MapToPcbUnits( seg_middle.x ) ).c_str(),
445 FormatDouble2Str( MapToPcbUnits( seg_middle.y ) ).c_str(),
446 FormatDouble2Str( MapToPcbUnits( seg_end.x ) ).c_str(),
447 FormatDouble2Str( MapToPcbUnits( seg_end.y ) ).c_str(),
448 LSET::Name( PCB_LAYER_ID( aLayer ) ).ToStdString().c_str() );
449
450 fprintf( m_fp, "\t\t(width %s) (net 0 )\n",
451 FormatDouble2Str( MapToPcbUnits( aGbrItem->m_Size.x ) ).c_str() );
452 fprintf( m_fp, "\t)\n" );
453}
454
455
457{
458 static D_CODE flashed_item_D_CODE( 0 );
459
460 D_CODE* d_codeDescr = aGbrItem->GetDcodeDescr();
461
462 if( d_codeDescr == nullptr )
463 d_codeDescr = &flashed_item_D_CODE;
464
465 if( aGbrItem->m_ShapeType == GBR_SPOT_CIRCLE )
466 {
467 // See if there's a via that we can enlarge to fit this flashed item
468 for( EXPORT_VIA& via : m_vias )
469 {
470 if( via.m_Pos == aGbrItem->m_Start )
471 {
472 via.m_Size = std::max( via.m_Size, aGbrItem->m_Size.x );
473 return;
474 }
475 }
476 }
477
478 VECTOR2I offset = aGbrItem->GetABPosition( aGbrItem->m_Start );
479
480 if( aGbrItem->m_ShapeType == GBR_SPOT_CIRCLE ||
481 ( aGbrItem->m_ShapeType == GBR_SPOT_OVAL && d_codeDescr->m_Size.x == d_codeDescr->m_Size.y ) )
482 {
483 // export it as filled circle
484 VECTOR2I center = offset;
485 int radius = d_codeDescr->m_Size.x / 2;
487 return;
488 }
489
490 APERTURE_MACRO* macro = d_codeDescr->GetMacro();
491
492 if( macro ) // export a GBR_SPOT_MACRO
493 {
494 SHAPE_POLY_SET macroShape;
495 macroShape = *macro->GetApertureMacroShape( aGbrItem, VECTOR2I( 0, 0 ) );
496
497 // Compensate the Y axis orientation ( writePcbPolygon invert the Y coordinate )
498 macroShape.Outline( 0 ).Mirror( { 0, 0 }, FLIP_DIRECTION::TOP_BOTTOM );
499
500 writePcbPolygon( macroShape, aLayer, offset );
501 }
502 else
503 {
504 // Should cover primitives: GBR_SPOT_RECT, GBR_SPOT_OVAL, GBR_SPOT_POLY
505 d_codeDescr->ConvertShapeToPolygon( aGbrItem );
506 writePcbPolygon( d_codeDescr->m_Polygon, aLayer, offset );
507 }
508}
509
510
511void GBR_TO_PCB_EXPORTER::writePcbFilledCircle( const VECTOR2I& aCenterPosition, int aRadius,
512 int aLayer )
513{
514 fprintf( m_fp, "\t(gr_circle\n\t\t(center %s %s) (end %s %s)\n",
515 FormatDouble2Str( MapToPcbUnits( aCenterPosition.x ) ).c_str(),
516 FormatDouble2Str( MapToPcbUnits( aCenterPosition.y ) ).c_str(),
517 FormatDouble2Str( MapToPcbUnits( aCenterPosition.x + aRadius ) ).c_str(),
518 FormatDouble2Str( MapToPcbUnits( aCenterPosition.y ) ).c_str() );
519
521 fprintf( m_fp, "\t\t(fill yes) (layer %s)",
522 LSET::Name( PCB_LAYER_ID( aLayer ) ).ToStdString().c_str() );
523 fprintf( m_fp, "\n\t)\n" );
524}
525
526
527void GBR_TO_PCB_EXPORTER::writePcbHeader( const int* aLayerLookUpTable )
528{
529 // Note: the .kicad_pcb version used here is after layers_id changes
530 fprintf( m_fp, "(kicad_pcb (version 20240928)\n" );
531 fprintf( m_fp, "\t(generator \"gerbview\")\n\t(generator_version \"%s\")\n\n",
532 GetMajorMinorVersion().c_str().AsChar() );
533
534 // Write layers section
535 fprintf( m_fp, "\t(layers \n" );
536
538
539 for( auto cu_it = layer_set.copper_layers_begin(); cu_it != layer_set.copper_layers_end(); ++cu_it )
540 {
541 fprintf( m_fp, "\t\t(%d %s signal)\n",
542 *cu_it, LSET::Name( *cu_it ).ToStdString().c_str() );
543 }
544
545 for( auto non_cu_it = layer_set.non_copper_layers_begin(); non_cu_it != layer_set.non_copper_layers_end(); ++non_cu_it )
546 {
547 fprintf( m_fp, "\t\t(%d %s user)\n",
548 *non_cu_it, LSET::Name( *non_cu_it ).ToStdString().c_str() );
549 }
550
551 fprintf( m_fp, "\t)\n\n" );
552}
553
554
556 const VECTOR2I& aOffset )
557{
558 // Ensure the polygon is valid:
559 if( aPolys.OutlineCount() < 1 )
560 return;
561
562 // aPolys is expected having only one outline and no hole
563 // (because it comes from a gerber file or is built from a aperture )
564 const SHAPE_LINE_CHAIN& poly = aPolys.COutline( 0 );
565
566 fprintf( m_fp, "\t(gr_poly\n\t\t(pts\n\t\t\t" );
567
568 #define MAX_COORD_CNT 4
569 int jj = MAX_COORD_CNT;
570 int cnt_max = poly.PointCount() -1;
571
572 // Do not generate last corner, if it is the same point as the first point:
573 if( poly.CPoint( 0 ) == poly.CPoint( cnt_max ) )
574 cnt_max--;
575
576 for( int ii = 0; ii <= cnt_max; ii++ )
577 {
578 if( --jj == 0 )
579 {
580 jj = MAX_COORD_CNT;
581 fprintf( m_fp, "\n\t\t\t" );
582 }
583
584 fprintf( m_fp, " (xy %s %s)",
585 FormatDouble2Str( MapToPcbUnits( poly.CPoint( ii ).x + aOffset.x ) ).c_str(),
586 FormatDouble2Str( MapToPcbUnits( -poly.CPoint( ii ).y + aOffset.y ) ).c_str() );
587 }
588
589 fprintf( m_fp, ")" );
590
591 fprintf( m_fp, "\n" );
593 fprintf( m_fp, "\t\t(fill yes) (layer %s)",
594 LSET::Name( PCB_LAYER_ID( aLayer ) ).ToStdString().c_str() );
595 fprintf( m_fp, "\n\t)\n" );
596}
597
598
600{
602 polys.Simplify();
603
604 if( polys.OutlineCount() == 0 )
605 return;
606
607 fprintf( m_fp, "\t(zone (net 0) (net_name \"\") (layer %s) (tstamp 0000000) (hatch edge 0.508)\n",
608 LSET::Name( PCB_LAYER_ID( aLayer ) ).ToStdString().c_str() );
609
610 fprintf( m_fp, " (connect_pads (clearance 0.0))\n" );
611
612 fprintf( m_fp, " (min_thickness 0.1) (filled_areas_thickness no)\n"
613 " (fill (thermal_gap 0.3) (thermal_bridge_width 0.3))\n" );
614
615 // Now, write the zone outlines with holes.
616 // first polygon is the main outline, next are holes
617 // One cannot know the initial zone outline.
618 // However most of (if not all) holes are just items with clearance,
619 // not really a hole in the initial zone outline.
620 // So we build a zone outline only with no hole.
621 fprintf( m_fp, " (polygon\n (pts" );
622
623 SHAPE_LINE_CHAIN& poly = polys.Outline( 0 );
624
625 #define MAX_COORD_CNT 4
626 int jj = MAX_COORD_CNT;
627 int cnt_max = poly.PointCount() -1;
628
629 // Do not generate last corner, if it is the same point as the first point:
630 if( poly.CPoint( 0 ) == poly.CPoint( cnt_max ) )
631 cnt_max--;
632
633 for( int ii = 0; ii <= cnt_max; ii++ )
634 {
635 if( --jj == 0 )
636 {
637 jj = MAX_COORD_CNT;
638 fprintf( m_fp, "\n " );
639 }
640
641 fprintf( m_fp, " (xy %s %s)", FormatDouble2Str( MapToPcbUnits( poly.CPoint( ii ).x ) ).c_str(),
642 FormatDouble2Str( MapToPcbUnits( -poly.CPoint( ii ).y ) ).c_str() );
643 }
644
645 fprintf( m_fp, ")\n" );
646
647 fprintf( m_fp, " )\n)\n" );
648}
wxString GetMajorMinorVersion()
Get only the major and minor version in a string major.minor.
Support the "aperture macro" defined within standard RS274X.
SHAPE_POLY_SET * GetApertureMacroShape(const GERBER_DRAW_ITEM *aParent, const VECTOR2I &aShapePos)
Calculate the primitive shape for flashed items.
A gerber DCODE (also called Aperture) definition.
Definition: dcode.h:80
APERTURE_MACRO * GetMacro() const
Definition: dcode.h:136
VECTOR2I m_Size
Horizontal and vertical dimensions.
Definition: dcode.h:201
APERTURE_T m_ApertType
Aperture type ( Line, rectangle, circle, oval poly, macro )
Definition: dcode.h:202
SHAPE_POLY_SET m_Polygon
Definition: dcode.h:217
void ConvertShapeToPolygon(const GERBER_DRAW_ITEM *aParent)
Convert a shape to an equivalent polygon.
Definition: dcode.cpp:297
Handle a drill image.
GERBER_FILE_IMAGE_LIST * GetImagesList() const
Definition: gbr_layout.cpp:41
void export_copper_item(const GERBER_DRAW_ITEM *aGbrItem, int aLayer)
Write a track (or via) to the board file.
void export_stroke_info(double aWidth)
Write the stroke info (thickness, line type) to the board file.
void export_non_copper_arc(const GERBER_DRAW_ITEM *aGbrItem, int aLayer)
Write a non copper arc to the board file.
void export_non_copper_item(const GERBER_DRAW_ITEM *aGbrItem, int aLayer)
Write a non copper line or arc to the board file.
void writePcbZoneItem(const GERBER_DRAW_ITEM *aGbrItem, int aLayer)
Write a zone item to the board file.
GERBVIEW_FRAME * m_gerbview_frame
void export_segarc_copper_item(const GERBER_DRAW_ITEM *aGbrItem, int aLayer)
Write a set of tracks (arcs are approximated by track segments) to the board file.
GBR_TO_PCB_EXPORTER(GERBVIEW_FRAME *aFrame, const wxString &aFileName)
void export_flashed_copper_item(const GERBER_DRAW_ITEM *aGbrItem, int aLayer)
Write a synthetic pad to the board file.
double MapToPcbUnits(int aValue) const
Map GerbView internal units to millimeters for Pcbnew board files.
std::vector< EXPORT_VIA > m_vias
void collect_hole(const GERBER_DRAW_ITEM *aGbrItem)
Collect holes from a drill layer.
void writePcbPolygon(const SHAPE_POLY_SET &aPolys, int aLayer, const VECTOR2I &aOffset={ 0, 0 })
Write a non-copper polygon to the board file.
void writePcbFilledCircle(const VECTOR2I &aCenterPosition, int aRadius, int aLayer)
Write a filled circle to the board file (with line thickness = 0).
void export_segline_copper_item(const GERBER_DRAW_ITEM *aGbrItem, int aLayer)
Write a track (not via) to the board file.
void writePcbHeader(const int *aLayerLookUpTable)
Write a very basic header to the board file.
bool ExportPcb(const int *aLayerLookUpTable, int aCopperLayers)
Save a board from a set of Gerber images.
void writeCopperLineItem(const VECTOR2I &aStart, const VECTOR2I &aEnd, int aWidth, int aLayer)
Basic write function to write a a PCB_TRACK to the board file from a non flashed item.
void export_via(const EXPORT_VIA &aVia)
Write a via to the board file.
D_CODE * GetDcodeDescr() const
Return the GetDcodeDescr of this object, or NULL.
VECTOR2I GetABPosition(const VECTOR2I &aXYPosition) const
Return the image position of aPosition for this object.
SHAPE_POLY_SET m_ShapeAsPolygon
bool GetLayerPolarity() const
void ConvertSegmentToPolygon()
Convert a line to an equivalent polygon.
GBR_BASIC_SHAPE_TYPE m_ShapeType
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)
Hold the image data and parameters for one gerber file and layer parameters.
GERBER_DRAW_ITEMS & GetItems()
GBR_LAYOUT * GetGerberLayout() const
Instantiate the current locale within a scope in which you are expecting exceptions to be thrown.
Definition: locale_io.h:41
LSET is a set of PCB_LAYER_IDs.
Definition: lset.h:37
copper_layers_iterator copper_layers_end() const
Definition: lset.cpp:915
static const LSET & UserMask()
Definition: lset.cpp:676
static LSET AllCuMask(int aCuLayerCount=MAX_CU_LAYERS)
Return a mask holding the requested number of Cu PCB_LAYER_IDs.
Definition: lset.cpp:583
copper_layers_iterator copper_layers_begin() const
Definition: lset.cpp:909
non_copper_layers_iterator non_copper_layers_begin() const
Definition: lset.cpp:921
static const LSET & AllTechMask()
Return a mask holding all technical layers (no CU layer) on both side.
Definition: lset.cpp:662
non_copper_layers_iterator non_copper_layers_end() const
Definition: lset.cpp:927
static wxString Name(PCB_LAYER_ID aLayerId)
Return the fixed name association with aLayerId.
Definition: lset.cpp:188
Represent a polyline containing arcs as well as line segments: A chain of connected line and/or arc s...
int PointCount() const
Return the number of points (vertices) in this line chain.
const VECTOR2I & CPoint(int aIndex) const
Return a reference to a given point in the line chain.
void Mirror(const VECTOR2I &aRef, FLIP_DIRECTION aFlipDirection)
Mirror the line points about y or x (or both).
Represent a set of closed polygons.
void Simplify()
Simplify the polyset (merges overlapping polys, eliminates degeneracy/self-intersections)
SHAPE_LINE_CHAIN & Outline(int aIndex)
Return the reference to aIndex-th outline in the set.
int OutlineCount() const
Return the number of outlines in the set.
SHAPE_POLY_SET CloneDropTriangulation() const
const SHAPE_LINE_CHAIN & COutline(int aIndex) const
void DisplayError(wxWindow *aParent, const wxString &aText)
Display an error or warning message box with aMessage.
Definition: confirm.cpp:170
This file is part of the common library.
@ APT_RECT
Definition: dcode.h:50
#define _(s)
@ RADIANS_T
Definition: eda_angle.h:32
#define MAX_COORD_CNT
@ GBR_SPOT_OVAL
@ GBR_SEGMENT
@ GBR_SPOT_POLY
@ GBR_SPOT_RECT
@ GBR_CIRCLE
@ GBR_POLYGON
@ GBR_SPOT_CIRCLE
@ GBR_ARC
@ GBR_SPOT_MACRO
bool IsPcbLayer(int aLayer)
Test whether a layer is a valid layer for Pcbnew.
Definition: layer_ids.h:652
bool IsCopperLayer(int aLayerId)
Test whether a layer is a copper layer.
Definition: layer_ids.h:663
PCB_LAYER_ID
A quick note on layer IDs:
Definition: layer_ids.h:60
@ B_Cu
Definition: layer_ids.h:65
@ UNDEFINED_LAYER
Definition: layer_ids.h:61
@ F_Cu
Definition: layer_ids.h:64
This file contains miscellaneous commonly used macros and functions.
std::string FormatDouble2Str(double aValue)
Print a float number without using scientific notation and no trailing 0 This function is intended in...
VECTOR2I m_Pos
VECTOR2I center
int radius
VECTOR2I GetRotated(const VECTOR2I &aVector, const EDA_ANGLE &aAngle)
Return a new VECTOR2I that is the result of rotating aVector by aAngle.
Definition: trigo.h:77
VECTOR2< int32_t > VECTOR2I
Definition: vector2d.h:695
Definition of file extensions used in Kicad.