KiCad PCB EDA Suite
Loading...
Searching...
No Matches
test_issue18299_bus_member_rename.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 32 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
42
45
46#include <connection_graph.h>
47#include <schematic.h>
48#include <sch_sheet.h>
49#include <sch_screen.h>
50#include <sch_label.h>
52#include <locale_io.h>
53
55{
58
60 std::unique_ptr<SCHEMATIC> m_schematic;
61};
62
63
72BOOST_FIXTURE_TEST_CASE( Issue18299BusMemberRename, ISSUE18299_FIXTURE )
73{
75
76 KI_TEST::LoadSchematic( m_settingsManager, "issue18299/issue18299", m_schematic );
77
78 SCH_SHEET_LIST sheets = m_schematic->BuildSheetListSortedByPageNumbers();
79 CONNECTION_GRAPH* graph = m_schematic->ConnectionGraph();
80
81 // Find the "b" label net codes in each sub-sheet instance
82 // We're looking for local labels named "b" in the sub-sheets
83 std::map<wxString, int> labelNetCodes; // "sheetname:labelname" -> net code
84
85 for( const auto& [key, subgraphs] : graph->GetNetMap() )
86 {
87 for( CONNECTION_SUBGRAPH* subgraph : subgraphs )
88 {
89 const SCH_SHEET_PATH& sheetPath = subgraph->GetSheet();
90
91 for( SCH_ITEM* item : subgraph->GetItems() )
92 {
93 if( item->Type() == SCH_LABEL_T )
94 {
95 SCH_LABEL* label = static_cast<SCH_LABEL*>( item );
96 wxString labelText = label->GetText();
97
98 // Get the sheet instance name from the path
99 wxString sheetName;
100
101 if( sheetPath.size() > 1 )
102 {
103 // Get the last sheet in the path (the containing sheet)
104 const SCH_SHEET* lastSheet = sheetPath.Last();
105
106 if( lastSheet )
107 sheetName = lastSheet->GetName();
108 }
109
110 if( !sheetName.IsEmpty() && labelText == "b" )
111 {
112 wxString mapKey = sheetName + ":" + labelText;
113 labelNetCodes[mapKey] = key.Netcode;
114 }
115 }
116 }
117 }
118 }
119
120 // Verify we found "b" labels in both sub-sheet instances
121 BOOST_REQUIRE_MESSAGE( labelNetCodes.count( "test1:b" ),
122 "Label 'b' should be found in test1 sub-sheet" );
123 BOOST_REQUIRE_MESSAGE( labelNetCodes.count( "test2:b" ),
124 "Label 'b' should be found in test2 sub-sheet" );
125
126 // The main test: "b" in test1 and "b" in test2 should be on the same net
127 // because they are both members of bus {a} which connects the two sheets.
128 // This tests that the individual sheet pin rename ("b" -> "bbb") does not
129 // break the bus member connection through the bus.
130 BOOST_CHECK_MESSAGE( labelNetCodes["test1:b"] == labelNetCodes["test2:b"],
131 "Label 'b' in test1 should be on the same net as label 'b' in test2 "
132 "(connected through bus {a})" );
133}
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:98
Instantiate the current locale within a scope in which you are expecting exceptions to be thrown.
Definition locale_io.h:41
Base class for any item which can be embedded within the SCHEMATIC container class,...
Definition sch_item.h:167
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...
const SCH_SHEET * GetSheet(unsigned aIndex) const
SCH_SHEET * Last() const
Return a pointer to the last SCH_SHEET of the list.
size_t size() const
Forwarded method from std::vector.
Sheet symbol placed in a schematic, and is the entry point for a sub schematic.
Definition sch_sheet.h:48
wxString GetName() const
Definition sch_sheet.h:142
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_FIXTURE_TEST_CASE(Issue18299BusMemberRename, ISSUE18299_FIXTURE)
Test that bus member connections are maintained through hierarchy even when the member is also indivi...
@ SCH_LABEL_T
Definition typeinfo.h:171