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.

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