← Back to team overview

kicad-developers team mailing list archive

[PATCH] - PCBNEW - undo for automove commands

 

Hello,

As a follow-up to my post of yesterday, I have added undo functionality
to PCBNEW when the automove commands are used. The same strategy has been
used:

A PICKED_ITEMS_LIST is populated through an ITEM_PICKER with only the items
that are going to be moved by the automover.

The list is then given to SaveCopyInUndoList to be added to the undo list.

-- 
Guillaume Simard
=== modified file 'pcbnew/automove.cpp'
--- pcbnew/automove.cpp	2011-12-05 06:15:33 +0000
+++ pcbnew/automove.cpp	2011-12-12 04:32:25 +0000
@@ -18,6 +18,7 @@
 #include "class_board.h"
 #include "class_module.h"
 
+extern BOARD_ITEM* DuplicateStruct( BOARD_ITEM* aItem );
 
 typedef enum {
     FIXE_MODULE,
@@ -184,6 +185,11 @@
     int      pas_grille = (int) GetScreen()->GetGridSize().x;
     double   surface;
 
+    // Undo: init list
+    PICKED_ITEMS_LIST  newList;
+    newList.m_Status = UR_CHANGED;
+    ITEM_PICKER        picker( NULL, UR_CHANGED );
+
     if( GetBoard()->m_Modules == NULL )
     {
         DisplayError( this, _( "No modules found!" ) );
@@ -264,6 +270,10 @@
                 continue;
         }
 
+        // Undo: add copy of old Module to undo
+        picker.m_Link           = DuplicateStruct( Module );
+        picker.m_PickedItemType = Module->Type();
+
         if( current.x > (Xsize_allowed + start.x) )
         {
             current.x  = start.x;
@@ -278,9 +288,17 @@
 
         PlaceModule( Module, NULL, true );
 
+        // Undo: add new Module to undo
+        picker.m_PickedItem = Module;
+        newList.PushItem( picker );
+
         current.x += Module->m_BoundaryBox.GetWidth() + pas_grille;
     }
 
+    // Undo: commit
+    if( newList.GetCount() )
+        SaveCopyInUndoList( newList, UR_CHANGED );
+
     DrawPanel->Refresh();
 }