KiCad PCB EDA Suite
BOARD_PRINTOUT Class Referenceabstract

An object 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)
 Configures PAINTER object for a printout. More...
 
virtual void setupPainter (KIGFX::PAINTER &aPainter)
 Configures GAL object for a printout. More...
 
virtual void setupGal (KIGFX::GAL *aGal)
 Returns bounding box of the printed objects (excluding drawing-sheet frame) More...
 
virtual EDA_RECT getBoundingBox ()=0
 Returns a PAINTER instance used to draw the items. More...
 
virtual std::unique_ptr< KIGFX::PAINTERgetPainter (KIGFX::GAL *aGal)=0
 Source VIEW object (note that actual printing only refers to this object) More...
 

Protected Attributes

const KIGFX::VIEWm_view
 Printout parameters. More...
 
BOARD_PRINTOUT_SETTINGS m_settings
 
bool m_gerbviewPrint
 True if the caller is Gerbview, false for Pcbnew. More...
 

Detailed Description

An object derived from wxPrintout to handle the necessary information to control a printer when printing a board.

Definition at line 70 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  m_gerbviewPrint = false;
74 }
const KIGFX::VIEW * m_view
Printout parameters.
BOARD_PRINTOUT_SETTINGS m_settings
bool m_gerbviewPrint
True if the caller is Gerbview, false for Pcbnew.

References m_gerbviewPrint, and m_view.

◆ ~BOARD_PRINTOUT()

virtual BOARD_PRINTOUT::~BOARD_PRINTOUT ( )
inlinevirtual

Definition at line 76 of file board_printout.h.

76 {}

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 prepares the print parameters for the function which actually prints the draw layers.
Parameters
aLayerNamea text which can be printed as layer name.
aPageNumthe number of the current page (only used to print this value).
aPageCountthe number of pages to print (only used to print this value).

Definition at line 87 of file board_printout.cpp.

88 {
89  wxDC* dc = GetDC();
91  std::unique_ptr<KIGFX::GAL_PRINT> galPrint = KIGFX::GAL_PRINT::Create( options, dc );
92  KIGFX::GAL* gal = galPrint->GetGAL();
93  KIGFX::PRINT_CONTEXT* printCtx = galPrint->GetPrintCtx();
94  std::unique_ptr<KIGFX::PAINTER> painter = getPainter( gal );
95  std::unique_ptr<KIGFX::VIEW> view( m_view->DataReference() );
96 
97  // Target paper size
98  wxRect pageSizePx = GetLogicalPageRect();
99  const VECTOR2D pageSizeIn( (double) pageSizePx.width / dc->GetPPI().x,
100  (double) pageSizePx.height / dc->GetPPI().y );
101  const VECTOR2D pageSizeIU( milsToIU( pageSizeIn.x * 1000 ), milsToIU( pageSizeIn.y * 1000 ) );
102 
103  galPrint->SetSheetSize( pageSizeIn );
104 
105  view->SetGAL( gal );
106  view->SetPainter( painter.get() );
107  view->SetScaleLimits( 10e9, 0.0001 );
108  view->SetScale( 1.0 );
109 
110 
111  // Set the color scheme
112  RENDER_SETTINGS* dstSettings = view->GetPainter()->GetSettings();
113  dstSettings->LoadColors( m_settings.m_colorSettings );
114 
116  {
117  for( int i = 0; i < LAYER_ID_COUNT; ++i )
118  dstSettings->SetLayerColor( i, COLOR4D::BLACK );
119  }
120  else // color enabled
121  {
122  for( int i = 0; i < LAYER_ID_COUNT; ++i )
123  {
124  // Cairo does not support translucent colors on PostScript surfaces
125  // see 'Features support by the PostScript surface' on
126  // https://www.cairographics.org/documentation/using_the_postscript_surface/
127  dstSettings->SetLayerColor( i, dstSettings->GetLayerColor( i ).WithAlpha( 1.0 ) );
128  }
129  }
130 
131  dstSettings->SetIsPrinting( true );
132 
133  setupPainter( *painter );
135 
136  wxSize sheetSizeMils = m_settings.m_pageInfo.GetSizeMils();
137  VECTOR2I sheetSizeIU( milsToIU( sheetSizeMils.GetWidth() ),
138  milsToIU( sheetSizeMils.GetHeight() ) );
139  BOX2I bBox;
140 
141  // Determine printout bounding box
143  {
144  bBox = BOX2I( VECTOR2I( 0, 0 ), VECTOR2I( sheetSizeIU ) );
145  view->SetLayerVisible( LAYER_DRAWINGSHEET, true );
146  }
147  else
148  {
149  EDA_RECT targetBbox = getBoundingBox();
150  bBox = BOX2I( targetBbox.GetOrigin(), targetBbox.GetSize() );
151  view->SetLayerVisible( LAYER_DRAWINGSHEET, false );
152  }
153 
154 
155  // Fit to page
156  if( m_settings.m_scale <= 0.0 )
157  {
158  if( bBox.GetWidth() == 0 || bBox.GetHeight() == 0 )
159  {
160  // Nothing to print
161  m_settings.m_scale = 1.0;
162  }
163  else
164  {
165  double scaleX = (double) pageSizeIU.x / bBox.GetWidth();
166  double scaleY = (double) pageSizeIU.y / bBox.GetHeight();
167  m_settings.m_scale = std::min( scaleX, scaleY );
168  }
169  }
170 
171  setupGal( gal );
172  galPrint->SetNativePaperSize( pageSizeIn, printCtx->HasNativeLandscapeRotation() );
173  gal->SetLookAtPoint( bBox.Centre() );
175 
176  gal->SetClearColor( dstSettings->GetBackgroundColor() );
177  gal->ClearScreen();
178 
179  if( m_gerbviewPrint )
180  // Mandatory in Gerbview to use the same order for printing as for screen redraw
181  // due to negative objects that need a specific order
182  view->UseDrawPriority( true );
183 
184  {
185  KIGFX::GAL_DRAWING_CONTEXT ctx( gal );
186  view->Redraw();
187  }
188 }
void SetClearColor(const COLOR4D &aColor)
BOX2< VECTOR2I > BOX2I
Definition: box2.h:506
const PAGE_INFO & m_pageInfo
Definition: printout.h:63
Container for all the knowledge about how graphical objects are drawn on any output surface/device.
virtual std::unique_ptr< KIGFX::PAINTER > getPainter(KIGFX::GAL *aGal)=0
Source VIEW object (note that actual printing only refers to this object)
virtual const COLOR4D & GetBackgroundColor()=0
Return current background color settings.
const KIGFX::VIEW * m_view
Printout parameters.
const COLOR4D & GetLayerColor(int aLayer) const
Return the color used to draw a layer.
COLOR4D WithAlpha(double aAlpha) const
Return a color with the same color, but the given alpha.
Definition: color4d.h:321
LSET m_LayerSet
Layers to print.
Definition: color4d.h:44
VECTOR2< int > VECTOR2I
Definition: vector2d.h:622
BOARD_PRINTOUT_SETTINGS m_settings
double m_scale
Printing scale.
Definition: printout.h:58
COLOR_SETTINGS * m_colorSettings
The color settings to be used for printing.
Definition: printout.h:66
bool m_gerbviewPrint
True if the caller is Gerbview, false for Pcbnew.
virtual int milsToIU(double aMils) const =0
< Convert mils to internal units
virtual void setupPainter(KIGFX::PAINTER &aPainter)
Configures GAL object for a printout.
const wxPoint GetOrigin() const
Definition: eda_rect.h:110
coord_type GetWidth() const
Definition: box2.h:180
virtual void setupGal(KIGFX::GAL *aGal)
Returns bounding box of the printed objects (excluding drawing-sheet frame)
void SetLayerColor(int aLayer, const COLOR4D &aColor)
Change the color used to draw a layer.
bool PrintBorderAndTitleBlock() const
Returns true if the drawing border and title block should be printed.
Definition: printout.h:55
const wxSize & GetSizeMils() const
Definition: page_info.h:135
drawingsheet frame and titleblock
Definition: layer_ids.h:224
virtual void setupViewLayers(KIGFX::VIEW &aView, const LSET &aLayerSet)
Configures PAINTER object for a printout.
bool m_blackWhite
Print in B&W or Color.
Definition: printout.h:60
std::unique_ptr< VIEW > DataReference() const
Return a new VIEW object that shares the same set of VIEW_ITEMs and LAYERs.
Definition: view.cpp:1506
virtual void ClearScreen()
Clear the screen.
Vec Centre() const
Definition: box2.h:63
virtual bool HasNativeLandscapeRotation() const =0
void SetIsPrinting(bool isPrinting)
Handle the component boundary box.
Definition: eda_rect.h:42
void SetZoomFactor(double aZoomFactor)
Set the zoom factor of the scene.
coord_type GetHeight() const
Definition: box2.h:181
void SetLookAtPoint(const VECTOR2D &aPoint)
Set the Point in world space to look at.
virtual void LoadColors(const COLOR_SETTINGS *aSettings)
virtual EDA_RECT getBoundingBox()=0
Returns a PAINTER instance used to draw the items.
#define LAYER_ID_COUNT
Must update this if you add any enums after GerbView!
Definition: layer_ids.h:436
const wxSize GetSize() const
Definition: eda_rect.h:100
Abstract interface for drawing on a 2D-surface.

References BLACK, BOX2< Vec >::Centre(), KIGFX::GAL::ClearScreen(), KIGFX::VIEW::DataReference(), KIGFX::RENDER_SETTINGS::GetBackgroundColor(), getBoundingBox(), BOX2< Vec >::GetHeight(), KIGFX::RENDER_SETTINGS::GetLayerColor(), EDA_RECT::GetOrigin(), getPainter(), EDA_RECT::GetSize(), PAGE_INFO::GetSizeMils(), BOX2< Vec >::GetWidth(), KIGFX::PRINT_CONTEXT::HasNativeLandscapeRotation(), LAYER_DRAWINGSHEET, LAYER_ID_COUNT, KIGFX::RENDER_SETTINGS::LoadColors(), PRINTOUT_SETTINGS::m_blackWhite, PRINTOUT_SETTINGS::m_colorSettings, m_gerbviewPrint, BOARD_PRINTOUT_SETTINGS::m_LayerSet, PRINTOUT_SETTINGS::m_pageInfo, PRINTOUT_SETTINGS::m_scale, m_settings, m_view, milsToIU(), PRINTOUT_SETTINGS::PrintBorderAndTitleBlock(), KIGFX::GAL::SetClearColor(), KIGFX::RENDER_SETTINGS::SetIsPrinting(), KIGFX::RENDER_SETTINGS::SetLayerColor(), KIGFX::GAL::SetLookAtPoint(), setupGal(), setupPainter(), setupViewLayers(), KIGFX::GAL::SetZoomFactor(), and KIGFX::COLOR4D::WithAlpha().

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

◆ getBoundingBox()

virtual EDA_RECT BOARD_PRINTOUT::getBoundingBox ( )
protectedpure virtual

Returns a PAINTER instance used to draw the items.

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 77 of file board_printout.cpp.

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

References PRINTOUT_SETTINGS::m_pageCount, and m_settings.

◆ getPainter()

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

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

Implemented in PCBNEW_PRINTOUT, and GERBVIEW_PRINTOUT.

Referenced by DrawPage().

◆ HasPage()

bool BOARD_PRINTOUT::HasPage ( int  aPage)
inlineoverride

Definition at line 80 of file board_printout.h.

81  {
82  return aPage <= m_settings.m_pageCount;
83  }
BOARD_PRINTOUT_SETTINGS m_settings
int m_pageCount
Number of pages to print.
Definition: printout.h:61

References PRINTOUT_SETTINGS::m_pageCount, and m_settings.

◆ milsToIU()

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

< Convert mils to internal units

Enables layers visibility for a printout

Implemented in PCBNEW_PRINTOUT, and GERBVIEW_PRINTOUT.

Referenced by DrawPage().

◆ setupGal()

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

Returns bounding box of the printed objects (excluding drawing-sheet frame)

Reimplemented in PCBNEW_PRINTOUT, and GERBVIEW_PRINTOUT.

Definition at line 210 of file board_printout.cpp.

211 {
212  aGal->SetFlip( m_settings.m_Mirror, false );
213 }
void SetFlip(bool xAxis, bool yAxis)
Sets flipping of the screen.
BOARD_PRINTOUT_SETTINGS m_settings
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 GAL object for a printout.

Reimplemented in PCBNEW_PRINTOUT.

Definition at line 203 of file board_printout.cpp.

204 {
205  if( !m_settings.m_background )
207 }
bool m_background
Print background color.
Definition: printout.h:62
BOARD_PRINTOUT_SETTINGS m_settings
Definition: color4d.h:48
virtual RENDER_SETTINGS * GetSettings()=0
Return a pointer to current settings that are going to be used when drawing items.
virtual void SetBackgroundColor(const COLOR4D &aColor)=0
Set 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

Configures PAINTER object for a printout.

Reimplemented in PCBNEW_PRINTOUT, and GERBVIEW_PRINTOUT.

Definition at line 191 of file board_printout.cpp.

192 {
193  // Disable all layers by default, let specific implementations enable required layers
194  for( int i = 0; i < KIGFX::VIEW::VIEW_MAX_LAYERS; ++i )
195  {
196  aView.SetLayerVisible( i, false );
197  aView.SetTopLayer( i, false );
199  }
200 }
virtual void SetTopLayer(int aLayer, bool aEnabled=true)
Set given layer to be displayed on the top or sets back the default order of layers.
Definition: view.cpp:826
static constexpr int VIEW_MAX_LAYERS
maximum number of layers that may be shown
Definition: view.h:711
Auxiliary rendering target (noncached)
Definition: definitions.h:49
void SetLayerTarget(int aLayer, RENDER_TARGET aTarget)
Change the rendering target for a particular layer.
Definition: view.h:461
void SetLayerVisible(int aLayer, bool aVisible=true)
Control 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_gerbviewPrint

bool BOARD_PRINTOUT::m_gerbviewPrint
protected

True if the caller is Gerbview, false for Pcbnew.

Definition at line 124 of file board_printout.h.

Referenced by BOARD_PRINTOUT(), DrawPage(), and GERBVIEW_PRINTOUT::GERBVIEW_PRINTOUT().

◆ m_settings

◆ m_view

const KIGFX::VIEW* BOARD_PRINTOUT::m_view
protected

Printout parameters.

Definition at line 118 of file board_printout.h.

Referenced by BOARD_PRINTOUT(), and DrawPage().


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