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 <wxPcbStruct.h>
31 #include <printout_controler.h>
32 #include <colors_selection.h>
33 #include <class_board.h>
34 #include <class_module.h>
35 #include <class_edge_mod.h>
36 #include <class_track.h>
37 #include <class_zone.h>
38 
39 #include <pcbnew.h>
40 #include <pcbplot.h>
41 #include <module_editor_frame.h>
42 
43 
44 static void Print_Module( EDA_DRAW_PANEL* aPanel, wxDC* aDC, MODULE* aModule,
45  GR_DRAWMODE aDraw_mode, LSET aMasklayer,
46  PRINT_PARAMETERS::DrillShapeOptT aDrillShapeOpt );
47 
49  LSET aPrintMaskLayer,
50  bool aPrintMirrorMode,
51  void * aData)
52 {
53  const GR_DRAWMODE drawmode = (GR_DRAWMODE) 0;
54  int defaultPenSize = Millimeter2iu( 0.2 );
56 
57  DISPLAY_OPTIONS save_opt;
58 
59  PRINT_PARAMETERS * printParameters = (PRINT_PARAMETERS*) aData; // can be null
61 
62  if( printParameters )
63  defaultPenSize = printParameters->m_PenDefaultSize;
64 
65  save_opt = *displ_opts;
66 
67  displ_opts->m_ContrastModeDisplay = false;
68  displ_opts->m_DisplayPadFill = true;
69  displ_opts->m_DisplayViaFill = true;
70  displ_opts->m_DisplayPadNum = false;
71  bool nctmp = GetBoard()->IsElementVisible( LAYER_NO_CONNECTS );
73  displ_opts->m_DisplayPadIsol = false;
74  displ_opts->m_DisplayModEdgeFill = FILLED;
75  displ_opts->m_DisplayModTextFill = FILLED;
76  displ_opts->m_DisplayPcbTrackFill = true;
78  displ_opts->m_DisplayDrawItemsFill = FILLED;
79  displ_opts->m_DisplayZonesMode = 0;
80  displ_opts->m_DisplayNetNamesMode = 0;
81 
82  m_canvas->SetPrintMirrored( aPrintMirrorMode );
83 
84  // Draw footprints, this is done at last in order to print the pad holes in
85  // white after the tracks and zones
87  D_PAD::m_PadSketchModePenSize = defaultPenSize;
88 
89  wxSize pageSizeIU = GetPageSizeIU() / 2;
90  wxPoint offset( pageSizeIU.x, pageSizeIU.y );
91 
92  for( MODULE* module = GetBoard()->m_Modules; module; module = module->Next() )
93  {
94  module->Move( offset );
95  Print_Module( m_canvas, aDC, module, drawmode, aPrintMaskLayer, drillShapeOpt );
96  module->Move( -offset );
97  }
98 
100 
101  m_canvas->SetPrintMirrored( false );
102 
103  *displ_opts = save_opt;
105 }
106 
107 
109  LSET aPrintMask,
110  bool aPrintMirrorMode,
111  void* aData)
112 {
113  const GR_DRAWMODE drawmode = (GR_DRAWMODE) 0;
114  DISPLAY_OPTIONS save_opt;
115  BOARD* Pcb = GetBoard();
116  int defaultPenSize = Millimeter2iu( 0.2 );
117  bool onePagePerLayer = false;
118 
119  PRINT_PARAMETERS* printParameters = (PRINT_PARAMETERS*) aData; // can be null
121 
122  if( printParameters && printParameters->m_OptionPrintPage == 0 )
123  onePagePerLayer = true;
124 
126 
127  if( printParameters )
128  {
129  drillShapeOpt = printParameters->m_DrillShapeOpt;
130  defaultPenSize = printParameters->m_PenDefaultSize;
131  }
132 
133  save_opt = *displ_opts;
134 
135  PCB_LAYER_ID activeLayer = GetScreen()->m_Active_Layer;
136 
137  displ_opts->m_ContrastModeDisplay = false;
138  displ_opts->m_DisplayPadFill = true;
139  displ_opts->m_DisplayViaFill = true;
140 
141  if( !( aPrintMask & LSET::AllCuMask() ).any() )
142  {
143  if( onePagePerLayer )
144  {
145  // We can print mask layers (solder mask and solder paste) with the actual
146  // pad sizes. To do that, we must set ContrastModeDisplay to true and set
147  // the GetScreen()->m_Active_Layer to the current printed layer
148  displ_opts->m_ContrastModeDisplay = true;
149  displ_opts->m_DisplayPadFill = true;
150 
151  // Calculate the active layer number to print from its mask layer:
153 
154  for( LAYER_NUM id = PCB_LAYER_ID_COUNT-1; id >= 0; --id )
155  {
156  if( aPrintMask[id] )
157  {
159  break;
160  }
161  }
162 
163  // pads on Silkscreen layer are usually plot in sketch mode:
164  if( GetScreen()->m_Active_Layer == B_SilkS ||
165  GetScreen()->m_Active_Layer == F_SilkS )
166  {
167  displ_opts->m_DisplayPadFill = false;
168  }
169  }
170  else
171  {
172  displ_opts->m_DisplayPadFill = false;
173  }
174  }
175 
176  displ_opts->m_DisplayPadNum = false;
177 
178  bool nctmp = GetBoard()->IsElementVisible( LAYER_NO_CONNECTS );
179 
181 
182  bool anchorsTmp = GetBoard()->IsElementVisible( LAYER_ANCHOR );
183 
185 
186  displ_opts->m_DisplayPadIsol = false;
187  displ_opts->m_DisplayModEdgeFill = FILLED;
188  displ_opts->m_DisplayModTextFill = FILLED;
189  displ_opts->m_DisplayPcbTrackFill = true;
191  displ_opts->m_DisplayDrawItemsFill = FILLED;
192  displ_opts->m_DisplayZonesMode = 0;
193  displ_opts->m_DisplayNetNamesMode = 0;
194 
195  m_canvas->SetPrintMirrored( aPrintMirrorMode );
196 
197  for( auto item : Pcb->Drawings() )
198  {
199  switch( item->Type() )
200  {
201  case PCB_LINE_T:
202  case PCB_DIMENSION_T:
203  case PCB_TEXT_T:
204  case PCB_TARGET_T:
205  if( aPrintMask[item->GetLayer()] )
206  item->Draw( m_canvas, aDC, drawmode );
207  break;
208 
209  case PCB_MARKER_T:
210  default:
211  break;
212  }
213  }
214 
215  // Print tracks
216  for( TRACK* track = Pcb->m_Track; track; track = track->Next() )
217  {
218  if( !( aPrintMask & track->GetLayerSet() ).any() )
219  continue;
220 
221  if( track->Type() == PCB_VIA_T ) // VIA encountered.
222  {
223  int radius = track->GetWidth() / 2;
224  const VIA* via = static_cast<const VIA*>( track );
225 
227 
229  via->GetStart().x,
230  via->GetStart().y,
231  radius,
232  0, color, color );
233  }
234  else
235  {
236  track->Draw( m_canvas, aDC, drawmode );
237  }
238  }
239 
240  // Outdated: only for compatibility to old boards
241  for( TRACK* track = Pcb->m_Zone; track; track = track->Next() )
242  {
243  if( !( aPrintMask & track->GetLayerSet() ).any() )
244  continue;
245 
246  track->Draw( m_canvas, aDC, drawmode );
247  }
248 
249  // Draw filled areas (i.e. zones)
250  for( int ii = 0; ii < Pcb->GetAreaCount(); ii++ )
251  {
252  ZONE_CONTAINER* zone = Pcb->GetArea( ii );
253 
254  if( aPrintMask[zone->GetLayer()] )
255  zone->DrawFilledArea( m_canvas, aDC, drawmode );
256  }
257 
258  // Draw footprints, this is done at last in order to print the pad holes in
259  // white after the tracks and zones
261  D_PAD::m_PadSketchModePenSize = defaultPenSize;
262 
263  for( MODULE* module = (MODULE*) Pcb->m_Modules; module; module = module->Next() )
264  {
265  Print_Module( m_canvas, aDC, module, drawmode, aPrintMask, drillShapeOpt );
266  }
267 
269 
270  /* Print via holes in bg color: Not sure it is good for buried or blind
271  * vias */
272  if( drillShapeOpt != PRINT_PARAMETERS::NO_DRILL_SHAPE )
273  {
274  TRACK* track = Pcb->m_Track;
276 
277  bool blackpenstate = GetGRForceBlackPenState();
278 
279  GRForceBlackPen( false );
280 
281  for( ; track; track = track->Next() )
282  {
283  if( !( aPrintMask & track->GetLayerSet() ).any() )
284  continue;
285 
286  if( track->Type() == PCB_VIA_T ) // VIA encountered.
287  {
288  int diameter;
289  const VIA *via = static_cast<const VIA*>( track );
290 
291  if( drillShapeOpt == PRINT_PARAMETERS::SMALL_DRILL_SHAPE )
292  diameter = std::min( SMALL_DRILL, via->GetDrillValue() );
293  else
294  diameter = via->GetDrillValue();
295 
297  track->GetStart().x, track->GetStart().y,
298  diameter/2,
299  0, color, color );
300  }
301  }
302 
303  GRForceBlackPen( blackpenstate );
304  }
305 
306  m_canvas->SetPrintMirrored( false );
307 
308  *displ_opts = save_opt;
309  GetScreen()->m_Active_Layer = activeLayer;
310 
312  GetBoard()->SetElementVisibility( LAYER_ANCHOR, anchorsTmp );
313 }
314 
315 
316 static void Print_Module( EDA_DRAW_PANEL* aPanel, wxDC* aDC, MODULE* aModule,
317  GR_DRAWMODE aDraw_mode, LSET aMask,
318  PRINT_PARAMETERS::DrillShapeOptT aDrillShapeOpt )
319 {
320  // Print pads
321  for( D_PAD* pad = aModule->PadsList(); pad; pad = pad->Next() )
322  {
323  if( !( pad->GetLayerSet() & aMask ).any() )
324  continue;
325 
326  // Manage hole according to the print drill option
327  wxSize drill_tmp = pad->GetDrillSize();
328 
329  switch( aDrillShapeOpt )
330  {
332  pad->SetDrillSize( wxSize(0,0) );
333  break;
334 
336  {
337  wxSize sz( std::min( SMALL_DRILL, pad->GetDrillSize().x ),
338  std::min( SMALL_DRILL, pad->GetDrillSize().y ) );
339 
340  pad->SetDrillSize( sz );
341  }
342  break;
343 
345  // Do nothing
346  break;
347  }
348 
349  pad->Draw( aPanel, aDC, aDraw_mode );
350  pad->SetDrillSize( drill_tmp );
351  }
352 
353  if( aModule->Reference().IsVisible() && aMask[aModule->Reference().GetLayer()] )
354  aModule->Reference().Draw( aPanel, aDC, aDraw_mode );
355 
356  if( aModule->Value().IsVisible() && aMask[aModule->Value().GetLayer()] )
357  aModule->Value().Draw( aPanel, aDC, aDraw_mode );
358 
359  for( EDA_ITEM* item = aModule->GraphicalItemsList(); item; item = item->Next() )
360  {
361  switch( item->Type() )
362  {
363  case PCB_MODULE_TEXT_T:
364  {
365  TEXTE_MODULE* textMod = static_cast<TEXTE_MODULE*>( item );
366 
367  if( !aMask[textMod->GetLayer()] )
368  break;
369 
370  textMod->Draw( aPanel, aDC, aDraw_mode );
371  break;
372  }
373 
374  case PCB_MODULE_EDGE_T:
375  {
376  EDGE_MODULE* edge = static_cast<EDGE_MODULE*>( item );
377 
378  if( !aMask[edge->GetLayer()] )
379  break;
380 
381  edge->Draw( aPanel, aDC, aDraw_mode );
382  }
383  break;
384 
385  default:
386  break;
387  }
388  }
389 }
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:639
KICAD_T Type() const
Function Type()
Definition: base_struct.h:198
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:83
#define SMALL_DRILL
Definition: pcbplot.h:72
Class ZONE_CONTAINER handles a list of polygons defining a copper zone.
Definition: class_zone.h:78
Definition of class FOOTPRINT_EDIT_FRAME.
show a marker on pads with no nets
bool IsElementVisible(GAL_LAYER_ID LAYER_aPCB) const
Function IsElementVisible tests whether a given element category is visible.
TEXTE_MODULE & Reference()
Definition: class_module.h:463
Board print handler definition file.
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:241
MODULE * Next() const
Definition: class_module.h:100
Class PRINT_PARAMETERS handles the parameters used to print a board drawing.
class TEXTE_PCB, text on a layer
Definition: typeinfo.h:104
bool m_DisplayModEdgeFill
Definition: pcbstruct.h:69
BOARD * GetBoard() const
Classes to handle copper zones.
DLIST< SEGZONE > m_Zone
Definition: class_board.h:247
void GRFilledCircle(EDA_RECT *ClipBox, wxDC *DC, int x, int y, int r, int width, COLOR4D Color, COLOR4D BgColor)
Definition: gr_basic.cpp:833
PCB_LAYER_ID m_Active_Layer
class EDGE_MODULE, a footprint edge
Definition: typeinfo.h:106
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...
SEGZONE * Next() const
Definition: class_track.h:358
Board plot function definition file.
BOARD_ITEM * Next() const
COLOR4D GetItemColor(int aItemIdx) const
Function GetItemColor.
bool m_DisplayPcbTrackFill
Definition: pcbstruct.h:71
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:439
void GRForceBlackPen(bool flagforce)
Function GRForceBlackPen.
Definition: gr_basic.cpp:271
GR_DRAWMODE
Drawmode. Compositing mode plus a flag or two.
Definition: gr_basic.h:41
TEXTE_MODULE & Value()
read/write accessors:
Definition: class_module.h:462
const wxPoint & GetStart() const
Definition: class_track.h:121
void SetElementVisibility(GAL_LAYER_ID LAYER_aPCB, bool aNewState)
Function SetElementVisibility changes the visibility of an element category.
bool m_ContrastModeDisplay
Definition: pcbstruct.h:85
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:106
bool m_DisplayDrawItemsFill
Definition: pcbstruct.h:84
EDA_RECT * GetClipBox()
DrillShapeOptT m_DrillShapeOpt
int m_DisplayZonesMode
Definition: pcbstruct.h:77
int GetAreaCount() const
Function GetAreaCount.
Definition: class_board.h:1025
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.
COLORS_DESIGN_SETTINGS g_ColorsSettings
Definition: pcbnew.cpp:68
class DIMENSION, a dimension (graphic item)
Definition: typeinfo.h:112
class PCB_TARGET, a target (graphic item)
Definition: typeinfo.h:113
int LAYER_NUM
Type LAYER_NUM can be replaced with int and removed.
Class DISPLAY_OPTIONS handles display options like enable/disable some optional drawings.
Definition: pcbstruct.h:62
class TEXTE_MODULE, text in a footprint
Definition: typeinfo.h:105
TRACE_CLEARANCE_DISPLAY_MODE_T m_ShowTrackClearanceMode
How trace clearances are displayed.
Definition: pcbstruct.h:74
EDA_DRAW_PANEL * m_canvas
The area to draw on.
Definition: draw_frame.h:92
bool m_DisplayPadFill
Definition: pcbstruct.h:65
PCB_LAYER_ID GetLayer() const
Function GetLayer returns the primary layer this item is on.
bool m_DisplayPadIsol
Definition: pcbstruct.h:68
class MARKER_PCB, a marker used to show something
Definition: typeinfo.h:111
TRACK * Next() const
Definition: class_track.h:98
ZONE_CONTAINER * GetArea(int index) const
Function GetArea returns the Area (Zone Container) at a given index.
Definition: class_board.h:996
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:176
bool m_DisplayPadNum
Definition: pcbstruct.h:67
Class EDA_ITEM is a base class for most all the KiCad significant classes, used in schematics and boa...
Definition: base_struct.h:151
int m_DisplayNetNamesMode
Definition: pcbstruct.h:78
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:137
class VIA, a via (like a track segment on a copper layer)
Definition: typeinfo.h:108
DLIST< D_PAD > & PadsList()
Definition: class_module.h:134
DLIST< TRACK > m_Track
Definition: class_board.h:246
Module description (excepted pads)
bool GetGRForceBlackPenState(void)
Function GetGRForceBlackPenState.
Definition: gr_basic.cpp:281
EDGE_MODULE class definition.
class DRAWSEGMENT, a segment not on copper layers
Definition: typeinfo.h:103
bool m_DisplayViaFill
Definition: pcbstruct.h:66
bool m_DisplayModTextFill
Definition: pcbstruct.h:70
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