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