Skip to content

Commit

Permalink
Re #9696. Added more try-catch blocks and error messages.
Browse files Browse the repository at this point in the history
  • Loading branch information
mantid-roman committed Jul 8, 2014
1 parent b40b467 commit 5a7aef7
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 10 deletions.
Expand Up @@ -731,7 +731,15 @@ void InstrumentWindowPickTab::addPeak(double x,double y)

try
{
Mantid::API::IPeaksWorkspace_sptr tw = m_instrWindow->getSurface()->getEditPeaksWorkspace();
auto surface = boost::dynamic_pointer_cast<UnwrappedSurface>( m_instrWindow->getSurface() );
if ( !surface )
{
QMessageBox::warning(this,"MantidPlot - Warning","Peaks can only be added in an \"unwrapped\" (2D) view.\n"
"Please switch to a 2D view from Render tab.");
return;
}

Mantid::API::IPeaksWorkspace_sptr tw = surface->getEditPeaksWorkspace();
InstrumentActor* instrActor = m_instrWindow->getInstrumentActor();
Mantid::API::MatrixWorkspace_const_sptr ws = instrActor->getWorkspace();
std::string peakTableName;
Expand Down Expand Up @@ -763,11 +771,7 @@ void InstrumentWindowPickTab::addPeak(double x,double y)
return;
}
}
auto surface = boost::dynamic_pointer_cast<UnwrappedSurface>( m_instrWindow->getSurface() );
if ( surface )
{
surface->setPeaksWorkspace(boost::dynamic_pointer_cast<Mantid::API::IPeaksWorkspace>(tw));
}
surface->setPeaksWorkspace(boost::dynamic_pointer_cast<Mantid::API::IPeaksWorkspace>(tw));
}

// Run the AddPeak algorithm
Expand Down
Expand Up @@ -5,6 +5,7 @@

#include <QPainter>
#include <QList>
#include <QMessageBox>
#include <cmath>
#include <algorithm>
#include <stdexcept>
Expand Down Expand Up @@ -307,7 +308,18 @@ void PeakOverlay::afterReplaceHandle(const std::string& wsName,
{
auto style = isEmpty() ? getDefaultStyle(0) : m_det2marker.begin().value()->getStyle();
clear();
createMarkers( style );
try
{
createMarkers( style );
}
catch(std::exception& e)
{
QMessageBox::critical(NULL,"MantidPlot - Error", QString("Cannot display peak markers:\n%1").arg(e.what()));
}
catch(...)
{
QMessageBox::critical(NULL,"MantidPlot - Error", QString("Cannot display peak markers because of an error."));
}
m_surface->requestRedraw(true);
}
}
Expand Down
Expand Up @@ -86,6 +86,7 @@ UnwrappedSurface::UnwrappedSurface(const InstrumentActor* rootActor):
connect(moveController,SIGNAL(setSelectionRect(QRect)),this,SLOT(setSelectionRect(QRect)));
connect(moveController,SIGNAL(zoom()),this,SLOT(zoom()));
connect(moveController,SIGNAL(unzoom()),this,SLOT(unzoom()));
connect(this,SIGNAL(requestDisplayErrorMessage(QString)),this,SLOT(displayErrorMessage(QString)),Qt::QueuedConnection);
}

/**
Expand Down Expand Up @@ -551,10 +552,17 @@ void UnwrappedSurface::createPeakShapes(const QRect& window)const
PeakMarker2D::Style style = peakShapes.getDefaultStyle(m_peakShapesStyle);
m_peakShapesStyle++;
peakShapes.setWindow(getSurfaceBounds(),window);
peakShapes.createMarkers( style );
try
{
peakShapes.createMarkers( style );
}
catch(...)
{
QApplication::restoreOverrideCursor();
throw;
}
QApplication::restoreOverrideCursor();
}
m_startPeakShapes = false;
setPeakVisibility();
}

Expand Down Expand Up @@ -597,7 +605,19 @@ void UnwrappedSurface::drawSimpleToImage(QImage* image,bool picking)const

if (m_startPeakShapes)
{
createPeakShapes(image->rect());
try
{
createPeakShapes(image->rect());
}
catch(std::exception& e)
{
emit requestDisplayErrorMessage( QString("Cannot display peak markers:\n%1").arg(e.what()) );
}
catch(...)
{
emit requestDisplayErrorMessage( QString("Cannot display peak markers because of an error.") );
}
m_startPeakShapes = false;
}

for(size_t i=0;i<m_unwrappedDetectors.size();++i)
Expand Down Expand Up @@ -784,3 +804,11 @@ void UnwrappedSurface::calcSize(UnwrappedDetector& udet)

}

/**
* Display an error message box.
* @param msg :: A message to display.
*/
void UnwrappedSurface::displayErrorMessage(QString msg) const
{
QMessageBox::critical(NULL,"MantidPlot - Error", msg);
}
Expand Up @@ -126,6 +126,13 @@ protected slots:
void zoom();
/// Unzoom view to the previous zoom area or to full view
void unzoom();
/// Display an error message box
void displayErrorMessage(QString msg) const;

signals:

/// Emit to display error message in the next event loop
void requestDisplayErrorMessage(QString msg) const;

protected:

Expand Down

0 comments on commit 5a7aef7

Please sign in to comment.