KiCad PCB EDA Suite
dialog_plot_schematic.cpp
Go to the documentation of this file.
1 /*
2  * This program source code file is part of KiCad, a free EDA CAD application.
3  *
4  * Copyright (C) 1992-2018 Jean-Pierre Charras jp.charras at wanadoo.fr
5  * Copyright (C) 1992-2010 Lorenzo Marcantonio
6  * Copyright (C) 2011 Wayne Stambaugh <stambaughw@gmail.com>
7  * Copyright (C) 1992-2021 KiCad Developers, see AUTHORS.txt for contributors.
8  *
9  * This program is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU General Public License
11  * as published by the Free Software Foundation; either version 2
12  * of the License, or (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, you may find one here:
21  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
22  * or you may search the http://www.gnu.org website for the version 2 license,
23  * or you may write to the Free Software Foundation, Inc.,
24  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
25  */
26 
27 #include <bitmaps.h>
28 #include <common.h> // For ExpandEnvVarSubstitutions
30 #include <dialog_plot_schematic.h>
31 #include <eeschema_settings.h>
32 #include <kiface_i.h>
33 #include <locale_io.h>
34 #include <plotters_specific.h>
35 #include <reporter.h>
36 #include <trace_helpers.h>
39 
40 #include <sch_edit_frame.h>
41 #include <sch_painter.h>
42 #include <schematic.h>
43 #include <sch_screen.h>
44 
45 #include <wx/dirdlg.h>
46 #include <wx/msgdlg.h>
47 #include <wx/stdpaths.h>
48 #include <wx/log.h>
49 
50 
51 // static members (static to remember last state):
54 
55 
69 };
70 
71 
72 static const wxChar* plot_sheet_list( int aSize )
73 {
74  switch( aSize )
75  {
76  default:
77  case PAGE_DEFAULT: return nullptr;
78  case HPGL_PAGE_SIZE_A5: return wxT( "A5" );
79  case HPGL_PAGE_SIZE_A4: return wxT( "A4" );
80  case HPGL_PAGE_SIZE_A3: return wxT( "A3" );
81  case HPGL_PAGE_SIZE_A2: return wxT( "A2" );
82  case HPGL_PAGE_SIZE_A1: return wxT( "A1" );
83  case HPGL_PAGE_SIZE_A0: return wxT( "A0" );
84  case HPGL_PAGE_SIZE_A: return wxT( "A" );
85  case HPGL_PAGE_SIZE_B: return wxT( "B" );
86  case HPGL_PAGE_SIZE_C: return wxT( "C" );
87  case HPGL_PAGE_SIZE_D: return wxT( "D" );
88  case HPGL_PAGE_SIZE_E: return wxT( "E" );
89  }
90 }
91 
92 
94  : DIALOG_PLOT_SCHEMATIC_BASE( parent ),
95  m_parent( parent ),
96  m_plotFormat( PLOT_FORMAT::UNDEFINED ),
97  m_HPGLPenSize( 1.0 ),
98  m_defaultLineWidth( parent, m_lineWidthLabel, m_lineWidthCtrl, m_lineWidthUnits ),
99  m_penWidth( parent, m_penWidthLabel, m_penWidthCtrl, m_penWidthUnits )
100 {
101  m_configChanged = false;
102 
104 
105  m_MessagesBox->SetFileName( Prj().GetProjectPath() + wxT( "report.txt" ) );
106 
107  // We use a sdbSizer to get platform-dependent ordering of the action buttons, but
108  // that requires us to correct the button labels here.
109  m_sdbSizer1OK->SetLabel( _( "Plot All Pages" ) );
110  m_sdbSizer1Apply->SetLabel( _( "Plot Current Page" ) );
111  m_sdbSizer1Cancel->SetLabel( _( "Close" ) );
112  m_sdbSizer1->Layout();
113 
114  m_sdbSizer1OK->SetDefault();
115  initDlg();
116 
117  // Now all widgets have the size fixed, call FinishDialogSettings
119 }
120 
121 
122 // Initialize the dialog options:
124 {
125  auto cfg = dynamic_cast<EESCHEMA_SETTINGS*>( Kiface().KifaceSettings() );
126  wxASSERT( cfg );
127 
128  if( cfg )
129  {
131  {
132  int idx = m_colorTheme->Append( settings->GetName(), static_cast<void*>( settings ) );
133 
134  if( settings->GetFilename() == cfg->m_PlotPanel.color_theme )
135  m_colorTheme->SetSelection( idx );
136  }
137 
138  m_colorTheme->Enable( cfg->m_PlotPanel.color );
139 
140  m_plotBackgroundColor->Enable( cfg->m_PlotPanel.color );
141  m_plotBackgroundColor->SetValue( cfg->m_PlotPanel.background_color );
142 
143  // Set color or B&W plot option
144  setModeColor( cfg->m_PlotPanel.color );
145 
146  // Set plot or not frame reference option
147  setPlotDrawingSheet( cfg->m_PlotPanel.frame_reference );
148 
149  // HPGL plot origin and unit system configuration
150  m_plotOriginOpt->SetSelection( cfg->m_PlotPanel.hpgl_origin );
151 
152  m_HPGLPaperSizeSelect = cfg->m_PlotPanel.hpgl_paper_size;
153 
154  // HPGL Pen Size is stored in mm in config
155  m_HPGLPenSize = cfg->m_PlotPanel.hpgl_pen_size * IU_PER_MM;
156 
157  // Switch to the last save plot format
158  PLOT_FORMAT fmt = static_cast<PLOT_FORMAT>( cfg->m_PlotPanel.format );
159 
160  switch( fmt )
161  {
162  default:
163  case PLOT_FORMAT::POST: m_plotFormatOpt->SetSelection( 0 ); break;
164  case PLOT_FORMAT::PDF: m_plotFormatOpt->SetSelection( 1 ); break;
165  case PLOT_FORMAT::SVG: m_plotFormatOpt->SetSelection( 2 ); break;
166  case PLOT_FORMAT::DXF: m_plotFormatOpt->SetSelection( 3 ); break;
167  case PLOT_FORMAT::HPGL: m_plotFormatOpt->SetSelection( 4 ); break;
168  }
169 
170  if( fmt == PLOT_FORMAT::DXF || fmt == PLOT_FORMAT::HPGL )
171  m_plotBackgroundColor->Disable();
172 
173  // Set the default line width (pen width which should be used for
174  // items that do not have a pen size defined (like frame ref)
175  // the default line width is stored in mils in config
176  m_defaultLineWidth.SetValue( Mils2iu( cfg->m_Drawing.default_line_thickness ) );
177  }
178 
179  // Initialize HPGL specific widgets
181 
182  // Plot directory
184  wxString path = settings.m_PlotDirectoryName;
185 #ifdef __WINDOWS__
186  path.Replace( '/', '\\' );
187 #endif
188  m_outputDirectoryName->SetValue( path );
189 }
190 
191 
197 {
198  // Build the absolute path of current output directory to preselect it in the file browser.
199  wxString path = ExpandEnvVarSubstitutions( m_outputDirectoryName->GetValue(), &Prj() );
200 
201  // When editing a schematic that is not part of a project in the stand alone mode, the
202  // project path is not defined so point to the users document path to save the plot files.
203  if( Prj().IsNullProject() )
204  {
205  path = wxStandardPaths::Get().GetDocumentsDir();
206  }
207  else
208  {
209  // Build the absolute path of current output directory to preselect it in the file browser.
211  path = Prj().AbsolutePath( path );
212  }
213 
214  wxDirDialog dirDialog( this, _( "Select Output Directory" ), path );
215 
216  if( dirDialog.ShowModal() == wxID_CANCEL )
217  return;
218 
219  wxFileName dirName = wxFileName::DirName( dirDialog.GetPath() );
220 
221  wxFileName fn( Prj().AbsolutePath( m_parent->Schematic().Root().GetFileName() ) );
222  wxString defaultPath = fn.GetPathWithSep();
223  wxString msg;
224  wxFileName relPathTest; // Used to test if we can make the path relative
225 
226  relPathTest.Assign( dirDialog.GetPath() );
227 
228  // Test if making the path relative is possible before asking the user if they want to do it
229  if( relPathTest.MakeRelativeTo( defaultPath ) )
230  {
231  msg.Printf( _( "Do you want to use a path relative to\n'%s'?" ), defaultPath );
232 
233  wxMessageDialog dialog( this, msg, _( "Plot Output Directory" ),
234  wxYES_NO | wxICON_QUESTION | wxYES_DEFAULT );
235 
236  if( dialog.ShowModal() == wxID_YES )
237  dirName.MakeRelativeTo( defaultPath );
238  }
239 
240  m_outputDirectoryName->SetValue( dirName.GetFullPath() );
241 }
242 
243 
245 {
246  switch( m_plotFormatOpt->GetSelection() )
247  {
248  default:
249  case 0: return PLOT_FORMAT::POST;
250  case 1: return PLOT_FORMAT::PDF;
251  case 2: return PLOT_FORMAT::SVG;
252  case 3: return PLOT_FORMAT::DXF;
253  case 4: return PLOT_FORMAT::HPGL;
254  }
255 }
256 
257 
258 void DIALOG_PLOT_SCHEMATIC::OnPageSizeSelected( wxCommandEvent& event )
259 {
261  m_HPGLPaperSizeSelect = m_paperSizeOption->GetSelection();
262  else
263  m_pageSizeSelect = m_paperSizeOption->GetSelection();
264 }
265 
266 
267 void DIALOG_PLOT_SCHEMATIC::OnUpdateUI( wxUpdateUIEvent& event )
268 {
270 
271  if( fmt != m_plotFormat )
272  {
273  m_plotFormat = fmt;
274 
275  wxArrayString paperSizes;
276  paperSizes.push_back( _( "Schematic size" ) );
277 
278  int selection;
279 
280  if( fmt == PLOT_FORMAT::HPGL )
281  {
282  paperSizes.push_back( _( "A5" ) );
283  paperSizes.push_back( _( "A4" ) );
284  paperSizes.push_back( _( "A3" ) );
285  paperSizes.push_back( _( "A2" ) );
286  paperSizes.push_back( _( "A1" ) );
287  paperSizes.push_back( _( "A0" ) );
288  paperSizes.push_back( _( "A" ) );
289  paperSizes.push_back( _( "B" ) );
290  paperSizes.push_back( _( "C" ) );
291  paperSizes.push_back( _( "D" ) );
292  paperSizes.push_back( _( "E" ) );
293 
294  selection = m_HPGLPaperSizeSelect;
295  }
296  else
297  {
298  paperSizes.push_back( _( "A4" ) );
299  paperSizes.push_back( _( "A" ) );
300 
301  selection = m_pageSizeSelect;
302  }
303 
304  m_paperSizeOption->Set( paperSizes );
305  m_paperSizeOption->SetSelection( selection );
306 
308  fmt == PLOT_FORMAT::POST || fmt == PLOT_FORMAT::PDF || fmt == PLOT_FORMAT::SVG );
309 
310  m_plotOriginTitle->Enable( fmt == PLOT_FORMAT::HPGL );
311  m_plotOriginOpt->Enable( fmt == PLOT_FORMAT::HPGL );
313 
314  m_plotBackgroundColor->Enable(
315  fmt == PLOT_FORMAT::POST || fmt == PLOT_FORMAT::PDF || fmt == PLOT_FORMAT::SVG );
316 
317  m_colorTheme->Enable( fmt != PLOT_FORMAT::HPGL );
318  m_ModeColorOption->Enable( fmt != PLOT_FORMAT::HPGL );
319  }
320 }
321 
322 
324 {
326 
327  EESCHEMA_SETTINGS* cfg = dynamic_cast<EESCHEMA_SETTINGS*>( Kiface().KifaceSettings() );
328  wxASSERT( cfg );
329 
330  COLOR_SETTINGS* colors = getColorSettings();
331 
332  if( cfg )
333  {
335  cfg->m_PlotPanel.color = getModeColor();
336  cfg->m_PlotPanel.color_theme = colors->GetFilename();
338  cfg->m_PlotPanel.format = static_cast<int>( GetPlotFileFormat() );
339  cfg->m_PlotPanel.hpgl_origin = m_plotOriginOpt->GetSelection();
341 
342  // HPGL Pen Size is stored in mm in config
344  }
345 
346  aSettings->LoadColors( colors );
347  aSettings->SetDefaultPenWidth( (int) m_defaultLineWidth.GetValue() );
348 
349  if( m_plotBackgroundColor->GetValue() )
350  aSettings->SetBackgroundColor( colors->GetColor( LAYER_SCHEMATIC_BACKGROUND ) );
351  else
352  aSettings->SetBackgroundColor( COLOR4D::UNSPECIFIED );
353 
354  // Plot directory
355  wxString path = m_outputDirectoryName->GetValue();
356  path.Replace( '\\', '/' );
357 
359 
360  if( settings.m_PlotDirectoryName != path )
361  m_configChanged = true;
362 
363  settings.m_PlotDirectoryName = path;
364 }
365 
366 
368 {
369  int selection = m_colorTheme->GetSelection();
370 
371  if( selection < 0 )
372  return m_parent->GetSettingsManager()->GetColorSettings( "_builtin_default" );
373 
374  return static_cast<COLOR_SETTINGS*>( m_colorTheme->GetClientData( selection ) );
375 }
376 
377 
378 void DIALOG_PLOT_SCHEMATIC::OnPlotCurrent( wxCommandEvent& event )
379 {
380  plotSchematic( false );
381 }
382 
383 
384 void DIALOG_PLOT_SCHEMATIC::OnPlotAll( wxCommandEvent& event )
385 {
386  plotSchematic( true );
387 }
388 
389 
391 {
393 
394  getPlotOptions( &renderSettings );
395 
396  switch( GetPlotFileFormat() )
397  {
398  default:
399  case PLOT_FORMAT::POST:
400  createPSFile( aPlotAll, getPlotDrawingSheet(), &renderSettings );
401  break;
402  case PLOT_FORMAT::DXF:
403  createDxfFile( aPlotAll, getPlotDrawingSheet(), &renderSettings );
404  break;
405  case PLOT_FORMAT::PDF:
406  createPDFFile( aPlotAll, getPlotDrawingSheet(), &renderSettings );
407  break;
408  case PLOT_FORMAT::SVG:
409  createSVGFile( aPlotAll, getPlotDrawingSheet(), &renderSettings );
410  break;
411  case PLOT_FORMAT::HPGL:
412  createHPGLFile( aPlotAll, getPlotDrawingSheet(), &renderSettings );
413  break;
414  }
415 }
416 
417 
418 wxFileName DIALOG_PLOT_SCHEMATIC::createPlotFileName( const wxString& aPlotFileName,
419  const wxString& aExtension,
420  REPORTER* aReporter )
421 {
422  wxFileName retv;
423  wxFileName tmp;
424 
425  tmp.SetPath( getOutputPath() );
426  retv.SetPath( tmp.GetPath() );
427 
428  if( !aPlotFileName.IsEmpty() )
429  retv.SetName( aPlotFileName );
430  else
431  retv.SetName( _( "Schematic" ) );
432 
433  retv.SetExt( aExtension );
434 
435  if( !EnsureFileDirectoryExists( &tmp, retv.GetFullName(), aReporter )
436  || !tmp.IsDirWritable() )
437  {
438  wxString msg = wxString::Format( _( "Could not write plot files to folder \"%s\"." ),
439  tmp.GetPath() );
440  aReporter->Report( msg, RPT_SEVERITY_ERROR );
441  retv.Clear();
442 
444  settings.m_PlotDirectoryName.Clear();
445 
446  m_configChanged = true;
447  }
448  else
449  {
450  retv.SetPath( tmp.GetPath() );
451  }
452 
453  wxLogTrace( tracePathsAndFiles, "Writing plot file '%s'.", retv.GetFullPath() );
454 
455  return retv;
456 }
457 
458 
459 void DIALOG_PLOT_SCHEMATIC::createDxfFile( bool aPlotAll, bool aPlotDrawingSheet,
460  RENDER_SETTINGS* aRenderSettings )
461 {
462  SCH_EDIT_FRAME* schframe = m_parent;
463  SCH_SHEET_PATH oldsheetpath = schframe->GetCurrentSheet();
464 
465  /* When printing all pages, the printed page is not the current page.
466  * In complex hierarchies, we must setup references and others parameters
467  * in the printed SCH_SCREEN
468  * because in complex hierarchies a SCH_SCREEN (a schematic drawings)
469  * is shared between many sheets
470  */
471  SCH_SHEET_LIST sheetList;
472 
473  if( aPlotAll )
474  {
475  sheetList.BuildSheetList( &schframe->Schematic().Root(), true );
476  sheetList.SortByPageNumbers();
477  }
478  else
479  {
480  sheetList.push_back( schframe->GetCurrentSheet() );
481  }
482 
483  REPORTER& reporter = m_MessagesBox->Reporter();
484 
485  for( unsigned i = 0; i < sheetList.size(); i++ )
486  {
487  schframe->SetCurrentSheet( sheetList[i] );
489  schframe->SetSheetNumberAndCount();
490 
491  SCH_SCREEN* screen = schframe->GetCurrentSheet().LastScreen();
492  wxPoint plot_offset;
493  wxString msg;
494 
495  try
496  {
497  wxString fname = schframe->GetUniqueFilenameForCurrentSheet();
498 
499  // The sub sheet can be in a sub_hierarchy, but we plot the file in the
500  // main project folder (or the folder specified by the caller),
501  // so replace separators to create a unique filename:
502  fname.Replace( "/", "_" );
503  fname.Replace( "\\", "_" );
504  wxString ext = DXF_PLOTTER::GetDefaultFileExtension();
505  wxFileName plotFileName = createPlotFileName( fname, ext, &reporter );
506 
507  if( !plotFileName.IsOk() )
508  return;
509 
510  if( plotOneSheetDxf( plotFileName.GetFullPath(), screen, aRenderSettings,
511  plot_offset, 1.0, aPlotDrawingSheet ) )
512  {
513  msg.Printf( _( "Plotted to '%s'.\n" ), plotFileName.GetFullPath() );
514  reporter.Report( msg, RPT_SEVERITY_ACTION );
515  }
516  else // Error
517  {
518  msg.Printf( _( "Unable to create file '%s'.\n" ), plotFileName.GetFullPath() );
519  reporter.Report( msg, RPT_SEVERITY_ERROR );
520  }
521  }
522  catch( IO_ERROR& e )
523  {
524  msg.Printf( wxT( "DXF Plotter exception: %s\n"), e.What() );
525  reporter.Report( msg, RPT_SEVERITY_ERROR );
526  schframe->SetCurrentSheet( oldsheetpath );
528  schframe->SetSheetNumberAndCount();
529  return;
530  }
531  }
532 
533  schframe->SetCurrentSheet( oldsheetpath );
535  schframe->SetSheetNumberAndCount();
536 }
537 
538 
539 bool DIALOG_PLOT_SCHEMATIC::plotOneSheetDxf( const wxString& aFileName,
540  SCH_SCREEN* aScreen,
541  RENDER_SETTINGS* aRenderSettings,
542  wxPoint aPlotOffset,
543  double aScale,
544  bool aPlotFrameRef )
545 {
546  aRenderSettings->LoadColors( getColorSettings() );
547  aRenderSettings->SetDefaultPenWidth( 0 );
548 
549  const PAGE_INFO& pageInfo = aScreen->GetPageSettings();
550  DXF_PLOTTER* plotter = new DXF_PLOTTER();
551 
552  plotter->SetRenderSettings( aRenderSettings );
553  plotter->SetPageSettings( pageInfo );
554  plotter->SetColorMode( getModeColor() );
555 
556  // Currently, plot units are in decimil
557  plotter->SetViewport( aPlotOffset, IU_PER_MILS/10, aScale, false );
558 
559  // Init :
560  plotter->SetCreator( wxT( "Eeschema-DXF" ) );
561 
562  if( ! plotter->OpenFile( aFileName ) )
563  {
564  delete plotter;
565  return false;
566  }
567 
568  LOCALE_IO toggle;
569 
570  plotter->StartPlot();
571 
572  if( aPlotFrameRef )
573  {
574  PlotDrawingSheet( plotter, &m_parent->Prj(), m_parent->GetTitleBlock(), pageInfo,
575  aScreen->GetPageNumber(), aScreen->GetPageCount(),
576  m_parent->GetScreenDesc(), aScreen->GetFileName(),
577  plotter->GetColorMode() ?
579  COLOR4D::BLACK, aScreen->GetVirtualPageNumber() == 1 );
580  }
581 
582  aScreen->Plot( plotter );
583 
584  // finish
585  plotter->EndPlot();
586  delete plotter;
587 
588  return true;
589 }
590 
591 
593 {
595 
596  if( m_HPGLPenSize > Millimeter2iu( 2 ) )
598 
599  if( m_HPGLPenSize < Millimeter2iu( 0.01 ) )
600  m_HPGLPenSize = Millimeter2iu( 0.01 );
601 }
602 
603 
604 void DIALOG_PLOT_SCHEMATIC::createHPGLFile( bool aPlotAll, bool aPlotFrameRef,
605  RENDER_SETTINGS* aRenderSettings )
606 {
607  SCH_SCREEN* screen = m_parent->GetScreen();
608  SCH_SHEET_PATH oldsheetpath = m_parent->GetCurrentSheet();
609 
610  /* When printing all pages, the printed page is not the current page.
611  * In complex hierarchies, we must setup references and other parameters
612  * in the printed SCH_SCREEN
613  * because in complex hierarchies a SCH_SCREEN (a schematic drawings)
614  * is shared between many sheets
615  */
616  SCH_SHEET_LIST sheetList;
617 
618  if( aPlotAll )
619  {
620  sheetList.BuildSheetList( &m_parent->Schematic().Root(), true );
621  sheetList.SortByPageNumbers();
622  }
623  else
624  {
625  sheetList.push_back( m_parent->GetCurrentSheet() );
626  }
627 
628  REPORTER& reporter = m_MessagesBox->Reporter();
629 
630  setHpglPenWidth();
631 
632  for( unsigned i = 0; i < sheetList.size(); i++ )
633  {
634  m_parent->SetCurrentSheet( sheetList[i] );
637 
638  screen = m_parent->GetCurrentSheet().LastScreen();
639 
640  if( !screen ) // LastScreen() may return NULL
641  screen = m_parent->GetScreen();
642 
643  const PAGE_INFO& curPage = screen->GetPageSettings();
644 
645  PAGE_INFO plotPage = curPage;
646 
647  // if plotting on a page size other than curPage
648  if( m_paperSizeOption->GetSelection() != PAGE_DEFAULT )
649  plotPage.SetType( plot_sheet_list( m_paperSizeOption->GetSelection() ) );
650 
651  // Calculation of conversion scales.
652  double plot_scale = (double) plotPage.GetWidthMils() / curPage.GetWidthMils();
653 
654  // Calculate offsets
655  wxPoint plotOffset;
656  wxString msg;
657 
659  {
660  plotOffset.x = plotPage.GetWidthIU() / 2;
661  plotOffset.y = -plotPage.GetHeightIU() / 2;
662  }
663 
664  try
665  {
666  wxString fname = m_parent->GetUniqueFilenameForCurrentSheet();
667  // The sub sheet can be in a sub_hierarchy, but we plot the file in the
668  // main project folder (or the folder specified by the caller),
669  // so replace separators to create a unique filename:
670  fname.Replace( "/", "_" );
671  fname.Replace( "\\", "_" );
672  wxString ext = HPGL_PLOTTER::GetDefaultFileExtension();
673  wxFileName plotFileName = createPlotFileName( fname, ext, &reporter );
674 
675  if( !plotFileName.IsOk() )
676  return;
677 
678  LOCALE_IO toggle;
679 
680  if( plotOneSheetHpgl( plotFileName.GetFullPath(), screen, plotPage, aRenderSettings,
681  plotOffset, plot_scale, aPlotFrameRef, getPlotOriginAndUnits() ) )
682  {
683  msg.Printf( _( "Plotted to '%s'.\n" ), plotFileName.GetFullPath() );
684  reporter.Report( msg, RPT_SEVERITY_ACTION );
685  }
686  else
687  {
688  msg.Printf( _( "Unable to create file '%s'.\n" ), plotFileName.GetFullPath() );
689  reporter.Report( msg, RPT_SEVERITY_ERROR );
690  }
691  }
692  catch( IO_ERROR& e )
693  {
694  msg.Printf( wxT( "HPGL Plotter exception: %s\n"), e.What() );
695  reporter.Report( msg, RPT_SEVERITY_ERROR );
696  }
697 
698  }
699 
700  m_parent->SetCurrentSheet( oldsheetpath );
703 }
704 
705 
706 bool DIALOG_PLOT_SCHEMATIC::plotOneSheetHpgl( const wxString& aFileName,
707  SCH_SCREEN* aScreen,
708  const PAGE_INFO& aPageInfo,
709  RENDER_SETTINGS* aRenderSettings,
710  wxPoint aPlot0ffset,
711  double aScale,
712  bool aPlotFrameRef,
713  HPGL_PLOT_ORIGIN_AND_UNITS aOriginAndUnits )
714 {
715  HPGL_PLOTTER* plotter = new HPGL_PLOTTER();
716  // Currently, plot units are in decimil
717 
718  plotter->SetPageSettings( aPageInfo );
719  plotter->SetRenderSettings( aRenderSettings );
720  plotter->RenderSettings()->LoadColors( getColorSettings() );
721  plotter->SetColorMode( getModeColor() );
722  plotter->SetViewport( aPlot0ffset, IU_PER_MILS/10, aScale, false );
723 
724  // TODO this could be configurable
725  plotter->SetTargetChordLength( Millimeter2iu( 0.6 ) );
726 
727  switch( aOriginAndUnits )
728  {
731  default:
732  plotter->SetUserCoords( false );
733  break;
735  plotter->SetUserCoords( true );
736  plotter->SetUserCoordsFit( false );
737  break;
739  plotter->SetUserCoords( true );
740  plotter->SetUserCoordsFit( true );
741  break;
742  }
743 
744  // Init :
745  plotter->SetCreator( wxT( "Eeschema-HPGL" ) );
746 
747  if( !plotter->OpenFile( aFileName ) )
748  {
749  delete plotter;
750  return false;
751  }
752 
753  LOCALE_IO toggle;
754 
755  // Pen num and pen speed are not initialized here.
756  // Default HPGL driver values are used
757  plotter->SetPenDiameter( m_HPGLPenSize );
758  plotter->StartPlot();
759 
760  if( aPlotFrameRef )
761  {
762  PlotDrawingSheet( plotter, &m_parent->Prj(), m_parent->GetTitleBlock(), aPageInfo,
763  aScreen->GetPageNumber(), aScreen->GetPageCount(),
765  aScreen->GetVirtualPageNumber() == 1 );
766  }
767 
768  aScreen->Plot( plotter );
769 
770  plotter->EndPlot();
771  delete plotter;
772 
773  return true;
774 }
775 
776 
777 void DIALOG_PLOT_SCHEMATIC::createPDFFile( bool aPlotAll, bool aPlotDrawingSheet,
778  RENDER_SETTINGS* aRenderSettings )
779 {
780  SCH_SHEET_PATH oldsheetpath = m_parent->GetCurrentSheet(); // sheetpath is saved here
781 
782  /* When printing all pages, the printed page is not the current page. In
783  * complex hierarchies, we must update symbol references and other
784  * parameters in the given printed SCH_SCREEN, accordant to the sheet path
785  * because in complex hierarchies a SCH_SCREEN (a drawing ) is shared
786  * between many sheets and symbol references depend on the actual sheet
787  * path used
788  */
789  SCH_SHEET_LIST sheetList;
790 
791  if( aPlotAll )
792  {
793  sheetList.BuildSheetList( &m_parent->Schematic().Root(), true );
794  sheetList.SortByPageNumbers();
795  }
796  else
797  {
798  sheetList.push_back( m_parent->GetCurrentSheet() );
799  }
800 
801  // Allocate the plotter and set the job level parameter
802  PDF_PLOTTER* plotter = new PDF_PLOTTER();
803  plotter->SetRenderSettings( aRenderSettings );
804  plotter->SetColorMode( getModeColor() );
805  plotter->SetCreator( wxT( "Eeschema-PDF" ) );
806  plotter->SetTitle( m_parent->GetTitleBlock().GetTitle() );
807 
808  wxString msg;
809  wxFileName plotFileName;
810  REPORTER& reporter = m_MessagesBox->Reporter();
811  LOCALE_IO toggle; // Switch the locale to standard C
812 
813  for( unsigned i = 0; i < sheetList.size(); i++ )
814  {
815  m_parent->SetCurrentSheet( sheetList[i] );
819 
820  if( i == 0 )
821  {
822 
823  try
824  {
825  wxString fname = m_parent->GetUniqueFilenameForCurrentSheet();
826 
827  // The sub sheet can be in a sub_hierarchy, but we plot the file in the
828  // main project folder (or the folder specified by the caller),
829  // so replace separators to create a unique filename:
830  fname.Replace( "/", "_" );
831  fname.Replace( "\\", "_" );
832  wxString ext = PDF_PLOTTER::GetDefaultFileExtension();
833  plotFileName = createPlotFileName( fname, ext, &reporter );
834 
835  if( !plotFileName.IsOk() )
836  return;
837 
838  if( !plotter->OpenFile( plotFileName.GetFullPath() ) )
839  {
840  msg.Printf( _( "Unable to create file '%s'.\n" ),
841  plotFileName.GetFullPath() );
842  reporter.Report( msg, RPT_SEVERITY_ERROR );
843  delete plotter;
844  return;
845  }
846 
847  // Open the plotter and do the first page
848  setupPlotPagePDF( plotter, screen );
849  plotter->StartPlot();
850  }
851  catch( const IO_ERROR& e )
852  {
853  // Cannot plot PDF file
854  msg.Printf( wxT( "PDF Plotter exception: %s\n" ), e.What() );
855  reporter.Report( msg, RPT_SEVERITY_ERROR );
856 
857  restoreEnvironment( plotter, oldsheetpath );
858  return;
859  }
860 
861  }
862  else
863  {
864  /* For the following pages you need to close the (finished) page,
865  * reconfigure, and then start a new one */
866  plotter->ClosePage();
867  setupPlotPagePDF( plotter, screen );
868  plotter->StartPage();
869  }
870 
871  plotOneSheetPDF( plotter, screen, aPlotDrawingSheet );
872  }
873 
874  // Everything done, close the plot and restore the environment
875  msg.Printf( _( "Plotted to '%s'.\n" ), plotFileName.GetFullPath() );
876  reporter.Report( msg, RPT_SEVERITY_ACTION );
877 
878  restoreEnvironment( plotter, oldsheetpath );
879 }
880 
881 
883  SCH_SHEET_PATH& aOldsheetpath )
884 {
885  aPlotter->EndPlot();
886  delete aPlotter;
887 
888  // Restore the previous sheet
889  m_parent->SetCurrentSheet( aOldsheetpath );
892 }
893 
894 
896  bool aPlotDrawingSheet )
897 {
898  if( m_plotBackgroundColor->GetValue() )
899  {
900  aPlotter->SetColor( aPlotter->RenderSettings()->GetBackgroundColor() );
901  wxPoint end( aPlotter->PageSettings().GetWidthIU(),
902  aPlotter->PageSettings().GetHeightIU() );
903  aPlotter->Rect( wxPoint( 0, 0 ), end, FILL_TYPE::FILLED_SHAPE, 1.0 );
904  }
905 
906  if( aPlotDrawingSheet )
907  {
909 
910  if( aPlotter->GetColorMode() )
912 
913  PlotDrawingSheet( aPlotter, &aScreen->Schematic()->Prj(), m_parent->GetTitleBlock(),
914  m_parent->GetPageSettings(), aScreen->GetPageNumber(),
915  aScreen->GetPageCount(), m_parent->GetScreenDesc(),
916  aScreen->GetFileName(), color, aScreen->GetVirtualPageNumber() == 1 );
917  }
918 
919  aScreen->Plot( aPlotter );
920 }
921 
922 
924 {
925  PAGE_INFO plotPage; // page size selected to plot
926 
927  // Considerations on page size and scaling requests
928  const PAGE_INFO& actualPage = aScreen->GetPageSettings(); // page size selected in schematic
929 
930  switch( m_pageSizeSelect )
931  {
932  case PAGE_SIZE_A:
933  plotPage.SetType( wxT( "A" ) );
934  plotPage.SetPortrait( actualPage.IsPortrait() );
935  break;
936 
937  case PAGE_SIZE_A4:
938  plotPage.SetType( wxT( "A4" ) );
939  plotPage.SetPortrait( actualPage.IsPortrait() );
940  break;
941 
942  case PAGE_SIZE_AUTO:
943  default:
944  plotPage = actualPage;
945  break;
946  }
947 
948  double scalex = (double) plotPage.GetWidthMils() / actualPage.GetWidthMils();
949  double scaley = (double) plotPage.GetHeightMils() / actualPage.GetHeightMils();
950  double scale = std::min( scalex, scaley );
951  aPlotter->SetPageSettings( plotPage );
952 
953  // Currently, plot units are in decimil
954  aPlotter->SetViewport( wxPoint( 0, 0 ), IU_PER_MILS/10, scale, false );
955 }
956 
957 
958 void DIALOG_PLOT_SCHEMATIC::createPSFile( bool aPlotAll, bool aPlotFrameRef,
959  RENDER_SETTINGS* aRenderSettings )
960 {
961  SCH_SHEET_PATH oldsheetpath = m_parent->GetCurrentSheet(); // sheetpath is saved here
962  PAGE_INFO plotPage; // page size selected to plot
963 
964  /* When printing all pages, the printed page is not the current page.
965  * In complex hierarchies, we must update symbol references and other parameters in the
966  * given printed SCH_SCREEN, accordant to the sheet path because in complex hierarchies
967  * a SCH_SCREEN (a drawing ) is shared between many sheets and symbol references
968  * depend on the actual sheet path used.
969  */
970  SCH_SHEET_LIST sheetList;
971 
972  if( aPlotAll )
973  {
974  sheetList.BuildSheetList( &m_parent->Schematic().Root(), true );
975  sheetList.SortByPageNumbers();
976  }
977  else
978  {
979  sheetList.push_back( m_parent->GetCurrentSheet() );
980  }
981 
982  for( unsigned i = 0; i < sheetList.size(); i++ )
983  {
984  m_parent->SetCurrentSheet( sheetList[i] );
987 
989  PAGE_INFO actualPage = screen->GetPageSettings();
990 
991  switch( m_pageSizeSelect )
992  {
993  case PAGE_SIZE_A:
994  plotPage.SetType( wxT( "A" ) );
995  plotPage.SetPortrait( actualPage.IsPortrait() );
996  break;
997 
998  case PAGE_SIZE_A4:
999  plotPage.SetType( wxT( "A4" ) );
1000  plotPage.SetPortrait( actualPage.IsPortrait() );
1001  break;
1002 
1003  case PAGE_SIZE_AUTO:
1004  default:
1005  plotPage = actualPage;
1006  break;
1007  }
1008 
1009  double scalex = (double) plotPage.GetWidthMils() / actualPage.GetWidthMils();
1010  double scaley = (double) plotPage.GetHeightMils() / actualPage.GetHeightMils();
1011 
1012  double scale = std::min( scalex, scaley );
1013 
1014  wxPoint plot_offset;
1015 
1016  wxString msg;
1017  REPORTER& reporter = m_MessagesBox->Reporter();
1018 
1019  try
1020  {
1021  wxString fname = m_parent->GetUniqueFilenameForCurrentSheet();
1022 
1023  // The sub sheet can be in a sub_hierarchy, but we plot the file in the
1024  // main project folder (or the folder specified by the caller),
1025  // so replace separators to create a unique filename:
1026  fname.Replace( "/", "_" );
1027  fname.Replace ("\\", "_" );
1028  wxString ext = PS_PLOTTER::GetDefaultFileExtension();
1029  wxFileName plotFileName = createPlotFileName( fname, ext, &reporter );
1030 
1031  if( !plotFileName.IsOk() )
1032  return;
1033 
1034  if( plotOneSheetPS( plotFileName.GetFullPath(), screen, aRenderSettings, plotPage,
1035  plot_offset, scale, aPlotFrameRef ) )
1036  {
1037  msg.Printf( _( "Plotted to '%s'.\n" ), plotFileName.GetFullPath() );
1038  reporter.Report( msg, RPT_SEVERITY_ACTION );
1039  }
1040  else
1041  {
1042  // Error
1043  msg.Printf( _( "Unable to create file '%s'.\n" ), plotFileName.GetFullPath() );
1044  reporter.Report( msg, RPT_SEVERITY_ERROR );
1045  }
1046 
1047  }
1048  catch( IO_ERROR& e )
1049  {
1050  msg.Printf( wxT( "PS Plotter exception: %s\n"), e.What() );
1051  reporter.Report( msg, RPT_SEVERITY_ERROR );
1052  }
1053  }
1054 
1055  m_parent->SetCurrentSheet( oldsheetpath );
1058 }
1059 
1060 
1061 bool DIALOG_PLOT_SCHEMATIC::plotOneSheetPS( const wxString& aFileName,
1062  SCH_SCREEN* aScreen,
1063  RENDER_SETTINGS* aRenderSettings,
1064  const PAGE_INFO& aPageInfo,
1065  wxPoint aPlot0ffset,
1066  double aScale,
1067  bool aPlotFrameRef )
1068 {
1069  PS_PLOTTER* plotter = new PS_PLOTTER();
1070  plotter->SetRenderSettings( aRenderSettings );
1071  plotter->SetPageSettings( aPageInfo );
1072  plotter->SetColorMode( getModeColor() );
1073 
1074  // Currently, plot units are in decimil
1075  plotter->SetViewport( aPlot0ffset, IU_PER_MILS/10, aScale, false );
1076 
1077  // Init :
1078  plotter->SetCreator( wxT( "Eeschema-PS" ) );
1079 
1080  if( ! plotter->OpenFile( aFileName ) )
1081  {
1082  delete plotter;
1083  return false;
1084  }
1085 
1086  LOCALE_IO toggle; // Switch the locale to standard C
1087 
1088  plotter->StartPlot();
1089 
1090  if( m_plotBackgroundColor->GetValue() )
1091  {
1093  wxPoint end( plotter->PageSettings().GetWidthIU(),
1094  plotter->PageSettings().GetHeightIU() );
1095  plotter->Rect( wxPoint( 0, 0 ), end, FILL_TYPE::FILLED_SHAPE, 1.0 );
1096  }
1097 
1098  if( aPlotFrameRef )
1099  {
1100  PlotDrawingSheet( plotter, &aScreen->Schematic()->Prj(), m_parent->GetTitleBlock(),
1101  aPageInfo, aScreen->GetPageNumber(), aScreen->GetPageCount(),
1102  m_parent->GetScreenDesc(), aScreen->GetFileName(),
1103  plotter->GetColorMode() ?
1105  COLOR4D::BLACK, aScreen->GetVirtualPageNumber() == 1 );
1106  }
1107 
1108  aScreen->Plot( plotter );
1109 
1110  plotter->EndPlot();
1111  delete plotter;
1112 
1113  return true;
1114 }
1115 
1116 
1117 void DIALOG_PLOT_SCHEMATIC::createSVGFile( bool aPrintAll, bool aPrintFrameRef,
1118  RENDER_SETTINGS* aRenderSettings )
1119 {
1120  wxString msg;
1121  REPORTER& reporter = m_MessagesBox->Reporter();
1122  SCH_SHEET_PATH oldsheetpath = m_parent->GetCurrentSheet();
1123  SCH_SHEET_LIST sheetList;
1124 
1125  if( aPrintAll )
1126  {
1127  sheetList.BuildSheetList( &m_parent->Schematic().Root(), true );
1128  sheetList.SortByPageNumbers();
1129  }
1130  else
1131  {
1132  sheetList.push_back( m_parent->GetCurrentSheet() );
1133  }
1134 
1135  for( unsigned i = 0; i < sheetList.size(); i++ )
1136  {
1137  SCH_SCREEN* screen;
1138  m_parent->SetCurrentSheet( sheetList[i] );
1141  screen = m_parent->GetCurrentSheet().LastScreen();
1142 
1143  try
1144  {
1145  wxString fname = m_parent->GetUniqueFilenameForCurrentSheet();
1146 
1147  // The sub sheet can be in a sub_hierarchy, but we plot the file in the
1148  // main project folder (or the folder specified by the caller),
1149  // so replace separators to create a unique filename:
1150  fname.Replace( "/", "_" );
1151  fname.Replace( "\\", "_" );
1152  wxString ext = SVG_PLOTTER::GetDefaultFileExtension();
1153  wxFileName plotFileName = createPlotFileName( fname, ext, &reporter );
1154 
1155  if( !plotFileName.IsOk() )
1156  return;
1157 
1158  bool success = plotOneSheetSVG( plotFileName.GetFullPath(), screen, aRenderSettings,
1159  getModeColor() ? false : true, aPrintFrameRef );
1160 
1161  if( !success )
1162  {
1163  msg.Printf( _( "Cannot create file '%s'.\n" ), plotFileName.GetFullPath() );
1164  reporter.Report( msg, RPT_SEVERITY_ERROR );
1165  }
1166  else
1167  {
1168  msg.Printf( _( "Plotted to '%s'.\n" ), plotFileName.GetFullPath() );
1169  reporter.Report( msg, RPT_SEVERITY_ACTION );
1170  }
1171  }
1172  catch( const IO_ERROR& e )
1173  {
1174  // Cannot plot SVG file
1175  msg.Printf( wxT( "SVG Plotter exception: %s\n" ), e.What() );
1176  reporter.Report( msg, RPT_SEVERITY_ERROR );
1177  break;
1178  }
1179  }
1180 
1181  m_parent->SetCurrentSheet( oldsheetpath );
1184 }
1185 
1186 
1187 bool DIALOG_PLOT_SCHEMATIC::plotOneSheetSVG( const wxString& aFileName,
1188  SCH_SCREEN* aScreen,
1189  RENDER_SETTINGS* aRenderSettings,
1190  bool aPlotBlackAndWhite,
1191  bool aPlotFrameRef )
1192 {
1193  const PAGE_INFO& pageInfo = aScreen->GetPageSettings();
1194 
1195  SVG_PLOTTER* plotter = new SVG_PLOTTER();
1196  plotter->SetRenderSettings( aRenderSettings );
1197  plotter->SetPageSettings( pageInfo );
1198  plotter->SetColorMode( aPlotBlackAndWhite ? false : true );
1199  wxPoint plot_offset;
1200  double scale = 1.0;
1201 
1202  // Currently, plot units are in decimil
1203  plotter->SetViewport( plot_offset, IU_PER_MILS/10, scale, false );
1204 
1205  // Init :
1206  plotter->SetCreator( wxT( "Eeschema-SVG" ) );
1207 
1208  if( ! plotter->OpenFile( aFileName ) )
1209  {
1210  delete plotter;
1211  return false;
1212  }
1213 
1214  LOCALE_IO toggle;
1215 
1216  plotter->StartPlot();
1217 
1218  if( m_plotBackgroundColor->GetValue() )
1219  {
1221  wxPoint end( plotter->PageSettings().GetWidthIU(),
1222  plotter->PageSettings().GetHeightIU() );
1223  plotter->Rect( wxPoint( 0, 0 ), end, FILL_TYPE::FILLED_SHAPE, 1.0 );
1224  }
1225 
1226  if( aPlotFrameRef )
1227  {
1228  PlotDrawingSheet( plotter, &aScreen->Schematic()->Prj(), m_parent->GetTitleBlock(),
1229  pageInfo, aScreen->GetPageNumber(), aScreen->GetPageCount(),
1230  m_parent->GetScreenDesc(), aScreen->GetFileName(),
1231  plotter->GetColorMode() ?
1233  COLOR4D::BLACK, aScreen->GetVirtualPageNumber() == 1 );
1234  }
1235 
1236  aScreen->Plot( plotter );
1237 
1238  plotter->EndPlot();
1239  delete plotter;
1240 
1241  return true;
1242 }
1243 
1244 
1246 {
1247  wxString msg;
1248  wxString extMsg;
1249  wxFileName fn;
1250 
1251  extMsg.Printf( _( "Falling back to user path '%s'." ),
1252  wxStandardPaths::Get().GetDocumentsDir() );
1253 
1254  // Build the absolute path of current output directory to preselect it in the file browser.
1255  wxString path = ExpandEnvVarSubstitutions( m_outputDirectoryName->GetValue(), &Prj() );
1256 
1257  fn.SetPath( path );
1258 
1259  // If the contents of the path edit control results in an absolute path, return it as is.
1260  if( fn.IsAbsolute() )
1261  return path;
1262 
1263  // When editing a schematic that is not part of a project in the stand alone mode, the
1264  // project path is not defined.
1265  if( Prj().IsNullProject() )
1266  {
1267  SCH_SCREEN* screen = m_parent->Schematic().RootScreen();
1268 
1269  if( screen && !screen->GetFileName().IsEmpty() )
1270  {
1271  fn = screen->GetFileName();
1272  msg.Printf( _( "Cannot normalize path '%s%s'." ), fn.GetPathWithSep(), path );
1273  fn.SetPath( fn.GetPathWithSep() + path );
1274 
1275  // Normalize always returns true for a non-empty file name so clear the file name
1276  // and extension so that only the path is normalized.
1277  fn.SetName( wxEmptyString );
1278  fn.SetExt( wxEmptyString );
1279 
1280  if( fn.Normalize() )
1281  {
1282  path = fn.GetPath();
1283  }
1284  else
1285  {
1286  wxMessageDialog dlg( this, msg, _( "Warning" ),
1287  wxOK | wxCENTER | wxRESIZE_BORDER | wxICON_EXCLAMATION |
1288  wxSTAY_ON_TOP );
1289 
1290  dlg.SetExtendedMessage( extMsg );
1291  dlg.ShowModal();
1292 
1293  path = wxStandardPaths::Get().GetDocumentsDir();
1294  }
1295  }
1296  else
1297  {
1298  msg = _( "No project or path defined for the current schematic." );
1299 
1300  wxMessageDialog dlg( this, msg, _( "Warning" ),
1301  wxOK | wxCENTER | wxRESIZE_BORDER | wxICON_EXCLAMATION |
1302  wxSTAY_ON_TOP );
1303  dlg.SetExtendedMessage( extMsg );
1304  dlg.ShowModal();
1305 
1306  // Always fall back to user's document path if no other absolute path can be normalized.
1307  path = wxStandardPaths::Get().GetDocumentsDir();
1308  }
1309  }
1310  else
1311  {
1312  msg.Printf( _( "Cannot normalize path '%s%s'." ), Prj().GetProjectPath(), path );
1313 
1314  // Build the absolute path of current output directory and the project path.
1315  fn.SetPath( Prj().GetProjectPath() + path );
1316 
1317  if( fn.Normalize() )
1318  {
1319  path = fn.GetPath();
1320  }
1321  else
1322  {
1323  wxMessageDialog dlg( this, msg, _( "Warning" ),
1324  wxOK | wxCENTER | wxRESIZE_BORDER | wxICON_EXCLAMATION |
1325  wxSTAY_ON_TOP );
1326 
1327  dlg.SetExtendedMessage( extMsg );
1328  dlg.ShowModal();
1329 
1330  path = wxStandardPaths::Get().GetDocumentsDir();
1331  }
1332  }
1333 
1334  return path;
1335 }
static wxString GetDefaultFileExtension()
void SetCurrentSheet(const SCH_SHEET_PATH &aSheet)
A container for handling SCH_SHEET_PATH objects in a flattened hierarchy.
virtual bool EndPlot() override
HPGL end of plot: sort and emit graphics, pen return and release.
virtual void SetViewport(const wxPoint &aOffset, double aIusPerDecimil, double aScale, bool aMirror) override
Set the plot offset and scaling for the current plot.
Definition: PS_plotter.cpp:413
void Plot(PLOTTER *aPlotter) const
Plot all the schematic objects to aPlotter.
Definition: sch_screen.cpp:770
const wxString & GetFileName() const
Definition: sch_screen.h:137
bool plotOneSheetHpgl(const wxString &aFileName, SCH_SCREEN *aScreen, const PAGE_INFO &aPageInfo, RENDER_SETTINGS *aRenderSettings, wxPoint aPlot0ffset, double aScale, bool aPlotFrameRef, HPGL_PLOT_ORIGIN_AND_UNITS aOriginAndUnits)
virtual void SetCreator(const wxString &aCreator)
Definition: plotter.h:174
void plotOneSheetPDF(PLOTTER *aPlotter, SCH_SCREEN *aScreen, bool aPlotDrawingSheet)
static wxString GetDefaultFileExtension()
SETTINGS_MANAGER * GetSettingsManager() const
void OnOutputDirectoryBrowseClicked(wxCommandEvent &event) override
Set the m_outputDirectoryName variable to the selected directory from directory dialog.
Instantiate the current locale within a scope in which you are expecting exceptions to be thrown.
Definition: locale_io.h:40
virtual void SetViewport(const wxPoint &aOffset, double aIusPerDecimil, double aScale, bool aMirror) override
Set the plot offset and scaling for the current plot.
Container for all the knowledge about how graphical objects are drawn on any output surface/device.
bool plotOneSheetDxf(const wxString &aFileName, SCH_SCREEN *aScreen, RENDER_SETTINGS *aRenderSettings, wxPoint aPlotOffset, double aScale, bool aPlotFrameRef)
virtual bool EndPlot() override
void OnUpdateUI(wxUpdateUIEvent &event) override
Plotting engines (PostScript, Gerber, HPGL and DXF)
std::vector< COLOR_SETTINGS * > GetColorSettingsList()
virtual const COLOR4D & GetBackgroundColor()=0
Return current background color settings.
int GetHeightMils() const
Definition: page_info.h:133
virtual void Rect(const wxPoint &p1, const wxPoint &p2, FILL_TYPE fill, int width=USE_DEFAULT_LINE_WIDTH)=0
virtual void SetViewport(const wxPoint &aOffset, double aIusPerDecimil, double aScale, bool aMirror) override
Set the scale/position for the DXF plot.
virtual void StartPage()
Start a new page in the PDF document.
static constexpr double IU_PER_MM
Mock up a conversion function.
virtual void SetTitle(const wxString &aTitle)
Definition: plotter.h:176
virtual bool OpenFile(const wxString &aFullFilename)
Open or create the plot file aFullFilename.
Definition: plotter.cpp:76
wxStdDialogButtonSizer * m_sdbSizer1
static wxString GetDefaultFileExtension()
virtual void SetColorMode(bool aColorMode)
Plot in B/W or color.
Definition: plotter.h:152
wxString GetFilename() const
Definition: json_settings.h:71
SCHEMATIC_SETTINGS & Settings() const
Definition: schematic.cpp:129
int color
Definition: DXF_plotter.cpp:60
DIALOG_PLOT_SCHEMATIC(SCH_EDIT_FRAME *parent)
int GetVirtualPageNumber() const
Definition: base_screen.h:75
virtual bool EndPlot() override
Definition: PS_plotter.cpp:949
void SetRenderSettings(RENDER_SETTINGS *aSettings)
Definition: plotter.h:155
const wxChar *const tracePathsAndFiles
Flag to enable path and file name debug output.
static const wxChar * plot_sheet_list(int aSize)
bool SetType(const wxString &aStandardPageDescriptionName, bool aIsPortrait=false)
Set the name of the page type and also the sizes and margins commonly associated with that type name.
Definition: page_info.cpp:119
virtual void SetPenDiameter(double diameter)
wxFileName createPlotFileName(const wxString &aPlotFileName, const wxString &aExtension, REPORTER *aReporter=nullptr)
Create a file name with an absolute path name.
const COLOR4D & GetLayerColor(int aLayer) const
Return the color used to draw a layer.
COLOR_SETTINGS * getColorSettings()
void setPlotDrawingSheet(bool aPlot)
int GetPageCount() const
Definition: base_screen.h:72
bool plotOneSheetSVG(const wxString &aFileName, SCH_SCREEN *aScreen, RENDER_SETTINGS *aRenderSettings, bool aPlotBlackAndWhite, bool aPlotFrameRef)
void OnPlotCurrent(wxCommandEvent &event) override
KIGFX::SCH_RENDER_SETTINGS * GetRenderSettings()
Class DIALOG_PLOT_SCHEMATIC_BASE.
Schematic editor (Eeschema) main window.
Definition: color4d.h:44
const wxString ExpandEnvVarSubstitutions(const wxString &aString, PROJECT *aProject)
Replace any environment variable & text variable references with their values.
Definition: common.cpp:279
void createPDFFile(bool aPlotAll, bool aPlotDrawingSheet, RENDER_SETTINGS *aRenderSettings)
void getPlotOptions(RENDER_SETTINGS *aSettings)
A pure virtual class used to derive REPORTER objects from.
Definition: reporter.h:64
void UpdateAllScreenReferences()
Update all the symbol references for this sheet path.
virtual void SetColor(const COLOR4D &color) override
The SetColor implementation is split with the subclasses: The PSLIKE computes the rgb values,...
void createSVGFile(bool aPlotAll, bool aPlotFrameRef, RENDER_SETTINGS *aSettings)
void OnPageSizeSelected(wxCommandEvent &event) override
const PAGE_INFO & GetPageSettings() const
Definition: sch_screen.h:124
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
Report a string with a given severity.
HPGL_PLOT_ORIGIN_AND_UNITS
void restoreEnvironment(PDF_PLOTTER *aPlotter, SCH_SHEET_PATH &aOldsheetpath)
Everything done, close the plot and restore the environment.
virtual const wxString AbsolutePath(const wxString &aFileName) const
Fix up aFileName if it is relative to the project's directory to be an absolute path and filename.
Definition: project.cpp:271
const wxString & GetPageNumber() const
Definition: base_screen.cpp:71
virtual void SetViewport(const wxPoint &aOffset, double aIusPerDecimil, double aScale, bool aMirror) override
Set the plot offset and scaling for the current plot.
void SetUserCoordsFit(bool user_coords_fit)
Set whether the user coordinate system is fit to content.
Definition: plotter_hpgl.h:60
void setupPlotPagePDF(PLOTTER *aPlotter, SCH_SCREEN *aScreen)
static wxString GetDefaultFileExtension()
Definition: plotter_dxf.h:49
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.
virtual bool EndPlot() override
virtual void ClosePage()
Close the current page in the PDF document (and emit its compressed stream).
virtual bool StartPlot() override
The code within this function (and the CloseFilePS function) creates postscript files whose contents ...
Definition: PS_plotter.cpp:792
void plotSchematic(bool aPlotAll)
void OnPlotAll(wxCommandEvent &event) override
virtual void SetColor(const COLOR4D &color) override
The SetColor implementation is split with the subclasses: The PSLIKE computes the rgb values,...
Definition: PS_plotter.cpp:64
virtual bool StartPlot() override
Opens the DXF plot with a skeleton header.
void createDxfFile(bool aPlotAll, bool aPlotDrawingSheet, RENDER_SETTINGS *aRenderSettings)
virtual const wxString What() const
A composite of Problem() and Where()
Definition: exceptions.cpp:30
bool plotOneSheetPS(const wxString &aFileName, SCH_SCREEN *aScreen, RENDER_SETTINGS *aRenderSettings, const PAGE_INFO &aPageInfo, wxPoint aPlot0ffset, double aScale, bool aPlotFrameRef)
PLOT_FORMAT
The set of supported output plot formats.
Definition: plotter.h:67
Describe the page size and margins of a paper page on which to eventually print or plot.
Definition: page_info.h:53
PROJECT & Prj() const
Return a reference to the PROJECT associated with this KIWAY.
bool EnsureFileDirectoryExists(wxFileName *aTargetFullFileName, const wxString &aBaseFilename, REPORTER *aReporter)
Make aTargetFullFileName absolute and create the path of this file if it doesn't yet exist.
Definition: common.cpp:307
KIFACE_I & Kiface()
Global KIFACE_I "get" accessor.
void BuildSheetList(SCH_SHEET *aSheet, bool aCheckIntegrity)
Build the list of sheets and their sheet path from aSheet.
SCHEMATIC & Schematic() const
virtual bool EndPlot() override
virtual bool StartPlot() override
Create SVG file header.
#define _(s)
wxLogTrace helper definitions.
Handle access to a stack of flattened SCH_SHEET objects by way of a path for creating a flattened sch...
void createPSFile(bool aPlotAll, bool aPlotFrameRef, RENDER_SETTINGS *aSettings)
wxString GetFileName() const
Return the filename corresponding to this sheet.
Definition: sch_sheet.h:315
wxBitmap KiBitmap(BITMAPS aBitmap, int aHeightTag)
Construct a wxBitmap from an image identifier Returns the image from the active theme if the image ha...
Definition: bitmap.cpp:105
virtual bool IsNullProject() const
Check if this project is a null project (i.e.
Definition: project.cpp:135
virtual void SetViewport(const wxPoint &aOffset, double aIusPerDecimil, double aScale, bool aMirror)=0
Set the plot offset and scaling for the current plot.
virtual void SetColor(const COLOR4D &color)=0
PROJECT & Prj() const override
Return a reference to the project this schematic is part of.
Definition: schematic.h:75
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, const CPTREE &aTree)
Output a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:200
const PAGE_INFO & GetPageSettings() const override
void finishDialogSettings()
In all dialogs, we must call the same functions to fix minimal dlg size, the default position and per...
COLOR_SETTINGS * GetColorSettings(const wxString &aName="user")
Retrieves a color settings object that applications can read colors from.
void SetTargetChordLength(double chord_len)
Set the target length of chords used to draw approximated circles and arcs.
Base plotter engine class.
Definition: plotter.h:121
COLOR4D GetColor(int aLayer) const
virtual void SetBackgroundColor(const COLOR4D &aColor)=0
Set the background color.
SCH_SHEET & Root() const
Definition: schematic.h:92
RENDER_SETTINGS * RenderSettings()
Definition: plotter.h:156
const int scale
SCH_SCREEN * LastScreen()
void SetSheetNumberAndCount()
Set the m_ScreenNumber and m_NumberOfScreens members for screens.
bool IsPortrait() const
Definition: page_info.h:117
void SetUserCoords(bool user_coords)
Switch to the user coordinate system.
Definition: plotter_hpgl.h:57
SCHEMATIC * Schematic() const
Definition: sch_screen.cpp:90
const TITLE_BLOCK & GetTitleBlock() const override
HPGL_PLOT_ORIGIN_AND_UNITS getPlotOriginAndUnits()
virtual void SetValue(int aValue)
Set new value (in Internal Units) for the text field, taking care of units conversion.
virtual void Rect(const wxPoint &p1, const wxPoint &p2, FILL_TYPE fill, int width=USE_DEFAULT_LINE_WIDTH) override
void PlotDrawingSheet(PLOTTER *plotter, const PROJECT *aProject, const TITLE_BLOCK &aTitleBlock, const PAGE_INFO &aPageInfo, const wxString &aSheetNumber, int aSheetCount, const wxString &aSheetDesc, const wxString &aFilename, COLOR4D aColor, bool aIsFirstPage)
void SortByPageNumbers(bool aUpdateVirtualPageNums=true)
Sort the list of sheets by page number.
static wxString GetDefaultFileExtension()
Definition: plotter_hpgl.h:45
#define IU_PER_MILS
Definition: plotter.cpp:137
virtual void Rect(const wxPoint &p1, const wxPoint &p2, FILL_TYPE fill, int width=USE_DEFAULT_LINE_WIDTH) override
Definition: PS_plotter.cpp:572
The common library.
These settings were stored in SCH_BASE_FRAME previously.
wxString GetUniqueFilenameForCurrentSheet()
virtual long long int GetValue()
Return the current value in Internal Units.
Store schematic specific render settings.
Definition: sch_painter.h:70
virtual bool OpenFile(const wxString &aFullFilename) override
Open or create the plot file aFullFilename.
Color settings are a bit different than most of the settings objects in that there can be more than o...
void createHPGLFile(bool aPlotAll, bool aPlotFrameRef, RENDER_SETTINGS *aRenderSettings)
SCH_SHEET_PATH & GetCurrentSheet() const
const wxString & GetTitle() const
Definition: title_block.h:63
WX_HTML_REPORT_PANEL * m_MessagesBox
SCH_SCREEN * RootScreen() const
Helper to retrieve the screen of the root sheet.
Definition: schematic.cpp:117
void SetDefaultPenWidth(int aWidth)
void SetFileName(const wxString &aReportFileName)
virtual bool StartPlot() override
The PDF engine supports multiple pages; the first one is opened 'for free' the following are to be cl...
virtual void LoadColors(const COLOR_SETTINGS *aSettings)
PAGE_INFO & PageSettings()
Definition: plotter.h:159
static constexpr int Millimeter2iu(double mm)
void SetPortrait(bool aIsPortrait)
Rotate the paper page 90 degrees.
Definition: page_info.cpp:186
Hold an error message and may be used when throwing exceptions containing meaningful error messages.
Definition: ki_exception.h:75
wxString getOutputPath()
Determine the best absolute path to plot files given the contents of the path edit control.
void Enable(bool aEnable)
Enable/disable the label, widget and units label.
int GetWidthMils() const
Definition: page_info.h:130
virtual void SetPageSettings(const PAGE_INFO &aPageSettings)
Definition: plotter.h:158
A color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:103
void setModeColor(bool aColor)
bool GetColorMode() const
Definition: plotter.h:153