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 (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 <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_UNITS "--units"
41
43 PCB_EXPORT_BASE_COMMAND( "ipc2581" )
44{
47
48 m_argParser.add_description( std::string( "Export the PCB in IPC2581 format" ) );
49
50 m_argParser.add_argument( ARG_PRECISION )
51 .help( std::string( "Precision" ) )
52 .scan<'i', int>()
53 .default_value( 3 )
54 .metavar( "PRECISION" );
55
56 m_argParser.add_argument( ARG_COMPRESS )
57 .help( std::string( "Compress the output" ) )
58 .flag();
59
60 m_argParser.add_argument( ARG_VERSION )
61 .default_value( std::string( "C" ) )
62 .help( std::string( "IPC2581 standard version" ) )
63 .choices( "B", "C" );
64
65 m_argParser.add_argument( ARG_UNITS )
66 .default_value( std::string( "mm" ) )
67 .help( std::string( "Units" ) )
68 .choices( "mm", "in" );
69
70 m_argParser.add_argument( ARG_BOM_COL_INT_ID )
71 .default_value( std::string() )
72 .help( std::string(
73 "Name of the part field to use for the Bill of Material Internal Id Column" ) )
74 .metavar( "FIELD_NAME" );
75
76 m_argParser.add_argument( ARG_BOM_COL_MFG_PN )
77 .default_value( std::string() )
78 .help( std::string( "Name of the part field to use for the Bill of "
79 "Material Manufacturer Part Number Column" ) )
80 .metavar( "FIELD_NAME" );
81
82 m_argParser.add_argument( ARG_BOM_COL_MFG )
83 .default_value( std::string() )
84 .help( std::string( "Name of the part field to use for the Bill of "
85 "Material Manufacturer Column" ) )
86 .metavar( "FIELD_NAME" );
87
88 m_argParser.add_argument( ARG_BOM_COL_DIST_PN )
89 .default_value( std::string() )
90 .help( std::string( "Name of the part field to use for the Bill of "
91 "Material Distributor Part Number Column" ) )
92 .metavar( "FIELD_NAME" );
93
94 m_argParser.add_argument( ARG_BOM_COL_DIST )
95 .default_value( std::string() )
96 .help( std::string( "Name to insert into Bill of "
97 "Material Distributor Column" ) )
98 .metavar( "FIELD_NAME" );
99
100}
101
102
104{
105 int exitCode = PCB_EXPORT_BASE_COMMAND::doPerform( aKiway );
106
107 if( exitCode != EXIT_CODES::OK )
108 return exitCode;
109
110 std::unique_ptr<JOB_EXPORT_PCB_IPC2581> ipc2581Job( new JOB_EXPORT_PCB_IPC2581() );
111
112 ipc2581Job->m_filename = m_argInput;
113 ipc2581Job->SetOutputPath( m_argOutput );
114 ipc2581Job->m_drawingSheet = m_argDrawingSheet;
115 ipc2581Job->SetVarOverrides( m_argDefineVars );
116
117 if( !wxFile::Exists( ipc2581Job->m_filename ) )
118 {
119 wxFprintf( stderr, _( "Board file does not exist or is not accessible\n" ) );
121 }
122
123 ipc2581Job->m_compress = m_argParser.get<bool>( ARG_COMPRESS );
124 ipc2581Job->m_precision = m_argParser.get<int>( ARG_PRECISION );
125
126 wxString version = From_UTF8( m_argParser.get<std::string>( ARG_VERSION ).c_str() );
127 if( version == 'B' )
128 ipc2581Job->m_version = JOB_EXPORT_PCB_IPC2581::IPC2581_VERSION::B;
129 else if( version == 'C' )
130 ipc2581Job->m_version = JOB_EXPORT_PCB_IPC2581::IPC2581_VERSION::C;
131
132 wxString units = From_UTF8( m_argParser.get<std::string>( ARG_UNITS ).c_str() );
133 if( units == "mm" )
135 else if( units == "in" )
137
138 ipc2581Job->m_colInternalId =
139 From_UTF8( m_argParser.get<std::string>( ARG_BOM_COL_INT_ID ).c_str() );
140 ipc2581Job->m_colMfgPn =
141 From_UTF8( m_argParser.get<std::string>( ARG_BOM_COL_MFG_PN ).c_str() );
142 ipc2581Job->m_colMfg = From_UTF8( m_argParser.get<std::string>( ARG_BOM_COL_MFG ).c_str() );
143 ipc2581Job->m_colDistPn =
144 From_UTF8( m_argParser.get<std::string>( ARG_BOM_COL_DIST_PN ).c_str() );
145 ipc2581Job->m_colDist =
146 From_UTF8( m_argParser.get<std::string>( ARG_BOM_COL_DIST ).c_str() );
147
149 exitCode = aKiway.ProcessJob( KIWAY::FACE_PCB, ipc2581Job.get() );
150
151 return exitCode;
152}
argparse::ArgumentParser m_argParser
Definition: command.h:100
void addDefineArg()
Set up the drawing sheet arg used by many of the export commands.
Definition: command.cpp:169
void addDrawingSheetArg()
Set up the drawing sheet arg used by many of the export commands.
Definition: command.cpp:157
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:284
int ProcessJob(KIWAY::FACE_T aFace, JOB *aJob)
Definition: kiway.cpp:709
@ FACE_PCB
pcbnew DSO
Definition: kiway.h:292
Instantiate the current locale within a scope in which you are expecting exceptions to be thrown.
Definition: locale_io.h:49
#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_COMPRESS
#define _(s)
This file contains miscellaneous commonly used macros and functions.
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.