KiCad PCB EDA Suite
Loading...
Searching...
No Matches
test_drc_npth_slot_clearance_issue24799.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
32
35
36#include <base_units.h>
37#include <board.h>
40#include <footprint.h>
41#include <pad.h>
42#include <zone.h>
43#include <drc/drc_item.h>
44#include <drc/drc_engine.h>
47
48
50{
52
54 {
55 if( m_board && m_board->GetDesignSettings().m_DRCEngine )
56 m_board->GetDesignSettings().m_DRCEngine->ClearViolationHandler();
57
58 if( m_board )
59 {
60 m_board->SetProject( nullptr );
61 m_board = nullptr;
62 }
63 }
64
66 std::unique_ptr<BOARD> m_board;
67};
68
69
71{
72 KI_TEST::LoadBoard( m_settingsManager, "issue24799/issue24799", m_board );
73
74 BOOST_REQUIRE_MESSAGE( m_board, "Failed to load board issue24799" );
75
76 PAD* slotPad = nullptr;
77 PAD* roundPad = nullptr;
78
79 for( FOOTPRINT* footprint : m_board->Footprints() )
80 {
81 for( PAD* pad : footprint->Pads() )
82 {
83 if( pad->GetAttribute() != PAD_ATTRIB::NPTH || !pad->HasHole() )
84 continue;
85
86 if( pad->GetDrillSizeX() != pad->GetDrillSizeY() )
87 slotPad = pad;
88 else
89 roundPad = pad;
90 }
91 }
92
93 BOOST_REQUIRE_MESSAGE( slotPad, "Fixture must contain an oblong NPTH pad" );
94 BOOST_REQUIRE_MESSAGE( roundPad, "Fixture must contain a round NPTH pad" );
95
96 KI_TEST::FillZones( m_board.get() );
97
98 BOOST_REQUIRE_EQUAL( m_board->Zones().size(), 1 );
99
100 const std::shared_ptr<SHAPE_POLY_SET>& fill = m_board->Zones().front()->GetFilledPolysList( F_Cu );
101
102 BOOST_REQUIRE( fill && fill->OutlineCount() > 0 );
103
104 const int searchDist = pcbIUScale.mmToIU( 2.0 );
105 const int minGap = pcbIUScale.mmToIU( 0.2 );
106 const int maxGap = pcbIUScale.mmToIU( 0.5 );
107
108 for( PAD* pad : { roundPad, slotPad } )
109 {
110 int actual = 0;
111
112 BOOST_REQUIRE_MESSAGE( fill->Collide( pad->GetEffectiveHoleShape().get(), searchDist, &actual ),
113 "No fill within 2 mm of the hole, standoff is far too large" );
114
115 BOOST_TEST_MESSAGE( wxString::Format( "Fill standoff from %s hole: %.3f mm",
116 pad->GetDrillSizeX() == pad->GetDrillSizeY() ? wxString( "round" )
117 : wxString( "oblong" ),
118 pcbIUScale.IUTomm( actual ) ) );
119
120 // both holes should get the 0.25 mm hole clearance, not the 1 mm edge clearance
121 BOOST_CHECK_GE( actual, minGap );
122 BOOST_CHECK_LE( actual, maxGap );
123 }
124
125 BOARD_DESIGN_SETTINGS& bds = m_board->GetDesignSettings();
126
127 BOOST_REQUIRE_MESSAGE( bds.m_DRCEngine, "DRC engine not initialized" );
128
129 for( int ii = DRCE_FIRST; ii <= DRCE_LAST; ++ii )
131
134
135 int edgeClearanceCount = 0;
136 int holeClearanceCount = 0;
137
139 [&]( const std::shared_ptr<DRC_ITEM>& aItem, const VECTOR2I& /*aPos*/, int /*aLayer*/,
140 const std::function<void( PCB_MARKER* )>& /*aPathGen*/ )
141 {
142 if( aItem->GetErrorCode() == DRCE_EDGE_CLEARANCE )
143 ++edgeClearanceCount;
144 else if( aItem->GetErrorCode() == DRCE_HOLE_CLEARANCE )
145 ++holeClearanceCount;
146 } );
147
148 bds.m_DRCEngine->RunTests( EDA_UNITS::MM, true, false );
149
151
152 BOOST_TEST_MESSAGE( wxString::Format( "Edge clearance violations: %d, hole clearance: %d", edgeClearanceCount,
153 holeClearanceCount ) );
154
155 // the track is 0.5 mm from the slot wall, legal against the 0.25 mm hole clearance
156 BOOST_CHECK_EQUAL( edgeClearanceCount, 0 );
157 BOOST_CHECK_EQUAL( holeClearanceCount, 0 );
158}
constexpr EDA_IU_SCALE pcbIUScale
Definition base_units.h:121
Container for design settings for a BOARD object.
std::map< int, SEVERITY > m_DRCSeverities
std::shared_ptr< DRC_ENGINE > m_DRCEngine
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
Definition pad.h:61
@ DRCE_HOLE_CLEARANCE
Definition drc_item.h:52
@ DRCE_EDGE_CLEARANCE
Definition drc_item.h:44
@ DRCE_FIRST
Definition drc_item.h:36
@ DRCE_LAST
Definition drc_item.h:122
@ F_Cu
Definition layer_ids.h:60
void LoadBoard(SETTINGS_MANAGER &aSettingsManager, const wxString &aRelPath, std::unique_ptr< BOARD > &aBoard)
void FillZones(BOARD *m_board)
@ 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(NpthSlotClearanceIssue24799, NPTH_SLOT_CLEARANCE_FIXTURE)
BOOST_REQUIRE(intersection.has_value()==c.ExpectedIntersection.has_value())
BOOST_TEST_MESSAGE("\n=== Real-World Polygon PIP Benchmark ===\n"<< formatTable(table))
int actual
BOOST_CHECK_EQUAL(result, "25.4")
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:683