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 <plotter.h>
29 #include <sch_edit_frame.h>
30 #include <base_units.h>
31 #include <sch_sheet_path.h>
32 #include <project.h>
33 #include <reporter.h>
34 
35 #include <dialog_plot_schematic.h>
36 #include <wx_html_report_panel.h>
37 
38 void DIALOG_PLOT_SCHEMATIC::createPSFile( bool aPlotAll, bool aPlotFrameRef )
39 {
40  SCH_SCREEN* screen = m_parent->GetScreen();
41  SCH_SHEET_PATH oldsheetpath = m_parent->GetCurrentSheet(); // sheetpath is saved here
42  PAGE_INFO actualPage; // page size selected in schematic
43  PAGE_INFO plotPage; // page size selected to plot
44 
45  /* When printing all pages, the printed page is not the current page.
46  * In complex hierarchies, we must update component references
47  * and others parameters in the given printed SCH_SCREEN, accordint to the sheet path
48  * because in complex hierarchies a SCH_SCREEN (a drawing )
49  * is shared between many sheets and component references depend on the actual sheet path used
50  */
51  SCH_SHEET_LIST sheetList;
52 
53  if( aPlotAll )
54  sheetList.BuildSheetList( g_RootSheet );
55  else
56  sheetList.push_back( m_parent->GetCurrentSheet() );
57 
58  for( unsigned i = 0; i < sheetList.size(); i++ )
59  {
60  m_parent->SetCurrentSheet( sheetList[i] );
63  screen = m_parent->GetCurrentSheet().LastScreen();
64  actualPage = screen->GetPageSettings();
65 
66  switch( m_pageSizeSelect )
67  {
68  case PAGE_SIZE_A:
69  plotPage.SetType( wxT( "A" ) );
70  plotPage.SetPortrait( actualPage.IsPortrait() );
71  break;
72 
73  case PAGE_SIZE_A4:
74  plotPage.SetType( wxT( "A4" ) );
75  plotPage.SetPortrait( actualPage.IsPortrait() );
76  break;
77 
78  case PAGE_SIZE_AUTO:
79  default:
80  plotPage = actualPage;
81  break;
82  }
83 
84  double scalex = (double) plotPage.GetWidthMils() / actualPage.GetWidthMils();
85  double scaley = (double) plotPage.GetHeightMils() / actualPage.GetHeightMils();
86 
87  double scale = std::min( scalex, scaley );
88 
89  wxPoint plot_offset;
90 
91  wxString outputDirName = m_outputDirectoryName->GetValue();
92 
93  wxString msg;
94  REPORTER& reporter = m_MessagesBox->Reporter();
95 
96  try
97  {
98  wxString fname = m_parent->GetUniqueFilenameForCurrentSheet();
99  wxString ext = PS_PLOTTER::GetDefaultFileExtension();
100  wxFileName plotFileName = createPlotFileName( m_outputDirectoryName,
101  fname, ext, &reporter );
102 
103  if( plotOneSheetPS( plotFileName.GetFullPath(), screen, plotPage, plot_offset,
104  scale, aPlotFrameRef ) )
105  {
106  msg.Printf( _( "Plot: \"%s\" OK.\n" ), GetChars( plotFileName.GetFullPath() ) );
107  reporter.Report( msg, REPORTER::RPT_ACTION );
108  }
109  else
110  {
111  // Error
112  msg.Printf( _( "Unable to create file \"%s\".\n" ),
113  GetChars( plotFileName.GetFullPath() ) );
114  reporter.Report( msg, REPORTER::RPT_ERROR );
115  }
116 
117  }
118  catch( IO_ERROR& e )
119  {
120  msg.Printf( wxT( "PS Plotter exception: %s"), GetChars( e.What() ) );
121  reporter.Report( msg, REPORTER::RPT_ERROR );
122  }
123  }
124 
125  m_parent->SetCurrentSheet( oldsheetpath );
128 }
129 
130 
131 bool DIALOG_PLOT_SCHEMATIC::plotOneSheetPS( const wxString& aFileName,
132  SCH_SCREEN* aScreen,
133  const PAGE_INFO& aPageInfo,
134  wxPoint aPlot0ffset,
135  double aScale,
136  bool aPlotFrameRef )
137 {
138  PS_PLOTTER* plotter = new PS_PLOTTER();
139  plotter->SetPageSettings( aPageInfo );
141  plotter->SetColorMode( getModeColor() );
142  // Currently, plot units are in decimil
143  plotter->SetViewport( aPlot0ffset, IU_PER_MILS/10, aScale, false );
144 
145  // Init :
146  plotter->SetCreator( wxT( "Eeschema-PS" ) );
147 
148  if( ! plotter->OpenFile( aFileName ) )
149  {
150  delete plotter;
151  return false;
152  }
153 
154  LOCALE_IO toggle; // Switch the locale to standard C
155 
156  plotter->StartPlot();
157 
158  if( aPlotFrameRef )
159  {
160  plotter->SetColor( BLACK );
161  PlotWorkSheet( plotter, m_parent->GetTitleBlock(),
163  aScreen->m_ScreenNumber, aScreen->m_NumberOfScreens,
165  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)
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.
Definition: PS_plotter.cpp:410
const wxString & GetFileName() const
Definition: sch_screen.h:123
int m_ScreenNumber
Definition: base_screen.h:135
virtual void SetCreator(const wxString &aCreator)
Definition: plotter.h:161
static wxString GetDefaultFileExtension()
Definition: plotter.h:782
Instantiate the current locale within a scope in which you are expecting exceptions to be thrown.
Definition: common.h:154
Implementation of conversion functions that require both schematic and board internal units.
int GetHeightMils() const
Definition: page_info.h:140
virtual bool OpenFile(const wxString &aFullFilename)
Open or create the plot file aFullFilename.
Definition: plotter.cpp:80
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....
virtual bool EndPlot() override
Definition: PS_plotter.cpp:965
bool SetType(const wxString &aStandardPageDescriptionName, bool aIsPortrait=false)
Function SetType sets the name of the page type and also the sizes and margins commonly associated wi...
Definition: page_info.cpp:117
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...
COLOR4D GetLayerColor(SCH_LAYER_ID aLayer)
Definition: eeschema.cpp:160
virtual void SetPageSettings(const PAGE_INFO &aPageSettings)
Definition: plotter.cpp:560
const PAGE_INFO & GetPageSettings() const
Definition: sch_screen.h:118
void PlotWorkSheet(PLOTTER *plotter, const TITLE_BLOCK &aTitleBlock, const PAGE_INFO &aPageInfo, int aSheetNumber, int aNumberOfSheets, const wxString &aSheetDesc, const wxString &aFilename, const COLOR4D aColor)
SCH_SCREEN * GetScreen() const override
Return a pointer to a BASE_SCREEN or one of its derivatives.
wxString GetScreenDesc() const override
Return a human-readable description of the current screen.
virtual bool StartPlot() override
The code within this function (and the CloseFilePS function) creates postscript files whose contents ...
Definition: PS_plotter.cpp:811
SCH_SHEET * g_RootSheet
Definition: eeschema.cpp:47
virtual void SetDefaultLineWidth(int width) override
Set the default line width.
Definition: PS_plotter.cpp:52
virtual const wxString What() const
A composite of Problem() and Where()
Definition: exceptions.cpp:33
bool plotOneSheetPS(const wxString &aFileName, SCH_SCREEN *aScreen, const PAGE_INFO &aPageInfo, wxPoint aPlot0ffset, double aScale, bool aPlotFrameRef)
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:54
REPORTER & Reporter()
returns the reporter object that reports to this panel
SCH_SHEET_PATH & GetCurrentSheet()
virtual void SetColor(COLOR4D color) override
The SetColor implementation is split with the subclasses: The PSLIKE computes the rgb values,...
Definition: PS_plotter.cpp:59
SCH_LAYER_ID
Eeschema drawing layers.
Class SCH_SHEET_PATH.
void BuildSheetList(SCH_SHEET *aSheet)
Function BuildSheetList builds the list of sheets and their sheet path from aSheet.
#define _(s)
void Plot(PLOTTER *aPlotter)
Plot all the schematic objects to aPlotter.
Definition: sch_screen.cpp:550
const PAGE_INFO & GetPageSettings() const override
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:101
void SetSheetNumberAndCount()
Set the m_ScreenNumber and m_NumberOfScreens members for screens.
bool IsPortrait() const
Definition: page_info.h:121
const TITLE_BLOCK & GetTitleBlock() const override
size_t i
Definition: json11.cpp:597
#define IU_PER_MILS
Definition: plotter.cpp:135
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:136
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.
void SetPortrait(bool aIsPortrait)
Function SetPortrait will rotate the paper page 90 degrees.
Definition: page_info.cpp:182
Struct IO_ERROR is a class used to hold an error message and may be used when throwing exceptions con...
Definition: ki_exception.h:76
SCH_SCREEN * LastScreen() const
Function LastScreen.
int GetWidthMils() const
Definition: page_info.h:137
#define min(a, b)
Definition: auxiliary.h:85