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.

173 lines
5.8 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
  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-2010 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 <plot_common.h>
  27. #include <class_sch_screen.h>
  28. #include <wxEeschemaStruct.h>
  29. #include <base_units.h>
  30. #include <sch_sheet_path.h>
  31. #include <dialog_plot_schematic.h>
  32. #include <project.h>
  33. void DIALOG_PLOT_SCHEMATIC::createPSFile( 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. wxString plotFileName;
  39. PAGE_INFO actualPage; // page size selected in schematic
  40. PAGE_INFO plotPage; // page size selected to plot
  41. /* When printing all pages, the printed page is not the current page.
  42. * In complex hierarchies, we must update component references
  43. * and others parameters in the given printed SCH_SCREEN, accordint to the sheet path
  44. * because in complex hierarchies a SCH_SCREEN (a drawing )
  45. * is shared between many sheets and component references depend on the actual sheet path used
  46. */
  47. SCH_SHEET_LIST SheetList( NULL );
  48. sheetpath = SheetList.GetFirst();
  49. SCH_SHEET_PATH list;
  50. while( true )
  51. {
  52. if( aPlotAll )
  53. {
  54. if( sheetpath == NULL )
  55. break;
  56. list.Clear();
  57. if( list.BuildSheetPathInfoFromSheetPathValue( sheetpath->Path() ) )
  58. {
  59. m_parent->SetCurrentSheet( list );
  60. m_parent->GetCurrentSheet().UpdateAllScreenReferences();
  61. m_parent->SetSheetNumberAndCount();
  62. screen = m_parent->GetCurrentSheet().LastScreen();
  63. }
  64. else // Should not happen
  65. return;
  66. sheetpath = SheetList.GetNext();
  67. }
  68. actualPage = screen->GetPageSettings();
  69. switch( m_pageSizeSelect )
  70. {
  71. case PAGE_SIZE_A:
  72. plotPage.SetType( wxT( "A" ) );
  73. plotPage.SetPortrait( actualPage.IsPortrait() );
  74. break;
  75. case PAGE_SIZE_A4:
  76. plotPage.SetType( wxT( "A4" ) );
  77. plotPage.SetPortrait( actualPage.IsPortrait() );
  78. break;
  79. case PAGE_SIZE_AUTO:
  80. default:
  81. plotPage = actualPage;
  82. break;
  83. }
  84. double scalex = (double) plotPage.GetWidthMils() / actualPage.GetWidthMils();
  85. double scaley = (double) plotPage.GetHeightMils() / actualPage.GetHeightMils();
  86. double scale = std::min( scalex, scaley );
  87. wxPoint plot_offset;
  88. plotFileName = m_parent->GetUniqueFilenameForCurrentSheet() + wxT( "." )
  89. + PS_PLOTTER::GetDefaultFileExtension();
  90. plotFileName = Prj().AbsolutePath( plotFileName );
  91. wxString msg;
  92. if( plotOneSheetPS( plotFileName, screen, plotPage, plot_offset,
  93. scale, aPlotFrameRef ) )
  94. msg.Printf( _( "Plot: <%s> OK\n" ), GetChars( plotFileName ) );
  95. else // Error
  96. msg.Printf( _( "Unable to create <%s>\n" ), GetChars( plotFileName ) );
  97. m_MessagesBox->AppendText( msg );
  98. if( !aPlotAll )
  99. break;
  100. }
  101. m_parent->SetCurrentSheet( oldsheetpath );
  102. m_parent->GetCurrentSheet().UpdateAllScreenReferences();
  103. m_parent->SetSheetNumberAndCount();
  104. }
  105. bool DIALOG_PLOT_SCHEMATIC::plotOneSheetPS( const wxString& aFileName,
  106. SCH_SCREEN* aScreen,
  107. const PAGE_INFO& aPageInfo,
  108. wxPoint aPlot0ffset,
  109. double aScale,
  110. bool aPlotFrameRef )
  111. {
  112. PS_PLOTTER* plotter = new PS_PLOTTER();
  113. plotter->SetPageSettings( aPageInfo );
  114. plotter->SetDefaultLineWidth( GetDefaultLineThickness() );
  115. plotter->SetColorMode( getModeColor() );
  116. plotter->SetViewport( aPlot0ffset, IU_PER_DECIMILS, aScale, false );
  117. // Init :
  118. plotter->SetCreator( wxT( "Eeschema-PS" ) );
  119. if( ! plotter->OpenFile( aFileName ) )
  120. {
  121. delete plotter;
  122. return false;
  123. }
  124. SetLocaleTo_C_standard();
  125. plotter->StartPlot();
  126. if( aPlotFrameRef )
  127. {
  128. plotter->SetColor( BLACK );
  129. PlotWorkSheet( plotter, m_parent->GetTitleBlock(),
  130. m_parent->GetPageSettings(),
  131. aScreen->m_ScreenNumber, aScreen->m_NumberOfScreens,
  132. m_parent->GetScreenDesc(),
  133. aScreen->GetFileName() );
  134. }
  135. aScreen->Plot( plotter );
  136. plotter->EndPlot();
  137. delete plotter;
  138. SetLocaleTo_Default();
  139. return true;
  140. }