From 2b8a29b662e7016aca7363949d27268a3e7dc295 Mon Sep 17 00:00:00 2001 From: Marek Roszko Date: Tue, 25 Oct 2022 19:53:18 -0400 Subject: [PATCH] Try and make the svg command handling warn a little, also default the output --- common/cli/command_export_pcb_svg.cpp | 13 +++++++++++++ pcbnew/pcb_plot_svg.cpp | 13 +++++++++++-- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/common/cli/command_export_pcb_svg.cpp b/common/cli/command_export_pcb_svg.cpp index fbbbf445ad..530380dafe 100644 --- a/common/cli/command_export_pcb_svg.cpp +++ b/common/cli/command_export_pcb_svg.cpp @@ -25,6 +25,7 @@ #include #include #include +#include #include #include @@ -80,6 +81,8 @@ int CLI::EXPORT_PCB_SVG_COMMAND::Perform( KIWAY& aKiway ) const //m_layerIndices[untranslated] = PCB_LAYER_ID( layer ); layerMasks[untranslated] = LSET( PCB_LAYER_ID( layer ) ); } + + layerMasks["*"] = LSET::AllLayersMask(); layerMasks["*.Cu"] = LSET::AllCuMask(); layerMasks["*In.Cu"] = LSET::InternalCuMask(); layerMasks["F&B.Cu"] = LSET( 2, F_Cu, B_Cu ); @@ -100,6 +103,12 @@ int CLI::EXPORT_PCB_SVG_COMMAND::Perform( KIWAY& aKiway ) const svgJob->m_outputFile = FROM_UTF8( m_argParser.get( ARG_OUTPUT ).c_str() ); svgJob->m_colorTheme = FROM_UTF8( m_argParser.get( ARG_THEME ).c_str() ); + if( !wxFile::Exists( svgJob->m_filename ) ) + { + wxFprintf( stderr, _( "Board file does not exist or is not accessible\n" ) ); + return EXIT_CODES::ERR_INVALID_INPUT_FILE; + } + wxString layers = FROM_UTF8( m_argParser.get( ARG_LAYERS ).c_str() ); LSET layerMask = LSET::AllCuMask(); @@ -115,6 +124,10 @@ int CLI::EXPORT_PCB_SVG_COMMAND::Perform( KIWAY& aKiway ) const { layerMask |= layerMasks[token]; } + else + { + wxFprintf( stderr, _( "Invalid layer option: %s\n" ), token ); + } } } diff --git a/pcbnew/pcb_plot_svg.cpp b/pcbnew/pcb_plot_svg.cpp index f28fff6aa3..aad5bd3655 100644 --- a/pcbnew/pcb_plot_svg.cpp +++ b/pcbnew/pcb_plot_svg.cpp @@ -32,6 +32,7 @@ bool PCB_PLOT_SVG::Plot( BOARD* aBoard, const PCB_PLOT_SVG_OPTIONS& aSvgPlotOptions ) { PCB_PLOT_PARAMS plot_opts; + wxString outputFile = aSvgPlotOptions.m_outputFile; plot_opts.SetPlotFrameRef( aSvgPlotOptions.m_pageSizeMode ); @@ -64,6 +65,15 @@ bool PCB_PLOT_SVG::Plot( BOARD* aBoard, const PCB_PLOT_SVG_OPTIONS& aSvgPlotOpti aBoard->GetDesignSettings().SetAuxOrigin( origin ); } + if( outputFile.IsEmpty() ) + { + wxFileName fn = aBoard->GetFileName(); + fn.SetName( fn.GetName() ); + fn.SetExt( wxS("svg") ); + + outputFile = fn.GetFullName(); + } + SETTINGS_MANAGER& mgr = Pgm().GetSettingsManager(); PCBNEW_SETTINGS* cfg = mgr.GetAppSettings(); @@ -84,8 +94,7 @@ bool PCB_PLOT_SVG::Plot( BOARD* aBoard, const PCB_PLOT_SVG_OPTIONS& aSvgPlotOpti //@todo allow controlling the sheet name and path that will be displayed in the title block // Leave blank for now - SVG_PLOTTER* plotter = (SVG_PLOTTER*) StartPlotBoard( aBoard, &plot_opts, UNDEFINED_LAYER, - aSvgPlotOptions.m_outputFile, + SVG_PLOTTER* plotter = (SVG_PLOTTER*) StartPlotBoard( aBoard, &plot_opts, UNDEFINED_LAYER, outputFile, wxEmptyString, wxEmptyString ); if( plotter )