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 The 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 <string_utils.h>
26#include <wx/crt.h>
27
28#include <macros.h>
29#include <locale_io.h>
30
31#define ARG_USE_CONTOURS "--use-contours"
32#define ARG_OUTPUT_UNITS "--output-units"
33#define ARG_USE_DRILL_ORIGIN "--use-drill-origin"
34#define ARG_MODE_SINGLE "--mode-single"
35#define ARG_MODE_MULTI "--mode-multi"
36
38 PCB_EXPORT_BASE_COMMAND( "dxf", false, true )
39{
40 m_argParser.add_description( UTF8STDSTR( _( "Generate a DXF from a list of layers" ) ) );
41
46
47 m_argParser.add_argument( "--erd", ARG_EXCLUDE_REFDES )
48 .help( UTF8STDSTR( _( "Exclude the reference designator text" ) ) )
49 .flag();
50
51 m_argParser.add_argument( "--ev", ARG_EXCLUDE_VALUE )
52 .help( UTF8STDSTR( _( "Exclude the value text" ) ) )
53 .flag();
54
55 m_argParser.add_argument( "--sp", ARG_SKETCH_PADS_ON_FAB_LAYERS )
57 .flag();
58
59 m_argParser.add_argument( "--hdnp", ARG_HIDE_DNP_FPS_ON_FAB_LAYERS )
61 .flag();
62
63 m_argParser.add_argument( "--sdnp", ARG_SKETCH_DNP_FPS_ON_FAB_LAYERS )
65 .flag();
66
67 m_argParser.add_argument( "--cdnp", ARG_CROSSOUT_DNP_FPS_ON_FAB_LAYERS )
69 .flag();
70
72 .help( UTF8STDSTR( _( "Subtract soldermask from silkscreen" ) ) )
73 .flag();
74
75 m_argParser.add_argument( "--uc", ARG_USE_CONTOURS )
76 .help( UTF8STDSTR( _( "Plot graphic items using their contours" ) ) )
77 .flag();
78
79 m_argParser.add_argument( "--udo", ARG_USE_DRILL_ORIGIN )
80 .help( UTF8STDSTR( _( "Plot using the drill/place file origin" ) ) )
81 .flag();
82
83 m_argParser.add_argument( "--ibt", ARG_INCLUDE_BORDER_TITLE )
84 .help( UTF8STDSTR( _( "Include the border and title block" ) ) )
85 .flag();
86
87 m_argParser.add_argument( "--ou", ARG_OUTPUT_UNITS )
88 .default_value( std::string( "in" ) )
89 .help( UTF8STDSTR( _( "Output units, valid options: mm, in" ) ) )
90 .metavar( "UNITS" );
91
94 .scan<'i', int>()
95 .default_value( 2 );
96
97 m_argParser.add_argument( ARG_MODE_SINGLE )
98 .help( UTF8STDSTR(
99 _( "Generates a single file with the output arg path acting as the complete "
100 "directory and filename path. COMMON_LAYER_LIST does not function in this "
101 "mode. Instead LAYER_LIST controls all layers plotted." ) ) )
102 .flag();
103
104 m_argParser.add_argument( ARG_MODE_MULTI )
105 .help( UTF8STDSTR( _( "Generates one or more files with behavior similar to the KiCad "
106 "GUI plotting. The given output path specifies a directory in "
107 "which files may be output." ) ) )
108 .flag();
109
112 .flag();
113}
114
115
117{
118 std::unique_ptr<JOB_EXPORT_PCB_DXF> dxfJob( new JOB_EXPORT_PCB_DXF() );
119
120 dxfJob->m_filename = m_argInput;
121 dxfJob->SetConfiguredOutputPath( m_argOutput );
122 dxfJob->m_drawingSheet = m_argDrawingSheet;
123 dxfJob->m_sketchPadsOnFabLayers = m_argParser.get<bool>( ARG_SKETCH_PADS_ON_FAB_LAYERS );
124 dxfJob->m_hideDNPFPsOnFabLayers = m_argParser.get<bool>( ARG_HIDE_DNP_FPS_ON_FAB_LAYERS );
125 dxfJob->m_sketchDNPFPsOnFabLayers = m_argParser.get<bool>( ARG_SKETCH_DNP_FPS_ON_FAB_LAYERS );
126 dxfJob->m_crossoutDNPFPsOnFabLayers = m_argParser.get<bool>( ARG_CROSSOUT_DNP_FPS_ON_FAB_LAYERS );
127 dxfJob->SetVarOverrides( m_argDefineVars );
128
129 if( !wxFile::Exists( dxfJob->m_filename ) )
130 {
131 wxFprintf( stderr, _( "Board file does not exist or is not accessible\n" ) );
133 }
134
135 dxfJob->m_plotFootprintValues = m_argParser.get<bool>( ARG_EXCLUDE_VALUE );
136 dxfJob->m_plotRefDes = !m_argParser.get<bool>( ARG_EXCLUDE_REFDES );
137 dxfJob->m_plotGraphicItemsUsingContours = m_argParser.get<bool>( ARG_USE_CONTOURS );
138 dxfJob->m_polygonMode = m_argParser.get<bool>( ARG_USE_CONTOURS );
139 dxfJob->m_useDrillOrigin = m_argParser.get<bool>( ARG_USE_DRILL_ORIGIN );
140 dxfJob->m_plotDrawingSheet = m_argParser.get<bool>( ARG_INCLUDE_BORDER_TITLE );
141 dxfJob->m_subtractSolderMaskFromSilk = m_argParser.get<bool>( ARG_SUBTRACT_SOLDERMASK );
142
143 if( m_argParser.get<bool>( DEPRECATED_ARG_PLOT_INVISIBLE_TEXT ) )
145
146 int drillShape = m_argParser.get<int>( ARG_DRILL_SHAPE_OPTION );
147 dxfJob->m_drillShapeOption = static_cast<DRILL_MARKS>( drillShape );
148
149 wxString units = From_UTF8( m_argParser.get<std::string>( ARG_OUTPUT_UNITS ).c_str() );
150
151 if( units == wxS( "mm" ) )
152 {
153 dxfJob->m_dxfUnits = JOB_EXPORT_PCB_DXF::DXF_UNITS::MM;
154 }
155 else if( units == wxS( "in" ) )
156 {
157 dxfJob->m_dxfUnits = JOB_EXPORT_PCB_DXF::DXF_UNITS::INCH;
158 }
159 else
160 {
161 wxFprintf( stderr, _( "Invalid units specified\n" ) );
163 }
164
165 dxfJob->m_argLayers = From_UTF8( m_argParser.get<std::string>( ARG_LAYERS ).c_str() );
166 dxfJob->m_argCommonLayers = From_UTF8( m_argParser.get<std::string>( ARG_COMMON_LAYERS ).c_str() );
167
168 if( m_argParser.get<bool>( ARG_MODE_MULTI ) )
169 dxfJob->m_genMode = JOB_EXPORT_PCB_DXF::GEN_MODE::MULTI;
170 else if( m_argParser.get<bool>( ARG_MODE_SINGLE ) )
171 dxfJob->m_genMode = JOB_EXPORT_PCB_DXF::GEN_MODE::SINGLE;
172 else
173 {
174 wxFprintf( stdout, wxT( "\033[33;1m%s\033[0m\n" ),
175 _( "This command has deprecated behavior as of KiCad 9.0, the default behavior "
176 "of this command will change in a future release." ) );
177
178 wxFprintf( stdout, wxT( "\033[33;1m%s\033[0m\n" ),
179 _( "The new behavior will match --mode-multi" ) );
180 }
181
182
183 LOCALE_IO dummy; // Switch to "C" locale
184 return aKiway.ProcessJob( KIWAY::FACE_PCB, dxfJob.get() );
185}
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:168
void addDrawingSheetArg()
Set up the drawing sheet arg used by many of the export commands.
Definition: command.cpp:156
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:285
@ FACE_PCB
pcbnew DSO
Definition: kiway.h:293
int ProcessJob(KIWAY::FACE_T aFace, JOB *aJob, REPORTER *aReporter=nullptr)
Definition: kiway.cpp:711
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_SKETCH_PADS_ON_FAB_LAYERS_DESC
#define ARG_INCLUDE_BORDER_TITLE
#define ARG_CROSSOUT_DNP_FPS_ON_FAB_LAYERS_DESC
#define ARG_SKETCH_PADS_ON_FAB_LAYERS
#define ARG_COMMON_LAYERS
#define ARG_SKETCH_DNP_FPS_ON_FAB_LAYERS_DESC
#define ARG_EXCLUDE_REFDES
#define ARG_EXCLUDE_VALUE
#define ARG_CROSSOUT_DNP_FPS_ON_FAB_LAYERS
#define DEPRECATED_ARG_PLOT_INVISIBLE_TEXT
#define ARG_HIDE_DNP_FPS_ON_FAB_LAYERS
#define DEPRECATED_ARD_PLOT_INVISIBLE_TEXT_WARNING
#define ARG_SUBTRACT_SOLDERMASK
#define ARG_DRILL_SHAPE_OPTION_DESC
#define ARG_USE_DRILL_ORIGIN
#define DEPRECATED_ARG_PLOT_INVISIBLE_TEXT_DESC
#define ARG_LAYERS
#define ARG_HIDE_DNP_FPS_ON_FAB_LAYERS_DESC
#define ARG_SKETCH_DNP_FPS_ON_FAB_LAYERS
#define ARG_DRILL_SHAPE_OPTION
#define ARG_MODE_MULTI
#define ARG_MODE_SINGLE
#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 ERR_INVALID_INPUT_FILE
Definition: exit_codes.h:33
DRILL_MARKS
Plots and prints can show holes in pads and vias 3 options are available:
std::vector< FAB_LAYER_COLOR > dummy
wxString From_UTF8(const char *cstring)