diff --git a/pcbnew/router/pns_router.cpp b/pcbnew/router/pns_router.cpp index 991dd71e84..3046c13f6e 100644 --- a/pcbnew/router/pns_router.cpp +++ b/pcbnew/router/pns_router.cpp @@ -241,7 +241,6 @@ void PNS_ROUTER::SyncWorld() ClearWorld(); - m_clearanceFunc = new PCBNEW_CLEARANCE_FUNC( m_board ); m_world = new PNS_NODE(); m_world->SetClearanceFunctor( m_clearanceFunc ); @@ -584,8 +583,9 @@ void PNS_ROUTER::commitRouting( PNS_NODE* aNode ) if( parent ) { - m_view->Remove( parent ); + m_undoBuffer.PushItem( ITEM_PICKER( parent, UR_DELETED ) ); m_board->Remove( parent ); + m_view->Remove( parent ); } } @@ -632,6 +632,7 @@ void PNS_ROUTER::commitRouting( PNS_NODE* aNode ) m_view->Add( newBI ); m_board->Add( newBI ); m_board->GetRatsnest()->Update( newBI ); + m_undoBuffer.PushItem( ITEM_PICKER( newBI, UR_NEW ) ); newBI->ViewUpdate( KIGFX::VIEW_ITEM::GEOMETRY ); } } diff --git a/pcbnew/router/pns_router.h b/pcbnew/router/pns_router.h index 0bb882fa25..3ba7be0125 100644 --- a/pcbnew/router/pns_router.h +++ b/pcbnew/router/pns_router.h @@ -27,6 +27,7 @@ #include #include +#include #include "pns_routing_settings.h" #include "pns_item.h" @@ -137,6 +138,18 @@ public: const PNS_ITEMSET QueryHoverItems( const VECTOR2I& aP ); const VECTOR2I SnapToItem( PNS_ITEM* item, VECTOR2I aP, bool& aSplitsSegment ); + /** + * Returns the last changes introduced by the router. After calling the method the list of + * changes is cleared, so only the latest changes are stored. + */ + PICKED_ITEMS_LIST GetLastChanges() + { + PICKED_ITEMS_LIST copy = m_undoBuffer; + m_undoBuffer.ClearItemsList(); // TODO and delete? + + return copy; + } + private: void clearViewFlags(); @@ -188,6 +201,9 @@ private: PNS_CLEARANCE_FUNC* m_clearanceFunc; boost::unordered_set m_hiddenItems; + + ///> Stores list of modified items in the current operation + PICKED_ITEMS_LIST m_undoBuffer; }; #endif diff --git a/pcbnew/router/router_tool.cpp b/pcbnew/router/router_tool.cpp index b301901048..ed3eb18092 100644 --- a/pcbnew/router/router_tool.cpp +++ b/pcbnew/router/router_tool.cpp @@ -322,6 +322,11 @@ void ROUTER_TOOL::startRouting() updateEndItem( *evt ); m_router->Move( m_endSnapPoint, m_endItem ); } + else if( evt->Action() == TA_UNDO_REDO ) + { + std::cout << "syncing the world while routing, I am going to craaaaaaaaaaaash!" << std::endl; + m_router->SyncWorld(); + } else if( evt->IsClick( BUT_LEFT ) ) { updateEndItem( *evt ); @@ -371,6 +376,10 @@ void ROUTER_TOOL::startRouting() m_router->StopRouting(); + // Save the recent changes in the undo buffer + getEditFrame()->SaveCopyInUndoList( m_router->GetLastChanges(), UR_UNSPECIFIED ); + getEditFrame()->OnModify(); + ctls->SetAutoPan( false ); ctls->ForceCursorPosition( false ); highlightNet( false ); @@ -392,6 +401,8 @@ int ROUTER_TOOL::Main( TOOL_EVENT& aEvent ) { if( evt->IsCancel() ) break; // Finish + else if( evt->Action() == TA_UNDO_REDO ) + m_router->SyncWorld(); else if( evt->IsMotion() ) updateStartItem( *evt ); else if( evt->IsClick( BUT_LEFT ) )