KiCad PCB EDA Suite
Loading...
Searching...
No Matches
symbol_editor_plotter.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) 1992-2021 KiCad Developers, see AUTHORS.txt for contributors.
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, you may find one here:
18 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
19 * or you may search the http://www.gnu.org website for the version 2 license,
20 * or you may write to the Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
22 */
23
24
25#include <sch_painter.h>
26#include <symbol_edit_frame.h>
27#include <locale_io.h>
29#include <sch_plotter.h>
30
31void SYMBOL_EDIT_FRAME::SVGPlotSymbol( const wxString& aFullFileName, const VECTOR2I& aOffset )
32{
33 SCH_RENDER_SETTINGS renderSettings;
34 renderSettings.LoadColors( GetColorSettings() );
35 renderSettings.SetDefaultPenWidth( GetRenderSettings()->GetDefaultPenWidth() );
36
37 const PAGE_INFO& pageInfo = GetScreen()->GetPageSettings();
38
39 SVG_PLOTTER* plotter = new SVG_PLOTTER();
40 plotter->SetRenderSettings( &renderSettings );
41 plotter->SetPageSettings( pageInfo );
42 plotter->SetColorMode( true );
43
44 VECTOR2I plot_offset;
45 const double scale = 1.0;
46
47 // Currently, plot units are in decimil
48 plotter->SetViewport( plot_offset, schIUScale.IU_PER_MILS/10, scale, false );
49
50 // Init :
51 plotter->SetCreator( wxT( "Eeschema-SVG" ) );
52
53 if( !plotter->OpenFile( aFullFileName ) )
54 {
55 delete plotter;
56 return;
57 }
58
59 LOCALE_IO toggle;
60 SCH_PLOT_OPTS plotOpts;
61
62 plotter->StartPlot( wxT( "1" ) );
63
64 if( m_symbol )
65 {
66 constexpr bool background = true;
67
68 m_symbol->Plot( plotter, background, plotOpts, GetUnit(), GetBodyStyle(), aOffset, false );
69 m_symbol->Plot( plotter, !background, plotOpts, GetUnit(), GetBodyStyle(), aOffset, false );
70 m_symbol->PlotFields( plotter, !background, plotOpts, GetUnit(), GetBodyStyle(), aOffset,
71 false );
72 }
73
74 plotter->EndPlot();
75 delete plotter;
76}
77
78
80{
81 if( !m_symbol )
82 return;
83
84 const SCH_RENDER_SETTINGS* cfg = static_cast<const SCH_RENDER_SETTINGS*>( aSettings );
86
87 // Print item centered to the page.
88 m_symbol->PrintBackground( cfg, m_unit, m_bodyStyle, pagesize / 2, false );
89 m_symbol->Print( cfg, m_unit, m_bodyStyle, pagesize / 2, false, false );
90}
constexpr EDA_IU_SCALE schIUScale
Definition: base_units.h:110
Container for all the knowledge about how graphical objects are drawn on any output surface/device.
void SetDefaultPenWidth(int aWidth)
void Print(const SCH_RENDER_SETTINGS *aSettings, int aUnit, int aBodyStyle, const VECTOR2I &aOffset, bool aForceNoFill, bool aDimmed) override
Print an item.
Definition: lib_symbol.cpp:567
void Plot(PLOTTER *aPlotter, bool aBackground, const SCH_PLOT_OPTS &aPlotOpts, int aUnit, int aBodyStyle, const VECTOR2I &aOffset, bool aDimmed) override
Plot the item to aPlotter.
Definition: lib_symbol.cpp:648
void PlotFields(PLOTTER *aPlotter, bool aBackground, const SCH_PLOT_OPTS &aPlotOpts, int aUnit, int aBodyStyle, const VECTOR2I &aOffset, bool aDimmed)
Plot symbol fields.
Definition: lib_symbol.cpp:690
void PrintBackground(const SCH_RENDER_SETTINGS *aSettings, int aUnit, int aBodyStyle, const VECTOR2I &aOffset, bool aDimmed) override
Print just the background fills.
Definition: lib_symbol.cpp:614
Instantiate the current locale within a scope in which you are expecting exceptions to be thrown.
Definition: locale_io.h:49
Describe the page size and margins of a paper page on which to eventually print or plot.
Definition: page_info.h:59
const VECTOR2D GetSizeIU(double aIUScale) const
Gets the page size in internal units.
Definition: page_info.h:171
virtual bool OpenFile(const wxString &aFullFilename)
Open or create the plot file aFullFilename.
Definition: plotter.cpp:75
virtual void SetPageSettings(const PAGE_INFO &aPageSettings)
Definition: plotter.h:138
void SetRenderSettings(RENDER_SETTINGS *aSettings)
Definition: plotter.h:135
virtual void SetCreator(const wxString &aCreator)
Definition: plotter.h:154
virtual void SetColorMode(bool aColorMode)
Plot in B/W or color.
Definition: plotter.h:132
SCH_RENDER_SETTINGS * GetRenderSettings()
SCH_SCREEN * GetScreen() const override
Return a pointer to a BASE_SCREEN or one of its derivatives.
void LoadColors(const COLOR_SETTINGS *aSettings) override
const PAGE_INFO & GetPageSettings() const
Definition: sch_screen.h:130
virtual bool StartPlot(const wxString &aPageNumber) override
Create SVG file header.
virtual void SetViewport(const VECTOR2I &aOffset, double aIusPerDecimil, double aScale, bool aMirror) override
Set the plot offset and scaling for the current plot.
virtual bool EndPlot() override
void SVGPlotSymbol(const wxString &aFullFileName, const VECTOR2I &aOffset)
Create the SVG print file for the current edited symbol.
void PrintPage(const RENDER_SETTINGS *aSettings) override
Print a page.
int GetBodyStyle() const
int m_bodyStyle
Flag if the symbol being edited was loaded directly from a schematic.
COLOR_SETTINGS * GetColorSettings(bool aForceRefresh=false) const override
Returns a pointer to the active color theme settings.
Plotting engines similar to ps (PostScript, Gerber, svg)
const int scale
const double IU_PER_MILS
Definition: base_units.h:77