KiCad PCB EDA Suite
Loading...
Searching...
No Matches
test_pns_diff_pair_tuning_width.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
21
22#include <board.h>
23#include <pad.h>
24#include <pcb_track.h>
27
29#include <router/pns_item.h>
31#include <router/pns_line.h>
33#include <router/pns_router.h>
36#include <router/pns_topology.h>
37#include <router/pns_via.h>
38
39#include <memory>
40
41
47
48
49static void checkLineUsesOnlyTrackWidth( const PNS::LINE& aLine )
50{
51 BOOST_REQUIRE_GT( aLine.LinkCount(), 0 );
52
53 const int lineWidth = aLine.Width();
54
55 for( const PNS::LINKED_ITEM* link : aLine.Links() )
56 {
57 BOOST_CHECK_EQUAL( link->Width(), lineWidth );
58 }
59}
60
61
62BOOST_FIXTURE_TEST_CASE( DiffPairTuningStopsAtTrackWidthChanges, DIFF_PAIR_TUNING_WIDTH_FIXTURE )
63{
64 KI_TEST::LoadBoard( m_settingsManager, "issue23550/issue23550", m_board );
65 BOOST_REQUIRE( m_board );
66
68 *m_board, PCB_TRACE_T, KIID( "5ca809fb-b7f4-4a3c-b239-272a2b12320f" ) ) );
69
70 PNS::ROUTER router;
72 iface.SetBoard( m_board.get() );
73 router.SetInterface( &iface );
74 router.ClearWorld();
75 router.SyncWorld();
76
77 PNS::ITEM* startItem = router.GetWorld()->FindItemByParent( &startTrack );
78 BOOST_REQUIRE( startItem );
79
80 PNS::DIFF_PAIR pair;
81 PNS::TOPOLOGY topology( router.GetWorld() );
82
83 BOOST_REQUIRE( topology.AssembleDiffPair( startItem, pair ) );
84
85 BOOST_CHECK_EQUAL( pair.PLine().Width(), pcbIUScale.mmToIU( 0.085 ) );
86 BOOST_CHECK_EQUAL( pair.NLine().Width(), pcbIUScale.mmToIU( 0.085 ) );
87
90}
91
92
93// Picking an inner target layer for a via sets a partial layer pair. A through via still has
94// to span the whole board, or its annular ring stops being drawn below the target layer.
95BOOST_FIXTURE_TEST_CASE( DiffPairThroughViaSpansFullStack, DIFF_PAIR_TUNING_WIDTH_FIXTURE )
96{
97 KI_TEST::LoadBoard( m_settingsManager, "issue23550/issue23550", m_board );
98 BOOST_REQUIRE( m_board );
99
100 PAD& startPad = static_cast<PAD&>( KI_TEST::RequireBoardItemWithTypeAndId(
101 *m_board, PCB_PAD_T, KIID( "ac8b01c9-e917-4508-be81-bb61731d5b93" ) ) );
102
103 PNS::ROUTING_SETTINGS settings( nullptr, "" );
104 PNS::ROUTER router;
106
107 iface.SetBoard( m_board.get() );
108 router.SetInterface( &iface );
109 router.ClearWorld();
110 router.SyncWorld();
111 router.LoadSettings( &settings );
113
114 PNS::ITEM* startItem = router.GetWorld()->FindItemByParent( &startPad );
115 BOOST_REQUIRE( startItem );
116
117 const int pnsFront = iface.GetPNSLayerFromBoardLayer( F_Cu );
118 const int pnsBack = iface.GetPNSLayerFromBoardLayer( B_Cu );
119 const int pnsTarget = iface.GetPNSLayerFromBoardLayer( In11_Cu );
120
121 BOOST_REQUIRE_MESSAGE( router.StartRouting( startPad.GetPosition(), startItem, pnsFront ), router.FailureReason() );
122
123 PNS::SIZES_SETTINGS sizes( router.Sizes() );
125 sizes.SetViaDiameter( pcbIUScale.mmToIU( 0.6 ) );
126 sizes.SetViaDrill( pcbIUScale.mmToIU( 0.3 ) );
127 sizes.ClearLayerPairs();
128 sizes.AddLayerPair( pnsFront, pnsTarget );
129 router.UpdateSizes( sizes );
130
131 router.ToggleViaPlacement();
132 BOOST_REQUIRE( router.IsPlacingVia() );
133
134 router.Move( startPad.GetPosition() + VECTOR2I( pcbIUScale.mmToIU( 2 ), pcbIUScale.mmToIU( 2 ) ), nullptr );
135
136 const PNS::ITEM_SET traces = router.Placer()->Traces();
137
138 int viasChecked = 0;
139
140 for( const PNS::ITEM* item : traces.CItems() )
141 {
142 if( !item->OfKind( PNS::ITEM::LINE_T ) )
143 continue;
144
145 const PNS::LINE* line = static_cast<const PNS::LINE*>( item );
146
147 if( !line->EndsWithVia() )
148 continue;
149
150 const PNS::VIA& via = line->Via();
151 viasChecked++;
152
153 BOOST_CHECK_EQUAL( via.Layers().Start(), pnsFront );
154 BOOST_CHECK_EQUAL( via.Layers().End(), pnsBack );
155 BOOST_CHECK_EQUAL( via.HoleLayers().Start(), pnsFront );
156 BOOST_CHECK_EQUAL( via.HoleLayers().End(), pnsBack );
157 }
158
159 router.StopRouting();
160
161 BOOST_REQUIRE_EQUAL( viasChecked, 2 );
162}
constexpr EDA_IU_SCALE pcbIUScale
Definition base_units.h:121
Definition kiid.h:46
Definition pad.h:61
VECTOR2I GetPosition() const override
Definition pad.cpp:246
Basic class for a differential pair.
const std::vector< ITEM * > & CItems() const
Definition pns_itemset.h:96
Base class for PNS router board items.
Definition pns_item.h:98
Represents a track on a PCB, connecting two non-trivial joints (that is, vias, pads,...
Definition pns_line.h:62
VIA & Via()
Definition pns_line.h:207
bool EndsWithVia() const
Definition pns_line.h:199
int Width() const
Return true if the line is geometrically identical as line aOther.
Definition pns_line.h:166
ITEM * FindItemByParent(const BOARD_ITEM *aParent)
virtual const ITEM_SET Traces()=0
Function Traces()
void SetMode(ROUTER_MODE aMode)
void StopRouting()
PLACEMENT_ALGO * Placer()
Definition pns_router.h:252
void ClearWorld()
void UpdateSizes(const SIZES_SETTINGS &aSizes)
Applies stored settings.
void LoadSettings(ROUTING_SETTINGS *aSettings)
Changes routing settings to ones passed in the parameter.
Definition pns_router.h:242
void SetInterface(ROUTER_IFACE *aIface)
void SyncWorld()
const wxString & FailureReason() const
Definition pns_router.h:250
bool IsPlacingVia() const
bool StartRouting(const VECTOR2I &aP, ITEM *aItem, int aLayer)
SIZES_SETTINGS & Sizes()
Definition pns_router.h:247
void ToggleViaPlacement()
NODE * GetWorld() const
Definition pns_router.h:200
bool Move(const VECTOR2I &aP, ITEM *aItem)
Contain all persistent settings of the router, such as the mode, optimization effort,...
void SetViaType(VIATYPE aViaType)
void SetViaDrill(int aDrill)
void AddLayerPair(int aL1, int aL2)
void SetViaDiameter(int aDiameter)
const DIFF_PAIR AssembleDiffPair(SEGMENT *aStart)
void SetBoard(BOARD *aBoard)
int GetPNSLayerFromBoardLayer(PCB_LAYER_ID aLayer) const override
@ In11_Cu
Definition layer_ids.h:72
@ B_Cu
Definition layer_ids.h:61
@ F_Cu
Definition layer_ids.h:60
void LoadBoard(SETTINGS_MANAGER &aSettingsManager, const wxString &aRelPath, std::unique_ptr< BOARD > &aBoard)
BOARD_ITEM & RequireBoardItemWithTypeAndId(const BOARD &aBoard, KICAD_T aItemType, const KIID &aID)
Get an item from the given board with a certain type and UUID.
@ PNS_MODE_ROUTE_DIFF_PAIR
Definition pns_router.h:69
BOOST_REQUIRE(intersection.has_value()==c.ExpectedIntersection.has_value())
BOOST_FIXTURE_TEST_CASE(DiffPairTuningStopsAtTrackWidthChanges, DIFF_PAIR_TUNING_WIDTH_FIXTURE)
static void checkLineUsesOnlyTrackWidth(const PNS::LINE &aLine)
BOOST_CHECK_EQUAL(result, "25.4")
@ PCB_PAD_T
class PAD, a pad in a footprint
Definition typeinfo.h:79
@ PCB_TRACE_T
class PCB_TRACK, a track segment (segment on a copper layer)
Definition typeinfo.h:88
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:683