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
30#include <locale_io.h>
31
32#define ARG_COMPRESS "--compress"
33
34#define ARG_BOM_COL_INT_ID "--bom-col-int-id"
35#define ARG_BOM_COL_MFG "--bom-col-mfg"
36#define ARG_BOM_COL_DIST_PN "--bom-col-dist-pn"
37#define ARG_BOM_COL_DIST "--bom-col-dist"
38#define ARG_BOM_REV "--bom-rev"
39#define ARG_MODE "--mode"
40#define ARG_REF_DES "--ref-des"
41
43 PCB_EXPORT_BASE_COMMAND( "ipc2581" )
44{
47 // Existing scripts pass --mode
49
50 m_argParser.add_description( std::string( "Export the PCB in IPC-2581 format" ) );
51
52 m_argParser.add_argument( ARG_COMPRESS )
53 .help( std::string( "Compress the output" ) )
54 .flag();
55
56 m_argParser.add_argument( ARG_VERSION )
57 .default_value( std::string( "C" ) )
58 .help( std::string( "IPC-2581 standard version" ) )
59 .choices( "B", "C" );
60
61 m_argParser.add_argument( ARG_BOM_COL_INT_ID )
62 .default_value( std::string() )
63 .help( std::string(
64 "Name of the part field to use for the Bill of Material Internal Id Column" ) )
65 .metavar( "FIELD_NAME" );
66
67 m_argParser.add_argument( ARG_BOM_COL_MFG )
68 .default_value( std::string() )
69 .help( std::string( "Name of the part field to use for the Bill of "
70 "Material Manufacturer Column" ) )
71 .metavar( "FIELD_NAME" );
72
73 m_argParser.add_argument( ARG_BOM_COL_DIST_PN )
74 .default_value( std::string() )
75 .help( std::string( "Name of the part field to use for the Bill of "
76 "Material Distributor Part Number Column" ) )
77 .metavar( "FIELD_NAME" );
78
79 m_argParser.add_argument( ARG_BOM_COL_DIST )
80 .default_value( std::string() )
81 .help( std::string( "Name to insert into Bill of "
82 "Material Distributor Column" ) )
83 .metavar( "FIELD_NAME" );
84
85 m_argParser.add_argument( ARG_BOM_REV )
86 .default_value( std::string() )
87 .help( std::string( "BOM revision to use in the output file. "
88 "Defaults to schematic revision from the project file" ) )
89 .metavar( "REVISION" );
90
91 m_argParser.add_argument( ARG_REF_DES )
92 .default_value( std::string( "include" ) )
93 .help( std::string( "Whether reference designators are exported" ) )
94 .choices( "include", "omit" );
95
97}
98
99
101{
102 std::unique_ptr<JOB_EXPORT_PCB_IPC2581> ipc2581Job( new JOB_EXPORT_PCB_IPC2581() );
103
104 applyFabExportArgs( *ipc2581Job );
105 ipc2581Job->SetConfiguredOutputPath( m_argOutput );
106 ipc2581Job->SetVarOverrides( m_argDefineVars );
107
108 if( !wxFile::Exists( ipc2581Job->m_filename ) )
109 {
110 wxFprintf( stderr, _( "Board file does not exist or is not accessible\n" ) );
112 }
113
114 ipc2581Job->m_compress = m_argParser.get<bool>( ARG_COMPRESS );
115
116 wxString version = From_UTF8( m_argParser.get<std::string>( ARG_VERSION ).c_str() );
117 if( version == 'B' )
118 ipc2581Job->m_version = JOB_EXPORT_PCB_IPC2581::IPC2581_VERSION::B;
119 else if( version == 'C' )
120 ipc2581Job->m_version = JOB_EXPORT_PCB_IPC2581::IPC2581_VERSION::C;
121
122 ipc2581Job->m_colInternalId =
123 From_UTF8( m_argParser.get<std::string>( ARG_BOM_COL_INT_ID ).c_str() );
124 ipc2581Job->m_colMfg = From_UTF8( m_argParser.get<std::string>( ARG_BOM_COL_MFG ).c_str() );
125 ipc2581Job->m_colDistPn =
126 From_UTF8( m_argParser.get<std::string>( ARG_BOM_COL_DIST_PN ).c_str() );
127 ipc2581Job->m_colDist =
128 From_UTF8( m_argParser.get<std::string>( ARG_BOM_COL_DIST ).c_str() );
129 ipc2581Job->m_bomRev =
130 From_UTF8( m_argParser.get<std::string>( ARG_BOM_REV ).c_str() );
131 ipc2581Job->m_refDes = m_argParser.get<std::string>( ARG_REF_DES ) == "omit"
134
136 return aKiway.ProcessJob( KIWAY::FACE_PCB, ipc2581Job.get() );
137}
std::map< wxString, wxString > m_argDefineVars
Value of the drawing sheet arg if configured.
Definition command.h:153
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:214
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
void addDrawingSheetArg()
Set up the drawing sheet arg used by many of the export commands.
Definition command.cpp:202
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:740
@ 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 ARG_VERSION
Definition command.h:29
#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_REV
#define ARG_COMPRESS
#define _(s)
static wxString From_UTF8(const char *cstring)
Convert a UTF8 encoded C string to a wxString for all wxWidgets build modes.
Definition idf_helpers.h:44
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
PCB_EXPORT_BASE_COMMAND(const std::string &aName, IO_TYPE aInputType=IO_TYPE::FILE, IO_TYPE aOutputType=IO_TYPE::FILE)
void applyFabExportArgs(JOB_EXPORT_PCB_FAB &aJob)
void addFabExportArgs(const JOB_EXPORT_PCB_FAB &aJob, const std::string &aDataSetAlias={})
aJob says which data sets the format supports aDataSetAlias is a second name for the flag