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 (const std::unique_ptr< KIGFX::VIEW > &aView, const LSET &aLayerSet) override
 

Enables layers visibility for a printout

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

Configures GAL object for a printout

More...
 
EDA_RECT getBoundingBox () override
 

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

More...
 
std::unique_ptr< KIGFX::PAINTERgetPainter (KIGFX::GAL *aGal) override
 

Returns a PAINTER instance used to draw the items.

More...
 
virtual void setupPainter (const std::unique_ptr< KIGFX::PAINTER > &aPainter)
 

Configures PAINTER object for a printout

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...
 

Private Attributes

GBR_LAYOUTm_layout
 

Detailed Description

Definition at line 27 of file gerbview_printout.h.

Constructor & Destructor Documentation

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

Definition at line 49 of file gerbview_printout.cpp.

References m_layout.

50  :
51  BOARD_PRINTOUT( aParams, aView, aTitle )
52 {
53  m_layout = aLayout;
54 }
GBR_LAYOUT * m_layout
BOARD_PRINTOUT(const BOARD_PRINTOUT_SETTINGS &aParams, const KIGFX::VIEW *aView, const wxString &aTitle)

Member Function Documentation

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

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

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

88 {
89  auto dc = GetDC();
91  auto galPrint = KIGFX::GAL_PRINT::Create( options, dc );
92  auto gal = galPrint->GetGAL();
93  auto printCtx = galPrint->GetPrintCtx();
94  auto 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  galPrint->SetSheetSize( pageSizeIn );
102  const VECTOR2D pageSizeIU( milsToIU( pageSizeIn.x * 1000 ), milsToIU( pageSizeIn.y * 1000 ) );
103 
104  view->SetGAL( gal );
105  view->SetPainter( painter.get() );
106  view->SetScaleLimits( 10e9, 0.0001 );
107  view->SetScale( 1.0 );
108 
109 
110  // Set the color scheme
111  auto srcSettings = m_view->GetPainter()->GetSettings();
112  auto dstSettings = view->GetPainter()->GetSettings();
113 
115  {
116  for( int i = 0; i < LAYER_ID_COUNT; ++i )
117  dstSettings->SetLayerColor( i, COLOR4D::BLACK );
118  }
119  else // color enabled
120  {
121  for( int i = 0; i < LAYER_ID_COUNT; ++i )
122  {
123  // Cairo does not support translucent colors on PostScript surfaces
124  // see 'Features support by the PostScript surface' on
125  // ttps://www.cairographics.org/documentation/using_the_postscript_surface/
126  dstSettings->SetLayerColor( i, srcSettings->GetLayerColor( i ).WithAlpha( 1.0 ) );
127  }
128  }
129 
130 
132  setupPainter( painter );
133 
134  auto sheetSizeMils = m_settings.m_pageInfo.GetSizeMils();
135  VECTOR2I sheetSizeIU( milsToIU( sheetSizeMils.GetWidth() ), milsToIU( sheetSizeMils.GetHeight() ) );
136  BOX2I bBox;
137 
138  // Determine printout bounding box
140  {
141  bBox = BOX2I( VECTOR2I( 0, 0 ), VECTOR2I( sheetSizeIU ) );
142  view->SetLayerVisible( LAYER_WORKSHEET, true );
143  }
144  else
145  {
146  EDA_RECT targetBbox = getBoundingBox();
147  bBox = BOX2I( targetBbox.GetOrigin(), targetBbox.GetSize() );
148  view->SetLayerVisible( LAYER_WORKSHEET, false );
149  }
150 
151 
152  // Fit to page
153  if( m_settings.m_scale <= 0.0 )
154  {
155  if( bBox.GetWidth() == 0 || bBox.GetHeight() == 0 )
156  {
157  // Nothing to print
158  m_settings.m_scale = 1.0;
159  }
160  else
161  {
162  double scaleX = (double) pageSizeIU.x / bBox.GetWidth();
163  double scaleY = (double) pageSizeIU.y / bBox.GetHeight();
164  m_settings.m_scale = std::min( scaleX, scaleY );
165  }
166  }
167 
168  setupGal( gal );
169  galPrint->SetNativePaperSize( pageSizeIn, printCtx->HasNativeLandscapeRotation() );
170  gal->SetLookAtPoint( bBox.Centre() );
171  gal->SetZoomFactor( m_settings.m_scale );
172 
173  {
174  KIGFX::GAL_DRAWING_CONTEXT ctx( gal );
175  view->Redraw();
176  }
177 }
BOX2< VECTOR2I > BOX2I
Definition: box2.h:520
const PAGE_INFO & m_pageInfo
Definition: printout.h:48
const wxPoint GetOrigin() const
Definition: eda_rect.h:112
virtual std::unique_ptr< KIGFX::PAINTER > getPainter(KIGFX::GAL *aGal)=0
Returns a PAINTER instance used to draw the items.
const wxSize GetSize() const
Definition: eda_rect.h:101
const KIGFX::VIEW * m_view
Source VIEW object (note that actual printing only refers to this object)
VECTOR2< int > VECTOR2I
Definition: vector2d.h:587
BOARD_PRINTOUT_SETTINGS m_settings
Printout parameters
const wxSize & GetSizeMils() const
Definition: page_info.h:142
double m_scale
Printing scale.
Definition: printout.h:44
coord_type GetWidth() const
Definition: box2.h:195
bool PrintBorderAndTitleBlock() const
Returns true if the drawing border and title block should be printed.
Definition: printout.h:56
virtual int milsToIU(double aMils) const =0
Convert mils to internal units
virtual void setupGal(KIGFX::GAL *aGal)
Configures GAL object for a printout
void SetLayerColor(int aLayer, const COLOR4D &aColor)
Function SetLayerColor Changes the color used to draw a layer.
Definition: painter.h:230
PAINTER * GetPainter() const
Function GetPainter() Returns the painter object used by the view for drawing VIEW_ITEMS.
Definition: view.h:199
virtual void setupPainter(const std::unique_ptr< KIGFX::PAINTER > &aPainter)
Configures PAINTER object for a printout
#define LAYER_ID_COUNT
Must update this if you add any enums after GerbView!
Vec Centre() const
Definition: box2.h:77
std::unique_ptr< VIEW > DataReference() const
Returns a new VIEW object that shares the same set of VIEW_ITEMs and LAYERs.
Definition: view.cpp:1457
bool m_blackWhite
Print in B&W or Color.
Definition: printout.h:46
coord_type GetHeight() const
Definition: box2.h:196
virtual RENDER_SETTINGS * GetSettings()=0
Function GetSettings Returns pointer to current settings that are going to be used when drawing items...
virtual void setupViewLayers(const std::unique_ptr< KIGFX::VIEW > &aView, const LSET &aLayerSet)
Enables layers visibility for a printout
size_t i
Definition: json11.cpp:597
Class EDA_RECT handles the component boundary box.
Definition: eda_rect.h:44
Definition: colors.h:45
virtual EDA_RECT getBoundingBox()=0
Returns bounding box of the printed objects (excluding worksheet frame)
LSET m_layerSet
Layers to print.
#define min(a, b)
Definition: auxiliary.h:85
EDA_RECT GERBVIEW_PRINTOUT::getBoundingBox ( )
overrideprotectedvirtual

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

Implements BOARD_PRINTOUT.

Definition at line 114 of file gerbview_printout.cpp.

References GBR_LAYOUT::ComputeBoundingBox(), and m_layout.

115 {
116  return m_layout->ComputeBoundingBox();
117 }
GBR_LAYOUT * m_layout
EDA_RECT ComputeBoundingBox() const
Function ComputeBoundingBox calculates the bounding box containing all Gerber items.
Definition: gbr_layout.cpp:56
void BOARD_PRINTOUT::GetPageInfo ( int *  minPage,
int *  maxPage,
int *  selPageFrom,
int *  selPageTo 
)
overrideinherited

Definition at line 77 of file board_printout.cpp.

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

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
Printout parameters
int m_pageCount
Number of pages to print.
Definition: printout.h:47
std::unique_ptr< KIGFX::PAINTER > GERBVIEW_PRINTOUT::getPainter ( KIGFX::GAL aGal)
overrideprotectedvirtual

Returns a PAINTER instance used to draw the items.

Implements BOARD_PRINTOUT.

Definition at line 120 of file gerbview_printout.cpp.

121 {
122  return std::unique_ptr<KIGFX::PAINTER>( new KIGFX::GERBVIEW_PAINTER( aGal ) );
123 }
Class GERBVIEW_PAINTER Contains methods for drawing GerbView-specific items.
bool BOARD_PRINTOUT::HasPage ( int  aPage)
inlineoverrideinherited

Definition at line 74 of file board_printout.h.

75  {
76  return aPage <= m_settings.m_pageCount;
77  }
BOARD_PRINTOUT_SETTINGS m_settings
Printout parameters
int m_pageCount
Number of pages to print.
Definition: printout.h:47
int GERBVIEW_PRINTOUT::milsToIU ( double  aMils) const
overrideprotectedvirtual

Convert mils to internal units

Implements BOARD_PRINTOUT.

Definition at line 91 of file gerbview_printout.cpp.

References IU_PER_MILS, and KiROUND().

92 {
93  return KiROUND( IU_PER_MILS * aMils );
94 }
static int KiROUND(double v)
Round a floating point number to an integer using "round halfway cases away from zero".
Definition: common.h:120
#define IU_PER_MILS
Definition: plotter.cpp:134
bool GERBVIEW_PRINTOUT::OnPrintPage ( int  aPage)
override

Definition at line 57 of file gerbview_printout.cpp.

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().

58 {
59  // Store the layerset, as it is going to be modified below and the original settings are needed
60  LSET lset = m_settings.m_layerSet;
61 
62  // The gerber filename of the page to print will be printed to the worksheet.
63  // Find this filename:
64  // Find the graphic layer number for the page to print
65  LSEQ seq = lset.UIOrder();
66  wxCHECK( unsigned( aPage - 1 ) < seq.size(), false );
67  auto layerId = seq[aPage - 1];
68 
69  // In gerbview, draw layers are always printed on separate pages
70  // because handling negative objects when using only one page is tricky
71 
72  // Enable only one layer to create a printout
73  m_settings.m_layerSet = LSET( layerId );
74 
76  GERBER_FILE_IMAGE* gbrImage = gbrImgList.GetGbrImage( layerId );
77  wxString gbr_filename;
78 
79  if( gbrImage )
80  gbr_filename = gbrImage->m_FileName;
81 
82  DrawPage( gbr_filename, aPage, m_settings.m_pageCount );
83 
84  // Restore the original layer set, so the next page can be printed
85  m_settings.m_layerSet = lset;
86 
87  return true;
88 }
Class GERBER_FILE_IMAGE holds the Image data and parameters for one gerber file and layer parameters ...
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...
BOARD_PRINTOUT_SETTINGS m_settings
Printout parameters
Class LSET is a set of PCB_LAYER_IDs.
GERBER_FILE_IMAGE * GetGbrImage(int aIdx)
static GERBER_FILE_IMAGE_LIST & GetImagesList()
Class LSEQ is a sequence (and therefore also a set) of PCB_LAYER_IDs.
int m_pageCount
Number of pages to print.
Definition: printout.h:47
LSET m_layerSet
Layers to print.
LSEQ UIOrder() const
Definition: lset.cpp:800
void GERBVIEW_PRINTOUT::setupGal ( KIGFX::GAL aGal)
overrideprotectedvirtual

Configures GAL object for a printout

Reimplemented from BOARD_PRINTOUT.

Definition at line 107 of file gerbview_printout.cpp.

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

108 {
109  BOARD_PRINTOUT::setupGal( aGal );
110  aGal->SetWorldUnitLength( 10e-9 /* 10 nm */ / 0.0254 /* 1 inch in meters */ );
111 }
virtual void setupGal(KIGFX::GAL *aGal)
Configures GAL object for a printout
void SetWorldUnitLength(double aWorldUnitLength)
Set the unit length.
void BOARD_PRINTOUT::setupPainter ( const std::unique_ptr< KIGFX::PAINTER > &  aPainter)
protectedvirtualinherited

Configures PAINTER object for a printout

Reimplemented in PCBNEW_PRINTOUT.

Definition at line 193 of file board_printout.cpp.

References WHITE.

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

194 {
195  aPainter->GetSettings()->SetBackgroundColor( COLOR4D::WHITE );
196 }
Definition: colors.h:49
void GERBVIEW_PRINTOUT::setupViewLayers ( const std::unique_ptr< KIGFX::VIEW > &  aView,
const LSET aLayerSet 
)
overrideprotectedvirtual

Enables layers visibility for a printout

Reimplemented from BOARD_PRINTOUT.

Definition at line 97 of file gerbview_printout.cpp.

References GERBVIEW_LAYER_ID_START, BOARD_PRINTOUT_SETTINGS::m_layerSet, BOARD_PRINTOUT::m_settings, LSET::Seq(), and BOARD_PRINTOUT::setupViewLayers().

99 {
100  BOARD_PRINTOUT::setupViewLayers( aView, aLayerSet );
101 
102  for( LSEQ layerSeq = m_settings.m_layerSet.Seq(); layerSeq; ++layerSeq )
103  aView->SetLayerVisible( GERBVIEW_LAYER_ID_START + *layerSeq, true );
104 }
BOARD_PRINTOUT_SETTINGS m_settings
Printout parameters
LSEQ Seq(const PCB_LAYER_ID *aWishListSequence, unsigned aCount) const
Function Seq returns an LSEQ from the union of this LSET and a desired sequence.
Definition: lset.cpp:364
Class LSEQ is a sequence (and therefore also a set) of PCB_LAYER_IDs.
virtual void setupViewLayers(const std::unique_ptr< KIGFX::VIEW > &aView, const LSET &aLayerSet)
Enables layers visibility for a printout
LSET m_layerSet
Layers to print.

Member Data Documentation

GBR_LAYOUT* GERBVIEW_PRINTOUT::m_layout
private

Definition at line 47 of file gerbview_printout.h.

Referenced by GERBVIEW_PRINTOUT(), and getBoundingBox().

const KIGFX::VIEW* BOARD_PRINTOUT::m_view
protectedinherited

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

Definition at line 110 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: