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 <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#define ARG_MODE_SINGLE "--mode-single"
38#define ARG_MODE_MULTI "--mode-multi"
39
41{
42 m_argParser.add_description( UTF8STDSTR( _( "Generate a DXF from a list of layers" ) ) );
43
44 addLayerArg( true );
47
48 m_argParser.add_argument( "--erd", ARG_EXCLUDE_REFDES )
49 .help( UTF8STDSTR( _( "Exclude the reference designator text" ) ) )
50 .flag();
51
52 m_argParser.add_argument( "--ev", ARG_EXCLUDE_VALUE )
53 .help( UTF8STDSTR( _( "Exclude the value text" ) ) )
54 .flag();
55
56 m_argParser.add_argument( "--uc", ARG_USE_CONTOURS )
57 .help( UTF8STDSTR( _( "Plot graphic items using their contours" ) ) )
58 .flag();
59
60 m_argParser.add_argument( "--udo", ARG_USE_DRILL_ORIGIN )
61 .help( UTF8STDSTR( _( "Plot using the drill/place file origin" ) ) )
62 .flag();
63
64 m_argParser.add_argument( "--ibt", ARG_INCLUDE_BORDER_TITLE )
65 .help( UTF8STDSTR( _( "Include the border and title block" ) ) )
66 .flag();
67
68 m_argParser.add_argument( "--ou", ARG_OUTPUT_UNITS )
69 .default_value( std::string( "in" ) )
70 .help( UTF8STDSTR( _( "Output units, valid options: mm, in" ) ) )
71 .metavar( "UNITS" );
72
75 .scan<'i', int>()
76 .default_value( 2 );
77
78 m_argParser.add_argument( "--cl", ARG_COMMON_LAYERS )
79 .default_value( std::string() )
80 .help( UTF8STDSTR(
81 _( "Layers to include on each plot, comma separated list of untranslated "
82 "layer names to include such as "
83 "F.Cu,B.Cu" ) ) )
84 .metavar( "COMMON_LAYER_LIST" );
85
86 m_argParser.add_argument( ARG_MODE_SINGLE )
87 .help( UTF8STDSTR(
88 _( "Generates a single file with the output arg path acting as the complete "
89 "directory and filename path. COMMON_LAYER_LIST does not function in this "
90 "mode. Instead LAYER_LIST controls all layers plotted." ) ) )
91 .flag();
92
93 m_argParser.add_argument( ARG_MODE_MULTI )
94 .help( UTF8STDSTR( _( "Generates one or more files with behavior similar to the KiCad "
95 "GUI plotting. The given output path specifies a directory in "
96 "which files may be output." ) ) )
97 .flag();
98
101 .flag();
102}
103
104
106{
107 int baseExit = PCB_EXPORT_BASE_COMMAND::doPerform( aKiway );
108 if( baseExit != EXIT_CODES::OK )
109 return baseExit;
110
111 std::unique_ptr<JOB_EXPORT_PCB_DXF> dxfJob( new JOB_EXPORT_PCB_DXF() );
112
113 dxfJob->m_filename = m_argInput;
114 dxfJob->SetConfiguredOutputPath( m_argOutput );
115 dxfJob->m_drawingSheet = m_argDrawingSheet;
116 dxfJob->SetVarOverrides( m_argDefineVars );
117
118 if( !wxFile::Exists( dxfJob->m_filename ) )
119 {
120 wxFprintf( stderr, _( "Board file does not exist or is not accessible\n" ) );
122 }
123
124 dxfJob->m_plotFootprintValues = m_argParser.get<bool>( ARG_EXCLUDE_VALUE );
125 dxfJob->m_plotRefDes = !m_argParser.get<bool>( ARG_EXCLUDE_REFDES );
126 dxfJob->m_plotGraphicItemsUsingContours = m_argParser.get<bool>( ARG_USE_CONTOURS );
127 dxfJob->m_useDrillOrigin = m_argParser.get<bool>( ARG_USE_DRILL_ORIGIN );
128 dxfJob->m_plotDrawingSheet = m_argParser.get<bool>( ARG_INCLUDE_BORDER_TITLE );
129 dxfJob->m_plotInvisibleText = m_argParser.get<bool>( ARG_PLOT_INVISIBLE_TEXT );
130
131 int drillShape = m_argParser.get<int>( ARG_DRILL_SHAPE_OPTION );
132 dxfJob->m_drillShapeOption = static_cast<JOB_EXPORT_PCB_DXF::DRILL_MARKS>( drillShape );
133
134 wxString units = From_UTF8( m_argParser.get<std::string>( ARG_OUTPUT_UNITS ).c_str() );
135
136 if( units == wxS( "mm" ) )
137 {
139 }
140 else if( units == wxS( "in" ) )
141 {
142 dxfJob->m_dxfUnits = JOB_EXPORT_PCB_DXF::DXF_UNITS::INCHES;
143 }
144 else
145 {
146 wxFprintf( stderr, _( "Invalid units specified\n" ) );
148 }
149
150 dxfJob->m_printMaskLayer = m_selectedLayers;
151
152 wxString layers = From_UTF8( m_argParser.get<std::string>( ARG_COMMON_LAYERS ).c_str() );
153 bool blah = false;
154 dxfJob->m_printMaskLayersToIncludeOnAllLayers = convertLayerStringList( layers, blah );
155
156 if( m_argParser.get<bool>( ARG_MODE_MULTI ) )
157 dxfJob->m_genMode = JOB_EXPORT_PCB_DXF::GEN_MODE::MULTI;
158 else if( m_argParser.get<bool>( ARG_MODE_SINGLE ) )
159 dxfJob->m_genMode = JOB_EXPORT_PCB_DXF::GEN_MODE::SINGLE;
160 else
161 {
162 wxFprintf( stdout, wxT( "\033[33;1m%s\033[0m\n" ),
163 _( "This command has deprecated behavior as of KiCad 9.0, the default behavior "
164 "of this command will change in a future release." ) );
165
166 wxFprintf( stdout, wxT( "\033[33;1m%s\033[0m\n" ),
167 _( "The new behavior will match --mode-multi" ) );
168 }
169
170
171 LOCALE_IO dummy; // Switch to "C" locale
172 int exitCode = aKiway.ProcessJob( KIWAY::FACE_PCB, dxfJob.get() );
173
174 return exitCode;
175}
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: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_INCLUDE_BORDER_TITLE
#define ARG_COMMON_LAYERS
#define ARG_EXCLUDE_REFDES
#define ARG_PLOT_INVISIBLE_TEXT_DESC
#define ARG_PLOT_INVISIBLE_TEXT
#define ARG_EXCLUDE_VALUE
#define ARG_DRILL_SHAPE_OPTION_DESC
#define ARG_USE_DRILL_ORIGIN
#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 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.