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-2022 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
75LSEQ CLI::PCB_EXPORT_BASE_COMMAND::convertLayerStringList( wxString& aLayerString, bool& aLayerArgSet ) const
76{
77 LSEQ layerMask;
78
79 if( !aLayerString.IsEmpty() )
80 {
81 wxStringTokenizer layerTokens( aLayerString, "," );
82
83 while( layerTokens.HasMoreTokens() )
84 {
85 std::string token = TO_UTF8( layerTokens.GetNextToken() );
86
87 // Search for a layer name in canonical layer name used in .kicad_pcb files:
88 if( m_layerMasks.count( token ) )
89 {
90 for( PCB_LAYER_ID layer : m_layerMasks.at( token ).Seq() )
91 layerMask.push_back( layer );
92
93 aLayerArgSet = true;
94 }
95 // Search for a layer name in canonical layer name used in GUI (not translated):
96 else if( m_layerGuiMasks.count( token ) )
97 {
98 for( PCB_LAYER_ID layer : m_layerGuiMasks.at( token ).Seq() )
99 layerMask.push_back( layer );
100
101 aLayerArgSet = true;
102 }
103 else
104 {
105 wxFprintf( stderr, _( "Invalid layer name \"%s\"\n" ), token );
106 }
107 }
108 }
109
110 return layerMask;
111}
112
113
115{
116 m_argParser.add_argument( "-l", ARG_LAYERS )
117 .default_value( std::string() )
118 .help( UTF8STDSTR(
119 _( "Comma separated list of untranslated layer names to include such as "
120 "F.Cu,B.Cu" ) ) )
121 .metavar( "LAYER_LIST" );
122
123 m_hasLayerArg = true;
124 m_requireLayers = aRequire;
125}
126
127
129{
130 if( m_hasLayerArg )
131 {
132 wxString layers = From_UTF8( m_argParser.get<std::string>( ARG_LAYERS ).c_str() );
133
134 LSEQ layerMask = convertLayerStringList( layers, m_selectedLayersSet );
135
136 if( m_requireLayers && layerMask.size() < 1 )
137 {
138 wxFprintf( stderr, _( "At least one layer must be specified\n" ) );
140 }
141
142 m_selectedLayers = layerMask;
143 }
144
145 return EXIT_CODES::OK;
146}
void addCommonArgs(bool aInput, bool aOutput, bool aInputIsDir, bool aOutputIsDir)
Sets 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:513
LSET is a set of PCB_LAYER_IDs.
Definition: layer_ids.h:556
static LSET AllLayersMask()
Definition: lset.cpp:817
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:742
static LSET AllCuMask(int aCuLayerCount=MAX_CU_LAYERS)
Return a mask holding the requested number of Cu PCB_LAYER_IDs.
Definition: lset.cpp:782
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:118
@ B_Adhes
Definition: layer_ids.h:98
@ F_Paste
Definition: layer_ids.h:102
@ F_Adhes
Definition: layer_ids.h:99
@ B_Mask
Definition: layer_ids.h:107
@ B_Cu
Definition: layer_ids.h:96
@ F_Mask
Definition: layer_ids.h:108
@ B_Paste
Definition: layer_ids.h:101
@ F_Fab
Definition: layer_ids.h:121
@ F_SilkS
Definition: layer_ids.h:105
@ B_CrtYd
Definition: layer_ids.h:117
@ B_SilkS
Definition: layer_ids.h:104
@ PCB_LAYER_ID_COUNT
Definition: layer_ids.h:138
@ F_Cu
Definition: layer_ids.h:65
@ B_Fab
Definition: layer_ids.h:120
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