X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=vv%2FvvThreadedFilter.cxx;h=3504b92ba7e3049d53d67168a3b57cd33513ddf5;hb=5a7da4aedae5c204bc55c187717193e5950f9a44;hp=839c4e0b125f0068a5a4808c57e0dc958be71e82;hpb=ee318a6de9c515e567f56b84d3f3789ef0881810;p=clitk.git diff --git a/vv/vvThreadedFilter.cxx b/vv/vvThreadedFilter.cxx index 839c4e0..3504b92 100644 --- a/vv/vvThreadedFilter.cxx +++ b/vv/vvThreadedFilter.cxx @@ -3,7 +3,7 @@ Authors belong to: - University of LYON http://www.universite-lyon.fr/ - - Léon Bérard cancer center http://oncora1.lyon.fnclcc.fr + - Léon Bérard cancer center http://www.centreleonberard.fr - CREATIS CNRS laboratory http://www.creatis.insa-lyon.fr This software is distributed WITHOUT ANY WARRANTY; without even @@ -14,7 +14,7 @@ - BSD See included LICENSE.txt file - CeCILL-B http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html - ======================================================================-====*/ + ===========================================================================**/ // vv #include "vvThreadedFilter.h" @@ -27,7 +27,6 @@ vvThreadedFilter::vvThreadedFilter(): QThread() { - DD("vvThreadedFilter"); m_Filter = NULL; } //------------------------------------------------------------------------------ @@ -43,7 +42,6 @@ vvThreadedFilter::~vvThreadedFilter() //------------------------------------------------------------------------------ void vvThreadedFilter::SetFilter(clitk::ImageToImageGenericFilterBase * f) { - DD("SetFilter"); m_Filter = f; } //------------------------------------------------------------------------------ @@ -56,13 +54,14 @@ void vvThreadedFilter::Update() // Show a progress bar while computing vvProgressDialog progress("Computing ...",100); + progress.SetCancelButtonEnabled(true); connect(&progress, SIGNAL(rejected()), this, SLOT(reject())); this->start(); this->setTerminationEnabled(true); std::string temp; while (this->isRunning()) { - DD(this->isRunning()); - m_FilterBase = m_Filter->GetFilterBase(); // get filterbase only after Update + // try { + m_FilterBase = m_Filter->GetFilterBase(); // get filterbase is only set after Update if (m_FilterBase != NULL) { progress.SetProgress(m_FilterBase->GetCurrentStepNumber(), m_FilterBase->GetNumberOfSteps()); @@ -71,10 +70,9 @@ void vvThreadedFilter::Update() } temp = m_FilterBase->GetCurrentStepName(); } - this->wait(200); // in milisecond + this->wait(200); // in miliseconds qApp->processEvents(); } - DD("after loop"); } //------------------------------------------------------------------------------ @@ -83,7 +81,16 @@ void vvThreadedFilter::Update() void vvThreadedFilter::run() { assert(m_Filter != NULL); - m_Filter->Update(); + try { + m_Filter->Update(); + } + catch(clitk::ExceptionObject e) { + DD("vvThreadedFilter : exceptionobject handeled"); + DD(e.what()); + QApplication::restoreOverrideCursor(); + QMessageBox::information(new QWidget, tr("Error"), e.what()); + } + DD("end RUN"); } //------------------------------------------------------------------------------ @@ -91,12 +98,11 @@ void vvThreadedFilter::run() //------------------------------------------------------------------------------ void vvThreadedFilter::reject() { - DD("vvThreadedFilter::reject"); - this->quit(); - // if (m_Filter != NULL) { -// m_Filter->MustStop(); -// } - DD("after terminate"); + // First, say the filter it must stop as soon as possible. We then + // wait that an exception occur in the main thread. + if (m_FilterBase != NULL) { + m_FilterBase->Cancel(); + } } //------------------------------------------------------------------------------