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, 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{
39
41 std::unique_ptr<SCHEMATIC> m_schematic;
42};
43
45{
47
48 // Check for Errors when using global labels
49 std::vector<wxString> tests = {// "incremental_test",
50 // "issue10430",
51 // "issue10926_1",
52 // "issue11926",
53 // "issue12505",
54 // "issue12814",
55 // "issue13112",
56 // "issue13162",
57 // "issue13212",
58 // "issue13431",
59 // "issue13591",
60 // "issue16223",
61 // "issue6588",
62 "issue7203"};//,
63 // "issue9367"};
64
65 for( const wxString& test : tests )
66 {
67 KI_TEST::LoadSchematic( m_settingsManager, test, m_schematic );
68
69 SCH_SHEET_LIST sheets = m_schematic->BuildSheetListSortedByPageNumbers();
70
71 for( const SCH_SHEET_PATH& path : sheets )
72 {
73 for( size_t ii = 0; ii < path.size(); ++ii )
74 {
75 const SCH_SHEET* sheet = path.GetSheet( ii );
76 const SCH_SCREEN* screen = sheet->GetScreen();
77 std::vector<SCH_ITEM*> items;
78
79 for( SCH_ITEM* item : screen->Items() )
80 {
81 if( !item->IsConnectable() )
82 {
83 continue;
84 }
85
86 if( item->Type() == SCH_SYMBOL_T )
87 {
88 for( SCH_PIN* pin : static_cast<SCH_SYMBOL*>( item )->GetPins() )
89 {
90 items.push_back( pin );
91 }
92 }
93 else
94 {
95 items.push_back( item );
96 }
97 }
98
99 for( SCH_ITEM* item : items )
100 {
101 for( SCH_ITEM* check_item : items )
102 {
103 auto& conn_items = check_item->ConnectedItems( path );
104 auto conn = check_item->Connection();
105 std::string netname = conn ? conn->GetNetName().ToStdString() : "NoNet";
106 int subgraph = conn ? conn->SubgraphCode() : -1;
107 BOOST_TEST_MESSAGE( test.ToStdString() << ": Item "
108 << check_item->GetFriendlyName().ToStdString()
109 << " in net " << netname << " subgraph " << subgraph
110 << " has " << conn_items.size() << " connections" );
111 }
112 SCH_CONNECTION* connection = item->Connection();
113
114 if( !connection )
115 continue;
116
117 wxString netname = connection->GetNetName();
118
119 if( !item->IsConnectable() )
120 continue;
121
122 SCH_ITEM_VEC prev_items = item->ConnectedItems( path );
123 std::sort( prev_items.begin(), prev_items.end() );
124 alg::remove_duplicates( prev_items );
125
126
127 std::set<std::pair<SCH_SHEET_PATH, SCH_ITEM*>> all_items =
128 m_schematic->ConnectionGraph()->ExtractAffectedItems( { item } );
129 all_items.insert( { path, item } );
130 BOOST_TEST_MESSAGE( test.ToStdString() << ": Item "
131 << item->GetFriendlyName().ToStdString()
132 << " in net " << netname.ToStdString()
133 << " has " << all_items.size() << " affected items" );
134
135 CONNECTION_GRAPH new_graph( m_schematic.get() );
136
137 new_graph.SetLastCodes( m_schematic->ConnectionGraph() );
138
139 for( auto&[ path, item ] : all_items )
140 {
141 wxCHECK2( item, continue );
142 item->SetConnectivityDirty();
143 }
144
145 new_graph.Recalculate( sheets, false );
146 m_schematic->ConnectionGraph()->Merge( new_graph );
147
148 SCH_ITEM_VEC curr_items = item->ConnectedItems( path );
149 std::sort( curr_items.begin(), curr_items.end() );
150 alg::remove_duplicates( curr_items );
151
152 BOOST_CHECK_MESSAGE( prev_items == curr_items,
153 test.ToStdString() << ": Item "
154 << item->GetFriendlyName().ToStdString()
155 << " in net " << netname.ToStdString()
156 << " changed from " << prev_items.size()
157 << " to " << curr_items.size() << " Location:" << item->GetPosition().x << "," << item->GetPosition().y );
158 }
159
160 }
161 }
162 }
163}
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:41
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: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.
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:47
SCH_SCREEN * GetScreen() const
Definition sch_sheet.h:116
Schematic symbol object.
Definition sch_symbol.h:76
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:161
std::vector< SCH_ITEM * > SCH_ITEM_VEC
Definition sch_item.h:156
std::vector< FAB_LAYER_COLOR > dummy
std::unique_ptr< SCHEMATIC > m_schematic
BOOST_FIXTURE_TEST_CASE(RemoveAddItems, CONNECTIVITY_TEST_FIXTURE)
BOOST_TEST_MESSAGE("Polyline has "<< chain.PointCount()<< " points")
@ SCH_SYMBOL_T
Definition typeinfo.h:176