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 = std::make_unique<BOARD>();
49 plugin.LoadBoard( KI_TEST::GetPcbnewTestDataDir() + aBoardFile, board.get() );
50 board->BuildConnectivity();
51 return board;
52}
53
54// Anchor terminals at the extreme-X footprints; the fixtures route in a single
55// row and carry no Reference strings to match on
56void tagAndSetTerminals( BOARD* aBoard, const wxString& aChain )
57{
58 for( NETINFO_ITEM* n : aBoard->GetNetInfo() )
59 {
60 if( n && n->GetNetname().StartsWith( wxS( "/NET_" ) ) )
61 n->SetNetChain( aChain );
62 }
63
64 FOOTPRINT* first = nullptr;
65 FOOTPRINT* last = nullptr;
66
67 for( FOOTPRINT* fp : aBoard->Footprints() )
68 {
69 if( fp->Pads().empty() )
70 continue;
71
72 if( !first || fp->GetPosition().x < first->GetPosition().x )
73 first = fp;
74
75 if( !last || fp->GetPosition().x > last->GetPosition().x )
76 last = fp;
77 }
78
79 BOOST_REQUIRE( first );
80 BOOST_REQUIRE( last );
81 BOOST_REQUIRE( first != last );
82
83 for( NETINFO_ITEM* n : aBoard->GetNetInfo() )
84 {
85 if( n && n->GetNetChain() == aChain )
86 {
87 n->SetTerminalPad( 0, first->Pads().front() );
88 n->SetTerminalPad( 1, last->Pads().front() );
89 }
90 }
91}
92
93} // namespace
94
95
96BOOST_AUTO_TEST_SUITE( DRCChainLengthTrunk )
97
98
99BOOST_AUTO_TEST_CASE( DaisyChainTrunkEqualsSumExplicit )
100{
101 auto board = loadBoard( DAISY_PCB_FILE );
102 tagAndSetTerminals( board.get(), wxS( "DSY" ) );
103
104 std::set<BOARD_CONNECTED_ITEM*> items;
105
106 for( PCB_TRACK* t : board->Tracks() )
107 {
108 if( t->GetNet() && t->GetNet()->GetNetChain() == wxS( "DSY" ) )
109 items.insert( t );
110 }
111
112 for( FOOTPRINT* fp : board->Footprints() )
113 {
114 for( PAD* p : fp->Pads() )
115 {
116 if( p->GetNet() && p->GetNet()->GetNetChain() == wxS( "DSY" ) )
117 items.insert( p );
118 }
119 }
120
121 CHAIN_TOPOLOGY topo( board.get(), wxS( "DSY" ), items );
122
123 BOOST_REQUIRE( topo.IsValid() );
124 BOOST_CHECK_CLOSE( topo.TrunkLength(), 50.0e6, 5.0 );
125}
126
127
128BOOST_AUTO_TEST_CASE( BranchedChainTrunkExcludesStubs )
129{
130 auto board = loadBoard( BRANCHED_PCB_FILE );
131 tagAndSetTerminals( board.get(), wxS( "BR" ) );
132
133 std::set<BOARD_CONNECTED_ITEM*> items;
134
135 for( PCB_TRACK* t : board->Tracks() )
136 {
137 if( t->GetNet() && t->GetNet()->GetNetChain() == wxS( "BR" ) )
138 items.insert( t );
139 }
140
141 for( FOOTPRINT* fp : board->Footprints() )
142 {
143 for( PAD* p : fp->Pads() )
144 {
145 if( p->GetNet() && p->GetNet()->GetNetChain() == wxS( "BR" ) )
146 items.insert( p );
147 }
148 }
149
150 CHAIN_TOPOLOGY topo( board.get(), wxS( "BR" ), items );
151
152 BOOST_REQUIRE( topo.IsValid() );
153 BOOST_CHECK_CLOSE( topo.TrunkLength(), 50.0e6, 5.0 );
154 BOOST_CHECK_EQUAL( topo.Stubs().size(), 3u );
155}
156
157
General utilities for PCB file IO for QA programs.
Information pertinent to a Pcbnew printed circuit board.
Definition board.h:373
const NETINFO_LIST & GetNetInfo() const
Definition board.h:1098
const FOOTPRINTS & Footprints() const
Definition board.h:421
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:375
VECTOR2I GetPosition() const override
Definition footprint.h:406
Handle the data for a net.
Definition netinfo.h:46
Definition pad.h:61
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 ...
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")