diff --git a/Code/Mantid/MantidQt/MantidWidgets/inc/MantidQtMantidWidgets/IndirectInstrumentConfig.h b/Code/Mantid/MantidQt/MantidWidgets/inc/MantidQtMantidWidgets/IndirectInstrumentConfig.h index 4940ab6a8f50..b800b92636e8 100644 --- a/Code/Mantid/MantidQt/MantidWidgets/inc/MantidQtMantidWidgets/IndirectInstrumentConfig.h +++ b/Code/Mantid/MantidQt/MantidWidgets/inc/MantidQtMantidWidgets/IndirectInstrumentConfig.h @@ -98,13 +98,15 @@ namespace MantidQt void newInstrumentConfiguration(); signals: - /// Emmitted when the instrument configuration is changed + /// Emitted when the instrument configuration is changed void instrumentConfigurationUpdated(const QString & instrumentName, const QString & analyserName, const QString & reflectionName); private slots: - /// Updates the list of analysers and reflections based on the selected instrument + /// Handles an instrument being selected void updateInstrumentConfigurations(const QString & instrumentName); + /// Updates the list of analysers when an instrument is selected + bool updateAnalysersList(Mantid::API::MatrixWorkspace_sptr ws); /// Updates the list of reflections when an analyser is selected void updateReflectionsList(int index); /// Filters out any disabled instruments diff --git a/Code/Mantid/MantidQt/MantidWidgets/src/IndirectInstrumentConfig.cpp b/Code/Mantid/MantidQt/MantidWidgets/src/IndirectInstrumentConfig.cpp index b38c577d6742..77a28a51facd 100644 --- a/Code/Mantid/MantidQt/MantidWidgets/src/IndirectInstrumentConfig.cpp +++ b/Code/Mantid/MantidQt/MantidWidgets/src/IndirectInstrumentConfig.cpp @@ -312,23 +312,60 @@ namespace MantidQt m_uiForm.cbAnalyser->clear(); - IAlgorithm_sptr loadInstAlg = AlgorithmManager::Instance().create("CreateSimulationWorkspace"); - loadInstAlg->initialize(); - loadInstAlg->setChild(true); - loadInstAlg->setProperty("Instrument", instrumentName.toStdString()); - loadInstAlg->setProperty("BinParams", "0,0.5,1"); - loadInstAlg->setProperty("OutputWorkspace", "__empty_instrument_workspace"); - loadInstAlg->execute(); - MatrixWorkspace_sptr instWorkspace = loadInstAlg->getProperty("OutputWorkspace"); + // Try to load the instrument into an empty workspace + MatrixWorkspace_sptr instWorkspace; + try + { + IAlgorithm_sptr loadInstAlg = AlgorithmManager::Instance().create("CreateSimulationWorkspace"); + loadInstAlg->initialize(); + loadInstAlg->setChild(true); + loadInstAlg->setLogging(false); + loadInstAlg->setProperty("Instrument", instrumentName.toStdString()); + loadInstAlg->setProperty("BinParams", "0,0.5,1"); + loadInstAlg->setProperty("OutputWorkspace", "__empty_instrument_workspace"); + loadInstAlg->execute(); + instWorkspace = loadInstAlg->getProperty("OutputWorkspace"); + } + catch(...) + { + } + + // Try to update the list of analysers + bool valid = updateAnalysersList(instWorkspace); + m_uiForm.cbAnalyser->setEnabled(valid); + if(!valid) + m_uiForm.cbAnalyser->addItem("No Valid Analysers"); + + // Update the list of reflections + int index = m_uiForm.cbAnalyser->currentIndex(); + updateReflectionsList(index); + + m_uiForm.cbAnalyser->blockSignals(analyserPreviousBlocking); + } + + + /** + * Update the list of analysers based on an instrument workspace. + * + * @param ws Instrument workspace + * @return If the workspace contained valid analysers + */ + bool IndirectInstrumentConfig::updateAnalysersList(MatrixWorkspace_sptr ws) + { + if(!ws) + return false; QList> instrumentModes; - Instrument_const_sptr instrument = instWorkspace->getInstrument(); + Instrument_const_sptr instrument = ws->getInstrument(); std::vector ipfAnalysers = instrument->getStringParameter("analysers"); - if(ipfAnalysers.size() == 0) - return; + QStringList analysers; + if(ipfAnalysers.size() > 0) + analysers = QString::fromStdString(ipfAnalysers[0]).split(","); - QStringList analysers = QString::fromStdString(ipfAnalysers[0]).split(","); + // Do not try to display analysers if there are none + if(analysers.size() == 0) + return false; for(auto it = analysers.begin(); it != analysers.end(); ++it) { @@ -353,10 +390,7 @@ namespace MantidQt } } - int index = m_uiForm.cbAnalyser->currentIndex(); - updateReflectionsList(index); - - m_uiForm.cbAnalyser->blockSignals(analyserPreviousBlocking); + return true; }