36struct CONNECTIVITY_TEST_FIXTURE
38 CONNECTIVITY_TEST_FIXTURE()
41 SETTINGS_MANAGER m_settingsManager;
42 std::unique_ptr<SCHEMATIC> m_schematic;
49 auto* graph = m_schematic->ConnectionGraph();
50 graph->Recalculate( m_schematic->Hierarchy(),
true );
51 SCH_SCREEN* screen = m_schematic->Hierarchy().front().LastScreen();
54 auto* symbol =
static_cast<SCH_SYMBOL*
>( *symbols.begin() );
67 BOOST_CHECK( !graph->GetSubgraphForItem(
pin ) );
78 auto expired = std::make_unique<CONNECTION_GRAPH>( m_schematic.get() );
79 expired->Recalculate( paths,
true );
82 SCH_SCREEN* screen = paths.front().LastScreen();
114 std::vector<wxString> tests = {
130 for(
const wxString&
test : tests )
134 SCH_SHEET_LIST sheets = m_schematic->BuildSheetListSortedByPageNumbers();
138 for(
size_t ii = 0; ii <
path.size(); ++ii )
142 std::vector<SCH_ITEM*> items;
146 if( !item->IsConnectable() )
155 items.push_back(
pin );
160 items.push_back( item );
166 const std::vector<SCH_ITEM*>& conn_items = item->ConnectedItems(
path );
168 wxString netname = conn ? conn->
GetNetName() : wxString(
"NoNet" );
172 <<
": Item " << item->GetFriendlyName().ToStdString()
173 <<
" in net " << netname.ToStdString() <<
" subgraph " << subgraph
174 <<
" has " << conn_items.size() <<
" connections" );
179 if( !item->IsConnectable() )
182 std::vector<SCH_ITEM*> prev_items = item->ConnectedItems(
path );
183 std::sort( prev_items.begin(), prev_items.end() );
186 std::set<std::pair<SCH_SHEET_PATH, SCH_ITEM*>> all_items =
187 m_schematic->ConnectionGraph()->ExtractAffectedItems( { item } );
188 all_items.insert( {
path, item } );
190 <<
": Item " << item->GetFriendlyName().ToStdString()
191 <<
" in net " << netname.ToStdString()
192 <<
" has " << all_items.size() <<
" affected items" );
196 new_graph.
SetLastCodes( m_schematic->ConnectionGraph() );
198 for(
auto&[ apath, aitem ] : all_items )
200 wxCHECK2( aitem,
continue );
201 aitem->SetConnectivityDirty();
205 m_schematic->ConnectionGraph()->Merge( new_graph );
207 std::vector<SCH_ITEM*> curr_items = item->ConnectedItems(
path );
208 std::sort( curr_items.begin(), curr_items.end() );
211 BOOST_CHECK_MESSAGE( prev_items == curr_items,
213 <<
": Item " << item->GetFriendlyName().ToStdString()
214 <<
" in net " << netname.ToStdString()
215 <<
" changed from " << prev_items.size() <<
" to " << curr_items.size()
216 <<
" Location:" << item->GetPosition().x <<
"," << item->GetPosition().y );
238 SCH_SHEET_LIST sheets = m_schematic->BuildSheetListSortedByPageNumbers();
240 std::map<SCH_SCREEN*, int> instanceCount;
243 instanceCount[
path.LastScreen()]++;
252 for(
const auto& [key, subgraphs] : graph->
GetNetMap() )
256 if( sg->GetItems().count( aItem ) )
268 for(
auto& [screen, count] : instanceCount )
282 if( countRefs(
pin ) >= 2 )
298 BOOST_REQUIRE_MESSAGE( symbol && victim,
"No shared-sheet pin registered on multiple paths" );
300 wxString pinNumber = victim->
GetNumber();
301 std::vector<SCH_PIN*> doomedPins = symbol->
GetPinsByNumber( pinNumber );
305 std::vector<SCH_ITEM*> danglingCandidates( doomedPins.begin(), doomedPins.end() );
311 for(
SCH_PIN* libPin : updated->GetPinsByNumber( pinNumber ) )
312 updated->RemoveDrawItem( libPin );
320 for(
SCH_ITEM* freedPin : danglingCandidates )
322 BOOST_CHECK_MESSAGE( countRefs( freedPin ) == 0,
323 "Freed pin " << pinNumber.ToStdString()
324 <<
" still referenced by a retained subgraph" );
338 SCH_SHEET_LIST sheets = m_schematic->BuildSheetListSortedByPageNumbers();
340 const wxString globalNet = wxT(
"+12V" );
341 const wxString localNet = wxT(
"local_label_on_page7" );
344 [&](
const wxString& aNetName )
346 std::set<wxString> paths;
349 paths.insert( sg->GetSheet().PathAsString() );
354 const std::set<wxString> before = sheetsOnNet( globalNet );
356 BOOST_REQUIRE_MESSAGE( before.size() > 1,
357 "Fixture net " << globalNet.ToStdString() <<
" must span several sheets" );
368 if(
static_cast<SCH_LABEL*
>( item )->GetText() == localNet )
370 localLabel =
static_cast<SCH_LABEL*
>( item );
376 BOOST_REQUIRE_MESSAGE( localLabel,
"Fixture must carry the local label from the issue report" );
382 std::set<SCH_ITEM*> changed = { newLabel, localLabel };
384 std::set<std::pair<SCH_SHEET_PATH, SCH_ITEM*>> affected = graph->
ExtractAffectedItems( changed );
386 affected.insert( { localPath, newLabel } );
387 affected.insert( { localPath, localLabel } );
389 for(
const auto& [
path, item] : affected )
390 item->SetConnectivityDirty();
395 graph->
Merge( new_graph );
397 const std::set<wxString> after = sheetsOnNet( globalNet );
399 for(
const wxString&
path : before )
401 BOOST_CHECK_MESSAGE( after.count(
path ),
402 "Sheet " <<
path.ToStdString() <<
" dropped from net "
403 << globalNet.ToStdString() <<
" (" << before.size() <<
" -> "
404 << after.size() <<
" sheets)" );
411 for(
const auto& [key, subgraphs] : graph->
GetNetMap() )
413 if( key.Name == globalNet )
414 codes.insert( key.Netcode );
417 BOOST_CHECK_MESSAGE( codes.size() == 1,
"Net " << globalNet.ToStdString() <<
" split across "
418 << codes.size() <<
" net codes" );
Calculate the connectivity of a schematic and generate netlists.
const NET_MAP & GetNetMap() const
const std::vector< CONNECTION_SUBGRAPH * > & GetAllSubgraphs(const wxString &aNetName) const
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.
std::set< std::pair< SCH_SHEET_PATH, SCH_ITEM * > > ExtractAffectedItems(const std::set< SCH_ITEM * > &aItems)
For a set of items, this will remove the connected items and their associated data including subgraph...
void SetLastCodes(const CONNECTION_GRAPH *aOther)
void Merge(CONNECTION_GRAPH &aGraph)
Combine the input graph contents into the current graph.
CONNECTION_SUBGRAPH * GetSubgraphForItem(SCH_ITEM *aItem) const
A subgraph is a set of items that are electrically connected on a single sheet.
EE_TYPE OfType(KICAD_T aType) const
std::unique_ptr< LIB_SYMBOL > Flatten() const
Return a flattened symbol inheritance to the caller.
Instantiate the current locale within a scope in which you are expecting exceptions to be thrown.
Holds all the data relating to one schematic.
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,...
const wxString & GetNumber() const
void Append(SCH_ITEM *aItem, bool aUpdateLibSymbol=true)
EE_RTREE & Items()
Get the full RTree, usually for iterating.
bool Remove(SCH_ITEM *aItem, bool aUpdateLibSymbol=true)
Remove aItem from the schematic associated with this screen.
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...
SCH_SCREEN * LastScreen()
Sheet symbol placed in a schematic, and is the entry point for a sub schematic.
SCH_SCREEN * GetScreen() const
std::vector< SCH_PIN * > GetGraphicalPins(int aUnit, int aBodyStyle) const override
std::vector< SCH_PIN * > GetPinsByNumber(const wxString &aNumber) const
Find all symbol pins with the given number.
std::unique_ptr< LIB_SYMBOL > & GetLibSymbolRef()
void SetLibSymbol(LIB_SYMBOL *aLibSymbol)
Set this schematic symbol library symbol reference to aLibSymbol.
VECTOR2I GetPosition() const override
void LoadSchematic(SETTINGS_MANAGER &aSettingsManager, const wxString &aRelPath, std::unique_ptr< SCHEMATIC > &aSchematic)
void remove_duplicates(_Container &__c)
Deletes all duplicate values from __c.
std::vector< FAB_LAYER_COLOR > dummy
BOOST_REQUIRE(intersection.has_value()==c.ExpectedIntersection.has_value())
BOOST_FIXTURE_TEST_CASE(DestroyingAnotherSchematicPreservesPinCleanup, CONNECTIVITY_TEST_FIXTURE)
BOOST_TEST_MESSAGE("Polyline has "<< chain.PointCount()<< " points")