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.

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