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, see <https://www.gnu.org/licenses/>.
18 */
19
29
32#include <board.h>
34#include <drc/drc_engine.h>
35#include <pcb_track.h>
36#include <drc/drc_engine.h>
37#include <drc/drc_item.h>
39#include <kiid.h>
40
41
50
51
53{
54 // Test board has:
55 // - A pad on B.Cu with B.Mask at position (100, 100) on net "netA"
56 // - A track on B.Cu at x=100.6 (0.6mm from pad center) on net "netB"
57 // - SolderMaskToCopperClearance set to 1.0mm
58 //
59 // The track is 0.6mm from the pad center. With a 1mm pad and 0.05mm mask expansion,
60 // the pad edge is at 100.5mm and mask aperture edge is at 100.55mm.
61 // The track (0.2mm wide) has its nearest edge at 100.5mm.
62 //
63 // The track copper is within the SolderMaskToCopperClearance of the pad's mask aperture,
64 // so a violation should be reported.
65
66 wxString brd_name( wxT( "soldermask_track_to_pad" ) );
67 KI_TEST::LoadBoard( m_settingsManager, brd_name, m_board );
68
69 std::vector<DRC_ITEM> violations;
70 BOARD_DESIGN_SETTINGS& bds = m_board->GetDesignSettings();
71
72 // Verify the clearance is set
73 BOOST_TEST_MESSAGE( wxString::Format( "SolderMaskToCopperClearance: %d nm",
75
76 // Disable DRC tests not relevant to this test
82
84 [&]( const std::shared_ptr<DRC_ITEM>& aItem, const VECTOR2I& aPos, int aLayer,
85 const std::function<void( PCB_MARKER* )>& aPathGenerator )
86 {
87 if( aItem->GetErrorCode() == DRCE_SOLDERMASK_BRIDGE )
88 violations.push_back( *aItem );
89 } );
90
91 // Run DRC
92 bds.m_DRCEngine->RunTests( EDA_UNITS::MM, true /* aReportAllTrackErrors */, false );
93
94 BOOST_TEST_MESSAGE( wxString::Format( "Found %zu soldermask bridge violations",
95 violations.size() ) );
96
97 // We expect at least one violation: track from netB is within clearance of pad from netA
98 BOOST_CHECK_GE( violations.size(), 1 );
99
100 // Verify the violation involves the track by checking item IDs in the cache
101 bool foundTrackViolation = false;
102 const auto& itemCache = m_board->GetItemByIdCache();
103
104 for( const DRC_ITEM& item : violations )
105 {
106 KIID mainId = item.GetMainItemID();
107 KIID auxId = item.GetAuxItemID();
108
109 BOARD_ITEM* mainItem = nullptr;
110 BOARD_ITEM* auxItem = nullptr;
111
112 if( mainId != niluuid )
113 {
114 auto it = itemCache.find( mainId );
115
116 if( it != itemCache.end() )
117 mainItem = it->second;
118 }
119
120 if( auxId != niluuid )
121 {
122 auto it = itemCache.find( auxId );
123
124 if( it != itemCache.end() )
125 auxItem = it->second;
126 }
127
128 BOOST_TEST_MESSAGE( wxString::Format( "Violation: main=%s aux=%s",
129 mainItem ? mainItem->GetClass() : wxString( "null" ),
130 auxItem ? auxItem->GetClass() : wxString( "null" ) ) );
131
132 if( ( mainItem && mainItem->Type() == PCB_TRACE_T ) ||
133 ( auxItem && auxItem->Type() == PCB_TRACE_T ) )
134 {
135 foundTrackViolation = true;
136 }
137 }
138
139 BOOST_CHECK_MESSAGE( foundTrackViolation, "Expected to find a track-to-pad soldermask violation" );
140}
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:81
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:164
KICAD_T Type() const
Returns the type of object.
Definition eda_item.h:108
virtual wxString GetClass() const =0
Return the class name.
Definition kiid.h:44
@ DRCE_LIB_FOOTPRINT_ISSUES
Definition drc_item.h:79
@ DRCE_STARVED_THERMAL
Definition drc_item.h:46
@ DRCE_COPPER_SLIVER
Definition drc_item.h:90
@ DRCE_SOLDERMASK_BRIDGE
Definition drc_item.h:91
@ DRCE_SILK_CLEARANCE
Definition drc_item.h:97
@ DRCE_LIB_FOOTPRINT_MISMATCH
Definition drc_item.h:80
KIID niluuid(0)
void LoadBoard(SETTINGS_MANAGER &aSettingsManager, const wxString &aRelPath, std::unique_ptr< BOARD > &aBoard)
@ RPT_SEVERITY_IGNORE
BOOST_CHECK_MESSAGE(totalMismatches==0, std::to_string(totalMismatches)+" board(s) with strategy disagreements")
BOOST_TEST_MESSAGE("\n=== Real-World Polygon PIP Benchmark ===\n"<< formatTable(table))
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:89
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:683