Newer
Older
/*=========================================================================
Program: ORFEO Toolbox
Language: C++
Date: $Date$
Version: $Revision$
Copyright (c) Centre National d'Etudes Spatiales. All rights reserved.
See OTBCopyright.txt for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notices for more information.
=========================================================================*/
#include "otbWrapperQtWidgetModel.h"

Stéphane Albert
committed
namespace Wrapper
{

Stéphane Albert
committed
QtWidgetModel
::QtWidgetModel(Application* app) :
m_Application(app),
m_LogOutput(),
m_IsRunning(false)
Julien Michel
committed
// Init only if not already done
if(!m_Application->IsInitialized())
{
m_Application->Init();
}
m_LogOutput = QtLogOutput::New();
// Attach log output to the Application logger
m_Application->GetLogger()->SetTimeStampFormat(itk::LoggerBase::HUMANREADABLE);
m_Application->GetLogger()->AddLogOutput(m_LogOutput);
}
QtWidgetModel::~QtWidgetModel()
{
}

Stéphane Albert
committed
void
QtWidgetModel
::NotifyUpdate()
// Update the parameters
m_Application->UpdateParameters();
if (!m_IsRunning)
{
bool applicationStatus = m_Application->IsApplicationReady();
emit SetApplicationReady(applicationStatus);
}

Stéphane Albert
committed
void
QtWidgetModel
::ExecuteAndWriteOutputSlot()
// Deactivate the Execute button while processing
emit SetApplicationReady(false);
m_IsRunning = true;
// launch the output image writing
AppliThread * taskAppli = new AppliThread( m_Application );

Stéphane Albert
committed
QObject::connect(
taskAppli,
SIGNAL( ExceptionRaised( QString ) ),
// to:
this,

Stéphane Albert
committed
SIGNAL( ExceptionRaised( QString ) )

Stéphane Albert
committed
);
QObject::connect(
taskAppli,
SIGNAL( ApplicationExecutionDone( int ) ),
// to:
this,
SLOT( OnApplicationExecutionDone( int ) )
);
taskAppli->Execute();
// Tell the Progress Reporter to begin
emit SetProgressReportBegin();
}

Stéphane Albert
committed
void
QtWidgetModel
::OnApplicationExecutionDone( int status )
{
m_IsRunning = false;

Stéphane Albert
committed
// Require GUI update.
NotifyUpdate();
// For the view to activate the button "Execute"

Stéphane Albert
committed
emit SetApplicationReady( true );
// For the progressReport to close the Progress widget

Stéphane Albert
committed
emit SetProgressReportDone( status );

Stéphane Albert
committed
void
QtWidgetModel
::SendLogWARNING( const std::string & mes )
{
m_Application->GetLogger()->Write( itk::LoggerBase::WARNING, mes );
}

Stéphane Albert
committed
void
QtWidgetModel
::SendLogINFO( const std::string & mes )
{
m_Application->GetLogger()->Write( itk::LoggerBase::INFO, mes );
}

Stéphane Albert
committed
void
QtWidgetModel
::SendLogDEBUG( const std::string & mes )
{
m_Application->GetLogger()->Write( itk::LoggerBase::DEBUG, mes );
}

Stéphane Albert
committed
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
}
}
namespace otb
{
namespace Wrapper
{
AppliThread
::~AppliThread()
{
wait();
}
void
AppliThread
::run()
{
int result = -1;
//
// Try to execute OTB-application.
try
{
result = m_Application->ExecuteAndWriteOutput();
}
//
// Catch standard exceptions.
catch( std::exception& err )
{
std::ostringstream message;
message
<< "The following error occurred during OTB-application execution: "
<< err.what()
<< std::endl;
m_Application->GetLogger()->Write( itk::LoggerBase::FATAL, message.str() );

Stéphane Albert
committed
// Signal exception.
emit ExceptionRaised( err.what() );
}
//
// Catch other exceptions.
catch( ... )
{
m_Application->GetLogger()->Write(
itk::LoggerBase::FATAL,
"An unknown exception has been raised during OTB-application execution"
);
// Signal exception.
emit ExceptionRaised( "Exception raised by OTB-application." );
}
//
// Signal OTB-application has ended with result status.
emit ApplicationExecutionDone( result );

Stéphane Albert
committed
}