KiCad PCB EDA Suite
Loading...
Searching...
No Matches
test_issue25521.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
22
23#include <map>
24#include <board.h>
26#include <zone.h>
27#include <zone_settings_bag.h>
28
29// Regression test for https://gitlab.com/kicad/code/kicad/-/work_items/25521
30//
31// The Zone Manager edits clones of the board zones. Resolving a unique name against the board
32// originals made every clone collide with itself, so each pass through the dialog appended another
33// suffix and "bigger" became "bigger_1", then "bigger_2".
34
35BOOST_AUTO_TEST_SUITE( Issue25521 )
36
37
38BOOST_AUTO_TEST_CASE( ZoneManagerKeepsZoneNames )
39{
40 SETTINGS_MANAGER settingsManager;
41 std::unique_ptr<BOARD> board;
42
43 KI_TEST::LoadBoard( settingsManager, "issue25521_zone_names", board );
44
45 ZONE_SETTINGS_BAG bag( board.get() );
46
47 BOOST_REQUIRE_EQUAL( bag.GetClonedZoneList().size(), 3u );
48
49 std::map<ZONE*, wxString> originalNames;
50
51 for( const auto& [zone, clone] : bag.GetZonesCloneMap() )
52 originalNames[clone.get()] = zone->GetZoneName();
53
54 // Every selection change in the manager reads the panel back, resolving the name once per zone
55 for( ZONE* clone : bag.GetClonedZoneList() )
56 {
57 std::shared_ptr<ZONE_SETTINGS> settings = bag.GetZoneSettings( clone );
58
59 settings->m_Name = bag.GetUniqueZoneName( *board, settings->m_Name, clone );
60 }
61
63
64 for( ZONE* clone : bag.GetClonedZoneList() )
65 BOOST_CHECK_EQUAL( clone->GetZoneName(), originalNames[clone] );
66}
67
68
std::unordered_map< ZONE *, std::shared_ptr< ZONE > > & GetZonesCloneMap()
void UpdateClonedZones()
The cloned list is the working storage.
wxString GetUniqueZoneName(const BOARD &aBoard, const wxString &aBaseName, const ZONE *aZone) const
Return a name based on aBaseName that no other zone on aBoard uses.
std::vector< ZONE * > & GetClonedZoneList()
std::shared_ptr< ZONE_SETTINGS > GetZoneSettings(ZONE *aZone)
Handle a list of polygons defining a copper zone.
Definition zone.h:70
void LoadBoard(SETTINGS_MANAGER &aSettingsManager, const wxString &aRelPath, std::unique_ptr< BOARD > &aBoard)
BOOST_AUTO_TEST_CASE(HorizontalAlignment)
BOOST_AUTO_TEST_SUITE(CadstarPartParser)
BOOST_AUTO_TEST_SUITE_END()
BOOST_CHECK_EQUAL(result, "25.4")