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, see <https://www.gnu.org/licenses/>.
22 */
23
24#include "pcbnew_printout.h"
25#include <board.h>
26#include <math/util.h> // for KiROUND
28#include <lset.h>
29#include <pcb_painter.h>
30#include <pcbnew_settings.h>
31#include <view/view.h>
32#include <pcbplot.h>
34#include <pad.h>
35
36#include <advanced_config.h>
37#include <pgm_base.h>
38
47
48
58
59
69
70
72 const KIGFX::VIEW* aView, const wxString& aTitle ) :
73 BOARD_PRINTOUT( aParams, aView, aTitle ), m_pcbnewSettings( aParams )
74{
75 m_board = aBoard;
76}
77
78
80{
81 // Store the layerset, as it is going to be modified below and the original settings are
82 // needed.
83 LSET lset = m_settings.m_LayerSet;
84 int pageCount = lset.count();
85 wxString layerName;
86 PCB_LAYER_ID extractLayer;
87
88 // compute layer mask from page number if we want one page per layer
90 {
91 // This sequence is TBD, call a different sequencer if needed, such as Seq().
92 // Could not find documentation on page order.
93 LSEQ seq = lset.UIOrder();
94
95 // aPage starts at 1, not 0
96 if( unsigned( aPage - 1 ) < seq.size() )
97 m_settings.m_LayerSet = LSET( { seq[aPage - 1] } );
98 }
99
100 if( !m_settings.m_LayerSet.any() )
101 return false;
102
103 extractLayer = m_settings.m_LayerSet.ExtractLayer();
104
105 if( extractLayer == UNDEFINED_LAYER )
106 layerName = _( "Multiple Layers" );
107 else
108 layerName = m_board->GetLayerName( extractLayer );
109
110 // In Pcbnew we can want the layer EDGE always printed
111 if( m_pcbnewSettings.m_PrintEdgeCutsOnAllPages )
112 m_settings.m_LayerSet.set( Edge_Cuts );
113
114 DrawPage( layerName, aPage, pageCount );
115
116 // Restore the original layer set, so the next page can be printed
117 m_settings.m_LayerSet = lset;
118
119 return true;
120}
121
122
123int PCBNEW_PRINTOUT::milsToIU( double aMils ) const
124{
125 return KiROUND( pcbIUScale.IU_PER_MILS * aMils );
126}
127
128
129void PCBNEW_PRINTOUT::setupViewLayers( KIGFX::VIEW& aView, const LSET& aLayerSet )
130{
131 BOARD_PRINTOUT::setupViewLayers( aView, aLayerSet );
132
133 for( PCB_LAYER_ID layer : m_settings.m_LayerSet )
134 {
135 aView.SetLayerVisible( PCBNEW_LAYER_ID_START + layer, true );
136
137 // Enable the corresponding zone layer (copper layers and other layers)
138 aView.SetLayerVisible( LAYER_ZONE_START + layer, true );
139 aView.SetLayerVisible( LAYER_PAD_COPPER_START + layer, true );
140 aView.SetLayerVisible( LAYER_VIA_COPPER_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 = COLOR4D::UNSPECIFIED;
147
148 if( m_pcbnewSettings.m_AsItemCheckboxes )
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_FOOTPRINTS_FR );
160 setVisibility( LAYER_FOOTPRINTS_BK );
161 setVisibility( LAYER_FP_VALUES );
162 setVisibility( LAYER_FP_REFERENCES );
163 setVisibility( LAYER_FP_TEXT );
164 setVisibility( LAYER_PADS );
165
166 setVisibility( LAYER_TRACKS );
167 setVisibility( LAYER_VIAS );
168 setVisibility( LAYER_VIA_MICROVIA );
169 setVisibility( LAYER_VIA_BLIND );
170 setVisibility( LAYER_VIA_BURIED );
171 setVisibility( LAYER_VIA_THROUGH );
172 setVisibility( LAYER_ZONES );
173 setVisibility( LAYER_FILLED_SHAPES );
174
175 setVisibility( LAYER_DRC_WARNING );
176 setVisibility( LAYER_DRC_ERROR );
177 setVisibility( LAYER_DRC_SHAPES );
178 setVisibility( LAYER_DRC_EXCLUSION );
179 setVisibility( LAYER_ANCHOR );
180 setVisibility( LAYER_DRAWINGSHEET );
181 setVisibility( LAYER_GRID );
182 }
183 else
184 {
185 // Enable items on copper layers, but do not draw holes
187 {
188 if( ( aLayerSet & LSET::AllCuMask() ).any() ) // Items visible on any copper layer
189 aView.SetLayerVisible( layer, true );
190 else
191 renderSettings->SetLayerColor( layer, invisible_color );
192 }
193
194 // Keep certain items always enabled/disabled and just rely on the layer visibility
195 // Note LAYER_PADS_SMD_FR, LAYER_PADS_SMD_BK, LAYER_PADS_TH are enabled here because paths must
196 // be drawn on some other (technical) layers.
197 const int alwaysEnabled[] =
198 {
204 };
205
206 for( int layer : alwaysEnabled )
207 aView.SetLayerVisible( layer, true );
208 }
209
211 {
212 // Enable hole layers to draw drill marks
214 {
215 aView.SetLayerVisible( layer, true );
216 aView.SetTopLayer( layer, true );
217 }
218
220 && !m_settings.m_blackWhite )
221 {
222 for( int layer : { LAYER_PAD_HOLEWALLS, LAYER_VIA_HOLEWALLS } )
223 {
224 aView.SetLayerVisible( layer, true );
225 aView.SetTopLayer( layer, true );
226 }
227 }
228 }
229}
230
231
233{
235
236 KIGFX::PCB_PRINT_PAINTER& painter = dynamic_cast<KIGFX::PCB_PRINT_PAINTER&>( aPainter );
237
238 switch( m_pcbnewSettings.m_DrillMarks )
239 {
241 painter.SetDrillMarks( false, 0 );
242 break;
243
245 painter.SetDrillMarks( false, pcbIUScale.mmToIU( ADVANCED_CFG::GetCfg().m_SmallDrillMarkSize ) );
246
250 break;
251
253 painter.SetDrillMarks( true );
254
258 break;
259 }
260}
261
262
264{
266 aGal->SetWorldUnitLength( 0.001/pcbIUScale.IU_PER_MM /* 1 nm */ / 0.0254 /* 1 inch in meters */ );
267}
268
269
271{
272 return m_board->ComputeBoundingBox( false, false );
273}
274
275
276std::unique_ptr<KIGFX::PAINTER> PCBNEW_PRINTOUT::getPainter( KIGFX::GAL* aGal )
277{
278 return std::make_unique<KIGFX::PCB_PRINT_PAINTER>( aGal );
279}
280
281
287
288
293
294
296{
297 if( m_drillMarkReal )
299 else
300 return SHAPE_SEGMENT( aPad->GetPosition(), aPad->GetPosition(), m_drillMarkSize );
301}
302
303
constexpr EDA_IU_SCALE pcbIUScale
Definition base_units.h:121
BOX2< VECTOR2I > BOX2I
Definition box2.h:918
constexpr BOX2I KiROUND(const BOX2D &aBoxD)
Definition box2.h:986
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.
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.
BOARD_PRINTOUT(const BOARD_PRINTOUT_SETTINGS &aParams, const KIGFX::VIEW *aView, const wxString &aTitle)
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:372
static const COLOR4D UNSPECIFIED
For legacy support; used as a value to indicate color hasn't been set yet.
Definition color4d.h:398
static const COLOR4D BLACK
Definition color4d.h:402
A color representation with 4 components: red, green, blue, alpha.
Definition color4d.h:101
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:55
virtual RENDER_SETTINGS * GetSettings()=0
Return a pointer to current settings that are going to be used when drawing items.
virtual SHAPE_SEGMENT getPadHoleShape(const PAD *aPad) const
Return hole shape for a pad (internal units).
PCB_PAINTER(GAL *aGal, FRAME_T aFrameType)
virtual PCB_RENDER_SETTINGS * GetSettings() override
Return a pointer to current settings that are going to be used when drawing items.
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).
int m_drillMarkSize
User-specified size (in internal units)
PAD_DRILL_SHAPE getDrillShape(const PAD *aPad) const override
Return drill shape of a pad.
bool m_drillMarkReal
Actual hole size or user-specified size for drill marks.
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:63
void SetLayerVisible(int aLayer, bool aVisible=true)
Control the visibility of a particular layer.
Definition view.h:405
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:908
PAINTER * GetPainter() const
Return the painter object used by the view for drawing #VIEW_ITEMS.
Definition view.h:225
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:739
static LSET AllCuMask(int aCuLayerCount)
Return a mask holding the requested number of Cu PCB_LAYER_IDs.
Definition lset.cpp:595
Definition pad.h:61
VECTOR2I GetPosition() const override
Definition pad.cpp:245
Describe the page size and margins of a paper page on which to eventually print or plot.
Definition page_info.h:75
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.
A type-safe container of any type.
Definition ki_any.h:92
#define _(s)
@ FRAME_PCB_EDITOR
Definition frame_type.h:38
constexpr PCB_LAYER_ID PCBNEW_LAYER_ID_START
Definition layer_ids.h:170
GAL_LAYER_ID
GAL layers are "virtual" layers, i.e.
Definition layer_ids.h:224
@ LAYER_GRID
Definition layer_ids.h:250
@ LAYER_PAD_COPPER_START
Virtual layers for pad copper on a given copper layer.
Definition layer_ids.h:335
@ LAYER_VIA_HOLEWALLS
Definition layer_ids.h:294
@ LAYER_FILLED_SHAPES
Copper graphic shape opacity/visibility (color ignored).
Definition layer_ids.h:309
@ LAYER_FOOTPRINTS_FR
Show footprints on front.
Definition layer_ids.h:255
@ LAYER_NON_PLATEDHOLES
Draw usual through hole vias.
Definition layer_ids.h:235
@ LAYER_DRAWINGSHEET
Sheet frame and title block.
Definition layer_ids.h:274
@ LAYER_FP_REFERENCES
Show footprints references (when texts are visible).
Definition layer_ids.h:262
@ LAYER_DRC_EXCLUSION
Layer for DRC markers which have been individually excluded.
Definition layer_ids.h:300
@ LAYER_ZONES
Control for copper zone opacity/visibility (color ignored).
Definition layer_ids.h:291
@ LAYER_DRC_SHAPES
Custom shapes for DRC markers.
Definition layer_ids.h:311
@ LAYER_PADS
Meta control for all pads opacity/visibility (color ignored).
Definition layer_ids.h:288
@ LAYER_DRC_WARNING
Layer for DRC markers with #SEVERITY_WARNING.
Definition layer_ids.h:297
@ LAYER_PAD_PLATEDHOLES
to draw pad holes (plated)
Definition layer_ids.h:267
@ LAYER_VIA_COPPER_START
Virtual layers for via copper on a given copper layer.
Definition layer_ids.h:339
@ LAYER_TRACKS
Definition layer_ids.h:263
@ LAYER_ZONE_START
Virtual layers for stacking zones and tracks on a given copper layer.
Definition layer_ids.h:331
@ LAYER_FP_TEXT
Definition layer_ids.h:236
@ LAYER_FOOTPRINTS_BK
Show footprints on back.
Definition layer_ids.h:256
@ LAYER_ANCHOR
Anchor of items having an anchor point (texts, footprints).
Definition layer_ids.h:244
@ LAYER_VIA_BURIED
Draw blind vias.
Definition layer_ids.h:231
@ LAYER_VIA_HOLES
Draw via holes (pad holes do not use this layer).
Definition layer_ids.h:270
@ LAYER_VIA_BLIND
Draw micro vias.
Definition layer_ids.h:230
@ LAYER_FP_VALUES
Show footprints values (when texts are visible).
Definition layer_ids.h:259
@ LAYER_VIA_MICROVIA
Definition layer_ids.h:229
@ LAYER_VIA_THROUGH
Draw buried vias.
Definition layer_ids.h:232
@ LAYER_DRC_ERROR
Layer for DRC markers with #SEVERITY_ERROR.
Definition layer_ids.h:273
@ LAYER_VIAS
Meta control for all vias opacity/visibility.
Definition layer_ids.h:228
@ LAYER_PAD_HOLEWALLS
Definition layer_ids.h:293
PCB_LAYER_ID
A quick note on layer IDs:
Definition layer_ids.h:56
@ Edge_Cuts
Definition layer_ids.h:108
@ UNDEFINED_LAYER
Definition layer_ids.h:57
PAD_DRILL_SHAPE
The set of pad drill shapes, used with PAD::{Set,Get}DrillShape()
Definition padstack.h:69
see class PGM_BASE
DRILL_MARKS
Plots and prints can show holes in pads and vias 3 options are available:
int pagination
0=all layers on one page, 1=one page per layer.
bool edge_cuts_on_all_pages
Print board edges on all pages.
int drill_marks
Drill marks type (0=none, 1=small, 2=real).
bool as_item_checkboxes
Honor checkboxes in appearance manager.
void Load(APP_SETTINGS_BASE *aConfig) override
BOARD_PRINTOUT_SETTINGS(const PAGE_INFO &aPageInfo)
void Save(APP_SETTINGS_BASE *aConfig) override
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)