Skip to content

Commit

Permalink
Replace usage on tools (both load ILL and trans)
Browse files Browse the repository at this point in the history
Refs #10863
  • Loading branch information
DanNixon committed Jan 12, 2015
1 parent 08d0550 commit 2003afe
Show file tree
Hide file tree
Showing 10 changed files with 59 additions and 422 deletions.
Expand Up @@ -32,16 +32,10 @@ namespace MantidQt
void run();

private slots:
/// Populate the analyser and reflection options on the interface
void instrumentChanged(const QString& instrument);
/// Populate the reflection option given the analyser
void analyserChanged(const QString& analyser);
/// Set the instrument based on the file name if possible
void handleFilesFound();

private:
/// Load the IDF file and get the instrument
Mantid::Geometry::Instrument_const_sptr getInstrument(const QString& instrument);
/// Map to store instrument analysers and reflections for this instrument
QMap<QString, QStringList> m_paramMap;
/// The ui form
Expand Down
Expand Up @@ -34,74 +34,19 @@
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_5">
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QLabel" name="lblInstrument">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Instrument: </string>
</property>
</widget>
</item>
<item>
<widget class="MantidQt::MantidWidgets::InstrumentSelector" name="cbInstrument">
<property name="techniques">
<stringlist>
<string>Reactor Indirect Geometry Spectroscopy</string>
</stringlist>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_3">
<item>
<widget class="QLabel" name="lblAnalyser">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Analyser:</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="cbAnalyser"/>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_4">
<item>
<widget class="QLabel" name="lblReflection">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Reflection:</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="cbReflection"/>
</item>
</layout>
</item>
</layout>
<widget class="MantidQt::MantidWidgets::IndirectInstrumentConfig" name="iicInstrumentConfiguration">
<property name="sizePolicy">
<sizepolicy hsizetype="Maximum" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="techniques" stdset="0">
<stringlist>
<string>Reactor Indirect Geometry Spectroscopy</string>
</stringlist>
</property>
</widget>
</item>
<item>
<layout class="QGridLayout" name="gridLayout">
Expand Down Expand Up @@ -269,9 +214,9 @@
<header>MantidQtMantidWidgets/MWRunFiles.h</header>
</customwidget>
<customwidget>
<class>MantidQt::MantidWidgets::InstrumentSelector</class>
<class>MantidQt::MantidWidgets::IndirectInstrumentConfig</class>
<extends>QComboBox</extends>
<header>MantidQtMantidWidgets/InstrumentSelector.h</header>
<header>MantidQtMantidWidgets/IndirectInstrumentConfig.h</header>
</customwidget>
</customwidgets>
<resources/>
Expand Down
Expand Up @@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>714</width>
<height>330</height>
<width>900</width>
<height>350</height>
</rect>
</property>
<property name="windowTitle">
Expand Down
Expand Up @@ -34,14 +34,6 @@ namespace MantidQt
private slots:
/// Handles completion of the algorithm
void algorithmComplete(bool error);
/// Handles completion of the instrument loading algorithm
void instrumentLoadingDone(bool error);
/// Handles an instrument being selected
void instrumentSelected(const QString& instrumentName);
/// Handles an analyser being selected
void analyserSelected(int);
/// Enables or disables the instrument selection controls
void enableInstrumentControls(bool enabled);

private:
/// The UI form
Expand Down
Expand Up @@ -23,59 +23,29 @@
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<widget class="QLabel" name="lblInstrument">
<widget class="MantidQt::MantidWidgets::IndirectInstrumentConfig" name="iicInstrumentConfiguration">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Preferred">
<sizepolicy hsizetype="Maximum" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Instrument: </string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="MantidQt::MantidWidgets::InstrumentSelector" name="cbInstrument">
<property name="techniques" stdset="0">
<stringlist>
<string>TOF Indirect Geometry Spectroscopy</string>
</stringlist>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="lblAnalyser">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Analyser:</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QComboBox" name="cbAnalyser"/>
</item>
<item row="2" column="0">
<widget class="QLabel" name="lblReflection">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
<property name="disabledInstruments" stdset="0">
<stringlist>
<string>TOSCA</string>
<string>TFXA</string>
</stringlist>
</property>
<property name="text">
<string>Reflection:</string>
<property name="enableDiffraction" stdset="0">
<bool>false</bool>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QComboBox" name="cbReflection"/>
</item>
</layout>
</widget>
</item>
Expand Down Expand Up @@ -201,6 +171,11 @@
<extends>QComboBox</extends>
<header>MantidQtMantidWidgets/InstrumentSelector.h</header>
</customwidget>
<customwidget>
<class>MantidQt::MantidWidgets::IndirectInstrumentConfig</class>
<extends>QComboBox</extends>
<header>MantidQtMantidWidgets/IndirectInstrumentConfig.h</header>
</customwidget>
</customwidgets>
<resources/>
<connections/>
Expand Down
139 changes: 5 additions & 134 deletions Code/Mantid/MantidQt/CustomInterfaces/src/IndirectLoadILL.cpp
Expand Up @@ -17,13 +17,8 @@ namespace MantidQt
{
m_uiForm.setupUi(parent);

connect(m_uiForm.cbInstrument, SIGNAL(instrumentSelectionChanged(const QString&)), this, SLOT(instrumentChanged(const QString&)));
connect(m_uiForm.cbAnalyser, SIGNAL(currentIndexChanged(const QString&)), this, SLOT(analyserChanged(const QString&)));
connect(m_uiForm.mwRun, SIGNAL(filesFound()), this, SLOT(handleFilesFound()));
connect(m_uiForm.chkUseMap, SIGNAL(toggled(bool)), m_uiForm.mwMapFile, SLOT(setEnabled(bool)));

QString instrument = m_uiForm.cbInstrument->currentText();
instrumentChanged(instrument);
}

/**
Expand Down Expand Up @@ -70,9 +65,9 @@ namespace MantidQt
QFileInfo finfo(filename);
QString ext = finfo.extension().toLower();

QString instrument = m_uiForm.cbInstrument->currentText();
QString analyser = m_uiForm.cbAnalyser->currentText();
QString reflection = m_uiForm.cbReflection->currentText();
QString instrument = m_uiForm.iicInstrumentConfiguration->getInstrumentName();
QString analyser = m_uiForm.iicInstrumentConfiguration->getAnalyserName();
QString reflection = m_uiForm.iicInstrumentConfiguration->getReflectionName();

if(m_uiForm.chkUseMap->isChecked()){ useMap ="True"; }
QString mapPath = m_uiForm.mwMapFile->getFirstFilename();
Expand Down Expand Up @@ -135,125 +130,6 @@ namespace MantidQt
m_uiForm.mwRun->readSettings(settings.group());
}

/**
* Set the analyser option when the instrument changes.
*
* @param instrument :: The name of the instrument
*/
void IndirectLoadILL::instrumentChanged(const QString& instrument)
{
using namespace Mantid::API;

if(!instrument.isEmpty())
{
m_uiForm.cbInstrument->blockSignals(true);
try
{
auto inst = getInstrument(instrument);
if(inst)
{
m_paramMap.clear();

auto analysers = inst->getStringParameter("analysers");

m_uiForm.cbAnalyser->clear();

if( analysers.size() > 0 )
{
// load analysers and add them to the interface
QStringList analysersList = QString(analysers[0].c_str()).split(',');
m_uiForm.cbAnalyser->addItems(analysersList);

// for each analyser for this instrument, get there reflections
QStringList::const_iterator it;
for( it = analysersList.begin(); it != analysersList.end(); ++it) {

auto reflections = inst->getStringParameter("refl-"+it->toStdString());

if( reflections.size() > 0 )
{
QStringList refs = QString(reflections[0].c_str()).split(',');

// analyser => list of reflections
m_paramMap[*it] = refs;
}
}

// set the list of reflections for the current analyser
analyserChanged(analysersList[0]);
}
}
}
catch(std::runtime_error& e)
{
emit showMessageBox(e.what());
}
m_uiForm.cbInstrument->blockSignals(false);
}
}

/**
* Get a pointer to the instrument.
*
* This will use LoadEmptyInstrument and get the instrument details off of
* the workspace. It also uses ExperimentInfo to get the most relevant instrument
* defintion.
*
* @param instrument :: The name of the instrument
* @return Pointer to the instrument
*/
Mantid::Geometry::Instrument_const_sptr IndirectLoadILL::getInstrument(const QString& instrument)
{
using namespace Mantid::API;

MatrixWorkspace_sptr idfWs;

// Find the file path of the insturment file
std::string idfPath = ExperimentInfo::getInstrumentFilename(instrument.toStdString());
if(idfPath.empty())
{
throw std::runtime_error("Could not locate instrument file for instrument " + instrument.toStdString());
}

// Attempt to load instrument file using LoadEmptyInstrument
try
{
Algorithm_sptr loadEmptyInst = AlgorithmManager::Instance().createUnmanaged("LoadEmptyInstrument", -1);

loadEmptyInst->initialize();
loadEmptyInst->setChild(true);
loadEmptyInst->setRethrows(true);
loadEmptyInst->setPropertyValue("Filename", idfPath);
loadEmptyInst->setPropertyValue("OutputWorkspace", "__" + instrument.toStdString() + "_defintion");
loadEmptyInst->executeAsChildAlg();

idfWs = loadEmptyInst->getProperty("OutputWorkspace");
}
catch(std::runtime_error& ex)
{
throw std::runtime_error("Could not load instrument file for instrument" + instrument.toStdString()
+ "\n " + ex.what());
}

return idfWs->getInstrument();
}

/**
* Set the reflection option when the analyser changes.
*
* @param analyser :: The name of the analyser
*/
void IndirectLoadILL::analyserChanged(const QString& analyser)
{
using namespace Mantid::API;

if(!analyser.isEmpty())
{
m_uiForm.cbReflection->clear();
m_uiForm.cbReflection->addItems(m_paramMap[analyser]);
}
}

/**
* Set the instrument selected in the combobox based on
* the file name of the run is possible.
Expand All @@ -269,13 +145,8 @@ namespace MantidQt

if( fnameParts.size() > 0 )
{
//Check if the first part of the name is in the instruments list
int instrIndex = m_uiForm.cbInstrument->findText(fnameParts[0]);

if( instrIndex >= 0 )
{
m_uiForm.cbInstrument->setCurrentIndex(instrIndex);
}
// Check if the first part of the name is in the instruments list
m_uiForm.iicInstrumentConfiguration->setInstrument(fnameParts[0]);
}
}

Expand Down

0 comments on commit 2003afe

Please sign in to comment.