KiCad PCB EDA Suite
Loading...
Searching...
No Matches
command_pcb_export_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-2024 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 <string_utils.h>
27#include <wx/crt.h>
28
29#include <macros.h>
30#include <wx/tokenzr.h>
31
32#include <locale_io.h>
33
34#define ARG_USE_CONTOURS "--use-contours"
35#define ARG_OUTPUT_UNITS "--output-units"
36#define ARG_USE_DRILL_ORIGIN "--use-drill-origin"
37
39{
40 m_argParser.add_description( UTF8STDSTR( _( "Generate a DXF from a list of layers" ) ) );
41
42 addLayerArg( true );
45
46 m_argParser.add_argument( "--erd", ARG_EXCLUDE_REFDES )
47 .help( UTF8STDSTR( _( "Exclude the reference designator text" ) ) )
48 .flag();
49
50 m_argParser.add_argument( "--ev", ARG_EXCLUDE_VALUE )
51 .help( UTF8STDSTR( _( "Exclude the value text" ) ) )
52 .flag();
53
54 m_argParser.add_argument( "--uc", ARG_USE_CONTOURS )
55 .help( UTF8STDSTR( _( "Plot graphic items using their contours" ) ) )
56 .flag();
57
58 m_argParser.add_argument( "--udo", ARG_USE_DRILL_ORIGIN )
59 .help( UTF8STDSTR( _( "Plot using the drill/place file origin" ) ) )
60 .flag();
61
62 m_argParser.add_argument( "--ibt", ARG_INCLUDE_BORDER_TITLE )
63 .help( UTF8STDSTR( _( "Include the border and title block" ) ) )
64 .flag();
65
66 m_argParser.add_argument( "--ou", ARG_OUTPUT_UNITS )
67 .default_value( std::string( "in" ) )
68 .help( UTF8STDSTR( _( "Output units, valid options: mm, in" ) ) )
69 .metavar( "UNITS" );
70}
71
72
74{
75 int baseExit = PCB_EXPORT_BASE_COMMAND::doPerform( aKiway );
76 if( baseExit != EXIT_CODES::OK )
77 return baseExit;
78
79 std::unique_ptr<JOB_EXPORT_PCB_DXF> dxfJob( new JOB_EXPORT_PCB_DXF() );
80
81 dxfJob->m_filename = m_argInput;
82 dxfJob->SetOutputPath( m_argOutput );
83 dxfJob->m_drawingSheet = m_argDrawingSheet;
84 dxfJob->SetVarOverrides( m_argDefineVars );
85
86 if( !wxFile::Exists( dxfJob->m_filename ) )
87 {
88 wxFprintf( stderr, _( "Board file does not exist or is not accessible\n" ) );
90 }
91
92 dxfJob->m_plotFootprintValues = m_argParser.get<bool>( ARG_EXCLUDE_VALUE );
93 dxfJob->m_plotRefDes = !m_argParser.get<bool>( ARG_EXCLUDE_REFDES );
94 dxfJob->m_plotGraphicItemsUsingContours = m_argParser.get<bool>( ARG_USE_CONTOURS );
95 dxfJob->m_useDrillOrigin = m_argParser.get<bool>( ARG_USE_DRILL_ORIGIN );
96 dxfJob->m_plotDrawingSheet = m_argParser.get<bool>( ARG_INCLUDE_BORDER_TITLE );
97
98 wxString units = From_UTF8( m_argParser.get<std::string>( ARG_OUTPUT_UNITS ).c_str() );
99
100 if( units == wxS( "mm" ) )
101 {
103 }
104 else if( units == wxS( "in" ) )
105 {
106 dxfJob->m_dxfUnits = JOB_EXPORT_PCB_DXF::DXF_UNITS::INCHES;
107 }
108 else
109 {
110 wxFprintf( stderr, _( "Invalid units specified\n" ) );
112 }
113
114 dxfJob->m_printMaskLayer = m_selectedLayers;
115
116 LOCALE_IO dummy; // Switch to "C" locale
117 int exitCode = aKiway.ProcessJob( KIWAY::FACE_PCB, dxfJob.get() );
118
119 return exitCode;
120}
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 UTF8STDSTR(s)
Definition: command.h:27
#define ARG_INCLUDE_BORDER_TITLE
#define ARG_EXCLUDE_REFDES
#define ARG_EXCLUDE_VALUE
#define ARG_USE_DRILL_ORIGIN
#define ARG_USE_CONTOURS
#define ARG_OUTPUT_UNITS
#define _(s)
This file contains miscellaneous commonly used macros and functions.
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
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.