KiCad PCB EDA Suite
Loading...
Searching...
No Matches
pcb_plot_svg.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) 2012 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 modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation, either version 3 of the License, or (at your
10 * option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License along
18 * with this program. If not, see <http://www.gnu.org/licenses/>.
19 */
20
21#include <board.h>
23#include <locale_io.h>
24#include <pcbnew_settings.h>
25#include <pcb_plot_params.h>
26#include <pcb_plot_svg.h>
27#include <pcbplot.h>
28#include <pgm_base.h>
30
31
32bool PCB_PLOT_SVG::Plot( BOARD* aBoard, const PCB_PLOT_SVG_OPTIONS& aSvgPlotOptions )
33{
34 PCB_PLOT_PARAMS plot_opts;
35 wxString outputFile = aSvgPlotOptions.m_outputFile;
36
37 plot_opts.SetPlotFrameRef( aSvgPlotOptions.m_plotFrame );
38
39 // Adding drill marks, for copper layers
40 if( ( aSvgPlotOptions.m_printMaskLayer & LSET::AllCuMask() ).any() )
41 plot_opts.SetDrillMarksType( DRILL_MARKS::FULL_DRILL_SHAPE );
42 else
43 plot_opts.SetDrillMarksType( DRILL_MARKS::NO_DRILL_SHAPE );
44
45 plot_opts.SetSkipPlotNPTH_Pads( false );
46
47 plot_opts.SetMirror( aSvgPlotOptions.m_mirror );
48 plot_opts.SetNegative( aSvgPlotOptions.m_negative );
49 plot_opts.SetFormat( PLOT_FORMAT::SVG );
50 // coord format: 4 digits in mantissa (units always in mm). This is a good choice.
51 plot_opts.SetSvgPrecision( 4 );
52
53 PAGE_INFO savedPageInfo = aBoard->GetPageSettings();
54 VECTOR2I savedAuxOrigin = aBoard->GetDesignSettings().GetAuxOrigin();
55
56 if( aSvgPlotOptions.m_pageSizeMode == 2 ) // Page is board boundary size
57 {
58 BOX2I bbox = aBoard->ComputeBoundingBox();
59 PAGE_INFO currpageInfo = aBoard->GetPageSettings();
60
61 currpageInfo.SetWidthMils( bbox.GetWidth() / pcbIUScale.IU_PER_MILS );
62 currpageInfo.SetHeightMils( bbox.GetHeight() / pcbIUScale.IU_PER_MILS );
63 aBoard->SetPageSettings( currpageInfo );
64 plot_opts.SetUseAuxOrigin( true );
65 VECTOR2I origin = bbox.GetOrigin();
66 aBoard->GetDesignSettings().SetAuxOrigin( origin );
67 }
68
69 if( outputFile.IsEmpty() )
70 {
71 wxFileName fn = aBoard->GetFileName();
72 fn.SetName( fn.GetName() );
73 fn.SetExt( wxS("svg") );
74
75 outputFile = fn.GetFullName();
76 }
77
78 SETTINGS_MANAGER& mgr = Pgm().GetSettingsManager();
79
80 plot_opts.SetColorSettings( mgr.GetColorSettings( aSvgPlotOptions.m_colorTheme ) );
81
82 LOCALE_IO toggle;
83
84 //@todo allow controlling the sheet name and path that will be displayed in the title block
85 // Leave blank for now
86 SVG_PLOTTER* plotter = (SVG_PLOTTER*) StartPlotBoard( aBoard, &plot_opts, UNDEFINED_LAYER, outputFile,
87 wxEmptyString, wxEmptyString );
88
89 if( plotter )
90 {
91 plotter->SetColorMode( !aSvgPlotOptions.m_blackAndWhite );
92 PlotBoardLayers( aBoard, plotter, aSvgPlotOptions.m_printMaskLayer.SeqStackupBottom2Top(),
93 plot_opts );
94 plotter->EndPlot();
95 }
96
97 delete plotter;
98
99 // reset to the values saved earlier
100 aBoard->GetDesignSettings().SetAuxOrigin( savedAuxOrigin );
101 aBoard->SetPageSettings( savedPageInfo );
102
103 return true;
104}
constexpr EDA_IU_SCALE pcbIUScale
Definition: base_units.h:109
const VECTOR2I & GetAuxOrigin()
void SetAuxOrigin(const VECTOR2I &aOrigin)
Information pertinent to a Pcbnew printed circuit board.
Definition: board.h:270
const PAGE_INFO & GetPageSettings() const
Definition: board.h:638
BOX2I ComputeBoundingBox(bool aBoardEdgesOnly=false) const
Calculate the bounding box containing all board items (or board edge segments).
Definition: board.cpp:1303
void SetPageSettings(const PAGE_INFO &aPageSettings)
Definition: board.h:639
const wxString & GetFileName() const
Definition: board.h:307
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Definition: board.cpp:728
const Vec & GetOrigin() const
Definition: box2.h:184
coord_type GetHeight() const
Definition: box2.h:189
coord_type GetWidth() const
Definition: box2.h:188
Instantiate the current locale within a scope in which you are expecting exceptions to be thrown.
Definition: locale_io.h:41
LSEQ SeqStackupBottom2Top() const
Return the sequence that is typical for a bottom-to-top stack-up.
Definition: lset.cpp:475
static LSET AllCuMask(int aCuLayerCount=MAX_CU_LAYERS)
Return a mask holding the requested number of Cu PCB_LAYER_IDs.
Definition: lset.cpp:773
Describe the page size and margins of a paper page on which to eventually print or plot.
Definition: page_info.h:54
void SetWidthMils(int aWidthInMils)
Definition: page_info.cpp:245
void SetHeightMils(int aHeightInMils)
Definition: page_info.cpp:259
Parameters and options when plotting/printing a board.
void SetDrillMarksType(DRILL_MARKS aVal)
void SetSkipPlotNPTH_Pads(bool aSkip)
void SetPlotFrameRef(bool aFlag)
void SetMirror(bool aFlag)
void SetColorSettings(COLOR_SETTINGS *aSettings)
void SetNegative(bool aFlag)
void SetUseAuxOrigin(bool aAux)
void SetSvgPrecision(unsigned aPrecision)
void SetFormat(PLOT_FORMAT aFormat)
static bool Plot(BOARD *aBoard, const PCB_PLOT_SVG_OPTIONS &aSvgPlotOptions)
virtual void SetColorMode(bool aColorMode)
Plot in B/W or color.
Definition: plotter.h:137
COLOR_SETTINGS * GetColorSettings(const wxString &aName="user")
Retrieves a color settings object that applications can read colors from.
virtual bool EndPlot() override
@ UNDEFINED_LAYER
Definition: layer_ids.h:60
PLOTTER * StartPlotBoard(BOARD *aBoard, const PCB_PLOT_PARAMS *aPlotOpts, int aLayer, const wxString &aFullFileName, const wxString &aSheetName, const wxString &aSheetPath)
Open a new plotfile using the options (and especially the format) specified in the options and prepar...
void PlotBoardLayers(BOARD *aBoard, PLOTTER *aPlotter, const LSEQ &aLayerSequence, const PCB_PLOT_PARAMS &aPlotOptions)
Plot a sequence of board layer IDs.
see class PGM_BASE
Plotting engines similar to ps (PostScript, Gerber, svg)
KIWAY Kiway & Pgm(), KFCTL_STANDALONE
The global Program "get" accessor.
Definition: single_top.cpp:115
const double IU_PER_MILS
Definition: base_units.h:78