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
46BOOST_AUTO_TEST_CASE( ExpansionCrossesAStackWithoutSelectingIt )
47{
48 // view must outlive board so board items unregister from a live view at teardown.
49 KIGFX::PCB_VIEW view;
50 BOARD board;
51 TOOL_MANAGER mgr;
52
53 board.SetCopperLayerCount( 4 );
55 mgr.SetEnvironment( &board, &view, nullptr, nullptr, nullptr );
56
58 mgr.RegisterTool( selTool );
59
60 VECTOR2I stackPos( 1000000, 0 );
61
62 PCB_VIA_STACK* stack = new PCB_VIA_STACK( &board, F_Cu );
63 stack->SetStartLayer( F_Cu );
64 stack->SetEndLayer( In1_Cu );
65 stack->SetViaSize( 300000 );
66 stack->SetViaDrill( 150000 );
67 stack->SetPosition( stackPos );
68 board.Add( stack );
69 stack->Regenerate( &board, nullptr );
70
71 PCB_TRACK* segIn = addSegment( board, F_Cu, { 0, 0 }, stackPos );
72 PCB_TRACK* segOut = addSegment( board, In1_Cu, stackPos, { 2000000, 0 } );
73
74 board.BuildConnectivity();
75
76 for( PCB_TRACK* track : { segIn, segOut } )
77 view.Add( track );
78
79 view.Add( stack );
80
81 std::vector<BOARD_CONNECTED_ITEM*> startItems = { segIn };
83
84 BOOST_CHECK( segIn->IsSelected() );
85 BOOST_CHECK_MESSAGE( segOut->IsSelected(), "expansion should reach across the stack" );
86
87 BOOST_CHECK_MESSAGE( !stack->IsSelected(), "generator members stay out of the expansion" );
88}
89
90
91// A stacked stack puts every hop at one position, so expansion has to walk down all of them.
92BOOST_AUTO_TEST_CASE( ExpansionCrossesAMultiHopStackedStack )
93{
94 KIGFX::PCB_VIEW view;
95 BOARD board;
96 TOOL_MANAGER mgr;
97
98 board.SetCopperLayerCount( 4 );
100 mgr.SetEnvironment( &board, &view, nullptr, nullptr, nullptr );
101
103 mgr.RegisterTool( selTool );
104
105 VECTOR2I stackPos( 1000000, 0 );
106
107 PCB_VIA_STACK* stack = new PCB_VIA_STACK( &board, F_Cu );
108 stack->SetStartLayer( F_Cu );
109 stack->SetEndLayer( In2_Cu );
110 stack->SetViaSize( 300000 );
111 stack->SetViaDrill( 150000 );
112 stack->SetPosition( stackPos );
113 board.Add( stack );
114 stack->Regenerate( &board, nullptr );
115
116 PCB_TRACK* segIn = addSegment( board, F_Cu, { 0, 0 }, stackPos );
117 PCB_TRACK* segOut = addSegment( board, In2_Cu, stackPos, { 2000000, 0 } );
118
119 board.BuildConnectivity();
120
121 for( PCB_TRACK* track : { segIn, segOut } )
122 view.Add( track );
123
124 view.Add( stack );
125
126 std::vector<BOARD_CONNECTED_ITEM*> startItems = { segIn };
128
129 BOOST_CHECK( segIn->IsSelected() );
130 BOOST_CHECK_MESSAGE( segOut->IsSelected(), "expansion must reach the track on the layer the stack lands on" );
131 BOOST_CHECK( !stack->IsSelected() );
132}
133
134
135// The conservative treatment of a plain group is deliberate (see Issue24967).
136BOOST_AUTO_TEST_CASE( ExpansionStillLeavesAPlainGroupAlone )
137{
138 KIGFX::PCB_VIEW view;
139 BOARD board;
140 TOOL_MANAGER mgr;
141
142 board.SetCopperLayerCount( 4 );
144 mgr.SetEnvironment( &board, &view, nullptr, nullptr, nullptr );
145
147 mgr.RegisterTool( selTool );
148
149 PCB_TRACK* segAB = addSegment( board, F_Cu, { 0, 0 }, { 1000000, 0 } );
150 PCB_TRACK* segBC = addSegment( board, F_Cu, { 1000000, 0 }, { 2000000, 0 } );
151 PCB_TRACK* segCD = addSegment( board, F_Cu, { 2000000, 0 }, { 3000000, 0 } );
152
153 PCB_GROUP* group = new PCB_GROUP( &board );
154 group->AddItem( segBC );
155 board.Add( group );
156
157 board.BuildConnectivity();
158
159 for( PCB_TRACK* track : { segAB, segBC, segCD } )
160 view.Add( track );
161
162 view.Add( group );
163
164 std::vector<BOARD_CONNECTED_ITEM*> startItems = { segAB };
166
167 BOOST_CHECK( segAB->IsSelected() );
168 BOOST_CHECK( segCD->IsSelected() );
169 BOOST_CHECK( !segBC->IsSelected() );
170 BOOST_CHECK( !group->IsSelected() );
171}
172
173
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:409
void Add(BOARD_ITEM *aItem, ADD_MODE aMode=ADD_MODE::INSERT, bool aSkipConnectivity=false) override
Removes an item from the container.
Definition board.cpp:1497
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:364
void SetCopperLayerCount(int aCount)
Definition board.cpp:1137
void SetEnabledLayers(const LSET &aLayerMask)
A proxy function that calls the correspondent function in m_BoardSettings.
Definition board.cpp:1203
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:89
void SetStart(const VECTOR2I &aStart)
Definition pcb_track.h:92
virtual void SetWidth(int aWidth)
Definition pcb_track.h:86
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(ExpansionCrossesAStackWithoutSelectingIt)
static PCB_TRACK * addSegment(BOARD &aBoard, PCB_LAYER_ID aLayer, const VECTOR2I &aStart, const VECTOR2I &aEnd)
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:683