Don't double-remove nets when netcodes are reused

Fixes https://gitlab.com/kicad/code/kicad/-/issues/8206
This commit is contained in:
Jon Evans 2021-05-10 19:52:19 -04:00
parent 55c1d814f9
commit ce01a28aad
2 changed files with 14 additions and 6 deletions

View File

@ -673,25 +673,27 @@ void BOARD::Remove( BOARD_ITEM* aBoardItem, REMOVE_MODE aRemoveMode )
{
NETINFO_ITEM* item = static_cast<NETINFO_ITEM*>( aBoardItem );
NETINFO_ITEM* unconnected = m_NetInfo.GetNetItem( NETINFO_LIST::UNCONNECTED );
int removedCode = item->GetNetCode();
for( FOOTPRINT* fp : m_footprints )
{
for( PAD* pad : fp->Pads() )
{
if( pad->GetNetCode() == removedCode )
if( pad->GetNet() == item )
pad->SetNet( unconnected );
}
}
for( ZONE* zone : m_zones )
{
if( zone->GetNetCode() == removedCode )
if( zone->GetNet() == item )
zone->SetNet( unconnected );
}
for( TRACK* track : TracksInNet( removedCode ) )
track->SetNet( unconnected );
for( TRACK* track : m_tracks )
{
if( track->GetNet() == item )
track->SetNet( unconnected );
}
m_NetInfo.RemoveNet( item );
break;

View File

@ -83,10 +83,13 @@ NETINFO_ITEM* NETINFO_LIST::GetNetItem( const wxString& aNetName ) const
void NETINFO_LIST::RemoveNet( NETINFO_ITEM* aNet )
{
bool removed = false;
for( NETCODES_MAP::iterator i = m_netCodes.begin(); i != m_netCodes.end(); ++i )
{
if ( i->second == aNet )
{
removed = true;
m_netCodes.erase(i);
break;
}
@ -96,12 +99,15 @@ void NETINFO_LIST::RemoveNet( NETINFO_ITEM* aNet )
{
if ( i->second == aNet )
{
wxASSERT_MSG( removed, "NETINFO_LIST::RemoveNet: target net found in m_netNames "
"but not m_netCodes!" );
m_netNames.erase(i);
break;
}
}
m_newNetCode = std::min( m_newNetCode, aNet->m_netCode - 1 );
if( removed )
m_newNetCode = std::min( m_newNetCode, aNet->m_netCode - 1 );
}