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, you may find one here:
18 * https://www.gnu.org/licenses/gpl-3.0.en.html
19 */
20
28
29#include <boost/test/unit_test.hpp>
30
31#include <connection_graph.h>
32#include <sch_label.h>
33#include <sch_screen.h>
34#include <sch_sheet.h>
35#include <schematic.h>
37
38
40{
43 {
44 m_settingsManager.LoadProject( "" );
45 m_schematic = std::make_unique<SCHEMATIC>( nullptr );
46 m_schematic->SetProject( &m_settingsManager.Prj() );
47 }
48
50
51 SCH_SHEET* makeTopLevelSheet( const wxString& aName, const wxString& aFileName )
52 {
53 SCH_SHEET* sheet = new SCH_SHEET( m_schematic.get() );
54 SCH_SCREEN* screen = new SCH_SCREEN( m_schematic.get() );
55
56 const_cast<KIID&>( sheet->m_Uuid ) = screen->GetUuid();
57 sheet->SetScreen( screen );
58 sheet->GetField( FIELD_T::SHEET_NAME )->SetText( aName );
59 screen->SetFileName( aFileName );
60
61 return sheet;
62 }
63
64 void addLocalLabel( SCH_SHEET* aSheet, const wxString& aText, const VECTOR2I& aPos )
65 {
66 SCH_LABEL* label = new SCH_LABEL( aPos, aText );
67 aSheet->GetScreen()->Append( label );
68 }
69
71 std::unique_ptr<SCHEMATIC> m_schematic;
72};
73
74
75BOOST_FIXTURE_TEST_CASE( Issue24290_LocalLabelsDontCrossTopLevelSheets, ISSUE24290_FIXTURE )
76{
77 // Build three sibling top-level sheets, each with a local label "LOCAL".
78 SCH_SHEET* sheetA = makeTopLevelSheet( "SheetA", "sheet_a.kicad_sch" );
79 SCH_SHEET* sheetB = makeTopLevelSheet( "SheetB", "sheet_b.kicad_sch" );
80 SCH_SHEET* sheetC = makeTopLevelSheet( "SheetC", "sheet_c.kicad_sch" );
81
82 m_schematic->SetTopLevelSheets( { sheetA, sheetB, sheetC } );
83
84 sheetA->GetScreen()->SetPageNumber( wxT( "1" ) );
85 sheetB->GetScreen()->SetPageNumber( wxT( "2" ) );
86 sheetC->GetScreen()->SetPageNumber( wxT( "3" ) );
87
88 addLocalLabel( sheetA, "LOCAL", VECTOR2I( 0, 0 ) );
89 addLocalLabel( sheetB, "LOCAL", VECTOR2I( 0, 0 ) );
90 addLocalLabel( sheetC, "LOCAL", VECTOR2I( 0, 0 ) );
91
92 m_schematic->RefreshHierarchy();
93 SCH_SHEET_LIST sheets = m_schematic->Hierarchy();
94 BOOST_REQUIRE_EQUAL( sheets.size(), 3u );
95
96 m_schematic->ConnectionGraph()->Recalculate( sheets, true );
97
98 // Walk the net map and collect the net codes of every subgraph driven by
99 // a local label whose text is "LOCAL". If the bug is present, all three
100 // share the same net code; once fixed, they must each have their own.
101 std::set<int> labelNetCodes;
102 std::set<wxString> labelNetNames;
103
104 for( const auto& [key, subgraphs] : m_schematic->ConnectionGraph()->GetNetMap() )
105 {
106 for( CONNECTION_SUBGRAPH* sg : subgraphs )
107 {
108 const SCH_ITEM* driver = sg->GetDriver();
109
110 if( !driver || driver->Type() != SCH_LABEL_T )
111 continue;
112
113 if( static_cast<const SCH_LABEL*>( driver )->GetText() == wxT( "LOCAL" ) )
114 {
115 labelNetCodes.insert( key.Netcode );
116 labelNetNames.insert( key.Name );
117 }
118 }
119 }
120
121 BOOST_TEST_MESSAGE( "Distinct LOCAL net names: " << labelNetNames.size() );
122
123 for( const wxString& n : labelNetNames )
124 BOOST_TEST_MESSAGE( " " << n );
125
126 BOOST_CHECK_MESSAGE( labelNetCodes.size() == 3u, "Local labels 'LOCAL' on three different top-level sheets should "
127 "yield three distinct net codes, got "
128 << labelNetCodes.size() );
129
130 BOOST_CHECK_MESSAGE( labelNetNames.size() == 3u, "Local labels 'LOCAL' on three different top-level sheets should "
131 "yield three distinct net names, got "
132 << labelNetNames.size() );
133}
void SetPageNumber(const wxString &aPageNumber)
Definition base_screen.h:79
A subgraph is a set of items that are electrically connected on a single sheet.
const KIID m_Uuid
Definition eda_item.h:528
KICAD_T Type() const
Returns the type of object.
Definition eda_item.h:112
Definition kiid.h:48
void SetText(const wxString &aText) override
Base class for any item which can be embedded within the SCHEMATIC container class,...
Definition sch_item.h:168
void Append(SCH_ITEM *aItem, bool aUpdateLibSymbol=true)
const KIID & GetUuid() const
Definition sch_screen.h:533
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:48
SCH_FIELD * GetField(FIELD_T aFieldType)
Return a mandatory field in this sheet.
SCH_SCREEN * GetScreen() const
Definition sch_sheet.h:143
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:168
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:687