KiCad PCB EDA Suite
Loading...
Searching...
No Matches
test_drc_keepout_disallow.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.
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
26#include <board.h>
28#include <drc/drc_engine.h>
29#include <drc/drc_item.h>
30#include <pcb_marker.h>
32
33
42
43
44// Regression test for GitLab #23911: Missing DRC notification for Rule Areas.
45// The test board has a rule area that disallows tracks, vias, pads, zones, and
46// footprints. It contains two vias fully inside the keepout and a track that
47// crosses into the keepout. All three items must produce DRCE_ALLOWED_ITEMS
48// violations.
49BOOST_FIXTURE_TEST_CASE( DRCKeepoutDisallowViasAndTracks, DRC_KEEPOUT_TEST_FIXTURE )
50{
51 KI_TEST::LoadBoard( m_settingsManager, "keepout_disallow/keepout_disallow", m_board );
52
53 std::vector<DRC_ITEM> violations;
54 BOARD_DESIGN_SETTINGS& bds = m_board->GetDesignSettings();
55
56 // Suppress unrelated checks that fire on a bare-bones board.
66
68 [&]( const std::shared_ptr<DRC_ITEM>& aItem, const VECTOR2I& aPos, int aLayer,
69 const std::function<void( PCB_MARKER* )>& aPathGenerator )
70 {
71 if( aItem->GetErrorCode() == DRCE_ALLOWED_ITEMS )
72 violations.push_back( *aItem );
73 } );
74
75 bds.m_DRCEngine->RunTests( EDA_UNITS::MM, true, false );
76
77 int trackViolations = 0;
78 int viaViolations = 0;
79
80 std::map<KIID, EDA_ITEM*> itemMap;
81 m_board->FillItemMap( itemMap );
82
83 for( const DRC_ITEM& item : violations )
84 {
85 const KIID id = item.GetMainItemID();
86
87 if( id == niluuid )
88 continue;
89
90 auto it = itemMap.find( id );
91
92 if( it == itemMap.end() )
93 continue;
94
95 switch( it->second->Type() )
96 {
97 case PCB_VIA_T: viaViolations++; break;
98 case PCB_TRACE_T: trackViolations++; break;
99 default: break;
100 }
101 }
102
103 // Expect exact counts so that duplicate-marker regressions are caught.
104 BOOST_CHECK_MESSAGE( viaViolations == 2,
105 "Expected exactly 2 via keepout violations, got "
106 << viaViolations << " (total: " << violations.size() << ")" );
107 BOOST_CHECK_MESSAGE( trackViolations == 1,
108 "Expected exactly 1 track keepout violation, got "
109 << trackViolations );
110 BOOST_CHECK_MESSAGE( violations.size() == 3,
111 "Expected exactly 3 DRCE_ALLOWED_ITEMS violations, got "
112 << violations.size() );
113
114 if( viaViolations != 2 || trackViolations != 1 || violations.size() != 3 )
115 {
116 UNITS_PROVIDER unitsProvider( pcbIUScale, EDA_UNITS::MM );
117
118 for( const DRC_ITEM& item : violations )
119 BOOST_TEST_MESSAGE( item.ShowReport( &unitsProvider, RPT_SEVERITY_ERROR, itemMap ) );
120 }
121}
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
Definition kiid.h:48
@ DRCE_VIA_DIAMETER
Definition drc_item.h:62
@ DRCE_UNCONNECTED_ITEMS
Definition drc_item.h:40
@ DRCE_LIB_FOOTPRINT_ISSUES
Definition drc_item.h:83
@ DRCE_INVALID_OUTLINE
Definition drc_item.h:73
@ DRCE_DRILL_OUT_OF_RANGE
Definition drc_item.h:61
@ DRCE_STARVED_THERMAL
Definition drc_item.h:50
@ DRCE_ALLOWED_ITEMS
Definition drc_item.h:42
@ DRCE_COPPER_SLIVER
Definition drc_item.h:93
@ DRCE_LIB_FOOTPRINT_MISMATCH
Definition drc_item.h:84
KIID niluuid(0)
void LoadBoard(SETTINGS_MANAGER &aSettingsManager, const wxString &aRelPath, std::unique_ptr< BOARD > &aBoard)
@ RPT_SEVERITY_ERROR
@ RPT_SEVERITY_IGNORE
BOOST_FIXTURE_TEST_CASE(DRCKeepoutDisallowViasAndTracks, DRC_KEEPOUT_TEST_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))
@ PCB_VIA_T
class PCB_VIA, a via (like a track segment on a copper layer)
Definition typeinfo.h:94
@ PCB_TRACE_T
class PCB_TRACK, a track segment (segment on a copper layer)
Definition typeinfo.h:93
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:687