KiCad PCB EDA Suite
Loading...
Searching...
No Matches
test_footprint_rescue_layer.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, you may find one here:
18 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
19 * or you may search the http://www.gnu.org website for the version 2 license,
20 * or you may write to the Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
22 */
23
25
26#include <footprint.h>
27#include <layer_ids.h>
28#include <layer_utils.h>
29#include <lset.h>
30#include <pad.h>
31#include <pcb_shape.h>
33
42BOOST_AUTO_TEST_SUITE( FootprintRescueLayer )
43
44
45BOOST_AUTO_TEST_CASE( OrphanLayerCheckIgnoresRescue )
46{
47 // Default allowed custom user layer set used by the Footprint Properties dialog when
48 // "Custom Layers" is off.
49 const LSET defaultCustomLayers =
51
52 // A footprint with only "clean" items on copper/tech layers must report no orphans.
53 {
54 FOOTPRINT footprint( nullptr );
55
56 PCB_SHAPE* shape = new PCB_SHAPE( &footprint );
57 shape->SetLayer( F_SilkS );
58 footprint.Add( shape );
59
60 LSET orphans = LAYER_UTILS::GetOrphanedFootprintLayers( footprint, defaultCustomLayers );
61 BOOST_TEST( orphans.none() );
62 }
63
64 // A footprint with an item on Rescue must NOT be reported as an orphan (it is handled
65 // by library-parity DRC, not by the properties dialog).
66 {
67 FOOTPRINT footprint( nullptr );
68
69 PCB_SHAPE* rescueShape = new PCB_SHAPE( &footprint );
70 rescueShape->SetLayer( Rescue );
71 footprint.Add( rescueShape );
72
73 LSET allLayers = LAYER_UTILS::GetAllFootprintLayers( footprint );
74 BOOST_TEST( allLayers.test( Rescue ) );
75
76 LSET orphans = LAYER_UTILS::GetOrphanedFootprintLayers( footprint, defaultCustomLayers );
77 BOOST_TEST( orphans.none() );
78 }
79
80 // An inner copper layer used by a footprint item is still correctly reported as an
81 // orphan when the custom user layer set excludes it.
82 {
83 FOOTPRINT footprint( nullptr );
84
85 PCB_SHAPE* copperShape = new PCB_SHAPE( &footprint );
86 copperShape->SetLayer( In1_Cu );
87 footprint.Add( copperShape );
88
89 LSET restrictive = LSET{ F_Cu, B_Cu };
90 LSET orphans = LAYER_UTILS::GetOrphanedFootprintLayers( footprint, restrictive );
91
92 BOOST_TEST( orphans.test( In1_Cu ) );
93 }
94
95 // Multi-layer items (PTH pads span all copper layers plus their masks) must be
96 // fully aggregated by GetAllFootprintLayers rather than collapsed to a single
97 // layer.
98 {
99 FOOTPRINT footprint( nullptr );
100
101 PAD* pthPad = new PAD( &footprint );
102 pthPad->SetAttribute( PAD_ATTRIB::PTH );
103 footprint.Add( pthPad );
104
105 LSET padLayers = pthPad->GetLayerSet();
106 LSET allLayers = LAYER_UTILS::GetAllFootprintLayers( footprint );
107
108 BOOST_TEST( ( allLayers & padLayers ) == padLayers );
109 }
110}
111
112
113BOOST_AUTO_TEST_CASE( Issue24045Footprint )
114{
115 // Load the exact footprint from the issue report. It contains graphic items on the
116 // Rescue layer. Loading must succeed and the orphan-layer validator must pass.
117 const std::string fpPath = KI_TEST::GetPcbnewTestDataDir() + "issue24045/"
118 + "QFN-24_L4.0-W4.0-P0.50-BL-EP2.6.kicad_mod";
119
120 std::unique_ptr<FOOTPRINT> fp = KI_TEST::ReadFootprintFromFileOrStream( fpPath );
121 BOOST_REQUIRE( fp );
122
123 LSET allLayers = LAYER_UTILS::GetAllFootprintLayers( *fp );
124 BOOST_TEST( allLayers.test( Rescue ),
125 "Issue footprint must exercise the Rescue layer for this test to be meaningful" );
126
127 const LSET defaultCustomLayers =
129
130 LSET orphans = LAYER_UTILS::GetOrphanedFootprintLayers( *fp, defaultCustomLayers );
131 BOOST_TEST( orphans.none(),
132 "Footprint properties dialog must not block saving when only Rescue items orphan" );
133}
134
135
General utilities for PCB file IO for QA programs.
void Add(BOARD_ITEM *aItem, ADD_MODE aMode=ADD_MODE::INSERT, bool aSkipConnectivity=false) override
Removes an item from the container.
LSET is a set of PCB_LAYER_IDs.
Definition lset.h:37
static LSET UserDefinedLayersMask(int aUserDefinedLayerCount=MAX_USER_DEFINED_LAYERS)
Return a mask with the requested number of user defined layers.
Definition lset.cpp:704
static const LSET & InternalCuMask()
Return a complete set of internal copper layers which is all Cu layers except F_Cu and B_Cu.
Definition lset.cpp:577
Definition pad.h:55
void SetAttribute(PAD_ATTRIB aAttribute)
Definition pad.cpp:1370
LSET GetLayerSet() const override
Return a std::bitset of all layers on which the item physically resides.
Definition pad.h:560
void SetLayer(PCB_LAYER_ID aLayer) override
Set the layer this item is on.
@ B_Cu
Definition layer_ids.h:65
@ F_SilkS
Definition layer_ids.h:100
@ In1_Cu
Definition layer_ids.h:66
@ Rescue
Definition layer_ids.h:121
@ F_Cu
Definition layer_ids.h:64
std::string GetPcbnewTestDataDir()
Utility which returns a path to the data directory where the test board files are stored.
std::unique_ptr< FOOTPRINT > ReadFootprintFromFileOrStream(const std::string &aFilename, std::istream &aFallback)
LSET GetAllFootprintLayers(const FOOTPRINT &aFootprint)
Return the union of layers referenced by every item inside the footprint (including graphic items,...
LSET GetOrphanedFootprintLayers(const FOOTPRINT &aFootprint, const LSET &aCustomUserLayers)
Compute the set of footprint-used layers that would be orphaned if the footprint's allowed layer set ...
@ PTH
Plated through hole pad.
Definition padstack.h:98
BOOST_AUTO_TEST_CASE(HorizontalAlignment)
BOOST_AUTO_TEST_SUITE(CadstarPartParser)
BOOST_AUTO_TEST_CASE(OrphanLayerCheckIgnoresRescue)
Regression test for https://gitlab.com/kicad/code/kicad/-/issues/24045.
BOOST_TEST(contains==c.ExpectedContains)
BOOST_REQUIRE(intersection.has_value()==c.ExpectedIntersection.has_value())
BOOST_AUTO_TEST_SUITE_END()