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.

110 lines
4.2 KiB

  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright (C) 2022 Mark Roszko <mark.roszko@gmail.com>
  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 "eeschema_jobs_handler.h"
  21. #include <cli/exit_codes.h>
  22. #include <jobs/job_export_sch_pdf.h>
  23. #include <jobs/job_export_sch_svg.h>
  24. #include <pgm_base.h>
  25. #include <sch_plotter.h>
  26. #include <schematic.h>
  27. #include <wx/crt.h>
  28. #include <memory>
  29. #include <connection_graph.h>
  30. #include "eeschema_helpers.h"
  31. #include <sch_painter.h>
  32. #include <settings/settings_manager.h>
  33. EESCHEMA_JOBS_HANDLER::EESCHEMA_JOBS_HANDLER()
  34. {
  35. Register( "pdf",
  36. std::bind( &EESCHEMA_JOBS_HANDLER::JobExportPdf, this, std::placeholders::_1 ) );
  37. Register( "svg",
  38. std::bind( &EESCHEMA_JOBS_HANDLER::JobExportSvg, this, std::placeholders::_1 ) );
  39. }
  40. void EESCHEMA_JOBS_HANDLER::InitRenderSettings( KIGFX::SCH_RENDER_SETTINGS* aRenderSettings,
  41. const wxString& aTheme, SCHEMATIC* aSch )
  42. {
  43. COLOR_SETTINGS* cs = Pgm().GetSettingsManager().GetColorSettings( aTheme );
  44. aRenderSettings->LoadColors( cs );
  45. aRenderSettings->SetDefaultPenWidth( aSch->Settings().m_DefaultLineWidth );
  46. aRenderSettings->m_LabelSizeRatio = aSch->Settings().m_LabelSizeRatio;
  47. aRenderSettings->m_TextOffsetRatio = aSch->Settings().m_TextOffsetRatio;
  48. aRenderSettings->m_PinSymbolSize = aSch->Settings().m_PinSymbolSize;
  49. aRenderSettings->SetDashLengthRatio( aSch->Settings().m_DashedLineDashRatio );
  50. aRenderSettings->SetGapLengthRatio( aSch->Settings().m_DashedLineGapRatio );
  51. }
  52. int EESCHEMA_JOBS_HANDLER::JobExportPdf( JOB* aJob )
  53. {
  54. JOB_EXPORT_SCH_PDF* aPdfJob = dynamic_cast<JOB_EXPORT_SCH_PDF*>( aJob );
  55. SCHEMATIC* sch = EESCHEMA_HELPERS::LoadSchematic( aPdfJob->m_filename, SCH_IO_MGR::SCH_KICAD );
  56. std::unique_ptr<KIGFX::SCH_RENDER_SETTINGS> renderSettings =
  57. std::make_unique<KIGFX::SCH_RENDER_SETTINGS>();
  58. InitRenderSettings( renderSettings.get(), aPdfJob->m_colorTheme, sch );
  59. std::unique_ptr<SCH_PLOTTER> schPlotter = std::make_unique<SCH_PLOTTER>( sch );
  60. SCH_PLOT_SETTINGS settings;
  61. settings.m_plotAll = true;
  62. settings.m_plotDrawingSheet = aPdfJob->m_plotDrawingSheet;
  63. settings.m_blackAndWhite = aPdfJob->m_blackAndWhite;
  64. settings.m_theme = aPdfJob->m_colorTheme;
  65. settings.m_useBackgroundColor = aPdfJob->m_useBackgroundColor;
  66. settings.m_pageSizeSelect = PAGE_SIZE_AUTO;
  67. settings.m_outputFile = aPdfJob->m_outputFile;
  68. schPlotter->Plot( PLOT_FORMAT::PDF, settings, renderSettings.get(), nullptr );
  69. return 0;
  70. }
  71. int EESCHEMA_JOBS_HANDLER::JobExportSvg( JOB* aJob )
  72. {
  73. JOB_EXPORT_SCH_SVG* aSvgJob = dynamic_cast<JOB_EXPORT_SCH_SVG*>( aJob );
  74. SCHEMATIC* sch = EESCHEMA_HELPERS::LoadSchematic( aSvgJob->m_filename, SCH_IO_MGR::SCH_KICAD );
  75. std::unique_ptr<KIGFX::SCH_RENDER_SETTINGS> renderSettings =
  76. std::make_unique<KIGFX::SCH_RENDER_SETTINGS>();
  77. InitRenderSettings( renderSettings.get(), aSvgJob->m_colorTheme, sch );
  78. std::unique_ptr<SCH_PLOTTER> schPlotter = std::make_unique<SCH_PLOTTER>( sch );
  79. SCH_PLOT_SETTINGS settings;
  80. settings.m_plotAll = true;
  81. settings.m_plotDrawingSheet = true;
  82. settings.m_blackAndWhite = aSvgJob->m_blackAndWhite;
  83. settings.m_theme = aSvgJob->m_colorTheme;
  84. settings.m_pageSizeSelect = PAGE_SIZE_AUTO;
  85. settings.m_outputDirectory = aSvgJob->m_outputDirectory;
  86. settings.m_useBackgroundColor = aSvgJob->m_useBackgroundColor;
  87. schPlotter->Plot( PLOT_FORMAT::SVG, settings, renderSettings.get(), nullptr );
  88. return 0;
  89. }