KiCad PCB EDA Suite
Loading...
Searching...
No Matches
command_pcb_export_ipc2581.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#include <wx/tokenzr.h>
30
31#include <locale_io.h>
32
33#define ARG_COMPRESS "--compress"
34
35#define ARG_BOM_COL_INT_ID "--bom-col-int-id"
36#define ARG_BOM_COL_MFG_PN "--bom-col-mfg-pn"
37#define ARG_BOM_COL_MFG "--bom-col-mfg"
38#define ARG_BOM_COL_DIST_PN "--bom-col-dist-pn"
39#define ARG_BOM_COL_DIST "--bom-col-dist"
40#define ARG_BOM_REV "--bom-rev"
41#define ARG_UNITS "--units"
42#define ARG_MODE "--mode"
43#define ARG_SECTIONS "--sections"
44#define ARG_NET_NAMES "--net-names"
45#define ARG_REF_DES "--ref-des"
46
48 PCB_EXPORT_BASE_COMMAND( "ipc2581" )
49{
52
53 m_argParser.add_description( std::string( "Export the PCB in IPC-2581 format" ) );
54
55 m_argParser.add_argument( ARG_PRECISION )
56 .help( std::string( "Precision" ) )
57 .scan<'i', int>()
58 .default_value( 6 )
59 .metavar( "PRECISION" );
60
61 m_argParser.add_argument( ARG_COMPRESS )
62 .help( std::string( "Compress the output" ) )
63 .flag();
64
65 m_argParser.add_argument( ARG_VERSION )
66 .default_value( std::string( "C" ) )
67 .help( std::string( "IPC-2581 standard version" ) )
68 .choices( "B", "C" );
69
70 m_argParser.add_argument( ARG_UNITS )
71 .default_value( std::string( "mm" ) )
72 .help( std::string( "Units" ) )
73 .choices( "mm", "in" );
74
75 m_argParser.add_argument( ARG_BOM_COL_INT_ID )
76 .default_value( std::string() )
77 .help( std::string(
78 "Name of the part field to use for the Bill of Material Internal Id Column" ) )
79 .metavar( "FIELD_NAME" );
80
81 m_argParser.add_argument( ARG_BOM_COL_MFG_PN )
82 .default_value( std::string() )
83 .help( std::string( "Name of the part field to use for the Bill of "
84 "Material Manufacturer Part Number Column" ) )
85 .metavar( "FIELD_NAME" );
86
87 m_argParser.add_argument( ARG_BOM_COL_MFG )
88 .default_value( std::string() )
89 .help( std::string( "Name of the part field to use for the Bill of "
90 "Material Manufacturer Column" ) )
91 .metavar( "FIELD_NAME" );
92
93 m_argParser.add_argument( ARG_BOM_COL_DIST_PN )
94 .default_value( std::string() )
95 .help( std::string( "Name of the part field to use for the Bill of "
96 "Material Distributor Part Number Column" ) )
97 .metavar( "FIELD_NAME" );
98
99 m_argParser.add_argument( ARG_BOM_COL_DIST )
100 .default_value( std::string() )
101 .help( std::string( "Name to insert into Bill of "
102 "Material Distributor Column" ) )
103 .metavar( "FIELD_NAME" );
104
105 m_argParser.add_argument( ARG_BOM_REV )
106 .default_value( std::string() )
107 .help( std::string( "BOM revision to use in the output file. "
108 "Defaults to schematic revision from the project file" ) )
109 .metavar( "REVISION" );
110
111 // An absent mode keeps the content that KiCad wrote before the function modes
112 // An explicit userdef does not keep it
113 m_argParser.add_argument( ARG_MODE )
114 .default_value( std::string() )
115 .help( std::string( "Data set to export, per the IPC-2581 function mode table: "
116 "userdef, bom, stackup, fabrication, assembly, test or "
117 "stencil" ) )
118 .metavar( "DATA_SET" );
119
120 m_argParser.add_argument( ARG_SECTIONS )
121 .default_value( std::string() )
122 .help( std::string( "Override the optional sections of the chosen data set, as "
123 "IPC-2581 section key letters" ) )
124 .metavar( "SECTION_KEY" );
125
126 m_argParser.add_argument( ARG_NET_NAMES )
127 .default_value( std::string( "include" ) )
128 .help( std::string( "Whether net names are exported as authored or replaced "
129 "with opaque names that preserve connectivity" ) )
130 .choices( "include", "anonymize" );
131
132 m_argParser.add_argument( ARG_REF_DES )
133 .default_value( std::string( "include" ) )
134 .help( std::string( "Whether reference designators are exported" ) )
135 .choices( "include", "omit" );
136
138}
139
140
142{
143 std::unique_ptr<JOB_EXPORT_PCB_IPC2581> ipc2581Job( new JOB_EXPORT_PCB_IPC2581() );
144
145 ipc2581Job->m_filename = m_argInput;
146 ipc2581Job->SetConfiguredOutputPath( m_argOutput );
147 ipc2581Job->m_drawingSheet = m_argDrawingSheet;
148 ipc2581Job->SetVarOverrides( m_argDefineVars );
149
150 if( !m_argVariantNames.empty() )
151 ipc2581Job->m_variant = m_argVariantNames.front();
152
153 if( !wxFile::Exists( ipc2581Job->m_filename ) )
154 {
155 wxFprintf( stderr, _( "Board file does not exist or is not accessible\n" ) );
157 }
158
159 ipc2581Job->m_compress = m_argParser.get<bool>( ARG_COMPRESS );
160 ipc2581Job->m_precision = m_argParser.get<int>( ARG_PRECISION );
161
162 wxString version = From_UTF8( m_argParser.get<std::string>( ARG_VERSION ).c_str() );
163 if( version == 'B' )
164 ipc2581Job->m_version = JOB_EXPORT_PCB_IPC2581::IPC2581_VERSION::B;
165 else if( version == 'C' )
166 ipc2581Job->m_version = JOB_EXPORT_PCB_IPC2581::IPC2581_VERSION::C;
167
168 wxString units = From_UTF8( m_argParser.get<std::string>( ARG_UNITS ).c_str() );
169 if( units == "mm" )
170 ipc2581Job->m_units = JOB_EXPORT_PCB_IPC2581::IPC2581_UNITS::MM;
171 else if( units == "in" )
173
174 ipc2581Job->m_colInternalId =
175 From_UTF8( m_argParser.get<std::string>( ARG_BOM_COL_INT_ID ).c_str() );
176 ipc2581Job->m_colMfgPn =
177 From_UTF8( m_argParser.get<std::string>( ARG_BOM_COL_MFG_PN ).c_str() );
178 ipc2581Job->m_colMfg = From_UTF8( m_argParser.get<std::string>( ARG_BOM_COL_MFG ).c_str() );
179 ipc2581Job->m_colDistPn =
180 From_UTF8( m_argParser.get<std::string>( ARG_BOM_COL_DIST_PN ).c_str() );
181 ipc2581Job->m_colDist =
182 From_UTF8( m_argParser.get<std::string>( ARG_BOM_COL_DIST ).c_str() );
183 ipc2581Job->m_bomRev =
184 From_UTF8( m_argParser.get<std::string>( ARG_BOM_REV ).c_str() );
185 ipc2581Job->m_mode = From_UTF8( m_argParser.get<std::string>( ARG_MODE ).c_str() );
186
187 ipc2581Job->m_sections = From_UTF8( m_argParser.get<std::string>( ARG_SECTIONS ).c_str() );
188
189 ipc2581Job->m_netNamePolicy = From_UTF8( m_argParser.get<std::string>( ARG_NET_NAMES ).c_str() );
190 ipc2581Job->m_refDesPolicy = From_UTF8( m_argParser.get<std::string>( ARG_REF_DES ).c_str() );
191
193 return aKiway.ProcessJob( KIWAY::FACE_PCB, ipc2581Job.get() );
194}
std::map< wxString, wxString > m_argDefineVars
Value of the drawing sheet arg if configured.
Definition command.h:153
void addVariantsArg()
Set up the list of variants to output arguement.
Definition command.cpp:227
argparse::ArgumentParser m_argParser
Definition command.h:113
void addDefineArg()
Set up the drawing sheet arg used by many of the export commands.
Definition command.cpp:212
wxString m_argDrawingSheet
Value of the drawing sheet arg if configured.
Definition command.h:148
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:165
void addDrawingSheetArg()
Set up the drawing sheet arg used by many of the export commands.
Definition command.cpp:200
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:340
int ProcessJob(KIWAY::FACE_T aFace, JOB *aJob, REPORTER *aReporter=nullptr, PROGRESS_REPORTER *aProgressReporter=nullptr)
Definition kiway.cpp:740
@ FACE_PCB
pcbnew DSO
Definition kiway.h:348
Instantiate the current locale within a scope in which you are expecting exceptions to be thrown.
Definition locale_io.h:37
#define ARG_VERSION
Definition command.h:29
#define ARG_UNITS
#define ARG_PRECISION
#define ARG_NET_NAMES
#define ARG_BOM_COL_MFG
#define ARG_BOM_COL_DIST_PN
#define ARG_BOM_COL_INT_ID
#define ARG_BOM_COL_DIST
#define ARG_REF_DES
#define ARG_BOM_COL_MFG_PN
#define ARG_BOM_REV
#define ARG_SECTIONS
#define ARG_COMPRESS
#define _(s)
This file contains miscellaneous commonly used macros and functions.
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)