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 = plugin.LoadBoard( KI_TEST::GetPcbnewTestDataDir() + BOARD_FILE );
74 board->BuildConnectivity();
75
76 NETINFO_ITEM* coveredNet = board->FindNet( wxS( "/CHAIN_COVERED" ) );
77 BOOST_REQUIRE( coveredNet );
78 coveredNet->SetNetChain( wxS( "COVERED" ) );
79
80 NETINFO_ITEM* uncoveredNet = board->FindNet( wxS( "/CHAIN_UNCOVERED" ) );
81 BOOST_REQUIRE( uncoveredNet );
82 uncoveredNet->SetNetChain( wxS( "UNCOVERED" ) );
83
84 BOARD_DESIGN_SETTINGS& bds = board->GetDesignSettings();
85
86 auto drcEngine = std::make_shared<DRC_ENGINE>( board.get(), &bds );
87 wxFileName ruleFile( druPath.string() );
88 drcEngine->InitEngine( ruleFile );
89 bds.m_DRCEngine = drcEngine;
90
98
99 std::vector<DRC_ITEM> returnPathViolations;
100
101 drcEngine->SetViolationHandler(
102 [&]( const std::shared_ptr<DRC_ITEM>& aItem, const VECTOR2I&, int,
103 const std::function<void( PCB_MARKER* )>& )
104 {
105 if( aItem->GetErrorCode() == DRCE_NET_CHAIN_RETURN_PATH_BREAK )
106 returnPathViolations.push_back( *aItem );
107 } );
108
109 drcEngine->RunTests( EDA_UNITS::MM, true, false );
110
111 // Exactly one chain (UNCOVERED) should report a return-path break. Pre-fix the
112 // board-wide zone count of 1 produced zero violations even though only COVERED is
113 // actually shadowed.
114 BOOST_CHECK_EQUAL( returnPathViolations.size(), 1u );
115
116 bool coveredFlagged = false;
117 bool uncoveredFlagged = false;
118
119 for( const DRC_ITEM& item : returnPathViolations )
120 {
121 const wxString msg = item.GetErrorMessage( false );
122
123 if( msg.Find( wxS( "COVERED" ) ) != wxNOT_FOUND
124 && msg.Find( wxS( "UNCOVERED" ) ) == wxNOT_FOUND )
125 {
126 coveredFlagged = true;
127 }
128
129 if( msg.Find( wxS( "UNCOVERED" ) ) != wxNOT_FOUND )
130 uncoveredFlagged = true;
131 }
132
133 BOOST_CHECK_MESSAGE( !coveredFlagged,
134 "Return-path break wrongly reported for chain shadowed by a zone" );
135 BOOST_CHECK_MESSAGE( uncoveredFlagged,
136 "Return-path break missing for chain with no overlying zone" );
137
138 std::error_code ec;
139 fs::remove( druPath, ec );
140}
141
142
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:50
void SetNetChain(const wxString &aNetChain)
Definition netinfo.h:123
A #PLUGIN derivation for saving and loading Pcbnew s-expression formatted files.
std::unique_ptr< BOARD > LoadBoard(const wxString &aFileName, const std::map< std::string, UTF8 > *aProperties=nullptr, PROJECT *aProject=nullptr)
Load information from some input file format that this PCB_IO implementation knows about into new BOA...
Definition pcb_io.cpp:72
@ DRCE_UNCONNECTED_ITEMS
Definition drc_item.h:37
@ DRCE_LIB_FOOTPRINT_ISSUES
Definition drc_item.h:85
@ DRCE_INVALID_OUTLINE
Definition drc_item.h:75
@ DRCE_DRILL_OUT_OF_RANGE
Definition drc_item.h:58
@ DRCE_NET_CHAIN_RETURN_PATH_BREAK
Definition drc_item.h:109
@ DRCE_DANGLING_VIA
Definition drc_item.h:48
@ DRCE_LIB_FOOTPRINT_MISMATCH
Definition drc_item.h:86
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