KiCad PCB EDA Suite
Loading...
Searching...
No Matches
test_pads_layer_mapper.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 The KiCad Developers, see AUTHORS.txt for contributors.
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <https://www.gnu.org/licenses/>.
18 */
19
24
26
28
29
34
35
36BOOST_FIXTURE_TEST_SUITE( PadsLayerMapper, PADS_LAYER_MAPPER_FIXTURE )
37
38
39BOOST_AUTO_TEST_CASE( CopperLayerType_TwoLayer )
40{
41 PADS_LAYER_MAPPER mapper;
42 mapper.SetCopperLayerCount( 2 );
43
44 // Layer 1 = Top
45 BOOST_CHECK( mapper.GetLayerType( 1 ) == PADS_LAYER_TYPE::COPPER_TOP );
46
47 // Layer 2 = Bottom (for 2-layer board)
48 BOOST_CHECK( mapper.GetLayerType( 2 ) == PADS_LAYER_TYPE::COPPER_BOTTOM );
49}
50
51
52BOOST_AUTO_TEST_CASE( CopperLayerType_FourLayer )
53{
54 PADS_LAYER_MAPPER mapper;
55 mapper.SetCopperLayerCount( 4 );
56
57 // Layer 1 = Top
58 BOOST_CHECK( mapper.GetLayerType( 1 ) == PADS_LAYER_TYPE::COPPER_TOP );
59
60 // Layer 2, 3 = Inner
61 BOOST_CHECK( mapper.GetLayerType( 2 ) == PADS_LAYER_TYPE::COPPER_INNER );
62 BOOST_CHECK( mapper.GetLayerType( 3 ) == PADS_LAYER_TYPE::COPPER_INNER );
63
64 // Layer 4 = Bottom
65 BOOST_CHECK( mapper.GetLayerType( 4 ) == PADS_LAYER_TYPE::COPPER_BOTTOM );
66}
67
68
69BOOST_AUTO_TEST_CASE( CopperLayerType_SixLayer )
70{
71 PADS_LAYER_MAPPER mapper;
72 mapper.SetCopperLayerCount( 6 );
73
74 BOOST_CHECK( mapper.GetLayerType( 1 ) == PADS_LAYER_TYPE::COPPER_TOP );
75 BOOST_CHECK( mapper.GetLayerType( 2 ) == PADS_LAYER_TYPE::COPPER_INNER );
76 BOOST_CHECK( mapper.GetLayerType( 3 ) == PADS_LAYER_TYPE::COPPER_INNER );
77 BOOST_CHECK( mapper.GetLayerType( 4 ) == PADS_LAYER_TYPE::COPPER_INNER );
78 BOOST_CHECK( mapper.GetLayerType( 5 ) == PADS_LAYER_TYPE::COPPER_INNER );
79 BOOST_CHECK( mapper.GetLayerType( 6 ) == PADS_LAYER_TYPE::COPPER_BOTTOM );
80}
81
82
93
94
108
109
110BOOST_AUTO_TEST_CASE( UnknownLayerType )
111{
112 PADS_LAYER_MAPPER mapper;
113 mapper.SetCopperLayerCount( 2 );
114
115 // Unknown layer numbers should return UNKNOWN
116 BOOST_CHECK( mapper.GetLayerType( 100 ) == PADS_LAYER_TYPE::UNKNOWN );
117 BOOST_CHECK( mapper.GetLayerType( 999 ) == PADS_LAYER_TYPE::UNKNOWN );
118}
119
120
121BOOST_AUTO_TEST_CASE( AutoMapCopper )
122{
123 PADS_LAYER_MAPPER mapper;
124 mapper.SetCopperLayerCount( 4 );
125
126 BOOST_CHECK_EQUAL( mapper.GetAutoMapLayer( 1 ), F_Cu );
127 BOOST_CHECK_EQUAL( mapper.GetAutoMapLayer( 4 ), B_Cu );
130}
131
132
146
147
148BOOST_AUTO_TEST_CASE( ParseLayerName_Silkscreen )
149{
150 PADS_LAYER_MAPPER mapper;
151
152 BOOST_CHECK( mapper.ParseLayerName( "Silkscreen Top" ) == PADS_LAYER_TYPE::SILKSCREEN_TOP );
153 BOOST_CHECK( mapper.ParseLayerName( "SILKSCREEN TOP" ) == PADS_LAYER_TYPE::SILKSCREEN_TOP );
154 BOOST_CHECK( mapper.ParseLayerName( "silkscreen top" ) == PADS_LAYER_TYPE::SILKSCREEN_TOP );
155 BOOST_CHECK( mapper.ParseLayerName( "SST" ) == PADS_LAYER_TYPE::SILKSCREEN_TOP );
156 BOOST_CHECK( mapper.ParseLayerName( "Top Silk" ) == PADS_LAYER_TYPE::SILKSCREEN_TOP );
157
158 BOOST_CHECK( mapper.ParseLayerName( "Silkscreen Bottom" ) == PADS_LAYER_TYPE::SILKSCREEN_BOTTOM );
159 BOOST_CHECK( mapper.ParseLayerName( "SSB" ) == PADS_LAYER_TYPE::SILKSCREEN_BOTTOM );
160}
161
162
163BOOST_AUTO_TEST_CASE( ParseLayerName_SolderMask )
164{
165 PADS_LAYER_MAPPER mapper;
166
167 BOOST_CHECK( mapper.ParseLayerName( "Solder Mask Top" ) == PADS_LAYER_TYPE::SOLDERMASK_TOP );
168 BOOST_CHECK( mapper.ParseLayerName( "SOLDERMASK TOP" ) == PADS_LAYER_TYPE::SOLDERMASK_TOP );
169 BOOST_CHECK( mapper.ParseLayerName( "SMT" ) == PADS_LAYER_TYPE::SOLDERMASK_TOP );
170 BOOST_CHECK( mapper.ParseLayerName( "Top Mask" ) == PADS_LAYER_TYPE::SOLDERMASK_TOP );
171
172 BOOST_CHECK( mapper.ParseLayerName( "Solder Mask Bottom" ) == PADS_LAYER_TYPE::SOLDERMASK_BOTTOM );
173 BOOST_CHECK( mapper.ParseLayerName( "SMB" ) == PADS_LAYER_TYPE::SOLDERMASK_BOTTOM );
174}
175
176
177BOOST_AUTO_TEST_CASE( ParseLayerName_Paste )
178{
179 PADS_LAYER_MAPPER mapper;
180
181 BOOST_CHECK( mapper.ParseLayerName( "Paste Top" ) == PADS_LAYER_TYPE::PASTE_TOP );
182 BOOST_CHECK( mapper.ParseLayerName( "Solder Paste Top" ) == PADS_LAYER_TYPE::PASTE_TOP );
183
184 BOOST_CHECK( mapper.ParseLayerName( "Paste Bottom" ) == PADS_LAYER_TYPE::PASTE_BOTTOM );
185}
186
187
188BOOST_AUTO_TEST_CASE( ParseLayerName_Assembly )
189{
190 PADS_LAYER_MAPPER mapper;
191
192 BOOST_CHECK( mapper.ParseLayerName( "Assembly Top" ) == PADS_LAYER_TYPE::ASSEMBLY_TOP );
193 BOOST_CHECK( mapper.ParseLayerName( "Top Assembly" ) == PADS_LAYER_TYPE::ASSEMBLY_TOP );
194 BOOST_CHECK( mapper.ParseLayerName( "ASSY TOP" ) == PADS_LAYER_TYPE::ASSEMBLY_TOP );
195
196 BOOST_CHECK( mapper.ParseLayerName( "Assembly Bottom" ) == PADS_LAYER_TYPE::ASSEMBLY_BOTTOM );
197}
198
199
200BOOST_AUTO_TEST_CASE( ParseLayerName_BoardOutline )
201{
202 PADS_LAYER_MAPPER mapper;
203
204 BOOST_CHECK( mapper.ParseLayerName( "Board Outline" ) == PADS_LAYER_TYPE::BOARD_OUTLINE );
205 BOOST_CHECK( mapper.ParseLayerName( "Board" ) == PADS_LAYER_TYPE::BOARD_OUTLINE );
206 BOOST_CHECK( mapper.ParseLayerName( "Outline" ) == PADS_LAYER_TYPE::BOARD_OUTLINE );
207}
208
209
210BOOST_AUTO_TEST_CASE( ParseLayerName_Copper )
211{
212 PADS_LAYER_MAPPER mapper;
213
214 // Pattern matching for copper layers
215 BOOST_CHECK( mapper.ParseLayerName( "Top" ) == PADS_LAYER_TYPE::COPPER_TOP );
216 BOOST_CHECK( mapper.ParseLayerName( "Layer 1" ) == PADS_LAYER_TYPE::COPPER_TOP );
217
218 BOOST_CHECK( mapper.ParseLayerName( "Bottom" ) == PADS_LAYER_TYPE::COPPER_BOTTOM );
219 BOOST_CHECK( mapper.ParseLayerName( "Bot" ) == PADS_LAYER_TYPE::COPPER_BOTTOM );
220
221 BOOST_CHECK( mapper.ParseLayerName( "Inner 1" ) == PADS_LAYER_TYPE::COPPER_INNER );
222 BOOST_CHECK( mapper.ParseLayerName( "Internal" ) == PADS_LAYER_TYPE::COPPER_INNER );
223 BOOST_CHECK( mapper.ParseLayerName( "Mid Layer" ) == PADS_LAYER_TYPE::COPPER_INNER );
224}
225
226
227BOOST_AUTO_TEST_CASE( ParseLayerName_Unknown )
228{
229 PADS_LAYER_MAPPER mapper;
230
231 BOOST_CHECK( mapper.ParseLayerName( "Random Name" ) == PADS_LAYER_TYPE::UNKNOWN );
232 BOOST_CHECK( mapper.ParseLayerName( "XYZ123" ) == PADS_LAYER_TYPE::UNKNOWN );
233}
234
235
236BOOST_AUTO_TEST_CASE( CustomLayerNameMapping )
237{
238 PADS_LAYER_MAPPER mapper;
239
240 // Add custom mapping
241 mapper.AddLayerNameMapping( "Custom Layer", PADS_LAYER_TYPE::DOCUMENTATION );
242
243 BOOST_CHECK( mapper.ParseLayerName( "Custom Layer" ) == PADS_LAYER_TYPE::DOCUMENTATION );
244 BOOST_CHECK( mapper.ParseLayerName( "CUSTOM LAYER" ) == PADS_LAYER_TYPE::DOCUMENTATION );
245}
246
247
248BOOST_AUTO_TEST_CASE( PermittedLayers )
249{
250 PADS_LAYER_MAPPER mapper;
251
252 // Copper layers should permit all copper
253 LSET copper_permitted = mapper.GetPermittedLayers( PADS_LAYER_TYPE::COPPER_TOP );
254 BOOST_CHECK( copper_permitted.Contains( F_Cu ) );
255 BOOST_CHECK( copper_permitted.Contains( B_Cu ) );
256 BOOST_CHECK( copper_permitted.Contains( In1_Cu ) );
257
258 // Silkscreen should permit silkscreen layers
260 BOOST_CHECK( silk_permitted.Contains( F_SilkS ) );
261 BOOST_CHECK( silk_permitted.Contains( B_SilkS ) );
262 BOOST_CHECK( !silk_permitted.Contains( F_Cu ) );
263
264 // Board outline should only permit Edge_Cuts
265 LSET outline_permitted = mapper.GetPermittedLayers( PADS_LAYER_TYPE::BOARD_OUTLINE );
266 BOOST_CHECK( outline_permitted.Contains( Edge_Cuts ) );
267 BOOST_CHECK( !outline_permitted.Contains( F_Cu ) );
268 BOOST_CHECK( !outline_permitted.Contains( F_SilkS ) );
269}
270
271
272BOOST_AUTO_TEST_CASE( BuildInputLayerDescriptions )
273{
274 PADS_LAYER_MAPPER mapper;
275 mapper.SetCopperLayerCount( 4 );
276
277 std::vector<PADS_LAYER_INFO> infos = {
278 { 1, "Top Copper", PADS_LAYER_TYPE::COPPER_TOP, true },
279 { 4, "Bottom Copper", PADS_LAYER_TYPE::COPPER_BOTTOM, true },
280 { 26, "Silkscreen Top", PADS_LAYER_TYPE::SILKSCREEN_TOP, false }
281 };
282
283 std::vector<INPUT_LAYER_DESC> descs = mapper.BuildInputLayerDescriptions( infos );
284
285 BOOST_CHECK_EQUAL( descs.size(), 3 );
286
287 BOOST_CHECK_EQUAL( descs[0].Name, wxT( "Top Copper" ) );
288 BOOST_CHECK_EQUAL( descs[0].AutoMapLayer, F_Cu );
289 BOOST_CHECK( descs[0].Required );
290
291 BOOST_CHECK_EQUAL( descs[1].Name, wxT( "Bottom Copper" ) );
292 BOOST_CHECK_EQUAL( descs[1].AutoMapLayer, B_Cu );
293 BOOST_CHECK( descs[1].Required );
294
295 BOOST_CHECK_EQUAL( descs[2].Name, wxT( "Silkscreen Top" ) );
296 BOOST_CHECK_EQUAL( descs[2].AutoMapLayer, F_SilkS );
297 BOOST_CHECK( !descs[2].Required );
298}
299
300
307
308
LSET is a set of PCB_LAYER_IDs.
Definition lset.h:37
bool Contains(PCB_LAYER_ID aLayer) const
See if the layer set contains a PCB layer.
Definition lset.h:63
Maps PADS layer numbers and names to KiCad layer IDs.
LSET GetPermittedLayers(PADS_LAYER_TYPE aType) const
Get the permitted KiCad layers for a given PADS layer type.
PADS_LAYER_TYPE ParseLayerName(const std::string &aLayerName) const
Parse a PADS layer name and return its type.
static constexpr int LAYER_ASSEMBLY_TOP
static constexpr int LAYER_SILKSCREEN_BOTTOM
static constexpr int LAYER_PASTE_TOP
static constexpr int LAYER_SILKSCREEN_TOP
PADS_LAYER_TYPE GetLayerType(int aPadsLayer) const
Parse a PADS layer number and return its type.
static constexpr int LAYER_SOLDERMASK_TOP
static constexpr int LAYER_ASSEMBLY_BOTTOM
PCB_LAYER_ID GetAutoMapLayer(int aPadsLayer, PADS_LAYER_TYPE aType=PADS_LAYER_TYPE::UNKNOWN) const
Get the suggested KiCad layer for a PADS layer.
static constexpr int LAYER_PAD_STACK_BOTTOM
Pad stack: Bottom copper.
static constexpr int LAYER_PAD_STACK_TOP
Pad stack: Top copper.
static constexpr int LAYER_PASTE_BOTTOM
static std::string LayerTypeToString(PADS_LAYER_TYPE aType)
Convert a layer type to a human-readable string.
void SetCopperLayerCount(int aLayerCount)
Set the total number of copper layers in the PADS design.
static constexpr int LAYER_PAD_STACK_INNER
Pad stack: Inner copper.
std::vector< INPUT_LAYER_DESC > BuildInputLayerDescriptions(const std::vector< PADS_LAYER_INFO > &aLayerInfos) const
Build a vector of INPUT_LAYER_DESC from parsed PADS layer information.
void AddLayerNameMapping(const std::string &aName, PADS_LAYER_TYPE aType)
Add or update a layer name to type mapping.
static constexpr int LAYER_SOLDERMASK_BOTTOM
@ Edge_Cuts
Definition layer_ids.h:108
@ F_Paste
Definition layer_ids.h:100
@ B_Mask
Definition layer_ids.h:94
@ B_Cu
Definition layer_ids.h:61
@ F_Mask
Definition layer_ids.h:93
@ B_Paste
Definition layer_ids.h:101
@ In2_Cu
Definition layer_ids.h:63
@ F_Fab
Definition layer_ids.h:115
@ F_SilkS
Definition layer_ids.h:96
@ In1_Cu
Definition layer_ids.h:62
@ B_SilkS
Definition layer_ids.h:97
@ F_Cu
Definition layer_ids.h:60
@ B_Fab
Definition layer_ids.h:114
BOOST_AUTO_TEST_CASE(HorizontalAlignment)
BOOST_AUTO_TEST_SUITE_END()
BOOST_AUTO_TEST_CASE(CopperLayerType_TwoLayer)
BOOST_CHECK_EQUAL(result, "25.4")