-
Notifications
You must be signed in to change notification settings - Fork 122
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Moving grouping functionality to Mask/Group tab.
Re #6212.
- Loading branch information
1 parent
14c136e
commit de59bda
Showing
7 changed files
with
202 additions
and
111 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
92 changes: 92 additions & 0 deletions
92
Code/Mantid/MantidPlot/src/Mantid/InstrumentWidget/DetXMLFile.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
#include "DetXMLFile.h" | ||
|
||
#include <QTemporaryFile> | ||
#include <QDir> | ||
|
||
#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) | ||
{ | ||
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 << "<group name=\"sum\"> <detids val=\""; | ||
std::vector<int>::const_iterator idet = detector_list.begin(); | ||
for(; idet != detector_list.end(); ++idet) | ||
{ | ||
if (!dets.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 | ||
DetXMLFile::DetXMLFile(const QList<int>& dets, Option opt, const QString& fname) | ||
{ | ||
if (dets.empty()) | ||
{ | ||
m_fileName = ""; | ||
return; | ||
} | ||
|
||
if (fname.isEmpty()) | ||
{ | ||
QTemporaryFile mapFile; | ||
mapFile.open(); | ||
m_fileName = mapFile.fileName() + ".xml"; | ||
mapFile.close(); | ||
m_delete = true; | ||
} | ||
else | ||
{ | ||
m_fileName = fname; | ||
m_delete = false; | ||
} | ||
|
||
switch(opt) | ||
{ | ||
case Sum: makeSumFile(dets); break; | ||
case List: makeListFile(dets); break; | ||
} | ||
} | ||
|
||
/// Make grouping file where each detector is put into its own group | ||
void DetXMLFile::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"; | ||
foreach(int det,dets) | ||
{ | ||
out << "<group name=\"" << det << "\"> <detids val=\"" << det << "\"/> </group> \n"; | ||
} | ||
out << "</detector-grouping>\n"; | ||
} | ||
|
||
/// Make grouping file for putting the detectors into one group (summing the detectors) | ||
void DetXMLFile::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 << "<group name=\"sum\"> <detids val=\""; | ||
foreach(int det,dets) | ||
{ | ||
out << det << ','; | ||
} | ||
out << "\"/> </group> \n</detector-grouping>\n"; | ||
} | ||
|
||
DetXMLFile::~DetXMLFile() | ||
{ | ||
if (m_delete) | ||
{ | ||
QDir dir; | ||
dir.remove(m_fileName); | ||
} | ||
} | ||
|
43 changes: 43 additions & 0 deletions
43
Code/Mantid/MantidPlot/src/Mantid/InstrumentWidget/DetXMLFile.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
#ifndef DETXMLFILE_H | ||
#define DETXMLFILE_H | ||
|
||
#include <QString> | ||
#include <QList> | ||
|
||
#include <vector> | ||
|
||
/** | ||
A class for creating grouping xml files | ||
*/ | ||
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 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 = ""); | ||
|
||
/// Destructor | ||
~DetXMLFile(); | ||
|
||
/// Make grouping file where each detector is put into its own group | ||
void makeListFile(const QList<int>& dets); | ||
|
||
/// Make grouping file for putting the detectors into one group (summing the detectors) | ||
void makeSumFile(const QList<int>& dets); | ||
|
||
/// Return the name of the created grouping file | ||
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 | ||
}; | ||
|
||
#endif // DETXMLFILE_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.