KiCad PCB EDA Suite
GERBVIEW_PRINTOUT Class Reference

#include <gerbview_printout.h>

Inheritance diagram for GERBVIEW_PRINTOUT:
BOARD_PRINTOUT

Public Member Functions

 GERBVIEW_PRINTOUT (GBR_LAYOUT *aLayout, const BOARD_PRINTOUT_SETTINGS &aParams, const KIGFX::VIEW *aView, const wxString &aTitle)
 
bool OnPrintPage (int aPage) override
 
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

int milsToIU (double aMils) const override
 < Convert mils to internal units More...
 
void setupViewLayers (KIGFX::VIEW &aView, const LSET &aLayerSet) override
 Configures PAINTER object for a printout. More...
 
void setupGal (KIGFX::GAL *aGal) override
 Returns bounding box of the printed objects (excluding drawing-sheet frame) More...
 
EDA_RECT getBoundingBox () override
 Returns a PAINTER instance used to draw the items. More...
 
std::unique_ptr< KIGFX::PAINTERgetPainter (KIGFX::GAL *aGal) override
 Source VIEW object (note that actual printing only refers to this object) More...
 
virtual void setupPainter (KIGFX::PAINTER &aPainter)
 Configures GAL object for a printout. 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...
 

Private Attributes

GBR_LAYOUTm_layout
 

Detailed Description

Definition at line 27 of file gerbview_printout.h.

Constructor & Destructor Documentation

◆ GERBVIEW_PRINTOUT()

GERBVIEW_PRINTOUT::GERBVIEW_PRINTOUT ( GBR_LAYOUT aLayout,
const BOARD_PRINTOUT_SETTINGS aParams,
const KIGFX::VIEW aView,
const wxString &  aTitle 
)

Definition at line 36 of file gerbview_printout.cpp.

37 :
38 BOARD_PRINTOUT( aParams, aView, aTitle )
39{
40 m_layout = aLayout;
41 m_gerbviewPrint = true;
42}
bool m_gerbviewPrint
True if the caller is Gerbview, false for Pcbnew.
BOARD_PRINTOUT(const BOARD_PRINTOUT_SETTINGS &aParams, const KIGFX::VIEW *aView, const wxString &aTitle)
GBR_LAYOUT * m_layout

References BOARD_PRINTOUT::m_gerbviewPrint, and m_layout.

Member Function Documentation

◆ DrawPage()

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

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 // In B&W mode, draw the background only in wxhite, because any other color
121 // will be replaced by a black background
122 dstSettings->SetBackgroundColor( COLOR4D::WHITE );
123 }
124 else // color enabled
125 {
126 for( int i = 0; i < LAYER_ID_COUNT; ++i )
127 {
128 // Cairo does not support translucent colors on PostScript surfaces
129 // see 'Features support by the PostScript surface' on
130 // https://www.cairographics.org/documentation/using_the_postscript_surface/
131 dstSettings->SetLayerColor( i, dstSettings->GetLayerColor( i ).WithAlpha( 1.0 ) );
132 }
133 }
134
135 dstSettings->SetIsPrinting( true );
136
137 setupPainter( *painter );
139 dstSettings->SetPrintLayers( m_settings.m_LayerSet );
140
141 dstSettings->SetLayerName( aLayerName );
142
143 VECTOR2I sheetSizeMils = m_settings.m_pageInfo.GetSizeMils();
144 VECTOR2I sheetSizeIU( milsToIU( sheetSizeMils.x ),
145 milsToIU( sheetSizeMils.y ) );
146 BOX2I bBox;
147
148 // Determine printout bounding box
150 {
151 bBox = BOX2I( VECTOR2I( 0, 0 ), VECTOR2I( sheetSizeIU ) );
152 view->SetLayerVisible( LAYER_DRAWINGSHEET, true );
153 }
154 else
155 {
156 EDA_RECT targetBbox = getBoundingBox();
157 bBox = BOX2I( targetBbox.GetOrigin(), targetBbox.GetSize() );
158 view->SetLayerVisible( LAYER_DRAWINGSHEET, false );
159 }
160
161
162 // Fit to page
163 if( m_settings.m_scale <= 0.0 )
164 {
165 if( bBox.GetWidth() == 0 || bBox.GetHeight() == 0 )
166 {
167 // Nothing to print
168 m_settings.m_scale = 1.0;
169 }
170 else
171 {
172 double scaleX = (double) pageSizeIU.x / bBox.GetWidth();
173 double scaleY = (double) pageSizeIU.y / bBox.GetHeight();
174 m_settings.m_scale = std::min( scaleX, scaleY );
175 }
176 }
177
178 setupGal( gal );
179 galPrint->SetNativePaperSize( pageSizeIn, printCtx->HasNativeLandscapeRotation() );
180 gal->SetLookAtPoint( bBox.Centre() );
182
183 gal->SetClearColor( dstSettings->GetBackgroundColor() );
184 gal->ClearScreen();
185
186 if( m_gerbviewPrint )
187 // Mandatory in Gerbview to use the same order for printing as for screen redraw
188 // due to negative objects that need a specific order
189 view->UseDrawPriority( true );
190
191 {
193 view->Redraw();
194 }
195}
BOX2< VECTOR2I > BOX2I
Definition: box2.h:506
virtual void setupPainter(KIGFX::PAINTER &aPainter)
Configures GAL object for a printout.
virtual int milsToIU(double aMils) const =0
< Convert mils to internal units
virtual std::unique_ptr< KIGFX::PAINTER > getPainter(KIGFX::GAL *aGal)=0
Source VIEW object (note that actual printing only refers to this object)
const KIGFX::VIEW * m_view
Printout parameters.
virtual void setupViewLayers(KIGFX::VIEW &aView, const LSET &aLayerSet)
Configures PAINTER object for a printout.
virtual void setupGal(KIGFX::GAL *aGal)
Returns bounding box of the printed objects (excluding drawing-sheet frame)
virtual EDA_RECT getBoundingBox()=0
Returns a PAINTER instance used to draw the items.
BOARD_PRINTOUT_SETTINGS m_settings
coord_type GetHeight() const
Definition: box2.h:181
coord_type GetWidth() const
Definition: box2.h:180
Vec Centre() const
Definition: box2.h:63
Handle the component boundary box.
Definition: eda_rect.h:44
const VECTOR2I GetOrigin() const
Definition: eda_rect.h:115
const VECTOR2I GetSize() const
Definition: eda_rect.h:105
COLOR4D WithAlpha(double aAlpha) const
Return a color with the same color, but the given alpha.
Definition: color4d.h:321
Abstract interface for drawing on a 2D-surface.
void SetZoomFactor(double aZoomFactor)
void SetLookAtPoint(const VECTOR2D &aPoint)
Get/set the Point in world space to look at.
virtual void ClearScreen()
Clear the screen.
void SetClearColor(const COLOR4D &aColor)
virtual bool HasNativeLandscapeRotation() const =0
Container for all the knowledge about how graphical objects are drawn on any output surface/device.
void SetLayerColor(int aLayer, const COLOR4D &aColor)
Change the color used to draw a layer.
virtual void LoadColors(const COLOR_SETTINGS *aSettings)
void SetPrintLayers(LSET aLayerSet)
virtual const COLOR4D & GetBackgroundColor()=0
Return current background color settings.
const COLOR4D & GetLayerColor(int aLayer) const
Return the color used to draw a layer.
virtual void SetBackgroundColor(const COLOR4D &aColor)=0
Set the background color.
void SetLayerName(const wxString &aLayerName)
void SetIsPrinting(bool isPrinting)
std::unique_ptr< VIEW > DataReference() const
Return a new VIEW object that shares the same set of VIEW_ITEMs and LAYERs.
Definition: view.cpp:1502
const VECTOR2I & GetSizeMils() const
Definition: page_info.h:135
@ WHITE
Definition: color4d.h:48
@ BLACK
Definition: color4d.h:44
#define LAYER_ID_COUNT
Must update this if you add any enums after GerbView!
Definition: layer_ids.h:448
@ LAYER_DRAWINGSHEET
drawingsheet frame and titleblock
Definition: layer_ids.h:217
LSET m_LayerSet
Layers to print.
bool PrintBorderAndTitleBlock() const
Returns true if the drawing border and title block should be printed.
Definition: printout.h:55
COLOR_SETTINGS * m_colorSettings
The color settings to be used for printing.
Definition: printout.h:66
bool m_blackWhite
Print in B&W or Color.
Definition: printout.h:60
const PAGE_INFO & m_pageInfo
Definition: printout.h:63
double m_scale
Printing scale.
Definition: printout.h:58
VECTOR2< int > VECTOR2I
Definition: vector2d.h:607

References BLACK, BOX2< Vec >::Centre(), KIGFX::GAL::ClearScreen(), KIGFX::VIEW::DataReference(), KIGFX::RENDER_SETTINGS::GetBackgroundColor(), BOARD_PRINTOUT::getBoundingBox(), BOX2< Vec >::GetHeight(), KIGFX::RENDER_SETTINGS::GetLayerColor(), EDA_RECT::GetOrigin(), BOARD_PRINTOUT::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, BOARD_PRINTOUT::m_gerbviewPrint, BOARD_PRINTOUT_SETTINGS::m_LayerSet, PRINTOUT_SETTINGS::m_pageInfo, PRINTOUT_SETTINGS::m_scale, BOARD_PRINTOUT::m_settings, BOARD_PRINTOUT::m_view, BOARD_PRINTOUT::milsToIU(), PRINTOUT_SETTINGS::PrintBorderAndTitleBlock(), KIGFX::RENDER_SETTINGS::SetBackgroundColor(), KIGFX::GAL::SetClearColor(), KIGFX::RENDER_SETTINGS::SetIsPrinting(), KIGFX::RENDER_SETTINGS::SetLayerColor(), KIGFX::RENDER_SETTINGS::SetLayerName(), KIGFX::GAL::SetLookAtPoint(), KIGFX::RENDER_SETTINGS::SetPrintLayers(), BOARD_PRINTOUT::setupGal(), BOARD_PRINTOUT::setupPainter(), BOARD_PRINTOUT::setupViewLayers(), KIGFX::GAL::SetZoomFactor(), WHITE, KIGFX::COLOR4D::WithAlpha(), VECTOR2< T >::x, and VECTOR2< T >::y.

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

◆ getBoundingBox()

EDA_RECT GERBVIEW_PRINTOUT::getBoundingBox ( )
overrideprotectedvirtual

Returns a PAINTER instance used to draw the items.

Implements BOARD_PRINTOUT.

Definition at line 98 of file gerbview_printout.cpp.

99{
101}
EDA_RECT ComputeBoundingBox() const
Calculate the bounding box containing all Gerber items.
Definition: gbr_layout.cpp:47

References GBR_LAYOUT::ComputeBoundingBox(), and m_layout.

◆ GetPageInfo()

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

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}
int m_pageCount
Number of pages to print.
Definition: printout.h:61

References PRINTOUT_SETTINGS::m_pageCount, and BOARD_PRINTOUT::m_settings.

◆ getPainter()

std::unique_ptr< KIGFX::PAINTER > GERBVIEW_PRINTOUT::getPainter ( KIGFX::GAL aGal)
overrideprotectedvirtual

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

Implements BOARD_PRINTOUT.

Definition at line 104 of file gerbview_printout.cpp.

105{
106 return std::make_unique<KIGFX::GERBVIEW_PAINTER>( aGal );
107}

◆ HasPage()

bool BOARD_PRINTOUT::HasPage ( int  aPage)
inlineoverrideinherited

Definition at line 80 of file board_printout.h.

81 {
82 return aPage <= m_settings.m_pageCount;
83 }

References PRINTOUT_SETTINGS::m_pageCount, and BOARD_PRINTOUT::m_settings.

◆ milsToIU()

int GERBVIEW_PRINTOUT::milsToIU ( double  aMils) const
overrideprotectedvirtual

< Convert mils to internal units

Enables layers visibility for a printout

Implements BOARD_PRINTOUT.

Definition at line 76 of file gerbview_printout.cpp.

77{
78 return KiROUND( IU_PER_MILS * aMils );
79}
#define IU_PER_MILS
Definition: plotter.cpp:129
constexpr ret_type KiROUND(fp_type v)
Round a floating point number to an integer using "round halfway cases away from zero".
Definition: util.h:80

References IU_PER_MILS, and KiROUND().

◆ OnPrintPage()

bool GERBVIEW_PRINTOUT::OnPrintPage ( int  aPage)
override

Definition at line 45 of file gerbview_printout.cpp.

46{
47 // Store the layerset, as it is going to be modified below and the original settings are needed
49
50 LSEQ seq = lset.UIOrder();
51 wxCHECK( unsigned( aPage - 1 ) < seq.size(), false );
52 auto layerId = seq[aPage - 1];
53
54 // In gerbview, draw layers are always printed on separate pages because handling negative
55 // objects when using only one page is tricky
56
57 // Enable only one layer to create a printout
58 m_settings.m_LayerSet = LSET( layerId );
59
61 GERBER_FILE_IMAGE* gbrImage = gbrImgList.GetGbrImage( layerId );
62 wxString gbr_filename;
63
64 if( gbrImage )
65 gbr_filename = gbrImage->m_FileName;
66
67 DrawPage( gbr_filename, aPage, m_settings.m_pageCount );
68
69 // Restore the original layer set, so the next page can be printed
71
72 return true;
73}
virtual void DrawPage(const wxString &aLayerName=wxEmptyString, int aPageNum=1, int aPageCount=1)
Print a page (or a set of pages).
GERBER_FILE_IMAGE_LIST is a helper class to handle a list of GERBER_FILE_IMAGE files which are loaded...
static GERBER_FILE_IMAGE_LIST & GetImagesList()
GERBER_FILE_IMAGE * GetGbrImage(int aIdx)
Hold the image data and parameters for one gerber file and layer parameters.
LSEQ is a sequence (and therefore also a set) of PCB_LAYER_IDs.
Definition: layer_ids.h:490
LSET is a set of PCB_LAYER_IDs.
Definition: layer_ids.h:529
LSEQ UIOrder() const
Definition: lset.cpp:916

References BOARD_PRINTOUT::DrawPage(), GERBER_FILE_IMAGE_LIST::GetGbrImage(), GERBER_FILE_IMAGE_LIST::GetImagesList(), GERBER_FILE_IMAGE::m_FileName, BOARD_PRINTOUT_SETTINGS::m_LayerSet, PRINTOUT_SETTINGS::m_pageCount, BOARD_PRINTOUT::m_settings, and LSET::UIOrder().

◆ setupGal()

void GERBVIEW_PRINTOUT::setupGal ( KIGFX::GAL aGal)
overrideprotectedvirtual

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

Reimplemented from BOARD_PRINTOUT.

Definition at line 91 of file gerbview_printout.cpp.

92{
94 aGal->SetWorldUnitLength( 1.0/IU_PER_MM /* 10 nm */ / 25.4 /* 1 inch in mm */ );
95}
void SetWorldUnitLength(double aWorldUnitLength)
Set the unit length.
static constexpr double IU_PER_MM
Mock up a conversion function.

References IU_PER_MM, BOARD_PRINTOUT::setupGal(), and KIGFX::GAL::SetWorldUnitLength().

◆ setupPainter()

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

Configures GAL object for a printout.

Reimplemented in PCBNEW_PRINTOUT.

Definition at line 210 of file board_printout.cpp.

211{
214}
virtual RENDER_SETTINGS * GetSettings()=0
Return a pointer to current settings that are going to be used when drawing items.
bool m_background
Print background color.
Definition: printout.h:62

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

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

◆ setupViewLayers()

void GERBVIEW_PRINTOUT::setupViewLayers ( KIGFX::VIEW aView,
const LSET aLayerSet 
)
overrideprotectedvirtual

Configures PAINTER object for a printout.

Reimplemented from BOARD_PRINTOUT.

Definition at line 82 of file gerbview_printout.cpp.

83{
84 BOARD_PRINTOUT::setupViewLayers( aView, aLayerSet );
85
86 for( LSEQ layerSeq = m_settings.m_LayerSet.Seq(); layerSeq; ++layerSeq )
87 aView.SetLayerVisible( GERBVIEW_LAYER_ID_START + *layerSeq, true );
88}
void SetLayerVisible(int aLayer, bool aVisible=true)
Control the visibility of a particular layer.
Definition: view.h:393
LSEQ Seq(const PCB_LAYER_ID *aWishListSequence, unsigned aCount) const
Return an LSEQ from the union of this LSET and a desired sequence.
Definition: lset.cpp:411
@ GERBVIEW_LAYER_ID_START
Definition: layer_ids.h:406

References GERBVIEW_LAYER_ID_START, BOARD_PRINTOUT_SETTINGS::m_LayerSet, BOARD_PRINTOUT::m_settings, LSET::Seq(), KIGFX::VIEW::SetLayerVisible(), and BOARD_PRINTOUT::setupViewLayers().

Member Data Documentation

◆ m_gerbviewPrint

bool BOARD_PRINTOUT::m_gerbviewPrint
protectedinherited

True if the caller is Gerbview, false for Pcbnew.

Definition at line 124 of file board_printout.h.

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

◆ m_layout

GBR_LAYOUT* GERBVIEW_PRINTOUT::m_layout
private

Definition at line 47 of file gerbview_printout.h.

Referenced by GERBVIEW_PRINTOUT(), and getBoundingBox().

◆ m_settings

◆ m_view

const KIGFX::VIEW* BOARD_PRINTOUT::m_view
protectedinherited

Printout parameters.

Definition at line 118 of file board_printout.h.

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


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