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 
31 #include <pcb_painter.h>
32 #include <view/view.h>
33 #include <pcbplot.h>
34 
36  : BOARD_PRINTOUT_SETTINGS( aPageInfo )
37 {
40  m_noEdgeLayer = false;
41 }
42 
43 
44 void PCBNEW_PRINTOUT_SETTINGS::Load( wxConfigBase* aConfig )
45 {
47  aConfig->Read( OPTKEY_PRINT_PADS_DRILL, (int*) &m_drillMarks, FULL_DRILL_SHAPE );
48  aConfig->Read( OPTKEY_PRINT_PAGE_PER_LAYER, (int*) &m_pagination, ALL_LAYERS );
49 }
50 
51 
52 void PCBNEW_PRINTOUT_SETTINGS::Save( wxConfigBase* aConfig )
53 {
55  aConfig->Write( OPTKEY_PRINT_PADS_DRILL, (int) m_drillMarks );
56  aConfig->Write( OPTKEY_PRINT_PAGE_PER_LAYER, (int) m_pagination );
57 }
58 
59 
61  const KIGFX::VIEW* aView, const wxString& aTitle ) :
62  BOARD_PRINTOUT( aParams, aView, aTitle ), m_pcbnewSettings( aParams )
63 {
64  m_board = aBoard;
65 }
66 
67 
69 {
70  // Store the layerset, as it is going to be modified below and the original settings are needed
71  LSET lset = m_settings.m_layerSet;
72  int pageCount = lset.count();
73  wxString layer;
74  PCB_LAYER_ID extractLayer;
75 
76  // compute layer mask from page number if we want one page per layer
77  if( m_pcbnewSettings.m_pagination == 0 ) // One page per layer
78  {
79  // This sequence is TBD, call a different
80  // sequencer if needed, such as Seq(). Could not find documentation on
81  // page order.
82  LSEQ seq = lset.UIOrder();
83 
84  // aPage starts at 1, not 0
85  if( unsigned( aPage - 1 ) < seq.size() )
86  m_settings.m_layerSet = LSET( seq[aPage - 1] );
87  }
88 
89  if( !m_settings.m_layerSet.any() )
90  return false;
91 
92  extractLayer = m_settings.m_layerSet.ExtractLayer();
93 
94  if( extractLayer == UNDEFINED_LAYER )
95  layer = _( "Multiple Layers" );
96  else
97  layer = LSET::Name( extractLayer );
98 
99  // In Pcbnew we can want the layer EDGE always printed
102 
103  DrawPage( layer, aPage, pageCount );
104 
105  // Restore the original layer set, so the next page can be printed
106  m_settings.m_layerSet = lset;
107 
108  return true;
109 }
110 
111 
112 int PCBNEW_PRINTOUT::milsToIU( double aMils ) const
113 {
114  return KiROUND( IU_PER_MILS * aMils );
115 }
116 
117 
118 void PCBNEW_PRINTOUT::setupViewLayers( const std::unique_ptr<KIGFX::VIEW>& aView,
119  const LSET& aLayerSet )
120 {
121  BOARD_PRINTOUT::setupViewLayers( aView, aLayerSet );
122 
123  for( LSEQ layerSeq = m_settings.m_layerSet.Seq(); layerSeq; ++layerSeq )
124  aView->SetLayerVisible( PCBNEW_LAYER_ID_START + *layerSeq, true );
125 
126  // Enable pad layers corresponding to the selected copper layers
127  if( aLayerSet.test( F_Cu ) )
128  aView->SetLayerVisible( LAYER_PAD_FR, true );
129 
130  if( aLayerSet.test( B_Cu ) )
131  aView->SetLayerVisible( LAYER_PAD_BK, true );
132 
133  if( ( aLayerSet & LSET::AllCuMask() ).any() ) // Items visible on any copper layer
134  {
135  // Enable items on copper layers, but do not draw holes
136  for( auto item : { LAYER_PADS_TH, LAYER_VIA_MICROVIA,
138  {
139  aView->SetLayerVisible( item, true );
140  }
141 
143  {
144  // Enable hole layers to draw drill marks
145  for( auto holeLayer : { LAYER_PADS_PLATEDHOLES,
147  {
148  aView->SetLayerVisible( holeLayer, true );
149  aView->SetTopLayer( holeLayer, true );
150  }
151  }
152 
153  }
154 
155 
156  // Keep certain items always enabled/disabled and just rely on the layer visibility
157  const int alwaysEnabled[] = {
160  };
161 
162  for( int item : alwaysEnabled )
163  aView->SetLayerVisible( item, true );
164 }
165 
166 
167 void PCBNEW_PRINTOUT::setupPainter( const std::unique_ptr<KIGFX::PAINTER>& aPainter )
168 {
169  BOARD_PRINTOUT::setupPainter( aPainter );
170 
171  auto painter = static_cast<KIGFX::PCB_PRINT_PAINTER*>( aPainter.get() );
172 
174  {
176  painter->SetDrillMarks( false, 0 );
177  break;
178 
180  painter->SetDrillMarks( false, Millimeter2iu( 0.3 ) );
181  break;
182 
184  painter->SetDrillMarks( true );
185  break;
186  }
187 
188  painter->GetSettings()->SetLayerColor( LAYER_PADS_PLATEDHOLES, COLOR4D::WHITE );
189  painter->GetSettings()->SetLayerColor( LAYER_NON_PLATEDHOLES, COLOR4D::WHITE );
190  painter->GetSettings()->SetLayerColor( LAYER_VIAS_HOLES, COLOR4D::WHITE );
191 }
192 
193 
195 {
196  BOARD_PRINTOUT::setupGal( aGal );
197  aGal->SetWorldUnitLength( 1e-9 /* 1 nm */ / 0.0254 /* 1 inch in meters */ );
198 }
199 
200 
202 {
203  return m_board->ComputeBoundingBox();
204 }
205 
206 
207 std::unique_ptr<KIGFX::PAINTER> PCBNEW_PRINTOUT::getPainter( KIGFX::GAL* aGal )
208 {
209  return std::unique_ptr<KIGFX::PAINTER>( new KIGFX::PCB_PRINT_PAINTER( aGal ) );
210 }
211 
212 
214  : PCB_PAINTER( aGal ), m_drillMarkReal( false ), m_drillMarkSize( 0 )
215 {
217 }
218 
219 
221 {
223 }
224 
225 
227 {
228  // TODO should it depend on the pad size?
231 }
232 
233 
235 {
236  // TODO should it depend on the via size?
238 }
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:673
bool m_noEdgeLayer
Disable board outline on each page.
to draw blind/buried vias
PCBNEW_PRINTOUT_SETTINGS(const PAGE_INFO &aPageInfo)
virtual int getDrillShape(const D_PAD *aPad) const
Return drill shape of a pad.
static int KiROUND(double v)
Round a floating point number to an integer using "round halfway cases away from zero".
Definition: common.h:120
void Save(wxConfigBase *aConfig) override
multilayer pads, usually with holes
EDA_RECT ComputeBoundingBox(bool aBoardEdgesOnly=false) const
Function ComputeBoundingBox calculates the bounding box containing all board items (or board edge seg...
handle color for not plated holes (holes, not pads)
Special flavor of PCB_PAINTER that contains modifications to handle printing options.
Class BOARD to handle a board.
show modules on back
void EnableZoneOutlines(bool aEnabled)
Turns on/off drawing outline and hatched lines for zones.
Definition: pcb_painter.h:142
to draw via holes (pad holes do not use this layer)
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:232
Class PCB_PAINTER Contains methods for drawing PCB-specific items.
Definition: pcb_painter.h:211
smd pads, back layer
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
PCB_LAYER_ID ExtractLayer() const
Find the first set PCB_LAYER_ID.
Definition: lset.cpp:612
Board plot function definition file.
show modules on front
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:364
bool m_drillMarkReal
Flag deciding whether use the actual hole size or user-specified size for drill marks ...
PCB_LAYER_ID
A quick note on layer IDs:
Class LSET is a set of PCB_LAYER_IDs.
void Load(wxConfigBase *aConfig) override
VECTOR2< double > VECTOR2D
Definition: vector2d.h:586
static const wxChar * Name(PCB_LAYER_ID aLayerId)
Function Name returns the fixed name association with aLayerId.
Definition: lset.cpp:73
int milsToIU(double aMils) const override
Convert mils to internal units
int m_drillMarkSize
User-specified size for drill marks (expressed in internal units)
Class PAGE_INFO describes the page size and margins of a paper page on which to eventually print or p...
Definition: page_info.h:54
to draw usual through hole vias
virtual void setupGal(KIGFX::GAL *aGal)
Configures GAL object for a printout
void Load(wxConfigBase *aConfig) override
VECTOR2D getDrillSize(const D_PAD *aPad) const override
Return drill size for a pad (internal units).
virtual void setupPainter(const std::unique_ptr< KIGFX::PAINTER > &aPainter)
Configures PAINTER object for a printout
void SetWorldUnitLength(double aWorldUnitLength)
Set the unit length.
Class LSEQ is a sequence (and therefore also a set) of PCB_LAYER_IDs.
void setupPainter(const std::unique_ptr< KIGFX::PAINTER > &aPainter) override
Configures PAINTER object for a printout
smd pads, front layer
virtual void setupViewLayers(const std::unique_ptr< KIGFX::VIEW > &aView, const LSET &aLayerSet)
Enables layers visibility for a printout
void setupViewLayers(const std::unique_ptr< KIGFX::VIEW > &aView, const LSET &aLayerSet) override
Enables layers visibility for a printout
Class BOARD_PRINTOUT is a class derived from wxPrintout to handle the necessary information to contro...
#define OPTKEY_PRINT_PADS_DRILL
Definition: pcbplot.h:59
PCBNEW_PRINTOUT_SETTINGS m_pcbnewSettings
Class BOARD holds information pertinent to a Pcbnew printed circuit board.
Definition: class_board.h:170
Class EDA_RECT handles the component boundary box.
Definition: eda_rect.h:44
#define IU_PER_MILS
Definition: plotter.cpp:134
#define OPTKEY_PRINT_PAGE_PER_LAYER
Definition: pcbplot.h:58
enum PCBNEW_PRINTOUT_SETTINGS::PAGINATION_T m_pagination
Pagination.
Definition: colors.h:49
virtual VECTOR2D getDrillSize(const D_PAD *aPad) const
Return drill size for a pad (internal units).
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.
Class 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.
bool OnPrintPage(int aPage) override
void Save(wxConfigBase *aConfig) override
show modules references (when texts are visibles)
LSET m_layerSet
Layers to print.
Class GAL is the abstract interface for drawing on a 2D-surface.
LSEQ UIOrder() const
Definition: lset.cpp:800