You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

174 lines
6.1 KiB

13 years ago
13 years ago
13 years ago
13 years ago
13 years ago
13 years ago
13 years ago
13 years ago
13 years ago
13 years ago
13 years ago
13 years ago
13 years ago
13 years ago
13 years ago
13 years ago
13 years ago
13 years ago
13 years ago
13 years ago
13 years ago
13 years ago
13 years ago
13 years ago
  1. /** @file plot_schematic_PS.cpp
  2. */
  3. /*
  4. * This program source code file is part of KiCad, a free EDA CAD application.
  5. *
  6. * Copyright (C) 1992-2016 KiCad Developers, see change_log.txt for contributors.
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License
  10. * as published by the Free Software Foundation; either version 2
  11. * of the License, or (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, you may find one here:
  20. * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
  21. * or you may search the http://www.gnu.org website for the version 2 license,
  22. * or you may write to the Free Software Foundation, Inc.,
  23. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
  24. */
  25. #include <fctsys.h>
  26. #include <plotter.h>
  27. #include <sch_edit_frame.h>
  28. #include <base_units.h>
  29. #include <sch_sheet_path.h>
  30. #include <project.h>
  31. #include <reporter.h>
  32. #include <dialog_plot_schematic.h>
  33. #include <wx_html_report_panel.h>
  34. void DIALOG_PLOT_SCHEMATIC::createPSFile( bool aPlotAll, bool aPlotFrameRef )
  35. {
  36. SCH_SCREEN* screen = m_parent->GetScreen();
  37. SCH_SHEET_PATH oldsheetpath = m_parent->GetCurrentSheet(); // sheetpath is saved here
  38. PAGE_INFO actualPage; // page size selected in schematic
  39. PAGE_INFO plotPage; // page size selected to plot
  40. /* When printing all pages, the printed page is not the current page.
  41. * In complex hierarchies, we must update component references
  42. * and others parameters in the given printed SCH_SCREEN, accordint to the sheet path
  43. * because in complex hierarchies a SCH_SCREEN (a drawing )
  44. * is shared between many sheets and component references depend on the actual sheet path used
  45. */
  46. SCH_SHEET_LIST sheetList;
  47. if( aPlotAll )
  48. sheetList.BuildSheetList( g_RootSheet );
  49. else
  50. sheetList.push_back( m_parent->GetCurrentSheet() );
  51. for( unsigned i = 0; i < sheetList.size(); i++ )
  52. {
  53. m_parent->SetCurrentSheet( sheetList[i] );
  54. m_parent->GetCurrentSheet().UpdateAllScreenReferences();
  55. m_parent->SetSheetNumberAndCount();
  56. screen = m_parent->GetCurrentSheet().LastScreen();
  57. actualPage = screen->GetPageSettings();
  58. switch( m_pageSizeSelect )
  59. {
  60. case PAGE_SIZE_A:
  61. plotPage.SetType( wxT( "A" ) );
  62. plotPage.SetPortrait( actualPage.IsPortrait() );
  63. break;
  64. case PAGE_SIZE_A4:
  65. plotPage.SetType( wxT( "A4" ) );
  66. plotPage.SetPortrait( actualPage.IsPortrait() );
  67. break;
  68. case PAGE_SIZE_AUTO:
  69. default:
  70. plotPage = actualPage;
  71. break;
  72. }
  73. double scalex = (double) plotPage.GetWidthMils() / actualPage.GetWidthMils();
  74. double scaley = (double) plotPage.GetHeightMils() / actualPage.GetHeightMils();
  75. double scale = std::min( scalex, scaley );
  76. wxPoint plot_offset;
  77. wxString outputDirName = m_outputDirectoryName->GetValue();
  78. wxString msg;
  79. REPORTER& reporter = m_MessagesBox->Reporter();
  80. try
  81. {
  82. wxString fname = m_parent->GetUniqueFilenameForCurrentSheet();
  83. wxString ext = PS_PLOTTER::GetDefaultFileExtension();
  84. wxFileName plotFileName = createPlotFileName( m_outputDirectoryName,
  85. fname, ext, &reporter );
  86. if( plotOneSheetPS( plotFileName.GetFullPath(), screen, plotPage, plot_offset,
  87. scale, aPlotFrameRef ) )
  88. {
  89. msg.Printf( _( "Plot: \"%s\" OK.\n" ), GetChars( plotFileName.GetFullPath() ) );
  90. reporter.Report( msg, REPORTER::RPT_ACTION );
  91. }
  92. else
  93. {
  94. // Error
  95. msg.Printf( _( "Unable to create file \"%s\".\n" ),
  96. GetChars( plotFileName.GetFullPath() ) );
  97. reporter.Report( msg, REPORTER::RPT_ERROR );
  98. }
  99. }
  100. catch( IO_ERROR& e )
  101. {
  102. msg.Printf( wxT( "PS Plotter exception: %s"), GetChars( e.What() ) );
  103. reporter.Report( msg, REPORTER::RPT_ERROR );
  104. }
  105. }
  106. m_parent->SetCurrentSheet( oldsheetpath );
  107. m_parent->GetCurrentSheet().UpdateAllScreenReferences();
  108. m_parent->SetSheetNumberAndCount();
  109. }
  110. bool DIALOG_PLOT_SCHEMATIC::plotOneSheetPS( const wxString& aFileName,
  111. SCH_SCREEN* aScreen,
  112. const PAGE_INFO& aPageInfo,
  113. wxPoint aPlot0ffset,
  114. double aScale,
  115. bool aPlotFrameRef )
  116. {
  117. PS_PLOTTER* plotter = new PS_PLOTTER();
  118. plotter->SetPageSettings( aPageInfo );
  119. plotter->SetDefaultLineWidth( GetDefaultLineThickness() );
  120. plotter->SetColorMode( getModeColor() );
  121. // Currently, plot units are in decimil
  122. plotter->SetViewport( aPlot0ffset, IU_PER_MILS/10, aScale, false );
  123. // Init :
  124. plotter->SetCreator( wxT( "Eeschema-PS" ) );
  125. if( ! plotter->OpenFile( aFileName ) )
  126. {
  127. delete plotter;
  128. return false;
  129. }
  130. LOCALE_IO toggle; // Switch the locale to standard C
  131. plotter->StartPlot();
  132. if( aPlotFrameRef )
  133. {
  134. plotter->SetColor( BLACK );
  135. PlotWorkSheet( plotter, m_parent->GetTitleBlock(),
  136. m_parent->GetPageSettings(),
  137. aScreen->m_ScreenNumber, aScreen->m_NumberOfScreens,
  138. m_parent->GetScreenDesc(),
  139. aScreen->GetFileName() );
  140. }
  141. aScreen->Plot( plotter );
  142. plotter->EndPlot();
  143. delete plotter;
  144. return true;
  145. }