KiCad PCB EDA Suite
libedit_plot_component.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-2019 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 <lib_edit_frame.h>
27 #include <class_libentry.h>
28 #include <class_library.h>
29 #include <plotters_specific.h>
30 
31 void LIB_EDIT_FRAME::SVG_PlotComponent( const wxString& aFullFileName )
32 {
33  KIGFX::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  wxPoint plot_offset;
45  const double scale = 1.0;
46 
47  // Currently, plot units are in decimil
48  plotter->SetViewport( plot_offset, 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 
61  plotter->StartPlot();
62 
63  if( m_my_part )
64  {
65  TRANSFORM temp; // Uses default transform
66  wxPoint plotPos;
67 
68  plotPos.x = pageInfo.GetWidthIU() /2;
69  plotPos.y = pageInfo.GetHeightIU()/2;
70 
71  m_my_part->Plot( plotter, GetUnit(), GetConvert(), plotPos, temp );
72 
73  // Plot lib fields, not plotted by m_component->Plot():
74  m_my_part->PlotLibFields( plotter, GetUnit(), GetConvert(), plotPos, temp );
75  }
76 
77  plotter->EndPlot();
78  delete plotter;
79 }
80 
81 
83 {
84  if( !m_my_part )
85  return;
86 
87  wxSize pagesize = GetScreen()->GetPageSettings().GetSizeIU();
88 
89  /* Plot item centered to the page
90  * In libedit, the component is centered at 0,0 coordinates.
91  * So we must plot it with an offset = pagesize/2.
92  */
93  wxPoint plot_offset;
94  plot_offset.x = pagesize.x / 2;
95  plot_offset.y = pagesize.y / 2;
96 
97  m_my_part->Print( aSettings, plot_offset, m_unit, m_convert, PART_DRAW_OPTIONS() );
98 }
void SVG_PlotComponent(const wxString &aFullFileName)
Creates the SVG print file for the current edited component.
virtual void SetCreator(const wxString &aCreator)
Definition: plotter.h:170
int m_convert
Flag if the symbol being edited was loaded directly from a schematic.
Instantiate the current locale within a scope in which you are expecting exceptions to be thrown.
Definition: common.h:222
int GetConvert() const
virtual void SetViewport(const wxPoint &aOffset, double aIusPerDecimil, double aScale, bool aMirror) override
Set the plot offset and scaling for the current plot.
RENDER_SETTINGS Contains all the knowledge about how graphical objects are drawn on any output surfac...
Plotting engines (Postscript, Gerber, HPGL and DXF)
virtual bool OpenFile(const wxString &aFullFilename)
Open or create the plot file aFullFilename.
Definition: plotter.cpp:76
virtual void SetColorMode(bool aColorMode)
Plot in B/W or color.
Definition: plotter.h:149
SCH_SCREEN * GetScreen() const override
Return a pointer to a BASE_SCREEN or one of its derivatives.
void SetRenderSettings(RENDER_SETTINGS *aSettings)
Definition: plotter.h:152
KIGFX::SCH_RENDER_SETTINGS * GetRenderSettings()
const PAGE_INFO & GetPageSettings() const
Definition: sch_screen.h:180
LIB_PART * m_my_part
void PrintPage(RENDER_SETTINGS *aSettings) override
Print a page.
void PlotLibFields(PLOTTER *aPlotter, int aUnit, int aConvert, const wxPoint &aOffset, const TRANSFORM &aTransform)
Plot Lib Fields only of the part to plotter.
virtual bool EndPlot() override
for transforming drawing coordinates for a wxDC device context.
Definition: transform.h:45
int GetUnit() const
void Plot(PLOTTER *aPlotter, int aUnit, int aConvert, const wxPoint &aOffset, const TRANSFORM &aTransform)
Plot lib part to plotter.
PAGE_INFO describes the page size and margins of a paper page on which to eventually print or plot.
Definition: page_info.h:54
virtual bool StartPlot() override
The code within this function creates SVG files header.
void LoadColors(const COLOR_SETTINGS *aSettings) override
Definition: sch_painter.cpp:93
const int scale
#define IU_PER_MILS
Definition: plotter.cpp:137
SCH_RENDER_SETTINGS Stores schematic-specific render settings.
Definition: sch_painter.h:70
void Print(RENDER_SETTINGS *aSettings, const wxPoint &aOffset, int aMulti, int aConvert, const PART_DRAW_OPTIONS &aOpts)
Print part.
COLOR_SETTINGS * GetColorSettings() override
Returns a pointer to the active color theme settings.
Definition for part library class.
void SetDefaultPenWidth(int aWidth)
virtual void SetPageSettings(const PAGE_INFO &aPageSettings)
Definition: plotter.h:155