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 <jean-pierre.charras@gipsa-lab.inpg.fr
8  * Copyright (C) 1992-2016 KiCad Developers, see change_log.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 <plot_common.h>
30 #include <class_sch_screen.h>
31 #include <schframe.h>
32 #include <base_units.h>
33 #include <sch_sheet_path.h>
34 #include <project.h>
35 
36 #include <dialog_plot_schematic.h>
37 #include <wx_html_report_panel.h>
38 
51 };
52 
53 
54 static const wxChar* plot_sheet_list( int aSize )
55 {
56  const wxChar* ret;
57 
58  switch( aSize )
59  {
60  default:
61  case PAGE_DEFAULT:
62  ret = NULL; break;
63 
64  case HPGL_PAGE_SIZE_A4:
65  ret = wxT( "A4" ); break;
66 
67  case HPGL_PAGE_SIZE_A3:
68  ret = wxT( "A3" ); break;
69 
70  case HPGL_PAGE_SIZE_A2:
71  ret = wxT( "A2" ); break;
72 
73  case HPGL_PAGE_SIZE_A1:
74  ret = wxT( "A1" ); break;
75 
76  case HPGL_PAGE_SIZE_A0:
77  ret = wxT( "A0" ); break;
78 
79  case HPGL_PAGE_SIZE_A:
80  ret = wxT( "A" ); break;
81 
82  case HPGL_PAGE_SIZE_B:
83  ret = wxT( "B" ); break;
84 
85  case HPGL_PAGE_SIZE_C:
86  ret = wxT( "C" ); break;
87 
88  case HPGL_PAGE_SIZE_D:
89  ret = wxT( "D" ); break;
90 
91  case HPGL_PAGE_SIZE_E:
92  ret = wxT( "E" ); break;
93  }
94 
95  return ret;
96 };
97 
98 
100 {
102 
103  if( m_HPGLPenSize > Millimeter2iu( 2 ) )
104  m_HPGLPenSize = Millimeter2iu( 2 );
105 
106  if( m_HPGLPenSize < Millimeter2iu( 0.01 ) )
107  m_HPGLPenSize = Millimeter2iu( 0.01 );
108 }
109 
110 
111 void DIALOG_PLOT_SCHEMATIC::createHPGLFile( bool aPlotAll, bool aPlotFrameRef )
112 {
113  SCH_SCREEN* screen = m_parent->GetScreen();
114  SCH_SHEET_PATH oldsheetpath = m_parent->GetCurrentSheet();
115 
116  /* When printing all pages, the printed page is not the current page.
117  * In complex hierarchies, we must setup references and other parameters
118  * in the printed SCH_SCREEN
119  * because in complex hierarchies a SCH_SCREEN (a schematic drawings)
120  * is shared between many sheets
121  */
122  SCH_SHEET_LIST sheetList;
123 
124  if( aPlotAll )
125  sheetList.BuildSheetList( g_RootSheet );
126  else
127  sheetList.push_back( m_parent->GetCurrentSheet() );
128 
129  REPORTER& reporter = m_MessagesBox->Reporter();
130 
131  SetHPGLPenWidth();
132 
133  for( unsigned i = 0; i < sheetList.size(); i++ )
134  {
135  m_parent->SetCurrentSheet( sheetList[i] );
138 
139  screen = m_parent->GetCurrentSheet().LastScreen();
140 
141  if( !screen ) // LastScreen() may return NULL
142  screen = m_parent->GetScreen();
143 
144  const PAGE_INFO& curPage = screen->GetPageSettings();
145 
146  PAGE_INFO plotPage = curPage;
147 
148  // if plotting on a page size other than curPage
149  if( m_HPGLPaperSizeOption->GetSelection() != PAGE_DEFAULT )
150  plotPage.SetType( plot_sheet_list( m_HPGLPaperSizeOption->GetSelection() ) );
151 
152  // Calculation of conversion scales.
153  double plot_scale = (double) plotPage.GetWidthMils() / curPage.GetWidthMils();
154 
155  // Calculate offsets
156  wxPoint plotOffset;
157  wxString msg;
158 
159  if( GetPlotOriginCenter() )
160  {
161  plotOffset.x = plotPage.GetWidthIU() / 2;
162  plotOffset.y = -plotPage.GetHeightIU() / 2;
163  }
164 
165  try
166  {
167  wxString fname = m_parent->GetUniqueFilenameForCurrentSheet();
168  wxString ext = HPGL_PLOTTER::GetDefaultFileExtension();
169  wxFileName plotFileName = createPlotFileName( m_outputDirectoryName, fname,
170  ext, &reporter );
171 
172  LOCALE_IO toggle;
173 
174  if( Plot_1_Page_HPGL( plotFileName.GetFullPath(), screen, plotPage, plotOffset,
175  plot_scale, aPlotFrameRef ) )
176  {
177  msg.Printf( _( "Plot: '%s' OK.\n" ), GetChars( plotFileName.GetFullPath() ) );
178  reporter.Report( msg, REPORTER::RPT_ACTION );
179  }
180  else
181  {
182  msg.Printf( _( "Unable to create file '%s'.\n" ),
183  GetChars( plotFileName.GetFullPath() ) );
184  reporter.Report( msg, REPORTER::RPT_ERROR );
185  }
186  }
187  catch( IO_ERROR& e )
188  {
189  msg.Printf( wxT( "HPGL Plotter exception: %s"), GetChars( e.What() ) );
190  reporter.Report( msg, REPORTER::RPT_ERROR );
191  }
192 
193  }
194 
195  m_parent->SetCurrentSheet( oldsheetpath );
198 }
199 
200 
201 bool DIALOG_PLOT_SCHEMATIC::Plot_1_Page_HPGL( const wxString& aFileName,
202  SCH_SCREEN* aScreen,
203  const PAGE_INFO& aPageInfo,
204  wxPoint aPlot0ffset,
205  double aScale,
206  bool aPlotFrameRef )
207 {
208  HPGL_PLOTTER* plotter = new HPGL_PLOTTER();
209 
210  plotter->SetPageSettings( aPageInfo );
211  // Currently, plot units are in decimil
212  plotter->SetViewport( aPlot0ffset, IU_PER_MILS/10, aScale, false );
213 
214  // Init :
215  plotter->SetCreator( wxT( "Eeschema-HPGL" ) );
216 
217  if( ! plotter->OpenFile( aFileName ) )
218  {
219  delete plotter;
220  return false;
221  }
222 
223  LOCALE_IO toggle;
224 
225  // Pen num and pen speed are not initialized here.
226  // Default HPGL driver values are used
227  plotter->SetPenDiameter( m_HPGLPenSize );
228  plotter->StartPlot();
229 
230  plotter->SetColor( BLACK );
231 
232  if( getPlotFrameRef() )
233  PlotWorkSheet( plotter, m_parent->GetTitleBlock(),
235  aScreen->m_ScreenNumber, aScreen->m_NumberOfScreens,
237  aScreen->GetFileName() );
238 
239  aScreen->Plot( plotter );
240 
241  plotter->EndPlot();
242  delete plotter;
243 
244  return true;
245 }
void SetCurrentSheet(const SCH_SHEET_PATH &aSheet)
Definition: schframe.cpp:573
Class SCH_SHEET_LIST.
virtual bool EndPlot() override
HPGL end of plot: pen return and release.
virtual void SetColor(COLOR4D color) override
Definition: plot_common.h:584
virtual void SetCreator(const wxString &aCreator)
Definition: plot_common.h:151
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.
const wxString & GetFileName() const
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)
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.
Definition: schframe.cpp:520
virtual wxString GetScreenDesc() const override
Definition: schframe.cpp:526
void createHPGLFile(bool aPlotAll, bool aPlotFrameRef)
SCH_SHEET * g_RootSheet
Definition: eeschema.cpp:54
static const wxChar * plot_sheet_list(int aSize)
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:565
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 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:384
int GetWidthMils() const
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
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:485
const TITLE_BLOCK & GetTitleBlock() const override
static wxString GetDefaultFileExtension()
Definition: plot_common.h:566
wxString GetUniqueFilenameForCurrentSheet()
Function GetUniqueFilenameForCurrentSheet.
Definition: schframe.cpp:730
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
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