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.

225 lines
7.3 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
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_HPGL.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 jp.charras at wanadoo.fr
  7. * Copyright (C) 1992-2020 KiCad Developers, see AUTHORS.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 <plotter.h>
  28. #include <sch_edit_frame.h>
  29. #include <base_units.h>
  30. #include <sch_sheet_path.h>
  31. #include <schematic.h>
  32. #include <project.h>
  33. #include <pgm_base.h>
  34. #include <settings/settings_manager.h>
  35. #include <dialog_plot_schematic.h>
  36. #include <wx_html_report_panel.h>
  37. enum HPGL_PAGEZ_T {
  38. PAGE_DEFAULT = 0,
  39. HPGL_PAGE_SIZE_A5,
  40. HPGL_PAGE_SIZE_A4,
  41. HPGL_PAGE_SIZE_A3,
  42. HPGL_PAGE_SIZE_A2,
  43. HPGL_PAGE_SIZE_A1,
  44. HPGL_PAGE_SIZE_A0,
  45. HPGL_PAGE_SIZE_A,
  46. HPGL_PAGE_SIZE_B,
  47. HPGL_PAGE_SIZE_C,
  48. HPGL_PAGE_SIZE_D,
  49. HPGL_PAGE_SIZE_E,
  50. };
  51. static const wxChar* plot_sheet_list( int aSize )
  52. {
  53. switch( aSize )
  54. {
  55. default:
  56. case PAGE_DEFAULT: return nullptr;
  57. case HPGL_PAGE_SIZE_A5: return wxT( "A5" );
  58. case HPGL_PAGE_SIZE_A4: return wxT( "A4" );
  59. case HPGL_PAGE_SIZE_A3: return wxT( "A3" );
  60. case HPGL_PAGE_SIZE_A2: return wxT( "A2" );
  61. case HPGL_PAGE_SIZE_A1: return wxT( "A1" );
  62. case HPGL_PAGE_SIZE_A0: return wxT( "A0" );
  63. case HPGL_PAGE_SIZE_A: return wxT( "A" );
  64. case HPGL_PAGE_SIZE_B: return wxT( "B" );
  65. case HPGL_PAGE_SIZE_C: return wxT( "C" );
  66. case HPGL_PAGE_SIZE_D: return wxT( "D" );
  67. case HPGL_PAGE_SIZE_E: return wxT( "E" );
  68. }
  69. }
  70. void DIALOG_PLOT_SCHEMATIC::SetHPGLPenWidth()
  71. {
  72. m_HPGLPenSize = m_penWidth.GetValue();
  73. if( m_HPGLPenSize > Millimeter2iu( 2 ) )
  74. m_HPGLPenSize = Millimeter2iu( 2 );
  75. if( m_HPGLPenSize < Millimeter2iu( 0.01 ) )
  76. m_HPGLPenSize = Millimeter2iu( 0.01 );
  77. }
  78. void DIALOG_PLOT_SCHEMATIC::createHPGLFile( bool aPlotAll, bool aPlotFrameRef,
  79. RENDER_SETTINGS* aRenderSettings )
  80. {
  81. SCH_SCREEN* screen = m_parent->GetScreen();
  82. SCH_SHEET_PATH oldsheetpath = m_parent->GetCurrentSheet();
  83. /* When printing all pages, the printed page is not the current page.
  84. * In complex hierarchies, we must setup references and other parameters
  85. * in the printed SCH_SCREEN
  86. * because in complex hierarchies a SCH_SCREEN (a schematic drawings)
  87. * is shared between many sheets
  88. */
  89. SCH_SHEET_LIST sheetList;
  90. if( aPlotAll )
  91. sheetList.BuildSheetList( &m_parent->Schematic().Root() );
  92. else
  93. sheetList.push_back( m_parent->GetCurrentSheet() );
  94. REPORTER& reporter = m_MessagesBox->Reporter();
  95. SetHPGLPenWidth();
  96. for( unsigned i = 0; i < sheetList.size(); i++ )
  97. {
  98. m_parent->SetCurrentSheet( sheetList[i] );
  99. m_parent->GetCurrentSheet().UpdateAllScreenReferences();
  100. m_parent->SetSheetNumberAndCount();
  101. screen = m_parent->GetCurrentSheet().LastScreen();
  102. if( !screen ) // LastScreen() may return NULL
  103. screen = m_parent->GetScreen();
  104. const PAGE_INFO& curPage = screen->GetPageSettings();
  105. PAGE_INFO plotPage = curPage;
  106. // if plotting on a page size other than curPage
  107. if( m_paperSizeOption->GetSelection() != PAGE_DEFAULT )
  108. plotPage.SetType( plot_sheet_list( m_paperSizeOption->GetSelection() ) );
  109. // Calculation of conversion scales.
  110. double plot_scale = (double) plotPage.GetWidthMils() / curPage.GetWidthMils();
  111. // Calculate offsets
  112. wxPoint plotOffset;
  113. wxString msg;
  114. if( GetPlotOriginCenter() )
  115. {
  116. plotOffset.x = plotPage.GetWidthIU() / 2;
  117. plotOffset.y = -plotPage.GetHeightIU() / 2;
  118. }
  119. try
  120. {
  121. wxString fname = m_parent->GetUniqueFilenameForCurrentSheet();
  122. wxString ext = HPGL_PLOTTER::GetDefaultFileExtension();
  123. wxFileName plotFileName = createPlotFileName( fname, ext, &reporter );
  124. LOCALE_IO toggle;
  125. if( Plot_1_Page_HPGL( plotFileName.GetFullPath(), screen, plotPage, aRenderSettings,
  126. plotOffset, plot_scale, aPlotFrameRef ) )
  127. {
  128. msg.Printf( _( "Plot: \"%s\" OK.\n" ), plotFileName.GetFullPath() );
  129. reporter.Report( msg, RPT_SEVERITY_ACTION );
  130. }
  131. else
  132. {
  133. msg.Printf( _( "Unable to create file \"%s\".\n" ), plotFileName.GetFullPath() );
  134. reporter.Report( msg, RPT_SEVERITY_ERROR );
  135. }
  136. }
  137. catch( IO_ERROR& e )
  138. {
  139. msg.Printf( wxT( "HPGL Plotter exception: %s"), e.What() );
  140. reporter.Report( msg, RPT_SEVERITY_ERROR );
  141. }
  142. }
  143. m_parent->SetCurrentSheet( oldsheetpath );
  144. m_parent->GetCurrentSheet().UpdateAllScreenReferences();
  145. m_parent->SetSheetNumberAndCount();
  146. }
  147. bool DIALOG_PLOT_SCHEMATIC::Plot_1_Page_HPGL( const wxString& aFileName,
  148. SCH_SCREEN* aScreen,
  149. const PAGE_INFO& aPageInfo,
  150. RENDER_SETTINGS* aRenderSettings,
  151. wxPoint aPlot0ffset,
  152. double aScale,
  153. bool aPlotFrameRef )
  154. {
  155. HPGL_PLOTTER* plotter = new HPGL_PLOTTER();
  156. // Currently, plot units are in decimil
  157. plotter->SetPageSettings( aPageInfo );
  158. plotter->SetRenderSettings( aRenderSettings );
  159. plotter->RenderSettings()->LoadColors( getColorSettings() );
  160. plotter->SetColorMode( getModeColor() );
  161. plotter->SetViewport( aPlot0ffset, IU_PER_MILS/10, aScale, false );
  162. // Init :
  163. plotter->SetCreator( wxT( "Eeschema-HPGL" ) );
  164. if( ! plotter->OpenFile( aFileName ) )
  165. {
  166. delete plotter;
  167. return false;
  168. }
  169. LOCALE_IO toggle;
  170. // Pen num and pen speed are not initialized here.
  171. // Default HPGL driver values are used
  172. plotter->SetPenDiameter( m_HPGLPenSize );
  173. plotter->StartPlot();
  174. if( aPlotFrameRef )
  175. {
  176. PlotWorkSheet( plotter, &m_parent->Prj(), m_parent->GetTitleBlock(), aPageInfo,
  177. aScreen->m_ScreenNumber, aScreen->m_NumberOfScreens,
  178. m_parent->GetScreenDesc(), aScreen->GetFileName(), COLOR4D::BLACK );
  179. }
  180. aScreen->Plot( plotter );
  181. plotter->EndPlot();
  182. delete plotter;
  183. return true;
  184. }