Hi all

Hugin keeps track of all operations done on the panorama.  Great for undo.  

It also stores the toggling of an image visibility status.  Personally I find 
this unnecessary:  when I move forth and back over the history of the project 
I am interested in "before and after", not "visible and invisible".  I end up 
clicking multiple times to get through an undo/redo cycle if in between I 
toggled visibility (e.g. to influence the set of CPs used by the optimizer).

In an attempt to work around the issue by simulating the multiple clicks, I 
produced the attached patch.  It's not perfect yet, and has segfaulted on me 
on "redo".  It's fairly simple.  I look forward for critique and feedback of 
the patch and I hope to fix the segfault soon.

Yuv
diff -r b9b37f9f0e0d src/hugin1/PT/PanoCommand.h
--- a/src/hugin1/PT/PanoCommand.h	Sun Sep 19 23:16:30 2010 +0200
+++ b/src/hugin1/PT/PanoCommand.h	Tue Sep 21 17:17:03 2010 -0400
@@ -503,7 +503,7 @@
     //=========================================================================
 
 
-    /** center panorama horizontically */
+    /** straighten panorama horizontically */
     class StraightenPanoCmd : public PanoCommand
     {
     public:
@@ -521,7 +521,7 @@
         
         virtual std::string getName() const
             {
-                return "center panorama";
+                return "straighten panorama";
             }
 
     private:
@@ -718,7 +718,7 @@
         
         virtual std::string getName() const
             {
-                return "change lens";
+                return "change active images";
             }
 
     private:
@@ -820,8 +820,7 @@
     //=========================================================================
     //=========================================================================
 
-    /** set image options for a set of images.
-     *  just sets the @p options given for all images in @p imgs
+    /** update source image
      */
     class UpdateSrcImageCmd : public PanoCommand
     {
@@ -840,7 +839,7 @@
             
         virtual std::string getName() const
             {
-                return "set image options";
+                return "update source image";
             }
     
     private:
@@ -851,8 +850,7 @@
     //=========================================================================
     //=========================================================================
 
-    /** set image options for a set of images.
-     *  just sets the @p options given for all images in @p imgs
+    /** update source images
      */
     class UpdateSrcImagesCmd : public PanoCommand
     {
@@ -877,7 +875,7 @@
             
         virtual std::string getName() const
             {
-                return "set multiple image options";
+                return "update source images";
             }
     
     private:
@@ -889,8 +887,7 @@
     //=========================================================================
     //=========================================================================
 
-    /** set image options for a set of images.
-     *  just sets the @p options given for all images in @p imgs
+    /** update image options
      */
     class UpdateImageOptionsCmd : public PanoCommand
     {
@@ -946,7 +943,7 @@
         
         virtual std::string getName() const
             {
-                return "unnamed command";
+                return "set panorama options";
             }
 
     private:
@@ -1034,7 +1031,7 @@
             
         virtual std::string getName() const
             {
-                return "set image options";
+                return "set flatfield correction parameters for all images of a lens";
             }
     
     private:
@@ -1069,7 +1066,7 @@
         
         virtual std::string getName() const
             {
-                return "set image options";
+                return "rotate panorama";
             }
 
     private:
diff -r b9b37f9f0e0d src/hugin1/hugin/CommandHistory.cpp
--- a/src/hugin1/hugin/CommandHistory.cpp	Sun Sep 19 23:16:30 2010 +0200
+++ b/src/hugin1/hugin/CommandHistory.cpp	Tue Sep 21 17:17:03 2010 -0400
@@ -24,12 +24,21 @@
  *
  */
 
+// for debugging
+#include <iostream>
+#include <stdio.h>
+
 // standard include
 #include <config.h>
 #include "panoinc_WX.h"
 #include "panoinc.h"
 #include "hugin/CommandHistory.h"
 
+// for sophisticated undo
+#include "hugin/huginApp.h"
+//#include <panodata/PanoramaData.h>
+
+
 CommandHistory::CommandHistory()
     : nextCmd(0)
 {
@@ -83,25 +92,58 @@
 
 
 
-void CommandHistory::undo()
+void CommandHistory::undo(PT::Panorama & pano)
 {
     if (nextCmd > 0) {
         // undo the current command
         DEBUG_DEBUG("undo: " << commands[nextCmd-1]->getName());
+        // get the currently active images
+        UIntSet activeImgs = pano.getActiveImages();
         commands[nextCmd-1]->undo();
         nextCmd--;
+        while ( (commands[nextCmd]->getName()=="change active images") && (nextCmd > 0) ) {
+            commands[nextCmd-1]->undo();
+            nextCmd--;
+        }
+        // restore the currently active images
+        UIntSet::iterator it;
+        for (unsigned int i = 0; i < pano.getNrOfImages(); i++) {
+            if (set_contains(activeImgs, i)) {
+                pano.activateImage(i, true);
+            } else {
+                pano.activateImage(i, false);
+            }
+         }
+         pano.changeFinished();
     } else {
         wxLogError(_("no command in undo history"));
     }
+//    std::cerr << "UNDO: " << commands[nextCmd]->getName();
 }
 
 
-void CommandHistory::redo()
+void CommandHistory::redo(PT::Panorama & pano)
 {
     if (nextCmd < commands.size()) {
         DEBUG_DEBUG("redo: " << commands[nextCmd]->getName());
+        // get the currently active images
+        UIntSet activeImgs = pano.getActiveImages();
         commands[nextCmd]->execute();
         nextCmd++;
+        while ( (commands[nextCmd]->getName()=="change active images") && (nextCmd < commands.size()) ) {
+            commands[nextCmd]->execute();
+            nextCmd++;
+        }
+        // restore the currently active images
+        UIntSet::iterator it;
+        for (unsigned int i = 0; i < pano.getNrOfImages(); i++) {
+            if (set_contains(activeImgs, i)) {
+                pano.activateImage(i, true);
+            } else {
+                pano.activateImage(i, false);
+            }
+         }
+         pano.changeFinished();
     } else {
         wxLogError(_("no command in redo history"));
     }
diff -r b9b37f9f0e0d src/hugin1/hugin/CommandHistory.h
--- a/src/hugin1/hugin/CommandHistory.h	Sun Sep 19 23:16:30 2010 +0200
+++ b/src/hugin1/hugin/CommandHistory.h	Tue Sep 21 17:17:03 2010 -0400
@@ -68,11 +68,11 @@
     /**
      * Undoes the last action.
      */
-    virtual void undo();
+    virtual void undo(PT::Panorama & pano);
     /**
      * Redoes the last undone action.
      */
-    virtual void redo();
+    virtual void redo(PT::Panorama & pano);
 
 private:
     // our commands
diff -r b9b37f9f0e0d src/hugin1/hugin/MainFrame.cpp
--- a/src/hugin1/hugin/MainFrame.cpp	Sun Sep 19 23:16:30 2010 +0200
+++ b/src/hugin1/hugin/MainFrame.cpp	Tue Sep 21 17:17:03 2010 -0400
@@ -1563,13 +1563,13 @@
 void MainFrame::OnUndo(wxCommandEvent & e)
 {
     DEBUG_TRACE("OnUndo");
-    GlobalCmdHist::getInstance().undo();
+    GlobalCmdHist::getInstance().undo(pano);
 }
 
 void MainFrame::OnRedo(wxCommandEvent & e)
 {
     DEBUG_TRACE("OnRedo");
-    GlobalCmdHist::getInstance().redo();
+    GlobalCmdHist::getInstance().redo(pano);
 }
 
 

Attachment: signature.asc
Description: This is a digitally signed message part.

Reply via email to