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.SetIsDryRun( false );
99 updater.SetWillDrag( false );
100 updater.SetLookupByTimestamp( false );
101 updater.SetReplaceFootprints( false );
102 updater.SetDeleteUnusedFootprints( false );
103
104 BOOST_REQUIRE( updater.UpdateNetlist( netlist ) );
105
106 BOOST_CHECK_EQUAL( updater.GetErrorCount(), 0 );
108 BOOST_REQUIRE_EQUAL( m_board->Footprints().size(), 1 );
109
110 FOOTPRINT* survivor = m_board->Footprints().front();
111 BOOST_CHECK( survivor == fp );
112 BOOST_CHECK( survivor->GetFPID() == makeFpid( wxS( "TestLib:R_0603" ) ) );
113
114 // matched footprints get relinked to the symbol
115 BOOST_CHECK( survivor->GetPath() == pathOf( kiid ) );
116}
117
118
119// same thing with UUID matching
120BOOST_FIXTURE_TEST_CASE( UuidMatchKeepsFootprintOnFpidChange, UPDATER_FIXTURE )
121{
122 KIID kiid;
123
124 FOOTPRINT* fp = addBoardFootprint( wxS( "R1" ), wxS( "TestLib:R_0603" ) );
125 fp->SetPath( pathOf( kiid ) );
126
128 netlist.AddComponent( new COMPONENT( makeFpid( wxS( "TestLib:R_0805" ) ), wxS( "R1" ), wxS( "R1" ), KIID_PATH(),
129 std::vector<KIID>{ kiid } ) );
130
131 BOARD_NETLIST_UPDATER updater( &m_toolMgr, m_board.get() );
132 updater.SetWillDrag( false );
133 updater.SetLookupByTimestamp( true );
134 updater.SetReplaceFootprints( false );
135 updater.SetDeleteUnusedFootprints( false );
136
137 BOOST_REQUIRE( updater.UpdateNetlist( netlist ) );
138
139 BOOST_CHECK_EQUAL( updater.GetErrorCount(), 0 );
141 BOOST_REQUIRE_EQUAL( m_board->Footprints().size(), 1 );
142 BOOST_CHECK( m_board->Footprints().front() == fp );
143 BOOST_CHECK( m_board->Footprints().front()->GetFPID() == makeFpid( wxS( "TestLib:R_0603" ) ) );
144}
145
146
Update the BOARD with a new netlist.
bool UpdateNetlist(NETLIST &aNetlist)
Update the board's components according to the new netlist.
void SetWillDrag(bool aWillDrag)
void SetIsDryRun(bool aEnabled)
Enable dry run mode (just report, no changes to PCB).
void SetDeleteUnusedFootprints(bool aEnabled)
void SetReplaceFootprints(bool aEnabled)
void SetLookupByTimestamp(bool aEnabled)
void SetFPID(const LIB_ID &aFPID)
Definition footprint.h:418
void SetPath(const KIID_PATH &aPath)
Definition footprint.h:456
const LIB_ID & GetFPID() const
Definition footprint.h:417
void SetReference(const wxString &aReference)
Definition footprint.h:799
const KIID_PATH & GetPath() const
Definition footprint.h:455
Definition kiid.h:46
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)