KiCad PCB EDA Suite
dialog_plot_schematic.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-2015 Jean-Pierre Charras jp.charras at wanadoo.fr
8  * Copyright (C) 1992-2010 Lorenzo Marcantonio
9  * Copyright (C) 2011 Wayne Stambaugh <stambaughw@gmail.com>
10  *
11  * Copyright (C) 1992-2017 KiCad Developers, see AUTHORS.txt for contributors.
12  *
13  * This program is free software; you can redistribute it and/or
14  * modify it under the terms of the GNU General Public License
15  * as published by the Free Software Foundation; either version 2
16  * of the License, or (at your option) any later version.
17  *
18  * This program is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21  * GNU General Public License for more details.
22  *
23  * You should have received a copy of the GNU General Public License
24  * along with this program; if not, you may find one here:
25  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
26  * or you may search the http://www.gnu.org website for the version 2 license,
27  * or you may write to the Free Software Foundation, Inc.,
28  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
29  */
30 
31 #include <fctsys.h>
32 #include <pgm_base.h>
33 #include <kiface_i.h>
34 #include <worksheet.h>
35 #include <class_sch_screen.h>
36 #include <schframe.h>
37 #include <base_units.h>
38 #include <sch_sheet.h>
39 #include <dialog_plot_schematic.h>
40 #include <wx_html_report_panel.h>
41 
42 // Keys for configuration
43 #define PLOT_FORMAT_KEY wxT( "PlotFormat" )
44 #define PLOT_MODECOLOR_KEY wxT( "PlotModeColor" )
45 #define PLOT_FRAME_REFERENCE_KEY wxT( "PlotFrameRef" )
46 #define PLOT_HPGL_ORIGIN_KEY wxT( "PlotHPGLOrg" )
47 #define PLOT_HPGL_PAPERSIZE_KEY wxT( "PlotHPGLPaperSize" )
48 #define PLOT_HPGL_PEN_SIZE_KEY wxT( "PlotHPGLPenSize" )
49 
50 
51 
52 // static members (static to remember last state):
54 
55 
56 void SCH_EDIT_FRAME::PlotSchematic( wxCommandEvent& event )
57 {
58  DIALOG_PLOT_SCHEMATIC dlg( this );
59 
60  dlg.ShowModal();
61 
62  // save project config if the prj config has changed:
63  if( dlg.PrjConfigChanged() )
64  SaveProjectSettings( false );
65 }
66 
67 
70 {
71  m_parent = parent;
72  m_configChanged = false;
74 
75  initDlg();
76 
77  // Now all widgets have the size fixed, call FinishDialogSettings
79 }
80 
81 
82 // Initialize the dialog options:
84 {
85  // Set paper size option
86  m_PaperSizeOption->SetSelection( m_pageSizeSelect );
87 
88  // Set color or B&W plot option
89  bool tmp;
90  m_config->Read( PLOT_MODECOLOR_KEY, &tmp, true );
91  setModeColor( tmp );
92 
93  // Set plot or not frame reference option
94  m_config->Read( PLOT_FRAME_REFERENCE_KEY, &tmp, true );
95  setPlotFrameRef( tmp );
96 
97  // Set HPGL plot origin to center of paper of left bottom corner
98  m_config->Read( PLOT_HPGL_ORIGIN_KEY, &tmp, false );
99  SetPlotOriginCenter( tmp );
100 
103 
104  // HPGL Pen Size is stored in mm in config
106  m_HPGLPenSize *= IU_PER_MM;
107 
108  // Switch to the last save plot format
109  long plotfmt;
110  m_config->Read( PLOT_FORMAT_KEY, &plotfmt, 0 );
111 
112  switch( plotfmt )
113  {
114  default:
115  case PLOT_FORMAT_POST:
116  m_plotFormatOpt->SetSelection( 0 );
117  break;
118 
119  case PLOT_FORMAT_PDF:
120  m_plotFormatOpt->SetSelection( 1 );
121  break;
122 
123  case PLOT_FORMAT_SVG:
124  m_plotFormatOpt->SetSelection( 2 );
125  break;
126 
127  case PLOT_FORMAT_DXF:
128  m_plotFormatOpt->SetSelection( 3 );
129  break;
130 
131  case PLOT_FORMAT_HPGL:
132  m_plotFormatOpt->SetSelection( 4 );
133  break;
134  }
135 
136  // Set the default line width (pen width which should be used for
137  // items that do not have a pen size defined (like frame ref)
140 
141  // Initialize HPGL specific widgets
145 
146  // Plot directory
147  wxString path = m_parent->GetPlotDirectoryName();
148 #ifdef __WINDOWS__
149  path.Replace( '/', '\\' );
150 #endif
151  m_outputDirectoryName->SetValue( path );
152 
153  // Hide/show widgets that are not always displayed:
154  wxCommandEvent cmd_event;
155  OnPlotFormatSelection( cmd_event );
156 }
157 
158 
164 {
165  // Build the absolute path of current output plot directory
166  // to preselect it when opening the dialog.
167  wxFileName fn( m_outputDirectoryName->GetValue() );
168  wxString path = Prj().AbsolutePath( m_outputDirectoryName->GetValue() );
169 
170  wxDirDialog dirDialog( this, _( "Select Output Directory" ), path );
171 
172  if( dirDialog.ShowModal() == wxID_CANCEL )
173  {
174  return;
175  }
176 
177  wxFileName dirName = wxFileName::DirName( dirDialog.GetPath() );
178 
180  wxString defaultPath = fn.GetPathWithSep();
181  wxString msg;
182  msg.Printf( _( "Do you want to use a path relative to\n'%s'" ),
183  GetChars( defaultPath ) );
184 
185  wxMessageDialog dialog( this, msg, _( "Plot Output Directory" ),
186  wxYES_NO | wxICON_QUESTION | wxYES_DEFAULT );
187 
188  // relative directory selected
189  if( dialog.ShowModal() == wxID_YES )
190  {
191  if( !dirName.MakeRelativeTo( defaultPath ) )
192  wxMessageBox( _( "Cannot make path relative (target volume different from file "
193  "volume)!" ), _( "Plot Output Directory" ), wxOK | wxICON_ERROR );
194  }
195 
196  m_outputDirectoryName->SetValue( dirName.GetFullPath() );
197 }
198 
199 
201 {
202  switch( m_plotFormatOpt->GetSelection() )
203  {
204  default:
205  case 0: return PLOT_FORMAT_POST;
206  case 1: return PLOT_FORMAT_PDF;
207  case 2: return PLOT_FORMAT_SVG;
208  case 3: return PLOT_FORMAT_DXF;
209  case 4: return PLOT_FORMAT_HPGL;
210  }
211 }
212 
213 
214 void DIALOG_PLOT_SCHEMATIC::OnButtonCancelClick( wxCommandEvent& event )
215 {
216  EndModal( wxID_CANCEL );
217 }
218 
219 
221 {
224  m_config->Write( PLOT_FORMAT_KEY, (long) GetPlotFileFormat() );
228 
229  // HPGL Pen Size is stored in mm in config
230  m_config->Write( PLOT_HPGL_PEN_SIZE_KEY, m_HPGLPenSize/IU_PER_MM );
231 
232  m_pageSizeSelect = m_PaperSizeOption->GetSelection();
234 
235  // Plot directory
236  wxString path = m_outputDirectoryName->GetValue();
237  path.Replace( '\\', '/' );
238 
239  if( m_parent->GetPlotDirectoryName() != path )
240  m_configChanged = true;
241 
243 }
244 
245 
246 void DIALOG_PLOT_SCHEMATIC::OnPlotFormatSelection( wxCommandEvent& event )
247 {
248 
249  switch( GetPlotFileFormat() )
250  {
251  default:
252  case PLOT_FORMAT_POST:
255  m_PaperSizeOption->Enable( true );
256  m_DefaultLineSizeCtrl->Enable( true );
257  break;
258 
259  case PLOT_FORMAT_PDF:
262  m_PaperSizeOption->Enable( true );
263  m_DefaultLineSizeCtrl->Enable( true );
264  break;
265 
266  case PLOT_FORMAT_SVG:
269  m_PaperSizeOption->Enable( false );
270  m_DefaultLineSizeCtrl->Enable( true );
271  break;
272 
273  case PLOT_FORMAT_DXF:
276  m_PaperSizeOption->Enable( false );
277  m_DefaultLineSizeCtrl->Enable( false );
278  break;
279 
280  case PLOT_FORMAT_HPGL:
283  m_DefaultLineSizeCtrl->Enable( false );
284  break;
285 
286  }
287 
288  GetSizer()->SetSizeHints( this );
289 }
290 
291 
293 {
294  PlotSchematic( false );
295 }
296 
297 
298 void DIALOG_PLOT_SCHEMATIC::OnButtonPlotAllClick( wxCommandEvent& event )
299 {
300  PlotSchematic( true );
301 }
302 
303 
305 {
306  getPlotOptions();
307 
308  switch( GetPlotFileFormat() )
309  {
310  case PLOT_FORMAT_HPGL:
311  createHPGLFile( aPlotAll, getPlotFrameRef() );
312  break;
313 
314  case PLOT_FORMAT_DXF:
315  CreateDXFFile( aPlotAll, getPlotFrameRef() );
316  break;
317 
318  case PLOT_FORMAT_PDF:
319  createPDFFile( aPlotAll, getPlotFrameRef() );
320  break;
321 
322  case PLOT_FORMAT_SVG:
323  createSVGFile( aPlotAll, getPlotFrameRef() );
324  break;
325 
326  case PLOT_FORMAT_POST:
327  // Fall through. Default to Postscript.
328  default:
329  createPSFile( aPlotAll, getPlotFrameRef() );
330  break;
331 
332  }
333 }
334 
335 
336 wxFileName DIALOG_PLOT_SCHEMATIC::createPlotFileName( wxTextCtrl* aOutputDirectoryName,
337  wxString& aPlotFileName,
338  wxString& aExtension,
339  REPORTER* aReporter )
340 {
341  wxString outputDirName = aOutputDirectoryName->GetValue();
342  wxFileName outputDir = wxFileName::DirName( outputDirName );
343 
344  wxString plotFileName = Prj().AbsolutePath( aPlotFileName + wxT( "." ) + aExtension);
345 
346  if( !EnsureFileDirectoryExists( &outputDir, plotFileName, aReporter ) )
347  {
348  wxString msg;
349  msg.Printf( _( "Could not write plot files to folder '%s'." ),
350  GetChars( outputDir.GetPath() ) );
351  aReporter->Report( msg, REPORTER::RPT_ERROR );
352  }
353 
354  wxFileName fn( plotFileName );
355  fn.SetPath( outputDir.GetFullPath() );
356  return fn;
357 }
Definition of the SCH_SHEET class for Eeschema.
void PlotSchematic(bool aPlotAll)
void CreateDXFFile(bool aPlotAll, bool aPlotFrameRef)
void SetPlotDirectoryName(const wxString &aDirName)
Definition: schframe.h:253
void OnOutputDirectoryBrowseClicked(wxCommandEvent &event) override
Set the m_outputDirectoryName variable to the selected directory from directory dialog.
Implementation of conversion functions that require both schematic and board internal units...
void SetPlotOriginCenter(bool aCenter)
DIALOG_PLOT_SCHEMATIC(SCH_EDIT_FRAME *parent)
int GetDefaultLineThickness()
Default line thickness used to draw/plot items having a default thickness line value (i...
void FinishDialogSettings()
In all dialogs, we must call the same functions to fix minimal dlg size, the default position and per...
Class DIALOG_PLOT_SCHEMATIC_BASE.
Schematic editor (Eeschema) main window.
Definition: schframe.h:118
void OnPlotFormatSelection(wxCommandEvent &event) override
Class REPORTER is a pure virtual class used to derive REPORTER objects from.
Definition: reporter.h:61
#define PLOT_HPGL_ORIGIN_KEY
void OnButtonPlotCurrentClick(wxCommandEvent &event) override
KIFACE_I & Kiface()
Global KIFACE_I "get" accessor.
Definition: kicad.cpp:52
void SaveProjectSettings(bool aAskForSave) override
Save changes to the project settings to the project (.pro) file.
void SetDefaultLineThickness(int aThickness)
#define PLOT_MODECOLOR_KEY
PROJECT & Prj() const
Function Prj returns a reference to the PROJECT "associated with" this KIWAY.
void createHPGLFile(bool aPlotAll, bool aPlotFrameRef)
const wxString & GetPlotDirectoryName() const
accessor to the destination directory to use when generating plot files.
Definition: schframe.h:252
SCH_SHEET * g_RootSheet
Definition: eeschema.cpp:55
void setPlotFrameRef(bool aPlot)
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.
bool EnsureFileDirectoryExists(wxFileName *aTargetFullFileName, const wxString &aBaseFilename, REPORTER *aReporter)
Helper function EnsureFileDirectoryExists make aTargetFullFileName absolute and creates the path of t...
Definition: common.cpp:267
#define PLOT_FRAME_REFERENCE_KEY
VTBL_ENTRY const wxString AbsolutePath(const wxString &aFileName) const
Function AbsolutePath fixes up aFileName if it is relative to the project's directory to be an absolu...
Definition: project.cpp:382
void PlotSchematic(wxCommandEvent &event)
PlotFormat
Enum PlotFormat is the set of supported output plot formats.
Definition: class_plotter.h:50
wxConfigBase * KifaceSettings() const
Definition: kiface_i.h:103
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:385
wxString GetFileName(void) const
Return the filename corresponding to this sheet.
Definition: sch_sheet.cpp:645
#define PLOT_HPGL_PEN_SIZE_KEY
EDA_UNITS_T g_UserUnit
Global variables definitions.
Definition: common.cpp:56
void createPDFFile(bool aPlotAll, bool aPlotFrameRef)
void PutValueInLocalUnits(wxTextCtrl &aTextCtr, int aValue)
Function PutValueInLocalUnits converts aValue from internal units to user units and append the units ...
Definition: base_units.cpp:266
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
see class PGM_BASE
void AddUnitSymbol(wxStaticText &Stext, EDA_UNITS_T aUnit)
Definition: base_units.cpp:514
virtual REPORTER & Report(const wxString &aText, SEVERITY aSeverity=RPT_UNDEFINED)=0
Function Report is a pure virtual function to override in the derived object.
void createPSFile(bool aPlotAll, bool aPlotFrameRef)
void OnButtonPlotAllClick(wxCommandEvent &event) override
void OnButtonCancelClick(wxCommandEvent &event) override
void createSVGFile(bool aPlotAll, bool aPlotFrameRef)
#define PLOT_HPGL_PAPERSIZE_KEY
#define PLOT_FORMAT_KEY
void setModeColor(bool aColor)