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.

179 lines
6.2 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
  1. /** @file plot_schematic_PDF.cpp
  2. */
  3. /*
  4. * This program source code file is part of KiCad, a free EDA CAD application.
  5. *
  6. * Copyright (C) 1992-2010 Jean-Pierre Charras <jean-pierre.charras@gipsa-lab.inpg.fr
  7. * Copyright (C) 1992-2010 KiCad Developers, see change_log.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. #include <fctsys.h>
  27. #include <plot_common.h>
  28. #include <class_sch_screen.h>
  29. #include <wxEeschemaStruct.h>
  30. #include <base_units.h>
  31. #include <sch_sheet_path.h>
  32. #include <dialog_plot_schematic.h>
  33. void DIALOG_PLOT_SCHEMATIC::createPDFFile( bool aPlotAll, bool aPlotFrameRef )
  34. {
  35. SCH_SCREEN* screen = m_parent->GetScreen();
  36. SCH_SHEET_PATH* sheetpath;
  37. SCH_SHEET_PATH oldsheetpath = m_parent->GetCurrentSheet(); // sheetpath is saved here
  38. wxPoint plot_offset;
  39. /* When printing all pages, the printed page is not the current page. In
  40. * complex hierarchies, we must update component references and others
  41. * parameters in the given printed SCH_SCREEN, accordint to the sheet path
  42. * because in complex hierarchies a SCH_SCREEN (a drawing ) is shared
  43. * between many sheets and component references depend on the actual sheet
  44. * path used
  45. */
  46. SCH_SHEET_LIST SheetList( NULL );
  47. sheetpath = SheetList.GetFirst();
  48. // Allocate the plotter and set the job level parameter
  49. PDF_PLOTTER* plotter = new PDF_PLOTTER();
  50. plotter->SetDefaultLineWidth( GetDefaultLineThickness() );
  51. plotter->SetColorMode( getModeColor() );
  52. plotter->SetCreator( wxT( "Eeschema-PDF" ) );
  53. wxString msg;
  54. wxString plotFileName;
  55. // First page handling is different
  56. bool first_page = true;
  57. do
  58. {
  59. // Step over the schematic hierarchy
  60. if( aPlotAll )
  61. {
  62. SCH_SHEET_PATH list;
  63. if( list.BuildSheetPathInfoFromSheetPathValue( sheetpath->Path() ) )
  64. {
  65. m_parent->SetCurrentSheet( list );
  66. m_parent->GetCurrentSheet().UpdateAllScreenReferences();
  67. m_parent->SetSheetNumberAndCount();
  68. screen = m_parent->GetCurrentSheet().LastScreen();
  69. }
  70. else // Should not happen
  71. wxASSERT( 0 );
  72. sheetpath = SheetList.GetNext();
  73. }
  74. if( first_page )
  75. {
  76. plotFileName = m_parent->GetUniqueFilenameForCurrentSheet() + wxT( "." )
  77. + PDF_PLOTTER::GetDefaultFileExtension();
  78. if( ! plotter->OpenFile( plotFileName ) )
  79. {
  80. msg.Printf( _( "Unable to create <%s>\n" ), GetChars( plotFileName ) );
  81. m_MessagesBox->AppendText( msg );
  82. delete plotter;
  83. return;
  84. }
  85. // Open the plotter and do the first page
  86. SetLocaleTo_C_standard();
  87. setupPlotPagePDF( plotter, screen );
  88. plotter->StartPlot();
  89. first_page = false;
  90. }
  91. else
  92. {
  93. /* For the following pages you need to close the (finished) page,
  94. * reconfigure, and then start a new one */
  95. plotter->ClosePage();
  96. setupPlotPagePDF( plotter, screen );
  97. plotter->StartPage();
  98. }
  99. plotOneSheetPDF( plotter, screen, aPlotFrameRef );
  100. } while( aPlotAll && sheetpath );
  101. // Everything done, close the plot and restore the environment
  102. plotter->EndPlot();
  103. delete plotter;
  104. SetLocaleTo_Default();
  105. // Restore the previous sheet
  106. m_parent->SetCurrentSheet( oldsheetpath );
  107. m_parent->GetCurrentSheet().UpdateAllScreenReferences();
  108. m_parent->SetSheetNumberAndCount();
  109. msg.Printf( _( "Plot: <%s> OK\n" ), GetChars( plotFileName ) );
  110. m_MessagesBox->AppendText( msg );
  111. }
  112. void DIALOG_PLOT_SCHEMATIC::plotOneSheetPDF( PLOTTER* aPlotter,
  113. SCH_SCREEN* aScreen,
  114. bool aPlotFrameRef )
  115. {
  116. if( aPlotFrameRef )
  117. {
  118. aPlotter->SetColor( BLACK );
  119. PlotWorkSheet( aPlotter, m_parent->GetTitleBlock(),
  120. m_parent->GetPageSettings(),
  121. aScreen->m_ScreenNumber, aScreen->m_NumberOfScreens,
  122. m_parent->GetScreenDesc(),
  123. aScreen->GetFileName() );
  124. }
  125. aScreen->Plot( aPlotter );
  126. }
  127. void DIALOG_PLOT_SCHEMATIC::setupPlotPagePDF( PLOTTER * aPlotter, SCH_SCREEN* aScreen )
  128. {
  129. PAGE_INFO plotPage; // page size selected to plot
  130. // Considerations on page size and scaling requests
  131. PAGE_INFO actualPage = aScreen->GetPageSettings(); // page size selected in schematic
  132. switch( m_pageSizeSelect )
  133. {
  134. case PAGE_SIZE_A:
  135. plotPage.SetType( wxT( "A" ) );
  136. plotPage.SetPortrait( actualPage.IsPortrait() );
  137. break;
  138. case PAGE_SIZE_A4:
  139. plotPage.SetType( wxT( "A4" ) );
  140. plotPage.SetPortrait( actualPage.IsPortrait() );
  141. break;
  142. case PAGE_SIZE_AUTO:
  143. default:
  144. plotPage = actualPage;
  145. break;
  146. }
  147. double scalex = (double) plotPage.GetWidthMils() / actualPage.GetWidthMils();
  148. double scaley = (double) plotPage.GetHeightMils() / actualPage.GetHeightMils();
  149. double scale = std::min( scalex, scaley );
  150. aPlotter->SetPageSettings( plotPage );
  151. aPlotter->SetViewport( wxPoint( 0, 0 ), IU_PER_DECIMILS, scale, false );
  152. }