KiCad PCB EDA Suite
plot_schematic_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) 2009 Jean-Pierre Charras, jp.charras at wanadoo.fr
5  * Copyright (C) 2011-2016 Wayne Stambaugh <stambaughw@verizon.net>
6  * Copyright (C) 1992-2016 KiCad Developers, see AUTHORS.txt for contributors.
7  *
8  * This program is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License
10  * as published by the Free Software Foundation; either version 2
11  * of the License, or (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, you may find one here:
20  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
21  * or you may search the http://www.gnu.org website for the version 2 license,
22  * or you may write to the Free Software Foundation, Inc.,
23  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
24  */
25 
30 #include <fctsys.h>
31 #include <pgm_base.h>
32 #include <class_drawpanel.h>
33 #include <sch_edit_frame.h>
34 #include <base_units.h>
35 #include <lib_edit_frame.h>
36 #include <sch_sheet_path.h>
37 #include <project.h>
38 #include <reporter.h>
39 
40 #include <dialog_plot_schematic.h>
41 #include <wx_html_report_panel.h>
42 
43 void DIALOG_PLOT_SCHEMATIC::createSVGFile( bool aPrintAll, bool aPrintFrameRef )
44 {
45  wxString msg;
46  REPORTER& reporter = m_MessagesBox->Reporter();
47  SCH_SHEET_PATH oldsheetpath = m_parent->GetCurrentSheet();
48  SCH_SHEET_LIST sheetList;
49 
50  if( aPrintAll )
51  sheetList.BuildSheetList( g_RootSheet );
52  else
53  sheetList.push_back( m_parent->GetCurrentSheet() );
54 
55  for( unsigned i = 0; i < sheetList.size(); i++ )
56  {
57  SCH_SCREEN* screen;
58  m_parent->SetCurrentSheet( sheetList[i] );
61  screen = m_parent->GetCurrentSheet().LastScreen();
62 
63  try
64  {
65  wxString fname = m_parent->GetUniqueFilenameForCurrentSheet();
66  wxString ext = SVG_PLOTTER::GetDefaultFileExtension();
67  wxFileName plotFileName = createPlotFileName( m_outputDirectoryName,
68  fname, ext, &reporter );
69 
70  bool success = plotOneSheetSVG( m_parent, plotFileName.GetFullPath(), screen,
71  getModeColor() ? false : true,
72  aPrintFrameRef );
73 
74  if( !success )
75  {
76  msg.Printf( _( "Cannot create file \"%s\".\n" ),
77  GetChars( plotFileName.GetFullPath() ) );
78  reporter.Report( msg, REPORTER::RPT_ERROR );
79  }
80  else
81  {
82  msg.Printf( _( "Plot: \"%s\" OK.\n" ),
83  GetChars( plotFileName.GetFullPath() ) );
84  reporter.Report( msg, REPORTER::RPT_ACTION );
85  }
86  }
87  catch( const IO_ERROR& e )
88  {
89  // Cannot plot SVG file
90  msg.Printf( wxT( "SVG Plotter exception: %s" ), GetChars( e.What() ) );
91  reporter.Report( msg, REPORTER::RPT_ERROR );
92  break;
93  }
94  }
95 
96  m_parent->SetCurrentSheet( oldsheetpath );
99 }
100 
101 
103  const wxString& aFileName,
104  SCH_SCREEN* aScreen,
105  bool aPlotBlackAndWhite,
106  bool aPlotFrameRef )
107 {
108  SVG_PLOTTER* plotter = new SVG_PLOTTER();
109 
110  const PAGE_INFO& pageInfo = aScreen->GetPageSettings();
111  plotter->SetPageSettings( pageInfo );
113  plotter->SetColorMode( aPlotBlackAndWhite ? false : true );
114  wxPoint plot_offset;
115  double scale = 1.0;
116  // Currently, plot units are in decimil
117  plotter->SetViewport( plot_offset, IU_PER_MILS/10, scale, false );
118 
119  // Init :
120  plotter->SetCreator( wxT( "Eeschema-SVG" ) );
121 
122  if( ! plotter->OpenFile( aFileName ) )
123  {
124  delete plotter;
125  return false;
126  }
127 
128  LOCALE_IO toggle;
129 
130  plotter->StartPlot();
131 
132  if( aPlotFrameRef )
133  {
134  plotter->SetColor( BLACK );
135  PlotWorkSheet( plotter, aFrame->GetTitleBlock(),
136  aFrame->GetPageSettings(),
137  aScreen->m_ScreenNumber, aScreen->m_NumberOfScreens,
138  aFrame->GetScreenDesc(),
139  aScreen->GetFileName() );
140  }
141 
142  aScreen->Plot( plotter );
143 
144  plotter->EndPlot();
145  delete plotter;
146 
147  return true;
148 }
void SetCurrentSheet(const SCH_SHEET_PATH &aSheet)
Class SCH_SHEET_LIST.
int m_ScreenNumber
Definition: base_screen.h:216
virtual void SetCreator(const wxString &aCreator)
Definition: plotter.h:160
virtual const TITLE_BLOCK & GetTitleBlock() const =0
Class LOCALE_IO is a class that can be instantiated within a scope in which you are expecting excepti...
Definition: common.h:166
virtual void SetViewport(const wxPoint &aOffset, double aIusPerDecimil, double aScale, bool aMirror) override
Set the plot offset and scaling for the current plot.
Implementation of conversion functions that require both schematic and board internal units...
virtual bool OpenFile(const wxString &aFullFilename)
Open or create the plot file aFullFilename.
Definition: plotter.cpp:82
static wxString GetDefaultFileExtension()
Definition: plotter.h:905
int GetDefaultLineThickness()
Default line thickness used to draw/plot items having a default thickness line value (i...
const wxString & GetFileName() const
Definition: sch_screen.h:120
SCH_SCREEN * LastScreen() const
Function LastScreen.
Class REPORTER is a pure virtual class used to derive REPORTER objects from.
Definition: reporter.h:61
void UpdateAllScreenReferences()
Function UpdateAllScreenReferences updates the reference and the m_Multi parameter (part selection) f...
Class EDA_DRAW_FRAME is the base class for create windows for drawing purpose.
Definition: draw_frame.h:55
virtual void SetPageSettings(const PAGE_INFO &aPageSettings)
Definition: plotter.cpp:538
void PlotWorkSheet(PLOTTER *plotter, const TITLE_BLOCK &aTitleBlock, const PAGE_INFO &aPageInfo, int aSheetNumber, int aNumberOfSheets, const wxString &aSheetDesc, const wxString &aFilename)
virtual bool EndPlot() override
virtual const PAGE_INFO & GetPageSettings() const =0
virtual void SetColor(COLOR4D color) override
The SetColor implementation is split with the subclasses: The PSLIKE computes the rgb values...
SCH_SHEET * g_RootSheet
Definition: eeschema.cpp:55
virtual void SetDefaultLineWidth(int width) override
Set the default line width.
Definition: PS_plotter.cpp:52
virtual wxString GetScreenDesc() const
Definition: worksheet.cpp:119
wxFileName createPlotFileName(wxTextCtrl *aOutputDirectoryName, wxString &aPlotFileName, wxString &aExtension, REPORTER *aReporter=NULL)
Create a file name with an absolute path name.
Class PAGE_INFO describes the page size and margins of a paper page on which to eventually print or p...
Definition: page_info.h:49
REPORTER & Reporter()
returns the reporter object that reports to this panel
SCH_SHEET_PATH & GetCurrentSheet()
virtual bool StartPlot() override
The code within this function creates SVG files header.
Class SCH_SHEET_PATH.
void BuildSheetList(SCH_SHEET *aSheet)
Function BuildSheetList builds the list of sheets and their sheet path from aSheet.
void Plot(PLOTTER *aPlotter)
Plot all the schematic objects to aPlotter.
Definition: sch_screen.cpp:554
virtual const wxString What() const
A composite of Problem() and Where()
Definition: exceptions.cpp:33
const int scale
static const wxChar * GetChars(const wxString &s)
Function GetChars returns a wxChar* to the actual wxChar* data within a wxString, and is helpful for ...
Definition: macros.h:92
see class PGM_BASE
void SetSheetNumberAndCount()
Set the m_ScreenNumber and m_NumberOfScreens members for screens.
size_t i
Definition: json11.cpp:597
wxString GetUniqueFilenameForCurrentSheet()
virtual REPORTER & Report(const wxString &aText, SEVERITY aSeverity=RPT_UNDEFINED)=0
Function Report is a pure virtual function to override in the derived object.
int m_NumberOfScreens
Definition: base_screen.h:217
const PAGE_INFO & GetPageSettings() const
Definition: sch_screen.h:115
Definition of class LIB_EDIT_FRAME.
Definition: colors.h:45
WX_HTML_REPORT_PANEL * m_MessagesBox
Definition of the SCH_SHEET_PATH and SCH_SHEET_LIST classes for Eeschema.
Struct IO_ERROR is a class used to hold an error message and may be used when throwing exceptions con...
Definition: ki_exception.h:47
void createSVGFile(bool aPlotAll, bool aPlotFrameRef)
virtual void SetColorMode(bool _color_mode)
Definition: plotter.h:125
static bool plotOneSheetSVG(EDA_DRAW_FRAME *aFrame, const wxString &aFileName, SCH_SCREEN *aScreen, bool aPlotBlackAndWhite, bool aPlotFrameRef)