KiCad PCB EDA Suite
command_export_pcb_dxf.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 <layer_ids.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_USE_CONTOURS "--use-contours"
34#define ARG_OUTPUT_UNITS "--output-units"
35
37{
38 addLayerArg( true );
39
40 m_argParser.add_argument( "--erd", ARG_EXCLUDE_REFDES )
41 .help( UTF8STDSTR( _( "Exclude the reference designator text" ) ) )
42 .implicit_value( true )
43 .default_value( false );
44
45 m_argParser.add_argument( "--ev", ARG_EXCLUDE_VALUE )
46 .help( UTF8STDSTR( _( "Exclude the value text" ) ) )
47 .implicit_value( true )
48 .default_value( false );
49
50 m_argParser.add_argument( "--uc", ARG_USE_CONTOURS )
51 .help( UTF8STDSTR( _( "Plot graphic items using their contours" ) ) )
52 .implicit_value( true )
53 .default_value( false );
54
55 m_argParser.add_argument( "--ou", ARG_OUTPUT_UNITS )
56 .default_value( std::string( "in" ) )
57 .help( UTF8STDSTR( _( "Output units, valid options: mm, in" ) ) );
58}
59
60
62{
63 int baseExit = EXPORT_PCB_BASE_COMMAND::doPerform( aKiway );
64 if( baseExit != EXIT_CODES::OK )
65 return baseExit;
66
67 std::unique_ptr<JOB_EXPORT_PCB_DXF> dxfJob( new JOB_EXPORT_PCB_DXF( true ) );
68
69 dxfJob->m_filename = FROM_UTF8( m_argParser.get<std::string>( ARG_INPUT ).c_str() );
70 dxfJob->m_outputFile = FROM_UTF8( m_argParser.get<std::string>( ARG_OUTPUT ).c_str() );
71
72 if( !wxFile::Exists( dxfJob->m_filename ) )
73 {
74 wxFprintf( stderr, _( "Board file does not exist or is not accessible\n" ) );
76 }
77
78 dxfJob->m_plotFootprintValues = m_argParser.get<bool>( ARG_EXCLUDE_VALUE );
79 dxfJob->m_plotRefDes = !m_argParser.get<bool>( ARG_EXCLUDE_REFDES );
80 dxfJob->m_plotGraphicItemsUsingContours = m_argParser.get<bool>( ARG_USE_CONTOURS );
81
82 wxString units = FROM_UTF8( m_argParser.get<std::string>( ARG_OUTPUT_UNITS ).c_str() );
83
84 if( units == wxS( "mm" ) )
85 {
87 }
88 else if( units == wxS( "in" ) )
89 {
90 dxfJob->m_dxfUnits = JOB_EXPORT_PCB_DXF::DXF_UNITS::INCHES;
91 }
92 else
93 {
94 wxFprintf( stderr, _( "Invalid units specified\n" ) );
96 }
97
98 dxfJob->m_printMaskLayer = m_selectedLayers;
99
100 LOCALE_IO dummy; // Switch to "C" locale
101 int exitCode = aKiway.ProcessJob( KIWAY::FACE_PCB, dxfJob.get() );
102
103 return exitCode;
104}
argparse::ArgumentParser m_argParser
Definition: command.h:68
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:279
int ProcessJob(KIWAY::FACE_T aFace, JOB *job)
Definition: kiway.cpp:660
@ FACE_PCB
pcbnew DSO
Definition: kiway.h:287
Instantiate the current locale within a scope in which you are expecting exceptions to be thrown.
Definition: locale_io.h:41
#define UTF8STDSTR(s)
Definition: command.h:27
#define ARG_OUTPUT
#define ARG_INPUT
#define ARG_EXCLUDE_REFDES
#define ARG_EXCLUDE_VALUE
#define ARG_USE_CONTOURS
#define ARG_OUTPUT_UNITS
#define _(s)
This file contains miscellaneous commonly used macros and functions.
static wxString FROM_UTF8(const char *cstring)
Convert a UTF8 encoded C string to a wxString for all wxWidgets build modes.
Definition: macros.h:110
static const int ERR_ARGS
Definition: exit_codes.h:31
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
int doPerform(KIWAY &aKiway) override
The internal handler that should be overloaded to implement command specific processing and work.