KiCad PCB EDA Suite
command_export_pcb_pos.cpp
Go to the documentation of this file.
1/*
2 * This program source code file is part of KiCad, a free EDA CAD application.
3 *
4 * Copyright (C) 2022 Mark Roszko <[email protected]>
5 * Copyright (C) 1992-2022 KiCad Developers, see AUTHORS.txt for contributors.
6 *
7 * This program is free software: you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation, either version 3 of the License, or (at your
10 * option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License along
18 * with this program. If not, see <http://www.gnu.org/licenses/>.
19 */
20
22#include <cli/exit_codes.h>
24#include <kiface_base.h>
25#include <layer_ids.h>
26#include <wx/crt.h>
27
28#include <macros.h>
29
30#include <locale_io.h>
31
32#define ARG_SIDE "--side"
33#define ARG_FORMAT "--format"
34#define ARG_UNITS "--units"
35#define ARG_NEGATE_BOTTOM_X "--bottom-negate-x"
36#define ARG_USE_DRILL_FILE_ORIGIN "--use-drill-file-origin"
37#define ARG_SMD_ONLY "--smd-only"
38#define ARG_EXCLUDE_FOOTPRINTS_TH "--exclude-fp-th"
39#define ARG_GERBER_BOARD_EDGE "--gerber-board-edge"
40
41
43{
44 m_argParser.add_description( UTF8STDSTR( _( "Generate Position File" ) ) );
45
46 m_argParser.add_argument( ARG_SIDE )
47 .default_value( std::string( "both" ) )
48 .help( UTF8STDSTR( _(
49 "Valid options: front,back,both. Gerber format only supports \"both\"." ) ) );
50
51 m_argParser.add_argument( ARG_FORMAT )
52 .default_value( std::string( "ascii" ) )
53 .help( UTF8STDSTR( _( "Valid options: ascii,csv,gerber" ) ) );
54
55 m_argParser.add_argument( ARG_UNITS )
56 .default_value( std::string( "in" ) )
57 .help( UTF8STDSTR( _( "Output units; ascii or csv format only; valid options: in,mm" ) ) );
58
59 m_argParser.add_argument( ARG_NEGATE_BOTTOM_X )
60 .help( UTF8STDSTR( _( "Use negative X coordinates for footprints on bottom layer "
61 "(ascii or csv formats only)" ) ) )
62 .implicit_value( true )
63 .default_value( false );
64
66 .help( UTF8STDSTR( _( "Use drill/place file origin (ascii or csv only)" ) ) )
67 .implicit_value( true )
68 .default_value( false );
69
70 m_argParser.add_argument( ARG_SMD_ONLY )
71 .help( UTF8STDSTR( _( "Include only SMD footprints (ascii or csv only)" ) ) )
72 .implicit_value( true )
73 .default_value( false );
74
76 .help( UTF8STDSTR(
77 _( "Exclude all footprints with through-hole pads (ascii or csv only)" ) ) )
78 .implicit_value( true )
79 .default_value( false );
80
82 .help( UTF8STDSTR( _( "Include board edge layer (gerber only)" ) ) )
83 .implicit_value( true )
84 .default_value( false );
85}
86
87
89{
90 int baseExit = EXPORT_PCB_BASE_COMMAND::doPerform( aKiway );
91 if( baseExit != EXIT_CODES::OK )
92 return baseExit;
93
94 std::unique_ptr<JOB_EXPORT_PCB_POS> aPosJob( new JOB_EXPORT_PCB_POS( true ) );
95
96 aPosJob->m_filename = FROM_UTF8( m_argParser.get<std::string>( ARG_INPUT ).c_str() );
97 aPosJob->m_outputFile = FROM_UTF8( m_argParser.get<std::string>( ARG_OUTPUT ).c_str() );
98
99 if( !wxFile::Exists( aPosJob->m_filename ) )
100 {
101 wxFprintf( stderr, _( "Board file does not exist or is not accessible\n" ) );
103 }
104
105 aPosJob->m_negateBottomX = m_argParser.get<bool>( ARG_NEGATE_BOTTOM_X );
106 aPosJob->m_smdOnly = m_argParser.get<bool>( ARG_SMD_ONLY );
107 aPosJob->m_excludeFootprintsWithTh = m_argParser.get<bool>( ARG_EXCLUDE_FOOTPRINTS_TH );
108 aPosJob->m_useDrillPlaceFileOrigin = m_argParser.get<bool>( ARG_USE_DRILL_FILE_ORIGIN );
109 aPosJob->m_gerberBoardEdge = m_argParser.get<bool>( ARG_GERBER_BOARD_EDGE );
110
111 wxString format = FROM_UTF8( m_argParser.get<std::string>( ARG_FORMAT ).c_str() );
112 if( format == wxS( "ascii" ) )
113 {
114 aPosJob->m_format = JOB_EXPORT_PCB_POS::FORMAT::ASCII;
115 }
116 else if( format == wxS( "csv" ) )
117 {
118 aPosJob->m_format = JOB_EXPORT_PCB_POS::FORMAT::CSV;
119 }
120 else if( format == wxS( "gerber" ) )
121 {
122 aPosJob->m_format = JOB_EXPORT_PCB_POS::FORMAT::GERBER;
123 }
124 else
125 {
126 wxFprintf( stderr, _( "Invalid format\n" ) );
128 }
129
130 wxString units = FROM_UTF8( m_argParser.get<std::string>( ARG_UNITS ).c_str() );
131
132 if( units == wxS( "mm" ) )
133 {
135 }
136 else if( units == wxS( "in" ) )
137 {
138 aPosJob->m_units = JOB_EXPORT_PCB_POS::UNITS::INCHES;
139 }
140 else
141 {
142 wxFprintf( stderr, _( "Invalid units specified\n" ) );
144 }
145
146 wxString side = FROM_UTF8( m_argParser.get<std::string>( ARG_SIDE ).c_str() );
147
148 if( side == wxS( "both" ) )
149 {
150 if( aPosJob->m_format == JOB_EXPORT_PCB_POS::FORMAT::GERBER )
151 {
152 wxFprintf( stderr, _( "\"both\" not supported for gerber format\n" ) );
154 }
155
156 aPosJob->m_side = JOB_EXPORT_PCB_POS::SIDE::BOTH;
157 }
158 else if( side == wxS( "front" ) )
159 {
160 aPosJob->m_side = JOB_EXPORT_PCB_POS::SIDE::FRONT;
161 }
162 else if( side == wxS( "back" ) )
163 {
164 aPosJob->m_side = JOB_EXPORT_PCB_POS::SIDE::BACK;
165 }
166 else
167 {
168 wxFprintf( stderr, _( "Invalid side specified\n" ) );
170 }
171
172
174 int exitCode = aKiway.ProcessJob( KIWAY::FACE_PCB, aPosJob.get() );
175
176 return exitCode;
177}
argparse::ArgumentParser m_argParser
Definition: command.h:68
int doPerform(KIWAY &aKiway) override
The internal handler that should be overloaded to implement command specific processing and work.
A minimalistic software bus for communications between various DLLs/DSOs (DSOs) within the same KiCad...
Definition: kiway.h:279
int ProcessJob(KIWAY::FACE_T aFace, JOB *job)
Definition: kiway.cpp:660
@ FACE_PCB
pcbnew DSO
Definition: kiway.h:287
Instantiate the current locale within a scope in which you are expecting exceptions to be thrown.
Definition: locale_io.h:41
#define UTF8STDSTR(s)
Definition: command.h:27
#define ARG_OUTPUT
#define ARG_INPUT
#define ARG_EXCLUDE_FOOTPRINTS_TH
#define ARG_GERBER_BOARD_EDGE
#define ARG_NEGATE_BOTTOM_X
#define ARG_UNITS
#define ARG_USE_DRILL_FILE_ORIGIN
#define ARG_SIDE
#define ARG_SMD_ONLY
#define ARG_FORMAT
#define _(s)
This file contains miscellaneous commonly used macros and functions.
static wxString FROM_UTF8(const char *cstring)
Convert a UTF8 encoded C string to a wxString for all wxWidgets build modes.
Definition: macros.h:110
static const int ERR_ARGS
Definition: exit_codes.h:31
static const int OK
Definition: exit_codes.h:30
static const int ERR_INVALID_INPUT_FILE
Definition: exit_codes.h:33
std::vector< FAB_LAYER_COLOR > dummy
int doPerform(KIWAY &aKiway) override
The internal handler that should be overloaded to implement command specific processing and work.