2022-12-13 22:48:07 -05:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2022 Mark Roszko <mark.roszko@gmail.com>
|
2023-12-11 15:07:58 -05:00
|
|
|
* Copyright (C) 1992-2023 KiCad Developers, see AUTHORS.txt for contributors.
|
2022-12-13 22:48:07 -05:00
|
|
|
*
|
|
|
|
* 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 <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "command_fp_export_svg.h"
|
|
|
|
#include <cli/exit_codes.h>
|
|
|
|
#include "jobs/job_fp_export_svg.h"
|
|
|
|
#include <kiface_base.h>
|
|
|
|
#include <layer_ids.h>
|
2023-09-09 00:10:57 -04:00
|
|
|
#include <string_utils.h>
|
2022-12-13 22:48:07 -05:00
|
|
|
#include <wx/crt.h>
|
|
|
|
#include <wx/dir.h>
|
|
|
|
|
|
|
|
#include <macros.h>
|
|
|
|
#include <wx/tokenzr.h>
|
|
|
|
|
|
|
|
#define ARG_FOOTPRINT "--footprint"
|
|
|
|
|
2023-11-20 22:30:26 -05:00
|
|
|
CLI::FP_EXPORT_SVG_COMMAND::FP_EXPORT_SVG_COMMAND() : PCB_EXPORT_BASE_COMMAND( "svg", true, true )
|
2022-12-13 22:48:07 -05:00
|
|
|
{
|
2023-12-19 14:29:17 -05:00
|
|
|
m_argParser.add_description( UTF8STDSTR( _( "Exports the footprint or entire footprint "
|
|
|
|
"library to SVG" ) ) );
|
2023-08-22 13:42:16 +00:00
|
|
|
|
2023-01-27 23:45:35 -05:00
|
|
|
addLayerArg( false );
|
2023-08-31 21:45:51 -04:00
|
|
|
addDefineArg();
|
2023-01-27 23:45:35 -05:00
|
|
|
|
2022-12-13 22:48:07 -05:00
|
|
|
m_argParser.add_argument( "-t", ARG_THEME )
|
|
|
|
.default_value( std::string() )
|
2023-12-19 14:29:17 -05:00
|
|
|
.help( UTF8STDSTR( _( "Color theme to use (will default to footprint editor "
|
|
|
|
"settings)" ) ) );
|
2022-12-13 22:48:07 -05:00
|
|
|
|
2023-02-08 13:55:20 +00:00
|
|
|
m_argParser.add_argument( "--fp", ARG_FOOTPRINT )
|
2022-12-13 22:48:07 -05:00
|
|
|
.default_value( std::string() )
|
2023-08-31 22:01:07 -04:00
|
|
|
.help( UTF8STDSTR( _( "Specific footprint to export within the library" ) ) )
|
|
|
|
.metavar( "FOOTPRINT_NAME" );
|
2022-12-13 22:48:07 -05:00
|
|
|
|
2024-05-27 20:56:16 +01:00
|
|
|
m_argParser.add_argument( "--sp", ARG_SKETCH_PADS_ON_FAB_LAYERS )
|
|
|
|
.help( UTF8STDSTR( _( ARG_SKETCH_PADS_ON_FAB_LAYERS_DESC ) ) )
|
|
|
|
.flag();
|
|
|
|
|
2022-12-13 22:48:07 -05:00
|
|
|
m_argParser.add_argument( ARG_BLACKANDWHITE )
|
2023-01-08 22:37:48 -05:00
|
|
|
.help( UTF8STDSTR( _( ARG_BLACKANDWHITE_DESC ) ) )
|
2024-01-03 21:39:54 -05:00
|
|
|
.flag();
|
2022-12-13 22:48:07 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-01-01 11:50:40 -05:00
|
|
|
int CLI::FP_EXPORT_SVG_COMMAND::doPerform( KIWAY& aKiway )
|
2022-12-13 22:48:07 -05:00
|
|
|
{
|
2023-08-19 11:51:50 -04:00
|
|
|
int baseExit = PCB_EXPORT_BASE_COMMAND::doPerform( aKiway );
|
2023-01-27 23:45:35 -05:00
|
|
|
if( baseExit != EXIT_CODES::OK )
|
|
|
|
return baseExit;
|
|
|
|
|
2022-12-13 22:48:07 -05:00
|
|
|
std::unique_ptr<JOB_FP_EXPORT_SVG> svgJob = std::make_unique<JOB_FP_EXPORT_SVG>( true );
|
|
|
|
|
2023-08-31 18:43:32 -04:00
|
|
|
svgJob->m_libraryPath = m_argInput;
|
|
|
|
svgJob->m_outputDirectory = m_argOutput;
|
2022-12-13 22:48:07 -05:00
|
|
|
svgJob->m_blackAndWhite = m_argParser.get<bool>( ARG_BLACKANDWHITE );
|
2024-05-27 20:56:16 +01:00
|
|
|
svgJob->m_sketchPadsOnFabLayers = m_argParser.get<bool>( ARG_SKETCH_PADS_ON_FAB_LAYERS );
|
2023-09-09 00:10:57 -04:00
|
|
|
svgJob->m_footprint = From_UTF8( m_argParser.get<std::string>( ARG_FOOTPRINT ).c_str() );
|
2023-08-31 21:45:51 -04:00
|
|
|
svgJob->SetVarOverrides( m_argDefineVars );
|
2022-12-13 22:48:07 -05:00
|
|
|
|
|
|
|
if( !wxDir::Exists( svgJob->m_libraryPath ) )
|
|
|
|
{
|
|
|
|
wxFprintf( stderr, _( "Footprint library does not exist or is not accessible\n" ) );
|
|
|
|
return EXIT_CODES::ERR_INVALID_INPUT_FILE;
|
|
|
|
}
|
|
|
|
|
2023-09-09 00:10:57 -04:00
|
|
|
svgJob->m_colorTheme = From_UTF8( m_argParser.get<std::string>( ARG_THEME ).c_str() );
|
2022-12-13 22:48:07 -05:00
|
|
|
|
2023-09-28 10:59:11 -04:00
|
|
|
if( !m_selectedLayers.empty() )
|
2023-01-27 23:45:35 -05:00
|
|
|
svgJob->m_printMaskLayer = m_selectedLayers;
|
|
|
|
else
|
2023-12-11 15:07:58 -05:00
|
|
|
svgJob->m_printMaskLayer = LSET::AllLayersMask().SeqStackupForPlotting();
|
2023-01-27 23:45:35 -05:00
|
|
|
|
2022-12-13 22:48:07 -05:00
|
|
|
int exitCode = aKiway.ProcessJob( KIWAY::FACE_PCB, svgJob.get() );
|
|
|
|
|
|
|
|
return exitCode;
|
2023-11-20 22:30:26 -05:00
|
|
|
}
|