KiCad PCB EDA Suite
Loading...
Searching...
No Matches
test_issue23840_bus_group_to_vector.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
40
43
44#include <connection_graph.h>
45#include <schematic.h>
46#include <sch_sheet.h>
47#include <sch_screen.h>
48#include <sch_symbol.h>
49#include <sch_pin.h>
51#include <locale_io.h>
52
53
61
62
63BOOST_FIXTURE_TEST_CASE( Issue23840BusGroupToVector, ISSUE23840_FIXTURE )
64{
66
67 KI_TEST::LoadSchematic( m_settingsManager, "issue23840/BusAndVectors", m_schematic );
68
69 SCH_SHEET_LIST sheets = m_schematic->BuildSheetListSortedByPageNumbers();
70 CONNECTION_GRAPH* graph = m_schematic->ConnectionGraph();
71
72 // Collect net names keyed by "ref.pin" across all sheet instances.
73 std::map<wxString, wxString> pinNetNames;
74
75 for( const SCH_SHEET_PATH& path : sheets )
76 {
77 for( SCH_ITEM* item : path.LastScreen()->Items().OfType( SCH_SYMBOL_T ) )
78 {
79 SCH_SYMBOL* symbol = static_cast<SCH_SYMBOL*>( item );
80 wxString ref = symbol->GetRef( &path );
81
82 for( SCH_PIN* pin : symbol->GetPins( &path ) )
83 {
84 SCH_CONNECTION* conn = pin->Connection( &path );
85
86 if( conn )
87 {
88 wxString pinKey = ref + "." + pin->GetNumber();
89 pinNetNames[pinKey] = conn->Name();
90 }
91 }
92 }
93 }
94
95 // Instance 2 (LED_B): bus group {CON_B_7 CON_B_8 CON_B_[1..3] CON_B_[4..6]} -> LEDs[0..7]
96 // Positional mapping: R9.1=CON_B_7, R10.1=CON_B_8, R11.1=CON_B_1, R12.1=CON_B_2,
97 // R13.1=CON_B_3, R14.1=CON_B_4, R15.1=CON_B_5, R16.1=CON_B_6
98 const std::vector<wxString> expectedNets = { "CON_B_7", "CON_B_8", "CON_B_1", "CON_B_2",
99 "CON_B_3", "CON_B_4", "CON_B_5", "CON_B_6" };
100
101 for( int i = 0; i < 8; i++ )
102 {
103 wxString ref = wxString::Format( "R%d.1", i + 9 );
104 BOOST_REQUIRE_MESSAGE( pinNetNames.count( ref ), wxString::Format( "%s should have a net assigned", ref ) );
105
106 wxString netName = pinNetNames[ref];
107 BOOST_CHECK_MESSAGE( netName == expectedNets[i],
108 wxString::Format( "%s expected %s, got %s", ref, expectedNets[i], netName ) );
109 }
110}
Calculate the connectivity of a schematic and generates netlists.
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
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...
Schematic symbol object.
Definition sch_symbol.h:69
std::vector< const SCH_PIN * > GetPins(const SCH_SHEET_PATH *aSheet) const
Retrieve a list of the SCH_PINs for the given sheet path.
const wxString GetRef(const SCH_SHEET_PATH *aSheet, bool aIncludeUnit=false) const override
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(Issue23840BusGroupToVector, ISSUE23840_FIXTURE)
std::string path
KIBIS_PIN * pin
BOOST_CHECK_MESSAGE(totalMismatches==0, std::to_string(totalMismatches)+" board(s) with strategy disagreements")
@ SCH_SYMBOL_T
Definition typeinfo.h:169