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 <fctsys.h>
26 #include <gr_basic.h>
27 #include <sch_draw_panel.h>
28 #include <sch_screen.h>
29 #include <general.h>
30 #include <lib_edit_frame.h>
31 #include <class_library.h>
32 #include <plotter.h>
33 
34 void LIB_EDIT_FRAME::SVG_PlotComponent( const wxString& aFullFileName )
35 {
36  const bool plotColor = true;
37  const PAGE_INFO& pageInfo = GetScreen()->GetPageSettings();
38 
39  SVG_PLOTTER* plotter = new SVG_PLOTTER();
40  plotter->SetPageSettings( pageInfo );
42  plotter->SetColorMode( plotColor );
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  LIB_PART* part = GetCurPart();
64 
65  if( part )
66  {
67  TRANSFORM temp; // Uses default transform
68  wxPoint plotPos;
69 
70  plotPos.x = pageInfo.GetWidthIU() /2;
71  plotPos.y = pageInfo.GetHeightIU()/2;
72 
73  part->Plot( plotter, GetUnit(), GetConvert(), plotPos, temp );
74 
75  // Plot lib fields, not plotted by m_component->Plot():
76  part->PlotLibFields( plotter, GetUnit(), GetConvert(), plotPos, temp );
77  }
78 
79  plotter->EndPlot();
80  delete plotter;
81 }
82 
83 
84 void LIB_EDIT_FRAME::PrintPage( wxDC* aDC )
85 {
86  LIB_PART* part = GetCurPart();
87 
88  if( !part )
89  return;
90 
91  wxSize pagesize = GetScreen()->GetPageSettings().GetSizeIU();
92 
93  /* Plot item centered to the page
94  * In libedit, the component is centered at 0,0 coordinates.
95  * So we must plot it with an offset = pagesize/2.
96  */
97  wxPoint plot_offset;
98  plot_offset.x = pagesize.x / 2;
99  plot_offset.y = pagesize.y / 2;
100 
101  part->Print( aDC, plot_offset, m_unit, m_convert, PART_DRAW_OPTIONS::Default() );
102 }
void SVG_PlotComponent(const wxString &aFullFileName)
Creates the SVG print file for the current edited component.
LIB_PART * GetCurPart() const
Return the current part being edited or NULL if none selected.
virtual void SetCreator(const wxString &aCreator)
Definition: plotter.h:161
Instantiate the current locale within a scope in which you are expecting exceptions to be thrown.
Definition: common.h:154
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.
virtual bool OpenFile(const wxString &aFullFilename)
Open or create the plot file aFullFilename.
Definition: plotter.cpp:81
virtual void SetColorMode(bool aColorMode)
Plot in B/W or color.
Definition: plotter.h:126
int GetDefaultLineThickness()
Default line thickness used to draw/plot items having a default thickness line value (i....
SCH_SCREEN * GetScreen() const override
Return a pointer to a BASE_SCREEN or one of its derivatives.
virtual void SetPageSettings(const PAGE_INFO &aPageSettings)
Definition: plotter.cpp:589
const PAGE_INFO & GetPageSettings() const
Definition: sch_screen.h:118
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
void PrintPage(wxDC *aDC) override
Print a page.
void Print(wxDC *aDc, const wxPoint &aOffset, int aMulti, int aConvert, const PART_DRAW_OPTIONS &aOpts)
Print part.
Class 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.
virtual void SetDefaultLineWidth(int width) override
Set the default line width.
Definition: PS_plotter.cpp:52
Class PAGE_INFO describes the page size and margins of a paper page on which to eventually print or p...
Definition: page_info.h:54
Define a library symbol object.
virtual bool StartPlot() override
The code within this function creates SVG files header.
static PART_DRAW_OPTIONS Default()
const int scale
#define IU_PER_MILS
Definition: plotter.cpp:136
Definition for part library class.