diff --git a/common/CMakeLists.txt b/common/CMakeLists.txt index 741bb50a14..da63522c43 100644 --- a/common/CMakeLists.txt +++ b/common/CMakeLists.txt @@ -84,6 +84,7 @@ set( KICOMMON_SRCS jobs/job_export_pcb_3d.cpp jobs/job_export_sch_bom.cpp jobs/job_export_sch_netlist.cpp + jobs/job_export_sch_plot.cpp jobs/job_export_sch_pythonbom.cpp jobs/job_fp_export_svg.cpp jobs/job_fp_upgrade.cpp diff --git a/common/jobs/job_export_sch_plot.cpp b/common/jobs/job_export_sch_plot.cpp new file mode 100644 index 0000000000..fd03c907dc --- /dev/null +++ b/common/jobs/job_export_sch_plot.cpp @@ -0,0 +1,41 @@ +/* + * This program source code file is part of KiCad, a free EDA CAD application. + * + * Copyright (C) 2023 Mark Roszko + * Copyright (C) 2023 KiCad Developers, see AUTHORS.txt for contributors. + * + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation, either version 3 of the License, or (at your + * option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see . + */ + +#include + + +JOB_EXPORT_SCH_PLOT::JOB_EXPORT_SCH_PLOT( bool aIsCli, SCH_PLOT_FORMAT aPlotFormat, wxString aFilename ) : + JOB( "plot", aIsCli ), + m_plotFormat( aPlotFormat ), + m_filename( aFilename ), + m_drawingSheet(), + m_plotAll( true ), + m_plotDrawingSheet( true ), + m_blackAndWhite( false ), + m_pageSizeSelect( JOB_PAGE_SIZE::PAGE_SIZE_AUTO ), + m_useBackgroundColor( true ), + m_HPGLPenSize( 1.0 ), + m_HPGLPaperSizeSelect( JOB_HPGL_PAGE_SIZE::DEFAULT ), + m_theme(), + m_outputDirectory(), + m_outputFile(), + m_HPGLPlotOrigin( JOB_HPGL_PLOT_ORIGIN_AND_UNITS::USER_FIT_CONTENT ) +{ +} \ No newline at end of file diff --git a/common/jobs/job_export_sch_plot.h b/common/jobs/job_export_sch_plot.h index b4fd48205f..210d52b8e0 100644 --- a/common/jobs/job_export_sch_plot.h +++ b/common/jobs/job_export_sch_plot.h @@ -21,26 +21,80 @@ #ifndef JOB_EXPORT_SCH_PLOT_H #define JOB_EXPORT_SCH_PLOT_H +#include #include -#include #include "job.h" -class JOB_EXPORT_SCH_PLOT : public JOB + +enum class JOB_HPGL_PLOT_ORIGIN_AND_UNITS +{ + PLOTTER_BOT_LEFT, + PLOTTER_CENTER, + USER_FIT_PAGE, + USER_FIT_CONTENT, +}; + + +enum class JOB_HPGL_PAGE_SIZE +{ + DEFAULT = 0, + SIZE_A5, + SIZE_A4, + SIZE_A3, + SIZE_A2, + SIZE_A1, + SIZE_A0, + SIZE_A, + SIZE_B, + SIZE_C, + SIZE_D, + SIZE_E, +}; + + +enum class JOB_PAGE_SIZE +{ + PAGE_SIZE_AUTO, + PAGE_SIZE_A4, + PAGE_SIZE_A +}; + + +enum class SCH_PLOT_FORMAT +{ + HPGL, + GERBER, + POST, + DXF, + PDF, + SVG +}; + + +class KICOMMON_API JOB_EXPORT_SCH_PLOT : public JOB { public: - JOB_EXPORT_SCH_PLOT( bool aIsCli, PLOT_FORMAT aPlotFormat, wxString aFilename ) : - JOB( "plot", aIsCli ), - m_plotFormat( aPlotFormat ), - m_filename( aFilename ), - settings(), - m_drawingSheet() - { - } + JOB_EXPORT_SCH_PLOT( bool aIsCli, SCH_PLOT_FORMAT aPlotFormat, wxString aFilename ); - PLOT_FORMAT m_plotFormat; + SCH_PLOT_FORMAT m_plotFormat; wxString m_filename; - SCH_PLOT_SETTINGS settings; wxString m_drawingSheet; + + bool m_plotAll; + bool m_plotDrawingSheet; + std::vector m_plotPages; + + bool m_blackAndWhite; + JOB_PAGE_SIZE m_pageSizeSelect; + bool m_useBackgroundColor; + double m_HPGLPenSize; // for HPGL format only: pen size + JOB_HPGL_PAGE_SIZE m_HPGLPaperSizeSelect; + wxString m_theme; + + wxString m_outputDirectory; + wxString m_outputFile; + + JOB_HPGL_PLOT_ORIGIN_AND_UNITS m_HPGLPlotOrigin; }; #endif \ No newline at end of file diff --git a/eeschema/eeschema_jobs_handler.cpp b/eeschema/eeschema_jobs_handler.cpp index 69fcb6a3af..161aa9268b 100644 --- a/eeschema/eeschema_jobs_handler.cpp +++ b/eeschema/eeschema_jobs_handler.cpp @@ -146,10 +146,69 @@ int EESCHEMA_JOBS_HANDLER::JobExportPlot( JOB* aJob ) std::unique_ptr renderSettings = std::make_unique(); - InitRenderSettings( renderSettings.get(), aPlotJob->settings.m_theme, sch, aPlotJob->m_drawingSheet ); + InitRenderSettings( renderSettings.get(), aPlotJob->m_theme, sch, aPlotJob->m_drawingSheet ); std::unique_ptr schPlotter = std::make_unique( sch ); - schPlotter->Plot( aPlotJob->m_plotFormat, aPlotJob->settings, renderSettings.get(), m_reporter ); + + PLOT_FORMAT format; + switch( aPlotJob->m_plotFormat ) + { + case SCH_PLOT_FORMAT::DXF: format = PLOT_FORMAT::DXF; break; + case SCH_PLOT_FORMAT::PDF: format = PLOT_FORMAT::PDF; break; + case SCH_PLOT_FORMAT::SVG: format = PLOT_FORMAT::SVG; break; + case SCH_PLOT_FORMAT::POST: format = PLOT_FORMAT::POST; break; + case SCH_PLOT_FORMAT::HPGL: format = PLOT_FORMAT::HPGL; break; + case SCH_PLOT_FORMAT::GERBER: format = PLOT_FORMAT::GERBER; break; + } + + HPGL_PAGE_SIZE hpglPageSize; + switch( aPlotJob->m_HPGLPaperSizeSelect ) + { + case JOB_HPGL_PAGE_SIZE::DEFAULT: hpglPageSize = HPGL_PAGE_SIZE::DEFAULT; break; + case JOB_HPGL_PAGE_SIZE::SIZE_A: hpglPageSize = HPGL_PAGE_SIZE::SIZE_A; break; + case JOB_HPGL_PAGE_SIZE::SIZE_A0: hpglPageSize = HPGL_PAGE_SIZE::SIZE_A0; break; + case JOB_HPGL_PAGE_SIZE::SIZE_A1: hpglPageSize = HPGL_PAGE_SIZE::SIZE_A1; break; + case JOB_HPGL_PAGE_SIZE::SIZE_A2: hpglPageSize = HPGL_PAGE_SIZE::SIZE_A2; break; + case JOB_HPGL_PAGE_SIZE::SIZE_A3: hpglPageSize = HPGL_PAGE_SIZE::SIZE_A3; break; + case JOB_HPGL_PAGE_SIZE::SIZE_A4: hpglPageSize = HPGL_PAGE_SIZE::SIZE_A4; break; + case JOB_HPGL_PAGE_SIZE::SIZE_A5: hpglPageSize = HPGL_PAGE_SIZE::SIZE_A5; break; + case JOB_HPGL_PAGE_SIZE::SIZE_B: hpglPageSize = HPGL_PAGE_SIZE::SIZE_B; break; + case JOB_HPGL_PAGE_SIZE::SIZE_C: hpglPageSize = HPGL_PAGE_SIZE::SIZE_C; break; + case JOB_HPGL_PAGE_SIZE::SIZE_D: hpglPageSize = HPGL_PAGE_SIZE::SIZE_D; break; + } + + HPGL_PLOT_ORIGIN_AND_UNITS hpglOrigin; + switch( aPlotJob->m_HPGLPlotOrigin ) + { + case JOB_HPGL_PLOT_ORIGIN_AND_UNITS::PLOTTER_BOT_LEFT: hpglOrigin = HPGL_PLOT_ORIGIN_AND_UNITS::PLOTTER_BOT_LEFT; break; + case JOB_HPGL_PLOT_ORIGIN_AND_UNITS::PLOTTER_CENTER: hpglOrigin = HPGL_PLOT_ORIGIN_AND_UNITS::PLOTTER_CENTER; break; + case JOB_HPGL_PLOT_ORIGIN_AND_UNITS::USER_FIT_CONTENT: hpglOrigin = HPGL_PLOT_ORIGIN_AND_UNITS::USER_FIT_CONTENT; break; + case JOB_HPGL_PLOT_ORIGIN_AND_UNITS::USER_FIT_PAGE: hpglOrigin = HPGL_PLOT_ORIGIN_AND_UNITS::USER_FIT_PAGE; break; + } + + int pageSizeSelect; + switch( aPlotJob->m_pageSizeSelect ) + { + case JOB_PAGE_SIZE::PAGE_SIZE_A: pageSizeSelect = PageFormatReq::PAGE_SIZE_A; break; + case JOB_PAGE_SIZE::PAGE_SIZE_A4: pageSizeSelect = PageFormatReq::PAGE_SIZE_A4; break; + case JOB_PAGE_SIZE::PAGE_SIZE_AUTO: pageSizeSelect = PageFormatReq::PAGE_SIZE_AUTO; break; + } + + SCH_PLOT_SETTINGS settings; + settings.m_blackAndWhite = aPlotJob->m_blackAndWhite; + settings.m_HPGLPaperSizeSelect = hpglPageSize; + settings.m_HPGLPenSize = aPlotJob->m_HPGLPenSize; + settings.m_HPGLPlotOrigin = hpglOrigin; + settings.m_outputDirectory = aPlotJob->m_outputDirectory; + settings.m_outputFile = aPlotJob->m_outputFile; + settings.m_pageSizeSelect = pageSizeSelect; + settings.m_plotAll = aPlotJob->m_plotAll; + settings.m_plotDrawingSheet = aPlotJob->m_plotDrawingSheet; + settings.m_plotPages = aPlotJob->m_plotPages; + settings.m_theme = aPlotJob->m_theme; + settings.m_useBackgroundColor = aPlotJob->m_useBackgroundColor; + + schPlotter->Plot( format, settings, renderSettings.get(), m_reporter ); return CLI::EXIT_CODES::OK; } diff --git a/kicad/cli/command_sch_export_plot.cpp b/kicad/cli/command_sch_export_plot.cpp index 7ce818dfeb..384db3dde0 100644 --- a/kicad/cli/command_sch_export_plot.cpp +++ b/kicad/cli/command_sch_export_plot.cpp @@ -36,14 +36,16 @@ #define ARG_HPGL_ORIGIN "--origin" #define ARG_PAGES "--pages" -const HPGL_PLOT_ORIGIN_AND_UNITS hpgl_origin_ops[4] = { - HPGL_PLOT_ORIGIN_AND_UNITS::PLOTTER_BOT_LEFT, HPGL_PLOT_ORIGIN_AND_UNITS::PLOTTER_CENTER, - HPGL_PLOT_ORIGIN_AND_UNITS::USER_FIT_PAGE, HPGL_PLOT_ORIGIN_AND_UNITS::USER_FIT_CONTENT +const JOB_HPGL_PLOT_ORIGIN_AND_UNITS hpgl_origin_ops[4] = { + JOB_HPGL_PLOT_ORIGIN_AND_UNITS::PLOTTER_BOT_LEFT, + JOB_HPGL_PLOT_ORIGIN_AND_UNITS::PLOTTER_CENTER, + JOB_HPGL_PLOT_ORIGIN_AND_UNITS::USER_FIT_PAGE, + JOB_HPGL_PLOT_ORIGIN_AND_UNITS::USER_FIT_CONTENT }; CLI::SCH_EXPORT_PLOT_COMMAND::SCH_EXPORT_PLOT_COMMAND( const std::string& aName, const std::string& aDescription, - PLOT_FORMAT aPlotFormat, + SCH_PLOT_FORMAT aPlotFormat, bool aOutputIsDir ) : COMMAND( aName ), m_plotFormat( aPlotFormat ) @@ -79,7 +81,7 @@ CLI::SCH_EXPORT_PLOT_COMMAND::SCH_EXPORT_PLOT_COMMAND( const std::string& aName, .help( UTF8STDSTR( _( "List of page numbers separated by comma to print, blank or unspecified is equivalent to all pages" ) ) ) .metavar( "PAGE_LIST" ); - if( aPlotFormat == PLOT_FORMAT::HPGL ) + if( aPlotFormat == SCH_PLOT_FORMAT::HPGL ) { m_argParser.add_argument( "-p", ARG_HPGL_PEN_SIZE ) .help( UTF8STDSTR( _( "Pen size [mm]" ) ) ) @@ -117,27 +119,26 @@ int CLI::SCH_EXPORT_PLOT_COMMAND::doPerform( KIWAY& aKiway ) std::unique_ptr plotJob = std::make_unique( true, m_plotFormat, filename ); - SCH_PLOT_SETTINGS& settings = plotJob->settings; - settings.m_plotPages = pages; - settings.m_plotDrawingSheet = !m_argParser.get( ARG_EXCLUDE_DRAWING_SHEET ); - settings.m_blackAndWhite = m_argParser.get( ARG_BLACKANDWHITE ); - settings.m_pageSizeSelect = PAGE_SIZE_AUTO; - settings.m_useBackgroundColor = !m_argParser.get( ARG_NO_BACKGROUND_COLOR ); - settings.m_theme = From_UTF8( m_argParser.get( ARG_THEME ).c_str() ); + plotJob->m_plotPages = pages; + plotJob->m_plotDrawingSheet = !m_argParser.get( ARG_EXCLUDE_DRAWING_SHEET ); + plotJob->m_blackAndWhite = m_argParser.get( ARG_BLACKANDWHITE ); + plotJob->m_pageSizeSelect = JOB_PAGE_SIZE::PAGE_SIZE_AUTO; + plotJob->m_useBackgroundColor = !m_argParser.get( ARG_NO_BACKGROUND_COLOR ); + plotJob->m_theme = From_UTF8( m_argParser.get( ARG_THEME ).c_str() ); if( m_outputArgExpectsDir ) - settings.m_outputDirectory = m_argOutput; + plotJob->m_outputDirectory = m_argOutput; else - settings.m_outputFile = m_argOutput; + plotJob->m_outputFile = m_argOutput; - settings.m_plotAll = settings.m_plotPages.size() == 0; + plotJob->m_plotAll = plotJob->m_plotPages.size() == 0; plotJob->m_drawingSheet = m_argDrawingSheet; plotJob->SetVarOverrides( m_argDefineVars ); // HPGL local options - if( m_plotFormat == PLOT_FORMAT::HPGL ) + if( m_plotFormat == SCH_PLOT_FORMAT::HPGL ) { - settings.m_HPGLPenSize = + plotJob->m_HPGLPenSize = m_argParser.get( ARG_HPGL_PEN_SIZE ) * schIUScale.IU_PER_MM; int origin = m_argParser.get( ARG_HPGL_ORIGIN ); if( origin < 0 || origin > 3 ) @@ -145,7 +146,7 @@ int CLI::SCH_EXPORT_PLOT_COMMAND::doPerform( KIWAY& aKiway ) wxFprintf( stderr, _( "HPGL origin option must be 0, 1, 2 or 3\n" ) ); return EXIT_CODES::ERR_ARGS; } - settings.m_HPGLPlotOrigin = hpgl_origin_ops[origin]; + plotJob->m_HPGLPlotOrigin = hpgl_origin_ops[origin]; } int exitCode = aKiway.ProcessJob( KIWAY::FACE_SCH, plotJob.get() ); diff --git a/kicad/cli/command_sch_export_plot.h b/kicad/cli/command_sch_export_plot.h index 67b0793085..ec524d6dfa 100644 --- a/kicad/cli/command_sch_export_plot.h +++ b/kicad/cli/command_sch_export_plot.h @@ -22,7 +22,7 @@ #define COMMAND_EXPORT_SCH_PLOT_H #include "command_pcb_export_base.h" -#include +#include namespace CLI { @@ -31,10 +31,10 @@ class SCH_EXPORT_PLOT_COMMAND : public COMMAND public: SCH_EXPORT_PLOT_COMMAND( const std::string& aName, const std::string& aDescription, - PLOT_FORMAT aPlotFormat, + SCH_PLOT_FORMAT aPlotFormat, bool aOutputIsDir = true ); - PLOT_FORMAT m_plotFormat; + SCH_PLOT_FORMAT m_plotFormat; protected: int doPerform( KIWAY& aKiway ) override; diff --git a/kicad/kicad_cli.cpp b/kicad/kicad_cli.cpp index 0d7d257dfc..ad1757391d 100644 --- a/kicad/kicad_cli.cpp +++ b/kicad/kicad_cli.cpp @@ -144,11 +144,11 @@ static CLI::SCH_ERC_COMMAND schErcCmd{}; static CLI::SCH_EXPORT_BOM_COMMAND exportSchBomCmd{}; static CLI::SCH_EXPORT_PYTHONBOM_COMMAND exportSchPythonBomCmd{}; static CLI::SCH_EXPORT_NETLIST_COMMAND exportSchNetlistCmd{}; -static CLI::SCH_EXPORT_PLOT_COMMAND exportSchDxfCmd{ "dxf", UTF8STDSTR( _( "Export DXF" ) ), PLOT_FORMAT::DXF }; -static CLI::SCH_EXPORT_PLOT_COMMAND exportSchHpglCmd{ "hpgl", UTF8STDSTR( _( "Export HPGL" ) ), PLOT_FORMAT::HPGL }; -static CLI::SCH_EXPORT_PLOT_COMMAND exportSchPdfCmd{ "pdf", UTF8STDSTR( _( "Export PDF" ) ), PLOT_FORMAT::PDF, false }; -static CLI::SCH_EXPORT_PLOT_COMMAND exportSchPostscriptCmd{ "ps", UTF8STDSTR( _( "Export PS" ) ), PLOT_FORMAT::POST }; -static CLI::SCH_EXPORT_PLOT_COMMAND exportSchSvgCmd{ "svg", UTF8STDSTR( _( "Export SVG" ) ), PLOT_FORMAT::SVG }; +static CLI::SCH_EXPORT_PLOT_COMMAND exportSchDxfCmd{ "dxf", UTF8STDSTR( _( "Export DXF" ) ), SCH_PLOT_FORMAT::DXF }; +static CLI::SCH_EXPORT_PLOT_COMMAND exportSchHpglCmd{ "hpgl", UTF8STDSTR( _( "Export HPGL" ) ), SCH_PLOT_FORMAT::HPGL }; +static CLI::SCH_EXPORT_PLOT_COMMAND exportSchPdfCmd{ "pdf", UTF8STDSTR( _( "Export PDF" ) ), SCH_PLOT_FORMAT::PDF, false }; +static CLI::SCH_EXPORT_PLOT_COMMAND exportSchPostscriptCmd{ "ps", UTF8STDSTR( _( "Export PS" ) ), SCH_PLOT_FORMAT::POST }; +static CLI::SCH_EXPORT_PLOT_COMMAND exportSchSvgCmd{ "svg", UTF8STDSTR( _( "Export SVG" ) ), SCH_PLOT_FORMAT::SVG }; static CLI::FP_COMMAND fpCmd{}; static CLI::FP_EXPORT_COMMAND fpExportCmd{}; static CLI::FP_EXPORT_SVG_COMMAND fpExportSvgCmd{};