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.

181 lines
6.5 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
  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-2020 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 <plotters_specific.h>
  26. #include <sch_edit_frame.h>
  27. #include <base_units.h>
  28. #include <sch_sheet_path.h>
  29. #include <pgm_base.h>
  30. #include <project.h>
  31. #include <reporter.h>
  32. #include <settings/settings_manager.h>
  33. #include <sch_painter.h>
  34. #include <schematic.h>
  35. #include <dialog_plot_schematic.h>
  36. #include <wx_html_report_panel.h>
  37. void DIALOG_PLOT_SCHEMATIC::createPSFile( bool aPlotAll, bool aPlotFrameRef,
  38. RENDER_SETTINGS* aRenderSettings )
  39. {
  40. SCH_SHEET_PATH oldsheetpath = m_parent->GetCurrentSheet(); // sheetpath is saved here
  41. PAGE_INFO plotPage; // page size selected to plot
  42. /* When printing all pages, the printed page is not the current page.
  43. * In complex hierarchies, we must update component references
  44. * and others parameters in the given printed SCH_SCREEN, accordint to the sheet path
  45. * because in complex hierarchies a SCH_SCREEN (a drawing )
  46. * is shared between many sheets and component references depend on the actual sheet path used
  47. */
  48. SCH_SHEET_LIST sheetList;
  49. if( aPlotAll )
  50. sheetList.BuildSheetList( &m_parent->Schematic().Root() );
  51. else
  52. sheetList.push_back( m_parent->GetCurrentSheet() );
  53. for( unsigned i = 0; i < sheetList.size(); i++ )
  54. {
  55. m_parent->SetCurrentSheet( sheetList[i] );
  56. m_parent->GetCurrentSheet().UpdateAllScreenReferences();
  57. m_parent->SetSheetNumberAndCount();
  58. SCH_SCREEN* screen = m_parent->GetCurrentSheet().LastScreen();
  59. PAGE_INFO actualPage = screen->GetPageSettings();
  60. switch( m_pageSizeSelect )
  61. {
  62. case PAGE_SIZE_A:
  63. plotPage.SetType( wxT( "A" ) );
  64. plotPage.SetPortrait( actualPage.IsPortrait() );
  65. break;
  66. case PAGE_SIZE_A4:
  67. plotPage.SetType( wxT( "A4" ) );
  68. plotPage.SetPortrait( actualPage.IsPortrait() );
  69. break;
  70. case PAGE_SIZE_AUTO:
  71. default:
  72. plotPage = actualPage;
  73. break;
  74. }
  75. double scalex = (double) plotPage.GetWidthMils() / actualPage.GetWidthMils();
  76. double scaley = (double) plotPage.GetHeightMils() / actualPage.GetHeightMils();
  77. double scale = std::min( scalex, scaley );
  78. wxPoint plot_offset;
  79. wxString msg;
  80. REPORTER& reporter = m_MessagesBox->Reporter();
  81. try
  82. {
  83. wxString fname = m_parent->GetUniqueFilenameForCurrentSheet();
  84. wxString ext = PS_PLOTTER::GetDefaultFileExtension();
  85. wxFileName plotFileName = createPlotFileName( fname, ext, &reporter );
  86. if( plotOneSheetPS( plotFileName.GetFullPath(), screen, aRenderSettings, plotPage,
  87. plot_offset, scale, aPlotFrameRef ) )
  88. {
  89. msg.Printf( _( "Plot: \"%s\" OK.\n" ), plotFileName.GetFullPath() );
  90. reporter.Report( msg, RPT_SEVERITY_ACTION );
  91. }
  92. else
  93. {
  94. // Error
  95. msg.Printf( _( "Unable to create file \"%s\".\n" ), plotFileName.GetFullPath() );
  96. reporter.Report( msg, RPT_SEVERITY_ERROR );
  97. }
  98. }
  99. catch( IO_ERROR& e )
  100. {
  101. msg.Printf( wxT( "PS Plotter exception: %s"), e.What() );
  102. reporter.Report( msg, RPT_SEVERITY_ERROR );
  103. }
  104. }
  105. m_parent->SetCurrentSheet( oldsheetpath );
  106. m_parent->GetCurrentSheet().UpdateAllScreenReferences();
  107. m_parent->SetSheetNumberAndCount();
  108. }
  109. bool DIALOG_PLOT_SCHEMATIC::plotOneSheetPS( const wxString& aFileName,
  110. SCH_SCREEN* aScreen,
  111. RENDER_SETTINGS* aRenderSettings,
  112. const PAGE_INFO& aPageInfo,
  113. wxPoint aPlot0ffset,
  114. double aScale,
  115. bool aPlotFrameRef )
  116. {
  117. PS_PLOTTER* plotter = new PS_PLOTTER();
  118. plotter->SetRenderSettings( aRenderSettings );
  119. plotter->SetPageSettings( aPageInfo );
  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( m_plotBackgroundColor->GetValue() )
  133. {
  134. plotter->SetColor( plotter->RenderSettings()->GetLayerColor( LAYER_SCHEMATIC_BACKGROUND ) );
  135. wxPoint end( plotter->PageSettings().GetWidthIU(),
  136. plotter->PageSettings().GetHeightIU() );
  137. plotter->Rect( wxPoint( 0, 0 ), end, FILLED_SHAPE, 1.0 );
  138. }
  139. if( aPlotFrameRef )
  140. {
  141. PlotWorkSheet( plotter, &aScreen->Schematic()->Prj(), m_parent->GetTitleBlock(), aPageInfo,
  142. aScreen->m_ScreenNumber, aScreen->m_NumberOfScreens,
  143. m_parent->GetScreenDesc(), aScreen->GetFileName(),
  144. plotter->GetColorMode() ?
  145. plotter->RenderSettings()->GetLayerColor( LAYER_SCHEMATIC_WORKSHEET ) :
  146. COLOR4D::BLACK );
  147. }
  148. aScreen->Plot( plotter );
  149. plotter->EndPlot();
  150. delete plotter;
  151. return true;
  152. }