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 // coord format: 4 digits in mantissa (units always in mm). This is a good choice.
68 plot_opts.SetSvgPrecision( 4 );
69
70 PAGE_INFO savedPageInfo = aBoard->GetPageSettings();
71 VECTOR2I savedAuxOrigin = aBoard->GetDesignSettings().GetAuxOrigin();
72
73 if( aSvgPlotOptions.m_pageSizeMode == 2 ) // Page is board boundary size
74 {
75 BOX2I bbox = aBoard->ComputeBoundingBox( false );
76 PAGE_INFO currpageInfo = aBoard->GetPageSettings();
77
78 currpageInfo.SetWidthMils( bbox.GetWidth() / pcbIUScale.IU_PER_MILS );
79 currpageInfo.SetHeightMils( bbox.GetHeight() / pcbIUScale.IU_PER_MILS );
80 aBoard->SetPageSettings( currpageInfo );
81 plot_opts.SetUseAuxOrigin( true );
82 VECTOR2I origin = bbox.GetOrigin();
83 aBoard->GetDesignSettings().SetAuxOrigin( origin );
84 }
85
86 if( outputFile.IsEmpty() )
87 {
88 wxFileName fn = aBoard->GetFileName();
89 fn.SetName( fn.GetName() );
90 fn.SetExt( wxS( "svg" ) );
91
92 outputFile = fn.GetFullName();
93 }
94
96
97 plot_opts.SetColorSettings( mgr.GetColorSettings( aSvgPlotOptions.m_colorTheme ) );
98
99 LOCALE_IO toggle;
101 wxString layerName;
102 //@todo allow controlling the sheet name and path that will be displayed in the title block
103 // Leave blank for now
104 wxString sheetName;
105 wxString sheetPath;
106
107 if( aSvgPlotOptions.m_printMaskLayer.size() == 1 )
108 {
109 layer = aSvgPlotOptions.m_printMaskLayer.front();
110 layerName = aBoard->GetLayerName( layer );
111 }
112
113 SVG_PLOTTER* plotter = (SVG_PLOTTER*) StartPlotBoard( aBoard, &plot_opts, layer, layerName,
114 outputFile, sheetName, sheetPath );
115
116 if( plotter )
117 {
118 plotter->SetColorMode( !aSvgPlotOptions.m_blackAndWhite );
119 PlotBoardLayers( aBoard, plotter, aSvgPlotOptions.m_printMaskLayer, plot_opts );
120 plotter->EndPlot();
121 }
122
123 delete plotter;
124
125 // reset to the values saved earlier
126 aBoard->GetDesignSettings().SetAuxOrigin( savedAuxOrigin );
127 aBoard->SetPageSettings( savedPageInfo );
128
129 return true;
130}
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:1670
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:579
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Definition: board.cpp:892
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:676
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 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
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