KiCad PCB EDA Suite
Loading...
Searching...
No Matches
command_gerber_info.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 The KiCad Developers, see AUTHORS.txt for contributors.
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
20#include "command_gerber_info.h"
21#include <cli/exit_codes.h>
23#include <kiface_base.h>
24#include <string_utils.h>
25#include <macros.h>
26#include <wx/crt.h>
27
28
29#define ARG_FORMAT "--format"
30#define ARG_UNITS "--units"
31#define ARG_CALCULATE_AREA "--area"
32#define ARG_STRICT "--strict"
33
34
36 COMMAND( "info" )
37{
39
40 m_argParser.add_description( UTF8STDSTR( _( "Display information about a Gerber or Excellon file" ) ) );
41
42 m_argParser.add_argument( ARG_FORMAT )
43 .default_value( std::string( "text" ) )
44 .help( UTF8STDSTR( _( "Output format, options: text, json" ) ) )
45 .metavar( "FORMAT" );
46
47 m_argParser.add_argument( ARG_UNITS )
48 .default_value( std::string( "mm" ) )
49 .help( UTF8STDSTR( _( "Output units, options: mm, inch, mils (default: mm)" ) ) )
50 .metavar( "UNITS" );
51
52 m_argParser.add_argument( ARG_CALCULATE_AREA )
53 .help( UTF8STDSTR( _( "Calculate and display copper area" ) ) )
54 .flag();
55
56 m_argParser.add_argument( ARG_STRICT ).help( UTF8STDSTR( _( "Fail on any parse warnings or errors" ) ) ).flag();
57}
58
59
61{
62 std::unique_ptr<JOB_GERBER_INFO> infoJob = std::make_unique<JOB_GERBER_INFO>();
63
64 infoJob->m_inputFile = m_argInput;
65 infoJob->m_calculateArea = m_argParser.get<bool>( ARG_CALCULATE_AREA );
66 infoJob->m_strict = m_argParser.get<bool>( ARG_STRICT );
67
68 wxString format = From_UTF8( m_argParser.get<std::string>( ARG_FORMAT ).c_str() );
69
70 if( format == wxS( "text" ) )
71 {
72 infoJob->m_outputFormat = JOB_GERBER_INFO::OUTPUT_FORMAT::TEXT;
73 }
74 else if( format == wxS( "json" ) )
75 {
76 infoJob->m_outputFormat = JOB_GERBER_INFO::OUTPUT_FORMAT::JSON;
77 }
78 else
79 {
80 wxFprintf( stderr, _( "Invalid output format: %s\n" ), format );
82 }
83
84 wxString units = From_UTF8( m_argParser.get<std::string>( ARG_UNITS ).c_str() );
85
86 if( units == wxS( "mm" ) )
87 {
88 infoJob->m_units = JOB_GERBER_INFO::UNITS::MM;
89 }
90 else if( units == wxS( "inch" ) )
91 {
92 infoJob->m_units = JOB_GERBER_INFO::UNITS::INCH;
93 }
94 else if( units == wxS( "mils" ) )
95 {
96 infoJob->m_units = JOB_GERBER_INFO::UNITS::MILS;
97 }
98 else
99 {
100 wxFprintf( stderr, _( "Invalid units: %s\n" ), units );
102 }
103
104 int exitCode = aKiway.ProcessJob( KIWAY::FACE_GERBVIEW, infoJob.get() );
105
106 return exitCode;
107}
argparse::ArgumentParser m_argParser
Definition command.h:113
COMMAND(const std::string &aName)
Define a new COMMAND instance.
Definition command.cpp:30
void addCommonArgs(bool aInput, bool aOutput, IO_TYPE aInputType, IO_TYPE aOutputType)
Set up the most common of args used across cli.
Definition command.cpp:132
wxString m_argInput
Value of the common input arg if configured.
Definition command.h:143
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:315
int ProcessJob(KIWAY::FACE_T aFace, JOB *aJob, REPORTER *aReporter=nullptr, PROGRESS_REPORTER *aProgressReporter=nullptr)
Definition kiway.cpp:750
@ FACE_GERBVIEW
Definition kiway.h:325
#define UTF8STDSTR(s)
Definition command.h:27
#define ARG_UNITS
#define ARG_STRICT
#define ARG_FORMAT
#define ARG_CALCULATE_AREA
#define _(s)
This file contains miscellaneous commonly used macros and functions.
static const int ERR_ARGS
Definition exit_codes.h:31
wxString From_UTF8(const char *cstring)