diff --git a/pcbnew/board_commit.cpp b/pcbnew/board_commit.cpp index a7c9d8986d..e8840023fb 100644 --- a/pcbnew/board_commit.cpp +++ b/pcbnew/board_commit.cpp @@ -164,7 +164,9 @@ void BOARD_COMMIT::Push( const wxString& aMessage, bool aCreateUndoEntry, bool a board->Add( boardItem ); // handles connectivity } - view->Add( boardItem ); + if( boardItem->Type() != PCB_NETINFO_T ) + view->Add( boardItem ); + break; } @@ -240,6 +242,12 @@ void BOARD_COMMIT::Push( const wxString& aMessage, bool aCreateUndoEntry, bool a } break; + // Metadata items + case PCB_NETINFO_T: + if( !( changeFlags & CHT_DONE ) ) + board->Remove( boardItem ); + break; + default: // other types do not need to (or should not) be handled wxASSERT( false ); break; diff --git a/pcbnew/netinfo.h b/pcbnew/netinfo.h index 43849e44f3..38d7190ea4 100644 --- a/pcbnew/netinfo.h +++ b/pcbnew/netinfo.h @@ -460,6 +460,8 @@ public: * Removes a new from the net list. */ void RemoveNet( NETINFO_ITEM* aNet ); + void RemoveUnusedNets(); + /** * Function GetPadCount * @return the number of pads in board diff --git a/pcbnew/netinfo_list.cpp b/pcbnew/netinfo_list.cpp index 655d1706ae..c1b8e59bd2 100644 --- a/pcbnew/netinfo_list.cpp +++ b/pcbnew/netinfo_list.cpp @@ -108,6 +108,24 @@ void NETINFO_LIST::RemoveNet( NETINFO_ITEM* aNet ) } +void NETINFO_LIST::RemoveUnusedNets() +{ + NETCODES_MAP existingNets = m_netCodes; + + m_netCodes.clear(); + m_netNames.clear(); + + for( std::pair item : existingNets ) + { + if( item.second->IsCurrent() ) + { + m_netNames.insert( std::make_pair( item.second->GetNetname(), item.second ) ); + m_netCodes.insert( std::make_pair( item.first, item.second ) ); + } + } +} + + void NETINFO_LIST::AppendNet( NETINFO_ITEM* aNewElement ) { // if there is a net with such name then just assign the correct number diff --git a/pcbnew/netlist_reader/board_netlist_updater.cpp b/pcbnew/netlist_reader/board_netlist_updater.cpp index 4d4a8c3aba..ab3dfeb914 100644 --- a/pcbnew/netlist_reader/board_netlist_updater.cpp +++ b/pcbnew/netlist_reader/board_netlist_updater.cpp @@ -827,13 +827,25 @@ bool BOARD_NETLIST_UPDATER::UpdateNetlist( NETLIST& aNetlist ) if( !m_isDryRun ) { - m_commit.Push( _( "Update netlist" ) ); m_board->GetConnectivity()->Build( m_board ); testConnectivity( aNetlist ); // Now the connectivity data is rebuilt, we can delete single pads nets if( m_deleteSinglePadNets ) deleteSinglePadNets(); + + for( NETINFO_ITEM* net : m_board->GetNetInfo() ) + { + if( !net->IsCurrent() ) + { + msg.Printf( _( "Remove unused net \"%s\"." ), net->GetNetname() ); + m_reporter->Report( msg, RPT_SEVERITY_ACTION ); + m_commit.Removed( net ); + } + } + + m_board->GetNetInfo().RemoveUnusedNets(); + m_commit.Push( _( "Update netlist" ) ); } else if( m_deleteSinglePadNets && !m_newFootprintsCount ) // We can delete single net pads in dry run mode only if no new footprints diff --git a/pcbnew/undo_redo.cpp b/pcbnew/undo_redo.cpp index b100931d79..7b017f98ce 100644 --- a/pcbnew/undo_redo.cpp +++ b/pcbnew/undo_redo.cpp @@ -28,9 +28,7 @@ #include using namespace std::placeholders; #include -#include #include -#include #include #include #include @@ -39,8 +37,6 @@ using namespace std::placeholders; #include #include #include -#include -#include #include #include #include @@ -49,7 +45,6 @@ using namespace std::placeholders; #include #include #include -#include #include /* Functions to undo and redo edit commands. @@ -483,13 +478,19 @@ void PCB_BASE_EDIT_FRAME::PutDataInPreviousState( PICKED_ITEMS_LIST* aList, bool case UR_NEW: /* new items are deleted */ aList->SetPickedItemStatus( UR_DELETED, ii ); GetModel()->Remove( (BOARD_ITEM*) eda_item ); - view->Remove( eda_item ); + + if( eda_item->Type() != PCB_NETINFO_T ) + view->Remove( eda_item ); + break; case UR_DELETED: /* deleted items are put in List, as new items */ aList->SetPickedItemStatus( UR_NEW, ii ); GetModel()->Add( (BOARD_ITEM*) eda_item ); - view->Add( eda_item ); + + if( eda_item->Type() != PCB_NETINFO_T ) + view->Add( eda_item ); + break; case UR_MOVED: