KiCad PCB EDA Suite
Loading...
Searching...
No Matches
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 The 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, see <https://www.gnu.org/licenses/>.
19 */
20
21#include <base_units.h>
22#include <base_screen.h>
24#include <gerbview_frame.h>
25#include <gerber_file_image.h>
27#include "gerbview_printout.h"
28
29#include <lseq.h>
30#include <lset.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 m_gerbviewPrint = true;
42}
43
44
46{
47 // Store the layerset, as it is going to be modified below and the original settings are needed
48 LSET lset = m_settings.m_LayerSet;
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
70 m_settings.m_LayerSet = lset;
71
72 return true;
73}
74
75
76int GERBVIEW_PRINTOUT::milsToIU( double aMils ) const
77{
78 return KiROUND( gerbIUScale.IU_PER_MILS * aMils );
79}
80
81
82void GERBVIEW_PRINTOUT::setupViewLayers( KIGFX::VIEW& aView, const LSET& aLayerSet )
83{
84 BOARD_PRINTOUT::setupViewLayers( aView, aLayerSet );
85
86 for( PCB_LAYER_ID layer : m_settings.m_LayerSet.Seq() )
87 aView.SetLayerVisible( static_cast<int>( GERBVIEW_LAYER_ID_START ) + layer, true );
88}
89
90
92{
94 aGal->SetWorldUnitLength( 1.0/ gerbIUScale.IU_PER_MM /* 10 nm */ / 25.4 /* 1 inch in mm */ );
95}
96
97
99{
100 return m_layout->ComputeBoundingBox();
101}
102
103
104std::unique_ptr<KIGFX::PAINTER> GERBVIEW_PRINTOUT::getPainter( KIGFX::GAL* aGal )
105{
106 return std::make_unique<KIGFX::GERBVIEW_PAINTER>( aGal );
107}
BASE_SCREEN class implementation.
constexpr EDA_IU_SCALE gerbIUScale
Definition base_units.h:120
BOX2< VECTOR2I > BOX2I
Definition box2.h:918
constexpr BOX2I KiROUND(const BOX2D &aBoxD)
Definition box2.h:986
virtual void DrawPage(const wxString &aLayerName=wxEmptyString, int aPageNum=1, int aPageCount=1)
Print a page (or a set of pages).
bool m_gerbviewPrint
True if the caller is Gerbview, false for Pcbnew.
virtual void setupViewLayers(KIGFX::VIEW &aView, const LSET &aLayerSet)
Enable layers visibility for a printout.
BOARD_PRINTOUT(const BOARD_PRINTOUT_SETTINGS &aParams, const KIGFX::VIEW *aView, const wxString &aTitle)
virtual void setupGal(KIGFX::GAL *aGal)
Configure GAL object for a printout.
BOARD_PRINTOUT_SETTINGS m_settings
Printout parameters.
A list of GERBER_DRAW_ITEM objects currently loaded.
Definition gbr_layout.h:42
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()
Hold the image data and parameters for one gerber file and layer parameters.
wxString m_FileName
Full File Name for this layer.
void setupGal(KIGFX::GAL *aGal) override
Configure GAL object for a printout.
std::unique_ptr< KIGFX::PAINTER > getPainter(KIGFX::GAL *aGal) override
Return the #PAINTER instance used to draw the items.
bool OnPrintPage(int aPage) override
int milsToIU(double aMils) const override
Convert mils to internal units.
void setupViewLayers(KIGFX::VIEW &aView, const LSET &aLayerSet) override
Enable layers visibility for a printout.
BOX2I getBoundingBox() override
Return bounding box of the printed objects (excluding drawing-sheet frame).
GERBVIEW_PRINTOUT(GBR_LAYOUT *aLayout, const BOARD_PRINTOUT_SETTINGS &aParams, const KIGFX::VIEW *aView, const wxString &aTitle)
Abstract interface for drawing on a 2D-surface.
void SetWorldUnitLength(double aWorldUnitLength)
Set the unit length.
Hold a (potentially large) number of VIEW_ITEMs and renders them on a graphics device provided by the...
Definition view.h:63
void SetLayerVisible(int aLayer, bool aVisible=true)
Control the visibility of a particular layer.
Definition view.h:405
LSEQ is a sequence (and therefore also a set) of PCB_LAYER_IDs.
Definition lseq.h:47
LSET is a set of PCB_LAYER_IDs.
Definition lset.h:37
LSEQ UIOrder() const
Return the copper, technical and user layers in the order shown in layer widget.
Definition lset.cpp:739
@ GERBVIEW_LAYER_ID_START
Definition layer_ids.h:522
PCB_LAYER_ID
A quick note on layer IDs:
Definition layer_ids.h:56