KiCad PCB EDA Suite
Loading...
Searching...
No Matches
plot_board_layers.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) 1992-2024 KiCad Developers, see AUTHORS.txt for contributors.
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, you may find one here:
18 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
19 * or you may search the http://www.gnu.org website for the version 2 license,
20 * or you may write to the Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
22 */
23
24#include <wx/log.h>
25#include <eda_item.h>
26#include <layer_ids.h>
27#include <lset.h>
30#include <pcb_base_frame.h>
31#include <math/util.h> // for KiROUND
32#include <board.h>
33#include <footprint.h>
34#include <pcb_track.h>
35#include <pad.h>
36#include <zone.h>
37#include <pcb_shape.h>
38#include <pcb_target.h>
39#include <pcb_dimension.h>
40#include <pcbplot.h>
45#include <pcb_painter.h>
46#include <gbr_metadata.h>
47#include <advanced_config.h>
48
49/*
50 * Plot a solder mask layer. Solder mask layers have a minimum thickness value and cannot be
51 * drawn like standard layers, unless the minimum thickness is 0.
52 */
53static void PlotSolderMaskLayer( BOARD *aBoard, PLOTTER* aPlotter, LSET aLayerMask,
54 const PCB_PLOT_PARAMS& aPlotOpt, int aMinThickness );
55
56
57void PlotBoardLayers( BOARD* aBoard, PLOTTER* aPlotter, const LSEQ& aLayers,
58 const PCB_PLOT_PARAMS& aPlotOptions )
59{
60 if( !aBoard || !aPlotter || aLayers.empty() )
61 return;
62
63 // if a drill mark must be plotted, the copper layer needs to be plotted
64 // after other layers because the drill mark must be plotted as a filled
65 // white shape *after* all other shapes are plotted
66 bool plot_mark = aPlotOptions.GetDrillMarksType() != DRILL_MARKS::NO_DRILL_SHAPE;
67
68 for( PCB_LAYER_ID layer : aLayers )
69 {
70 // copper layers with drill marks will be plotted after all other layers
71 if( IsCopperLayer( layer ) && plot_mark )
72 continue;
73
74 PlotOneBoardLayer( aBoard, aPlotter, layer, aPlotOptions );
75 }
76
77 if( !plot_mark )
78 return;
79
80 for( PCB_LAYER_ID layer : aLayers )
81 {
82 if( !IsCopperLayer( layer ) )
83 continue;
84
85 PlotOneBoardLayer( aBoard, aPlotter, layer, aPlotOptions );
86 }
87}
88
89
90void PlotInteractiveLayer( BOARD* aBoard, PLOTTER* aPlotter, const PCB_PLOT_PARAMS& aPlotOpt )
91{
92 for( const FOOTPRINT* fp : aBoard->Footprints() )
93 {
94 if( fp->GetLayer() == F_Cu && !aPlotOpt.m_PDFFrontFPPropertyPopups )
95 continue;
96
97 if( fp->GetLayer() == B_Cu && !aPlotOpt.m_PDFBackFPPropertyPopups )
98 continue;
99
100 std::vector<wxString> properties;
101
102 properties.emplace_back( wxString::Format( wxT( "!%s = %s" ),
103 _( "Reference designator" ),
104 fp->Reference().GetShownText( false ) ) );
105
106 properties.emplace_back( wxString::Format( wxT( "!%s = %s" ),
107 _( "Value" ),
108 fp->Value().GetShownText( false ) ) );
109
110 properties.emplace_back( wxString::Format( wxT( "!%s = %s" ),
111 _( "Footprint" ),
112 fp->GetFPID().GetUniStringLibItemName() ) );
113
114 for( int i = 0; i < fp->GetFieldCount(); i++ )
115 {
116 PCB_FIELD* field = fp->GetFields().at( i );
117
118 if( field->IsReference() || field->IsValue() || field->IsFootprint() )
119 continue;
120
121 if( field->GetText().IsEmpty() )
122 continue;
123
124 properties.emplace_back( wxString::Format( wxT( "!%s = %s" ),
125 field->GetName(),
126 field->GetText() ) );
127 }
128
129 // These 2 properties are not very useful in a plot file (like a PDF)
130#if 0
131 properties.emplace_back( wxString::Format( wxT( "!%s = %s" ), _( "Library Description" ),
132 fp->GetLibDescription() ) );
133
134 properties.emplace_back( wxString::Format( wxT( "!%s = %s" ),
135 _( "Keywords" ),
136 fp->GetKeywords() ) );
137#endif
138 // Draw items are plotted with a position offset. So we need to move
139 // our boxes (which are not plotted) by the same offset.
140 VECTOR2I offset = -aPlotter->GetPlotOffsetUserUnits();
141
142 // Use a footprint bbox without texts to create the hyperlink area
143 BOX2I bbox = fp->GetBoundingBox( false );
144 bbox.Move( offset );
145 aPlotter->HyperlinkMenu( bbox, properties );
146
147 // Use a footprint bbox with visible texts only to create the bookmark area
148 // which is the area to zoom on ft selection
149 // However the bbox need to be inflated for a better look.
150 bbox = fp->GetBoundingBox( true );
151 bbox.Move( offset );
152 bbox.Inflate( bbox.GetWidth() /2, bbox.GetHeight() /2 );
153 aPlotter->Bookmark( bbox, fp->GetReference(), _( "Footprints" ) );
154 }
155}
156
157
158void PlotOneBoardLayer( BOARD *aBoard, PLOTTER* aPlotter, PCB_LAYER_ID aLayer,
159 const PCB_PLOT_PARAMS& aPlotOpt )
160{
161 auto plotLayer =
162 [&]( LSET layerMask, PCB_PLOT_PARAMS& plotOpts )
163 {
164 // PlotLayerOutlines() is designed only for DXF plotters.
165 if( plotOpts.GetFormat() == PLOT_FORMAT::DXF && plotOpts.GetDXFPlotPolygonMode() )
166 PlotLayerOutlines( aBoard, aPlotter, layerMask, plotOpts );
167 else
168 PlotStandardLayer( aBoard, aPlotter, layerMask, plotOpts );
169 };
170
171 PCB_PLOT_PARAMS plotOpt = aPlotOpt;
172 int soldermask_min_thickness = aBoard->GetDesignSettings().m_SolderMaskMinWidth;
173
174 // Set a default color and the text mode for this layer
175 aPlotter->SetColor( BLACK );
176 aPlotter->SetTextMode( aPlotOpt.GetTextMode() );
177
178 // Specify that the contents of the "Edges Pcb" layer are to be plotted in addition to the
179 // contents of the currently specified layer.
180 LSET layer_mask( { aLayer } );
181
182 if( IsCopperLayer( aLayer ) )
183 {
184 // Skip NPTH pads on copper layers ( only if hole size == pad size ):
185 // Drill mark will be plotted if drill mark is SMALL_DRILL_SHAPE or FULL_DRILL_SHAPE
186 if( plotOpt.GetFormat() == PLOT_FORMAT::DXF )
187 plotOpt.SetDXFPlotPolygonMode( true );
188 else
189 plotOpt.SetSkipPlotNPTH_Pads( true );
190
191 plotLayer( layer_mask, plotOpt );
192 }
193 else
194 {
195 switch( aLayer )
196 {
197 case B_Mask:
198 case F_Mask:
199 // Disable plot pad holes
201
202 // Use outline mode for DXF
203 plotOpt.SetDXFPlotPolygonMode( true );
204
205 // Plot solder mask:
206 if( soldermask_min_thickness == 0 )
207 {
208 plotLayer( layer_mask, plotOpt );
209 }
210 else
211 {
212 PlotSolderMaskLayer( aBoard, aPlotter, layer_mask, plotOpt,
213 soldermask_min_thickness );
214 }
215
216 break;
217
218 case B_Adhes:
219 case F_Adhes:
220 case B_Paste:
221 case F_Paste:
222 // Disable plot pad holes
224
225 // Use outline mode for DXF
226 plotOpt.SetDXFPlotPolygonMode( true );
227
228 plotLayer( layer_mask, plotOpt );
229
230 break;
231
232 case F_SilkS:
233 case B_SilkS:
234 plotLayer( layer_mask, plotOpt );
235
236 // Gerber: Subtract soldermask from silkscreen if enabled
237 if( aPlotter->GetPlotterType() == PLOT_FORMAT::GERBER
238 && plotOpt.GetSubtractMaskFromSilk() )
239 {
240 if( aLayer == F_SilkS )
241 layer_mask = LSET( { F_Mask } );
242 else
243 layer_mask = LSET( { B_Mask } );
244
245 // Create the mask to subtract by creating a negative layer polarity
246 aPlotter->SetLayerPolarity( false );
247
248 // Disable plot pad holes
250
251 // Plot the mask
252 PlotStandardLayer( aBoard, aPlotter, layer_mask, plotOpt );
253
254 // Disable the negative polarity
255 aPlotter->SetLayerPolarity( true );
256 }
257
258 break;
259
260 case Dwgs_User:
261 case Cmts_User:
262 case Eco1_User:
263 case Eco2_User:
264 case Edge_Cuts:
265 case Margin:
266 case F_CrtYd:
267 case B_CrtYd:
268 case F_Fab:
269 case B_Fab:
270 default:
271 plotLayer( layer_mask, plotOpt );
272 break;
273 }
274 }
275}
276
277
281void PlotStandardLayer( BOARD* aBoard, PLOTTER* aPlotter, LSET aLayerMask,
282 const PCB_PLOT_PARAMS& aPlotOpt )
283{
284 BRDITEMS_PLOTTER itemplotter( aPlotter, aBoard, aPlotOpt );
285 int maxError = aBoard->GetDesignSettings().m_MaxError;
286
287 itemplotter.SetLayerSet( aLayerMask );
288
289 OUTLINE_MODE plotMode = aPlotOpt.GetPlotMode();
290 bool onCopperLayer = ( LSET::AllCuMask() & aLayerMask ).any();
291 bool onSolderMaskLayer = ( LSET( { F_Mask, B_Mask } ) & aLayerMask ).any();
292 bool onSolderPasteLayer = ( LSET( { F_Paste, B_Paste } ) & aLayerMask ).any();
293 bool onFrontFab = ( LSET( { F_Fab } ) & aLayerMask ).any();
294 bool onBackFab = ( LSET( { B_Fab } ) & aLayerMask ).any();
295 bool sketchPads = ( onFrontFab || onBackFab ) && aPlotOpt.GetSketchPadsOnFabLayers();
296
297 // Plot edge layer and graphic items
298 for( const BOARD_ITEM* item : aBoard->Drawings() )
299 itemplotter.PlotBoardGraphicItem( item );
300
301 // Draw footprint texts:
302 for( const FOOTPRINT* footprint : aBoard->Footprints() )
303 itemplotter.PlotFootprintTextItems( footprint );
304
305 // Draw footprint other graphic items:
306 for( const FOOTPRINT* footprint : aBoard->Footprints() )
307 itemplotter.PlotFootprintGraphicItems( footprint );
308
309 // Plot footprint pads
310 for( FOOTPRINT* footprint : aBoard->Footprints() )
311 {
312 aPlotter->StartBlock( nullptr );
313
314 for( PAD* pad : footprint->Pads() )
315 {
316 OUTLINE_MODE padPlotMode = plotMode;
317
318 if( !( pad->GetLayerSet() & aLayerMask ).any() )
319 {
320 if( sketchPads &&
321 ( ( onFrontFab && pad->GetLayerSet().Contains( F_Cu ) ) ||
322 ( onBackFab && pad->GetLayerSet().Contains( B_Cu ) ) ) )
323 {
324 padPlotMode = SKETCH;
325 }
326 else
327 {
328 continue;
329 }
330 }
331
332 if( onCopperLayer && !pad->IsOnCopperLayer() )
333 continue;
334
336 if( onCopperLayer && !pad->FlashLayer( aLayerMask ) )
337 continue;
338
339 // TODO(JE) padstacks - different behavior for single layer or multilayer
340
342
343 // If we're plotting a single layer, the color for that layer can be used directly.
344 if( aLayerMask.count() == 1 )
345 {
346 color = aPlotOpt.ColorSettings()->GetColor( aLayerMask.Seq()[0] );
347 }
348 else
349 {
350 if( ( pad->GetLayerSet() & aLayerMask )[B_Cu] )
351 color = aPlotOpt.ColorSettings()->GetColor( B_Cu );
352
353 if( ( pad->GetLayerSet() & aLayerMask )[F_Cu] )
354 color = color.LegacyMix( aPlotOpt.ColorSettings()->GetColor( F_Cu ) );
355
356 if( sketchPads && aLayerMask[F_Fab] )
357 color = aPlotOpt.ColorSettings()->GetColor( F_Fab );
358 else if( sketchPads && aLayerMask[B_Fab] )
359 color = aPlotOpt.ColorSettings()->GetColor( B_Fab );
360 }
361
362 if( sketchPads &&
363 ( ( onFrontFab && pad->GetLayerSet().Contains( F_Cu ) ) ||
364 ( onBackFab && pad->GetLayerSet().Contains( B_Cu ) ) ) )
365 {
366 if( aPlotOpt.GetPlotPadNumbers() )
367 itemplotter.PlotPadNumber( pad, color );
368 }
369
370 auto plotPadLayer =
371 [&]( PCB_LAYER_ID aLayer )
372 {
373 VECTOR2I margin;
374 int width_adj = 0;
375
376 if( onCopperLayer )
377 width_adj = itemplotter.getFineWidthAdj();
378
379 if( onSolderMaskLayer )
380 margin.x = margin.y = pad->GetSolderMaskExpansion( aLayer );
381
382 if( onSolderPasteLayer )
383 margin = pad->GetSolderPasteMargin( aLayer );
384
385 // not all shapes can have a different margin for x and y axis
386 // in fact only oval and rect shapes can have different values.
387 // Round shape have always the same x,y margin
388 // so define a unique value for other shapes that do not support different values
389 int mask_clearance = margin.x;
390
391 // Now offset the pad size by margin + width_adj
392 VECTOR2I padPlotsSize =
393 pad->GetSize( aLayer ) + margin * 2 + VECTOR2I( width_adj, width_adj );
394
395 // Store these parameters that can be modified to plot inflated/deflated pads shape
396 PAD_SHAPE padShape = pad->GetShape( aLayer );
397 VECTOR2I padSize = pad->GetSize( aLayer );
398 VECTOR2I padDelta = pad->GetDelta( aLayer ); // has meaning only for trapezoidal pads
399 // CornerRadius and CornerRadiusRatio can be modified
400 // the radius is built from the ratio, so saving/restoring the ratio is enough
401 double padCornerRadiusRatio = pad->GetRoundRectRadiusRatio( aLayer );
402
403 // Don't draw a 0 sized pad.
404 // Note: a custom pad can have its pad anchor with size = 0
405 if( padShape != PAD_SHAPE::CUSTOM
406 && ( padPlotsSize.x <= 0 || padPlotsSize.y <= 0 ) )
407 {
408 return;
409 }
410
411 switch( padShape )
412 {
414 case PAD_SHAPE::OVAL:
415 pad->SetSize( aLayer, padPlotsSize );
416
417 if( aPlotOpt.GetSkipPlotNPTH_Pads() &&
419 ( pad->GetSize(aLayer ) == pad->GetDrillSize() ) &&
420 ( pad->GetAttribute() == PAD_ATTRIB::NPTH ) )
421 {
422 break;
423 }
424
425 itemplotter.PlotPad( pad, aLayer, color, padPlotMode );
426 break;
427
429 pad->SetSize( aLayer, padPlotsSize );
430
431 if( mask_clearance > 0 )
432 {
433 pad->SetShape( aLayer, PAD_SHAPE::ROUNDRECT );
434 pad->SetRoundRectCornerRadius( aLayer, mask_clearance );
435 }
436
437 itemplotter.PlotPad( pad, aLayer, color, padPlotMode );
438 break;
439
441 // inflate/deflate a trapezoid is a bit complex.
442 // so if the margin is not null, build a similar polygonal pad shape,
443 // and inflate/deflate the polygonal shape
444 // because inflating/deflating using different values for y and y
445 // we are using only margin.x as inflate/deflate value
446 if( mask_clearance == 0 )
447 {
448 itemplotter.PlotPad( pad, aLayer, color, padPlotMode );
449 }
450 else
451 {
452 PAD dummy( *pad );
453 dummy.SetAnchorPadShape( aLayer, PAD_SHAPE::CIRCLE );
454 dummy.SetShape( aLayer, PAD_SHAPE::CUSTOM );
455 SHAPE_POLY_SET outline;
456 outline.NewOutline();
457 int dx = padSize.x / 2;
458 int dy = padSize.y / 2;
459 int ddx = padDelta.x / 2;
460 int ddy = padDelta.y / 2;
461
462 outline.Append( -dx - ddy, dy + ddx );
463 outline.Append( dx + ddy, dy - ddx );
464 outline.Append( dx - ddy, -dy + ddx );
465 outline.Append( -dx + ddy, -dy - ddx );
466
467 // Shape polygon can have holes so use InflateWithLinkedHoles(), not Inflate()
468 // which can create bad shapes if margin.x is < 0
469 outline.InflateWithLinkedHoles( mask_clearance,
472 dummy.DeletePrimitivesList();
473 dummy.AddPrimitivePoly( aLayer, outline, 0, true );
474
475 // Be sure the anchor pad is not bigger than the deflated shape because this
476 // anchor will be added to the pad shape when plotting the pad. So now the
477 // polygonal shape is built, we can clamp the anchor size
478 dummy.SetSize( aLayer, VECTOR2I( 0, 0 ) );
479
480 itemplotter.PlotPad( &dummy, aLayer, color, padPlotMode );
481 }
482
483 break;
484
486 {
487 // rounding is stored as a percent, but we have to update this ratio
488 // to force recalculation of other values after size changing (we do not
489 // really change the rounding percent value)
490 double radius_ratio = pad->GetRoundRectRadiusRatio( aLayer );
491 pad->SetSize( aLayer, padPlotsSize );
492 pad->SetRoundRectRadiusRatio( aLayer, radius_ratio );
493
494 itemplotter.PlotPad( pad, aLayer, color, padPlotMode );
495 break;
496 }
497
499 if( mask_clearance == 0 )
500 {
501 // the size can be slightly inflated by width_adj (PS/PDF only)
502 pad->SetSize( aLayer, padPlotsSize );
503 itemplotter.PlotPad( pad, aLayer, color, padPlotMode );
504 }
505 else
506 {
507 // Due to the polygonal shape of a CHAMFERED_RECT pad, the best way is to
508 // convert the pad shape to a full polygon, inflate/deflate the polygon
509 // and use a dummy CUSTOM pad to plot the final shape.
510 PAD dummy( *pad );
511 // Build the dummy pad outline with coordinates relative to the pad position
512 // pad offset and orientation 0. The actual pos, offset and rotation will be
513 // taken in account later by the plot function
514 dummy.SetPosition( VECTOR2I( 0, 0 ) );
515 dummy.SetOffset( aLayer, VECTOR2I( 0, 0 ) );
516 dummy.SetOrientation( ANGLE_0 );
517 SHAPE_POLY_SET outline;
518 dummy.TransformShapeToPolygon( outline, UNDEFINED_LAYER, 0, maxError,
519 ERROR_INSIDE );
520 outline.InflateWithLinkedHoles( mask_clearance,
523
524 // Initialize the dummy pad shape:
525 dummy.SetAnchorPadShape( aLayer, PAD_SHAPE::CIRCLE );
526 dummy.SetShape( aLayer, PAD_SHAPE::CUSTOM );
527 dummy.DeletePrimitivesList();
528 dummy.AddPrimitivePoly( aLayer, outline, 0, true );
529
530 // Be sure the anchor pad is not bigger than the deflated shape because this
531 // anchor will be added to the pad shape when plotting the pad.
532 // So we set the anchor size to 0
533 dummy.SetSize( aLayer, VECTOR2I( 0, 0 ) );
534 // Restore pad position and offset
535 dummy.SetPosition( pad->GetPosition() );
536 dummy.SetOffset( aLayer, pad->GetOffset( aLayer ) );
537 dummy.SetOrientation( pad->GetOrientation() );
538
539 itemplotter.PlotPad( &dummy, aLayer, color, padPlotMode );
540 }
541
542 break;
543
545 {
546 // inflate/deflate a custom shape is a bit complex.
547 // so build a similar pad shape, and inflate/deflate the polygonal shape
548 PAD dummy( *pad );
549 dummy.SetParentGroup( nullptr );
550
551 SHAPE_POLY_SET shape;
552 pad->MergePrimitivesAsPolygon( aLayer, &shape );
553
554 // Shape polygon can have holes so use InflateWithLinkedHoles(), not Inflate()
555 // which can create bad shapes if margin.x is < 0
556 shape.InflateWithLinkedHoles( mask_clearance,
559 dummy.DeletePrimitivesList();
560 dummy.AddPrimitivePoly( aLayer, shape, 0, true );
561
562 // Be sure the anchor pad is not bigger than the deflated shape because this
563 // anchor will be added to the pad shape when plotting the pad. So now the
564 // polygonal shape is built, we can clamp the anchor size
565 if( mask_clearance < 0 ) // we expect margin.x = margin.y for custom pads
566 dummy.SetSize( aLayer, padPlotsSize );
567
568 itemplotter.PlotPad( &dummy, aLayer, color, padPlotMode );
569 break;
570 }
571 }
572
573 // Restore the pad parameters modified by the plot code
574 pad->SetSize( aLayer, padSize );
575 pad->SetDelta( aLayer, padDelta );
576 pad->SetShape( aLayer, padShape );
577 pad->SetRoundRectRadiusRatio( aLayer, padCornerRadiusRatio );
578 };
579
580 for( PCB_LAYER_ID layer : aLayerMask.SeqStackupForPlotting() )
581 plotPadLayer( layer );
582 }
583
584 if( footprint->IsDNP()
585 && !itemplotter.GetHideDNPFPsOnFabLayers()
586 && itemplotter.GetCrossoutDNPFPsOnFabLayers()
587 && ( onFrontFab || onBackFab ) )
588 {
589 BOX2I rect = footprint->GetBoundingHull().BBox();
590 int width = aBoard->GetDesignSettings().m_LineThickness[ LAYER_CLASS_FAB ];
591
592 aPlotter->ThickSegment( rect.GetOrigin(), rect.GetEnd(), width, FILLED, nullptr );
593 aPlotter->ThickSegment( VECTOR2I( rect.GetLeft(), rect.GetBottom() ),
594 VECTOR2I( rect.GetRight(), rect.GetTop() ),
595 width, FILLED, nullptr );
596 }
597
598 aPlotter->EndBlock( nullptr );
599 }
600
601 // Plot vias on copper layers, and if aPlotOpt.GetPlotViaOnMaskLayer() is true,
602
603 GBR_METADATA gbr_metadata;
604
605 if( onCopperLayer )
606 {
609 }
610
611 aPlotter->StartBlock( nullptr );
612
613 for( const PCB_TRACK* track : aBoard->Tracks() )
614 {
615 if( track->Type() != PCB_VIA_T )
616 continue;
617
618 const PCB_VIA* via = static_cast<const PCB_VIA*>( track );
619
620 // vias are not plotted if not on selected layer
621 LSET via_mask_layer = via->GetLayerSet();
622
623 if( !( via_mask_layer & aLayerMask ).any() )
624 continue;
625
626 int via_margin = 0;
627 double width_adj = 0;
628
629 if( onSolderMaskLayer )
630 via_margin = via->GetSolderMaskExpansion();
631
632 if( ( aLayerMask & LSET::AllCuMask() ).any() )
633 width_adj = itemplotter.getFineWidthAdj();
634
635 // TODO(JE) padstacks
636 int diameter = via->GetWidth( PADSTACK::ALL_LAYERS ) + 2 * via_margin + width_adj;
637
639 if( onCopperLayer && !via->FlashLayer( aLayerMask ) )
640 continue;
641
642 // Don't draw a null size item :
643 if( diameter <= 0 )
644 continue;
645
646 // Some vias can be not connected (no net).
647 // Set the m_NotInNet for these vias to force a empty net name in gerber file
648 gbr_metadata.m_NetlistMetadata.m_NotInNet = via->GetNetname().IsEmpty();
649
650 gbr_metadata.SetNetName( via->GetNetname() );
651
652 COLOR4D color = aPlotOpt.ColorSettings()->GetColor(
653 LAYER_VIAS + static_cast<int>( via->GetViaType() ) );
654
655 // Set plot color (change WHITE to LIGHTGRAY because the white items are not seen on a
656 // white paper or screen
657 aPlotter->SetColor( color != WHITE ? color : LIGHTGRAY );
658 aPlotter->FlashPadCircle( via->GetStart(), diameter, plotMode, &gbr_metadata );
659 }
660
661 aPlotter->EndBlock( nullptr );
662 aPlotter->StartBlock( nullptr );
663
664 if( onCopperLayer )
665 {
668 }
669 else
670 {
671 // Reset attributes if non-copper (soldermask) layer
674 }
675
676 // Plot tracks (not vias) :
677 for( const PCB_TRACK* track : aBoard->Tracks() )
678 {
679 if( track->Type() == PCB_VIA_T )
680 continue;
681
682 if( !( aLayerMask & track->GetLayerSet() ).any() )
683 continue;
684
685 // Some track segments can be not connected (no net).
686 // Set the m_NotInNet for these segments to force a empty net name in gerber file
687 gbr_metadata.m_NetlistMetadata.m_NotInNet = track->GetNetname().IsEmpty();
688
689 gbr_metadata.SetNetName( track->GetNetname() );
690
691 int margin = 0;
692
693 if( onSolderMaskLayer )
694 margin = track->GetSolderMaskExpansion();
695
696 int width = track->GetWidth() + 2 * margin + itemplotter.getFineWidthAdj();
697
698 aPlotter->SetColor( itemplotter.getColor( track->GetLayer() ) );
699
700 if( track->Type() == PCB_ARC_T )
701 {
702 const PCB_ARC* arc = static_cast<const PCB_ARC*>( track );
703
704 // Too small arcs cannot be really handled: arc center (and arc radius)
705 // cannot be safely computed
706 if( !arc->IsDegenerated( 10 /* in IU */ ) )
707 {
708 aPlotter->ThickArc( arc->GetCenter(), arc->GetArcAngleStart(), arc->GetAngle(),
709 arc->GetRadius(), width, plotMode, &gbr_metadata );
710 }
711 else
712 {
713 // Approximate this very small arc by a segment.
714 aPlotter->ThickSegment( track->GetStart(), track->GetEnd(), width, plotMode,
715 &gbr_metadata );
716 }
717 }
718 else
719 {
720 aPlotter->ThickSegment( track->GetStart(), track->GetEnd(), width, plotMode,
721 &gbr_metadata );
722 }
723 }
724
725 aPlotter->EndBlock( nullptr );
726
727 // Plot filled ares
728 aPlotter->StartBlock( nullptr );
729
730 NETINFO_ITEM nonet( aBoard );
731
732 for( const ZONE* zone : aBoard->Zones() )
733 {
734 if( zone->GetIsRuleArea() )
735 continue;
736
737 for( PCB_LAYER_ID layer : zone->GetLayerSet().Seq() )
738 {
739 if( !aLayerMask[layer] )
740 continue;
741
742 SHAPE_POLY_SET mainArea = zone->GetFilledPolysList( layer )->CloneDropTriangulation();
743 SHAPE_POLY_SET islands;
744
745 for( int i = mainArea.OutlineCount() - 1; i >= 0; i-- )
746 {
747 if( zone->IsIsland( layer, i ) )
748 {
749 islands.AddOutline( mainArea.CPolygon( i )[0] );
750 mainArea.DeletePolygon( i );
751 }
752 }
753
754 itemplotter.PlotZone( zone, layer, mainArea );
755
756 if( !islands.IsEmpty() )
757 {
758 ZONE dummy( *zone );
759 dummy.SetNet( &nonet );
760 itemplotter.PlotZone( &dummy, layer, islands );
761 }
762 }
763 }
764
765 aPlotter->EndBlock( nullptr );
766
767 // Adding drill marks, if required and if the plotter is able to plot them:
769 itemplotter.PlotDrillMarks();
770}
771
772
776void PlotLayerOutlines( BOARD* aBoard, PLOTTER* aPlotter, LSET aLayerMask,
777 const PCB_PLOT_PARAMS& aPlotOpt )
778{
779 BRDITEMS_PLOTTER itemplotter( aPlotter, aBoard, aPlotOpt );
780 itemplotter.SetLayerSet( aLayerMask );
781
782 SHAPE_POLY_SET outlines;
783
784 for( PCB_LAYER_ID layer : aLayerMask.Seq( aLayerMask.SeqStackupForPlotting() ) )
785 {
786 outlines.RemoveAllContours();
787 aBoard->ConvertBrdLayerToPolygonalContours( layer, outlines );
788
790
791 // Plot outlines
792 std::vector<VECTOR2I> cornerList;
793
794 // Now we have one or more basic polygons: plot each polygon
795 for( int ii = 0; ii < outlines.OutlineCount(); ii++ )
796 {
797 for( int kk = 0; kk <= outlines.HoleCount(ii); kk++ )
798 {
799 cornerList.clear();
800 const SHAPE_LINE_CHAIN& path = ( kk == 0 ) ? outlines.COutline( ii )
801 : outlines.CHole( ii, kk - 1 );
802
803 aPlotter->PlotPoly( path, FILL_T::NO_FILL );
804 }
805 }
806
807 // Plot pad holes
809 {
810 int smallDrill = ( aPlotOpt.GetDrillMarksType() == DRILL_MARKS::SMALL_DRILL_SHAPE )
812 : INT_MAX;
813
814 for( FOOTPRINT* footprint : aBoard->Footprints() )
815 {
816 for( PAD* pad : footprint->Pads() )
817 {
818 if( pad->HasHole() )
819 {
820 std::shared_ptr<SHAPE_SEGMENT> slot = pad->GetEffectiveHoleShape();
821
822 if( slot->GetSeg().A == slot->GetSeg().B ) // circular hole
823 {
824 int drill = std::min( smallDrill, slot->GetWidth() );
825 aPlotter->Circle( pad->GetPosition(), drill, FILL_T::NO_FILL );
826 }
827 else
828 {
829 // Note: small drill marks have no significance when applied to slots
830 aPlotter->ThickSegment( slot->GetSeg().A, slot->GetSeg().B,
831 slot->GetWidth(), SKETCH, nullptr );
832 }
833 }
834 }
835 }
836 }
837
838 // Plot vias holes
839 for( PCB_TRACK* track : aBoard->Tracks() )
840 {
841 if( track->Type() != PCB_VIA_T )
842 continue;
843
844 const PCB_VIA* via = static_cast<const PCB_VIA*>( track );
845
846 if( via->GetLayerSet().Contains( layer ) ) // via holes can be not through holes
847 aPlotter->Circle( via->GetPosition(), via->GetDrillValue(), FILL_T::NO_FILL );
848 }
849 }
850}
851
852
870void PlotSolderMaskLayer( BOARD *aBoard, PLOTTER* aPlotter, LSET aLayerMask,
871 const PCB_PLOT_PARAMS& aPlotOpt, int aMinThickness )
872{
873 int maxError = aBoard->GetDesignSettings().m_MaxError;
874 PCB_LAYER_ID layer = aLayerMask[B_Mask] ? B_Mask : F_Mask;
875 SHAPE_POLY_SET buffer;
876 SHAPE_POLY_SET* boardOutline = nullptr;
877
878 if( aBoard->GetBoardPolygonOutlines( buffer ) )
879 boardOutline = &buffer;
880
881 // We remove 1nm as we expand both sides of the shapes, so allowing for a strictly greater
882 // than or equal comparison in the shape separation (boolean add)
883 int inflate = aMinThickness / 2 - 1;
884
885 BRDITEMS_PLOTTER itemplotter( aPlotter, aBoard, aPlotOpt );
886 itemplotter.SetLayerSet( aLayerMask );
887
888 // Build polygons for each pad shape. The size of the shape on solder mask should be size
889 // of pad + clearance around the pad, where clearance = solder mask clearance + extra margin.
890 // Extra margin is half the min width for solder mask, which is used to merge too-close shapes
891 // (distance < aMinThickness), and will be removed when creating the actual shapes.
892
893 // Will contain shapes inflated by inflate value that will be merged and deflated by inflate
894 // value to build final polygons
895 SHAPE_POLY_SET areas;
896
897 // Will contain exact shapes of all items on solder mask
898 SHAPE_POLY_SET initialPolys;
899
900 auto plotFPTextItem =
901 [&]( const PCB_TEXT& aText )
902 {
903 if( !itemplotter.GetPlotFPText() )
904 return;
905
906 if( !aText.IsVisible() && !itemplotter.GetPlotInvisibleText() )
907 return;
908
909 if( aText.GetText() == wxT( "${REFERENCE}" ) && !itemplotter.GetPlotReference() )
910 return;
911
912 if( aText.GetText() == wxT( "${VALUE}" ) && !itemplotter.GetPlotValue() )
913 return;
914
915 // add shapes with their exact mask layer size in initialPolys
916 aText.TransformTextToPolySet( initialPolys, 0, maxError, ERROR_OUTSIDE );
917
918 // add shapes inflated by aMinThickness/2 in areas
919 aText.TransformTextToPolySet( areas, inflate, maxError, ERROR_OUTSIDE );
920 };
921
922 // Generate polygons with arcs inside the shape or exact shape to minimize shape changes
923 // created by arc to segment size correction.
925 {
926 // Plot footprint pads and graphics
927 for( const FOOTPRINT* footprint : aBoard->Footprints() )
928 {
929 // add shapes with their exact mask layer size in initialPolys
930 footprint->TransformPadsToPolySet( initialPolys, layer, 0, maxError, ERROR_OUTSIDE );
931 // add shapes inflated by aMinThickness/2 in areas
932 footprint->TransformPadsToPolySet( areas, layer, inflate, maxError, ERROR_OUTSIDE );
933
934 for( const PCB_FIELD* field : footprint->Fields() )
935 {
936 if( field->IsReference() && !itemplotter.GetPlotReference() )
937 continue;
938
939 if( field->IsValue() && !itemplotter.GetPlotValue() )
940 continue;
941
942 if( field->IsOnLayer( layer ) )
943 plotFPTextItem( static_cast<const PCB_TEXT&>( *field ) );
944 }
945
946 for( const BOARD_ITEM* item : footprint->GraphicalItems() )
947 {
948 if( item->IsOnLayer( layer ) )
949 {
950 if( item->Type() == PCB_TEXT_T )
951 {
952 plotFPTextItem( static_cast<const PCB_TEXT&>( *item ) );
953 }
954 else
955 {
956 // add shapes with their exact mask layer size in initialPolys
957 item->TransformShapeToPolygon( initialPolys, layer, 0, maxError,
959
960 // add shapes inflated by aMinThickness/2 in areas
961 item->TransformShapeToPolygon( areas, layer, inflate, maxError,
963 }
964 }
965 }
966 }
967
968 // Plot (untented) vias
969 for( const PCB_TRACK* track : aBoard->Tracks() )
970 {
971 if( track->Type() != PCB_VIA_T )
972 continue;
973
974 const PCB_VIA* via = static_cast<const PCB_VIA*>( track );
975
976 // Note: IsOnLayer() checks relevant mask layers of untented vias
977 if( !via->IsOnLayer( layer ) )
978 continue;
979
980 int clearance = via->GetSolderMaskExpansion();
981
982 // add shapes with their exact mask layer size in initialPolys
983 via->TransformShapeToPolygon( initialPolys, layer, clearance, maxError, ERROR_OUTSIDE );
984
985 // add shapes inflated by aMinThickness/2 in areas
986 clearance += inflate;
987 via->TransformShapeToPolygon( areas, layer, clearance, maxError, ERROR_OUTSIDE );
988 }
989
990 // Add filled zone areas.
991#if 0 // Set to 1 if a solder mask expansion must be applied to zones on solder mask
992 int zone_margin = aBoard->GetDesignSettings().m_SolderMaskExpansion;
993#else
994 int zone_margin = 0;
995#endif
996
997 for( const BOARD_ITEM* item : aBoard->Drawings() )
998 {
999 if( item->IsOnLayer( layer ) )
1000 {
1001 if( item->Type() == PCB_TEXT_T )
1002 {
1003 const PCB_TEXT* text = static_cast<const PCB_TEXT*>( item );
1004
1005 // add shapes with their exact mask layer size in initialPolys
1006 text->TransformTextToPolySet( initialPolys, 0, maxError, ERROR_OUTSIDE );
1007
1008 // add shapes inflated by aMinThickness/2 in areas
1009 text->TransformTextToPolySet( areas, inflate, maxError, ERROR_OUTSIDE );
1010 }
1011 else
1012 {
1013 // add shapes with their exact mask layer size in initialPolys
1014 item->TransformShapeToPolygon( initialPolys, layer, 0, maxError,
1015 ERROR_OUTSIDE );
1016
1017 // add shapes inflated by aMinThickness/2 in areas
1018 item->TransformShapeToPolygon( areas, layer, inflate, maxError, ERROR_OUTSIDE );
1019 }
1020 }
1021 }
1022
1023 for( ZONE* zone : aBoard->Zones() )
1024 {
1025 if( zone->GetIsRuleArea() )
1026 continue;
1027
1028 if( !zone->IsOnLayer( layer ) )
1029 continue;
1030
1031 // add shapes inflated by aMinThickness/2 in areas
1032 zone->TransformSmoothedOutlineToPolygon( areas, inflate + zone_margin, maxError,
1033 ERROR_OUTSIDE, boardOutline );
1034
1035 // add shapes with their exact mask layer size in initialPolys
1036 zone->TransformSmoothedOutlineToPolygon( initialPolys, zone_margin, maxError,
1037 ERROR_OUTSIDE, boardOutline );
1038 }
1039 }
1040
1041 // Merge all polygons: After deflating, not merged (not overlapping) polygons will have the
1042 // initial shape (with perhaps small changes due to deflating transform)
1044 areas.Deflate( inflate, CORNER_STRATEGY::CHAMFER_ALL_CORNERS, maxError );
1045
1046 // To avoid a lot of code, use a ZONE to handle and plot polygons, because our polygons look
1047 // exactly like filled areas in zones.
1048 // Note, also this code is not optimized: it creates a lot of copy/duplicate data.
1049 // However it is not complex, and fast enough for plot purposes (copy/convert data is only a
1050 // very small calculation time for these calculations).
1051 ZONE zone( aBoard );
1052 zone.SetMinThickness( 0 ); // trace polygons only
1053 zone.SetLayer( layer );
1054
1055 // Combine the current areas to initial areas. This is mandatory because inflate/deflate
1056 // transform is not perfect, and we want the initial areas perfectly kept
1057 areas.BooleanAdd( initialPolys, SHAPE_POLY_SET::PM_FAST );
1059
1060 itemplotter.PlotZone( &zone, layer, areas );
1061}
1062
1063
1070static void initializePlotter( PLOTTER* aPlotter, const BOARD* aBoard,
1071 const PCB_PLOT_PARAMS* aPlotOpts )
1072{
1073 PAGE_INFO pageA4( wxT( "A4" ) );
1074 const PAGE_INFO& pageInfo = aBoard->GetPageSettings();
1075 const PAGE_INFO* sheet_info;
1076 double paperscale; // Page-to-paper ratio
1077 VECTOR2I paperSizeIU;
1078 VECTOR2I pageSizeIU( pageInfo.GetSizeIU( pcbIUScale.IU_PER_MILS ) );
1079 bool autocenter = false;
1080
1081 // Special options: to fit the sheet to an A4 sheet replace the paper size. However there
1082 // is a difference between the autoscale and the a4paper option:
1083 // - Autoscale fits the board to the paper size
1084 // - A4paper fits the original paper size to an A4 sheet
1085 // - Both of them fit the board to an A4 sheet
1086 if( aPlotOpts->GetA4Output() )
1087 {
1088 sheet_info = &pageA4;
1089 paperSizeIU = pageA4.GetSizeIU( pcbIUScale.IU_PER_MILS );
1090 paperscale = (double) paperSizeIU.x / pageSizeIU.x;
1091 autocenter = true;
1092 }
1093 else
1094 {
1095 sheet_info = &pageInfo;
1096 paperSizeIU = pageSizeIU;
1097 paperscale = 1;
1098
1099 // Need autocentering only if scale is not 1:1
1100 autocenter = (aPlotOpts->GetScale() != 1.0);
1101 }
1102
1103 BOX2I bbox = aBoard->ComputeBoundingBox( false );
1104 VECTOR2I boardCenter = bbox.Centre();
1105 VECTOR2I boardSize = bbox.GetSize();
1106
1107 double compound_scale;
1108
1109 // Fit to 80% of the page if asked; it could be that the board is empty, in this case
1110 // regress to 1:1 scale
1111 if( aPlotOpts->GetAutoScale() && boardSize.x > 0 && boardSize.y > 0 )
1112 {
1113 double xscale = (paperSizeIU.x * 0.8) / boardSize.x;
1114 double yscale = (paperSizeIU.y * 0.8) / boardSize.y;
1115
1116 compound_scale = std::min( xscale, yscale ) * paperscale;
1117 }
1118 else
1119 {
1120 compound_scale = aPlotOpts->GetScale() * paperscale;
1121 }
1122
1123 // For the plot offset we have to keep in mind the auxiliary origin too: if autoscaling is
1124 // off we check that plot option (i.e. autoscaling overrides auxiliary origin)
1125 VECTOR2I offset( 0, 0);
1126
1127 if( autocenter )
1128 {
1129 offset.x = KiROUND( boardCenter.x - ( paperSizeIU.x / 2.0 ) / compound_scale );
1130 offset.y = KiROUND( boardCenter.y - ( paperSizeIU.y / 2.0 ) / compound_scale );
1131 }
1132 else
1133 {
1134 if( aPlotOpts->GetUseAuxOrigin() )
1135 offset = aBoard->GetDesignSettings().GetAuxOrigin();
1136 }
1137
1138 aPlotter->SetPageSettings( *sheet_info );
1139
1140 aPlotter->SetViewport( offset, pcbIUScale.IU_PER_MILS/10, compound_scale, aPlotOpts->GetMirror() );
1141
1142 // Has meaning only for gerber plotter. Must be called only after SetViewport
1143 aPlotter->SetGerberCoordinatesFormat( aPlotOpts->GetGerberPrecision() );
1144
1145 // Has meaning only for SVG plotter. Must be called only after SetViewport
1146 aPlotter->SetSvgCoordinatesFormat( aPlotOpts->GetSvgPrecision() );
1147
1148 aPlotter->SetCreator( wxT( "PCBNEW" ) );
1149 aPlotter->SetColorMode( !aPlotOpts->GetBlackAndWhite() ); // default is plot in Black and White.
1150 aPlotter->SetTextMode( aPlotOpts->GetTextMode() );
1151}
1152
1153
1157static void FillNegativeKnockout( PLOTTER *aPlotter, const BOX2I &aBbbox )
1158{
1159 const int margin = 5 * pcbIUScale.IU_PER_MM; // Add a 5 mm margin around the board
1160 aPlotter->SetNegative( true );
1161 aPlotter->SetColor( WHITE ); // Which will be plotted as black
1162
1163 BOX2I area = aBbbox;
1164 area.Inflate( margin );
1165 aPlotter->Rect( area.GetOrigin(), area.GetEnd(), FILL_T::FILLED_SHAPE );
1166 aPlotter->SetColor( BLACK );
1167}
1168
1169
1173static void ConfigureHPGLPenSizes( HPGL_PLOTTER *aPlotter, const PCB_PLOT_PARAMS *aPlotOpts )
1174{
1175 // Compute penDiam (the value is given in mils) in pcb units, with plot scale (if Scale is 2,
1176 // penDiam value is always m_HPGLPenDiam so apparent penDiam is actually penDiam / Scale
1177 int penDiam = KiROUND( aPlotOpts->GetHPGLPenDiameter() * pcbIUScale.IU_PER_MILS / aPlotOpts->GetScale() );
1178
1179 // Set HPGL-specific options and start
1180 aPlotter->SetPenSpeed( aPlotOpts->GetHPGLPenSpeed() );
1181 aPlotter->SetPenNumber( aPlotOpts->GetHPGLPenNum() );
1182 aPlotter->SetPenDiameter( penDiam );
1183}
1184
1185
1192PLOTTER* StartPlotBoard( BOARD *aBoard, const PCB_PLOT_PARAMS *aPlotOpts, int aLayer,
1193 const wxString& aLayerName, const wxString& aFullFileName,
1194 const wxString& aSheetName, const wxString& aSheetPath )
1195{
1196 // Create the plotter driver and set the few plotter specific options
1197 PLOTTER* plotter = nullptr;
1198
1199 switch( aPlotOpts->GetFormat() )
1200 {
1201 case PLOT_FORMAT::DXF:
1202 DXF_PLOTTER* DXF_plotter;
1203 DXF_plotter = new DXF_PLOTTER();
1204 DXF_plotter->SetUnits( aPlotOpts->GetDXFPlotUnits() );
1205
1206 plotter = DXF_plotter;
1207 break;
1208
1209 case PLOT_FORMAT::POST:
1210 PS_PLOTTER* PS_plotter;
1211 PS_plotter = new PS_PLOTTER();
1212 PS_plotter->SetScaleAdjust( aPlotOpts->GetFineScaleAdjustX(),
1213 aPlotOpts->GetFineScaleAdjustY() );
1214 plotter = PS_plotter;
1215 break;
1216
1217 case PLOT_FORMAT::PDF:
1218 plotter = new PDF_PLOTTER();
1219 break;
1220
1221 case PLOT_FORMAT::HPGL:
1222 HPGL_PLOTTER* HPGL_plotter;
1223 HPGL_plotter = new HPGL_PLOTTER();
1224
1225 // HPGL options are a little more convoluted to compute, so they get their own function
1226 ConfigureHPGLPenSizes( HPGL_plotter, aPlotOpts );
1227 plotter = HPGL_plotter;
1228 break;
1229
1231 // For Gerber plotter, a valid board layer must be set, in order to create a valid
1232 // Gerber header, especially the TF.FileFunction and .FilePolarity data
1233 if( aLayer < PCBNEW_LAYER_ID_START || aLayer >= PCB_LAYER_ID_COUNT )
1234 {
1235 wxLogError( wxString::Format(
1236 "Invalid board layer %d, cannot build a valid Gerber file header",
1237 aLayer ) );
1238 }
1239
1240 plotter = new GERBER_PLOTTER();
1241 break;
1242
1243 case PLOT_FORMAT::SVG:
1244 plotter = new SVG_PLOTTER();
1245 break;
1246
1247 default:
1248 wxASSERT( false );
1249 return nullptr;
1250 }
1251
1253 renderSettings->LoadColors( aPlotOpts->ColorSettings() );
1254 renderSettings->SetDefaultPenWidth( pcbIUScale.mmToIU( 0.0212 ) ); // Hairline at 1200dpi
1255 renderSettings->SetLayerName( aLayerName );
1256
1257 plotter->SetRenderSettings( renderSettings );
1258
1259 // Compute the viewport and set the other options
1260
1261 // page layout is not mirrored, so temporarily change mirror option for the page layout
1262 PCB_PLOT_PARAMS plotOpts = *aPlotOpts;
1263
1264 if( plotOpts.GetPlotFrameRef() && plotOpts.GetMirror() )
1265 plotOpts.SetMirror( false );
1266
1267 initializePlotter( plotter, aBoard, &plotOpts );
1268
1269 if( plotter->OpenFile( aFullFileName ) )
1270 {
1271 plotter->ClearHeaderLinesList();
1272
1273 // For the Gerber "file function" attribute, set the layer number
1274 if( plotter->GetPlotterType() == PLOT_FORMAT::GERBER )
1275 {
1276 bool useX2mode = plotOpts.GetUseGerberX2format();
1277
1278 GERBER_PLOTTER* gbrplotter = static_cast <GERBER_PLOTTER*> ( plotter );
1279 gbrplotter->DisableApertMacros( plotOpts.GetDisableGerberMacros() );
1280 gbrplotter->UseX2format( useX2mode );
1281 gbrplotter->UseX2NetAttributes( plotOpts.GetIncludeGerberNetlistInfo() );
1282
1283 // Attributes can be added using X2 format or as comment (X1 format)
1284 AddGerberX2Attribute( plotter, aBoard, aLayer, not useX2mode );
1285 }
1286
1287 if( plotter->StartPlot( wxT( "1" ) ) )
1288 {
1289 // Plot the frame reference if requested
1290 if( aPlotOpts->GetPlotFrameRef() )
1291 {
1292 PlotDrawingSheet( plotter, aBoard->GetProject(), aBoard->GetTitleBlock(),
1293 aBoard->GetPageSettings(), &aBoard->GetProperties(), wxT( "1" ),
1294 1, aSheetName, aSheetPath, aBoard->GetFileName(),
1295 renderSettings->GetLayerColor( LAYER_DRAWINGSHEET ) );
1296
1297 if( aPlotOpts->GetMirror() )
1298 initializePlotter( plotter, aBoard, aPlotOpts );
1299 }
1300
1301 // When plotting a negative board: draw a black rectangle (background for plot board
1302 // in white) and switch the current color to WHITE; note the color inversion is actually
1303 // done in the driver (if supported)
1304 if( aPlotOpts->GetNegative() )
1305 {
1306 BOX2I bbox = aBoard->ComputeBoundingBox( false );
1307 FillNegativeKnockout( plotter, bbox );
1308 }
1309
1310 return plotter;
1311 }
1312 }
1313
1314 delete plotter->RenderSettings();
1315 delete plotter;
1316 return nullptr;
1317}
int color
Definition: DXF_plotter.cpp:58
@ ERROR_OUTSIDE
Definition: approximation.h:33
@ ERROR_INSIDE
Definition: approximation.h:34
constexpr EDA_IU_SCALE pcbIUScale
Definition: base_units.h:108
@ LAYER_CLASS_FAB
constexpr BOX2I KiROUND(const BOX2D &aBoxD)
Definition: box2.h:990
static const ADVANCED_CFG & GetCfg()
Get the singleton instance's config, which is shared by all consumers.
const VECTOR2I & GetAuxOrigin()
int m_LineThickness[LAYER_CLASS_COUNT]
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition: board_item.h:80
Information pertinent to a Pcbnew printed circuit board.
Definition: board.h:290
bool GetBoardPolygonOutlines(SHAPE_POLY_SET &aOutlines, OUTLINE_ERROR_HANDLER *aErrorHandler=nullptr, bool aAllowUseArcsInPolygons=false, bool aIncludeNPTHAsOutlines=false)
Extract the board outlines and build a closed polygon from lines, arcs and circle items on edge cut l...
Definition: board.cpp:2491
const PAGE_INFO & GetPageSettings() const
Definition: board.h:689
const ZONES & Zones() const
Definition: board.h:335
void ConvertBrdLayerToPolygonalContours(PCB_LAYER_ID aLayer, SHAPE_POLY_SET &aOutlines) const
Build a set of polygons which are the outlines of copper items (pads, tracks, vias,...
Definition: board.cpp:2919
TITLE_BLOCK & GetTitleBlock()
Definition: board.h:695
BOX2I ComputeBoundingBox(bool aBoardEdgesOnly=false) const
Calculate the bounding box containing all board items (or board edge segments).
Definition: board.cpp:1668
const std::map< wxString, wxString > & GetProperties() const
Definition: board.h:362
const FOOTPRINTS & Footprints() const
Definition: board.h:331
const TRACKS & Tracks() const
Definition: board.h:329
const wxString & GetFileName() const
Definition: board.h:327
PROJECT * GetProject() const
Definition: board.h:491
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Definition: board.cpp:890
const DRAWINGS & Drawings() const
Definition: board.h:333
constexpr BOX2< Vec > & Inflate(coord_type dx, coord_type dy)
Inflates the rectangle horizontally by dx and vertically by dy.
Definition: box2.h:558
constexpr const Vec GetEnd() const
Definition: box2.h:212
constexpr size_type GetWidth() const
Definition: box2.h:214
constexpr Vec Centre() const
Definition: box2.h:97
constexpr size_type GetHeight() const
Definition: box2.h:215
constexpr coord_type GetLeft() const
Definition: box2.h:228
constexpr void Move(const Vec &aMoveVector)
Move the rectangle by the aMoveVector.
Definition: box2.h:138
constexpr const Vec & GetOrigin() const
Definition: box2.h:210
constexpr coord_type GetRight() const
Definition: box2.h:217
constexpr const SizeVec & GetSize() const
Definition: box2.h:206
constexpr coord_type GetTop() const
Definition: box2.h:229
constexpr coord_type GetBottom() const
Definition: box2.h:222
void PlotDrillMarks()
Draw a drill mark for pads and vias.
void PlotZone(const ZONE *aZone, PCB_LAYER_ID aLayer, const SHAPE_POLY_SET &aPolysList)
void PlotPadNumber(const PAD *aPad, const COLOR4D &aColor)
void PlotBoardGraphicItem(const BOARD_ITEM *item)
Plot items like text and graphics but not tracks and footprints.
void SetLayerSet(LSET aLayerMask)
Definition: pcbplot.h:86
void PlotPad(const PAD *aPad, PCB_LAYER_ID aLayer, const COLOR4D &aColor, OUTLINE_MODE aPlotMode)
Plot a pad.
COLOR4D getColor(int aLayer) const
White color is special because it cannot be seen on a white paper in B&W mode.
void PlotFootprintTextItems(const FOOTPRINT *aFootprint)
int getFineWidthAdj() const
Definition: pcbplot.h:77
void PlotFootprintGraphicItems(const FOOTPRINT *aFootprint)
COLOR4D GetColor(int aLayer) const
When creating polygons to create a clearance polygonal area, the polygon must be same or bigger than ...
void SetUnits(DXF_UNITS aUnit)
Set the units to use for plotting the DXF file.
virtual const wxString & GetText() const
Return the string associated with the text object.
Definition: eda_text.h:94
@ GBR_APERTURE_ATTRIB_VIAPAD
aperture used for vias.
Definition: gbr_metadata.h:102
@ GBR_APERTURE_ATTRIB_NONE
uninitialized attribute.
Definition: gbr_metadata.h:93
Metadata which can be added in a gerber file as attribute in X2 format.
Definition: gbr_metadata.h:205
void SetNetName(const wxString &aNetname)
Definition: gbr_metadata.h:229
void SetApertureAttrib(GBR_APERTURE_METADATA::GBR_APERTURE_ATTRIB aApertAttribute)
Definition: gbr_metadata.h:209
GBR_NETLIST_METADATA m_NetlistMetadata
An item to handle object attribute.
Definition: gbr_metadata.h:262
void SetNetAttribType(int aNetAttribType)
Definition: gbr_metadata.h:219
@ GBR_NETINFO_NET
print info associated to a net (TO.N attribute)
@ GBR_NETINFO_UNSPECIFIED
idle command (no command)
bool m_NotInNet
true if a pad of a footprint cannot be connected (for instance a mechanical NPTH, ot a not named pad)...
void UseX2format(bool aEnable)
void UseX2NetAttributes(bool aEnable)
void DisableApertMacros(bool aDisable)
Disable Aperture Macro (AM) command, only for broken Gerber Readers.
virtual void SetPenSpeed(int speed)
Definition: plotter_hpgl.h:88
virtual void SetPenNumber(int number)
Definition: plotter_hpgl.h:93
virtual void SetPenDiameter(double diameter)
A color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:104
static const COLOR4D BLACK
Definition: color4d.h:402
PCB specific render settings.
Definition: pcb_painter.h:78
void LoadColors(const COLOR_SETTINGS *aSettings) override
void SetDefaultPenWidth(int aWidth)
const COLOR4D & GetLayerColor(int aLayer) const
Return the color used to draw a layer.
void SetLayerName(const wxString &aLayerName)
LSEQ is a sequence (and therefore also a set) of PCB_LAYER_IDs.
Definition: lseq.h:47
LSET is a set of PCB_LAYER_IDs.
Definition: lset.h:36
LSEQ SeqStackupForPlotting() const
Return the sequence that is typical for a bottom-to-top stack-up.
Definition: lset.cpp:500
static LSET AllCuMask(int aCuLayerCount=MAX_CU_LAYERS)
Return a mask holding the requested number of Cu PCB_LAYER_IDs.
Definition: lset.cpp:676
LSEQ Seq(const LSEQ &aSequence) const
Return an LSEQ from the union of this LSET and a desired sequence.
Definition: lset.cpp:410
Handle the data for a net.
Definition: netinfo.h:56
static constexpr PCB_LAYER_ID ALL_LAYERS
! Temporary layer identifier to identify code that is not padstack-aware
Definition: padstack.h:138
Definition: pad.h:54
Describe the page size and margins of a paper page on which to eventually print or plot.
Definition: page_info.h:59
const VECTOR2D GetSizeIU(double aIUScale) const
Gets the page size in internal units.
Definition: page_info.h:171
bool IsDegenerated(int aThreshold=5) const
Definition: pcb_track.cpp:1840
EDA_ANGLE GetArcAngleStart() const
Definition: pcb_track.cpp:1822
double GetRadius() const
Definition: pcb_track.cpp:1805
EDA_ANGLE GetAngle() const
Definition: pcb_track.cpp:1812
virtual VECTOR2I GetCenter() const override
This defaults to the center of the bounding box if not overridden.
Definition: pcb_track.h:304
bool IsReference() const
Definition: pcb_field.h:70
wxString GetName(bool aUseDefaultName=true) const
Return the field name (not translated).
Definition: pcb_field.cpp:92
bool IsValue() const
Definition: pcb_field.h:71
bool IsFootprint() const
Definition: pcb_field.h:72
Parameters and options when plotting/printing a board.
bool GetNegative() const
PLOT_FORMAT GetFormat() const
bool GetSkipPlotNPTH_Pads() const
void SetDrillMarksType(DRILL_MARKS aVal)
bool GetUseAuxOrigin() const
bool GetHideDNPFPsOnFabLayers() const
void SetSkipPlotNPTH_Pads(bool aSkip)
bool GetMirror() const
DXF_UNITS GetDXFPlotUnits() const
bool GetAutoScale() const
bool GetPlotInvisibleText() const
PLOT_TEXT_MODE GetTextMode() const
bool GetCrossoutDNPFPsOnFabLayers() const
void SetDXFPlotPolygonMode(bool aFlag)
double GetHPGLPenDiameter() const
unsigned GetSvgPrecision() const
unsigned GetBlackAndWhite() const
double GetScale() const
bool GetPlotReference() const
bool m_PDFFrontFPPropertyPopups
Generate PDF property popup menus for footprints.
void SetMirror(bool aFlag)
bool GetSketchPadsOnFabLayers() const
bool GetSubtractMaskFromSilk() const
int GetGerberPrecision() const
int GetHPGLPenSpeed() const
double GetFineScaleAdjustY() const
bool GetPlotPadNumbers() const
bool GetA4Output() const
int GetHPGLPenNum() const
DRILL_MARKS GetDrillMarksType() const
bool GetUseGerberX2format() const
bool GetPlotValue() const
bool GetIncludeGerberNetlistInfo() const
double GetFineScaleAdjustX() const
bool m_PDFBackFPPropertyPopups
on front and/or back of board
bool GetPlotFPText() const
bool GetPlotFrameRef() const
bool GetDisableGerberMacros() const
OUTLINE_MODE GetPlotMode() const
COLOR_SETTINGS * ColorSettings() const
Base plotter engine class.
Definition: plotter.h:105
virtual void ThickArc(const EDA_SHAPE &aArcShape, OUTLINE_MODE aTraceMode, void *aData, int aWidth)
Definition: plotter.cpp:596
virtual void ThickSegment(const VECTOR2I &start, const VECTOR2I &end, int width, OUTLINE_MODE tracemode, void *aData)
Definition: plotter.cpp:553
virtual void Circle(const VECTOR2I &pos, int diametre, FILL_T fill, int width=USE_DEFAULT_LINE_WIDTH)=0
virtual bool OpenFile(const wxString &aFullFilename)
Open or create the plot file aFullFilename.
Definition: plotter.cpp:74
virtual void SetNegative(bool aNegative)
Definition: plotter.h:125
virtual void SetSvgCoordinatesFormat(unsigned aPrecision)
Set the number of digits for mantissa in coordinates in mm for SVG plotter.
Definition: plotter.h:525
virtual void SetPageSettings(const PAGE_INFO &aPageSettings)
Definition: plotter.h:138
void SetRenderSettings(RENDER_SETTINGS *aSettings)
Definition: plotter.h:135
virtual bool StartPlot(const wxString &aPageNumber)=0
RENDER_SETTINGS * RenderSettings()
Definition: plotter.h:136
virtual void SetGerberCoordinatesFormat(int aResolution, bool aUseInches=false)
Definition: plotter.h:519
virtual void Bookmark(const BOX2I &aBox, const wxString &aName, const wxString &aGroupName=wxEmptyString)
Create a bookmark to a symbol.
Definition: plotter.h:476
virtual PLOT_FORMAT GetPlotterType() const =0
Returns the effective plot engine in use.
virtual void SetTextMode(PLOT_TEXT_MODE mode)
Change the current text mode.
Definition: plotter.h:514
virtual void SetCreator(const wxString &aCreator)
Definition: plotter.h:154
VECTOR2I GetPlotOffsetUserUnits()
Definition: plotter.h:552
void ClearHeaderLinesList()
Remove all lines from the list of free lines to print at the beginning of the file.
Definition: plotter.h:172
virtual void FlashPadCircle(const VECTOR2I &aPadPos, int aDiameter, OUTLINE_MODE aTraceMode, void *aData)=0
virtual void SetViewport(const VECTOR2I &aOffset, double aIusPerDecimil, double aScale, bool aMirror)=0
Set the plot offset and scaling for the current plot.
virtual void SetColorMode(bool aColorMode)
Plot in B/W or color.
Definition: plotter.h:132
virtual void StartBlock(void *aData)
calling this function allows one to define the beginning of a group of drawing items,...
Definition: plotter.h:537
virtual void PlotPoly(const std::vector< VECTOR2I > &aCornerList, FILL_T aFill, int aWidth=USE_DEFAULT_LINE_WIDTH, void *aData=nullptr)=0
Draw a polygon ( filled or not ).
virtual void HyperlinkMenu(const BOX2I &aBox, const std::vector< wxString > &aDestURLs)
Create a clickable hyperlink menu with a rectangular click area.
Definition: plotter.h:465
virtual void SetLayerPolarity(bool aPositive)
Set the current Gerber layer polarity to positive or negative by writing %LPD*% or %LPC*% to the Gerb...
Definition: plotter.h:505
virtual void Rect(const VECTOR2I &p1, const VECTOR2I &p2, FILL_T fill, int width=USE_DEFAULT_LINE_WIDTH)=0
virtual void SetColor(const COLOR4D &color)=0
virtual void EndBlock(void *aData)
calling this function allows one to define the end of a group of drawing items for instance in SVG or...
Definition: plotter.h:546
void SetScaleAdjust(double scaleX, double scaleY)
Set the 'fine' scaling for the postscript engine.
Represent a polyline containing arcs as well as line segments: A chain of connected line and/or arc s...
Represent a set of closed polygons.
void RemoveAllContours()
Remove all outlines & holes (clears) the polygon set.
void InflateWithLinkedHoles(int aFactor, CORNER_STRATEGY aCornerStrategy, int aMaxError, POLYGON_MODE aFastMode)
Perform outline inflation/deflation, using round corners.
void Fracture(POLYGON_MODE aFastMode)
Convert a set of polygons with holes to a single outline with "slits"/"fractures" connecting the oute...
int AddOutline(const SHAPE_LINE_CHAIN &aOutline)
Adds a new outline to the set and returns its index.
void DeletePolygon(int aIdx)
Delete aIdx-th polygon from the set.
bool IsEmpty() const
Return true if the set is empty (no polygons at all)
void BooleanAdd(const SHAPE_POLY_SET &b, POLYGON_MODE aFastMode)
Perform boolean polyset union For aFastMode meaning, see function booleanOp.
int HoleCount(int aOutline) const
Returns the number of holes in a given outline.
int Append(int x, int y, int aOutline=-1, int aHole=-1, bool aAllowDuplication=false)
Appends a vertex at the end of the given outline/hole (default: the last outline)
void Simplify(POLYGON_MODE aFastMode)
Simplify the polyset (merges overlapping polys, eliminates degeneracy/self-intersections) For aFastMo...
int NewOutline()
Creates a new empty polygon in the set and returns its index.
void Deflate(int aAmount, CORNER_STRATEGY aCornerStrategy, int aMaxError)
const SHAPE_LINE_CHAIN & CHole(int aOutline, int aHole) const
int OutlineCount() const
Return the number of outlines in the set.
SHAPE_POLY_SET CloneDropTriangulation() const
const POLYGON & CPolygon(int aIndex) const
const SHAPE_LINE_CHAIN & COutline(int aIndex) const
Handle a list of polygons defining a copper zone.
Definition: zone.h:73
void SetMinThickness(int aMinThickness)
Definition: zone.h:271
virtual void SetLayer(PCB_LAYER_ID aLayer) override
Set the layer this item is on.
Definition: zone.cpp:298
@ WHITE
Definition: color4d.h:48
@ LIGHTGRAY
Definition: color4d.h:47
@ BLACK
Definition: color4d.h:44
void PlotDrawingSheet(PLOTTER *plotter, const PROJECT *aProject, const TITLE_BLOCK &aTitleBlock, const PAGE_INFO &aPageInfo, const std::map< wxString, wxString > *aProperties, const wxString &aSheetNumber, int aSheetCount, const wxString &aSheetName, const wxString &aSheetPath, const wxString &aFilename, COLOR4D aColor, bool aIsFirstPage)
@ CHAMFER_ALL_CORNERS
All angles are chamfered.
@ ROUND_ALL_CORNERS
All angles are rounded.
#define _(s)
static constexpr EDA_ANGLE ANGLE_0
Definition: eda_angle.h:401
@ FILLED_SHAPE
Handle special data (items attributes) during plot.
a few functions useful in geometry calculations.
static const bool FILLED
Definition: gr_basic.cpp:30
double m_SmallDrillMarkSize
The diameter of the drill marks on print and plot outputs (in mm) when the "Drill marks" option is se...
bool IsCopperLayer(int aLayerId)
Tests whether a layer is a copper layer.
Definition: layer_ids.h:530
@ LAYER_DRAWINGSHEET
drawingsheet frame and titleblock
Definition: layer_ids.h:219
@ LAYER_VIAS
Meta control for all vias opacity/visibility.
Definition: layer_ids.h:195
PCB_LAYER_ID
A quick note on layer IDs:
Definition: layer_ids.h:60
@ F_CrtYd
Definition: layer_ids.h:116
@ B_Adhes
Definition: layer_ids.h:103
@ Edge_Cuts
Definition: layer_ids.h:112
@ Dwgs_User
Definition: layer_ids.h:107
@ F_Paste
Definition: layer_ids.h:104
@ Cmts_User
Definition: layer_ids.h:108
@ F_Adhes
Definition: layer_ids.h:102
@ B_Mask
Definition: layer_ids.h:98
@ B_Cu
Definition: layer_ids.h:65
@ Eco1_User
Definition: layer_ids.h:109
@ F_Mask
Definition: layer_ids.h:97
@ B_Paste
Definition: layer_ids.h:105
@ F_Fab
Definition: layer_ids.h:119
@ Margin
Definition: layer_ids.h:113
@ F_SilkS
Definition: layer_ids.h:100
@ B_CrtYd
Definition: layer_ids.h:115
@ UNDEFINED_LAYER
Definition: layer_ids.h:61
@ Eco2_User
Definition: layer_ids.h:110
@ B_SilkS
Definition: layer_ids.h:101
@ PCB_LAYER_ID_COUNT
Definition: layer_ids.h:135
@ F_Cu
Definition: layer_ids.h:64
@ B_Fab
Definition: layer_ids.h:118
OUTLINE_MODE
Definition: outline_mode.h:25
@ SKETCH
Definition: outline_mode.h:26
@ NPTH
like PAD_PTH, but not plated mechanical use only, no connection allowed
PAD_SHAPE
The set of pad shapes, used with PAD::{Set,Get}Shape()
Definition: padstack.h:46
void AddGerberX2Attribute(PLOTTER *aPlotter, const BOARD *aBoard, int aLayer, bool aUseX1CompatibilityMode)
Calculate some X2 attributes as defined in the Gerber file format specification and add them to the g...
Definition: pcbplot.cpp:354
static void FillNegativeKnockout(PLOTTER *aPlotter, const BOX2I &aBbbox)
Prefill in black an area a little bigger than the board to prepare for the negative plot.
void PlotBoardLayers(BOARD *aBoard, PLOTTER *aPlotter, const LSEQ &aLayers, const PCB_PLOT_PARAMS &aPlotOptions)
Plot a sequence of board layer IDs.
void PlotStandardLayer(BOARD *aBoard, PLOTTER *aPlotter, LSET aLayerMask, const PCB_PLOT_PARAMS &aPlotOpt)
Plot any layer EXCEPT a solder-mask with an enforced minimum width.
static void PlotSolderMaskLayer(BOARD *aBoard, PLOTTER *aPlotter, LSET aLayerMask, const PCB_PLOT_PARAMS &aPlotOpt, int aMinThickness)
Plot a solder mask layer.
void PlotOneBoardLayer(BOARD *aBoard, PLOTTER *aPlotter, PCB_LAYER_ID aLayer, const PCB_PLOT_PARAMS &aPlotOpt)
Plot one copper or technical layer.
void PlotLayerOutlines(BOARD *aBoard, PLOTTER *aPlotter, LSET aLayerMask, const PCB_PLOT_PARAMS &aPlotOpt)
Plot outlines.
static void ConfigureHPGLPenSizes(HPGL_PLOTTER *aPlotter, const PCB_PLOT_PARAMS *aPlotOpts)
Calculate the effective size of HPGL pens and set them in the plotter object.
static void initializePlotter(PLOTTER *aPlotter, const BOARD *aBoard, const PCB_PLOT_PARAMS *aPlotOpts)
Set up most plot options for plotting a board (especially the viewport) Important thing: page size is...
void PlotInteractiveLayer(BOARD *aBoard, PLOTTER *aPlotter, const PCB_PLOT_PARAMS &aPlotOpt)
Plot interactive items (hypertext links, properties, etc.).
PLOTTER * StartPlotBoard(BOARD *aBoard, const PCB_PLOT_PARAMS *aPlotOpts, int aLayer, const wxString &aLayerName, const wxString &aFullFileName, const wxString &aSheetName, const wxString &aSheetPath)
Open a new plotfile using the options (and especially the format) specified in the options and prepar...
Plotting engine (HPGL)
Plotting engines similar to ps (PostScript, Gerber, svg)
std::vector< FAB_LAYER_COLOR > dummy
const double IU_PER_MM
Definition: base_units.h:76
const double IU_PER_MILS
Definition: base_units.h:77
constexpr int mmToIU(double mm) const
Definition: base_units.h:88
@ PCB_VIA_T
class PCB_VIA, a via (like a track segment on a copper layer)
Definition: typeinfo.h:97
@ PCB_TEXT_T
class PCB_TEXT, text on a layer
Definition: typeinfo.h:92
@ PCB_ARC_T
class PCB_ARC, an arc track segment on a copper layer
Definition: typeinfo.h:98
VECTOR2< int32_t > VECTOR2I
Definition: vector2d.h:691