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} // namespace
72
73
74BOOST_AUTO_TEST_SUITE( BoardNetlistUpdaterNestedGroups )
75
76
77BOOST_AUTO_TEST_CASE( NestedSchematicGroupNestsOnBoard )
78{
79 // The updater dereferences the board's project, so the board needs one.
80 SETTINGS_MANAGER settingsManager;
81 settingsManager.LoadProject( "" );
82
83 std::unique_ptr<BOARD> board = std::make_unique<BOARD>();
84 board->SetProject( &settingsManager.Prj() );
85
86 LIB_ID fpid;
87 BOOST_REQUIRE_EQUAL( fpid.Parse( wxS( "TestLib:R" ) ), -1 );
88
89 addFootprint( board.get(), wxS( "R1" ), fpid );
90 addFootprint( board.get(), wxS( "R2" ), fpid );
91 addFootprint( board.get(), wxS( "X3" ), fpid );
92 addFootprint( board.get(), wxS( "X4" ), fpid );
93 addFootprint( board.get(), wxS( "X5" ), fpid );
94
96
97 KIID r1 = addComponent( netlist, wxS( "R1" ), fpid );
98 KIID r2 = addComponent( netlist, wxS( "R2" ), fpid );
99 KIID x3 = addComponent( netlist, wxS( "X3" ), fpid );
100 KIID x4 = addComponent( netlist, wxS( "X4" ), fpid );
101 KIID x5 = addComponent( netlist, wxS( "X5" ), fpid );
102
103 KIID childUuid;
104 KIID parentUuid;
105
106 netlist.AddGroup( new NETLIST_GROUP{ wxS( "RPI" ), childUuid, LIB_ID(), std::vector<KIID>{ r1, r2 } } );
107
108 // RPI1 nests RPI: its members include the child group's uuid.
109 netlist.AddGroup(
110 new NETLIST_GROUP{ wxS( "RPI1" ), parentUuid, LIB_ID(), std::vector<KIID>{ x3, x4, x5, childUuid } } );
111
112 netlist.ApplyGroupMembership();
113
114 TOOL_MANAGER toolMgr;
115 toolMgr.SetEnvironment( board.get(), nullptr, nullptr, nullptr, nullptr );
116 toolMgr.RegisterTool( new KI_TEST::DUMMY_TOOL() );
117
118 BOARD_NETLIST_UPDATER updater( &toolMgr, board.get() );
119 updater.SetTransferGroups( true );
120 updater.SetReplaceFootprints( false );
121 updater.SetDeleteUnusedFootprints( false );
122
123 BOOST_REQUIRE( updater.UpdateNetlist( netlist ) );
124
125 PCB_GROUP* parentGroup = findGroup( board.get(), parentUuid );
126 PCB_GROUP* childGroup = findGroup( board.get(), childUuid );
127
128 BOOST_REQUIRE_MESSAGE( parentGroup, "parent group RPI1 was not created on the board" );
129 BOOST_REQUIRE_MESSAGE( childGroup, "child group RPI was not created on the board" );
130
131 BOOST_CHECK_MESSAGE( childGroup->GetParentGroup() == static_cast<EDA_GROUP*>( parentGroup ),
132 "child group RPI is not nested inside parent group RPI1 "
133 "(nested group membership was lost on update)" );
134
135 BOOST_CHECK_MESSAGE( parentGroup->GetItems().count( childGroup ) == 1,
136 "parent group RPI1 does not list child group RPI as a member" );
137}
138
139
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:1295
const GROUPS & Groups() const
The groups must maintain the following invariants.
Definition board.h:454
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:442
void SetReference(const wxString &aReference)
Definition footprint.h:847
Definition kiid.h:44
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:48
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:49
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
BOOST_CHECK_MESSAGE(totalMismatches==0, std::to_string(totalMismatches)+" board(s) with strategy disagreements")