KiCad PCB EDA Suite
Loading...
Searching...
No Matches
test_tuning_pattern_layer.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, you may find one here:
18 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
19 * or you may search the http://www.gnu.org website for the version 2 license,
20 * or you may write to the Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
22 */
23
33
35
36#include <board.h>
37#include <pcb_track.h>
38#include <pcb_generator.h>
43
44#include <router/pns_router.h>
46#include <router/pns_item.h>
47
48
50{
52 {
53 KI_TEST::LoadBoard( m_settingsManager, "issue17971/issue17971", m_board );
55
56 KIID patternUuid( "24d674f0-f4fd-411b-8bf7-cc6e9297d826" );
58
59 return static_cast<PCB_TUNING_PATTERN&>( item );
60 }
61
63 std::unique_ptr<BOARD> m_board;
64};
65
66
67// PCB_TUNING_PATTERN::recoverBaseline() is protected; a derived class can form a pointer to it and
68// invoke that on the real (base) object, driving the exact code path that #17971 corrected without
69// an ill-formed downcast of the loaded pattern.
71{
72 static bool Recover( PCB_TUNING_PATTERN& aPattern, PNS::ROUTER* aRouter, int aPNSLayer )
73 {
74 return ( aPattern.*( &BASELINE_ACCESSOR::recoverBaseline ) )( aRouter, aPNSLayer );
75 }
76};
77
78
79// Captures the PNS layer of every item the router hands back so the test can observe which copper
80// layer the recovered baseline actually landed on. The stock base interface swallows AddItem().
82{
83 void AddItem( PNS::ITEM* aItem ) override
84 {
86 m_recoveredLayers.insert( aItem->Layer() );
87 }
88
89 std::set<int> m_recoveredLayers;
90};
91
92
93BOOST_FIXTURE_TEST_CASE( SetLayerPropagatesToMemberTracks, TUNING_PATTERN_LAYER_FIXTURE )
94{
95 PCB_TUNING_PATTERN& pattern = LoadPattern();
96
97 // The reproduction board has the pattern on B.Cu.
98 BOOST_CHECK_EQUAL( pattern.GetLayer(), B_Cu );
99
100 // Step 4 of the report: move the pattern (and its member tracks) to another layer.
101 pattern.SetLayer( In2_Cu );
102 BOOST_CHECK_EQUAL( pattern.GetLayer(), In2_Cu );
103
104 for( BOARD_ITEM* member : pattern.GetBoardItems() )
105 {
106 if( PCB_TRACK* track = dynamic_cast<PCB_TRACK*>( member ) )
107 BOOST_CHECK_EQUAL( track->GetLayer(), In2_Cu );
108 }
109}
110
111
112BOOST_FIXTURE_TEST_CASE( RecoverBaselineFollowsMovedLayer, TUNING_PATTERN_LAYER_FIXTURE )
113{
114 PCB_TUNING_PATTERN& pattern = LoadPattern();
115
116 // Reproduce the report: move the pattern off its saved layer before deleting it.
117 pattern.SetLayer( In2_Cu );
118
120 iface.SetBoard( m_board.get() );
121
122 PNS::ROUTER router;
123 router.SetInterface( &iface );
124 router.ClearWorld();
125 router.SyncWorld();
126
127 // Remove() converts the current board layer to a PNS layer before recovery; do the same here.
128 const int pnsLayer = iface.GetPNSLayerFromBoardLayer( pattern.GetLayer() );
129
130 bool ok = BASELINE_ACCESSOR::Recover( pattern, &router, pnsLayer );
131 BOOST_CHECK( ok );
132
133 BOOST_REQUIRE( !iface.m_recoveredLayers.empty() );
134
135 // Every recovered baseline segment must sit on the pattern's current layer. Feeding the raw
136 // PCB_LAYER_ID (In2.Cu == 6) as a PNS layer, as the bug did, recovers onto an out-of-range PNS
137 // layer that maps back to no board copper layer at all.
138 for( int recoveredLayer : iface.m_recoveredLayers )
139 BOOST_CHECK_EQUAL( iface.GetBoardLayerFromPNSLayer( recoveredLayer ), In2_Cu );
140}
General utilities for PCB file IO for QA programs.
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition board_item.h:81
Definition kiid.h:44
std::unordered_set< BOARD_ITEM * > GetBoardItems() const
Definition pcb_group.cpp:98
bool recoverBaseline(PNS::ROUTER *aRouter, int aPNSLayer)
PCB_TUNING_PATTERN(BOARD_ITEM *aParent=nullptr, PCB_LAYER_ID aLayer=F_Cu, LENGTH_TUNING_MODE aMode=LENGTH_TUNING_MODE::SINGLE)
void SetLayer(PCB_LAYER_ID aLayer) override
Set the layer this item is on.
PCB_LAYER_ID GetLayer() const override
Return the primary layer this item is on.
Base class for PNS router board items.
Definition pns_item.h:98
virtual int Layer() const
Definition pns_item.h:216
bool OfKind(int aKindMask) const
Definition pns_item.h:181
void ClearWorld()
void SetInterface(ROUTER_IFACE *aIface)
void SyncWorld()
void SetBoard(BOARD *aBoard)
PCB_LAYER_ID GetBoardLayerFromPNSLayer(int aLayer) const override
int GetPNSLayerFromBoardLayer(PCB_LAYER_ID aLayer) const override
@ B_Cu
Definition layer_ids.h:61
@ In2_Cu
Definition layer_ids.h:63
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.
static bool Recover(PCB_TUNING_PATTERN &aPattern, PNS::ROUTER *aRouter, int aPNSLayer)
void AddItem(PNS::ITEM *aItem) override
Regression test for https://gitlab.com/kicad/code/kicad/-/issues/17971.
BOOST_REQUIRE(intersection.has_value()==c.ExpectedIntersection.has_value())
BOOST_CHECK_EQUAL(result, "25.4")
BOOST_FIXTURE_TEST_CASE(SetLayerPropagatesToMemberTracks, TUNING_PATTERN_LAYER_FIXTURE)
@ PCB_GENERATOR_T
class PCB_GENERATOR, generator on a layer
Definition typeinfo.h:84