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-2016 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 <class_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 
37  : BOARD_PRINTOUT_SETTINGS( aPageInfo )
38 {
41  m_noEdgeLayer = false;
42 }
43 
44 
46 {
48 
49  if( auto cfg = dynamic_cast<PCBNEW_SETTINGS*>( aConfig ) )
50  {
51  m_drillMarks = static_cast<DRILL_MARK_SHAPE_T>( cfg->m_Plot.pads_drill_mode );
52  m_pagination = static_cast<PAGINATION_T>( cfg->m_Plot.one_page_per_layer );
53  }
54 }
55 
56 
58 {
60 
61  if( auto cfg = dynamic_cast<PCBNEW_SETTINGS*>( aConfig ) )
62  {
63  cfg->m_Plot.pads_drill_mode = m_drillMarks;
64  cfg->m_Plot.one_page_per_layer = m_pagination;
65  }
66 }
67 
68 
70  const KIGFX::VIEW* aView, const wxString& aTitle ) :
71  BOARD_PRINTOUT( aParams, aView, aTitle ), m_pcbnewSettings( aParams )
72 {
73  m_board = aBoard;
74 }
75 
76 
78 {
79  // Store the layerset, as it is going to be modified below and the original settings are
80  // needed.
81  LSET lset = m_settings.m_layerSet;
82  int pageCount = lset.count();
83  wxString layer;
84  PCB_LAYER_ID extractLayer;
85 
86  // compute layer mask from page number if we want one page per layer
88  {
89  // This sequence is TBD, call a different sequencer if needed, such as Seq().
90  // Could not find documentation on page order.
91  LSEQ seq = lset.UIOrder();
92 
93  // aPage starts at 1, not 0
94  if( unsigned( aPage - 1 ) < seq.size() )
95  m_settings.m_layerSet = LSET( seq[aPage - 1] );
96  }
97 
98  if( !m_settings.m_layerSet.any() )
99  return false;
100 
101  extractLayer = m_settings.m_layerSet.ExtractLayer();
102 
103  if( extractLayer == UNDEFINED_LAYER )
104  layer = _( "Multiple Layers" );
105  else
106  layer = LSET::Name( extractLayer );
107 
108  // In Pcbnew we can want the layer EDGE always printed
111 
112  DrawPage( layer, aPage, pageCount );
113 
114  // Restore the original layer set, so the next page can be printed
115  m_settings.m_layerSet = lset;
116 
117  return true;
118 }
119 
120 
121 int PCBNEW_PRINTOUT::milsToIU( double aMils ) const
122 {
123  return KiROUND( IU_PER_MILS * aMils );
124 }
125 
126 
127 void PCBNEW_PRINTOUT::setupViewLayers( KIGFX::VIEW& aView, const LSET& aLayerSet )
128 {
129  BOARD_PRINTOUT::setupViewLayers( aView, aLayerSet );
130 
131  for( LSEQ layerSeq = m_settings.m_layerSet.Seq(); layerSeq; ++layerSeq )
132  aView.SetLayerVisible( PCBNEW_LAYER_ID_START + *layerSeq, true );
133 
134  // Enable pad layers corresponding to the selected copper layers
135  if( aLayerSet.test( F_Cu ) )
136  aView.SetLayerVisible( LAYER_PAD_FR, true );
137 
138  if( aLayerSet.test( B_Cu ) )
139  aView.SetLayerVisible( LAYER_PAD_BK, true );
140 
141  if( ( aLayerSet & LSET::AllCuMask() ).any() ) // Items visible on any copper layer
142  {
143  // Enable items on copper layers, but do not draw holes
144  for( GAL_LAYER_ID item : { LAYER_PADS_TH, LAYER_VIAS } )
145  {
146  aView.SetLayerVisible( item, true );
147  }
148 
150  {
151  // Enable hole layers to draw drill marks
153  LAYER_VIAS_HOLES } )
154  {
155  aView.SetLayerVisible( holeLayer, true );
156  aView.SetTopLayer( holeLayer, true );
157  }
158  }
159  }
160 
161 
162  // Keep certain items always enabled/disabled and just rely on the layer visibility
163  const int alwaysEnabled[] = {
167  };
168 
169  for( int item : alwaysEnabled )
170  aView.SetLayerVisible( item, true );
171 }
172 
173 
175 {
176  BOARD_PRINTOUT::setupPainter( aPainter );
177 
178  KIGFX::PCB_PRINT_PAINTER& painter = dynamic_cast<KIGFX::PCB_PRINT_PAINTER&>( aPainter );
179 
181  {
183  painter.SetDrillMarks( false, 0 );
184  break;
185 
187  painter.SetDrillMarks( false, Millimeter2iu( 0.3 ) );
188  break;
189 
191  painter.SetDrillMarks( true );
192  break;
193  }
194 
197 
201 }
202 
203 
205 {
206  BOARD_PRINTOUT::setupGal( aGal );
207  aGal->SetWorldUnitLength( 1e-9 /* 1 nm */ / 0.0254 /* 1 inch in meters */ );
208 }
209 
210 
212 {
213  return m_board->ComputeBoundingBox();
214 }
215 
216 
217 std::unique_ptr<KIGFX::PAINTER> PCBNEW_PRINTOUT::getPainter( KIGFX::GAL* aGal )
218 {
219  return std::unique_ptr<KIGFX::PAINTER>( new KIGFX::PCB_PRINT_PAINTER( aGal ) );
220 }
221 
222 
224  : PCB_PAINTER( aGal ), m_drillMarkReal( false ), m_drillMarkSize( 0 )
225 {
227 }
228 
229 
231 {
232  return m_drillMarkReal ? KIGFX::PCB_PAINTER::getDrillShape( aPad ) : PAD_DRILL_SHAPE_CIRCLE;
233 }
234 
235 
237 {
238  // TODO should it depend on the pad size?
239  return m_drillMarkReal ? KIGFX::PCB_PAINTER::getDrillSize( aPad ) :
240  VECTOR2D( m_drillMarkSize, m_drillMarkSize );
241 }
242 
243 
245 {
246  // TODO should it depend on the via size?
247  return m_drillMarkReal ? KIGFX::PCB_PAINTER::getDrillSize( aVia ) : m_drillMarkSize;
248 }
static LSET AllCuMask(int aCuLayerCount=MAX_CU_LAYERS)
Function AllCuMask returns a mask holding the requested number of Cu PCB_LAYER_IDs.
Definition: lset.cpp:712
bool m_noEdgeLayer
Disable board outline on each page.
to draw blind/buried vias
PCBNEW_PRINTOUT_SETTINGS(const PAGE_INFO &aPageInfo)
void Save(APP_SETTINGS_BASE *aConfig) override
virtual void SetTopLayer(int aLayer, bool aEnabled=true)
Function SetTopLayer() Sets given layer to be displayed on the top or sets back the default order of ...
Definition: view.cpp:864
multilayer pads, usually with holes
handle color for not plated holes (holes, not pads)
Special flavor of PCB_PAINTER that contains modifications to handle printing options.
virtual VECTOR2D getDrillSize(const D_PAD *aPad) const
Return drill size for a pad (internal units).
void EnableZoneOutlines(bool aEnabled)
Turns on/off drawing outline and hatched lines for zones.
Definition: pcb_painter.h:159
GAL_LAYER_ID
GAL layers are "virtual" layers, i.e.
to draw via holes (pad holes do not use this layer)
void Load(APP_SETTINGS_BASE *aConfig) override
show modules values (when texts are visibles)
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
LSEQ Seq(const PCB_LAYER_ID *aWishListSequence, unsigned aCount) const
Function Seq returns an LSEQ from the union of this LSET and a desired sequence.
Definition: lset.cpp:377
PCB_PAINTER Contains methods for drawing PCB-specific items.
Definition: pcb_painter.h:274
std::unique_ptr< KIGFX::PAINTER > getPainter(KIGFX::GAL *aGal) override
Returns a PAINTER instance used to draw the items.
BOARD_PRINTOUT_SETTINGS m_settings
Printout parameters
Board plot function definition file.
void setupPainter(KIGFX::PAINTER &aPainter) override
Configures PAINTER object for a printout
show modules on front
PCB_LAYER_ID
A quick note on layer IDs:
PAINTER contains all the knowledge about how to draw graphical object onto any particular output devi...
Definition: painter.h:58
void Load(APP_SETTINGS_BASE *aConfig) override
void setupViewLayers(KIGFX::VIEW &aView, const LSET &aLayerSet) override
Enables layers visibility for a printout
LSET is a set of PCB_LAYER_IDs.
APP_SETTINGS_BASE is a settings class that should be derived for each standalone KiCad application.
Definition: app_settings.h:92
VECTOR2< double > VECTOR2D
Definition: vector2d.h:593
virtual PCB_RENDER_SETTINGS * GetSettings() override
Definition: pcb_painter.h:286
virtual void setupPainter(KIGFX::PAINTER &aPainter)
Configures PAINTER object for a printout
static const wxChar * Name(PCB_LAYER_ID aLayerId)
Function Name returns the fixed name association with aLayerId.
Definition: lset.cpp:78
int milsToIU(double aMils) const override
Convert mils to internal units
PAGE_INFO describes the page size and margins of a paper page on which to eventually print or plot.
Definition: page_info.h:54
to draw usual through hole vias
virtual void setupGal(KIGFX::GAL *aGal)
Configures GAL object for a printout
VECTOR2D getDrillSize(const D_PAD *aPad) const override
Return drill size for a pad (internal units).
void SetLayerColor(int aLayer, const COLOR4D &aColor)
Function SetLayerColor Changes the color used to draw a layer.
void SetLayerVisible(int aLayer, bool aVisible=true)
Function SetLayerVisible() Controls the visibility of a particular layer.
Definition: view.h:399
void Save(APP_SETTINGS_BASE *aConfig) override
void SetWorldUnitLength(double aWorldUnitLength)
Set the unit length.
void SetDrawIndividualViaLayers(bool aFlag)
Definition: pcb_painter.h:196
LSEQ is a sequence (and therefore also a set) of PCB_LAYER_IDs.
virtual void setupViewLayers(KIGFX::VIEW &aView, const LSET &aLayerSet)
Enables layers visibility for a printout
Definition: color4d.h:48
smd pads, front layer
BOARD_PRINTOUT is a class derived from wxPrintout to handle the necessary information to control a pr...
PCB_LAYER_ID ExtractLayer() const
Find the first set PCB_LAYER_ID.
Definition: lset.cpp:625
PCBNEW_PRINTOUT_SETTINGS m_pcbnewSettings
BOARD holds information pertinent to a Pcbnew printed circuit board.
Definition: class_board.h:180
#define _(s)
Definition: 3d_actions.cpp:33
EDA_RECT handles the component boundary box.
Definition: eda_rect.h:44
#define IU_PER_MILS
Definition: plotter.cpp:138
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:68
enum PCBNEW_PRINTOUT_SETTINGS::PAGINATION_T m_pagination
Pagination.
EDA_RECT ComputeBoundingBox(bool aBoardEdgesOnly=false) const
Function ComputeBoundingBox calculates the bounding box containing all board items (or board edge seg...
EDA_RECT getBoundingBox() override
Returns bounding box of the printed objects (excluding worksheet frame)
enum PCBNEW_PRINTOUT_SETTINGS::DRILL_MARK_SHAPE_T m_drillMarks
Drill marks shape.
VIEW.
Definition: view.h:61
void setupGal(KIGFX::GAL *aGal) override
Configures GAL object for a printout
int getDrillShape(const D_PAD *aPad) const override
Return drill shape of a pad.
LSEQ UIOrder() const
Definition: lset.cpp:839
static constexpr int Millimeter2iu(double mm)
bool OnPrintPage(int aPage) override
show modules references (when texts are visibles)
LSET m_layerSet
Layers to print.
void SetDrillMarks(bool aRealSize, unsigned int aSize=0)
Set drill marks visibility and options.
Class GAL is the abstract interface for drawing on a 2D-surface.
virtual int getDrillShape(const D_PAD *aPad) const
Return drill shape of a pad.