2022-11-07 07:15:55 -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>
|
|
|
|
* 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 <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2023-08-19 11:46:18 -04:00
|
|
|
#include "command_pcb_export_pos.h"
|
2022-11-07 07:15:55 -05:00
|
|
|
#include <cli/exit_codes.h>
|
|
|
|
#include "jobs/job_export_pcb_pos.h"
|
|
|
|
#include <kiface_base.h>
|
|
|
|
#include <layer_ids.h>
|
2023-09-09 00:10:57 -04:00
|
|
|
#include <string_utils.h>
|
2022-11-07 07:15:55 -05:00
|
|
|
#include <wx/crt.h>
|
|
|
|
|
|
|
|
#include <macros.h>
|
|
|
|
|
|
|
|
#include <locale_io.h>
|
|
|
|
|
|
|
|
#define ARG_SIDE "--side"
|
|
|
|
#define ARG_FORMAT "--format"
|
|
|
|
#define ARG_UNITS "--units"
|
|
|
|
#define ARG_NEGATE_BOTTOM_X "--bottom-negate-x"
|
|
|
|
#define ARG_USE_DRILL_FILE_ORIGIN "--use-drill-file-origin"
|
|
|
|
#define ARG_SMD_ONLY "--smd-only"
|
|
|
|
#define ARG_EXCLUDE_FOOTPRINTS_TH "--exclude-fp-th"
|
2023-08-04 11:02:10 -07:00
|
|
|
#define ARG_EXCLUDE_DNP "--exclude-dnp"
|
2022-11-07 07:15:55 -05:00
|
|
|
#define ARG_GERBER_BOARD_EDGE "--gerber-board-edge"
|
|
|
|
|
|
|
|
|
2023-08-19 11:51:50 -04:00
|
|
|
CLI::PCB_EXPORT_POS_COMMAND::PCB_EXPORT_POS_COMMAND() : PCB_EXPORT_BASE_COMMAND( "pos" )
|
2022-11-07 07:15:55 -05:00
|
|
|
{
|
2023-01-17 17:55:48 +00:00
|
|
|
m_argParser.add_description( UTF8STDSTR( _( "Generate Position File" ) ) );
|
2023-01-14 14:31:56 -05:00
|
|
|
|
2022-11-07 07:15:55 -05:00
|
|
|
m_argParser.add_argument( ARG_SIDE )
|
|
|
|
.default_value( std::string( "both" ) )
|
2022-11-14 07:25:33 -05:00
|
|
|
.help( UTF8STDSTR( _(
|
|
|
|
"Valid options: front,back,both. Gerber format only supports \"both\"." ) ) );
|
2022-11-07 07:15:55 -05:00
|
|
|
|
|
|
|
m_argParser.add_argument( ARG_FORMAT )
|
|
|
|
.default_value( std::string( "ascii" ) )
|
2023-08-31 22:01:07 -04:00
|
|
|
.help( UTF8STDSTR( _( "Valid options: ascii,csv,gerber" ) ) )
|
|
|
|
.metavar( "FORMAT" );
|
2022-11-07 07:15:55 -05:00
|
|
|
|
|
|
|
m_argParser.add_argument( ARG_UNITS )
|
|
|
|
.default_value( std::string( "in" ) )
|
2023-08-31 22:01:07 -04:00
|
|
|
.help( UTF8STDSTR(
|
|
|
|
_( "Output units; ascii or csv format only; valid options: in,mm" ) ) )
|
|
|
|
.metavar( "UNITS" );
|
2022-11-07 07:15:55 -05:00
|
|
|
|
|
|
|
m_argParser.add_argument( ARG_NEGATE_BOTTOM_X )
|
2022-11-14 07:25:33 -05:00
|
|
|
.help( UTF8STDSTR( _( "Use negative X coordinates for footprints on bottom layer "
|
|
|
|
"(ascii or csv formats only)" ) ) )
|
2022-11-07 07:15:55 -05:00
|
|
|
.implicit_value( true )
|
|
|
|
.default_value( false );
|
|
|
|
|
|
|
|
m_argParser.add_argument( ARG_USE_DRILL_FILE_ORIGIN )
|
2022-11-14 07:25:33 -05:00
|
|
|
.help( UTF8STDSTR( _( "Use drill/place file origin (ascii or csv only)" ) ) )
|
2022-11-07 07:15:55 -05:00
|
|
|
.implicit_value( true )
|
|
|
|
.default_value( false );
|
|
|
|
|
|
|
|
m_argParser.add_argument( ARG_SMD_ONLY )
|
2022-11-14 07:25:33 -05:00
|
|
|
.help( UTF8STDSTR( _( "Include only SMD footprints (ascii or csv only)" ) ) )
|
2022-11-07 07:15:55 -05:00
|
|
|
.implicit_value( true )
|
|
|
|
.default_value( false );
|
|
|
|
|
|
|
|
m_argParser.add_argument( ARG_EXCLUDE_FOOTPRINTS_TH )
|
2022-11-14 07:25:33 -05:00
|
|
|
.help( UTF8STDSTR(
|
|
|
|
_( "Exclude all footprints with through-hole pads (ascii or csv only)" ) ) )
|
2022-11-07 07:15:55 -05:00
|
|
|
.implicit_value( true )
|
|
|
|
.default_value( false );
|
|
|
|
|
2023-08-04 11:02:10 -07:00
|
|
|
m_argParser.add_argument( ARG_EXCLUDE_DNP )
|
|
|
|
.help( UTF8STDSTR(
|
|
|
|
_( "Exclude all footprints with the Do Not Populate flag set" ) ) )
|
|
|
|
.implicit_value( true )
|
|
|
|
.default_value( false );
|
|
|
|
|
2022-11-07 07:15:55 -05:00
|
|
|
m_argParser.add_argument( ARG_GERBER_BOARD_EDGE )
|
2022-11-14 07:25:33 -05:00
|
|
|
.help( UTF8STDSTR( _( "Include board edge layer (gerber only)" ) ) )
|
2022-11-07 07:15:55 -05:00
|
|
|
.implicit_value( true )
|
|
|
|
.default_value( false );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-08-19 11:51:50 -04:00
|
|
|
int CLI::PCB_EXPORT_POS_COMMAND::doPerform( KIWAY& aKiway )
|
2022-11-07 07:15:55 -05:00
|
|
|
{
|
2023-08-19 11:51:50 -04:00
|
|
|
int baseExit = PCB_EXPORT_BASE_COMMAND::doPerform( aKiway );
|
2022-11-07 07:15:55 -05:00
|
|
|
if( baseExit != EXIT_CODES::OK )
|
|
|
|
return baseExit;
|
|
|
|
|
|
|
|
std::unique_ptr<JOB_EXPORT_PCB_POS> aPosJob( new JOB_EXPORT_PCB_POS( true ) );
|
|
|
|
|
2023-08-31 18:43:32 -04:00
|
|
|
aPosJob->m_filename = m_argInput;
|
|
|
|
aPosJob->m_outputFile = m_argOutput;
|
2022-11-07 07:15:55 -05:00
|
|
|
|
|
|
|
if( !wxFile::Exists( aPosJob->m_filename ) )
|
|
|
|
{
|
|
|
|
wxFprintf( stderr, _( "Board file does not exist or is not accessible\n" ) );
|
|
|
|
return EXIT_CODES::ERR_INVALID_INPUT_FILE;
|
|
|
|
}
|
|
|
|
|
|
|
|
aPosJob->m_negateBottomX = m_argParser.get<bool>( ARG_NEGATE_BOTTOM_X );
|
|
|
|
aPosJob->m_smdOnly = m_argParser.get<bool>( ARG_SMD_ONLY );
|
|
|
|
aPosJob->m_excludeFootprintsWithTh = m_argParser.get<bool>( ARG_EXCLUDE_FOOTPRINTS_TH );
|
|
|
|
aPosJob->m_useDrillPlaceFileOrigin = m_argParser.get<bool>( ARG_USE_DRILL_FILE_ORIGIN );
|
2023-08-04 11:02:10 -07:00
|
|
|
aPosJob->m_excludeDNP = m_argParser.get<bool>( ARG_EXCLUDE_DNP );
|
2023-02-19 00:24:05 -05:00
|
|
|
aPosJob->m_gerberBoardEdge = m_argParser.get<bool>( ARG_GERBER_BOARD_EDGE );
|
2022-11-07 07:15:55 -05:00
|
|
|
|
2023-09-09 00:10:57 -04:00
|
|
|
wxString format = From_UTF8( m_argParser.get<std::string>( ARG_FORMAT ).c_str() );
|
2022-11-07 07:15:55 -05:00
|
|
|
if( format == wxS( "ascii" ) )
|
|
|
|
{
|
|
|
|
aPosJob->m_format = JOB_EXPORT_PCB_POS::FORMAT::ASCII;
|
|
|
|
}
|
|
|
|
else if( format == wxS( "csv" ) )
|
|
|
|
{
|
|
|
|
aPosJob->m_format = JOB_EXPORT_PCB_POS::FORMAT::CSV;
|
|
|
|
}
|
|
|
|
else if( format == wxS( "gerber" ) )
|
|
|
|
{
|
|
|
|
aPosJob->m_format = JOB_EXPORT_PCB_POS::FORMAT::GERBER;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
wxFprintf( stderr, _( "Invalid format\n" ) );
|
|
|
|
return EXIT_CODES::ERR_ARGS;
|
|
|
|
}
|
|
|
|
|
2023-09-09 00:10:57 -04:00
|
|
|
wxString units = From_UTF8( m_argParser.get<std::string>( ARG_UNITS ).c_str() );
|
2022-11-07 07:15:55 -05:00
|
|
|
|
|
|
|
if( units == wxS( "mm" ) )
|
|
|
|
{
|
|
|
|
aPosJob->m_units = JOB_EXPORT_PCB_POS::UNITS::MILLIMETERS;
|
|
|
|
}
|
|
|
|
else if( units == wxS( "in" ) )
|
|
|
|
{
|
|
|
|
aPosJob->m_units = JOB_EXPORT_PCB_POS::UNITS::INCHES;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
wxFprintf( stderr, _( "Invalid units specified\n" ) );
|
|
|
|
return EXIT_CODES::ERR_ARGS;
|
|
|
|
}
|
|
|
|
|
2023-09-09 00:10:57 -04:00
|
|
|
wxString side = From_UTF8( m_argParser.get<std::string>( ARG_SIDE ).c_str() );
|
2022-11-07 07:15:55 -05:00
|
|
|
|
2022-11-13 18:20:08 -05:00
|
|
|
if( side == wxS( "both" ) )
|
2022-11-07 07:15:55 -05:00
|
|
|
{
|
|
|
|
if( aPosJob->m_format == JOB_EXPORT_PCB_POS::FORMAT::GERBER )
|
|
|
|
{
|
|
|
|
wxFprintf( stderr, _( "\"both\" not supported for gerber format\n" ) );
|
|
|
|
return EXIT_CODES::ERR_ARGS;
|
|
|
|
}
|
|
|
|
|
|
|
|
aPosJob->m_side = JOB_EXPORT_PCB_POS::SIDE::BOTH;
|
|
|
|
}
|
2022-11-13 18:20:08 -05:00
|
|
|
else if( side == wxS( "front" ) )
|
2022-11-07 07:15:55 -05:00
|
|
|
{
|
|
|
|
aPosJob->m_side = JOB_EXPORT_PCB_POS::SIDE::FRONT;
|
|
|
|
}
|
2022-11-13 18:20:08 -05:00
|
|
|
else if( side == wxS( "back" ) )
|
2022-11-07 07:15:55 -05:00
|
|
|
{
|
|
|
|
aPosJob->m_side = JOB_EXPORT_PCB_POS::SIDE::BACK;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
wxFprintf( stderr, _( "Invalid side specified\n" ) );
|
|
|
|
return EXIT_CODES::ERR_ARGS;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
LOCALE_IO dummy;
|
|
|
|
int exitCode = aKiway.ProcessJob( KIWAY::FACE_PCB, aPosJob.get() );
|
|
|
|
|
|
|
|
return exitCode;
|
|
|
|
}
|