KiCad PCB EDA Suite
Loading...
Searching...
No Matches
command_pcb_export_stackup.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) 2026 Krishna Swaroop <[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
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
19 */
20
22
23#include <cli/exit_codes.h>
25#include <string_utils.h>
26#include <wx/crt.h>
27
28#define ARG_FORMAT "--format"
29#define ARG_UNITS "--units"
30#define ARG_EXCLUDE_COLOR "--exclude-color"
31#define ARG_EXCLUDE_MATERIAL "--exclude-material"
32#define ARG_EXCLUDE_THICKNESS "--exclude-thickness"
33#define ARG_EXCLUDE_EPSILON_R "--exclude-epsilon-r"
34#define ARG_EXCLUDE_LOSS_TANGENT "--exclude-loss-tangent"
35#define ARG_EXCLUDE_FINISH "--exclude-finish"
36#define ARG_EXCLUDE_BOARD_OPTIONS "--exclude-board-options"
37
40{
41 m_argParser.add_description( UTF8STDSTR( _( "Export a board stackup report" ) ) );
42
43 m_argParser.add_argument( ARG_FORMAT )
44 .default_value( std::string( "csv" ) )
45 .help( UTF8STDSTR( _( "Output file format; valid options: csv, json" ) ) )
46 .metavar( "FORMAT" );
47
48 m_argParser.add_argument( ARG_UNITS )
49 .default_value( std::string( "mm" ) )
50 .help( UTF8STDSTR( _( "CSV units; valid options: in, mm" ) ) )
51 .metavar( "UNITS" );
52
53 m_argParser.add_argument( ARG_EXCLUDE_COLOR ).help( UTF8STDSTR( _( "Omit color from the CSV export" ) ) ).flag();
54
55 m_argParser.add_argument( ARG_EXCLUDE_MATERIAL )
56 .help( UTF8STDSTR( _( "Omit material from the CSV export" ) ) )
57 .flag();
58
60 .help( UTF8STDSTR( _( "Omit thickness from the CSV export" ) ) )
61 .flag();
62
64 .help( UTF8STDSTR( _( "Omit Epsilon R from the CSV export" ) ) )
65 .flag();
66
68 .help( UTF8STDSTR( _( "Omit loss tangent from the CSV export" ) ) )
69 .flag();
70
71 m_argParser.add_argument( ARG_EXCLUDE_FINISH )
72 .help( UTF8STDSTR( _( "Omit board finish from the CSV export" ) ) )
73 .flag();
74
76 .help( UTF8STDSTR( _( "Omit board options from the CSV export" ) ) )
77 .flag();
78}
79
80
82{
83 std::unique_ptr<JOB_EXPORT_PCB_STACKUP> stackupJob( new JOB_EXPORT_PCB_STACKUP() );
84
85 stackupJob->m_filename = m_argInput;
86
87 if( !wxFile::Exists( stackupJob->m_filename ) )
88 {
89 wxFprintf( stderr, _( "Board file does not exist or is not accessible\n" ) );
91 }
92
93 wxString format = From_UTF8( m_argParser.get<std::string>( ARG_FORMAT ).c_str() );
94
95 if( format == "json" )
96 {
98 }
99 else if( format == "csv" )
100 {
101 stackupJob->m_format = JOB_EXPORT_PCB_STACKUP::OUTPUT_FORMAT::CSV;
102 }
103 else
104 {
105 wxFprintf( stderr, _( "Invalid format\n" ) );
107 }
108
109 wxString units = From_UTF8( m_argParser.get<std::string>( ARG_UNITS ).c_str() );
110
111 if( units == wxS( "mm" ) )
112 {
113 stackupJob->m_units = JOB_EXPORT_PCB_STACKUP::UNITS::MM;
114 }
115 else if( units == wxS( "in" ) || units == wxS( "inch" ) )
116 {
117 stackupJob->m_units = JOB_EXPORT_PCB_STACKUP::UNITS::INCH;
118 }
119 else
120 {
121 wxFprintf( stderr, _( "Invalid units specified\n" ) );
123 }
124
125 stackupJob->m_includeColor = !m_argParser.get<bool>( ARG_EXCLUDE_COLOR );
126 stackupJob->m_includeMaterial = !m_argParser.get<bool>( ARG_EXCLUDE_MATERIAL );
127 stackupJob->m_includeThickness = !m_argParser.get<bool>( ARG_EXCLUDE_THICKNESS );
128 stackupJob->m_includeEpsilonR = !m_argParser.get<bool>( ARG_EXCLUDE_EPSILON_R );
129 stackupJob->m_includeLossTangent = !m_argParser.get<bool>( ARG_EXCLUDE_LOSS_TANGENT );
130 stackupJob->m_includeFinish = !m_argParser.get<bool>( ARG_EXCLUDE_FINISH );
131 stackupJob->m_includeBoardOptions = !m_argParser.get<bool>( ARG_EXCLUDE_BOARD_OPTIONS );
132
133 stackupJob->SetConfiguredOutputPath( m_argOutput );
134
135 return aKiway.ProcessJob( KIWAY::FACE_PCB, stackupJob.get() );
136}
argparse::ArgumentParser m_argParser
Definition command.h:113
wxString m_argOutput
Value of the output arg if configured.
Definition command.h:143
wxString m_argInput
Value of the common input arg if configured.
Definition command.h:138
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:340
int ProcessJob(KIWAY::FACE_T aFace, JOB *aJob, REPORTER *aReporter=nullptr, PROGRESS_REPORTER *aProgressReporter=nullptr)
Definition kiway.cpp:740
@ FACE_PCB
pcbnew DSO
Definition kiway.h:348
#define UTF8STDSTR(s)
Definition command.h:27
#define ARG_UNITS
#define ARG_FORMAT
#define ARG_EXCLUDE_BOARD_OPTIONS
#define ARG_EXCLUDE_FINISH
#define ARG_EXCLUDE_MATERIAL
#define ARG_EXCLUDE_COLOR
#define ARG_EXCLUDE_EPSILON_R
#define ARG_EXCLUDE_LOSS_TANGENT
#define ARG_EXCLUDE_THICKNESS
#define _(s)
static const int ERR_ARGS
Definition exit_codes.h:31
static const int ERR_INVALID_INPUT_FILE
Definition exit_codes.h:33
wxString From_UTF8(const char *cstring)
PCB_EXPORT_BASE_COMMAND(const std::string &aName, IO_TYPE aInputType=IO_TYPE::FILE, IO_TYPE aOutputType=IO_TYPE::FILE)