From 561441b48a95dd451d11cb9f5ba740982b2ca070 Mon Sep 17 00:00:00 2001 From: "Salvador E. Tropea" Date: Wed, 22 Mar 2023 02:14:50 +0000 Subject: [PATCH] Adds the missing plot formats to `kicad-cli sch export` --- common/jobs/job_export_sch_pdf.h | 49 ------- .../jobs/job_export_sch_plot.h | 23 ++-- common/jobs/job_export_sch_svg.h | 49 ------- eeschema/eeschema_jobs_handler.cpp | 71 ++-------- eeschema/eeschema_jobs_handler.h | 3 +- kicad/CMakeLists.txt | 3 +- kicad/cli/command_export_sch_pdf.cpp | 78 ----------- kicad/cli/command_export_sch_plot.cpp | 125 ++++++++++++++++++ ...rt_sch_svg.h => command_export_sch_plot.h} | 13 +- kicad/cli/command_export_sch_svg.cpp | 78 ----------- kicad/kicad_cli.cpp | 20 ++- 11 files changed, 175 insertions(+), 337 deletions(-) delete mode 100644 common/jobs/job_export_sch_pdf.h rename kicad/cli/command_export_sch_pdf.h => common/jobs/job_export_sch_plot.h (65%) delete mode 100644 common/jobs/job_export_sch_svg.h delete mode 100644 kicad/cli/command_export_sch_pdf.cpp create mode 100644 kicad/cli/command_export_sch_plot.cpp rename kicad/cli/{command_export_sch_svg.h => command_export_sch_plot.h} (73%) delete mode 100644 kicad/cli/command_export_sch_svg.cpp diff --git a/common/jobs/job_export_sch_pdf.h b/common/jobs/job_export_sch_pdf.h deleted file mode 100644 index e940fd1726..0000000000 --- a/common/jobs/job_export_sch_pdf.h +++ /dev/null @@ -1,49 +0,0 @@ -/* - * This program source code file is part of KiCad, a free EDA CAD application. - * - * Copyright (C) 2022 Mark Roszko - * Copyright (C) 1992-2022 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 . - */ - -#ifndef JOB_EXPORT_SCH_PDF_H -#define JOB_EXPORT_SCH_PDF_H - -#include -#include "job.h" - -class JOB_EXPORT_SCH_PDF : public JOB -{ -public: - JOB_EXPORT_SCH_PDF( bool aIsCli ) : - JOB( "pdf", aIsCli ), - m_filename(), - m_outputFile(), - m_blackAndWhite( false ), - m_useBackgroundColor( false ), - m_plotDrawingSheet( false ) - { - } - - wxString m_filename; - wxString m_outputFile; - wxString m_colorTheme; - - bool m_blackAndWhite; - bool m_useBackgroundColor; - bool m_plotDrawingSheet; -}; - -#endif \ No newline at end of file diff --git a/kicad/cli/command_export_sch_pdf.h b/common/jobs/job_export_sch_plot.h similarity index 65% rename from kicad/cli/command_export_sch_pdf.h rename to common/jobs/job_export_sch_plot.h index 6dedfc7f53..a7b57427c3 100644 --- a/kicad/cli/command_export_sch_pdf.h +++ b/common/jobs/job_export_sch_plot.h @@ -18,21 +18,24 @@ * with this program. If not, see . */ -#ifndef COMMAND_EXPORT_SCH_PDF_H -#define COMMAND_EXPORT_SCH_PDF_H +#ifndef JOB_EXPORT_SCH_PLOT_H +#define JOB_EXPORT_SCH_PLOT_H -#include "command_export_pcb_base.h" +#include +#include +#include "job.h" -namespace CLI -{ -class EXPORT_SCH_PDF_COMMAND : public EXPORT_PCB_BASE_COMMAND +class JOB_EXPORT_SCH_PLOT : public JOB { public: - EXPORT_SCH_PDF_COMMAND(); + JOB_EXPORT_SCH_PLOT( bool aIsCli, PLOT_FORMAT aPlotFormat, wxString aFilename ) : + JOB( "plot", aIsCli ), m_plotFormat( aPlotFormat ), m_filename( aFilename ) + { + } -protected: - int doPerform( KIWAY& aKiway ) override; + PLOT_FORMAT m_plotFormat; + wxString m_filename; + SCH_PLOT_SETTINGS settings; }; -} // namespace CLI #endif \ No newline at end of file diff --git a/common/jobs/job_export_sch_svg.h b/common/jobs/job_export_sch_svg.h deleted file mode 100644 index 786fc8945c..0000000000 --- a/common/jobs/job_export_sch_svg.h +++ /dev/null @@ -1,49 +0,0 @@ -/* - * This program source code file is part of KiCad, a free EDA CAD application. - * - * Copyright (C) 2022 Mark Roszko - * Copyright (C) 1992-2022 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 . - */ - -#ifndef JOB_EXPORT_SCH_SVG_H -#define JOB_EXPORT_SCH_SVG_H - -#include -#include "job.h" - -class JOB_EXPORT_SCH_SVG : public JOB -{ -public: - JOB_EXPORT_SCH_SVG( bool aIsCli ) : - JOB( "svg", aIsCli ), - m_filename(), - m_outputDirectory(), - m_blackAndWhite( false ), - m_useBackgroundColor( false ), - m_plotDrawingSheet( false ) - { - } - - wxString m_filename; - wxString m_outputDirectory; - wxString m_colorTheme; - - bool m_blackAndWhite; - bool m_useBackgroundColor; - bool m_plotDrawingSheet; -}; - -#endif \ No newline at end of file diff --git a/eeschema/eeschema_jobs_handler.cpp b/eeschema/eeschema_jobs_handler.cpp index e135b900ff..9b51ad78f2 100644 --- a/eeschema/eeschema_jobs_handler.cpp +++ b/eeschema/eeschema_jobs_handler.cpp @@ -19,15 +19,14 @@ */ #include "eeschema_jobs_handler.h" +#include #include +#include #include #include -#include -#include +#include #include #include -#include -#include #include #include #include @@ -63,10 +62,8 @@ EESCHEMA_JOBS_HANDLER::EESCHEMA_JOBS_HANDLER() std::bind( &EESCHEMA_JOBS_HANDLER::JobExportPythonBom, this, std::placeholders::_1 ) ); Register( "netlist", std::bind( &EESCHEMA_JOBS_HANDLER::JobExportNetlist, this, std::placeholders::_1 ) ); - Register( "pdf", - std::bind( &EESCHEMA_JOBS_HANDLER::JobExportPdf, this, std::placeholders::_1 ) ); - Register( "svg", - std::bind( &EESCHEMA_JOBS_HANDLER::JobExportSvg, this, std::placeholders::_1 ) ); + Register( "plot", + std::bind( &EESCHEMA_JOBS_HANDLER::JobExportPlot, this, std::placeholders::_1 ) ); Register( "symupgrade", std::bind( &EESCHEMA_JOBS_HANDLER::JobSymUpgrade, this, std::placeholders::_1 ) ); Register( "symsvg", @@ -109,14 +106,14 @@ REPORTER& EESCHEMA_JOBS_HANDLER::Report( const wxString& aText, SEVERITY aSeveri } -int EESCHEMA_JOBS_HANDLER::JobExportPdf( JOB* aJob ) +int EESCHEMA_JOBS_HANDLER::JobExportPlot( JOB* aJob ) { - JOB_EXPORT_SCH_PDF* aPdfJob = dynamic_cast( aJob ); + JOB_EXPORT_SCH_PLOT* aPlotJob = dynamic_cast( aJob ); - if( !aPdfJob ) + if( !aPlotJob ) return CLI::EXIT_CODES::ERR_UNKNOWN; - SCHEMATIC* sch = EESCHEMA_HELPERS::LoadSchematic( aPdfJob->m_filename, SCH_IO_MGR::SCH_KICAD ); + SCHEMATIC* sch = EESCHEMA_HELPERS::LoadSchematic( aPlotJob->m_filename, SCH_IO_MGR::SCH_KICAD ); if( sch == nullptr ) { @@ -126,56 +123,10 @@ int EESCHEMA_JOBS_HANDLER::JobExportPdf( JOB* aJob ) std::unique_ptr renderSettings = std::make_unique(); - InitRenderSettings( renderSettings.get(), aPdfJob->m_colorTheme, sch ); + InitRenderSettings( renderSettings.get(), aPlotJob->settings.m_theme, sch ); std::unique_ptr schPlotter = std::make_unique( sch ); - - SCH_PLOT_SETTINGS settings; - settings.m_plotAll = true; - settings.m_plotDrawingSheet = aPdfJob->m_plotDrawingSheet; - settings.m_blackAndWhite = aPdfJob->m_blackAndWhite; - settings.m_theme = aPdfJob->m_colorTheme; - settings.m_useBackgroundColor = aPdfJob->m_useBackgroundColor; - settings.m_pageSizeSelect = PAGE_SIZE_AUTO; - settings.m_outputFile = aPdfJob->m_outputFile; - - schPlotter->Plot( PLOT_FORMAT::PDF, settings, renderSettings.get(), this ); - - return CLI::EXIT_CODES::OK; -} - - -int EESCHEMA_JOBS_HANDLER::JobExportSvg( JOB* aJob ) -{ - JOB_EXPORT_SCH_SVG* aSvgJob = dynamic_cast( aJob ); - - if( !aSvgJob ) - return CLI::EXIT_CODES::ERR_UNKNOWN; - - SCHEMATIC* sch = EESCHEMA_HELPERS::LoadSchematic( aSvgJob->m_filename, SCH_IO_MGR::SCH_KICAD ); - - if( sch == nullptr ) - { - wxFprintf( stderr, _( "Failed to load schematic file\n" ) ); - return CLI::EXIT_CODES::ERR_INVALID_INPUT_FILE; - } - - std::unique_ptr renderSettings = - std::make_unique(); - InitRenderSettings( renderSettings.get(), aSvgJob->m_colorTheme, sch ); - - std::unique_ptr schPlotter = std::make_unique( sch ); - - SCH_PLOT_SETTINGS settings; - settings.m_plotAll = true; - settings.m_plotDrawingSheet = aSvgJob->m_plotDrawingSheet; - settings.m_blackAndWhite = aSvgJob->m_blackAndWhite; - settings.m_theme = aSvgJob->m_colorTheme; - settings.m_pageSizeSelect = PAGE_SIZE_AUTO; - settings.m_outputDirectory = aSvgJob->m_outputDirectory; - settings.m_useBackgroundColor = aSvgJob->m_useBackgroundColor; - - schPlotter->Plot( PLOT_FORMAT::SVG, settings, renderSettings.get(), this ); + schPlotter->Plot( aPlotJob->m_plotFormat, aPlotJob->settings, renderSettings.get(), this ); return CLI::EXIT_CODES::OK; } diff --git a/eeschema/eeschema_jobs_handler.h b/eeschema/eeschema_jobs_handler.h index 43c4af2d89..bd5375b549 100644 --- a/eeschema/eeschema_jobs_handler.h +++ b/eeschema/eeschema_jobs_handler.h @@ -43,8 +43,7 @@ public: EESCHEMA_JOBS_HANDLER(); int JobExportPythonBom( JOB* aJob ); int JobExportNetlist( JOB* aJob ); - int JobExportPdf( JOB* aJob ); - int JobExportSvg( JOB* aJob ); + int JobExportPlot( JOB* aJob ); int JobSymUpgrade( JOB* aJob ); int JobSymExportSvg( JOB* aJob ); diff --git a/kicad/CMakeLists.txt b/kicad/CMakeLists.txt index f85c5bc449..157eb2e166 100644 --- a/kicad/CMakeLists.txt +++ b/kicad/CMakeLists.txt @@ -48,8 +48,7 @@ set( KICAD_CLI_SRCS cli/command_fp_upgrade.cpp cli/command_export_sch_pythonbom.cpp cli/command_export_sch_netlist.cpp - cli/command_export_sch_pdf.cpp - cli/command_export_sch_svg.cpp + cli/command_export_sch_plot.cpp cli/command_sym_export_svg.cpp cli/command_sym_upgrade.cpp cli/command_version.cpp diff --git a/kicad/cli/command_export_sch_pdf.cpp b/kicad/cli/command_export_sch_pdf.cpp deleted file mode 100644 index 925634f78b..0000000000 --- a/kicad/cli/command_export_sch_pdf.cpp +++ /dev/null @@ -1,78 +0,0 @@ -/* - * This program source code file is part of KiCad, a free EDA CAD application. - * - * Copyright (C) 2022 Mark Roszko - * Copyright (C) 1992-2022 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 "command_export_sch_pdf.h" -#include -#include "jobs/job_export_sch_pdf.h" -#include -#include -#include - -#include -#include - -#define ARG_EXCLUDE_DRAWING_SHEET "--exclude-drawing-sheet" -#define ARG_NO_BACKGROUND_COLOR "--no-background-color" - -CLI::EXPORT_SCH_PDF_COMMAND::EXPORT_SCH_PDF_COMMAND() : EXPORT_PCB_BASE_COMMAND( "pdf" ) -{ - m_argParser.add_argument( "-t", ARG_THEME ) - .default_value( std::string() ) - .help( UTF8STDSTR( _( "Color theme to use (will default to schematic settings)" ) ) ); - - m_argParser.add_argument( ARG_BLACKANDWHITE ) - .help( UTF8STDSTR( _( ARG_BLACKANDWHITE_DESC ) ) ) - .implicit_value( true ) - .default_value( false ); - - m_argParser.add_argument( ARG_EXCLUDE_DRAWING_SHEET ) - .help( UTF8STDSTR( _( "No drawing sheet" ) ) ) - .implicit_value( true ) - .default_value( false ); - - m_argParser.add_argument( ARG_NO_BACKGROUND_COLOR ) - .help( UTF8STDSTR( _( "Avoid setting a background color (regardless of theme)" ) ) ) - .implicit_value( true ) - .default_value( false ); -} - - -int CLI::EXPORT_SCH_PDF_COMMAND::doPerform( KIWAY& aKiway ) -{ - std::unique_ptr pdfJob = std::make_unique( true ); - - pdfJob->m_filename = FROM_UTF8( m_argParser.get( ARG_INPUT ).c_str() ); - pdfJob->m_outputFile = FROM_UTF8( m_argParser.get( ARG_OUTPUT ).c_str() ); - pdfJob->m_blackAndWhite = m_argParser.get( ARG_BLACKANDWHITE ); - pdfJob->m_plotDrawingSheet = !m_argParser.get( ARG_EXCLUDE_DRAWING_SHEET ); - pdfJob->m_useBackgroundColor = !m_argParser.get( ARG_NO_BACKGROUND_COLOR ); - - if( !wxFile::Exists( pdfJob->m_filename ) ) - { - wxFprintf( stderr, _( "Schematic file does not exist or is not accessible\n" ) ); - return EXIT_CODES::ERR_INVALID_INPUT_FILE; - } - - pdfJob->m_colorTheme = FROM_UTF8( m_argParser.get( ARG_THEME ).c_str() ); - - int exitCode = aKiway.ProcessJob( KIWAY::FACE_SCH, pdfJob.get() ); - - return exitCode; -} \ No newline at end of file diff --git a/kicad/cli/command_export_sch_plot.cpp b/kicad/cli/command_export_sch_plot.cpp new file mode 100644 index 0000000000..9aca8afb8b --- /dev/null +++ b/kicad/cli/command_export_sch_plot.cpp @@ -0,0 +1,125 @@ +/* + * This program source code file is part of KiCad, a free EDA CAD application. + * + * Copyright (C) 2022 Mark Roszko + * Copyright (C) 1992-2022 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 +#include +#include "command_export_sch_plot.h" +#include +#include "jobs/job_export_sch_plot.h" +#include +#include + +#include +#include + +#define ARG_EXCLUDE_DRAWING_SHEET "--exclude-drawing-sheet" +#define ARG_NO_BACKGROUND_COLOR "--no-background-color" +#define ARG_PLOT_ONE "--plot-one" +#define ARG_HPGL_PEN_SIZE "--pen-size" +#define ARG_HPGL_ORIGIN "--origin" + +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 +}; + +CLI::EXPORT_SCH_PLOT_COMMAND::EXPORT_SCH_PLOT_COMMAND( const std::string& aName, + PLOT_FORMAT aPlotFormat, + bool aOutputIsDir ) : + EXPORT_PCB_BASE_COMMAND( aName, aOutputIsDir ), + m_plotFormat( aPlotFormat ), m_useDir( aOutputIsDir ) +{ + m_argParser.add_argument( "-t", ARG_THEME ) + .default_value( std::string() ) + .help( UTF8STDSTR( _( "Color theme to use (will default to schematic settings)" ) ) ); + + m_argParser.add_argument( "-b", ARG_BLACKANDWHITE ) + .help( UTF8STDSTR( _( ARG_BLACKANDWHITE_DESC ) ) ) + .implicit_value( true ) + .default_value( false ); + + m_argParser.add_argument( "-e", ARG_EXCLUDE_DRAWING_SHEET ) + .help( UTF8STDSTR( _( "No drawing sheet" ) ) ) + .implicit_value( true ) + .default_value( false ); + + m_argParser.add_argument( "-n", ARG_NO_BACKGROUND_COLOR ) + .help( UTF8STDSTR( _( "Avoid setting a background color (regardless of theme)" ) ) ) + .implicit_value( true ) + .default_value( false ); + + m_argParser.add_argument( "-O", ARG_PLOT_ONE ) + .implicit_value( true ) + .default_value( false ); + + if( aPlotFormat == PLOT_FORMAT::HPGL ) + { + m_argParser.add_argument( "-p", ARG_HPGL_PEN_SIZE ) + .scan<'g', double>() + .default_value( 0.5 ); + + m_argParser.add_argument( "-r", ARG_HPGL_ORIGIN ) + .scan<'d', int>() + .default_value( 1 ); + } +} + + +int CLI::EXPORT_SCH_PLOT_COMMAND::doPerform( KIWAY& aKiway ) +{ + wxString filename = FROM_UTF8( m_argParser.get( ARG_INPUT ).c_str() ); + if( !wxFile::Exists( filename ) ) + { + wxFprintf( stderr, _( "Schematic file does not exist or is not accessible\n" ) ); + return EXIT_CODES::ERR_INVALID_INPUT_FILE; + } + + std::unique_ptr plotJob = + std::make_unique( true, m_plotFormat, filename ); + + SCH_PLOT_SETTINGS& settings = plotJob->settings; + settings.m_plotAll = !m_argParser.get( ARG_PLOT_ONE ); + 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() ); + if( m_useDir ) + settings.m_outputDirectory = + FROM_UTF8( m_argParser.get( ARG_OUTPUT ).c_str() ); + else + settings.m_outputFile = FROM_UTF8( m_argParser.get( ARG_OUTPUT ).c_str() ); + // HPGL local options + if( m_plotFormat == PLOT_FORMAT::HPGL ) + { + settings.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 ) + { + return EXIT_CODES::ERR_ARGS; + } + settings.m_HPGLPlotOrigin = hpgl_origin_ops[origin]; + } + + int exitCode = aKiway.ProcessJob( KIWAY::FACE_SCH, plotJob.get() ); + + return exitCode; +} \ No newline at end of file diff --git a/kicad/cli/command_export_sch_svg.h b/kicad/cli/command_export_sch_plot.h similarity index 73% rename from kicad/cli/command_export_sch_svg.h rename to kicad/cli/command_export_sch_plot.h index c09e52c865..577fc3a2c2 100644 --- a/kicad/cli/command_export_sch_svg.h +++ b/kicad/cli/command_export_sch_plot.h @@ -18,17 +18,22 @@ * with this program. If not, see . */ -#ifndef COMMAND_EXPORT_SCH_SVG_H -#define COMMAND_EXPORT_SCH_SVG_H +#ifndef COMMAND_EXPORT_SCH_PLOT_H +#define COMMAND_EXPORT_SCH_PLOT_H #include "command_export_pcb_base.h" +#include namespace CLI { -class EXPORT_SCH_SVG_COMMAND : public EXPORT_PCB_BASE_COMMAND +class EXPORT_SCH_PLOT_COMMAND : public EXPORT_PCB_BASE_COMMAND { public: - EXPORT_SCH_SVG_COMMAND(); + EXPORT_SCH_PLOT_COMMAND( const std::string& aName, PLOT_FORMAT aPlotFormat, + bool aOutputIsDir = true ); + + PLOT_FORMAT m_plotFormat; + bool m_useDir; protected: int doPerform( KIWAY& aKiway ) override; diff --git a/kicad/cli/command_export_sch_svg.cpp b/kicad/cli/command_export_sch_svg.cpp deleted file mode 100644 index 6e6bc5bac7..0000000000 --- a/kicad/cli/command_export_sch_svg.cpp +++ /dev/null @@ -1,78 +0,0 @@ -/* - * This program source code file is part of KiCad, a free EDA CAD application. - * - * Copyright (C) 2022 Mark Roszko - * Copyright (C) 1992-2022 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 "command_export_sch_svg.h" -#include -#include "jobs/job_export_sch_svg.h" -#include -#include -#include - -#include -#include - -#define ARG_EXCLUDE_DRAWING_SHEET "--exclude-drawing-sheet" -#define ARG_NO_BACKGROUND_COLOR "--no-background-color" - -CLI::EXPORT_SCH_SVG_COMMAND::EXPORT_SCH_SVG_COMMAND() : EXPORT_PCB_BASE_COMMAND( "svg", true ) -{ - m_argParser.add_argument( "-t", ARG_THEME ) - .default_value( std::string() ) - .help( UTF8STDSTR( _( "Color theme to use (will default to pcbnew settings)" ) ) ); - - m_argParser.add_argument( ARG_BLACKANDWHITE ) - .help( UTF8STDSTR( _( ARG_BLACKANDWHITE_DESC ) ) ) - .implicit_value( true ) - .default_value( false ); - - m_argParser.add_argument( ARG_EXCLUDE_DRAWING_SHEET ) - .help( UTF8STDSTR( _( "No drawing sheet" ) ) ) - .implicit_value( true ) - .default_value( false ); - - m_argParser.add_argument( ARG_NO_BACKGROUND_COLOR ) - .help( UTF8STDSTR( _( "Avoid setting a background color (regardless of theme)" ) ) ) - .implicit_value( true ) - .default_value( false ); -} - - -int CLI::EXPORT_SCH_SVG_COMMAND::doPerform( KIWAY& aKiway ) -{ - std::unique_ptr svgJob = std::make_unique( true ); - - svgJob->m_filename = FROM_UTF8( m_argParser.get( ARG_INPUT ).c_str() ); - svgJob->m_outputDirectory = FROM_UTF8( m_argParser.get( ARG_OUTPUT ).c_str() ); - svgJob->m_blackAndWhite = m_argParser.get( ARG_BLACKANDWHITE ); - svgJob->m_plotDrawingSheet = !m_argParser.get( ARG_EXCLUDE_DRAWING_SHEET ); - svgJob->m_useBackgroundColor = !m_argParser.get( ARG_NO_BACKGROUND_COLOR ); - - if( !wxFile::Exists( svgJob->m_filename ) ) - { - wxFprintf( stderr, _( "Schematic file does not exist or is not accessible\n" ) ); - return EXIT_CODES::ERR_INVALID_INPUT_FILE; - } - - svgJob->m_colorTheme = FROM_UTF8( m_argParser.get( ARG_THEME ).c_str() ); - - int exitCode = aKiway.ProcessJob( KIWAY::FACE_SCH, svgJob.get() ); - - return exitCode; -} \ No newline at end of file diff --git a/kicad/kicad_cli.cpp b/kicad/kicad_cli.cpp index 1c3005aeac..6fae7b19ea 100644 --- a/kicad/kicad_cli.cpp +++ b/kicad/kicad_cli.cpp @@ -46,6 +46,7 @@ #include #include #include +#include #include "cli/command_pcb.h" #include "cli/command_pcb_export.h" @@ -59,8 +60,7 @@ #include "cli/command_export_pcb_step.h" #include "cli/command_export_sch_pythonbom.h" #include "cli/command_export_sch_netlist.h" -#include "cli/command_export_sch_pdf.h" -#include "cli/command_export_sch_svg.h" +#include "cli/command_export_sch_plot.h" #include "cli/command_fp.h" #include "cli/command_fp_export.h" #include "cli/command_fp_export_svg.h" @@ -136,8 +136,11 @@ static CLI::EXPORT_SCH_COMMAND exportSchCmd{}; static CLI::SCH_COMMAND schCmd{}; static CLI::EXPORT_SCH_PYTHONBOM_COMMAND exportSchPythonBomCmd{}; static CLI::EXPORT_SCH_NETLIST_COMMAND exportSchNetlistCmd{}; -static CLI::EXPORT_SCH_PDF_COMMAND exportSchPdfCmd{}; -static CLI::EXPORT_SCH_SVG_COMMAND exportSchSvgCmd{}; +static CLI::EXPORT_SCH_PLOT_COMMAND exportSchDxfCmd{ "dxf", PLOT_FORMAT::DXF }; +static CLI::EXPORT_SCH_PLOT_COMMAND exportSchHpglCmd{ "hpgl", PLOT_FORMAT::HPGL }; +static CLI::EXPORT_SCH_PLOT_COMMAND exportSchPdfCmd{ "pdf", PLOT_FORMAT::PDF, false }; +static CLI::EXPORT_SCH_PLOT_COMMAND exportSchPostscriptCmd{ "ps", PLOT_FORMAT::POST }; +static CLI::EXPORT_SCH_PLOT_COMMAND exportSchSvgCmd{ "svg", PLOT_FORMAT::SVG }; static CLI::FP_COMMAND fpCmd{}; static CLI::FP_EXPORT_COMMAND fpExportCmd{}; static CLI::FP_EXPORT_SVG_COMMAND fpExportSvgCmd{}; @@ -188,8 +191,11 @@ static std::vector commandStack = { { &exportSchCmd, { + &exportSchDxfCmd, + &exportSchHpglCmd, &exportSchNetlistCmd, &exportSchPdfCmd, + &exportSchPostscriptCmd, &exportSchPythonBomCmd, &exportSchSvgCmd } @@ -311,9 +317,13 @@ int PGM_KICAD::OnPgmRun() try { + // Use the C locale to parse arguments + // Otherwise the decimal separator for the locale will be applied + LOCALE_IO dummy; argParser.parse_args( m_argcUtf8, m_argvUtf8 ); } - catch( const std::runtime_error& err ) + // std::runtime_error doesn't seem to be enough for the scan<>() + catch( const std::exception& err ) { wxPrintf( "%s\n", err.what() );