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 
25 #include <base_units.h>
26 #include <base_screen.h>
27 #include <gerbview_frame.h>
28 #include <gerber_file_image.h>
29 #include <gerber_file_image_list.h>
30 #include "gerbview_printout.h"
31 #include <view/view.h>
32 #include <gerbview_painter.h>
33 #include <math/util.h> // for KiROUND
34 
35 
37  const KIGFX::VIEW* aView, const wxString& aTitle ) :
38  BOARD_PRINTOUT( aParams, aView, aTitle )
39 {
40  m_layout = aLayout;
41 }
42 
43 
45 {
46  // Store the layerset, as it is going to be modified below and the original settings are needed
47  LSET lset = m_settings.m_LayerSet;
48 
49  LSEQ seq = lset.UIOrder();
50  wxCHECK( unsigned( aPage - 1 ) < seq.size(), false );
51  auto layerId = seq[aPage - 1];
52 
53  // In gerbview, draw layers are always printed on separate pages because handling negative
54  // objects when using only one page is tricky
55 
56  // Enable only one layer to create a printout
57  m_settings.m_LayerSet = LSET( layerId );
58 
60  GERBER_FILE_IMAGE* gbrImage = gbrImgList.GetGbrImage( layerId );
61  wxString gbr_filename;
62 
63  if( gbrImage )
64  gbr_filename = gbrImage->m_FileName;
65 
66  DrawPage( gbr_filename, aPage, m_settings.m_pageCount );
67 
68  // Restore the original layer set, so the next page can be printed
69  m_settings.m_LayerSet = lset;
70 
71  return true;
72 }
73 
74 
75 int GERBVIEW_PRINTOUT::milsToIU( double aMils ) const
76 {
77  return KiROUND( IU_PER_MILS * aMils );
78 }
79 
80 
81 void GERBVIEW_PRINTOUT::setupViewLayers( KIGFX::VIEW& aView, const LSET& aLayerSet )
82 {
83  BOARD_PRINTOUT::setupViewLayers( aView, aLayerSet );
84 
85  for( LSEQ layerSeq = m_settings.m_LayerSet.Seq(); layerSeq; ++layerSeq )
86  aView.SetLayerVisible( GERBVIEW_LAYER_ID_START + *layerSeq, true );
87 }
88 
89 
91 {
93  aGal->SetWorldUnitLength( 1.0/IU_PER_MM /* 10 nm */ / 25.4 /* 1 inch in mm */ );
94 }
95 
96 
98 {
99  return m_layout->ComputeBoundingBox();
100 }
101 
102 
103 std::unique_ptr<KIGFX::PAINTER> GERBVIEW_PRINTOUT::getPainter( KIGFX::GAL* aGal )
104 {
105  return std::make_unique<KIGFX::GERBVIEW_PAINTER>( aGal );
106 }
void setupGal(KIGFX::GAL *aGal) override
Returns bounding box of the printed objects (excluding drawing-sheet frame)
A list of GERBER_DRAW_ITEM objects currently loaded.
Definition: gbr_layout.h:45
Implementation of conversion functions that require both schematic and board internal units.
static constexpr double IU_PER_MM
Mock up a conversion function.
GBR_LAYOUT * m_layout
void setupViewLayers(KIGFX::VIEW &aView, const LSET &aLayerSet) override
Configures PAINTER object for a printout.
Hold the image data and parameters for one gerber file and layer parameters.
LSET m_LayerSet
Layers to print.
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...
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
BOARD_PRINTOUT_SETTINGS m_settings
std::unique_ptr< KIGFX::PAINTER > getPainter(KIGFX::GAL *aGal) override
Source VIEW object (note that actual printing only refers to this object)
LSET is a set of PCB_LAYER_IDs.
GERBER_FILE_IMAGE * GetGbrImage(int aIdx)
bool OnPrintPage(int aPage) override
virtual void setupGal(KIGFX::GAL *aGal)
Returns bounding box of the printed objects (excluding drawing-sheet frame)
static GERBER_FILE_IMAGE_LIST & GetImagesList()
void SetLayerVisible(int aLayer, bool aVisible=true)
Control the visibility of a particular layer.
Definition: view.h:387
EDA_RECT ComputeBoundingBox() const
Calculate the bounding box containing all Gerber items.
Definition: gbr_layout.cpp:47
void SetWorldUnitLength(double aWorldUnitLength)
Set the unit length.
LSEQ is a sequence (and therefore also a set) of PCB_LAYER_IDs.
virtual void setupViewLayers(KIGFX::VIEW &aView, const LSET &aLayerSet)
Configures PAINTER object for a printout.
GERBVIEW_PRINTOUT(GBR_LAYOUT *aLayout, const BOARD_PRINTOUT_SETTINGS &aParams, const KIGFX::VIEW *aView, const wxString &aTitle)
An object derived from wxPrintout to handle the necessary information to control a printer when print...
int m_pageCount
Number of pages to print.
Definition: printout.h:61
int milsToIU(double aMils) const override
< Convert mils to internal units
Handle the component boundary box.
Definition: eda_rect.h:42
#define IU_PER_MILS
Definition: plotter.cpp:137
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:68
EDA_RECT getBoundingBox() override
Returns a PAINTER instance used to draw the items.
Hold a (potentially large) number of VIEW_ITEMs and renders them on a graphics device provided by the...
Definition: view.h:67
BASE_SCREEN class implementation.
LSEQ UIOrder() const
Definition: lset.cpp:895
Abstract interface for drawing on a 2D-surface.