KiCad PCB EDA Suite
BOARD_PRINTOUT Class Referenceabstract

BOARD_PRINTOUT is a class derived from wxPrintout to handle the necessary information to control a printer when printing a board. More...

#include <board_printout.h>

Inheritance diagram for BOARD_PRINTOUT:
GERBVIEW_PRINTOUT PCBNEW_PRINTOUT

Public Member Functions

 BOARD_PRINTOUT (const BOARD_PRINTOUT_SETTINGS &aParams, const KIGFX::VIEW *aView, const wxString &aTitle)
 
virtual ~BOARD_PRINTOUT ()
 
void GetPageInfo (int *minPage, int *maxPage, int *selPageFrom, int *selPageTo) override
 
bool HasPage (int aPage) override
 
virtual void DrawPage (const wxString &aLayerName=wxEmptyString, int aPageNum=1, int aPageCount=1)
 Print a page (or a set of pages). More...
 

Protected Member Functions

virtual int milsToIU (double aMils) const =0
 

Convert mils to internal units

More...
 
virtual void setupViewLayers (KIGFX::VIEW &aView, const LSET &aLayerSet)
 

Enables layers visibility for a printout

More...
 
virtual void setupPainter (KIGFX::PAINTER &aPainter)
 

Configures PAINTER object for a printout

More...
 
virtual void setupGal (KIGFX::GAL *aGal)
 

Configures GAL object for a printout

More...
 
virtual EDA_RECT getBoundingBox ()=0
 

Returns bounding box of the printed objects (excluding worksheet frame)

More...
 
virtual std::unique_ptr< KIGFX::PAINTERgetPainter (KIGFX::GAL *aGal)=0
 

Returns a PAINTER instance used to draw the items.

More...
 

Protected Attributes

const KIGFX::VIEWm_view
 

Source VIEW object (note that actual printing only refers to this object)

More...
 
BOARD_PRINTOUT_SETTINGS m_settings
 

Printout parameters

More...
 

Detailed Description

BOARD_PRINTOUT is a class derived from wxPrintout to handle the necessary information to control a printer when printing a board.

Definition at line 68 of file board_printout.h.

Constructor & Destructor Documentation

◆ BOARD_PRINTOUT()

BOARD_PRINTOUT::BOARD_PRINTOUT ( const BOARD_PRINTOUT_SETTINGS aParams,
const KIGFX::VIEW aView,
const wxString &  aTitle 
)

Definition at line 67 of file board_printout.cpp.

68  :
69  wxPrintout( aTitle ),
70  m_settings( aParams )
71 {
72  m_view = aView;
73 }
const KIGFX::VIEW * m_view
Source VIEW object (note that actual printing only refers to this object)
BOARD_PRINTOUT_SETTINGS m_settings
Printout parameters

References m_view.

◆ ~BOARD_PRINTOUT()

virtual BOARD_PRINTOUT::~BOARD_PRINTOUT ( )
inlinevirtual

Definition at line 74 of file board_printout.h.

74 {}

Member Function Documentation

◆ DrawPage()

void BOARD_PRINTOUT::DrawPage ( const wxString &  aLayerName = wxEmptyString,
int  aPageNum = 1,
int  aPageCount = 1 
)
virtual

Print a page (or a set of pages).

Note: this function prepare print parameters for the function which actually print the draw layers.

Parameters
aLayerName= a text which can be printed as layer name
aPageNum= the number of the current page (only used to print this value)
aPageCount= the number of pages to ptint (only used to print this value)

Definition at line 86 of file board_printout.cpp.

87 {
88  auto dc = GetDC();
90  auto galPrint = KIGFX::GAL_PRINT::Create( options, dc );
91  auto gal = galPrint->GetGAL();
92  auto printCtx = galPrint->GetPrintCtx();
93  auto painter = getPainter( gal );
94  std::unique_ptr<KIGFX::VIEW> view( m_view->DataReference() );
95 
96  // Target paper size
97  wxRect pageSizePx = GetLogicalPageRect();
98  const VECTOR2D pageSizeIn( (double) pageSizePx.width / dc->GetPPI().x,
99  (double) pageSizePx.height / dc->GetPPI().y );
100  galPrint->SetSheetSize( pageSizeIn );
101  const VECTOR2D pageSizeIU( milsToIU( pageSizeIn.x * 1000 ), milsToIU( pageSizeIn.y * 1000 ) );
102 
103  view->SetGAL( gal );
104  view->SetPainter( painter.get() );
105  view->SetScaleLimits( 10e9, 0.0001 );
106  view->SetScale( 1.0 );
107 
108 
109  // Set the color scheme
110  auto dstSettings = view->GetPainter()->GetSettings();
111  dstSettings->LoadColors( m_settings.m_colorSettings );
112 
114  {
115  for( int i = 0; i < LAYER_ID_COUNT; ++i )
116  dstSettings->SetLayerColor( i, COLOR4D::BLACK );
117  }
118  else // color enabled
119  {
120  for( int i = 0; i < LAYER_ID_COUNT; ++i )
121  {
122  // Cairo does not support translucent colors on PostScript surfaces
123  // see 'Features support by the PostScript surface' on
124  // https://www.cairographics.org/documentation/using_the_postscript_surface/
125  dstSettings->SetLayerColor( i, dstSettings->GetLayerColor( i ).WithAlpha( 1.0 ) );
126  }
127  }
128 
130  setupPainter( *painter );
131 
132  auto sheetSizeMils = m_settings.m_pageInfo.GetSizeMils();
133  VECTOR2I sheetSizeIU( milsToIU( sheetSizeMils.GetWidth() ), milsToIU( sheetSizeMils.GetHeight() ) );
134  BOX2I bBox;
135 
136  // Determine printout bounding box
138  {
139  bBox = BOX2I( VECTOR2I( 0, 0 ), VECTOR2I( sheetSizeIU ) );
140  view->SetLayerVisible( LAYER_WORKSHEET, true );
141  }
142  else
143  {
144  EDA_RECT targetBbox = getBoundingBox();
145  bBox = BOX2I( targetBbox.GetOrigin(), targetBbox.GetSize() );
146  view->SetLayerVisible( LAYER_WORKSHEET, false );
147  }
148 
149 
150  // Fit to page
151  if( m_settings.m_scale <= 0.0 )
152  {
153  if( bBox.GetWidth() == 0 || bBox.GetHeight() == 0 )
154  {
155  // Nothing to print
156  m_settings.m_scale = 1.0;
157  }
158  else
159  {
160  double scaleX = (double) pageSizeIU.x / bBox.GetWidth();
161  double scaleY = (double) pageSizeIU.y / bBox.GetHeight();
162  m_settings.m_scale = std::min( scaleX, scaleY );
163  }
164  }
165 
166  view->SetPrintMode( 1 );
167 
168  setupGal( gal );
169  galPrint->SetNativePaperSize( pageSizeIn, printCtx->HasNativeLandscapeRotation() );
170  gal->SetLookAtPoint( bBox.Centre() );
171  gal->SetZoomFactor( m_settings.m_scale );
172 
173  gal->SetClearColor( dstSettings->GetBackgroundColor() );
174  gal->ClearScreen();
175 
176  {
177  KIGFX::GAL_DRAWING_CONTEXT ctx( gal );
178  view->Redraw();
179  }
180 
181  view->SetPrintMode( 0 );
182 }
BOX2< VECTOR2I > BOX2I
Definition: box2.h:522
const PAGE_INFO & m_pageInfo
Definition: printout.h:56
virtual std::unique_ptr< KIGFX::PAINTER > getPainter(KIGFX::GAL *aGal)=0
Returns a PAINTER instance used to draw the items.
const KIGFX::VIEW * m_view
Source VIEW object (note that actual printing only refers to this object)
Definition: color4d.h:44
VECTOR2< int > VECTOR2I
Definition: vector2d.h:594
BOARD_PRINTOUT_SETTINGS m_settings
Printout parameters
double m_scale
Printing scale.
Definition: printout.h:51
COLOR_SETTINGS * m_colorSettings
The color settings to be used for printing.
Definition: printout.h:59
virtual int milsToIU(double aMils) const =0
Convert mils to internal units
virtual void setupPainter(KIGFX::PAINTER &aPainter)
Configures PAINTER object for a printout
const wxPoint GetOrigin() const
Definition: eda_rect.h:114
coord_type GetWidth() const
Definition: box2.h:197
virtual void setupGal(KIGFX::GAL *aGal)
Configures GAL object for a printout
bool PrintBorderAndTitleBlock() const
Returns true if the drawing border and title block should be printed.
Definition: printout.h:64
const wxSize & GetSizeMils() const
Definition: page_info.h:143
#define LAYER_ID_COUNT
Must update this if you add any enums after GerbView!
virtual void setupViewLayers(KIGFX::VIEW &aView, const LSET &aLayerSet)
Enables layers visibility for a printout
bool m_blackWhite
Print in B&W or Color.
Definition: printout.h:53
std::unique_ptr< VIEW > DataReference() const
Returns a new VIEW object that shares the same set of VIEW_ITEMs and LAYERs.
Definition: view.cpp:1467
Vec Centre() const
Definition: box2.h:79
EDA_RECT handles the component boundary box.
Definition: eda_rect.h:44
coord_type GetHeight() const
Definition: box2.h:198
virtual EDA_RECT getBoundingBox()=0
Returns bounding box of the printed objects (excluding worksheet frame)
LSET m_layerSet
Layers to print.
const wxSize GetSize() const
Definition: eda_rect.h:103

References BLACK, BOX2< Vec >::Centre(), KIGFX::VIEW::DataReference(), getBoundingBox(), BOX2< Vec >::GetHeight(), EDA_RECT::GetOrigin(), getPainter(), EDA_RECT::GetSize(), PAGE_INFO::GetSizeMils(), BOX2< Vec >::GetWidth(), LAYER_ID_COUNT, LAYER_WORKSHEET, PRINTOUT_SETTINGS::m_blackWhite, PRINTOUT_SETTINGS::m_colorSettings, BOARD_PRINTOUT_SETTINGS::m_layerSet, PRINTOUT_SETTINGS::m_pageInfo, PRINTOUT_SETTINGS::m_scale, m_settings, m_view, milsToIU(), PRINTOUT_SETTINGS::PrintBorderAndTitleBlock(), setupGal(), setupPainter(), setupViewLayers(), VECTOR2< T >::x, and VECTOR2< T >::y.

Referenced by GERBVIEW_PRINTOUT::OnPrintPage(), and PCBNEW_PRINTOUT::OnPrintPage().

◆ getBoundingBox()

virtual EDA_RECT BOARD_PRINTOUT::getBoundingBox ( )
protectedpure virtual

Returns bounding box of the printed objects (excluding worksheet frame)

Implemented in PCBNEW_PRINTOUT, and GERBVIEW_PRINTOUT.

Referenced by DrawPage().

◆ GetPageInfo()

void BOARD_PRINTOUT::GetPageInfo ( int *  minPage,
int *  maxPage,
int *  selPageFrom,
int *  selPageTo 
)
override

Definition at line 76 of file board_printout.cpp.

77 {
78  *minPage = 1;
79  *selPageFrom = 1;
80 
81  *maxPage = m_settings.m_pageCount;
82  *selPageTo = m_settings.m_pageCount;
83 }
BOARD_PRINTOUT_SETTINGS m_settings
Printout parameters
int m_pageCount
Number of pages to print.
Definition: printout.h:54

References PRINTOUT_SETTINGS::m_pageCount, and m_settings.

◆ getPainter()

virtual std::unique_ptr<KIGFX::PAINTER> BOARD_PRINTOUT::getPainter ( KIGFX::GAL aGal)
protectedpure virtual

Returns a PAINTER instance used to draw the items.

Implemented in PCBNEW_PRINTOUT, and GERBVIEW_PRINTOUT.

Referenced by DrawPage().

◆ HasPage()

bool BOARD_PRINTOUT::HasPage ( int  aPage)
inlineoverride

Definition at line 78 of file board_printout.h.

79  {
80  return aPage <= m_settings.m_pageCount;
81  }
BOARD_PRINTOUT_SETTINGS m_settings
Printout parameters
int m_pageCount
Number of pages to print.
Definition: printout.h:54

References PRINTOUT_SETTINGS::m_pageCount, and m_settings.

◆ milsToIU()

virtual int BOARD_PRINTOUT::milsToIU ( double  aMils) const
protectedpure virtual

Convert mils to internal units

Implemented in PCBNEW_PRINTOUT, and GERBVIEW_PRINTOUT.

Referenced by DrawPage().

◆ setupGal()

void BOARD_PRINTOUT::setupGal ( KIGFX::GAL aGal)
protectedvirtual

Configures GAL object for a printout

Reimplemented in PCBNEW_PRINTOUT, and GERBVIEW_PRINTOUT.

Definition at line 204 of file board_printout.cpp.

205 {
206  aGal->SetFlip( m_settings.m_mirror, false );
207 }
void SetFlip(bool xAxis, bool yAxis)
Sets flipping of the screen.
BOARD_PRINTOUT_SETTINGS m_settings
Printout parameters
bool m_mirror
Print mirrored.

References BOARD_PRINTOUT_SETTINGS::m_mirror, m_settings, and KIGFX::GAL::SetFlip().

Referenced by DrawPage(), GERBVIEW_PRINTOUT::setupGal(), and PCBNEW_PRINTOUT::setupGal().

◆ setupPainter()

void BOARD_PRINTOUT::setupPainter ( KIGFX::PAINTER aPainter)
protectedvirtual

Configures PAINTER object for a printout

Reimplemented in PCBNEW_PRINTOUT.

Definition at line 197 of file board_printout.cpp.

198 {
199  if( !m_settings.m_background )
201 }
bool m_background
Print background color.
Definition: printout.h:55
BOARD_PRINTOUT_SETTINGS m_settings
Printout parameters
Definition: color4d.h:48
virtual RENDER_SETTINGS * GetSettings()=0
Function GetAdapter Returns pointer to current settings that are going to be used when drawing items.
virtual void SetBackgroundColor(const COLOR4D &aColor)=0
Sets the background color.

References KIGFX::PAINTER::GetSettings(), PRINTOUT_SETTINGS::m_background, m_settings, KIGFX::RENDER_SETTINGS::SetBackgroundColor(), and WHITE.

Referenced by DrawPage(), and PCBNEW_PRINTOUT::setupPainter().

◆ setupViewLayers()

void BOARD_PRINTOUT::setupViewLayers ( KIGFX::VIEW aView,
const LSET aLayerSet 
)
protectedvirtual

Enables layers visibility for a printout

Reimplemented in PCBNEW_PRINTOUT, and GERBVIEW_PRINTOUT.

Definition at line 185 of file board_printout.cpp.

186 {
187  // Disable all layers by default, let specific implementions enable required layers
188  for( int i = 0; i < KIGFX::VIEW::VIEW_MAX_LAYERS; ++i )
189  {
190  aView.SetLayerVisible( i, false );
191  aView.SetTopLayer( i, false );
193  }
194 }
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:856
static constexpr int VIEW_MAX_LAYERS
maximum number of layers that may be shown
Definition: view.h:697
Auxiliary rendering target (noncached)
Definition: definitions.h:49
void SetLayerTarget(int aLayer, RENDER_TARGET aTarget)
Function SetLayerTarget() Changes the rendering target for a particular layer.
Definition: view.h:423
void SetLayerVisible(int aLayer, bool aVisible=true)
Function SetLayerVisible() Controls the visibility of a particular layer.
Definition: view.h:388

References KIGFX::VIEW::SetLayerTarget(), KIGFX::VIEW::SetLayerVisible(), KIGFX::VIEW::SetTopLayer(), KIGFX::TARGET_NONCACHED, and KIGFX::VIEW::VIEW_MAX_LAYERS.

Referenced by DrawPage(), GERBVIEW_PRINTOUT::setupViewLayers(), and PCBNEW_PRINTOUT::setupViewLayers().

Member Data Documentation

◆ m_settings

◆ m_view

const KIGFX::VIEW* BOARD_PRINTOUT::m_view
protected

Source VIEW object (note that actual printing only refers to this object)

Definition at line 114 of file board_printout.h.

Referenced by BOARD_PRINTOUT(), and DrawPage().


The documentation for this class was generated from the following files: