From a0518879716860274b37a68a8d6a0a71b80356fe Mon Sep 17 00:00:00 2001 From: Maciej Suminski Date: Wed, 29 Jan 2014 10:17:14 +0100 Subject: [PATCH] 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). --- pcbnew/board_undo_redo.cpp | 24 ++++++++++++++++++------ pcbnew/class_board.cpp | 9 ++++++++- pcbnew/tools/edit_tool.cpp | 19 ++++++++++++------- 3 files changed, 38 insertions(+), 14 deletions(-) diff --git a/pcbnew/board_undo_redo.cpp b/pcbnew/board_undo_redo.cpp index a0bb32575c..484b76fa05 100644 --- a/pcbnew/board_undo_redo.cpp +++ b/pcbnew/board_undo_redo.cpp @@ -41,6 +41,8 @@ #include #include +#include + #include #include @@ -453,13 +455,14 @@ void PCB_EDIT_FRAME::PutDataInPreviousState( PICKED_ITEMS_LIST* aList, bool aRed bool not_found = false; bool reBuild_ratsnest = false; KIGFX::VIEW* view = GetGalCanvas()->GetView(); + RN_DATA* ratsnest = GetBoard()->GetRatsnest(); // 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 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 ); wxASSERT( item ); @@ -519,8 +522,8 @@ void PCB_EDIT_FRAME::PutDataInPreviousState( PICKED_ITEMS_LIST* aList, bool aRed if( item->Type() == PCB_MODULE_T ) { MODULE* oldModule = static_cast( item ); - oldModule->RunOnChildren( std::bind1st( std::mem_fun( &KIGFX::VIEW::Remove ), - view ) ); + oldModule->RunOnChildren( std::bind1st( std::mem_fun( &KIGFX::VIEW::Remove ), view ) ); + oldModule->RunOnChildren( std::bind1st( std::mem_fun( &RN_DATA::Remove ), ratsnest ) ); } item->SwapData( image ); @@ -530,8 +533,8 @@ void PCB_EDIT_FRAME::PutDataInPreviousState( PICKED_ITEMS_LIST* aList, bool aRed if( item->Type() == PCB_MODULE_T ) { MODULE* newModule = static_cast( item ); - newModule->RunOnChildren( std::bind1st( std::mem_fun( &KIGFX::VIEW::Add ), - view ) ); + newModule->RunOnChildren( std::bind1st( std::mem_fun( &KIGFX::VIEW::Add ), view ) ); + newModule->RunOnChildren( std::bind1st( std::mem_fun( &RN_DATA::Add ), ratsnest ) ); } item->ViewUpdate( KIGFX::VIEW_ITEM::LAYERS ); @@ -577,11 +580,13 @@ void PCB_EDIT_FRAME::PutDataInPreviousState( PICKED_ITEMS_LIST* aList, bool aRed case UR_ROTATED: item->Rotate( aList->m_TransformPoint, aRedoCommand ? m_rotationAngle : -m_rotationAngle ); + item->ViewUpdate( KIGFX::VIEW_ITEM::GEOMETRY ); break; case UR_ROTATED_CLOCKWISE: item->Rotate( aList->m_TransformPoint, aRedoCommand ? -m_rotationAngle : m_rotationAngle ); + item->ViewUpdate( KIGFX::VIEW_ITEM::GEOMETRY ); break; case UR_FLIPPED: @@ -598,6 +603,8 @@ void PCB_EDIT_FRAME::PutDataInPreviousState( PICKED_ITEMS_LIST* aList, bool aRed } break; } + + ratsnest->Update( item ); } 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. if( reBuild_ratsnest && aRebuildRatsnet ) - Compile_Ratsnest( NULL, true ); + { + if( IsGalCanvasActive() ) + ratsnest->Recalculate(); + else + Compile_Ratsnest( NULL, true ); + } } diff --git a/pcbnew/class_board.cpp b/pcbnew/class_board.cpp index 446f1f5bf3..5c32b53881 100644 --- a/pcbnew/class_board.cpp +++ b/pcbnew/class_board.cpp @@ -895,7 +895,6 @@ BOARD_ITEM* BOARD::Remove( BOARD_ITEM* aBoardItem ) break; case PCB_TRACE_T: - case PCB_VIA_T: { TRACK* track = static_cast( aBoardItem ); m_Track.Remove( track ); @@ -903,6 +902,14 @@ BOARD_ITEM* BOARD::Remove( BOARD_ITEM* aBoardItem ) } break; + case PCB_VIA_T: + { + SEGVIA* via = static_cast( aBoardItem ); + m_Track.Remove( via ); + m_ratsnest->GetNets()[via->GetNet()].RemoveItem( via ); + } + break; + case PCB_ZONE_T: m_Zone.Remove( (SEGZONE*) aBoardItem ); break; diff --git a/pcbnew/tools/edit_tool.cpp b/pcbnew/tools/edit_tool.cpp index 706134d1bc..451164bf23 100644 --- a/pcbnew/tools/edit_tool.cpp +++ b/pcbnew/tools/edit_tool.cpp @@ -119,7 +119,7 @@ int EDIT_TOOL::Main( TOOL_EVENT& 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(); updateRatsnest( true ); + getModel( PCB_T )->GetRatsnest()->Recalculate(); return 0; } @@ -233,12 +234,14 @@ int EDIT_TOOL::Rotate( TOOL_EVENT& aEvent ) item->ViewUpdate( KIGFX::VIEW_ITEM::GEOMETRY ); } - if( m_dragging ) - selection.group->ViewUpdate( KIGFX::VIEW_ITEM::GEOMETRY ); - setTransitions(); updateRatsnest( true ); + if( m_dragging ) + selection.group->ViewUpdate( KIGFX::VIEW_ITEM::GEOMETRY ); + else + getModel( PCB_T )->GetRatsnest()->Recalculate(); + return 0; } @@ -264,12 +267,14 @@ int EDIT_TOOL::Flip( TOOL_EVENT& aEvent ) item->ViewUpdate( KIGFX::VIEW_ITEM::LAYERS ); } - if( m_dragging ) - selection.group->ViewUpdate( KIGFX::VIEW_ITEM::GEOMETRY ); - setTransitions(); updateRatsnest( true ); + if( m_dragging ) + selection.group->ViewUpdate( KIGFX::VIEW_ITEM::GEOMETRY ); + else + getModel( PCB_T )->GetRatsnest()->Recalculate(); + return 0; }