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 <pgm_base.h>
33 #include <project.h>
34 #include <reporter.h>
36 
37 #include <dialog_plot_schematic.h>
38 #include <wx_html_report_panel.h>
39 
40 void DIALOG_PLOT_SCHEMATIC::createPSFile( bool aPlotAll, bool aPlotFrameRef )
41 {
42  SCH_SCREEN* screen = m_parent->GetScreen();
43  SCH_SHEET_PATH oldsheetpath = m_parent->GetCurrentSheet(); // sheetpath is saved here
44  PAGE_INFO actualPage; // page size selected in schematic
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( g_RootSheet );
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  screen = m_parent->GetCurrentSheet().LastScreen();
66  actualPage = screen->GetPageSettings();
67 
68  switch( m_pageSizeSelect )
69  {
70  case PAGE_SIZE_A:
71  plotPage.SetType( wxT( "A" ) );
72  plotPage.SetPortrait( actualPage.IsPortrait() );
73  break;
74 
75  case PAGE_SIZE_A4:
76  plotPage.SetType( wxT( "A4" ) );
77  plotPage.SetPortrait( actualPage.IsPortrait() );
78  break;
79 
80  case PAGE_SIZE_AUTO:
81  default:
82  plotPage = actualPage;
83  break;
84  }
85 
86  double scalex = (double) plotPage.GetWidthMils() / actualPage.GetWidthMils();
87  double scaley = (double) plotPage.GetHeightMils() / actualPage.GetHeightMils();
88 
89  double scale = std::min( scalex, scaley );
90 
91  wxPoint plot_offset;
92 
93  wxString outputDirName = m_outputDirectoryName->GetValue();
94 
95  wxString msg;
96  REPORTER& reporter = m_MessagesBox->Reporter();
97 
98  try
99  {
100  wxString fname = m_parent->GetUniqueFilenameForCurrentSheet();
101  wxString ext = PS_PLOTTER::GetDefaultFileExtension();
102  wxFileName plotFileName = createPlotFileName( m_outputDirectoryName,
103  fname, ext, &reporter );
104 
105  if( plotOneSheetPS( plotFileName.GetFullPath(), screen, plotPage, plot_offset,
106  scale, aPlotFrameRef ) )
107  {
108  msg.Printf( _( "Plot: \"%s\" OK.\n" ), plotFileName.GetFullPath() );
109  reporter.Report( msg, RPT_SEVERITY_ACTION );
110  }
111  else
112  {
113  // Error
114  msg.Printf( _( "Unable to create file \"%s\".\n" ), plotFileName.GetFullPath() );
115  reporter.Report( msg, RPT_SEVERITY_ERROR );
116  }
117 
118  }
119  catch( IO_ERROR& e )
120  {
121  msg.Printf( wxT( "PS Plotter exception: %s"), e.What() );
122  reporter.Report( msg, RPT_SEVERITY_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  auto colors = static_cast<COLOR_SETTINGS*>(
140  m_colorTheme->GetClientData( m_colorTheme->GetSelection() ) );
141 
142  PS_PLOTTER* plotter = new PS_PLOTTER();
143  plotter->SetPageSettings( aPageInfo );
145  plotter->SetColorMode( getModeColor() );
146  plotter->SetColorSettings( colors );
147  // Currently, plot units are in decimil
148  plotter->SetViewport( aPlot0ffset, IU_PER_MILS/10, aScale, false );
149 
150  // Init :
151  plotter->SetCreator( wxT( "Eeschema-PS" ) );
152 
153  if( ! plotter->OpenFile( aFileName ) )
154  {
155  delete plotter;
156  return false;
157  }
158 
159  LOCALE_IO toggle; // Switch the locale to standard C
160 
161  plotter->StartPlot();
162 
164  {
165  plotter->SetColor( plotter->ColorSettings()->GetColor( LAYER_SCHEMATIC_BACKGROUND ) );
166  wxPoint end( plotter->PageSettings().GetWidthIU(),
167  plotter->PageSettings().GetHeightIU() );
168  plotter->Rect( wxPoint( 0, 0 ), end, FILLED_SHAPE, 1.0 );
169  }
170 
171  if( aPlotFrameRef )
172  {
173  COLOR4D color = plotter->GetColorMode() ?
176 
177  PlotWorkSheet( plotter, m_parent->GetTitleBlock(),
179  aScreen->m_ScreenNumber, aScreen->m_NumberOfScreens,
181  aScreen->GetFileName(),
182  color );
183  }
184 
185  aScreen->Plot( plotter );
186 
187  plotter->EndPlot();
188  delete plotter;
189 
190  return true;
191 }
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:412
const wxString & GetFileName() const
Definition: sch_screen.h:157
int m_ScreenNumber
Definition: base_screen.h:135
virtual void SetCreator(const wxString &aCreator)
Definition: plotter.h:180
static wxString GetDefaultFileExtension()
Definition: plotter.h:813
Instantiate the current locale within a scope in which you are expecting exceptions to be thrown.
Definition: common.h:202
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:82
virtual void SetColorMode(bool aColorMode)
Plot in B/W or color.
Definition: plotter.h:133
int color
Definition: DXF_plotter.cpp:61
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:967
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
REPORTER is a pure virtual class used to derive REPORTER objects from.
Definition: reporter.h:62
void UpdateAllScreenReferences()
Function UpdateAllScreenReferences updates the reference and the m_Multi parameter (part selection) f...
const PAGE_INFO & GetPageSettings() const
Definition: sch_screen.h:152
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.
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:813
virtual void SetDefaultLineWidth(int width) override
Set the default line width.
Definition: PS_plotter.cpp:53
virtual const wxString What() const
A composite of Problem() and Where()
Definition: exceptions.cpp:33
COLOR_SETTINGS * ColorSettings()
Definition: plotter.h:145
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.
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
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:60
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:573
const PAGE_INFO & GetPageSettings() const override
COLOR4D GetColor(int aLayer) const
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:580
#define _(s)
Definition: 3d_actions.cpp:33
const TITLE_BLOCK & GetTitleBlock() const override
#define IU_PER_MILS
Definition: plotter.cpp:137
void SetColorSettings(COLOR_SETTINGS *aSettings)
Definition: plotter.h:143
wxString GetUniqueFilenameForCurrentSheet()
int m_NumberOfScreens
Definition: base_screen.h:136
SCH_SHEET * g_RootSheet
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.
PAGE_INFO & PageSettings()
Definition: plotter.h:152
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
static VRML_COLOR colors[VRML_COLOR_LAST]
int GetWidthMils() const
Definition: page_info.h:137
virtual void SetPageSettings(const PAGE_INFO &aPageSettings)
Definition: plotter.h:147
COLOR4D is the color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:40
bool GetColorMode() const
Definition: plotter.h:138