Skip to content

Commit

Permalink
refs #7664. Update the UI components for new behaviour.
Browse files Browse the repository at this point in the history
This hooks the UI into the new algorithms. The menu will now use HasUB to determine if the workspace has any UB matrixes, and update the clear options appropriately, this includes handling of workspace types that are not compatible with ExperimentInfo, such as table workspace. The Clear UB option is disabled until HasUB reports otherwise. The Clear UB option should execute the ClearUB algorithm.
  • Loading branch information
OwenArnold committed Aug 22, 2013
1 parent adc211a commit f14b52f
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 11 deletions.
8 changes: 6 additions & 2 deletions Code/Mantid/MantidPlot/src/Mantid/MantidDock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -546,10 +546,14 @@ void MantidDockWidget::addTableWorkspaceMenuItems(QMenu * menu) const
/**
* Add menu for clearing workspace items.
* @param menu : Parent menu.
* @param wsName : Name of the selected workspace.
*/
void MantidDockWidget::addClearMenuItems(QMenu* menu)
void MantidDockWidget::addClearMenuItems(QMenu* menu, const QString& wsName)
{
QMenu* clearMenu = new QMenu(tr("Clear Options"), this);

m_clearUB->setEnabled( m_mantidUI->hasUB(wsName) );

clearMenu->addAction(m_clearUB);
menu->addMenu(clearMenu);
}
Expand Down Expand Up @@ -842,7 +846,7 @@ void MantidDockWidget::popupMenu(const QPoint & pos)
{
addTableWorkspaceMenuItems(menu);
}
addClearMenuItems(menu);
addClearMenuItems(menu, selectedWsName);

//Get the names of the programs for the send to option
std::vector<std::string> programNames = (Mantid::Kernel::ConfigService::Instance().getKeys("workspace.sendto.name"));
Expand Down
2 changes: 1 addition & 1 deletion Code/Mantid/MantidPlot/src/Mantid/MantidDock.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ private slots:
void addPeaksWorkspaceMenuItems(QMenu *menu, const Mantid::API::IPeaksWorkspace_const_sptr & WS) const;
void addWorkspaceGroupMenuItems(QMenu *menu) const;
void addTableWorkspaceMenuItems(QMenu * menu) const;
void addClearMenuItems(QMenu* menu);
void addClearMenuItems(QMenu* menu, const QString& wsName);

void excludeItemFromSort(MantidTreeWidgetItem *item);

Expand Down
54 changes: 46 additions & 8 deletions Code/Mantid/MantidPlot/src/Mantid/MantidUI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1493,28 +1493,66 @@ void MantidUI::copyWorkspacestoVector(const QList<QTreeWidgetItem*> &selectedIt
}

/**
* Clears the UB from the selected workspace
* @param wsName :: selected workspace name
*/
* Determine if the workspace has one or more UB matrixes on one of it's samples.
* @param wsName
* @return True if present
*/
bool MantidUI::hasUB(const QString& wsName)
{
const std::string algName("HasUB");
const int version = -1;
Mantid::API::IAlgorithm_sptr alg;
try
{
alg = Mantid::API::AlgorithmManager::Instance().create(algName);
} catch (...)
{
QMessageBox::critical(appWindow(), "MantidPlot - Algorithm error",
"Cannot create algorithm " + QString::fromStdString(algName) + " version "
+ QString::number(version));
return false;
}
if (!alg)
{
return false;
}

alg->setPropertyValue("Workspace", wsName.toStdString());
executeAlgorithmAsync(alg, true);

bool hasUB = alg->getProperty("HasUB");
return hasUB;
}

/**
* Clears the UB from the selected workspace
* @param wsName :: selected workspace name
*/
void MantidUI::clearUB(const QStringList& wsName)
{
const std::string algName("ClearUB");
const int version = -1;
for(int i = 0; i < wsName.size(); ++i)
for (int i = 0; i < wsName.size(); ++i)
{
Mantid::API::IAlgorithm_sptr alg;
try
{
alg = Mantid::API::AlgorithmManager::Instance().create(algName, version);
}
catch(...)
catch (...)
{
QMessageBox::critical(appWindow(),"MantidPlot - Algorithm error","Cannot create algorithm "+QString::fromStdString(algName)+" version "+QString::number(version));
QMessageBox::critical(appWindow(), "MantidPlot - Algorithm error",
"Cannot create algorithm " + QString::fromStdString(algName) + " version "
+ QString::number(version));
return;
}
alg->initialize();
if (!alg)
{
return;
}

alg->setPropertyValue("Workspace", wsName[i].toStdString());
alg->execute();
executeAlgorithmAsync(alg);
}
}

Expand Down
2 changes: 2 additions & 0 deletions Code/Mantid/MantidPlot/src/Mantid/MantidUI.h
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,8 @@ public slots:
Table* createDetectorTable(const QString & wsName, const Mantid::API::IPeaksWorkspace_sptr & ws);


// Determine whether the workspace has a UB matrix
bool hasUB(const QString& wsName);
// Clear the UB via the ClearUB algorithm
void clearUB(const QStringList& workspaces);
// ***** ***** //
Expand Down

0 comments on commit f14b52f

Please sign in to comment.