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 "pcb_plot_params.h"
24#include "export_svg.h"
25#include "pcbplot.h"
26#include "pgm_base.h"
28
29
30bool EXPORT_SVG::Plot( BOARD* aBoard, const PCB_PLOT_SVG_OPTIONS& aSvgPlotOptions )
31{
32 PCB_PLOT_PARAMS plot_opts;
33 wxString outputFile = aSvgPlotOptions.m_outputFile;
34
35 plot_opts.SetPlotFrameRef( aSvgPlotOptions.m_plotFrame );
36
37 // Adding drill marks, for copper layers
38 if( ( LSET( aSvgPlotOptions.m_printMaskLayer ) & LSET::AllCuMask() ).any() )
39 {
40 switch( aSvgPlotOptions.m_drillShapeOption )
41 {
42 default:
43 case 0: plot_opts.SetDrillMarksType( DRILL_MARKS::NO_DRILL_SHAPE ); break;
44 case 1: plot_opts.SetDrillMarksType( DRILL_MARKS::SMALL_DRILL_SHAPE ); break;
45 case 2: plot_opts.SetDrillMarksType( DRILL_MARKS::FULL_DRILL_SHAPE ); break;
46 }
47 }
48 else
49 {
50 plot_opts.SetDrillMarksType( DRILL_MARKS::NO_DRILL_SHAPE );
51 }
52
53 plot_opts.SetSkipPlotNPTH_Pads( false );
54
55 plot_opts.SetMirror( aSvgPlotOptions.m_mirror );
56 plot_opts.SetNegative( aSvgPlotOptions.m_negative );
57 plot_opts.SetFormat( PLOT_FORMAT::SVG );
58 // coord format: 4 digits in mantissa (units always in mm). This is a good choice.
59 plot_opts.SetSvgPrecision( 4 );
60
61 PAGE_INFO savedPageInfo = aBoard->GetPageSettings();
62 VECTOR2I savedAuxOrigin = aBoard->GetDesignSettings().GetAuxOrigin();
63
64 if( aSvgPlotOptions.m_pageSizeMode == 2 ) // Page is board boundary size
65 {
66 BOX2I bbox = aBoard->ComputeBoundingBox();
67 PAGE_INFO currpageInfo = aBoard->GetPageSettings();
68
69 currpageInfo.SetWidthMils( bbox.GetWidth() / pcbIUScale.IU_PER_MILS );
70 currpageInfo.SetHeightMils( bbox.GetHeight() / pcbIUScale.IU_PER_MILS );
71 aBoard->SetPageSettings( currpageInfo );
72 plot_opts.SetUseAuxOrigin( true );
73 VECTOR2I origin = bbox.GetOrigin();
74 aBoard->GetDesignSettings().SetAuxOrigin( origin );
75 }
76
77 if( outputFile.IsEmpty() )
78 {
79 wxFileName fn = aBoard->GetFileName();
80 fn.SetName( fn.GetName() );
81 fn.SetExt( wxS("svg") );
82
83 outputFile = fn.GetFullName();
84 }
85
87
88 plot_opts.SetColorSettings( mgr.GetColorSettings( aSvgPlotOptions.m_colorTheme ) );
89
90 LOCALE_IO toggle;
91
92 //@todo allow controlling the sheet name and path that will be displayed in the title block
93 // Leave blank for now
94 SVG_PLOTTER* plotter = (SVG_PLOTTER*) StartPlotBoard( aBoard, &plot_opts, UNDEFINED_LAYER, outputFile,
95 wxEmptyString, wxEmptyString );
96
97 if( plotter )
98 {
99 plotter->SetColorMode( !aSvgPlotOptions.m_blackAndWhite );
100 PlotBoardLayers( aBoard, plotter, aSvgPlotOptions.m_printMaskLayer,
101 plot_opts );
102 plotter->EndPlot();
103 }
104
105 delete plotter;
106
107 // reset to the values saved earlier
108 aBoard->GetDesignSettings().SetAuxOrigin( savedAuxOrigin );
109 aBoard->SetPageSettings( savedPageInfo );
110
111 return true;
112}
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:281
const PAGE_INFO & GetPageSettings() const
Definition: board.h:668
BOX2I ComputeBoundingBox(bool aBoardEdgesOnly=false) const
Calculate the bounding box containing all board items (or board edge segments).
Definition: board.cpp:1555
void SetPageSettings(const PAGE_INFO &aPageSettings)
Definition: board.h:669
const wxString & GetFileName() const
Definition: board.h:318
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Definition: board.cpp:797
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:30
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: layer_ids.h:575
static LSET AllCuMask(int aCuLayerCount=MAX_CU_LAYERS)
Return a mask holding the requested number of Cu PCB_LAYER_IDs.
Definition: lset.cpp:863
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 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)
virtual SETTINGS_MANAGER & GetSettingsManager() const
Definition: pgm_base.h:142
virtual void SetColorMode(bool aColorMode)
Plot in B/W or color.
Definition: plotter.h:131
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:61
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.
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
wxString m_colorTheme
Definition: export_svg.h:27
wxString m_outputFile
Definition: export_svg.h:26