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 (C) 1992-2024 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 along
17 * with this program. If not, see <http://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 <wx/tokenzr.h>
29
30#include <locale_io.h>
31
32#define ARG_COMPRESS "--compression"
33#define ARG_UNITS "--units"
34
37{
40
41 m_argParser.add_description( std::string( "Export the PCB in ODB++ format" ) );
42
43 m_argParser.add_argument( ARG_PRECISION )
44 .help( std::string( "Precision" ) )
45 .scan<'i', int>()
46 .default_value( 2 )
47 .metavar( "PRECISION" );
48
49 m_argParser.add_argument( ARG_COMPRESS )
50 .default_value( std::string( "zip" ) )
51 .help( std::string( "Compression mode" ) )
52 .choices( "none", "zip" );
53
54 m_argParser.add_argument( ARG_UNITS )
55 .default_value( std::string( "mm" ) )
56 .help( std::string( "Units" ) )
57 .choices( "mm", "in" );
58}
59
60
62{
63 int exitCode = PCB_EXPORT_BASE_COMMAND::doPerform( aKiway );
64
65 if( exitCode != EXIT_CODES::OK )
66 return exitCode;
67
68 std::unique_ptr<JOB_EXPORT_PCB_ODB> job( new JOB_EXPORT_PCB_ODB() );
69
70 job->m_filename = m_argInput;
71 job->SetOutputPath( m_argOutput );
72 job->m_drawingSheet = m_argDrawingSheet;
73 job->SetVarOverrides( m_argDefineVars );
74
75 if( !wxFile::Exists( job->m_filename ) )
76 {
77 wxFprintf( stderr, _( "Board file does not exist or is not accessible\n" ) );
79 }
80
81 job->m_precision = m_argParser.get<int>( ARG_PRECISION );
82
83 wxString units = From_UTF8( m_argParser.get<std::string>( ARG_UNITS ).c_str() );
84
85 if( units == "mm" )
87 else if( units == "in" )
89
90 wxString compression = From_UTF8( m_argParser.get<std::string>( ARG_COMPRESS ).c_str() );
91
92 if( compression == "zip" )
93 job->m_compressionMode = JOB_EXPORT_PCB_ODB::ODB_COMPRESSION::ZIP;
94 else
95 job->m_compressionMode = JOB_EXPORT_PCB_ODB::ODB_COMPRESSION::NONE;
96
98 exitCode = aKiway.ProcessJob( KIWAY::FACE_PCB, job.get() );
99
100 return exitCode;
101}
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_UNITS
#define ARG_PRECISION
#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.