Commit 86668669 authored by Samuel Jackson's avatar Samuel Jackson
Browse files

Refs #19662 Save masks on view and masked bins

parent e8767823
......@@ -4572,6 +4572,8 @@ void ApplicationWindow::openRecentProject(QAction *action) {
// Have to change the working directory here because that is used when
// finding the nexus files to load
workingDir = QFileInfo(f).absolutePath();
ConfigService::Instance().setString("project.workingdir",
workingDir.toStdString());
ApplicationWindow *a = open(fn, false, false);
if (a && (fn.endsWith(".qti", Qt::CaseInsensitive) ||
fn.endsWith(".qti~", Qt::CaseInsensitive) ||
......@@ -4606,6 +4608,9 @@ ApplicationWindow *ApplicationWindow::openProject(const QString &filename,
newProject();
m_mantidmatrixWindows.clear();
 
// store the working directory in the config service.
ConfigService::Instance().setString("project.workingdir",
workingDir.toStdString());
projectname = filename;
setWindowTitle("MantidPlot - " + filename);
 
......
......@@ -4,7 +4,6 @@
#include <MantidQtMantidWidgets/WidgetDllOption.h>
#include "MantidQtMantidWidgets/InstrumentView/InstrumentWidgetTab.h"
#include "MantidQtMantidWidgets/InstrumentView/MantidGLWidget.h"
#include "MantidGeometry/Instrument.h"
#include <QFrame>
......@@ -120,7 +119,7 @@ protected:
void clearProperties();
void setProperties();
boost::shared_ptr<Mantid::API::MatrixWorkspace>
createMaskWorkspace(bool invertMask, bool temp = false);
createMaskWorkspace(bool invertMask, bool temp = false) const;
void saveMaskingToWorkspace(bool invertMask = false);
void saveMaskingToFile(bool invertMask = false);
void saveMaskingToCalFile(bool invertMask = false);
......
......@@ -42,6 +42,10 @@ public:
void subtractIntegratedSpectra(const Mantid::API::MatrixWorkspace &workspace,
std::vector<double> &spectraIntgrs) const;
void clear();
/// Load the state of the bin masks from a Mantid project file.
void loadFromProject(const std::string &lines);
/// Save the state of the bin masks to a Mantid project file.
std::string saveToProject() const;
private:
/// Range of x values to mask in a spectrum. (Using MaskBins)
......
......@@ -1289,13 +1289,13 @@ bool FindComponentVisitor::visit(GLActor *actor) {
* @return string representing the current state of the instrumet actor.
*/
std::string InstrumentActor::saveToProject() const {
TSVSerialiser tsv, actor;
TSVSerialiser tsv;
const std::string currentColorMap = getCurrentColorMap().toStdString();
if (!currentColorMap.empty())
actor.writeLine("FileName") << currentColorMap;
tsv.writeLine("FileName") << currentColorMap;
tsv.writeSection("actor", actor.outputLines());
tsv.writeSection("binmasks", m_maskBinsData.saveToProject());
return tsv.outputLines();
}
......@@ -1310,6 +1310,12 @@ void InstrumentActor::loadFromProject(const std::string &lines) {
tsv >> filename;
loadColorMap(filename);
}
if (tsv.selectSection("binmasks")) {
std::string binMaskLines;
tsv >> binMaskLines;
m_maskBinsData.loadFromProject(binMaskLines);
}
}
} // MantidWidgets
......
......@@ -1301,7 +1301,7 @@ std::string InstrumentWidget::saveToProject() const {
<< m_xIntegration->getMaximum();
// serialise widget subsections
tsv.writeRaw(m_instrumentActor->saveToProject());
tsv.writeSection("actor", m_instrumentActor->saveToProject());
tsv.writeSection("tabs", saveTabs());
return tsv.outputLines();
......@@ -1361,18 +1361,18 @@ void InstrumentWidget::loadFromProject(const std::string &lines) {
setBinRange(min, max);
}
if (tsv.selectSection("tabs")) {
std::string tabLines;
tsv >> tabLines;
loadTabs(tabLines);
}
if (tsv.selectSection("Surface")) {
std::string surfaceLines;
tsv >> surfaceLines;
getSurface()->loadFromProject(surfaceLines);
}
if (tsv.selectSection("tabs")) {
std::string tabLines;
tsv >> tabLines;
loadTabs(tabLines);
}
updateInstrumentView();
}
......
......@@ -9,6 +9,7 @@
#include "MantidAPI/AnalysisDataService.h"
#include "MantidAPI/FrameworkManager.h"
#include "MantidAPI/IMaskWorkspace.h"
#include "MantidAPI/IMaskWorkspace.h"
#include "MantidAPI/ITableWorkspace.h"
#include "MantidAPI/MatrixWorkspace.h"
// #include "MantidDataObjects/TableWorkspace.h"
......@@ -646,7 +647,7 @@ void InstrumentWidgetMaskTab::clearMask() {
* false the name will be unique.
*/
Mantid::API::MatrixWorkspace_sptr
InstrumentWidgetMaskTab::createMaskWorkspace(bool invertMask, bool temp) {
InstrumentWidgetMaskTab::createMaskWorkspace(bool invertMask, bool temp) const {
m_instrWidget->updateInstrumentView(); // to refresh the pick image
Mantid::API::MatrixWorkspace_sptr inputWS =
m_instrWidget->getInstrumentActor()->getMaskMatrixWorkspace();
......@@ -1210,6 +1211,42 @@ void MantidQt::MantidWidgets::InstrumentWidgetMaskTab::loadFromProject(
tab >> value;
type->setChecked(value);
}
if (tab.selectLine("MaskViewWorkspace")) {
// the view was masked. We should load reapply this from a cached
// workspace in the project folder
std::string maskWSName;
tab >> maskWSName;
std::string workingDir =
Mantid::Kernel::ConfigService::Instance().getString(
"project.workingdir");
std::string fileName = workingDir + "/" + maskWSName;
using namespace Mantid::API;
auto actor = m_instrWidget->getInstrumentActor();
auto workspace = actor->getWorkspace();
auto instrument = workspace->getInstrument();
auto instrumentName = instrument->getName();
std::string tempName = "__" + workspace->name() + "MaskView";
auto alg = AlgorithmManager::Instance().create("LoadMask", -1);
alg->initialize();
alg->setPropertyValue("Instrument", instrumentName);
alg->setPropertyValue("InputFile", fileName);
alg->setPropertyValue("OutputWorkspace", tempName);
alg->execute();
MatrixWorkspace_sptr maskWS =
AnalysisDataService::Instance().retrieveWS<MatrixWorkspace>(tempName);
AnalysisDataService::Instance().remove(tempName);
if (maskWS) {
actor->setMaskMatrixWorkspace(maskWS);
actor->updateColors();
m_instrWidget->updateInstrumentDetectors();
m_instrWidget->updateInstrumentView();
}
}
}
}
......@@ -1235,6 +1272,31 @@ MantidQt::MantidWidgets::InstrumentWidgetMaskTab::saveToProject() const {
tab << type->isChecked();
}
using namespace Mantid::API;
using namespace Mantid::Kernel;
try {
auto actor = m_instrWidget->getInstrumentActor();
MatrixWorkspace_sptr outputWS = actor->getMaskMatrixWorkspace();
std::string workingDir =
ConfigService::Instance().getString("project.workingdir");
std::string wsName =
m_instrWidget->getWorkspaceName().toStdString() + "MaskView.xml";
std::string fileName = workingDir + "/" + wsName;
if (outputWS) {
IAlgorithm_sptr alg = AlgorithmManager::Instance().create("SaveMask", -1);
alg->setProperty("InputWorkspace",
boost::dynamic_pointer_cast<Workspace>(outputWS));
alg->setPropertyValue("OutputFile", fileName);
alg->execute();
}
tab.writeLine("MaskViewWorkspace") << wsName;
} catch (...) {
// just fail silently, if we can't save the mask then we should
// give up at this point.
}
tsv.writeSection("masktab", tab.outputLines());
return tsv.outputLines();
}
......
#include "MantidQtMantidWidgets/InstrumentView/MaskBinsData.h"
#include "MantidAPI/AlgorithmManager.h"
#include "MantidAPI/MatrixWorkspace.h"
#include "MantidQtAPI/TSVSerialiser.h"
#include <vector>
......@@ -57,5 +58,39 @@ void MaskBinsData::subtractIntegratedSpectra(
/// Clear the masking data
void MaskBinsData::clear() { m_masks.clear(); }
void MaskBinsData::loadFromProject(const std::string &lines) {
TSVSerialiser tsv(lines);
for (auto &maskLines : tsv.sections("Mask")) {
TSVSerialiser mask(maskLines);
mask.selectLine("Range");
double start, end;
mask >> start >> end;
QList<int> spectra;
const size_t numSpectra = mask.values("Spectra").size();
for (size_t i = 0; i < numSpectra; ++i) {
int spectrum;
mask >> spectrum;
spectra.append(spectrum);
}
addXRange(start, end, spectra);
}
}
std::string MaskBinsData::saveToProject() const {
TSVSerialiser tsv;
for (const auto &binMask : m_masks) {
TSVSerialiser mask;
mask.writeLine("Range") << binMask.start << binMask.end;
mask.writeLine("Spectra");
for (const int spectrum : binMask.spectra) {
mask << spectrum;
}
tsv.writeSection("Mask", mask.outputLines());
}
return tsv.outputLines();
}
} // MantidWidgets
} // MantidQt
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment