KiCad PCB EDA Suite
Loading...
Searching...
No Matches
command_pcb_export_base.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
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
19 */
20
22#include <bitset>
24#include <string_utils.h>
25
26#include <magic_enum.hpp>
27
28
30 IO_TYPE aOutputType ) :
31 COMMAND( aName )
32{
33 addCommonArgs( true, true, aInputType, aOutputType );
34}
35
36
38{
39 m_argParser.add_argument( "-l", ARG_LAYERS )
40 .default_value( std::string() )
41 .help( UTF8STDSTR( _( "Comma separated list of untranslated layer names to include "
42 "such as F.Cu,B.Cu" ) ) )
43 .metavar( "LAYER_LIST" );
44}
45
46
48{
49 m_argParser.add_argument( "--cl", ARG_COMMON_LAYERS )
50 .default_value( std::string() )
51 .help( UTF8STDSTR( _( "Layers to include on each plot, comma separated list of "
52 "untranslated layer names to include such as F.Cu,B.Cu" ) ) )
53 .metavar( "COMMON_LAYER_LIST" );
54}
55
56
58 const std::string& aDataSetAlias )
59{
60 m_argParser.add_argument( ARG_BOM_COL_MFG_PN )
61 .default_value( std::string() )
62 .help( std::string( "Name of the part field to use for the Bill of Material "
63 "Manufacturer Part Number Column" ) )
64 .metavar( "FIELD_NAME" );
65
66 m_argParser.add_argument( ARG_PRECISION )
67 .help( std::string( "Precision" ) )
68 .scan<'i', int>()
69 .default_value( 6 )
70 .metavar( "PRECISION" );
71
72 m_argParser.add_argument( ARG_FAB_UNITS )
73 .default_value( std::string( "mm" ) )
74 .help( std::string( "Units" ) )
75 .choices( "mm", "in" );
76
77 m_argParser.add_argument( ARG_CHECK_ZONES ).help( UTF8STDSTR( _( ARG_CHECK_ZONES_DESC ) ) ).flag();
78
79 std::string dataSetHelp = "Data set to export:";
80
81 for( JOB_EXPORT_PCB_FAB::DATA_SET dataSet : magic_enum::enum_values<JOB_EXPORT_PCB_FAB::DATA_SET>() )
82 {
83 if( aJob.SupportsDataSet( dataSet ) )
84 dataSetHelp += " " + JOB_EXPORT_PCB_FAB::DataSetToken( dataSet );
85 }
86
87 argparse::Argument& dataSetArg = aDataSetAlias.empty() ? m_argParser.add_argument( ARG_DATA_SET )
88 : m_argParser.add_argument( ARG_DATA_SET, aDataSetAlias );
89
90 dataSetArg.default_value( std::string( "userdef" ) ).help( dataSetHelp ).metavar( "DATA_SET" );
91
92 m_argParser.add_argument( ARG_SECTIONS )
93 .default_value( std::string() )
94 .help( std::string( "Override the optional sections of the chosen data set, as "
95 "IPC-2581 section key letters" ) )
96 .metavar( "SECTION_KEY" );
97
98 m_argParser.add_argument( ARG_NET_NAMES )
99 .default_value( std::string( "include" ) )
100 .help( std::string( "Export net names as authored or as anonymous names that preserve "
101 "connectivity" ) )
102 .choices( "include", "anonymize" );
103}
104
105
107{
108 aJob.m_filename = m_argInput;
111 aJob.m_precision = m_argParser.get<int>( ARG_PRECISION );
113 aJob.m_colMfgPn = From_UTF8( m_argParser.get<std::string>( ARG_BOM_COL_MFG_PN ).c_str() );
114 std::string units = m_argParser.get<std::string>( ARG_FAB_UNITS );
116
118 From_UTF8( m_argParser.get<std::string>( ARG_DATA_SET ).c_str() ) );
119
120 wxString sections = From_UTF8( m_argParser.get<std::string>( ARG_SECTIONS ).c_str() );
121 aJob.m_sections = sections.IsEmpty() ? std::nullopt : std::optional<wxString>( sections );
122 aJob.m_netNames = m_argParser.get<std::string>( ARG_NET_NAMES ) == "anonymize"
125}
argparse::ArgumentParser m_argParser
Definition command.h:113
COMMAND(const std::string &aName)
Define a new COMMAND instance.
Definition command.cpp:30
wxString m_argDrawingSheet
Value of the drawing sheet arg if configured.
Definition command.h:148
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:134
wxString m_argInput
Value of the common input arg if configured.
Definition command.h:138
std::vector< wxString > m_argVariantNames
The list of variant names to output.
Definition command.h:166
DATA_SET
Columns of the IPC-2581C function mode table, Table 4 p 80.
static std::string DataSetToken(DATA_SET aDataSet)
Lower case token that the job file and the CLI use for aDataSet Empty when it has none.
std::optional< wxString > m_sections
Section key that replaces the optional sections of the data set Unset lets the data set select them a...
static DATA_SET DataSetFromToken(const wxString &aToken)
Read a data set token in upper case or in lower case An empty token is USERDEF.
virtual bool SupportsDataSet(DATA_SET aDataSet) const =0
std::vector< wxString > m_variantNames
#define UTF8STDSTR(s)
Definition command.h:27
#define ARG_NET_NAMES
#define ARG_CHECK_ZONES_DESC
#define ARG_PRECISION
#define ARG_COMMON_LAYERS
#define ARG_CHECK_ZONES
#define ARG_BOM_COL_MFG_PN
#define ARG_SECTIONS
#define ARG_FAB_UNITS
#define ARG_LAYERS
#define ARG_DATA_SET
#define _(s)
static wxString From_UTF8(const char *cstring)
Convert a UTF8 encoded C string to a wxString for all wxWidgets build modes.
Definition idf_helpers.h:44
PCB_EXPORT_BASE_COMMAND(const std::string &aName, IO_TYPE aInputType=IO_TYPE::FILE, IO_TYPE aOutputType=IO_TYPE::FILE)
void applyFabExportArgs(JOB_EXPORT_PCB_FAB &aJob)
void addFabExportArgs(const JOB_EXPORT_PCB_FAB &aJob, const std::string &aDataSetAlias={})
aJob says which data sets the format supports aDataSetAlias is a second name for the flag