KiCad PCB EDA Suite
plot_board_layers.cpp
Go to the documentation of this file.
1 
8 /*
9  * This program source code file is part of KiCad, a free EDA CAD application.
10  *
11  * Copyright (C) 1992-2021 KiCad Developers, see AUTHORS.txt for contributors.
12  *
13  * This program is free software; you can redistribute it and/or
14  * modify it under the terms of the GNU General Public License
15  * as published by the Free Software Foundation; either version 2
16  * of the License, or (at your option) any later version.
17  *
18  * This program is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21  * GNU General Public License for more details.
22  *
23  * You should have received a copy of the GNU General Public License
24  * along with this program; if not, you may find one here:
25  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
26  * or you may search the http://www.gnu.org website for the version 2 license,
27  * or you may write to the Free Software Foundation, Inc.,
28  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
29  */
30 
31 
32 #include <eda_item.h>
34 #include <geometry/shape_segment.h>
35 #include <pcb_base_frame.h>
36 #include <math/util.h> // for KiROUND
37 
38 #include <board.h>
39 #include <board_design_settings.h>
40 #include <core/arraydim.h>
41 #include <footprint.h>
42 #include <pcb_track.h>
43 #include <fp_shape.h>
44 #include <pad.h>
45 #include <pcb_text.h>
46 #include <zone.h>
47 #include <pcb_shape.h>
48 #include <pcb_target.h>
49 #include <pcb_dimension.h>
50 
51 #include <pcbplot.h>
52 #include <plotters/plotter_dxf.h>
53 #include <plotters/plotter_hpgl.h>
56 #include <pcb_painter.h>
57 #include <gbr_metadata.h>
58 #include <advanced_config.h>
59 
60 /*
61  * Plot a solder mask layer. Solder mask layers have a minimum thickness value and cannot be
62  * drawn like standard layers, unless the minimum thickness is 0.
63  */
64 static void PlotSolderMaskLayer( BOARD *aBoard, PLOTTER* aPlotter, LSET aLayerMask,
65  const PCB_PLOT_PARAMS& aPlotOpt, int aMinThickness );
66 
67 
68 void PlotOneBoardLayer( BOARD *aBoard, PLOTTER* aPlotter, PCB_LAYER_ID aLayer,
69  const PCB_PLOT_PARAMS& aPlotOpt )
70 {
71  PCB_PLOT_PARAMS plotOpt = aPlotOpt;
72  int soldermask_min_thickness = aBoard->GetDesignSettings().m_SolderMaskMinWidth;
73 
74  // Set a default color and the text mode for this layer
75  aPlotter->SetColor( BLACK );
76  aPlotter->SetTextMode( aPlotOpt.GetTextMode() );
77 
78  // Specify that the contents of the "Edges Pcb" layer are to be plotted in addition to the
79  // contents of the currently specified layer.
80  LSET layer_mask( aLayer );
81 
82  if( !aPlotOpt.GetExcludeEdgeLayer() )
83  layer_mask.set( Edge_Cuts );
84 
85  if( IsCopperLayer( aLayer ) )
86  {
87  // Skip NPTH pads on copper layers ( only if hole size == pad size ):
88  // Drill mark will be plotted if drill mark is SMALL_DRILL_SHAPE or FULL_DRILL_SHAPE
89  if( plotOpt.GetFormat() == PLOT_FORMAT::DXF )
90  {
91  plotOpt.SetSkipPlotNPTH_Pads( false );
92  PlotLayerOutlines( aBoard, aPlotter, layer_mask, plotOpt );
93  }
94  else
95  {
96  plotOpt.SetSkipPlotNPTH_Pads( true );
97  PlotStandardLayer( aBoard, aPlotter, layer_mask, plotOpt );
98  }
99  }
100  else
101  {
102  switch( aLayer )
103  {
104  case B_Mask:
105  case F_Mask:
106  plotOpt.SetSkipPlotNPTH_Pads( false );
107  // Disable plot pad holes
109 
110  // Plot solder mask:
111  if( soldermask_min_thickness == 0 )
112  {
113  if( plotOpt.GetFormat() == PLOT_FORMAT::DXF )
114  PlotLayerOutlines( aBoard, aPlotter, layer_mask, plotOpt );
115  else
116  PlotStandardLayer( aBoard, aPlotter, layer_mask, plotOpt );
117  }
118  else
119  {
120  PlotSolderMaskLayer( aBoard, aPlotter, layer_mask, plotOpt,
121  soldermask_min_thickness );
122  }
123 
124  break;
125 
126  case B_Adhes:
127  case F_Adhes:
128  case B_Paste:
129  case F_Paste:
130  plotOpt.SetSkipPlotNPTH_Pads( false );
131  // Disable plot pad holes
133 
134  if( plotOpt.GetFormat() == PLOT_FORMAT::DXF )
135  PlotLayerOutlines( aBoard, aPlotter, layer_mask, plotOpt );
136  else
137  PlotStandardLayer( aBoard, aPlotter, layer_mask, plotOpt );
138 
139  break;
140 
141  case F_SilkS:
142  case B_SilkS:
143  if( plotOpt.GetFormat() == PLOT_FORMAT::DXF && plotOpt.GetDXFPlotPolygonMode() )
144  // PlotLayerOutlines() is designed only for DXF plotters.
145  // and must not be used for other plot formats
146  PlotLayerOutlines( aBoard, aPlotter, layer_mask, plotOpt );
147  else
148  PlotStandardLayer( aBoard, aPlotter, layer_mask, plotOpt );
149 
150  // Gerber: Subtract soldermask from silkscreen if enabled
151  if( aPlotter->GetPlotterType() == PLOT_FORMAT::GERBER
152  && plotOpt.GetSubtractMaskFromSilk() )
153  {
154  if( aLayer == F_SilkS )
155  layer_mask = LSET( F_Mask );
156  else
157  layer_mask = LSET( B_Mask );
158 
159  // Create the mask to subtract by creating a negative layer polarity
160  aPlotter->SetLayerPolarity( false );
161 
162  // Disable plot pad holes
164 
165  // Plot the mask
166  PlotStandardLayer( aBoard, aPlotter, layer_mask, plotOpt );
167  }
168 
169  break;
170 
171  // These layers are plotted like silk screen layers.
172  // Mainly, pads on these layers are not filled.
173  // This is not necessary the best choice.
174  case Dwgs_User:
175  case Cmts_User:
176  case Eco1_User:
177  case Eco2_User:
178  case Edge_Cuts:
179  case Margin:
180  case F_CrtYd:
181  case B_CrtYd:
182  case F_Fab:
183  case B_Fab:
184  plotOpt.SetSkipPlotNPTH_Pads( false );
186 
187  if( plotOpt.GetFormat() == PLOT_FORMAT::DXF && plotOpt.GetDXFPlotPolygonMode() )
188  // PlotLayerOutlines() is designed only for DXF plotters.
189  // and must not be used for other plot formats
190  PlotLayerOutlines( aBoard, aPlotter, layer_mask, plotOpt );
191  else
192  PlotStandardLayer( aBoard, aPlotter, layer_mask, plotOpt );
193 
194  break;
195 
196  default:
197  plotOpt.SetSkipPlotNPTH_Pads( false );
199 
200  if( plotOpt.GetFormat() == PLOT_FORMAT::DXF && plotOpt.GetDXFPlotPolygonMode() )
201  // PlotLayerOutlines() is designed only for DXF plotters.
202  // and must not be used for other plot formats
203  PlotLayerOutlines( aBoard, aPlotter, layer_mask, plotOpt );
204  else
205  PlotStandardLayer( aBoard, aPlotter, layer_mask, plotOpt );
206 
207  break;
208  }
209  }
210 }
211 
212 
218 void PlotStandardLayer( BOARD* aBoard, PLOTTER* aPlotter, LSET aLayerMask,
219  const PCB_PLOT_PARAMS& aPlotOpt )
220 {
221  BRDITEMS_PLOTTER itemplotter( aPlotter, aBoard, aPlotOpt );
222 
223  itemplotter.SetLayerSet( aLayerMask );
224 
225  OUTLINE_MODE plotMode = aPlotOpt.GetPlotMode();
226  bool onCopperLayer = ( LSET::AllCuMask() & aLayerMask ).any();
227  bool onSolderMaskLayer = ( LSET( 2, F_Mask, B_Mask ) & aLayerMask ).any();
228  bool onSolderPasteLayer = ( LSET( 2, F_Paste, B_Paste ) & aLayerMask ).any();
229  bool onFrontFab = ( LSET( F_Fab ) & aLayerMask ).any();
230  bool onBackFab = ( LSET( B_Fab ) & aLayerMask ).any();
231  bool sketchPads = ( onFrontFab || onBackFab ) && aPlotOpt.GetSketchPadsOnFabLayers();
232 
233  // Plot edge layer and graphic items
234  itemplotter.PlotBoardGraphicItems();
235 
236  // Draw footprint texts:
237  for( const FOOTPRINT* footprint : aBoard->Footprints() )
238  itemplotter.PlotFootprintTextItems( footprint );
239 
240  // Draw footprint other graphic items:
241  for( const FOOTPRINT* footprint : aBoard->Footprints() )
242  itemplotter.PlotFootprintGraphicItems( footprint );
243 
244  // Plot footprint pads
245  for( FOOTPRINT* footprint : aBoard->Footprints() )
246  {
247  aPlotter->StartBlock( nullptr );
248 
249  for( PAD* pad : footprint->Pads() )
250  {
251  OUTLINE_MODE padPlotMode = plotMode;
252 
253  if( !( pad->GetLayerSet() & aLayerMask ).any() )
254  {
255  if( sketchPads &&
256  ( ( onFrontFab && pad->GetLayerSet().Contains( F_Cu ) ) ||
257  ( onBackFab && pad->GetLayerSet().Contains( B_Cu ) ) ) )
258  {
259  padPlotMode = SKETCH;
260  }
261  else
262  {
263  continue;
264  }
265  }
266 
268  if( onCopperLayer && !pad->FlashLayer( aLayerMask ) )
269  continue;
270 
272 
273  if( ( pad->GetLayerSet() & aLayerMask )[B_Cu] )
274  color = aPlotOpt.ColorSettings()->GetColor( B_Cu );
275 
276  if( ( pad->GetLayerSet() & aLayerMask )[F_Cu] )
277  color = color.LegacyMix( aPlotOpt.ColorSettings()->GetColor( F_Cu ) );
278 
279  if( sketchPads && aLayerMask[F_Fab] )
280  color = aPlotOpt.ColorSettings()->GetColor( F_Fab );
281  else if( sketchPads && aLayerMask[B_Fab] )
282  color = aPlotOpt.ColorSettings()->GetColor( B_Fab );
283 
284  wxSize margin;
285  int width_adj = 0;
286 
287  if( onCopperLayer )
288  width_adj = itemplotter.getFineWidthAdj();
289 
290  if( onSolderMaskLayer )
291  margin.x = margin.y = pad->GetSolderMaskMargin();
292 
293  if( onSolderPasteLayer )
294  margin = pad->GetSolderPasteMargin();
295 
296  // not all shapes can have a different margin for x and y axis
297  // in fact only oval and rect shapes can have different values.
298  // Round shape have always the same x,y margin
299  // so define a unique value for other shapes that do not support different values
300  int mask_clearance = margin.x;
301 
302  // Now offset the pad size by margin + width_adj
303  wxSize padPlotsSize = pad->GetSize() + margin * 2 + wxSize( width_adj, width_adj );
304 
305  // Store these parameters that can be modified to plot inflated/deflated pads shape
306  PAD_SHAPE padShape = pad->GetShape();
307  wxSize padSize = pad->GetSize();
308  wxSize padDelta = pad->GetDelta(); // has meaning only for trapezoidal pads
309  double padCornerRadius = pad->GetRoundRectCornerRadius();
310 
311  // Don't draw a 0 sized pad.
312  // Note: a custom pad can have its pad anchor with size = 0
313  if( pad->GetShape() != PAD_SHAPE::CUSTOM
314  && ( padPlotsSize.x <= 0 || padPlotsSize.y <= 0 ) )
315  continue;
316 
317  switch( pad->GetShape() )
318  {
319  case PAD_SHAPE::CIRCLE:
320  case PAD_SHAPE::OVAL:
321  pad->SetSize( padPlotsSize );
322 
323  if( aPlotOpt.GetSkipPlotNPTH_Pads() &&
325  ( pad->GetSize() == pad->GetDrillSize() ) &&
326  ( pad->GetAttribute() == PAD_ATTRIB::NPTH ) )
327  {
328  break;
329  }
330 
331  itemplotter.PlotPad( pad, color, padPlotMode );
332  break;
333 
334  case PAD_SHAPE::RECT:
335  pad->SetSize( padPlotsSize );
336 
337  if( mask_clearance > 0 )
338  {
339  pad->SetShape( PAD_SHAPE::ROUNDRECT );
340  pad->SetRoundRectCornerRadius( mask_clearance );
341  }
342 
343  itemplotter.PlotPad( pad, color, padPlotMode );
344  break;
345 
347  // inflate/deflate a trapezoid is a bit complex.
348  // so if the margin is not null, build a similar polygonal pad shape,
349  // and inflate/deflate the polygonal shape
350  // because inflating/deflating using different values for y and y
351  // we are using only margin.x as inflate/deflate value
352  if( mask_clearance == 0 )
353  {
354  itemplotter.PlotPad( pad, color, padPlotMode );
355  }
356  else
357  {
358  PAD dummy( *pad );
359  dummy.SetAnchorPadShape( PAD_SHAPE::CIRCLE );
360  dummy.SetShape( PAD_SHAPE::CUSTOM );
361  SHAPE_POLY_SET outline;
362  outline.NewOutline();
363  int dx = padSize.x / 2;
364  int dy = padSize.y / 2;
365  int ddx = padDelta.x / 2;
366  int ddy = padDelta.y / 2;
367 
368  outline.Append( -dx - ddy, dy + ddx );
369  outline.Append( dx + ddy, dy - ddx );
370  outline.Append( dx - ddy, -dy + ddx );
371  outline.Append( -dx + ddy, -dy - ddx );
372 
373  // Shape polygon can have holes so use InflateWithLinkedHoles(), not Inflate()
374  // which can create bad shapes if margin.x is < 0
375  int maxError = aBoard->GetDesignSettings().m_MaxError;
376  int numSegs = GetArcToSegmentCount( mask_clearance, maxError, 360.0 );
377  outline.InflateWithLinkedHoles( mask_clearance, numSegs,
379  dummy.DeletePrimitivesList();
380  dummy.AddPrimitivePoly( outline, 0, true );
381 
382  // Be sure the anchor pad is not bigger than the deflated shape because this
383  // anchor will be added to the pad shape when plotting the pad. So now the
384  // polygonal shape is built, we can clamp the anchor size
385  dummy.SetSize( wxSize( 0,0 ) );
386 
387  itemplotter.PlotPad( &dummy, color, padPlotMode );
388  }
389 
390  break;
391 
393  {
394  // rounding is stored as a percent, but we have to change the new radius
395  // to initial_radius + clearance to have a inflated/deflated similar shape
396  int initial_radius = pad->GetRoundRectCornerRadius();
397  pad->SetSize( padPlotsSize );
398  pad->SetRoundRectCornerRadius( std::max( initial_radius + mask_clearance, 0 ) );
399 
400  itemplotter.PlotPad( pad, color, padPlotMode );
401  break;
402  }
403 
405  if( mask_clearance == 0 )
406  {
407  // the size can be slightly inflated by width_adj (PS/PDF only)
408  pad->SetSize( padPlotsSize );
409  itemplotter.PlotPad( pad, color, padPlotMode );
410  }
411  else
412  {
413  // Due to the polygonal shape of a CHAMFERED_RECT pad, the best way is to
414  // convert the pad shape to a full polygon, inflate/deflate the polygon
415  // and use a dummy CUSTOM pad to plot the final shape.
416  PAD dummy( *pad );
417  // Build the dummy pad outline with coordinates relative to the pad position
418  // and orientation 0. The actual pos and rotation will be taken in account
419  // later by the plot function
420  dummy.SetPosition( wxPoint( 0, 0 ) );
421  dummy.SetOrientation( 0 );
422  SHAPE_POLY_SET outline;
423  int maxError = aBoard->GetDesignSettings().m_MaxError;
424  int numSegs = GetArcToSegmentCount( mask_clearance, maxError, 360.0 );
425  dummy.TransformShapeWithClearanceToPolygon( outline, UNDEFINED_LAYER, 0,
426  maxError, ERROR_INSIDE );
427  outline.InflateWithLinkedHoles( mask_clearance, numSegs,
429 
430  // Initialize the dummy pad shape:
431  dummy.SetAnchorPadShape( PAD_SHAPE::CIRCLE );
432  dummy.SetShape( PAD_SHAPE::CUSTOM );
433  dummy.DeletePrimitivesList();
434  dummy.AddPrimitivePoly( outline, 0, true );
435 
436  // Be sure the anchor pad is not bigger than the deflated shape because this
437  // anchor will be added to the pad shape when plotting the pad.
438  // So we set the anchor size to 0
439  dummy.SetSize( wxSize( 0,0 ) );
440  dummy.SetPosition( pad->GetPosition() );
441  dummy.SetOrientation( pad->GetOrientation() );
442 
443  itemplotter.PlotPad( &dummy, color, padPlotMode );
444  }
445 
446  break;
447 
448  case PAD_SHAPE::CUSTOM:
449  {
450  // inflate/deflate a custom shape is a bit complex.
451  // so build a similar pad shape, and inflate/deflate the polygonal shape
452  PAD dummy( *pad );
453  SHAPE_POLY_SET shape;
454  pad->MergePrimitivesAsPolygon( &shape );
455 
456  // Shape polygon can have holes so use InflateWithLinkedHoles(), not Inflate()
457  // which can create bad shapes if margin.x is < 0
458  int maxError = aBoard->GetDesignSettings().m_MaxError;
459  int numSegs = GetArcToSegmentCount( mask_clearance, maxError, 360.0 );
460  shape.InflateWithLinkedHoles( mask_clearance, numSegs, SHAPE_POLY_SET::PM_FAST );
461  dummy.DeletePrimitivesList();
462  dummy.AddPrimitivePoly( shape, 0, true );
463 
464  // Be sure the anchor pad is not bigger than the deflated shape because this
465  // anchor will be added to the pad shape when plotting the pad. So now the
466  // polygonal shape is built, we can clamp the anchor size
467  if( mask_clearance < 0 ) // we expect margin.x = margin.y for custom pads
468  dummy.SetSize( padPlotsSize );
469 
470  itemplotter.PlotPad( &dummy, color, padPlotMode );
471  break;
472  }
473  }
474 
475  // Restore the pad parameters modified by the plot code
476  pad->SetSize( padSize );
477  pad->SetDelta( padDelta );
478  pad->SetShape( padShape );
479  pad->SetRoundRectCornerRadius( padCornerRadius );
480  }
481 
482  aPlotter->EndBlock( nullptr );
483  }
484 
485  // Plot vias on copper layers, and if aPlotOpt.GetPlotViaOnMaskLayer() is true,
486  // plot them on solder mask
487 
488  GBR_METADATA gbr_metadata;
489 
490  bool isOnCopperLayer = ( aLayerMask & LSET::AllCuMask() ).any();
491 
492  if( isOnCopperLayer )
493  {
496  }
497 
498  aPlotter->StartBlock( nullptr );
499 
500  for( const PCB_TRACK* track : aBoard->Tracks() )
501  {
502  const PCB_VIA* via = dyn_cast<const PCB_VIA*>( track );
503 
504  if( !via )
505  continue;
506 
507  // vias are not plotted if not on selected layer, but if layer is SOLDERMASK_LAYER_BACK
508  // or SOLDERMASK_LAYER_FRONT, vias are drawn only if they are on the corresponding
509  // external copper layer
510  LSET via_mask_layer = via->GetLayerSet();
511 
512  if( aPlotOpt.GetPlotViaOnMaskLayer() )
513  {
514  if( via_mask_layer[B_Cu] )
515  via_mask_layer.set( B_Mask );
516 
517  if( via_mask_layer[F_Cu] )
518  via_mask_layer.set( F_Mask );
519  }
520 
521  if( !( via_mask_layer & aLayerMask ).any() )
522  continue;
523 
524  int via_margin = 0;
525  double width_adj = 0;
526 
527  // If the current layer is a solder mask, use the global mask clearance for vias
528  if( aLayerMask[B_Mask] || aLayerMask[F_Mask] )
529  via_margin = aBoard->GetDesignSettings().m_SolderMaskMargin;
530 
531  if( ( aLayerMask & LSET::AllCuMask() ).any() )
532  width_adj = itemplotter.getFineWidthAdj();
533 
534  int diameter = via->GetWidth() + 2 * via_margin + width_adj;
535 
537  if( onCopperLayer && !via->FlashLayer( aLayerMask ) )
538  continue;
539 
540  // Don't draw a null size item :
541  if( diameter <= 0 )
542  continue;
543 
544  // Some vias can be not connected (no net).
545  // Set the m_NotInNet for these vias to force a empty net name in gerber file
546  gbr_metadata.m_NetlistMetadata.m_NotInNet = via->GetNetname().IsEmpty();
547 
548  gbr_metadata.SetNetName( via->GetNetname() );
549 
550  COLOR4D color = aPlotOpt.ColorSettings()->GetColor(
551  LAYER_VIAS + static_cast<int>( via->GetViaType() ) );
552 
553  // Set plot color (change WHITE to LIGHTGRAY because the white items are not seen on a
554  // white paper or screen
555  aPlotter->SetColor( color != WHITE ? color : LIGHTGRAY );
556  aPlotter->FlashPadCircle( via->GetStart(), diameter, plotMode, &gbr_metadata );
557  }
558 
559  aPlotter->EndBlock( nullptr );
560  aPlotter->StartBlock( nullptr );
562 
563  // Plot tracks (not vias) :
564  for( const PCB_TRACK* track : aBoard->Tracks() )
565  {
566  if( track->Type() == PCB_VIA_T )
567  continue;
568 
569  if( !aLayerMask[track->GetLayer()] )
570  continue;
571 
572  // Some track segments can be not connected (no net).
573  // Set the m_NotInNet for these segments to force a empty net name in gerber file
574  gbr_metadata.m_NetlistMetadata.m_NotInNet = track->GetNetname().IsEmpty();
575 
576  gbr_metadata.SetNetName( track->GetNetname() );
577  int width = track->GetWidth() + itemplotter.getFineWidthAdj();
578  aPlotter->SetColor( itemplotter.getColor( track->GetLayer() ) );
579 
580  if( track->Type() == PCB_ARC_T )
581  {
582  const PCB_ARC* arc = static_cast<const PCB_ARC*>( track );
583  VECTOR2D center( arc->GetCenter() );
584  int radius = arc->GetRadius();
585  double start_angle = arc->GetArcAngleStart();
586  double end_angle = start_angle + arc->GetAngle();
587 
588  aPlotter->ThickArc( wxPoint( center.x, center.y ), -end_angle, -start_angle,
589  radius, width, plotMode, &gbr_metadata );
590  }
591  else
592  {
593  aPlotter->ThickSegment( track->GetStart(), track->GetEnd(), width, plotMode,
594  &gbr_metadata );
595  }
596  }
597 
598  aPlotter->EndBlock( nullptr );
599 
600  // Plot filled ares
601  aPlotter->StartBlock( nullptr );
602 
603  NETINFO_ITEM nonet( aBoard );
604 
605  for( const ZONE* zone : aBoard->Zones() )
606  {
607  for( PCB_LAYER_ID layer : zone->GetLayerSet().Seq() )
608  {
609  if( !aLayerMask[layer] )
610  continue;
611 
612  SHAPE_POLY_SET mainArea = zone->GetFilledPolysList( layer );
613  SHAPE_POLY_SET islands;
614 
615  for( int i = mainArea.OutlineCount() - 1; i >= 0; i-- )
616  {
617  if( zone->IsIsland( layer, i ) )
618  {
619  islands.AddOutline( mainArea.CPolygon( i )[0] );
620  mainArea.DeletePolygon( i );
621  }
622  }
623 
624  itemplotter.PlotFilledAreas( zone, mainArea );
625 
626  if( !islands.IsEmpty() )
627  {
628  ZONE dummy( *zone );
629  dummy.SetNet( &nonet );
630  itemplotter.PlotFilledAreas( &dummy, islands );
631  }
632  }
633  }
634 
635  aPlotter->EndBlock( nullptr );
636 
637  // Adding drill marks, if required and if the plotter is able to plot them:
639  itemplotter.PlotDrillMarks();
640 }
641 
642 
643 // Seems like we want to plot from back to front?
644 static const PCB_LAYER_ID plot_seq[] = {
645 
646  User_9,
647  User_8,
648  User_7,
649  User_6,
650  User_5,
651  User_4,
652  User_3,
653  User_2,
654  User_1,
655  B_Adhes,
656  F_Adhes,
657  B_Paste,
658  F_Paste,
659  B_SilkS,
660  B_Mask,
661  F_Mask,
662  Dwgs_User,
663  Cmts_User,
664  Eco1_User,
665  Eco2_User,
666  Edge_Cuts,
667  Margin,
668 
669  F_CrtYd, // CrtYd & Body are footprint only
670  B_CrtYd,
671  F_Fab,
672  B_Fab,
673 
674  B_Cu,
675  In30_Cu,
676  In29_Cu,
677  In28_Cu,
678  In27_Cu,
679  In26_Cu,
680  In25_Cu,
681  In24_Cu,
682  In23_Cu,
683  In22_Cu,
684  In21_Cu,
685  In20_Cu,
686  In19_Cu,
687  In18_Cu,
688  In17_Cu,
689  In16_Cu,
690  In15_Cu,
691  In14_Cu,
692  In13_Cu,
693  In12_Cu,
694  In11_Cu,
695  In10_Cu,
696  In9_Cu,
697  In8_Cu,
698  In7_Cu,
699  In6_Cu,
700  In5_Cu,
701  In4_Cu,
702  In3_Cu,
703  In2_Cu,
704  In1_Cu,
705  F_Cu,
706 
707  F_SilkS,
708 };
709 
710 
714 void PlotLayerOutlines( BOARD* aBoard, PLOTTER* aPlotter, LSET aLayerMask,
715  const PCB_PLOT_PARAMS& aPlotOpt )
716 {
717  BRDITEMS_PLOTTER itemplotter( aPlotter, aBoard, aPlotOpt );
718  itemplotter.SetLayerSet( aLayerMask );
719 
720  SHAPE_POLY_SET outlines;
721 
722  for( LSEQ seq = aLayerMask.Seq( plot_seq, arrayDim( plot_seq ) ); seq; ++seq )
723  {
724  PCB_LAYER_ID layer = *seq;
725 
726  outlines.RemoveAllContours();
727  aBoard->ConvertBrdLayerToPolygonalContours( layer, outlines );
728 
729  outlines.Simplify( SHAPE_POLY_SET::PM_FAST );
730 
731  // Plot outlines
732  std::vector<wxPoint> cornerList;
733 
734  // Now we have one or more basic polygons: plot each polygon
735  for( int ii = 0; ii < outlines.OutlineCount(); ii++ )
736  {
737  for( int kk = 0; kk <= outlines.HoleCount(ii); kk++ )
738  {
739  cornerList.clear();
740  const SHAPE_LINE_CHAIN& path =
741  ( kk == 0 ) ? outlines.COutline( ii ) : outlines.CHole( ii, kk - 1 );
742 
743  aPlotter->PlotPoly( path, FILL_T::NO_FILL );
744  }
745  }
746 
747  // Plot pad holes
749  {
750  int smallDrill = (aPlotOpt.GetDrillMarksType() == PCB_PLOT_PARAMS::SMALL_DRILL_SHAPE)
752 
753  for( FOOTPRINT* footprint : aBoard->Footprints() )
754  {
755  for( PAD* pad : footprint->Pads() )
756  {
757  wxSize hole = pad->GetDrillSize();
758 
759  if( hole.x == 0 || hole.y == 0 )
760  continue;
761 
762  if( hole.x == hole.y )
763  {
764  hole.x = std::min( smallDrill, hole.x );
765  aPlotter->Circle( pad->GetPosition(), hole.x, FILL_T::NO_FILL );
766  }
767  else
768  {
769  // Note: small drill marks have no significance when applied to slots
770  const SHAPE_SEGMENT* seg = pad->GetEffectiveHoleShape();
771  aPlotter->ThickSegment( (wxPoint) seg->GetSeg().A,
772  (wxPoint) seg->GetSeg().B,
773  seg->GetWidth(), SKETCH, nullptr );
774  }
775  }
776  }
777  }
778 
779  // Plot vias holes
780  for( PCB_TRACK* track : aBoard->Tracks() )
781  {
782  const PCB_VIA* via = dyn_cast<const PCB_VIA*>( track );
783 
784  if( via && via->IsOnLayer( layer ) ) // via holes can be not through holes
785  aPlotter->Circle( via->GetPosition(), via->GetDrillValue(), FILL_T::NO_FILL );
786  }
787  }
788 }
789 
790 
821 #define NEW_ALGO 1
822 
823 void PlotSolderMaskLayer( BOARD *aBoard, PLOTTER* aPlotter, LSET aLayerMask,
824  const PCB_PLOT_PARAMS& aPlotOpt, int aMinThickness )
825 {
826  int maxError = aBoard->GetDesignSettings().m_MaxError;
827  PCB_LAYER_ID layer = aLayerMask[B_Mask] ? B_Mask : F_Mask;
828  SHAPE_POLY_SET buffer;
829  SHAPE_POLY_SET* boardOutline = nullptr;
830 
831  if( aBoard->GetBoardPolygonOutlines( buffer ) )
832  boardOutline = &buffer;
833 
834  // We remove 1nm as we expand both sides of the shapes, so allowing for
835  // a strictly greater than or equal comparison in the shape separation (boolean add)
836  // means that we will end up with separate shapes that then are shrunk
837  int inflate = aMinThickness/2 - 1;
838 
839  BRDITEMS_PLOTTER itemplotter( aPlotter, aBoard, aPlotOpt );
840  itemplotter.SetLayerSet( aLayerMask );
841 
842  // Plot edge layer and graphic items.
843  // They do not have a solder Mask margin, because they are graphic items
844  // on this layer (like logos), not actually areas around pads.
845 
846  itemplotter.PlotBoardGraphicItems();
847 
848  for( FOOTPRINT* footprint : aBoard->Footprints() )
849  {
850  itemplotter.PlotFootprintTextItems( footprint );
851 
852  for( BOARD_ITEM* item : footprint->GraphicalItems() )
853  {
854  if( item->Type() == PCB_FP_SHAPE_T && item->GetLayer() == layer )
855  itemplotter.PlotFootprintGraphicItem( (FP_SHAPE*) item );
856  }
857  }
858 
859  // Build polygons for each pad shape. The size of the shape on solder mask should be size
860  // of pad + clearance around the pad, where clearance = solder mask clearance + extra margin.
861  // Extra margin is half the min width for solder mask, which is used to merge too-close shapes
862  // (distance < aMinThickness), and will be removed when creating the actual shapes.
863 
864  // Will contain shapes inflated by inflate value that will be merged and deflated by
865  // inflate value to build final polygons
866  // After calculations the remaining polygons are polygons to plot
867  SHAPE_POLY_SET areas;
868 
869  // Will contain exact shapes of all items on solder mask
870  SHAPE_POLY_SET initialPolys;
871 
872 #if NEW_ALGO
873  // Generate polygons with arcs inside the shape or exact shape
874  // to minimize shape changes created by arc to segment size correction.
876 #endif
877  {
878  // Plot pads
879  for( FOOTPRINT* footprint : aBoard->Footprints() )
880  {
881  // add shapes with their exact mask layer size in initialPolys
882  footprint->TransformPadsWithClearanceToPolygon( initialPolys, layer, 0, maxError,
883  ERROR_OUTSIDE );
884  // add shapes inflated by aMinThickness/2 in areas
885  footprint->TransformPadsWithClearanceToPolygon( areas, layer, inflate, maxError,
886  ERROR_OUTSIDE );
887  }
888 
889  // Plot vias on solder masks, if aPlotOpt.GetPlotViaOnMaskLayer() is true,
890  if( aPlotOpt.GetPlotViaOnMaskLayer() )
891  {
892  // The current layer is a solder mask, use the global mask clearance for vias
893  int via_clearance = aBoard->GetDesignSettings().m_SolderMaskMargin;
894  int via_margin = via_clearance + inflate;
895 
896  for( PCB_TRACK* track : aBoard->Tracks() )
897  {
898  const PCB_VIA* via = dyn_cast<const PCB_VIA*>( track );
899 
900  if( !via )
901  continue;
902 
903  // vias are plotted only if they are on the corresponding external copper layer
904  LSET via_set = via->GetLayerSet();
905 
906  if( via_set[B_Cu] )
907  via_set.set( B_Mask );
908 
909  if( via_set[F_Cu] )
910  via_set.set( F_Mask );
911 
912  if( !( via_set & aLayerMask ).any() )
913  continue;
914 
915  // add shapes with their exact mask layer size in initialPolys
916  via->TransformShapeWithClearanceToPolygon( initialPolys, layer, via_clearance,
917  maxError, ERROR_OUTSIDE );
918  // add shapes inflated by aMinThickness/2 in areas
919  via->TransformShapeWithClearanceToPolygon( areas, layer, via_margin, maxError,
920  ERROR_OUTSIDE );
921  }
922  }
923 
924  // Add filled zone areas.
925 #if 0 // Set to 1 if a solder mask margin must be applied to zones on solder mask
926  int zone_margin = aBoard->GetDesignSettings().m_SolderMaskMargin;
927 #else
928  int zone_margin = 0;
929 #endif
930 
931  for( ZONE* zone : aBoard->Zones() )
932  {
933  if( !zone->IsOnLayer( layer ) )
934  continue;
935 
936  // add shapes inflated by aMinThickness/2 in areas
937  zone->TransformSmoothedOutlineToPolygon( areas, inflate + zone_margin, maxError,
938  ERROR_OUTSIDE, boardOutline );
939 
940  // add shapes with their exact mask layer size in initialPolys
941  zone->TransformSmoothedOutlineToPolygon( initialPolys, zone_margin, maxError,
942  ERROR_OUTSIDE, boardOutline );
943  }
944  }
945 
946  int numSegs = GetArcToSegmentCount( inflate, maxError, 360.0 );
947 
948  // Merge all polygons: After deflating, not merged (not overlapping) polygons
949  // will have the initial shape (with perhaps small changes due to deflating transform)
951  areas.Deflate( inflate, numSegs );
952 
953 #if !NEW_ALGO
954  // To avoid a lot of code, use a ZONE to handle and plot polygons, because our polygons look
955  // exactly like filled areas in zones.
956  // Note, also this code is not optimized: it creates a lot of copy/duplicate data.
957  // However it is not complex, and fast enough for plot purposes (copy/convert data is only a
958  // very small calculation time for these calculations).
959  ZONE zone( aBoard );
960  zone.SetMinThickness( 0 ); // trace polygons only
961  zone.SetLayer( layer );
962 
963  // Combine the current areas to initial areas. This is mandatory because inflate/deflate
964  // transform is not perfect, and we want the initial areas perfectly kept
965  areas.BooleanAdd( initialPolys, SHAPE_POLY_SET::PM_FAST );
967 
968  itemplotter.PlotFilledAreas( &zone, areas );
969 #else
970 
971  // Remove initial shapes: each shape will be added later, as flashed item or region
972  // with a suitable attribute.
973  // Do not merge pads is mandatory in Gerber files: They must be identified as pads
974 
975  // we deflate areas in polygons, to avoid after subtracting initial shapes
976  // having small artifacts due to approximations during polygon transforms
978 
979  // Slightly inflate polygons to avoid any gap between them and other shapes,
980  // These gaps are created by arc to segments approximations
981  areas.Inflate( Millimeter2iu( 0.002 ), 6 );
982 
983  // Now, only polygons with a too small thickness are stored in areas.
985 
986  // Plot each initial shape (pads and polygons on mask layer), with suitable attributes:
987  PlotStandardLayer( aBoard, aPlotter, aLayerMask, aPlotOpt );
988 
989  for( int ii = 0; ii < areas.OutlineCount(); ii++ )
990  {
991  const SHAPE_LINE_CHAIN& path = areas.COutline( ii );
992 
993  // polygon area in mm^2 :
994  double curr_area = path.Area() / ( IU_PER_MM * IU_PER_MM );
995 
996  // Skip very small polygons: they are certainly artifacts created by
997  // arc approximations and polygon transforms
998  // (inflate/deflate transforms)
999  constexpr double poly_min_area_mm2 = 0.01; // 0.01 mm^2 gives a good filtering
1000 
1001  if( curr_area < poly_min_area_mm2 )
1002  continue;
1003 
1004  aPlotter->PlotPoly( path, FILL_T::FILLED_SHAPE );
1005  }
1006 #endif
1007 }
1008 
1009 
1016 static void initializePlotter( PLOTTER* aPlotter, const BOARD* aBoard,
1017  const PCB_PLOT_PARAMS* aPlotOpts )
1018 {
1019  PAGE_INFO pageA4( wxT( "A4" ) );
1020  const PAGE_INFO& pageInfo = aBoard->GetPageSettings();
1021  const PAGE_INFO* sheet_info;
1022  double paperscale; // Page-to-paper ratio
1023  wxSize paperSizeIU;
1024  wxSize pageSizeIU( pageInfo.GetSizeIU() );
1025  bool autocenter = false;
1026 
1027  // Special options: to fit the sheet to an A4 sheet replace the paper size. However there
1028  // is a difference between the autoscale and the a4paper option:
1029  // - Autoscale fits the board to the paper size
1030  // - A4paper fits the original paper size to an A4 sheet
1031  // - Both of them fit the board to an A4 sheet
1032  if( aPlotOpts->GetA4Output() )
1033  {
1034  sheet_info = &pageA4;
1035  paperSizeIU = pageA4.GetSizeIU();
1036  paperscale = (double) paperSizeIU.x / pageSizeIU.x;
1037  autocenter = true;
1038  }
1039  else
1040  {
1041  sheet_info = &pageInfo;
1042  paperSizeIU = pageSizeIU;
1043  paperscale = 1;
1044 
1045  // Need autocentering only if scale is not 1:1
1046  autocenter = (aPlotOpts->GetScale() != 1.0);
1047  }
1048 
1049  EDA_RECT bbox = aBoard->ComputeBoundingBox();
1050  wxPoint boardCenter = bbox.Centre();
1051  wxSize boardSize = bbox.GetSize();
1052 
1053  double compound_scale;
1054 
1055  // Fit to 80% of the page if asked; it could be that the board is empty, in this case
1056  // regress to 1:1 scale
1057  if( aPlotOpts->GetAutoScale() && boardSize.x > 0 && boardSize.y > 0 )
1058  {
1059  double xscale = (paperSizeIU.x * 0.8) / boardSize.x;
1060  double yscale = (paperSizeIU.y * 0.8) / boardSize.y;
1061 
1062  compound_scale = std::min( xscale, yscale ) * paperscale;
1063  }
1064  else
1065  {
1066  compound_scale = aPlotOpts->GetScale() * paperscale;
1067  }
1068 
1069  // For the plot offset we have to keep in mind the auxiliary origin too: if autoscaling is
1070  // off we check that plot option (i.e. autoscaling overrides auxiliary origin)
1071  wxPoint offset( 0, 0);
1072 
1073  if( autocenter )
1074  {
1075  offset.x = KiROUND( boardCenter.x - ( paperSizeIU.x / 2.0 ) / compound_scale );
1076  offset.y = KiROUND( boardCenter.y - ( paperSizeIU.y / 2.0 ) / compound_scale );
1077  }
1078  else
1079  {
1080  if( aPlotOpts->GetUseAuxOrigin() )
1081  offset = aBoard->GetDesignSettings().GetAuxOrigin();
1082  }
1083 
1084  aPlotter->SetPageSettings( *sheet_info );
1085 
1086  aPlotter->SetViewport( offset, IU_PER_MILS/10, compound_scale, aPlotOpts->GetMirror() );
1087 
1088  // Has meaning only for gerber plotter. Must be called only after SetViewport
1089  aPlotter->SetGerberCoordinatesFormat( aPlotOpts->GetGerberPrecision() );
1090 
1091  // Has meaning only for SVG plotter. Must be called only after SetViewport
1092  aPlotter->SetSvgCoordinatesFormat( aPlotOpts->GetSvgPrecision(), aPlotOpts->GetSvgUseInch() );
1093 
1094  aPlotter->SetCreator( wxT( "PCBNEW" ) );
1095  aPlotter->SetColorMode( false ); // default is plot in Black and White.
1096  aPlotter->SetTextMode( aPlotOpts->GetTextMode() );
1097 }
1098 
1099 
1103 static void FillNegativeKnockout( PLOTTER *aPlotter, const EDA_RECT &aBbbox )
1104 {
1105  const int margin = 5 * IU_PER_MM; // Add a 5 mm margin around the board
1106  aPlotter->SetNegative( true );
1107  aPlotter->SetColor( WHITE ); // Which will be plotted as black
1108  EDA_RECT area = aBbbox;
1109  area.Inflate( margin );
1110  aPlotter->Rect( area.GetOrigin(), area.GetEnd(), FILL_T::FILLED_SHAPE );
1111  aPlotter->SetColor( BLACK );
1112 }
1113 
1114 
1118 static void ConfigureHPGLPenSizes( HPGL_PLOTTER *aPlotter, const PCB_PLOT_PARAMS *aPlotOpts )
1119 {
1120  // Compute penDiam (the value is given in mils) in pcb units, with plot scale (if Scale is 2,
1121  // penDiam value is always m_HPGLPenDiam so apparent penDiam is actually penDiam / Scale
1122  int penDiam = KiROUND( aPlotOpts->GetHPGLPenDiameter() * IU_PER_MILS / aPlotOpts->GetScale() );
1123 
1124  // Set HPGL-specific options and start
1125  aPlotter->SetPenSpeed( aPlotOpts->GetHPGLPenSpeed() );
1126  aPlotter->SetPenNumber( aPlotOpts->GetHPGLPenNum() );
1127  aPlotter->SetPenDiameter( penDiam );
1128 }
1129 
1130 
1137 PLOTTER* StartPlotBoard( BOARD *aBoard, const PCB_PLOT_PARAMS *aPlotOpts, int aLayer,
1138  const wxString& aFullFileName, const wxString& aSheetDesc )
1139 {
1140  // Create the plotter driver and set the few plotter specific options
1141  PLOTTER* plotter = nullptr;
1142 
1143  switch( aPlotOpts->GetFormat() )
1144  {
1145  case PLOT_FORMAT::DXF:
1146  DXF_PLOTTER* DXF_plotter;
1147  DXF_plotter = new DXF_PLOTTER();
1148  DXF_plotter->SetUnits( aPlotOpts->GetDXFPlotUnits() );
1149 
1150  plotter = DXF_plotter;
1151  break;
1152 
1153  case PLOT_FORMAT::POST:
1154  PS_PLOTTER* PS_plotter;
1155  PS_plotter = new PS_PLOTTER();
1156  PS_plotter->SetScaleAdjust( aPlotOpts->GetFineScaleAdjustX(),
1157  aPlotOpts->GetFineScaleAdjustY() );
1158  plotter = PS_plotter;
1159  break;
1160 
1161  case PLOT_FORMAT::PDF:
1162  plotter = new PDF_PLOTTER();
1163  break;
1164 
1165  case PLOT_FORMAT::HPGL:
1166  HPGL_PLOTTER* HPGL_plotter;
1167  HPGL_plotter = new HPGL_PLOTTER();
1168 
1169  // HPGL options are a little more convoluted to compute, so they get their own function
1170  ConfigureHPGLPenSizes( HPGL_plotter, aPlotOpts );
1171  plotter = HPGL_plotter;
1172  break;
1173 
1174  case PLOT_FORMAT::GERBER:
1175  plotter = new GERBER_PLOTTER();
1176  break;
1177 
1178  case PLOT_FORMAT::SVG:
1179  plotter = new SVG_PLOTTER();
1180  break;
1181 
1182  default:
1183  wxASSERT( false );
1184  return nullptr;
1185  }
1186 
1188  renderSettings->LoadColors( aPlotOpts->ColorSettings() );
1189  renderSettings->SetDefaultPenWidth( Millimeter2iu( 0.0212 ) ); // Hairline at 1200dpi
1190  plotter->SetRenderSettings( renderSettings );
1191 
1192  // Compute the viewport and set the other options
1193 
1194  // page layout is not mirrored, so temporarily change mirror option for the page layout
1195  PCB_PLOT_PARAMS plotOpts = *aPlotOpts;
1196 
1197  if( plotOpts.GetPlotFrameRef() && plotOpts.GetMirror() )
1198  plotOpts.SetMirror( false );
1199 
1200  initializePlotter( plotter, aBoard, &plotOpts );
1201 
1202  if( plotter->OpenFile( aFullFileName ) )
1203  {
1204  plotter->ClearHeaderLinesList();
1205 
1206  // For the Gerber "file function" attribute, set the layer number
1207  if( plotter->GetPlotterType() == PLOT_FORMAT::GERBER )
1208  {
1209  bool useX2mode = plotOpts.GetUseGerberX2format();
1210 
1211  GERBER_PLOTTER* gbrplotter = static_cast <GERBER_PLOTTER*> ( plotter );
1212  gbrplotter->DisableApertMacros( plotOpts.GetDisableGerberMacros() );
1213  gbrplotter->UseX2format( useX2mode );
1214  gbrplotter->UseX2NetAttributes( plotOpts.GetIncludeGerberNetlistInfo() );
1215 
1216  // Attributes can be added using X2 format or as comment (X1 format)
1217  AddGerberX2Attribute( plotter, aBoard, aLayer, not useX2mode );
1218  }
1219 
1220  plotter->StartPlot();
1221 
1222  // Plot the frame reference if requested
1223  if( aPlotOpts->GetPlotFrameRef() )
1224  {
1225  PlotDrawingSheet( plotter, aBoard->GetProject(), aBoard->GetTitleBlock(),
1226  aBoard->GetPageSettings(), wxT( "1" ), 1, aSheetDesc,
1227  aBoard->GetFileName() );
1228 
1229  if( aPlotOpts->GetMirror() )
1230  initializePlotter( plotter, aBoard, aPlotOpts );
1231  }
1232 
1233  // When plotting a negative board: draw a black rectangle (background for plot board
1234  // in white) and switch the current color to WHITE; note the color inversion is actually
1235  // done in the driver (if supported)
1236  if( aPlotOpts->GetNegative() )
1237  {
1238  EDA_RECT bbox = aBoard->ComputeBoundingBox();
1239  FillNegativeKnockout( plotter, bbox );
1240  }
1241 
1242  return plotter;
1243  }
1244 
1245  delete plotter->RenderSettings();
1246  delete plotter;
1247  return nullptr;
1248 }
static LSET AllCuMask(int aCuLayerCount=MAX_CU_LAYERS)
Return a mask holding the requested number of Cu PCB_LAYER_IDs.
Definition: lset.cpp:759
OUTLINE_MODE GetPlotMode() const
Handle special data (items attributes) during plot.
COLOR4D getColor(LAYER_NUM aLayer) const
White color is special because it cannot be seen on a white paper in B&W mode.
OUTLINE_MODE
Definition: outline_mode.h:24
virtual wxPoint GetCenter() const override
This defaults to the center of the bounding box if not overridden.
Definition: pcb_track.h:281
const POLYGON & CPolygon(int aIndex) const
const PAGE_INFO & GetPageSettings() const
Definition: board.h:536
virtual void SetCreator(const wxString &aCreator)
Definition: plotter.h:174
virtual void LoadColors(const COLOR_SETTINGS *aSettings) override
Definition: pcb_painter.cpp:91
int OutlineCount() const
Return the number of vertices in a given outline/hole.
void UseX2NetAttributes(bool aEnable)
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:496
bool GetBoardPolygonOutlines(SHAPE_POLY_SET &aOutlines, OUTLINE_ERROR_HANDLER *aErrorHandler=nullptr)
Extract the board outlines and build a closed polygon from lines, arcs and circle items on edge cut l...
Definition: board.cpp:1835
ZONES & Zones()
Definition: board.h:240
bool GetPlotFrameRef() const
bool GetDXFPlotPolygonMode() const
void BooleanAdd(const SHAPE_POLY_SET &b, POLYGON_MODE aFastMode)
Perform boolean polyset difference For aFastMode meaning, see function booleanOp.
virtual bool StartPlot()=0
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:2129
virtual void SetPosition(const wxPoint &aPos)
Definition: eda_item.h:252
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition: board_item.h:49
static void FillNegativeKnockout(PLOTTER *aPlotter, const EDA_RECT &aBbbox)
Prefill in black an area a little bigger than the board to prepare for the negative plot.
static constexpr double IU_PER_MM
Mock up a conversion function.
virtual void PlotPoly(const std::vector< wxPoint > &aCornerList, FILL_T aFill, int aWidth=USE_DEFAULT_LINE_WIDTH, void *aData=nullptr)=0
Draw a polygon ( filled or not ).
virtual bool OpenFile(const wxString &aFullFilename)
Open or create the plot file aFullFilename.
Definition: plotter.cpp:76
void PlotFootprintGraphicItems(const FOOTPRINT *aFootprint)
void SetNetAttribType(int aNetAttribType)
Definition: gbr_metadata.h:219
virtual void SetColorMode(bool aColorMode)
Plot in B/W or color.
Definition: plotter.h:152
bool GetDisableGerberMacros() const
void SetScaleAdjust(double scaleX, double scaleY)
Set the 'fine' scaling for the postscript engine.
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:456
static const PCB_LAYER_ID plot_seq[]
void PlotStandardLayer(BOARD *aBoard, PLOTTER *aPlotter, LSET aLayerMask, const PCB_PLOT_PARAMS &aPlotOpt)
Plot a copper layer or mask.
int color
Definition: DXF_plotter.cpp:57
bool IsEmpty() const
void SetRenderSettings(RENDER_SETTINGS *aSettings)
Definition: plotter.h:155
PROJECT * GetProject() const
Definition: board.h:361
void PlotDrillMarks()
Draw a drill mark for pads and vias.
void SetMirror(bool aFlag)
virtual void SetPenDiameter(double diameter)
PLOTTER * StartPlotBoard(BOARD *aBoard, const PCB_PLOT_PARAMS *aPlotOpts, int aLayer, const wxString &aFullFileName, const wxString &aSheetDesc)
Open a new plotfile using the options (and especially the format) specified in the options and prepar...
virtual void StartBlock(void *aData)
calling this function allows one to define the beginning of a group of drawing items,...
Definition: plotter.h:487
class PCB_ARC, an arc track segment on a copper layer
Definition: typeinfo.h:97
void UseX2format(bool aEnable)
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.
class FP_SHAPE, a footprint edge
Definition: typeinfo.h:93
int GetHPGLPenSpeed() const
const SHAPE_LINE_CHAIN & CHole(int aOutline, int aHole) const
void AddGerberX2Attribute(PLOTTER *aPlotter, const BOARD *aBoard, LAYER_NUM aLayer, bool aUseX1CompatibilityMode)
Calculate some X2 attributes as defined in the Gerber file format specification and add them to the g...
Definition: pcbplot.cpp:353
void SetUnits(DXF_UNITS aUnit)
Set the units to use for plotting the DXF file.
void PlotFootprintGraphicItem(const FP_SHAPE *aShape)
Definition: color4d.h:44
void SetDrillMarksType(DrillMarksType aVal)
void PlotPad(const PAD *aPad, const COLOR4D &aColor, OUTLINE_MODE aPlotMode)
Plot a pad.
double m_SmallDrillMarkSize
The diameter of the drill marks on print and plot outputs (in mm), when the "Drill marks" option is s...
void PlotFootprintTextItems(const FOOTPRINT *aFootprint)
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...
LSEQ Seq(const PCB_LAYER_ID *aWishListSequence, unsigned aCount) const
Return an LSEQ from the union of this LSET and a desired sequence.
Definition: lset.cpp:411
const wxString & GetFileName() const
Definition: board.h:229
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Definition: board.cpp:590
double GetScale() const
bool GetUseGerberX2format() const
virtual void ThickSegment(const wxPoint &start, const wxPoint &end, int width, OUTLINE_MODE tracemode, void *aData)
Definition: plotter.cpp:519
virtual void SetGerberCoordinatesFormat(int aResolution, bool aUseInches=false)
Definition: plotter.h:470
virtual void SetSvgCoordinatesFormat(unsigned aResolution, bool aUseInches=false)
Definition: plotter.h:475
const SEG & GetSeg() const
bool GetMirror() const
Classes used in Pcbnew, CvPcb and GerbView.
void DeletePolygon(int aIdx)
Board plot function definition file.
static void PlotSolderMaskLayer(BOARD *aBoard, PLOTTER *aPlotter, LSET aLayerMask, const PCB_PLOT_PARAMS &aPlotOpt, int aMinThickness)
static LIB_SYMBOL * dummy()
Used to draw a dummy shape when a LIB_SYMBOL is not found in library.
Definition: sch_symbol.cpp:72
PCB specific render settings.
Definition: pcb_painter.h:64
const wxPoint GetEnd() const
Definition: eda_rect.h:112
PAD_SHAPE
The set of pad shapes, used with PAD::{Set,Get}Shape() DO NOT REORDER, legacy_plugin is dependent on ...
Definition: pad_shapes.h:33
void PlotLayerOutlines(BOARD *aBoard, PLOTTER *aPlotter, LSET aLayerMask, const PCB_PLOT_PARAMS &aPlotOpt)
Plot outlines of copper layer.
like PAD_PTH, but not plated
bool GetA4Output() const
int GetGerberPrecision() const
LSET is a set of PCB_LAYER_IDs.
Definition: layer_ids.h:516
PLOT_FORMAT GetFormat() const
void SetLayerSet(LSET aLayerMask)
Definition: pcbplot.h:84
Meta control for all vias opacity/visibility.
Definition: layer_ids.h:200
void PlotOneBoardLayer(BOARD *aBoard, PLOTTER *aPlotter, PCB_LAYER_ID aLayer, const PCB_PLOT_PARAMS &aPlotOpt)
Plot one copper or technical layer.
double GetArcAngleStart() const
Definition: pcb_track.cpp:964
Represent a set of closed polygons.
unsigned GetSvgPrecision() const
const wxPoint GetOrigin() const
Definition: eda_rect.h:110
virtual PLOT_FORMAT GetPlotterType() const =0
Returns the effective plot engine in use.
Describe the page size and margins of a paper page on which to eventually print or plot.
Definition: page_info.h:53
void PlotBoardGraphicItems()
Plot items like text and graphics but not tracks and footprints.
double GetRadius() const
Definition: pcb_track.cpp:946
virtual void SetPenSpeed(int speed)
Definition: plotter_hpgl.h:85
FOOTPRINTS & Footprints()
Definition: board.h:234
Plotting engine (HPGL)
int getFineWidthAdj() const
Definition: pcbplot.h:75
bool GetIncludeGerberNetlistInfo() const
virtual void SetTextMode(PLOT_TEXT_MODE mode)
Change the current text mode.
Definition: plotter.h:465
void Deflate(int aAmount, int aCircleSegmentsCount, CORNER_STRATEGY aCornerStrategy=ROUND_ALL_CORNERS)
void SetSkipPlotNPTH_Pads(bool aSkip)
PLOT_TEXT_MODE GetTextMode() const
bool GetSkipPlotNPTH_Pads() const
constexpr std::size_t arrayDim(T const (&)[N]) noexcept
Returns # of elements in an array.
Definition: arraydim.h:31
a few functions useful in geometry calculations.
void Simplify(POLYGON_MODE aFastMode)
Handle a list of polygons defining a copper zone.
Definition: zone.h:56
void SetMinThickness(int aMinThickness)
Definition: zone.h:245
Metadata which can be added in a gerber file as attribute in X2 format.
Definition: gbr_metadata.h:204
bool GetAutoScale() const
Parameters and options when plotting/printing a board.
Plotting engine (DXF)
int NewOutline()
Creates a new hole in a given outline.
int HoleCount(int aOutline) const
Return the reference to aIndex-th outline in the set.
virtual void SetNegative(bool aNegative)
Definition: plotter.h:142
double GetFineScaleAdjustX() const
void Fracture(POLYGON_MODE aFastMode)
Convert a single outline slitted ("fractured") polygon into a set ouf outlines with holes.
LSEQ is a sequence (and therefore also a set) of PCB_LAYER_IDs.
Definition: layer_ids.h:477
bool IsCopperLayer(LAYER_NUM aLayerId)
Tests whether a layer is a copper layer.
Definition: layer_ids.h:808
virtual void SetViewport(const wxPoint &aOffset, double aIusPerDecimil, double aScale, bool aMirror)=0
Set the plot offset and scaling for the current plot.
virtual void SetColor(const COLOR4D &color)=0
void PlotFilledAreas(const ZONE *aZone, const SHAPE_POLY_SET &aPolysList)
void Inflate(int aAmount, int aCircleSegCount, CORNER_STRATEGY aCornerStrategy=ROUND_ALL_CORNERS)
Perform outline inflation/deflation.
Plotting engines similar to ps (PostScript, Gerber, svg)
Plotting engine (Gerber)
Definition: color4d.h:48
int GetHPGLPenNum() const
int AddOutline(const SHAPE_LINE_CHAIN &aOutline)
Adds a new hole to the given outline (default: last) and returns its index.
void DisableApertMacros(bool aDisable)
Disable Aperture Macro (AM) command, only for broken Gerber Readers.
void SetNetName(const wxString &aNetname)
Definition: gbr_metadata.h:229
Base plotter engine class.
Definition: plotter.h:121
COLOR4D GetColor(int aLayer) const
bool GetSketchPadsOnFabLayers() const
Handle the data for a net.
Definition: netinfo.h:66
double GetAngle() const
Definition: pcb_track.cpp:952
RENDER_SETTINGS * RenderSettings()
Definition: plotter.h:156
bool GetPlotViaOnMaskLayer() const
TITLE_BLOCK & GetTitleBlock()
Definition: board.h:542
const wxPoint & GetAuxOrigin()
Information pertinent to a Pcbnew printed circuit board.
Definition: board.h:191
bool GetSubtractMaskFromSilk() const
Represent a polyline containing arcs as well as line segments: A chain of connected line and/or arc s...
PCB_LAYER_ID
A quick note on layer IDs:
Definition: layer_ids.h:65
When creating polygons to create a clearance polygonal area, the polygon must be same or bigger than ...
const SHAPE_LINE_CHAIN & COutline(int aIndex) const
Definition: layer_ids.h:71
virtual void SetPenNumber(int number)
Definition: plotter_hpgl.h:90
void PlotDrawingSheet(PLOTTER *plotter, const PROJECT *aProject, const TITLE_BLOCK &aTitleBlock, const PAGE_INFO &aPageInfo, const wxString &aSheetNumber, int aSheetCount, const wxString &aSheetDesc, const wxString &aFilename, COLOR4D aColor, bool aIsFirstPage)
double GetHPGLPenDiameter() const
VECTOR2I A
Definition: seg.h:48
Handle the component boundary box.
Definition: eda_rect.h:42
#define IU_PER_MILS
Definition: plotter.cpp:130
constexpr ret_type KiROUND(fp_type v)
Round a floating point number to an integer using "round halfway cases away from zero".
Definition: util.h:73
void InflateWithLinkedHoles(int aFactor, int aCircleSegmentsCount, POLYGON_MODE aFastMode)
Perform outline inflation/deflation, using round corners.
virtual void Rect(const wxPoint &p1, const wxPoint &p2, FILL_T fill, int width=USE_DEFAULT_LINE_WIDTH)=0
wxPoint Centre() const
Definition: eda_rect.h:64
void ClearHeaderLinesList()
Remove all lines from the list of free lines to print at the beginning of the file.
Definition: plotter.h:191
virtual void ThickArc(const wxPoint &centre, double StAngle, double EndAngle, int rayon, int width, OUTLINE_MODE tracemode, void *aData)
Definition: plotter.cpp:543
EDA_RECT ComputeBoundingBox(bool aBoardEdgesOnly=false) const
Calculate the bounding box containing all board items (or board edge segments).
Definition: board.cpp:1085
double GetFineScaleAdjustY() const
static const ADVANCED_CFG & GetCfg()
Get the singleton instance's config, which is shared by all consumers.
void SetApertureAttrib(GBR_APERTURE_METADATA::GBR_APERTURE_ATTRIB aApertAttribute)
Definition: gbr_metadata.h:209
COLOR_SETTINGS * ColorSettings() const
DXF_UNITS GetDXFPlotUnits() const
bool m_NotInNet
true if a pad of a footprint cannot be connected (for instance a mechanical NPTH, ot a not named pad)...
virtual void SetLayer(PCB_LAYER_ID aLayer) override
Set the layer this item is on.
Definition: zone.cpp:242
class PCB_VIA, a via (like a track segment on a copper layer)
Definition: typeinfo.h:96
bool GetSvgUseInch() const
GBR_NETLIST_METADATA m_NetlistMetadata
An item to handle object attribute.
Definition: gbr_metadata.h:262
bool GetNegative() const
void BooleanSubtract(const SHAPE_POLY_SET &b, POLYGON_MODE aFastMode)
Perform boolean polyset intersection For aFastMode meaning, see function booleanOp.
bool GetUseAuxOrigin() const
Definition: pad.h:57
void SetDefaultPenWidth(int aWidth)
DrillMarksType GetDrillMarksType() const
int GetWidth() const
static constexpr int Millimeter2iu(double mm)
print info associated to a net (TO.N attribute)
int GetArcToSegmentCount(int aRadius, int aErrorMax, double aArcAngleDegree)
TRACKS & Tracks()
Definition: board.h:231
virtual void Circle(const wxPoint &pos, int diametre, FILL_T fill, int width=USE_DEFAULT_LINE_WIDTH)=0
bool GetExcludeEdgeLayer() const
virtual void FlashPadCircle(const wxPoint &aPadPos, int aDiameter, OUTLINE_MODE aTraceMode, void *aData)=0
EDA_RECT & Inflate(wxCoord dx, wxCoord dy)
Inflate the rectangle horizontally by dx and vertically by dy.
Definition: eda_rect.cpp:364
const wxSize GetSize() const
Definition: eda_rect.h:100
virtual void SetPageSettings(const PAGE_INFO &aPageSettings)
Definition: plotter.h:158
int Append(int x, int y, int aOutline=-1, int aHole=-1, bool aAllowDuplication=false)
Add a new vertex to the contour indexed by aOutline and aHole (defaults to the outline of the last po...
A color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:103
VECTOR2I B
Definition: seg.h:49