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@verizon.net>
10  *
11  * Copyright (C) 1992-2015 KiCad Developers, see change_log.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 <plot_common.h>
36 #include <class_sch_screen.h>
37 #include <schframe.h>
38 #include <base_units.h>
39 #include <sch_sheet.h>
40 #include <dialog_plot_schematic.h>
41 #include <wx_html_report_panel.h>
42 
43 // Keys for configuration
44 #define PLOT_FORMAT_KEY wxT( "PlotFormat" )
45 #define PLOT_MODECOLOR_KEY wxT( "PlotModeColor" )
46 #define PLOT_FRAME_REFERENCE_KEY wxT( "PlotFrameRef" )
47 #define PLOT_HPGL_ORIGIN_KEY wxT( "PlotHPGLOrg" )
48 #define PLOT_HPGL_PAPERSIZE_KEY wxT( "PlotHPGLPaperSize" )
49 #define PLOT_HPGL_PEN_SIZE_KEY wxT( "PlotHPGLPenSize" )
50 
51 
52 
53 // static members (static to remember last state):
55 
56 
57 void SCH_EDIT_FRAME::PlotSchematic( wxCommandEvent& event )
58 {
59  DIALOG_PLOT_SCHEMATIC dlg( this );
60 
61  dlg.ShowModal();
62 
63  // save project config if the prj config has changed:
64  if( dlg.PrjConfigChanged() )
65  SaveProjectSettings( true );
66 }
67 
68 
71 {
72  m_parent = parent;
73  m_configChanged = false;
75 
76  initDlg();
77 
78  // Now all widgets have the size fixed, call FinishDialogSettings
80 }
81 
82 
83 
84 // Initialize the dialog options:
86 {
87  // Set paper size option
88  m_PaperSizeOption->SetSelection( m_pageSizeSelect );
89 
90  // Set color or B&W plot option
91  bool tmp;
92  m_config->Read( PLOT_MODECOLOR_KEY, &tmp, true );
93  setModeColor( tmp );
94 
95  // Set plot or not frame reference option
96  m_config->Read( PLOT_FRAME_REFERENCE_KEY, &tmp, true );
97  setPlotFrameRef( tmp );
98 
99  // Set HPGL plot origin to center of paper of left bottom corner
100  m_config->Read( PLOT_HPGL_ORIGIN_KEY, &tmp, false );
101  SetPlotOriginCenter( tmp );
102 
105 
106  // HPGL Pen Size is stored in mm in config
108  m_HPGLPenSize *= IU_PER_MM;
109 
110  // Switch to the last save plot format
111  long plotfmt;
112  m_config->Read( PLOT_FORMAT_KEY, &plotfmt, 0 );
113 
114  switch( plotfmt )
115  {
116  default:
117  case PLOT_FORMAT_POST:
118  m_plotFormatOpt->SetSelection( 0 );
119  break;
120 
121  case PLOT_FORMAT_PDF:
122  m_plotFormatOpt->SetSelection( 1 );
123  break;
124 
125  case PLOT_FORMAT_SVG:
126  m_plotFormatOpt->SetSelection( 2 );
127  break;
128 
129  case PLOT_FORMAT_DXF:
130  m_plotFormatOpt->SetSelection( 3 );
131  break;
132 
133  case PLOT_FORMAT_HPGL:
134  m_plotFormatOpt->SetSelection( 4 );
135  break;
136  }
137 
138  // Set the default line width (pen width which should be used for
139  // items that do not have a pen size defined (like frame ref)
142 
143  // Initialize HPGL specific widgets
147 
148  // Plot directory
149  wxString path = m_parent->GetPlotDirectoryName();
150 #ifdef __WINDOWS__
151  path.Replace( '/', '\\' );
152 #endif
153  m_outputDirectoryName->SetValue( path );
154 
155  // Hide/show widgets that are not always displayed:
156  wxCommandEvent cmd_event;
157  OnPlotFormatSelection( cmd_event );
158 }
159 
160 /*
161  * TODO: Copy of DIALOG_PLOT::OnOutputDirectoryBrowseClicked in dialog_plot.cpp, maybe merge to a common method.
162  */
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 volume)!" ),
193  _( "Plot Output Directory" ), wxOK | wxICON_ERROR );
194  }
195 
196  m_outputDirectoryName->SetValue( dirName.GetFullPath() );
197 }
198 
200 {
201  switch( m_plotFormatOpt->GetSelection() )
202  {
203  default:
204  case 0: return PLOT_FORMAT_POST;
205  case 1: return PLOT_FORMAT_PDF;
206  case 2: return PLOT_FORMAT_SVG;
207  case 3: return PLOT_FORMAT_DXF;
208  case 4: return PLOT_FORMAT_HPGL;
209  }
210 }
211 
212 
213 void DIALOG_PLOT_SCHEMATIC::OnButtonCancelClick( wxCommandEvent& event )
214 {
215  EndModal( wxID_CANCEL );
216 }
217 
218 
220 {
223  m_config->Write( PLOT_FORMAT_KEY, (long) GetPlotFileFormat() );
227  // HPGL Pen Size is stored in mm in config
228  m_config->Write( PLOT_HPGL_PEN_SIZE_KEY, m_HPGLPenSize/IU_PER_MM );
229 
230  m_pageSizeSelect = m_PaperSizeOption->GetSelection();
232 
233  // Plot directory
234  wxString path = m_outputDirectoryName->GetValue();
235  path.Replace( '\\', '/' );
236 
237  if( m_parent->GetPlotDirectoryName() != path )
238  m_configChanged = true;
239 
241 
242 }
243 
244 
245 void DIALOG_PLOT_SCHEMATIC::OnPlotFormatSelection( wxCommandEvent& event )
246 {
247 
248  switch( GetPlotFileFormat() )
249  {
250  default:
251  case PLOT_FORMAT_POST:
254  m_PaperSizeOption->Enable( true );
255  m_DefaultLineSizeCtrl->Enable( true );
256  break;
257 
258  case PLOT_FORMAT_PDF:
261  m_PaperSizeOption->Enable( true );
262  m_DefaultLineSizeCtrl->Enable( true );
263  break;
264 
265  case PLOT_FORMAT_SVG:
268  m_PaperSizeOption->Enable( false );
269  m_DefaultLineSizeCtrl->Enable( true );
270  break;
271 
272  case PLOT_FORMAT_DXF:
275  m_PaperSizeOption->Enable( false );
276  m_DefaultLineSizeCtrl->Enable( false );
277  break;
278 
279  case PLOT_FORMAT_HPGL:
282  m_DefaultLineSizeCtrl->Enable( false );
283  break;
284 
285  }
286 
287  GetSizer()->SetSizeHints( this );
288 }
289 
290 
292 {
293  PlotSchematic( false );
294 }
295 
296 
297 void DIALOG_PLOT_SCHEMATIC::OnButtonPlotAllClick( wxCommandEvent& event )
298 {
299  PlotSchematic( true );
300 }
301 
302 
304 {
305  getPlotOptions();
306 
307  switch( GetPlotFileFormat() )
308  {
309  case PLOT_FORMAT_HPGL:
310  createHPGLFile( aPlotAll, getPlotFrameRef() );
311  break;
312 
313  case PLOT_FORMAT_DXF:
314  CreateDXFFile( aPlotAll, getPlotFrameRef() );
315  break;
316 
317  case PLOT_FORMAT_PDF:
318  createPDFFile( aPlotAll, getPlotFrameRef() );
319  break;
320 
321  case PLOT_FORMAT_SVG:
322  createSVGFile( aPlotAll, getPlotFrameRef() );
323  break;
324 
325  case PLOT_FORMAT_POST:
326  // Fall through. Default to Postscript.
327  default:
328  createPSFile( aPlotAll, getPlotFrameRef() );
329  break;
330 
331  }
332 }
333 
334 wxFileName DIALOG_PLOT_SCHEMATIC::createPlotFileName( wxTextCtrl* aOutputDirectoryName,
335  wxString& aPlotFileName,
336  wxString& aExtension,
337  REPORTER* aReporter )
338 {
339  wxString outputDirName = aOutputDirectoryName->GetValue();
340  wxFileName outputDir = wxFileName::DirName( outputDirName );
341 
342  wxString plotFileName = Prj().AbsolutePath( aPlotFileName + wxT(".") + aExtension);
343 
344  if( !EnsureFileDirectoryExists( &outputDir, plotFileName, aReporter ) )
345  {
346  wxString msg;
347  msg.Printf( _( "Could not write plot files to folder '%s'." ),
348  GetChars( outputDir.GetPath() ) );
349  aReporter->Report( msg, REPORTER::RPT_ERROR );
350  }
351 
352  wxFileName fn( plotFileName );
353  fn.SetPath( outputDir.GetFullPath() );
354  return fn;
355 }
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:263
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...
PlotFormat
Enum PlotFormat is the set of supported output plot formats.
Definition: plot_common.h:49
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:117
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
Function SaveProjectSettings saves changes to the project settings to the project (...
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:262
SCH_SHEET * g_RootSheet
Definition: eeschema.cpp:54
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:371
void PlotSchematic(wxCommandEvent &event)
wxConfigBase * KifaceSettings() const
Definition: kiface_i.h:103
Common plot library Plot settings, and plotting engines (Postscript, Gerber, HPGL and DXF) ...
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
wxString GetFileName(void) const
Function GetFileName return the filename corresponding to this sheet.
Definition: sch_sheet.cpp:849
#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:265
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:509
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)