KiCad PCB EDA Suite
Loading...
Searching...
No Matches
test_stacked_pin_nomenclature.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
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 at
18 * http://www.gnu.org/licenses/
19 */
20
23
24#include <algorithm>
25#include <vector>
26
27#include <schematic.h>
28#include <sch_screen.h>
29#include <sch_symbol.h>
30#include <sch_pin.h>
32#include <locale_io.h>
33
35{
36 STACKED_PIN_FIXTURE() : m_settingsManager( true /* headless */ ) {}
37
39 std::unique_ptr<SCHEMATIC> m_schematic;
40};
41
42static std::vector<wxString> ToVector( const std::initializer_list<const char*>& init )
43{
44 std::vector<wxString> out;
45 for( const char* s : init )
46 out.emplace_back( wxString::FromUTF8( s ) );
47 return out;
48}
49
50BOOST_FIXTURE_TEST_CASE( StackedPinNomenclature_ExpandsCorrectly, STACKED_PIN_FIXTURE )
51{
53
54 // Load the custom schematic with bracketed pin numbers
55 KI_TEST::LoadSchematic( m_settingsManager, "stacked_pin_nomenclature", m_schematic );
56
57 SCH_SHEET_LIST sheets = m_schematic->BuildSheetListSortedByPageNumbers();
58 BOOST_REQUIRE( sheets.size() >= 1 );
59 SCH_SCREEN* screen = sheets.at( 0 ).LastScreen();
60
61 // Find the Device:R symbol on the sheet
62 SCH_SYMBOL* resistor = nullptr;
63 for( SCH_ITEM* item : screen->Items().OfType( SCH_SYMBOL_T ) )
64 {
65 SCH_SYMBOL* sym = static_cast<SCH_SYMBOL*>( item );
66 if( sym->GetSchSymbolLibraryName() == wxT( "Device:R" ) )
67 {
68 resistor = sym;
69 break;
70 }
71 }
72
73 BOOST_REQUIRE_MESSAGE( resistor, "Resistor symbol not found in test schematic" );
74
75 // Collect both pins (each with bracketed numbers)
76 std::vector<SCH_PIN*> rpins = resistor->GetPins( &sheets.at( 0 ) );
77 BOOST_REQUIRE_EQUAL( rpins.size(), 2 );
78
79 // For determinism, sort by local Y position
80 std::sort( rpins.begin(), rpins.end(), []( SCH_PIN* a, SCH_PIN* b ) {
81 return a->GetLocalPosition().y < b->GetLocalPosition().y;
82 } );
83
84 // Top pin is [1-5]
85 bool validTop = false;
86 std::vector<wxString> top = rpins[0]->GetStackedPinNumbers( &validTop );
87 BOOST_CHECK( validTop );
88 std::vector<wxString> expectedTop = ToVector( { "1", "2", "3", "4", "5" } );
89 BOOST_CHECK_EQUAL_COLLECTIONS( top.begin(), top.end(), expectedTop.begin(), expectedTop.end() );
90
91 // Bottom pin is [6,7,9-11]
92 bool validBot = false;
93 std::vector<wxString> bot = rpins[1]->GetStackedPinNumbers( &validBot );
94 BOOST_CHECK( validBot );
95 std::vector<wxString> expectedBot = ToVector( { "6", "7", "9", "10", "11" } );
96 BOOST_CHECK_EQUAL_COLLECTIONS( bot.begin(), bot.end(), expectedBot.begin(), expectedBot.end() );
97
98 // Total expanded count across both pins should be 10
99 size_t total = top.size() + bot.size();
100 BOOST_CHECK_EQUAL( total, 10 );
101}
EE_TYPE OfType(KICAD_T aType) const
Definition sch_rtree.h:241
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
EE_RTREE & Items()
Get the full RTree, usually for iterating.
Definition sch_screen.h:117
A container for handling SCH_SHEET_PATH objects in a flattened hierarchy.
Schematic symbol object.
Definition sch_symbol.h:75
wxString GetSchSymbolLibraryName() const
std::vector< SCH_PIN * > GetPins(const SCH_SHEET_PATH *aSheet) const
Retrieve a list of the SCH_PINs for the given sheet path.
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(StackedPinNomenclature_ExpandsCorrectly, STACKED_PIN_FIXTURE)
static std::vector< wxString > ToVector(const std::initializer_list< const char * > &init)
BOOST_CHECK_EQUAL(result, "25.4")
@ SCH_SYMBOL_T
Definition typeinfo.h:174