KiCad PCB EDA Suite
pcbplot.h File Reference

Board plot function definition file. More...

#include <layers_id_colors_and_visibility.h>
#include <math/util.h>
#include <pad_shapes.h>
#include <pcb_plot_params.h>
#include <pgm_base.h>
#include <settings/color_settings.h>
#include <settings/settings_manager.h>
#include <wx/filename.h>

Go to the source code of this file.

Classes

class  BRDITEMS_PLOTTER
 

Macros

#define PLOT_MIN_SCALE   0.01
 
#define PLOT_MAX_SCALE   100.0
 
#define SMALL_DRILL   KiROUND( 0.35 * IU_PER_MM )
 

Functions

PLOTTERStartPlotBoard (BOARD *aBoard, 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 prepare the page for plotting. More...
 
void PlotOneBoardLayer (BOARD *aBoard, PLOTTER *aPlotter, PCB_LAYER_ID aLayer, const PCB_PLOT_PARAMS &aPlotOpt)
 Function PlotOneBoardLayer main function to plot one copper or technical layer. More...
 
void PlotStandardLayer (BOARD *aBoard, PLOTTER *aPlotter, LSET aLayerMask, const PCB_PLOT_PARAMS &aPlotOpt)
 Function PlotStandardLayer plot copper or technical layers. More...
 
void PlotLayerOutlines (BOARD *aBoard, PLOTTER *aPlotter, LSET aLayerMask, const PCB_PLOT_PARAMS &aPlotOpt)
 Function PlotLayerOutlines plot copper outline of a copper layer. More...
 
void BuildPlotFileName (wxFileName *aFilename, const wxString &aOutputDir, const wxString &aSuffix, const wxString &aExtension)
 Function BuildPlotFileName (helper function) Complete a plot filename: forces the output directory, add a suffix to the name and sets the specified extension the suffix is usually the layer name replaces not allowed chars in suffix by '_'. More...
 
const wxString GetGerberProtelExtension (LAYER_NUM aLayer)
 Function GetGerberProtelExtension. More...
 
const wxString GetGerberFileFunctionAttribute (const BOARD *aBoard, LAYER_NUM aLayer)
 Function GetGerberFileFunctionAttribute Returns the "file function" attribute for aLayer, as defined in the Gerber file format specification J1 (chapter 5). More...
 
void AddGerberX2Header (PLOTTER *aPlotter, const BOARD *aBoard, bool aUseX1CompatibilityMode=false)
 Calculates some X2 attributes, as defined in the Gerber file format specification J4 (chapter 5) and add them the to the gerber file header: TF.GenerationSoftware TF.CreationDate TF.ProjectId file format attribute is not added. More...
 
void AddGerberX2Attribute (PLOTTER *aPlotter, const BOARD *aBoard, LAYER_NUM aLayer, bool aUseX1CompatibilityMode)
 Calculates some X2 attributes, as defined in the Gerber file format specification and add them to the gerber file header: TF.GenerationSoftware TF.CreationDate TF.ProjectId TF.FileFunction TF.FilePolarity. More...
 

Detailed Description

Board plot function definition file.

Definition in file pcbplot.h.

Macro Definition Documentation

◆ PLOT_MAX_SCALE

#define PLOT_MAX_SCALE   100.0

Definition at line 57 of file pcbplot.h.

◆ PLOT_MIN_SCALE

#define PLOT_MIN_SCALE   0.01

Definition at line 56 of file pcbplot.h.

◆ SMALL_DRILL

#define SMALL_DRILL   KiROUND( 0.35 * IU_PER_MM )

Definition at line 60 of file pcbplot.h.

Function Documentation

◆ AddGerberX2Attribute()

void AddGerberX2Attribute ( PLOTTER aPlotter,
const BOARD aBoard,
LAYER_NUM  aLayer,
bool  aUseX1CompatibilityMode 
)

Calculates some X2 attributes, as defined in the Gerber file format specification and add them to the gerber file header: TF.GenerationSoftware TF.CreationDate TF.ProjectId TF.FileFunction TF.FilePolarity.

Parameters
aPlotter= the current plotter.
aBoard= the board, needed to extract some info
aLayer= the layer number to create the attribute for
aUseX1CompatibilityMode= false to generate X2 attributes, true to use X1 compatibility (X2 attributes added as structured comments, starting by "G04 #@! " followed by the X2 attribute

Definition at line 354 of file pcbplot.cpp.

356 {
357  AddGerberX2Header( aPlotter, aBoard, aUseX1CompatibilityMode );
358 
359  wxString text;
360 
361  // Add the TF.FileFunction
362  text = GetGerberFileFunctionAttribute( aBoard, aLayer );
363  aPlotter->AddLineToHeader( makeStringCompatX1( text, aUseX1CompatibilityMode ) );
364 
365  // Add the TF.FilePolarity (for layers which support that)
366  text = GetGerberFilePolarityAttribute( aLayer );
367 
368  if( !text.IsEmpty() )
369  aPlotter->AddLineToHeader( makeStringCompatX1( text, aUseX1CompatibilityMode ) );
370 }
void AddGerberX2Header(PLOTTER *aPlotter, const BOARD *aBoard, bool aUseX1CompatibilityMode)
Calculates some X2 attributes, as defined in the Gerber file format specification J4 (chapter 5) and ...
Definition: pcbplot.cpp:282
void AddLineToHeader(const wxString &aExtraString)
Function AddLineToHeader Add a line to the list of free lines to print at the beginning of the file.
Definition: plotter.h:179
static const wxString GetGerberFilePolarityAttribute(LAYER_NUM aLayer)
Definition: pcbplot.cpp:211
static wxString & makeStringCompatX1(wxString &aText, bool aUseX1CompatibilityMode)
Definition: pcbplot.cpp:270
const wxString GetGerberFileFunctionAttribute(const BOARD *aBoard, LAYER_NUM aLayer)
Function GetGerberFileFunctionAttribute Returns the "file function" attribute for aLayer,...
Definition: pcbplot.cpp:89

References AddGerberX2Header(), PLOTTER::AddLineToHeader(), GetGerberFileFunctionAttribute(), GetGerberFilePolarityAttribute(), and makeStringCompatX1().

Referenced by StartPlotBoard().

◆ AddGerberX2Header()

void AddGerberX2Header ( PLOTTER aPlotter,
const BOARD aBoard,
bool  aUseX1CompatibilityMode = false 
)

Calculates some X2 attributes, as defined in the Gerber file format specification J4 (chapter 5) and add them the to the gerber file header: TF.GenerationSoftware TF.CreationDate TF.ProjectId file format attribute is not added.

Parameters
aPlotter= the current plotter.
aBoard= the board, needed to extract some info
aUseX1CompatibilityMode= false to generate X2 attributes, true to use X1 compatibility (X2 attributes added as structured comments, starting by "G04 #@! " followed by the X2 attribute

Definition at line 282 of file pcbplot.cpp.

284 {
285  wxString text;
286 
287  // Creates the TF,.GenerationSoftware. Format is:
288  // %TF,.GenerationSoftware,<vendor>,<application name>[,<application version>]*%
289  text.Printf( wxT( "%%TF.GenerationSoftware,KiCad,Pcbnew,%s*%%" ), GetBuildVersion() );
290  aPlotter->AddLineToHeader( makeStringCompatX1( text, aUseX1CompatibilityMode ) );
291 
292  // creates the TF.CreationDate attribute:
293  text = GbrMakeCreationDateAttributeString( aUseX1CompatibilityMode ?
296  aPlotter->AddLineToHeader( text );
297 
298  // Creates the TF,.ProjectId. Format is (from Gerber file format doc):
299  // %TF.ProjectId,<project id>,<project GUID>,<revision id>*%
300  // <project id> is the name of the project, restricted to basic ASCII symbols only,
301  // Rem: <project id> accepts only ASCII 7 code (only basic ASCII codes are allowed in gerber files).
302  // and comma not accepted
303  // All illegal chars will be replaced by underscore
304  //
305  // <project GUID> is a string which is an unique id of a project.
306  // However Kicad does not handle such a project GUID, so it is built from the board name
307  wxFileName fn = aBoard->GetFileName();
308  wxString msg = fn.GetFullName();
309 
310  // Build a <project GUID>, from the board name
311  wxString guid = GbrMakeProjectGUIDfromString( msg );
312 
313  // build the <project id> string: this is the board short filename (without ext)
314  // and all non ASCII chars and comma are replaced by '_'
315  msg = fn.GetName();
316  msg.Replace( wxT( "," ), wxT( "_" ) );
317 
318  // build the <rec> string. All non ASCII chars and comma are replaced by '_'
319  wxString rev = ((BOARD*)aBoard)->GetTitleBlock().GetRevision();
320  rev.Replace( wxT( "," ), wxT( "_" ) );
321 
322  if( rev.IsEmpty() )
323  rev = wxT( "rev?" );
324 
325  text.Printf( wxT( "%%TF.ProjectId,%s,%s,%s*%%" ), msg.ToAscii(), GetChars( guid ), rev.ToAscii() );
326  aPlotter->AddLineToHeader( makeStringCompatX1( text, aUseX1CompatibilityMode ) );
327 
328  // Add the TF.SameCoordinates, that specify all gerber files uses the same
329  // origin and orientation, and the registration between files is OK.
330  // The parameter of TF.SameCoordinates is a string that is common
331  // to all files using the same registration and has no special meaning:
332  // this is just a key
333  // Because there is no mirroring/rotation in Kicad, only the plot offset origin
334  // can create incorrect registration.
335  // So we create a key from plot offset options.
336  // and therefore for a given board, all Gerber files having the same key have the same
337  // plot origin and use the same registration
338  //
339  // Currently the key is "Original" when using absolute Pcbnew coordinates,
340  // and te PY ans PY position od auxiliary axis, when using it.
341  // Please, if absolute Pcbnew coordinates, one day, are set by user, change the way
342  // the key is built to ensure file only using the *same* axis have the same key.
343  wxString registration_id = "Original";
344  wxPoint auxOrigin = aBoard->GetDesignSettings().m_AuxOrigin;
345 
346  if( aBoard->GetPlotOptions().GetUseAuxOrigin() && auxOrigin.x && auxOrigin.y )
347  registration_id.Printf( "PX%xPY%x", auxOrigin.x, auxOrigin.y );
348 
349  text.Printf( "%%TF.SameCoordinates,%s*%%", registration_id.GetData() );
350  aPlotter->AddLineToHeader( makeStringCompatX1( text, aUseX1CompatibilityMode ) );
351 }
const PCB_PLOT_PARAMS & GetPlotOptions() const
Definition: class_board.h:577
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Function GetDesignSettings.
Definition: class_board.h:553
wxString GbrMakeCreationDateAttributeString(GBR_NC_STRING_FORMAT aFormat)
void AddLineToHeader(const wxString &aExtraString)
Function AddLineToHeader Add a line to the list of free lines to print at the beginning of the file.
Definition: plotter.h:179
const wxString & GetFileName() const
Definition: class_board.h:255
wxString GetBuildVersion()
Get the full KiCad version string.
wxString GbrMakeProjectGUIDfromString(wxString &aText)
A helper function to build a project GUID using format RFC4122 Version 1 or 4 from the project name,...
static const wxChar * GetChars(const wxString &s)
Function GetChars returns a wxChar* to the actual wxChar* data within a wxString, and is helpful for ...
Definition: macros.h:153
static wxString & makeStringCompatX1(wxString &aText, bool aUseX1CompatibilityMode)
Definition: pcbplot.cpp:270
BOARD holds information pertinent to a Pcbnew printed circuit board.
Definition: class_board.h:180
bool GetUseAuxOrigin() const
wxPoint m_AuxOrigin
origin for plot exports

References PLOTTER::AddLineToHeader(), GBR_NC_STRING_FORMAT_X1, GBR_NC_STRING_FORMAT_X2, GbrMakeCreationDateAttributeString(), GbrMakeProjectGUIDfromString(), GetBuildVersion(), GetChars(), BOARD::GetDesignSettings(), BOARD::GetFileName(), BOARD::GetPlotOptions(), PCB_PLOT_PARAMS::GetUseAuxOrigin(), BOARD_DESIGN_SETTINGS::m_AuxOrigin, makeStringCompatX1(), wxPoint::x, and wxPoint::y.

Referenced by AddGerberX2Attribute(), GERBER_WRITER::createDrillFile(), and PLACEFILE_GERBER_WRITER::CreatePlaceFile().

◆ BuildPlotFileName()

void BuildPlotFileName ( wxFileName *  aFilename,
const wxString &  aOutputDir,
const wxString &  aSuffix,
const wxString &  aExtension 
)

Function BuildPlotFileName (helper function) Complete a plot filename: forces the output directory, add a suffix to the name and sets the specified extension the suffix is usually the layer name replaces not allowed chars in suffix by '_'.

Parameters
aFilename= the wxFileName to initialize Contains the base filename
aOutputDir= the path
aSuffix= the suffix to add to the base filename
aExtension= the file extension

Definition at line 373 of file pcbplot.cpp.

375 {
376  // aFilename contains the base filename only (without path and extension)
377  // when calling this function.
378  // It is expected to be a valid filename (this is usually the board filename)
379  aFilename->SetPath( aOutputDir );
380 
381  // Set the file extension
382  aFilename->SetExt( aExtension );
383 
384  // remove leading and trailing spaces if any from the suffix, if
385  // something survives add it to the name;
386  // also the suffix can contain some not allowed chars in filename (/ \ . : and some others),
387  // so change them to underscore
388  // Remember it can be called from a python script, so the illegal chars
389  // have to be filtered here.
390  wxString suffix = aSuffix;
391  suffix.Trim( true );
392  suffix.Trim( false );
393 
394  wxString badchars = wxFileName::GetForbiddenChars(wxPATH_DOS);
395  badchars.Append( "%." );
396 
397  for( unsigned ii = 0; ii < badchars.Len(); ii++ )
398  suffix.Replace( badchars[ii], wxT("_") );
399 
400  if( !suffix.IsEmpty() )
401  aFilename->SetName( aFilename->GetName() + wxT( "-" ) + suffix );
402 }

Referenced by DIALOG_EXPORT_SVG::ExportSVGFile(), PLOT_CONTROLLER::OpenPlotfile(), and DIALOG_PLOT::Plot().

◆ GetGerberFileFunctionAttribute()

const wxString GetGerberFileFunctionAttribute ( const BOARD aBoard,
LAYER_NUM  aLayer 
)

Function GetGerberFileFunctionAttribute Returns the "file function" attribute for aLayer, as defined in the Gerber file format specification J1 (chapter 5).

The returned string includes the "%TF.FileFunction" attribute prefix and the "*%" suffix.

Parameters
aBoard= the board, needed to get the total count of copper layers
aLayer= the layer number to create the attribute for
Returns
The attribute, as a text string

Definition at line 89 of file pcbplot.cpp.

90 {
91  wxString attrib;
92 
93  switch( aLayer )
94  {
95  case F_Adhes:
96  attrib = "Glue,Top";
97  break;
98 
99  case B_Adhes:
100  attrib = "Glue,Bot";
101  break;
102 
103  case F_SilkS:
104  attrib = "Legend,Top";
105  break;
106 
107  case B_SilkS:
108  attrib = "Legend,Bot";
109  break;
110 
111  case F_Mask:
112  attrib = "Soldermask,Top";
113  break;
114 
115  case B_Mask:
116  attrib = "Soldermask,Bot";
117  break;
118 
119  case F_Paste:
120  attrib = "Paste,Top";
121  break;
122 
123  case B_Paste:
124  attrib = "Paste,Bot";
125  break;
126 
127  case Edge_Cuts:
128  // Board outline.
129  // Can be "Profile,NP" (Not Plated: usual) or "Profile,P"
130  // This last is the exception (Plated)
131  attrib = "Profile,NP";
132  break;
133 
134  case Dwgs_User:
135  attrib = "OtherDrawing,Comment";
136  break;
137 
138  case Cmts_User:
139  attrib = "Other,Comment";
140  break;
141 
142  case Eco1_User:
143  attrib = "Other,ECO1";
144  break;
145 
146  case Eco2_User:
147  attrib = "Other,ECO2";
148  break;
149 
150  case B_Fab:
151  // This is actually a assembly layer
152  attrib = "AssemblyDrawing,Bot";
153  break;
154 
155  case F_Fab:
156  // This is actually a assembly layer
157  attrib = "AssemblyDrawing,Top";
158  break;
159 
160  case B_Cu:
161  attrib.Printf( wxT( "Copper,L%d,Bot" ), aBoard->GetCopperLayerCount() );
162  break;
163 
164  case F_Cu:
165  attrib = "Copper,L1,Top";
166  break;
167 
168  default:
169  if( IsCopperLayer( aLayer ) )
170  attrib.Printf( wxT( "Copper,L%d,Inr" ), aLayer+1 );
171  else
172  attrib.Printf( wxT( "Other,User" ), aLayer+1 );
173  break;
174  }
175 
176  // This code adds a optional parameter: the type of copper layers.
177  // Because it is not used by Pcbnew (it can be used only by external autorouters)
178  // user do not really set this parameter.
179  // Therefore do not add it.
180  // However, this code is left here, for perhaps a future usage.
181 #if 0
182  // Add the signal type of the layer, if relevant
183  if( IsCopperLayer( aLayer ) )
184  {
185  LAYER_T type = aBoard->GetLayerType( ToLAYER_ID( aLayer ) );
186 
187  switch( type )
188  {
189  case LT_SIGNAL:
190  attrib += ",Signal";
191  break;
192  case LT_POWER:
193  attrib += ",Plane";
194  break;
195  case LT_MIXED:
196  attrib += ",Mixed";
197  break;
198  default:
199  break; // do nothing (but avoid a warning for unhandled LAYER_T values from GCC)
200  }
201  }
202 #endif
203 
204  wxString fileFct;
205  fileFct.Printf( "%%TF.FileFunction,%s*%%", GetChars( attrib ) );
206 
207  return fileFct;
208 }
LAYER_T
Enum LAYER_T gives the allowed types of layers, same as Specctra DSN spec.
Definition: class_board.h:66
LAYER_T GetLayerType(PCB_LAYER_ID aLayer) const
Function GetLayerType returns the type of the copper layer given by aLayer.
static const wxChar * GetChars(const wxString &s)
Function GetChars returns a wxChar* to the actual wxChar* data within a wxString, and is helpful for ...
Definition: macros.h:153
int GetCopperLayerCount() const
Function GetCopperLayerCount.
bool IsCopperLayer(LAYER_NUM aLayerId)
Function IsCopperLayer tests whether a layer is a copper layer.
PCB_LAYER_ID ToLAYER_ID(int aLayer)
Definition: lset.cpp:849

References B_Adhes, B_Cu, B_Fab, B_Mask, B_Paste, B_SilkS, Cmts_User, Dwgs_User, Eco1_User, Eco2_User, Edge_Cuts, F_Adhes, F_Cu, F_Fab, F_Mask, F_Paste, F_SilkS, GetChars(), BOARD::GetCopperLayerCount(), BOARD::GetLayerType(), IsCopperLayer(), LT_MIXED, LT_POWER, LT_SIGNAL, and ToLAYER_ID().

Referenced by AddGerberX2Attribute().

◆ GetGerberProtelExtension()

const wxString GetGerberProtelExtension ( LAYER_NUM  aLayer)

Function GetGerberProtelExtension.

Returns
the appropriate Gerber file extension for aLayer used by Protel, and still sometimes in use (although the official Gerber Ext is now .gbr)

Definition at line 48 of file pcbplot.cpp.

49 {
50  if( IsCopperLayer( aLayer ) )
51  {
52  if( aLayer == F_Cu )
53  return wxT( "gtl" );
54  else if( aLayer == B_Cu )
55  return wxT( "gbl" );
56  else
57  {
58  return wxString::Format( wxT( "g%d" ), aLayer+1 );
59  }
60  }
61  else
62  {
63  switch( aLayer )
64  {
65  case B_Adhes: return wxT( "gba" );
66  case F_Adhes: return wxT( "gta" );
67 
68  case B_Paste: return wxT( "gbp" );
69  case F_Paste: return wxT( "gtp" );
70 
71  case B_SilkS: return wxT( "gbo" );
72  case F_SilkS: return wxT( "gto" );
73 
74  case B_Mask: return wxT( "gbs" );
75  case F_Mask: return wxT( "gts" );
76 
77  case Edge_Cuts: return wxT( "gm1" );
78 
79  case Dwgs_User:
80  case Cmts_User:
81  case Eco1_User:
82  case Eco2_User:
83  default: return wxT( "gbr" );
84  }
85  }
86 }
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, CPTREE &aTree)
Function Format outputs a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:205
bool IsCopperLayer(LAYER_NUM aLayerId)
Function IsCopperLayer tests whether a layer is a copper layer.

References B_Adhes, B_Cu, B_Mask, B_Paste, B_SilkS, Cmts_User, Dwgs_User, Eco1_User, Eco2_User, Edge_Cuts, F_Adhes, F_Cu, F_Mask, F_Paste, F_SilkS, Format(), and IsCopperLayer().

Referenced by PLOT_CONTROLLER::OpenPlotfile(), and DIALOG_PLOT::Plot().

◆ PlotLayerOutlines()

void PlotLayerOutlines ( BOARD aBoard,
PLOTTER aPlotter,
LSET  aLayerMask,
const PCB_PLOT_PARAMS aPlotOpt 
)

Function PlotLayerOutlines plot copper outline of a copper layer.

Parameters
aBoard= the board to plot
aPlotter= the plotter to use
aLayerMask= the mask to define the layers to plot
aPlotOpt= the plot options. Has meaning for some formats only

Definition at line 639 of file plot_board_layers.cpp.

641 {
642  BRDITEMS_PLOTTER itemplotter( aPlotter, aBoard, aPlotOpt );
643  itemplotter.SetLayerSet( aLayerMask );
644 
645  SHAPE_POLY_SET outlines;
646 
647  for( LSEQ seq = aLayerMask.Seq( plot_seq, arrayDim( plot_seq ) ); seq; ++seq )
648  {
649  PCB_LAYER_ID layer = *seq;
650 
651  outlines.RemoveAllContours();
652  aBoard->ConvertBrdLayerToPolygonalContours( layer, outlines );
653 
654  outlines.Simplify( SHAPE_POLY_SET::PM_FAST );
655 
656  // Plot outlines
657  std::vector<wxPoint> cornerList;
658 
659  // Now we have one or more basic polygons: plot each polygon
660  for( int ii = 0; ii < outlines.OutlineCount(); ii++ )
661  {
662  for(int kk = 0; kk <= outlines.HoleCount (ii); kk++ )
663  {
664  cornerList.clear();
665  const SHAPE_LINE_CHAIN& path = (kk == 0) ? outlines.COutline( ii ) : outlines.CHole( ii, kk - 1 );
666 
667  for( int jj = 0; jj < path.PointCount(); jj++ )
668  cornerList.emplace_back( (wxPoint) path.CPoint( jj ) );
669 
670  // Ensure the polygon is closed
671  if( cornerList[0] != cornerList[cornerList.size() - 1] )
672  cornerList.push_back( cornerList[0] );
673 
674  aPlotter->PlotPoly( cornerList, NO_FILL );
675  }
676  }
677 
678  // Plot pad holes
680  {
681  int smallDrill = (aPlotOpt.GetDrillMarksType() == PCB_PLOT_PARAMS::SMALL_DRILL_SHAPE)
682  ? SMALL_DRILL : INT_MAX;
683 
684  for( MODULE* module : aBoard->Modules() )
685  {
686  for( D_PAD* pad : module->Pads() )
687  {
688  wxSize hole = pad->GetDrillSize();
689 
690  if( hole.x == 0 || hole.y == 0 )
691  continue;
692 
693  if( hole.x == hole.y )
694  {
695  hole.x = std::min( smallDrill, hole.x );
696  aPlotter->Circle( pad->GetPosition(), hole.x, NO_FILL );
697  }
698  else
699  {
700  // Note: small drill marks have no significance when applied to slots
701  const SHAPE_SEGMENT* seg = pad->GetEffectiveHoleShape();
702  aPlotter->ThickSegment( (wxPoint) seg->GetSeg().A,
703  (wxPoint) seg->GetSeg().B,
704  seg->GetWidth(), SKETCH, NULL );
705  }
706  }
707  }
708  }
709 
710  // Plot vias holes
711  for( TRACK* track : aBoard->Tracks() )
712  {
713  const VIA* via = dyn_cast<const VIA*>( track );
714 
715  if( via && via->IsOnLayer( layer ) ) // via holes can be not through holes
716  {
717  aPlotter->Circle( via->GetPosition(), via->GetDrillValue(), NO_FILL );
718  }
719  }
720  }
721 }
#define SMALL_DRILL
Definition: pcbplot.h:60
int OutlineCount() const
Returns the number of outlines in the set
static const PCB_LAYER_ID plot_seq[]
const SHAPE_LINE_CHAIN & CHole(int aOutline, int aHole) const
virtual void PlotPoly(const std::vector< wxPoint > &aCornerList, FILL_T aFill, int aWidth=USE_DEFAULT_LINE_WIDTH, void *aData=NULL)=0
Function PlotPoly.
int PointCount() const
Function PointCount()
LSEQ Seq(const PCB_LAYER_ID *aWishListSequence, unsigned aCount) const
Function Seq returns an LSEQ from the union of this LSET and a desired sequence.
Definition: lset.cpp:377
const SEG & GetSeg() const
const VECTOR2I & CPoint(int aIndex) const
Function Point()
PCB_LAYER_ID
A quick note on layer IDs:
#define NULL
int GetDrillValue() const
Function GetDrillValue "calculates" the drill value for vias (m-Drill if > 0, or default drill value ...
MODULES & Modules()
Definition: class_board.h:266
SHAPE_POLY_SET.
void ConvertBrdLayerToPolygonalContours(PCB_LAYER_ID aLayer, SHAPE_POLY_SET &aOutlines)
Function ConvertBrdLayerToPolygonalContours Build a set of polygons which are the outlines of copper ...
void Simplify(POLYGON_MODE aFastMode)
Simplifies the polyset (merges overlapping polys, eliminates degeneracy/self-intersections) For aFast...
int HoleCount(int aOutline) const
Returns the number of holes in a given outline
LSEQ is a sequence (and therefore also a set) of PCB_LAYER_IDs.
constexpr std::size_t arrayDim(T const (&)[N]) noexcept
Definition: macros.h:160
SHAPE_LINE_CHAIN.
virtual void ThickSegment(const wxPoint &start, const wxPoint &end, int width, EDA_DRAW_MODE_T tracemode, void *aData)
Definition: plotter.cpp:507
const SHAPE_LINE_CHAIN & COutline(int aIndex) const
void RemoveAllContours()
Removes all outlines & holes (clears) the polygon set.
VECTOR2I A
Definition: seg.h:47
bool IsOnLayer(PCB_LAYER_ID aLayer) const override
Function IsOnLayer tests to see if this object is on the given layer.
wxPoint GetPosition() const override
Definition: class_track.h:416
DrillMarksType GetDrillMarksType() const
int GetWidth() const
TRACKS & Tracks()
Definition: class_board.h:257
virtual void Circle(const wxPoint &pos, int diametre, FILL_T fill, int width=USE_DEFAULT_LINE_WIDTH)=0
VECTOR2I B
Definition: seg.h:48

References SEG::A, arrayDim(), SEG::B, SHAPE_POLY_SET::CHole(), PLOTTER::Circle(), BOARD::ConvertBrdLayerToPolygonalContours(), SHAPE_POLY_SET::COutline(), SHAPE_LINE_CHAIN::CPoint(), PCB_PLOT_PARAMS::GetDrillMarksType(), VIA::GetDrillValue(), VIA::GetPosition(), SHAPE_SEGMENT::GetSeg(), SHAPE_SEGMENT::GetWidth(), SHAPE_POLY_SET::HoleCount(), VIA::IsOnLayer(), BOARD::Modules(), PCB_PLOT_PARAMS::NO_DRILL_SHAPE, NO_FILL, NULL, SHAPE_POLY_SET::OutlineCount(), plot_seq, PLOTTER::PlotPoly(), SHAPE_POLY_SET::PM_FAST, SHAPE_LINE_CHAIN::PointCount(), SHAPE_POLY_SET::RemoveAllContours(), LSET::Seq(), BRDITEMS_PLOTTER::SetLayerSet(), SHAPE_POLY_SET::Simplify(), SKETCH, SMALL_DRILL, PCB_PLOT_PARAMS::SMALL_DRILL_SHAPE, PLOTTER::ThickSegment(), and BOARD::Tracks().

Referenced by PlotOneBoardLayer().

◆ PlotOneBoardLayer()

void PlotOneBoardLayer ( BOARD aBoard,
PLOTTER aPlotter,
PCB_LAYER_ID  aLayer,
const PCB_PLOT_PARAMS aPlotOpt 
)

Function PlotOneBoardLayer main function to plot one copper or technical layer.

It prepare options and calls the specialized plot function, according to the layer type

Parameters
aBoard= the board to plot
aPlotter= the plotter to use
aLayer= the layer id to plot
aPlotOpt= the plot options (files, sketch). Has meaning for some formats only

Definition at line 64 of file plot_board_layers.cpp.

66 {
67  PCB_PLOT_PARAMS plotOpt = aPlotOpt;
68  int soldermask_min_thickness = aBoard->GetDesignSettings().m_SolderMaskMinWidth;
69 
70  // Set a default color and the text mode for this layer
71  aPlotter->SetColor( aPlotOpt.GetColor() );
72  aPlotter->SetTextMode( aPlotOpt.GetTextMode() );
73 
74  // Specify that the contents of the "Edges Pcb" layer are to be plotted in addition to the
75  // contents of the currently specified layer.
76  LSET layer_mask( aLayer );
77 
78  if( !aPlotOpt.GetExcludeEdgeLayer() )
79  layer_mask.set( Edge_Cuts );
80 
81  if( IsCopperLayer( aLayer ) )
82  {
83  // Skip NPTH pads on copper layers ( only if hole size == pad size ):
84  // Drill mark will be plotted if drill mark is SMALL_DRILL_SHAPE or FULL_DRILL_SHAPE
85  if( plotOpt.GetFormat() == PLOT_FORMAT::DXF )
86  {
87  plotOpt.SetSkipPlotNPTH_Pads( false );
88  PlotLayerOutlines( aBoard, aPlotter, layer_mask, plotOpt );
89  }
90  else
91  {
92  plotOpt.SetSkipPlotNPTH_Pads( true );
93  PlotStandardLayer( aBoard, aPlotter, layer_mask, plotOpt );
94  }
95  }
96  else
97  {
98  switch( aLayer )
99  {
100  case B_Mask:
101  case F_Mask:
102  plotOpt.SetSkipPlotNPTH_Pads( false );
103  // Disable plot pad holes
105 
106  // Plot solder mask:
107  if( soldermask_min_thickness == 0 )
108  {
109  if( plotOpt.GetFormat() == PLOT_FORMAT::DXF )
110  PlotLayerOutlines( aBoard, aPlotter, layer_mask, plotOpt );
111  else
112  PlotStandardLayer( aBoard, aPlotter, layer_mask, plotOpt );
113  }
114  else
115  PlotSolderMaskLayer( aBoard, aPlotter, layer_mask, plotOpt,
116  soldermask_min_thickness );
117 
118  break;
119 
120  case B_Adhes:
121  case F_Adhes:
122  case B_Paste:
123  case F_Paste:
124  plotOpt.SetSkipPlotNPTH_Pads( false );
125  // Disable plot pad holes
127 
128  if( plotOpt.GetFormat() == PLOT_FORMAT::DXF )
129  PlotLayerOutlines( aBoard, aPlotter, layer_mask, plotOpt );
130  else
131  PlotStandardLayer( aBoard, aPlotter, layer_mask, plotOpt );
132  break;
133 
134  case F_SilkS:
135  case B_SilkS:
136  if( plotOpt.GetFormat() == PLOT_FORMAT::DXF && plotOpt.GetDXFPlotPolygonMode() )
137  // PlotLayerOutlines() is designed only for DXF plotters.
138  // and must not be used for other plot formats
139  PlotLayerOutlines( aBoard, aPlotter, layer_mask, plotOpt );
140  else
141  PlotStandardLayer( aBoard, aPlotter, layer_mask, plotOpt );
142 
143  // Gerber: Subtract soldermask from silkscreen if enabled
144  if( aPlotter->GetPlotterType() == PLOT_FORMAT::GERBER
145  && plotOpt.GetSubtractMaskFromSilk() )
146  {
147  if( aLayer == F_SilkS )
148  layer_mask = LSET( F_Mask );
149  else
150  layer_mask = LSET( B_Mask );
151 
152  // Create the mask to subtract by creating a negative layer polarity
153  aPlotter->SetLayerPolarity( false );
154 
155  // Disable plot pad holes
157 
158  // Plot the mask
159  PlotStandardLayer( aBoard, aPlotter, layer_mask, plotOpt );
160  }
161  break;
162 
163  // These layers are plotted like silk screen layers.
164  // Mainly, pads on these layers are not filled.
165  // This is not necessary the best choice.
166  case Dwgs_User:
167  case Cmts_User:
168  case Eco1_User:
169  case Eco2_User:
170  case Edge_Cuts:
171  case Margin:
172  case F_CrtYd:
173  case B_CrtYd:
174  case F_Fab:
175  case B_Fab:
176  plotOpt.SetSkipPlotNPTH_Pads( false );
178 
179  if( plotOpt.GetFormat() == PLOT_FORMAT::DXF && plotOpt.GetDXFPlotPolygonMode() )
180  // PlotLayerOutlines() is designed only for DXF plotters.
181  // and must not be used for other plot formats
182  PlotLayerOutlines( aBoard, aPlotter, layer_mask, plotOpt );
183  else
184  PlotStandardLayer( aBoard, aPlotter, layer_mask, plotOpt );
185  break;
186 
187  default:
188  plotOpt.SetSkipPlotNPTH_Pads( false );
190 
191  if( plotOpt.GetFormat() == PLOT_FORMAT::DXF && plotOpt.GetDXFPlotPolygonMode() )
192  // PlotLayerOutlines() is designed only for DXF plotters.
193  // and must not be used for other plot formats
194  PlotLayerOutlines( aBoard, aPlotter, layer_mask, plotOpt );
195  else
196  PlotStandardLayer( aBoard, aPlotter, layer_mask, plotOpt );
197  break;
198  }
199  }
200 }
bool GetDXFPlotPolygonMode() const
virtual void SetColor(COLOR4D color)=0
virtual void SetLayerPolarity(bool aPositive)
Function SetLayerPolarity sets current Gerber layer polarity to positive or negative by writing %LPD*...
Definition: plotter.h:446
void PlotStandardLayer(BOARD *aBoard, PLOTTER *aPlotter, LSET aLayerMask, const PCB_PLOT_PARAMS &aPlotOpt)
Function PlotStandardLayer plot copper or technical layers.
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Function GetDesignSettings.
Definition: class_board.h:553
void SetDrillMarksType(DrillMarksType aVal)
static void PlotSolderMaskLayer(BOARD *aBoard, PLOTTER *aPlotter, LSET aLayerMask, const PCB_PLOT_PARAMS &aPlotOpt, int aMinThickness)
void PlotLayerOutlines(BOARD *aBoard, PLOTTER *aPlotter, LSET aLayerMask, const PCB_PLOT_PARAMS &aPlotOpt)
Function PlotLayerOutlines plot copper outline of a copper layer.
LSET is a set of PCB_LAYER_IDs.
PLOT_FORMAT GetFormat() const
virtual PLOT_FORMAT GetPlotterType() const =0
Returns the effective plot engine in use.
COLOR4D GetColor() const
virtual void SetTextMode(PLOT_TEXT_MODE mode)
Change the current text mode.
Definition: plotter.h:455
void SetSkipPlotNPTH_Pads(bool aSkip)
PLOT_TEXT_MODE GetTextMode() const
PCB_PLOT_PARAMS handles plot parameters and options when plotting/printing a board.
bool GetSubtractMaskFromSilk() const
bool IsCopperLayer(LAYER_NUM aLayerId)
Function IsCopperLayer tests whether a layer is a copper layer.
bool GetExcludeEdgeLayer() const
int m_SolderMaskMinWidth
Solder mask min width.

References B_Adhes, B_CrtYd, B_Fab, B_Mask, B_Paste, B_SilkS, Cmts_User, Dwgs_User, DXF, Eco1_User, Eco2_User, Edge_Cuts, F_Adhes, F_CrtYd, F_Fab, F_Mask, F_Paste, F_SilkS, GERBER, PCB_PLOT_PARAMS::GetColor(), BOARD::GetDesignSettings(), PCB_PLOT_PARAMS::GetDXFPlotPolygonMode(), PCB_PLOT_PARAMS::GetExcludeEdgeLayer(), PCB_PLOT_PARAMS::GetFormat(), PLOTTER::GetPlotterType(), PCB_PLOT_PARAMS::GetSubtractMaskFromSilk(), PCB_PLOT_PARAMS::GetTextMode(), IsCopperLayer(), BOARD_DESIGN_SETTINGS::m_SolderMaskMinWidth, Margin, PCB_PLOT_PARAMS::NO_DRILL_SHAPE, PlotLayerOutlines(), PlotSolderMaskLayer(), PlotStandardLayer(), PLOTTER::SetColor(), PCB_PLOT_PARAMS::SetDrillMarksType(), PLOTTER::SetLayerPolarity(), PCB_PLOT_PARAMS::SetSkipPlotNPTH_Pads(), and PLOTTER::SetTextMode().

Referenced by DIALOG_EXPORT_SVG::CreateSVGFile(), DIALOG_PLOT::Plot(), and PLOT_CONTROLLER::PlotLayer().

◆ PlotStandardLayer()

void PlotStandardLayer ( BOARD aBoard,
PLOTTER aPlotter,
LSET  aLayerMask,
const PCB_PLOT_PARAMS aPlotOpt 
)

Function PlotStandardLayer plot copper or technical layers.

not used for silk screen layers, because these layers have specific requirements, mainly for pads

Parameters
aBoard= the board to plot
aPlotter= the plotter to use
aLayerMask= the mask to define the layers to plot
aPlotOpt= the plot options (files, sketch). Has meaning for some formats only

aPlotOpt has 3 important options to control this plot, which are set, depending on the layer type to plot SetEnablePlotVia( bool aEnable ) aEnable = true to plot vias, false to skip vias (has meaning only for solder mask layers). SetSkipPlotNPTH_Pads( bool aSkip ) aSkip = true to skip NPTH Pads, when the pad size and the pad hole have the same size. Used in GERBER format only. SetDrillMarksType( DrillMarksType aVal ) controle the actual hole: no hole, small hole, actual hole

Definition at line 206 of file plot_board_layers.cpp.

208 {
209  BRDITEMS_PLOTTER itemplotter( aPlotter, aBoard, aPlotOpt );
210 
211  itemplotter.SetLayerSet( aLayerMask );
212 
213  EDA_DRAW_MODE_T plotMode = aPlotOpt.GetPlotMode();
214  bool onCopperLayer = ( LSET::AllCuMask() & aLayerMask ).any();
215  bool onSolderMaskLayer = ( LSET( 2, F_Mask, B_Mask ) & aLayerMask ).any();
216  bool onSolderPasteLayer = ( LSET( 2, F_Paste, B_Paste ) & aLayerMask ).any();
217  bool onFrontFab = ( LSET( F_Fab ) & aLayerMask ).any();
218  bool onBackFab = ( LSET( B_Fab ) & aLayerMask ).any();
219  bool sketchPads = ( onFrontFab || onBackFab ) && aPlotOpt.GetSketchPadsOnFabLayers();
220 
221  // Plot edge layer and graphic items
222  itemplotter.PlotBoardGraphicItems();
223 
224  // Draw footprint texts:
225  for( MODULE* module : aBoard->Modules() )
226  itemplotter.PlotFootprintTextItems( module );
227 
228  // Draw footprint other graphic items:
229  for( MODULE* module : aBoard->Modules() )
230  itemplotter.PlotFootprintGraphicItems( module );
231 
232  // Plot footprint pads
233  for( MODULE* module : aBoard->Modules() )
234  {
235  aPlotter->StartBlock( NULL );
236 
237  for( D_PAD* pad : module->Pads() )
238  {
239  EDA_DRAW_MODE_T padPlotMode = plotMode;
240 
241  if( !( pad->GetLayerSet() & aLayerMask ).any() )
242  {
243  if( sketchPads &&
244  ( ( onFrontFab && pad->GetLayerSet().Contains( F_Cu ) ) ||
245  ( onBackFab && pad->GetLayerSet().Contains( B_Cu ) ) ) )
246  padPlotMode = SKETCH;
247  else
248  continue;
249  }
250 
252 
253  if( pad->GetLayerSet()[B_Cu] )
254  color = aPlotOpt.ColorSettings()->GetColor( LAYER_PAD_BK );
255 
256  if( pad->GetLayerSet()[F_Cu] )
257  color = color.LegacyMix( aPlotOpt.ColorSettings()->GetColor( LAYER_PAD_FR ) );
258 
259  if( sketchPads && aLayerMask[F_Fab] )
260  color = aPlotOpt.ColorSettings()->GetColor( F_Fab );
261  else if( sketchPads && aLayerMask[B_Fab] )
262  color = aPlotOpt.ColorSettings()->GetColor( B_Fab );
263 
264  wxSize margin;
265  int width_adj = 0;
266 
267  if( onCopperLayer )
268  width_adj = itemplotter.getFineWidthAdj();
269 
270  if( onSolderMaskLayer )
271  margin.x = margin.y = pad->GetSolderMaskMargin();
272 
273  if( onSolderPasteLayer )
274  margin = pad->GetSolderPasteMargin();
275 
276  // Now offset the pad size by margin + width_adj
277  wxSize padPlotsSize = pad->GetSize() + margin * 2 + wxSize( width_adj, width_adj );
278 
279  // Store these parameters that can be modified to plot inflated/deflated pads shape
280  PAD_SHAPE_T padShape = pad->GetShape();
281  wxSize padSize = pad->GetSize();
282  wxSize padDelta = pad->GetDelta(); // has meaning only for trapezoidal pads
283  double padCornerRadius = pad->GetRoundRectCornerRadius();
284 
285  // Don't draw a null size item :
286  if( padPlotsSize.x <= 0 || padPlotsSize.y <= 0 )
287  continue;
288 
289  switch( pad->GetShape() )
290  {
291  case PAD_SHAPE_CIRCLE:
292  case PAD_SHAPE_OVAL:
293  pad->SetSize( padPlotsSize );
294 
295  if( aPlotOpt.GetSkipPlotNPTH_Pads() &&
297  ( pad->GetSize() == pad->GetDrillSize() ) &&
298  ( pad->GetAttribute() == PAD_ATTRIB_HOLE_NOT_PLATED ) )
299  break;
300 
301  itemplotter.PlotPad( pad, color, padPlotMode );
302  break;
303 
304  case PAD_SHAPE_RECT:
305  if( margin.x > 0 )
306  {
307  pad->SetShape( PAD_SHAPE_ROUNDRECT );
308  pad->SetRoundRectCornerRadius( margin.x );
309  }
310 
311  pad->SetSize( padPlotsSize );
312  itemplotter.PlotPad( pad, color, padPlotMode );
313  break;
314 
315  case PAD_SHAPE_TRAPEZOID:
316  {
317  wxSize scale( padPlotsSize.x / padSize.x, padPlotsSize.y / padSize.y );
318  pad->SetDelta( wxSize( padDelta.x * scale.x, padDelta.y * scale.y ) );
319 
320  pad->SetSize( padPlotsSize );
321  itemplotter.PlotPad( pad, color, padPlotMode );
322  }
323  break;
324 
325  case PAD_SHAPE_ROUNDRECT:
327  // Chamfer and rounding are stored as a percent and so don't need scaling
328  pad->SetSize( padPlotsSize );
329  itemplotter.PlotPad( pad, color, padPlotMode );
330  break;
331 
332  case PAD_SHAPE_CUSTOM:
333  {
334  // inflate/deflate a custom shape is a bit complex.
335  // so build a similar pad shape, and inflate/deflate the polygonal shape
336  D_PAD dummy( *pad );
337  SHAPE_POLY_SET shape;
338  pad->MergePrimitivesAsPolygon( &shape );
339  // Shape polygon can have holes so use InflateWithLinkedHoles(), not Inflate()
340  // which can create bad shapes if margin.x is < 0
341  int maxError = aBoard->GetDesignSettings().m_MaxError;
342  int numSegs = std::max( GetArcToSegmentCount( margin.x, maxError, 360.0 ), 6 );
343  shape.InflateWithLinkedHoles( margin.x, numSegs, SHAPE_POLY_SET::PM_FAST );
344  dummy.DeletePrimitivesList();
345  dummy.AddPrimitivePoly( shape, 0 );
346 
347  // Be sure the anchor pad is not bigger than the deflated shape because this
348  // anchor will be added to the pad shape when plotting the pad. So now the
349  // polygonal shape is built, we can clamp the anchor size
350  if( margin.x < 0 ) // we expect margin.x = margin.y for custom pads
351  dummy.SetSize( padPlotsSize );
352 
353  itemplotter.PlotPad( &dummy, color, padPlotMode );
354  }
355  break;
356  }
357 
358  // Restore the pad parameters modified by the plot code
359  pad->SetSize( padSize );
360  pad->SetDelta( padDelta );
361  pad->SetShape( padShape );
362  pad->SetRoundRectCornerRadius( padCornerRadius );
363  }
364 
365  aPlotter->EndBlock( NULL );
366  }
367 
368  // Plot vias on copper layers, and if aPlotOpt.GetPlotViaOnMaskLayer() is true,
369  // plot them on solder mask
370 
371  GBR_METADATA gbr_metadata;
372 
373  bool isOnCopperLayer = ( aLayerMask & LSET::AllCuMask() ).any();
374 
375  if( isOnCopperLayer )
376  {
379  }
380 
381  aPlotter->StartBlock( NULL );
382 
383  for( auto track : aBoard->Tracks() )
384  {
385  const VIA* Via = dyn_cast<const VIA*>( track );
386 
387  if( !Via )
388  continue;
389 
390  // vias are not plotted if not on selected layer, but if layer is SOLDERMASK_LAYER_BACK
391  // or SOLDERMASK_LAYER_FRONT, vias are drawn only if they are on the corresponding
392  // external copper layer
393  LSET via_mask_layer = Via->GetLayerSet();
394 
395  if( aPlotOpt.GetPlotViaOnMaskLayer() )
396  {
397  if( via_mask_layer[B_Cu] )
398  via_mask_layer.set( B_Mask );
399 
400  if( via_mask_layer[F_Cu] )
401  via_mask_layer.set( F_Mask );
402  }
403 
404  if( !( via_mask_layer & aLayerMask ).any() )
405  continue;
406 
407  int via_margin = 0;
408  double width_adj = 0;
409 
410  // If the current layer is a solder mask, use the global mask clearance for vias
411  if( aLayerMask[B_Mask] || aLayerMask[F_Mask] )
412  via_margin = aBoard->GetDesignSettings().m_SolderMaskMargin;
413 
414  if( ( aLayerMask & LSET::AllCuMask() ).any() )
415  width_adj = itemplotter.getFineWidthAdj();
416 
417  int diameter = Via->GetWidth() + 2 * via_margin + width_adj;
418 
419  // Don't draw a null size item :
420  if( diameter <= 0 )
421  continue;
422 
423  // Some vias can be not connected (no net).
424  // Set the m_NotInNet for these vias to force a empty net name in gerber file
425  gbr_metadata.m_NetlistMetadata.m_NotInNet = Via->GetNetname().IsEmpty();
426 
427  gbr_metadata.SetNetName( Via->GetNetname() );
428 
429  COLOR4D color = aPlotOpt.ColorSettings()->GetColor(
430  LAYER_VIAS + static_cast<int>( Via->GetViaType() ) );
431  // Set plot color (change WHITE to LIGHTGRAY because the white items are not seen on a
432  // white paper or screen
433  aPlotter->SetColor( color != WHITE ? color : LIGHTGRAY );
434  aPlotter->FlashPadCircle( Via->GetStart(), diameter, plotMode, &gbr_metadata );
435  }
436 
437  aPlotter->EndBlock( NULL );
438  aPlotter->StartBlock( NULL );
440 
441  // Plot tracks (not vias) :
442  for( auto track : aBoard->Tracks() )
443  {
444  if( track->Type() == PCB_VIA_T )
445  continue;
446 
447  if( !aLayerMask[track->GetLayer()] )
448  continue;
449 
450  // Some track segments can be not connected (no net).
451  // Set the m_NotInNet for these segments to force a empty net name in gerber file
452  gbr_metadata.m_NetlistMetadata.m_NotInNet = track->GetNetname().IsEmpty();
453 
454  gbr_metadata.SetNetName( track->GetNetname() );
455  int width = track->GetWidth() + itemplotter.getFineWidthAdj();
456  aPlotter->SetColor( itemplotter.getColor( track->GetLayer() ) );
457 
458  if( track->Type() == PCB_ARC_T )
459  {
460  ARC* arc = static_cast<ARC*>( track );
461  VECTOR2D center( arc->GetCenter() );
462  auto radius = arc->GetRadius();
463  auto start_angle = arc->GetArcAngleStart();
464  auto end_angle = start_angle + arc->GetAngle();
465 
466  aPlotter->ThickArc( wxPoint( center.x, center.y ), -end_angle, -start_angle,
467  radius, width, plotMode, &gbr_metadata );
468  }
469  else
470  aPlotter->ThickSegment( track->GetStart(), track->GetEnd(), width, plotMode, &gbr_metadata );
471  }
472 
473  aPlotter->EndBlock( NULL );
474 
475  // Plot filled ares
476  aPlotter->StartBlock( NULL );
477 
478  // Plot all zones of the same layer & net together so we don't end up with divots where
479  // zones touch each other.
480  std::set<std::pair<PCB_LAYER_ID, ZONE_CONTAINER*>> plotted;
481 
482  NETINFO_ITEM nonet( aBoard );
483 
484  for( ZONE_CONTAINER* zone : aBoard->Zones() )
485  {
486  for( PCB_LAYER_ID layer : zone->GetLayerSet().Seq() )
487  {
488  auto pair = std::make_pair( layer, zone );
489 
490  if( !aLayerMask[layer] || plotted.count( pair ) )
491  continue;
492 
493  plotted.insert( pair );
494 
495  SHAPE_POLY_SET aggregateArea = zone->GetFilledPolysList( layer );
496  SHAPE_POLY_SET islands;
497  bool needFracture = false; // If 2 or more filled areas are combined, resulting
498  // aggregateArea will be simplified and fractured
499  // (Long calculation time)
500 
501  for( int i = aggregateArea.OutlineCount() - 1; i >= 0; i-- )
502  {
503  if( zone->IsIsland( layer, i ) )
504  {
505  islands.AddOutline( aggregateArea.CPolygon( i )[0] );
506  aggregateArea.DeletePolygon( i );
507  }
508  }
509 
510  for( ZONE_CONTAINER* candidate : aBoard->Zones() )
511  {
512  if( !candidate->IsOnLayer( layer ) )
513  continue;
514 
515  auto candidate_pair = std::make_pair( layer, candidate );
516 
517  if( plotted.count( candidate_pair ) )
518  continue;
519 
520  if( candidate->GetNetCode() != zone->GetNetCode() )
521  continue;
522 
523  // Merging zones of the same net can be done only for areas
524  // having compatible settings for drawings:
525  // use or not outline thickness, and if using outline thickness,
526  // having the same thickness
527  // because after merging only one outline thickness is used
528  if( candidate->GetFilledPolysUseThickness() != zone->GetFilledPolysUseThickness() )
529  // Should not happens, because usually the same option is used for filling
530  continue;
531 
532  if( zone->GetFilledPolysUseThickness()
533  && ( candidate->GetMinThickness() != zone->GetMinThickness() ) )
534  continue;
535 
536  plotted.insert( candidate_pair );
537 
538  SHAPE_POLY_SET candidateArea = candidate->GetFilledPolysList( layer );
539 
540  for( int i = candidateArea.OutlineCount() - 1; i >= 0; i-- )
541  {
542  if( candidate->IsIsland( layer, i ) )
543  {
544  islands.AddOutline( candidateArea.CPolygon( i )[0] );
545  candidateArea.DeletePolygon( i );
546  }
547  }
548 
549  aggregateArea.Append( candidateArea );
550  needFracture = true;
551  }
552 
553  if( needFracture )
554  {
557  }
558 
559  itemplotter.PlotFilledAreas( zone, aggregateArea );
560 
561  if( !islands.IsEmpty() )
562  {
563  ZONE_CONTAINER dummy( *zone );
564  dummy.SetNet( &nonet );
565  itemplotter.PlotFilledAreas( &dummy, islands );
566  }
567  }
568  }
569  aPlotter->EndBlock( NULL );
570 
571  // Adding drill marks, if required and if the plotter is able to plot them:
573  itemplotter.PlotDrillMarks();
574 }
static LSET AllCuMask(int aCuLayerCount=MAX_CU_LAYERS)
Function AllCuMask returns a mask holding the requested number of Cu PCB_LAYER_IDs.
Definition: lset.cpp:712
int m_SolderMaskMargin
Solder mask margin.
ZONE_CONTAINER handles a list of polygons defining a copper zone.
Definition: class_zone.h:61
const POLYGON & CPolygon(int aIndex) const
int OutlineCount() const
Returns the number of outlines in the set
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:486
virtual LSET GetLayerSet() const override
Function GetLayerSet returns a "layer mask", which is a bitmap of all layers on which the TRACK segme...
like PAD_STANDARD, but not plated mechanical use only, no connection allowed
Definition: pad_shapes.h:85
virtual void SetColor(COLOR4D color)=0
const wxPoint & GetStart() const
Definition: class_track.h:118
void SetNetAttribType(int aNetAttribType)
Definition: gbr_metadata.h:170
int color
Definition: DXF_plotter.cpp:61
bool IsEmpty() const
Returns true if the set is empty (no polygons at all)
virtual void StartBlock(void *aData)
calling this function allows one to define the beginning of a group of drawing items,...
Definition: plotter.h:477
class ARC, an arc track segment on a copper layer
Definition: typeinfo.h:98
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Function GetDesignSettings.
Definition: class_board.h:553
Definition: color4d.h:44
PAD_SHAPE_T
Enum PAD_SHAPE_T is the set of pad shapes, used with D_PAD::{Set,Get}Shape()
Definition: pad_shapes.h:33
virtual void ThickArc(const wxPoint &centre, double StAngle, double EndAngle, int rayon, int width, EDA_DRAW_MODE_T tracemode, void *aData)
Definition: plotter.cpp:531
void DeletePolygon(int aIdx)
Deletes aIdx-th polygon from the set
virtual void FlashPadCircle(const wxPoint &aPadPos, int aDiameter, EDA_DRAW_MODE_T aTraceMode, void *aData)=0
virtual function FlashPadCircle
PCB_LAYER_ID
A quick note on layer IDs:
LSET is a set of PCB_LAYER_IDs.
#define NULL
MODULES & Modules()
Definition: class_board.h:266
SHAPE_POLY_SET.
EDA_DRAW_MODE_T
Definition: eda_text.h:63
bool GetSkipPlotNPTH_Pads() const
virtual wxPoint GetCenter() const
Function GetCenter()
double GetRadius() const
const wxString & GetNetname() const
Function GetNetname.
void Fracture(POLYGON_MODE aFastMode)
Converts a set of polygons with holes to a singe outline with "slits"/"fractures" connecting the oute...
aperture used for connected items like tracks (not vias)
Definition: gbr_metadata.h:84
Definition: color4d.h:48
int AddOutline(const SHAPE_LINE_CHAIN &aOutline)
Adds a new outline to the set and returns its index
double GetAngle() const
void SetNetName(const wxString &aNetname)
Definition: gbr_metadata.h:180
COLOR4D GetColor(int aLayer) const
bool GetSketchPadsOnFabLayers() const
NETINFO_ITEM handles the data for a net.
Definition: netinfo.h:65
ZONE_CONTAINERS & Zones()
Definition: class_board.h:280
bool GetPlotViaOnMaskLayer() const
const int scale
smd pads, front layer
int GetWidth() const
Definition: class_track.h:112
static LIB_PART * dummy()
Used to draw a dummy shape when a LIB_PART is not found in library.
virtual void ThickSegment(const wxPoint &start, const wxPoint &end, int width, EDA_DRAW_MODE_T tracemode, void *aData)
Definition: plotter.cpp:507
VIATYPE GetViaType() const
Definition: class_track.h:378
void InflateWithLinkedHoles(int aFactor, int aCircleSegmentsCount, POLYGON_MODE aFastMode)
Performs outline inflation/deflation, using round corners.
void SetApertureAttrib(GBR_APERTURE_METADATA::GBR_APERTURE_ATTRIB aApertAttribute)
Definition: gbr_metadata.h:160
COLOR_SETTINGS * ColorSettings() const
double GetArcAngleStart() const
bool m_NotInNet
true if a pad of a footprint cannot be connected (for instance a mechanical NPTH, ot a not named pad)...
class VIA, a via (like a track segment on a copper layer)
Definition: typeinfo.h:97
GBR_NETLIST_METADATA m_NetlistMetadata
a item to handle object attribute:
Definition: gbr_metadata.h:212
DrillMarksType GetDrillMarksType() const
print info associated to a net (TO.N attribute)
int GetArcToSegmentCount(int aRadius, int aErrorMax, double aArcAngleDegree)
TRACKS & Tracks()
Definition: class_board.h:257
EDA_DRAW_MODE_T GetPlotMode() const
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)
COLOR4D is the color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:99
void Unfracture(POLYGON_MODE aFastMode)
Converts a single outline slitted ("fractured") polygon into a set ouf outlines with holes.

References SHAPE_POLY_SET::AddOutline(), LSET::AllCuMask(), SHAPE_POLY_SET::Append(), B_Cu, B_Fab, B_Mask, B_Paste, BLACK, color, PCB_PLOT_PARAMS::ColorSettings(), SHAPE_POLY_SET::CPolygon(), SHAPE_POLY_SET::DeletePolygon(), dummy(), PLOTTER::EndBlock(), F_Cu, F_Fab, F_Mask, F_Paste, PLOTTER::FlashPadCircle(), SHAPE_POLY_SET::Fracture(), GBR_APERTURE_METADATA::GBR_APERTURE_ATTRIB_CONDUCTOR, GBR_APERTURE_METADATA::GBR_APERTURE_ATTRIB_VIAPAD, GBR_NETLIST_METADATA::GBR_NETINFO_NET, ARC::GetAngle(), ARC::GetArcAngleStart(), GetArcToSegmentCount(), BOARD_ITEM::GetCenter(), COLOR_SETTINGS::GetColor(), BRDITEMS_PLOTTER::getColor(), BOARD::GetDesignSettings(), PCB_PLOT_PARAMS::GetDrillMarksType(), BRDITEMS_PLOTTER::getFineWidthAdj(), VIA::GetLayerSet(), BOARD_CONNECTED_ITEM::GetNetname(), PCB_PLOT_PARAMS::GetPlotMode(), PCB_PLOT_PARAMS::GetPlotViaOnMaskLayer(), ARC::GetRadius(), PCB_PLOT_PARAMS::GetSketchPadsOnFabLayers(), PCB_PLOT_PARAMS::GetSkipPlotNPTH_Pads(), TRACK::GetStart(), VIA::GetViaType(), TRACK::GetWidth(), SHAPE_POLY_SET::InflateWithLinkedHoles(), SHAPE_POLY_SET::IsEmpty(), LAYER_PAD_BK, LAYER_PAD_FR, LAYER_VIAS, LIGHTGRAY, BOARD_DESIGN_SETTINGS::m_MaxError, GBR_METADATA::m_NetlistMetadata, GBR_NETLIST_METADATA::m_NotInNet, BOARD_DESIGN_SETTINGS::m_SolderMaskMargin, BOARD::Modules(), PCB_PLOT_PARAMS::NO_DRILL_SHAPE, NULL, SHAPE_POLY_SET::OutlineCount(), PAD_ATTRIB_HOLE_NOT_PLATED, PAD_SHAPE_CHAMFERED_RECT, PAD_SHAPE_CIRCLE, PAD_SHAPE_CUSTOM, PAD_SHAPE_OVAL, PAD_SHAPE_RECT, PAD_SHAPE_ROUNDRECT, PAD_SHAPE_TRAPEZOID, PCB_ARC_T, PCB_VIA_T, BRDITEMS_PLOTTER::PlotBoardGraphicItems(), BRDITEMS_PLOTTER::PlotDrillMarks(), BRDITEMS_PLOTTER::PlotFilledAreas(), BRDITEMS_PLOTTER::PlotFootprintGraphicItems(), BRDITEMS_PLOTTER::PlotFootprintTextItems(), BRDITEMS_PLOTTER::PlotPad(), SHAPE_POLY_SET::PM_FAST, SHAPE_POLY_SET::PM_STRICTLY_SIMPLE, scale, GBR_METADATA::SetApertureAttrib(), PLOTTER::SetColor(), BRDITEMS_PLOTTER::SetLayerSet(), GBR_METADATA::SetNetAttribType(), GBR_METADATA::SetNetName(), SKETCH, PLOTTER::StartBlock(), PLOTTER::ThickArc(), PLOTTER::ThickSegment(), BOARD::Tracks(), SHAPE_POLY_SET::Unfracture(), WHITE, and BOARD::Zones().

Referenced by PlotOneBoardLayer(), and PlotSolderMaskLayer().

◆ StartPlotBoard()

PLOTTER* StartPlotBoard ( BOARD aBoard,
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 prepare the page for plotting.

Return the plotter object if OK, NULL if the file is not created (or has a problem)

Definition at line 1081 of file plot_board_layers.cpp.

1083 {
1084  // Create the plotter driver and set the few plotter specific options
1085  PLOTTER* plotter = NULL;
1086 
1087  switch( aPlotOpts->GetFormat() )
1088  {
1089  case PLOT_FORMAT::DXF:
1090  DXF_PLOTTER* DXF_plotter;
1091  DXF_plotter = new DXF_PLOTTER();
1092  DXF_plotter->SetUnits(
1093  static_cast<DXF_PLOTTER::DXF_UNITS>( aPlotOpts->GetDXFPlotUnits() ) );
1094 
1095  plotter = DXF_plotter;
1096  break;
1097 
1098  case PLOT_FORMAT::POST:
1099  PS_PLOTTER* PS_plotter;
1100  PS_plotter = new PS_PLOTTER();
1101  PS_plotter->SetScaleAdjust( aPlotOpts->GetFineScaleAdjustX(),
1102  aPlotOpts->GetFineScaleAdjustY() );
1103  plotter = PS_plotter;
1104  break;
1105 
1106  case PLOT_FORMAT::PDF:
1107  plotter = new PDF_PLOTTER();
1108  break;
1109 
1110  case PLOT_FORMAT::HPGL:
1111  HPGL_PLOTTER* HPGL_plotter;
1112  HPGL_plotter = new HPGL_PLOTTER();
1113 
1114  // HPGL options are a little more convoluted to compute, so they get their own function
1115  ConfigureHPGLPenSizes( HPGL_plotter, aPlotOpts );
1116  plotter = HPGL_plotter;
1117  break;
1118 
1119  case PLOT_FORMAT::GERBER:
1120  plotter = new GERBER_PLOTTER();
1121  break;
1122 
1123  case PLOT_FORMAT::SVG:
1124  plotter = new SVG_PLOTTER();
1125  break;
1126 
1127  default:
1128  wxASSERT( false );
1129  return NULL;
1130  }
1131 
1133  renderSettings->LoadColors( aPlotOpts->ColorSettings() );
1134  plotter->SetRenderSettings( renderSettings );
1135 
1136  // Compute the viewport and set the other options
1137 
1138  // page layout is not mirrored, so temporarily change mirror option for the page layout
1139  PCB_PLOT_PARAMS plotOpts = *aPlotOpts;
1140 
1141  if( plotOpts.GetPlotFrameRef() && plotOpts.GetMirror() )
1142  plotOpts.SetMirror( false );
1143 
1144  initializePlotter( plotter, aBoard, &plotOpts );
1145 
1146  if( plotter->OpenFile( aFullFileName ) )
1147  {
1148  plotter->ClearHeaderLinesList();
1149 
1150  // For the Gerber "file function" attribute, set the layer number
1151  if( plotter->GetPlotterType() == PLOT_FORMAT::GERBER )
1152  {
1153  bool useX2mode = plotOpts.GetUseGerberX2format();
1154 
1155  GERBER_PLOTTER* gbrplotter = static_cast <GERBER_PLOTTER*> ( plotter );
1156  gbrplotter->UseX2format( useX2mode );
1157  gbrplotter->UseX2NetAttributes( plotOpts.GetIncludeGerberNetlistInfo() );
1158 
1159  // Attributes can be added using X2 format or as comment (X1 format)
1160  AddGerberX2Attribute( plotter, aBoard, aLayer, not useX2mode );
1161  }
1162 
1163  plotter->StartPlot();
1164 
1165  // Plot the frame reference if requested
1166  if( aPlotOpts->GetPlotFrameRef() )
1167  {
1168  PlotWorkSheet( plotter, aBoard->GetProject(), aBoard->GetTitleBlock(),
1169  aBoard->GetPageSettings(), 1, 1, aSheetDesc, aBoard->GetFileName() );
1170 
1171  if( aPlotOpts->GetMirror() )
1172  initializePlotter( plotter, aBoard, aPlotOpts );
1173  }
1174 
1175  // When plotting a negative board: draw a black rectangle (background for plot board
1176  // in white) and switch the current color to WHITE; note the color inversion is actually
1177  // done in the driver (if supported)
1178  if( aPlotOpts->GetNegative() )
1179  {
1180  EDA_RECT bbox = aBoard->ComputeBoundingBox();
1181  FillNegativeKnockout( plotter, bbox );
1182  }
1183 
1184  return plotter;
1185  }
1186 
1187  delete plotter->RenderSettings();
1188  delete plotter;
1189  return NULL;
1190 }
const PAGE_INFO & GetPageSettings() const
Definition: class_board.h:574
virtual void LoadColors(const COLOR_SETTINGS *aSettings) override
Definition: pcb_painter.cpp:78
void UseX2NetAttributes(bool aEnable)
Definition: plotter.h:1309
bool GetPlotFrameRef() const
static void initializePlotter(PLOTTER *aPlotter, BOARD *aBoard, PCB_PLOT_PARAMS *aPlotOpts)
Set up most plot options for plotting a board (especially the viewport) Important thing: page size is...
virtual bool StartPlot()=0
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.
virtual bool OpenFile(const wxString &aFullFilename)
Open or create the plot file aFullFilename.
Definition: plotter.cpp:77
void SetScaleAdjust(double scaleX, double scaleY)
Set the 'fine' scaling for the postscript engine.
Definition: plotter.h:716
void SetRenderSettings(RENDER_SETTINGS *aSettings)
Definition: plotter.h:146
PROJECT * GetProject() const
Definition: class_board.h:378
void SetMirror(bool aFlag)
void UseX2format(bool aEnable)
Definition: plotter.h:1308
void AddGerberX2Attribute(PLOTTER *aPlotter, const BOARD *aBoard, LAYER_NUM aLayer, bool aUseX1CompatibilityMode)
Calculates some X2 attributes, as defined in the Gerber file format specification and add them to the...
Definition: pcbplot.cpp:354
void SetUnits(DXF_UNITS aUnit)
Set the units to use for plotting the DXF file.
const wxString & GetFileName() const
Definition: class_board.h:255
bool GetUseGerberX2format() const
bool GetMirror() const
PCB_RENDER_SETTINGS Stores PCB specific render settings.
Definition: pcb_painter.h:63
PLOT_FORMAT GetFormat() const
#define NULL
void PlotWorkSheet(PLOTTER *plotter, const PROJECT *aProject, const TITLE_BLOCK &aTitleBlock, const PAGE_INFO &aPageInfo, int aSheetNumber, int aNumberOfSheets, const wxString &aSheetDesc, const wxString &aFilename, COLOR4D aColor)
virtual PLOT_FORMAT GetPlotterType() const =0
Returns the effective plot engine in use.
bool GetIncludeGerberNetlistInfo() const
static void ConfigureHPGLPenSizes(HPGL_PLOTTER *aPlotter, PCB_PLOT_PARAMS *aPlotOpts)
Calculate the effective size of HPGL pens and set them in the plotter object.
PCB_PLOT_PARAMS handles plot parameters and options when plotting/printing a board.
double GetFineScaleAdjustX() const
Base plotter engine class.
Definition: plotter.h:114
RENDER_SETTINGS * RenderSettings()
Definition: plotter.h:147
TITLE_BLOCK & GetTitleBlock()
Definition: class_board.h:580
EDA_RECT handles the component boundary box.
Definition: eda_rect.h:44
void ClearHeaderLinesList()
Function ClearHeaderLinesList remove all lines from the list of free lines to print at the beginning ...
Definition: plotter.h:188
EDA_RECT ComputeBoundingBox(bool aBoardEdgesOnly=false) const
Function ComputeBoundingBox calculates the bounding box containing all board items (or board edge seg...
double GetFineScaleAdjustY() const
COLOR_SETTINGS * ColorSettings() const
bool GetNegative() const
DXF_PLOTTER::DXF_UNITS GetDXFPlotUnits() const

References AddGerberX2Attribute(), PLOTTER::ClearHeaderLinesList(), PCB_PLOT_PARAMS::ColorSettings(), BOARD::ComputeBoundingBox(), ConfigureHPGLPenSizes(), DXF, FillNegativeKnockout(), GERBER, PCB_PLOT_PARAMS::GetDXFPlotUnits(), BOARD::GetFileName(), PCB_PLOT_PARAMS::GetFineScaleAdjustX(), PCB_PLOT_PARAMS::GetFineScaleAdjustY(), PCB_PLOT_PARAMS::GetFormat(), PCB_PLOT_PARAMS::GetIncludeGerberNetlistInfo(), PCB_PLOT_PARAMS::GetMirror(), PCB_PLOT_PARAMS::GetNegative(), BOARD::GetPageSettings(), PCB_PLOT_PARAMS::GetPlotFrameRef(), PLOTTER::GetPlotterType(), BOARD::GetProject(), BOARD::GetTitleBlock(), PCB_PLOT_PARAMS::GetUseGerberX2format(), HPGL, initializePlotter(), KIGFX::PCB_RENDER_SETTINGS::LoadColors(), NULL, PLOTTER::OpenFile(), PDF, PlotWorkSheet(), POST, PLOTTER::RenderSettings(), PCB_PLOT_PARAMS::SetMirror(), PLOTTER::SetRenderSettings(), PSLIKE_PLOTTER::SetScaleAdjust(), DXF_PLOTTER::SetUnits(), PLOTTER::StartPlot(), SVG, GERBER_PLOTTER::UseX2format(), and GERBER_PLOTTER::UseX2NetAttributes().

Referenced by DIALOG_EXPORT_SVG::CreateSVGFile(), PLOT_CONTROLLER::OpenPlotfile(), and DIALOG_PLOT::Plot().