KiCad PCB EDA Suite
Loading...
Searching...
No Matches
test_issue24760_plot_page_numbers.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
20// Regression test for https://gitlab.com/kicad/code/kicad/-/issues/24760
21
23
24#include <map>
25#include <memory>
26#include <set>
27
28#include <eeschema_helpers.h>
29#include <locale_io.h>
30#include <sch_sheet_path.h>
31#include <schematic.h>
32
33
34// The reproduction project is an 11-page hierarchy that was saved with duplicate
35// page numbers (two sheets numbered "11", two numbered "12") and gaps. Plotting
36// stamps each page's title-block Id from the sheet's stored page number, so the
37// duplicates produced two pages sharing an Id (and an impossible "12/11") while
38// others were missing. Loading the project must repair the collisions so every
39// sheet carries a unique page number; the CLI/headless loader is used directly
40// because kicad-cli sch export pdf goes through it rather than the GUI.
41BOOST_AUTO_TEST_CASE( Issue24760PlotPageNumbers )
42{
44
45 wxString schPath = wxString::FromUTF8( KI_TEST::GetEeschemaTestDataDir() ) +
46 wxS( "issue24760/issue24760.kicad_sch" );
47
48 std::unique_ptr<SCHEMATIC> sch( EESCHEMA_HELPERS::LoadSchematic( schPath, true, false ) );
49 BOOST_REQUIRE( sch != nullptr );
50
51 SCH_SHEET_LIST sheets = sch->Hierarchy();
52
53 // Root sheet plus ten sub-sheets.
54 BOOST_REQUIRE_EQUAL( sheets.size(), 11u );
55
56 std::map<wxString, int> pageCounts;
57
58 for( const SCH_SHEET_PATH& sheet : sheets )
59 {
60 wxString pageNumber = sheet.GetPageNumber();
61 BOOST_CHECK_MESSAGE( !pageNumber.IsEmpty(),
62 "Sheet " << sheet.PathHumanReadable().ToStdString()
63 << " has no page number" );
64 pageCounts[pageNumber]++;
65 }
66
67 for( const auto& [pageNumber, count] : pageCounts )
68 {
69 BOOST_CHECK_MESSAGE( count == 1,
70 "Page number " << pageNumber.ToStdString() << " is shared by "
71 << count << " sheets" );
72 }
73
74 BOOST_CHECK_EQUAL( pageCounts.size(), sheets.size() );
75}
static SCHEMATIC * LoadSchematic(const wxString &aFileName, bool aSetActive, bool aForceDefaultProject, PROJECT *aProject=nullptr, bool aCalculateConnectivity=true)
Instantiate the current locale within a scope in which you are expecting exceptions to be thrown.
Definition locale_io.h:37
A container for handling SCH_SHEET_PATH objects in a flattened hierarchy.
Handle access to a stack of flattened SCH_SHEET objects by way of a path for creating a flattened sch...
std::string GetEeschemaTestDataDir()
Get the configured location of Eeschema test data.
Definition of the SCH_SHEET_PATH and SCH_SHEET_LIST classes for Eeschema.
std::vector< FAB_LAYER_COLOR > dummy
BOOST_REQUIRE(intersection.has_value()==c.ExpectedIntersection.has_value())
BOOST_AUTO_TEST_CASE(Issue24760PlotPageNumbers)
BOOST_CHECK_MESSAGE(totalMismatches==0, std::to_string(totalMismatches)+" board(s) with strategy disagreements")
BOOST_CHECK_EQUAL(result, "25.4")