KiCad PCB EDA Suite
print_board_functions.cpp
Go to the documentation of this file.
1 
5 /*
6  * This program source code file is part of KiCad, a free EDA CAD application.
7  *
8  * Copyright (C) 1992-2013 KiCad Developers, see AUTHORS.txt for contributors.
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 <fctsys.h>
29 #include <class_drawpanel.h>
30 #include <pcb_edit_frame.h>
31 #include <printout_controler.h>
32 #include <class_board.h>
33 #include <class_module.h>
34 #include <class_edge_mod.h>
35 #include <class_track.h>
36 #include <class_zone.h>
37 
38 #include <pcbnew.h>
39 #include <pcbplot.h>
40 #include <footprint_edit_frame.h>
41 
42 
43 static void Print_Module( EDA_DRAW_PANEL* aPanel, wxDC* aDC, MODULE* aModule,
44  GR_DRAWMODE aDraw_mode, LSET aMasklayer,
45  PRINT_PARAMETERS::DrillShapeOptT aDrillShapeOpt );
46 
48  LSET aPrintMaskLayer,
49  bool aPrintMirrorMode,
50  void * aData)
51 {
52  const GR_DRAWMODE drawmode = (GR_DRAWMODE) 0;
53  int defaultPenSize = Millimeter2iu( 0.2 );
54  auto displ_opts = (PCB_DISPLAY_OPTIONS*) GetDisplayOptions();
55  PCB_DISPLAY_OPTIONS save_opt;
56 
57  PRINT_PARAMETERS * printParameters = (PRINT_PARAMETERS*) aData; // can be null
59 
60  if( printParameters )
61  defaultPenSize = printParameters->m_PenDefaultSize;
62 
63  save_opt = *displ_opts;
64 
65  displ_opts->m_ContrastModeDisplay = false;
66  displ_opts->m_DisplayPadFill = true;
67  displ_opts->m_DisplayViaFill = true;
68  displ_opts->m_DisplayPadNum = false;
69  bool nctmp = GetBoard()->IsElementVisible( LAYER_NO_CONNECTS );
71  displ_opts->m_DisplayPadIsol = false;
72  displ_opts->m_DisplayModEdgeFill = FILLED;
73  displ_opts->m_DisplayModTextFill = FILLED;
74  displ_opts->m_DisplayPcbTrackFill = true;
75  displ_opts->m_ShowTrackClearanceMode = PCB_DISPLAY_OPTIONS::DO_NOT_SHOW_CLEARANCE;
76  displ_opts->m_DisplayDrawItemsFill = FILLED;
77  displ_opts->m_DisplayZonesMode = 0;
78  displ_opts->m_DisplayNetNamesMode = 0;
79 
80  m_canvas->SetPrintMirrored( aPrintMirrorMode );
81 
82  // Draw footprints, this is done at last in order to print the pad holes in
83  // white after the tracks and zones
85  D_PAD::m_PadSketchModePenSize = defaultPenSize;
86 
87  wxSize pageSizeIU = GetPageSizeIU() / 2;
88  wxPoint offset( pageSizeIU.x, pageSizeIU.y );
89 
90  for( MODULE* module = GetBoard()->m_Modules; module; module = module->Next() )
91  {
92  module->Move( offset );
93  Print_Module( m_canvas, aDC, module, drawmode, aPrintMaskLayer, drillShapeOpt );
94  module->Move( -offset );
95  }
96 
98 
99  m_canvas->SetPrintMirrored( false );
100 
101  *displ_opts = save_opt;
103 }
104 
105 
107  LSET aPrintMask,
108  bool aPrintMirrorMode,
109  void* aData)
110 {
111  const GR_DRAWMODE drawmode = (GR_DRAWMODE) 0;
112  PCB_DISPLAY_OPTIONS save_opt;
113  BOARD* Pcb = GetBoard();
114  int defaultPenSize = Millimeter2iu( 0.2 );
115 
116  PRINT_PARAMETERS* printParameters = (PRINT_PARAMETERS*) aData; // can be null
117  auto displ_opts = (PCB_DISPLAY_OPTIONS*) GetDisplayOptions();
118 
120 
121  if( printParameters )
122  {
123  drillShapeOpt = printParameters->m_DrillShapeOpt;
124  defaultPenSize = printParameters->m_PenDefaultSize;
125  }
126 
127  save_opt = *displ_opts;
128 
129  PCB_LAYER_ID activeLayer = GetScreen()->m_Active_Layer;
130 
131  displ_opts->m_ContrastModeDisplay = false;
132  displ_opts->m_DisplayPadFill = true;
133  displ_opts->m_DisplayViaFill = true;
134 
135  // Set all board layers as visible, because the print dialog has itself
136  // a layer selection, that have priority over the layer manager setup
137  LSET save_visible_brd_layers = Pcb->GetVisibleLayers();
138  Pcb->SetVisibleLayers( aPrintMask );
139 
140  int save_visible_brd_elements = Pcb->GetVisibleElements();
141  Pcb->SetElementVisibility( LAYER_PAD_FR, true );
142  Pcb->SetElementVisibility( LAYER_PAD_BK, true );
145 
146  PCB_LAYER_ID layer = aPrintMask.ExtractLayer();
147 
148  // pads on Silkscreen layer are usually printed in sketch mode:
149  if( layer == B_SilkS || layer == F_SilkS )
150  displ_opts->m_DisplayPadFill = false;
151 
152  displ_opts->m_DisplayPadNum = false;
153 
154  bool nctmp = GetBoard()->IsElementVisible( LAYER_NO_CONNECTS );
155 
157 
158  bool anchorsTmp = GetBoard()->IsElementVisible( LAYER_ANCHOR );
159 
161 
162  displ_opts->m_DisplayPadIsol = false;
163  displ_opts->m_DisplayModEdgeFill = FILLED;
164  displ_opts->m_DisplayModTextFill = FILLED;
165  displ_opts->m_DisplayPcbTrackFill = true;
166  displ_opts->m_ShowTrackClearanceMode = PCB_DISPLAY_OPTIONS::DO_NOT_SHOW_CLEARANCE;
167  displ_opts->m_DisplayDrawItemsFill = FILLED;
168  displ_opts->m_DisplayZonesMode = 0;
169  displ_opts->m_DisplayNetNamesMode = 0;
170 
171  m_canvas->SetPrintMirrored( aPrintMirrorMode );
172 
173  for( auto item : Pcb->Drawings() )
174  {
175  switch( item->Type() )
176  {
177  case PCB_LINE_T:
178  case PCB_DIMENSION_T:
179  case PCB_TEXT_T:
180  case PCB_TARGET_T:
181  if( aPrintMask[item->GetLayer()] )
182  item->Draw( m_canvas, aDC, drawmode );
183  break;
184 
185  case PCB_MARKER_T:
186  default:
187  break;
188  }
189  }
190 
191  // Print tracks
192  for( TRACK* track = Pcb->m_Track; track; track = track->Next() )
193  {
194  if( !( aPrintMask & track->GetLayerSet() ).any() )
195  continue;
196 
197  if( track->Type() == PCB_VIA_T ) // VIA encountered.
198  {
199  int radius = track->GetWidth() / 2;
200  const VIA* via = static_cast<const VIA*>( track );
201 
203 
205  via->GetStart().x,
206  via->GetStart().y,
207  radius,
208  0, color, color );
209  }
210  else
211  {
212  track->Draw( m_canvas, aDC, drawmode );
213  }
214  }
215 
216  // Outdated: only for compatibility to old boards
217  for( TRACK* track = Pcb->m_Zone; track; track = track->Next() )
218  {
219  if( !( aPrintMask & track->GetLayerSet() ).any() )
220  continue;
221 
222  track->Draw( m_canvas, aDC, drawmode );
223  }
224 
225  // Draw filled areas (i.e. zones)
226  for( int ii = 0; ii < Pcb->GetAreaCount(); ii++ )
227  {
228  ZONE_CONTAINER* zone = Pcb->GetArea( ii );
229 
230  if( aPrintMask[zone->GetLayer()] )
231  zone->DrawFilledArea( m_canvas, aDC, drawmode );
232  }
233 
234  // Draw footprints, this is done at last in order to print the pad holes in
235  // white after the tracks and zones
237  D_PAD::m_PadSketchModePenSize = defaultPenSize;
238 
239  for( MODULE* module = (MODULE*) Pcb->m_Modules; module; module = module->Next() )
240  {
241  Print_Module( m_canvas, aDC, module, drawmode, aPrintMask, drillShapeOpt );
242  }
243 
245 
246  /* Print via holes in bg color: Not sure it is good for buried or blind
247  * vias */
248  if( drillShapeOpt != PRINT_PARAMETERS::NO_DRILL_SHAPE )
249  {
250  TRACK* track = Pcb->m_Track;
252 
253  bool blackpenstate = GetGRForceBlackPenState();
254 
255  GRForceBlackPen( false );
256 
257  for( ; track; track = track->Next() )
258  {
259  if( !( aPrintMask & track->GetLayerSet() ).any() )
260  continue;
261 
262  if( track->Type() == PCB_VIA_T ) // VIA encountered.
263  {
264  int diameter;
265  const VIA *via = static_cast<const VIA*>( track );
266 
267  if( drillShapeOpt == PRINT_PARAMETERS::SMALL_DRILL_SHAPE )
268  diameter = std::min( SMALL_DRILL, via->GetDrillValue() );
269  else
270  diameter = via->GetDrillValue();
271 
273  track->GetStart().x, track->GetStart().y,
274  diameter/2,
275  0, color, color );
276  }
277  }
278 
279  GRForceBlackPen( blackpenstate );
280  }
281 
282  m_canvas->SetPrintMirrored( false );
283 
284  // Restore settings:
285  *displ_opts = save_opt;
286  Pcb->SetVisibleLayers( save_visible_brd_layers );
287  Pcb->SetVisibleElements( save_visible_brd_elements );
288  GetScreen()->m_Active_Layer = activeLayer;
289 
291  GetBoard()->SetElementVisibility( LAYER_ANCHOR, anchorsTmp );
292 }
293 
294 
295 static void Print_Module( EDA_DRAW_PANEL* aPanel, wxDC* aDC, MODULE* aModule,
296  GR_DRAWMODE aDraw_mode, LSET aMask,
297  PRINT_PARAMETERS::DrillShapeOptT aDrillShapeOpt )
298 {
299  // Print pads
300  for( D_PAD* pad = aModule->PadsList(); pad; pad = pad->Next() )
301  {
302  if( !( pad->GetLayerSet() & aMask ).any() )
303  continue;
304 
305  // Manage hole according to the print drill option
306  wxSize drill_tmp = pad->GetDrillSize();
307 
308  switch( aDrillShapeOpt )
309  {
311  pad->SetDrillSize( wxSize(0,0) );
312  break;
313 
315  {
316  wxSize sz( std::min( SMALL_DRILL, pad->GetDrillSize().x ),
317  std::min( SMALL_DRILL, pad->GetDrillSize().y ) );
318 
319  pad->SetDrillSize( sz );
320  }
321  break;
322 
324  // Do nothing
325  break;
326  }
327 
328  pad->Draw( aPanel, aDC, aDraw_mode );
329  pad->SetDrillSize( drill_tmp );
330  }
331 
332  if( aModule->Reference().IsVisible() && aMask[aModule->Reference().GetLayer()] )
333  aModule->Reference().Draw( aPanel, aDC, aDraw_mode );
334 
335  if( aModule->Value().IsVisible() && aMask[aModule->Value().GetLayer()] )
336  aModule->Value().Draw( aPanel, aDC, aDraw_mode );
337 
338  for( EDA_ITEM* item = aModule->GraphicalItemsList(); item; item = item->Next() )
339  {
340  switch( item->Type() )
341  {
342  case PCB_MODULE_TEXT_T:
343  {
344  TEXTE_MODULE* textMod = static_cast<TEXTE_MODULE*>( item );
345 
346  if( !aMask[textMod->GetLayer()] )
347  break;
348 
349  textMod->Draw( aPanel, aDC, aDraw_mode );
350  break;
351  }
352 
353  case PCB_MODULE_EDGE_T:
354  {
355  EDGE_MODULE* edge = static_cast<EDGE_MODULE*>( item );
356 
357  if( !aMask[edge->GetLayer()] )
358  break;
359 
360  edge->Draw( aPanel, aDC, aDraw_mode );
361  }
362  break;
363 
364  default:
365  break;
366  }
367  }
368 }
KICAD_T Type() const
Function Type()
Definition: base_struct.h:209
static int m_PadSketchModePenSize
Pen size used to draw pads in sketch mode (mode used to print pads on silkscreen layer) ...
Definition: class_pad.h:137
#define SMALL_DRILL
Definition: pcbplot.h:72
Class ZONE_CONTAINER handles a list of polygons defining a copper zone.
Definition: class_zone.h:60
show a marker on pads with no nets
TEXTE_MODULE & Reference()
Definition: class_module.h:502
void SetElementVisibility(GAL_LAYER_ID aLayer, bool aNewState)
Function SetElementVisibility changes the visibility of an element category.
Board print handler definition file.
void SetVisibleElements(int aMask)
Function SetVisibleElements is a proxy function that calls the correspondent function in m_BoardSetti...
virtual PCB_LAYER_ID GetLayer() const
Function GetLayer returns the primary layer this item is on.
anchor of items having an anchor point (texts, footprints)
Class BOARD to handle a board.
void DrawFilledArea(EDA_DRAW_PANEL *panel, wxDC *DC, GR_DRAWMODE aDrawMode, const wxPoint &offset=ZeroOffset)
Function DrawDrawFilledArea Draws the filled area for this zone (polygon list .m_FilledPolysList) ...
Definition: class_zone.cpp:406
int color
Definition: DXF_plotter.cpp:62
MODULE * Next() const
Definition: class_module.h:121
Class PRINT_PARAMETERS handles the parameters used to print a board drawing.
virtual PCB_LAYER_ID GetLayer() const override
Function GetLayer returns the primary layer this item is on.
Definition: class_zone.cpp:175
class TEXTE_PCB, text on a layer
Definition: typeinfo.h:92
BOARD * GetBoard() const
Classes to handle copper zones.
DLIST< SEGZONE > m_Zone
Definition: class_board.h:247
int GetVisibleElements() const
Function GetVisibleElements is a proxy function that calls the correspondent function in m_BoardSetti...
void GRFilledCircle(EDA_RECT *ClipBox, wxDC *DC, int x, int y, int r, int width, COLOR4D Color, COLOR4D BgColor)
Definition: gr_basic.cpp:873
PCB_LAYER_ID m_Active_Layer
Definition: pcb_screen.h:44
Definition of class FOOTPRINT_EDIT_FRAME.
smd pads, back layer
class EDGE_MODULE, a footprint edge
Definition: typeinfo.h:94
Functions relatives to tracks, vias and segments used to fill zones.
void * GetDisplayOptions() override
Function GetDisplayOptions returns the display options current in use Display options are relative to...
PCB_LAYER_ID ExtractLayer() const
Find the first set PCB_LAYER_ID.
Definition: lset.cpp:612
SEGZONE * Next() const
Definition: class_track.h:364
Board plot function definition file.
BOARD_ITEM * Next() const
COLOR4D GetItemColor(int aItemIdx) const
Function GetItemColor.
Class PCB_DISPLAY_OPTIONS handles display options like enable/disable some optional drawings...
PCB_LAYER_ID
A quick note on layer IDs:
Class LSET is a set of PCB_LAYER_IDs.
virtual void PrintPage(wxDC *aDC, LSET aPrintMaskLayer, bool aPrintMirrorMode, void *aData=NULL) override
Function PrintPage is used to print a page.
VIATYPE_T GetViaType() const
Definition: class_track.h:458
void GRForceBlackPen(bool flagforce)
Function GRForceBlackPen.
Definition: gr_basic.cpp:299
GR_DRAWMODE
Drawmode. Compositing mode plus a flag or two.
Definition: gr_basic.h:37
TEXTE_MODULE & Value()
read/write accessors:
Definition: class_module.h:501
void SetVisibleLayers(LSET aLayerMask)
Function SetVisibleLayers is a proxy function that calls the correspondent function in m_BoardSetting...
PCB_GENERAL_SETTINGS & Settings()
const wxPoint & GetStart() const
Definition: class_track.h:122
virtual LSET GetLayerSet() const
Function GetLayerSet returns a "layer mask", which is a bitmap of all layers on which the TRACK segme...
D_PAD * Next() const
Definition: class_pad.h:160
EDA_RECT * GetClipBox()
DrillShapeOptT m_DrillShapeOpt
int GetAreaCount() const
Function GetAreaCount.
Definition: class_board.h:1011
void Draw(EDA_DRAW_PANEL *panel, wxDC *DC, GR_DRAWMODE aDrawMode, const wxPoint &offset=ZeroOffset) override
Function Draw BOARD_ITEMs have their own color information.
virtual void PrintPage(wxDC *aDC, LSET aPrintMaskLayer, bool aPrintMirrorMode, void *aData=NULL) override
Function PrintPage , virtual used to print a page Print the page pointed by the current screen...
void Draw(EDA_DRAW_PANEL *aPanel, wxDC *aDC, GR_DRAWMODE aDrawMode, const wxPoint &aOffset=ZeroOffset) override
Function Draw Draw the text according to the footprint pos and orient.
class DIMENSION, a dimension (graphic item)
Definition: typeinfo.h:100
COLORS_DESIGN_SETTINGS & Colors()
class PCB_TARGET, a target (graphic item)
Definition: typeinfo.h:101
class TEXTE_MODULE, text in a footprint
Definition: typeinfo.h:93
EDA_DRAW_PANEL * m_canvas
The area to draw on.
Definition: draw_frame.h:98
bool IsElementVisible(GAL_LAYER_ID aLayer) const
Function IsElementVisible tests whether a given element category is visible.
class MARKER_PCB, a marker used to show something
Definition: typeinfo.h:99
TRACK * Next() const
Definition: class_track.h:99
smd pads, front layer
ZONE_CONTAINER * GetArea(int index) const
Function GetArea returns the Area (Zone Container) at a given index.
Definition: class_board.h:982
int GetDrillValue() const
Function GetDrillValue "calculates" the drill value for vias (m-Drill if > 0, or default drill value ...
Class BOARD holds information pertinent to a Pcbnew printed circuit board.
Definition: class_board.h:169
DLIST< MODULE > m_Modules
Definition: class_board.h:245
bool IsVisible() const
Definition: eda_text.h:174
LSET GetVisibleLayers() const
Function GetVisibleLayers is a proxy function that calls the correspondent function in m_BoardSetting...
Class EDA_ITEM is a base class for most all the KiCad significant classes, used in schematics and boa...
Definition: base_struct.h:162
PCB_SCREEN * GetScreen() const override
Function GetScreen returns a pointer to a BASE_SCREEN or one of its derivatives.
Definition: colors.h:49
void SetPrintMirrored(bool aMirror)
const wxSize GetPageSizeIU() const override
Function GetPageSizeIU works off of GetPageSettings() to return the size of the paper page in the int...
DLIST< BOARD_ITEM > & GraphicalItemsList()
Definition: class_module.h:164
class VIA, a via (like a track segment on a copper layer)
Definition: typeinfo.h:96
DLIST< D_PAD > & PadsList()
Definition: class_module.h:161
DLIST< TRACK > m_Track
Definition: class_board.h:246
Module description (excepted pads)
bool GetGRForceBlackPenState(void)
Function GetGRForceBlackPenState.
Definition: gr_basic.cpp:309
EDGE_MODULE class definition.
class DRAWSEGMENT, a segment not on copper layers
Definition: typeinfo.h:91
DLIST_ITERATOR_WRAPPER< BOARD_ITEM > Drawings()
Definition: class_board.h:251
#define min(a, b)
Definition: auxiliary.h:85
Class COLOR4D is the color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:39