KiCad PCB EDA Suite
Loading...
Searching...
No Matches
test_issue23058_jumper_pin_groups.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
26
29
30#include <connection_graph.h>
31#include <schematic.h>
32#include <sch_sheet.h>
33#include <sch_screen.h>
35#include <lib_symbol.h>
36#include <sch_pin.h>
37#include <sch_symbol.h>
38#include <locale_io.h>
39
41{
43 {
44 m_settingsManager.LoadProject( "" );
45 m_schematic = std::make_unique<SCHEMATIC>( &m_settingsManager.Prj() );
46 m_schematic->Reset();
47 SCH_SHEET* defaultSheet = m_schematic->GetTopLevelSheet( 0 );
48
49 SCH_SHEET* root = new SCH_SHEET( m_schematic.get() );
50 SCH_SCREEN* screen = new SCH_SCREEN( m_schematic.get() );
51 root->SetScreen( screen );
52
53 m_schematic->AddTopLevelSheet( root );
54 m_schematic->RemoveTopLevelSheet( defaultSheet );
55 delete defaultSheet;
56 }
57
59 std::unique_ptr<SCHEMATIC> m_schematic;
60};
61
62
64{
65 SCH_SCREEN* screen = m_schematic->RootScreen();
67 path.push_back( &m_schematic->Root() );
68
69 LIB_SYMBOL* libSym = new LIB_SYMBOL( "SW_SPST", nullptr );
70
71 SCH_PIN* pin1 = new SCH_PIN( libSym );
72 pin1->SetNumber( "1" );
74 pin1->SetPosition( VECTOR2I( -508000, 0 ) );
75 libSym->AddDrawItem( pin1 );
76
77 SCH_PIN* pin2 = new SCH_PIN( libSym );
78 pin2->SetNumber( "2" );
80 pin2->SetPosition( VECTOR2I( 508000, 0 ) );
81 libSym->AddDrawItem( pin2 );
82
83 // Add a jumper pin group that references non-existent pin "3"
84 std::set<wxString> group;
85 group.insert( wxT( "1" ) );
86 group.insert( wxT( "3" ) );
87 libSym->JumperPinGroups().push_back( group );
88
89 SCH_SYMBOL* sym = new SCH_SYMBOL( *libSym, libSym->GetLibId(), &path, 0, 0,
90 VECTOR2I( 15621000, 6223000 ) );
91 sym->UpdatePins();
92 screen->Append( sym );
93
94 // This must not crash even though pin "3" doesn't exist
95 SCH_SHEET_LIST sheets = m_schematic->BuildSheetListSortedByPageNumbers();
96 BOOST_CHECK_NO_THROW( m_schematic->ConnectionGraph()->Recalculate( sheets, true ) );
97
98 delete libSym;
99}
100
101
103{
104 SCH_SCREEN* screen = m_schematic->RootScreen();
106 path.push_back( &m_schematic->Root() );
107
108 LIB_SYMBOL* libSym = new LIB_SYMBOL( "SW_SPST", nullptr );
109
110 SCH_PIN* pin1 = new SCH_PIN( libSym );
111 pin1->SetNumber( "1" );
113 pin1->SetPosition( VECTOR2I( -508000, 0 ) );
114 libSym->AddDrawItem( pin1 );
115
116 // Add a jumper pin group where ALL pin numbers are invalid
117 std::set<wxString> group;
118 group.insert( wxT( "5" ) );
119 group.insert( wxT( "6" ) );
120 libSym->JumperPinGroups().push_back( group );
121
122 SCH_SYMBOL* sym = new SCH_SYMBOL( *libSym, libSym->GetLibId(), &path, 0, 0,
123 VECTOR2I( 15621000, 6223000 ) );
124 sym->UpdatePins();
125 screen->Append( sym );
126
127 SCH_SHEET_LIST sheets = m_schematic->BuildSheetListSortedByPageNumbers();
128 BOOST_CHECK_NO_THROW( m_schematic->ConnectionGraph()->Recalculate( sheets, true ) );
129
130 delete libSym;
131}
132
133
135{
136 SCH_SCREEN* screen = m_schematic->RootScreen();
138 path.push_back( &m_schematic->Root() );
139
140 LIB_SYMBOL* libSym = new LIB_SYMBOL( "SW_SPDT", nullptr );
141
142 SCH_PIN* pin1 = new SCH_PIN( libSym );
143 pin1->SetNumber( "1" );
145 pin1->SetPosition( VECTOR2I( -508000, 0 ) );
146 libSym->AddDrawItem( pin1 );
147
148 SCH_PIN* pin2 = new SCH_PIN( libSym );
149 pin2->SetNumber( "2" );
151 pin2->SetPosition( VECTOR2I( 508000, 0 ) );
152 libSym->AddDrawItem( pin2 );
153
154 SCH_PIN* pin3 = new SCH_PIN( libSym );
155 pin3->SetNumber( "3" );
157 pin3->SetPosition( VECTOR2I( 508000, 254000 ) );
158 libSym->AddDrawItem( pin3 );
159
160 // Add a valid jumper pin group
161 std::set<wxString> group;
162 group.insert( wxT( "1" ) );
163 group.insert( wxT( "3" ) );
164 libSym->JumperPinGroups().push_back( group );
165
166 SCH_SYMBOL* sym = new SCH_SYMBOL( *libSym, libSym->GetLibId(), &path, 0, 0,
167 VECTOR2I( 15621000, 6223000 ) );
168 sym->UpdatePins();
169 screen->Append( sym );
170
171 SCH_SHEET_LIST sheets = m_schematic->BuildSheetListSortedByPageNumbers();
172 m_schematic->ConnectionGraph()->Recalculate( sheets, true );
173
174 path = sheets[0];
175
176 // Verify that pins 1 and 3 are connected via the jumper group
177 SCH_PIN* schPin1 = sym->GetPin( wxT( "1" ) );
178 SCH_PIN* schPin3 = sym->GetPin( wxT( "3" ) );
179
180 BOOST_REQUIRE( schPin1 );
181 BOOST_REQUIRE( schPin3 );
182
183 bool connected = false;
184
185 for( SCH_ITEM* item : schPin1->ConnectedItems( path ) )
186 {
187 if( item == schPin3 )
188 {
189 connected = true;
190 break;
191 }
192 }
193
194 BOOST_CHECK_MESSAGE( connected, "Pins 1 and 3 should be connected via jumper pin group" );
195
196 delete libSym;
197}
198
199
201{
203
204 KI_TEST::LoadSchematic( m_settingsManager, "issue23058/issue23058", m_schematic );
205
206 SCH_SHEET_LIST sheets = m_schematic->BuildSheetListSortedByPageNumbers();
207
208 // This must not crash. The schematic has a jumper pin group referencing
209 // pin "3" but the symbol only has pins "1" and "2".
210 BOOST_CHECK_NO_THROW( m_schematic->ConnectionGraph()->Recalculate( sheets, true ) );
211}
Define a library symbol object.
Definition lib_symbol.h:79
const LIB_ID & GetLibId() const override
Definition lib_symbol.h:148
std::vector< std::set< wxString > > & JumperPinGroups()
Each jumper pin group is a set of pin numbers that should be treated as internally connected.
Definition lib_symbol.h:757
void AddDrawItem(SCH_ITEM *aItem, bool aSort=true)
Add a new draw aItem to the draw object list and sort according to aSort.
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
const std::vector< SCH_ITEM * > & ConnectedItems(const SCH_SHEET_PATH &aPath)
Retrieve the set of items connected to this item on the given sheet.
Definition sch_item.cpp:558
void SetNumber(const wxString &aNumber)
Definition sch_pin.cpp:734
void SetPosition(const VECTOR2I &aPos) override
Definition sch_pin.h:254
void SetType(ELECTRICAL_PINTYPE aType)
Definition sch_pin.cpp:422
void Append(SCH_ITEM *aItem, bool aUpdateLibSymbol=true)
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...
Sheet symbol placed in a schematic, and is the entry point for a sub schematic.
Definition sch_sheet.h:44
void SetScreen(SCH_SCREEN *aScreen)
Set the SCH_SCREEN associated with this sheet to aScreen.
Schematic symbol object.
Definition sch_symbol.h:69
void UpdatePins()
Updates the cache of SCH_PIN objects for each pin.
SCH_PIN * GetPin(const wxString &number) const
Find a symbol pin by number.
void LoadSchematic(SETTINGS_MANAGER &aSettingsManager, const wxString &aRelPath, std::unique_ptr< SCHEMATIC > &aSchematic)
@ PT_PASSIVE
pin for passive symbols: must be connected, and can be connected to any pin.
Definition pin_type.h:39
std::vector< FAB_LAYER_COLOR > dummy
Test for issue #23058: Jumper pin groups with out-of-bounds pin numbers cause crash.
BOOST_REQUIRE(intersection.has_value()==c.ExpectedIntersection.has_value())
BOOST_FIXTURE_TEST_CASE(JumperPinGroupOutOfBounds, JUMPER_PIN_GROUP_FIXTURE)
KIBIS_PIN * pin3
std::string path
KIBIS_PIN * pin1
BOOST_CHECK_MESSAGE(totalMismatches==0, std::to_string(totalMismatches)+" board(s) with strategy disagreements")
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:683