KiCad PCB EDA Suite
Loading...
Searching...
No Matches
test_issue21798_bus_sheet_copy.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 * 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
33
36
37#include <connection_graph.h>
38#include <schematic.h>
39#include <sch_sheet.h>
40#include <sch_sheet_pin.h>
41#include <sch_screen.h>
42#include <sch_label.h>
43#include <sch_bus_entry.h>
44#include <sch_line.h>
45#include <sch_symbol.h>
46#include <sch_pin.h>
48#include <locale_io.h>
49
50
58
59
71BOOST_FIXTURE_TEST_CASE( Issue21798DuplicatedSheetBusConnectivity, ISSUE21798_FIXTURE )
72{
74
75 KI_TEST::LoadSchematic( m_settingsManager, "issue21798/issue21798", m_schematic );
76
77 SCH_SHEET_LIST sheets = m_schematic->BuildSheetListSortedByPageNumbers();
78 CONNECTION_GRAPH* graph = m_schematic->ConnectionGraph();
79
80 BOOST_REQUIRE( graph != nullptr );
81 BOOST_REQUIRE( sheets.size() >= 1 );
82
83 SCH_SHEET_PATH rootPath = sheets[0];
84
85 // Count label subgraphs on the root sheet that have bus parents.
86 // Each label (D0/D1) should be in a subgraph with at least one bus parent,
87 // indicating successful bus member matching.
88 int labelSubgraphsWithBusParents = 0;
89 int labelSubgraphsTotal = 0;
90
91 // Count distinct bus parent subgraphs. With two sheets, both bus subgraphs
92 // should be parents of the label subgraphs.
93 std::set<const CONNECTION_SUBGRAPH*> allBusParents;
94
95 for( const auto& [key, subgraphs] : graph->GetNetMap() )
96 {
97 for( CONNECTION_SUBGRAPH* subgraph : subgraphs )
98 {
99 if( subgraph->GetSheet() != rootPath )
100 continue;
101
102 const SCH_CONNECTION* conn = subgraph->GetDriverConnection();
103
104 if( !conn || conn->IsBus() )
105 continue;
106
107 bool hasLabel = false;
108 wxString labelText;
109
110 for( SCH_ITEM* item : subgraph->GetItems() )
111 {
112 if( item->Type() == SCH_LABEL_T )
113 {
114 SCH_LABEL* label = static_cast<SCH_LABEL*>( item );
115
116 if( label->GetText() == wxT( "D0" ) || label->GetText() == wxT( "D1" ) )
117 {
118 hasLabel = true;
119 labelText = label->GetText();
120 }
121 }
122 }
123
124 if( !hasLabel )
125 continue;
126
127 labelSubgraphsTotal++;
128
129 const auto& busParents = subgraph->GetBusParents();
130
131 if( !busParents.empty() )
132 {
133 labelSubgraphsWithBusParents++;
134
135 for( const auto& [busConn, parentSet] : busParents )
136 {
137 for( const CONNECTION_SUBGRAPH* parent : parentSet )
138 allBusParents.insert( parent );
139 }
140
141 BOOST_TEST_MESSAGE( "Label subgraph '" << labelText
142 << "' net='" << conn->Name()
143 << "' has " << busParents.size()
144 << " bus parent entries" );
145 }
146 else
147 {
148 BOOST_TEST_MESSAGE( "Label subgraph '" << labelText
149 << "' net='" << conn->Name()
150 << "' has NO bus parents (BUG)" );
151 }
152 }
153 }
154
155 BOOST_CHECK_MESSAGE( labelSubgraphsTotal > 0,
156 "Should find at least one label subgraph for D0/D1" );
157
158 BOOST_CHECK_MESSAGE( labelSubgraphsWithBusParents == labelSubgraphsTotal,
159 "All " << labelSubgraphsTotal
160 << " label subgraphs should have bus parents, but only "
161 << labelSubgraphsWithBusParents << " do" );
162
163 // With the fix, labels should be linked to BOTH bus subgraphs (Sheet1 and Sheet2).
164 // Without the fix, labels only link to the unrenamed bus (1 parent instead of 2).
165 BOOST_CHECK_MESSAGE( allBusParents.size() == 2,
166 "Labels should have bus parents from both sheets (2), found "
167 << allBusParents.size() );
168}
Calculate the connectivity of a schematic and generates netlists.
const NET_MAP & GetNetMap() const
A subgraph is a set of items that are electrically connected on a single sheet.
virtual const wxString & GetText() const
Return the string associated with the text object.
Definition eda_text.h:110
Instantiate the current locale within a scope in which you are expecting exceptions to be thrown.
Definition locale_io.h:37
Each graphical item can have a SCH_CONNECTION describing its logical connection (to a bus or net).
wxString Name(bool aIgnoreSheet=false) const
bool IsBus() const
Base class for any item which can be embedded within the SCHEMATIC container class,...
Definition sch_item.h:162
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...
void LoadSchematic(SETTINGS_MANAGER &aSettingsManager, const wxString &aRelPath, std::unique_ptr< SCHEMATIC > &aSchematic)
std::vector< FAB_LAYER_COLOR > dummy
std::unique_ptr< SCHEMATIC > m_schematic
BOOST_REQUIRE(intersection.has_value()==c.ExpectedIntersection.has_value())
BOOST_FIXTURE_TEST_CASE(Issue21798DuplicatedSheetBusConnectivity, ISSUE21798_FIXTURE)
Test that two sheets with the same bus pin name both have working bus connectivity.
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