Skip to content

Commit

Permalink
Added instrument name to grouping output,
Browse files Browse the repository at this point in the history
open save dialog either in the user save directory or the last used
for saving files from the instruemnt view. Re #6130.
  • Loading branch information
mantid-roman authored and abuts committed Mar 22, 2013
1 parent 88e1a77 commit 8eb9a62
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -718,6 +718,24 @@ void InstrumentWindow::saveImage()
m_InstrumentDisplay->saveToFile(filename);
}

/**
* Use the file dialog to select a filename to save grouping.
*/
QString InstrumentWindow::getSaveGroupingFilename()
{
QString filename = MantidQt::API::FileDialogHandler::getSaveFileName(this, "Save grouping file", m_savedialog_dir, "Grouping (*.xml);;All files (*.*)");

// If its empty, they cancelled the dialog
if( !filename.isEmpty() )
{
//Save the directory used
QFileInfo finfo(filename);
m_savedialog_dir = finfo.dir().path();
}

return filename;
}

///**
// * Update the text display that informs the user of the current mode and details about it
// */
Expand Down Expand Up @@ -951,19 +969,23 @@ 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)
DetXMLFile(const std::string& instrName, const std::vector<int>& detector_list, const QList<int>& dets, const QString& fname)
{
m_instrName = instrName;
m_fileName = fname;
m_delete = false;
std::ofstream out(m_fileName.toStdString().c_str());
out << "<?xml version=\"1.0\" encoding=\"UTF-8\" ?> \n<detector-grouping> \n";
out << "<?xml version=\"1.0\" encoding=\"UTF-8\" ?> \n<detector-grouping instrument=\"" << m_instrName << "\"> \n";
out << "<group name=\"sum\"> <detids val=\"";
std::vector<int>::const_iterator idet = detector_list.begin();
bool first = true;
for(; idet != detector_list.end(); ++idet)
{
if (!dets.contains(*idet))
{
out << *idet << ',';
if ( !first ) out << ',';
out << *idet ;
first = false;
}
}
out << "\"/> </group> \n</detector-grouping>\n";
Expand All @@ -972,14 +994,15 @@ class DetXMLFile
/// 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(const QList<int>& dets, Option opt = List, const QString& fname = "")
DetXMLFile(const std::string& instrName, const QList<int>& dets, Option opt = List, const QString& fname = "")
{
if (dets.empty())
{
m_fileName = "";
return;
}

m_instrName = instrName;
if (fname.isEmpty())
{
QTemporaryFile mapFile;
Expand All @@ -1006,7 +1029,7 @@ class DetXMLFile
void makeListFile(const QList<int>& dets)
{
std::ofstream out(m_fileName.toStdString().c_str());
out << "<?xml version=\"1.0\" encoding=\"UTF-8\" ?> \n<detector-grouping> \n";
out << "<?xml version=\"1.0\" encoding=\"UTF-8\" ?> \n<detector-grouping instrument=\"" << m_instrName << "\"> \n";
foreach(int det,dets)
{
out << "<group name=\"" << det << "\"> <detids val=\"" << det << "\"/> </group> \n";
Expand All @@ -1018,11 +1041,13 @@ class DetXMLFile
void makeSumFile(const QList<int>& dets)
{
std::ofstream out(m_fileName.toStdString().c_str());
out << "<?xml version=\"1.0\" encoding=\"UTF-8\" ?> \n<detector-grouping> \n";
out << "<?xml version=\"1.0\" encoding=\"UTF-8\" ?> \n<detector-grouping instrument=\"" << m_instrName << "\"> \n";
out << "<group name=\"sum\"> <detids val=\"";
int first_det = dets[0];
foreach(int det,dets)
{
out << det << ',';
if ( det != first_det ) out << ',';
out << det;
}
out << "\"/> </group> \n</detector-grouping>\n";
}
Expand All @@ -1040,8 +1065,9 @@ class DetXMLFile
const std::string operator()()const{return m_fileName.toStdString();}

private:
QString m_fileName; ///< holds the grouping file name
bool m_delete; ///< if true delete the file on destruction
std::string m_instrName; ///< the instrument name
QString m_fileName; ///< holds the grouping file name
bool m_delete; ///< if true delete the file on destruction
};

/**
Expand All @@ -1050,7 +1076,7 @@ class DetXMLFile
void InstrumentWindow::extractDetsToWorkspace()
{
QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
DetXMLFile mapFile(m_selectedDetectors);
DetXMLFile mapFile(m_instrumentActor->getInstrument()->getName(), m_selectedDetectors);
std::string fname = mapFile();

if (!fname.empty())
Expand All @@ -1071,7 +1097,7 @@ void InstrumentWindow::extractDetsToWorkspace()
void InstrumentWindow::sumDetsToWorkspace()
{
QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
DetXMLFile mapFile(m_selectedDetectors,DetXMLFile::Sum);
DetXMLFile mapFile(m_instrumentActor->getInstrument()->getName(), m_selectedDetectors,DetXMLFile::Sum);
std::string fname = mapFile();

if (!fname.empty())
Expand All @@ -1088,20 +1114,20 @@ void InstrumentWindow::sumDetsToWorkspace()

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

}

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,8 @@ private slots:
void selectOpenGLDisplay(bool yes);
/// Set the surface type.
void setSurfaceType(const QString& typeStr);
/// Return a filename to save a grouping to
QString getSaveGroupingFilename();

// GUI elements
QLabel* mInteractionInfo;
Expand Down

0 comments on commit 8eb9a62

Please sign in to comment.