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 (C) 1992-2023 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 <pcb_painter.h>
33#include <pcbnew_settings.h>
34#include <view/view.h>
35#include <pcbplot.h>
37#include <pad.h>
38
39#include <advanced_config.h>
40
42 BOARD_PRINTOUT_SETTINGS( aPageInfo )
43{
44 m_DrillMarks = DRILL_MARKS::SMALL_DRILL_SHAPE;
47 m_AsItemCheckboxes = false;
48}
49
50
52{
54
55 if( PCBNEW_SETTINGS* cfg = dynamic_cast<PCBNEW_SETTINGS*>( aConfig ) )
56 {
57 m_DrillMarks = static_cast<DRILL_MARKS>( cfg->m_Plot.pads_drill_mode );
58 m_Pagination = static_cast<PAGINATION_T>( cfg->m_Plot.all_layers_on_one_page );
59 m_PrintEdgeCutsOnAllPages = cfg->m_Plot.edgecut_on_all_layers;
60 m_Mirror = cfg->m_Plot.mirror;
61 m_AsItemCheckboxes = cfg->m_Plot.as_item_checkboxes;
62 }
63}
64
65
67{
69
70 if( PCBNEW_SETTINGS* cfg = dynamic_cast<PCBNEW_SETTINGS*>( aConfig ) )
71 {
72 cfg->m_Plot.pads_drill_mode = (int)m_DrillMarks;
73 cfg->m_Plot.all_layers_on_one_page = m_Pagination;
74 cfg->m_Plot.edgecut_on_all_layers = m_PrintEdgeCutsOnAllPages;
75 cfg->m_Plot.mirror = m_Mirror;
76 cfg->m_Plot.as_item_checkboxes = m_AsItemCheckboxes;
77 }
78}
79
80
82 const KIGFX::VIEW* aView, const wxString& aTitle ) :
83 BOARD_PRINTOUT( aParams, aView, aTitle ), m_pcbnewSettings( aParams )
84{
85 m_board = aBoard;
86}
87
88
90{
91 // Store the layerset, as it is going to be modified below and the original settings are
92 // needed.
94 int pageCount = lset.count();
95 wxString layerName;
96 PCB_LAYER_ID extractLayer;
97
98 // compute layer mask from page number if we want one page per layer
100 {
101 // This sequence is TBD, call a different sequencer if needed, such as Seq().
102 // Could not find documentation on page order.
103 LSEQ seq = lset.UIOrder();
104
105 // aPage starts at 1, not 0
106 if( unsigned( aPage - 1 ) < seq.size() )
107 m_settings.m_LayerSet = LSET( seq[ aPage - 1] );
108 }
109
110 if( !m_settings.m_LayerSet.any() )
111 return false;
112
113 extractLayer = m_settings.m_LayerSet.ExtractLayer();
114
115 if( extractLayer == UNDEFINED_LAYER )
116 layerName = _( "Multiple Layers" );
117 else
118 layerName = m_board->GetLayerName( extractLayer );
119
120 // In Pcbnew we can want the layer EDGE always printed
123
124 DrawPage( layerName, aPage, pageCount );
125
126 // Restore the original layer set, so the next page can be printed
127 m_settings.m_LayerSet = lset;
128
129 return true;
130}
131
132
133int PCBNEW_PRINTOUT::milsToIU( double aMils ) const
134{
135 return KiROUND( pcbIUScale.IU_PER_MILS * aMils );
136}
137
138
139void PCBNEW_PRINTOUT::setupViewLayers( KIGFX::VIEW& aView, const LSET& aLayerSet )
140{
141 BOARD_PRINTOUT::setupViewLayers( aView, aLayerSet );
142
143 for( PCB_LAYER_ID layer : m_settings.m_LayerSet.Seq() )
144 {
145 aView.SetLayerVisible( PCBNEW_LAYER_ID_START + layer, true );
146
147 // Enable the corresponding zone layer (copper layers and other layers)
148 aView.SetLayerVisible( LAYER_ZONE_START + layer, true );
149 }
150
151 RENDER_SETTINGS* renderSettings = aView.GetPainter()->GetSettings();
152 // A color to do not print objects on some layers, when the layer must be enabled
153 // to print some other objects
154 COLOR4D invisible_color = COLOR4D::UNSPECIFIED;
155
157 {
158 auto setVisibility =
159 [&]( GAL_LAYER_ID aLayer )
160 {
161 if( m_board->IsElementVisible( aLayer ) )
162 aView.SetLayerVisible( aLayer, true );
163 else
164 renderSettings->SetLayerColor( aLayer, invisible_color );
165 };
166
167 setVisibility( LAYER_FOOTPRINTS_FR );
168 setVisibility( LAYER_FOOTPRINTS_BK );
169 setVisibility( LAYER_FP_VALUES );
170 setVisibility( LAYER_FP_REFERENCES );
171 setVisibility( LAYER_FP_TEXT );
172 setVisibility( LAYER_HIDDEN_TEXT );
173 setVisibility( LAYER_PADS );
174 setVisibility( LAYER_PADS_SMD_FR );
175 setVisibility( LAYER_PADS_SMD_BK );
176 setVisibility( LAYER_PADS_TH );
177
178 setVisibility( LAYER_TRACKS );
179 setVisibility( LAYER_VIAS );
180 setVisibility( LAYER_VIA_MICROVIA );
181 setVisibility( LAYER_VIA_BBLIND );
182 setVisibility( LAYER_VIA_THROUGH );
183 setVisibility( LAYER_ZONES );
184
185 setVisibility( LAYER_DRC_WARNING );
186 setVisibility( LAYER_DRC_ERROR );
187 setVisibility( LAYER_DRC_EXCLUSION );
188 setVisibility( LAYER_ANCHOR );
189 setVisibility( LAYER_DRAWINGSHEET );
190 setVisibility( LAYER_GRID );
191 }
192 else
193 {
194 // Draw layers that must be not visible on printing are set to an invisible layer
195 // LAYER_PADS_SMD_FR, LAYER_PADS_SMD_BK and LAYER_PADS_TH must be enabled to print pads on
196 // technical layers, but not the pad on copper layer(s) if they are not enabled
197
198 if( !aLayerSet.test( F_Cu ) )
199 renderSettings->SetLayerColor( LAYER_PADS_SMD_FR, invisible_color );
200
201 if( !aLayerSet.test( B_Cu ) )
202 renderSettings->SetLayerColor( LAYER_PADS_SMD_BK, invisible_color );
203
204 // Enable items on copper layers, but do not draw holes
206 {
207 if( ( aLayerSet & LSET::AllCuMask() ).any() ) // Items visible on any copper layer
208 aView.SetLayerVisible( layer, true );
209 else
210 renderSettings->SetLayerColor( layer, invisible_color );
211 }
212
213 // Keep certain items always enabled/disabled and just rely on the layer visibility
214 // Note LAYER_PADS_SMD_FR, LAYER_PADS_SMD_BK, LAYER_PADS_TH are enabled here because paths must
215 // be drawn on some other (technical) layers.
216 const int alwaysEnabled[] =
217 {
223 };
224
225 for( int layer : alwaysEnabled )
226 aView.SetLayerVisible( layer, true );
227 }
228
229 if( m_pcbnewSettings.m_DrillMarks != DRILL_MARKS::NO_DRILL_SHAPE )
230 {
231 // Enable hole layers to draw drill marks
233 {
234 aView.SetLayerVisible( layer, true );
235 aView.SetTopLayer( layer, true );
236 }
237
238 if( m_pcbnewSettings.m_DrillMarks == DRILL_MARKS::FULL_DRILL_SHAPE
240 {
241 for( int layer : { LAYER_PAD_HOLEWALLS, LAYER_VIA_HOLEWALLS } )
242 {
243 aView.SetLayerVisible( layer, true );
244 aView.SetTopLayer( layer, true );
245 }
246 }
247 }
248}
249
250
252{
254
255 KIGFX::PCB_PRINT_PAINTER& painter = dynamic_cast<KIGFX::PCB_PRINT_PAINTER&>( aPainter );
256
258 {
259 case DRILL_MARKS::NO_DRILL_SHAPE:
260 painter.SetDrillMarks( false, 0 );
261 break;
262
263 case DRILL_MARKS::SMALL_DRILL_SHAPE:
265
266 painter.GetSettings()->SetLayerColor( LAYER_PAD_PLATEDHOLES, COLOR4D::BLACK );
267 painter.GetSettings()->SetLayerColor( LAYER_NON_PLATEDHOLES, COLOR4D::BLACK );
268 painter.GetSettings()->SetLayerColor( LAYER_VIA_HOLES, COLOR4D::BLACK );
269 break;
270
271 case DRILL_MARKS::FULL_DRILL_SHAPE:
272 painter.SetDrillMarks( true );
273
274 painter.GetSettings()->SetLayerColor( LAYER_PAD_PLATEDHOLES, COLOR4D::BLACK );
275 painter.GetSettings()->SetLayerColor( LAYER_NON_PLATEDHOLES, COLOR4D::BLACK );
276 painter.GetSettings()->SetLayerColor( LAYER_VIA_HOLES, COLOR4D::BLACK );
277 break;
278 }
279}
280
281
283{
285 aGal->SetWorldUnitLength( 0.001/pcbIUScale.IU_PER_MM /* 1 nm */ / 0.0254 /* 1 inch in meters */ );
286}
287
288
290{
291 return m_board->ComputeBoundingBox();
292}
293
294
295std::unique_ptr<KIGFX::PAINTER> PCBNEW_PRINTOUT::getPainter( KIGFX::GAL* aGal )
296{
297 return std::make_unique<KIGFX::PCB_PRINT_PAINTER>( aGal );
298}
299
300
303 m_drillMarkReal( false ),
304 m_drillMarkSize( 0 )
305{ }
306
307
309{
310 return m_drillMarkReal ? KIGFX::PCB_PAINTER::getDrillShape( aPad ) : PAD_DRILL_SHAPE_CIRCLE;
311}
312
313
315{
316 if( m_drillMarkReal )
318 else
319 return SHAPE_SEGMENT( aPad->GetPosition(), aPad->GetPosition(), m_drillMarkSize );
320}
321
322
324{
325 return m_drillMarkReal ? KIGFX::PCB_PAINTER::getViaDrillSize( aVia ) : m_drillMarkSize;
326}
constexpr EDA_IU_SCALE pcbIUScale
Definition: base_units.h:108
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
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)
Configures GAL object for a printout.
virtual void setupViewLayers(KIGFX::VIEW &aView, const LSET &aLayerSet)
Configures PAINTER object for a printout.
virtual void setupGal(KIGFX::GAL *aGal)
Returns bounding box of the printed objects (excluding drawing-sheet frame)
BOARD_PRINTOUT_SETTINGS m_settings
Information pertinent to a Pcbnew printed circuit board.
Definition: board.h:281
bool IsElementVisible(GAL_LAYER_ID aLayer) const
Test whether a given element category is visible.
Definition: board.cpp:746
BOX2I ComputeBoundingBox(bool aBoardEdgesOnly=false) const
Calculate the bounding box containing all board items (or board edge segments).
Definition: board.cpp:1555
const wxString GetLayerName(PCB_LAYER_ID aLayer) const
Return the name of a aLayer.
Definition: board.cpp:567
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:164
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:169
virtual int 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).
int 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:68
void SetLayerVisible(int aLayer, bool aVisible=true)
Control the visibility of a particular layer.
Definition: view.h:395
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
PAINTER * GetPainter() const
Return the painter object used by the view for drawing #VIEW_ITEMS.
Definition: view.h:215
LSEQ is a sequence (and therefore also a set) of PCB_LAYER_IDs.
Definition: layer_ids.h:520
LSET is a set of PCB_LAYER_IDs.
Definition: layer_ids.h:574
LSEQ UIOrder() const
Definition: lset.cpp:1012
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:418
PCB_LAYER_ID ExtractLayer() const
Find the first set PCB_LAYER_ID.
Definition: lset.cpp:774
static LSET AllCuMask(int aCuLayerCount=MAX_CU_LAYERS)
Return a mask holding the requested number of Cu PCB_LAYER_IDs.
Definition: lset.cpp:863
Definition: pad.h:59
VECTOR2I GetPosition() const override
Definition: pad.h:201
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
Source VIEW object (note that actual printing only refers to this object)
void setupGal(KIGFX::GAL *aGal) override
Returns bounding box of the printed objects (excluding drawing-sheet frame)
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
Configures GAL object for a printout.
BOX2I getBoundingBox() override
Returns a PAINTER instance used to draw the items.
void setupViewLayers(KIGFX::VIEW &aView, const LSET &aLayerSet) override
Configures PAINTER object for a printout.
#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:140
GAL_LAYER_ID
GAL layers are "virtual" layers, i.e.
Definition: layer_ids.h:194
@ LAYER_GRID
Definition: layer_ids.h:209
@ LAYER_VIA_HOLEWALLS
Definition: layer_ids.h:238
@ LAYER_FOOTPRINTS_FR
show footprints on front
Definition: layer_ids.h:212
@ LAYER_NON_PLATEDHOLES
handle color for not plated holes (holes, not pads)
Definition: layer_ids.h:201
@ LAYER_DRAWINGSHEET
drawingsheet frame and titleblock
Definition: layer_ids.h:221
@ LAYER_FP_REFERENCES
show footprints references (when texts are visible)
Definition: layer_ids.h:215
@ LAYER_DRC_EXCLUSION
layer for drc markers which have been individually excluded
Definition: layer_ids.h:240
@ LAYER_ZONES
Control for copper zone opacity/visibility (color ignored)
Definition: layer_ids.h:235
@ LAYER_PADS
Meta control for all pads opacity/visibility (color ignored)
Definition: layer_ids.h:234
@ LAYER_DRC_WARNING
layer for drc markers with SEVERITY_WARNING
Definition: layer_ids.h:239
@ LAYER_PAD_PLATEDHOLES
to draw pad holes (plated)
Definition: layer_ids.h:218
@ LAYER_HIDDEN_TEXT
text marked as invisible
Definition: layer_ids.h:204
@ LAYER_TRACKS
Definition: layer_ids.h:216
@ LAYER_ZONE_START
Virtual layers for stacking zones and tracks on a given copper layer.
Definition: layer_ids.h:257
@ LAYER_FP_TEXT
Definition: layer_ids.h:202
@ LAYER_FOOTPRINTS_BK
show footprints on back
Definition: layer_ids.h:213
@ LAYER_ANCHOR
anchor of items having an anchor point (texts, footprints)
Definition: layer_ids.h:205
@ LAYER_PADS_SMD_BK
smd pads, back layer
Definition: layer_ids.h:207
@ LAYER_PADS_TH
multilayer pads, usually with holes
Definition: layer_ids.h:217
@ LAYER_PADS_SMD_FR
smd pads, front layer
Definition: layer_ids.h:206
@ LAYER_VIA_HOLES
to draw via holes (pad holes do not use this layer)
Definition: layer_ids.h:219
@ LAYER_FP_VALUES
show footprints values (when texts are visible)
Definition: layer_ids.h:214
@ LAYER_VIA_MICROVIA
to draw micro vias
Definition: layer_ids.h:198
@ LAYER_VIA_THROUGH
to draw usual through hole vias
Definition: layer_ids.h:200
@ LAYER_DRC_ERROR
layer for drc markers with SEVERITY_ERROR
Definition: layer_ids.h:220
@ LAYER_VIAS
Meta control for all vias opacity/visibility.
Definition: layer_ids.h:197
@ LAYER_VIA_BBLIND
to draw blind/buried vias
Definition: layer_ids.h:199
@ LAYER_PAD_HOLEWALLS
Definition: layer_ids.h:237
PCB_LAYER_ID
A quick note on layer IDs:
Definition: layer_ids.h:60
@ Edge_Cuts
Definition: layer_ids.h:113
@ B_Cu
Definition: layer_ids.h:95
@ UNDEFINED_LAYER
Definition: layer_ids.h:61
@ F_Cu
Definition: layer_ids.h:64
@ PAD_DRILL_SHAPE_CIRCLE
Definition: pad_shapes.h:54
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
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:118