Skip to content
Snippets Groups Projects
Commit 455ea7e9 authored by Michael Reuter's avatar Michael Reuter
Browse files

Merge remote-tracking branch 'origin/bugfix/5983_simple_instrument_crash'

parents dd75cbe3 ae80e6bc
No related branches found
No related tags found
No related merge requests found
......@@ -58,6 +58,18 @@ using namespace MantidQt::API;
// Name of the QSettings group to store the InstrumentWindw settings
const char* InstrumentWindowSettingsGroup = "Mantid/InstrumentWindow";
namespace {
/**
* Exception type thrown when an istrument has no sample and cannot be displayed in the instrument view.
*/
class InstrumentHasNoSampleError: public std::runtime_error
{
public:
InstrumentHasNoSampleError():std::runtime_error("Instrument has no sample.\nSource and sample need to be set in the IDF."){}
};
}
/**
* Constructor.
*/
......@@ -331,6 +343,10 @@ void InstrumentWindow::setSurfaceType(int type)
{
Mantid::Geometry::Instrument_const_sptr instr = m_instrumentActor->getInstrument();
Mantid::Geometry::IComponent_const_sptr sample = instr->getSample();
if ( !sample )
{
throw InstrumentHasNoSampleError();
}
Mantid::Kernel::V3D sample_pos = sample->getPos();
Mantid::Kernel::V3D axis;
// define the axis
......@@ -369,6 +385,11 @@ void InstrumentWindow::setSurfaceType(int type)
surface = new PanelsSurface(m_instrumentActor,sample_pos,axis);
}
}
catch(InstrumentHasNoSampleError&)
{
QApplication::restoreOverrideCursor();
throw;
}
catch(std::exception &e)
{
errorMessage = e.what();
......@@ -703,12 +724,17 @@ void InstrumentWindow::saveSettings()
settings.beginGroup("Mantid/InstrumentWindow");
if ( m_InstrumentDisplay )
settings.setValue("BackgroundColor", m_InstrumentDisplay->currentBackgroundColor());
settings.setValue("PeakLabelPrecision",getSurface()->getPeakLabelPrecision());
settings.setValue("ShowPeakRows",getSurface()->getShowPeakRowsFlag());
settings.setValue("ShowPeakLabels",getSurface()->getShowPeakLabelsFlag());
foreach(InstrumentWindowTab* tab, m_tabs)
auto surface = getSurface();
if ( surface )
{
tab->saveSettings(settings);
// if surface is null istrument view wasn't created and there is nothing to save
settings.setValue("PeakLabelPrecision",getSurface()->getPeakLabelPrecision());
settings.setValue("ShowPeakRows",getSurface()->getShowPeakRowsFlag());
settings.setValue("ShowPeakLabels",getSurface()->getShowPeakLabelsFlag());
foreach(InstrumentWindowTab* tab, m_tabs)
{
tab->saveSettings(settings);
}
}
settings.endGroup();
}
......
......@@ -1886,7 +1886,8 @@ InstrumentWindow* MantidUI::getInstrumentView(const QString & wsName, int tab)
catch(const std::exception& e)
{
QApplication::restoreOverrideCursor();
QMessageBox::critical(appWindow(),"MantidPlot - Error",e.what());
QString errorMessage = "Instrument view cannot be created:\n\n" + QString(e.what());
QMessageBox::critical(appWindow(),"MantidPlot - Error",errorMessage);
if (insWin)
{
appWindow()->closeWindow(insWin);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment