Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into 11187_threadsanitizer
Browse files Browse the repository at this point in the history
  • Loading branch information
quantumsteve committed May 6, 2015
2 parents a76d46b + e0f235d commit 49fab8b
Show file tree
Hide file tree
Showing 58 changed files with 7,988 additions and 263 deletions.
5 changes: 2 additions & 3 deletions Code/Mantid/Framework/DataHandling/src/DownloadFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,7 @@ const std::string DownloadFile::summary() const {
void DownloadFile::init() {
declareProperty("Address", "",
boost::make_shared<MandatoryValidator<std::string>>(),
"The address of the network resource to download. This "
"should start http:// or https:// .",
"The address of the network resource to download.",
Direction::InOut);
declareProperty(new FileProperty("Filename", "", FileProperty::Save),
"The filename to save the download to.");
Expand All @@ -83,4 +82,4 @@ void DownloadFile::exec() {
}

} // namespace DataHandling
} // namespace Mantid
} // namespace Mantid
3 changes: 2 additions & 1 deletion Code/Mantid/Framework/Properties/Mantid.properties.template
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ default.facility = ISIS
default.instrument =

# Set of PyQt interfaces to add to the Interfaces menu, separated by a space. Interfaces are seperated from their respective categories by a "/".
mantidqt.python_interfaces = Direct/DGS_Reduction.py Direct/DGSPlanner.py SANS/ORNL_SANS.py Reflectometry/REFL_Reduction.py Reflectometry/REFL_SF_Calculator.py Reflectometry/REFM_Reduction.py Utility/TofConverter.py Reflectometry/ISIS_Reflectometry.py Diffraction/Powder_Diffraction_Reduction.py Utility/FilterEvents.py
mantidqt.python_interfaces = Direct/DGS_Reduction.py Direct/DGSPlanner.py SANS/ORNL_SANS.py Reflectometry/REFL_Reduction.py Reflectometry/REFL_SF_Calculator.py Reflectometry/REFM_Reduction.py Utility/TofConverter.py Reflectometry/ISIS_Reflectometry.py Diffraction/Powder_Diffraction_Reduction.py Utility/FilterEvents.py Diffraction/HFIR_Powder_Diffraction_Reduction.py

mantidqt.python_interfaces_directory = @MANTID_ROOT@/scripts

# Where to find mantid plugin libraries
Expand Down
15 changes: 12 additions & 3 deletions Code/Mantid/MantidPlot/ipython_widget/mantid_ipython_widget.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import threading
import types
import inspect

from PyQt4 import QtGui

Expand All @@ -14,7 +15,7 @@
from IPython.qt.inprocess import QtInProcessKernelManager


def our_run_code(self, code_obj):
def our_run_code(self, code_obj, result=None):
""" Method with which we replace the run_code method of IPython's InteractiveShell class.
It calls the original method (renamed to ipython_run_code) on a separate thread
so that we can avoid locking up the whole of MantidPlot while a command runs.
Expand All @@ -23,12 +24,20 @@ def our_run_code(self, code_obj):
----------
code_obj : code object
A compiled code object, to be executed
result : ExecutionResult, optional
An object to store exceptions that occur during execution.
Returns
-------
False : Always, as it doesn't seem to matter.
"""
t = threading.Thread(target=self.ipython_run_code, args=[code_obj])

t = threading.Thread()
#ipython 3.0 introduces a third argument named result
nargs = len(inspect.getargspec(self.ipython_run_code).args)
if (nargs == 3):
t = threading.Thread(target=self.ipython_run_code, args=[code_obj,result])
else:
t = threading.Thread(target=self.ipython_run_code, args=[code_obj])
t.start()
while t.is_alive():
QtGui.QApplication.processEvents()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ private slots:
private:
QLabel *labelRun, *labelOpt;
QLineEdit *editRun, *editOpt;
QHBoxLayout *hRun, *hOpt;
QHBoxLayout *hRun, *hOpt, *hBut;
QGridLayout *layout;
QPushButton *okButton, *cancelButton;
};
Expand Down
19 changes: 13 additions & 6 deletions Code/Mantid/MantidQt/CustomInterfaces/src/Indirect/CalcCorr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -295,19 +295,26 @@ namespace IDA
return;
}

std::string paramName = "Workflow.beam-width";
auto instrument = ws->getInstrument();

if(instrument->hasParameter(paramName))
const std::string beamWidthParamName = "Workflow.beam-width";
if(instrument->hasParameter(beamWidthParamName))
{
QString beamWidth = QString::fromStdString(instrument->getStringParameter(paramName)[0]);
QString beamWidth = QString::fromStdString(instrument->getStringParameter(beamWidthParamName)[0]);
double beamWidthValue = beamWidth.toDouble();

m_uiForm.spCylBeamWidth->setValue(beamWidthValue);
m_uiForm.spCylBeamHeight->setValue(beamWidthValue);

m_uiForm.spAnnBeamWidth->setValue(beamWidthValue);
m_uiForm.spAnnBeamHeight->setValue(beamWidthValue);
}

const std::string beamHeightParamName = "Workflow.beam-height";
if(instrument->hasParameter(beamHeightParamName))
{
QString beamHeight = QString::fromStdString(instrument->getStringParameter(beamHeightParamName)[0]);
double beamHeightValue = beamHeight.toDouble();

m_uiForm.spCylBeamHeight->setValue(beamHeightValue);
m_uiForm.spAnnBeamHeight->setValue(beamHeightValue);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,32 +137,34 @@ class OwnTreeWidgetItem : public QTreeWidgetItem {
void TomoReconstruction::paramValModified(QTreeWidgetItem *item,
int /*column*/) {
OwnTreeWidgetItem *ownItem = dynamic_cast<OwnTreeWidgetItem *>(item);
int topLevelIndex = -1;
if (!ownItem)
return;

int topLevelIndex = -1;
if (ownItem->getRootParent() != NULL) {
topLevelIndex = m_uiSavu.treeCurrentPlugins->indexOfTopLevelItem(
ownItem->getRootParent());
}
if (-1 == topLevelIndex)
return;

if (topLevelIndex != -1) {
// Recreate the json string from the nodes and write back
std::string json = m_currPlugins->cell<std::string>(topLevelIndex, 1);
// potential new line out, and trim spaces
json.erase(std::remove(json.begin(), json.end(), '\n'), json.end());
json.erase(std::remove(json.begin(), json.end(), '\r'), json.end());
json = Poco::trimInPlace(json);

::Json::Reader r;
::Json::Value root;
if (r.parse(json, root)) {
// Look for the key and replace it
root[ownItem->getKey()] = ownItem->text(0).toStdString();
}
// Recreate the json string from the nodes and write back
std::string json = m_currPlugins->cell<std::string>(topLevelIndex, 1);
// potential new line out, and trim spaces
json.erase(std::remove(json.begin(), json.end(), '\n'), json.end());
json.erase(std::remove(json.begin(), json.end(), '\r'), json.end());
json = Poco::trimInPlace(json);

m_currPlugins->cell<std::string>(topLevelIndex, 1) =
::Json::FastWriter().write(root);
currentPluginSelected();
::Json::Reader r;
::Json::Value root;
if (r.parse(json, root)) {
// Look for the key and replace it
root[ownItem->getKey()] = ownItem->text(0).toStdString();
}

m_currPlugins->cell<std::string>(topLevelIndex, 1) =
::Json::FastWriter().write(root);
currentPluginSelected();
}

// When a top level item is expanded, also expand its child items - if tree
Expand All @@ -178,88 +180,93 @@ void TomoReconstruction::expandedItem(QTreeWidgetItem *item) {
// Adds one plugin from the available plugins list into the list of
// current plugins
void TomoReconstruction::transferClicked() {
if (m_uiSavu.listAvailablePlugins->selectedItems().count() != 0) {
int idx = m_uiSavu.listAvailablePlugins->currentIndex().row();
Mantid::API::TableRow row = m_currPlugins->appendRow();
for (size_t j = 0; j < m_currPlugins->columnCount(); ++j) {
row << m_availPlugins->cell<std::string>(idx, j);
}
createPluginTreeEntry(row);
if (0 == m_uiSavu.listAvailablePlugins->selectedItems().count())
return;

int idx = m_uiSavu.listAvailablePlugins->currentIndex().row();
Mantid::API::TableRow row = m_currPlugins->appendRow();
for (size_t j = 0; j < m_currPlugins->columnCount(); ++j) {
row << m_availPlugins->cell<std::string>(idx, j);
}
createPluginTreeEntry(row);
}

void TomoReconstruction::moveUpClicked() {
if (m_uiSavu.treeCurrentPlugins->selectedItems().count() != 0) {
size_t idx =
static_cast<size_t>(m_uiSavu.treeCurrentPlugins->currentIndex().row());
if (idx > 0 && idx < m_currPlugins->rowCount()) {
// swap row, all columns
for (size_t j = 0; j < m_currPlugins->columnCount(); ++j) {
std::string swap = m_currPlugins->cell<std::string>(idx, j);
m_currPlugins->cell<std::string>(idx, j) =
m_currPlugins->cell<std::string>(idx - 1, j);
m_currPlugins->cell<std::string>(idx - 1, j) = swap;
}
refreshCurrentPluginListUI();
if (0 == m_uiSavu.treeCurrentPlugins->selectedItems().count())
return;

size_t idx =
static_cast<size_t>(m_uiSavu.treeCurrentPlugins->currentIndex().row());
if (idx > 0 && idx < m_currPlugins->rowCount()) {
// swap row, all columns
for (size_t j = 0; j < m_currPlugins->columnCount(); ++j) {
std::string swap = m_currPlugins->cell<std::string>(idx, j);
m_currPlugins->cell<std::string>(idx, j) =
m_currPlugins->cell<std::string>(idx - 1, j);
m_currPlugins->cell<std::string>(idx - 1, j) = swap;
}
refreshCurrentPluginListUI();
}
}

void TomoReconstruction::moveDownClicked() {
// TODO: this can be done with the same function as above...
if (m_uiSavu.treeCurrentPlugins->selectedItems().count() != 0) {
size_t idx =
static_cast<size_t>(m_uiSavu.treeCurrentPlugins->currentIndex().row());
if (idx < m_currPlugins->rowCount() - 1) {
// swap all columns
for (size_t j = 0; j < m_currPlugins->columnCount(); ++j) {
std::string swap = m_currPlugins->cell<std::string>(idx, j);
m_currPlugins->cell<std::string>(idx, j) =
m_currPlugins->cell<std::string>(idx + 1, j);
m_currPlugins->cell<std::string>(idx + 1, j) = swap;
}
refreshCurrentPluginListUI();
if (0 == m_uiSavu.treeCurrentPlugins->selectedItems().count())
return;

size_t idx =
static_cast<size_t>(m_uiSavu.treeCurrentPlugins->currentIndex().row());
if (idx < m_currPlugins->rowCount() - 1) {
// swap all columns
for (size_t j = 0; j < m_currPlugins->columnCount(); ++j) {
std::string swap = m_currPlugins->cell<std::string>(idx, j);
m_currPlugins->cell<std::string>(idx, j) =
m_currPlugins->cell<std::string>(idx + 1, j);
m_currPlugins->cell<std::string>(idx + 1, j) = swap;
}
refreshCurrentPluginListUI();
}
}

void TomoReconstruction::removeClicked() {
// Also clear ADS entries
if (m_uiSavu.treeCurrentPlugins->selectedItems().count() != 0) {
int idx = m_uiSavu.treeCurrentPlugins->currentIndex().row();
m_currPlugins->removeRow(idx);
if (0 == m_uiSavu.treeCurrentPlugins->selectedItems().count())
return;

refreshCurrentPluginListUI();
}
int idx = m_uiSavu.treeCurrentPlugins->currentIndex().row();
m_currPlugins->removeRow(idx);

refreshCurrentPluginListUI();
}

void TomoReconstruction::menuOpenClicked() {
QString s =
QFileDialog::getOpenFileName(0, "Open file", QDir::currentPath(),
"NeXus files (*.nxs);;All files (*.*)",
new QString("NeXus files (*.nxs)"));
std::string returned = s.toStdString();
if (returned != "") {
bool opening = true;

if (m_currPlugins->rowCount() > 0) {
QMessageBox::StandardButton reply = QMessageBox::question(
this, "Open file confirmation",
"Opening the configuration file will clear the current list."
"\nWould you like to continue?",
QMessageBox::Yes | QMessageBox::No);
if (reply == QMessageBox::No) {
opening = false;
}
}
std::string name = s.toStdString();

if (opening) {
loadSavuTomoConfig(returned, m_currPlugins);
if ("" == name)
return;

m_currentParamPath = returned;
refreshCurrentPluginListUI();
bool opening = true;
if (m_currPlugins->rowCount() > 0) {
QMessageBox::StandardButton reply = QMessageBox::question(
this, "Open file confirmation",
"Opening the configuration file will clear the current list."
"\nWould you like to continue?",
QMessageBox::Yes | QMessageBox::No);
if (reply == QMessageBox::No) {
opening = false;
}
}

if (opening) {
loadSavuTomoConfig(name, m_currPlugins);

m_currentParamPath = name;
refreshCurrentPluginListUI();
}
}

void TomoReconstruction::menuSaveClicked() {
Expand All @@ -268,7 +275,12 @@ void TomoReconstruction::menuSaveClicked() {
return;
}

if (m_currPlugins->rowCount() != 0) {
if (0 == m_currPlugins->rowCount()) {
// Alert that the plugin list is empty
QMessageBox::information(this, tr("Unable to save file"),
"The current plugin list is empty, please add one "
"or more to the list.");
} else {
AnalysisDataService::Instance().add(createUniqueNameHidden(),
m_currPlugins);
std::string csvWorkspaceNames = m_currPlugins->name();
Expand All @@ -282,11 +294,6 @@ void TomoReconstruction::menuSaveClicked() {
if (!alg->isExecuted()) {
throw std::runtime_error("Error when trying to save config file");
}
} else {
// Alert that the plugin list is empty
QMessageBox::information(this, tr("Unable to save file"),
"The current plugin list is empty, please add one "
"or more to the list.");
}
}

Expand All @@ -295,11 +302,12 @@ void TomoReconstruction::menuSaveAsClicked() {
QFileDialog::getSaveFileName(0, "Save file", QDir::currentPath(),
"NeXus files (*.nxs);;All files (*.*)",
new QString("NeXus files (*.nxs)"));
std::string returned = s.toStdString();
if (returned != "") {
m_currentParamPath = returned;
menuSaveClicked();
}
std::string name = s.toStdString();
if ("" == name)
return;

m_currentParamPath = name;
menuSaveClicked();
}

QString TomoReconstruction::tableWSRowToString(ITableWorkspace_sptr table,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1285,18 +1285,25 @@ std::string TomoReconstruction::getPassword() {
*/
void TomoReconstruction::drawImage(const MatrixWorkspace_sptr &ws) {
// From logs we expect a name "run_title", width "Axis1" and height "Axis2"
size_t width, height;
const size_t MAXDIM = 2048 * 16;
size_t width;
try {
width = boost::lexical_cast<size_t>(ws->run().getLogData("Axis1")->value());
// TODO: add a settings option for this (like max mem allocation for images)?
if (width >= MAXDIM)
width = MAXDIM;
} catch (std::exception &e) {
userError("Cannot load image", "There was a problem while trying to "
"find the width of the image: " +
std::string(e.what()));
return;
}
size_t height;
try {
height =
boost::lexical_cast<size_t>(ws->run().getLogData("Axis2")->value());
if (height >= MAXDIM)
height = MAXDIM;
} catch (std::exception &e) {
userError("Cannot load image", "There was a problem while trying to "
"find the height of the image: " +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,17 @@ TomoToolConfigDialog::TomoToolConfigDialog(QWidget *parent) : QDialog(parent) {
hOpt->addWidget(labelOpt);
hOpt->addWidget(editOpt);

okButton = new QPushButton("Ok");
cancelButton = new QPushButton("Cancel");
hBut = new QHBoxLayout();
hBut->insertStretch(0,1);
hBut->addWidget(okButton);
hBut->addWidget(cancelButton);

layout = new QGridLayout();
layout->addLayout(hRun, 0, 0);
layout->addLayout(hOpt, 1, 0);
layout->addLayout(hOpt, 2, 0);

connect(okButton, SIGNAL(clicked()), this, SLOT(okClicked()));
connect(cancelButton, SIGNAL(clicked()), this, SLOT(cancelClicked()));
Expand Down

0 comments on commit 49fab8b

Please sign in to comment.