KiCad PCB EDA Suite
Loading...
Searching...
No Matches
test_drc_chain_length_trunk.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 <board.h>
26#include <footprint.h>
27#include <netinfo.h>
28#include <pad.h>
29#include <pcb_track.h>
31
32
33// Two-net daisy through a single bridge; trunk is both routed runs plus the
34// cross-net pad span: 21.55 + 1.9 + 26.55 = 50 mm
35static const char* DAISY_PCB_FILE = "net_chains/chain_length_daisy.kicad_pcb";
36
37
38// Same 50 mm trunk as the daisy fixture with three perpendicular branches
39// tapped off it, all on the same chain, so stubs must not reach the trunk sum
40static const char* BRANCHED_PCB_FILE = "net_chains/chain_length_branched.kicad_pcb";
41
42
43namespace
44{
45std::unique_ptr<BOARD> loadBoard( const char* aBoardFile )
46{
47 PCB_IO_KICAD_SEXPR plugin;
48 std::unique_ptr<BOARD> board = plugin.LoadBoard( KI_TEST::GetPcbnewTestDataDir() + aBoardFile );
49 board->BuildConnectivity();
50 return board;
51}
52
53// Anchor terminals at the extreme-X footprints; the fixtures route in a single
54// row and carry no Reference strings to match on
55void tagAndSetTerminals( BOARD* aBoard, const wxString& aChain )
56{
57 for( NETINFO_ITEM* n : aBoard->GetNetInfo() )
58 {
59 if( n && n->GetNetname().StartsWith( wxS( "/NET_" ) ) )
60 n->SetNetChain( aChain );
61 }
62
63 FOOTPRINT* first = nullptr;
64 FOOTPRINT* last = nullptr;
65
66 for( FOOTPRINT* fp : aBoard->Footprints() )
67 {
68 if( fp->Pads().empty() )
69 continue;
70
71 if( !first || fp->GetPosition().x < first->GetPosition().x )
72 first = fp;
73
74 if( !last || fp->GetPosition().x > last->GetPosition().x )
75 last = fp;
76 }
77
78 BOOST_REQUIRE( first );
79 BOOST_REQUIRE( last );
80 BOOST_REQUIRE( first != last );
81
82 for( NETINFO_ITEM* n : aBoard->GetNetInfo() )
83 {
84 if( n && n->GetNetChain() == aChain )
85 {
86 n->SetTerminalPad( 0, first->Pads().front() );
87 n->SetTerminalPad( 1, last->Pads().front() );
88 }
89 }
90}
91
92} // namespace
93
94
95BOOST_AUTO_TEST_SUITE( DRCChainLengthTrunk )
96
97
98BOOST_AUTO_TEST_CASE( DaisyChainTrunkEqualsSumExplicit )
99{
100 auto board = loadBoard( DAISY_PCB_FILE );
101 tagAndSetTerminals( board.get(), wxS( "DSY" ) );
102
103 std::set<BOARD_CONNECTED_ITEM*> items;
104
105 for( PCB_TRACK* t : board->Tracks() )
106 {
107 if( t->GetNet() && t->GetNet()->GetNetChain() == wxS( "DSY" ) )
108 items.insert( t );
109 }
110
111 for( FOOTPRINT* fp : board->Footprints() )
112 {
113 for( PAD* p : fp->Pads() )
114 {
115 if( p->GetNet() && p->GetNet()->GetNetChain() == wxS( "DSY" ) )
116 items.insert( p );
117 }
118 }
119
120 CHAIN_TOPOLOGY topo( board.get(), wxS( "DSY" ), items );
121
122 BOOST_REQUIRE( topo.IsValid() );
123 BOOST_CHECK_CLOSE( topo.TrunkLength(), 50.0e6, 5.0 );
124}
125
126
127BOOST_AUTO_TEST_CASE( BranchedChainTrunkExcludesStubs )
128{
129 auto board = loadBoard( BRANCHED_PCB_FILE );
130 tagAndSetTerminals( board.get(), wxS( "BR" ) );
131
132 std::set<BOARD_CONNECTED_ITEM*> items;
133
134 for( PCB_TRACK* t : board->Tracks() )
135 {
136 if( t->GetNet() && t->GetNet()->GetNetChain() == wxS( "BR" ) )
137 items.insert( t );
138 }
139
140 for( FOOTPRINT* fp : board->Footprints() )
141 {
142 for( PAD* p : fp->Pads() )
143 {
144 if( p->GetNet() && p->GetNet()->GetNetChain() == wxS( "BR" ) )
145 items.insert( p );
146 }
147 }
148
149 CHAIN_TOPOLOGY topo( board.get(), wxS( "BR" ), items );
150
151 BOOST_REQUIRE( topo.IsValid() );
152 BOOST_CHECK_CLOSE( topo.TrunkLength(), 50.0e6, 5.0 );
153 BOOST_CHECK_EQUAL( topo.Stubs().size(), 3u );
154}
155
156
General utilities for PCB file IO for QA programs.
Information pertinent to a Pcbnew printed circuit board.
Definition board.h:409
const NETINFO_LIST & GetNetInfo() const
Definition board.h:1207
const FOOTPRINTS & Footprints() const
Definition board.h:463
Build a topological view of a single named net chain's routed copper.
const std::vector< STUB > & Stubs() const
double TrunkLength() const
bool IsValid() const
std::deque< PAD * > & Pads()
Definition footprint.h:404
VECTOR2I GetPosition() const override
Definition footprint.h:435
Handle the data for a net.
Definition netinfo.h:50
Definition pad.h:61
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
std::string GetPcbnewTestDataDir()
Utility which returns a path to the data directory where the test board files are stored.
BOOST_AUTO_TEST_CASE(HorizontalAlignment)
BOOST_AUTO_TEST_SUITE(CadstarPartParser)
BOOST_AUTO_TEST_CASE(DaisyChainTrunkEqualsSumExplicit)
static const char * BRANCHED_PCB_FILE
static const char * DAISY_PCB_FILE
BOOST_REQUIRE(intersection.has_value()==c.ExpectedIntersection.has_value())
BOOST_AUTO_TEST_SUITE_END()
BOOST_CHECK_EQUAL(result, "25.4")