Ratsnest Add()/Remove()/Update() return true on success

This commit is contained in:
Maciej Suminski 2016-09-05 12:18:55 +02:00
parent 790b6eaeb9
commit 828f28ecca
2 changed files with 58 additions and 22 deletions

View File

@ -1033,22 +1033,27 @@ void RN_NET::processPads()
} }
void RN_DATA::Add( const BOARD_ITEM* aItem ) bool RN_DATA::Add( const BOARD_ITEM* aItem )
{ {
int net; int net;
if( aItem->IsConnected() ) if( aItem->IsConnected() )
{ {
net = static_cast<const BOARD_CONNECTED_ITEM*>( aItem )->GetNetCode(); net = static_cast<const BOARD_CONNECTED_ITEM*>( aItem )->GetNetCode();
if( net < 1 ) // do not process unconnected items
return;
if( net < 1 ) // do not process unconnected items
return false;
wxASSERT( (unsigned) net < m_nets.size() );
/// @todo if the assert above has not been triggered for a long time,
/// then removed the autoresize code below
if( net >= (int) m_nets.size() ) // Autoresize if( net >= (int) m_nets.size() ) // Autoresize
m_nets.resize( net + 1 ); m_nets.resize( net + 1 );
} }
else if( aItem->Type() == PCB_MODULE_T ) else if( aItem->Type() == PCB_MODULE_T )
{ {
const MODULE* module = static_cast<const MODULE*>( aItem ); const MODULE* module = static_cast<const MODULE*>( aItem );
for( const D_PAD* pad = module->Pads().GetFirst(); pad; pad = pad->Next() ) for( const D_PAD* pad = module->Pads().GetFirst(); pad; pad = pad->Next() )
{ {
net = pad->GetNetCode(); net = pad->GetNetCode();
@ -1056,16 +1061,26 @@ void RN_DATA::Add( const BOARD_ITEM* aItem )
if( net < 1 ) // do not process unconnected items if( net < 1 ) // do not process unconnected items
continue; continue;
wxASSERT( (unsigned) net < m_nets.size() );
/// @todo if the assert above has not been triggered for a long time,
/// then removed the autoresize code below
if( net >= (int) m_nets.size() ) // Autoresize if( net >= (int) m_nets.size() ) // Autoresize
m_nets.resize( net + 1 ); m_nets.resize( net + 1 );
m_nets[net].AddItem( pad ); m_nets[net].AddItem( pad );
} }
return; return true;
}
else if( aItem->Type() == PCB_NETINFO_T )
{
int netCount = m_board->GetNetCount();
if( (unsigned) netCount > m_nets.size() )
m_nets.resize( netCount );
return true;
} }
else
return;
switch( aItem->Type() ) switch( aItem->Type() )
{ {
@ -1086,12 +1101,15 @@ void RN_DATA::Add( const BOARD_ITEM* aItem )
break; break;
default: default:
return false;
break; break;
} }
return true;
} }
void RN_DATA::Remove( const BOARD_ITEM* aItem ) bool RN_DATA::Remove( const BOARD_ITEM* aItem )
{ {
int net; int net;
@ -1100,21 +1118,23 @@ void RN_DATA::Remove( const BOARD_ITEM* aItem )
net = static_cast<const BOARD_CONNECTED_ITEM*>( aItem )->GetNetCode(); net = static_cast<const BOARD_CONNECTED_ITEM*>( aItem )->GetNetCode();
if( net < 1 ) // do not process unconnected items if( net < 1 ) // do not process unconnected items
return; return false;
wxASSERT( (unsigned) net < m_nets.size() );
/// @todo if the assert above has not been triggered for a long time,
/// then removed the autoresize code below
#ifdef NDEBUG #ifdef NDEBUG
if( net >= (int) m_nets.size() ) // Autoresize if( net >= (int) m_nets.size() ) // Autoresize
{ {
m_nets.resize( net + 1 ); m_nets.resize( net + 1 );
return false; // if it was resized, then surely the item had not been added before
return; // if it was resized, then surely the item had not been added before
} }
#endif #endif
assert( net < (int) m_nets.size() );
} }
else if( aItem->Type() == PCB_MODULE_T ) else if( aItem->Type() == PCB_MODULE_T )
{ {
const MODULE* module = static_cast<const MODULE*>( aItem ); const MODULE* module = static_cast<const MODULE*>( aItem );
for( const D_PAD* pad = module->Pads().GetFirst(); pad; pad = pad->Next() ) for( const D_PAD* pad = module->Pads().GetFirst(); pad; pad = pad->Next() )
{ {
net = pad->GetNetCode(); net = pad->GetNetCode();
@ -1122,23 +1142,26 @@ void RN_DATA::Remove( const BOARD_ITEM* aItem )
if( net < 1 ) // do not process unconnected items if( net < 1 ) // do not process unconnected items
continue; continue;
wxASSERT( (unsigned) net < m_nets.size() );
/// @todo if the assert above has not been triggered for a long time,
/// then removed the autoresize code below
#ifdef NDEBUG #ifdef NDEBUG
if( net >= (int) m_nets.size() ) // Autoresize if( net >= (int) m_nets.size() ) // Autoresize
{ {
m_nets.resize( net + 1 ); m_nets.resize( net + 1 );
return false; // if it was resized, then surely the item had not been added before
return; // if it was resized, then surely the item had not been added before
} }
#endif #endif
assert( net < (int) m_nets.size() );
m_nets[net].RemoveItem( pad ); m_nets[net].RemoveItem( pad );
} }
return; return true;
} }
else else
return; {
return false;
}
switch( aItem->Type() ) switch( aItem->Type() )
{ {
@ -1159,15 +1182,24 @@ void RN_DATA::Remove( const BOARD_ITEM* aItem )
break; break;
default: default:
return false;
break; break;
} }
return true;
} }
void RN_DATA::Update( const BOARD_ITEM* aItem ) bool RN_DATA::Update( const BOARD_ITEM* aItem )
{ {
Remove( aItem ); if( Remove( aItem ) )
Add( aItem ); {
bool res = Add( aItem );
assert( res );
return true;
}
return false;
} }

View File

@ -647,22 +647,26 @@ public:
* Function Add() * Function Add()
* Adds an item to the ratsnest data. * Adds an item to the ratsnest data.
* @param aItem is an item to be added. * @param aItem is an item to be added.
* @return True if operation succeeded.
*/ */
void Add( const BOARD_ITEM* aItem ); bool Add( const BOARD_ITEM* aItem );
/** /**
* Function Remove() * Function Remove()
* Removes an item from the ratsnest data. * Removes an item from the ratsnest data.
* @param aItem is an item to be updated. * @param aItem is an item to be updated.
* @return True if operation succeeded.
*/ */
void Remove( const BOARD_ITEM* aItem ); bool Remove( const BOARD_ITEM* aItem );
/** /**
* Function Update() * Function Update()
* Updates the ratsnest data for an item. * Updates the ratsnest data for an item.
* @param aItem is an item to be updated. * @param aItem is an item to be updated.
* @return True if operation succeeded. The item will not be updated if it was not previously
* added to the ratsnest.
*/ */
void Update( const BOARD_ITEM* aItem ); bool Update( const BOARD_ITEM* aItem );
/** /**
* Function AddSimple() * Function AddSimple()