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.

149 lines
5.1 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
  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-2017 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 <sch_sheet_path.h>
  30. #include <project.h>
  31. #include <dialog_plot_schematic.h>
  32. #include <wx_html_report_panel.h>
  33. void DIALOG_PLOT_SCHEMATIC::CreateDXFFile( bool aPlotAll, bool aPlotFrameRef )
  34. {
  35. SCH_EDIT_FRAME* schframe = m_parent;
  36. SCH_SCREEN* screen = schframe->GetScreen();
  37. SCH_SHEET_PATH oldsheetpath = schframe->GetCurrentSheet();
  38. /* When printing all pages, the printed page is not the current page.
  39. * In complex hierarchies, we must setup references and others parameters
  40. * in the printed SCH_SCREEN
  41. * because in complex hierarchies a SCH_SCREEN (a schematic drawings)
  42. * is shared between many sheets
  43. */
  44. SCH_SHEET_LIST sheetList;
  45. if( aPlotAll )
  46. sheetList.BuildSheetList( g_RootSheet );
  47. else
  48. sheetList.push_back( schframe->GetCurrentSheet() );
  49. REPORTER& reporter = m_MessagesBox->Reporter();
  50. for( unsigned i = 0; i < sheetList.size(); i++ )
  51. {
  52. schframe->SetCurrentSheet( sheetList[i] );
  53. schframe->GetCurrentSheet().UpdateAllScreenReferences();
  54. schframe->SetSheetNumberAndCount();
  55. screen = schframe->GetCurrentSheet().LastScreen();
  56. wxPoint plot_offset;
  57. wxString msg;
  58. try
  59. {
  60. wxString fname = schframe->GetUniqueFilenameForCurrentSheet();
  61. wxString ext = DXF_PLOTTER::GetDefaultFileExtension();
  62. wxFileName plotFileName = createPlotFileName( m_outputDirectoryName, fname,
  63. ext, &reporter );
  64. if( PlotOneSheetDXF( plotFileName.GetFullPath(), screen, plot_offset, 1.0,
  65. aPlotFrameRef ) )
  66. {
  67. msg.Printf( _( "Plot: \"%s\" OK.\n" ), GetChars( plotFileName.GetFullPath() ) );
  68. reporter.Report( msg, REPORTER::RPT_ACTION );
  69. }
  70. else // Error
  71. {
  72. msg.Printf( _( "Unable to create file \"%s\".\n" ),
  73. GetChars( plotFileName.GetFullPath() ) );
  74. reporter.Report( msg, REPORTER::RPT_ERROR );
  75. }
  76. }
  77. catch( IO_ERROR& e )
  78. {
  79. msg.Printf( wxT( "DXF Plotter exception: %s"), GetChars( e.What() ) );
  80. reporter.Report( msg, REPORTER::RPT_ERROR );
  81. schframe->SetCurrentSheet( oldsheetpath );
  82. schframe->GetCurrentSheet().UpdateAllScreenReferences();
  83. schframe->SetSheetNumberAndCount();
  84. return;
  85. }
  86. }
  87. schframe->SetCurrentSheet( oldsheetpath );
  88. schframe->GetCurrentSheet().UpdateAllScreenReferences();
  89. schframe->SetSheetNumberAndCount();
  90. }
  91. bool DIALOG_PLOT_SCHEMATIC::PlotOneSheetDXF( const wxString& aFileName,
  92. SCH_SCREEN* aScreen,
  93. wxPoint aPlotOffset,
  94. double aScale,
  95. bool aPlotFrameRef )
  96. {
  97. DXF_PLOTTER* plotter = new DXF_PLOTTER();
  98. const PAGE_INFO& pageInfo = aScreen->GetPageSettings();
  99. plotter->SetPageSettings( pageInfo );
  100. plotter->SetColorMode( getModeColor() );
  101. // Currently, plot units are in decimil
  102. plotter->SetViewport( aPlotOffset, IU_PER_MILS/10, aScale, false );
  103. // Init :
  104. plotter->SetCreator( wxT( "Eeschema-DXF" ) );
  105. if( ! plotter->OpenFile( aFileName ) )
  106. {
  107. delete plotter;
  108. return false;
  109. }
  110. LOCALE_IO toggle;
  111. plotter->StartPlot();
  112. if( aPlotFrameRef )
  113. {
  114. PlotWorkSheet( plotter, m_parent->GetTitleBlock(),
  115. m_parent->GetPageSettings(),
  116. aScreen->m_ScreenNumber, aScreen->m_NumberOfScreens,
  117. m_parent->GetScreenDesc(),
  118. aScreen->GetFileName() );
  119. }
  120. aScreen->Plot( plotter );
  121. // finish
  122. plotter->EndPlot();
  123. delete plotter;
  124. return true;
  125. }