Commit 6f7b8942 authored by Guillaume Pasero's avatar Guillaume Pasero

Merge branch 'stop_appli_button' into 'develop'

Stop button for graphic applications

See merge request !34
parents 1c6bb187 83c31a67
......@@ -51,6 +51,9 @@ namespace Utils
/** Function that prints nothing (useful to disable libsvm logs)*/
void OTBCommon_EXPORT PrintNothing(const char *s);
extern OTBCommon_EXPORT bool const TrueConstant;
extern OTBCommon_EXPORT bool const FalseConstant;
}
} // namespace otb
......
......@@ -41,6 +41,10 @@ void PrintNothing(const char * /* s */)
{
}
bool const TrueConstant = true;
bool const FalseConstant = false;
}
}
......@@ -24,6 +24,7 @@
#include "itkMacro.h"
#include "itkImageToImageFilter.h"
#include "otbStreamingManager.h"
#include "itkFastMutexLock.h"
namespace otb
{
......@@ -142,6 +143,11 @@ public:
* This filter does not produce an output */
void Update() override;
/** This override doesn't return a const ref on the actual boolean */
const bool & GetAbortGenerateData() const override;
void SetAbortGenerateData(const bool val) override;
protected:
StreamingImageVirtualWriter();
......@@ -186,6 +192,9 @@ private:
bool m_IsObserving;
unsigned long m_ObserverID;
/** Lock to ensure thread-safety (added for the AbortGenerateData flag) */
itk::SimpleFastMutexLock m_Lock;
};
} // end namespace otb
......
......@@ -32,6 +32,7 @@
#include "otbTileDimensionTiledStreamingManager.h"
#include "otbRAMDrivenTiledStreamingManager.h"
#include "otbRAMDrivenAdaptativeStreamingManager.h"
#include "otbUtils.h"
namespace otb
{
......@@ -258,6 +259,13 @@ StreamingImageVirtualWriter<TInputImage>
{
this->UpdateProgress(1.0);
}
else
{
itk::ProcessAborted e(__FILE__, __LINE__);
e.SetLocation(ITK_LOCATION);
e.SetDescription("Image streaming has been aborted");
throw e;
}
// Notify end event observers
this->InvokeEvent(itk::EndEvent());
......@@ -285,6 +293,27 @@ StreamingImageVirtualWriter<TInputImage>
this->ReleaseInputs();
}
template <class TInputImage>
const bool &
StreamingImageVirtualWriter<TInputImage>
::GetAbortGenerateData() const
{
m_Lock.Lock();
bool ret = Superclass::GetAbortGenerateData();
m_Lock.Unlock();
if (ret) return otb::Utils::TrueConstant;
return otb::Utils::FalseConstant;
}
template <class TInputImage>
void
StreamingImageVirtualWriter<TInputImage>
::SetAbortGenerateData(bool val)
{
m_Lock.Lock();
Superclass::SetAbortGenerateData(val);
m_Lock.Unlock();
}
} // end namespace otb
......
......@@ -25,6 +25,7 @@
#include "itkProcessObject.h"
#include "otbStreamingManager.h"
#include "otbExtendedFilenameToWriterOptions.h"
#include "itkFastMutexLock.h"
namespace otb
{
......@@ -199,6 +200,11 @@ public:
itkGetObjectMacro(ImageIO, otb::ImageIOBase);
itkGetConstObjectMacro(ImageIO, otb::ImageIOBase);
/** This override doesn't return a const ref on the actual boolean */
const bool & GetAbortGenerateData() const override;
void SetAbortGenerateData(const bool val) override;
protected:
ImageFileWriter();
~ImageFileWriter() override;
......@@ -270,6 +276,9 @@ private:
* This variable can be the number of components in m_ImageIO or the
* number of components in the m_BandList (if used) */
unsigned int m_IOComponents;
/** Lock to ensure thread-safety (added for the AbortGenerateData flag) */
itk::SimpleFastMutexLock m_Lock;
};
} // end namespace otb
......
......@@ -48,6 +48,7 @@
#include "otb_boost_tokenizer_header.h"
#include "otbStringUtils.h"
#include "otbUtils.h"
namespace otb
{
......@@ -645,6 +646,13 @@ ImageFileWriter<TInputImage>
{
this->UpdateProgress(1.0);
}
else
{
itk::ProcessAborted e(__FILE__, __LINE__);
e.SetLocation(ITK_LOCATION);
e.SetDescription("Image writing has been aborted");
throw e;
}
// Notify end event observers
this->InvokeEvent(itk::EndEvent());
......@@ -833,6 +841,29 @@ ImageFileWriter<TInputImage>
return this->m_FilenameHelper->GetSimpleFileName();
}
template <class TInputImage>
const bool &
ImageFileWriter<TInputImage>
::GetAbortGenerateData() const
{
m_Lock.Lock();
// protected read here
bool ret = Superclass::GetAbortGenerateData();
m_Lock.Unlock();
if (ret) return otb::Utils::TrueConstant;
return otb::Utils::FalseConstant;
}
template <class TInputImage>
void
ImageFileWriter<TInputImage>
::SetAbortGenerateData(bool val)
{
m_Lock.Lock();
Superclass::SetAbortGenerateData(val);
m_Lock.Unlock();
}
} // end namespace otb
#endif
......@@ -31,6 +31,7 @@
#include "itkImageFileWriter.h"
#include "itkObjectFactoryBase.h"
#include "itkFastMutexLock.h"
#include "itkImageRegionMultidimensionalSplitter.h"
#include "otbImageIOFactory.h"
......@@ -252,6 +253,11 @@ public:
itkSetMacro(TiffTiledMode, bool);
itkGetMacro(TiffTiledMode, bool);
/** This override doesn't return a const ref on the actual boolean */
const bool & GetAbortGenerateData() const override;
void SetAbortGenerateData(bool val) override;
protected:
SimpleParallelTiffWriter();
virtual ~SimpleParallelTiffWriter();
......@@ -325,6 +331,9 @@ private:
bool m_Verbose;
bool m_VirtualMode;
bool m_TiffTiledMode;
/** Lock to ensure thread-safety (added for the AbortGenerateData flag) */
itk::SimpleFastMutexLock m_Lock;
};
......
......@@ -23,6 +23,7 @@
#include "otbSimpleParallelTiffWriter.h"
#include "otbStopwatch.h"
#include "otbUtils.h"
using std::vector;
......@@ -729,6 +730,16 @@ SimpleParallelTiffWriter<TInputImage>
}
}
// abort case
if (this->GetAbortGenerateData())
{
itk::ProcessAborted e(__FILE__, __LINE__);
e.SetLocation(ITK_LOCATION);
e.SetDescription("Image writing has been aborted");
throw e;
otb::MPIConfig::Instance()->abort(EXIT_FAILURE);
}
// Clean up
close_raster(output_raster);
output_raster = NULL;
......@@ -837,5 +848,27 @@ SimpleParallelTiffWriter<TInputImage>
return this->m_FilenameHelper->GetSimpleFileName();
}
template <class TInputImage>
const bool &
SimpleParallelTiffWriter<TInputImage>
::GetAbortGenerateData() const
{
m_Lock.Lock();
bool ret = Superclass::GetAbortGenerateData();
m_Lock.Unlock();
if (ret) return otb::Utils::TrueConstant;
return otb::Utils::FalseConstant;
}
template <class TInputImage>
void
SimpleParallelTiffWriter<TInputImage>
::SetAbortGenerateData(bool val)
{
m_Lock.Lock();
Superclass::SetAbortGenerateData(val);
m_Lock.Unlock();
}
}
#endif
......@@ -1431,11 +1431,11 @@ MainWindow
if( !( *it )->IsClosable() )
{
assert( !( *it )->GetApplication().IsNull() );
assert( ( *it )->GetModel()->GetApplication() );
// qDebug() << "OTB-application:" << ( *it )->GetApplication()->GetDocName();
names.push_back( ( *it )->GetApplication()->GetDocName() );
names.push_back( ( *it )->GetModel()->GetApplication()->GetDocName() );
}
}
......
......@@ -37,16 +37,10 @@
#include <QtGui>
#include <QShortcut>
//
// System includes (sorted by alphabetic order)
//
// ITK includes (sorted by alphabetic order)
//
// OTB includes (sorted by alphabetic order)
#ifndef Q_MOC_RUN // See: https://bugreports.qt-project.org/browse/QTBUG-22829 //tag=QT4-boost-compatibility
#include "otbWrapperApplication.h"
#include "otbWrapperQtWidgetView.h"
#include "otbWrapperQtWidgetModel.h"
#endif //tag=QT4-boost-compatibility
#include "OTBMonteverdiGUIExport.h"
......@@ -57,18 +51,8 @@
#include "mvdTypes.h"
#endif //tag=QT4-boost-compatibility
/*****************************************************************************/
/* PRE-DECLARATION SECTION */
//
// External classes pre-declaration.
namespace
{
}
namespace mvd
{
namespace Wrapper
{
......@@ -84,16 +68,12 @@ namespace Wrapper
*/
class OTBMonteverdiGUI_EXPORT QtWidgetView :
public QWidget
public otb::Wrapper::QtWidgetView
{
/*-[ QOBJECT SECTION ]-----------------------------------------------------*/
Q_OBJECT
Q_PROPERTY( bool isClosable
READ IsClosable
WRITE SetClosable );
/*-[ PUBLIC SECTION ]------------------------------------------------------*/
//
......@@ -112,29 +92,6 @@ public:
/** \brief Destructor. */
~QtWidgetView() override;
/** \brief Gui Creation. */
void CreateGui();
/** \brief Model Accessor */
inline otb::Wrapper::QtWidgetModel* GetModel()
{
return m_Model;
}
/**
* \return The OTB-application pointer of this view.
*/
otb::Wrapper::Application::ConstPointer GetApplication() const
{
return otb::ConstCast< otb::Wrapper::Application >(
m_Application
);
}
/**
*/
inline bool IsClosable() const;
/*-[ PUBLIC SLOTS SECTION ]------------------------------------------------*/
//
......@@ -146,12 +103,9 @@ public slots:
//
// Signals.
signals:
void QuitSignal();
void OTBApplicationOutputImageChanged( const QString &, const QString &);
void ExecuteAndWriteOutput();
void ExecutionDone( int nbOutputs );
/*-[ PROTECTED SECTION ]---------------------------------------------------*/
......@@ -160,14 +114,16 @@ signals:
// Protected methods.
protected:
//
// QWidget overloads.
QWidget* CreateInputWidgets() override;
void closeEvent( QCloseEvent * event ) override;
protected slots:
//
// Protected attributes.
protected:
/** extend the behaviour of base class OnExecButtonClicked */
void OnExecButtonClicked();
/** modify the behaviour of base class OnExceptionRaised
*/
void OnExceptionRaised( QString what );
/*-[ PRIVATE SECTION ]-----------------------------------------------------*/
......@@ -178,12 +134,6 @@ private:
QtWidgetView(const QtWidgetView&); //purposely not implemented
void operator=(const QtWidgetView&); //purposely not implemented
QWidget* CreateFooter();
QWidget* CreateInputWidgets();
QWidget* CreateDoc();
/**
*/
void SetupParameterWidgets( QWidget* widget );
......@@ -192,21 +142,6 @@ private:
*/
void SetupFileSelectionWidget( QWidget * );
//
// Private attributes.
private:
otb::Wrapper::Application::Pointer m_Application;
otb::Wrapper::QtWidgetModel* m_Model;
QPushButton* m_ExecButton;
QPushButton* m_QuitButton;
QShortcut* m_QuitShortcut;
QLabel* m_Message;
bool m_IsClosable : 1;
/*-[ PRIVATE SLOTS SECTION ]-----------------------------------------------*/
//
......@@ -218,30 +153,6 @@ private slots:
// image filename{s} set by the user in this OTB application (if any).
void OnApplicationExecutionDone( int );
void UpdateMessageAfterApplicationReady(bool val);
void UpdateMessageAfterExecution(int status);
/**
*/
void OnExecButtonClicked();
/**
*/
inline void OnProgressReportBegin();
/**
*/
inline void OnProgressReportEnd( int status );
/**
*/
void OnExceptionRaised( QString what );
/**
*/
inline void SetClosable( bool );
/**
*/
inline void OnFileSelectionWidgetAdded0( QWidget * );
......@@ -264,47 +175,6 @@ namespace mvd
namespace Wrapper
{
/*****************************************************************************/
inline
bool
QtWidgetView
::IsClosable() const
{
return m_IsClosable;
}
/*****************************************************************************/
inline
void
QtWidgetView
::SetClosable( bool enabled )
{
m_IsClosable = enabled;
setEnabled( true );
if( m_QuitButton!=NULL )
m_QuitButton->setEnabled( m_IsClosable );
}
/*******************************************************************************/
inline
void
QtWidgetView
::OnProgressReportBegin()
{
SetClosable( false );
}
/*******************************************************************************/
inline
void
QtWidgetView
::OnProgressReportEnd( int )
{
SetClosable( true );
}
/*******************************************************************************/
inline
void
......
......@@ -217,13 +217,13 @@ ApplicationLauncher
ApplicationLauncher::NewOtbApplicationWidget( appName, isStandalone );
assert( appWidget!=NULL );
assert( appWidget->GetApplication() );
assert( appWidget->GetModel()->GetApplication() );
QMainWindow * mainWindow = new QMainWindow( p, flags );
mainWindow->setWindowTitle(
QString( "%1 (OTB-" OTB_VERSION_STRING ")" )
.arg( appWidget->GetApplication()->GetDocName() )
.arg( appWidget->GetModel()->GetApplication()->GetDocName() )
);
mainWindow->setWindowIcon( QIcon( ":/otb_small.png" ) );
......@@ -251,11 +251,11 @@ ApplicationLauncher
);
assert( appWidget!=NULL );
assert( appWidget->GetApplication() );
assert( appWidget->GetModel()->GetApplication() );
appWidget->setWindowTitle(
QString( "%1 (OTB-" OTB_VERSION_STRING ")" )
.arg( appWidget->GetApplication()->GetDocName() )
.arg( appWidget->GetModel()->GetApplication()->GetDocName() )
);
appWidget->setWindowIcon( QIcon( ":/icons/process" ) );
......
......@@ -155,6 +155,9 @@ public:
*/
int ExecuteAndWriteOutput();
/** Request the application to stop its processing */
void Stop();
/* Get the internal application parameters
*
* WARNING: this method may disappear from the API */
......
......@@ -757,6 +757,12 @@ int Application::ExecuteAndWriteOutput()
return status;
}
void
Application::Stop()
{
m_ProgressSource->SetAbortGenerateData(true);
}
/* Enable the use of an optional parameter. Returns the previous state */
void Application::EnableParameter(std::string paramKey)
{
......
......@@ -68,6 +68,13 @@ signals:
*/
void ExceptionRaised( QString what );
public slots:
/** Ask the running application to stop */
void Stop()
{
m_Application->Stop();
}
protected:
void run() override;
......@@ -139,6 +146,8 @@ signals:
void UpdateGui();
void Stop();
protected slots:
/**
* \brief Slot called when execution is requested (e.g. by
......
......@@ -22,75 +22,244 @@
#define otbWrapperQtWidgetView_h
#include <QtGui>
#include <QObject>
#include <QShortcut>
//
// OTB includes (sorted by alphabetic order)
#ifndef Q_MOC_RUN // See: https://bugreports.qt-project.org/browse/QTBUG-22829 //tag=QT4-boost-compatibility
#include "otbWrapperApplication.h"
#include "otbWrapperQtWidgetModel.h"
#endif //tag=QT4-boost-compatibility
#include "OTBQtWidgetExport.h"
namespace otb
{
namespace Wrapper
{
/** \class QtWidgetView
* \brief
/*****************************************************************************/
/* CLASS DEFINITION SECTION */
/**
* \class QtWidgetView
*
* \ingroup OTBQtWidget
*
* \brief WIP.
*/
class OTBQtWidget_EXPORT QtWidgetView : public QWidget
class OTBQtWidget_EXPORT QtWidgetView :
public QWidget
{
/*-[ QOBJECT SECTION ]-----------------------------------------------------*/
Q_OBJECT
Q_PROPERTY( bool isClosable
READ IsClosable
WRITE SetClosable );
/*-[ PUBLIC SECTION ]------------------------------------------------------*/
//
// Public methods.
public:
QtWidgetView(Application* app);
/**
*/
static char const * const OBJECT_NAME;
/** \brief Constructor. */
QtWidgetView( const otb::Wrapper::Application::Pointer & otbApp,
QWidget* p =0,
Qt::WindowFlags flags =0 );
/** \brief Destructor. */
~QtWidgetView() override;
/** \brief Gui Creation. */
void CreateGui();
QtWidgetModel* GetModel()
/** \brief Model Accessor */
inline otb::Wrapper::QtWidgetModel* GetModel()
{
return m_Model;
}
/**
* \return The OTB-application pointer of this view.
*/
//~ otb::Wrapper::Application::ConstPointer GetApplication() const
//~ {
//~ return otb::ConstCast< otb::Wrapper::Application >(
//~ m_Application
//~ );
//~ }
/**
*/
inline bool IsClosable() const;
/*-[ PUBLIC SLOTS SECTION ]------------------------------------------------*/
//
// Public SLOTS.
public slots:
void CloseSlot();
void UnhandledException(QString message);
void OnExceptionRaised(QString message);
private slots:
void UpdateMessageAfterExecuteClicked();
void UpdateMessageAfterExecution(int status);
void UpdateMessageAfterApplicationReady(bool val);
/*-[ SIGNALS SECTION ]-----------------------------------------------------*/
//
// Signals.
signals:
void QuitSignal();
void ExecuteAndWriteOutput();
void Stop();
/*-[ PROTECTED SECTION ]---------------------------------------------------*/
//
// Protected methods.
protected:
bool IsRunning();
virtual QWidget* CreateInputWidgets();
//
// QWidget overloads.
void closeEvent( QCloseEvent * event ) override;
//
// Protected attributes.