KiCad PCB EDA Suite
pcbplot.h File Reference

Board plot function definition file. More...

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
 

Functions

PLOTTERStartPlotBoard (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 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.

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 350 of file pcbplot.cpp.

352 {
353  AddGerberX2Header( aPlotter, aBoard, aUseX1CompatibilityMode );
354 
355  wxString text;
356 
357  // Add the TF.FileFunction
358  text = GetGerberFileFunctionAttribute( aBoard, aLayer );
359  aPlotter->AddLineToHeader( makeStringCompatX1( text, aUseX1CompatibilityMode ) );
360 
361  // Add the TF.FilePolarity (for layers which support that)
363 
364  if( !text.IsEmpty() )
365  aPlotter->AddLineToHeader( makeStringCompatX1( text, aUseX1CompatibilityMode ) );
366 }
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:279
void AddLineToHeader(const wxString &aExtraString)
Add a line to the list of free lines to print at the beginning of the file.
Definition: plotter.h:180
static const wxString GetGerberFilePolarityAttribute(LAYER_NUM aLayer)
Definition: pcbplot.cpp:208
static wxString & makeStringCompatX1(wxString &aText, bool aUseX1CompatibilityMode)
Definition: pcbplot.cpp:267
const wxString GetGerberFileFunctionAttribute(const BOARD *aBoard, LAYER_NUM aLayer)
Function GetGerberFileFunctionAttribute Returns the "file function" attribute for aLayer,...
Definition: pcbplot.cpp:86

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

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 279 of file pcbplot.cpp.

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

References PLOTTER::AddLineToHeader(), ExpandTextVars(), GBR_NC_STRING_FORMAT_X1, GBR_NC_STRING_FORMAT_X2, GbrMakeCreationDateAttributeString(), GbrMakeProjectGUIDfromString(), GetBuildVersion(), BOARD::GetDesignSettings(), BOARD::GetFileName(), BOARD::GetPlotOptions(), BOARD::GetProject(), TITLE_BLOCK::GetRevision(), BOARD::GetTitleBlock(), PCB_PLOT_PARAMS::GetUseAuxOrigin(), BOARD_DESIGN_SETTINGS::m_AuxOrigin, makeStringCompatX1(), and text.

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 369 of file pcbplot.cpp.

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

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 86 of file pcbplot.cpp.

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

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, 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 45 of file pcbplot.cpp.

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

634 {
635  BRDITEMS_PLOTTER itemplotter( aPlotter, aBoard, aPlotOpt );
636  itemplotter.SetLayerSet( aLayerMask );
637 
638  SHAPE_POLY_SET outlines;
639 
640  for( LSEQ seq = aLayerMask.Seq( plot_seq, arrayDim( plot_seq ) ); seq; ++seq )
641  {
642  PCB_LAYER_ID layer = *seq;
643 
644  outlines.RemoveAllContours();
645  aBoard->ConvertBrdLayerToPolygonalContours( layer, outlines );
646 
647  outlines.Simplify( SHAPE_POLY_SET::PM_FAST );
648 
649  // Plot outlines
650  std::vector<wxPoint> cornerList;
651 
652  // Now we have one or more basic polygons: plot each polygon
653  for( int ii = 0; ii < outlines.OutlineCount(); ii++ )
654  {
655  for( int kk = 0; kk <= outlines.HoleCount(ii); kk++ )
656  {
657  cornerList.clear();
658  const SHAPE_LINE_CHAIN& path = (kk == 0) ? outlines.COutline( ii ) : outlines.CHole( ii, kk - 1 );
659 
660  for( int jj = 0; jj < path.PointCount(); jj++ )
661  cornerList.emplace_back( (wxPoint) path.CPoint( jj ) );
662 
663  // Ensure the polygon is closed
664  if( cornerList[0] != cornerList[cornerList.size() - 1] )
665  cornerList.push_back( cornerList[0] );
666 
667  aPlotter->PlotPoly( cornerList, FILL_TYPE::NO_FILL );
668  }
669  }
670 
671  // Plot pad holes
673  {
674  int smallDrill = (aPlotOpt.GetDrillMarksType() == PCB_PLOT_PARAMS::SMALL_DRILL_SHAPE)
676 
677  for( FOOTPRINT* footprint : aBoard->Footprints() )
678  {
679  for( PAD* pad : footprint->Pads() )
680  {
681  wxSize hole = pad->GetDrillSize();
682 
683  if( hole.x == 0 || hole.y == 0 )
684  continue;
685 
686  if( hole.x == hole.y )
687  {
688  hole.x = std::min( smallDrill, hole.x );
689  aPlotter->Circle( pad->GetPosition(), hole.x, FILL_TYPE::NO_FILL );
690  }
691  else
692  {
693  // Note: small drill marks have no significance when applied to slots
694  const SHAPE_SEGMENT* seg = pad->GetEffectiveHoleShape();
695  aPlotter->ThickSegment( (wxPoint) seg->GetSeg().A,
696  (wxPoint) seg->GetSeg().B,
697  seg->GetWidth(), SKETCH, NULL );
698  }
699  }
700  }
701  }
702 
703  // Plot vias holes
704  for( TRACK* track : aBoard->Tracks() )
705  {
706  const VIA* via = dyn_cast<const VIA*>( track );
707 
708  if( via && via->IsOnLayer( layer ) ) // via holes can be not through holes
709  {
710  aPlotter->Circle( via->GetPosition(), via->GetDrillValue(), FILL_TYPE::NO_FILL );
711  }
712  }
713  }
714 }
Definition: track.h:343
int OutlineCount() const
Return the number of vertices in a given outline/hole.
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,...
static const PCB_LAYER_ID plot_seq[]
virtual void PlotPoly(const std::vector< wxPoint > &aCornerList, FILL_TYPE aFill, int aWidth=USE_DEFAULT_LINE_WIDTH, void *aData=NULL)=0
Draw a polygon ( filled or not )
const SHAPE_LINE_CHAIN & CHole(int aOutline, int aHole) const
double m_SmallDrillMarkSize
The diameter of the drill marks on print and plot outputs (in mm), when the "Drill marks" option is s...
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
virtual void ThickSegment(const wxPoint &start, const wxPoint &end, int width, OUTLINE_MODE tracemode, void *aData)
Definition: plotter.cpp:506
const SEG & GetSeg() const
PCB_LAYER_ID
A quick note on layer IDs:
#define NULL
Represent a set of closed polygons.
FOOTPRINTS & Footprints()
Definition: board.h:305
constexpr std::size_t arrayDim(T const (&)[N]) noexcept
Returns # of elements in an array.
Definition: arraydim.h:31
void Simplify(POLYGON_MODE aFastMode)
virtual void Circle(const wxPoint &pos, int diametre, FILL_TYPE fill, int width=USE_DEFAULT_LINE_WIDTH)=0
int HoleCount(int aOutline) const
Return the reference to aIndex-th outline in the set.
LSEQ is a sequence (and therefore also a set) of PCB_LAYER_IDs.
SHAPE_LINE_CHAIN.
const SHAPE_LINE_CHAIN & COutline(int aIndex) const
VECTOR2I A
Definition: seg.h:49
static const ADVANCED_CFG & GetCfg()
Get the singleton instance's config, which is shared by all consumers.
Definition: pad.h:60
DrillMarksType GetDrillMarksType() const
int GetWidth() const
TRACKS & Tracks()
Definition: board.h:302
Definition: track.h:83
VECTOR2I B
Definition: seg.h:50

References SEG::A, arrayDim(), SEG::B, SHAPE_POLY_SET::CHole(), PLOTTER::Circle(), BOARD::ConvertBrdLayerToPolygonalContours(), SHAPE_POLY_SET::COutline(), BOARD::Footprints(), ADVANCED_CFG::GetCfg(), PCB_PLOT_PARAMS::GetDrillMarksType(), SHAPE_SEGMENT::GetSeg(), SHAPE_SEGMENT::GetWidth(), SHAPE_POLY_SET::HoleCount(), ADVANCED_CFG::m_SmallDrillMarkSize, PCB_PLOT_PARAMS::NO_DRILL_SHAPE, NO_FILL, NULL, SHAPE_POLY_SET::OutlineCount(), pad, path, plot_seq, PLOTTER::PlotPoly(), SHAPE_POLY_SET::PM_FAST, SHAPE_POLY_SET::RemoveAllContours(), LSET::Seq(), BRDITEMS_PLOTTER::SetLayerSet(), SHAPE_POLY_SET::Simplify(), SKETCH, PCB_PLOT_PARAMS::SMALL_DRILL_SHAPE, PLOTTER::ThickSegment(), BOARD::Tracks(), and via.

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 63 of file plot_board_layers.cpp.

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

References B_Adhes, B_CrtYd, B_Fab, B_Mask, B_Paste, B_SilkS, BLACK, Cmts_User, Dwgs_User, DXF, Eco1_User, Eco2_User, Edge_Cuts, F_Adhes, F_CrtYd, F_Fab, F_Mask, F_Paste, F_SilkS, GERBER, 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

pads not connected to copper are optionally not drawn

Vias not connected to copper are optionally not drawn

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  OUTLINE_MODE 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( const FOOTPRINT* footprint : aBoard->Footprints() )
226  itemplotter.PlotFootprintTextItems( footprint );
227 
228  // Draw footprint other graphic items:
229  for( const FOOTPRINT* footprint : aBoard->Footprints() )
230  itemplotter.PlotFootprintGraphicItems( footprint );
231 
232  // Plot footprint pads
233  for( FOOTPRINT* footprint : aBoard->Footprints() )
234  {
235  aPlotter->StartBlock( NULL );
236 
237  for( PAD* pad : footprint->Pads() )
238  {
239  OUTLINE_MODE 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  if( onCopperLayer && !pad->FlashLayer( aLayerMask ) )
253  continue;
254 
256 
257  if( pad->GetLayerSet()[B_Cu] )
258  color = aPlotOpt.ColorSettings()->GetColor( LAYER_PAD_BK );
259 
260  if( pad->GetLayerSet()[F_Cu] )
261  color = color.LegacyMix( aPlotOpt.ColorSettings()->GetColor( LAYER_PAD_FR ) );
262 
263  if( sketchPads && aLayerMask[F_Fab] )
264  color = aPlotOpt.ColorSettings()->GetColor( F_Fab );
265  else if( sketchPads && aLayerMask[B_Fab] )
266  color = aPlotOpt.ColorSettings()->GetColor( B_Fab );
267 
268  wxSize margin;
269  int width_adj = 0;
270 
271  if( onCopperLayer )
272  width_adj = itemplotter.getFineWidthAdj();
273 
274  if( onSolderMaskLayer )
275  margin.x = margin.y = pad->GetSolderMaskMargin();
276 
277  if( onSolderPasteLayer )
278  margin = pad->GetSolderPasteMargin();
279 
280  // not all shapes can have a different margin for x and y axis
281  // in fact only oval and rect shapes can have different values.
282  // Round shape have always the same x,y margin
283  // so define a unique value for other shapes that do not support different values
284  int mask_clearance = margin.x;
285 
286  // Now offset the pad size by margin + width_adj
287  wxSize padPlotsSize = pad->GetSize() + margin * 2 + wxSize( width_adj, width_adj );
288 
289  // Store these parameters that can be modified to plot inflated/deflated pads shape
290  PAD_SHAPE_T padShape = pad->GetShape();
291  wxSize padSize = pad->GetSize();
292  wxSize padDelta = pad->GetDelta(); // has meaning only for trapezoidal pads
293  double padCornerRadius = pad->GetRoundRectCornerRadius();
294 
295  // Don't draw a null size item :
296  if( padPlotsSize.x <= 0 || padPlotsSize.y <= 0 )
297  continue;
298 
299  switch( pad->GetShape() )
300  {
301  case PAD_SHAPE_CIRCLE:
302  case PAD_SHAPE_OVAL:
303  pad->SetSize( padPlotsSize );
304 
305  if( aPlotOpt.GetSkipPlotNPTH_Pads() &&
307  ( pad->GetSize() == pad->GetDrillSize() ) &&
308  ( pad->GetAttribute() == PAD_ATTRIB_NPTH ) )
309  break;
310 
311  itemplotter.PlotPad( pad, color, padPlotMode );
312  break;
313 
314  case PAD_SHAPE_RECT:
315  pad->SetSize( padPlotsSize );
316 
317  if( mask_clearance > 0 )
318  {
319  pad->SetShape( PAD_SHAPE_ROUNDRECT );
320  pad->SetRoundRectCornerRadius( mask_clearance );
321  }
322 
323  itemplotter.PlotPad( pad, color, padPlotMode );
324  break;
325 
326  case PAD_SHAPE_TRAPEZOID:
327  // inflate/deflate a trapezoid is a bit complex.
328  // so if the margin is not null, build a similar polygonal pad shape,
329  // and inflate/deflate the polygonal shape
330  // because inflating/deflating using different values for y and y
331  // we are using only margin.x as inflate/deflate value
332  if( mask_clearance == 0 )
333  itemplotter.PlotPad( pad, color, padPlotMode );
334  else
335  {
336  PAD dummy( *pad );
337  dummy.SetAnchorPadShape( PAD_SHAPE_CIRCLE );
338  dummy.SetShape( PAD_SHAPE_CUSTOM );
339  SHAPE_POLY_SET outline;
340  outline.NewOutline();
341  int dx = padSize.x / 2;
342  int dy = padSize.y / 2;
343  int ddx = padDelta.x / 2;
344  int ddy = padDelta.y / 2;
345 
346  outline.Append( -dx - ddy, dy + ddx );
347  outline.Append( dx + ddy, dy - ddx );
348  outline.Append( dx - ddy, -dy + ddx );
349  outline.Append( -dx + ddy, -dy - ddx );
350 
351  // Shape polygon can have holes so use InflateWithLinkedHoles(), not Inflate()
352  // which can create bad shapes if margin.x is < 0
353  int maxError = aBoard->GetDesignSettings().m_MaxError;
354  int numSegs = GetArcToSegmentCount( mask_clearance, maxError, 360.0 );
355  outline.InflateWithLinkedHoles( mask_clearance, numSegs, SHAPE_POLY_SET::PM_FAST );
356  dummy.DeletePrimitivesList();
357  dummy.AddPrimitivePoly( outline, 0, true );
358 
359  // Be sure the anchor pad is not bigger than the deflated shape because this
360  // anchor will be added to the pad shape when plotting the pad. So now the
361  // polygonal shape is built, we can clamp the anchor size
362  dummy.SetSize( wxSize( 0,0 ) );
363 
364  itemplotter.PlotPad( &dummy, color, padPlotMode );
365  }
366 
367  break;
368 
369  case PAD_SHAPE_ROUNDRECT:
371  // Chamfer and rounding are stored as a percent and so don't need scaling
372  pad->SetSize( padPlotsSize );
373  itemplotter.PlotPad( pad, color, padPlotMode );
374  break;
375 
376  case PAD_SHAPE_CUSTOM:
377  {
378  // inflate/deflate a custom shape is a bit complex.
379  // so build a similar pad shape, and inflate/deflate the polygonal shape
380  PAD dummy( *pad );
381  SHAPE_POLY_SET shape;
382  pad->MergePrimitivesAsPolygon( &shape, UNDEFINED_LAYER );
383  // Shape polygon can have holes so use InflateWithLinkedHoles(), not Inflate()
384  // which can create bad shapes if margin.x is < 0
385  int maxError = aBoard->GetDesignSettings().m_MaxError;
386  int numSegs = GetArcToSegmentCount( mask_clearance, maxError, 360.0 );
387  shape.InflateWithLinkedHoles( mask_clearance, numSegs, SHAPE_POLY_SET::PM_FAST );
388  dummy.DeletePrimitivesList();
389  dummy.AddPrimitivePoly( shape, 0, true );
390 
391  // Be sure the anchor pad is not bigger than the deflated shape because this
392  // anchor will be added to the pad shape when plotting the pad. So now the
393  // polygonal shape is built, we can clamp the anchor size
394  if( mask_clearance < 0 ) // we expect margin.x = margin.y for custom pads
395  dummy.SetSize( padPlotsSize );
396 
397  itemplotter.PlotPad( &dummy, color, padPlotMode );
398  }
399  break;
400  }
401 
402  // Restore the pad parameters modified by the plot code
403  pad->SetSize( padSize );
404  pad->SetDelta( padDelta );
405  pad->SetShape( padShape );
406  pad->SetRoundRectCornerRadius( padCornerRadius );
407  }
408 
409  aPlotter->EndBlock( NULL );
410  }
411 
412  // Plot vias on copper layers, and if aPlotOpt.GetPlotViaOnMaskLayer() is true,
413  // plot them on solder mask
414 
415  GBR_METADATA gbr_metadata;
416 
417  bool isOnCopperLayer = ( aLayerMask & LSET::AllCuMask() ).any();
418 
419  if( isOnCopperLayer )
420  {
423  }
424 
425  aPlotter->StartBlock( NULL );
426 
427  for( const TRACK* track : aBoard->Tracks() )
428  {
429  const VIA* via = dyn_cast<const VIA*>( track );
430 
431  if( !via )
432  continue;
433 
434  // vias are not plotted if not on selected layer, but if layer is SOLDERMASK_LAYER_BACK
435  // or SOLDERMASK_LAYER_FRONT, vias are drawn only if they are on the corresponding
436  // external copper layer
437  LSET via_mask_layer = via->GetLayerSet();
438 
439  if( aPlotOpt.GetPlotViaOnMaskLayer() )
440  {
441  if( via_mask_layer[B_Cu] )
442  via_mask_layer.set( B_Mask );
443 
444  if( via_mask_layer[F_Cu] )
445  via_mask_layer.set( F_Mask );
446  }
447 
448  if( !( via_mask_layer & aLayerMask ).any() )
449  continue;
450 
451  int via_margin = 0;
452  double width_adj = 0;
453 
454  // If the current layer is a solder mask, use the global mask clearance for vias
455  if( aLayerMask[B_Mask] || aLayerMask[F_Mask] )
456  via_margin = aBoard->GetDesignSettings().m_SolderMaskMargin;
457 
458  if( ( aLayerMask & LSET::AllCuMask() ).any() )
459  width_adj = itemplotter.getFineWidthAdj();
460 
461  int diameter = via->GetWidth() + 2 * via_margin + width_adj;
462 
464  if( onCopperLayer && !via->FlashLayer( aLayerMask ) )
465  continue;
466 
467  // Don't draw a null size item :
468  if( diameter <= 0 )
469  continue;
470 
471  // Some vias can be not connected (no net).
472  // Set the m_NotInNet for these vias to force a empty net name in gerber file
473  gbr_metadata.m_NetlistMetadata.m_NotInNet = via->GetNetname().IsEmpty();
474 
475  gbr_metadata.SetNetName( via->GetNetname() );
476 
477  COLOR4D color = aPlotOpt.ColorSettings()->GetColor(
478  LAYER_VIAS + static_cast<int>( via->GetViaType() ) );
479  // Set plot color (change WHITE to LIGHTGRAY because the white items are not seen on a
480  // white paper or screen
481  aPlotter->SetColor( color != WHITE ? color : LIGHTGRAY );
482  aPlotter->FlashPadCircle( via->GetStart(), diameter, plotMode, &gbr_metadata );
483  }
484 
485  aPlotter->EndBlock( NULL );
486  aPlotter->StartBlock( NULL );
488 
489  // Plot tracks (not vias) :
490  for( const TRACK* track : aBoard->Tracks() )
491  {
492  if( track->Type() == PCB_VIA_T )
493  continue;
494 
495  if( !aLayerMask[track->GetLayer()] )
496  continue;
497 
498  // Some track segments can be not connected (no net).
499  // Set the m_NotInNet for these segments to force a empty net name in gerber file
500  gbr_metadata.m_NetlistMetadata.m_NotInNet = track->GetNetname().IsEmpty();
501 
502  gbr_metadata.SetNetName( track->GetNetname() );
503  int width = track->GetWidth() + itemplotter.getFineWidthAdj();
504  aPlotter->SetColor( itemplotter.getColor( track->GetLayer() ) );
505 
506  if( track->Type() == PCB_ARC_T )
507  {
508  const ARC* arc = static_cast<const ARC*>( track );
509  VECTOR2D center( arc->GetCenter() );
510  int radius = arc->GetRadius();
511  double start_angle = arc->GetArcAngleStart();
512  double end_angle = start_angle + arc->GetAngle();
513 
514  aPlotter->ThickArc( wxPoint( center.x, center.y ), -end_angle, -start_angle,
515  radius, width, plotMode, &gbr_metadata );
516  }
517  else
518  {
519  aPlotter->ThickSegment( track->GetStart(), track->GetEnd(), width, plotMode,
520  &gbr_metadata );
521  }
522 
523  }
524 
525  aPlotter->EndBlock( NULL );
526 
527  // Plot filled ares
528  aPlotter->StartBlock( NULL );
529 
530  NETINFO_ITEM nonet( aBoard );
531 
532  for( const ZONE* zone : aBoard->Zones() )
533  {
534  for( PCB_LAYER_ID layer : zone->GetLayerSet().Seq() )
535  {
536  if( !aLayerMask[layer] )
537  continue;
538 
539  SHAPE_POLY_SET mainArea = zone->GetFilledPolysList( layer );
540  SHAPE_POLY_SET islands;
541 
542  for( int i = mainArea.OutlineCount() - 1; i >= 0; i-- )
543  {
544  if( zone->IsIsland( layer, i ) )
545  {
546  islands.AddOutline( mainArea.CPolygon( i )[0] );
547  mainArea.DeletePolygon( i );
548  }
549  }
550 
551  itemplotter.PlotFilledAreas( zone, mainArea );
552 
553  if( !islands.IsEmpty() )
554  {
555  ZONE dummy( *zone );
556  dummy.SetNet( &nonet );
557  itemplotter.PlotFilledAreas( &dummy, islands );
558  }
559  }
560  }
561 
562  aPlotter->EndBlock( NULL );
563 
564  // Adding drill marks, if required and if the plotter is able to plot them:
566  itemplotter.PlotDrillMarks();
567 }
static LSET AllCuMask(int aCuLayerCount=MAX_CU_LAYERS)
Return a mask holding the requested number of Cu PCB_LAYER_IDs.
Definition: lset.cpp:750
OUTLINE_MODE GetPlotMode() const
OUTLINE_MODE
Definition: outline_mode.h:24
Definition: track.h:343
virtual wxPoint GetCenter() const override
This defaults to the center of the bounding box if not overridden.
Definition: track.h:301
const POLYGON & CPolygon(int aIndex) const
int OutlineCount() const
Return the number of vertices in a given outline/hole.
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:484
ZONES & Zones()
Definition: board.h:311
virtual void SetColor(COLOR4D color)=0
void SetNetAttribType(int aNetAttribType)
Definition: gbr_metadata.h:219
int color
Definition: DXF_plotter.cpp:60
bool IsEmpty() const
virtual void StartBlock(void *aData)
calling this function allows one to define the beginning of a group of drawing items,...
Definition: plotter.h:475
class ARC, an arc track segment on a copper layer
Definition: typeinfo.h:97
static LIB_PART * dummy()
Used to draw a dummy shape when a LIB_PART is not found in library.
Definition: sch_symbol.cpp:69
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Definition: board.h:593
Definition: color4d.h:44
like PAD_PTH, but not plated mechanical use only, no connection allowed
Definition: pad_shapes.h:85
virtual void ThickSegment(const wxPoint &start, const wxPoint &end, int width, OUTLINE_MODE tracemode, void *aData)
Definition: plotter.cpp:506
PAD_SHAPE_T
The set of pad shapes, used with PAD::{Set,Get}Shape()
Definition: pad_shapes.h:32
void DeletePolygon(int aIdx)
PCB_LAYER_ID
A quick note on layer IDs:
LSET is a set of PCB_LAYER_IDs.
#define NULL
Represent a set of closed polygons.
FOOTPRINTS & Footprints()
Definition: board.h:305
bool GetSkipPlotNPTH_Pads() const
Handle a list of polygons defining a copper zone.
Definition: zone.h:57
double GetRadius() const
Definition: track.cpp:932
Metadata which can be added in a gerber file as attribute in X2 format.
Definition: gbr_metadata.h:204
int NewOutline()
Creates a new hole in a given outline.
Definition: color4d.h:48
int AddOutline(const SHAPE_LINE_CHAIN &aOutline)
Adds a new hole to the given outline (default: last) and returns its index.
double GetAngle() const
Definition: track.cpp:938
void SetNetName(const wxString &aNetname)
Definition: gbr_metadata.h:229
COLOR4D GetColor(int aLayer) const
bool GetSketchPadsOnFabLayers() const
Handle the data for a net.
Definition: netinfo.h:64
bool GetPlotViaOnMaskLayer() const
smd pads, front layer
Meta control for all vias opacity/visibility.
Definition: track.h:262
void InflateWithLinkedHoles(int aFactor, int aCircleSegmentsCount, POLYGON_MODE aFastMode)
Perform outline inflation/deflation, using round corners.
virtual void ThickArc(const wxPoint &centre, double StAngle, double EndAngle, int rayon, int width, OUTLINE_MODE tracemode, void *aData)
Definition: plotter.cpp:530
void SetApertureAttrib(GBR_APERTURE_METADATA::GBR_APERTURE_ATTRIB aApertAttribute)
Definition: gbr_metadata.h:209
COLOR_SETTINGS * ColorSettings() const
double GetArcAngleStart() const
Definition: track.cpp:950
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:96
GBR_NETLIST_METADATA m_NetlistMetadata
An item to handle object attribute.
Definition: gbr_metadata.h:262
Definition: pad.h:60
DrillMarksType GetDrillMarksType() const
print info associated to a net (TO.N attribute)
int GetArcToSegmentCount(int aRadius, int aErrorMax, double aArcAngleDegree)
TRACKS & Tracks()
Definition: board.h:302
Definition: track.h:83
virtual void FlashPadCircle(const wxPoint &aPadPos, int aDiameter, OUTLINE_MODE aTraceMode, void *aData)=0
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:98

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(), BOARD::Footprints(), 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(), ARC::GetCenter(), COLOR_SETTINGS::GetColor(), BRDITEMS_PLOTTER::getColor(), BOARD::GetDesignSettings(), PCB_PLOT_PARAMS::GetDrillMarksType(), BRDITEMS_PLOTTER::getFineWidthAdj(), PCB_PLOT_PARAMS::GetPlotMode(), PCB_PLOT_PARAMS::GetPlotViaOnMaskLayer(), ARC::GetRadius(), PCB_PLOT_PARAMS::GetSketchPadsOnFabLayers(), PCB_PLOT_PARAMS::GetSkipPlotNPTH_Pads(), 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, SHAPE_POLY_SET::NewOutline(), PCB_PLOT_PARAMS::NO_DRILL_SHAPE, NULL, SHAPE_POLY_SET::OutlineCount(), pad, PAD_ATTRIB_NPTH, 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, GBR_METADATA::SetApertureAttrib(), PLOTTER::SetColor(), BRDITEMS_PLOTTER::SetLayerSet(), GBR_METADATA::SetNetAttribType(), GBR_METADATA::SetNetName(), SKETCH, PLOTTER::StartBlock(), PLOTTER::ThickArc(), PLOTTER::ThickSegment(), BOARD::Tracks(), UNDEFINED_LAYER, via, WHITE, and BOARD::Zones().

Referenced by PlotOneBoardLayer(), and PlotSolderMaskLayer().

◆ StartPlotBoard()

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 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 1063 of file plot_board_layers.cpp.

1065 {
1066  // Create the plotter driver and set the few plotter specific options
1067  PLOTTER* plotter = NULL;
1068 
1069  switch( aPlotOpts->GetFormat() )
1070  {
1071  case PLOT_FORMAT::DXF:
1072  DXF_PLOTTER* DXF_plotter;
1073  DXF_plotter = new DXF_PLOTTER();
1074  DXF_plotter->SetUnits( aPlotOpts->GetDXFPlotUnits() );
1075 
1076  plotter = DXF_plotter;
1077  break;
1078 
1079  case PLOT_FORMAT::POST:
1080  PS_PLOTTER* PS_plotter;
1081  PS_plotter = new PS_PLOTTER();
1082  PS_plotter->SetScaleAdjust( aPlotOpts->GetFineScaleAdjustX(),
1083  aPlotOpts->GetFineScaleAdjustY() );
1084  plotter = PS_plotter;
1085  break;
1086 
1087  case PLOT_FORMAT::PDF:
1088  plotter = new PDF_PLOTTER();
1089  break;
1090 
1091  case PLOT_FORMAT::HPGL:
1092  HPGL_PLOTTER* HPGL_plotter;
1093  HPGL_plotter = new HPGL_PLOTTER();
1094 
1095  // HPGL options are a little more convoluted to compute, so they get their own function
1096  ConfigureHPGLPenSizes( HPGL_plotter, aPlotOpts );
1097  plotter = HPGL_plotter;
1098  break;
1099 
1100  case PLOT_FORMAT::GERBER:
1101  plotter = new GERBER_PLOTTER();
1102  break;
1103 
1104  case PLOT_FORMAT::SVG:
1105  plotter = new SVG_PLOTTER();
1106  break;
1107 
1108  default:
1109  wxASSERT( false );
1110  return NULL;
1111  }
1112 
1114  renderSettings->LoadColors( aPlotOpts->ColorSettings() );
1115  renderSettings->SetDefaultPenWidth( Millimeter2iu( 0.0212 ) ); // Hairline at 1200dpi
1116  plotter->SetRenderSettings( renderSettings );
1117 
1118  // Compute the viewport and set the other options
1119 
1120  // page layout is not mirrored, so temporarily change mirror option for the page layout
1121  PCB_PLOT_PARAMS plotOpts = *aPlotOpts;
1122 
1123  if( plotOpts.GetPlotFrameRef() && plotOpts.GetMirror() )
1124  plotOpts.SetMirror( false );
1125 
1126  initializePlotter( plotter, aBoard, &plotOpts );
1127 
1128  if( plotter->OpenFile( aFullFileName ) )
1129  {
1130  plotter->ClearHeaderLinesList();
1131 
1132  // For the Gerber "file function" attribute, set the layer number
1133  if( plotter->GetPlotterType() == PLOT_FORMAT::GERBER )
1134  {
1135  bool useX2mode = plotOpts.GetUseGerberX2format();
1136 
1137  GERBER_PLOTTER* gbrplotter = static_cast <GERBER_PLOTTER*> ( plotter );
1138  gbrplotter->DisableApertMacros( plotOpts.GetDisableGerberMacros() );
1139  gbrplotter->UseX2format( useX2mode );
1140  gbrplotter->UseX2NetAttributes( plotOpts.GetIncludeGerberNetlistInfo() );
1141 
1142  // Attributes can be added using X2 format or as comment (X1 format)
1143  AddGerberX2Attribute( plotter, aBoard, aLayer, not useX2mode );
1144  }
1145 
1146  plotter->StartPlot();
1147 
1148  // Plot the frame reference if requested
1149  if( aPlotOpts->GetPlotFrameRef() )
1150  {
1151  PlotDrawingSheet( plotter, aBoard->GetProject(), aBoard->GetTitleBlock(),
1152  aBoard->GetPageSettings(), "1", 1, aSheetDesc,
1153  aBoard->GetFileName() );
1154 
1155  if( aPlotOpts->GetMirror() )
1156  initializePlotter( plotter, aBoard, aPlotOpts );
1157  }
1158 
1159  // When plotting a negative board: draw a black rectangle (background for plot board
1160  // in white) and switch the current color to WHITE; note the color inversion is actually
1161  // done in the driver (if supported)
1162  if( aPlotOpts->GetNegative() )
1163  {
1164  EDA_RECT bbox = aBoard->ComputeBoundingBox();
1165  FillNegativeKnockout( plotter, bbox );
1166  }
1167 
1168  return plotter;
1169  }
1170 
1171  delete plotter->RenderSettings();
1172  delete plotter;
1173  return NULL;
1174 }
const PAGE_INFO & GetPageSettings() const
Definition: board.h:608
virtual void LoadColors(const COLOR_SETTINGS *aSettings) override
Definition: pcb_painter.cpp:87
void UseX2NetAttributes(bool aEnable)
bool GetPlotFrameRef() const
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:76
bool GetDisableGerberMacros() const
void SetScaleAdjust(double scaleX, double scaleY)
Set the 'fine' scaling for the postscript engine.
void SetRenderSettings(RENDER_SETTINGS *aSettings)
Definition: plotter.h:154
PROJECT * GetProject() const
Definition: board.h:432
void SetMirror(bool aFlag)
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.
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:350
void SetUnits(DXF_UNITS aUnit)
Set the units to use for plotting the DXF file.
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...
const wxString & GetFileName() const
Definition: board.h:300
bool GetUseGerberX2format() const
bool GetMirror() const
PCB specific render settings.
Definition: pcb_painter.h:64
PLOT_FORMAT GetFormat() const
#define NULL
virtual PLOT_FORMAT GetPlotterType() const =0
Returns the effective plot engine in use.
bool GetIncludeGerberNetlistInfo() const
PCB_PLOT_PARAMS handles plot parameters and options when plotting/printing a board.
double GetFineScaleAdjustX() const
void DisableApertMacros(bool aDisable)
Disable Aperture Macro (AM) command, only for broken Gerber Readers Regions will be used instead of A...
Base plotter engine class.
Definition: plotter.h:121
RENDER_SETTINGS * RenderSettings()
Definition: plotter.h:155
TITLE_BLOCK & GetTitleBlock()
Definition: board.h:614
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)
Handle the component boundary box.
Definition: eda_rect.h:42
void ClearHeaderLinesList()
Remove all lines from the list of free lines to print at the beginning of the file.
Definition: plotter.h:188
EDA_RECT ComputeBoundingBox(bool aBoardEdgesOnly=false) const
Calculate the bounding box containing all board items (or board edge segments).
Definition: board.cpp:1050
double GetFineScaleAdjustY() const
COLOR_SETTINGS * ColorSettings() const
DXF_UNITS GetDXFPlotUnits() const
bool GetNegative() const
void SetDefaultPenWidth(int aWidth)
static constexpr int Millimeter2iu(double mm)

References AddGerberX2Attribute(), PLOTTER::ClearHeaderLinesList(), PCB_PLOT_PARAMS::ColorSettings(), BOARD::ComputeBoundingBox(), ConfigureHPGLPenSizes(), GERBER_PLOTTER::DisableApertMacros(), DXF, FillNegativeKnockout(), GERBER, PCB_PLOT_PARAMS::GetDisableGerberMacros(), 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(), Millimeter2iu(), NULL, PLOTTER::OpenFile(), PDF, PlotDrawingSheet(), POST, PLOTTER::RenderSettings(), KIGFX::RENDER_SETTINGS::SetDefaultPenWidth(), 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().