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 <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 <module_editor_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 );
55 
56  DISPLAY_OPTIONS save_opt;
57 
58  PRINT_PARAMETERS * printParameters = (PRINT_PARAMETERS*) aData; // can be null
60 
61  if( printParameters )
62  defaultPenSize = printParameters->m_PenDefaultSize;
63 
64  save_opt = *displ_opts;
65 
66  displ_opts->m_ContrastModeDisplay = false;
67  displ_opts->m_DisplayPadFill = true;
68  displ_opts->m_DisplayViaFill = true;
69  displ_opts->m_DisplayPadNum = false;
70  bool nctmp = GetBoard()->IsElementVisible( LAYER_NO_CONNECTS );
72  displ_opts->m_DisplayPadIsol = false;
73  displ_opts->m_DisplayModEdgeFill = FILLED;
74  displ_opts->m_DisplayModTextFill = FILLED;
75  displ_opts->m_DisplayPcbTrackFill = true;
77  displ_opts->m_DisplayDrawItemsFill = FILLED;
78  displ_opts->m_DisplayZonesMode = 0;
79  displ_opts->m_DisplayNetNamesMode = 0;
80 
81  m_canvas->SetPrintMirrored( aPrintMirrorMode );
82 
83  // Draw footprints, this is done at last in order to print the pad holes in
84  // white after the tracks and zones
86  D_PAD::m_PadSketchModePenSize = defaultPenSize;
87 
88  wxSize pageSizeIU = GetPageSizeIU() / 2;
89  wxPoint offset( pageSizeIU.x, pageSizeIU.y );
90 
91  for( MODULE* module = GetBoard()->m_Modules; module; module = module->Next() )
92  {
93  module->Move( offset );
94  Print_Module( m_canvas, aDC, module, drawmode, aPrintMaskLayer, drillShapeOpt );
95  module->Move( -offset );
96  }
97 
99 
100  m_canvas->SetPrintMirrored( false );
101 
102  *displ_opts = save_opt;
104 }
105 
106 
108  LSET aPrintMask,
109  bool aPrintMirrorMode,
110  void* aData)
111 {
112  const GR_DRAWMODE drawmode = (GR_DRAWMODE) 0;
113  DISPLAY_OPTIONS save_opt;
114  BOARD* Pcb = GetBoard();
115  int defaultPenSize = Millimeter2iu( 0.2 );
116  bool onePagePerLayer = false;
117 
118  PRINT_PARAMETERS* printParameters = (PRINT_PARAMETERS*) aData; // can be null
120 
121  if( printParameters && printParameters->m_OptionPrintPage == 0 )
122  onePagePerLayer = true;
123 
125 
126  if( printParameters )
127  {
128  drillShapeOpt = printParameters->m_DrillShapeOpt;
129  defaultPenSize = printParameters->m_PenDefaultSize;
130  }
131 
132  save_opt = *displ_opts;
133 
134  PCB_LAYER_ID activeLayer = GetScreen()->m_Active_Layer;
135 
136  displ_opts->m_ContrastModeDisplay = false;
137  displ_opts->m_DisplayPadFill = true;
138  displ_opts->m_DisplayViaFill = true;
139 
140  if( !( aPrintMask & LSET::AllCuMask() ).any() )
141  {
142  if( onePagePerLayer )
143  {
144  // We can print mask layers (solder mask and solder paste) with the actual
145  // pad sizes. To do that, we must set ContrastModeDisplay to true and set
146  // the GetScreen()->m_Active_Layer to the current printed layer
147  displ_opts->m_ContrastModeDisplay = true;
148  displ_opts->m_DisplayPadFill = true;
149 
150  // Calculate the active layer number to print from its mask layer:
152 
153  for( LAYER_NUM id = PCB_LAYER_ID_COUNT-1; id >= 0; --id )
154  {
155  if( aPrintMask[id] )
156  {
158  break;
159  }
160  }
161 
162  // pads on Silkscreen layer are usually plot in sketch mode:
163  if( GetScreen()->m_Active_Layer == B_SilkS ||
164  GetScreen()->m_Active_Layer == F_SilkS )
165  {
166  displ_opts->m_DisplayPadFill = false;
167  }
168  }
169  else
170  {
171  displ_opts->m_DisplayPadFill = false;
172  }
173  }
174 
175  displ_opts->m_DisplayPadNum = false;
176 
177  bool nctmp = GetBoard()->IsElementVisible( LAYER_NO_CONNECTS );
178 
180 
181  bool anchorsTmp = GetBoard()->IsElementVisible( LAYER_ANCHOR );
182 
184 
185  displ_opts->m_DisplayPadIsol = false;
186  displ_opts->m_DisplayModEdgeFill = FILLED;
187  displ_opts->m_DisplayModTextFill = FILLED;
188  displ_opts->m_DisplayPcbTrackFill = true;
190  displ_opts->m_DisplayDrawItemsFill = FILLED;
191  displ_opts->m_DisplayZonesMode = 0;
192  displ_opts->m_DisplayNetNamesMode = 0;
193 
194  m_canvas->SetPrintMirrored( aPrintMirrorMode );
195 
196  for( auto item : Pcb->Drawings() )
197  {
198  switch( item->Type() )
199  {
200  case PCB_LINE_T:
201  case PCB_DIMENSION_T:
202  case PCB_TEXT_T:
203  case PCB_TARGET_T:
204  if( aPrintMask[item->GetLayer()] )
205  item->Draw( m_canvas, aDC, drawmode );
206  break;
207 
208  case PCB_MARKER_T:
209  default:
210  break;
211  }
212  }
213 
214  // Print tracks
215  for( TRACK* track = Pcb->m_Track; track; track = track->Next() )
216  {
217  if( !( aPrintMask & track->GetLayerSet() ).any() )
218  continue;
219 
220  if( track->Type() == PCB_VIA_T ) // VIA encountered.
221  {
222  int radius = track->GetWidth() / 2;
223  const VIA* via = static_cast<const VIA*>( track );
224 
226 
228  via->GetStart().x,
229  via->GetStart().y,
230  radius,
231  0, color, color );
232  }
233  else
234  {
235  track->Draw( m_canvas, aDC, drawmode );
236  }
237  }
238 
239  // Outdated: only for compatibility to old boards
240  for( TRACK* track = Pcb->m_Zone; track; track = track->Next() )
241  {
242  if( !( aPrintMask & track->GetLayerSet() ).any() )
243  continue;
244 
245  track->Draw( m_canvas, aDC, drawmode );
246  }
247 
248  // Draw filled areas (i.e. zones)
249  for( int ii = 0; ii < Pcb->GetAreaCount(); ii++ )
250  {
251  ZONE_CONTAINER* zone = Pcb->GetArea( ii );
252 
253  if( aPrintMask[zone->GetLayer()] )
254  zone->DrawFilledArea( m_canvas, aDC, drawmode );
255  }
256 
257  // Draw footprints, this is done at last in order to print the pad holes in
258  // white after the tracks and zones
260  D_PAD::m_PadSketchModePenSize = defaultPenSize;
261 
262  for( MODULE* module = (MODULE*) Pcb->m_Modules; module; module = module->Next() )
263  {
264  Print_Module( m_canvas, aDC, module, drawmode, aPrintMask, drillShapeOpt );
265  }
266 
268 
269  /* Print via holes in bg color: Not sure it is good for buried or blind
270  * vias */
271  if( drillShapeOpt != PRINT_PARAMETERS::NO_DRILL_SHAPE )
272  {
273  TRACK* track = Pcb->m_Track;
275 
276  bool blackpenstate = GetGRForceBlackPenState();
277 
278  GRForceBlackPen( false );
279 
280  for( ; track; track = track->Next() )
281  {
282  if( !( aPrintMask & track->GetLayerSet() ).any() )
283  continue;
284 
285  if( track->Type() == PCB_VIA_T ) // VIA encountered.
286  {
287  int diameter;
288  const VIA *via = static_cast<const VIA*>( track );
289 
290  if( drillShapeOpt == PRINT_PARAMETERS::SMALL_DRILL_SHAPE )
291  diameter = std::min( SMALL_DRILL, via->GetDrillValue() );
292  else
293  diameter = via->GetDrillValue();
294 
296  track->GetStart().x, track->GetStart().y,
297  diameter/2,
298  0, color, color );
299  }
300  }
301 
302  GRForceBlackPen( blackpenstate );
303  }
304 
305  m_canvas->SetPrintMirrored( false );
306 
307  *displ_opts = save_opt;
308  GetScreen()->m_Active_Layer = activeLayer;
309 
311  GetBoard()->SetElementVisibility( LAYER_ANCHOR, anchorsTmp );
312 }
313 
314 
315 static void Print_Module( EDA_DRAW_PANEL* aPanel, wxDC* aDC, MODULE* aModule,
316  GR_DRAWMODE aDraw_mode, LSET aMask,
317  PRINT_PARAMETERS::DrillShapeOptT aDrillShapeOpt )
318 {
319  // Print pads
320  for( D_PAD* pad = aModule->PadsList(); pad; pad = pad->Next() )
321  {
322  if( !( pad->GetLayerSet() & aMask ).any() )
323  continue;
324 
325  // Manage hole according to the print drill option
326  wxSize drill_tmp = pad->GetDrillSize();
327 
328  switch( aDrillShapeOpt )
329  {
331  pad->SetDrillSize( wxSize(0,0) );
332  break;
333 
335  {
336  wxSize sz( std::min( SMALL_DRILL, pad->GetDrillSize().x ),
337  std::min( SMALL_DRILL, pad->GetDrillSize().y ) );
338 
339  pad->SetDrillSize( sz );
340  }
341  break;
342 
344  // Do nothing
345  break;
346  }
347 
348  pad->Draw( aPanel, aDC, aDraw_mode );
349  pad->SetDrillSize( drill_tmp );
350  }
351 
352  if( aModule->Reference().IsVisible() && aMask[aModule->Reference().GetLayer()] )
353  aModule->Reference().Draw( aPanel, aDC, aDraw_mode );
354 
355  if( aModule->Value().IsVisible() && aMask[aModule->Value().GetLayer()] )
356  aModule->Value().Draw( aPanel, aDC, aDraw_mode );
357 
358  for( EDA_ITEM* item = aModule->GraphicalItemsList(); item; item = item->Next() )
359  {
360  switch( item->Type() )
361  {
362  case PCB_MODULE_TEXT_T:
363  {
364  TEXTE_MODULE* textMod = static_cast<TEXTE_MODULE*>( item );
365 
366  if( !aMask[textMod->GetLayer()] )
367  break;
368 
369  textMod->Draw( aPanel, aDC, aDraw_mode );
370  break;
371  }
372 
373  case PCB_MODULE_EDGE_T:
374  {
375  EDGE_MODULE* edge = static_cast<EDGE_MODULE*>( item );
376 
377  if( !aMask[edge->GetLayer()] )
378  break;
379 
380  edge->Draw( aPanel, aDC, aDraw_mode );
381  }
382  break;
383 
384  default:
385  break;
386  }
387  }
388 }
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:212
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:122
#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:242
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
PCB_GENERAL_SETTINGS & Settings()
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:145
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: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:112
COLORS_DESIGN_SETTINGS & Colors()
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: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: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:165
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