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 <class_sch_screen.h>
34 #include <schframe.h>
35 #include <base_units.h>
36 #include <libeditframe.h>
37 #include <sch_sheet_path.h>
38 #include <project.h>
39 #include <reporter.h>
40 
41 #include <dialog_plot_schematic.h>
42 #include <wx_html_report_panel.h>
43 
44 void DIALOG_PLOT_SCHEMATIC::createSVGFile( bool aPrintAll, bool aPrintFrameRef )
45 {
46  wxString msg;
47  REPORTER& reporter = m_MessagesBox->Reporter();
48  SCH_SHEET_PATH oldsheetpath = m_parent->GetCurrentSheet();
49  SCH_SHEET_LIST sheetList;
50 
51  if( aPrintAll )
52  sheetList.BuildSheetList( g_RootSheet );
53  else
54  sheetList.push_back( m_parent->GetCurrentSheet() );
55 
56  for( unsigned i = 0; i < sheetList.size(); i++ )
57  {
58  SCH_SCREEN* screen;
59  m_parent->SetCurrentSheet( sheetList[i] );
62  screen = m_parent->GetCurrentSheet().LastScreen();
63 
64  try
65  {
66  wxString fname = m_parent->GetUniqueFilenameForCurrentSheet();
67  wxString ext = SVG_PLOTTER::GetDefaultFileExtension();
68  wxFileName plotFileName = createPlotFileName( m_outputDirectoryName,
69  fname, ext, &reporter );
70 
71  bool success = plotOneSheetSVG( m_parent, plotFileName.GetFullPath(), screen,
72  getModeColor() ? false : true,
73  aPrintFrameRef );
74 
75  if( !success )
76  {
77  msg.Printf( _( "Cannot create file '%s'.\n" ),
78  GetChars( plotFileName.GetFullPath() ) );
79  reporter.Report( msg, REPORTER::RPT_ERROR );
80  }
81  else
82  {
83  msg.Printf( _( "Plot: '%s' OK.\n" ),
84  GetChars( plotFileName.GetFullPath() ) );
85  reporter.Report( msg, REPORTER::RPT_ACTION );
86  }
87  }
88  catch( const IO_ERROR& e )
89  {
90  // Cannot plot SVG file
91  msg.Printf( wxT( "SVG Plotter exception: %s" ), GetChars( e.What() ) );
92  reporter.Report( msg, REPORTER::RPT_ERROR );
93  break;
94  }
95  }
96 
97  m_parent->SetCurrentSheet( oldsheetpath );
100 }
101 
102 
104  const wxString& aFileName,
105  SCH_SCREEN* aScreen,
106  bool aPlotBlackAndWhite,
107  bool aPlotFrameRef )
108 {
109  SVG_PLOTTER* plotter = new SVG_PLOTTER();
110 
111  const PAGE_INFO& pageInfo = aScreen->GetPageSettings();
112  plotter->SetPageSettings( pageInfo );
114  plotter->SetColorMode( aPlotBlackAndWhite ? false : true );
115  wxPoint plot_offset;
116  double scale = 1.0;
117  // Currently, plot units are in decimil
118  plotter->SetViewport( plot_offset, IU_PER_MILS/10, scale, false );
119 
120  // Init :
121  plotter->SetCreator( wxT( "Eeschema-SVG" ) );
122 
123  if( ! plotter->OpenFile( aFileName ) )
124  {
125  delete plotter;
126  return false;
127  }
128 
129  LOCALE_IO toggle;
130 
131  plotter->StartPlot();
132 
133  if( aPlotFrameRef )
134  {
135  plotter->SetColor( BLACK );
136  PlotWorkSheet( plotter, aFrame->GetTitleBlock(),
137  aFrame->GetPageSettings(),
138  aScreen->m_ScreenNumber, aScreen->m_NumberOfScreens,
139  aFrame->GetScreenDesc(),
140  aScreen->GetFileName() );
141  }
142 
143  aScreen->Plot( plotter );
144 
145  plotter->EndPlot();
146  delete plotter;
147 
148  return true;
149 }
void SetCurrentSheet(const SCH_SHEET_PATH &aSheet)
Definition: schframe.cpp:573
Class SCH_SHEET_LIST.
virtual void SetCreator(const wxString &aCreator)
Definition: plot_common.h:151
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.
static wxString GetDefaultFileExtension()
Definition: plot_common.h:883
int GetDefaultLineThickness()
Default line thickness used to draw/plot items having a default thickness line value (i...
const wxString & GetFileName() const
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:53
virtual void SetPageSettings(const PAGE_INFO &aPageSettings)
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:54
virtual void SetDefaultLineWidth(int width) override
Set the default line width.
virtual wxString GetScreenDesc() const
Definition: worksheet.cpp:120
Definitions for the Eeschema program SCH_SCREEN class.
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...
REPORTER & Reporter()
returns the reporter object that reports to this panel
SCH_SHEET_PATH & GetCurrentSheet()
Definition: schframe.cpp:565
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)
Function Plot plots all the schematic objects to aPlotter.
Definition: sch_screen.cpp:583
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()
Function SetSheetNumberAndCount Set the m_ScreenNumber and m_NumberOfScreens members for screens must...
Definition: schframe.cpp:485
wxString GetUniqueFilenameForCurrentSheet()
Function GetUniqueFilenameForCurrentSheet.
Definition: schframe.cpp:730
virtual REPORTER & Report(const wxString &aText, SEVERITY aSeverity=RPT_UNDEFINED)=0
Function Report is a pure virtual function to override in the derived object.
const PAGE_INFO & GetPageSettings() const
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: plot_common.h:116
Definition of class LIB_EDIT_FRAME.
static bool plotOneSheetSVG(EDA_DRAW_FRAME *aFrame, const wxString &aFileName, SCH_SCREEN *aScreen, bool aPlotBlackAndWhite, bool aPlotFrameRef)