KiCad PCB EDA Suite
pcbnew_printout.cpp
Go to the documentation of this file.
1 /*
2  * This program source code file is part of KiCad, a free EDA CAD application.
3  *
4  * Copyright (C) 2009 Jean-Pierre Charras, [email protected]
5  * Copyright (C) 1992-2021 KiCad Developers, see AUTHORS.txt for contributors.
6  * Copyright (C) 2018 CERN
7  * Author: Maciej Suminski <[email protected]>
8  * Author: Tomasz Wlostowski <[email protected]>
9  *
10  * This program is free software; you can redistribute it and/or
11  * modify it under the terms of the GNU General Public License
12  * as published by the Free Software Foundation; either version 2
13  * of the License, or (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program; if not, you may find one here:
22  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
23  * or you may search the http://www.gnu.org website for the version 2 license,
24  * or you may write to the Free Software Foundation, Inc.,
25  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
26  */
27 
28 #include "pcbnew_printout.h"
29 #include <board.h>
30 #include <math/util.h> // for KiROUND
31 #include <pcb_painter.h>
32 #include <pcbnew_settings.h>
33 #include <view/view.h>
34 #include <pcbplot.h>
35 #include <advanced_config.h>
36 
38  : BOARD_PRINTOUT_SETTINGS( aPageInfo )
39 {
43  m_AsItemCheckboxes = false;
44 }
45 
46 
48 {
50 
51  if( auto cfg = dynamic_cast<PCBNEW_SETTINGS*>( aConfig ) )
52  {
53  m_DrillMarks = static_cast<DRILL_MARK_SHAPE_T>( cfg->m_Plot.pads_drill_mode );
54  m_Pagination = static_cast<PAGINATION_T>( cfg->m_Plot.all_layers_on_one_page );
55  m_PrintEdgeCutsOnAllPages = cfg->m_Plot.edgecut_on_all_layers;
56  m_Mirror = cfg->m_Plot.mirror;
57  }
58 }
59 
60 
62 {
64 
65  if( auto cfg = dynamic_cast<PCBNEW_SETTINGS*>( aConfig ) )
66  {
67  cfg->m_Plot.pads_drill_mode = m_DrillMarks;
68  cfg->m_Plot.all_layers_on_one_page = m_Pagination;
69  cfg->m_Plot.edgecut_on_all_layers = m_PrintEdgeCutsOnAllPages;
70  cfg->m_Plot.mirror = m_Mirror;
71  }
72 }
73 
74 
76  const KIGFX::VIEW* aView, const wxString& aTitle ) :
77  BOARD_PRINTOUT( aParams, aView, aTitle ), m_pcbnewSettings( aParams )
78 {
79  m_board = aBoard;
80 }
81 
82 
84 {
85  // Store the layerset, as it is going to be modified below and the original settings are
86  // needed.
87  LSET lset = m_settings.m_LayerSet;
88  int pageCount = lset.count();
89  wxString layerName;
90  PCB_LAYER_ID extractLayer;
91 
92  // compute layer mask from page number if we want one page per layer
94  {
95  // This sequence is TBD, call a different sequencer if needed, such as Seq().
96  // Could not find documentation on page order.
97  LSEQ seq = lset.UIOrder();
98 
99  // aPage starts at 1, not 0
100  if( unsigned( aPage - 1 ) < seq.size() )
101  m_settings.m_LayerSet = LSET( seq[ aPage - 1] );
102  }
103 
104  if( !m_settings.m_LayerSet.any() )
105  return false;
106 
107  extractLayer = m_settings.m_LayerSet.ExtractLayer();
108 
109  if( extractLayer == UNDEFINED_LAYER )
110  layerName = _( "Multiple Layers" );
111  else
112  layerName = LSET::Name( extractLayer );
113 
114  // In Pcbnew we can want the layer EDGE always printed
117 
118  DrawPage( layerName, aPage, pageCount );
119 
120  // Restore the original layer set, so the next page can be printed
121  m_settings.m_LayerSet = lset;
122 
123  return true;
124 }
125 
126 
127 int PCBNEW_PRINTOUT::milsToIU( double aMils ) const
128 {
129  return KiROUND( IU_PER_MILS * aMils );
130 }
131 
132 
133 void PCBNEW_PRINTOUT::setupViewLayers( KIGFX::VIEW& aView, const LSET& aLayerSet )
134 {
135  BOARD_PRINTOUT::setupViewLayers( aView, aLayerSet );
136 
137  for( PCB_LAYER_ID layer : m_settings.m_LayerSet.Seq() )
138  {
139  aView.SetLayerVisible( PCBNEW_LAYER_ID_START + layer, true );
140 
141  // Enable the corresponding zone layer (copper layers and other layers)
142  aView.SetLayerVisible( LAYER_ZONE_START + layer, true );
143  }
144 
145  RENDER_SETTINGS* renderSettings = aView.GetPainter()->GetSettings();
146  // A color to do not print objects on some layers, when the layer must be enabled
147  // to print some other objects
148  COLOR4D invisible_color = COLOR4D::UNSPECIFIED;
149 
151  {
152  auto setVisibility =
153  [&]( GAL_LAYER_ID aLayer )
154  {
155  if( m_board->IsElementVisible( aLayer ) )
156  aView.SetLayerVisible( aLayer, true );
157  else
158  renderSettings->SetLayerColor( aLayer, invisible_color );
159  };
160 
161  setVisibility( LAYER_MOD_FR );
162  setVisibility( LAYER_MOD_BK );
163  setVisibility( LAYER_MOD_VALUES );
164  setVisibility( LAYER_MOD_REFERENCES );
165  setVisibility( LAYER_MOD_TEXT );
166  setVisibility( LAYER_MOD_TEXT_INVISIBLE );
167  setVisibility( LAYER_PADS );
168  setVisibility( LAYER_PAD_FR );
169  setVisibility( LAYER_PAD_BK );
170  setVisibility( LAYER_PADS_TH );
171 
172  setVisibility( LAYER_TRACKS );
173  setVisibility( LAYER_VIAS );
174  setVisibility( LAYER_VIA_MICROVIA );
175  setVisibility( LAYER_VIA_BBLIND );
176  setVisibility( LAYER_VIA_THROUGH );
177  setVisibility( LAYER_ZONES );
178 
179  setVisibility( LAYER_NO_CONNECTS );
180  setVisibility( LAYER_DRC_WARNING );
181  setVisibility( LAYER_DRC_ERROR );
182  setVisibility( LAYER_DRC_EXCLUSION );
183  setVisibility( LAYER_ANCHOR );
184  setVisibility( LAYER_DRAWINGSHEET );
185  setVisibility( LAYER_GRID );
186  }
187  else
188  {
189  // Draw layers that must be not visible on printing are set to an invisible layer
190  // LAYER_PAD_FR, LAYER_PAD_BK and LAYER_PADS_TH must be enabled to print pads on
191  // technical layers, but not the pad on copper layer(s) if they are not enabled
192 
193  if( !aLayerSet.test( F_Cu ) )
194  renderSettings->SetLayerColor( LAYER_PAD_FR, invisible_color );
195 
196  if( !aLayerSet.test( B_Cu ) )
197  renderSettings->SetLayerColor( LAYER_PAD_BK, invisible_color );
198 
199  // Enable items on copper layers, but do not draw holes
201  {
202  if( ( aLayerSet & LSET::AllCuMask() ).any() ) // Items visible on any copper layer
203  aView.SetLayerVisible( layer, true );
204  else
205  renderSettings->SetLayerColor( layer, invisible_color );
206  }
207 
208  // Keep certain items always enabled/disabled and just rely on the layer visibility
209  // Note LAYER_PAD_FR, LAYER_PAD_BK, LAYER_PADS_TH are enabled here because paths must
210  // be drawn on some other (technical) layers.
211  const int alwaysEnabled[] =
212  {
215  LAYER_VIAS,
217  };
218 
219  for( int layer : alwaysEnabled )
220  aView.SetLayerVisible( layer, true );
221  }
222 
224  {
225  // Enable hole layers to draw drill marks
227  {
228  aView.SetLayerVisible( layer, true );
229  aView.SetTopLayer( layer, true );
230  }
231  }
232 }
233 
234 
236 {
237  BOARD_PRINTOUT::setupPainter( aPainter );
238 
239  KIGFX::PCB_PRINT_PAINTER& painter = dynamic_cast<KIGFX::PCB_PRINT_PAINTER&>( aPainter );
240 
242  {
244  painter.SetDrillMarks( false, 0 );
245  break;
246 
248  painter.SetDrillMarks( false, Millimeter2iu( ADVANCED_CFG::GetCfg().m_SmallDrillMarkSize ) );
249 
253  break;
254 
256  painter.SetDrillMarks( true );
257 
261  break;
262  }
263 
266 }
267 
268 
270 {
271  BOARD_PRINTOUT::setupGal( aGal );
272  aGal->SetWorldUnitLength( 0.001/IU_PER_MM /* 1 nm */ / 0.0254 /* 1 inch in meters */ );
273 }
274 
275 
277 {
278  return m_board->ComputeBoundingBox();
279 }
280 
281 
282 std::unique_ptr<KIGFX::PAINTER> PCBNEW_PRINTOUT::getPainter( KIGFX::GAL* aGal )
283 {
284  return std::make_unique<KIGFX::PCB_PRINT_PAINTER>( aGal );
285 }
286 
287 
289  PCB_PAINTER( aGal ),
290  m_drillMarkReal( false ),
291  m_drillMarkSize( 0 )
292 {
294 }
295 
296 
298 {
299  return m_drillMarkReal ? KIGFX::PCB_PAINTER::getDrillShape( aPad ) : PAD_DRILL_SHAPE_CIRCLE;
300 }
301 
302 
304 {
305  // TODO should it depend on the pad size?
306  return m_drillMarkReal ? KIGFX::PCB_PAINTER::getDrillSize( aPad ) :
307  VECTOR2D( m_drillMarkSize, m_drillMarkSize );
308 }
309 
310 
312 {
313  // TODO should it depend on the via size?
314  return m_drillMarkReal ? KIGFX::PCB_PAINTER::getDrillSize( aVia ) : m_drillMarkSize;
315 }
static LSET AllCuMask(int aCuLayerCount=MAX_CU_LAYERS)
Return a mask holding the requested number of Cu PCB_LAYER_IDs.
Definition: lset.cpp:759
smd pads, front layer
Definition: layer_ids.h:209
to draw micro vias
Definition: layer_ids.h:201
PCBNEW_PRINTOUT_SETTINGS(const PAGE_INFO &aPageInfo)
void Save(APP_SETTINGS_BASE *aConfig) override
layer for drc markers with SEVERITY_ERROR
Definition: layer_ids.h:223
virtual void SetTopLayer(int aLayer, bool aEnabled=true)
Set given layer to be displayed on the top or sets back the default order of layers.
Definition: view.cpp:826
Container for all the knowledge about how graphical objects are drawn on any output surface/device.
Meta control for all pads opacity/visibility (color ignored)
Definition: layer_ids.h:237
static constexpr double IU_PER_MM
Mock up a conversion function.
show footprints values (when texts are visible)
Definition: layer_ids.h:217
enum PCBNEW_PRINTOUT_SETTINGS::DRILL_MARK_SHAPE_T m_DrillMarks
int getDrillShape(const PAD *aPad) const override
Return drill shape of a pad.
Special flavor of PCB_PAINTER that contains modifications to handle printing options.
GAL_LAYER_ID
GAL layers are "virtual" layers, i.e.
Definition: layer_ids.h:196
smd pads, back layer
Definition: layer_ids.h:210
void EnableZoneOutlines(bool aEnabled)
Turn on/off drawing outline and hatched lines for zones.
Definition: pcb_painter.h:136
anchor of items having an anchor point (texts, footprints)
Definition: layer_ids.h:208
void Load(APP_SETTINGS_BASE *aConfig) override
LSET m_LayerSet
Layers to print.
PCBNEW_PRINTOUT(BOARD *aBoard, const PCBNEW_PRINTOUT_SETTINGS &aParams, const KIGFX::VIEW *aView, const wxString &aTitle)
virtual void DrawPage(const wxString &aLayerName=wxEmptyString, int aPageNum=1, int aPageCount=1)
Print a page (or a set of pages).
show footprints on back
Definition: layer_ids.h:216
PCB_RENDER_SETTINGS m_pcbSettings
Definition: pcb_painter.h:295
Definition: color4d.h:44
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
Contains methods for drawing PCB-specific items.
Definition: pcb_painter.h:241
std::unique_ptr< KIGFX::PAINTER > getPainter(KIGFX::GAL *aGal) override
Source VIEW object (note that actual printing only refers to this object)
to draw via holes (pad holes do not use this layer)
Definition: layer_ids.h:222
PAINTER * GetPainter() const
Return the painter object used by the view for drawing #VIEW_ITEMS.
Definition: view.h:208
Control for copper zone opacity/visibility (color ignored)
Definition: layer_ids.h:238
BOARD_PRINTOUT_SETTINGS m_settings
virtual VECTOR2D getDrillSize(const PAD *aPad) const
Return drill size for a pad (internal units).
to draw usual through hole vias
Definition: layer_ids.h:203
Board plot function definition file.
void setupPainter(KIGFX::PAINTER &aPainter) override
Configures GAL object for a printout.
Contains all the knowledge about how to draw graphical object onto any particular output device.
Definition: painter.h:57
void Load(APP_SETTINGS_BASE *aConfig) override
void setupViewLayers(KIGFX::VIEW &aView, const LSET &aLayerSet) override
Configures PAINTER object for a printout.
LSET is a set of PCB_LAYER_IDs.
Definition: layer_ids.h:516
bool m_AsItemCheckboxes
Honor checkboxes in the Items tab of the Layers Manager.
handle color for not plated holes (holes, not pads)
Definition: layer_ids.h:204
APP_SETTINGS_BASE is a settings class that should be derived for each standalone KiCad application.
Definition: app_settings.h:99
VECTOR2< double > VECTOR2D
Definition: vector2d.h:621
Meta control for all vias opacity/visibility.
Definition: layer_ids.h:200
virtual PCB_RENDER_SETTINGS * GetSettings() override
Return a pointer to current settings that are going to be used when drawing items.
Definition: pcb_painter.h:247
virtual void setupPainter(KIGFX::PAINTER &aPainter)
Configures GAL object for a printout.
static const wxChar * Name(PCB_LAYER_ID aLayerId)
Return the fixed name association with aLayerId.
Definition: lset.cpp:82
int milsToIU(double aMils) const override
< Convert mils to internal units
Describe the page size and margins of a paper page on which to eventually print or plot.
Definition: page_info.h:53
virtual void setupGal(KIGFX::GAL *aGal)
Returns bounding box of the printed objects (excluding drawing-sheet frame)
text marked as invisible
Definition: layer_ids.h:207
show footprints on front
Definition: layer_ids.h:215
Virtual layers for stacking zones and tracks on a given copper layer.
Definition: layer_ids.h:253
#define _(s)
void SetLayerColor(int aLayer, const COLOR4D &aColor)
Change the color used to draw a layer.
void SetLayerVisible(int aLayer, bool aVisible=true)
Control the visibility of a particular layer.
Definition: view.h:388
drawingsheet frame and titleblock
Definition: layer_ids.h:224
void Save(APP_SETTINGS_BASE *aConfig) override
bool m_PrintEdgeCutsOnAllPages
Print board outline on each page.
void SetWorldUnitLength(double aWorldUnitLength)
Set the unit length.
void SetDrawIndividualViaLayers(bool aFlag)
Definition: pcb_painter.h:175
LSEQ is a sequence (and therefore also a set) of PCB_LAYER_IDs.
Definition: layer_ids.h:477
virtual void setupViewLayers(KIGFX::VIEW &aView, const LSET &aLayerSet)
Configures PAINTER object for a printout.
show a marker on pads with no nets
Definition: layer_ids.h:214
bool IsElementVisible(GAL_LAYER_ID aLayer) const
Test whether a given element category is visible.
Definition: board.cpp:533
show footprints references (when texts are visible)
Definition: layer_ids.h:218
virtual RENDER_SETTINGS * GetSettings()=0
Return a pointer to current settings that are going to be used when drawing items.
An object derived from wxPrintout to handle the necessary information to control a printer when print...
multilayer pads, usually with holes
Definition: layer_ids.h:220
to draw blind/buried vias
Definition: layer_ids.h:202
layer for drc markers which have been individually excluded
Definition: layer_ids.h:243
PCB_LAYER_ID ExtractLayer() const
Find the first set PCB_LAYER_ID.
Definition: lset.cpp:670
PCBNEW_PRINTOUT_SETTINGS m_pcbnewSettings
Information pertinent to a Pcbnew printed circuit board.
Definition: board.h:191
PCB_LAYER_ID
A quick note on layer IDs:
Definition: layer_ids.h:65
Definition: layer_ids.h:71
Handle the component boundary box.
Definition: eda_rect.h:42
VECTOR2D getDrillSize(const PAD *aPad) const override
Return drill size for a pad (internal units).
#define IU_PER_MILS
Definition: plotter.cpp:130
constexpr ret_type KiROUND(fp_type v)
Round a floating point number to an integer using "round halfway cases away from zero".
Definition: util.h:73
layer for drc markers with SEVERITY_WARNING
Definition: layer_ids.h:242
EDA_RECT ComputeBoundingBox(bool aBoardEdgesOnly=false) const
Calculate the bounding box containing all board items (or board edge segments).
Definition: board.cpp:1085
EDA_RECT getBoundingBox() override
Returns a PAINTER instance used to draw the items.
to draw pad holes (plated)
Definition: layer_ids.h:221
static const ADVANCED_CFG & GetCfg()
Get the singleton instance's config, which is shared by all consumers.
Hold a (potentially large) number of VIEW_ITEMs and renders them on a graphics device provided by the...
Definition: view.h:68
void setupGal(KIGFX::GAL *aGal) override
Returns bounding box of the printed objects (excluding drawing-sheet frame)
Definition: pad.h:57
virtual int getDrillShape(const PAD *aPad) const
Return drill shape of a pad.
LSEQ UIOrder() const
Definition: lset.cpp:904
static constexpr int Millimeter2iu(double mm)
bool OnPrintPage(int aPage) override
bool m_Mirror
Print mirrored.
void SetDrillMarks(bool aRealSize, unsigned int aSize=0)
Set drill marks visibility and options.
enum PCBNEW_PRINTOUT_SETTINGS::PAGINATION_T m_Pagination
Abstract interface for drawing on a 2D-surface.
A color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:103