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  COLOR4D backgroundColor = renderSettings->GetLayerColor( LAYER_PCB_BACKGROUND );
145 
147  {
148  auto setVisibility =
149  [&]( GAL_LAYER_ID aLayer )
150  {
151  if( m_board->IsElementVisible( aLayer ) )
152  aView.SetLayerVisible( aLayer, true );
153  else
154  renderSettings->SetLayerColor( aLayer, backgroundColor );
155  };
156 
157  setVisibility( LAYER_MOD_FR );
158  setVisibility( LAYER_MOD_BK );
159  setVisibility( LAYER_MOD_VALUES );
160  setVisibility( LAYER_MOD_REFERENCES );
161  setVisibility( LAYER_MOD_TEXT_FR );
162  setVisibility( LAYER_MOD_TEXT_BK );
163  setVisibility( LAYER_MOD_TEXT_INVISIBLE );
164  setVisibility( LAYER_PAD_FR );
165  setVisibility( LAYER_PAD_BK );
166  setVisibility( LAYER_PADS_TH );
167 
168  setVisibility( LAYER_TRACKS );
169  setVisibility( LAYER_VIAS );
170 
171  setVisibility( LAYER_NO_CONNECTS );
172  setVisibility( LAYER_DRC_WARNING );
173  setVisibility( LAYER_DRC_ERROR );
174  setVisibility( LAYER_DRC_EXCLUSION );
175  setVisibility( LAYER_ANCHOR );
176  setVisibility( LAYER_DRAWINGSHEET );
177  setVisibility( LAYER_GRID );
178 
179  // Keep certain items always enabled and just rely on either the finer or coarser
180  // visibility controls
181  const int alwaysEnabled[] =
182  {
185  };
186 
187  for( int layer : alwaysEnabled )
188  aView.SetLayerVisible( layer, true );
189  }
190  else
191  {
192  // Enable pad layers corresponding to the selected copper layers
193  if( aLayerSet.test( F_Cu ) )
194  aView.SetLayerVisible( LAYER_PAD_FR, true );
195  else
196  renderSettings->SetLayerColor( LAYER_PAD_FR, backgroundColor );
197 
198  if( aLayerSet.test( B_Cu ) )
199  aView.SetLayerVisible( LAYER_PAD_BK, true );
200  else
201  renderSettings->SetLayerColor( LAYER_PAD_BK, backgroundColor );
202 
203  // Enable items on copper layers, but do not draw holes
204  for( GAL_LAYER_ID layer : { LAYER_PADS_TH, LAYER_VIA_THROUGH } )
205  {
206  if( ( aLayerSet & LSET::AllCuMask() ).any() ) // Items visible on any copper layer
207  aView.SetLayerVisible( layer, true );
208  else
209  renderSettings->SetLayerColor( layer, backgroundColor );
210  }
211 
212  // Keep certain items always enabled/disabled and just rely on the layer visibility
213  const int alwaysEnabled[] =
214  {
218  };
219 
220  for( int layer : alwaysEnabled )
221  aView.SetLayerVisible( layer, true );
222  }
223 
225  {
226  // Enable hole layers to draw drill marks
228  {
229  aView.SetLayerVisible( layer, true );
230  aView.SetTopLayer( layer, true );
231  }
232  }
233 }
234 
235 
237 {
238  BOARD_PRINTOUT::setupPainter( aPainter );
239 
240  KIGFX::PCB_PRINT_PAINTER& painter = dynamic_cast<KIGFX::PCB_PRINT_PAINTER&>( aPainter );
241 
243  {
245  painter.SetDrillMarks( false, 0 );
246  break;
247 
249  painter.SetDrillMarks( false, Millimeter2iu( ADVANCED_CFG::GetCfg().m_SmallDrillMarkSize ) );
250 
254  break;
255 
257  painter.SetDrillMarks( true );
258 
262  break;
263  }
264 
267 }
268 
269 
271 {
272  BOARD_PRINTOUT::setupGal( aGal );
273  aGal->SetWorldUnitLength( 0.001/IU_PER_MM /* 1 nm */ / 0.0254 /* 1 inch in meters */ );
274 }
275 
276 
278 {
279  return m_board->ComputeBoundingBox();
280 }
281 
282 
283 std::unique_ptr<KIGFX::PAINTER> PCBNEW_PRINTOUT::getPainter( KIGFX::GAL* aGal )
284 {
285  return std::make_unique<KIGFX::PCB_PRINT_PAINTER>( aGal );
286 }
287 
288 
290  PCB_PAINTER( aGal ),
291  m_drillMarkReal( false ),
292  m_drillMarkSize( 0 )
293 {
295 }
296 
297 
299 {
300  return m_drillMarkReal ? KIGFX::PCB_PAINTER::getDrillShape( aPad ) : PAD_DRILL_SHAPE_CIRCLE;
301 }
302 
303 
305 {
306  // TODO should it depend on the pad size?
307  return m_drillMarkReal ? KIGFX::PCB_PAINTER::getDrillSize( aPad ) :
308  VECTOR2D( m_drillMarkSize, m_drillMarkSize );
309 }
310 
311 
313 {
314  // TODO should it depend on the via size?
315  return m_drillMarkReal ? KIGFX::PCB_PAINTER::getDrillSize( aVia ) : m_drillMarkSize;
316 }
static LSET AllCuMask(int aCuLayerCount=MAX_CU_LAYERS)
Return a mask holding the requested number of Cu PCB_LAYER_IDs.
Definition: lset.cpp:750
Virtual layers for stacking zones and tracks on a given copper layer.
to draw blind/buried vias
PCBNEW_PRINTOUT_SETTINGS(const PAGE_INFO &aPageInfo)
show a marker on pads with no nets
void Save(APP_SETTINGS_BASE *aConfig) override
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:838
Container for all the knowledge about how graphical objects are drawn on any output surface/device.
multilayer pads, usually with holes
static constexpr double IU_PER_MM
Mock up a conversion function.
enum PCBNEW_PRINTOUT_SETTINGS::DRILL_MARK_SHAPE_T m_DrillMarks
to draw via holes (pad holes do not use this layer)
handle color for not plated holes (holes, not pads)
anchor of items having an anchor point (texts, footprints)
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.
Control for copper zone opacity/visibility (color ignored)
show footprints on back
void EnableZoneOutlines(bool aEnabled)
Turn on/off drawing outline and hatched lines for zones.
Definition: pcb_painter.h:136
const COLOR4D & GetLayerColor(int aLayer) const
Return the color used to draw a layer.
GAL_LAYER_ID
GAL layers are "virtual" layers, i.e.
void Load(APP_SETTINGS_BASE *aConfig) override
show footprints values (when texts are visible)
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).
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)
PAINTER * GetPainter() const
Return the painter object used by the view for drawing #VIEW_ITEMS.
Definition: view.h:207
BOARD_PRINTOUT_SETTINGS m_settings
virtual VECTOR2D getDrillSize(const PAD *aPad) const
Return drill size for a pad (internal units).
Board plot function definition file.
void setupPainter(KIGFX::PAINTER &aPainter) override
Configures GAL object for a printout.
show footprints on front
PCB_LAYER_ID
A quick note on layer IDs:
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.
bool m_AsItemCheckboxes
Honor checkboxes in the Items tab of the Layers Manager.
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
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
Meta control for all pads opacity/visibility (color ignored)
to draw usual through hole vias
virtual void setupGal(KIGFX::GAL *aGal)
Returns bounding box of the printed objects (excluding drawing-sheet frame)
#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:387
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.
virtual void setupViewLayers(KIGFX::VIEW &aView, const LSET &aLayerSet)
Configures PAINTER object for a printout.
layer for drc markers which have been individually excluded
bool IsElementVisible(GAL_LAYER_ID aLayer) const
Test whether a given element category is visible.
Definition: board.cpp:531
layer for drc markers with SEVERITY_WARNING
virtual RENDER_SETTINGS * GetSettings()=0
Return a pointer to current settings that are going to be used when drawing items.
smd pads, front layer
An object derived from wxPrintout to handle the necessary information to control a printer when print...
Meta control for all vias opacity/visibility.
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
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:137
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:70
EDA_RECT ComputeBoundingBox(bool aBoardEdgesOnly=false) const
Calculate the bounding box containing all board items (or board edge segments).
Definition: board.cpp:1104
EDA_RECT getBoundingBox() override
Returns a PAINTER instance used to draw the items.
static const ADVANCED_CFG & GetCfg()
Get the singleton instance's config, which is shared by all consumers.
drawingsheet frame and titleblock
Hold a (potentially large) number of VIEW_ITEMs and renders them on a graphics device provided by the...
Definition: view.h:67
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.
show footprints references (when texts are visible)
layer for drc markers with SEVERITY_ERROR
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