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
30void SYMBOL_EDIT_FRAME::SVGPlotSymbol( const wxString& aFullFileName, VECTOR2I aOffset )
31{
32 KIGFX::SCH_RENDER_SETTINGS renderSettings;
33 renderSettings.LoadColors( GetColorSettings() );
34 renderSettings.SetDefaultPenWidth( GetRenderSettings()->GetDefaultPenWidth() );
35
36 const PAGE_INFO& pageInfo = GetScreen()->GetPageSettings();
37
38 SVG_PLOTTER* plotter = new SVG_PLOTTER();
39 plotter->SetRenderSettings( &renderSettings );
40 plotter->SetPageSettings( pageInfo );
41 plotter->SetColorMode( true );
42
43 VECTOR2I plot_offset;
44 const double scale = 1.0;
45
46 // Currently, plot units are in decimil
47 plotter->SetViewport( plot_offset, schIUScale.IU_PER_MILS/10, scale, false );
48
49 // Init :
50 plotter->SetCreator( wxT( "Eeschema-SVG" ) );
51
52 if( ! plotter->OpenFile( aFullFileName ) )
53 {
54 delete plotter;
55 return;
56 }
57
58 LOCALE_IO toggle;
59
60 plotter->StartPlot( wxT( "1" ) );
61
62 if( m_symbol )
63 {
64 constexpr bool background = true;
65 TRANSFORM temp; // Uses default transform
66 VECTOR2I plotPos;
67
68 plotPos.x = aOffset.x;
69 plotPos.y = aOffset.y;
70
71 m_symbol->Plot( plotter, GetUnit(), GetBodyStyle(), background, plotPos, temp, false );
72
73 // Plot lib fields, not plotted by m_symbol->Plot():
74 m_symbol->PlotLibFields( plotter, GetUnit(), GetBodyStyle(), background, plotPos, temp,
75 false );
76
77 m_symbol->Plot( plotter, GetUnit(), GetBodyStyle(), !background, plotPos, temp, false );
78
79 // Plot lib fields, not plotted by m_symbol->Plot():
80 m_symbol->PlotLibFields( plotter, GetUnit(), GetBodyStyle(), !background, plotPos, temp,
81 false );
82 }
83
84 plotter->EndPlot();
85 delete plotter;
86}
87
88
90{
91 if( !m_symbol )
92 return;
93
95
96 /* Plot item centered to the page
97 * In symbol_editor, the symbol is centered at 0,0 coordinates.
98 * So we must plot it with an offset = pagesize/2.
99 */
100 VECTOR2I plot_offset;
101 plot_offset.x = pagesize.x / 2;
102 plot_offset.y = pagesize.y / 2;
103
104 m_symbol->PrintBackground( aSettings, plot_offset, m_unit, m_bodyStyle, LIB_SYMBOL_OPTIONS(),
105 false );
106
107 m_symbol->Print( aSettings, plot_offset, m_unit, m_bodyStyle, LIB_SYMBOL_OPTIONS(), false );
108}
constexpr EDA_IU_SCALE schIUScale
Definition: base_units.h:111
Container for all the knowledge about how graphical objects are drawn on any output surface/device.
void SetDefaultPenWidth(int aWidth)
Store schematic specific render settings.
Definition: sch_painter.h:72
void LoadColors(const COLOR_SETTINGS *aSettings) override
void PlotLibFields(PLOTTER *aPlotter, int aUnit, int aBodyStyle, bool aBackground, const VECTOR2I &aOffset, const TRANSFORM &aTransform, bool aDimmed, bool aPlotHidden=true)
Plot Lib Fields only of the symbol to plotter.
Definition: lib_symbol.cpp:906
void Print(const RENDER_SETTINGS *aSettings, const VECTOR2I &aOffset, int aMulti, int aBodyStyle, const LIB_SYMBOL_OPTIONS &aOpts, bool aDimmed)
Print symbol.
Definition: lib_symbol.cpp:814
void PrintBackground(const RENDER_SETTINGS *aSettings, const VECTOR2I &aOffset, int aMulti, int aBodyStyle, const LIB_SYMBOL_OPTIONS &aOpts, bool aDimmed)
Print just the background fills of a symbol.
Definition: lib_symbol.cpp:779
void Plot(PLOTTER *aPlotter, int aUnit, int aBodyStyle, bool aBackground, const VECTOR2I &aOffset, const TRANSFORM &aTransform, bool aDimmed) const
Plot lib symbol to plotter.
Definition: lib_symbol.cpp:865
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:74
virtual void SetPageSettings(const PAGE_INFO &aPageSettings)
Definition: plotter.h:137
void SetRenderSettings(RENDER_SETTINGS *aSettings)
Definition: plotter.h:134
virtual void SetCreator(const wxString &aCreator)
Definition: plotter.h:153
virtual void SetColorMode(bool aColorMode)
Plot in B/W or color.
Definition: plotter.h:131
SCH_SCREEN * GetScreen() const override
Return a pointer to a BASE_SCREEN or one of its derivatives.
KIGFX::SCH_RENDER_SETTINGS * GetRenderSettings()
const PAGE_INFO & GetPageSettings() const
Definition: sch_screen.h:131
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 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.
void SVGPlotSymbol(const wxString &aFullFileName, VECTOR2I aOffset)
Create the SVG print file for the current edited symbol.
COLOR_SETTINGS * GetColorSettings(bool aForceRefresh=false) const override
Returns a pointer to the active color theme settings.
for transforming drawing coordinates for a wxDC device context.
Definition: transform.h:46
Plotting engines similar to ps (PostScript, Gerber, svg)
const int scale
const double IU_PER_MILS
Definition: base_units.h:78