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 <lset.h>
27#include <lseq.h>
28#include <string_utils.h>
29
30#include <macros.h>
31#include <wx/tokenzr.h>
32#include <wx/crt.h>
33
35 bool aInputIsDir,
36 bool aOutputIsDir ) :
37 COMMAND( aName )
38{
39 m_selectedLayersSet = false;
40 m_requireLayers = false;
41 m_hasLayerArg = false;
42
43 addCommonArgs( true, true, aInputIsDir, aOutputIsDir );
44
45 // Build list of layer names and their layer mask:
46 for( int layer = 0; layer < PCB_LAYER_ID_COUNT; ++layer )
47 {
48 std::string untranslated = TO_UTF8( wxString( LSET::Name( PCB_LAYER_ID( layer ) ) ) );
49
50 //m_layerIndices[untranslated] = PCB_LAYER_ID( layer );
51
52 // Add layer name used in pcb files
53 m_layerMasks[untranslated] = LSET( { PCB_LAYER_ID( layer ) } );
54 // Add layer name using GUI canonical layer name
55 m_layerGuiMasks[ TO_UTF8(LayerName( layer ) ) ] = LSET( { PCB_LAYER_ID( layer ) } );
56 }
57
58 // Add list of grouped layer names used in pcb files
60 m_layerMasks["*.Cu"] = LSET::AllCuMask();
62 m_layerMasks["F&B.Cu"] = LSET( { F_Cu, B_Cu } );
63 m_layerMasks["*.Adhes"] = LSET( { B_Adhes, F_Adhes } );
64 m_layerMasks["*.Paste"] = LSET( { B_Paste, F_Paste } );
65 m_layerMasks["*.Mask"] = LSET( { B_Mask, F_Mask } );
66 m_layerMasks["*.SilkS"] = LSET( { B_SilkS, F_SilkS } );
67 m_layerMasks["*.Fab"] = LSET( { B_Fab, F_Fab } );
68 m_layerMasks["*.CrtYd"] = LSET( { B_CrtYd, F_CrtYd } );
69
70 // Add list of grouped layer names using GUI canonical layer names
71 m_layerGuiMasks["*.Adhesive"] = LSET( { B_Adhes, F_Adhes } );
72 m_layerGuiMasks["*.Silkscreen"] = LSET( { B_SilkS, F_SilkS } );
73 m_layerGuiMasks["*.Courtyard"] = LSET( { B_CrtYd, F_CrtYd } );
74}
75
76
78 bool& aLayerArgSet ) const
79{
80 LSEQ layerMask;
81
82 if( !aLayerString.IsEmpty() )
83 {
84 wxStringTokenizer layerTokens( aLayerString, "," );
85
86 while( layerTokens.HasMoreTokens() )
87 {
88 std::string token = TO_UTF8( layerTokens.GetNextToken() );
89
90 // Search for a layer name in canonical layer name used in .kicad_pcb files:
91 if( m_layerMasks.count( token ) )
92 {
93 for( PCB_LAYER_ID layer : m_layerMasks.at( token ).Seq() )
94 layerMask.push_back( layer );
95
96 aLayerArgSet = true;
97 }
98 // Search for a layer name in canonical layer name used in GUI (not translated):
99 else if( m_layerGuiMasks.count( token ) )
100 {
101 for( PCB_LAYER_ID layer : m_layerGuiMasks.at( token ).Seq() )
102 layerMask.push_back( layer );
103
104 aLayerArgSet = true;
105 }
106 else
107 {
108 wxFprintf( stderr, _( "Invalid layer name \"%s\"\n" ), token );
109 }
110 }
111 }
112
113 return layerMask;
114}
115
116
118{
119 m_argParser.add_argument( "-l", ARG_LAYERS )
120 .default_value( std::string() )
121 .help( UTF8STDSTR(
122 _( "Comma separated list of untranslated layer names to include such as "
123 "F.Cu,B.Cu" ) ) )
124 .metavar( "LAYER_LIST" );
125
126 m_hasLayerArg = true;
127 m_requireLayers = aRequire;
128}
129
130
132{
133 if( m_hasLayerArg )
134 {
135 wxString layers = From_UTF8( m_argParser.get<std::string>( ARG_LAYERS ).c_str() );
136
137 LSEQ layerMask = convertLayerStringList( layers, m_selectedLayersSet );
138
139 if( m_requireLayers && layerMask.size() < 1 )
140 {
141 wxFprintf( stderr, _( "At least one layer must be specified\n" ) );
143 }
144
145 m_selectedLayers = layerMask;
146 }
147
148 return EXIT_CODES::OK;
149}
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:284
LSEQ is a sequence (and therefore also a set) of PCB_LAYER_IDs.
Definition: lseq.h:47
LSET is a set of PCB_LAYER_IDs.
Definition: lset.h:36
static LSET AllLayersMask()
Definition: lset.cpp:711
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:675
static LSET AllCuMask(int aCuLayerCount=MAX_CU_LAYERS)
Return a mask holding the requested number of Cu PCB_LAYER_IDs.
Definition: lset.cpp:686
static wxString Name(PCB_LAYER_ID aLayerId)
Return the fixed name association with aLayerId.
Definition: lset.cpp:193
#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:31
PCB_LAYER_ID
A quick note on layer IDs:
Definition: layer_ids.h:60
@ F_CrtYd
Definition: layer_ids.h:116
@ B_Adhes
Definition: layer_ids.h:103
@ F_Paste
Definition: layer_ids.h:104
@ F_Adhes
Definition: layer_ids.h:102
@ B_Mask
Definition: layer_ids.h:98
@ B_Cu
Definition: layer_ids.h:65
@ F_Mask
Definition: layer_ids.h:97
@ B_Paste
Definition: layer_ids.h:105
@ F_Fab
Definition: layer_ids.h:119
@ F_SilkS
Definition: layer_ids.h:100
@ B_CrtYd
Definition: layer_ids.h:115
@ B_SilkS
Definition: layer_ids.h:101
@ PCB_LAYER_ID_COUNT
Definition: layer_ids.h:135
@ F_Cu
Definition: layer_ids.h:64
@ B_Fab
Definition: layer_ids.h:118
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:398
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