Skip to content

Commit

Permalink
Enable/disable tabs as needed, update instrument selector
Browse files Browse the repository at this point in the history
Need to actually remove the tab

Refs #11158
  • Loading branch information
DanNixon committed Feb 23, 2015
1 parent 0f9090b commit b5361fa
Show file tree
Hide file tree
Showing 3 changed files with 126 additions and 61 deletions.
Expand Up @@ -70,7 +70,7 @@ namespace MantidQt
virtual void initLocalPython();

/// Handled configuration changes
void handleDirectoryChange(Mantid::Kernel::ConfigValChangeNotification_ptr pNf);
void handleConfigChange(Mantid::Kernel::ConfigValChangeNotification_ptr pNf);

Mantid::API::MatrixWorkspace_sptr loadInstrumentIfNotExist(std::string instrumentName,
std::string analyser = "", std::string reflection = "");
Expand All @@ -83,6 +83,8 @@ namespace MantidQt
void newInstrumentConfiguration();

private slots:
/// Shows/hides tabs based on facility
void filterUiForFacility(QString facility);
/// Opens the help page for the current tab
void helpClicked();
/// Exports the current tab algorithms as a Python script
Expand Down
Expand Up @@ -38,11 +38,9 @@
<property name="techniques" stdset="0">
<stringlist>
<string>TOF Indirect Geometry Spectroscopy</string>
<string>Reactor Indirect Geometry Spectroscopy</string>
</stringlist>
</property>
<property name="facility" stdset="0">
<string>ISIS</string>
</property>
<property name="enableDiffraction" stdset="0">
<bool>false</bool>
</property>
Expand All @@ -62,9 +60,6 @@
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="styleSheet">
<string notr="true"/>
</property>
<property name="currentIndex">
<number>0</number>
</property>
Expand All @@ -74,71 +69,71 @@
<height>14</height>
</size>
</property>
<widget class="QWidget" name="tabEnergyTransfer">
<widget class="QWidget" name="tabISISEnergyTransfer">
<attribute name="title">
<string>Energy Transfer</string>
<string>ISIS Energy Transfer</string>
</attribute>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QScrollArea" name="saEnergyTransfer">
<widget class="QScrollArea" name="saISISEnergyTransfer">
<property name="widgetResizable">
<bool>true</bool>
</property>
<widget class="QWidget" name="loEnergyTransfer">
<widget class="QWidget" name="loISISEnergyTransfer">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>100</width>
<height>100</height>
<width>656</width>
<height>446</height>
</rect>
</property>
</widget>
</widget>
</item>
</layout>
</widget>
<widget class="QWidget" name="tabCalibration">
<widget class="QWidget" name="tabISISCalibration">
<attribute name="title">
<string>Calibration</string>
<string>ISIS Calibration</string>
</attribute>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<widget class="QScrollArea" name="saCalibration">
<widget class="QScrollArea" name="saISISCalibration">
<property name="widgetResizable">
<bool>true</bool>
</property>
<widget class="QWidget" name="loCalibration">
<widget class="QWidget" name="loISISCalibration">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>100</width>
<height>100</height>
<width>96</width>
<height>26</height>
</rect>
</property>
</widget>
</widget>
</item>
</layout>
</widget>
<widget class="QWidget" name="tabDiagnostics">
<widget class="QWidget" name="tabISISDiagnostics">
<attribute name="title">
<string>Diagnostics</string>
<string>ISIS Diagnostics</string>
</attribute>
<layout class="QVBoxLayout" name="verticalLayout_3">
<item>
<widget class="QScrollArea" name="saDiagnostics">
<widget class="QScrollArea" name="saISISDiagnostics">
<property name="widgetResizable">
<bool>true</bool>
</property>
<widget class="QWidget" name="loDiagnostics">
<widget class="QWidget" name="loISISDiagnostics">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>100</width>
<height>100</height>
<width>96</width>
<height>26</height>
</rect>
</property>
</widget>
Expand All @@ -161,8 +156,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>100</width>
<height>100</height>
<width>96</width>
<height>26</height>
</rect>
</property>
</widget>
Expand All @@ -185,8 +180,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>100</width>
<height>100</height>
<width>96</width>
<height>26</height>
</rect>
</property>
</widget>
Expand All @@ -209,8 +204,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>100</width>
<height>100</height>
<width>96</width>
<height>26</height>
</rect>
</property>
</widget>
Expand All @@ -233,8 +228,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>100</width>
<height>100</height>
<width>96</width>
<height>26</height>
</rect>
</property>
</widget>
Expand Down
Expand Up @@ -55,10 +55,12 @@ IndirectDataReduction::IndirectDataReduction(QWidget *parent) :
m_instrument(""),
m_settingsGroup("CustomInterfaces/IndirectDataReduction"),
m_algRunner(new MantidQt::API::AlgorithmRunner(this)),
m_changeObserver(*this, &IndirectDataReduction::handleDirectoryChange)
m_changeObserver(*this, &IndirectDataReduction::handleConfigChange)
{
// Signals to report load instrument algo result
connect(m_algRunner, SIGNAL(algorithmComplete(bool)), this, SLOT(instrumentLoadingDone(bool)));

Mantid::Kernel::ConfigService::Instance().addObserver(m_changeObserver);
}


Expand All @@ -67,6 +69,8 @@ IndirectDataReduction::IndirectDataReduction(QWidget *parent) :
*/
IndirectDataReduction::~IndirectDataReduction()
{
Mantid::Kernel::ConfigService::Instance().removeObserver(m_changeObserver);

// Make sure no algos are running after the window has been closed
m_algRunner->cancelRunningAlgorithm();

Expand Down Expand Up @@ -116,9 +120,9 @@ void IndirectDataReduction::initLayout()
updateRunButton(false, "Loading UI", "Initialising user interface components...");

// Create the tabs
m_tabs["Energy Transfer"] = new ISISEnergyTransfer(this, m_uiForm.twIDRTabs->findChild<QWidget *>("loEnergyTransfer"));
m_tabs["Calibration"] = new ISISCalibration(this, m_uiForm.twIDRTabs->findChild<QWidget *>("loCalibration"));
m_tabs["Diagnostics"] = new ISISDiagnostics(this, m_uiForm.twIDRTabs->findChild<QWidget *>("loDiagnostics"));
m_tabs["ISIS Energy Transfer"] = new ISISEnergyTransfer(this, m_uiForm.twIDRTabs->findChild<QWidget *>("loISISEnergyTransfer"));
m_tabs["ISIS Calibration"] = new ISISCalibration(this, m_uiForm.twIDRTabs->findChild<QWidget *>("loISISCalibration"));
m_tabs["ISIS Diagnostics"] = new ISISDiagnostics(this, m_uiForm.twIDRTabs->findChild<QWidget *>("loISISDiagnostics"));
m_tabs["Transmission"] = new IndirectTransmission(this, m_uiForm.twIDRTabs->findChild<QWidget *>("loTransmission"));
m_tabs["Symmetrise"] = new IndirectSymmetrise(this, m_uiForm.twIDRTabs->findChild<QWidget *>("loSymmetrise"));
m_tabs["S(Q, w)"] = new IndirectSqw(this, m_uiForm.twIDRTabs->findChild<QWidget *>("loSofQW"));
Expand Down Expand Up @@ -152,6 +156,9 @@ void IndirectDataReduction::initLayout()

// Update the instrument configuration across the UI
m_uiForm.iicInstrumentConfiguration->newInstrumentConfiguration();

std::string facility = Mantid::Kernel::ConfigService::Instance().getString("default.facility");
filterUiForFacility(QString::fromStdString(facility));
}


Expand Down Expand Up @@ -203,28 +210,37 @@ Mantid::API::MatrixWorkspace_sptr IndirectDataReduction::loadInstrumentIfNotExis
{
std::string idfDirectory = Mantid::Kernel::ConfigService::Instance().getString("instrumentDefinition.directory");

std::string parameterFilename = idfDirectory + instrumentName + "_Definition.xml";
IAlgorithm_sptr loadAlg = AlgorithmManager::Instance().create("LoadEmptyInstrument");
loadAlg->setChild(true);
loadAlg->initialize();
loadAlg->setProperty("Filename", parameterFilename);
loadAlg->setProperty("OutputWorkspace", "__IDR_Inst");
loadAlg->execute();
MatrixWorkspace_sptr instWorkspace = loadAlg->getProperty("OutputWorkspace");

// Load the IPF if given an analyser and reflection
if(!analyser.empty() && !reflection.empty())
try
{
std::string ipfFilename = idfDirectory + instrumentName + "_" + analyser + "_" + reflection + "_Parameters.xml";
IAlgorithm_sptr loadParamAlg = AlgorithmManager::Instance().create("LoadParameterFile");
loadParamAlg->setChild(true);
loadParamAlg->initialize();
loadParamAlg->setProperty("Filename", ipfFilename);
loadParamAlg->setProperty("Workspace", instWorkspace);
loadParamAlg->execute();
}
std::string parameterFilename = idfDirectory + instrumentName + "_Definition.xml";
IAlgorithm_sptr loadAlg = AlgorithmManager::Instance().create("LoadEmptyInstrument");
loadAlg->setChild(true);
loadAlg->initialize();
loadAlg->setProperty("Filename", parameterFilename);
loadAlg->setProperty("OutputWorkspace", "__IDR_Inst");
loadAlg->execute();
MatrixWorkspace_sptr instWorkspace = loadAlg->getProperty("OutputWorkspace");

// Load the IPF if given an analyser and reflection
if(!analyser.empty() && !reflection.empty())
{
std::string ipfFilename = idfDirectory + instrumentName + "_" + analyser + "_" + reflection + "_Parameters.xml";
IAlgorithm_sptr loadParamAlg = AlgorithmManager::Instance().create("LoadParameterFile");
loadParamAlg->setChild(true);
loadParamAlg->initialize();
loadParamAlg->setProperty("Filename", ipfFilename);
loadParamAlg->setProperty("Workspace", instWorkspace);
loadParamAlg->execute();
}

return instWorkspace;
return instWorkspace;
}
catch(std::exception &ex)
{
g_log.error() << "Failed to load instrument with error: "
<< ex.what() << std::endl;
return NULL;
}
}


Expand Down Expand Up @@ -293,7 +309,9 @@ std::map<QString, QString> IndirectDataReduction::getInstrumentDetails()
catch(Mantid::Kernel::Exception::NotFoundError &nfe)
{
UNUSED_ARG(nfe);
g_log.warning() << "Could not find parameter " << *it << " in instrument " << instrumentName << std::endl;
g_log.warning() << "Could not find parameter " << *it
<< " in instrument " << instrumentName
<< std::endl;
}
}

Expand Down Expand Up @@ -335,7 +353,7 @@ void IndirectDataReduction::instrumentLoadingDone(bool error)
{
if(error)
{
g_log.error("Instument loading failed! (this can be caused by having both direct and indirect interfaces open)");
g_log.error("Instument loading failed!");
updateRunButton(false, "No Instrument", "No instrument is currently loaded.");
return;
}
Expand All @@ -357,14 +375,28 @@ void IndirectDataReduction::closeEvent(QCloseEvent* close)


/**
* Reloads settings if the default sata search or save directories have been changed.
* Handles configuration values being changed.
*
* Currently checks for data search paths and default facility.
*
* @param pNf Poco notification
*/
void IndirectDataReduction::handleDirectoryChange(Mantid::Kernel::ConfigValChangeNotification_ptr pNf)
void IndirectDataReduction::handleConfigChange(Mantid::Kernel::ConfigValChangeNotification_ptr pNf)
{
std::string key = pNf->key();
std::string value = pNf->curValue();

if(key == "datasearch.directories" || key == "defaultsave.directory")
{
readSettings();
}
else if(key == "default.facility")
{
QString facility = QString::fromStdString(value);

m_uiForm.iicInstrumentConfiguration->setFacility(facility);
filterUiForFacility(facility);
}
}


Expand Down Expand Up @@ -440,6 +472,42 @@ void IndirectDataReduction::saveSettings()
}


/**
* Filters the displayed tabs based on the current facility.
*
* @param facility Name of facility
*/
void IndirectDataReduction::filterUiForFacility(QString facility)
{
g_log.information() << "Facility selected: "
<< facility.toStdString()
<< std::endl;

QStringList enabledTabs;

// These tabs work at any facility
enabledTabs << "Transmission" << "Symmetrise" << "S(Q, w)" << "Moments";

// add facility specific tabs
if(facility == "ISIS")
enabledTabs << "ISIS Energy Transfer"
<< "ISIS Calibration"
<< "ISIS Diagnostics";

// Modify tabs as required
for(int i = 0; i < m_uiForm.twIDRTabs->count(); i++)
{
QString name = m_uiForm.twIDRTabs->tabText(i);
bool enabled = enabledTabs.contains(name);

m_uiForm.twIDRTabs->setTabEnabled(i, enabled);
m_tabs[name]->blockSignals(!enabled);

//TODO: handle instrument update connection
}
}


/**
* Handles showing the manage directory dialog box.
*/
Expand Down

0 comments on commit b5361fa

Please sign in to comment.