From 48363731d62d46ffad8ca257326cc147a92ab681 Mon Sep 17 00:00:00 2001 From: jose guzman Date: Fri, 9 Oct 2015 16:11:48 +0200 Subject: [PATCH] update: undo/redo for image to image filters --- appli/ImageMPR/ImageMPR.cxx | 50 +++++++++++++++++++++---------------- appli/ImageMPR/ImageMPR.h | 1 + 2 files changed, 30 insertions(+), 21 deletions(-) diff --git a/appli/ImageMPR/ImageMPR.cxx b/appli/ImageMPR/ImageMPR.cxx index 0823bb2..402baff 100644 --- a/appli/ImageMPR/ImageMPR.cxx +++ b/appli/ImageMPR/ImageMPR.cxx @@ -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") + ); + } + } diff --git a/appli/ImageMPR/ImageMPR.h b/appli/ImageMPR/ImageMPR.h index e690a51..c864bfe 100644 --- a/appli/ImageMPR/ImageMPR.h +++ b/appli/ImageMPR/ImageMPR.h @@ -176,6 +176,7 @@ private: // Memento stuff unsigned long m_state; + unsigned long m_max_state; /* TODO vtkSmartPointer< vtkOrientationMarkerWidget > m_3DOrientationWidget; -- 2.45.1