pcbnew: support for removing NETINFO_ITEMS from BOARD for proper netlist undo

This commit is contained in:
Tomasz Wlostowski 2016-01-29 11:29:56 +01:00 committed by Maciej Suminski
parent 867a0444bd
commit 5ef6001e06
6 changed files with 59 additions and 22 deletions

View File

@ -672,6 +672,10 @@ void BOARD::Add( BOARD_ITEM* aBoardItem, int aControl )
switch( aBoardItem->Type() )
{
case PCB_NETINFO_T:
aBoardItem->SetParent( this );
m_NetInfo.AppendNet( (NETINFO_ITEM*) aBoardItem );
// this one uses a vector
case PCB_MARKER_T:
aBoardItem->SetParent( this );
@ -737,10 +741,6 @@ void BOARD::Add( BOARD_ITEM* aBoardItem, int aControl )
aBoardItem->SetParent( this );
break;
case PCB_NETINFO_T:
m_NetInfo.AppendNet( (NETINFO_ITEM *) aBoardItem );
break;
// other types may use linked list
default:
{
@ -763,6 +763,10 @@ BOARD_ITEM* BOARD::Remove( BOARD_ITEM* aBoardItem )
switch( aBoardItem->Type() )
{
case PCB_NETINFO_T:
m_NetInfo.RemoveNet ( (NETINFO_ITEM*) aBoardItem );
break;
case PCB_MARKER_T:
// find the item in the vector, then remove it
@ -811,11 +815,6 @@ BOARD_ITEM* BOARD::Remove( BOARD_ITEM* aBoardItem )
m_Drawings.Remove( aBoardItem );
break;
case PCB_NETINFO_T:
printf( "Unimpl! remove netinfo!\n" );
assert( false );
break;
// other types may use linked list
default:
wxFAIL_MSG( wxT( "BOARD::Remove() needs more ::Type() support" ) );
@ -1261,7 +1260,7 @@ NETINFO_ITEM* BOARD::FindNet( int aNetcode ) const
wxASSERT( m_NetInfo.GetNetCount() > 0 ); // net zero should exist
if( aNetcode == NETINFO_LIST::UNCONNECTED && m_NetInfo.GetNetCount() == 0 )
return &NETINFO_LIST::ORPHANED;
return &NETINFO_LIST::ORPHANED_ITEM;
else
return m_NetInfo.GetNetItem( aNetcode );
}

View File

@ -35,7 +35,7 @@
#include <class_board_item.h>
BOARD_CONNECTED_ITEM::BOARD_CONNECTED_ITEM( BOARD_ITEM* aParent, KICAD_T idtype ) :
BOARD_ITEM( aParent, idtype ), m_netinfo( &NETINFO_LIST::ORPHANED ),
BOARD_ITEM( aParent, idtype ), m_netinfo( &NETINFO_LIST::ORPHANED_ITEM ),
m_Subnet( 0 ), m_ZoneSubnet( 0 )
{
}
@ -59,7 +59,7 @@ bool BOARD_CONNECTED_ITEM::SetNetCode( int aNetCode, bool aNoAssert )
if( ( aNetCode >= 0 ) && board )
m_netinfo = board->FindNet( aNetCode );
else
m_netinfo = &NETINFO_LIST::ORPHANED;
m_netinfo = &NETINFO_LIST::ORPHANED_ITEM;
if( !aNoAssert )
assert( m_netinfo );

View File

@ -186,7 +186,7 @@ void MODULE::ClearAllNets()
// Force the ORPHANED dummy net info for all pads.
// ORPHANED dummy net does not depend on a board
for( D_PAD* pad = Pads(); pad; pad = pad->Next() )
pad->SetNetCode( NETINFO_LIST::FORCE_ORPHANED );
pad->SetNetCode( NETINFO_LIST::ORPHANED );
}

View File

@ -291,12 +291,18 @@ public:
unsigned GetNetCount() const { return m_netNames.size(); }
/**
* Function Append
* adds \a aNewElement to the end of the list. Negative net code means it is going to be
* Function AppendNet
* adds \a aNewElement to the end of the net list. Negative net code means it is going to be
* auto-assigned.
*/
void AppendNet( NETINFO_ITEM* aNewElement );
/**
* Function RemoveNet
* Removes a new from the net list.
*/
void RemoveNet( NETINFO_ITEM* aNet );
/**
* Function GetPadCount
* @return the number of pads in board
@ -348,11 +354,11 @@ public:
///> Constant that forces initialization of a netinfo item to the NETINFO_ITEM ORPHANED
///> (typically -1) when calling SetNetCode od board connected items
static const int FORCE_ORPHANED;
static const int ORPHANED;
///> NETINFO_ITEM meaning that there was no net assigned for an item, as there was no
///> board storing net list available.
static NETINFO_ITEM ORPHANED;
static NETINFO_ITEM ORPHANED_ITEM;
#if defined(DEBUG)
void Show() const;

View File

@ -69,6 +69,28 @@ void NETINFO_LIST::clear()
}
void NETINFO_LIST::RemoveNet( NETINFO_ITEM* aNet )
{
for( NETCODES_MAP::iterator i = m_netCodes.begin(); i != m_netCodes.end(); ++i )
{
if ( i->second == aNet )
{
m_netCodes.erase(i);
break;
}
}
for( NETNAMES_MAP::iterator i = m_netNames.begin(); i != m_netNames.end(); ++i )
{
if ( i->second == aNet )
{
m_netNames.erase(i);
break;
}
}
}
void NETINFO_LIST::AppendNet( NETINFO_ITEM* aNewElement )
{
// if there is a net with such name then just assign the correct number
@ -295,6 +317,6 @@ NETINFO_ITEM* NETINFO_MAPPING::iterator::operator->() const
const int NETINFO_LIST::UNCONNECTED = 0;
const int NETINFO_LIST::FORCE_ORPHANED = -1;
const int NETINFO_LIST::ORPHANED = -1;
NETINFO_ITEM NETINFO_LIST::ORPHANED = NETINFO_ITEM( NULL, wxEmptyString, NETINFO_LIST::UNCONNECTED );
NETINFO_ITEM NETINFO_LIST::ORPHANED_ITEM = NETINFO_ITEM( NULL, wxEmptyString, NETINFO_LIST::UNCONNECTED );

View File

@ -52,13 +52,23 @@ void DIALOG_UPDATE_PCB::PerformUpdate( bool aDryRun )
toolManager->RunAction( COMMON_ACTIONS::selectionClear, true );
}
m_frame->LoadFootprints( *m_netlist, &reporter );
try {
m_frame->LoadFootprints( *m_netlist, &reporter );
}
catch( IO_ERROR &error )
{
wxString msg;
reporter.Report( _( "Failed to load one or more footprints. Please add the missing libraries in PCBNew configuration. "
"The PCB will not update completely." ), REPORTER::RPT_ERROR );
reporter.Report( error.errorText, REPORTER::RPT_INFO );
}
BOARD_NETLIST_UPDATER updater( m_frame, m_frame->GetBoard() );
updater.SetReporter ( &reporter );
updater.SetIsDryRun( aDryRun);
updater.SetLookupByTimestamp( true );
updater.SetLookupByTimestamp( m_matchByTimestamp->GetValue() );
updater.SetDeleteUnusedComponents ( true );
updater.SetReplaceFootprints( true );
updater.SetDeleteSinglePadNets ( false );
@ -94,7 +104,7 @@ void DIALOG_UPDATE_PCB::PerformUpdate( bool aDryRun )
void DIALOG_UPDATE_PCB::OnMatchChange( wxCommandEvent& event )
{
PerformUpdate( true );
}
void DIALOG_UPDATE_PCB::OnCancelClick( wxCommandEvent& event )