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 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 <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
44 PCB_EXPORT_BASE_COMMAND( "ipc2581" )
45{
48
49 m_argParser.add_description( std::string( "Export the PCB in IPC-2581 format" ) );
50
51 m_argParser.add_argument( ARG_PRECISION )
52 .help( std::string( "Precision" ) )
53 .scan<'i', int>()
54 .default_value( 6 )
55 .metavar( "PRECISION" );
56
57 m_argParser.add_argument( ARG_COMPRESS )
58 .help( std::string( "Compress the output" ) )
59 .flag();
60
61 m_argParser.add_argument( ARG_VERSION )
62 .default_value( std::string( "C" ) )
63 .help( std::string( "IPC-2581 standard version" ) )
64 .choices( "B", "C" );
65
66 m_argParser.add_argument( ARG_UNITS )
67 .default_value( std::string( "mm" ) )
68 .help( std::string( "Units" ) )
69 .choices( "mm", "in" );
70
71 m_argParser.add_argument( ARG_BOM_COL_INT_ID )
72 .default_value( std::string() )
73 .help( std::string(
74 "Name of the part field to use for the Bill of Material Internal Id Column" ) )
75 .metavar( "FIELD_NAME" );
76
77 m_argParser.add_argument( ARG_BOM_COL_MFG_PN )
78 .default_value( std::string() )
79 .help( std::string( "Name of the part field to use for the Bill of "
80 "Material Manufacturer Part Number Column" ) )
81 .metavar( "FIELD_NAME" );
82
83 m_argParser.add_argument( ARG_BOM_COL_MFG )
84 .default_value( std::string() )
85 .help( std::string( "Name of the part field to use for the Bill of "
86 "Material Manufacturer Column" ) )
87 .metavar( "FIELD_NAME" );
88
89 m_argParser.add_argument( ARG_BOM_COL_DIST_PN )
90 .default_value( std::string() )
91 .help( std::string( "Name of the part field to use for the Bill of "
92 "Material Distributor Part Number Column" ) )
93 .metavar( "FIELD_NAME" );
94
95 m_argParser.add_argument( ARG_BOM_COL_DIST )
96 .default_value( std::string() )
97 .help( std::string( "Name to insert into Bill of "
98 "Material Distributor Column" ) )
99 .metavar( "FIELD_NAME" );
100
101 m_argParser.add_argument( ARG_BOM_REV )
102 .default_value( std::string() )
103 .help( std::string( "BOM revision to use in the output file. "
104 "Defaults to schematic revision from the project file" ) )
105 .metavar( "REVISION" );
106
108}
109
110
112{
113 std::unique_ptr<JOB_EXPORT_PCB_IPC2581> ipc2581Job( new JOB_EXPORT_PCB_IPC2581() );
114
115 ipc2581Job->m_filename = m_argInput;
116 ipc2581Job->SetConfiguredOutputPath( m_argOutput );
117 ipc2581Job->m_drawingSheet = m_argDrawingSheet;
118 ipc2581Job->SetVarOverrides( m_argDefineVars );
119
120 if( !m_argVariantNames.empty() )
121 ipc2581Job->m_variant = m_argVariantNames.front();
122
123 if( !wxFile::Exists( ipc2581Job->m_filename ) )
124 {
125 wxFprintf( stderr, _( "Board file does not exist or is not accessible\n" ) );
127 }
128
129 ipc2581Job->m_compress = m_argParser.get<bool>( ARG_COMPRESS );
130 ipc2581Job->m_precision = m_argParser.get<int>( ARG_PRECISION );
131
132 wxString version = From_UTF8( m_argParser.get<std::string>( ARG_VERSION ).c_str() );
133 if( version == 'B' )
134 ipc2581Job->m_version = JOB_EXPORT_PCB_IPC2581::IPC2581_VERSION::B;
135 else if( version == 'C' )
136 ipc2581Job->m_version = JOB_EXPORT_PCB_IPC2581::IPC2581_VERSION::C;
137
138 wxString units = From_UTF8( m_argParser.get<std::string>( ARG_UNITS ).c_str() );
139 if( units == "mm" )
140 ipc2581Job->m_units = JOB_EXPORT_PCB_IPC2581::IPC2581_UNITS::MM;
141 else if( units == "in" )
143
144 ipc2581Job->m_colInternalId =
145 From_UTF8( m_argParser.get<std::string>( ARG_BOM_COL_INT_ID ).c_str() );
146 ipc2581Job->m_colMfgPn =
147 From_UTF8( m_argParser.get<std::string>( ARG_BOM_COL_MFG_PN ).c_str() );
148 ipc2581Job->m_colMfg = From_UTF8( m_argParser.get<std::string>( ARG_BOM_COL_MFG ).c_str() );
149 ipc2581Job->m_colDistPn =
150 From_UTF8( m_argParser.get<std::string>( ARG_BOM_COL_DIST_PN ).c_str() );
151 ipc2581Job->m_colDist =
152 From_UTF8( m_argParser.get<std::string>( ARG_BOM_COL_DIST ).c_str() );
153 ipc2581Job->m_bomRev =
154 From_UTF8( m_argParser.get<std::string>( ARG_BOM_REV ).c_str() );
155
157 return aKiway.ProcessJob( KIWAY::FACE_PCB, ipc2581Job.get() );
158}
std::map< wxString, wxString > m_argDefineVars
Value of the drawing sheet arg if configured.
Definition command.h:158
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:153
wxString m_argOutput
Value of the output arg if configured.
Definition command.h:148
wxString m_argInput
Value of the common input arg if configured.
Definition command.h:143
std::vector< wxString > m_argVariantNames
The list of variant names to output.
Definition command.h:170
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:295
int ProcessJob(KIWAY::FACE_T aFace, JOB *aJob, REPORTER *aReporter=nullptr, PROGRESS_REPORTER *aProgressReporter=nullptr)
Definition kiway.cpp:744
@ FACE_PCB
pcbnew DSO
Definition kiway.h:303
Instantiate the current locale within a scope in which you are expecting exceptions to be thrown.
Definition locale_io.h:41
#define ARG_VERSION
Definition command.h:29
#define ARG_UNITS
#define ARG_PRECISION
#define ARG_BOM_COL_MFG
#define ARG_BOM_COL_DIST_PN
#define ARG_BOM_COL_INT_ID
#define ARG_BOM_COL_DIST
#define ARG_BOM_COL_MFG_PN
#define ARG_BOM_REV
#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)