KiCad PCB EDA Suite
Loading...
Searching...
No Matches
test_incremental_netlister.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 (C) 2024 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
24
27
28#include <connection_graph.h>
29#include <schematic.h>
30#include <sch_sheet.h>
31#include <sch_screen.h>
33#include <locale_io.h>
34
36{
38 m_settingsManager( true /* headless */ )
39 { }
40
42 std::unique_ptr<SCHEMATIC> m_schematic;
43};
44
46{
48
49 // Check for Errors when using global labels
50 std::vector<wxString> tests = {// "incremental_test",
51 // "issue10430",
52 // "issue10926_1",
53 // "issue11926",
54 // "issue12505",
55 // "issue12814",
56 // "issue13112",
57 // "issue13162",
58 // "issue13212",
59 // "issue13431",
60 // "issue13591",
61 // "issue16223",
62 // "issue6588",
63 "issue7203"};//,
64 // "issue9367"};
65
66 for( const wxString& test : tests )
67 {
68 KI_TEST::LoadSchematic( m_settingsManager, test, m_schematic );
69
70 SCH_SHEET_LIST sheets = m_schematic->GetSheets();
71
72 for( const SCH_SHEET_PATH& path : sheets )
73 {
74 for( size_t ii = 0; ii < path.size(); ++ii )
75 {
76 const SCH_SHEET* sheet = path.GetSheet( ii );
77 const SCH_SCREEN* screen = sheet->GetScreen();
78 std::vector<SCH_ITEM*> items;
79
80 for( SCH_ITEM* item : screen->Items() )
81 {
82 if( !item->IsConnectable() )
83 {
84 continue;
85 }
86
87 if( item->Type() == SCH_SYMBOL_T )
88 {
89 for( SCH_PIN* pin : static_cast<SCH_SYMBOL*>( item )->GetPins() )
90 {
91 items.push_back( pin );
92 }
93 }
94 else
95 {
96 items.push_back( item );
97 }
98 }
99
100 for( SCH_ITEM* item : items )
101 {
102 for( SCH_ITEM* check_item : items )
103 {
104 auto& conn_items = check_item->ConnectedItems( path );
105 auto conn = check_item->Connection();
106 std::string netname = conn ? conn->GetNetName().ToStdString() : "NoNet";
107 int subgraph = conn ? conn->SubgraphCode() : -1;
108 BOOST_TEST_MESSAGE( test.ToStdString() << ": Item "
109 << check_item->GetFriendlyName().ToStdString()
110 << " in net " << netname << " subgraph " << subgraph
111 << " has " << conn_items.size() << " connections" );
112 }
113 SCH_CONNECTION* connection = item->Connection();
114
115 if( !connection )
116 continue;
117
118 wxString netname = connection->GetNetName();
119
120 if( !item->IsConnectable() )
121 continue;
122
123 SCH_ITEM_VEC prev_items = item->ConnectedItems( path );
124 std::sort( prev_items.begin(), prev_items.end() );
125 alg::remove_duplicates( prev_items );
126
127
128 std::set<std::pair<SCH_SHEET_PATH, SCH_ITEM*>> all_items =
129 m_schematic->ConnectionGraph()->ExtractAffectedItems( { item } );
130 all_items.insert( { path, item } );
131 BOOST_TEST_MESSAGE( test.ToStdString() << ": Item "
132 << item->GetFriendlyName().ToStdString()
133 << " in net " << netname.ToStdString()
134 << " has " << all_items.size() << " affected items" );
135
136 CONNECTION_GRAPH new_graph( m_schematic.get() );
137
138 new_graph.SetLastCodes( m_schematic->ConnectionGraph() );
139
140 for( auto&[ path, item ] : all_items )
141 {
142 wxCHECK2( item, continue );
143 item->SetConnectivityDirty();
144 }
145
146 new_graph.Recalculate( sheets, false );
147 m_schematic->ConnectionGraph()->Merge( new_graph );
148
149 SCH_ITEM_VEC curr_items = item->ConnectedItems( path );
150 std::sort( curr_items.begin(), curr_items.end() );
151 alg::remove_duplicates( curr_items );
152
153 BOOST_CHECK_MESSAGE( prev_items == curr_items,
154 test.ToStdString() << ": Item "
155 << item->GetFriendlyName().ToStdString()
156 << " in net " << netname.ToStdString()
157 << " changed from " << prev_items.size()
158 << " to " << curr_items.size() << " Location:" << item->GetPosition().x << "," << item->GetPosition().y );
159 }
160
161 }
162 }
163 }
164}
Calculate the connectivity of a schematic and generates netlists.
void SetLastCodes(const CONNECTION_GRAPH *aOther)
void Recalculate(const SCH_SHEET_LIST &aSheetList, bool aUnconditional=false, std::function< void(SCH_ITEM *)> *aChangedItemHandler=nullptr)
Update the connection graph for the given list of sheets.
Instantiate the current locale within a scope in which you are expecting exceptions to be thrown.
Definition: locale_io.h:49
Each graphical item can have a SCH_CONNECTION describing its logical connection (to a bus or net).
wxString GetNetName() const
Base class for any item which can be embedded within the SCHEMATIC container class,...
Definition: sch_item.h:174
EE_RTREE & Items()
Gets the full RTree, usually for iterating.
Definition: sch_screen.h:109
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:57
SCH_SCREEN * GetScreen() const
Definition: sch_sheet.h:110
Schematic symbol object.
Definition: sch_symbol.h:105
void LoadSchematic(SETTINGS_MANAGER &aSettingsManager, const wxString &aRelPath, std::unique_ptr< SCHEMATIC > &aSchematic)
void remove_duplicates(_Container &__c)
Deletes all duplicate values from __c.
Definition: kicad_algo.h:183
std::vector< SCH_ITEM * > SCH_ITEM_VEC
Definition: sch_item.h:163
std::vector< FAB_LAYER_COLOR > dummy
std::unique_ptr< SCHEMATIC > m_schematic
BOOST_FIXTURE_TEST_CASE(RemoveAddItems, INCREMENTAL_NETLIST_TEST_FIXTURE)
@ SCH_SYMBOL_T
Definition: typeinfo.h:172