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.

164 lines
5.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
  1. /** @file plot_schematic_DXF.cpp
  2. */
  3. /*
  4. * This program source code file is part of KiCad, a free EDA CAD application.
  5. *
  6. * Copyright (C) 1992-2010 Lorenzo Marcantonio
  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 <sch_sheet_path.h>
  31. #include <dialog_plot_schematic.h>
  32. #include <project.h>
  33. void DIALOG_PLOT_SCHEMATIC::CreateDXFFile( bool aPlotAll, bool aPlotFrameRef )
  34. {
  35. SCH_EDIT_FRAME* schframe = (SCH_EDIT_FRAME*) m_parent;
  36. SCH_SCREEN* screen = schframe->GetScreen();
  37. SCH_SHEET_PATH* sheetpath;
  38. SCH_SHEET_PATH oldsheetpath = schframe->GetCurrentSheet();
  39. /* When printing all pages, the printed page is not the current page.
  40. * In complex hierarchies, we must setup references and others parameters
  41. * in the printed SCH_SCREEN
  42. * because in complex hierarchies a SCH_SCREEN (a schematic drawings)
  43. * is shared between many sheets
  44. */
  45. SCH_SHEET_LIST SheetList( NULL );
  46. sheetpath = SheetList.GetFirst();
  47. SCH_SHEET_PATH list;
  48. WX_TEXT_CTRL_REPORTER reporter(m_MessagesBox);
  49. while( true )
  50. {
  51. if( aPlotAll )
  52. {
  53. if( sheetpath == NULL )
  54. break;
  55. list.Clear();
  56. if( list.BuildSheetPathInfoFromSheetPathValue( sheetpath->Path() ) )
  57. {
  58. schframe->SetCurrentSheet( list );
  59. schframe->GetCurrentSheet().UpdateAllScreenReferences();
  60. schframe->SetSheetNumberAndCount();
  61. screen = schframe->GetCurrentSheet().LastScreen();
  62. }
  63. else // Should not happen
  64. {
  65. return;
  66. }
  67. sheetpath = SheetList.GetNext();
  68. }
  69. wxPoint plot_offset;
  70. wxString msg;
  71. try
  72. {
  73. wxString fname = schframe->GetUniqueFilenameForCurrentSheet();
  74. wxString ext = DXF_PLOTTER::GetDefaultFileExtension();
  75. wxFileName plotFileName = createPlotFileName( m_outputDirectoryName, fname,
  76. ext, &reporter );
  77. if( PlotOneSheetDXF( plotFileName.GetFullPath(), screen, plot_offset, 1.0, aPlotFrameRef ) )
  78. {
  79. msg.Printf( _( "Plot: '%s' OK\n" ), GetChars( plotFileName.GetFullPath() ) );
  80. }
  81. else // Error
  82. {
  83. msg.Printf( _( "Unable to create '%s'\n" ), GetChars( plotFileName.GetFullPath() ) );
  84. }
  85. m_MessagesBox->AppendText( msg );
  86. }
  87. catch( IO_ERROR& e )
  88. {
  89. msg.Printf( wxT( "DXF Plotter Exception : '%s'"), GetChars( e.errorText ) );
  90. m_MessagesBox->AppendText( msg );
  91. schframe->SetCurrentSheet( oldsheetpath );
  92. schframe->GetCurrentSheet().UpdateAllScreenReferences();
  93. schframe->SetSheetNumberAndCount();
  94. return;
  95. }
  96. if( !aPlotAll )
  97. {
  98. break;
  99. }
  100. }
  101. schframe->SetCurrentSheet( oldsheetpath );
  102. schframe->GetCurrentSheet().UpdateAllScreenReferences();
  103. schframe->SetSheetNumberAndCount();
  104. }
  105. bool DIALOG_PLOT_SCHEMATIC::PlotOneSheetDXF( const wxString& aFileName,
  106. SCH_SCREEN* aScreen,
  107. wxPoint aPlotOffset,
  108. double aScale,
  109. bool aPlotFrameRef )
  110. {
  111. DXF_PLOTTER* plotter = new DXF_PLOTTER();
  112. const PAGE_INFO& pageInfo = aScreen->GetPageSettings();
  113. plotter->SetPageSettings( pageInfo );
  114. plotter->SetColorMode( getModeColor() );
  115. plotter->SetViewport( aPlotOffset, IU_PER_DECIMILS, aScale, false );
  116. // Init :
  117. plotter->SetCreator( wxT( "Eeschema-DXF" ) );
  118. if( ! plotter->OpenFile( aFileName ) )
  119. {
  120. delete plotter;
  121. return false;
  122. }
  123. LOCALE_IO toggle;
  124. plotter->StartPlot();
  125. if( aPlotFrameRef )
  126. {
  127. PlotWorkSheet( plotter, m_parent->GetTitleBlock(),
  128. m_parent->GetPageSettings(),
  129. aScreen->m_ScreenNumber, aScreen->m_NumberOfScreens,
  130. m_parent->GetScreenDesc(),
  131. aScreen->GetFileName() );
  132. }
  133. aScreen->Plot( plotter );
  134. // finish
  135. plotter->EndPlot();
  136. delete plotter;
  137. return true;
  138. }