KiCad PCB EDA Suite
Loading...
Searching...
No Matches
test_drc_annular_overlap_issue24340.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
49
52
53#include <board.h>
55#include <base_units.h>
56#include <drc/drc_item.h>
57#include <drc/drc_engine.h>
60
61
63{
65
67 {
68 if( m_board && m_board->GetDesignSettings().m_DRCEngine )
69 m_board->GetDesignSettings().m_DRCEngine->ClearViolationHandler();
70
71 if( m_board )
72 {
73 m_board->SetProject( nullptr );
74 m_board = nullptr;
75 }
76 }
77
79 std::unique_ptr<BOARD> m_board;
80};
81
82
84{
85 KI_TEST::LoadBoard( m_settingsManager, "issue24340/issue24340", m_board );
86
87 BOOST_REQUIRE_MESSAGE( m_board, "Failed to load board issue24340" );
88
89 struct Violation
90 {
91 std::shared_ptr<DRC_ITEM> item;
92 VECTOR2I pos;
93 };
94
95 std::vector<Violation> annularViolations;
96 BOARD_DESIGN_SETTINGS& bds = m_board->GetDesignSettings();
97
98 BOOST_REQUIRE_MESSAGE( bds.m_DRCEngine, "DRC engine not initialized" );
99
100 for( int ii = DRCE_FIRST; ii <= DRCE_LAST; ++ii )
102
104
106 [&]( const std::shared_ptr<DRC_ITEM>& aItem, const VECTOR2I& aPos, int /*aLayer*/,
107 const std::function<void( PCB_MARKER* )>& /*aPathGen*/ )
108 {
109 if( aItem->GetErrorCode() == DRCE_ANNULAR_WIDTH )
110 annularViolations.push_back( { aItem, aPos } );
111 } );
112
113 bds.m_DRCEngine->RunTests( EDA_UNITS::MM, true, false );
114
116
117 BOOST_TEST_MESSAGE( wxString::Format( "Annular violations: %d", (int) annularViolations.size() ) );
118
119 // Bug-case THT board position: footprint (130, 95.5) + pad (-1.4, 0) = (128.6, 95.5).
120 // Control THT board position: footprint (176, 95.5) + pad (-1.4, 0) = (174.6, 95.5).
121 const VECTOR2I bugPos = VECTOR2I( pcbIUScale.mmToIU( 128.6 ), pcbIUScale.mmToIU( 95.5 ) );
122 const VECTOR2I controlPos = VECTOR2I( pcbIUScale.mmToIU( 174.6 ), pcbIUScale.mmToIU( 95.5 ) );
123 const int tol = pcbIUScale.mmToIU( 0.5 );
124
125 int onBugFootprint = 0;
126 int onControlFootprint = 0;
127
128 for( const Violation& v : annularViolations )
129 {
130 if( std::abs( v.pos.x - bugPos.x ) < tol && std::abs( v.pos.y - bugPos.y ) < tol )
131 ++onBugFootprint;
132 else if( std::abs( v.pos.x - controlPos.x ) < tol && std::abs( v.pos.y - controlPos.y ) < tol )
133 ++onControlFootprint;
134 }
135
136 // Bug-case pad: exact annular 0.1524 mm meets the 0.1524 mm constraint. The
137 // pre-fix polygon path under-reported it by ~maxError and falsely flagged.
138 BOOST_CHECK_EQUAL( onBugFootprint, 0 );
139
140 // Control pad: 0.1 mm annular is genuinely below the constraint. The fix
141 // must still report this -- guards against the optimization swallowing
142 // real violations.
143 BOOST_CHECK_EQUAL( onControlFootprint, 1 );
144}
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
@ DRCE_FIRST
Definition drc_item.h:35
@ DRCE_LAST
Definition drc_item.h:121
@ DRCE_ANNULAR_WIDTH
Definition drc_item.h:55
void LoadBoard(SETTINGS_MANAGER &aSettingsManager, const wxString &aRelPath, std::unique_ptr< BOARD > &aBoard)
EDA_ANGLE abs(const EDA_ANGLE &aAngle)
Definition eda_angle.h:400
@ RPT_SEVERITY_ERROR
@ RPT_SEVERITY_IGNORE
BOOST_FIXTURE_TEST_CASE(AnnularOverlapIssue24340, DRC_ANNULAR_OVERLAP_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