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 // A name that merely contains one of the words above is not copper. "Top Overlay" is
226 // silkscreen rather than unknown because the exact-name table is consulted first.
227 BOOST_CHECK( mapper.ParseLayerName( "Top Overlay" ) == PADS_LAYER_TYPE::SILKSCREEN_TOP );
228 BOOST_CHECK( mapper.ParseLayerName( "Top Notes" ) == PADS_LAYER_TYPE::UNKNOWN );
229 BOOST_CHECK( mapper.ParseLayerName( "Topology" ) == PADS_LAYER_TYPE::UNKNOWN );
230 BOOST_CHECK( mapper.ParseLayerName( "Bot Assy Text" ) == PADS_LAYER_TYPE::UNKNOWN );
231
232 // Ordinary PADS copper layer names. A binary file that under-reports its layer count has only
233 // the name to go on, and an unrecognised one lands on Dwgs_User.
234 BOOST_CHECK( mapper.ParseLayerName( "Top Copper" ) == PADS_LAYER_TYPE::COPPER_TOP );
235 BOOST_CHECK( mapper.ParseLayerName( "Top Layer" ) == PADS_LAYER_TYPE::COPPER_TOP );
236 BOOST_CHECK( mapper.ParseLayerName( "Bottom Copper" ) == PADS_LAYER_TYPE::COPPER_BOTTOM );
237 BOOST_CHECK( mapper.ParseLayerName( "Bottom Layer" ) == PADS_LAYER_TYPE::COPPER_BOTTOM );
238 BOOST_CHECK( mapper.ParseLayerName( "Bot Cu" ) == PADS_LAYER_TYPE::COPPER_BOTTOM );
239
240 BOOST_CHECK( mapper.ParseLayerName( "Internal 1" ) == PADS_LAYER_TYPE::COPPER_INNER );
241 BOOST_CHECK( mapper.ParseLayerName( "Inner1" ) == PADS_LAYER_TYPE::COPPER_INNER );
242 BOOST_CHECK( mapper.ParseLayerName( "Mid1" ) == PADS_LAYER_TYPE::COPPER_INNER );
243 BOOST_CHECK( mapper.ParseLayerName( "Inner" ) == PADS_LAYER_TYPE::COPPER_INNER );
244
245 BOOST_CHECK( mapper.ParseLayerName( "Internally Routed" ) == PADS_LAYER_TYPE::UNKNOWN );
246 BOOST_CHECK( mapper.ParseLayerName( "Middle East Notes" ) == PADS_LAYER_TYPE::UNKNOWN );
247}
248
249
250BOOST_AUTO_TEST_CASE( ParseLayerName_Unknown )
251{
252 PADS_LAYER_MAPPER mapper;
253
254 BOOST_CHECK( mapper.ParseLayerName( "Random Name" ) == PADS_LAYER_TYPE::UNKNOWN );
255 BOOST_CHECK( mapper.ParseLayerName( "XYZ123" ) == PADS_LAYER_TYPE::UNKNOWN );
256}
257
258
259BOOST_AUTO_TEST_CASE( CustomLayerNameMapping )
260{
261 PADS_LAYER_MAPPER mapper;
262
263 // Add custom mapping
264 mapper.AddLayerNameMapping( "Custom Layer", PADS_LAYER_TYPE::DOCUMENTATION );
265
266 BOOST_CHECK( mapper.ParseLayerName( "Custom Layer" ) == PADS_LAYER_TYPE::DOCUMENTATION );
267 BOOST_CHECK( mapper.ParseLayerName( "CUSTOM LAYER" ) == PADS_LAYER_TYPE::DOCUMENTATION );
268}
269
270
271BOOST_AUTO_TEST_CASE( PermittedLayers )
272{
273 PADS_LAYER_MAPPER mapper;
274
275 // Copper layers should permit all copper
276 LSET copper_permitted = mapper.GetPermittedLayers( PADS_LAYER_TYPE::COPPER_TOP );
277 BOOST_CHECK( copper_permitted.Contains( F_Cu ) );
278 BOOST_CHECK( copper_permitted.Contains( B_Cu ) );
279 BOOST_CHECK( copper_permitted.Contains( In1_Cu ) );
280
281 // Silkscreen should permit silkscreen layers
283 BOOST_CHECK( silk_permitted.Contains( F_SilkS ) );
284 BOOST_CHECK( silk_permitted.Contains( B_SilkS ) );
285 BOOST_CHECK( !silk_permitted.Contains( F_Cu ) );
286
287 // Board outline should only permit Edge_Cuts
288 LSET outline_permitted = mapper.GetPermittedLayers( PADS_LAYER_TYPE::BOARD_OUTLINE );
289 BOOST_CHECK( outline_permitted.Contains( Edge_Cuts ) );
290 BOOST_CHECK( !outline_permitted.Contains( F_Cu ) );
291 BOOST_CHECK( !outline_permitted.Contains( F_SilkS ) );
292}
293
294
295BOOST_AUTO_TEST_CASE( BuildInputLayerDescriptions )
296{
297 PADS_LAYER_MAPPER mapper;
298 mapper.SetCopperLayerCount( 4 );
299
300 std::vector<PADS_LAYER_INFO> infos = {
301 { 1, "Top Copper", PADS_LAYER_TYPE::COPPER_TOP, true },
302 { 4, "Bottom Copper", PADS_LAYER_TYPE::COPPER_BOTTOM, true },
303 { 26, "Silkscreen Top", PADS_LAYER_TYPE::SILKSCREEN_TOP, false }
304 };
305
306 std::vector<INPUT_LAYER_DESC> descs = mapper.BuildInputLayerDescriptions( infos );
307
308 BOOST_CHECK_EQUAL( descs.size(), 3 );
309
310 BOOST_CHECK_EQUAL( descs[0].Name, wxT( "Top Copper" ) );
311 BOOST_CHECK_EQUAL( descs[0].AutoMapLayer, F_Cu );
312 BOOST_CHECK( descs[0].Required );
313
314 BOOST_CHECK_EQUAL( descs[1].Name, wxT( "Bottom Copper" ) );
315 BOOST_CHECK_EQUAL( descs[1].AutoMapLayer, B_Cu );
316 BOOST_CHECK( descs[1].Required );
317
318 BOOST_CHECK_EQUAL( descs[2].Name, wxT( "Silkscreen Top" ) );
319 BOOST_CHECK_EQUAL( descs[2].AutoMapLayer, F_SilkS );
320 BOOST_CHECK( !descs[2].Required );
321}
322
323
330
331
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
PADS_LAYER_TYPE ParseLayerName(const std::string &aLayerName) const
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
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
Suggested KiCad layer for a PADS layer.
static constexpr int LAYER_PAD_STACK_BOTTOM
static constexpr int LAYER_PAD_STACK_TOP
static constexpr int LAYER_PASTE_BOTTOM
static std::string LayerTypeToString(PADS_LAYER_TYPE aType)
void SetCopperLayerCount(int aLayerCount)
static constexpr int LAYER_PAD_STACK_INNER
std::vector< INPUT_LAYER_DESC > BuildInputLayerDescriptions(const std::vector< PADS_LAYER_INFO > &aLayerInfos) const
void AddLayerNameMapping(const std::string &aName, PADS_LAYER_TYPE aType)
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")