KiCad PCB EDA Suite
Loading...
Searching...
No Matches
command_pcb_export_stats.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) 2024 The KiCad Developers
5 *
6 * This program is free software: you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation, either version 3 of the License, or (at your
9 * option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License along
17 * with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
21
22#include <cli/exit_codes.h>
24#include <string_utils.h>
25#include <wx/crt.h>
26
27#define ARG_EXCLUDE_NO_PADS "--exclude-footprints-without-pads"
28#define ARG_SUBTRACT_HOLES "--subtract-holes-from-board"
29#define ARG_SUBTRACT_HOLES_COPPER "--subtract-holes-from-copper"
30#define ARG_FORMAT "--format"
31#define ARG_UNITS "--units"
32
34 PCB_EXPORT_BASE_COMMAND( "stats", false, false )
35{
36 m_argParser.add_description( UTF8STDSTR( _( "Generate a board statistics report" ) ) );
37
38 m_argParser.add_argument( ARG_FORMAT )
39 .default_value( std::string( "report" ) )
40 .help( UTF8STDSTR( _( "Output file format, options: json, report" ) ) )
41 .metavar( "FORMAT" );
42
43 m_argParser.add_argument( ARG_UNITS )
44 .default_value( std::string( "mm" ) )
45 .help( UTF8STDSTR( _( "Report units; valid options: in, mm" ) ) )
46 .metavar( "UNITS" );
47
48 m_argParser.add_argument( ARG_EXCLUDE_NO_PADS )
49 .help( UTF8STDSTR( _( "Exclude footprints without pads" ) ) )
50 .flag();
51
52 m_argParser.add_argument( ARG_SUBTRACT_HOLES )
53 .help( UTF8STDSTR( _( "Subtract holes from the board area" ) ) )
54 .flag();
55
57 .help( UTF8STDSTR( _( "Subtract holes from copper areas" ) ) )
58 .flag();
59}
60
61
63{
64 std::unique_ptr<JOB_EXPORT_PCB_STATS> statsJob( new JOB_EXPORT_PCB_STATS() );
65
66 statsJob->m_filename = m_argInput;
67
68 if( !wxFile::Exists( statsJob->m_filename ) )
69 {
70 wxFprintf( stderr, _( "Board file does not exist or is not accessible\n" ) );
72 }
73
74 statsJob->m_excludeFootprintsWithoutPads = m_argParser.get<bool>( ARG_EXCLUDE_NO_PADS );
75 statsJob->m_subtractHolesFromBoardArea = m_argParser.get<bool>( ARG_SUBTRACT_HOLES );
76 statsJob->m_subtractHolesFromCopperAreas = m_argParser.get<bool>( ARG_SUBTRACT_HOLES_COPPER );
77
78 wxString format = From_UTF8( m_argParser.get<std::string>( ARG_FORMAT ).c_str() );
79
80 if( format == "report" )
82 else if( format == "json" )
84 else
85 {
86 wxFprintf( stderr, _( "Invalid report format\n" ) );
88 }
89
90 wxString units = From_UTF8( m_argParser.get<std::string>( ARG_UNITS ).c_str() );
91
92 if( units == wxS( "mm" ) )
93 statsJob->m_units = JOB_EXPORT_PCB_STATS::UNITS::MM;
94 else if( units == wxS( "in" ) || units == wxS( "inch" ) )
95 statsJob->m_units = JOB_EXPORT_PCB_STATS::UNITS::INCH;
96 else
97 {
98 wxFprintf( stderr, _( "Invalid units specified\n" ) );
100 }
101
102 statsJob->SetConfiguredOutputPath( m_argOutput );
103
104 return aKiway.ProcessJob( KIWAY::FACE_PCB, statsJob.get() );
105}
argparse::ArgumentParser m_argParser
Definition command.h:106
wxString m_argOutput
Value of the output arg if configured.
Definition command.h:141
wxString m_argInput
Value of the common input arg if configured.
Definition command.h:136
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_UNITS
#define ARG_FORMAT
#define ARG_SUBTRACT_HOLES
#define ARG_EXCLUDE_NO_PADS
#define ARG_SUBTRACT_HOLES_COPPER
#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, bool aInputCanBeDir=false, bool aOutputIsDir=false)