Ratsnest is updated after rotation, flip, undo/redo operations.

Fixed crashes of ratsnest when a pointer for an item has changed after undo/redo operations.
Vias are properly removed from ratsnest (pcbnew/class_board.cpp).
This commit is contained in:
Maciej Suminski 2014-01-29 10:17:14 +01:00
parent 83f7c7e35e
commit bec24b6c7f
3 changed files with 38 additions and 14 deletions

View File

@ -41,6 +41,8 @@
#include <class_zone.h> #include <class_zone.h>
#include <class_edge_mod.h> #include <class_edge_mod.h>
#include <ratsnest_data.h>
#include <tools/selection_tool.h> #include <tools/selection_tool.h>
#include <tool/tool_manager.h> #include <tool/tool_manager.h>
@ -453,13 +455,14 @@ void PCB_EDIT_FRAME::PutDataInPreviousState( PICKED_ITEMS_LIST* aList, bool aRed
bool not_found = false; bool not_found = false;
bool reBuild_ratsnest = false; bool reBuild_ratsnest = false;
KIGFX::VIEW* view = GetGalCanvas()->GetView(); KIGFX::VIEW* view = GetGalCanvas()->GetView();
RN_DATA* ratsnest = GetBoard()->GetRatsnest();
// Undo in the reverse order of list creation: (this can allow stacked changes // Undo in the reverse order of list creation: (this can allow stacked changes
// like the same item can be changes and deleted in the same complex command // like the same item can be changes and deleted in the same complex command
bool build_item_list = true; // if true the list of existing items must be rebuilt bool build_item_list = true; // if true the list of existing items must be rebuilt
for( int ii = aList->GetCount()-1; ii >= 0 ; ii-- ) for( int ii = aList->GetCount() - 1; ii >= 0 ; ii-- )
{ {
item = (BOARD_ITEM*) aList->GetPickedItem( ii ); item = (BOARD_ITEM*) aList->GetPickedItem( ii );
wxASSERT( item ); wxASSERT( item );
@ -519,8 +522,8 @@ void PCB_EDIT_FRAME::PutDataInPreviousState( PICKED_ITEMS_LIST* aList, bool aRed
if( item->Type() == PCB_MODULE_T ) if( item->Type() == PCB_MODULE_T )
{ {
MODULE* oldModule = static_cast<MODULE*>( item ); MODULE* oldModule = static_cast<MODULE*>( item );
oldModule->RunOnChildren( std::bind1st( std::mem_fun( &KIGFX::VIEW::Remove ), oldModule->RunOnChildren( std::bind1st( std::mem_fun( &KIGFX::VIEW::Remove ), view ) );
view ) ); oldModule->RunOnChildren( std::bind1st( std::mem_fun( &RN_DATA::Remove ), ratsnest ) );
} }
item->SwapData( image ); item->SwapData( image );
@ -530,8 +533,8 @@ void PCB_EDIT_FRAME::PutDataInPreviousState( PICKED_ITEMS_LIST* aList, bool aRed
if( item->Type() == PCB_MODULE_T ) if( item->Type() == PCB_MODULE_T )
{ {
MODULE* newModule = static_cast<MODULE*>( item ); MODULE* newModule = static_cast<MODULE*>( item );
newModule->RunOnChildren( std::bind1st( std::mem_fun( &KIGFX::VIEW::Add ), newModule->RunOnChildren( std::bind1st( std::mem_fun( &KIGFX::VIEW::Add ), view ) );
view ) ); newModule->RunOnChildren( std::bind1st( std::mem_fun( &RN_DATA::Add ), ratsnest ) );
} }
item->ViewUpdate( KIGFX::VIEW_ITEM::LAYERS ); item->ViewUpdate( KIGFX::VIEW_ITEM::LAYERS );
@ -577,11 +580,13 @@ void PCB_EDIT_FRAME::PutDataInPreviousState( PICKED_ITEMS_LIST* aList, bool aRed
case UR_ROTATED: case UR_ROTATED:
item->Rotate( aList->m_TransformPoint, item->Rotate( aList->m_TransformPoint,
aRedoCommand ? m_rotationAngle : -m_rotationAngle ); aRedoCommand ? m_rotationAngle : -m_rotationAngle );
item->ViewUpdate( KIGFX::VIEW_ITEM::GEOMETRY );
break; break;
case UR_ROTATED_CLOCKWISE: case UR_ROTATED_CLOCKWISE:
item->Rotate( aList->m_TransformPoint, item->Rotate( aList->m_TransformPoint,
aRedoCommand ? -m_rotationAngle : m_rotationAngle ); aRedoCommand ? -m_rotationAngle : m_rotationAngle );
item->ViewUpdate( KIGFX::VIEW_ITEM::GEOMETRY );
break; break;
case UR_FLIPPED: case UR_FLIPPED:
@ -598,6 +603,8 @@ void PCB_EDIT_FRAME::PutDataInPreviousState( PICKED_ITEMS_LIST* aList, bool aRed
} }
break; break;
} }
ratsnest->Update( item );
} }
if( not_found ) if( not_found )
@ -605,7 +612,12 @@ void PCB_EDIT_FRAME::PutDataInPreviousState( PICKED_ITEMS_LIST* aList, bool aRed
// Rebuild pointers and ratsnest that can be changed. // Rebuild pointers and ratsnest that can be changed.
if( reBuild_ratsnest && aRebuildRatsnet ) if( reBuild_ratsnest && aRebuildRatsnet )
{
if( IsGalCanvasActive() )
ratsnest->Recalculate();
else
Compile_Ratsnest( NULL, true ); Compile_Ratsnest( NULL, true );
}
} }

View File

@ -895,7 +895,6 @@ BOARD_ITEM* BOARD::Remove( BOARD_ITEM* aBoardItem )
break; break;
case PCB_TRACE_T: case PCB_TRACE_T:
case PCB_VIA_T:
{ {
TRACK* track = static_cast<TRACK*>( aBoardItem ); TRACK* track = static_cast<TRACK*>( aBoardItem );
m_Track.Remove( track ); m_Track.Remove( track );
@ -903,6 +902,14 @@ BOARD_ITEM* BOARD::Remove( BOARD_ITEM* aBoardItem )
} }
break; break;
case PCB_VIA_T:
{
SEGVIA* via = static_cast<SEGVIA*>( aBoardItem );
m_Track.Remove( via );
m_ratsnest->GetNets()[via->GetNet()].RemoveItem( via );
}
break;
case PCB_ZONE_T: case PCB_ZONE_T:
m_Zone.Remove( (SEGZONE*) aBoardItem ); m_Zone.Remove( (SEGZONE*) aBoardItem );
break; break;

View File

@ -119,7 +119,7 @@ int EDIT_TOOL::Main( TOOL_EVENT& aEvent )
{ {
Remove( aEvent ); Remove( aEvent );
break; break; // exit the loop, as there is no further processing for removed items
} }
} }
@ -207,6 +207,7 @@ int EDIT_TOOL::Properties( TOOL_EVENT& aEvent )
setTransitions(); setTransitions();
updateRatsnest( true ); updateRatsnest( true );
getModel<BOARD>( PCB_T )->GetRatsnest()->Recalculate();
return 0; return 0;
} }
@ -233,12 +234,14 @@ int EDIT_TOOL::Rotate( TOOL_EVENT& aEvent )
item->ViewUpdate( KIGFX::VIEW_ITEM::GEOMETRY ); item->ViewUpdate( KIGFX::VIEW_ITEM::GEOMETRY );
} }
if( m_dragging )
selection.group->ViewUpdate( KIGFX::VIEW_ITEM::GEOMETRY );
setTransitions(); setTransitions();
updateRatsnest( true ); updateRatsnest( true );
if( m_dragging )
selection.group->ViewUpdate( KIGFX::VIEW_ITEM::GEOMETRY );
else
getModel<BOARD>( PCB_T )->GetRatsnest()->Recalculate();
return 0; return 0;
} }
@ -264,12 +267,14 @@ int EDIT_TOOL::Flip( TOOL_EVENT& aEvent )
item->ViewUpdate( KIGFX::VIEW_ITEM::LAYERS ); item->ViewUpdate( KIGFX::VIEW_ITEM::LAYERS );
} }
if( m_dragging )
selection.group->ViewUpdate( KIGFX::VIEW_ITEM::GEOMETRY );
setTransitions(); setTransitions();
updateRatsnest( true ); updateRatsnest( true );
if( m_dragging )
selection.group->ViewUpdate( KIGFX::VIEW_ITEM::GEOMETRY );
else
getModel<BOARD>( PCB_T )->GetRatsnest()->Recalculate();
return 0; return 0;
} }