KiCad PCB EDA Suite
Loading...
Searching...
No Matches
test_board_netlist_updater_nested_groups.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 3
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
20/*
21 * Regression test for https://gitlab.com/kicad/code/kicad/-/work_items/24766
22 *
23 * A nested schematic group must stay nested on the board after Update PCB from Schematic.
24 */
25
26#include <board.h>
27#include <footprint.h>
28#include <pcb_group.h>
31#include <lib_id.h>
32#include <project.h>
34#include <tool/tool_manager.h>
37
38
39namespace
40{
41
42FOOTPRINT* addFootprint( BOARD* aBoard, const wxString& aRef, const LIB_ID& aFpid )
43{
44 FOOTPRINT* fp = new FOOTPRINT( aBoard );
45 fp->SetReference( aRef );
46 fp->SetFPID( aFpid );
47 aBoard->Add( fp );
48 return fp;
49}
50
51
52KIID addComponent( NETLIST& aNetlist, const wxString& aRef, const LIB_ID& aFpid )
53{
54 KIID kiid;
55 aNetlist.AddComponent( new COMPONENT( aFpid, aRef, aRef, KIID_PATH(), std::vector<KIID>{ kiid } ) );
56 return kiid;
57}
58
59
60PCB_GROUP* findGroup( BOARD* aBoard, const KIID& aUuid )
61{
62 for( PCB_GROUP* group : aBoard->Groups() )
63 {
64 if( group->m_Uuid == aUuid )
65 return group;
66 }
67
68 return nullptr;
69}
70
71
72KIID_PATH pathOf( const KIID& aUuid )
73{
75 path.push_back( aUuid );
76 return path;
77}
78
79} // namespace
80
81
82BOOST_AUTO_TEST_SUITE( BoardNetlistUpdaterNestedGroups )
83
84
85BOOST_AUTO_TEST_CASE( NestedSchematicGroupNestsOnBoard )
86{
87 // The updater dereferences the board's project, so the board needs one.
88 SETTINGS_MANAGER settingsManager;
89 settingsManager.LoadProject( "" );
90
91 std::unique_ptr<BOARD> board = std::make_unique<BOARD>();
92 board->SetProject( &settingsManager.Prj() );
93
94 LIB_ID fpid;
95 BOOST_REQUIRE_EQUAL( fpid.Parse( wxS( "TestLib:R" ) ), -1 );
96
97 addFootprint( board.get(), wxS( "R1" ), fpid );
98 addFootprint( board.get(), wxS( "R2" ), fpid );
99 addFootprint( board.get(), wxS( "X3" ), fpid );
100 addFootprint( board.get(), wxS( "X4" ), fpid );
101 addFootprint( board.get(), wxS( "X5" ), fpid );
102
104
105 KIID r1 = addComponent( netlist, wxS( "R1" ), fpid );
106 KIID r2 = addComponent( netlist, wxS( "R2" ), fpid );
107 KIID x3 = addComponent( netlist, wxS( "X3" ), fpid );
108 KIID x4 = addComponent( netlist, wxS( "X4" ), fpid );
109 KIID x5 = addComponent( netlist, wxS( "X5" ), fpid );
110
111 KIID childUuid;
112 KIID parentUuid;
113
114 netlist.AddGroup( new NETLIST_GROUP{ wxS( "RPI" ), childUuid, LIB_ID(),
115 std::vector<KIID_PATH>{ pathOf( r1 ), pathOf( r2 ) } } );
116
117 // RPI1 nests RPI: its members include the child group's uuid.
118 netlist.AddGroup( new NETLIST_GROUP{
119 wxS( "RPI1" ), parentUuid, LIB_ID(),
120 std::vector<KIID_PATH>{ pathOf( x3 ), pathOf( x4 ), pathOf( x5 ), pathOf( childUuid ) } } );
121
122 netlist.ApplyGroupMembership();
123
124 TOOL_MANAGER toolMgr;
125 toolMgr.SetEnvironment( board.get(), nullptr, nullptr, nullptr, nullptr );
126 toolMgr.RegisterTool( new KI_TEST::DUMMY_TOOL() );
127
128 BOARD_NETLIST_UPDATER updater( &toolMgr, board.get() );
129 updater.SetTransferGroups( true );
130 updater.SetReplaceFootprints( false );
131 updater.SetDeleteUnusedFootprints( false );
132
133 BOOST_REQUIRE( updater.UpdateNetlist( netlist ) );
134
135 PCB_GROUP* parentGroup = findGroup( board.get(), parentUuid );
136 PCB_GROUP* childGroup = findGroup( board.get(), childUuid );
137
138 BOOST_REQUIRE_MESSAGE( parentGroup, "parent group RPI1 was not created on the board" );
139 BOOST_REQUIRE_MESSAGE( childGroup, "child group RPI was not created on the board" );
140
141 BOOST_CHECK_MESSAGE( childGroup->GetParentGroup() == static_cast<EDA_GROUP*>( parentGroup ),
142 "child group RPI is not nested inside parent group RPI1 "
143 "(nested group membership was lost on update)" );
144
145 BOOST_CHECK_MESSAGE( parentGroup->GetItems().count( childGroup ) == 1,
146 "parent group RPI1 does not list child group RPI as a member" );
147}
148
149
Update the BOARD with a new netlist.
bool UpdateNetlist(NETLIST &aNetlist)
Update the board's components according to the new netlist.
void SetDeleteUnusedFootprints(bool aEnabled)
void SetReplaceFootprints(bool aEnabled)
void SetTransferGroups(bool aEnabled)
Information pertinent to a Pcbnew printed circuit board.
Definition board.h:373
void Add(BOARD_ITEM *aItem, ADD_MODE aMode=ADD_MODE::INSERT, bool aSkipConnectivity=false) override
Removes an item from the container.
Definition board.cpp:1355
const GROUPS & Groups() const
The groups must maintain the following invariants.
Definition board.h:461
A set of EDA_ITEMs (i.e., without duplicates).
Definition eda_group.h:42
std::unordered_set< EDA_ITEM * > & GetItems()
Definition eda_group.h:50
virtual EDA_GROUP * GetParentGroup() const
Definition eda_item.h:114
void SetFPID(const LIB_ID &aFPID)
Definition footprint.h:445
void SetReference(const wxString &aReference)
Definition footprint.h:863
Definition kiid.h:46
A logical library item identifier and consists of various portions much like a URI.
Definition lib_id.h:45
int Parse(const UTF8 &aId, bool aFix=false)
Parse LIB_ID with the information from aId.
Definition lib_id.cpp:65
Store information read from a netlist along with the flags used to update the NETLIST in the BOARD.
void AddComponent(COMPONENT *aComponent)
Add aComponent to the NETLIST.
A set of BOARD_ITEMs (i.e., without duplicates).
Definition pcb_group.h:51
bool LoadProject(const wxString &aFullPath, bool aSetActive=true)
Load a project or sets up a new project with a specified path.
PROJECT & Prj() const
A helper while we are not MDI-capable – return the one and only project.
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).
Class to handle a set of BOARD_ITEMs.
BOOST_AUTO_TEST_CASE(HorizontalAlignment)
BOOST_AUTO_TEST_SUITE(CadstarPartParser)
BOOST_REQUIRE(intersection.has_value()==c.ExpectedIntersection.has_value())
BOOST_AUTO_TEST_SUITE_END()
std::string netlist
std::string path