KiCad PCB EDA Suite
Loading...
Searching...
No Matches
test_board_netlist_updater_fpid_change.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, you may find one here:
18 * http://www.gnu.org/licenses/gpl-3.0.html
19 * or you may search the http://www.gnu.org website for the version 3 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
24#include <board.h>
25#include <footprint.h>
26#include <lib_id.h>
29#include <project.h>
31#include <tool/tool_manager.h>
34
35
36namespace
37{
38
39LIB_ID makeFpid( const wxString& aFull )
40{
41 LIB_ID id;
42 BOOST_REQUIRE_EQUAL( id.Parse( aFull ), -1 );
43 return id;
44}
45
46KIID_PATH pathOf( const KIID& aUuid )
47{
49 path.push_back( aUuid );
50 return path;
51}
52
53struct UPDATER_FIXTURE
54{
55 UPDATER_FIXTURE()
56 {
57 m_settingsManager.LoadProject( "" );
58 m_board = std::make_unique<BOARD>();
59 m_board->SetProject( &m_settingsManager.Prj() );
60
61 m_toolMgr.SetEnvironment( m_board.get(), nullptr, nullptr, nullptr, nullptr );
62 m_toolMgr.RegisterTool( new KI_TEST::DUMMY_TOOL() );
63 }
64
65 FOOTPRINT* addBoardFootprint( const wxString& aRef, const wxString& aFpid )
66 {
67 FOOTPRINT* fp = new FOOTPRINT( m_board.get() );
68 fp->SetReference( aRef );
69 fp->SetFPID( makeFpid( aFpid ) );
70 m_board->Add( fp );
71 return fp;
72 }
73
74 SETTINGS_MANAGER m_settingsManager;
75 std::unique_ptr<BOARD> m_board;
76 TOOL_MANAGER m_toolMgr;
77};
78
79} // namespace
80
81
82BOOST_AUTO_TEST_SUITE( BoardNetlistUpdaterFpidChange )
83
84
85// https://gitlab.com/kicad/code/kicad/-/issues/24960
86// The schematic assigned a different footprint to R1. With replace footprints off the
87// updater must keep the matched board footprint instead of adding a second R1.
88BOOST_FIXTURE_TEST_CASE( RelinkKeepsFootprintOnFpidChange, UPDATER_FIXTURE )
89{
90 FOOTPRINT* fp = addBoardFootprint( wxS( "R1" ), wxS( "TestLib:R_0603" ) );
91
92 KIID kiid;
94 netlist.AddComponent( new COMPONENT( makeFpid( wxS( "TestLib:R_0805" ) ), wxS( "R1" ), wxS( "R1" ), KIID_PATH(),
95 std::vector<KIID>{ kiid } ) );
96
97 BOARD_NETLIST_UPDATER updater( &m_toolMgr, m_board.get() );
98 updater.SetLookupByTimestamp( false );
99 updater.SetReplaceFootprints( false );
100 updater.SetDeleteUnusedFootprints( false );
101
102 BOOST_REQUIRE( updater.UpdateNetlist( netlist ) );
103
104 BOOST_CHECK_EQUAL( updater.GetErrorCount(), 0 );
106 BOOST_REQUIRE_EQUAL( m_board->Footprints().size(), 1 );
107
108 FOOTPRINT* survivor = m_board->Footprints().front();
109 BOOST_CHECK( survivor == fp );
110 BOOST_CHECK( survivor->GetFPID() == makeFpid( wxS( "TestLib:R_0603" ) ) );
111
112 // matched footprints get relinked to the symbol
113 BOOST_CHECK( survivor->GetPath() == pathOf( kiid ) );
114}
115
116
117// same thing with UUID matching
118BOOST_FIXTURE_TEST_CASE( UuidMatchKeepsFootprintOnFpidChange, UPDATER_FIXTURE )
119{
120 KIID kiid;
121
122 FOOTPRINT* fp = addBoardFootprint( wxS( "R1" ), wxS( "TestLib:R_0603" ) );
123 fp->SetPath( pathOf( kiid ) );
124
126 netlist.AddComponent( new COMPONENT( makeFpid( wxS( "TestLib:R_0805" ) ), wxS( "R1" ), wxS( "R1" ), KIID_PATH(),
127 std::vector<KIID>{ kiid } ) );
128
129 BOARD_NETLIST_UPDATER updater( &m_toolMgr, m_board.get() );
130 updater.SetLookupByTimestamp( true );
131 updater.SetReplaceFootprints( false );
132 updater.SetDeleteUnusedFootprints( false );
133
134 BOOST_REQUIRE( updater.UpdateNetlist( netlist ) );
135
136 BOOST_CHECK_EQUAL( updater.GetErrorCount(), 0 );
138 BOOST_REQUIRE_EQUAL( m_board->Footprints().size(), 1 );
139 BOOST_CHECK( m_board->Footprints().front() == fp );
140 BOOST_CHECK( m_board->Footprints().front()->GetFPID() == makeFpid( wxS( "TestLib:R_0603" ) ) );
141}
142
143
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 SetLookupByTimestamp(bool aEnabled)
void SetFPID(const LIB_ID &aFPID)
Definition footprint.h:445
void SetPath(const KIID_PATH &aPath)
Definition footprint.h:468
const LIB_ID & GetFPID() const
Definition footprint.h:444
void SetReference(const wxString &aReference)
Definition footprint.h:850
const KIID_PATH & GetPath() const
Definition footprint.h:467
Definition kiid.h:44
A logical library item identifier and consists of various portions much like a URI.
Definition lib_id.h:45
Store information read from a netlist along with the flags used to update the NETLIST in the BOARD.
PARSE_RESULT Parse(const std::string &aString, NOTATION aNotation=NOTATION::SI, SIM_VALUE::TYPE aValueType=SIM_VALUE::TYPE_FLOAT)
BOOST_FIXTURE_TEST_CASE(ServerStartsAndResponds, API_SERVER_E2E_FIXTURE)
BOOST_FIXTURE_TEST_CASE(RelinkKeepsFootprintOnFpidChange, UPDATER_FIXTURE)
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
BOOST_CHECK_EQUAL(result, "25.4")
static LIB_ID makeFpid(const wxString &aLibrary, const wxString &aItem)