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-2020 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 <schematic.h>
34 #include <project.h>
35 #include <pgm_base.h>
37 
38 #include <dialog_plot_schematic.h>
39 #include <wx_html_report_panel.h>
40 
53 };
54 
55 
56 static const wxChar* plot_sheet_list( int aSize )
57 {
58  switch( aSize )
59  {
60  default:
61  case PAGE_DEFAULT: return nullptr;
62  case HPGL_PAGE_SIZE_A4: return wxT( "A4" );
63  case HPGL_PAGE_SIZE_A3: return wxT( "A3" );
64  case HPGL_PAGE_SIZE_A2: return wxT( "A2" );
65  case HPGL_PAGE_SIZE_A1: return wxT( "A1" );
66  case HPGL_PAGE_SIZE_A0: return wxT( "A0" );
67  case HPGL_PAGE_SIZE_A: return wxT( "A" );
68  case HPGL_PAGE_SIZE_B: return wxT( "B" );
69  case HPGL_PAGE_SIZE_C: return wxT( "C" );
70  case HPGL_PAGE_SIZE_D: return wxT( "D" );
71  case HPGL_PAGE_SIZE_E: return wxT( "E" );
72  }
73 }
74 
75 
77 {
79 
80  if( m_HPGLPenSize > Millimeter2iu( 2 ) )
81  m_HPGLPenSize = Millimeter2iu( 2 );
82 
83  if( m_HPGLPenSize < Millimeter2iu( 0.01 ) )
84  m_HPGLPenSize = Millimeter2iu( 0.01 );
85 }
86 
87 
88 void DIALOG_PLOT_SCHEMATIC::createHPGLFile( bool aPlotAll, bool aPlotFrameRef,
89  RENDER_SETTINGS* aRenderSettings )
90 {
91  SCH_SCREEN* screen = m_parent->GetScreen();
92  SCH_SHEET_PATH oldsheetpath = m_parent->GetCurrentSheet();
93 
94  /* When printing all pages, the printed page is not the current page.
95  * In complex hierarchies, we must setup references and other parameters
96  * in the printed SCH_SCREEN
97  * because in complex hierarchies a SCH_SCREEN (a schematic drawings)
98  * is shared between many sheets
99  */
100  SCH_SHEET_LIST sheetList;
101 
102  if( aPlotAll )
103  sheetList.BuildSheetList( &m_parent->Schematic().Root() );
104  else
105  sheetList.push_back( m_parent->GetCurrentSheet() );
106 
107  REPORTER& reporter = m_MessagesBox->Reporter();
108 
109  SetHPGLPenWidth();
110 
111  for( unsigned i = 0; i < sheetList.size(); i++ )
112  {
113  m_parent->SetCurrentSheet( sheetList[i] );
116 
117  screen = m_parent->GetCurrentSheet().LastScreen();
118 
119  if( !screen ) // LastScreen() may return NULL
120  screen = m_parent->GetScreen();
121 
122  const PAGE_INFO& curPage = screen->GetPageSettings();
123 
124  PAGE_INFO plotPage = curPage;
125 
126  // if plotting on a page size other than curPage
127  if( m_paperSizeOption->GetSelection() != PAGE_DEFAULT )
128  plotPage.SetType( plot_sheet_list( m_paperSizeOption->GetSelection() ) );
129 
130  // Calculation of conversion scales.
131  double plot_scale = (double) plotPage.GetWidthMils() / curPage.GetWidthMils();
132 
133  // Calculate offsets
134  wxPoint plotOffset;
135  wxString msg;
136 
137  if( GetPlotOriginCenter() )
138  {
139  plotOffset.x = plotPage.GetWidthIU() / 2;
140  plotOffset.y = -plotPage.GetHeightIU() / 2;
141  }
142 
143  try
144  {
145  wxString fname = m_parent->GetUniqueFilenameForCurrentSheet();
146  wxString ext = HPGL_PLOTTER::GetDefaultFileExtension();
147  wxFileName plotFileName = createPlotFileName( fname, ext, &reporter );
148 
149  LOCALE_IO toggle;
150 
151  if( Plot_1_Page_HPGL( plotFileName.GetFullPath(), screen, plotPage, aRenderSettings,
152  plotOffset, plot_scale, aPlotFrameRef ) )
153  {
154  msg.Printf( _( "Plot: \"%s\" OK.\n" ), plotFileName.GetFullPath() );
155  reporter.Report( msg, RPT_SEVERITY_ACTION );
156  }
157  else
158  {
159  msg.Printf( _( "Unable to create file \"%s\".\n" ), plotFileName.GetFullPath() );
160  reporter.Report( msg, RPT_SEVERITY_ERROR );
161  }
162  }
163  catch( IO_ERROR& e )
164  {
165  msg.Printf( wxT( "HPGL Plotter exception: %s"), e.What() );
166  reporter.Report( msg, RPT_SEVERITY_ERROR );
167  }
168 
169  }
170 
171  m_parent->SetCurrentSheet( oldsheetpath );
174 }
175 
176 
177 bool DIALOG_PLOT_SCHEMATIC::Plot_1_Page_HPGL( const wxString& aFileName,
178  SCH_SCREEN* aScreen,
179  const PAGE_INFO& aPageInfo,
180  RENDER_SETTINGS* aRenderSettings,
181  wxPoint aPlot0ffset,
182  double aScale,
183  bool aPlotFrameRef )
184 {
185  HPGL_PLOTTER* plotter = new HPGL_PLOTTER();
186  // Currently, plot units are in decimil
187 
188  plotter->SetPageSettings( aPageInfo );
189  plotter->SetRenderSettings( aRenderSettings );
190  plotter->RenderSettings()->LoadColors( getColorSettings() );
191  plotter->SetColorMode( getModeColor() );
192  plotter->SetViewport( aPlot0ffset, IU_PER_MILS/10, aScale, false );
193 
194  // Init :
195  plotter->SetCreator( wxT( "Eeschema-HPGL" ) );
196 
197  if( ! plotter->OpenFile( aFileName ) )
198  {
199  delete plotter;
200  return false;
201  }
202 
203  LOCALE_IO toggle;
204 
205  // Pen num and pen speed are not initialized here.
206  // Default HPGL driver values are used
207  plotter->SetPenDiameter( m_HPGLPenSize );
208  plotter->StartPlot();
209 
210  if( aPlotFrameRef )
211  {
212  PlotWorkSheet( plotter, &m_parent->Prj(), m_parent->GetTitleBlock(), aPageInfo,
213  aScreen->m_ScreenNumber, aScreen->m_NumberOfScreens,
215  }
216 
217  aScreen->Plot( plotter );
218 
219  plotter->EndPlot();
220  delete plotter;
221 
222  return true;
223 }
void SetCurrentSheet(const SCH_SHEET_PATH &aSheet)
SCH_SHEET_LIST.
virtual bool EndPlot() override
HPGL end of plot: pen return and release.
const wxString & GetFileName() const
Definition: sch_screen.h:185
int m_ScreenNumber
Definition: base_screen.h:85
virtual void SetCreator(const wxString &aCreator)
Definition: plotter.h:164
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.
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
bool Plot_1_Page_HPGL(const wxString &aFileName, SCH_SCREEN *aScreen, const PAGE_INFO &aPageInfo, RENDER_SETTINGS *aRenderSettings, wxPoint aPlot0ffset, double aScale, bool aPlotFrameRef)
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
virtual void SetPenDiameter(double diameter)
COLOR_SETTINGS * getColorSettings()
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:180
virtual bool StartPlot() override
At the start of the HPGL plot pen speed and number are requested.
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.
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
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.
static const wxChar * plot_sheet_list(int aSize)
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)
PROJECT & Prj() const
Function Prj returns a reference to the PROJECT "associated with" this KIWAY.
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
SCHEMATIC & Schematic() const
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:751
SCH_SHEET & Root() const
Definition: schematic.h:97
RENDER_SETTINGS * RenderSettings()
Definition: plotter.h:147
see class PGM_BASE
SCH_SCREEN * LastScreen()
Function LastScreen.
void SetSheetNumberAndCount()
Set the m_ScreenNumber and m_NumberOfScreens members for screens.
#define _(s)
Definition: 3d_actions.cpp:33
const TITLE_BLOCK & GetTitleBlock() const override
static wxString GetDefaultFileExtension()
Definition: plotter.h:617
#define IU_PER_MILS
Definition: plotter.cpp:138
wxString GetUniqueFilenameForCurrentSheet()
virtual long long int GetValue()
Function GetValue Returns the current value in Internal Units.
int m_NumberOfScreens
Definition: base_screen.h:86
void createHPGLFile(bool aPlotAll, bool aPlotFrameRef, RENDER_SETTINGS *aRenderSettings)
SCH_SHEET_PATH & GetCurrentSheet() const
WX_HTML_REPORT_PANEL * m_MessagesBox
Definition of the SCH_SHEET_PATH and SCH_SHEET_LIST classes for Eeschema.
virtual void LoadColors(const COLOR_SETTINGS *aSettings)
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