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.

103 lines
3.7 KiB

  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright (C) 2012 Jean-Pierre Charras, jp.charras at wanadoo.fr
  5. * Copyright (C) 1992-2022 KiCad Developers, see AUTHORS.txt for contributors.
  6. *
  7. * This program is free software: you can redistribute it and/or modify it
  8. * under the terms of the GNU General Public License as published by the
  9. * Free Software Foundation, either version 3 of the License, or (at your
  10. * option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful, but
  13. * WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License along
  18. * with this program. If not, see <http://www.gnu.org/licenses/>.
  19. */
  20. #include <board.h>
  21. #include <board_design_settings.h>
  22. #include <locale_io.h>
  23. #include <pcbnew_settings.h>
  24. #include <pcb_plot_params.h>
  25. #include <pcb_plot_svg.h>
  26. #include <pcbplot.h>
  27. #include <pgm_base.h>
  28. #include <plotters/plotters_pslike.h>
  29. bool PCB_PLOT_SVG::Plot( BOARD* aBoard, const PCB_PLOT_SVG_OPTIONS& aSvgPlotOptions )
  30. {
  31. PCB_PLOT_PARAMS plot_opts;
  32. wxString outputFile = aSvgPlotOptions.m_outputFile;
  33. plot_opts.SetPlotFrameRef( aSvgPlotOptions.m_plotFrame );
  34. // Adding drill marks, for copper layers
  35. if( ( aSvgPlotOptions.m_printMaskLayer & LSET::AllCuMask() ).any() )
  36. plot_opts.SetDrillMarksType( DRILL_MARKS::FULL_DRILL_SHAPE );
  37. else
  38. plot_opts.SetDrillMarksType( DRILL_MARKS::NO_DRILL_SHAPE );
  39. plot_opts.SetSkipPlotNPTH_Pads( false );
  40. plot_opts.SetMirror( aSvgPlotOptions.m_mirror );
  41. plot_opts.SetFormat( PLOT_FORMAT::SVG );
  42. // coord format: 4 digits in mantissa (units always in mm). This is a good choice.
  43. plot_opts.SetSvgPrecision( 4 );
  44. PAGE_INFO savedPageInfo = aBoard->GetPageSettings();
  45. VECTOR2I savedAuxOrigin = aBoard->GetDesignSettings().GetAuxOrigin();
  46. if( aSvgPlotOptions.m_pageSizeMode == 2 ) // Page is board boundary size
  47. {
  48. BOX2I bbox = aBoard->ComputeBoundingBox();
  49. PAGE_INFO currpageInfo = aBoard->GetPageSettings();
  50. currpageInfo.SetWidthMils( bbox.GetWidth() / pcbIUScale.IU_PER_MILS );
  51. currpageInfo.SetHeightMils( bbox.GetHeight() / pcbIUScale.IU_PER_MILS );
  52. aBoard->SetPageSettings( currpageInfo );
  53. plot_opts.SetUseAuxOrigin( true );
  54. VECTOR2I origin = bbox.GetOrigin();
  55. aBoard->GetDesignSettings().SetAuxOrigin( origin );
  56. }
  57. if( outputFile.IsEmpty() )
  58. {
  59. wxFileName fn = aBoard->GetFileName();
  60. fn.SetName( fn.GetName() );
  61. fn.SetExt( wxS("svg") );
  62. outputFile = fn.GetFullName();
  63. }
  64. SETTINGS_MANAGER& mgr = Pgm().GetSettingsManager();
  65. plot_opts.SetColorSettings( mgr.GetColorSettings( aSvgPlotOptions.m_colorTheme ) );
  66. LOCALE_IO toggle;
  67. //@todo allow controlling the sheet name and path that will be displayed in the title block
  68. // Leave blank for now
  69. SVG_PLOTTER* plotter = (SVG_PLOTTER*) StartPlotBoard( aBoard, &plot_opts, UNDEFINED_LAYER, outputFile,
  70. wxEmptyString, wxEmptyString );
  71. if( plotter )
  72. {
  73. plotter->SetColorMode( !aSvgPlotOptions.m_blackAndWhite );
  74. PlotBoardLayers( aBoard, plotter, aSvgPlotOptions.m_printMaskLayer.SeqStackupBottom2Top(),
  75. plot_opts );
  76. plotter->EndPlot();
  77. }
  78. delete plotter;
  79. // reset to the values saved earlier
  80. aBoard->GetDesignSettings().SetAuxOrigin( savedAuxOrigin );
  81. aBoard->SetPageSettings( savedPageInfo );
  82. return true;
  83. }