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 plot_opts.SetHideDNPFPsOnFabLayers( aSvgPlotOptions.m_hideDNPFPsOnFabLayers );
43 plot_opts.SetSketchDNPFPsOnFabLayers( aSvgPlotOptions.m_sketchDNPFPsOnFabLayers );
45
46 // Adding drill marks, for copper layers
47 if( ( LSET( { aSvgPlotOptions.m_printMaskLayer } ) & LSET::AllCuMask() ).any() )
48 {
49 switch( aSvgPlotOptions.m_drillShapeOption )
50 {
51 default:
52 case 0: plot_opts.SetDrillMarksType( DRILL_MARKS::NO_DRILL_SHAPE ); break;
53 case 1: plot_opts.SetDrillMarksType( DRILL_MARKS::SMALL_DRILL_SHAPE ); break;
54 case 2: plot_opts.SetDrillMarksType( DRILL_MARKS::FULL_DRILL_SHAPE ); break;
55 }
56 }
57 else
58 {
59 plot_opts.SetDrillMarksType( DRILL_MARKS::NO_DRILL_SHAPE );
60 }
61
62 plot_opts.SetSkipPlotNPTH_Pads( false );
63
64 plot_opts.SetMirror( aSvgPlotOptions.m_mirror );
65 plot_opts.SetNegative( aSvgPlotOptions.m_negative );
66 plot_opts.SetFormat( PLOT_FORMAT::SVG );
67 plot_opts.SetSvgPrecision( aSvgPlotOptions.m_precision );
68
69 PAGE_INFO savedPageInfo = aBoard->GetPageSettings();
70 VECTOR2I savedAuxOrigin = aBoard->GetDesignSettings().GetAuxOrigin();
71
72 if( aSvgPlotOptions.m_pageSizeMode == 2 ) // Page is board boundary size
73 {
74 BOX2I bbox = aBoard->ComputeBoundingBox( false );
75 PAGE_INFO currpageInfo = aBoard->GetPageSettings();
76
77 currpageInfo.SetWidthMils( bbox.GetWidth() / pcbIUScale.IU_PER_MILS );
78 currpageInfo.SetHeightMils( bbox.GetHeight() / pcbIUScale.IU_PER_MILS );
79 aBoard->SetPageSettings( currpageInfo );
80 plot_opts.SetUseAuxOrigin( true );
81 VECTOR2I origin = bbox.GetOrigin();
82 aBoard->GetDesignSettings().SetAuxOrigin( origin );
83 }
84
85 if( outputFile.IsEmpty() )
86 {
87 wxFileName fn = aBoard->GetFileName();
88 fn.SetName( fn.GetName() );
89 fn.SetExt( wxS( "svg" ) );
90
91 outputFile = fn.GetFullName();
92 }
93
95
96 plot_opts.SetColorSettings( mgr.GetColorSettings( aSvgPlotOptions.m_colorTheme ) );
97
98 LOCALE_IO toggle;
100 wxString layerName;
101 //@todo allow controlling the sheet name and path that will be displayed in the title block
102 // Leave blank for now
103 wxString sheetName;
104 wxString sheetPath;
105
106 if( aSvgPlotOptions.m_printMaskLayer.size() == 1 )
107 {
108 layer = aSvgPlotOptions.m_printMaskLayer.front();
109 layerName = aBoard->GetLayerName( layer );
110 }
111
112 SVG_PLOTTER* plotter = (SVG_PLOTTER*) StartPlotBoard( aBoard, &plot_opts, layer, layerName,
113 outputFile, sheetName, sheetPath );
114
115 if( plotter )
116 {
117 plotter->SetColorMode( !aSvgPlotOptions.m_blackAndWhite );
118 PlotBoardLayers( aBoard, plotter, aSvgPlotOptions.m_printMaskLayer, plot_opts );
119 plotter->EndPlot();
120 }
121
122 delete plotter;
123
124 // reset to the values saved earlier
125 aBoard->GetDesignSettings().SetAuxOrigin( savedAuxOrigin );
126 aBoard->SetPageSettings( savedPageInfo );
127
128 return true;
129}
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:290
const PAGE_INFO & GetPageSettings() const
Definition: board.h:689
BOX2I ComputeBoundingBox(bool aBoardEdgesOnly=false) const
Calculate the bounding box containing all board items (or board edge segments).
Definition: board.cpp:1674
void SetPageSettings(const PAGE_INFO &aPageSettings)
Definition: board.h:690
const wxString & GetFileName() const
Definition: board.h:327
const wxString GetLayerName(PCB_LAYER_ID aLayer) const
Return the name of a aLayer.
Definition: board.cpp:574
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Definition: board.cpp:895
constexpr size_type GetWidth() const
Definition: box2.h:214
constexpr size_type GetHeight() const
Definition: box2.h:215
constexpr const Vec & GetOrigin() const
Definition: box2.h:210
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:36
static LSET AllCuMask(int aCuLayerCount=MAX_CU_LAYERS)
Return a mask holding the requested number of Cu PCB_LAYER_IDs.
Definition: lset.cpp:686
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:259
void SetWidthMils(double aWidthInMils)
Definition: page_info.cpp:245
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 SetSketchDNPFPsOnFabLayers(bool aFlag)
void SetPlotPadNumbers(bool aFlag)
void SetMirror(bool aFlag)
void SetHideDNPFPsOnFabLayers(bool aFlag)
void SetColorSettings(COLOR_SETTINGS *aSettings)
void SetNegative(bool aFlag)
void SetUseAuxOrigin(bool aAux)
void SetSvgPrecision(unsigned aPrecision)
void SetCrossoutDNPFPsOnFabLayers(bool aFlag)
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:1060
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
bool m_sketchDNPFPsOnFabLayers
Definition: export_svg.h:39
unsigned int m_precision
Definition: export_svg.h:48
wxString m_colorTheme
Definition: export_svg.h:27
wxString m_outputFile
Definition: export_svg.h:26
bool m_crossoutDNPFPsOnFabLayers
Definition: export_svg.h:40
bool m_hideDNPFPsOnFabLayers
Definition: export_svg.h:38