KiCad PCB EDA Suite
Loading...
Searching...
No Matches
command_pcb_export_idf.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 The KiCad Developers, see AUTHORS.txt for contributors.
5 *
6 * This program is free software: you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation, either version 3 of the License, or (at your
9 * option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <https://www.gnu.org/licenses/>.
18 */
19#include <regex>
20#include <magic_enum.hpp>
21
22#include <cli/exit_codes.h>
23#include <kiface_base.h>
24#include <string_utils.h>
25#include <wx/crt.h>
26
29
30#define ARG_UNITS "--units"
31#define ARG_ORIGIN "--origin"
32#define ARG_USER_ORIGIN_X "--user-origin-x"
33#define ARG_USER_ORIGIN_Y "--user-origin-y"
34#define ARG_NO_UNSPECIFIED "--no-unspecified"
35#define ARG_NO_DNP "--no-dnp"
36#define ARG_EXPLICIT_HEIGHT "--explicit-height"
37#define ARG_PART_NUMBER_FIELD "--part-number-field"
38
39
42{
44
45 m_argParser.add_description( UTF8STDSTR( _( "Export the PCB in IDFv3 format" ) ) );
46
47 m_argParser.add_argument( ARG_UNITS )
48 .default_value( std::string( "mm" ) )
49 .help( UTF8STDSTR( _( "Output units" ) ) )
50 .choices( "mm", "mils" );
51
52 m_argParser.add_argument( ARG_ORIGIN )
53 .default_value( std::string( "center" ) )
54 .help( UTF8STDSTR( _( "Coordinate system origin for the board" ) ) )
55 .choices( "drill", "grid", "user", "center" );
56
57 m_argParser.add_argument( ARG_USER_ORIGIN_X )
58 .default_value( 0.0 )
59 .scan<'g', double>()
60 .help( UTF8STDSTR( _( "User-specified board origin X" ) ) )
61 .metavar( "VALUE" );
62
63 m_argParser.add_argument( ARG_USER_ORIGIN_Y )
64 .default_value( 0.0 )
65 .scan<'g', double>()
66 .help( UTF8STDSTR( _( "User-specified board origin Y" ) ) )
67 .metavar( "VALUE" );
68
69 m_argParser.add_argument( ARG_NO_UNSPECIFIED )
70 .help( UTF8STDSTR( _( "Exclude components with 'Unspecified' footprint type" ) ) )
71 .flag();
72
73 m_argParser.add_argument( ARG_NO_DNP )
74 .help( UTF8STDSTR( _( "Exclude components with 'Do not populate' attribute" ) ) )
75 .flag();
76
77 m_argParser.add_argument( ARG_EXPLICIT_HEIGHT )
78 .help( UTF8STDSTR( _( "Only use explicitly-set footprint heights to create IDFv3 shapes" ) ) )
79 .flag();
80
82 .default_value( std::string( "Value" ) )
83 .help( UTF8STDSTR( _( "Footprint field to export as the part number to the IDF library" ) ) );
84}
85
86
88{
89 std::unique_ptr<JOB_EXPORT_PCB_IDF> idfJob( new JOB_EXPORT_PCB_IDF() );
90
91 idfJob->m_filename = m_argInput;
92 idfJob->SetConfiguredOutputPath( m_argOutput );
93 idfJob->SetVarOverrides( m_argDefineVars );
94
95 if( !wxFile::Exists( idfJob->m_filename ) )
96 {
97 wxFprintf( stderr, _( "Board file does not exist or is not accessible\n" ) );
99 }
100
101 idfJob->m_units = magic_enum::enum_cast<IDF_SETTINGS::UNITS>( m_argParser.get<std::string>( ARG_UNITS ),
102 magic_enum::case_insensitive )
103 .value_or( IDF_SETTINGS::UNITS::MM );
104
105 idfJob->m_originMode = magic_enum::enum_cast<IDF_SETTINGS::COORD_ORIGIN>(
106 m_argParser.get<std::string>( ARG_ORIGIN ), magic_enum::case_insensitive )
108
109 idfJob->m_userOrigin.x = m_argParser.get<double>( ARG_USER_ORIGIN_X );
110 idfJob->m_userOrigin.y = m_argParser.get<double>( ARG_USER_ORIGIN_Y );
111
112 idfJob->m_includeUnspecified = !m_argParser.get<bool>( ARG_NO_UNSPECIFIED );
113 idfJob->m_includeDNP = !m_argParser.get<bool>( ARG_NO_DNP );
114 idfJob->m_calculateHeightFromModels = !m_argParser.get<bool>( ARG_EXPLICIT_HEIGHT );
115 idfJob->m_partNumberField = wxString::FromUTF8( m_argParser.get<std::string>( ARG_PART_NUMBER_FIELD ) );
116
117 return aKiway.ProcessJob( KIWAY::FACE_PCB, idfJob.get() );
118}
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
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
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
#define UTF8STDSTR(s)
Definition command.h:27
#define ARG_UNITS
#define ARG_NO_UNSPECIFIED
#define ARG_NO_DNP
#define ARG_USER_ORIGIN_Y
#define ARG_USER_ORIGIN_X
#define ARG_ORIGIN
#define ARG_PART_NUMBER_FIELD
#define ARG_EXPLICIT_HEIGHT
#define _(s)
static const int ERR_INVALID_INPUT_FILE
Definition exit_codes.h:33
PCB_EXPORT_BASE_COMMAND(const std::string &aName, IO_TYPE aInputType=IO_TYPE::FILE, IO_TYPE aOutputType=IO_TYPE::FILE)