#include "mdispqtapp.h"
#include "mainframe.h"
#include <QtGui>
#include <QMessageBox>
MdispQtApp::MdispQtApp( int& argc, char** argv )
: QApplication( argc, argv )
, m_isCurrentlyHookedOnErrors(false)
{
connect(this, SIGNAL(message(const QString&)), this, SLOT(OnErrorMessage(const QString&)));
MappAllocDefault(M_DEFAULT, &m_MilApplication, &m_MilSystem, M_NULL, M_NULL, M_NULL);
MappHookFunction(M_DEFAULT, M_ERROR_CURRENT,DisplayErrorExt,M_NULL);
m_isCurrentlyHookedOnErrors = true;
MappControl(M_DEFAULT, M_ERROR,M_PRINT_DISABLE);
MsysInquire(m_MilSystem,M_DIGITIZER_NUM,&m_numberOfDigitizer);
if (m_numberOfDigitizer)
{
MdigAlloc(m_MilSystem,M_DEFAULT,MIL_TEXT("M_DEFAULT"),M_DEFAULT,&m_MilDigitizer);
MdigInquire(m_MilDigitizer,M_SIZE_X,&m_digitizerSizeX);
MdigInquire(m_MilDigitizer,M_SIZE_Y,&m_digitizerSizeY);
MdigInquire(m_MilDigitizer,M_SIZE_BAND,&m_digitizerNbBands);
}
m_isGrabStarted = false;
MainFrame* mf = new MainFrame();
mf->show();
}
MdispQtApp::~MdispQtApp()
{
if(m_MilDigitizer)
MdigFree (m_MilDigitizer);
if(m_MilSystem)
MsysFree (m_MilSystem);
if(m_MilApplication)
{
MappControl(M_DEFAULT, M_ERROR,M_PRINT_ENABLE);
if(m_isCurrentlyHookedOnErrors)
{
MappHookFunction(M_DEFAULT, M_ERROR_CURRENT+M_UNHOOK,DisplayErrorExt,M_NULL);
m_isCurrentlyHookedOnErrors = false;
}
MappFree(m_MilApplication);
}
}
MIL_INT MFTYPE MdispQtApp::DisplayErrorExt(MIL_INT , MIL_ID EventId, void* )
{
((MdispQtApp*) qApp)->DisplayError(EventId);
return M_NULL;
}
long MFTYPE MdispQtApp::DisplayError( MIL_ID EventId )
{
MIL_TEXT_CHAR ErrorMessageFunction[M_ERROR_MESSAGE_SIZE] = MIL_TEXT("");
MIL_TEXT_CHAR ErrorMessage[M_ERROR_MESSAGE_SIZE] = MIL_TEXT("");
MIL_TEXT_CHAR ErrorSubMessage1[M_ERROR_MESSAGE_SIZE] = MIL_TEXT("");
MIL_TEXT_CHAR ErrorSubMessage2[M_ERROR_MESSAGE_SIZE] = MIL_TEXT("");
MIL_TEXT_CHAR ErrorSubMessage3[M_ERROR_MESSAGE_SIZE] = MIL_TEXT("");
MIL_INT NbSubCode;
QString QErrorMessage;
MappGetHookInfo(EventId,M_MESSAGE+M_CURRENT_FCT,ErrorMessageFunction);
MappGetHookInfo(EventId,M_MESSAGE+M_CURRENT,ErrorMessage);
MappGetHookInfo(EventId,M_CURRENT_SUB_NB,&NbSubCode);
if (NbSubCode > 2)
MappGetHookInfo(EventId,M_MESSAGE+M_CURRENT_SUB_3,ErrorSubMessage3);
if (NbSubCode > 1)
MappGetHookInfo(EventId,M_MESSAGE+M_CURRENT_SUB_2,ErrorSubMessage2);
if (NbSubCode > 0)
MappGetHookInfo(EventId,M_MESSAGE+M_CURRENT_SUB_1,ErrorSubMessage1);
#if M_MIL_USE_LINUX
QErrorMessage = ErrorMessageFunction;
#else
QErrorMessage = QString::fromWCharArray(ErrorMessageFunction);
#endif
QErrorMessage = QErrorMessage + "\n";
#if M_MIL_USE_LINUX
QErrorMessage = QErrorMessage + ErrorMessage;
#else
QErrorMessage = QErrorMessage + QString::fromWCharArray(ErrorMessage);
#endif
if(NbSubCode > 0)
{
QErrorMessage = QErrorMessage + "\n";
#if M_MIL_USE_LINUX
QErrorMessage = QErrorMessage + ErrorSubMessage1;
#else
QErrorMessage = QErrorMessage + QString::fromWCharArray(ErrorSubMessage1);
#endif
}
if(NbSubCode > 1)
{
QErrorMessage = QErrorMessage + "\n";
#if M_MIL_USE_LINUX
QErrorMessage = QErrorMessage + ErrorSubMessage2;
#else
QErrorMessage = QErrorMessage + QString::fromWCharArray(ErrorSubMessage2);
#endif
}
if(NbSubCode > 2)
{
QErrorMessage = QErrorMessage + "\n";
#if M_MIL_USE_LINUX
QErrorMessage = QErrorMessage + ErrorSubMessage3;
#else
QErrorMessage = QErrorMessage + QString::fromWCharArray(ErrorSubMessage3);
#endif
}
QErrorMessage = QErrorMessage + "\n\n";
QErrorMessage = QErrorMessage + "Do you want to continue error print?";
emit message(QErrorMessage);
return M_NULL;
}
void MdispQtApp::OnErrorMessage(const QString& QErrorMessage)
{
if ( QMessageBox::warning( 0, tr("MIL Error"), QErrorMessage, QMessageBox::Yes,
QMessageBox::No ) == QMessageBox::No )
{
MappHookFunction(M_DEFAULT, M_ERROR_CURRENT+M_UNHOOK,DisplayErrorExt,M_NULL);
((MdispQtApp*) qApp)->HookedOnErrors(false);
}
}
#include "moc_mdispqtapp.cpp"