KiCad PCB EDA Suite
Loading...
Searching...
No Matches
export_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-2023 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"
22#include "locale_io.h"
23#include "export_svg.h"
24#include "pcbplot.h"
25#include "pgm_base.h"
27
28
29bool EXPORT_SVG::Plot( BOARD* aBoard, const PCB_PLOT_SVG_OPTIONS& aSvgPlotOptions )
30{
31 PCB_PLOT_PARAMS plot_opts;
32 wxString outputFile = aSvgPlotOptions.m_outputFile;
33
34 plot_opts.SetPlotFrameRef( aSvgPlotOptions.m_plotFrame );
35
36 if( aSvgPlotOptions.m_sketchPadsOnFabLayers )
37 {
38 plot_opts.SetSketchPadsOnFabLayers( true );
39 plot_opts.SetPlotPadNumbers( true );
40 }
41
42 // Adding drill marks, for copper layers
43 if( ( LSET( aSvgPlotOptions.m_printMaskLayer ) & LSET::AllCuMask() ).any() )
44 {
45 switch( aSvgPlotOptions.m_drillShapeOption )
46 {
47 default:
48 case 0: plot_opts.SetDrillMarksType( DRILL_MARKS::NO_DRILL_SHAPE ); break;
49 case 1: plot_opts.SetDrillMarksType( DRILL_MARKS::SMALL_DRILL_SHAPE ); break;
50 case 2: plot_opts.SetDrillMarksType( DRILL_MARKS::FULL_DRILL_SHAPE ); break;
51 }
52 }
53 else
54 {
55 plot_opts.SetDrillMarksType( DRILL_MARKS::NO_DRILL_SHAPE );
56 }
57
58 plot_opts.SetSkipPlotNPTH_Pads( false );
59
60 plot_opts.SetMirror( aSvgPlotOptions.m_mirror );
61 plot_opts.SetNegative( aSvgPlotOptions.m_negative );
62 plot_opts.SetFormat( PLOT_FORMAT::SVG );
63 // coord format: 4 digits in mantissa (units always in mm). This is a good choice.
64 plot_opts.SetSvgPrecision( 4 );
65
66 PAGE_INFO savedPageInfo = aBoard->GetPageSettings();
67 VECTOR2I savedAuxOrigin = aBoard->GetDesignSettings().GetAuxOrigin();
68
69 if( aSvgPlotOptions.m_pageSizeMode == 2 ) // Page is board boundary size
70 {
71 BOX2I bbox = aBoard->ComputeBoundingBox( false, false );
72 PAGE_INFO currpageInfo = aBoard->GetPageSettings();
73
74 currpageInfo.SetWidthMils( bbox.GetWidth() / pcbIUScale.IU_PER_MILS );
75 currpageInfo.SetHeightMils( bbox.GetHeight() / pcbIUScale.IU_PER_MILS );
76 aBoard->SetPageSettings( currpageInfo );
77 plot_opts.SetUseAuxOrigin( true );
78 VECTOR2I origin = bbox.GetOrigin();
79 aBoard->GetDesignSettings().SetAuxOrigin( origin );
80 }
81
82 if( outputFile.IsEmpty() )
83 {
84 wxFileName fn = aBoard->GetFileName();
85 fn.SetName( fn.GetName() );
86 fn.SetExt( wxS( "svg" ) );
87
88 outputFile = fn.GetFullName();
89 }
90
92
93 plot_opts.SetColorSettings( mgr.GetColorSettings( aSvgPlotOptions.m_colorTheme ) );
94
95 LOCALE_IO toggle;
97 wxString layerName;
98 //@todo allow controlling the sheet name and path that will be displayed in the title block
99 // Leave blank for now
100 wxString sheetName;
101 wxString sheetPath;
102
103 if( aSvgPlotOptions.m_printMaskLayer.size() == 1 )
104 {
105 layer = aSvgPlotOptions.m_printMaskLayer.front();
106 layerName = aBoard->GetLayerName( layer );
107 }
108
109 SVG_PLOTTER* plotter = (SVG_PLOTTER*) StartPlotBoard( aBoard, &plot_opts, layer, layerName,
110 outputFile, sheetName, sheetPath );
111
112 if( plotter )
113 {
114 plotter->SetColorMode( !aSvgPlotOptions.m_blackAndWhite );
115 PlotBoardLayers( aBoard, plotter, aSvgPlotOptions.m_printMaskLayer, plot_opts );
116 plotter->EndPlot();
117 }
118
119 delete plotter;
120
121 // reset to the values saved earlier
122 aBoard->GetDesignSettings().SetAuxOrigin( savedAuxOrigin );
123 aBoard->SetPageSettings( savedPageInfo );
124
125 return true;
126}
constexpr EDA_IU_SCALE pcbIUScale
Definition: base_units.h:108
const VECTOR2I & GetAuxOrigin()
void SetAuxOrigin(const VECTOR2I &aOrigin)
Information pertinent to a Pcbnew printed circuit board.
Definition: board.h:289
const PAGE_INFO & GetPageSettings() const
Definition: board.h:682
BOX2I ComputeBoundingBox(bool aBoardEdgesOnly=false, bool aIncludeHiddenText=false) const
Calculate the bounding box containing all board items (or board edge segments).
Definition: board.cpp:1652
void SetPageSettings(const PAGE_INFO &aPageSettings)
Definition: board.h:683
const wxString & GetFileName() const
Definition: board.h:326
const wxString GetLayerName(PCB_LAYER_ID aLayer) const
Return the name of a aLayer.
Definition: board.cpp:575
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Definition: board.cpp:874
const Vec & GetOrigin() const
Definition: box2.h:200
size_type GetHeight() const
Definition: box2.h:205
size_type GetWidth() const
Definition: box2.h:204
static bool Plot(BOARD *aBoard, const PCB_PLOT_SVG_OPTIONS &aSvgPlotOptions)
Definition: export_svg.cpp:29
Instantiate the current locale within a scope in which you are expecting exceptions to be thrown.
Definition: locale_io.h:49
LSET is a set of PCB_LAYER_IDs.
Definition: lset.h:35
static LSET AllCuMask(int aCuLayerCount=MAX_CU_LAYERS)
Return a mask holding the requested number of Cu PCB_LAYER_IDs.
Definition: lset.cpp:732
Describe the page size and margins of a paper page on which to eventually print or plot.
Definition: page_info.h:59
void SetHeightMils(double aHeightInMils)
Definition: page_info.cpp:261
void SetWidthMils(double aWidthInMils)
Definition: page_info.cpp:247
Parameters and options when plotting/printing a board.
void SetDrillMarksType(DRILL_MARKS aVal)
void SetSkipPlotNPTH_Pads(bool aSkip)
void SetSketchPadsOnFabLayers(bool aFlag)
void SetPlotFrameRef(bool aFlag)
void SetPlotPadNumbers(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)
virtual SETTINGS_MANAGER & GetSettingsManager() const
Definition: pgm_base.h:142
virtual void SetColorMode(bool aColorMode)
Plot in B/W or color.
Definition: plotter.h:132
COLOR_SETTINGS * GetColorSettings(const wxString &aName="user")
Retrieves a color settings object that applications can read colors from.
virtual bool EndPlot() override
PCB_LAYER_ID
A quick note on layer IDs:
Definition: layer_ids.h:60
@ UNDEFINED_LAYER
Definition: layer_ids.h:61
void PlotBoardLayers(BOARD *aBoard, PLOTTER *aPlotter, const LSEQ &aLayerSequence, const PCB_PLOT_PARAMS &aPlotOptions)
Plot a sequence of board layer IDs.
PLOTTER * StartPlotBoard(BOARD *aBoard, const PCB_PLOT_PARAMS *aPlotOpts, int aLayer, const wxString &aLayerName, 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...
PGM_BASE & Pgm()
The global Program "get" accessor.
Definition: pgm_base.cpp:1059
see class PGM_BASE
Plotting engines similar to ps (PostScript, Gerber, svg)
const double IU_PER_MILS
Definition: base_units.h:77
bool m_sketchPadsOnFabLayers
Definition: export_svg.h:37
wxString m_colorTheme
Definition: export_svg.h:27
wxString m_outputFile
Definition: export_svg.h:26