KiCad PCB EDA Suite
Loading...
Searching...
No Matches
test_drc_creepage_issue24523.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
38
41
42#include <board.h>
44#include <layer_ids.h>
45#include <drc/drc_item.h>
46#include <drc/drc_engine.h>
47#include <footprint.h>
48#include <pad.h>
49#include <pcb_marker.h>
52
53
55{
57
59 {
60 if( m_board && m_board->GetDesignSettings().m_DRCEngine )
61 m_board->GetDesignSettings().m_DRCEngine->ClearViolationHandler();
62
63 if( m_board )
64 {
65 m_board->SetProject( nullptr );
66 m_board = nullptr;
67 }
68 }
69
71 std::unique_ptr<BOARD> m_board;
72};
73
74
76{
77 KI_TEST::LoadBoard( m_settingsManager, "issue24523/issue24523", m_board );
78
79 BOOST_REQUIRE_MESSAGE( m_board, "Failed to load board issue24523" );
80
81 struct ViolationInfo
82 {
83 std::shared_ptr<DRC_ITEM> item;
84 VECTOR2I pos;
85 std::vector<PCB_SHAPE> pathShapes;
86 int layer = 0;
87 double reportedActual = -1.0;
88 };
89
90 std::vector<ViolationInfo> violations;
91 BOARD_DESIGN_SETTINGS& bds = m_board->GetDesignSettings();
92
93 BOOST_REQUIRE_MESSAGE( bds.m_DRCEngine, "DRC engine not initialized" );
94
95 for( int ii = DRCE_FIRST; ii <= DRCE_LAST; ++ii )
97
99
100 auto parseActual =
101 []( const wxString& aMsg ) -> double
102 {
103 int actualPos = aMsg.Find( wxT( "actual " ) );
104
105 if( actualPos == wxNOT_FOUND )
106 return -1.0;
107
108 wxString tail = aMsg.Mid( actualPos + 7 );
109 int spacePos = tail.Find( ' ' );
110
111 if( spacePos != wxNOT_FOUND )
112 tail = tail.Left( spacePos );
113
114 double value = -1.0;
115 tail.ToDouble( &value );
116 return value;
117 };
118
120 [&]( const std::shared_ptr<DRC_ITEM>& aItem, const VECTOR2I& aPos, int aLayer,
121 const std::function<void( PCB_MARKER* )>& aPathGenerator )
122 {
123 if( bds.GetSeverity( aItem->GetErrorCode() ) != SEVERITY::RPT_SEVERITY_ERROR )
124 return;
125
126 ViolationInfo vi;
127 vi.item = aItem;
128 vi.pos = aPos;
129 vi.layer = aLayer;
130 vi.reportedActual = parseActual( aItem->GetErrorMessage( false ) );
131
132 if( aPathGenerator )
133 {
134 PCB_MARKER marker( aItem, aPos, aLayer );
135 aPathGenerator( &marker );
136 vi.pathShapes = marker.GetPath();
137 }
138
139 violations.push_back( vi );
140 } );
141
142 bds.m_DRCEngine->RunTests( EDA_UNITS::MM, true, false );
143
145
146 BOOST_TEST_MESSAGE( wxString::Format( "Found %d creepage violations",
147 (int) violations.size() ) );
148
149 double shortestActual = std::numeric_limits<double>::max();
150
151 for( const ViolationInfo& vi : violations )
152 {
153 BOOST_TEST_MESSAGE( wxString::Format( " layer=%d arrow=(%.4f,%.4f) shapes=%d actual=%.4f",
154 vi.layer, vi.pos.x / 1e6, vi.pos.y / 1e6,
155 (int) vi.pathShapes.size(), vi.reportedActual ) );
156
157 if( vi.reportedActual >= 0.0 )
158 shortestActual = std::min( shortestActual, vi.reportedActual );
159 }
160
161 // The two nets violate the 5 mm rule because the true surface path that winds
162 // around the two NPTH slots is only ~3 mm. The path search must find it.
163 BOOST_REQUIRE_MESSAGE( !violations.empty(),
164 "No creepage violation reported; the path search failed to find the ~3 mm route "
165 "winding around the two NPTH slots and overestimated the creepage distance." );
166
167 BOOST_TEST_MESSAGE( wxString::Format( "Shortest reported creepage actual: %.4f mm",
168 shortestActual ) );
169
170 // A violation is only emitted when the computed distance is below the 5 mm rule, so any
171 // reported actual is already < 5 mm. Guard against a future regression that lets a grossly
172 // overestimated (but still sub-5 mm) path through: the real path is ~3 mm.
173 BOOST_CHECK_MESSAGE( shortestActual < 4.0,
174 wxString::Format( "Shortest reported creepage %.4f mm is far longer than the true "
175 "~3 mm winding path, indicating the search is still missing the "
176 "shortest route around the two slots.", shortestActual ) );
177}
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:168
void ClearViolationHandler()
Definition drc_engine.h:173
const std::vector< PCB_SHAPE > & GetPath() const
Definition pcb_marker.h:162
@ DRCE_CREEPAGE
Definition drc_item.h:45
@ DRCE_FIRST
Definition drc_item.h:39
@ DRCE_LAST
Definition drc_item.h:124
void LoadBoard(SETTINGS_MANAGER &aSettingsManager, const wxString &aRelPath, std::unique_ptr< BOARD > &aBoard)
@ RPT_SEVERITY_ERROR
@ RPT_SEVERITY_IGNORE
BOOST_FIXTURE_TEST_CASE(CreepageTwoNPTHSlotsIssue24523, DRC_CREEPAGE_TWO_SLOTS_FIXTURE)
BOOST_CHECK_MESSAGE(totalMismatches==0, std::to_string(totalMismatches)+" board(s) with strategy disagreements")
BOOST_TEST_MESSAGE("\n=== Real-World Polygon PIP Benchmark ===\n"<< formatTable(table))
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:687