KiCad PCB EDA Suite
Loading...
Searching...
No Matches
test_drc_solder_mask_expansion.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
26#include <board.h>
28#include <pad.h>
29#include <footprint.h>
30#include <drc/drc_engine.h>
32
33
42
43
45{
46 // This test verifies that footprint-level solder mask expansion override is correctly
47 // applied to pads that don't have their own local override.
48 // Regression test for https://gitlab.com/kicad/code/kicad/-/issues/22751
49
50 KI_TEST::LoadBoard( m_settingsManager, "issue22751/issue22751", m_board );
51
52 BOARD_DESIGN_SETTINGS& bds = m_board->GetDesignSettings();
53 bds.m_DRCEngine->InitEngine( wxFileName() );
54
55 // Board default solder mask expansion is 0.05mm (50000 IU)
57
58 // Find footprints and their pads
59 PAD* padWithFootprintMargin = nullptr;
60 PAD* padWithNoMargin = nullptr;
61 PAD* padWithOwnMargin = nullptr;
62
63 for( FOOTPRINT* fp : m_board->Footprints() )
64 {
65 if( fp->GetFPIDAsString() == "TestFootprint_WithSolderMaskMargin" )
66 {
67 // Footprint has solder mask margin of 0.1mm (100000 IU)
68 BOOST_CHECK( fp->GetLocalSolderMaskMargin().has_value() );
69 BOOST_CHECK_EQUAL( fp->GetLocalSolderMaskMargin().value(), 100000 );
70
71 for( PAD* pad : fp->Pads() )
72 {
73 if( pad->GetNumber() == "1" )
74 {
75 padWithFootprintMargin = pad;
76
77 // Pad should NOT have its own local margin
78 BOOST_CHECK( !pad->GetLocalSolderMaskMargin().has_value() );
79 }
80 }
81 }
82 else if( fp->GetFPIDAsString() == "TestFootprint_NoSolderMaskMargin" )
83 {
84 // Footprint has no solder mask margin
85 BOOST_CHECK( !fp->GetLocalSolderMaskMargin().has_value() );
86
87 for( PAD* pad : fp->Pads() )
88 {
89 if( pad->GetNumber() == "1" )
90 padWithNoMargin = pad;
91 }
92 }
93 else if( fp->GetFPIDAsString() == "TestFootprint_PadOverridesSolderMaskMargin" )
94 {
95 // Footprint has solder mask margin of 0.1mm
96 BOOST_CHECK( fp->GetLocalSolderMaskMargin().has_value() );
97 BOOST_CHECK_EQUAL( fp->GetLocalSolderMaskMargin().value(), 100000 );
98
99 for( PAD* pad : fp->Pads() )
100 {
101 if( pad->GetNumber() == "1" )
102 {
103 padWithOwnMargin = pad;
104
105 // Pad has its own margin of 0.2mm (200000 IU)
106 BOOST_CHECK( pad->GetLocalSolderMaskMargin().has_value() );
107 BOOST_CHECK_EQUAL( pad->GetLocalSolderMaskMargin().value(), 200000 );
108 }
109 }
110 }
111 }
112
113 BOOST_REQUIRE( padWithFootprintMargin != nullptr );
114 BOOST_REQUIRE( padWithNoMargin != nullptr );
115 BOOST_REQUIRE( padWithOwnMargin != nullptr );
116
117 // Test GetSolderMaskExpansion which uses the DRC engine to evaluate the constraint
118
119 // Pad in footprint with solder mask margin should use footprint's margin (0.1mm = 100000 IU)
120 int expansionWithFpMargin = padWithFootprintMargin->GetSolderMaskExpansion( F_Mask );
121 BOOST_CHECK_EQUAL( expansionWithFpMargin, 100000 );
122
123 // Pad in footprint without solder mask margin should use board default (0.05mm = 50000 IU)
124 int expansionNoMargin = padWithNoMargin->GetSolderMaskExpansion( F_Mask );
125 BOOST_CHECK_EQUAL( expansionNoMargin, 50000 );
126
127 // Pad with its own solder mask margin should use pad's margin (0.2mm = 200000 IU),
128 // overriding the footprint's margin
129 int expansionWithPadMargin = padWithOwnMargin->GetSolderMaskExpansion( F_Mask );
130 BOOST_CHECK_EQUAL( expansionWithPadMargin, 200000 );
131}
Container for design settings for a BOARD object.
std::shared_ptr< DRC_ENGINE > m_DRCEngine
void InitEngine(const wxFileName &aRulePath)
Initialize the DRC engine.
Definition pad.h:55
int GetSolderMaskExpansion(PCB_LAYER_ID aLayer) const
Definition pad.cpp:1603
@ F_Mask
Definition layer_ids.h:97
void LoadBoard(SETTINGS_MANAGER &aSettingsManager, const wxString &aRelPath, std::unique_ptr< BOARD > &aBoard)
BOOST_FIXTURE_TEST_CASE(FootprintLevelSolderMaskExpansion, DRC_SOLDER_MASK_EXPANSION_TEST_FIXTURE)
BOOST_REQUIRE(intersection.has_value()==c.ExpectedIntersection.has_value())
BOOST_CHECK_EQUAL(result, "25.4")