KiCad PCB EDA Suite
Loading...
Searching...
No Matches
command_pcb_export_odb.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
21#include <cli/exit_codes.h>
23#include <kiface_base.h>
24#include <string_utils.h>
25#include <wx/crt.h>
26
27#include <macros.h>
28#include <locale_io.h>
29
30#define ARG_COMPRESS "--compression"
31#define ARG_VARIANT_PACKAGING "--variant-packaging"
32#define ARG_ORIGIN "--origin"
33#define ARG_PRODUCT_NAME "--product-name"
34
37{
41
42 m_argParser.add_description( std::string( "Export the PCB in ODB++ format" ) );
43
44 m_argParser.add_argument( ARG_COMPRESS )
45 .default_value( std::string( "zip" ) )
46 .help( std::string( "Compression mode" ) )
47 .choices( "none", "zip", "tgz" );
48
50 .default_value( std::string( "separate" ) )
51 .help( std::string( "Package variants separately or together" ) )
52 .choices( "separate", "combined" );
53
54 m_argParser.add_argument( ARG_ORIGIN )
55 .default_value( std::string( "absolute" ) )
56 .help( std::string( "Coordinate origin" ) )
57 .choices( "absolute", "aux", "grid" );
58
59 m_argParser.add_argument( ARG_PRODUCT_NAME )
60 .default_value( std::string() )
61 .help( std::string( "ODB++ product model name" ) )
62 .metavar( "NAME" );
63
64 addVariantsArg( false );
65}
66
67
69{
70 std::unique_ptr<JOB_EXPORT_PCB_ODB> job( new JOB_EXPORT_PCB_ODB() );
71
72 applyFabExportArgs( *job );
73 job->SetConfiguredOutputPath( m_argOutput );
74 job->SetVarOverrides( m_argDefineVars );
75
76 if( !wxFile::Exists( job->m_filename ) )
77 {
78 wxFprintf( stderr, _( "Board file does not exist or is not accessible\n" ) );
80 }
81
82 wxString compression = From_UTF8( m_argParser.get<std::string>( ARG_COMPRESS ).c_str() ).Lower();
83
84 if( compression == "zip" )
85 job->m_compressionMode = JOB_EXPORT_PCB_ODB::ODB_COMPRESSION::ZIP;
86 else if( compression == "tgz" )
87 job->m_compressionMode = JOB_EXPORT_PCB_ODB::ODB_COMPRESSION::TGZ;
88 else if( compression == "none" )
89 job->m_compressionMode = JOB_EXPORT_PCB_ODB::ODB_COMPRESSION::NONE;
90
91 if( m_argParser.get<std::string>( ARG_VARIANT_PACKAGING ) == "combined" )
93
94 std::string origin = m_argParser.get<std::string>( ARG_ORIGIN );
95
96 if( origin == "aux" )
97 job->m_origin = JOB_EXPORT_PCB_ODB::ORIGIN::AUX;
98 else if( origin == "grid" )
100
101 job->m_productName = From_UTF8( m_argParser.get<std::string>( ARG_PRODUCT_NAME ).c_str() );
102
104 return aKiway.ProcessJob( KIWAY::FACE_PCB, job.get() );
105}
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_ORIGIN
#define ARG_COMPRESS
#define ARG_VARIANT_PACKAGING
#define ARG_PRODUCT_NAME
#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