Skip to content

Commit

Permalink
Moved all grouping to Mask/Group tab. Re #6212.
Browse files Browse the repository at this point in the history
  • Loading branch information
mantid-roman committed Mar 21, 2013
1 parent de59bda commit a85ff04
Show file tree
Hide file tree
Showing 11 changed files with 355 additions and 257 deletions.
22 changes: 16 additions & 6 deletions Code/Mantid/MantidPlot/src/Mantid/InstrumentWidget/DetXMLFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,13 @@

#include <fstream>

/// Create a grouping file to extract all detectors in detector_list excluding those in dets
DetXMLFile::DetXMLFile(const std::vector<int>& detector_list, const QList<int>& dets, const QString& fname)
/**
* Create a grouping file to extract all detectors in detector_list excluding those in exclude.
* @param detector_list :: List of detector ids to include in the grouping file.
* @param exclude :: List of detector ids which if founfd in detector_list to be excluded from grouping.
* @param fname :: Name of the file to save the grouping to.
*/
DetXMLFile::DetXMLFile(const std::vector<int>& detector_list, const QList<int>& exclude, const QString& fname)
{
m_fileName = fname;
m_delete = false;
Expand All @@ -16,17 +21,19 @@ DetXMLFile::DetXMLFile(const std::vector<int>& detector_list, const QList<int>&
std::vector<int>::const_iterator idet = detector_list.begin();
for(; idet != detector_list.end(); ++idet)
{
if (!dets.contains(*idet))
if (!exclude.contains(*idet))
{
out << *idet << ',';
}
}
out << "\"/> </group> \n</detector-grouping>\n";
}

/// Create a grouping file to extract detectors in dets. Option List - one group - one detector,
/// Option Sum - one group which is a sum of the detectors
/// If fname is empty create a temporary file
/**
* Create a grouping file to extract detectors in dets. Option List - one group - one detector,
* Option Sum - one group which is a sum of the detectors
* If fname is empty create a temporary file
*/
DetXMLFile::DetXMLFile(const QList<int>& dets, Option opt, const QString& fname)
{
if (dets.empty())
Expand Down Expand Up @@ -81,6 +88,9 @@ void DetXMLFile::makeSumFile(const QList<int>& dets)
out << "\"/> </group> \n</detector-grouping>\n";
}

/**
* Destructor. Removes the temporary file.
*/
DetXMLFile::~DetXMLFile()
{
if (m_delete)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ class DetXMLFile
{
public:
enum Option {List,Sum};
/// Create a grouping file to extract all detectors in detector_list excluding those in dets
DetXMLFile(const std::vector<int>& detector_list, const QList<int>& dets, const QString& fname);
/// Create a grouping file to extract all detectors in detector_list excluding those in exclude
DetXMLFile(const std::vector<int>& detector_list, const QList<int>& exclude, const QString& fname);

/// Create a grouping file to extract detectors in dets. Option List - one group - one detector,
/// Option Sum - one group which is a sum of the detectors
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,24 +132,6 @@ InstrumentWindow::InstrumentWindow(const QString& wsName, const QString& label,
mDetTableAction = new QAction(tr("&Extract Data"), this);
connect(mDetTableAction, SIGNAL(triggered()), this, SLOT(showDetectorTable()));

mGroupDetsAction = new QAction(tr("&Group"), this);
connect(mGroupDetsAction, SIGNAL(triggered()), this, SLOT(groupDetectors()));

mMaskDetsAction = new QAction(tr("&Mask"), this);
connect(mMaskDetsAction, SIGNAL(triggered()), this, SLOT(maskDetectors()));

m_ExtractDetsToWorkspaceAction = new QAction("Extract to new workspace",this);
connect(m_ExtractDetsToWorkspaceAction,SIGNAL(activated()),this,SLOT(extractDetsToWorkspace()));

m_SumDetsToWorkspaceAction = new QAction("Sum to new workspace",this);
connect(m_SumDetsToWorkspaceAction,SIGNAL(activated()),this,SLOT(sumDetsToWorkspace()));

m_createIncludeGroupingFileAction = new QAction("Include",this);
connect(m_createIncludeGroupingFileAction,SIGNAL(activated()),this,SLOT(createIncludeGroupingFile()));

m_createExcludeGroupingFileAction = new QAction("Exclude",this);
connect(m_createExcludeGroupingFileAction,SIGNAL(activated()),this,SLOT(createExcludeGroupingFile()));

m_clearPeakOverlays = new QAction("Clear peaks",this);
connect(m_clearPeakOverlays,SIGNAL(activated()),this,SLOT(clearPeakOverlays()));

Expand Down Expand Up @@ -262,9 +244,9 @@ InstrumentWindowTab *InstrumentWindow::getTab()const
* @param filters :: The filters
* @param selectedFilter :: The selected filter.
*/
QString InstrumentWindow::getSaveFileName(const QString& title, const QString& filters, QString& selectedFilter)
QString InstrumentWindow::getSaveFileName(const QString& title, const QString& filters, QString *selectedFilter)
{
QString filename = MantidQt::API::FileDialogHandler::getSaveFileName(this, title, m_savedialog_dir, filters, &selectedFilter);
QString filename = MantidQt::API::FileDialogHandler::getSaveFileName(this, title, m_savedialog_dir, filters, selectedFilter);

// If its empty, they cancelled the dialog
if( !filename.isEmpty() )
Expand Down Expand Up @@ -449,23 +431,14 @@ void InstrumentWindow::changeColormap(const QString &filename)

void InstrumentWindow::showPickOptions()
{
if (/*m_pickTab->canUpdateTouchedDetector() &&*/ !m_selectedDetectors.empty())
if ( !m_selectedDetectors.empty() )
{
QMenu context(m_InstrumentDisplay);

context.addAction(mInfoAction);
context.addAction(mPlotAction);
context.addAction(mDetTableAction);

context.insertSeparator();
// context.addAction(mGroupDetsAction);
// context.addAction(mMaskDetsAction);
context.addAction(m_ExtractDetsToWorkspaceAction);
context.addAction(m_SumDetsToWorkspaceAction);
// QMenu *gfileMenu = context.addMenu("Create grouping file");
// gfileMenu->addAction(m_createIncludeGroupingFileAction);
// gfileMenu->addAction(m_createExcludeGroupingFileAction);

context.exec(QCursor::pos());
}
}
Expand Down Expand Up @@ -570,54 +543,6 @@ QString InstrumentWindow::confirmDetectorOperation(const QString & opName, const
return outputWS;
}

/**
* Group selected detectors
*/
void InstrumentWindow::groupDetectors()
{
if (m_selectedDetectors.empty()) return;
std::vector<int> wksp_indices;
for(int i = 0; i < m_selectedDetectors.size(); ++i)
{
try {
wksp_indices.push_back(int(m_instrumentActor->getWorkspaceIndex(m_selectedDetectors[i])));
} catch (Mantid::Kernel::Exception::NotFoundError &) {
continue; // Detector doesn't have a workspace index relating to it
}
}

QString inputWS = m_workspaceName;
QString outputWS = confirmDetectorOperation("grouped", inputWS, static_cast<int>(m_selectedDetectors.size()));
if( outputWS.isEmpty() ) return;
QString param_list = "InputWorkspace=%1;OutputWorkspace=%2;WorkspaceIndexList=%3;KeepUngroupedSpectra=1";
emit execMantidAlgorithm("GroupDetectors",
param_list.arg(inputWS, outputWS, asString(wksp_indices)),
this
);
}

/**
* Mask selected detectors
*/
void InstrumentWindow::maskDetectors()
{
if (m_selectedDetectors.empty()) return;
std::vector<int> wksp_indices;
for(int i = 0; i < m_selectedDetectors.size(); ++i)
{
try {
wksp_indices.push_back(int(m_instrumentActor->getWorkspaceIndex(m_selectedDetectors[i])));
} catch (Mantid::Kernel::Exception::NotFoundError &) {
continue; // Detector doesn't have a workspace index relating to it
}
}

QString inputWS = m_workspaceName;
// Masking can only replace the input workspace so no need to ask for confirmation
QString param_list = "Workspace=%1;WorkspaceIndexList=%2";
emit execMantidAlgorithm("MaskDetectors",param_list.arg(inputWS, asString(wksp_indices)),this);
}

/**
* Convert a list of integers to a comma separated string of numbers
*/
Expand Down Expand Up @@ -711,7 +636,7 @@ void InstrumentWindow::saveImage()
}
}
QString selectedFilter = "*.png";
QString filename = getSaveFileName("Save image ...", filter, selectedFilter);
QString filename = getSaveFileName("Save image ...", filter, &selectedFilter);

// If its empty, they cancelled the dialog
if( filename.isEmpty() ) return;
Expand Down Expand Up @@ -964,67 +889,6 @@ void InstrumentWindow::componentSelected(ComponentID id)
}
}

/**
* Extract selected detectors to a new workspace
*/
void InstrumentWindow::extractDetsToWorkspace()
{
QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
DetXMLFile mapFile(m_selectedDetectors);
std::string fname = mapFile();

if (!fname.empty())
{
Mantid::API::IAlgorithm* alg = Mantid::API::FrameworkManager::Instance().createAlgorithm("GroupDetectors");
alg->setPropertyValue("InputWorkspace",m_workspaceName.toStdString());
alg->setPropertyValue("MapFile",fname);
alg->setPropertyValue("OutputWorkspace",m_workspaceName.toStdString()+"_selection");
alg->execute();
}

QApplication::restoreOverrideCursor();
}

/**
* Sum selected detectors to a new workspace
*/
void InstrumentWindow::sumDetsToWorkspace()
{
QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
DetXMLFile mapFile(m_selectedDetectors,DetXMLFile::Sum);
std::string fname = mapFile();

if (!fname.empty())
{
Mantid::API::IAlgorithm* alg = Mantid::API::FrameworkManager::Instance().createAlgorithm("GroupDetectors");
alg->setPropertyValue("InputWorkspace",m_workspaceName.toStdString());
alg->setPropertyValue("MapFile",fname);
alg->setPropertyValue("OutputWorkspace",m_workspaceName.toStdString()+"_sum");
alg->execute();
}

QApplication::restoreOverrideCursor();
}

void InstrumentWindow::createIncludeGroupingFile()
{
QString fname = MantidQt::API::FileDialogHandler::getSaveFileName(this,"Save grouping file");
if (!fname.isEmpty())
{
DetXMLFile mapFile(m_selectedDetectors,DetXMLFile::Sum,fname);
}

}

void InstrumentWindow::createExcludeGroupingFile()
{
QString fname = MantidQt::API::FileDialogHandler::getSaveFileName(this,"Save grouping file");
if (!fname.isEmpty())
{
DetXMLFile mapFile(m_instrumentActor->getAllDetIDs(),m_selectedDetectors,fname);
}
}

void InstrumentWindow::executeAlgorithm(const QString& alg_name, const QString& param_list)
{
emit execMantidAlgorithm(alg_name,param_list,this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ class InstrumentWindow : public MdiSubWindow, public MantidQt::API::WorkspaceObs
void selectTab(Tab tab){selectTab(int(tab));}
InstrumentWindowTab *getTab()const;
/// Get a filename for saving
QString getSaveFileName(const QString& title, const QString& filters, QString& selectedFilter);
QString getSaveFileName(const QString& title, const QString& filters, QString* selectedFilter = NULL);

signals:
void enableLighting(bool);
Expand Down Expand Up @@ -129,16 +129,9 @@ public slots:
void spectraInfoDialog();
void plotSelectedSpectra();
void showDetectorTable();
void groupDetectors();
void maskDetectors();
void executeAlgorithm(const QString&, const QString&);
void executeAlgorithm(Mantid::API::IAlgorithm_sptr);

void extractDetsToWorkspace();
void sumDetsToWorkspace();
void createIncludeGroupingFile();
void createExcludeGroupingFile();

void setupColorMap();
void changeColormap(const QString & filename = "");
void changeScaleType(int);
Expand Down Expand Up @@ -203,15 +196,7 @@ private slots:
SimpleWidget* m_simpleDisplay;

// Actions for the pick menu
QAction *mInfoAction, *mPlotAction, *mDetTableAction, *mGroupDetsAction, *mMaskDetsAction;
/// Extract selected detector ids to a new workspace
QAction *m_ExtractDetsToWorkspaceAction;
/// Sum selected detectors to a new workspace
QAction *m_SumDetsToWorkspaceAction;
/// Create grouping xml file which includes selected detectors
QAction *m_createIncludeGroupingFileAction;
/// Create grouping xml file which excludes selected detectors
QAction *m_createExcludeGroupingFileAction;
QAction *mInfoAction, *mPlotAction, *mDetTableAction;
// Context menu actions
QAction *m_clearPeakOverlays;

Expand Down

0 comments on commit a85ff04

Please sign in to comment.