Skip to content
Snippets Groups Projects
Commit 5bdc20b7 authored by Roman Tolchenov's avatar Roman Tolchenov
Browse files

Re #5983. Check if sample is null.

parent 06e1a705
No related branches found
No related tags found
No related merge requests found
...@@ -58,6 +58,18 @@ using namespace MantidQt::API; ...@@ -58,6 +58,18 @@ using namespace MantidQt::API;
// Name of the QSettings group to store the InstrumentWindw settings // Name of the QSettings group to store the InstrumentWindw settings
const char* InstrumentWindowSettingsGroup = "Mantid/InstrumentWindow"; 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("Istrument has no sample.\nSource and sample need to be set in the IDF."){}
};
}
/** /**
* Constructor. * Constructor.
*/ */
...@@ -331,6 +343,10 @@ void InstrumentWindow::setSurfaceType(int type) ...@@ -331,6 +343,10 @@ void InstrumentWindow::setSurfaceType(int type)
{ {
Mantid::Geometry::Instrument_const_sptr instr = m_instrumentActor->getInstrument(); Mantid::Geometry::Instrument_const_sptr instr = m_instrumentActor->getInstrument();
Mantid::Geometry::IComponent_const_sptr sample = instr->getSample(); Mantid::Geometry::IComponent_const_sptr sample = instr->getSample();
if ( !sample )
{
throw InstrumentHasNoSampleError();
}
Mantid::Kernel::V3D sample_pos = sample->getPos(); Mantid::Kernel::V3D sample_pos = sample->getPos();
Mantid::Kernel::V3D axis; Mantid::Kernel::V3D axis;
// define the axis // define the axis
...@@ -369,6 +385,11 @@ void InstrumentWindow::setSurfaceType(int type) ...@@ -369,6 +385,11 @@ void InstrumentWindow::setSurfaceType(int type)
surface = new PanelsSurface(m_instrumentActor,sample_pos,axis); surface = new PanelsSurface(m_instrumentActor,sample_pos,axis);
} }
} }
catch(InstrumentHasNoSampleError&)
{
QApplication::restoreOverrideCursor();
throw;
}
catch(std::exception &e) catch(std::exception &e)
{ {
errorMessage = e.what(); errorMessage = e.what();
...@@ -703,12 +724,17 @@ void InstrumentWindow::saveSettings() ...@@ -703,12 +724,17 @@ void InstrumentWindow::saveSettings()
settings.beginGroup("Mantid/InstrumentWindow"); settings.beginGroup("Mantid/InstrumentWindow");
if ( m_InstrumentDisplay ) if ( m_InstrumentDisplay )
settings.setValue("BackgroundColor", m_InstrumentDisplay->currentBackgroundColor()); settings.setValue("BackgroundColor", m_InstrumentDisplay->currentBackgroundColor());
settings.setValue("PeakLabelPrecision",getSurface()->getPeakLabelPrecision()); auto surface = getSurface();
settings.setValue("ShowPeakRows",getSurface()->getShowPeakRowsFlag()); if ( surface )
settings.setValue("ShowPeakLabels",getSurface()->getShowPeakLabelsFlag());
foreach(InstrumentWindowTab* tab, m_tabs)
{ {
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(); settings.endGroup();
} }
......
...@@ -1886,7 +1886,8 @@ InstrumentWindow* MantidUI::getInstrumentView(const QString & wsName, int tab) ...@@ -1886,7 +1886,8 @@ InstrumentWindow* MantidUI::getInstrumentView(const QString & wsName, int tab)
catch(const std::exception& e) catch(const std::exception& e)
{ {
QApplication::restoreOverrideCursor(); QApplication::restoreOverrideCursor();
QMessageBox::critical(appWindow(),"MantidPlot - Error",e.what()); QString errorMessage = "Instrument view canot be created:\n\n" + QString(e.what());
QMessageBox::critical(appWindow(),"MantidPlot - Error",errorMessage);
if (insWin) if (insWin)
{ {
appWindow()->closeWindow(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