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, 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
44
47
48#include <connection_graph.h>
49#include <schematic.h>
50#include <sch_sheet.h>
51#include <sch_screen.h>
52#include <sch_symbol.h>
53#include <sch_pin.h>
55#include <locale_io.h>
56
57
65
66
67BOOST_FIXTURE_TEST_CASE( Issue23840BusGroupToVector, ISSUE23840_FIXTURE )
68{
70
71 KI_TEST::LoadSchematic( m_settingsManager, "issue23840/BusAndVectors", m_schematic );
72
73 SCH_SHEET_LIST sheets = m_schematic->BuildSheetListSortedByPageNumbers();
74 CONNECTION_GRAPH* graph = m_schematic->ConnectionGraph();
75
76 // Collect net names keyed by "ref.pin" across all sheet instances.
77 std::map<wxString, wxString> pinNetNames;
78
79 for( const SCH_SHEET_PATH& path : sheets )
80 {
81 for( SCH_ITEM* item : path.LastScreen()->Items().OfType( SCH_SYMBOL_T ) )
82 {
83 SCH_SYMBOL* symbol = static_cast<SCH_SYMBOL*>( item );
84 wxString ref = symbol->GetRef( &path );
85
86 for( SCH_PIN* pin : symbol->GetPins( &path ) )
87 {
88 SCH_CONNECTION* conn = pin->Connection( &path );
89
90 if( conn )
91 {
92 wxString pinKey = ref + "." + pin->GetNumber();
93 pinNetNames[pinKey] = conn->Name();
94 }
95 }
96 }
97 }
98
99 // Instance 2 (LED_B): bus group {CON_B_7 CON_B_8 CON_B_[1..3] CON_B_[4..6]} -> LEDs[0..7]
100 // Positional mapping: R9.1=CON_B_7, R10.1=CON_B_8, R11.1=CON_B_1, R12.1=CON_B_2,
101 // R13.1=CON_B_3, R14.1=CON_B_4, R15.1=CON_B_5, R16.1=CON_B_6
102 const std::vector<wxString> expectedNets = { "CON_B_7", "CON_B_8", "CON_B_1", "CON_B_2",
103 "CON_B_3", "CON_B_4", "CON_B_5", "CON_B_6" };
104
105 for( int i = 0; i < 8; i++ )
106 {
107 wxString ref = wxString::Format( "R%d.1", i + 9 );
108 BOOST_REQUIRE_MESSAGE( pinNetNames.count( ref ), wxString::Format( "%s should have a net assigned", ref ) );
109
110 wxString netName = pinNetNames[ref];
111 BOOST_CHECK_MESSAGE( netName == expectedNets[i],
112 wxString::Format( "%s expected %s, got %s", ref, expectedNets[i], netName ) );
113 }
114}
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:41
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:168
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:76
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:173