KiCad PCB EDA Suite
Loading...
Searching...
No Matches
test_drc_return_path_zone_bbox.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
20#include <boost/test/unit_test.hpp>
21
23
24#include <filesystem>
25#include <fstream>
26
27#include <board.h>
29#include <drc/drc_engine.h>
30#include <drc/drc_item.h>
31#include <netinfo.h>
32#include <pcb_marker.h>
34
35
36// Two F.Cu chains, each 30 mm long. CHAIN_COVERED is shadowed by a B.Cu zone in the
37// (0,0)..(30,1) corridor; CHAIN_UNCOVERED is at y=20 with no overlying B.Cu zone.
38// Pre-fix the global zone count is 1 board-wide so the return-path check never fires.
39// Post-fix the spatial test catches CHAIN_UNCOVERED while leaving CHAIN_COVERED clean.
40static const char* BOARD_FILE = "net_chains/return_path_zone_bbox.kicad_pcb";
41
42
43// length 0..200 mm passes; the only firing constraint is return_path which requires a
44// continuous B.Cu reference under the F.Cu chain.
45static const char* DRU_TEXT = R"KICAD((version 1)
46
47(rule "ReturnPath"
48 (condition "A.NetClass == 'Default'")
49 (constraint length (min 0mm) (max 200mm))
50 (constraint return_path (layer "B.Cu"))
51)
52)KICAD";
53
54
55BOOST_AUTO_TEST_SUITE( DRCReturnPathZoneBBox )
56
57
58BOOST_AUTO_TEST_CASE( ZoneSpatialFilterFiresForUnshadowedChain )
59{
60 namespace fs = std::filesystem;
61
62 fs::path tmpDir = fs::temp_directory_path() / "kicad_drc_return_path_bbox";
63 fs::create_directories( tmpDir );
64
65 fs::path druPath = tmpDir / "ret_path.kicad_dru";
66
67 {
68 std::ofstream druOut( druPath );
69 druOut << DRU_TEXT;
70 }
71
72 PCB_IO_KICAD_SEXPR plugin;
73 std::unique_ptr<BOARD> board = std::make_unique<BOARD>();
74 plugin.LoadBoard( KI_TEST::GetPcbnewTestDataDir() + BOARD_FILE, board.get() );
75 board->BuildConnectivity();
76
77 NETINFO_ITEM* coveredNet = board->FindNet( wxS( "/CHAIN_COVERED" ) );
78 BOOST_REQUIRE( coveredNet );
79 coveredNet->SetNetChain( wxS( "COVERED" ) );
80
81 NETINFO_ITEM* uncoveredNet = board->FindNet( wxS( "/CHAIN_UNCOVERED" ) );
82 BOOST_REQUIRE( uncoveredNet );
83 uncoveredNet->SetNetChain( wxS( "UNCOVERED" ) );
84
85 BOARD_DESIGN_SETTINGS& bds = board->GetDesignSettings();
86
87 auto drcEngine = std::make_shared<DRC_ENGINE>( board.get(), &bds );
88 wxFileName ruleFile( druPath.string() );
89 drcEngine->InitEngine( ruleFile );
90 bds.m_DRCEngine = drcEngine;
91
99
100 std::vector<DRC_ITEM> returnPathViolations;
101
102 drcEngine->SetViolationHandler(
103 [&]( const std::shared_ptr<DRC_ITEM>& aItem, const VECTOR2I&, int,
104 const std::function<void( PCB_MARKER* )>& )
105 {
106 if( aItem->GetErrorCode() == DRCE_NET_CHAIN_RETURN_PATH_BREAK )
107 returnPathViolations.push_back( *aItem );
108 } );
109
110 drcEngine->RunTests( EDA_UNITS::MM, true, false );
111
112 // Exactly one chain (UNCOVERED) should report a return-path break. Pre-fix the
113 // board-wide zone count of 1 produced zero violations even though only COVERED is
114 // actually shadowed.
115 BOOST_CHECK_EQUAL( returnPathViolations.size(), 1u );
116
117 bool coveredFlagged = false;
118 bool uncoveredFlagged = false;
119
120 for( const DRC_ITEM& item : returnPathViolations )
121 {
122 const wxString msg = item.GetErrorMessage( false );
123
124 if( msg.Find( wxS( "COVERED" ) ) != wxNOT_FOUND
125 && msg.Find( wxS( "UNCOVERED" ) ) == wxNOT_FOUND )
126 {
127 coveredFlagged = true;
128 }
129
130 if( msg.Find( wxS( "UNCOVERED" ) ) != wxNOT_FOUND )
131 uncoveredFlagged = true;
132 }
133
134 BOOST_CHECK_MESSAGE( !coveredFlagged,
135 "Return-path break wrongly reported for chain shadowed by a zone" );
136 BOOST_CHECK_MESSAGE( uncoveredFlagged,
137 "Return-path break missing for chain with no overlying zone" );
138
139 std::error_code ec;
140 fs::remove( druPath, ec );
141}
142
143
General utilities for PCB file IO for QA programs.
Container for design settings for a BOARD object.
std::map< int, SEVERITY > m_DRCSeverities
std::shared_ptr< DRC_ENGINE > m_DRCEngine
Handle the data for a net.
Definition netinfo.h:46
void SetNetChain(const wxString &aNetChain)
Definition netinfo.h:113
A #PLUGIN derivation for saving and loading Pcbnew s-expression formatted files.
BOARD * LoadBoard(const wxString &aFileName, BOARD *aAppendToMe, const std::map< std::string, UTF8 > *aProperties=nullptr, PROJECT *aProject=nullptr) override
Load information from some input file format that this PCB_IO implementation knows about into either ...
@ DRCE_UNCONNECTED_ITEMS
Definition drc_item.h:37
@ DRCE_LIB_FOOTPRINT_ISSUES
Definition drc_item.h:80
@ DRCE_INVALID_OUTLINE
Definition drc_item.h:70
@ DRCE_DRILL_OUT_OF_RANGE
Definition drc_item.h:58
@ DRCE_NET_CHAIN_RETURN_PATH_BREAK
Definition drc_item.h:104
@ DRCE_DANGLING_VIA
Definition drc_item.h:48
@ DRCE_LIB_FOOTPRINT_MISMATCH
Definition drc_item.h:81
std::string GetPcbnewTestDataDir()
Utility which returns a path to the data directory where the test board files are stored.
@ RPT_SEVERITY_ERROR
@ RPT_SEVERITY_IGNORE
BOOST_AUTO_TEST_CASE(HorizontalAlignment)
BOOST_AUTO_TEST_SUITE(CadstarPartParser)
static const char * BOARD_FILE
static const char * DRU_TEXT
BOOST_REQUIRE(intersection.has_value()==c.ExpectedIntersection.has_value())
BOOST_AUTO_TEST_SUITE_END()
BOOST_CHECK_EQUAL(result, "25.4")
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:683