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 (C) 1992-2022 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>
28#include <gerbview_frame.h>
29#include <gerber_file_image.h>
31#include "gerbview_printout.h"
32#include <view/view.h>
33#include <gerbview_painter.h>
34#include <math/util.h> // for KiROUND
35
36
38 const KIGFX::VIEW* aView, const wxString& aTitle ) :
39 BOARD_PRINTOUT( aParams, aView, aTitle )
40{
41 m_layout = aLayout;
42 m_gerbviewPrint = true;
43}
44
45
47{
48 // Store the layerset, as it is going to be modified below and the original settings are needed
50
51 LSEQ seq = lset.UIOrder();
52 wxCHECK( unsigned( aPage - 1 ) < seq.size(), false );
53 auto layerId = seq[aPage - 1];
54
55 // In gerbview, draw layers are always printed on separate pages because handling negative
56 // objects when using only one page is tricky
57
58 // Enable only one layer to create a printout
59 m_settings.m_LayerSet = LSET( layerId );
60
62 GERBER_FILE_IMAGE* gbrImage = gbrImgList.GetGbrImage( layerId );
63 wxString gbr_filename;
64
65 if( gbrImage )
66 gbr_filename = gbrImage->m_FileName;
67
68 DrawPage( gbr_filename, aPage, m_settings.m_pageCount );
69
70 // Restore the original layer set, so the next page can be printed
72
73 return true;
74}
75
76
77int GERBVIEW_PRINTOUT::milsToIU( double aMils ) const
78{
79 return KiROUND( gerbIUScale.IU_PER_MILS * aMils );
80}
81
82
83void GERBVIEW_PRINTOUT::setupViewLayers( KIGFX::VIEW& aView, const LSET& aLayerSet )
84{
85 BOARD_PRINTOUT::setupViewLayers( aView, aLayerSet );
86
87 for( LSEQ layerSeq = m_settings.m_LayerSet.Seq(); layerSeq; ++layerSeq )
88 aView.SetLayerVisible( static_cast<int>( GERBVIEW_LAYER_ID_START ) + *layerSeq, true );
89}
90
91
93{
95 aGal->SetWorldUnitLength( 1.0/ gerbIUScale.IU_PER_MM /* 10 nm */ / 25.4 /* 1 inch in mm */ );
96}
97
98
100{
102}
103
104
105std::unique_ptr<KIGFX::PAINTER> GERBVIEW_PRINTOUT::getPainter( KIGFX::GAL* aGal )
106{
107 return std::make_unique<KIGFX::GERBVIEW_PAINTER>( aGal );
108}
BASE_SCREEN class implementation.
constexpr EDA_IU_SCALE gerbIUScale
Definition: base_units.h:107
An object derived from wxPrintout to handle the necessary information to control a printer when print...
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)
Configures PAINTER object for a printout.
virtual void setupGal(KIGFX::GAL *aGal)
Returns bounding box of the printed objects (excluding drawing-sheet frame)
BOARD_PRINTOUT_SETTINGS m_settings
A list of GERBER_DRAW_ITEM objects currently loaded.
Definition: gbr_layout.h:46
BOX2I ComputeBoundingBox() const
Calculate the bounding box containing all Gerber items.
Definition: gbr_layout.cpp:47
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.
wxString m_FileName
Full File Name for this layer.
void setupGal(KIGFX::GAL *aGal) override
Returns bounding box of the printed objects (excluding drawing-sheet frame)
std::unique_ptr< KIGFX::PAINTER > getPainter(KIGFX::GAL *aGal) override
Source VIEW object (note that actual printing only refers to this object)
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
Configures PAINTER object for a printout.
BOX2I getBoundingBox() override
Returns a PAINTER instance used to draw the items.
GERBVIEW_PRINTOUT(GBR_LAYOUT *aLayout, const BOARD_PRINTOUT_SETTINGS &aParams, const KIGFX::VIEW *aView, const wxString &aTitle)
GBR_LAYOUT * m_layout
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:68
void SetLayerVisible(int aLayer, bool aVisible=true)
Control the visibility of a particular layer.
Definition: view.h:395
LSEQ is a sequence (and therefore also a set) of PCB_LAYER_IDs.
Definition: layer_ids.h:520
LSET is a set of PCB_LAYER_IDs.
Definition: layer_ids.h:574
LSEQ UIOrder() const
Definition: lset.cpp:1012
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:418
@ GERBVIEW_LAYER_ID_START
Definition: layer_ids.h:422
LSET m_LayerSet
Layers to print.
const double IU_PER_MM
Definition: base_units.h:76
const double IU_PER_MILS
Definition: base_units.h:77
int m_pageCount
Number of pages to print.
Definition: printout.h:61
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:118