KiCad PCB EDA Suite
plot_schematic_PS.cpp
Go to the documentation of this file.
1 
4 /*
5  * This program source code file is part of KiCad, a free EDA CAD application.
6  *
7  * Copyright (C) 1992-2016 KiCad Developers, see change_log.txt for contributors.
8  *
9  * This program is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU General Public License
11  * as published by the Free Software Foundation; either version 2
12  * of the License, or (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, you may find one here:
21  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
22  * or you may search the http://www.gnu.org website for the version 2 license,
23  * or you may write to the Free Software Foundation, Inc.,
24  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
25  */
26 
27 #include <fctsys.h>
28 #include <plot_common.h>
29 #include <class_sch_screen.h>
30 #include <schframe.h>
31 #include <base_units.h>
32 #include <sch_sheet_path.h>
33 #include <project.h>
34 #include <reporter.h>
35 
36 #include <dialog_plot_schematic.h>
37 #include <wx_html_report_panel.h>
38 
39 void DIALOG_PLOT_SCHEMATIC::createPSFile( bool aPlotAll, bool aPlotFrameRef )
40 {
41  SCH_SCREEN* screen = m_parent->GetScreen();
42  SCH_SHEET_PATH oldsheetpath = m_parent->GetCurrentSheet(); // sheetpath is saved here
43  PAGE_INFO actualPage; // page size selected in schematic
44  PAGE_INFO plotPage; // page size selected to plot
45 
46  /* When printing all pages, the printed page is not the current page.
47  * In complex hierarchies, we must update component references
48  * and others parameters in the given printed SCH_SCREEN, accordint to the sheet path
49  * because in complex hierarchies a SCH_SCREEN (a drawing )
50  * is shared between many sheets and component references depend on the actual sheet path used
51  */
52  SCH_SHEET_LIST sheetList;
53 
54  if( aPlotAll )
55  sheetList.BuildSheetList( g_RootSheet );
56  else
57  sheetList.push_back( m_parent->GetCurrentSheet() );
58 
59  for( unsigned i = 0; i < sheetList.size(); i++ )
60  {
61  m_parent->SetCurrentSheet( sheetList[i] );
64  screen = m_parent->GetCurrentSheet().LastScreen();
65  actualPage = screen->GetPageSettings();
66 
67  switch( m_pageSizeSelect )
68  {
69  case PAGE_SIZE_A:
70  plotPage.SetType( wxT( "A" ) );
71  plotPage.SetPortrait( actualPage.IsPortrait() );
72  break;
73 
74  case PAGE_SIZE_A4:
75  plotPage.SetType( wxT( "A4" ) );
76  plotPage.SetPortrait( actualPage.IsPortrait() );
77  break;
78 
79  case PAGE_SIZE_AUTO:
80  default:
81  plotPage = actualPage;
82  break;
83  }
84 
85  double scalex = (double) plotPage.GetWidthMils() / actualPage.GetWidthMils();
86  double scaley = (double) plotPage.GetHeightMils() / actualPage.GetHeightMils();
87 
88  double scale = std::min( scalex, scaley );
89 
90  wxPoint plot_offset;
91 
92  wxString outputDirName = m_outputDirectoryName->GetValue();
93 
94  wxString msg;
95  REPORTER& reporter = m_MessagesBox->Reporter();
96 
97  try
98  {
99  wxString fname = m_parent->GetUniqueFilenameForCurrentSheet();
100  wxString ext = PS_PLOTTER::GetDefaultFileExtension();
101  wxFileName plotFileName = createPlotFileName( m_outputDirectoryName,
102  fname, ext, &reporter );
103 
104  if( plotOneSheetPS( plotFileName.GetFullPath(), screen, plotPage, plot_offset,
105  scale, aPlotFrameRef ) )
106  {
107  msg.Printf( _( "Plot: '%s' OK.\n" ), GetChars( plotFileName.GetFullPath() ) );
108  reporter.Report( msg, REPORTER::RPT_ACTION );
109  }
110  else
111  {
112  // Error
113  msg.Printf( _( "Unable to create file '%s'.\n" ),
114  GetChars( plotFileName.GetFullPath() ) );
115  reporter.Report( msg, REPORTER::RPT_ERROR );
116  }
117 
118  }
119  catch( IO_ERROR& e )
120  {
121  msg.Printf( wxT( "PS Plotter exception: %s"), GetChars( e.What() ) );
122  reporter.Report( msg, REPORTER::RPT_ERROR );
123  }
124  }
125 
126  m_parent->SetCurrentSheet( oldsheetpath );
129 }
130 
131 
132 bool DIALOG_PLOT_SCHEMATIC::plotOneSheetPS( const wxString& aFileName,
133  SCH_SCREEN* aScreen,
134  const PAGE_INFO& aPageInfo,
135  wxPoint aPlot0ffset,
136  double aScale,
137  bool aPlotFrameRef )
138 {
139  PS_PLOTTER* plotter = new PS_PLOTTER();
140  plotter->SetPageSettings( aPageInfo );
142  plotter->SetColorMode( getModeColor() );
143  // Currently, plot units are in decimil
144  plotter->SetViewport( aPlot0ffset, IU_PER_MILS/10, aScale, false );
145 
146  // Init :
147  plotter->SetCreator( wxT( "Eeschema-PS" ) );
148 
149  if( ! plotter->OpenFile( aFileName ) )
150  {
151  delete plotter;
152  return false;
153  }
154 
155  LOCALE_IO toggle; // Switch the locale to standard C
156 
157  plotter->StartPlot();
158 
159  if( aPlotFrameRef )
160  {
161  plotter->SetColor( BLACK );
162  PlotWorkSheet( plotter, m_parent->GetTitleBlock(),
164  aScreen->m_ScreenNumber, aScreen->m_NumberOfScreens,
166  aScreen->GetFileName() );
167  }
168 
169  aScreen->Plot( plotter );
170 
171  plotter->EndPlot();
172  delete plotter;
173 
174  return true;
175 }
void SetCurrentSheet(const SCH_SHEET_PATH &aSheet)
Definition: schframe.cpp:574
Class SCH_SHEET_LIST.
virtual void SetViewport(const wxPoint &aOffset, double aIusPerDecimil, double aScale, bool aMirror) override
Set the plot offset and scaling for the current plot.
virtual void SetCreator(const wxString &aCreator)
Definition: plot_common.h:151
static wxString GetDefaultFileExtension()
Definition: plot_common.h:741
Class LOCALE_IO is a class that can be instantiated within a scope in which you are expecting excepti...
Definition: common.h:166
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.
int GetDefaultLineThickness()
Default line thickness used to draw/plot items having a default thickness line value (i...
const wxString & GetFileName() const
virtual bool EndPlot() override
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...
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)
SCH_SCREEN * GetScreen() const override
Function GetScreen returns a pointer to a BASE_SCREEN or one of its derivatives.
Definition: schframe.cpp:521
virtual wxString GetScreenDesc() const override
Definition: schframe.cpp:527
virtual bool StartPlot() override
The code within this function (and the CloseFilePS function) creates postscript files whose contents ...
bool IsPortrait() const
SCH_SHEET * g_RootSheet
Definition: eeschema.cpp:54
virtual void SetDefaultLineWidth(int width) override
Set the default line width.
bool plotOneSheetPS(const wxString &aFileName, SCH_SCREEN *aScreen, const PAGE_INFO &aPageInfo, wxPoint aPlot0ffset, double aScale, bool aPlotFrameRef)
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:566
virtual void SetColor(COLOR4D color) override
The SetColor implementation is split with the subclasses: The PSLIKE computes the rgb values...
Common plot library Plot settings, and plotting engines (Postscript, Gerber, HPGL and DXF) ...
bool SetType(const wxString &aStandardPageDescriptionName, bool IsPortrait=false)
Function SetType sets the name of the page type and also the sizes and margins commonly associated wi...
Class SCH_SHEET_PATH.
void BuildSheetList(SCH_SHEET *aSheet)
Function BuildSheetList builds the list of sheets and their sheet path from aSheet.
int GetWidthMils() const
void SetPortrait(bool isPortrait)
Function SetPortrait will rotate the paper page 90 degrees.
void Plot(PLOTTER *aPlotter)
Function Plot plots all the schematic objects to aPlotter.
Definition: sch_screen.cpp:583
const PAGE_INFO & GetPageSettings() const override
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
void SetSheetNumberAndCount()
Function SetSheetNumberAndCount Set the m_ScreenNumber and m_NumberOfScreens members for screens must...
Definition: schframe.cpp:486
const TITLE_BLOCK & GetTitleBlock() const override
wxString GetUniqueFilenameForCurrentSheet()
Function GetUniqueFilenameForCurrentSheet.
Definition: schframe.cpp:731
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
void createPSFile(bool aPlotAll, bool aPlotFrameRef)
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
int GetHeightMils() const
virtual void SetColorMode(bool _color_mode)
Definition: plot_common.h:116
#define min(a, b)
Definition: auxiliary.h:85