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 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
20
23
24#include <connection_graph.h>
25#include <schematic.h>
26#include <sch_sheet.h>
27#include <sch_screen.h>
29#include <locale_io.h>
30
32{
35
37 std::unique_ptr<SCHEMATIC> m_schematic;
38};
39
41{
43
44 // Check for Errors when using global labels
45 std::vector<wxString> tests = {// "incremental_test",
46 // "issue10430",
47 // "issue10926_1",
48 // "issue11926",
49 // "issue12505",
50 // "issue12814",
51 // "issue13112",
52 // "issue13162",
53 // "issue13212",
54 // "issue13431",
55 // "issue13591",
56 // "issue16223",
57 // "issue6588",
58 "issue7203"};//,
59 // "issue9367"};
60
61 for( const wxString& test : tests )
62 {
63 KI_TEST::LoadSchematic( m_settingsManager, test, m_schematic );
64
65 SCH_SHEET_LIST sheets = m_schematic->BuildSheetListSortedByPageNumbers();
66
67 for( const SCH_SHEET_PATH& path : sheets )
68 {
69 for( size_t ii = 0; ii < path.size(); ++ii )
70 {
71 const SCH_SHEET* sheet = path.GetSheet( ii );
72 const SCH_SCREEN* screen = sheet->GetScreen();
73 std::vector<SCH_ITEM*> items;
74
75 for( SCH_ITEM* item : screen->Items() )
76 {
77 if( !item->IsConnectable() )
78 {
79 continue;
80 }
81
82 if( item->Type() == SCH_SYMBOL_T )
83 {
84 for( SCH_PIN* pin : static_cast<SCH_SYMBOL*>( item )->GetPins() )
85 {
86 items.push_back( pin );
87 }
88 }
89 else
90 {
91 items.push_back( item );
92 }
93 }
94
95 for( SCH_ITEM* item : items )
96 {
97 const std::vector<SCH_ITEM*>& conn_items = item->ConnectedItems( path );
98 SCH_CONNECTION* conn = item->Connection();
99 wxString netname = conn ? conn->GetNetName().ToStdString() : wxString( "NoNet" );
100 int subgraph = conn ? conn->SubgraphCode() : -1;
101
102 BOOST_TEST_MESSAGE( test.ToStdString()
103 << ": Item " << item->GetFriendlyName().ToStdString()
104 << " in net " << netname.ToStdString() << " subgraph " << subgraph
105 << " has " << conn_items.size() << " connections" );
106
107 if( !conn )
108 continue;
109
110 if( !item->IsConnectable() )
111 continue;
112
113 std::vector<SCH_ITEM*> prev_items = item->ConnectedItems( path );
114 std::sort( prev_items.begin(), prev_items.end() );
115 alg::remove_duplicates( prev_items );
116
117 std::set<std::pair<SCH_SHEET_PATH, SCH_ITEM*>> all_items =
118 m_schematic->ConnectionGraph()->ExtractAffectedItems( { item } );
119 all_items.insert( { path, item } );
120 BOOST_TEST_MESSAGE( test.ToStdString()
121 << ": Item " << item->GetFriendlyName().ToStdString()
122 << " in net " << netname.ToStdString()
123 << " has " << all_items.size() << " affected items" );
124
125 CONNECTION_GRAPH new_graph( m_schematic.get() );
126
127 new_graph.SetLastCodes( m_schematic->ConnectionGraph() );
128
129 for( auto&[ apath, aitem ] : all_items )
130 {
131 wxCHECK2( aitem, continue );
132 aitem->SetConnectivityDirty();
133 }
134
135 new_graph.Recalculate( sheets, false );
136 m_schematic->ConnectionGraph()->Merge( new_graph );
137
138 std::vector<SCH_ITEM*> curr_items = item->ConnectedItems( path );
139 std::sort( curr_items.begin(), curr_items.end() );
140 alg::remove_duplicates( curr_items );
141
142 BOOST_CHECK_MESSAGE( prev_items == curr_items,
143 test.ToStdString()
144 << ": Item " << item->GetFriendlyName().ToStdString()
145 << " in net " << netname.ToStdString()
146 << " changed from " << prev_items.size() << " to " << curr_items.size()
147 << " Location:" << item->GetPosition().x << "," << item->GetPosition().y );
148 }
149
150 }
151 }
152 }
153}
Calculate the connectivity of a schematic and generates netlists.
void Recalculate(const SCH_SHEET_LIST &aSheetList, bool aUnconditional=false, std::function< void(SCH_ITEM *)> *aChangedItemHandler=nullptr, PROGRESS_REPORTER *aProgressReporter=nullptr)
Update the connection graph for the given list of sheets.
void SetLastCodes(const CONNECTION_GRAPH *aOther)
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 GetNetName() const
int SubgraphCode() const
Base class for any item which can be embedded within the SCHEMATIC container class,...
Definition sch_item.h:162
EE_RTREE & Items()
Get the full RTree, usually for iterating.
Definition sch_screen.h:115
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
SCH_SCREEN * GetScreen() const
Definition sch_sheet.h:139
Schematic symbol object.
Definition sch_symbol.h:69
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:157
std::vector< FAB_LAYER_COLOR > dummy
std::unique_ptr< SCHEMATIC > m_schematic
BOOST_FIXTURE_TEST_CASE(RemoveAddItems, CONNECTIVITY_TEST_FIXTURE)
std::string path
KIBIS_PIN * pin
BOOST_CHECK_MESSAGE(totalMismatches==0, std::to_string(totalMismatches)+" board(s) with strategy disagreements")
BOOST_TEST_MESSAGE("\n=== Real-World Polygon PIP Benchmark ===\n"<< formatTable(table))
@ SCH_SYMBOL_T
Definition typeinfo.h:169