KiCad PCB EDA Suite
gerbview_printout.cpp
Go to the documentation of this file.
1 /*
2  * This program source code file is part of KiCad, a free EDA CAD application.
3  *
4  * Copyright (C) 2016 Jean-Pierre Charras, jp.charras at wanadoo.fr
5  * Copyright (C) 1992-2016 KiCad Developers, see AUTHORS.txt for contributors.
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, you may find one here:
19  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
20  * or you may search the http://www.gnu.org website for the version 2 license,
21  * or you may write to the Free Software Foundation, Inc.,
22  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
23  */
24 
31 #include <fctsys.h>
32 #include <pgm_base.h>
33 #include <gr_basic.h>
34 #include <class_drawpanel.h>
35 #include <base_units.h>
36 #include <base_screen.h>
37 
38 #include <gerbview_frame.h>
39 #include <gerber_file_image.h>
40 #include <gerber_file_image_list.h>
41 
42 #include "gerbview_printout.h"
43 
44 #include <gal/gal_print.h>
45 #include <view/view.h>
46 #include <gerbview_painter.h>
47 
48 
50  const KIGFX::VIEW* aView, const wxString& aTitle ) :
51  BOARD_PRINTOUT( aParams, aView, aTitle )
52 {
53  m_layout = aLayout;
54 }
55 
56 
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 }
89 
90 
91 int GERBVIEW_PRINTOUT::milsToIU( double aMils ) const
92 {
93  return KiROUND( IU_PER_MILS * aMils );
94 }
95 
96 
97 void GERBVIEW_PRINTOUT::setupViewLayers( const std::unique_ptr<KIGFX::VIEW>& aView,
98  const LSET& aLayerSet )
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 }
105 
106 
108 {
109  BOARD_PRINTOUT::setupGal( aGal );
110  aGal->SetWorldUnitLength( 1.0/IU_PER_MM /* 10 nm */ / 25.4 /* 1 inch in mm */ );
111 }
112 
113 
115 {
116  return m_layout->ComputeBoundingBox();
117 }
118 
119 
120 std::unique_ptr<KIGFX::PAINTER> GERBVIEW_PRINTOUT::getPainter( KIGFX::GAL* aGal )
121 {
122  return std::unique_ptr<KIGFX::PAINTER>( new KIGFX::GERBVIEW_PAINTER( aGal ) );
123 }
void setupGal(KIGFX::GAL *aGal) override
Configures GAL object for a printout
Class GBR_LAYOUT holds list of GERBER_DRAW_ITEM currently loaded.
Definition: gbr_layout.h:53
static int KiROUND(double v)
Round a floating point number to an integer using "round halfway cases away from zero".
Definition: common.h:120
Implementation of conversion functions that require both schematic and board internal units...
GBR_LAYOUT * m_layout
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...
EDA_RECT ComputeBoundingBox() const
Function ComputeBoundingBox calculates the bounding box containing all Gerber items.
Definition: gbr_layout.cpp:56
BOARD_PRINTOUT_SETTINGS m_settings
Printout parameters
std::unique_ptr< KIGFX::PAINTER > getPainter(KIGFX::GAL *aGal) override
Returns a PAINTER instance used to draw the items.
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 LSET is a set of PCB_LAYER_IDs.
GERBER_FILE_IMAGE * GetGbrImage(int aIdx)
Class GERBVIEW_PAINTER Contains methods for drawing GerbView-specific items.
bool OnPrintPage(int aPage) override
virtual void setupGal(KIGFX::GAL *aGal)
Configures GAL object for a printout
static GERBER_FILE_IMAGE_LIST & GetImagesList()
void SetWorldUnitLength(double aWorldUnitLength)
Set the unit length.
Class LSEQ is a sequence (and therefore also a set) of PCB_LAYER_IDs.
void setupViewLayers(const std::unique_ptr< KIGFX::VIEW > &aView, const LSET &aLayerSet) override
Enables layers visibility for a printout
GERBVIEW_PRINTOUT(GBR_LAYOUT *aLayout, const BOARD_PRINTOUT_SETTINGS &aParams, const KIGFX::VIEW *aView, const wxString &aTitle)
see class PGM_BASE
virtual void setupViewLayers(const std::unique_ptr< KIGFX::VIEW > &aView, const LSET &aLayerSet)
Enables layers visibility for a printout
Class BOARD_PRINTOUT is a class derived from wxPrintout to handle the necessary information to contro...
int m_pageCount
Number of pages to print.
Definition: printout.h:47
int milsToIU(double aMils) const override
Convert mils to internal units
Class EDA_RECT handles the component boundary box.
Definition: eda_rect.h:44
#define IU_PER_MILS
Definition: plotter.cpp:134
EDA_RECT getBoundingBox() override
Returns bounding box of the printed objects (excluding worksheet frame)
Class VIEW.
Definition: view.h:61
BASE_SCREEN class implementation.
LSET m_layerSet
Layers to print.
Class GAL is the abstract interface for drawing on a 2D-surface.
LSEQ UIOrder() const
Definition: lset.cpp:800