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-2020 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 <pgm_base.h>
33 #include <project.h>
34 #include <reporter.h>
36 #include <sch_painter.h>
37 #include <schematic.h>
38 #include <dialog_plot_schematic.h>
39 #include <wx_html_report_panel.h>
40 
41 void DIALOG_PLOT_SCHEMATIC::createPSFile( bool aPlotAll, bool aPlotFrameRef,
42  RENDER_SETTINGS* aRenderSettings )
43 {
44  SCH_SHEET_PATH oldsheetpath = m_parent->GetCurrentSheet(); // sheetpath is saved here
45  PAGE_INFO plotPage; // page size selected to plot
46 
47  /* When printing all pages, the printed page is not the current page.
48  * In complex hierarchies, we must update component references
49  * and others parameters in the given printed SCH_SCREEN, accordint to the sheet path
50  * because in complex hierarchies a SCH_SCREEN (a drawing )
51  * is shared between many sheets and component references depend on the actual sheet path used
52  */
53  SCH_SHEET_LIST sheetList;
54 
55  if( aPlotAll )
56  sheetList.BuildSheetList( &m_parent->Schematic().Root() );
57  else
58  sheetList.push_back( m_parent->GetCurrentSheet() );
59 
60  for( unsigned i = 0; i < sheetList.size(); i++ )
61  {
62  m_parent->SetCurrentSheet( sheetList[i] );
65 
67  PAGE_INFO actualPage = screen->GetPageSettings();
68 
69  switch( m_pageSizeSelect )
70  {
71  case PAGE_SIZE_A:
72  plotPage.SetType( wxT( "A" ) );
73  plotPage.SetPortrait( actualPage.IsPortrait() );
74  break;
75 
76  case PAGE_SIZE_A4:
77  plotPage.SetType( wxT( "A4" ) );
78  plotPage.SetPortrait( actualPage.IsPortrait() );
79  break;
80 
81  case PAGE_SIZE_AUTO:
82  default:
83  plotPage = actualPage;
84  break;
85  }
86 
87  double scalex = (double) plotPage.GetWidthMils() / actualPage.GetWidthMils();
88  double scaley = (double) plotPage.GetHeightMils() / actualPage.GetHeightMils();
89 
90  double scale = std::min( scalex, scaley );
91 
92  wxPoint plot_offset;
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( fname, ext, &reporter );
102 
103  if( plotOneSheetPS( plotFileName.GetFullPath(), screen, aRenderSettings, plotPage,
104  plot_offset, scale, aPlotFrameRef ) )
105  {
106  msg.Printf( _( "Plot: \"%s\" OK.\n" ), plotFileName.GetFullPath() );
107  reporter.Report( msg, RPT_SEVERITY_ACTION );
108  }
109  else
110  {
111  // Error
112  msg.Printf( _( "Unable to create file \"%s\".\n" ), plotFileName.GetFullPath() );
113  reporter.Report( msg, RPT_SEVERITY_ERROR );
114  }
115 
116  }
117  catch( IO_ERROR& e )
118  {
119  msg.Printf( wxT( "PS Plotter exception: %s"), e.What() );
120  reporter.Report( msg, RPT_SEVERITY_ERROR );
121  }
122  }
123 
124  m_parent->SetCurrentSheet( oldsheetpath );
127 }
128 
129 
130 bool DIALOG_PLOT_SCHEMATIC::plotOneSheetPS( const wxString& aFileName,
131  SCH_SCREEN* aScreen,
132  RENDER_SETTINGS* aRenderSettings,
133  const PAGE_INFO& aPageInfo,
134  wxPoint aPlot0ffset,
135  double aScale,
136  bool aPlotFrameRef )
137 {
138  PS_PLOTTER* plotter = new PS_PLOTTER();
139  plotter->SetRenderSettings( aRenderSettings );
140  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( m_plotBackgroundColor->GetValue() )
159  {
161  wxPoint end( plotter->PageSettings().GetWidthIU(),
162  plotter->PageSettings().GetHeightIU() );
163  plotter->Rect( wxPoint( 0, 0 ), end, FILLED_SHAPE, 1.0 );
164  }
165 
166  if( aPlotFrameRef )
167  {
168  PlotWorkSheet( plotter, &aScreen->Schematic()->Prj(), m_parent->GetTitleBlock(), aPageInfo,
169  aScreen->m_ScreenNumber, aScreen->m_NumberOfScreens,
170  m_parent->GetScreenDesc(), aScreen->GetFileName(),
171  plotter->GetColorMode() ?
173  COLOR4D::BLACK );
174  }
175 
176  aScreen->Plot( plotter );
177 
178  plotter->EndPlot();
179  delete plotter;
180 
181  return true;
182 }
void SetCurrentSheet(const SCH_SHEET_PATH &aSheet)
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:404
const wxString & GetFileName() const
Definition: sch_screen.h:189
int m_ScreenNumber
Definition: base_screen.h:85
virtual void SetCreator(const wxString &aCreator)
Definition: plotter.h:164
static wxString GetDefaultFileExtension()
Definition: plotter.h:798
Instantiate the current locale within a scope in which you are expecting exceptions to be thrown.
Definition: common.h:216
RENDER_SETTINGS Contains all the knowledge about how graphical objects are drawn on any output surfac...
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:77
virtual void SetColorMode(bool aColorMode)
Plot in B/W or color.
Definition: plotter.h:143
virtual bool EndPlot() override
Definition: PS_plotter.cpp:961
void SetRenderSettings(RENDER_SETTINGS *aSettings)
Definition: plotter.h:146
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
const COLOR4D & GetLayerColor(int aLayer) const
Function GetLayerColor Returns the color used to draw a layer.
Definition: color4d.h:44
REPORTER is a pure virtual class used to derive REPORTER objects from.
Definition: reporter.h:64
void UpdateAllScreenReferences()
Function UpdateAllScreenReferences updates the reference and the m_Multi parameter (part selection) f...
const PAGE_INFO & GetPageSettings() const
Definition: sch_screen.h:184
virtual REPORTER & Report(const wxString &aText, SEVERITY aSeverity=RPT_SEVERITY_UNDEFINED)=0
Function Report is a pure virtual function to override in the derived object.
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:807
virtual const wxString What() const
A composite of Problem() and Where()
Definition: exceptions.cpp:33
void PlotWorkSheet(PLOTTER *plotter, const PROJECT *aProject, const TITLE_BLOCK &aTitleBlock, const PAGE_INFO &aPageInfo, int aSheetNumber, int aNumberOfSheets, const wxString &aSheetDesc, const wxString &aFilename, COLOR4D aColor)
bool plotOneSheetPS(const wxString &aFileName, SCH_SCREEN *aScreen, RENDER_SETTINGS *aRenderSettings, const PAGE_INFO &aPageInfo, wxPoint aPlot0ffset, double aScale, bool aPlotFrameRef)
PAGE_INFO describes the page size and margins of a paper page on which to eventually print or plot.
Definition: page_info.h:54
REPORTER & Reporter()
returns the reporter object that reports to this panel
virtual void SetColor(COLOR4D color) override
The SetColor implementation is split with the subclasses: The PSLIKE computes the rgb values,...
Definition: PS_plotter.cpp:52
SCHEMATIC & Schematic() const
SCH_SHEET_PATH.
void createPSFile(bool aPlotAll, bool aPlotFrameRef, RENDER_SETTINGS *aSettings)
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:751
SCH_SHEET & Root() const
Definition: schematic.h:97
RENDER_SETTINGS * RenderSettings()
Definition: plotter.h:147
const int scale
see class PGM_BASE
SCH_SCREEN * LastScreen()
Function LastScreen.
void SetSheetNumberAndCount()
Set the m_ScreenNumber and m_NumberOfScreens members for screens.
bool IsPortrait() const
Definition: page_info.h:121
virtual void Rect(const wxPoint &p1, const wxPoint &p2, FILL_T fill, int width=USE_DEFAULT_LINE_WIDTH) override
Definition: PS_plotter.cpp:574
#define _(s)
Definition: 3d_actions.cpp:33
SCHEMATIC * Schematic() const
Definition: sch_screen.cpp:93
const TITLE_BLOCK & GetTitleBlock() const override
PROJECT & Prj() const
Return a reference to the project this schematic is part of.
Definition: schematic.h:77
#define IU_PER_MILS
Definition: plotter.cpp:138
wxString GetUniqueFilenameForCurrentSheet()
int m_NumberOfScreens
Definition: base_screen.h:86
SCH_SHEET_PATH & GetCurrentSheet() const
WX_HTML_REPORT_PANEL * m_MessagesBox
Definition of the SCH_SHEET_PATH and SCH_SHEET_LIST classes for Eeschema.
PAGE_INFO & PageSettings()
Definition: plotter.h:150
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
wxFileName createPlotFileName(wxString &aPlotFileName, wxString &aExtension, REPORTER *aReporter=NULL)
Create a file name with an absolute path name.
int GetWidthMils() const
Definition: page_info.h:137
virtual void SetPageSettings(const PAGE_INFO &aPageSettings)
Definition: plotter.h:149
bool GetColorMode() const
Definition: plotter.h:144