KiCad PCB EDA Suite
Loading...
Searching...
No Matches
test_drc_creepage_issue23389.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
30
33
34#include <board.h>
36#include <drc/drc_item.h>
37#include <drc/drc_engine.h>
40
41
43{
45
47 {
48 if( m_board && m_board->GetDesignSettings().m_DRCEngine )
49 m_board->GetDesignSettings().m_DRCEngine->ClearViolationHandler();
50
51 if( m_board )
52 {
53 m_board->SetProject( nullptr );
54 m_board = nullptr;
55 }
56 }
57
59 std::unique_ptr<BOARD> m_board;
60};
61
62
64{
65 KI_TEST::LoadBoard( m_settingsManager, "issue23389/issue23389", m_board );
66
67 BOOST_REQUIRE_MESSAGE( m_board, "Failed to load board issue23389" );
68
69 std::vector<std::shared_ptr<DRC_ITEM>> violations;
70 BOARD_DESIGN_SETTINGS& bds = m_board->GetDesignSettings();
71
72 BOOST_REQUIRE_MESSAGE( bds.m_DRCEngine, "DRC engine not initialized" );
73
74 for( int ii = DRCE_FIRST; ii <= DRCE_LAST; ++ii )
76
78
80 [&]( const std::shared_ptr<DRC_ITEM>& aItem, const VECTOR2I& aPos, int aLayer,
81 const std::function<void( PCB_MARKER* )>& aPathGenerator )
82 {
83 if( bds.GetSeverity( aItem->GetErrorCode() ) == SEVERITY::RPT_SEVERITY_ERROR )
84 violations.push_back( aItem );
85 } );
86
87 bds.m_DRCEngine->RunTests( EDA_UNITS::MM, true, false );
88
90
91 BOOST_TEST_MESSAGE( wxString::Format( "Found %d creepage violations", (int) violations.size() ) );
92
93 double maxActual = 0.0;
94
95 for( const auto& v : violations )
96 {
97 wxString msg = v->GetErrorMessage( false );
98 BOOST_TEST_MESSAGE( wxString::Format( " Violation: %s", msg ) );
99
100 // Extract the reported actual distance from "actual X.XXXX mm"
101 int pos = msg.Find( "actual " );
102
103 if( pos != wxNOT_FOUND )
104 {
105 double val = 0.0;
106 wxString tail = msg.Mid( pos + 7 );
107 int spacePos = tail.Find( ' ' );
108
109 if( spacePos != wxNOT_FOUND )
110 tail = tail.Left( spacePos );
111
112 if( tail.ToDouble( &val ) )
113 maxActual = std::max( maxActual, val );
114 }
115 }
116
117 // The board has multiple 'Sitove' netclass pad pairs around a 5mm x 1mm NPTH oval slot.
118 // With correct slot modeling (arcs + segments), creepage paths must go around the actual
119 // slot boundary. This produces 4 violations, two of which have actual distances above 4mm.
120 // If the slot were modeled as an oversized circle (old bug, radius=2.5mm instead of 0.5mm),
121 // those longer paths would exceed 5mm and not be reported, dropping the count to 2.
122 BOOST_CHECK_EQUAL( violations.size(), 4u );
123
124 // At least one violation must have a measured distance above 4mm, proving the path
125 // correctly traverses the slot boundary rather than cutting through the slot interior
126 // or detouring around an oversized circle.
127 BOOST_CHECK_GT( maxActual, 4.0 );
128}
Container for design settings for a BOARD object.
std::map< int, SEVERITY > m_DRCSeverities
std::shared_ptr< DRC_ENGINE > m_DRCEngine
SEVERITY GetSeverity(int aDRCErrorCode)
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_CREEPAGE
Definition drc_item.h:41
@ DRCE_FIRST
Definition drc_item.h:35
@ DRCE_LAST
Definition drc_item.h:121
void LoadBoard(SETTINGS_MANAGER &aSettingsManager, const wxString &aRelPath, std::unique_ptr< BOARD > &aBoard)
@ RPT_SEVERITY_ERROR
@ RPT_SEVERITY_IGNORE
BOOST_FIXTURE_TEST_CASE(CreepageNPTHSlotIssue23389, DRC_CREEPAGE_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