KiCad PCB EDA Suite
Loading...
Searching...
No Matches
test_drc_hole_to_hole_npth_slot_issue24541.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
46
47#include <algorithm>
48#include <set>
49#include <utility>
50
53
54#include <board.h>
56#include <footprint.h>
57#include <pad.h>
58#include <drc/drc_item.h>
59#include <drc/drc_engine.h>
62
63
65{
67
69 {
70 if( m_board && m_board->GetDesignSettings().m_DRCEngine )
71 m_board->GetDesignSettings().m_DRCEngine->ClearViolationHandler();
72
73 if( m_board )
74 {
75 m_board->SetProject( nullptr );
76 m_board = nullptr;
77 }
78 }
79
81 std::unique_ptr<BOARD> m_board;
82};
83
84
86{
87 KI_TEST::LoadBoard( m_settingsManager, "issue24541/issue24541", m_board );
88
89 BOOST_REQUIRE_MESSAGE( m_board, "Failed to load board issue24541" );
90 BOOST_REQUIRE_EQUAL( m_board->Footprints().size(), 2 );
91
92 // Confirm the fixture still carries two NPTH oval slots whose drill is a
93 // non-round slot (drill.x != drill.y); these are the holes the provider
94 // currently ignores.
95 int npthSlotCount = 0;
96
97 for( FOOTPRINT* fp : m_board->Footprints() )
98 {
99 for( PAD* pad : fp->Pads() )
100 {
101 if( pad->GetAttribute() == PAD_ATTRIB::NPTH
102 && pad->GetDrillSize().x != pad->GetDrillSize().y )
103 {
104 ++npthSlotCount;
105 }
106 }
107 }
108
109 BOOST_REQUIRE_MESSAGE( npthSlotCount == 2,
110 "Fixture changed: expected two NPTH oval slots." );
111
112 BOARD_DESIGN_SETTINGS& bds = m_board->GetDesignSettings();
113
114 BOOST_REQUIRE_MESSAGE( bds.m_DRCEngine, "DRC engine not initialized" );
115
116 for( int ii = DRCE_FIRST; ii <= DRCE_LAST; ++ii )
118
121
122 // Count only violations between the two NPTH oval slots, deduplicated by the pair of items
123 // involved. A bare >= 1 check could be satisfied by an unrelated hole pair in the fixture or
124 // by the same pair being reported twice, so we assert exactly one distinct slot-to-slot pair.
125 int holeToHoleCount = 0;
126 std::set<std::pair<KIID, KIID>> npthSlotPairs;
127
128 auto isNpthSlot =
129 []( const BOARD_ITEM* aItem ) -> bool
130 {
131 const PAD* pad = dynamic_cast<const PAD*>( aItem );
132
133 return pad && pad->GetAttribute() == PAD_ATTRIB::NPTH
134 && pad->GetDrillSize().x != pad->GetDrillSize().y;
135 };
136
138 [&]( const std::shared_ptr<DRC_ITEM>& aItem, const VECTOR2I& /*aPos*/, int /*aLayer*/,
139 const std::function<void( PCB_MARKER* )>& /*aPathGen*/ )
140 {
141 int code = aItem->GetErrorCode();
142
144 return;
145
146 ++holeToHoleCount;
147
148 BOARD_ITEM* itemA = m_board->ResolveItem( aItem->GetMainItemID(), true );
149 BOARD_ITEM* itemB = m_board->ResolveItem( aItem->GetAuxItemID(), true );
150
151 if( isNpthSlot( itemA ) && isNpthSlot( itemB ) )
152 npthSlotPairs.emplace( std::minmax( itemA->m_Uuid, itemB->m_Uuid ) );
153 } );
154
155 bds.m_DRCEngine->RunTests( EDA_UNITS::MM, true, false );
156
158
159 BOOST_TEST_MESSAGE( wxString::Format( "Hole-to-hole violations: %d; NPTH slot pairs: %d",
160 holeToHoleCount, (int) npthSlotPairs.size() ) );
161
162 // The two overlapping NPTH slots must produce exactly one distinct hole-to-hole violation.
163 BOOST_CHECK_EQUAL( npthSlotPairs.size(), 1 );
164}
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:80
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
void ClearViolationHandler()
Definition drc_engine.h:169
const KIID m_Uuid
Definition eda_item.h:531
Definition pad.h:61
@ DRCE_DRILLED_HOLES_TOO_CLOSE
Definition drc_item.h:49
@ DRCE_FIRST
Definition drc_item.h:35
@ DRCE_DRILLED_HOLES_COLOCATED
Definition drc_item.h:50
@ DRCE_LAST
Definition drc_item.h:120
void LoadBoard(SETTINGS_MANAGER &aSettingsManager, const wxString &aRelPath, std::unique_ptr< BOARD > &aBoard)
@ NPTH
like PAD_PTH, but not plated mechanical use only, no connection allowed
Definition padstack.h:103
@ RPT_SEVERITY_ERROR
@ RPT_SEVERITY_IGNORE
BOOST_FIXTURE_TEST_CASE(HoleToHoleNpthSlotIssue24541, DRC_HOLE_TO_HOLE_NPTH_SLOT_FIXTURE)
BOOST_TEST_MESSAGE("\n=== Real-World Polygon PIP Benchmark ===\n"<< formatTable(table))
BOOST_CHECK_EQUAL(result, "25.4")
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:683