KiCad PCB EDA Suite
Loading...
Searching...
No Matches
test_issue24290_local_labels_across_top_sheets.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
27
28#include <boost/test/unit_test.hpp>
29
30#include <connection_graph.h>
31#include <sch_label.h>
32#include <sch_screen.h>
33#include <sch_sheet.h>
34#include <schematic.h>
36
37
39{
42 {
43 m_settingsManager.LoadProject( "" );
44 m_schematic = std::make_unique<SCHEMATIC>( nullptr );
45 m_schematic->SetProject( &m_settingsManager.Prj() );
46 }
47
49
50 SCH_SHEET* makeTopLevelSheet( const wxString& aName, const wxString& aFileName )
51 {
52 SCH_SHEET* sheet = new SCH_SHEET( m_schematic.get() );
53 SCH_SCREEN* screen = new SCH_SCREEN( m_schematic.get() );
54
55 const_cast<KIID&>( sheet->m_Uuid ) = screen->GetUuid();
56 sheet->SetScreen( screen );
57 sheet->GetField( FIELD_T::SHEET_NAME )->SetText( aName );
58 screen->SetFileName( aFileName );
59
60 return sheet;
61 }
62
63 void addLocalLabel( SCH_SHEET* aSheet, const wxString& aText, const VECTOR2I& aPos )
64 {
65 SCH_LABEL* label = new SCH_LABEL( aPos, aText );
66 aSheet->GetScreen()->Append( label );
67 }
68
70 std::unique_ptr<SCHEMATIC> m_schematic;
71};
72
73
74BOOST_FIXTURE_TEST_CASE( Issue24290_LocalLabelsDontCrossTopLevelSheets, ISSUE24290_FIXTURE )
75{
76 // Build three sibling top-level sheets, each with a local label "LOCAL".
77 SCH_SHEET* sheetA = makeTopLevelSheet( "SheetA", "sheet_a.kicad_sch" );
78 SCH_SHEET* sheetB = makeTopLevelSheet( "SheetB", "sheet_b.kicad_sch" );
79 SCH_SHEET* sheetC = makeTopLevelSheet( "SheetC", "sheet_c.kicad_sch" );
80
81 m_schematic->SetTopLevelSheets( { sheetA, sheetB, sheetC } );
82
83 sheetA->GetScreen()->SetPageNumber( wxT( "1" ) );
84 sheetB->GetScreen()->SetPageNumber( wxT( "2" ) );
85 sheetC->GetScreen()->SetPageNumber( wxT( "3" ) );
86
87 addLocalLabel( sheetA, "LOCAL", VECTOR2I( 0, 0 ) );
88 addLocalLabel( sheetB, "LOCAL", VECTOR2I( 0, 0 ) );
89 addLocalLabel( sheetC, "LOCAL", VECTOR2I( 0, 0 ) );
90
91 m_schematic->RefreshHierarchy();
92 SCH_SHEET_LIST sheets = m_schematic->Hierarchy();
93 BOOST_REQUIRE_EQUAL( sheets.size(), 3u );
94
95 m_schematic->ConnectionGraph()->Recalculate( sheets, true );
96
97 // Walk the net map and collect the net codes of every subgraph driven by
98 // a local label whose text is "LOCAL". If the bug is present, all three
99 // share the same net code; once fixed, they must each have their own.
100 std::set<int> labelNetCodes;
101 std::set<wxString> labelNetNames;
102
103 for( const auto& [key, subgraphs] : m_schematic->ConnectionGraph()->GetNetMap() )
104 {
105 for( CONNECTION_SUBGRAPH* sg : subgraphs )
106 {
107 const SCH_ITEM* driver = sg->GetDriver();
108
109 if( !driver || driver->Type() != SCH_LABEL_T )
110 continue;
111
112 if( static_cast<const SCH_LABEL*>( driver )->GetText() == wxT( "LOCAL" ) )
113 {
114 labelNetCodes.insert( key.Netcode );
115 labelNetNames.insert( key.Name );
116 }
117 }
118 }
119
120 BOOST_TEST_MESSAGE( "Distinct LOCAL net names: " << labelNetNames.size() );
121
122 for( const wxString& n : labelNetNames )
123 BOOST_TEST_MESSAGE( " " << n );
124
125 BOOST_CHECK_MESSAGE( labelNetCodes.size() == 3u, "Local labels 'LOCAL' on three different top-level sheets should "
126 "yield three distinct net codes, got "
127 << labelNetCodes.size() );
128
129 BOOST_CHECK_MESSAGE( labelNetNames.size() == 3u, "Local labels 'LOCAL' on three different top-level sheets should "
130 "yield three distinct net names, got "
131 << labelNetNames.size() );
132}
void SetPageNumber(const wxString &aPageNumber)
Definition base_screen.h:75
A subgraph is a set of items that are electrically connected on a single sheet.
const KIID m_Uuid
Definition eda_item.h:531
KICAD_T Type() const
Returns the type of object.
Definition eda_item.h:108
Definition kiid.h:44
void SetText(const wxString &aText) override
Base class for any item which can be embedded within the SCHEMATIC container class,...
Definition sch_item.h:162
void Append(SCH_ITEM *aItem, bool aUpdateLibSymbol=true)
const KIID & GetUuid() const
Definition sch_screen.h:529
void SetFileName(const wxString &aFileName)
Set the file name for this screen to aFileName.
A container for handling SCH_SHEET_PATH objects in a flattened hierarchy.
Sheet symbol placed in a schematic, and is the entry point for a sub schematic.
Definition sch_sheet.h:44
SCH_FIELD * GetField(FIELD_T aFieldType)
Return a mandatory field in this sheet.
SCH_SCREEN * GetScreen() const
Definition sch_sheet.h:139
void SetScreen(SCH_SCREEN *aScreen)
Set the SCH_SCREEN associated with this sheet to aScreen.
Test for issue #24290: Local labels create connections between top-level sheets.
void addLocalLabel(SCH_SHEET *aSheet, const wxString &aText, const VECTOR2I &aPos)
SCH_SHEET * makeTopLevelSheet(const wxString &aName, const wxString &aFileName)
BOOST_FIXTURE_TEST_CASE(Issue24290_LocalLabelsDontCrossTopLevelSheets, ISSUE24290_FIXTURE)
BOOST_CHECK_MESSAGE(totalMismatches==0, std::to_string(totalMismatches)+" board(s) with strategy disagreements")
BOOST_TEST_MESSAGE("\n=== Real-World Polygon PIP Benchmark ===\n"<< formatTable(table))
@ SCH_LABEL_T
Definition typeinfo.h:164
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:683