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 The 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
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
19 */
20
22#include <cli/exit_codes.h>
24#include <kiface_base.h>
25#include <string_utils.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_EXCLUDE_DNP "--exclude-dnp"
40#define ARG_EXCLUDE_BOM "--exclude-bom"
41#define ARG_GERBER_BOARD_EDGE "--gerber-board-edge"
42
43
46{
47 m_argParser.add_description( UTF8STDSTR( _( "Generate Position File" ) ) );
48
49 m_argParser.add_argument( ARG_SIDE )
50 .default_value( std::string( "both" ) )
51 .help( UTF8STDSTR( _( "Valid options: front, back, both. Gerber format only supports "
52 "\"front\" or \"back\"." ) ) );
53
54 m_argParser.add_argument( ARG_FORMAT )
55 .default_value( std::string( "ascii" ) )
56 .help( UTF8STDSTR( _( "Valid options: ascii, csv, gerber" ) ) )
57 .metavar( "FORMAT" );
58
59 m_argParser.add_argument( ARG_UNITS )
60 .default_value( std::string( "in" ) )
61 .help( UTF8STDSTR( _( "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
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( _( "Exclude all footprints with the Do Not Populate flag set" ) ) )
84 .flag();
85
86 m_argParser.add_argument( ARG_EXCLUDE_BOM )
87 .help( UTF8STDSTR( _( "Exclude all footprints with the Exclude from BOM flag set" ) ) )
88 .flag();
89
91 .help( UTF8STDSTR( _( "Include board edge layer (Gerber only)" ) ) )
92 .flag();
93
95}
96
97
99{
100 std::unique_ptr<JOB_EXPORT_PCB_POS> aPosJob( new JOB_EXPORT_PCB_POS() );
101
102 aPosJob->m_filename = m_argInput;
103 aPosJob->SetConfiguredOutputPath( m_argOutput );
104
105 if( !wxFile::Exists( aPosJob->m_filename ) )
106 {
107 wxFprintf( stderr, _( "Board file does not exist or is not accessible\n" ) );
109 }
110
111 aPosJob->m_negateBottomX = m_argParser.get<bool>( ARG_NEGATE_BOTTOM_X );
112 aPosJob->m_singleFile = true;
113 aPosJob->m_nakedFilename = true;
114 aPosJob->m_smdOnly = m_argParser.get<bool>( ARG_SMD_ONLY );
115 aPosJob->m_excludeFootprintsWithTh = m_argParser.get<bool>( ARG_EXCLUDE_FOOTPRINTS_TH );
116 aPosJob->m_useDrillPlaceFileOrigin = m_argParser.get<bool>( ARG_USE_DRILL_FILE_ORIGIN );
117 aPosJob->m_excludeDNP = m_argParser.get<bool>( ARG_EXCLUDE_DNP );
118 aPosJob->m_excludeBOM = m_argParser.get<bool>( ARG_EXCLUDE_BOM );
119 aPosJob->m_gerberBoardEdge = m_argParser.get<bool>( ARG_GERBER_BOARD_EDGE );
120
121 if( !m_argVariantNames.empty() )
122 aPosJob->m_variant = m_argVariantNames.front();
123
124 wxString format = From_UTF8( m_argParser.get<std::string>( ARG_FORMAT ).c_str() );
125
126 if( format == wxS( "ascii" ) )
127 {
128 aPosJob->m_format = JOB_EXPORT_PCB_POS::FORMAT::ASCII;
129 }
130 else if( format == wxS( "csv" ) )
131 {
132 aPosJob->m_format = JOB_EXPORT_PCB_POS::FORMAT::CSV;
133 }
134 else if( format == wxS( "gerber" ) )
135 {
136 aPosJob->m_format = JOB_EXPORT_PCB_POS::FORMAT::GERBER;
137 }
138 else
139 {
140 wxFprintf( stderr, _( "Invalid format\n" ) );
142 }
143
144 wxString units = From_UTF8( m_argParser.get<std::string>( ARG_UNITS ).c_str() );
145
146 if( units == wxS( "mm" ) )
147 {
148 aPosJob->m_units = JOB_EXPORT_PCB_POS::UNITS::MM;
149 }
150 else if( units == wxS( "in" ) )
151 {
152 aPosJob->m_units = JOB_EXPORT_PCB_POS::UNITS::INCH;
153 }
154 else
155 {
156 wxFprintf( stderr, _( "Invalid units specified\n" ) );
158 }
159
160 wxString side = From_UTF8( m_argParser.get<std::string>( ARG_SIDE ).c_str() );
161
162 if( side == wxS( "both" ) )
163 {
164 if( aPosJob->m_format == JOB_EXPORT_PCB_POS::FORMAT::GERBER )
165 {
166 wxFprintf( stderr, _( "\"both\" not supported for Gerber format\n" ) );
168 }
169
170 aPosJob->m_side = JOB_EXPORT_PCB_POS::SIDE::BOTH;
171 }
172 else if( side == wxS( "front" ) )
173 {
174 aPosJob->m_side = JOB_EXPORT_PCB_POS::SIDE::FRONT;
175 }
176 else if( side == wxS( "back" ) )
177 {
178 aPosJob->m_side = JOB_EXPORT_PCB_POS::SIDE::BACK;
179 }
180 else
181 {
182 wxFprintf( stderr, _( "Invalid side specified\n" ) );
184 }
185
187 return aKiway.ProcessJob( KIWAY::FACE_PCB, aPosJob.get() );
188}
argparse::ArgumentParser m_argParser
Definition command.h:113
void addVariantsArg(bool aRequireOutputToken=true)
Set up the list of variants to output arguement.
Definition command.cpp:229
wxString m_argOutput
Value of the output arg if configured.
Definition command.h:143
wxString m_argInput
Value of the common input arg if configured.
Definition command.h:138
std::vector< wxString > m_argVariantNames
The list of variant names to output.
Definition command.h:166
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:348
int ProcessJob(KIWAY::FACE_T aFace, JOB *aJob, REPORTER *aReporter=nullptr, PROGRESS_REPORTER *aProgressReporter=nullptr)
Definition kiway.cpp:765
@ FACE_PCB
pcbnew DSO
Definition kiway.h:356
Instantiate the current locale within a scope in which you are expecting exceptions to be thrown.
Definition locale_io.h:37
#define UTF8STDSTR(s)
Definition command.h:27
#define ARG_EXCLUDE_DNP
#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_EXCLUDE_BOM
#define ARG_SMD_ONLY
#define _(s)
This file contains miscellaneous commonly used macros and functions.
static const int ERR_ARGS
Definition exit_codes.h:31
static const int ERR_INVALID_INPUT_FILE
Definition exit_codes.h:33
std::vector< FAB_LAYER_COLOR > dummy
wxString From_UTF8(const char *cstring)
PCB_EXPORT_BASE_COMMAND(const std::string &aName, IO_TYPE aInputType=IO_TYPE::FILE, IO_TYPE aOutputType=IO_TYPE::FILE)