KiCad PCB EDA Suite
Loading...
Searching...
No Matches
test_solder_mask_track_to_pad.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
33
36#include <board.h>
38#include <pcb_track.h>
39#include <drc/drc_item.h>
41#include <kiid.h>
42
43
52
53
55{
56 // Test board has:
57 // - A pad on B.Cu with B.Mask at position (100, 100) on net "netA"
58 // - A track on B.Cu at x=100.6 (0.6mm from pad center) on net "netB"
59 // - SolderMaskToCopperClearance set to 1.0mm
60 //
61 // The track is 0.6mm from the pad center. With a 1mm pad and 0.05mm mask expansion,
62 // the pad edge is at 100.5mm and mask aperture edge is at 100.55mm.
63 // The track (0.2mm wide) has its nearest edge at 100.5mm.
64 //
65 // The track copper is within the SolderMaskToCopperClearance of the pad's mask aperture,
66 // so a violation should be reported.
67
68 wxString brd_name( wxT( "soldermask_track_to_pad" ) );
69 KI_TEST::LoadBoard( m_settingsManager, brd_name, m_board );
70
71 std::vector<DRC_ITEM> violations;
72 BOARD_DESIGN_SETTINGS& bds = m_board->GetDesignSettings();
73
74 // Verify the clearance is set
75 BOOST_TEST_MESSAGE( wxString::Format( "SolderMaskToCopperClearance: %d nm",
77
78 // Disable DRC tests not relevant to this test
84
86 [&]( const std::shared_ptr<DRC_ITEM>& aItem, const VECTOR2I& aPos, int aLayer,
87 const std::function<void( PCB_MARKER* )>& aPathGenerator )
88 {
89 if( aItem->GetErrorCode() == DRCE_SOLDERMASK_BRIDGE )
90 violations.push_back( *aItem );
91 } );
92
93 // Run DRC
94 bds.m_DRCEngine->RunTests( EDA_UNITS::MM, true /* aReportAllTrackErrors */, false );
95
96 BOOST_TEST_MESSAGE( wxString::Format( "Found %zu soldermask bridge violations",
97 violations.size() ) );
98
99 // We expect at least one violation: track from netB is within clearance of pad from netA
100 BOOST_CHECK_GE( violations.size(), 1 );
101
102 // Verify the violation involves the track by checking item IDs in the cache
103 bool foundTrackViolation = false;
104 const auto& itemCache = m_board->GetItemByIdCache();
105
106 for( const DRC_ITEM& item : violations )
107 {
108 KIID mainId = item.GetMainItemID();
109 KIID auxId = item.GetAuxItemID();
110
111 BOARD_ITEM* mainItem = nullptr;
112 BOARD_ITEM* auxItem = nullptr;
113
114 if( mainId != niluuid )
115 {
116 auto it = itemCache.find( mainId );
117
118 if( it != itemCache.end() )
119 mainItem = it->second;
120 }
121
122 if( auxId != niluuid )
123 {
124 auto it = itemCache.find( auxId );
125
126 if( it != itemCache.end() )
127 auxItem = it->second;
128 }
129
130 BOOST_TEST_MESSAGE( wxString::Format( "Violation: main=%s aux=%s",
131 mainItem ? mainItem->GetClass() : wxString( "null" ),
132 auxItem ? auxItem->GetClass() : wxString( "null" ) ) );
133
134 if( ( mainItem && mainItem->Type() == PCB_TRACE_T ) ||
135 ( auxItem && auxItem->Type() == PCB_TRACE_T ) )
136 {
137 foundTrackViolation = true;
138 }
139 }
140
141 BOOST_CHECK_MESSAGE( foundTrackViolation, "Expected to find a track-to-pad soldermask violation" );
142}
Container for design settings for a BOARD object.
std::map< int, SEVERITY > m_DRCSeverities
std::shared_ptr< DRC_ENGINE > m_DRCEngine
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition board_item.h:83
void RunTests(EDA_UNITS aUnits, bool aReportAllTrackErrors, bool aTestFootprints, BOARD_COMMIT *aCommit=nullptr)
Run the DRC tests.
void SetViolationHandler(DRC_VIOLATION_HANDLER aHandler)
Set an optional DRC violation handler (receives DRC_ITEMs and positions).
Definition drc_engine.h:168
KICAD_T Type() const
Returns the type of object.
Definition eda_item.h:110
virtual wxString GetClass() const =0
Return the class name.
Definition kiid.h:49
@ DRCE_LIB_FOOTPRINT_ISSUES
Definition drc_item.h:83
@ DRCE_STARVED_THERMAL
Definition drc_item.h:50
@ DRCE_COPPER_SLIVER
Definition drc_item.h:93
@ DRCE_SOLDERMASK_BRIDGE
Definition drc_item.h:94
@ DRCE_SILK_CLEARANCE
Definition drc_item.h:100
@ DRCE_LIB_FOOTPRINT_MISMATCH
Definition drc_item.h:84
KIID niluuid(0)
void LoadBoard(SETTINGS_MANAGER &aSettingsManager, const wxString &aRelPath, std::unique_ptr< BOARD > &aBoard)
@ RPT_SEVERITY_IGNORE
BOOST_TEST_MESSAGE("Polyline has "<< chain.PointCount()<< " points")
BOOST_FIXTURE_TEST_CASE(DRCTrackToPadBridgeTest, DRC_TRACK_TO_PAD_BRIDGE_FIXTURE)
@ PCB_TRACE_T
class PCB_TRACK, a track segment (segment on a copper layer)
Definition typeinfo.h:96
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:695