KiCad PCB EDA Suite
Loading...
Searching...
No Matches
test_via_stack_selection.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 <lset.h>
24#include <pcb_group.h>
25#include <pcb_track.h>
26#include <pcb_view.h>
28#include <tool/tool_manager.h>
30
31BOOST_AUTO_TEST_SUITE( ViaStackSelection )
32
33
34static PCB_TRACK* addSegment( BOARD& aBoard, PCB_LAYER_ID aLayer, const VECTOR2I& aStart, const VECTOR2I& aEnd )
35{
36 PCB_TRACK* track = new PCB_TRACK( &aBoard );
37 track->SetLayer( aLayer );
38 track->SetWidth( 250000 );
39 track->SetStart( aStart );
40 track->SetEnd( aEnd );
41 aBoard.Add( track );
42 return track;
43}
44
45
50BOOST_AUTO_TEST_CASE( ExpansionSelectsTheStackItCrosses )
51{
52 // view must outlive board so board items unregister from a live view at teardown.
53 KIGFX::PCB_VIEW view;
54 BOARD board;
55 TOOL_MANAGER mgr;
56
57 board.SetCopperLayerCount( 4 );
59 mgr.SetEnvironment( &board, &view, nullptr, nullptr, nullptr );
60
62 mgr.RegisterTool( selTool );
63
64 VECTOR2I stackPos( 1000000, 0 );
65
66 PCB_VIA_STACK* stack = new PCB_VIA_STACK( &board, F_Cu );
67 stack->SetStartLayer( F_Cu );
68 stack->SetEndLayer( In1_Cu );
69 stack->SetViaSize( 300000 );
70 stack->SetViaDrill( 150000 );
71 stack->SetPosition( stackPos );
72 board.Add( stack );
73 stack->Regenerate( &board, nullptr );
74
75 PCB_TRACK* segIn = addSegment( board, F_Cu, { 0, 0 }, stackPos );
76 PCB_TRACK* segOut = addSegment( board, In1_Cu, stackPos, { 2000000, 0 } );
77
78 board.BuildConnectivity();
79
80 for( PCB_TRACK* track : { segIn, segOut } )
81 view.Add( track );
82
83 view.Add( stack );
84
85 std::vector<BOARD_CONNECTED_ITEM*> startItems = { segIn };
87
88 BOOST_CHECK( segIn->IsSelected() );
89 BOOST_CHECK_MESSAGE( segOut->IsSelected(), "expansion should reach across the stack" );
90 BOOST_CHECK_MESSAGE( stack->IsSelected(), "expansion should select the stack it crosses" );
91}
92
93
94// A stacked stack puts every hop at one position, so expansion has to walk down all of them.
95BOOST_AUTO_TEST_CASE( ExpansionCrossesAMultiHopStackedStack )
96{
97 KIGFX::PCB_VIEW view;
98 BOARD board;
99 TOOL_MANAGER mgr;
100
101 board.SetCopperLayerCount( 4 );
103 mgr.SetEnvironment( &board, &view, nullptr, nullptr, nullptr );
104
106 mgr.RegisterTool( selTool );
107
108 VECTOR2I stackPos( 1000000, 0 );
109
110 PCB_VIA_STACK* stack = new PCB_VIA_STACK( &board, F_Cu );
111 stack->SetStartLayer( F_Cu );
112 stack->SetEndLayer( In2_Cu );
113 stack->SetViaSize( 300000 );
114 stack->SetViaDrill( 150000 );
115 stack->SetPosition( stackPos );
116 board.Add( stack );
117 stack->Regenerate( &board, nullptr );
118
119 PCB_TRACK* segIn = addSegment( board, F_Cu, { 0, 0 }, stackPos );
120 PCB_TRACK* segOut = addSegment( board, In2_Cu, stackPos, { 2000000, 0 } );
121
122 board.BuildConnectivity();
123
124 for( PCB_TRACK* track : { segIn, segOut } )
125 view.Add( track );
126
127 view.Add( stack );
128
129 std::vector<BOARD_CONNECTED_ITEM*> startItems = { segIn };
131
132 BOOST_CHECK( segIn->IsSelected() );
133 BOOST_CHECK_MESSAGE( segOut->IsSelected(), "expansion must reach the track on the layer the stack lands on" );
134 BOOST_CHECK( stack->IsSelected() );
135}
136
137
138// The conservative treatment of a plain group is deliberate (see Issue24967).
139BOOST_AUTO_TEST_CASE( ExpansionStillLeavesAPlainGroupAlone )
140{
141 KIGFX::PCB_VIEW view;
142 BOARD board;
143 TOOL_MANAGER mgr;
144
145 board.SetCopperLayerCount( 4 );
147 mgr.SetEnvironment( &board, &view, nullptr, nullptr, nullptr );
148
150 mgr.RegisterTool( selTool );
151
152 PCB_TRACK* segAB = addSegment( board, F_Cu, { 0, 0 }, { 1000000, 0 } );
153 PCB_TRACK* segBC = addSegment( board, F_Cu, { 1000000, 0 }, { 2000000, 0 } );
154 PCB_TRACK* segCD = addSegment( board, F_Cu, { 2000000, 0 }, { 3000000, 0 } );
155
156 PCB_GROUP* group = new PCB_GROUP( &board );
157 group->AddItem( segBC );
158 board.Add( group );
159
160 board.BuildConnectivity();
161
162 for( PCB_TRACK* track : { segAB, segBC, segCD } )
163 view.Add( track );
164
165 view.Add( group );
166
167 std::vector<BOARD_CONNECTED_ITEM*> startItems = { segAB };
169
170 BOOST_CHECK( segAB->IsSelected() );
171 BOOST_CHECK( segCD->IsSelected() );
172 BOOST_CHECK( !segBC->IsSelected() );
173 BOOST_CHECK( !group->IsSelected() );
174}
175
176
void SetLayer(PCB_LAYER_ID aLayer) override
Set the layer this item is on.
Information pertinent to a Pcbnew printed circuit board.
Definition board.h:411
void Add(BOARD_ITEM *aItem, ADD_MODE aMode=ADD_MODE::INSERT, bool aSkipConnectivity=false) override
Removes an item from the container.
Definition board.cpp:1520
bool BuildConnectivity(PROGRESS_REPORTER *aReporter=nullptr)
Build or rebuild the board connectivity database for the board, especially the list of connected item...
Definition board.cpp:369
void SetCopperLayerCount(int aCount)
Definition board.cpp:1133
void SetEnabledLayers(const LSET &aLayerMask)
A proxy function that calls the correspondent function in m_BoardSettings.
Definition board.cpp:1194
bool IsSelected() const
Definition eda_item.h:134
virtual void Add(VIEW_ITEM *aItem, int aDrawPriority=-1) override
Add a VIEW_ITEM to the view.
Definition pcb_view.cpp:53
static const LSET & AllTechMask()
Return a mask holding all technical layers (no CU layer) on both side.
Definition lset.cpp:672
static LSET AllCuMask(int aCuLayerCount)
Return a mask holding the requested number of Cu PCB_LAYER_IDs.
Definition lset.cpp:595
void SetPosition(const VECTOR2I &aPos) override
A set of BOARD_ITEMs (i.e., without duplicates).
Definition pcb_group.h:51
The selection tool: currently supports:
void selectAllConnectedTracks(const std::vector< BOARD_CONNECTED_ITEM * > &aStartItems, STOP_CONDITION aStopCondition)
Select connected tracks and vias.
@ STOP_NEVER
Select the entire net.
void SetEnd(const VECTOR2I &aEnd)
Definition pcb_track.h:94
void SetStart(const VECTOR2I &aStart)
Definition pcb_track.h:97
virtual void SetWidth(int aWidth)
Definition pcb_track.h:91
A microvia stack: several single hop microvias, plus connecting traces for staggered stacks,...
void Regenerate(BOARD *aBoard, BOARD_COMMIT *aCommit)
Rebuild the member vias (and, for a staggered stack, the connecting traces) from the current stack se...
void SetStartLayer(PCB_LAYER_ID aLayer)
void SetViaSize(int aSize)
void SetViaDrill(int aDrill)
void SetEndLayer(PCB_LAYER_ID aLayer)
Master controller class:
void RegisterTool(TOOL_BASE *aTool)
Add a tool to the manager set and sets it up.
void SetEnvironment(EDA_ITEM *aModel, KIGFX::VIEW *aView, KIGFX::VIEW_CONTROLS *aViewControls, APP_SETTINGS_BASE *aSettings, TOOLS_HOLDER *aFrame)
Set the work environment (model, view, view controls and the parent window).
PCB_LAYER_ID
A quick note on layer IDs:
Definition layer_ids.h:56
@ In2_Cu
Definition layer_ids.h:63
@ In1_Cu
Definition layer_ids.h:62
@ F_Cu
Definition layer_ids.h:60
Class to handle a set of BOARD_ITEMs.
static bool addSegment(VRML_LAYER &model, IDF_SEGMENT *seg, int icont, int iseg)
BOOST_AUTO_TEST_SUITE(CadstarPartParser)
BOOST_AUTO_TEST_SUITE_END()
BOOST_AUTO_TEST_CASE(ExpansionSelectsTheStackItCrosses)
Test that selecting a track connected to a via stack expands the selection to include the stack as it...
static PCB_TRACK * addSegment(BOARD &aBoard, PCB_LAYER_ID aLayer, const VECTOR2I &aStart, const VECTOR2I &aEnd)
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:708