KiCad PCB EDA Suite
Loading...
Searching...
No Matches
test_net_chain_total_length.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 modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation, either version 3 of the License, or (at your
9 * option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License along
17 * with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19#include <boost/test/unit_test.hpp>
20#include <board.h>
21#include <pcb_track.h>
22#include <netinfo.h>
24
25static const long long MM = 1000000LL; // internal nanometers per mm
26
27BOOST_AUTO_TEST_SUITE( SignalTotalLength )
28
29BOOST_AUTO_TEST_CASE( SignalAggregatePlusNetEqualsPadSpacing )
30{
31 std::unique_ptr<BOARD> board = std::make_unique<BOARD>();
32 // Create 4 nets making a 30 mm chain (0-8, 8-18, 18-23, 23-30)
33 NETINFO_ITEM* n1 = new NETINFO_ITEM( board.get(), wxS("N1"), 1 ); board->Add( n1 );
34 NETINFO_ITEM* n2 = new NETINFO_ITEM( board.get(), wxS("N2"), 2 ); board->Add( n2 );
35 NETINFO_ITEM* n3 = new NETINFO_ITEM( board.get(), wxS("N3"), 3 ); board->Add( n3 );
36 NETINFO_ITEM* n4 = new NETINFO_ITEM( board.get(), wxS("N4"), 4 ); board->Add( n4 );
37 for( NETINFO_ITEM* n : { n1, n2, n3, n4 } ) n->SetNetChain( wxS("Signal1") );
38
39 auto addSeg = [&]( NETINFO_ITEM* net, double x1mm, double x2mm )
40 {
41 PCB_TRACK* t = new PCB_TRACK( board.get() );
42 t->SetNetCode( net->GetNetCode() );
43 t->SetStart( VECTOR2I( (long long)( x1mm * MM ), 0 ) );
44 t->SetEnd( VECTOR2I( (long long)( x2mm * MM ), 0 ) );
45 t->SetWidth( 100000 );
46 board->Add( t );
47 };
48 addSeg( n1, 0.0, 8.0 ); // 8 mm
49 addSeg( n2, 8.0, 18.0 ); // 10 mm
50 addSeg( n3, 18.0, 23.0 ); // 5 mm
51 addSeg( n4, 23.0, 30.0 ); // 7 mm
52
53 PNS_KICAD_IFACE_BASE ifaceBase; ifaceBase.SetBoard( board.get() );
54 long long extraLen = 0, extraDelay = 0;
55 bool ok = ifaceBase.GetSignalAggregate( n1, n1, extraLen, extraDelay ); // all other nets
56 BOOST_CHECK( ok );
57
58 // Enumerate tracks for diagnostics
59 int trackCount = 0;
60 for( BOARD_ITEM* bi : board->Tracks() ) if( dynamic_cast<PCB_TRACK*>( bi ) ) trackCount++;
61
62 // Compute routed length for net1 summing track+pad contributions per segment
63 long long net1Len = 0;
64 for( BOARD_ITEM* bi : board->Tracks() )
65 if( auto tr = dynamic_cast<PCB_TRACK*>( bi ) )
66 if( tr->GetNetCode() == n1->GetNetCode() )
67 net1Len += ( tr->GetStart() - tr->GetEnd() ).EuclideanNorm();
68
69 // net1Len should be 8mm, aggregated should be 22mm
70 long long expectedNet1 = 8 * MM;
71 long long expectedExtra = 22 * MM;
72 BOOST_CHECK_EQUAL( net1Len, expectedNet1 );
73 BOOST_CHECK_EQUAL( extraLen, expectedExtra );
74 BOOST_CHECK( net1Len > 0 );
75
76 long long total = net1Len + extraLen;
77
78 // Expected: 30 mm end-to-end spacing between TP2 (0,0) and TP1 (30,0)
79 long long expected = 30 * MM;
80
81 // Allow small tolerance (1 micron) for rounding
82 long long tol = 1000; // 0.001 mm
83 BOOST_CHECK_MESSAGE( llabs( total - expected ) <= tol,
84 "Total signal length " << total << " differs from expected " << expected << " (extra=" << extraLen << " net1=" << net1Len << ")" );
85}
86
virtual bool SetNetCode(int aNetCode, bool aNoAssert)
Set net using a net code.
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition board_item.h:84
Handle the data for a net.
Definition netinfo.h:50
int GetNetCode() const
Definition netinfo.h:97
void SetEnd(const VECTOR2I &aEnd)
Definition pcb_track.h:93
void SetStart(const VECTOR2I &aStart)
Definition pcb_track.h:96
virtual void SetWidth(int aWidth)
Definition pcb_track.h:90
void SetBoard(BOARD *aBoard)
bool GetSignalAggregate(PNS::NET_HANDLE aNetP, PNS::NET_HANDLE aNetN, long long &aExtraLength, long long &aExtraDelay) const override
BOOST_AUTO_TEST_CASE(HorizontalAlignment)
BOOST_AUTO_TEST_SUITE(CadstarPartParser)
BOOST_AUTO_TEST_SUITE_END()
VECTOR3I expected(15, 30, 45)
static const long long MM
BOOST_CHECK_MESSAGE(totalMismatches==0, std::to_string(totalMismatches)+" board(s) with strategy disagreements")
BOOST_CHECK_EQUAL(result, "25.4")
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:687