KiCad PCB EDA Suite
Loading...
Searching...
No Matches
command_pcb_export_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 <string_utils.h>
27#include <wx/crt.h>
28
29#include <macros.h>
30
31#include <locale_io.h>
32
33#define ARG_SIDE "--side"
34#define ARG_FORMAT "--format"
35#define ARG_UNITS "--units"
36#define ARG_NEGATE_BOTTOM_X "--bottom-negate-x"
37#define ARG_USE_DRILL_FILE_ORIGIN "--use-drill-file-origin"
38#define ARG_SMD_ONLY "--smd-only"
39#define ARG_EXCLUDE_FOOTPRINTS_TH "--exclude-fp-th"
40#define ARG_EXCLUDE_DNP "--exclude-dnp"
41#define ARG_GERBER_BOARD_EDGE "--gerber-board-edge"
42
43
45{
46 m_argParser.add_description( UTF8STDSTR( _( "Generate Position File" ) ) );
47
48 m_argParser.add_argument( ARG_SIDE )
49 .default_value( std::string( "both" ) )
50 .help( UTF8STDSTR( _(
51 "Valid options: front,back,both. Gerber format only supports \"both\"." ) ) );
52
53 m_argParser.add_argument( ARG_FORMAT )
54 .default_value( std::string( "ascii" ) )
55 .help( UTF8STDSTR( _( "Valid options: ascii,csv,gerber" ) ) )
56 .metavar( "FORMAT" );
57
58 m_argParser.add_argument( ARG_UNITS )
59 .default_value( std::string( "in" ) )
60 .help( UTF8STDSTR(
61 _( "Output units; ascii or csv format only; valid options: in,mm" ) ) )
62 .metavar( "UNITS" );
63
64 m_argParser.add_argument( ARG_NEGATE_BOTTOM_X )
65 .help( UTF8STDSTR( _( "Use negative X coordinates for footprints on bottom layer "
66 "(ascii or csv formats only)" ) ) )
67 .flag();
68
70 .help( UTF8STDSTR( _( "Use drill/place file origin (ascii or csv only)" ) ) )
71 .flag();
72
73 m_argParser.add_argument( ARG_SMD_ONLY )
74 .help( UTF8STDSTR( _( "Include only SMD footprints (ascii or csv only)" ) ) )
75 .flag();
76
78 .help( UTF8STDSTR(
79 _( "Exclude all footprints with through-hole pads (ascii or csv only)" ) ) )
80 .flag();
81
82 m_argParser.add_argument( ARG_EXCLUDE_DNP )
83 .help( UTF8STDSTR(
84 _( "Exclude all footprints with the Do Not Populate flag set" ) ) )
85 .flag();
86
88 .help( UTF8STDSTR( _( "Include board edge layer (Gerber only)" ) ) )
89 .flag();
90}
91
92
94{
95 int baseExit = PCB_EXPORT_BASE_COMMAND::doPerform( aKiway );
96 if( baseExit != EXIT_CODES::OK )
97 return baseExit;
98
99 std::unique_ptr<JOB_EXPORT_PCB_POS> aPosJob( new JOB_EXPORT_PCB_POS( true ) );
100
101 aPosJob->m_filename = m_argInput;
102 aPosJob->m_outputFile = m_argOutput;
103
104 if( !wxFile::Exists( aPosJob->m_filename ) )
105 {
106 wxFprintf( stderr, _( "Board file does not exist or is not accessible\n" ) );
108 }
109
110 aPosJob->m_negateBottomX = m_argParser.get<bool>( ARG_NEGATE_BOTTOM_X );
111 aPosJob->m_smdOnly = m_argParser.get<bool>( ARG_SMD_ONLY );
112 aPosJob->m_excludeFootprintsWithTh = m_argParser.get<bool>( ARG_EXCLUDE_FOOTPRINTS_TH );
113 aPosJob->m_useDrillPlaceFileOrigin = m_argParser.get<bool>( ARG_USE_DRILL_FILE_ORIGIN );
114 aPosJob->m_excludeDNP = m_argParser.get<bool>( ARG_EXCLUDE_DNP );
115 aPosJob->m_gerberBoardEdge = m_argParser.get<bool>( ARG_GERBER_BOARD_EDGE );
116
117 wxString format = From_UTF8( m_argParser.get<std::string>( ARG_FORMAT ).c_str() );
118 if( format == wxS( "ascii" ) )
119 {
120 aPosJob->m_format = JOB_EXPORT_PCB_POS::FORMAT::ASCII;
121 }
122 else if( format == wxS( "csv" ) )
123 {
124 aPosJob->m_format = JOB_EXPORT_PCB_POS::FORMAT::CSV;
125 }
126 else if( format == wxS( "gerber" ) )
127 {
128 aPosJob->m_format = JOB_EXPORT_PCB_POS::FORMAT::GERBER;
129 }
130 else
131 {
132 wxFprintf( stderr, _( "Invalid format\n" ) );
134 }
135
136 wxString units = From_UTF8( m_argParser.get<std::string>( ARG_UNITS ).c_str() );
137
138 if( units == wxS( "mm" ) )
139 {
141 }
142 else if( units == wxS( "in" ) )
143 {
144 aPosJob->m_units = JOB_EXPORT_PCB_POS::UNITS::INCHES;
145 }
146 else
147 {
148 wxFprintf( stderr, _( "Invalid units specified\n" ) );
150 }
151
152 wxString side = From_UTF8( m_argParser.get<std::string>( ARG_SIDE ).c_str() );
153
154 if( side == wxS( "both" ) )
155 {
156 if( aPosJob->m_format == JOB_EXPORT_PCB_POS::FORMAT::GERBER )
157 {
158 wxFprintf( stderr, _( "\"both\" not supported for Gerber format\n" ) );
160 }
161
162 aPosJob->m_side = JOB_EXPORT_PCB_POS::SIDE::BOTH;
163 }
164 else if( side == wxS( "front" ) )
165 {
166 aPosJob->m_side = JOB_EXPORT_PCB_POS::SIDE::FRONT;
167 }
168 else if( side == wxS( "back" ) )
169 {
170 aPosJob->m_side = JOB_EXPORT_PCB_POS::SIDE::BACK;
171 }
172 else
173 {
174 wxFprintf( stderr, _( "Invalid side specified\n" ) );
176 }
177
178
180 int exitCode = aKiway.ProcessJob( KIWAY::FACE_PCB, aPosJob.get() );
181
182 return exitCode;
183}
argparse::ArgumentParser m_argParser
Definition: command.h:100
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:709
@ 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:49
#define UTF8STDSTR(s)
Definition: command.h:27
#define ARG_UNITS
#define ARG_FORMAT
#define ARG_USE_DRILL_FILE_ORIGIN
#define ARG_EXCLUDE_FOOTPRINTS_TH
#define ARG_GERBER_BOARD_EDGE
#define ARG_NEGATE_BOTTOM_X
#define ARG_SIDE
#define ARG_SMD_ONLY
#define ARG_EXCLUDE_DNP
#define _(s)
This file contains miscellaneous commonly used macros and functions.
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
wxString From_UTF8(const char *cstring)
int doPerform(KIWAY &aKiway) override
The internal handler that should be overloaded to implement command specific processing and work.