Skip to content

Commit

Permalink
refs #4328 Functionality for setting the UB Matrix
Browse files Browse the repository at this point in the history
  • Loading branch information
OwenArnold committed Jan 3, 2012
1 parent 0a96987 commit d30a861
Show file tree
Hide file tree
Showing 11 changed files with 187 additions and 50 deletions.
1 change: 1 addition & 0 deletions Code/Mantid/MantidQt/CustomInterfaces/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ set ( SRC_FILES
src/background.cpp
src/deltaECalc.cpp
src/WorkspaceInADS.cpp
src/WorkspaceMemento.cpp
src/WorkspaceOnDisk.cpp
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,12 @@ namespace MantidQt

void addFileClicked();

void setUBMatrixClicked();

void removeSelectedClicked();

void findUBMatrixClicked();

private:
Ui::CreateMDWorkspace m_uiForm;
WorkspaceMementoCollection m_data;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="toolTip">
<string>Add a raw file</string>
</property>
<property name="text">
<string>Add Raw File</string>
</property>
Expand All @@ -52,6 +55,9 @@
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="toolTip">
<string>Remove any workspace once it is highlighted</string>
</property>
<property name="text">
<string>Remove Selected</string>
</property>
Expand Down Expand Up @@ -93,7 +99,7 @@
</sizepolicy>
</property>
<property name="selectionMode">
<enum>QAbstractItemView::MultiSelection</enum>
<enum>QAbstractItemView::SingleSelection</enum>
</property>
<property name="selectionBehavior">
<enum>QAbstractItemView::SelectRows</enum>
Expand Down Expand Up @@ -141,7 +147,22 @@
<property name="title">
<string>UB Matrix</string>
</property>
<layout class="QHBoxLayout" name="horizontalLayout_5"/>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QPushButton" name="btn_set_ub_matrix">
<property name="text">
<string>Set UB Matrix</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="btn_find_ub_matrix">
<property name="text">
<string>Find UB Matrix</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
</layout>
Expand All @@ -159,7 +180,6 @@
<property name="title">
<string>Goniometer Settings</string>
</property>
<zorder>tableView</zorder>
</widget>
</item>
</layout>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,18 @@ namespace MantidQt
*/
virtual Mantid::API::MatrixWorkspace_sptr fetchIt() const;

virtual std::string statusReport() const;
/*
Do nothing clean-up method.
*/
virtual void cleanUp()
{
}

/// Destructor
virtual ~WorkspaceInADS();
private:
/// Id/name of the workspace in the ADS
std::string m_wsName;
/// Status report message.
std::string m_statusReportMessage;
};

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ namespace MantidQt
class DLLExport WorkspaceMemento
{
public:
//Status enumeration type.
enum Status{NoOrientedLattice=0, Ready};

/// Constructor for the workspace memento.
WorkspaceMemento();
/**
Getter for the id of the workspace
@return the id of the workspace
Expand All @@ -66,7 +71,15 @@ namespace MantidQt
/**
Generates a status report based on the workspace state.
*/
virtual std::string statusReport() const = 0;
std::string statusReport()
{
return m_statusReport;
}
/// Perform any clean up operations of the underlying workspace
virtual void cleanUp() = 0;
/// Sets the status report overrideing it with the provided message.
void setReport(const Status status);

/// Destructor
virtual ~WorkspaceMemento(){};

Expand All @@ -76,19 +89,15 @@ namespace MantidQt
Common implementation of report generation.
@param ws : workspace to report on.
*/
std::string generateReport(Mantid::API::MatrixWorkspace_sptr ws)
{
std::string msg;
if(!ws->sample().hasOrientedLattice())
{
msg = "Has no Oriented Lattice";
}
else
{
msg = "Ready!";
}
return msg;
}
void generateReport(Mantid::API::MatrixWorkspace_sptr ws);

private:

/// Extract a friendly status.
void interpretStatus(const Status arg);

/// Status report.
std::string m_statusReport;

};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,18 +58,17 @@ namespace MantidQt
@throw if workspace has been moved since instantiation.
*/
virtual Mantid::API::MatrixWorkspace_sptr fetchIt() const;

virtual std::string statusReport() const;

///Clean-up operations
virtual void cleanUp();
/// Destructor
virtual ~WorkspaceOnDisk();
private:
/// Helper method to delete a workspace out of memory after loading.
void dumpIt(const std::string& name);
/// Path + name of file containing workspace to use.
std::string m_fileName;
/// Status report message.
std::string m_statusReportMessage;
// Id of the workspace in the ADS.
std::string m_adsID;
};

}
Expand Down
46 changes: 46 additions & 0 deletions Code/Mantid/MantidQt/CustomInterfaces/src/CreateMDWorkspace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,56 @@ void CreateMDWorkspace::initLayout()
connect(m_uiForm.btn_add_workspace, SIGNAL(clicked()), this, SLOT(addWorkspaceClicked()));
connect(m_uiForm.btn_add_file, SIGNAL(clicked()), this, SLOT(addFileClicked()));
connect(m_uiForm.btn_remove_workspace, SIGNAL(clicked()), this, SLOT(removeSelectedClicked()));
connect(m_uiForm.btn_set_ub_matrix, SIGNAL(clicked()), this, SLOT(setUBMatrixClicked()));
connect(m_uiForm.btn_find_ub_matrix, SIGNAL(clicked()), this, SLOT(findUBMatrixClicked()));
//Set MVC Model
m_uiForm.tableView->setModel(m_model);
}

void CreateMDWorkspace::findUBMatrixClicked()
{
runConfirmation("Not yet implemented!");
}

/*
Event handler for setting the UB Matrix
*/
void CreateMDWorkspace::setUBMatrixClicked()
{
QTableView* view = m_uiForm.tableView;
QModelIndexList indexes = view->selectionModel()->selection().indexes();
if(indexes.size() > 0)
{
int index = indexes.front().row();
WorkspaceMemento_sptr memento = m_data[index];
Mantid::API::MatrixWorkspace_sptr ws = memento->fetchIt();
std::string id = memento->getId();
std::string command = "SetUBDialog(Workspace='" + id + "')";

QString pyInput =
"from mantidsimple import *\n"
"import sys\n"
"try:\n"
" SetUBDialog(Workspace='%1')\n"
" print 1\n"
"except:\n"
" print 0\n";

pyInput = pyInput.arg(QString(id.c_str()));
QString pyOutput = runPythonCode(pyInput).trimmed();

if ( pyOutput == "1" )
{
memento->setReport(WorkspaceMemento::Ready);
m_model->update();
}
}
else
{
runConfirmation("Nothing selected");
}
}

/*
Add a workspace from the ADS
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,4 +87,4 @@ namespace CustomInterfaces
}

}
}
}
14 changes: 3 additions & 11 deletions Code/Mantid/MantidQt/CustomInterfaces/src/WorkspaceInADS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,11 @@ namespace MantidQt
{
throw std::invalid_argument("WorkspaceInADS:: Workspace is not a matrix workspace : " + wsName );
}
//Generate an initial report.
m_statusReportMessage = generateReport(ws);
generateReport(ws);
}



/**
Getter for the id of the workspace
@return the id of the workspace
Expand Down Expand Up @@ -53,15 +54,6 @@ namespace MantidQt
return Mantid::API::AnalysisDataService::Instance().doesExist(m_wsName);
}

/**
Gets a friendly status report on the state of the workspace memento.
@return a formatted string containing the report.
*/
std::string WorkspaceInADS::statusReport() const
{
return m_statusReportMessage;
}

/**
Getter for the workspace itself
@returns the matrix workspace
Expand Down
57 changes: 57 additions & 0 deletions Code/Mantid/MantidQt/CustomInterfaces/src/WorkspaceMemento.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#include "MantidQtCustomInterfaces/WorkspaceMemento.h"

namespace MantidQt
{
namespace CustomInterfaces
{
/// Constructor
WorkspaceMemento::WorkspaceMemento()
{
}

/**
Common implementation of report generation.
@param ws : workspace to report on.
*/
void WorkspaceMemento::generateReport(Mantid::API::MatrixWorkspace_sptr ws)
{
Status status;
if(!ws->sample().hasOrientedLattice())
{
status = NoOrientedLattice;
}
else
{
status = Ready;
}
interpretStatus(status);
}

/*
Setter for the status report.
*/
void WorkspaceMemento::setReport(const Status status)
{
interpretStatus(status);
}

/*
Helper method for extracting friendly messages from status enum.
Single point for providing messages.
*/
void WorkspaceMemento::interpretStatus(const Status status)
{
std::string msg;
if(status == NoOrientedLattice)
{
msg = "Has no Oriented Lattice";
}
else
{
msg = "Ready!";
}
m_statusReport = msg;
}

}
}

0 comments on commit d30a861

Please sign in to comment.