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
30#define ARG_USE_CONTOURS "--use-contours"
31#define ARG_OUTPUT_UNITS "--output-units"
32#define ARG_USE_DRILL_ORIGIN "--use-drill-origin"
33#define ARG_MODE_SINGLE "--mode-single"
34#define ARG_MODE_MULTI "--mode-multi"
35
37 PCB_EXPORT_BASE_COMMAND( "dxf", false, true )
38{
39 m_argParser.add_description( UTF8STDSTR( _( "Generate a DXF from a list of layers" ) ) );
40
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( "--sp", ARG_SKETCH_PADS_ON_FAB_LAYERS )
56 .flag();
57
58 m_argParser.add_argument( "--hdnp", ARG_HIDE_DNP_FPS_ON_FAB_LAYERS )
60 .flag();
61
62 m_argParser.add_argument( "--sdnp", ARG_SKETCH_DNP_FPS_ON_FAB_LAYERS )
64 .flag();
65
66 m_argParser.add_argument( "--cdnp", ARG_CROSSOUT_DNP_FPS_ON_FAB_LAYERS )
68 .flag();
69
71 .help( UTF8STDSTR( _( "Subtract soldermask from silkscreen" ) ) )
72 .flag();
73
74 m_argParser.add_argument( "--uc", ARG_USE_CONTOURS )
75 .help( UTF8STDSTR( _( "Plot graphic items using their contours" ) ) )
76 .flag();
77
78 m_argParser.add_argument( "--udo", ARG_USE_DRILL_ORIGIN )
79 .help( UTF8STDSTR( _( "Plot using the drill/place file origin" ) ) )
80 .flag();
81
82 m_argParser.add_argument( "--ibt", ARG_INCLUDE_BORDER_TITLE )
83 .help( UTF8STDSTR( _( "Include the border and title block" ) ) )
84 .flag();
85
86 m_argParser.add_argument( "--ou", ARG_OUTPUT_UNITS )
87 .default_value( std::string( "in" ) )
88 .help( UTF8STDSTR( _( "Output units, valid options: mm, in" ) ) )
89 .metavar( "UNITS" );
90
93 .scan<'i', int>()
94 .default_value( 2 );
95
96 m_argParser.add_argument( ARG_MODE_SINGLE )
97 .help( UTF8STDSTR(
98 _( "Generates a single file with the output arg path acting as the complete "
99 "directory and filename path. COMMON_LAYER_LIST does not function in this "
100 "mode. Instead LAYER_LIST controls all layers plotted." ) ) )
101 .flag();
102
103 m_argParser.add_argument( ARG_MODE_MULTI )
104 .help( UTF8STDSTR( _( "Generates one or more files with behavior similar to the KiCad "
105 "GUI plotting. The given output path specifies a directory in "
106 "which files may be output." ) ) )
107 .flag();
108
111 .flag();
112
113 m_argParser.add_argument( ARG_SCALE )
114 .help( UTF8STDSTR( _( ARG_SCALE_DESC ) ) )
115 .scan<'g', double>()
116 .default_value( 1.0 )
117 .metavar( "SCALE" );
118
119 m_argParser.add_argument( ARG_CHECK_ZONES )
120 .help( UTF8STDSTR( _( ARG_CHECK_ZONES_DESC ) ) )
121 .flag();
122}
123
124
126{
127 std::unique_ptr<JOB_EXPORT_PCB_DXF> dxfJob( new JOB_EXPORT_PCB_DXF() );
128
129 dxfJob->m_filename = m_argInput;
130 dxfJob->SetConfiguredOutputPath( m_argOutput );
131 dxfJob->m_drawingSheet = m_argDrawingSheet;
132 dxfJob->m_sketchPadsOnFabLayers = m_argParser.get<bool>( ARG_SKETCH_PADS_ON_FAB_LAYERS );
133 dxfJob->m_hideDNPFPsOnFabLayers = m_argParser.get<bool>( ARG_HIDE_DNP_FPS_ON_FAB_LAYERS );
134 dxfJob->m_sketchDNPFPsOnFabLayers = m_argParser.get<bool>( ARG_SKETCH_DNP_FPS_ON_FAB_LAYERS );
135 dxfJob->m_crossoutDNPFPsOnFabLayers = m_argParser.get<bool>( ARG_CROSSOUT_DNP_FPS_ON_FAB_LAYERS );
136 dxfJob->SetVarOverrides( m_argDefineVars );
137
138 if( !wxFile::Exists( dxfJob->m_filename ) )
139 {
140 wxFprintf( stderr, _( "Board file does not exist or is not accessible\n" ) );
142 }
143
144 dxfJob->m_plotFootprintValues = m_argParser.get<bool>( ARG_EXCLUDE_VALUE );
145 dxfJob->m_plotRefDes = !m_argParser.get<bool>( ARG_EXCLUDE_REFDES );
146 dxfJob->m_plotGraphicItemsUsingContours = m_argParser.get<bool>( ARG_USE_CONTOURS );
147 dxfJob->m_polygonMode = m_argParser.get<bool>( ARG_USE_CONTOURS );
148 dxfJob->m_useDrillOrigin = m_argParser.get<bool>( ARG_USE_DRILL_ORIGIN );
149 dxfJob->m_plotDrawingSheet = m_argParser.get<bool>( ARG_INCLUDE_BORDER_TITLE );
150 dxfJob->m_subtractSolderMaskFromSilk = m_argParser.get<bool>( ARG_SUBTRACT_SOLDERMASK );
151 dxfJob->m_scale = m_argParser.get<double>( ARG_SCALE );
152 dxfJob->m_checkZonesBeforePlot = m_argParser.get<bool>( ARG_CHECK_ZONES );
153
156
157 int drillShape = m_argParser.get<int>( ARG_DRILL_SHAPE_OPTION );
158 dxfJob->m_drillShapeOption = static_cast<DRILL_MARKS>( drillShape );
159
160 wxString units = From_UTF8( m_argParser.get<std::string>( ARG_OUTPUT_UNITS ).c_str() );
161
162 if( units == wxS( "mm" ) )
163 {
164 dxfJob->m_dxfUnits = JOB_EXPORT_PCB_DXF::DXF_UNITS::MM;
165 }
166 else if( units == wxS( "in" ) )
167 {
168 dxfJob->m_dxfUnits = JOB_EXPORT_PCB_DXF::DXF_UNITS::INCH;
169 }
170 else
171 {
172 wxFprintf( stderr, _( "Invalid units specified\n" ) );
174 }
175
176 dxfJob->m_argLayers = From_UTF8( m_argParser.get<std::string>( ARG_LAYERS ).c_str() );
177 dxfJob->m_argCommonLayers = From_UTF8( m_argParser.get<std::string>( ARG_COMMON_LAYERS ).c_str() );
178
179 if( m_argParser.get<bool>( ARG_MODE_MULTI ) )
180 dxfJob->m_genMode = JOB_EXPORT_PCB_DXF::GEN_MODE::MULTI;
181 else if( m_argParser.get<bool>( ARG_MODE_SINGLE ) )
182 dxfJob->m_genMode = JOB_EXPORT_PCB_DXF::GEN_MODE::SINGLE;
183 else
184 {
185 wxFprintf( stdout, wxT( "\033[33;1m%s\033[0m\n" ),
186 _( "This command has deprecated behavior as of KiCad 9.0, the default behavior "
187 "of this command will change in a future release." ) );
188
189 wxFprintf( stdout, wxT( "\033[33;1m%s\033[0m\n" ),
190 _( "The new behavior will match --mode-multi" ) );
191 }
192
193 return aKiway.ProcessJob( KIWAY::FACE_PCB, dxfJob.get() );
194}
std::map< wxString, wxString > m_argDefineVars
Value of the drawing sheet arg if configured.
Definition command.h:145
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
wxString m_argDrawingSheet
Value of the drawing sheet arg if configured.
Definition command.h:140
wxString m_argOutput
Value of the output arg if configured.
Definition command.h:135
wxString m_argInput
Value of the common input arg if configured.
Definition command.h:130
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:286
int ProcessJob(KIWAY::FACE_T aFace, JOB *aJob, REPORTER *aReporter=nullptr, PROGRESS_REPORTER *aProgressReporter=nullptr)
Definition kiway.cpp:701
@ FACE_PCB
pcbnew DSO
Definition kiway.h:294
#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_CHECK_ZONES_DESC
#define ARG_SKETCH_PADS_ON_FAB_LAYERS
#define ARG_COMMON_LAYERS
#define ARG_SCALE_DESC
#define ARG_SCALE
#define ARG_SKETCH_DNP_FPS_ON_FAB_LAYERS_DESC
#define ARG_EXCLUDE_REFDES
#define ARG_CHECK_ZONES
#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_ARG_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:
wxString From_UTF8(const char *cstring)
PCB_EXPORT_BASE_COMMAND(const std::string &aName, bool aInputCanBeDir=false, bool aOutputIsDir=false)