Remove unused nets when updating PCB.

Fixes https://gitlab.com/kicad/code/kicad/issues/4247
This commit is contained in:
Jeff Young 2020-07-13 22:35:05 +01:00
parent 940570e9ec
commit efc3f8c29d
5 changed files with 50 additions and 9 deletions

View File

@ -164,7 +164,9 @@ void BOARD_COMMIT::Push( const wxString& aMessage, bool aCreateUndoEntry, bool a
board->Add( boardItem ); // handles connectivity board->Add( boardItem ); // handles connectivity
} }
view->Add( boardItem ); if( boardItem->Type() != PCB_NETINFO_T )
view->Add( boardItem );
break; break;
} }
@ -240,6 +242,12 @@ void BOARD_COMMIT::Push( const wxString& aMessage, bool aCreateUndoEntry, bool a
} }
break; 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 default: // other types do not need to (or should not) be handled
wxASSERT( false ); wxASSERT( false );
break; break;

View File

@ -460,6 +460,8 @@ public:
* Removes a new from the net list. * Removes a new from the net list.
*/ */
void RemoveNet( NETINFO_ITEM* aNet ); void RemoveNet( NETINFO_ITEM* aNet );
void RemoveUnusedNets();
/** /**
* Function GetPadCount * Function GetPadCount
* @return the number of pads in board * @return the number of pads in board

View File

@ -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<const int, NETINFO_ITEM*> 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 ) void NETINFO_LIST::AppendNet( NETINFO_ITEM* aNewElement )
{ {
// if there is a net with such name then just assign the correct number // if there is a net with such name then just assign the correct number

View File

@ -827,13 +827,25 @@ bool BOARD_NETLIST_UPDATER::UpdateNetlist( NETLIST& aNetlist )
if( !m_isDryRun ) if( !m_isDryRun )
{ {
m_commit.Push( _( "Update netlist" ) );
m_board->GetConnectivity()->Build( m_board ); m_board->GetConnectivity()->Build( m_board );
testConnectivity( aNetlist ); testConnectivity( aNetlist );
// Now the connectivity data is rebuilt, we can delete single pads nets // Now the connectivity data is rebuilt, we can delete single pads nets
if( m_deleteSinglePadNets ) if( m_deleteSinglePadNets )
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 ) else if( m_deleteSinglePadNets && !m_newFootprintsCount )
// We can delete single net pads in dry run mode only if no new footprints // We can delete single net pads in dry run mode only if no new footprints

View File

@ -28,9 +28,7 @@
#include <functional> #include <functional>
using namespace std::placeholders; using namespace std::placeholders;
#include <fctsys.h> #include <fctsys.h>
#include <class_draw_panel_gal.h>
#include <macros.h> #include <macros.h>
#include <pcbnew.h>
#include <pcb_edit_frame.h> #include <pcb_edit_frame.h>
#include <class_board.h> #include <class_board.h>
#include <class_track.h> #include <class_track.h>
@ -39,8 +37,6 @@ using namespace std::placeholders;
#include <class_pcb_target.h> #include <class_pcb_target.h>
#include <class_module.h> #include <class_module.h>
#include <class_dimension.h> #include <class_dimension.h>
#include <class_zone.h>
#include <class_edge_mod.h>
#include <origin_viewitem.h> #include <origin_viewitem.h>
#include <connectivity/connectivity_data.h> #include <connectivity/connectivity_data.h>
#include <pcbnew_settings.h> #include <pcbnew_settings.h>
@ -49,7 +45,6 @@ using namespace std::placeholders;
#include <tools/selection_tool.h> #include <tools/selection_tool.h>
#include <tools/pcbnew_control.h> #include <tools/pcbnew_control.h>
#include <tools/pcb_editor_control.h> #include <tools/pcb_editor_control.h>
#include <view/view.h>
#include <ws_proxy_undo_item.h> #include <ws_proxy_undo_item.h>
/* Functions to undo and redo edit commands. /* 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 */ case UR_NEW: /* new items are deleted */
aList->SetPickedItemStatus( UR_DELETED, ii ); aList->SetPickedItemStatus( UR_DELETED, ii );
GetModel()->Remove( (BOARD_ITEM*) eda_item ); GetModel()->Remove( (BOARD_ITEM*) eda_item );
view->Remove( eda_item );
if( eda_item->Type() != PCB_NETINFO_T )
view->Remove( eda_item );
break; break;
case UR_DELETED: /* deleted items are put in List, as new items */ case UR_DELETED: /* deleted items are put in List, as new items */
aList->SetPickedItemStatus( UR_NEW, ii ); aList->SetPickedItemStatus( UR_NEW, ii );
GetModel()->Add( (BOARD_ITEM*) eda_item ); GetModel()->Add( (BOARD_ITEM*) eda_item );
view->Add( eda_item );
if( eda_item->Type() != PCB_NETINFO_T )
view->Add( eda_item );
break; break;
case UR_MOVED: case UR_MOVED: