46 auto* graph = m_schematic->ConnectionGraph();
47 graph->Recalculate( m_schematic->Hierarchy(),
true );
48 SCH_SCREEN* screen = m_schematic->Hierarchy().front().LastScreen();
51 auto* symbol =
static_cast<SCH_SYMBOL*
>( *symbols.begin() );
52 std::vector<SCH_PIN*> pins = symbol->
GetPins();
64 BOOST_CHECK( !graph->GetSubgraphForItem(
pin ) );
71 auto* mainGraph = m_schematic->ConnectionGraph();
72 const auto paths = m_schematic->Hierarchy();
73 mainGraph->Recalculate( paths,
true );
74 auto expired = std::make_unique<CONNECTION_GRAPH>( m_schematic.get() );
75 expired->Recalculate( paths,
true );
78 SCH_SCREEN* screen = paths.front().LastScreen();
81 auto* symbol =
static_cast<SCH_SYMBOL*
>( *symbols.begin() );
82 const auto pins = symbol->
GetPins();
98 BOOST_CHECK( !mainGraph->GetSubgraphForItem(
pin ) );
109 std::vector<wxString> tests = {
125 for(
const wxString&
test : tests )
129 SCH_SHEET_LIST sheets = m_schematic->BuildSheetListSortedByPageNumbers();
133 for(
size_t ii = 0; ii <
path.size(); ++ii )
137 std::vector<SCH_ITEM*> items;
141 if( !item->IsConnectable() )
150 items.push_back(
pin );
155 items.push_back( item );
161 const std::vector<SCH_ITEM*>& conn_items = item->ConnectedItems(
path );
163 wxString netname = conn ? conn->
GetNetName() : wxString(
"NoNet" );
167 <<
": Item " << item->GetFriendlyName().ToStdString()
168 <<
" in net " << netname.ToStdString() <<
" subgraph " << subgraph
169 <<
" has " << conn_items.size() <<
" connections" );
174 if( !item->IsConnectable() )
177 std::vector<SCH_ITEM*> prev_items = item->ConnectedItems(
path );
178 std::sort( prev_items.begin(), prev_items.end() );
181 std::set<std::pair<SCH_SHEET_PATH, SCH_ITEM*>> all_items =
182 m_schematic->ConnectionGraph()->ExtractAffectedItems( { item } );
183 all_items.insert( {
path, item } );
185 <<
": Item " << item->GetFriendlyName().ToStdString()
186 <<
" in net " << netname.ToStdString()
187 <<
" has " << all_items.size() <<
" affected items" );
191 new_graph.
SetLastCodes( m_schematic->ConnectionGraph() );
193 for(
auto&[ apath, aitem ] : all_items )
195 wxCHECK2( aitem,
continue );
196 aitem->SetConnectivityDirty();
200 m_schematic->ConnectionGraph()->Merge( new_graph );
202 std::vector<SCH_ITEM*> curr_items = item->ConnectedItems(
path );
203 std::sort( curr_items.begin(), curr_items.end() );
206 BOOST_CHECK_MESSAGE( prev_items == curr_items,
208 <<
": Item " << item->GetFriendlyName().ToStdString()
209 <<
" in net " << netname.ToStdString()
210 <<
" changed from " << prev_items.size() <<
" to " << curr_items.size()
211 <<
" Location:" << item->GetPosition().x <<
"," << item->GetPosition().y );
233 SCH_SHEET_LIST sheets = m_schematic->BuildSheetListSortedByPageNumbers();
235 std::map<SCH_SCREEN*, int> instanceCount;
238 instanceCount[
path.LastScreen()]++;
247 for(
const auto& [key, subgraphs] : graph->
GetNetMap() )
251 if( sg->GetItems().count( aItem ) )
263 for(
auto& [screen, count] : instanceCount )
277 if( countRefs(
pin ) >= 2 )
293 BOOST_REQUIRE_MESSAGE( symbol && victim,
"No shared-sheet pin registered on multiple paths" );
295 wxString pinNumber = victim->
GetNumber();
296 std::vector<SCH_PIN*> doomedPins = symbol->
GetPinsByNumber( pinNumber );
300 std::vector<SCH_ITEM*> danglingCandidates( doomedPins.begin(), doomedPins.end() );
306 for(
SCH_PIN* libPin : updated->GetPinsByNumber( pinNumber ) )
307 updated->RemoveDrawItem( libPin );
315 for(
SCH_ITEM* freedPin : danglingCandidates )
317 BOOST_CHECK_MESSAGE( countRefs( freedPin ) == 0,
318 "Freed pin " << pinNumber.ToStdString()
319 <<
" still referenced by a retained subgraph" );
333 SCH_SHEET_LIST sheets = m_schematic->BuildSheetListSortedByPageNumbers();
335 const wxString globalNet = wxT(
"+12V" );
336 const wxString localNet = wxT(
"local_label_on_page7" );
339 [&](
const wxString& aNetName )
341 std::set<wxString> paths;
344 paths.insert( sg->GetSheet().PathAsString() );
349 const std::set<wxString> before = sheetsOnNet( globalNet );
351 BOOST_REQUIRE_MESSAGE( before.size() > 1,
352 "Fixture net " << globalNet.ToStdString() <<
" must span several sheets" );
363 if(
static_cast<SCH_LABEL*
>( item )->GetText() == localNet )
365 localLabel =
static_cast<SCH_LABEL*
>( item );
371 BOOST_REQUIRE_MESSAGE( localLabel,
"Fixture must carry the local label from the issue report" );
377 std::set<SCH_ITEM*> changed = { newLabel, localLabel };
379 std::set<std::pair<SCH_SHEET_PATH, SCH_ITEM*>> affected = graph->
ExtractAffectedItems( changed );
381 affected.insert( { localPath, newLabel } );
382 affected.insert( { localPath, localLabel } );
384 for(
const auto& [
path, item] : affected )
385 item->SetConnectivityDirty();
390 graph->
Merge( new_graph );
392 const std::set<wxString> after = sheetsOnNet( globalNet );
394 for(
const wxString&
path : before )
396 BOOST_CHECK_MESSAGE( after.count(
path ),
397 "Sheet " <<
path.ToStdString() <<
" dropped from net "
398 << globalNet.ToStdString() <<
" (" << before.size() <<
" -> "
399 << after.size() <<
" sheets)" );
406 for(
const auto& [key, subgraphs] : graph->
GetNetMap() )
408 if( key.Name == globalNet )
409 codes.insert( key.Netcode );
412 BOOST_CHECK_MESSAGE( codes.size() == 1,
"Net " << globalNet.ToStdString() <<
" split across "
413 << 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< const SCH_PIN * > GetPins(const SCH_SHEET_PATH *aSheet) const
Retrieve a list of the SCH_PINs for the given sheet path.
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
SETTINGS_MANAGER m_settingsManager
CONNECTIVITY_TEST_FIXTURE()
std::unique_ptr< SCHEMATIC > m_schematic
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")