KiCad PCB EDA Suite
Loading...
Searching...
No Matches
test_drc_creepage_issue24853.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
29
32
33#include <board.h>
35#include <layer_ids.h>
36#include <netinfo.h>
37#include <drc/drc_item.h>
38#include <drc/drc_rule.h>
39#include <drc/drc_engine.h>
42
43
45{
47
49 {
50 if( m_board && m_board->GetDesignSettings().m_DRCEngine )
51 m_board->GetDesignSettings().m_DRCEngine->ClearViolationHandler();
52
53 if( m_board )
54 {
55 m_board->SetProject( nullptr );
56 m_board = nullptr;
57 }
58 }
59
61 std::unique_ptr<BOARD> m_board;
62};
63
64
65BOOST_FIXTURE_TEST_CASE( CreepageRuleAreaConditionIssue24853, DRC_CREEPAGE_RULE_AREA_FIXTURE )
66{
67 KI_TEST::LoadBoard( m_settingsManager, "issue24853/issue24853", m_board );
68
69 BOOST_REQUIRE_MESSAGE( m_board, "Failed to load board issue24853" );
70
71 NETINFO_ITEM* netA = m_board->FindNet( wxT( "a" ) );
72 NETINFO_ITEM* netB = m_board->FindNet( wxT( "b" ) );
73
74 BOOST_REQUIRE_MESSAGE( netA && netB, "Nets 'a' and 'b' not found in board" );
75
76 struct ViolationInfo
77 {
78 wxString rule;
79 int layer = 0;
80 };
81
82 std::vector<ViolationInfo> creepageViolations;
83 BOARD_DESIGN_SETTINGS& bds = m_board->GetDesignSettings();
84
85 BOOST_REQUIRE_MESSAGE( bds.m_DRCEngine, "DRC engine not initialized" );
86
87 for( int ii = DRCE_FIRST; ii <= DRCE_LAST; ++ii )
89
91
93 [&]( const std::shared_ptr<DRC_ITEM>& aItem, const VECTOR2I& /* aPos */, int aLayer,
94 const std::function<void( PCB_MARKER* )>& /* aPathGenerator */ )
95 {
96 if( aItem->GetErrorCode() != DRCE_CREEPAGE )
97 return;
98
99 ViolationInfo vi;
100 vi.layer = aLayer;
101
102 if( DRC_RULE* rule = aItem->GetViolatingRule() )
103 vi.rule = rule->m_Name;
104
105 creepageViolations.push_back( vi );
106 } );
107
108 bds.m_DRCEngine->RunTests( EDA_UNITS::MM, true, false );
109
111
112 BOOST_TEST_MESSAGE( wxString::Format( "Found %d creepage violations",
113 (int) creepageViolations.size() ) );
114
115 for( const ViolationInfo& vi : creepageViolations )
116 BOOST_TEST_MESSAGE( wxString::Format( " layer=%d rule=%s", vi.layer, vi.rule ) );
117
118 BOOST_REQUIRE_MESSAGE( !creepageViolations.empty(),
119 "Expected a creepage violation between the two tracks inside the area" );
120
121 // Both conductors cross the 'forcreepage' area, so every creepage violation between them
122 // must resolve from the in-area rule 'creep'. The complementary 'creep2' rule requires both
123 // conductors to be outside the area and must never fire here. Attribution to 'creep2' is the
124 // exact #24853 failure mode where positional conditions were evaluated against origin
125 // placeholders.
126 for( const ViolationInfo& vi : creepageViolations )
127 {
128 BOOST_CHECK_MESSAGE( vi.rule == wxT( "creep" ),
129 wxString::Format( "Creepage violation resolved from rule '%s'; the conductors are "
130 "inside 'forcreepage' so it must resolve from 'creep'. Rule-area "
131 "conditions are being ignored for creepage.",
132 vi.rule ) );
133 }
134}
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
Handle the data for a net.
Definition netinfo.h:50
@ DRCE_CREEPAGE
Definition drc_item.h:42
@ DRCE_FIRST
Definition drc_item.h:36
@ DRCE_LAST
Definition drc_item.h:131
void LoadBoard(SETTINGS_MANAGER &aSettingsManager, const wxString &aRelPath, std::unique_ptr< BOARD > &aBoard)
@ RPT_SEVERITY_ERROR
@ RPT_SEVERITY_IGNORE
BOOST_FIXTURE_TEST_CASE(CreepageRuleAreaConditionIssue24853, DRC_CREEPAGE_RULE_AREA_FIXTURE)
BOOST_TEST_MESSAGE("Polyline has "<< chain.PointCount()<< " points")
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:683