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, see <https://www.gnu.org/licenses/>.
18 */
19
38
41
42#include <connection_graph.h>
43#include <schematic.h>
44#include <sch_sheet.h>
45#include <sch_screen.h>
46#include <sch_label.h>
48#include <locale_io.h>
49
51{
54
56 std::unique_ptr<SCHEMATIC> m_schematic;
57};
58
59
68BOOST_FIXTURE_TEST_CASE( Issue18299BusMemberRename, ISSUE18299_FIXTURE )
69{
71
72 KI_TEST::LoadSchematic( m_settingsManager, "issue18299/issue18299", m_schematic );
73
74 SCH_SHEET_LIST sheets = m_schematic->BuildSheetListSortedByPageNumbers();
75 CONNECTION_GRAPH* graph = m_schematic->ConnectionGraph();
76
77 // Find the "b" label net codes in each sub-sheet instance
78 // We're looking for local labels named "b" in the sub-sheets
79 std::map<wxString, int> labelNetCodes; // "sheetname:labelname" -> net code
80
81 for( const auto& [key, subgraphs] : graph->GetNetMap() )
82 {
83 for( CONNECTION_SUBGRAPH* subgraph : subgraphs )
84 {
85 const SCH_SHEET_PATH& sheetPath = subgraph->GetSheet();
86
87 for( SCH_ITEM* item : subgraph->GetItems() )
88 {
89 if( item->Type() == SCH_LABEL_T )
90 {
91 SCH_LABEL* label = static_cast<SCH_LABEL*>( item );
92 wxString labelText = label->GetText();
93
94 // Get the sheet instance name from the path
95 wxString sheetName;
96
97 if( sheetPath.size() > 1 )
98 {
99 // Get the last sheet in the path (the containing sheet)
100 const SCH_SHEET* lastSheet = sheetPath.Last();
101
102 if( lastSheet )
103 sheetName = lastSheet->GetName();
104 }
105
106 if( !sheetName.IsEmpty() && labelText == "b" )
107 {
108 wxString mapKey = sheetName + ":" + labelText;
109 labelNetCodes[mapKey] = key.Netcode;
110 }
111 }
112 }
113 }
114 }
115
116 // Verify we found "b" labels in both sub-sheet instances
117 BOOST_REQUIRE_MESSAGE( labelNetCodes.count( "test1:b" ),
118 "Label 'b' should be found in test1 sub-sheet" );
119 BOOST_REQUIRE_MESSAGE( labelNetCodes.count( "test2:b" ),
120 "Label 'b' should be found in test2 sub-sheet" );
121
122 // The main test: "b" in test1 and "b" in test2 should be on the same net
123 // because they are both members of bus {a} which connects the two sheets.
124 // This tests that the individual sheet pin rename ("b" -> "bbb") does not
125 // break the bus member connection through the bus.
126 BOOST_CHECK_MESSAGE( labelNetCodes["test1:b"] == labelNetCodes["test2:b"],
127 "Label 'b' in test1 should be on the same net as label 'b' in test2 "
128 "(connected through bus {a})" );
129}
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
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...
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:44
wxString GetName() const
Definition sch_sheet.h:136
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...
BOOST_CHECK_MESSAGE(totalMismatches==0, std::to_string(totalMismatches)+" board(s) with strategy disagreements")
@ SCH_LABEL_T
Definition typeinfo.h:164