Another way of handling items for the ratsnest (clearer and now finally supports undo/redo of the PNS created tracks).

This commit is contained in:
Maciej Suminski 2014-01-30 15:46:39 +01:00
parent bbb3972fb7
commit 510fee1358
5 changed files with 28 additions and 49 deletions

View File

@ -548,8 +548,7 @@ void PCB_EDIT_FRAME::PutDataInPreviousState( PICKED_ITEMS_LIST* aList, bool aRed
if( item->Type() == PCB_MODULE_T )
{
MODULE* module = static_cast<MODULE*>( item );
module->RunOnChildren( std::bind1st( std::mem_fun( &KIGFX::VIEW::Remove ),
view ) );
module->RunOnChildren( std::bind1st( std::mem_fun( &KIGFX::VIEW::Remove ), view ) );
}
view->Remove( item );
@ -563,8 +562,7 @@ void PCB_EDIT_FRAME::PutDataInPreviousState( PICKED_ITEMS_LIST* aList, bool aRed
if( item->Type() == PCB_MODULE_T )
{
MODULE* module = static_cast<MODULE*>( item );
module->RunOnChildren( std::bind1st( std::mem_fun( &KIGFX::VIEW::Add ),
view ) );
module->RunOnChildren( std::bind1st( std::mem_fun( &KIGFX::VIEW::Add ), view ) );
}
view->Add( item );
@ -575,23 +573,27 @@ void PCB_EDIT_FRAME::PutDataInPreviousState( PICKED_ITEMS_LIST* aList, bool aRed
case UR_MOVED:
item->Move( aRedoCommand ? aList->m_TransformPoint : -aList->m_TransformPoint );
item->ViewUpdate( KIGFX::VIEW_ITEM::GEOMETRY );
ratsnest->Update( item );
break;
case UR_ROTATED:
item->Rotate( aList->m_TransformPoint,
aRedoCommand ? m_rotationAngle : -m_rotationAngle );
item->ViewUpdate( KIGFX::VIEW_ITEM::GEOMETRY );
ratsnest->Update( item );
break;
case UR_ROTATED_CLOCKWISE:
item->Rotate( aList->m_TransformPoint,
aRedoCommand ? -m_rotationAngle : m_rotationAngle );
item->ViewUpdate( KIGFX::VIEW_ITEM::GEOMETRY );
ratsnest->Update( item );
break;
case UR_FLIPPED:
item->Flip( aList->m_TransformPoint );
item->ViewUpdate( KIGFX::VIEW_ITEM::LAYERS );
ratsnest->Update( item );
break;
default:
@ -603,8 +605,6 @@ void PCB_EDIT_FRAME::PutDataInPreviousState( PICKED_ITEMS_LIST* aList, bool aRed
}
break;
}
ratsnest->Update( item );
}
if( not_found )

View File

@ -842,6 +842,8 @@ void BOARD::Add( BOARD_ITEM* aBoardItem, int aControl )
}
break;
}
m_ratsnest->Add( aBoardItem );
}
@ -867,55 +869,25 @@ BOARD_ITEM* BOARD::Remove( BOARD_ITEM* aBoardItem )
break;
case PCB_ZONE_AREA_T: // this one uses a vector
{
ZONE_CONTAINER* zone = static_cast<ZONE_CONTAINER*>( aBoardItem );
// find the item in the vector, then delete then erase it.
for( unsigned i = 0; i<m_ZoneDescriptorList.size(); ++i )
{
if( m_ZoneDescriptorList[i] == zone )
if( m_ZoneDescriptorList[i] == (ZONE_CONTAINER*) aBoardItem )
{
m_ZoneDescriptorList.erase( m_ZoneDescriptorList.begin() + i );
break;
}
}
if( zone->GetNet() > 0 )
m_ratsnest->GetNet( zone->GetNet() ).RemoveItem( zone );
}
break;
case PCB_MODULE_T:
{
MODULE* module = static_cast<MODULE*>( aBoardItem );
m_Modules.Remove( (MODULE*) aBoardItem );
for( D_PAD* pad = module->Pads().GetFirst(); pad; pad = pad->Next() )
{
if( pad->GetNet() > 0 )
m_ratsnest->GetNet( pad->GetNet() ).RemoveItem( pad );
}
}
break;
case PCB_TRACE_T:
{
TRACK* track = static_cast<TRACK*>( aBoardItem );
m_Track.Remove( track );
if( track->GetNet() > 0 )
m_ratsnest->GetNet( track->GetNet() ).RemoveItem( track );
}
break;
case PCB_VIA_T:
{
SEGVIA* via = static_cast<SEGVIA*>( aBoardItem );
m_Track.Remove( via );
if( via->GetNet() > 0 )
m_ratsnest->GetNet( via->GetNet() ).RemoveItem( via );
}
m_Track.Remove( (TRACK*) aBoardItem );
break;
case PCB_ZONE_T:
@ -935,6 +907,8 @@ BOARD_ITEM* BOARD::Remove( BOARD_ITEM* aBoardItem )
wxFAIL_MSG( wxT( "BOARD::Remove() needs more ::Type() support" ) );
}
m_ratsnest->Remove( aBoardItem );
return aBoardItem;
}

View File

@ -428,11 +428,11 @@ BOARD* PCB_PARSER::parseBOARD() throw( IO_ERROR, PARSE_ERROR )
break;
case T_segment:
m_board->m_Track.Append( parseTRACK() );
m_board->Add( parseTRACK(), ADD_APPEND );
break;
case T_via:
m_board->m_Track.Append( parseSEGVIA() );
m_board->Add( parseSEGVIA(), ADD_APPEND );
break;
case T_zone:

View File

@ -612,7 +612,6 @@ void PCB_EDIT_FRAME::ViewReloadBoard( const BOARD* aBoard ) const
// Add an entry for the ratsnest
RN_DATA* ratsnest = aBoard->GetRatsnest();
ratsnest->ProcessBoard();
ratsnest->Recalculate();
view->Add( new KIGFX::RATSNEST_VIEWITEM( ratsnest ) );

View File

@ -782,6 +782,10 @@ void RN_DATA::Add( const BOARD_ITEM* aItem )
net = static_cast<const BOARD_CONNECTED_ITEM*>( aItem )->GetNet();
if( net < 1 ) // do not process unconnected items
return;
// Autoresize
if( net >= (int) m_nets.size() )
m_nets.resize( net + 1 );
}
else if( aItem->Type() == PCB_MODULE_T )
{
@ -789,10 +793,13 @@ void RN_DATA::Add( const BOARD_ITEM* aItem )
for( const D_PAD* pad = module->Pads().GetFirst(); pad; pad = pad->Next() )
{
net = pad->GetNet();
if( net < 1 ) // do not process unconnected items
continue;
// Autoresize
if( net >= (int) m_nets.size() )
m_nets.resize( net + 1 );
m_nets[net].AddItem( pad );
}
@ -841,7 +848,6 @@ void RN_DATA::Remove( const BOARD_ITEM* aItem )
for( const D_PAD* pad = module->Pads().GetFirst(); pad; pad = pad->Next() )
{
net = pad->GetNet();
if( net < 1 ) // do not process unconnected items
continue;
@ -916,8 +922,8 @@ void RN_DATA::Recalculate( int aNet )
{
if( aNet < 0 ) // Recompute everything
{
// Start with net number 1, as 0 stand for not connected
for( unsigned int i = 1; i < m_board->GetNetCount(); ++i )
// Start with net number 1, as 0 stands for not connected
for( unsigned int i = 1; i < m_nets.size(); ++i )
{
// Recompute only nets that require it
if( m_nets[i].IsDirty() )