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 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( false );
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 // Initialize the dialog options:
85 {
86  // Set paper size option
87  m_PaperSizeOption->SetSelection( m_pageSizeSelect );
88 
89  // Set color or B&W plot option
90  bool tmp;
91  m_config->Read( PLOT_MODECOLOR_KEY, &tmp, true );
92  setModeColor( tmp );
93 
94  // Set plot or not frame reference option
95  m_config->Read( PLOT_FRAME_REFERENCE_KEY, &tmp, true );
96  setPlotFrameRef( tmp );
97 
98  // Set HPGL plot origin to center of paper of left bottom corner
99  m_config->Read( PLOT_HPGL_ORIGIN_KEY, &tmp, false );
100  SetPlotOriginCenter( tmp );
101 
104 
105  // HPGL Pen Size is stored in mm in config
107  m_HPGLPenSize *= IU_PER_MM;
108 
109  // Switch to the last save plot format
110  long plotfmt;
111  m_config->Read( PLOT_FORMAT_KEY, &plotfmt, 0 );
112 
113  switch( plotfmt )
114  {
115  default:
116  case PLOT_FORMAT_POST:
117  m_plotFormatOpt->SetSelection( 0 );
118  break;
119 
120  case PLOT_FORMAT_PDF:
121  m_plotFormatOpt->SetSelection( 1 );
122  break;
123 
124  case PLOT_FORMAT_SVG:
125  m_plotFormatOpt->SetSelection( 2 );
126  break;
127 
128  case PLOT_FORMAT_DXF:
129  m_plotFormatOpt->SetSelection( 3 );
130  break;
131 
132  case PLOT_FORMAT_HPGL:
133  m_plotFormatOpt->SetSelection( 4 );
134  break;
135  }
136 
137  // Set the default line width (pen width which should be used for
138  // items that do not have a pen size defined (like frame ref)
141 
142  // Initialize HPGL specific widgets
146 
147  // Plot directory
148  wxString path = m_parent->GetPlotDirectoryName();
149 #ifdef __WINDOWS__
150  path.Replace( '/', '\\' );
151 #endif
152  m_outputDirectoryName->SetValue( path );
153 
154  // Hide/show widgets that are not always displayed:
155  wxCommandEvent cmd_event;
156  OnPlotFormatSelection( cmd_event );
157 }
158 
159 
165 {
166  // Build the absolute path of current output plot directory
167  // to preselect it when opening the dialog.
168  wxFileName fn( m_outputDirectoryName->GetValue() );
169  wxString path = Prj().AbsolutePath( m_outputDirectoryName->GetValue() );
170 
171  wxDirDialog dirDialog( this, _( "Select Output Directory" ), path );
172 
173  if( dirDialog.ShowModal() == wxID_CANCEL )
174  {
175  return;
176  }
177 
178  wxFileName dirName = wxFileName::DirName( dirDialog.GetPath() );
179 
181  wxString defaultPath = fn.GetPathWithSep();
182  wxString msg;
183  msg.Printf( _( "Do you want to use a path relative to\n'%s'" ),
184  GetChars( defaultPath ) );
185 
186  wxMessageDialog dialog( this, msg, _( "Plot Output Directory" ),
187  wxYES_NO | wxICON_QUESTION | wxYES_DEFAULT );
188 
189  // relative directory selected
190  if( dialog.ShowModal() == wxID_YES )
191  {
192  if( !dirName.MakeRelativeTo( defaultPath ) )
193  wxMessageBox( _( "Cannot make path relative (target volume different from file "
194  "volume)!" ), _( "Plot Output Directory" ), wxOK | wxICON_ERROR );
195  }
196 
197  m_outputDirectoryName->SetValue( dirName.GetFullPath() );
198 }
199 
200 
202 {
203  switch( m_plotFormatOpt->GetSelection() )
204  {
205  default:
206  case 0: return PLOT_FORMAT_POST;
207  case 1: return PLOT_FORMAT_PDF;
208  case 2: return PLOT_FORMAT_SVG;
209  case 3: return PLOT_FORMAT_DXF;
210  case 4: return PLOT_FORMAT_HPGL;
211  }
212 }
213 
214 
215 void DIALOG_PLOT_SCHEMATIC::OnButtonCancelClick( wxCommandEvent& event )
216 {
217  EndModal( wxID_CANCEL );
218 }
219 
220 
222 {
225  m_config->Write( PLOT_FORMAT_KEY, (long) GetPlotFileFormat() );
229 
230  // HPGL Pen Size is stored in mm in config
231  m_config->Write( PLOT_HPGL_PEN_SIZE_KEY, m_HPGLPenSize/IU_PER_MM );
232 
233  m_pageSizeSelect = m_PaperSizeOption->GetSelection();
235 
236  // Plot directory
237  wxString path = m_outputDirectoryName->GetValue();
238  path.Replace( '\\', '/' );
239 
240  if( m_parent->GetPlotDirectoryName() != path )
241  m_configChanged = true;
242 
244 }
245 
246 
247 void DIALOG_PLOT_SCHEMATIC::OnPlotFormatSelection( wxCommandEvent& event )
248 {
249 
250  switch( GetPlotFileFormat() )
251  {
252  default:
253  case PLOT_FORMAT_POST:
256  m_PaperSizeOption->Enable( true );
257  m_DefaultLineSizeCtrl->Enable( true );
258  break;
259 
260  case PLOT_FORMAT_PDF:
263  m_PaperSizeOption->Enable( true );
264  m_DefaultLineSizeCtrl->Enable( true );
265  break;
266 
267  case PLOT_FORMAT_SVG:
270  m_PaperSizeOption->Enable( false );
271  m_DefaultLineSizeCtrl->Enable( true );
272  break;
273 
274  case PLOT_FORMAT_DXF:
277  m_PaperSizeOption->Enable( false );
278  m_DefaultLineSizeCtrl->Enable( false );
279  break;
280 
281  case PLOT_FORMAT_HPGL:
284  m_DefaultLineSizeCtrl->Enable( false );
285  break;
286 
287  }
288 
289  GetSizer()->SetSizeHints( this );
290 }
291 
292 
294 {
295  PlotSchematic( false );
296 }
297 
298 
299 void DIALOG_PLOT_SCHEMATIC::OnButtonPlotAllClick( wxCommandEvent& event )
300 {
301  PlotSchematic( true );
302 }
303 
304 
306 {
307  getPlotOptions();
308 
309  switch( GetPlotFileFormat() )
310  {
311  case PLOT_FORMAT_HPGL:
312  createHPGLFile( aPlotAll, getPlotFrameRef() );
313  break;
314 
315  case PLOT_FORMAT_DXF:
316  CreateDXFFile( aPlotAll, getPlotFrameRef() );
317  break;
318 
319  case PLOT_FORMAT_PDF:
320  createPDFFile( aPlotAll, getPlotFrameRef() );
321  break;
322 
323  case PLOT_FORMAT_SVG:
324  createSVGFile( aPlotAll, getPlotFrameRef() );
325  break;
326 
327  case PLOT_FORMAT_POST:
328  // Fall through. Default to Postscript.
329  default:
330  createPSFile( aPlotAll, getPlotFrameRef() );
331  break;
332 
333  }
334 }
335 
336 
337 wxFileName DIALOG_PLOT_SCHEMATIC::createPlotFileName( wxTextCtrl* aOutputDirectoryName,
338  wxString& aPlotFileName,
339  wxString& aExtension,
340  REPORTER* aReporter )
341 {
342  wxString outputDirName = aOutputDirectoryName->GetValue();
343  wxFileName outputDir = wxFileName::DirName( outputDirName );
344 
345  wxString plotFileName = Prj().AbsolutePath( aPlotFileName + wxT( "." ) + aExtension);
346 
347  if( !EnsureFileDirectoryExists( &outputDir, plotFileName, aReporter ) )
348  {
349  wxString msg;
350  msg.Printf( _( "Could not write plot files to folder '%s'." ),
351  GetChars( outputDir.GetPath() ) );
352  aReporter->Report( msg, REPORTER::RPT_ERROR );
353  }
354 
355  wxFileName fn( plotFileName );
356  fn.SetPath( outputDir.GetFullPath() );
357  return fn;
358 }
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: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: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:880
#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)