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.

244 lines
7.0 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
  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 <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. enum HPGL_PAGEZ_T {
  34. PAGE_DEFAULT = 0,
  35. HPGL_PAGE_SIZE_A4,
  36. HPGL_PAGE_SIZE_A3,
  37. HPGL_PAGE_SIZE_A2,
  38. HPGL_PAGE_SIZE_A1,
  39. HPGL_PAGE_SIZE_A0,
  40. HPGL_PAGE_SIZE_A,
  41. HPGL_PAGE_SIZE_B,
  42. HPGL_PAGE_SIZE_C,
  43. HPGL_PAGE_SIZE_D,
  44. HPGL_PAGE_SIZE_E,
  45. };
  46. static const wxChar* plot_sheet_list( int aSize )
  47. {
  48. const wxChar* ret;
  49. switch( aSize )
  50. {
  51. default:
  52. case PAGE_DEFAULT:
  53. ret = NULL; break;
  54. case HPGL_PAGE_SIZE_A4:
  55. ret = wxT( "A4" ); break;
  56. case HPGL_PAGE_SIZE_A3:
  57. ret = wxT( "A3" ); break;
  58. case HPGL_PAGE_SIZE_A2:
  59. ret = wxT( "A2" ); break;
  60. case HPGL_PAGE_SIZE_A1:
  61. ret = wxT( "A1" ); break;
  62. case HPGL_PAGE_SIZE_A0:
  63. ret = wxT( "A0" ); break;
  64. case HPGL_PAGE_SIZE_A:
  65. ret = wxT( "A" ); break;
  66. case HPGL_PAGE_SIZE_B:
  67. ret = wxT( "B" ); break;
  68. case HPGL_PAGE_SIZE_C:
  69. ret = wxT( "C" ); break;
  70. case HPGL_PAGE_SIZE_D:
  71. ret = wxT( "D" ); break;
  72. case HPGL_PAGE_SIZE_E:
  73. ret = wxT( "E" ); break;
  74. }
  75. return ret;
  76. };
  77. void DIALOG_PLOT_SCHEMATIC::SetHPGLPenWidth()
  78. {
  79. m_HPGLPenSize = ReturnValueFromTextCtrl( *m_penHPGLWidthCtrl );
  80. if( m_HPGLPenSize > Millimeter2iu( 2 ) )
  81. m_HPGLPenSize = Millimeter2iu( 2 );
  82. if( m_HPGLPenSize < Millimeter2iu( 0.01 ) )
  83. m_HPGLPenSize = Millimeter2iu( 0.01 );
  84. }
  85. void DIALOG_PLOT_SCHEMATIC::createHPGLFile( bool aPlotAll, bool aPlotFrameRef )
  86. {
  87. wxString plotFileName;
  88. SCH_SCREEN* screen = m_parent->GetScreen();
  89. SCH_SHEET_PATH* sheetpath;
  90. SCH_SHEET_PATH oldsheetpath = m_parent->GetCurrentSheet();
  91. /* When printing all pages, the printed page is not the current page.
  92. * In complex hierarchies, we must setup references and other parameters
  93. * in the printed SCH_SCREEN
  94. * because in complex hierarchies a SCH_SCREEN (a schematic drawings)
  95. * is shared between many sheets
  96. */
  97. SCH_SHEET_LIST SheetList( NULL );
  98. sheetpath = SheetList.GetFirst();
  99. SCH_SHEET_PATH list;
  100. SetHPGLPenWidth();
  101. while( true )
  102. {
  103. if( aPlotAll )
  104. {
  105. if( sheetpath == NULL )
  106. break;
  107. list.Clear();
  108. if( list.BuildSheetPathInfoFromSheetPathValue( sheetpath->Path() ) )
  109. {
  110. m_parent->SetCurrentSheet( list );
  111. m_parent->GetCurrentSheet().UpdateAllScreenReferences();
  112. m_parent->SetSheetNumberAndCount();
  113. screen = m_parent->GetCurrentSheet().LastScreen();
  114. if( !screen ) // LastScreen() may return NULL
  115. screen = m_parent->GetScreen();
  116. }
  117. else // Should not happen
  118. return;
  119. sheetpath = SheetList.GetNext();
  120. }
  121. const PAGE_INFO& curPage = screen->GetPageSettings();
  122. PAGE_INFO plotPage = curPage;
  123. // if plotting on a page size other than curPage
  124. if( m_HPGLPaperSizeOption->GetSelection() != PAGE_DEFAULT )
  125. plotPage.SetType( plot_sheet_list( m_HPGLPaperSizeOption->GetSelection() ) );
  126. // Calculation of conversion scales.
  127. double plot_scale = (double) plotPage.GetWidthMils() / curPage.GetWidthMils();
  128. // Calculate offsets
  129. wxPoint plotOffset;
  130. if( GetPlotOriginCenter() )
  131. {
  132. plotOffset.x = plotPage.GetWidthIU() / 2;
  133. plotOffset.y = -plotPage.GetHeightIU() / 2;
  134. }
  135. plotFileName = m_parent->GetUniqueFilenameForCurrentSheet() + wxT( "." )
  136. + HPGL_PLOTTER::GetDefaultFileExtension();
  137. LOCALE_IO toggle;
  138. wxString msg;
  139. if( Plot_1_Page_HPGL( plotFileName, screen, plotPage, plotOffset,
  140. plot_scale, aPlotFrameRef ) )
  141. msg.Printf( _( "Plot: <%s> OK\n" ), GetChars( plotFileName ) );
  142. else // Error
  143. msg.Printf( _( "Unable to create <%s>\n" ), GetChars( plotFileName ) );
  144. m_MessagesBox->AppendText( msg );
  145. if( !aPlotAll )
  146. break;
  147. }
  148. m_parent->SetCurrentSheet( oldsheetpath );
  149. m_parent->GetCurrentSheet().UpdateAllScreenReferences();
  150. m_parent->SetSheetNumberAndCount();
  151. }
  152. bool DIALOG_PLOT_SCHEMATIC::Plot_1_Page_HPGL( const wxString& aFileName,
  153. SCH_SCREEN* aScreen,
  154. const PAGE_INFO& aPageInfo,
  155. wxPoint aPlot0ffset,
  156. double aScale,
  157. bool aPlotFrameRef )
  158. {
  159. HPGL_PLOTTER* plotter = new HPGL_PLOTTER();
  160. plotter->SetPageSettings( aPageInfo );
  161. plotter->SetViewport( aPlot0ffset, IU_PER_DECIMILS, 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->SetPenOverlap( m_HPGLPenSize / 4 );
  174. plotter->StartPlot();
  175. plotter->SetColor( BLACK );
  176. if( getPlotFrameRef() )
  177. PlotWorkSheet( plotter, m_parent->GetTitleBlock(),
  178. m_parent->GetPageSettings(),
  179. aScreen->m_ScreenNumber, aScreen->m_NumberOfScreens,
  180. m_parent->GetScreenDesc(),
  181. aScreen->GetFileName() );
  182. aScreen->Plot( plotter );
  183. plotter->EndPlot();
  184. delete plotter;
  185. return true;
  186. }