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 <lset.h>
32#include <macros.h>
33#include <trigo.h>
34#include <gerbview_frame.h>
35#include <gerber_file_image.h>
37#include <build_version.h>
39#include "excellon_image.h"
40#include <wx/log.h>
41
42
43GBR_TO_PCB_EXPORTER::GBR_TO_PCB_EXPORTER( GERBVIEW_FRAME* aFrame, const wxString& aFileName )
44{
45 m_gerbview_frame = aFrame;
46 m_pcb_file_name = aFileName;
47 m_fp = nullptr;
49}
50
51
53{
54}
55
56
57bool GBR_TO_PCB_EXPORTER::ExportPcb( const int* aLayerLookUpTable, int aCopperLayers )
58{
59 m_fp = wxFopen( m_pcb_file_name, wxT( "wt" ) );
60
61 if( m_fp == nullptr )
62 {
63 wxString msg;
64 msg.Printf( _( "Failed to create file '%s'." ), m_pcb_file_name );
66 return false;
67 }
68
69 m_pcbCopperLayersCount = aCopperLayers;
70
71 writePcbHeader( aLayerLookUpTable );
72
73 // create an image of gerber data
75
76 // First collect all the holes. We'll use these to generate pads, vias, etc.
77 for( unsigned layer = 0; layer < images->ImagesMaxCount(); ++layer )
78 {
79 int pcb_layer_number = aLayerLookUpTable[layer];
80 EXCELLON_IMAGE* excellon = dynamic_cast<EXCELLON_IMAGE*>( images->GetGbrImage( layer ) );
81 GERBER_FILE_IMAGE* gerb = dynamic_cast<GERBER_FILE_IMAGE*>( images->GetGbrImage( layer ) );
82
83 if( excellon )
84 {
85 for( GERBER_DRAW_ITEM* gerb_item : excellon->GetItems() )
86 collect_hole( gerb_item );
87 }
88 else if( gerb && pcb_layer_number == UNDEFINED_LAYER ) // PCB_LAYER_ID doesn't have an entry for Hole Data,
89 // but the dialog returns UNDEFINED_LAYER for it
90 {
91 for( GERBER_DRAW_ITEM* gerb_item : gerb->GetItems() )
92 collect_hole( gerb_item );
93 }
94 else
95 {
96 continue;
97 }
98 }
99
100 // Next: non copper layers:
101 for( unsigned layer = 0; layer < images->ImagesMaxCount(); ++layer )
102 {
103 GERBER_FILE_IMAGE* gerber = images->GetGbrImage( layer );
104
105 if( gerber == nullptr ) // Graphic layer not yet used
106 continue;
107
108 int pcb_layer_number = aLayerLookUpTable[layer];
109
110 if( !IsPcbLayer( pcb_layer_number ) || IsCopperLayer( pcb_layer_number ) )
111 continue;
112
113 for( GERBER_DRAW_ITEM* gerb_item : gerber->GetItems() )
114 export_non_copper_item( gerb_item, pcb_layer_number );
115 }
116
117 // Copper layers
118 for( unsigned layer = 0; layer < images->ImagesMaxCount(); ++layer )
119 {
120 GERBER_FILE_IMAGE* gerber = images->GetGbrImage( layer );
121
122 if( gerber == nullptr ) // Graphic layer not yet used
123 continue;
124
125 int pcb_layer_number = aLayerLookUpTable[layer];
126
127 if( !IsCopperLayer( pcb_layer_number ) )
128 continue;
129
130 for( GERBER_DRAW_ITEM* gerb_item : gerber->GetItems() )
131 export_copper_item( gerb_item, pcb_layer_number );
132 }
133
134 // Now write out the holes we collected earlier as vias
135 for( const EXPORT_VIA& via : m_vias )
136 export_via( via );
137
138 fprintf( m_fp, ")\n" );
139
140 fclose( m_fp );
141 m_fp = nullptr;
142 return true;
143}
144
145
147{
148 if( aGbrItem->GetLayerPolarity() )
149 return;
150
151 // used when a D_CODE is not found. default D_CODE to draw a flashed item
152 static D_CODE dummyD_CODE( 0 );
153
154 VECTOR2I seg_start = aGbrItem->m_Start;
155 VECTOR2I seg_end = aGbrItem->m_End;
156 D_CODE* d_codeDescr = aGbrItem->GetDcodeDescr();
157 SHAPE_POLY_SET polygon;
158
159 if( d_codeDescr == nullptr )
160 d_codeDescr = &dummyD_CODE;
161
162 switch( aGbrItem->m_ShapeType )
163 {
164 case GBR_POLYGON:
165 writePcbPolygon( aGbrItem->m_ShapeAsPolygon, aLayer );
166 break;
167
168 case GBR_SPOT_CIRCLE:
169 {
170 VECTOR2I center = aGbrItem->GetABPosition( seg_start );
171 int radius = d_codeDescr->m_Size.x / 2;
173 }
174 break;
175
176 case GBR_SPOT_RECT:
177 case GBR_SPOT_OVAL:
178 case GBR_SPOT_POLY:
179 case GBR_SPOT_MACRO:
180 d_codeDescr->ConvertShapeToPolygon( aGbrItem );
181 {
182 SHAPE_POLY_SET polyshape = d_codeDescr->m_Polygon;
183
184 // Compensate the Y axis orientation ( writePcbPolygon invert the Y coordinate )
185 polyshape.Outline( 0 ).Mirror( { 0, 0 }, FLIP_DIRECTION::TOP_BOTTOM );
186 writePcbPolygon( polyshape, aLayer, aGbrItem->GetABPosition( seg_start ) );
187 }
188 break;
189
190 case GBR_ARC:
191 export_non_copper_arc( aGbrItem, aLayer );
192 break;
193
194 case GBR_CIRCLE:
195 // Reverse Y axis:
196 seg_start.y = -seg_start.y;
197 seg_end.y = -seg_end.y;
198
199 fprintf( m_fp, "\t(gr_circle (start %s %s) (end %s %s) (layer %s)\n",
200 FormatDouble2Str( MapToPcbUnits( seg_start.x ) ).c_str(),
201 FormatDouble2Str( MapToPcbUnits( seg_start.y ) ).c_str(),
202 FormatDouble2Str( MapToPcbUnits( seg_end.x ) ).c_str(),
203 FormatDouble2Str( MapToPcbUnits( seg_end.y ) ).c_str(),
204 LSET::Name( PCB_LAYER_ID( aLayer ) ).ToStdString().c_str() );
205 export_stroke_info( aGbrItem->m_Size.x );
206 fprintf( m_fp, "\t)\n" );
207 break;
208
209 case GBR_SEGMENT:
210 if( d_codeDescr->m_ApertType == APT_RECT )
211 {
212 // Using a rectangular aperture to draw a line is deprecated since 2020
213 // However old gerber file can use it (rare case) and can generate
214 // strange shapes, because the rect aperture is not rotated to match the
215 // line orientation.
216 // So draw this line as polygon
217 SHAPE_POLY_SET polyshape;
218 aGbrItem->ConvertSegmentToPolygon( &polyshape );
219 writePcbPolygon( polyshape, aLayer );
220 }
221 else
222 {
223 // Reverse Y axis:
224 seg_start.y = -seg_start.y;
225 seg_end.y = -seg_end.y;
226
227 fprintf( m_fp, "\t(gr_line\n\t\t(start %s %s) (end %s %s) (layer %s)\n",
228 FormatDouble2Str( MapToPcbUnits( seg_start.x ) ).c_str(),
229 FormatDouble2Str( MapToPcbUnits( seg_start.y ) ).c_str(),
230 FormatDouble2Str( MapToPcbUnits( seg_end.x ) ).c_str(),
231 FormatDouble2Str( MapToPcbUnits( seg_end.y ) ).c_str(),
232 LSET::Name( PCB_LAYER_ID( aLayer ) ).ToStdString().c_str() );
233
234 export_stroke_info( aGbrItem->m_Size.x );
235 fprintf( m_fp, "\t)\n" );
236 }
237 break;
238 }
239}
240
241
243{
244 double a = atan2( (double) ( aGbrItem->m_Start.y - aGbrItem->m_ArcCentre.y ),
245 (double) ( aGbrItem->m_Start.x - aGbrItem->m_ArcCentre.x ) );
246 double b = atan2( (double) ( aGbrItem->m_End.y - aGbrItem->m_ArcCentre.y ),
247 (double) ( aGbrItem->m_End.x - aGbrItem->m_ArcCentre.x ) );
248
249 VECTOR2I arc_center = aGbrItem->m_ArcCentre;
250 VECTOR2I seg_start = aGbrItem->m_Start;
251 VECTOR2I seg_end = aGbrItem->m_End;
252
253 if( a > b )
254 b += 2 * M_PI;
255
256 if( seg_start == seg_end )
257 {
258 // Reverse Y axis:
259 arc_center.y = -arc_center.y;
260 seg_end.y = -seg_end.y;
261
262 fprintf( m_fp, "\t(gr_circle\n\t\t(center %s %s) (end %s %s) (layer %s)\n",
263 FormatDouble2Str( MapToPcbUnits( arc_center.x ) ).c_str(),
264 FormatDouble2Str( MapToPcbUnits( arc_center.y ) ).c_str(),
265 FormatDouble2Str( MapToPcbUnits( seg_end.x ) ).c_str(),
266 FormatDouble2Str( MapToPcbUnits( seg_end.y ) ).c_str(),
267 LSET::Name( PCB_LAYER_ID( aLayer ) ).ToStdString().c_str() );
268 export_stroke_info( aGbrItem->m_Size.x );
269 fprintf( m_fp, "\t)\n" );
270 }
271 else
272 {
273 VECTOR2I seg_middle = GetRotated( seg_start, arc_center,
274 -EDA_ANGLE( (b-a)/2, RADIANS_T ));
275
276 // Reverse Y axis:
277 seg_middle.y = -seg_middle.y;
278 seg_start.y = -seg_start.y;
279 seg_end.y = -seg_end.y;
280
281 fprintf( m_fp, "\t(gr_arc\n\t\t(start %s %s) (mid %s %s) (end %s %s) (layer %s)\n",
282 FormatDouble2Str( MapToPcbUnits( seg_start.x ) ).c_str(),
283 FormatDouble2Str( MapToPcbUnits( seg_start.y ) ).c_str(),
284 FormatDouble2Str( MapToPcbUnits( seg_middle.x ) ).c_str(),
285 FormatDouble2Str( MapToPcbUnits( seg_middle.y ) ).c_str(),
286 FormatDouble2Str( MapToPcbUnits( seg_end.x ) ).c_str(),
287 FormatDouble2Str( MapToPcbUnits( seg_end.y ) ).c_str(),
288 LSET::Name( PCB_LAYER_ID( aLayer ) ).ToStdString().c_str() );
289
290 export_stroke_info( aGbrItem->m_Size.x );
291 fprintf( m_fp, "\t)\n" );
292 }
293}
294
295
297{
298 int size = std::min( aGbrItem->m_Size.x, aGbrItem->m_Size.y );
299 m_vias.emplace_back( aGbrItem->m_Start, size + 1, size );
300}
301
302
304{
305 VECTOR2I via_pos = aVia.m_Pos;
306
307 // Reverse Y axis:
308 via_pos.y = -via_pos.y;
309
310 // Layers are Front to Back
311 fprintf( m_fp, " (via (at %s %s) (size %s) (drill %s)",
312 FormatDouble2Str( MapToPcbUnits( via_pos.x ) ).c_str(),
313 FormatDouble2Str( MapToPcbUnits( via_pos.y ) ).c_str(),
314 FormatDouble2Str( MapToPcbUnits( aVia.m_Size ) ).c_str(),
315 FormatDouble2Str( MapToPcbUnits( aVia.m_Drill ) ).c_str() );
316
317 fprintf( m_fp, " (layers %s %s))\n",
318 LSET::Name( F_Cu ).ToStdString().c_str(),
319 LSET::Name( B_Cu ).ToStdString().c_str() );
320}
321
322
324{
325 if( aGbrItem->GetLayerPolarity() )
326 return;
327
328 switch( aGbrItem->m_ShapeType )
329 {
330 case GBR_SPOT_CIRCLE:
331 case GBR_SPOT_RECT:
332 case GBR_SPOT_OVAL:
333 case GBR_SPOT_POLY:
334 case GBR_SPOT_MACRO:
335 export_flashed_copper_item( aGbrItem, aLayer );
336 break;
337
338 case GBR_CIRCLE:
339 case GBR_ARC:
340 export_segarc_copper_item( aGbrItem, aLayer );
341 break;
342
343 case GBR_POLYGON:
344 // One can use a polygon or a zone to output a Gerber region.
345 // none are perfect.
346 // The current way is use a polygon, as the zone export
347 // is experimental and only for tests.
348#if 1
349 writePcbPolygon( aGbrItem->m_ShapeAsPolygon, aLayer );
350#else
351 // Only for tests:
352 writePcbZoneItem( aGbrItem, aLayer );
353#endif
354 break;
355
356 case GBR_SEGMENT:
357 {
358 D_CODE* code = aGbrItem->GetDcodeDescr();
359
360 if( code && code->m_ApertType == APT_RECT )
361 {
362 if( aGbrItem->m_ShapeAsPolygon.OutlineCount() == 0 )
363 const_cast<GERBER_DRAW_ITEM*>( aGbrItem )->ConvertSegmentToPolygon();
364
365 writePcbPolygon( aGbrItem->m_ShapeAsPolygon, aLayer );
366 }
367 else
368 {
369 export_segline_copper_item( aGbrItem, aLayer );
370 }
371
372 break;
373 }
374
375 default:
376 break;
377 }
378}
379
380
382{
383 VECTOR2I seg_start, seg_end;
384
385 seg_start = aGbrItem->m_Start;
386 seg_end = aGbrItem->m_End;
387
388 // Reverse Y axis:
389 seg_start.y = -seg_start.y;
390 seg_end.y = -seg_end.y;
391
392 writeCopperLineItem( seg_start, seg_end, aGbrItem->m_Size.x, aLayer );
393}
394
395
397 int aWidth, int aLayer )
398{
399 fprintf( m_fp, "\t(segment (start %s %s) (end %s %s) (width %s) (layer %s) (net 0))\n",
400 FormatDouble2Str( MapToPcbUnits(aStart.x) ).c_str(),
401 FormatDouble2Str( MapToPcbUnits(aStart.y) ).c_str(),
402 FormatDouble2Str( MapToPcbUnits(aEnd.x) ).c_str(),
403 FormatDouble2Str( MapToPcbUnits(aEnd.y) ).c_str(),
404 FormatDouble2Str( MapToPcbUnits( aWidth ) ).c_str(),
405 LSET::Name( PCB_LAYER_ID( aLayer ) ).ToStdString().c_str() );
406}
407
408
410{
411 fprintf( m_fp, "\t\t(stroke (width %s) (type solid))\n",
412 FormatDouble2Str( MapToPcbUnits( aWidth ) ).c_str() );
413}
414
415
417{
418 double a = atan2( (double) ( aGbrItem->m_Start.y - aGbrItem->m_ArcCentre.y ),
419 (double) ( aGbrItem->m_Start.x - aGbrItem->m_ArcCentre.x ) );
420 double b = atan2( (double) ( aGbrItem->m_End.y - aGbrItem->m_ArcCentre.y ),
421 (double) ( aGbrItem->m_End.x - aGbrItem->m_ArcCentre.x ) );
422
423 if( a > b )
424 b += 2 * M_PI;
425
426 VECTOR2I arc_center = aGbrItem->m_ArcCentre;
427 VECTOR2I seg_end = aGbrItem->m_End;
428 VECTOR2I seg_start = aGbrItem->m_Start;
429
430 VECTOR2I seg_middle = GetRotated( seg_start, arc_center,
431 -EDA_ANGLE( (b-a)/2, RADIANS_T ));
432
433 // Reverse Y axis:
434 seg_end.y = -seg_end.y;
435 seg_start.y = -seg_start.y;
436 seg_middle.y = -seg_middle.y;
437
438 fprintf( m_fp, "\t(arc\n\t\t(start %s %s) (mid %s %s) (end %s %s) (layer %s)\n",
439 FormatDouble2Str( MapToPcbUnits( seg_start.x ) ).c_str(),
440 FormatDouble2Str( MapToPcbUnits( seg_start.y ) ).c_str(),
441 FormatDouble2Str( MapToPcbUnits( seg_middle.x ) ).c_str(),
442 FormatDouble2Str( MapToPcbUnits( seg_middle.y ) ).c_str(),
443 FormatDouble2Str( MapToPcbUnits( seg_end.x ) ).c_str(),
444 FormatDouble2Str( MapToPcbUnits( seg_end.y ) ).c_str(),
445 LSET::Name( PCB_LAYER_ID( aLayer ) ).ToStdString().c_str() );
446
447 fprintf( m_fp, "\t\t(width %s) (net 0 )\n",
448 FormatDouble2Str( MapToPcbUnits( aGbrItem->m_Size.x ) ).c_str() );
449 fprintf( m_fp, "\t)\n" );
450}
451
452
454{
455 static D_CODE flashed_item_D_CODE( 0 );
456
457 D_CODE* d_codeDescr = aGbrItem->GetDcodeDescr();
458
459 if( d_codeDescr == nullptr )
460 d_codeDescr = &flashed_item_D_CODE;
461
462 if( aGbrItem->m_ShapeType == GBR_SPOT_CIRCLE )
463 {
464 // See if there's a via that we can enlarge to fit this flashed item
465 for( EXPORT_VIA& via : m_vias )
466 {
467 if( via.m_Pos == aGbrItem->m_Start )
468 {
469 via.m_Size = std::max( via.m_Size, aGbrItem->m_Size.x );
470 return;
471 }
472 }
473 }
474
475 VECTOR2I offset = aGbrItem->GetABPosition( aGbrItem->m_Start );
476
477 if( aGbrItem->m_ShapeType == GBR_SPOT_CIRCLE ||
478 ( aGbrItem->m_ShapeType == GBR_SPOT_OVAL && d_codeDescr->m_Size.x == d_codeDescr->m_Size.y ) )
479 {
480 // export it as filled circle
481 VECTOR2I center = offset;
482 int radius = d_codeDescr->m_Size.x / 2;
484 return;
485 }
486
487 APERTURE_MACRO* macro = d_codeDescr->GetMacro();
488
489 if( macro ) // export a GBR_SPOT_MACRO
490 {
491 SHAPE_POLY_SET macroShape;
492 macroShape = *macro->GetApertureMacroShape( aGbrItem, VECTOR2I( 0, 0 ) );
493
494 // Compensate the Y axis orientation ( writePcbPolygon invert the Y coordinate )
495 macroShape.Outline( 0 ).Mirror( { 0, 0 }, FLIP_DIRECTION::TOP_BOTTOM );
496
497 writePcbPolygon( macroShape, aLayer, offset );
498 }
499 else
500 {
501 // Should cover primitives: GBR_SPOT_RECT, GBR_SPOT_OVAL, GBR_SPOT_POLY
502 d_codeDescr->ConvertShapeToPolygon( aGbrItem );
503 writePcbPolygon( d_codeDescr->m_Polygon, aLayer, offset );
504 }
505}
506
507
508void GBR_TO_PCB_EXPORTER::writePcbFilledCircle( const VECTOR2I& aCenterPosition, int aRadius,
509 int aLayer )
510{
511 fprintf( m_fp, "\t(gr_circle\n\t\t(center %s %s) (end %s %s)\n",
512 FormatDouble2Str( MapToPcbUnits( aCenterPosition.x ) ).c_str(),
513 FormatDouble2Str( MapToPcbUnits( aCenterPosition.y ) ).c_str(),
514 FormatDouble2Str( MapToPcbUnits( aCenterPosition.x + aRadius ) ).c_str(),
515 FormatDouble2Str( MapToPcbUnits( aCenterPosition.y ) ).c_str() );
516
518 fprintf( m_fp, "\t\t(fill yes) (layer %s)",
519 LSET::Name( PCB_LAYER_ID( aLayer ) ).ToStdString().c_str() );
520 fprintf( m_fp, "\n\t)\n" );
521}
522
523
524void GBR_TO_PCB_EXPORTER::writePcbHeader( const int* aLayerLookUpTable )
525{
526 // Note: the .kicad_pcb version used here is after layers_id changes
527 fprintf( m_fp, "(kicad_pcb (version 20240928)\n" );
528 fprintf( m_fp, "\t(generator \"gerbview\")\n\t(generator_version \"%s\")\n\n",
529 GetMajorMinorVersion().c_str().AsChar() );
530
531 // Write layers section
532 fprintf( m_fp, "\t(layers \n" );
533
535
536 for( auto cu_it = layer_set.copper_layers_begin(); cu_it != layer_set.copper_layers_end(); ++cu_it )
537 {
538 fprintf( m_fp, "\t\t(%d %s signal)\n",
539 *cu_it, LSET::Name( *cu_it ).ToStdString().c_str() );
540 }
541
542 for( auto non_cu_it = layer_set.non_copper_layers_begin(); non_cu_it != layer_set.non_copper_layers_end(); ++non_cu_it )
543 {
544 fprintf( m_fp, "\t\t(%d %s user)\n",
545 *non_cu_it, LSET::Name( *non_cu_it ).ToStdString().c_str() );
546 }
547
548 fprintf( m_fp, "\t)\n\n" );
549}
550
551
553 const VECTOR2I& aOffset )
554{
555 // Ensure the polygon is valid:
556 if( aPolys.OutlineCount() < 1 )
557 return;
558
559 // aPolys is expected having only one outline and no hole
560 // (because it comes from a gerber file or is built from a aperture )
561 const SHAPE_LINE_CHAIN& poly = aPolys.COutline( 0 );
562
563 fprintf( m_fp, "\t(gr_poly\n\t\t(pts\n\t\t\t" );
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\t\t\t" );
579 }
580
581 fprintf( m_fp, " (xy %s %s)",
582 FormatDouble2Str( MapToPcbUnits( poly.CPoint( ii ).x + aOffset.x ) ).c_str(),
583 FormatDouble2Str( MapToPcbUnits( -poly.CPoint( ii ).y + aOffset.y ) ).c_str() );
584 }
585
586 fprintf( m_fp, ")" );
587
588 fprintf( m_fp, "\n" );
590 fprintf( m_fp, "\t\t(fill yes) (layer %s)",
591 LSET::Name( PCB_LAYER_ID( aLayer ) ).ToStdString().c_str() );
592 fprintf( m_fp, "\n\t)\n" );
593}
594
595
597{
599 polys.Simplify();
600
601 if( polys.OutlineCount() == 0 )
602 return;
603
604 fprintf( m_fp, "\t(zone (net 0) (net_name \"\") (layer %s) (tstamp 0000000) (hatch edge 0.508)\n",
605 LSET::Name( PCB_LAYER_ID( aLayer ) ).ToStdString().c_str() );
606
607 fprintf( m_fp, " (connect_pads (clearance 0.0))\n" );
608
609 fprintf( m_fp, " (min_thickness 0.1) (filled_areas_thickness no)\n"
610 " (fill (thermal_gap 0.3) (thermal_bridge_width 0.3))\n" );
611
612 // Now, write the zone outlines with holes.
613 // first polygon is the main outline, next are holes
614 // One cannot know the initial zone outline.
615 // However most of (if not all) holes are just items with clearance,
616 // not really a hole in the initial zone outline.
617 // So we build a zone outline only with no hole.
618 fprintf( m_fp, " (polygon\n (pts" );
619
620 SHAPE_LINE_CHAIN& poly = polys.Outline( 0 );
621
622 #define MAX_COORD_CNT 4
623 int jj = MAX_COORD_CNT;
624 int cnt_max = poly.PointCount() -1;
625
626 // Do not generate last corner, if it is the same point as the first point:
627 if( poly.CPoint( 0 ) == poly.CPoint( cnt_max ) )
628 cnt_max--;
629
630 for( int ii = 0; ii <= cnt_max; ii++ )
631 {
632 if( --jj == 0 )
633 {
634 jj = MAX_COORD_CNT;
635 fprintf( m_fp, "\n " );
636 }
637
638 fprintf( m_fp, " (xy %s %s)", FormatDouble2Str( MapToPcbUnits( poly.CPoint( ii ).x ) ).c_str(),
639 FormatDouble2Str( MapToPcbUnits( -poly.CPoint( ii ).y ) ).c_str() );
640 }
641
642 fprintf( m_fp, ")\n" );
643
644 fprintf( m_fp, " )\n)\n" );
645}
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
LSET is a set of PCB_LAYER_IDs.
Definition: lset.h:37
copper_layers_iterator copper_layers_end() const
Definition: lset.cpp:913
static const LSET & UserMask()
Definition: lset.cpp:673
copper_layers_iterator copper_layers_begin() const
Definition: lset.cpp:907
non_copper_layers_iterator non_copper_layers_begin() const
Definition: lset.cpp:919
static const LSET & AllTechMask()
Return a mask holding all technical layers (no CU layer) on both side.
Definition: lset.cpp:659
non_copper_layers_iterator non_copper_layers_end() const
Definition: lset.cpp:925
static LSET AllCuMask()
return AllCuMask( MAX_CU_LAYERS );
Definition: lset.cpp:591
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:169
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:654
bool IsCopperLayer(int aLayerId)
Test whether a layer is a copper layer.
Definition: layer_ids.h:665
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.