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 (C) 1992-2023 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>
23#include <kiface_base.h>
24#include <bitset>
25#include <layer_ids.h>
26#include <string_utils.h>
27
28#include <macros.h>
29#include <wx/tokenzr.h>
30#include <wx/crt.h>
31
33 bool aInputIsDir,
34 bool aOutputIsDir ) :
35 COMMAND( aName )
36{
37 m_selectedLayersSet = false;
38 m_requireLayers = false;
39 m_hasLayerArg = false;
40
41 addCommonArgs( true, true, aInputIsDir, aOutputIsDir );
42
43 // Build list of layer names and their layer mask:
44 for( int layer = 0; layer < PCB_LAYER_ID_COUNT; ++layer )
45 {
46 std::string untranslated = TO_UTF8( wxString( LSET::Name( PCB_LAYER_ID( layer ) ) ) );
47
48 //m_layerIndices[untranslated] = PCB_LAYER_ID( layer );
49
50 // Add layer name used in pcb files
51 m_layerMasks[untranslated] = LSET( PCB_LAYER_ID( layer ) );
52 // Add layer name using GUI canonical layer name
53 m_layerGuiMasks[ TO_UTF8(LayerName( layer ) ) ] = LSET( PCB_LAYER_ID( layer ) );
54 }
55
56 // Add list of grouped layer names used in pcb files
58 m_layerMasks["*.Cu"] = LSET::AllCuMask();
60 m_layerMasks["F&B.Cu"] = LSET( 2, F_Cu, B_Cu );
61 m_layerMasks["*.Adhes"] = LSET( 2, B_Adhes, F_Adhes );
62 m_layerMasks["*.Paste"] = LSET( 2, B_Paste, F_Paste );
63 m_layerMasks["*.Mask"] = LSET( 2, B_Mask, F_Mask );
64 m_layerMasks["*.SilkS"] = LSET( 2, B_SilkS, F_SilkS );
65 m_layerMasks["*.Fab"] = LSET( 2, B_Fab, F_Fab );
66 m_layerMasks["*.CrtYd"] = LSET( 2, B_CrtYd, F_CrtYd );
67
68 // Add list of grouped layer names using GUI canonical layer names
69 m_layerGuiMasks["*.Adhesive"] = LSET( 2, B_Adhes, F_Adhes );
70 m_layerGuiMasks["*.Silkscreen"] = LSET( 2, B_SilkS, F_SilkS );
71 m_layerGuiMasks["*.Courtyard"] = LSET( 2, B_CrtYd, F_CrtYd );
72}
73
74
76 bool& aLayerArgSet ) const
77{
78 LSEQ layerMask;
79
80 if( !aLayerString.IsEmpty() )
81 {
82 wxStringTokenizer layerTokens( aLayerString, "," );
83
84 while( layerTokens.HasMoreTokens() )
85 {
86 std::string token = TO_UTF8( layerTokens.GetNextToken() );
87
88 // Search for a layer name in canonical layer name used in .kicad_pcb files:
89 if( m_layerMasks.count( token ) )
90 {
91 for( PCB_LAYER_ID layer : m_layerMasks.at( token ).Seq() )
92 layerMask.push_back( layer );
93
94 aLayerArgSet = true;
95 }
96 // Search for a layer name in canonical layer name used in GUI (not translated):
97 else if( m_layerGuiMasks.count( token ) )
98 {
99 for( PCB_LAYER_ID layer : m_layerGuiMasks.at( token ).Seq() )
100 layerMask.push_back( layer );
101
102 aLayerArgSet = true;
103 }
104 else
105 {
106 wxFprintf( stderr, _( "Invalid layer name \"%s\"\n" ), token );
107 }
108 }
109 }
110
111 return layerMask;
112}
113
114
116{
117 m_argParser.add_argument( "-l", ARG_LAYERS )
118 .default_value( std::string() )
119 .help( UTF8STDSTR(
120 _( "Comma separated list of untranslated layer names to include such as "
121 "F.Cu,B.Cu" ) ) )
122 .metavar( "LAYER_LIST" );
123
124 m_hasLayerArg = true;
125 m_requireLayers = aRequire;
126}
127
128
130{
131 if( m_hasLayerArg )
132 {
133 wxString layers = From_UTF8( m_argParser.get<std::string>( ARG_LAYERS ).c_str() );
134
135 LSEQ layerMask = convertLayerStringList( layers, m_selectedLayersSet );
136
137 if( m_requireLayers && layerMask.size() < 1 )
138 {
139 wxFprintf( stderr, _( "At least one layer must be specified\n" ) );
141 }
142
143 m_selectedLayers = layerMask;
144 }
145
146 return EXIT_CODES::OK;
147}
void addCommonArgs(bool aInput, bool aOutput, bool aInputIsDir, bool aOutputIsDir)
Set up the most common of args used across cli.
Definition: command.cpp:115
A minimalistic software bus for communications between various DLLs/DSOs (DSOs) within the same KiCad...
Definition: kiway.h:279
LSEQ is a sequence (and therefore also a set) of PCB_LAYER_IDs.
Definition: layer_ids.h:521
LSET is a set of PCB_LAYER_IDs.
Definition: layer_ids.h:575
static LSET AllLayersMask()
Definition: lset.cpp:898
static LSET InternalCuMask()
Return a complete set of internal copper layers which is all Cu layers except F_Cu and B_Cu.
Definition: lset.cpp:823
static LSET AllCuMask(int aCuLayerCount=MAX_CU_LAYERS)
Return a mask holding the requested number of Cu PCB_LAYER_IDs.
Definition: lset.cpp:863
static const wxChar * Name(PCB_LAYER_ID aLayerId)
Return the fixed name association with aLayerId.
Definition: lset.cpp:89
#define UTF8STDSTR(s)
Definition: command.h:27
#define ARG_LAYERS
#define _(s)
wxString LayerName(int aLayer)
Returns the default display name for a given layer.
Definition: layer_id.cpp:30
PCB_LAYER_ID
A quick note on layer IDs:
Definition: layer_ids.h:60
@ F_CrtYd
Definition: layer_ids.h:117
@ B_Adhes
Definition: layer_ids.h:97
@ F_Paste
Definition: layer_ids.h:101
@ F_Adhes
Definition: layer_ids.h:98
@ B_Mask
Definition: layer_ids.h:106
@ B_Cu
Definition: layer_ids.h:95
@ F_Mask
Definition: layer_ids.h:107
@ B_Paste
Definition: layer_ids.h:100
@ F_Fab
Definition: layer_ids.h:120
@ F_SilkS
Definition: layer_ids.h:104
@ B_CrtYd
Definition: layer_ids.h:116
@ B_SilkS
Definition: layer_ids.h:103
@ PCB_LAYER_ID_COUNT
Definition: layer_ids.h:137
@ F_Cu
Definition: layer_ids.h:64
@ B_Fab
Definition: layer_ids.h:119
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
wxString From_UTF8(const char *cstring)
#define TO_UTF8(wxstring)
Convert a wxString to a UTF8 encoded C string for all wxWidgets build modes.
Definition: string_utils.h:391
PCB_EXPORT_BASE_COMMAND(const std::string &aName, bool aInputIsDir=false, bool aOutputIsDir=false)
int doPerform(KIWAY &aKiway) override
The internal handler that should be overloaded to implement command specific processing and work.
std::map< std::string, LSET > m_layerMasks
LSEQ convertLayerStringList(wxString &aLayerString, bool &aLayerArgSet) const
std::map< std::string, LSET > m_layerGuiMasks