]> Creatis software - cpPlugins.git/commitdiff
update: undo/redo for image to image filters
authorjose guzman <jose@gmail.com>
Fri, 9 Oct 2015 14:11:48 +0000 (16:11 +0200)
committerjose guzman <jose@gmail.com>
Fri, 9 Oct 2015 14:11:48 +0000 (16:11 +0200)
appli/ImageMPR/ImageMPR.cxx
appli/ImageMPR/ImageMPR.h

index 0823bb2fca37a7d3aef576b2d42b0c060e63855b..402baff2c1b1c4a074f6da2af00f34b50fe3692b 100644 (file)
@@ -29,7 +29,8 @@ ImageMPR::ImageMPR( QWidget* parent )
     m_MeshWriterClass( "" ),
     m_MeshCutterClass( "" ),
     m_Image( NULL ),
-       m_state(1)
+       m_state(0),
+       m_max_state(0)
 {
   this->m_UI->setupUi( this );
 
@@ -284,7 +285,8 @@ _triggered_actionOpenInputImage( )
       this->m_MPRObjects->ResetCameras( );
       this->m_MPRObjects->RenderAll( );
 
-         MementoState(m_state, this->m_Image);   
+         MementoState(m_state, this->m_Image);  
+         this->m_state++;
     }
     else
       QMessageBox::critical(
@@ -432,8 +434,14 @@ _triggered_actionImageToImage( )
         this->m_Image->GetVTK< vtkImageData >( )
 
                );
-       m_state++;
-       MementoState(m_state, this->m_Image);
+       
+       
+       MementoState(this->m_state, this->m_Image);
+       this->m_state++;
+       if (this->m_state > this->m_max_state)
+       {
+               this->m_max_state = this->m_state;
+       }
   }
   else
     QMessageBox::critical(
@@ -507,9 +515,9 @@ _triggered_actionUndo()
                        );
        } else
        {
-               QMessageBox::critical(
+               QMessageBox::warning(
                        this,
-                       tr("Error message"),
+                       tr("message"),
                        tr("No history to undo")
                        );
        }
@@ -521,21 +529,21 @@ void ImageMPR::
 _triggered_actionRedo()
 {
        MementoState memento = MementoState();
-       try
-       {
-               this->m_state++;
-               this->m_MPRObjects->SetImage(
-                       memento.getMemento(this->m_state)->GetOutput()
-                       );
-       }
-       catch (int err)
-       {
-               QMessageBox::critical(
-                       this,
-                       tr("Error message"),
-                       tr("No history to redo")
-                       );
-       }
+               if (this->m_state + 1 <= m_max_state)
+               {
+                       this->m_state++;
+                       this->m_MPRObjects->SetImage(
+                               memento.getMemento(this->m_state)->GetOutput()
+                               );
+               } else
+               {
+                       QMessageBox::warning(
+                               this,
+                               tr("message"),
+                               tr("No history to redo")
+                               );
+               }
+       
 }
        
 
index e690a51640dc40a634a9c99fe7c8034b7492e0c8..c864bfe471dc04c05d7cc2bfb2879f00f31895cb 100644 (file)
@@ -176,6 +176,7 @@ private:
 
   // Memento stuff
   unsigned long m_state;
+  unsigned long m_max_state;
 
   /* TODO
      vtkSmartPointer< vtkOrientationMarkerWidget > m_3DOrientationWidget;