KiCad PCB EDA Suite
Loading...
Searching...
No Matches
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 The 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
32#include <lset.h>
33#include <pcb_painter.h>
34#include <pcbnew_settings.h>
35#include <view/view.h>
36#include <pcbplot.h>
38#include <pad.h>
39
40#include <advanced_config.h>
41#include <pgm_base.h>
42
44 BOARD_PRINTOUT_SETTINGS( aPageInfo )
45{
46 m_DrillMarks = DRILL_MARKS::SMALL_DRILL_SHAPE;
49 m_AsItemCheckboxes = false;
50}
51
52
54{
56
58 PCBNEW_SETTINGS* cfg = mgr.GetAppSettings<PCBNEW_SETTINGS>( "pcbnew" );
59
60 if( cfg )
61 {
62 m_DrillMarks = static_cast<DRILL_MARKS>( cfg->m_Plot.pads_drill_mode );
65 m_Mirror = cfg->m_Plot.mirror;
67 }
68}
69
70
72{
74
76 PCBNEW_SETTINGS* cfg = mgr.GetAppSettings<PCBNEW_SETTINGS>( "pcbnew" );
77
78 if( cfg )
79 {
83 cfg->m_Plot.mirror = m_Mirror;
85 }
86}
87
88
90 const KIGFX::VIEW* aView, const wxString& aTitle ) :
91 BOARD_PRINTOUT( aParams, aView, aTitle ), m_pcbnewSettings( aParams )
92{
93 m_board = aBoard;
94}
95
96
98{
99 // Store the layerset, as it is going to be modified below and the original settings are
100 // needed.
102 int pageCount = lset.count();
103 wxString layerName;
104 PCB_LAYER_ID extractLayer;
105
106 // compute layer mask from page number if we want one page per layer
108 {
109 // This sequence is TBD, call a different sequencer if needed, such as Seq().
110 // Could not find documentation on page order.
111 LSEQ seq = lset.UIOrder();
112
113 // aPage starts at 1, not 0
114 if( unsigned( aPage - 1 ) < seq.size() )
115 m_settings.m_LayerSet = LSET( { seq[aPage - 1] } );
116 }
117
118 if( !m_settings.m_LayerSet.any() )
119 return false;
120
121 extractLayer = m_settings.m_LayerSet.ExtractLayer();
122
123 if( extractLayer == UNDEFINED_LAYER )
124 layerName = _( "Multiple Layers" );
125 else
126 layerName = m_board->GetLayerName( extractLayer );
127
128 // In Pcbnew we can want the layer EDGE always printed
131
132 DrawPage( layerName, aPage, pageCount );
133
134 // Restore the original layer set, so the next page can be printed
135 m_settings.m_LayerSet = lset;
136
137 return true;
138}
139
140
141int PCBNEW_PRINTOUT::milsToIU( double aMils ) const
142{
143 return KiROUND( pcbIUScale.IU_PER_MILS * aMils );
144}
145
146
147void PCBNEW_PRINTOUT::setupViewLayers( KIGFX::VIEW& aView, const LSET& aLayerSet )
148{
149 BOARD_PRINTOUT::setupViewLayers( aView, aLayerSet );
150
151 for( PCB_LAYER_ID layer : m_settings.m_LayerSet.Seq() )
152 {
153 aView.SetLayerVisible( PCBNEW_LAYER_ID_START + layer, true );
154
155 // Enable the corresponding zone layer (copper layers and other layers)
156 aView.SetLayerVisible( LAYER_ZONE_START + layer, true );
157 aView.SetLayerVisible( LAYER_PAD_COPPER_START + layer, true );
158 aView.SetLayerVisible( LAYER_VIA_COPPER_START + layer, true );
159 }
160
161 RENDER_SETTINGS* renderSettings = aView.GetPainter()->GetSettings();
162 // A color to do not print objects on some layers, when the layer must be enabled
163 // to print some other objects
164 COLOR4D invisible_color = COLOR4D::UNSPECIFIED;
165
167 {
168 auto setVisibility =
169 [&]( GAL_LAYER_ID aLayer )
170 {
171 if( m_board->IsElementVisible( aLayer ) )
172 aView.SetLayerVisible( aLayer, true );
173 else
174 renderSettings->SetLayerColor( aLayer, invisible_color );
175 };
176
177 setVisibility( LAYER_FOOTPRINTS_FR );
178 setVisibility( LAYER_FOOTPRINTS_BK );
179 setVisibility( LAYER_FP_VALUES );
180 setVisibility( LAYER_FP_REFERENCES );
181 setVisibility( LAYER_FP_TEXT );
182 setVisibility( LAYER_PADS );
183
184 setVisibility( LAYER_TRACKS );
185 setVisibility( LAYER_VIAS );
186 setVisibility( LAYER_VIA_MICROVIA );
187 setVisibility( LAYER_VIA_BBLIND );
188 setVisibility( LAYER_VIA_THROUGH );
189 setVisibility( LAYER_ZONES );
190 setVisibility( LAYER_SHAPES );
191
192 setVisibility( LAYER_DRC_WARNING );
193 setVisibility( LAYER_DRC_ERROR );
194 setVisibility( LAYER_DRC_SHAPE1 );
195 setVisibility( LAYER_DRC_SHAPE2 );
196 setVisibility( LAYER_DRC_EXCLUSION );
197 setVisibility( LAYER_ANCHOR );
198 setVisibility( LAYER_DRAWINGSHEET );
199 setVisibility( LAYER_GRID );
200 }
201 else
202 {
203 // Enable items on copper layers, but do not draw holes
205 {
206 if( ( aLayerSet & LSET::AllCuMask() ).any() ) // Items visible on any copper layer
207 aView.SetLayerVisible( layer, true );
208 else
209 renderSettings->SetLayerColor( layer, invisible_color );
210 }
211
212 // Keep certain items always enabled/disabled and just rely on the layer visibility
213 // Note LAYER_PADS_SMD_FR, LAYER_PADS_SMD_BK, LAYER_PADS_TH are enabled here because paths must
214 // be drawn on some other (technical) layers.
215 const int alwaysEnabled[] =
216 {
222 };
223
224 for( int layer : alwaysEnabled )
225 aView.SetLayerVisible( layer, true );
226 }
227
228 if( m_pcbnewSettings.m_DrillMarks != DRILL_MARKS::NO_DRILL_SHAPE )
229 {
230 // Enable hole layers to draw drill marks
232 {
233 aView.SetLayerVisible( layer, true );
234 aView.SetTopLayer( layer, true );
235 }
236
237 if( m_pcbnewSettings.m_DrillMarks == DRILL_MARKS::FULL_DRILL_SHAPE
239 {
240 for( int layer : { LAYER_PAD_HOLEWALLS, LAYER_VIA_HOLEWALLS } )
241 {
242 aView.SetLayerVisible( layer, true );
243 aView.SetTopLayer( layer, true );
244 }
245 }
246 }
247}
248
249
251{
253
254 KIGFX::PCB_PRINT_PAINTER& painter = dynamic_cast<KIGFX::PCB_PRINT_PAINTER&>( aPainter );
255
257 {
258 case DRILL_MARKS::NO_DRILL_SHAPE:
259 painter.SetDrillMarks( false, 0 );
260 break;
261
262 case DRILL_MARKS::SMALL_DRILL_SHAPE:
264
265 painter.GetSettings()->SetLayerColor( LAYER_PAD_PLATEDHOLES, COLOR4D::BLACK );
266 painter.GetSettings()->SetLayerColor( LAYER_NON_PLATEDHOLES, COLOR4D::BLACK );
267 painter.GetSettings()->SetLayerColor( LAYER_VIA_HOLES, COLOR4D::BLACK );
268 break;
269
270 case DRILL_MARKS::FULL_DRILL_SHAPE:
271 painter.SetDrillMarks( true );
272
273 painter.GetSettings()->SetLayerColor( LAYER_PAD_PLATEDHOLES, COLOR4D::BLACK );
274 painter.GetSettings()->SetLayerColor( LAYER_NON_PLATEDHOLES, COLOR4D::BLACK );
275 painter.GetSettings()->SetLayerColor( LAYER_VIA_HOLES, COLOR4D::BLACK );
276 break;
277 }
278}
279
280
282{
284 aGal->SetWorldUnitLength( 0.001/pcbIUScale.IU_PER_MM /* 1 nm */ / 0.0254 /* 1 inch in meters */ );
285}
286
287
289{
290 return m_board->ComputeBoundingBox( false );
291}
292
293
294std::unique_ptr<KIGFX::PAINTER> PCBNEW_PRINTOUT::getPainter( KIGFX::GAL* aGal )
295{
296 return std::make_unique<KIGFX::PCB_PRINT_PAINTER>( aGal );
297}
298
299
302 m_drillMarkReal( false ),
303 m_drillMarkSize( 0 )
304{ }
305
306
308{
309 return m_drillMarkReal ? KIGFX::PCB_PAINTER::getDrillShape( aPad ) : PAD_DRILL_SHAPE::CIRCLE;
310}
311
312
314{
315 if( m_drillMarkReal )
317 else
318 return SHAPE_SEGMENT( aPad->GetPosition(), aPad->GetPosition(), m_drillMarkSize );
319}
320
321
323{
324 return m_drillMarkReal ? KIGFX::PCB_PAINTER::getViaDrillSize( aVia ) : m_drillMarkSize;
325}
constexpr EDA_IU_SCALE pcbIUScale
Definition: base_units.h:108
constexpr BOX2I KiROUND(const BOX2D &aBoxD)
Definition: box2.h:990
static const ADVANCED_CFG & GetCfg()
Get the singleton instance's config, which is shared by all consumers.
APP_SETTINGS_BASE is a settings class that should be derived for each standalone KiCad application.
Definition: app_settings.h:92
BASE_SET & set(size_t pos)
Definition: base_set.h:116
An object derived from wxPrintout to handle the necessary information to control a printer when print...
virtual void DrawPage(const wxString &aLayerName=wxEmptyString, int aPageNum=1, int aPageCount=1)
Print a page (or a set of pages).
virtual void setupPainter(KIGFX::PAINTER &aPainter)
Configure #PAINTER object for a printout.
virtual void setupViewLayers(KIGFX::VIEW &aView, const LSET &aLayerSet)
Enable layers visibility for a printout.
virtual void setupGal(KIGFX::GAL *aGal)
Configure #GAL object for a printout.
BOARD_PRINTOUT_SETTINGS m_settings
Printout parameters.
Information pertinent to a Pcbnew printed circuit board.
Definition: board.h:295
bool IsElementVisible(GAL_LAYER_ID aLayer) const
Test whether a given element category is visible.
Definition: board.cpp:883
BOX2I ComputeBoundingBox(bool aBoardEdgesOnly=false) const
Calculate the bounding box containing all board items (or board edge segments).
Definition: board.cpp:1713
const wxString GetLayerName(PCB_LAYER_ID aLayer) const
Return the name of a aLayer.
Definition: board.cpp:613
A color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:104
Abstract interface for drawing on a 2D-surface.
void SetWorldUnitLength(double aWorldUnitLength)
Set the unit length.
Contains all the knowledge about how to draw graphical object onto any particular output device.
Definition: painter.h:59
virtual RENDER_SETTINGS * GetSettings()=0
Return a pointer to current settings that are going to be used when drawing items.
Contains methods for drawing PCB-specific items.
Definition: pcb_painter.h:180
virtual SHAPE_SEGMENT getPadHoleShape(const PAD *aPad) const
Return hole shape for a pad (internal units).
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:185
virtual PAD_DRILL_SHAPE getDrillShape(const PAD *aPad) const
Return drill shape of a pad.
virtual int getViaDrillSize(const PCB_VIA *aVia) const
Return drill diameter for a via (internal units).
Special flavor of PCB_PAINTER that contains modifications to handle printing options.
void SetDrillMarks(bool aRealSize, unsigned int aSize=0)
Set drill marks visibility and options.
SHAPE_SEGMENT getPadHoleShape(const PAD *aPad) const override
Return hole shape for a pad (internal units).
int getViaDrillSize(const PCB_VIA *aVia) const override
Return drill diameter for a via (internal units).
PAD_DRILL_SHAPE getDrillShape(const PAD *aPad) const override
Return drill shape of a pad.
Container for all the knowledge about how graphical objects are drawn on any output surface/device.
void SetLayerColor(int aLayer, const COLOR4D &aColor)
Change the color used to draw a layer.
Hold a (potentially large) number of VIEW_ITEMs and renders them on a graphics device provided by the...
Definition: view.h:67
void SetLayerVisible(int aLayer, bool aVisible=true)
Control the visibility of a particular layer.
Definition: view.h:396
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:829
PAINTER * GetPainter() const
Return the painter object used by the view for drawing #VIEW_ITEMS.
Definition: view.h:216
LSEQ is a sequence (and therefore also a set) of PCB_LAYER_IDs.
Definition: lseq.h:47
LSET is a set of PCB_LAYER_IDs.
Definition: lset.h:37
LSEQ UIOrder() const
Return the copper, technical and user layers in the order shown in layer widget.
Definition: lset.cpp:688
PCB_LAYER_ID ExtractLayer() const
Find the first set PCB_LAYER_ID.
Definition: lset.cpp:516
static LSET AllCuMask(int aCuLayerCount=MAX_CU_LAYERS)
Return a mask holding the requested number of Cu PCB_LAYER_IDs.
Definition: lset.cpp:562
LSEQ Seq(const LSEQ &aSequence) const
Return an LSEQ from the union of this LSET and a desired sequence.
Definition: lset.cpp:295
Definition: pad.h:54
VECTOR2I GetPosition() const override
Definition: pad.h:206
Describe the page size and margins of a paper page on which to eventually print or plot.
Definition: page_info.h:59
int milsToIU(double aMils) const override
Convert mils to internal units.
bool OnPrintPage(int aPage) override
std::unique_ptr< KIGFX::PAINTER > getPainter(KIGFX::GAL *aGal) override
Return the #PAINTER instance used to draw the items.
void setupGal(KIGFX::GAL *aGal) override
Configure #GAL object for a printout.
PCBNEW_PRINTOUT(BOARD *aBoard, const PCBNEW_PRINTOUT_SETTINGS &aParams, const KIGFX::VIEW *aView, const wxString &aTitle)
PCBNEW_PRINTOUT_SETTINGS m_pcbnewSettings
void setupPainter(KIGFX::PAINTER &aPainter) override
Configure #PAINTER object for a printout.
BOX2I getBoundingBox() override
Return bounding box of the printed objects (excluding drawing-sheet frame).
void setupViewLayers(KIGFX::VIEW &aView, const LSET &aLayerSet) override
Enable layers visibility for a printout.
DIALOG_PLOT m_Plot
virtual SETTINGS_MANAGER & GetSettingsManager() const
Definition: pgm_base.h:125
T * GetAppSettings(const wxString &aFilename)
Return a handle to the a given settings by type.
#define _(s)
@ FRAME_PCB_EDITOR
Definition: frame_type.h:42
double m_SmallDrillMarkSize
The diameter of the drill marks on print and plot outputs (in mm) when the "Drill marks" option is se...
constexpr PCB_LAYER_ID PCBNEW_LAYER_ID_START
Definition: layer_ids.h:138
GAL_LAYER_ID
GAL layers are "virtual" layers, i.e.
Definition: layer_ids.h:191
@ LAYER_GRID
Definition: layer_ids.h:216
@ LAYER_PAD_COPPER_START
Virtual layers for pad copper on a given copper layer.
Definition: layer_ids.h:294
@ LAYER_VIA_HOLEWALLS
Definition: layer_ids.h:260
@ LAYER_FOOTPRINTS_FR
Show footprints on front.
Definition: layer_ids.h:221
@ LAYER_DRC_SHAPE1
Custom shape for DRC marker.
Definition: layer_ids.h:277
@ LAYER_NON_PLATEDHOLES
Draw usual through hole vias.
Definition: layer_ids.h:201
@ LAYER_DRAWINGSHEET
Sheet frame and title block.
Definition: layer_ids.h:240
@ LAYER_FP_REFERENCES
Show footprints references (when texts are visible).
Definition: layer_ids.h:228
@ LAYER_DRC_EXCLUSION
Layer for DRC markers which have been individually excluded.
Definition: layer_ids.h:266
@ LAYER_ZONES
Control for copper zone opacity/visibility (color ignored).
Definition: layer_ids.h:257
@ LAYER_SHAPES
Copper graphic shape opacity/visibility (color ignored).
Definition: layer_ids.h:275
@ LAYER_PADS
Meta control for all pads opacity/visibility (color ignored).
Definition: layer_ids.h:254
@ LAYER_DRC_WARNING
Layer for DRC markers with #SEVERITY_WARNING.
Definition: layer_ids.h:263
@ LAYER_PAD_PLATEDHOLES
to draw pad holes (plated)
Definition: layer_ids.h:233
@ LAYER_VIA_COPPER_START
Virtual layers for via copper on a given copper layer.
Definition: layer_ids.h:298
@ LAYER_TRACKS
Definition: layer_ids.h:229
@ LAYER_DRC_SHAPE2
Custom shape for DRC marker.
Definition: layer_ids.h:278
@ LAYER_ZONE_START
Virtual layers for stacking zones and tracks on a given copper layer.
Definition: layer_ids.h:290
@ LAYER_FP_TEXT
Definition: layer_ids.h:202
@ LAYER_FOOTPRINTS_BK
Show footprints on back.
Definition: layer_ids.h:222
@ LAYER_ANCHOR
Anchor of items having an anchor point (texts, footprints).
Definition: layer_ids.h:210
@ LAYER_VIA_HOLES
Draw via holes (pad holes do not use this layer).
Definition: layer_ids.h:236
@ LAYER_FP_VALUES
Show footprints values (when texts are visible).
Definition: layer_ids.h:225
@ LAYER_VIA_MICROVIA
Definition: layer_ids.h:196
@ LAYER_VIA_THROUGH
Draw blind/buried vias.
Definition: layer_ids.h:198
@ LAYER_DRC_ERROR
Layer for DRC markers with #SEVERITY_ERROR.
Definition: layer_ids.h:239
@ LAYER_VIAS
Meta control for all vias opacity/visibility.
Definition: layer_ids.h:195
@ LAYER_VIA_BBLIND
Draw micro vias.
Definition: layer_ids.h:197
@ LAYER_PAD_HOLEWALLS
Definition: layer_ids.h:259
PCB_LAYER_ID
A quick note on layer IDs:
Definition: layer_ids.h:60
@ Edge_Cuts
Definition: layer_ids.h:112
@ UNDEFINED_LAYER
Definition: layer_ids.h:61
PAD_DRILL_SHAPE
The set of pad drill shapes, used with PAD::{Set,Get}DrillShape()
Definition: padstack.h:69
PGM_BASE & Pgm()
The global program "get" accessor.
Definition: pgm_base.cpp:1073
see class PGM_BASE
DRILL_MARKS
Plots and prints can show holes in pads and vias 3 options are available:
void Load(APP_SETTINGS_BASE *aConfig) override
LSET m_LayerSet
Layers to print.
void Save(APP_SETTINGS_BASE *aConfig) override
bool m_Mirror
Print mirrored.
const double IU_PER_MM
Definition: base_units.h:76
const double IU_PER_MILS
Definition: base_units.h:77
constexpr int mmToIU(double mm) const
Definition: base_units.h:88
enum PCBNEW_PRINTOUT_SETTINGS::PAGINATION_T m_Pagination
bool m_PrintEdgeCutsOnAllPages
Print board outline on each page.
enum DRILL_MARKS m_DrillMarks
bool m_AsItemCheckboxes
Honor checkboxes in the Items tab of the Layers Manager.
void Load(APP_SETTINGS_BASE *aConfig) override
void Save(APP_SETTINGS_BASE *aConfig) override
PCBNEW_PRINTOUT_SETTINGS(const PAGE_INFO &aPageInfo)
bool m_blackWhite
Print in B&W or Color.
Definition: printout.h:60