Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/feature/6212_grouping_functions_…
Browse files Browse the repository at this point in the history
…in_mask_tab' Refs #6212

Conflicts:
	Code/Mantid/MantidPlot/src/Mantid/InstrumentWidget/InstrumentWindow.cpp
  • Loading branch information
martyngigg committed Apr 5, 2013
2 parents 2961eeb + cb82c1c commit 314f706
Show file tree
Hide file tree
Showing 19 changed files with 605 additions and 401 deletions.
2 changes: 2 additions & 0 deletions Code/Mantid/MantidPlot/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,7 @@ set ( MANTID_SRCS src/Mantid/AbstractMantidLog.cpp
src/Mantid/InstrumentWidget/Shape2DCollection.cpp
src/Mantid/InstrumentWidget/SimpleWidget.cpp
src/Mantid/InstrumentWidget/Viewport.cpp
src/Mantid/InstrumentWidget/DetXMLFile.cpp
)

###########################################################################
Expand Down Expand Up @@ -457,6 +458,7 @@ set ( MANTID_HDRS src/Mantid/AbstractMantidLog.h
src/Mantid/InstrumentWidget/Shape2DCollection.h
src/Mantid/InstrumentWidget/SimpleWidget.h
src/Mantid/InstrumentWidget/Viewport.h
src/Mantid/InstrumentWidget/DetXMLFile.h
)

###########################################################################
Expand Down
102 changes: 102 additions & 0 deletions Code/Mantid/MantidPlot/src/Mantid/InstrumentWidget/DetXMLFile.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
#include "DetXMLFile.h"

#include <QTemporaryFile>
#include <QDir>

#include <fstream>

/**
* 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;
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 (!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
*/
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";
}

/**
* Destructor. Removes the temporary file.
*/
DetXMLFile::~DetXMLFile()
{
if (m_delete)
{
QDir dir;
dir.remove(m_fileName);
}
}

43 changes: 43 additions & 0 deletions Code/Mantid/MantidPlot/src/Mantid/InstrumentWidget/DetXMLFile.h
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 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
/// 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
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,12 @@
GLActorCollection::GLActorCollection()
:GLActor(),
m_minBound(DBL_MAX,DBL_MAX,DBL_MAX),
m_maxBound(-DBL_MAX,-DBL_MAX,-DBL_MAX),
m_displayListId(0),
m_useDisplayList(false)
m_maxBound(-DBL_MAX,-DBL_MAX,-DBL_MAX)
{
m_displayListId[0] = 0;
m_displayListId[1] = 0;
m_useDisplayList[0] = false;
m_useDisplayList[1] = false;
}

GLActorCollection::~GLActorCollection()
Expand All @@ -26,10 +28,13 @@ GLActorCollection::~GLActorCollection()
delete (*i);
}
mActorsList.clear();
if(m_displayListId != 0)
{
glDeleteLists(m_displayListId,1);
}
for(size_t i = 0; i < 2; ++i)
{
if (m_displayListId[i] != 0)
{
glDeleteLists(m_displayListId[i],1);
}
}

}

Expand All @@ -38,37 +43,31 @@ GLActorCollection::~GLActorCollection()
*/
void GLActorCollection::draw(bool picking)const
{
if (!isVisible()) return;
OpenGLError::check("GLActorCollection::draw(0)");
if (picking)
{
drawGL(picking);
}
else
{
if (m_useDisplayList)
if (!isVisible()) return;
OpenGLError::check("GLActorCollection::draw(0)");
size_t i = picking? 1 : 0;
if (m_useDisplayList[i])
{
glCallList(m_displayListId);
glCallList(m_displayListId[i]);
}
else if (m_displayListId == 0)
else if (m_displayListId[i] == 0)
{
m_displayListId = glGenLists(1);
m_displayListId[i] = glGenLists(1);
// child actors can also create display lists, so delay
// until all the children have finished making theirs
drawGL(picking);
}
else
{
m_useDisplayList = true;
glNewList(m_displayListId,GL_COMPILE); //Construct display list for object representation
m_useDisplayList[i] = true;
glNewList(m_displayListId[i],GL_COMPILE); //Construct display list for object representation
drawGL(picking);
glEndList();
if(glGetError()==GL_OUT_OF_MEMORY) //Throw an exception
throw Mantid::Kernel::Exception::OpenGLError("OpenGL: Out of video memory");
glCallList(m_displayListId);
glCallList(m_displayListId[i]);
}
}
OpenGLError::check("GLActorCollection::draw()");
OpenGLError::check("GLActorCollection::draw()");
}

void GLActorCollection::drawGL(bool picking )const
Expand Down Expand Up @@ -168,11 +167,14 @@ void GLActorCollection::getBoundingBox(Mantid::Kernel::V3D& minBound,Mantid::Ker

void GLActorCollection::invalidateDisplayList()const
{
if(m_displayListId != 0)
for(size_t i = 0; i < 2; ++i)
{
glDeleteLists(m_displayListId,1);
m_displayListId = 0;
m_useDisplayList = false;
if (m_displayListId[i] != 0)
{
glDeleteLists(m_displayListId[i],1);
m_displayListId[i] = 0;
m_useDisplayList[i] = false;
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ class GLActorCollection: public GLActor
mutable std::vector<GLActor*> mActorsList; ///< Vector of GLActors for fast access.
Mantid::Kernel::V3D m_minBound;
Mantid::Kernel::V3D m_maxBound;
mutable GLuint m_displayListId;
mutable bool m_useDisplayList;
mutable GLuint m_displayListId[2];
mutable bool m_useDisplayList[2];
};


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ void InputController3DMove::mouseMoveEvent(QMouseEvent *event)
void InputController3DMove::mouseReleaseEvent(QMouseEvent *)
{
m_isButtonPressed = false;
emit finish();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ class InputController3DMove: public InputController
void rotate(int x, int y);
/// Translate
void translate(int x, int y);
/// Finish movement
void finish();

private:
bool m_isButtonPressed;
Expand Down

0 comments on commit 314f706

Please sign in to comment.