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, jean-pierre.charras@ujf-grenoble.fr
5  * Copyright (C) 1992-2021 KiCad Developers, see AUTHORS.txt for contributors.
6  * Copyright (C) 2018 CERN
7  * Author: Maciej Suminski <maciej.suminski@cern.ch>
8  * Author: Tomasz Wlostowski <tomasz.wlostowski@cern.ch>
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_Mirror = cfg->m_Plot.mirror;
56  }
57 }
58 
59 
61 {
63 
64  if( auto cfg = dynamic_cast<PCBNEW_SETTINGS*>( aConfig ) )
65  {
66  cfg->m_Plot.pads_drill_mode = m_DrillMarks;
67  cfg->m_Plot.all_layers_on_one_page = m_Pagination;
68  cfg->m_Plot.mirror = m_Mirror;
69  }
70 }
71 
72 
74  const KIGFX::VIEW* aView, const wxString& aTitle ) :
75  BOARD_PRINTOUT( aParams, aView, aTitle ), m_pcbnewSettings( aParams )
76 {
77  m_board = aBoard;
78 }
79 
80 
82 {
83  // Store the layerset, as it is going to be modified below and the original settings are
84  // needed.
85  LSET lset = m_settings.m_LayerSet;
86  int pageCount = lset.count();
87  wxString layerName;
88  PCB_LAYER_ID extractLayer;
89 
90  // compute layer mask from page number if we want one page per layer
92  {
93  // This sequence is TBD, call a different sequencer if needed, such as Seq().
94  // Could not find documentation on page order.
95  LSEQ seq = lset.UIOrder();
96 
97  // aPage starts at 1, not 0
98  if( unsigned( aPage - 1 ) < seq.size() )
99  m_settings.m_LayerSet = LSET( seq[ aPage - 1] );
100  }
101 
102  if( !m_settings.m_LayerSet.any() )
103  return false;
104 
105  extractLayer = m_settings.m_LayerSet.ExtractLayer();
106 
107  if( extractLayer == UNDEFINED_LAYER )
108  layerName = _( "Multiple Layers" );
109  else
110  layerName = LSET::Name( extractLayer );
111 
112  // In Pcbnew we can want the layer EDGE always printed
115 
116  DrawPage( layerName, aPage, pageCount );
117 
118  // Restore the original layer set, so the next page can be printed
119  m_settings.m_LayerSet = lset;
120 
121  return true;
122 }
123 
124 
125 int PCBNEW_PRINTOUT::milsToIU( double aMils ) const
126 {
127  return KiROUND( IU_PER_MILS * aMils );
128 }
129 
130 
131 void PCBNEW_PRINTOUT::setupViewLayers( KIGFX::VIEW& aView, const LSET& aLayerSet )
132 {
133  BOARD_PRINTOUT::setupViewLayers( aView, aLayerSet );
134 
135  for( PCB_LAYER_ID layer : m_settings.m_LayerSet.Seq() )
136  {
137  aView.SetLayerVisible( PCBNEW_LAYER_ID_START + layer, true );
138 
139  // Enable the corresponding zone layer (copper layers and other layers)
140  aView.SetLayerVisible( LAYER_ZONE_START + layer, true );
141  }
142 
143  RENDER_SETTINGS* renderSettings = aView.GetPainter()->GetSettings();
144  // A color to do not print objects on some layers, when the layer must be enabled
145  // to print some other objects
146  COLOR4D invisible_color( 0.0, 0.0, 0.0, 0.0 );
147 
149  {
150  auto setVisibility =
151  [&]( GAL_LAYER_ID aLayer )
152  {
153  if( m_board->IsElementVisible( aLayer ) )
154  aView.SetLayerVisible( aLayer, true );
155  else
156  renderSettings->SetLayerColor( aLayer, invisible_color );
157  };
158 
159  setVisibility( LAYER_MOD_FR );
160  setVisibility( LAYER_MOD_BK );
161  setVisibility( LAYER_MOD_VALUES );
162  setVisibility( LAYER_MOD_REFERENCES );
163  setVisibility( LAYER_MOD_TEXT_FR );
164  setVisibility( LAYER_MOD_TEXT_BK );
165  setVisibility( LAYER_MOD_TEXT_INVISIBLE );
166  setVisibility( LAYER_PADS );
167  setVisibility( LAYER_PAD_FR );
168  setVisibility( LAYER_PAD_BK );
169  setVisibility( LAYER_PADS_TH );
170 
171  setVisibility( LAYER_TRACKS );
172  setVisibility( LAYER_VIAS );
173  setVisibility( LAYER_VIA_MICROVIA );
174  setVisibility( LAYER_VIA_BBLIND );
175  setVisibility( LAYER_VIA_THROUGH );
176  setVisibility( LAYER_ZONES );
177 
178  setVisibility( LAYER_NO_CONNECTS );
179  setVisibility( LAYER_DRC_WARNING );
180  setVisibility( LAYER_DRC_ERROR );
181  setVisibility( LAYER_DRC_EXCLUSION );
182  setVisibility( LAYER_ANCHOR );
183  setVisibility( LAYER_DRAWINGSHEET );
184  setVisibility( LAYER_GRID );
185  }
186  else
187  {
188  // Draw layers that must be not visible on printing are set to an invisible layer
189  // LAYER_PAD_FR, LAYER_PAD_BK and LAYER_PADS_TH must be enabled to print pads on
190  // technical layers, but not the pad on copper layer(s) if they are not enabled
191 
192  if( !aLayerSet.test( F_Cu ) )
193  renderSettings->SetLayerColor( LAYER_PAD_FR, invisible_color );
194 
195  if( !aLayerSet.test( B_Cu ) )
196  renderSettings->SetLayerColor( LAYER_PAD_BK, invisible_color );
197 
198  // Enable items on copper layers, but do not draw holes
199  for( GAL_LAYER_ID layer : { LAYER_PADS_TH, LAYER_VIA_THROUGH } )
200  {
201  if( ( aLayerSet & LSET::AllCuMask() ).any() ) // Items visible on any copper layer
202  aView.SetLayerVisible( layer, true );
203  else
204  renderSettings->SetLayerColor( layer, invisible_color );
205  }
206 
207  // Keep certain items always enabled/disabled and just rely on the layer visibility
208  // Note LAYER_PAD_FR, LAYER_PAD_BK, LAYER_PADS_TH are enabled here because paths must
209  // be drawn on some other (technical) layers.
210  const int alwaysEnabled[] =
211  {
216  };
217 
218  for( int layer : alwaysEnabled )
219  aView.SetLayerVisible( layer, true );
220  }
221 
223  {
224  // Enable hole layers to draw drill marks
226  {
227  aView.SetLayerVisible( layer, true );
228  aView.SetTopLayer( layer, true );
229  }
230  }
231 }
232 
233 
235 {
236  BOARD_PRINTOUT::setupPainter( aPainter );
237 
238  KIGFX::PCB_PRINT_PAINTER& painter = dynamic_cast<KIGFX::PCB_PRINT_PAINTER&>( aPainter );
239 
241  {
243  painter.SetDrillMarks( false, 0 );
244  break;
245 
247  painter.SetDrillMarks( false, Millimeter2iu( ADVANCED_CFG::GetCfg().m_SmallDrillMarkSize ) );
248 
252  break;
253 
255  painter.SetDrillMarks( true );
256 
260  break;
261  }
262 
265 }
266 
267 
269 {
270  BOARD_PRINTOUT::setupGal( aGal );
271  aGal->SetWorldUnitLength( 0.001/IU_PER_MM /* 1 nm */ / 0.0254 /* 1 inch in meters */ );
272 }
273 
274 
276 {
277  return m_board->ComputeBoundingBox();
278 }
279 
280 
281 std::unique_ptr<KIGFX::PAINTER> PCBNEW_PRINTOUT::getPainter( KIGFX::GAL* aGal )
282 {
283  return std::make_unique<KIGFX::PCB_PRINT_PAINTER>( aGal );
284 }
285 
286 
288  PCB_PAINTER( aGal ),
289  m_drillMarkReal( false ),
290  m_drillMarkSize( 0 )
291 {
293 }
294 
295 
297 {
298  return m_drillMarkReal ? KIGFX::PCB_PAINTER::getDrillShape( aPad ) : PAD_DRILL_SHAPE_CIRCLE;
299 }
300 
301 
303 {
304  // TODO should it depend on the pad size?
305  return m_drillMarkReal ? KIGFX::PCB_PAINTER::getDrillSize( aPad ) :
306  VECTOR2D( m_drillMarkSize, m_drillMarkSize );
307 }
308 
309 
311 {
312  // TODO should it depend on the via size?
313  return m_drillMarkReal ? KIGFX::PCB_PAINTER::getDrillSize( aVia ) : m_drillMarkSize;
314 }
static LSET AllCuMask(int aCuLayerCount=MAX_CU_LAYERS)
Return a mask holding the requested number of Cu PCB_LAYER_IDs.
Definition: lset.cpp:750
smd pads, front layer
Definition: layer_ids.h:198
to draw micro vias
Definition: layer_ids.h:190
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:212
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:830
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:226
static constexpr double IU_PER_MM
Mock up a conversion function.
show footprints values (when texts are visible)
Definition: layer_ids.h:206
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:185
smd pads, back layer
Definition: layer_ids.h:199
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:197
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:205
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:211
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:227
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:192
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:504
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:193
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:622
Meta control for all vias opacity/visibility.
Definition: layer_ids.h:189
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:196
show footprints on front
Definition: layer_ids.h:204
Virtual layers for stacking zones and tracks on a given copper layer.
Definition: layer_ids.h:242
#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:213
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:465
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:203
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:207
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:209
to draw blind/buried vias
Definition: layer_ids.h:191
layer for drc markers which have been individually excluded
Definition: layer_ids.h:232
PCB_LAYER_ID ExtractLayer() const
Find the first set PCB_LAYER_ID.
Definition: lset.cpp:661
PCBNEW_PRINTOUT_SETTINGS m_pcbnewSettings
Information pertinent to a Pcbnew printed circuit board.
Definition: board.h:190
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:136
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:231
EDA_RECT ComputeBoundingBox(bool aBoardEdgesOnly=false) const
Calculate the bounding box containing all board items (or board edge segments).
Definition: board.cpp:1082
EDA_RECT getBoundingBox() override
Returns a PAINTER instance used to draw the items.
to draw pad holes (plated)
Definition: layer_ids.h:210
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:895
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