KiCad PCB EDA Suite
plot_schematic_HPGL.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-2010 Jean-Pierre Charras jp.charras at wanadoo.fr
8  * Copyright (C) 1992-2017 KiCad Developers, see AUTHORS.txt for contributors.
9  *
10  * This program is free software; you can redistribute it and/or
11  * modify it under the terms of the GNU General Public License
12  * as published by the Free Software Foundation; either version 2
13  * of the License, or (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program; if not, you may find one here:
22  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
23  * or you may search the http://www.gnu.org website for the version 2 license,
24  * or you may write to the Free Software Foundation, Inc.,
25  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
26  */
27 
28 #include <fctsys.h>
29 #include <plotter.h>
30 #include <sch_edit_frame.h>
31 #include <base_units.h>
32 #include <sch_sheet_path.h>
33 #include <project.h>
34 
35 #include <dialog_plot_schematic.h>
36 #include <wx_html_report_panel.h>
37 
50 };
51 
52 
53 static const wxChar* plot_sheet_list( int aSize )
54 {
55  const wxChar* ret;
56 
57  switch( aSize )
58  {
59  default:
60  case PAGE_DEFAULT:
61  ret = NULL; break;
62 
63  case HPGL_PAGE_SIZE_A4:
64  ret = wxT( "A4" ); break;
65 
66  case HPGL_PAGE_SIZE_A3:
67  ret = wxT( "A3" ); break;
68 
69  case HPGL_PAGE_SIZE_A2:
70  ret = wxT( "A2" ); break;
71 
72  case HPGL_PAGE_SIZE_A1:
73  ret = wxT( "A1" ); break;
74 
75  case HPGL_PAGE_SIZE_A0:
76  ret = wxT( "A0" ); break;
77 
78  case HPGL_PAGE_SIZE_A:
79  ret = wxT( "A" ); break;
80 
81  case HPGL_PAGE_SIZE_B:
82  ret = wxT( "B" ); break;
83 
84  case HPGL_PAGE_SIZE_C:
85  ret = wxT( "C" ); break;
86 
87  case HPGL_PAGE_SIZE_D:
88  ret = wxT( "D" ); break;
89 
90  case HPGL_PAGE_SIZE_E:
91  ret = wxT( "E" ); break;
92  }
93 
94  return ret;
95 }
96 
97 
99 {
101 
102  if( m_HPGLPenSize > Millimeter2iu( 2 ) )
103  m_HPGLPenSize = Millimeter2iu( 2 );
104 
105  if( m_HPGLPenSize < Millimeter2iu( 0.01 ) )
106  m_HPGLPenSize = Millimeter2iu( 0.01 );
107 }
108 
109 
110 void DIALOG_PLOT_SCHEMATIC::createHPGLFile( bool aPlotAll, bool aPlotFrameRef )
111 {
112  SCH_SCREEN* screen = m_parent->GetScreen();
113  SCH_SHEET_PATH oldsheetpath = m_parent->GetCurrentSheet();
114 
115  /* When printing all pages, the printed page is not the current page.
116  * In complex hierarchies, we must setup references and other parameters
117  * in the printed SCH_SCREEN
118  * because in complex hierarchies a SCH_SCREEN (a schematic drawings)
119  * is shared between many sheets
120  */
121  SCH_SHEET_LIST sheetList;
122 
123  if( aPlotAll )
124  sheetList.BuildSheetList( g_RootSheet );
125  else
126  sheetList.push_back( m_parent->GetCurrentSheet() );
127 
128  REPORTER& reporter = m_MessagesBox->Reporter();
129 
130  SetHPGLPenWidth();
131 
132  for( unsigned i = 0; i < sheetList.size(); i++ )
133  {
134  m_parent->SetCurrentSheet( sheetList[i] );
137 
138  screen = m_parent->GetCurrentSheet().LastScreen();
139 
140  if( !screen ) // LastScreen() may return NULL
141  screen = m_parent->GetScreen();
142 
143  const PAGE_INFO& curPage = screen->GetPageSettings();
144 
145  PAGE_INFO plotPage = curPage;
146 
147  // if plotting on a page size other than curPage
148  if( m_HPGLPaperSizeOption->GetSelection() != PAGE_DEFAULT )
149  plotPage.SetType( plot_sheet_list( m_HPGLPaperSizeOption->GetSelection() ) );
150 
151  // Calculation of conversion scales.
152  double plot_scale = (double) plotPage.GetWidthMils() / curPage.GetWidthMils();
153 
154  // Calculate offsets
155  wxPoint plotOffset;
156  wxString msg;
157 
158  if( GetPlotOriginCenter() )
159  {
160  plotOffset.x = plotPage.GetWidthIU() / 2;
161  plotOffset.y = -plotPage.GetHeightIU() / 2;
162  }
163 
164  try
165  {
166  wxString fname = m_parent->GetUniqueFilenameForCurrentSheet();
167  wxString ext = HPGL_PLOTTER::GetDefaultFileExtension();
168  wxFileName plotFileName = createPlotFileName( m_outputDirectoryName, fname,
169  ext, &reporter );
170 
171  LOCALE_IO toggle;
172 
173  if( Plot_1_Page_HPGL( plotFileName.GetFullPath(), screen, plotPage, plotOffset,
174  plot_scale, aPlotFrameRef ) )
175  {
176  msg.Printf( _( "Plot: \"%s\" OK.\n" ), GetChars( plotFileName.GetFullPath() ) );
177  reporter.Report( msg, REPORTER::RPT_ACTION );
178  }
179  else
180  {
181  msg.Printf( _( "Unable to create file \"%s\".\n" ),
182  GetChars( plotFileName.GetFullPath() ) );
183  reporter.Report( msg, REPORTER::RPT_ERROR );
184  }
185  }
186  catch( IO_ERROR& e )
187  {
188  msg.Printf( wxT( "HPGL Plotter exception: %s"), GetChars( e.What() ) );
189  reporter.Report( msg, REPORTER::RPT_ERROR );
190  }
191 
192  }
193 
194  m_parent->SetCurrentSheet( oldsheetpath );
197 }
198 
199 
200 bool DIALOG_PLOT_SCHEMATIC::Plot_1_Page_HPGL( const wxString& aFileName,
201  SCH_SCREEN* aScreen,
202  const PAGE_INFO& aPageInfo,
203  wxPoint aPlot0ffset,
204  double aScale,
205  bool aPlotFrameRef )
206 {
207  HPGL_PLOTTER* plotter = new HPGL_PLOTTER();
208 
209  plotter->SetPageSettings( aPageInfo );
210  // Currently, plot units are in decimil
211  plotter->SetViewport( aPlot0ffset, IU_PER_MILS/10, aScale, false );
212 
213  // Init :
214  plotter->SetCreator( wxT( "Eeschema-HPGL" ) );
215 
216  if( ! plotter->OpenFile( aFileName ) )
217  {
218  delete plotter;
219  return false;
220  }
221 
222  LOCALE_IO toggle;
223 
224  // Pen num and pen speed are not initialized here.
225  // Default HPGL driver values are used
226  plotter->SetPenDiameter( m_HPGLPenSize );
227  plotter->StartPlot();
228 
229  plotter->SetColor( BLACK );
230 
231  if( getPlotFrameRef() )
232  PlotWorkSheet( plotter, m_parent->GetTitleBlock(),
234  aScreen->m_ScreenNumber, aScreen->m_NumberOfScreens,
236  aScreen->GetFileName() );
237 
238  aScreen->Plot( plotter );
239 
240  plotter->EndPlot();
241  delete plotter;
242 
243  return true;
244 }
void SetCurrentSheet(const SCH_SHEET_PATH &aSheet)
Class SCH_SHEET_LIST.
virtual bool EndPlot() override
HPGL end of plot: pen return and release.
virtual void SetColor(COLOR4D color) override
Definition: plotter.h:603
int m_ScreenNumber
Definition: base_screen.h:216
virtual void SetCreator(const wxString &aCreator)
Definition: plotter.h:160
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.
Definition: plotter.cpp:82
const wxString & GetFileName() const
Definition: sch_screen.h:120
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
virtual void SetPenDiameter(double diameter)
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)
Definition: plotter.cpp:538
virtual bool StartPlot() override
At the start of the HPGL plot pen speed and number are requested.
void PlotWorkSheet(PLOTTER *plotter, const TITLE_BLOCK &aTitleBlock, const PAGE_INFO &aPageInfo, int aSheetNumber, int aNumberOfSheets, const wxString &aSheetDesc, const wxString &aFilename)
virtual void SetViewport(const wxPoint &aOffset, double aIusPerDecimil, double aScale, bool aMirror) override
Set the plot offset and scaling for the current plot.
SCH_SCREEN * GetScreen() const override
Function GetScreen returns a pointer to a BASE_SCREEN or one of its derivatives.
virtual wxString GetScreenDesc() const override
void createHPGLFile(bool aPlotAll, bool aPlotFrameRef)
SCH_SHEET * g_RootSheet
Definition: eeschema.cpp:55
static const wxChar * plot_sheet_list(int aSize)
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:49
REPORTER & Reporter()
returns the reporter object that reports to this panel
SCH_SHEET_PATH & GetCurrentSheet()
Class SCH_SHEET_PATH.
void BuildSheetList(SCH_SHEET *aSheet)
Function BuildSheetList builds the list of sheets and their sheet path from aSheet.
int ValueFromTextCtrl(const wxTextCtrl &aTextCtr)
Convert the number Value in a string according to the internal units and the selected unit (g_UserUni...
Definition: base_units.cpp:386
int GetWidthMils() const
Definition: page_info.h:132
void Plot(PLOTTER *aPlotter)
Plot all the schematic objects to aPlotter.
Definition: sch_screen.cpp:554
const PAGE_INFO & GetPageSettings() const override
virtual const wxString What() const
A composite of Problem() and Where()
Definition: exceptions.cpp:33
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()
Set the m_ScreenNumber and m_NumberOfScreens members for screens.
const TITLE_BLOCK & GetTitleBlock() const override
size_t i
Definition: json11.cpp:597
static wxString GetDefaultFileExtension()
Definition: plotter.h:585
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:217
const PAGE_INFO & GetPageSettings() const
Definition: sch_screen.h:115
bool Plot_1_Page_HPGL(const wxString &aFileName, SCH_SCREEN *aScreen, const PAGE_INFO &aPageInfo, wxPoint aPlot0ffset, double aScale, 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