From 4eba781013ddc60a8b525c20a03d18aafe895a52 Mon Sep 17 00:00:00 2001 From: Jon Evans Date: Sat, 10 Feb 2024 23:26:25 -0500 Subject: [PATCH] Try harder to remove stale pins from connectivity Fixes https://gitlab.com/kicad/code/kicad/-/issues/16846 --- eeschema/connection_graph.cpp | 29 +++++++++++++++++++++++++++++ eeschema/connection_graph.h | 2 ++ eeschema/sch_commit.cpp | 9 +++++++++ 3 files changed, 40 insertions(+) diff --git a/eeschema/connection_graph.cpp b/eeschema/connection_graph.cpp index e8c9491817..5056dcb257 100644 --- a/eeschema/connection_graph.cpp +++ b/eeschema/connection_graph.cpp @@ -734,6 +734,14 @@ std::set> CONNECTION_GRAPH::ExtractAffected } alg::delete_matching( m_items, item ); + + if( item->Type() == SCH_SYMBOL_T ) + { + SCH_SYMBOL* symbol = static_cast( item ); + + for( SCH_PIN* pin : symbol->GetPins( &sg->m_sheet ) ) + alg::delete_matching( m_items, pin ); + } } removeSubgraphs( subgraphs ); @@ -742,6 +750,24 @@ std::set> CONNECTION_GRAPH::ExtractAffected } +void CONNECTION_GRAPH::RemoveItem( SCH_ITEM* aItem ) +{ + auto it = m_item_to_subgraph_map.find( aItem ); + + if( it == m_item_to_subgraph_map.end() ) + return; + + CONNECTION_SUBGRAPH* subgraph = it->second; + + while(subgraph->m_absorbed_by ) + subgraph = subgraph->m_absorbed_by; + + subgraph->RemoveItem( aItem ); + alg::delete_matching( m_items, aItem ); + m_item_to_subgraph_map.erase( it ); +} + + void CONNECTION_GRAPH::removeSubgraphs( std::set& aSubgraphs ) { std::sort( m_driver_subgraphs.begin(), m_driver_subgraphs.end() ); @@ -906,6 +932,9 @@ void CONNECTION_GRAPH::updateItemConnectivity( const SCH_SHEET_PATH& aSheet, for( SCH_ITEM* item : aItemList ) { + if( item->Type() == SCH_PIN_T ) + std::cout << "conn updateItemConnectivity " << item << std::endl; + std::vector points = item->GetConnectionPoints(); item->ConnectedItems( aSheet ).clear(); diff --git a/eeschema/connection_graph.h b/eeschema/connection_graph.h index cbf0bd64c8..f0ab387f4c 100644 --- a/eeschema/connection_graph.h +++ b/eeschema/connection_graph.h @@ -452,6 +452,8 @@ public: */ void Merge( CONNECTION_GRAPH& aGraph ); + void RemoveItem( SCH_ITEM* aItem ); + private: /** * Update the graphical connectivity between items (i.e. where they touch) diff --git a/eeschema/sch_commit.cpp b/eeschema/sch_commit.cpp index b6bcd94a34..de5b823d58 100644 --- a/eeschema/sch_commit.cpp +++ b/eeschema/sch_commit.cpp @@ -33,6 +33,7 @@ #include #include +#include #include @@ -533,6 +534,14 @@ void SCH_COMMIT::Revert() { SCH_SYMBOL* symbol = static_cast( item ); symbol->UpdatePins(); + + CONNECTION_GRAPH* graph = schematic->ConnectionGraph(); + + SCH_SYMBOL* symbolCopy = static_cast( copy ); + graph->RemoveItem( symbolCopy ); + + for( SCH_PIN* pin : symbolCopy->GetPins() ) + graph->RemoveItem( pin ); } item->SetConnectivityDirty();