KiCad PCB EDA Suite
Loading...
Searching...
No Matches
command_export_pcb_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
27#include <macros.h>
28#include <wx/tokenzr.h>
29#include <wx/crt.h>
30
32 bool aOutputIsDir ) :
33 COMMAND( aName )
34{
35 m_selectedLayersSet = false;
36 m_requireLayers = false;
37 m_hasLayerArg = false;
38
39 if( aOutputIsDir )
40 {
41 m_argParser.add_argument( "-o", ARG_OUTPUT )
42 .default_value( std::string() )
43 .help( UTF8STDSTR( _( "Output directory:" ) ) ); // todo fix after string freeze in v8
44 }
45 else
46 {
47 m_argParser.add_argument( "-o", ARG_OUTPUT )
48 .default_value( std::string() )
49 .help( UTF8STDSTR( _( "Output file name" ) ) );
50 }
51
52 m_argParser.add_argument( ARG_INPUT ).help( UTF8STDSTR( _( "Input file" ) ) );
53
54 // Build list of layer names and their layer mask:
55 for( int layer = 0; layer < PCB_LAYER_ID_COUNT; ++layer )
56 {
57 std::string untranslated = TO_UTF8( wxString( LSET::Name( PCB_LAYER_ID( layer ) ) ) );
58
59 //m_layerIndices[untranslated] = PCB_LAYER_ID( layer );
60
61 // Add layer name used in pcb files
62 m_layerMasks[untranslated] = LSET( PCB_LAYER_ID( layer ) );
63 // Add layer name using GUI canonical layer name
64 m_layerGuiMasks[ TO_UTF8(LayerName( layer ) ) ] = LSET( PCB_LAYER_ID( layer ) );
65 }
66
67 // Add list of grouped layer names used in pcb files
69 m_layerMasks["*.Cu"] = LSET::AllCuMask();
71 m_layerMasks["F&B.Cu"] = LSET( 2, F_Cu, B_Cu );
72 m_layerMasks["*.Adhes"] = LSET( 2, B_Adhes, F_Adhes );
73 m_layerMasks["*.Paste"] = LSET( 2, B_Paste, F_Paste );
74 m_layerMasks["*.Mask"] = LSET( 2, B_Mask, F_Mask );
75 m_layerMasks["*.SilkS"] = LSET( 2, B_SilkS, F_SilkS );
76 m_layerMasks["*.Fab"] = LSET( 2, B_Fab, F_Fab );
77 m_layerMasks["*.CrtYd"] = LSET( 2, B_CrtYd, F_CrtYd );
78
79 // Add list of grouped layer names using GUI canonical layer names
80 m_layerGuiMasks["*.Adhesive"] = LSET( 2, B_Adhes, F_Adhes );
81 m_layerGuiMasks["*.Silkscreen"] = LSET( 2, B_SilkS, F_SilkS );
82 m_layerGuiMasks["*.Courtyard"] = LSET( 2, B_CrtYd, F_CrtYd );
83}
84
85
86LSET CLI::EXPORT_PCB_BASE_COMMAND::convertLayerStringList( wxString& aLayerString, bool& aLayerArgSet ) const
87{
88 LSET layerMask;
89
90 if( !aLayerString.IsEmpty() )
91 {
92 layerMask.reset();
93 wxStringTokenizer layerTokens( aLayerString, "," );
94
95 while( layerTokens.HasMoreTokens() )
96 {
97 std::string token = TO_UTF8( layerTokens.GetNextToken() );
98
99 // Search for a layer name in canonical layer name used in .kicad_pcb files:
100 if( m_layerMasks.count( token ) )
101 {
102 layerMask |= m_layerMasks.at(token);
103 aLayerArgSet = true;
104 }
105 // Search for a layer name in canonical layer name used in GUI (not translated):
106 else if( m_layerGuiMasks.count( token ) )
107 {
108 layerMask |= m_layerGuiMasks.at(token);
109 aLayerArgSet = true;
110 }
111 else
112 {
113 wxFprintf( stderr, _( "Invalid layer name \"%s\"\n" ), token );
114 }
115 }
116 }
117
118 return layerMask;
119}
120
121
123{
124 m_argParser.add_argument( "-l", ARG_LAYERS )
125 .default_value( std::string() )
126 .help( UTF8STDSTR(
127 _( "Comma separated list of untranslated layer names to include such as "
128 "F.Cu,B.Cu" ) ) );
129
130 m_hasLayerArg = true;
131 m_requireLayers = aRequire;
132}
133
134
136{
137 if( m_hasLayerArg )
138 {
139 wxString layers = FROM_UTF8( m_argParser.get<std::string>( ARG_LAYERS ).c_str() );
140
141 LSET layerMask = convertLayerStringList( layers, m_selectedLayersSet );
142 if( m_requireLayers && layerMask.Seq().size() < 1 )
143 {
144 wxFprintf( stderr, _( "At least one or more layers must be specified\n" ) );
146 }
147
148 m_selectedLayers = layerMask;
149 }
150
151 return EXIT_CODES::OK;
152}
argparse::ArgumentParser m_argParser
Definition: command.h:68
A minimalistic software bus for communications between various DLLs/DSOs (DSOs) within the same KiCad...
Definition: kiway.h:279
LSET is a set of PCB_LAYER_IDs.
Definition: layer_ids.h:536
static LSET AllLayersMask()
Definition: lset.cpp:808
LSEQ Seq(const PCB_LAYER_ID *aWishListSequence, unsigned aCount) const
Return an LSEQ from the union of this LSET and a desired sequence.
Definition: lset.cpp:411
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:733
static LSET AllCuMask(int aCuLayerCount=MAX_CU_LAYERS)
Return a mask holding the requested number of Cu PCB_LAYER_IDs.
Definition: lset.cpp:773
static const wxChar * Name(PCB_LAYER_ID aLayerId)
Return the fixed name association with aLayerId.
Definition: lset.cpp:82
#define UTF8STDSTR(s)
Definition: command.h:27
#define ARG_OUTPUT
#define ARG_INPUT
#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:59
@ 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.
#define TO_UTF8(wxstring)
Convert a wxString to a UTF8 encoded C string for all wxWidgets build modes.
Definition: macros.h:96
static wxString FROM_UTF8(const char *cstring)
Convert a UTF8 encoded C string to a wxString for all wxWidgets build modes.
Definition: macros.h:110
static const int ERR_ARGS
Definition: exit_codes.h:31
static const int OK
Definition: exit_codes.h:30
int doPerform(KIWAY &aKiway) override
The internal handler that should be overloaded to implement command specific processing and work.
LSET convertLayerStringList(wxString &aLayerString, bool &aLayerArgSet) const
std::map< std::string, LSET > m_layerGuiMasks
std::map< std::string, LSET > m_layerMasks
EXPORT_PCB_BASE_COMMAND(const std::string &aName, bool aOutputIsDir=false)