diff --git a/Code/Mantid/Framework/DataObjects/inc/MantidDataObjects/MDHistoWorkspace.h b/Code/Mantid/Framework/DataObjects/inc/MantidDataObjects/MDHistoWorkspace.h index 567c10f6b009b1df0f485e376a91607be42a43b4..8e6eaca21128413edfb3dda1b232c9a73f2ca8a3 100644 --- a/Code/Mantid/Framework/DataObjects/inc/MantidDataObjects/MDHistoWorkspace.h +++ b/Code/Mantid/Framework/DataObjects/inc/MantidDataObjects/MDHistoWorkspace.h @@ -371,6 +371,8 @@ public: /// Apply masking. void setMDMasking(Mantid::Geometry::MDImplicitFunction *maskingRegion); + /// Apply masking. + void setMDMaskAt(const size_t& index, bool mask); /// Clear masking. void clearMDMasking(); diff --git a/Code/Mantid/Framework/DataObjects/src/MDHistoWorkspace.cpp b/Code/Mantid/Framework/DataObjects/src/MDHistoWorkspace.cpp index f5264363224903ad911355fe21108c6960d95b05..b1687145357598e2bc49e6c4c4822dcd663e0adc 100644 --- a/Code/Mantid/Framework/DataObjects/src/MDHistoWorkspace.cpp +++ b/Code/Mantid/Framework/DataObjects/src/MDHistoWorkspace.cpp @@ -1165,6 +1165,15 @@ void MDHistoWorkspace::setMDMasking( } } +/** + * Set the masking + * @param index : linear index to mask + * @param mask : True to mask. False to clear. + */ +void MDHistoWorkspace::setMDMaskAt(const size_t& index, bool mask){ + m_masks[index] = mask; +} + /// Clear any existing masking. void MDHistoWorkspace::clearMDMasking() { for (size_t i = 0; i < this->getNPoints(); ++i) { diff --git a/Code/Mantid/Framework/MDAlgorithms/CMakeLists.txt b/Code/Mantid/Framework/MDAlgorithms/CMakeLists.txt index b64ab8c3316d23e7cfa74ce1d5cf4b99708c84c9..12b1561a2dda2012e92d813f457e3f6b0520eb21 100644 --- a/Code/Mantid/Framework/MDAlgorithms/CMakeLists.txt +++ b/Code/Mantid/Framework/MDAlgorithms/CMakeLists.txt @@ -109,6 +109,7 @@ set ( SRC_FILES src/SmoothMD.cpp src/ThresholdMD.cpp src/TransformMD.cpp + src/TransposeMD.cpp src/UnaryOperationMD.cpp src/UnitsConversionHelper.cpp src/UserFunctionMD.cpp @@ -227,6 +228,7 @@ set ( INC_FILES inc/MantidMDAlgorithms/SmoothMD.h inc/MantidMDAlgorithms/ThresholdMD.h inc/MantidMDAlgorithms/TransformMD.h + inc/MantidMDAlgorithms/TransposeMD.h inc/MantidMDAlgorithms/UnaryOperationMD.h inc/MantidMDAlgorithms/UnitsConversionHelper.h inc/MantidMDAlgorithms/Vector3DParameter.h @@ -334,6 +336,7 @@ set ( TEST_FILES TobyFitResolutionModelTest.h TobyFitYVectorTest.h TransformMDTest.h + TransposeMDTest.h UnaryOperationMDTest.h UnitsConversionHelperTest.h WeightedMeanMDTest.h diff --git a/Code/Mantid/Framework/MDAlgorithms/inc/MantidMDAlgorithms/TransposeMD.h b/Code/Mantid/Framework/MDAlgorithms/inc/MantidMDAlgorithms/TransposeMD.h new file mode 100644 index 0000000000000000000000000000000000000000..a218102a80ebe1bf030fb1eed9e769258355213a --- /dev/null +++ b/Code/Mantid/Framework/MDAlgorithms/inc/MantidMDAlgorithms/TransposeMD.h @@ -0,0 +1,50 @@ +#ifndef MANTID_MDALGORITHMS_TRANSPOSEMD_H_ +#define MANTID_MDALGORITHMS_TRANSPOSEMD_H_ + +#include "MantidMDAlgorithms/DllConfig.h" +#include "MantidAPI/Algorithm.h" +namespace Mantid { +namespace MDAlgorithms { + +/** TransposeMD : Transpose an MDWorkspace. Allows dimensions to be collapsed down. + + Copyright © 2015 ISIS Rutherford Appleton Laboratory, NScD Oak Ridge + National Laboratory & European Spallation Source + + This file is part of Mantid. + + Mantid is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + Mantid is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. + + File change history is stored at: <https://github.com/mantidproject/mantid> + Code Documentation is available at: <http://doxygen.mantidproject.org> +*/ +class MANTID_MDALGORITHMS_DLL TransposeMD : public API::Algorithm { +public: + TransposeMD(); + virtual ~TransposeMD(); + + virtual const std::string name() const; + virtual int version() const; + virtual const std::string category() const; + virtual const std::string summary() const; + +private: + void init(); + void exec(); +}; + +} // namespace MDAlgorithms +} // namespace Mantid + +#endif /* MANTID_MDALGORITHMS_TRANSPOSEMD_H_ */ diff --git a/Code/Mantid/Framework/MDAlgorithms/src/TransposeMD.cpp b/Code/Mantid/Framework/MDAlgorithms/src/TransposeMD.cpp new file mode 100644 index 0000000000000000000000000000000000000000..12cc1a5e7cc7d9b6d270e3ca875f4895743c1e74 --- /dev/null +++ b/Code/Mantid/Framework/MDAlgorithms/src/TransposeMD.cpp @@ -0,0 +1,168 @@ +#include "MantidMDAlgorithms/TransposeMD.h" +#include "MantidKernel/ArrayProperty.h" +#include "MantidKernel/ArrayBoundedValidator.h" +#include "MantidKernel/MultiThreaded.h" +#include "MantidAPI/FrameworkManager.h" +#include "MantidAPI/IMDHistoWorkspace.h" +#include "MantidAPI/IMDIterator.h" +#include "MantidAPI/Progress.h" +#include "MantidDataObjects/CoordTransformAligned.h" +#include "MantidDataObjects/MDHistoWorkspace.h" +#include "MantidGeometry/MDGeometry/IMDDimension.h" +#include "MantidGeometry/MDGeometry/MDHistoDimension.h" + +#include <vector> +#include <algorithm> +#include <numeric> +#include <memory> +#include <boost/shared_ptr.hpp> +#include <boost/make_shared.hpp> + +namespace Mantid { +namespace MDAlgorithms { + +using namespace Mantid::Kernel; +using namespace Mantid::API; +using namespace Mantid::DataObjects; + +// Register the algorithm into the AlgorithmFactory +DECLARE_ALGORITHM(TransposeMD) + +//---------------------------------------------------------------------------------------------- +/** Constructor + */ +TransposeMD::TransposeMD() {} + +//---------------------------------------------------------------------------------------------- +/** Destructor + */ +TransposeMD::~TransposeMD() {} + +//---------------------------------------------------------------------------------------------- + +/// Algorithms name for identification. @see Algorithm::name +const std::string TransposeMD::name() const { return "TransposeMD"; } + +/// Algorithm's version for identification. @see Algorithm::version +int TransposeMD::version() const { return 1; } + +/// Algorithm's category for identification. @see Algorithm::category +const std::string TransposeMD::category() const { return "MDAlgorithms"; } + +/// Algorithm's summary for use in the GUI and help. @see Algorithm::summary +const std::string TransposeMD::summary() const { + return "Transpose the dimensions of a MDWorkspace to create a new output " + "MDWorkspace"; +} + +//---------------------------------------------------------------------------------------------- +/** Initialize the algorithm's properties. + */ +void TransposeMD::init() { + declareProperty(new WorkspaceProperty<IMDHistoWorkspace>("InputWorkspace", "", + Direction::Input), + "An input workspace."); + + auto axisValidator = boost::make_shared<ArrayBoundedValidator<int>>(); + axisValidator->clearUpper(); + axisValidator->setLower(0); + + declareProperty(new ArrayProperty<int>("Axes", std::vector<int>(0), + axisValidator, Direction::Input), + "Permutes the axes according to the indexes given. Zero " + "based indexing. Defaults to no transpose."); + + declareProperty(new WorkspaceProperty<IMDHistoWorkspace>( + "OutputWorkspace", "", Direction::Output), + "An output workspace."); +} + +//---------------------------------------------------------------------------------------------- +/** Execute the algorithm. + */ +void TransposeMD::exec() { + IMDHistoWorkspace_sptr inWSProp = getProperty("InputWorkspace"); + auto inWS = boost::dynamic_pointer_cast<MDHistoWorkspace>(inWSProp); + if (!inWS) { + throw std::invalid_argument( + "Expect the InputWorkspace to be a MDHistoWorkspace"); + } + + size_t nDimsInput = inWS->getNumDims(); + size_t nDimsOutput = inWS->getNumDims(); // The assumed default. + std::vector<int> axesInts = this->getProperty("Axes"); + std::vector<size_t> axes(axesInts.begin(), axesInts.end()); + Property *axesProperty = this->getProperty("Axes"); + if (!axesProperty->isDefault()) { + if (axes.size() > nDimsInput) { + throw std::invalid_argument( + "More axis specified than dimensions are avaiable in the input"); + } + auto it = std::max_element(axes.begin(), axes.end()); + if (*it > nDimsInput) { + throw std::invalid_argument("One of the axis indexes specified indexes a " + "dimension outside the real dimension range"); + } + nDimsOutput = axes.size(); + } else { + axes = std::vector<size_t>(nDimsOutput); + std::iota(axes.begin(), axes.end(), 0); + } + + std::vector<coord_t> origin(nDimsOutput, 0.0); + std::vector<Geometry::IMDDimension_sptr> targetGeometry; + for (size_t i = 0; i < nDimsOutput; ++i) { + // Clone the dimension corresponding to the axis requested. + auto cloneDim = Geometry::IMDDimension_sptr( + new Geometry::MDHistoDimension(inWS->getDimension(axes[i]).get())); + targetGeometry.push_back(cloneDim); + } + + // Make the output workspace in the right shape. + auto outWS = MDHistoWorkspace_sptr(new MDHistoWorkspace(targetGeometry)); + outWS->copyExperimentInfos(*inWS); + + // Configure the coordinate transform. + std::vector<coord_t> scaling(nDimsOutput, 1); // No scaling + CoordTransformAligned coordTransform(nDimsInput, nDimsOutput, axes, origin, + scaling); + + uint64_t nPoints = inWS->getNPoints(); + Progress progress(this, 0, 1, size_t(nPoints)); + + progress.reportIncrement( + size_t(double(nPoints) * 0.1)); // Report ~10% progress + + const int nThreads = Mantid::API::FrameworkManager::Instance() + .getNumOMPThreads(); // NThreads to Request + + auto iterators = inWS->createIterators(nThreads, NULL); + + PARALLEL_FOR_NO_WSP_CHECK() + for (int it = 0; it < int(iterators.size()); ++it) { + + PARALLEL_START_INTERUPT_REGION + auto inIterator = std::unique_ptr<IMDIterator>(iterators[it]); + do { + auto center = inIterator->getCenter(); + const coord_t *incoords = center.getBareArray(); + std::vector<coord_t> outcoords(nDimsOutput); + coordTransform.apply(incoords, &outcoords[0]); + + size_t index = outWS->getLinearIndexAtCoord(&outcoords[0]); + outWS->setSignalAt(index, inIterator->getSignal()); + const signal_t error = inIterator->getError(); + outWS->setErrorSquaredAt(index, error * error); + outWS->setNumEventsAt(index, Mantid::signal_t(inIterator->getNumEvents())); + outWS->setMDMaskAt(index, inIterator->getIsMasked()); + progress.report(); + } while (inIterator->next()); + PARALLEL_END_INTERUPT_REGION + } + PARALLEL_CHECK_INTERUPT_REGION + + this->setProperty("OutputWorkspace", outWS); +} + +} // namespace MDAlgorithms +} // namespace Mantid diff --git a/Code/Mantid/Framework/MDAlgorithms/test/TransposeMDTest.h b/Code/Mantid/Framework/MDAlgorithms/test/TransposeMDTest.h new file mode 100644 index 0000000000000000000000000000000000000000..7f008da51b4f51b3858582cfa4ee112e58e9b633 --- /dev/null +++ b/Code/Mantid/Framework/MDAlgorithms/test/TransposeMDTest.h @@ -0,0 +1,174 @@ +#ifndef MANTID_MDALGORITHMS_TRANSPOSEMDTEST_H_ +#define MANTID_MDALGORITHMS_TRANSPOSEMDTEST_H_ + +#include <cxxtest/TestSuite.h> +#include <vector> + +#include "MantidMDAlgorithms/TransposeMD.h" +#include "MantidTestHelpers/MDEventsTestHelper.h" +#include "MantidGeometry/MDGeometry/MDTypes.h" + +using Mantid::MDAlgorithms::TransposeMD; +using namespace Mantid::DataObjects; +using namespace Mantid::API; + +class TransposeMDTest : public CxxTest::TestSuite { +public: + // This pair of boilerplate methods prevent the suite being created statically + // This means the constructor isn't called when running other tests + static TransposeMDTest *createSuite() { return new TransposeMDTest(); } + static void destroySuite(TransposeMDTest *suite) { delete suite; } + + void test_Init() { + TransposeMD alg; + TS_ASSERT_THROWS_NOTHING(alg.initialize()) + TS_ASSERT(alg.isInitialized()) + } + + void test_valid_axes_lower_limit_throws() { + TransposeMD transposeMD; + transposeMD.initialize(); + std::vector<int> axes; + axes.push_back(1); // should be fine. + TS_ASSERT_THROWS_NOTHING(transposeMD.setProperty("Axes", axes)); + axes.push_back(-1); // Not a valid axis + TS_ASSERT_THROWS(transposeMD.setProperty("Axes", axes), + std::invalid_argument &); + } + + void test_too_many_dimension_indexes_throws() { + auto inputWS = MDEventsTestHelper::makeFakeMDHistoWorkspace( + 1 /*signal*/, 2 /*numDims*/, 3 /*numBins in each dimension*/); + + TransposeMD transposeMD; + transposeMD.setChild(true); + transposeMD.initialize(); + transposeMD.setPropertyValue("OutputWorkspace", "dummy"); + transposeMD.setProperty( + "Axes", + std::vector<int>(4, 1)); // 4-axis entries, but only 3 dimensions + transposeMD.setProperty("InputWorkspace", inputWS); + TS_ASSERT_THROWS(transposeMD.execute(), std::invalid_argument &); + } + + void test_indexes_that_dont_exist_throws() { + auto inputWS = MDEventsTestHelper::makeFakeMDHistoWorkspace( + 1 /*signal*/, 2 /*numDims*/, 3 /*numBins in each dimension*/); + + TransposeMD transposeMD; + transposeMD.setChild(true); + transposeMD.initialize(); + transposeMD.setPropertyValue("OutputWorkspace", "dummy"); + transposeMD.setProperty("Axes", + std::vector<int>(1, 3)); // Invalid index of 3! + transposeMD.setProperty("InputWorkspace", inputWS); + TSM_ASSERT_THROWS( + "Axis values can only be 0-2 for this ws. 3 is not valid.", + transposeMD.execute(), std::invalid_argument &); + } + + void test_no_transpose() { + auto inputWS = MDEventsTestHelper::makeFakeMDHistoWorkspace( + 1 /*signal*/, 2 /*numDims*/, 3 /*numBins in each dimension*/); + + // Set some values. If transposed then these should end up elsewhere. + inputWS->setSignalAt(0, 2); + inputWS->setSignalAt(1, 2); + + TransposeMD transposeMD; + transposeMD.setChild(true); + transposeMD.initialize(); + transposeMD.setPropertyValue("OutputWorkspace", "dummy"); + transposeMD.setProperty("InputWorkspace", inputWS); + transposeMD.execute(); + IMDHistoWorkspace_sptr outputWS = + transposeMD.getProperty("OutputWorkspace"); + + // Lets check that the workspaces are essentially the same. + TS_ASSERT_EQUALS(inputWS->getNumDims(), outputWS->getNumDims()); + TS_ASSERT_EQUALS(inputWS->getDimension(0)->getName(), + outputWS->getDimension(0)->getName()); + TS_ASSERT_EQUALS(inputWS->getDimension(1)->getName(), + outputWS->getDimension(1)->getName()); + + // Data should be the same too. + TS_ASSERT_EQUALS(inputWS->getSignalAt(0), outputWS->getSignalAt(0)); + TS_ASSERT_EQUALS(inputWS->getSignalAt(1), outputWS->getSignalAt(1)); + TS_ASSERT_EQUALS(inputWS->getSignalAt(2), outputWS->getSignalAt(2)); + } + + void test_transpose_all() { + auto inputWS = MDEventsTestHelper::makeFakeMDHistoWorkspace( + 1 /*signal*/, 2 /*numDims*/, 3 /*numBins in each dimension*/); + + // Set some values. If transposed then these should end up elsewhere. + inputWS->setSignalAt(0, 2); + inputWS->setSignalAt(1, 2); + + TransposeMD transposeMD; + transposeMD.setChild(true); + transposeMD.initialize(); + transposeMD.setPropertyValue("OutputWorkspace", "dummy"); + transposeMD.setProperty("InputWorkspace", inputWS); + std::vector<int> axes; + axes.push_back(1); + axes.push_back(0); + transposeMD.setProperty("Axes", axes); + transposeMD.execute(); + IMDHistoWorkspace_sptr outputWS = + transposeMD.getProperty("OutputWorkspace"); + + // Lets check the output workspace + TS_ASSERT_EQUALS(inputWS->getNumDims(), outputWS->getNumDims()); + TS_ASSERT_EQUALS(inputWS->getDimension(0)->getName(), + outputWS->getDimension(axes[0])->getName()); + TS_ASSERT_EQUALS(inputWS->getDimension(1)->getName(), + outputWS->getDimension(axes[1])->getName()); + + // Data should be transposed. + TS_ASSERT_EQUALS(inputWS->getSignalAt(0), outputWS->getSignalAt(0)); + TS_ASSERT_EQUALS(inputWS->getSignalAt(1), outputWS->getSignalAt(1 * 3)); + TS_ASSERT_EQUALS(inputWS->getSignalAt(2), outputWS->getSignalAt(2)); + } + + void test_collapse() { + + size_t nbins[3] = {3, 3, 1}; // last dimension integrated out + Mantid::coord_t min[3] = {0, 0, 0}; + Mantid::coord_t max[3] = {10, 10, 5}; + auto inputWS = MDEventsTestHelper::makeFakeMDHistoWorkspaceGeneral(3 /*ndims*/, 1 /*signal*/, + 1 /*errorSquared*/, + nbins /*numBins*/, min, max); + // Set some values. If transposed then these should end up elsewhere. + inputWS->setSignalAt(0, 2); + inputWS->setSignalAt(1, 2); + + TransposeMD transposeMD; + transposeMD.setChild(true); + transposeMD.initialize(); + transposeMD.setPropertyValue("OutputWorkspace", "dummy"); + transposeMD.setProperty("InputWorkspace", inputWS); + std::vector<int> axes; + axes.push_back(0); + axes.push_back(1); + transposeMD.setProperty("Axes", axes); // 0 and 1, but 2 not specified! + transposeMD.execute(); + IMDHistoWorkspace_sptr outputWS = + transposeMD.getProperty("OutputWorkspace"); + + // Lets check that output workspace + TS_ASSERT_EQUALS(inputWS->getNumDims(), outputWS->getNumDims() + 1); + TS_ASSERT_EQUALS(inputWS->getDimension(0)->getName(), + outputWS->getDimension(axes[0])->getName()); + TS_ASSERT_EQUALS(inputWS->getDimension(1)->getName(), + outputWS->getDimension(axes[1])->getName()); + + // Otherwise the data should be the same. We simply clipped off the + // integrated dimension. + TS_ASSERT_EQUALS(inputWS->getSignalAt(0), outputWS->getSignalAt(0)); + TS_ASSERT_EQUALS(inputWS->getSignalAt(1), outputWS->getSignalAt(1)); + TS_ASSERT_EQUALS(inputWS->getSignalAt(2), outputWS->getSignalAt(2)); + } +}; + +#endif /* MANTID_MDALGORITHMS_TRANSPOSEMDTEST_H_ */ diff --git a/Code/Mantid/Vates/ParaviewPlugins/ParaViewWidgets/QtWidgets/CMakeLists.txt b/Code/Mantid/Vates/ParaviewPlugins/ParaViewWidgets/QtWidgets/CMakeLists.txt index 3e0774ec72bc1363e5dcbc1c94fd3c7476c31bd1..3ad9523a000aef68d45dba67c509f5e72d5759ef 100644 --- a/Code/Mantid/Vates/ParaviewPlugins/ParaViewWidgets/QtWidgets/CMakeLists.txt +++ b/Code/Mantid/Vates/ParaviewPlugins/ParaViewWidgets/QtWidgets/CMakeLists.txt @@ -2,9 +2,6 @@ set( INC_FILES BinInputWidget.h WidgetDllOption.h - GeometryWidget.h - DimensionWidget.h - DimensionWidgetFactory.h LowHighStepInputWidget.h SimpleBinInputWidget.h ThresholdRangeWidget.h @@ -13,8 +10,6 @@ set( INC_FILES # header files that are mocced set( HDR_FILES BinInputWidget.h - GeometryWidget.h - DimensionWidget.h LowHighStepInputWidget.h SimpleBinInputWidget.h ThresholdRangeWidget.h @@ -22,9 +17,6 @@ set( HDR_FILES # source files set( SRC_FILES - GeometryWidget.cpp - DimensionWidget.cpp - DimensionWidgetFactory.cpp LowHighStepInputWidget.cpp SimpleBinInputWidget.cpp ThresholdRangeWidget.cpp diff --git a/Code/Mantid/Vates/ParaviewPlugins/ParaViewWidgets/QtWidgets/DimensionWidget.cpp b/Code/Mantid/Vates/ParaviewPlugins/ParaViewWidgets/QtWidgets/DimensionWidget.cpp deleted file mode 100644 index 66f4fafd4cf509b7aaca7f6bd7cc6b67dd1afdf6..0000000000000000000000000000000000000000 --- a/Code/Mantid/Vates/ParaviewPlugins/ParaViewWidgets/QtWidgets/DimensionWidget.cpp +++ /dev/null @@ -1,328 +0,0 @@ -#include <QLabel> -#include <QLayout> -#include <QLineEdit> -#include <QComboBox> -#include <QPushButton> -#include <QCheckBox> -#include <QSpacerItem> -#include <QStackedWidget> -#include <qmessagebox.h> -#include <stdio.h> -#include <string> -#include <vector> -#include <iostream> -#include "DimensionWidget.h" -#include "LowHighStepInputWidget.h" -#include "SimpleBinInputWidget.h" -#include <boost/algorithm/string.hpp> -#include <boost/format.hpp> -#include <boost/scoped_ptr.hpp> - -using namespace Mantid::VATES; - -/** -Constructor -*/ -DimensionWidget::DimensionWidget() : - m_layout(NULL), m_binLayout(NULL), m_axisLayout(NULL), m_currentDimensionIndex(0), - m_currentBinWidgetIndex(0), m_pDimensionPresenter(NULL), m_initialBinDisplay(BinDisplay::Simple) -{ - m_binStackedWidget = new QStackedWidget; - BinInputWidget* simple = new SimpleBinInputWidget; - BinInputWidget* lowstephigh = new LowHighStepInputWidget; - m_binStackedWidget->addWidget(simple); - m_binStackedWidget->addWidget(lowstephigh); - m_binStackedWidget->addWidget(new QLabel("")); - m_binStackedWidget->setCurrentIndex(m_currentBinWidgetIndex); - - using namespace Mantid::Geometry; - QVBoxLayout* m_layout = new QVBoxLayout(); - m_layout->setSpacing(2); - - m_dimensionLabel = new QLabel(); - m_layout->addWidget(m_dimensionLabel, Qt::AlignLeft); - - QHBoxLayout* m_binLayout = new QHBoxLayout(); - - m_ckIntegrated = new QCheckBox(); - m_ckIntegrated->setText("Integrate"); - m_ckIntegrated->setToolTip("Collapse/Expand dimension"); - connect(m_ckIntegrated, SIGNAL(clicked(bool)), this, SLOT(integratedChanged(bool))); - m_binLayout->addWidget(m_ckIntegrated); - - QSpacerItem* spacer = new QSpacerItem(40, 20, - QSizePolicy::Maximum, - QSizePolicy::Minimum); - m_binLayout->addSpacerItem(spacer); - - m_binLayout->addWidget(m_binStackedWidget, Qt::AlignLeft); - connect(simple, SIGNAL(valueChanged()), this, SLOT(nBinsListener())); - connect(lowstephigh, SIGNAL(valueChanged()), this, SLOT(nBinsListener())); - - m_layout->addLayout(m_binLayout); - - QHBoxLayout* m_axisLayout = new QHBoxLayout(); - - m_dimensionCombo = new QComboBox(); - QSizePolicy sizePolicy(QSizePolicy::Fixed, QSizePolicy::Minimum); - m_dimensionCombo->setSizePolicy(sizePolicy); - m_dimensionCombo->setMinimumSize(QSize(80, 0)); - connect(m_dimensionCombo,SIGNAL(activated(int)),this ,SLOT(dimensionSelectedListener())); - m_axisLayout->addWidget(m_dimensionCombo, Qt::AlignLeft); - - m_axisLayout->addWidget(new QLabel("Min")); - - m_minBox = new QLineEdit(); - m_minBox->setValidator(new QDoubleValidator(this)); - QSizePolicy sizePolicy1(QSizePolicy::Minimum, QSizePolicy::Minimum); - m_minBox->setSizePolicy(sizePolicy1); - m_minBox->setMinimumSize(QSize(50, 0)); - connect(m_minBox, SIGNAL(editingFinished()), this, SLOT(minBoxListener())); - m_axisLayout->addWidget(m_minBox, Qt::AlignLeft); - - m_axisLayout->addWidget(new QLabel("Max")); - - m_maxBox = new QLineEdit(); - m_maxBox->setValidator(new QDoubleValidator(this)); - QSizePolicy sizePolicy2(QSizePolicy::Minimum, QSizePolicy::Minimum); - m_maxBox->setSizePolicy(sizePolicy2); - m_maxBox->setMinimumSize(QSize(50, 0)); - connect(m_maxBox, SIGNAL(editingFinished()), this, SLOT(maxBoxListener())); - m_axisLayout->addWidget(m_maxBox, Qt::AlignLeft); - - m_layout->addLayout(m_axisLayout); - - this->setLayout(m_layout); -} - -void DimensionWidget::initalizeViewMode(BinDisplay binDisplay) -{ - m_initialBinDisplay = binDisplay; -} - - -BinInputWidget* DimensionWidget::getCurrentBinInputWidget() const -{ - QWidget *w; - if (m_binStackedWidget->currentIndex() > 1) - { - w = m_binStackedWidget->widget(m_currentBinWidgetIndex); - } - else - { - w = m_binStackedWidget->currentWidget(); - } - return dynamic_cast<BinInputWidget*>(w); -} - -Mantid::coord_t DimensionWidget::getMinimum() const -{ - return m_minBox->text().toFloat(); -} - -Mantid::coord_t DimensionWidget::getMaximum() const -{ - return m_maxBox->text().toFloat(); -} - -unsigned int DimensionWidget::getNBins() const -{ - int nbins = static_cast<int>(m_pDimensionPresenter->getModel()->getNBins()); - double max = m_pDimensionPresenter->getModel()->getMaximum(); - double min = m_pDimensionPresenter->getModel()->getMinimum(); - BinInputWidget* binInputWidget = getCurrentBinInputWidget(); - int entry = binInputWidget->getEntry(min, max); - if(entry == nbins || entry <= 1) - { - binInputWidget->setEntry(nbins, min, max); - } - return binInputWidget->getEntry(min, max); -} - -void DimensionWidget::displayError(std::string message) const -{ - QMessageBox msgBox; - msgBox.setText(message.c_str()); - msgBox.exec(); -} - -unsigned int DimensionWidget::getSelectedIndex() const -{ - return m_dimensionCombo->currentIndex(); -} - - -void DimensionWidget::showAsNotIntegrated(Mantid::Geometry::VecIMDDimension_sptr) -{ - setDimensionName(m_pDimensionPresenter->getLabel()); - double max = m_pDimensionPresenter->getModel()->getMaximum(); - double min = m_pDimensionPresenter->getModel()->getMinimum(); - m_binStackedWidget->setCurrentIndex(m_currentBinWidgetIndex); - m_ckIntegrated->setChecked(false); - BinInputWidget* binInputWidget = getCurrentBinInputWidget(); - if(binInputWidget->getEntry(min, max) <= 1) - { - size_t modelBins = m_pDimensionPresenter->getModel()->getNBins(); - if( modelBins > 1) - { - binInputWidget->setEntry(int(modelBins), min, max); - } - else - { - binInputWidget->setEntry(10, min, max); - } - - } -} - -/* -Helper method to set dimension names whereever required. -@param name : name of the dimension to display -*/ -void DimensionWidget::setDimensionName(const std::string& name) -{ - m_dimensionLabel->setText(name.c_str()); - this->setToolTip(name.c_str()); -} - - -void DimensionWidget::showAsIntegrated() -{ - setDimensionName(m_pDimensionPresenter->getModel()->getDimensionId()); - m_binStackedWidget->setCurrentIndex(2); - m_ckIntegrated->setChecked(true); -} - -/** Configure the DimensionView to override only selection choice controls. Otherwise leave nbins, max, min in their current state. -*/ -void DimensionWidget::configureWeakly() -{ - using Mantid::Geometry::VecIMDDimension_sptr; - m_dimensionCombo->clear(); - - GeometryPresenter::MappingType mappings = m_pDimensionPresenter->getMappings(); //Should be sv collection? - GeometryPresenter::MappingType::iterator it = mappings.begin(); - unsigned int count = 0; - for(; it != mappings.end(); ++it) - { - m_dimensionCombo->addItem(it->first.c_str()); - if(it->first == m_pDimensionPresenter->getMapping()) - { - m_dimensionCombo->setCurrentItem(count); - } - count++; - - } -} - -/** Configure the DimensionView to override any controls with the values obtained from the model. -*/ -void DimensionWidget::configureStrongly() -{ - configureWeakly(); - double max = m_pDimensionPresenter->getModel()->getMaximum(); - double min = m_pDimensionPresenter->getModel()->getMinimum(); - BinInputWidget* binInputWidget = getCurrentBinInputWidget(); - binInputWidget->setEntry(int(m_pDimensionPresenter->getModel()->getNBins()),min,max); - - std::string maxValueString = boost::str(boost::format("%i") % m_pDimensionPresenter->getModel()->getMaximum()); - m_maxBox->setText(maxValueString.c_str()); - - std::string minValueString = boost::str(boost::format("%i") % m_pDimensionPresenter->getModel()->getMinimum()); - m_minBox->setText(minValueString.c_str()); - setViewMode(m_initialBinDisplay); -} - -void DimensionWidget::accept(Mantid::VATES::DimensionPresenter* pDimensionPresenter) -{ - m_pDimensionPresenter = pDimensionPresenter; -} - -bool DimensionWidget::getIsIntegrated() const -{ - return m_ckIntegrated->isChecked(); -} - -void DimensionWidget::dimensionSelectedListener() -{ - m_pDimensionPresenter->updateModel(); -} - - -void DimensionWidget::nBinsListener() -{ - m_pDimensionPresenter->updateModel(); -} - -void DimensionWidget::minBoxListener() -{ - m_pDimensionPresenter->updateModel(); -} - -void DimensionWidget::maxBoxListener() -{ - m_pDimensionPresenter->updateModel(); -} - -void DimensionWidget::integratedChanged(bool) -{ - try - { - m_pDimensionPresenter->updateModel(); - } - catch(std::invalid_argument& ex) - { - m_ckIntegrated->setChecked(false); - QMessageBox msgBox; - msgBox.setText(ex.what()); - msgBox.exec(); - } -} - -DimensionWidget::~DimensionWidget() -{ -} - -std::string DimensionWidget::getVisDimensionName() const -{ - if(m_dimensionCombo->isHidden()) - { - return m_pDimensionPresenter->getMapping(); - } - else - { - return m_dimensionCombo->currentText().toStdString(); - } -} - -void DimensionWidget::setViewMode(Mantid::VATES::BinDisplay mode) -{ - double max = m_pDimensionPresenter->getModel()->getMaximum(); - double min = m_pDimensionPresenter->getModel()->getMinimum(); - BinInputWidget* binInputWidget = getCurrentBinInputWidget(); - int nBins = binInputWidget->getEntry(min, max); - - if(mode == Simple) - { - m_currentBinWidgetIndex = 0; - if (!m_ckIntegrated->isChecked()) - { - m_binStackedWidget->setCurrentIndex(m_currentBinWidgetIndex); - } - } - else if(mode == LowHighStep) - { - m_currentBinWidgetIndex = 1; - if (!m_ckIntegrated->isChecked()) - { - m_binStackedWidget->setCurrentIndex(m_currentBinWidgetIndex); - } - } - else - { - throw std::invalid_argument("Unknown bin display mode."); - } - BinInputWidget* binWidget = getCurrentBinInputWidget(); - binWidget->setEntry(nBins, min, max); -} - diff --git a/Code/Mantid/Vates/ParaviewPlugins/ParaViewWidgets/QtWidgets/DimensionWidget.h b/Code/Mantid/Vates/ParaviewPlugins/ParaViewWidgets/QtWidgets/DimensionWidget.h deleted file mode 100644 index 9d707e0873ce09f84bec307eb7532ad152e0d039..0000000000000000000000000000000000000000 --- a/Code/Mantid/Vates/ParaviewPlugins/ParaViewWidgets/QtWidgets/DimensionWidget.h +++ /dev/null @@ -1,147 +0,0 @@ -#ifndef DIMENSION_WIDGET_H -#define DIMENSION_WIDGET_H - -#include <qgridlayout.h> -#include <qwidget.h> -#include <memory> -#include <boost/shared_ptr.hpp> -#include <vector> -#include "WidgetDllOption.h" -#include "GeometryWidget.h" -#include "MantidVatesAPI/DimensionPresenter.h" - -//Foward decs -class QLabel; -class QComboBox; -class QLineEdit; -class QCheckBox; -class QStackedWidget; -class BinInputWidget; - -namespace Mantid -{ - namespace Geometry - { - /// Forward decs - class IMDDimension; - } -} - -/** -class is a Qt (QWidget) concrete version of a DimensionView. - -Displays dimension information as commanded by a DimensionPresenter. - -- DimensionWidgets are passed a DimensionPresenter, as part of the accept call, but DimensionWidgets do not own it! -- Controlled by a DimensionPresenter -- Has public methods to allow the DimensionPresenter to command changes - -*/ -// cppcheck-suppress class_X_Y -class EXPORT_OPT_MANTIDPARVIEW DimensionWidget: public QWidget, public Mantid::VATES::DimensionView -{ -Q_OBJECT -public: - - /// Constructor. - DimensionWidget(); - - /// Destructor - ~DimensionWidget(); - - /// Get minimum - Mantid::coord_t getMinimum() const; - - /// Get maximum - Mantid::coord_t getMaximum() const; - - -signals: - void maxSet(); - void minSet(); - void nBinsSet(); -private: - QVBoxLayout* m_layout; - QHBoxLayout* m_binLayout; - QHBoxLayout* m_axisLayout; - - //QLineEdit* m_nBinsBox; - - QLineEdit* m_minBox; - - QLineEdit* m_maxBox; - - QCheckBox* m_ckIntegrated; - - QComboBox* m_dimensionCombo; - - //QLabel* m_nBinsLabel; - - QLabel* m_dimensionLabel; - - int m_currentDimensionIndex; - - int m_currentBinWidgetIndex; - - std::string m_name; - - Mantid::VATES::DimensionPresenter* m_pDimensionPresenter; - - //Stacked widget to contain the bins input widget types. - QStackedWidget* m_binStackedWidget; - - Mantid::VATES::BinDisplay m_initialBinDisplay; - - /// Helper method to set names in all places required. - void setDimensionName(const std::string& name); - - BinInputWidget* getCurrentBinInputWidget() const; - - private slots: - - /// Handles dimension change events. - void dimensionSelectedListener(); - - void nBinsListener(); - - void maxBoxListener(); - - void minBoxListener(); - - void integratedChanged(bool checkedState); - -public: - - //--------------------------------------------------------- - // DimensionView implementations - //--------------------------------------------------------- - virtual void showAsNotIntegrated(Mantid::Geometry::VecIMDDimension_sptr nonIntegratedDims); - - virtual void showAsIntegrated(); - - virtual void displayError(std::string message) const; - - virtual void accept(Mantid::VATES::DimensionPresenter* pDimensionPresenter); - - virtual void configureStrongly(); - - virtual void configureWeakly(); - - virtual std::string getVisDimensionName() const; - - virtual unsigned int getNBins() const; - - virtual unsigned int getSelectedIndex() const; - - virtual bool getIsIntegrated() const; - - virtual void setViewMode(Mantid::VATES::BinDisplay mode); - - //--------------------------------------------------------- - // End DimensionView implementations - //--------------------------------------------------------- - - void initalizeViewMode(Mantid::VATES::BinDisplay binDisplay); -}; - -#endif diff --git a/Code/Mantid/Vates/ParaviewPlugins/ParaViewWidgets/QtWidgets/DimensionWidgetFactory.cpp b/Code/Mantid/Vates/ParaviewPlugins/ParaViewWidgets/QtWidgets/DimensionWidgetFactory.cpp deleted file mode 100644 index 0582eb1c00689def9d848b47606cb733d3f5a02e..0000000000000000000000000000000000000000 --- a/Code/Mantid/Vates/ParaviewPlugins/ParaViewWidgets/QtWidgets/DimensionWidgetFactory.cpp +++ /dev/null @@ -1,21 +0,0 @@ -#include "DimensionWidgetFactory.h" -#include "DimensionWidget.h" - -/** -Constructor -@param binDisplay : Enum indicating what type of bin display should be used. -*/ -DimensionWidgetFactory::DimensionWidgetFactory(Mantid::VATES::BinDisplay binDisplay) : m_binDisplay(binDisplay) -{ -} - -/** -Factory Method. -@return a new DimensionWidget -*/ -Mantid::VATES::DimensionView* DimensionWidgetFactory::create() const -{ - DimensionWidget* widget = new DimensionWidget; - widget->initalizeViewMode(m_binDisplay); - return widget; -} \ No newline at end of file diff --git a/Code/Mantid/Vates/ParaviewPlugins/ParaViewWidgets/QtWidgets/DimensionWidgetFactory.h b/Code/Mantid/Vates/ParaviewPlugins/ParaViewWidgets/QtWidgets/DimensionWidgetFactory.h deleted file mode 100644 index df68ccbf6fd223480fa610eee6c8f77d201bedb8..0000000000000000000000000000000000000000 --- a/Code/Mantid/Vates/ParaviewPlugins/ParaViewWidgets/QtWidgets/DimensionWidgetFactory.h +++ /dev/null @@ -1,24 +0,0 @@ -#ifndef _DIMENSION_WIDGET_FACTORY_H -#define _DIMENSION_WIDGET_FACTORY_H - -#include "WidgetDllOption.h" -#include "MantidVatesAPI/DimensionViewFactory.h" - -/** -class DimensionWidgetFactory -concrete DimensionViewFactory. Creational type, fabricating dimension widgets on request. -*/ -// cppcheck-suppress class_X_Y -class EXPORT_OPT_MANTIDPARVIEW DimensionWidgetFactory : public Mantid::VATES::DimensionViewFactory -{ -public: - /// Constructor - DimensionWidgetFactory(Mantid::VATES::BinDisplay binDisplay); - /// Construction method. - Mantid::VATES::DimensionView* create() const; -private: - /// Bin display configuration. - const Mantid::VATES::BinDisplay m_binDisplay; -}; - -#endif diff --git a/Code/Mantid/Vates/ParaviewPlugins/ParaViewWidgets/QtWidgets/GeometryWidget.cpp b/Code/Mantid/Vates/ParaviewPlugins/ParaViewWidgets/QtWidgets/GeometryWidget.cpp deleted file mode 100644 index f04757075311132d6e13f12c601ec4d18e9724ab..0000000000000000000000000000000000000000 --- a/Code/Mantid/Vates/ParaviewPlugins/ParaViewWidgets/QtWidgets/GeometryWidget.cpp +++ /dev/null @@ -1,96 +0,0 @@ -#include "GeometryWidget.h" -#include "DimensionWidget.h" -#include "MantidVatesAPI/GeometryPresenter.h" -#include <QLabel> -#include <QGridLayout> -#include <QCheckBox> - -using namespace Mantid::VATES; - -/** -Constructor -@param pPresenter : pointer to MVP presenter -@param binDisplay : Enum describing how the bins should be displayed -*/ -GeometryWidget::GeometryWidget(Mantid::VATES::GeometryPresenter* pPresenter, BinDisplay binDisplay) : m_widgetFactory(binDisplay), m_pPresenter(pPresenter), m_ckBinDisplay(new QCheckBox) -{ - m_ckBinDisplay->setText("By Number of Bins"); - m_ckBinDisplay->setToolTip("Specify the exact number of bins or a step in a low, high step schenario"); - m_ckBinDisplay->setChecked(binDisplay == Simple); - connect(m_ckBinDisplay, SIGNAL(clicked(bool)), this, SLOT(binModeChanged(bool))); - - QGridLayout* headerLayout = new QGridLayout(); - QVBoxLayout* bodyLayout = new QVBoxLayout(); - - headerLayout->addWidget(new QLabel("Geometry"), 0, 0, 1, 2, Qt::AlignCenter); - - bodyLayout->addWidget(m_ckBinDisplay); - bodyLayout->addLayout(headerLayout); - - this->setLayout(bodyLayout); - m_pPresenter->acceptView(this); -} - -/// Destructor -GeometryWidget::~GeometryWidget() -{ - delete m_pPresenter; -} - -/** -Add a new dimension view. -@param dimView : dimensionview (widget) to add to overall geometry widget. -*/ -void GeometryWidget::addDimensionView(DimensionView* dimView) -{ - DimensionWidget* dimWidget = dynamic_cast<DimensionWidget*>(dimView); //TODO. design should not need capability queries! - if(dimWidget != NULL) - { - QLayout* layout = this->layout(); - layout->addWidget(dimWidget); - } -} - -/** -Getter for the resultant/current xml string. -@return xml as a string. -*/ -std::string GeometryWidget::getGeometryXMLString() const -{ - return m_pPresenter->getGeometryXML(); -} - -/* -Gets a ref to the dimension view factory -Allows new dimensions of a type compatible with this GeometryWidget to be fabricated. -*/ -const Mantid::VATES::DimensionViewFactory& GeometryWidget::getDimensionViewFactory() -{ - return m_widgetFactory; -} - -/** -Indicate that the geometry widget has been modified by emitting an event. -*/ -void GeometryWidget::raiseModified() -{ - emit valueChanged(); -} - -/** -Handle changes in the binning mode. -*/ -void GeometryWidget::binModeChanged(bool) -{ - this->m_pPresenter->setDimensionModeChanged(); -} - -/** -Getter to indicate whether the number of bins should be used -@return BinDisplayMode to use. -*/ -BinDisplay GeometryWidget::getBinDisplayMode() const -{ - bool useNumberOfBins = this->m_ckBinDisplay->checkState(); - return useNumberOfBins ? Simple : LowHighStep; -} diff --git a/Code/Mantid/Vates/ParaviewPlugins/ParaViewWidgets/QtWidgets/GeometryWidget.h b/Code/Mantid/Vates/ParaviewPlugins/ParaViewWidgets/QtWidgets/GeometryWidget.h deleted file mode 100644 index 05aac8b5a4fa713619ee185b759455b10345e9da..0000000000000000000000000000000000000000 --- a/Code/Mantid/Vates/ParaviewPlugins/ParaViewWidgets/QtWidgets/GeometryWidget.h +++ /dev/null @@ -1,139 +0,0 @@ -#ifndef GEOMETRY_WIDGET_H -#define GEOMETRY_WIDGET_H - -/** This is the GUI implementation of the geometry layout for the Rebinning operations. -* Inpects input geometry to determine possibilities for shaping the geometry via the user interface. -* Manages DimensionWidget and IntegratedDimensionWidget types. - -@author Owen Arnold Tessella/ISIS -@date January 10/2011 - -Copyright © 2008 ISIS Rutherford Appleton Laboratory, NScD Oak Ridge National Laboratory & European Spallation Source - -This file is part of Mantid. - -Mantid is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 3 of the License, or -(at your option) any later version. - -Mantid is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program. If not, see <http://www.gnu.org/licenses/>. - -File change history is stored at: <https://github.com/mantidproject/mantid>. -Code Documentation is available at: <http://doxygen.mantidproject.org> -*/ - -#include <memory> -#include <boost/shared_ptr.hpp> -#include "WidgetDllOption.h" -#include "MantidGeometry/MDGeometry/MDGeometryXMLParser.h" -#include "MantidVatesAPI/GeometryView.h" -#include "MantidVatesAPI/DimensionView.h" -#include "DimensionWidgetFactory.h" -#include "DimensionWidget.h" - -/// Foward decs -class QLabel; -class QComboBox; -class QLayout; -class QCheckBox; - -namespace Mantid -{ - namespace Geometry - { - /// Forward decs - class IMDDimension; - } - namespace VATES - { - /// Forward decs - class GeometryPresenter; - } -} - -/** -GeometryWidget is a QWidget and a GeometryView. - -View of an MVP pattern. Controlled by an Presenter, which this View owns. - -- Internally, this type generates a layout onto which the presenter can command the placement of Dimensions. -- This type also owns a factory for creating DimensionViews, which the presenter will utilise. -- The view may be commanded by the presenter to raise events, so that owners of this widget may subscribe to and observe changes. - -*/ -// cppcheck-suppress class_X_Y -class EXPORT_OPT_MANTIDPARVIEW GeometryWidget: public QWidget, public Mantid::VATES::GeometryView -{ - -private: - - /// Dimension generating factory. - DimensionWidgetFactory m_widgetFactory; - - /// MVP presenter. - Mantid::VATES::GeometryPresenter* m_pPresenter; - - /// Checkbox for changing the bin display mode. - QCheckBox* m_ckBinDisplay; - - Q_OBJECT -public: - Q_PROPERTY(QString GeometryXML READ getGeometryXML WRITE setGeometryXML NOTIFY valueChanged) - - /// Constructor - GeometryWidget(Mantid::VATES::GeometryPresenter* pPresenter, Mantid::VATES::BinDisplay binDisplay); - - /// Raise geometry modified event. - virtual void raiseModified(); - - /// Destructor - ~GeometryWidget(); - - /// Gets the chosen geometry configuration. - QString getGeometryXML() const - { - return getGeometryXMLString().c_str(); - } - - /* - Sets the geometry xml. - @param value: xml string. - */ - void setGeometryXML(QString value) - { - //Do nothing. - UNUSED_ARG(value); - } - - /// Add a dimension view. - virtual void addDimensionView(Mantid::VATES::DimensionView*); - - /// Get the new geometry xml. - virtual std::string getGeometryXMLString() const; - - /// Get the dimension generating factory. - virtual const Mantid::VATES::DimensionViewFactory& getDimensionViewFactory(); - - /// Getter to indicate whether the number of bins should be used, or low - virtual Mantid::VATES::BinDisplay getBinDisplayMode() const; - - /// Single signal gets raised if anything changes -Q_SIGNALS: - void valueChanged(); - void ignoreBinChanges(); - -private slots: - - // Handler for the bin mode changing. - void binModeChanged(bool); - -}; - -#endif diff --git a/Code/Mantid/Vates/VatesAPI/CMakeLists.txt b/Code/Mantid/Vates/VatesAPI/CMakeLists.txt index 1b7c641a25d79f492038836bcdc58fe1a025baba..fa6b78519d055c2cdd77c2738d806ede15be563d 100644 --- a/Code/Mantid/Vates/VatesAPI/CMakeLists.txt +++ b/Code/Mantid/Vates/VatesAPI/CMakeLists.txt @@ -9,7 +9,6 @@ src/BoxInfo.cpp src/Common.cpp src/CompositePeaksPresenterVsi.cpp src/ConcretePeaksPresenterVsi.cpp -src/DimensionPresenter.cpp src/EventNexusLoadingPresenter.cpp src/FieldDataToMetadata.cpp src/IgnoreZerosThresholdRange.cpp @@ -29,7 +28,6 @@ src/MetadataJsonManager.cpp src/Normalization.cpp src/NoThresholdRange.cpp src/ProgressAction.cpp -src/SynchronisingGeometryPresenter.cpp src/TimeStepToTimeStep.cpp src/TimeToTimeStep.cpp src/UserDefinedThresholdRange.cpp @@ -68,13 +66,10 @@ inc/MantidVatesAPI/BoxInfo.h inc/MantidVatesAPI/Common.h inc/MantidVatesAPI/CompositePeaksPresenterVsi.h inc/MantidVatesAPI/ConcretePeaksPresenterVsi.h -inc/MantidVatesAPI/DimensionPresenter.h -inc/MantidVatesAPI/DimensionView.h inc/MantidVatesAPI/DimensionViewFactory.h inc/MantidVatesAPI/EventNexusLoadingPresenter.h inc/MantidVatesAPI/FieldDataToMetadata.h inc/MantidVatesAPI/FilteringUpdateProgressAction.h -inc/MantidVatesAPI/GeometryPresenter.h inc/MantidVatesAPI/GeometryView.h inc/MantidVatesAPI/LoadVTK.h inc/MantidVatesAPI/MDEWEventNexusLoadingPresenter.h @@ -98,7 +93,6 @@ inc/MantidVatesAPI/NullPeaksPresenterVsi.h inc/MantidVatesAPI/PeaksPresenterVsi.h inc/MantidVatesAPI/ProgressAction.h inc/MantidVatesAPI/SQWLoadingPresenter.h -inc/MantidVatesAPI/SynchronisingGeometryPresenter.h inc/MantidVatesAPI/ThresholdRange.h inc/MantidVatesAPI/TimeStepToTimeStep.h inc/MantidVatesAPI/TimeToTimeStep.h @@ -139,7 +133,6 @@ test/vtkDataSetToWsNameTest.h test/vtkDataSetToWsLocationTest.h test/ADSWorkspaceProviderTest.h test/BoxInfoTest.h -test/DimensionPresenterTest.h test/EventNexusLoadingPresenterTest.h test/vtkDataSetFactoryTest.h test/vtkDataSetToGeometryTest.h @@ -168,7 +161,6 @@ test/MetadataJsonManagerTest.h test/MetadataToFieldDataTest.h test/NormalizationTest.h test/SQWLoadingPresenterTest.h -test/SynchronisingGeometryPresenterTest.h test/TimeStepToTimeStepTest.h test/TimeToTimeStepTest.h test/UserDefinedThresholdRangeTest.h diff --git a/Code/Mantid/Vates/VatesAPI/inc/MantidVatesAPI/DimensionPresenter.h b/Code/Mantid/Vates/VatesAPI/inc/MantidVatesAPI/DimensionPresenter.h deleted file mode 100644 index 2943a50a9d4510c83a9b93aa13cf175f3bdde9ba..0000000000000000000000000000000000000000 --- a/Code/Mantid/Vates/VatesAPI/inc/MantidVatesAPI/DimensionPresenter.h +++ /dev/null @@ -1,83 +0,0 @@ -#ifndef DIMENSION_PRESENTER_H_ -#define DIMENSION_PRESENTER_H_ -#include "MantidKernel/System.h" -#include "MantidGeometry/MDGeometry/IMDDimension.h" -#include "MantidVatesAPI/GeometryPresenter.h" -#include "MantidVatesAPI/DimensionView.h" - -namespace Mantid -{ - namespace VATES - { - - /** @class DimensionPresenter - - MVP presenter for a IMDDimension model. - - @author Owen Arnold, Tessella Support Services plc - @date 24/05/2011 - - Copyright © 2007-11 ISIS Rutherford Appleton Laboratory, NScD Oak Ridge National Laboratory & European Spallation Source - - This file is part of Mantid. - - Mantid is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 3 of the License, or - (at your option) any later version. - - Mantid is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see <http://www.gnu.org/licenses/>. - - File change history is stored at: <https://github.com/mantidproject/mantid>. - Code Documentation is available at: <http://doxygen.mantidproject.org> - */ - class DimensionView; - class DLLExport DimensionPresenter - { - public: - DimensionPresenter(DimensionView* view, GeometryPresenter * geometryPresenter); - void acceptModelStrongly(Mantid::Geometry::IMDDimension_sptr model); - void acceptModelWeakly(Mantid::Geometry::IMDDimension_sptr model); - void acceptAppliedModel(); - void updateModel(); - Mantid::Geometry::IMDDimension_sptr getAppliedModel() const; - Mantid::Geometry::IMDDimension_sptr getModel() const; - Mantid::Geometry::VecIMDDimension_sptr getNonIntegratedDimensions() const; - std::string getVisDimensionName() const; - std::string getLabel() const; - void updateIfNotIntegrated(); - virtual ~DimensionPresenter(); - GeometryPresenter::MappingType getMappings() const; - void setMapping(std::string mapping); - std::string getMapping() const; - void setViewMode(BinDisplay mode); - private: - void commonSetup(); - DimensionPresenter(const DimensionPresenter&); - DimensionPresenter& operator=(const DimensionPresenter&); - void validate() const; - - /// Core model of MVP - Mantid::Geometry::IMDDimension_sptr m_model; - - /// Core parent geometry presenter in MVP. - GeometryPresenter * m_geometryPresenter; - - /// Core MVP view. - DimensionView* m_view; - - /// Flag capturing the last state of the isIntegrated flag. Used for comparisons. - bool m_lastIsIntegrated; - - /// Mapping name. - std::string m_mapping; - }; - } -} -#endif diff --git a/Code/Mantid/Vates/VatesAPI/inc/MantidVatesAPI/DimensionView.h b/Code/Mantid/Vates/VatesAPI/inc/MantidVatesAPI/DimensionView.h deleted file mode 100644 index e068c5472a6373a000c3d0880553160c3643b192..0000000000000000000000000000000000000000 --- a/Code/Mantid/Vates/VatesAPI/inc/MantidVatesAPI/DimensionView.h +++ /dev/null @@ -1,41 +0,0 @@ -#ifndef DIMENSION_VIEW_H_ -#define DIMENSION_VIEW_H_ -#include "MantidKernel/System.h" -#include "MantidGeometry/MDGeometry/IMDDimension.h" - -namespace Mantid -{ - namespace VATES - { - /// Enum describing the type of display to use - enum BinDisplay{LowHighStep, Simple}; - - /// Forward delaration - class DimensionPresenter; - - /** - class DimensionView - Abstract Dimension View. View in MVP pattern. - */ - class DLLExport DimensionView - { - public: - virtual void configureStrongly() = 0; - virtual void configureWeakly() = 0; - virtual void showAsNotIntegrated(Mantid::Geometry::VecIMDDimension_sptr nonIntegratedDims) = 0; - virtual void showAsIntegrated() = 0; - virtual void displayError(std::string message) const = 0; - virtual void accept(DimensionPresenter* pDimensionPresenter) = 0; //TODO should accept non-deleting unique pointer. - virtual std::string getVisDimensionName() const = 0; - virtual coord_t getMaximum() const = 0; - virtual coord_t getMinimum() const = 0; - virtual unsigned int getNBins() const = 0; - virtual unsigned int getSelectedIndex() const = 0; - virtual bool getIsIntegrated() const = 0; - virtual void setViewMode(BinDisplay mode) = 0; - virtual ~DimensionView() {}; - }; - } -} - -#endif diff --git a/Code/Mantid/Vates/VatesAPI/inc/MantidVatesAPI/GeometryPresenter.h b/Code/Mantid/Vates/VatesAPI/inc/MantidVatesAPI/GeometryPresenter.h deleted file mode 100644 index 0bd5ebd3793d2788000925078f8126f7d043364d..0000000000000000000000000000000000000000 --- a/Code/Mantid/Vates/VatesAPI/inc/MantidVatesAPI/GeometryPresenter.h +++ /dev/null @@ -1,63 +0,0 @@ -#ifndef GEOMETRY_PRESENTER_H -#define GEOMETRY_PRESENTER_H - -#include "MantidKernel/System.h" -#include "MantidGeometry/MDGeometry/IMDDimension.h" -#include <map> - -namespace Mantid -{ - namespace VATES - { - class GeometryView; - class DimensionView; - class DimensionPresenter; - - /** @class GeometryPresenter - - Abstract type for MVP style presenter for a Multi-dimensional workspace geometry. - - @author Owen Arnold, Tessella Support Services plc - @date 24/05/2011 - - Copyright © 2007-11 ISIS Rutherford Appleton Laboratory, NScD Oak Ridge National Laboratory & European Spallation Source - - This file is part of Mantid. - - Mantid is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 3 of the License, or - (at your option) any later version. - - Mantid is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see <http://www.gnu.org/licenses/>. - - File change history is stored at: <https://github.com/mantidproject/mantid>. - Code Documentation is available at: <http://doxygen.mantidproject.org> - */ - - - class DimensionPresenter; - class DLLExport GeometryPresenter - { - public: - typedef std::map<std::string, boost::shared_ptr<DimensionPresenter> > MappingType; - virtual void dimensionResized(DimensionPresenter* pDimensionPresenter) = 0; - virtual void dimensionRealigned(DimensionPresenter* pDimensionPresenter) = 0; - virtual Mantid::Geometry::VecIMDDimension_sptr getNonIntegratedDimensions() const = 0; - virtual MappingType getMappings() const = 0; - virtual std::string getGeometryXML() const = 0; - virtual ~GeometryPresenter() {} - virtual void acceptView(GeometryView*)=0; - virtual void setModified() = 0; - virtual void setDimensionModeChanged() = 0; - }; - } -} - -#endif diff --git a/Code/Mantid/Vates/VatesAPI/inc/MantidVatesAPI/MDHWInMemoryLoadingPresenter.h b/Code/Mantid/Vates/VatesAPI/inc/MantidVatesAPI/MDHWInMemoryLoadingPresenter.h index 1934847aa17b1714793ccacdb8d9e2585f955c51..892ee4a88158fcec943a9cfd67a25a82adee626f 100644 --- a/Code/Mantid/Vates/VatesAPI/inc/MantidVatesAPI/MDHWInMemoryLoadingPresenter.h +++ b/Code/Mantid/Vates/VatesAPI/inc/MantidVatesAPI/MDHWInMemoryLoadingPresenter.h @@ -3,64 +3,81 @@ #include "MantidVatesAPI/MDHWLoadingPresenter.h" #include <boost/scoped_ptr.hpp> +#include <boost/shared_ptr.hpp> #include <vector> class vtkDataSet; -namespace Mantid -{ - namespace VATES - { - /** - @class MDHWInMemoryLoadingPresenter - Presenter for loading MDHWs directly from the ADS, does not touch the disk. - @date 02/12/2011 - - Copyright © 2011 ISIS Rutherford Appleton Laboratory, NScD Oak Ridge National Laboratory & European Spallation Source - - This file is part of Mantid. - - Mantid is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 3 of the License, or - (at your option) any later version. - - Mantid is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see <http://www.gnu.org/licenses/>. - - File change history is stored at: <https://github.com/mantidproject/mantid> - Code Documentation is available at: <http://doxygen.mantidproject.org> - */ - - class MDLoadingView; - class WorkspaceProvider; - class MetaDataExtractorUtils; - class vtkDataSetFactory; - - class DLLExport MDHWInMemoryLoadingPresenter : public MDHWLoadingPresenter - { - public: - MDHWInMemoryLoadingPresenter(MDLoadingView* view, WorkspaceProvider* repository, std::string wsName); - virtual vtkDataSet* execute(vtkDataSetFactory* factory, ProgressAction& rebinningProgressUpdate, ProgressAction& drawingProgressUpdate); - virtual void executeLoadMetadata(); - virtual ~MDHWInMemoryLoadingPresenter(); - virtual bool canReadFile() const; - virtual std::string getWorkspaceTypeName(); - virtual int getSpecialCoordinates(); - std::vector<int> getExtents(); - private: - /// Repository for accessing workspaces. At this level, does not specify how or where from. - boost::scoped_ptr<WorkspaceProvider> m_repository; - /// The name of the workspace. - const std::string m_wsName; - std::string m_wsTypeName; - int m_specialCoords; - }; - } +namespace Mantid { +namespace API { +class IMDHistoWorkspace; +} +namespace VATES { +/** +@class MDHWInMemoryLoadingPresenter +Presenter for loading MDHWs directly from the ADS, does not touch the disk. +@date 02/12/2011 + +Copyright © 2011 ISIS Rutherford Appleton Laboratory, NScD Oak Ridge +National Laboratory & European Spallation Source + +This file is part of Mantid. + +Mantid is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 3 of the License, or +(at your option) any later version. + +Mantid is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see <http://www.gnu.org/licenses/>. + +File change history is stored at: <https://github.com/mantidproject/mantid> +Code Documentation is available at: <http://doxygen.mantidproject.org> +*/ + +class MDLoadingView; +class WorkspaceProvider; +class MetaDataExtractorUtils; +class vtkDataSetFactory; + +class DLLExport MDHWInMemoryLoadingPresenter : public MDHWLoadingPresenter { +public: + MDHWInMemoryLoadingPresenter(MDLoadingView *view, + WorkspaceProvider *repository, + std::string wsName); + virtual vtkDataSet *execute(vtkDataSetFactory *factory, + ProgressAction &rebinningProgressUpdate, + ProgressAction &drawingProgressUpdate); + virtual void executeLoadMetadata(); + virtual ~MDHWInMemoryLoadingPresenter(); + virtual bool canReadFile() const; + virtual std::string getWorkspaceTypeName(); + virtual int getSpecialCoordinates(); + std::vector<int> getExtents(); + +private: + + + /// Repository for accessing workspaces. At this level, does not specify how + /// or where from. + boost::scoped_ptr<WorkspaceProvider> m_repository; + /// The name of the workspace. + const std::string m_wsName; + /// The type name of the workspace + std::string m_wsTypeName; + /// The workspace special coordinate system + int m_specialCoords; + /// Cached visual histogram workspace. Post transpose. Avoids repeating + /// transpose. + boost::shared_ptr<Mantid::API::IMDHistoWorkspace> m_cachedVisualHistoWs; +}; + + +} } #endif diff --git a/Code/Mantid/Vates/VatesAPI/inc/MantidVatesAPI/MDHWLoadingPresenter.h b/Code/Mantid/Vates/VatesAPI/inc/MantidVatesAPI/MDHWLoadingPresenter.h index 51cc1ff323b033960296db10ac7bcb0c06a8d9e9..c6e023f131f7405914fbef84c2c3fbd903c2b9d4 100644 --- a/Code/Mantid/Vates/VatesAPI/inc/MantidVatesAPI/MDHWLoadingPresenter.h +++ b/Code/Mantid/Vates/VatesAPI/inc/MantidVatesAPI/MDHWLoadingPresenter.h @@ -11,80 +11,87 @@ #include <boost/scoped_ptr.hpp> -namespace Mantid -{ - namespace VATES - { - - /** - @class MDHWLoadingPresenter - Abstract presenter encapsulating common operations used by all MDHW type loading. Reduces template bloat. - @author Owen Arnold, Tessella plc - @date 16/08/2011 - - Copyright © 2011 ISIS Rutherford Appleton Laboratory, NScD Oak Ridge National Laboratory & European Spallation Source - - This file is part of Mantid. - - Mantid is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 3 of the License, or - (at your option) any later version. - - Mantid is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see <http://www.gnu.org/licenses/>. - - File change history is stored at: <https://github.com/mantidproject/mantid> - Code Documentation is available at: <http://doxygen.mantidproject.org> - */ - class MDLoadingView; - class DLLExport MDHWLoadingPresenter : public MDLoadingPresenter - { - public: - MDHWLoadingPresenter(MDLoadingView* view); - const std::string& getGeometryXML() const; - virtual bool hasTDimensionAvailable() const; - virtual std::vector<double> getTimeStepValues() const; - virtual std::string getTimeStepLabel() const; - virtual void setAxisLabels(vtkDataSet* visualDataSet); - virtual void makeNonOrthogonal(vtkDataSet* visualDataSet); - virtual ~MDHWLoadingPresenter(); - virtual const std::string& getInstrument(); - virtual double getMinValue(); - virtual double getMaxValue(); - - protected: - /*--------------------------------------------------------------------------- - Common/shared operations and members for all MDHW file-type loading. - ---------------------------------------------------------------------------*/ - MDLoadingView* m_view; - - Mantid::Geometry::MDGeometryBuilderXML<Mantid::Geometry::NoDimensionPolicy> xmlBuilder; - - Mantid::Geometry::IMDDimension_sptr tDimension; - std::vector<std::string> axisLabels; - virtual void appendMetadata(vtkDataSet* visualDataSet, - const std::string& wsName) ; - virtual void extractMetadata(Mantid::API::IMDHistoWorkspace_sptr histoWs); - virtual bool canLoadFileBasedOnExtension(const std::string& filename, - const std::string& expectedExtension) const; - virtual bool shouldLoad(); - bool m_isSetup; - double m_time; - bool m_loadInMemory; - bool m_firstLoad; - - boost::scoped_ptr<MetadataJsonManager> m_metadataJsonManager; - boost::scoped_ptr<MetaDataExtractorUtils> m_metaDataExtractor; - boost::scoped_ptr<VatesConfigurations> m_vatesConfigurations; - - }; - } +namespace Mantid { +namespace VATES { + +/** +@class MDHWLoadingPresenter +Abstract presenter encapsulating common operations used by all MDHW type +loading. Reduces template bloat. +@author Owen Arnold, Tessella plc +@date 16/08/2011 + +Copyright © 2011 ISIS Rutherford Appleton Laboratory, NScD Oak Ridge +National Laboratory & European Spallation Source + +This file is part of Mantid. + +Mantid is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 3 of the License, or +(at your option) any later version. + +Mantid is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see <http://www.gnu.org/licenses/>. + +File change history is stored at: <https://github.com/mantidproject/mantid> +Code Documentation is available at: <http://doxygen.mantidproject.org> +*/ +class MDLoadingView; +class DLLExport MDHWLoadingPresenter : public MDLoadingPresenter { +public: + MDHWLoadingPresenter(MDLoadingView *view); + const std::string &getGeometryXML() const; + virtual bool hasTDimensionAvailable() const; + virtual std::vector<double> getTimeStepValues() const; + virtual std::string getTimeStepLabel() const; + virtual void setAxisLabels(vtkDataSet *visualDataSet); + virtual void makeNonOrthogonal(vtkDataSet *visualDataSet); + virtual ~MDHWLoadingPresenter(); + virtual const std::string &getInstrument(); + virtual double getMinValue(); + virtual double getMaxValue(); + + /// Transpose a workspace to push integrated dimensions to the last + static void transposeWs( + Mantid::API::IMDHistoWorkspace_sptr &inHistoWs, + Mantid::API::IMDHistoWorkspace_sptr &outCachedHistoWs); + +protected: + /*--------------------------------------------------------------------------- + Common/shared operations and members for all MDHW file-type loading. + ---------------------------------------------------------------------------*/ + MDLoadingView *m_view; + + Mantid::Geometry::MDGeometryBuilderXML<Mantid::Geometry::NoDimensionPolicy> + xmlBuilder; + + Mantid::Geometry::IMDDimension_sptr tDimension; + std::vector<std::string> axisLabels; + virtual void appendMetadata(vtkDataSet *visualDataSet, + const std::string &wsName); + virtual void extractMetadata(Mantid::API::IMDHistoWorkspace_sptr histoWs); + virtual bool + canLoadFileBasedOnExtension(const std::string &filename, + const std::string &expectedExtension) const; + virtual bool shouldLoad(); + bool m_isSetup; + double m_time; + bool m_loadInMemory; + bool m_firstLoad; + + boost::scoped_ptr<MetadataJsonManager> m_metadataJsonManager; + boost::scoped_ptr<MetaDataExtractorUtils> m_metaDataExtractor; + boost::scoped_ptr<VatesConfigurations> m_vatesConfigurations; +}; + + +} } #endif diff --git a/Code/Mantid/Vates/VatesAPI/inc/MantidVatesAPI/SynchronisingGeometryPresenter.h b/Code/Mantid/Vates/VatesAPI/inc/MantidVatesAPI/SynchronisingGeometryPresenter.h deleted file mode 100644 index 6ac4779145d11ee09f140c63c0c7b3c1644f9f78..0000000000000000000000000000000000000000 --- a/Code/Mantid/Vates/VatesAPI/inc/MantidVatesAPI/SynchronisingGeometryPresenter.h +++ /dev/null @@ -1,135 +0,0 @@ -#ifndef SYNCHRONISING_GEOMETRY_PRESENTER_H_ -#define SYNCHRONISING_GEOMETRY_PRESENTER_H_ - -#include "MantidGeometry/MDGeometry/MDGeometryXMLParser.h" -#include "MantidVatesAPI/GeometryPresenter.h" -#include "MantidGeometry/MDGeometry/IMDDimension.h" -#include "MantidVatesAPI/DimensionView.h" - -namespace Mantid -{ - namespace VATES - { - //Forward dec - class DimensionPresenter; - - typedef boost::shared_ptr<DimensionPresenter> DimPresenter_sptr; - - typedef std::vector<DimPresenter_sptr> VecDimPresenter_sptr; - - /** @class SynchronisingGeometryPresenter - - Concrete type for MVP style presenter for a Multi-dimensional workspace geometry. This implementation synchronises changes between non-integrated and integrated dimensions. - contains knowledge on what should happen as non-integrated dimensions are collapsed and vica-versa. - - @author Owen Arnold, Tessella Support Services plc - @date 24/05/2011 - - Copyright © 2007-8 ISIS Rutherford Appleton Laboratory, NScD Oak Ridge National Laboratory & European Spallation Source - - This file is part of Mantid. - - Mantid is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 3 of the License, or - (at your option) any later version. - - Mantid is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see <http://www.gnu.org/licenses/>. - - File change history is stored at: <https://github.com/mantidproject/mantid>. - Code Documentation is available at: <http://doxygen.mantidproject.org> - */ - class DLLExport SynchronisingGeometryPresenter : public GeometryPresenter - { - public: - - SynchronisingGeometryPresenter(Mantid::Geometry::MDGeometryXMLParser& source); - - void dimensionResized(DimensionPresenter* pDimensionPresenter); - - void dimensionRealigned(DimensionPresenter* pDimensionPresenter); - - Mantid::Geometry::VecIMDDimension_sptr getNonIntegratedDimensions() const; - - Mantid::Geometry::VecIMDDimension_sptr getIntegratedDimensions() const; - - MappingType getMappings() const; - - std::string getGeometryXML() const; - - ~SynchronisingGeometryPresenter(); - - void acceptView(GeometryView*); - - void setModified(); - - void setDimensionModeChanged(); - - //Constant reference name for an X-AXIS - const std::string X_AXIS; - //Constant reference name for an Y-AXIS - const std::string Y_AXIS; - //Constant reference name for an Z-AXIS - const std::string Z_AXIS; - //Constant reference name for an T-AXIS - const std::string T_AXIS; - - private: - - void swap(const GeometryPresenter::MappingType::key_type& keyA, const GeometryPresenter::MappingType::key_type& keyB); - - bool hasXDim() const; - - bool hasYDim() const; - - bool hasZDim() const; - - bool hasTDim() const; - - bool isXDimensionPresenter(DimPresenter_sptr dimensionPresenter) const; - - bool isYDimensionPresenter(DimPresenter_sptr dimensionPresenter) const; - - bool isZDimensionPresenter(DimPresenter_sptr dimensionPresenter) const; - - bool isTDimensionPresenter(DimPresenter_sptr dimensionPresenter) const; - - void shuffleMappedPresenters(); - - void eraseMappedPresenter(DimPresenter_sptr); - - void insertMappedPresenter(DimPresenter_sptr); - - void dimensionExpanded(DimensionPresenter* pDimensionPresenter); - - /// Disabled copy constructor - SynchronisingGeometryPresenter(const SynchronisingGeometryPresenter&); - /// Disabled assignement operator - SynchronisingGeometryPresenter& operator=(const SynchronisingGeometryPresenter&); - /// Collection of synchronised non-integrated dimensions. - mutable Mantid::Geometry::VecIMDDimension_sptr m_dimensions; - /// Original geometry model/source. - Mantid::Geometry::MDGeometryXMLParser m_source; - /// The View with which the presenter will be bound. - GeometryView* m_view; - /// Map containing pairs of visdimensionnames to dimension presenters. - MappingType m_mapping; - /// Current bin display mode - BinDisplay m_binDisplayMode; - protected: - - virtual void dimensionCollapsed(DimensionPresenter* pDimensionPresenter); - - /// Collection of individual dimension presenters owned by this geometry presenter. - VecDimPresenter_sptr m_dimPresenters; - }; - } -} - -#endif \ No newline at end of file diff --git a/Code/Mantid/Vates/VatesAPI/src/DimensionPresenter.cpp b/Code/Mantid/Vates/VatesAPI/src/DimensionPresenter.cpp deleted file mode 100644 index 25c10bb0f0fa4e7e8dcd4aef9860c7ed40a2dd0a..0000000000000000000000000000000000000000 --- a/Code/Mantid/Vates/VatesAPI/src/DimensionPresenter.cpp +++ /dev/null @@ -1,224 +0,0 @@ -#include "MantidVatesAPI/DimensionPresenter.h" -#include "MantidGeometry/MDGeometry/IMDDimensionFactory.h" - -namespace Mantid -{ - namespace VATES - { - /** - Constructor - @param view : MVP view. - @param geometryPresenter : parent presenter wrapping all dimensions. - */ - DimensionPresenter::DimensionPresenter(DimensionView* view, GeometryPresenter * geometryPresenter) : m_geometryPresenter(geometryPresenter), m_view(view), m_lastIsIntegrated(false) - { - } - - /** - Accept a model. In this schenario the model overrules any settings on the view. - @param model : The model to manage/contain. - */ - void DimensionPresenter::acceptModelStrongly(Mantid::Geometry::IMDDimension_sptr model) - { - m_model = model; - m_view->configureStrongly(); - commonSetup(); - } - - /** - Accept a model. In this schenario the model does not overrule settings on the view relating to nbins/max/mins. - @param model : The model to manage/contain. - */ - void DimensionPresenter::acceptModelWeakly(Mantid::Geometry::IMDDimension_sptr model) - { - m_model = model; - m_view->configureWeakly(); - commonSetup(); - } - - void DimensionPresenter::commonSetup() - { - if(m_model->getIsIntegrated()) - { - m_view->showAsIntegrated(); - m_lastIsIntegrated = true; - } - else - { - m_view->showAsNotIntegrated(m_geometryPresenter->getNonIntegratedDimensions()); - m_lastIsIntegrated = false; - } - } - - /** - Accept the applied model. i.e. Model -> AppliedModel - */ - void DimensionPresenter::acceptAppliedModel() - { - m_model = this->getAppliedModel(); - } - - /** - Callable method from the view. Determines what to do after the view is updated in some manner. - */ - void DimensionPresenter::updateModel() - { - validate(); - bool isIntegrated = m_view->getIsIntegrated(); - std::string mapping = m_view->getVisDimensionName(); - if(isIntegrated != m_lastIsIntegrated) - { - //Dimension must have been collapsed/integrated. - m_geometryPresenter->dimensionResized(this); - m_lastIsIntegrated = isIntegrated; - } - else if(mapping != this->m_mapping) - { - //Dimensions must have been swapped. - m_geometryPresenter->dimensionRealigned(this); - } - if(isIntegrated) - { - m_view->showAsIntegrated(); - } - else - { - m_view->showAsNotIntegrated(m_geometryPresenter->getNonIntegratedDimensions()); - } - m_geometryPresenter->setModified(); - } - - /** - Update the view only if it is displaying for non-integrated. - */ - void DimensionPresenter::updateIfNotIntegrated() - { - if(!m_view->getIsIntegrated()) - { - m_view->configureWeakly(); - m_view->showAsNotIntegrated(m_geometryPresenter->getNonIntegratedDimensions()); - m_lastIsIntegrated = false; - } - } - - /** - Getter for the applied model. This is the base model + any changes taken from the view. - @return applied model. - */ - Mantid::Geometry::IMDDimension_sptr DimensionPresenter::getAppliedModel() const - { - validate(); - bool isIntegrated = m_view->getIsIntegrated(); - unsigned int nbins; - if(!isIntegrated) //TODO. Needs cleaning up! - { - if(m_view->getNBins() > 1) - { - nbins = m_view->getNBins(); - } - else - { - nbins = 10; - } - } - else - { - nbins = 1; - } - - auto min = m_view->getMinimum(); - auto max = m_view->getMaximum(); - try - { - return Mantid::Geometry::createDimension(m_model->toXMLString(), nbins, min, max); - } - catch(std::invalid_argument&) - { - m_view->configureStrongly(); - m_view->displayError("Check the ranges just entered. Must have min < max."); - return m_model; - } - } - - /** - Getter for the MVP model. - @return read-only model to visualise. - */ - Mantid::Geometry::IMDDimension_sptr DimensionPresenter::getModel() const - { - validate(); - return m_model; - } - - /// Destructor - DimensionPresenter::~DimensionPresenter() - { - } - - /** - Validate the usage of the presenter. - */ - void DimensionPresenter::validate() const - { - if(m_model.get() == NULL) - { - throw std::runtime_error("Trying to use DimensionPresenter without calling ::acceptModel first"); - } - } - - /** - Getter for the label to use for this presenter. - @return applied label. - */ - std::string DimensionPresenter::getLabel() const - { - return this->m_model->getDimensionId(); - } - - /** - Getter for the name of the visualisation dimension. - @return name of the visualisation dimension this presenter is using (if any) - */ - std::string DimensionPresenter::getVisDimensionName() const - { - return m_view->getVisDimensionName(); - } - - /** - Pass through method. Gets all mapping-presenter pairs. - @return mapping pairs. - */ - GeometryPresenter::MappingType DimensionPresenter::getMappings() const - { - return m_geometryPresenter->getMappings(); - } - - /** - Setter for the mapping to use. - @param mapping to use. - */ - void DimensionPresenter::setMapping(std::string mapping) - { - this->m_mapping = mapping; - } - - /** - Getter for the mapping to use. - @return mapping used. - */ - std::string DimensionPresenter::getMapping() const - { - return m_mapping; - } - - /** - Setter for the bin display mode. - @param mode : Bin display mode. - */ - void DimensionPresenter::setViewMode(BinDisplay mode) - { - this->m_view->setViewMode(mode); - } - - } -} diff --git a/Code/Mantid/Vates/VatesAPI/src/MDHWInMemoryLoadingPresenter.cpp b/Code/Mantid/Vates/VatesAPI/src/MDHWInMemoryLoadingPresenter.cpp index ca524ac4cf2c79d10e0cd2b022e6763955cf6797..cd33892016a552eaa9ad50da8706884293732f4d 100644 --- a/Code/Mantid/Vates/VatesAPI/src/MDHWInMemoryLoadingPresenter.cpp +++ b/Code/Mantid/Vates/VatesAPI/src/MDHWInMemoryLoadingPresenter.cpp @@ -1,4 +1,5 @@ #include "MantidVatesAPI/MDHWInMemoryLoadingPresenter.h" +#include "MantidAPI/AlgorithmManager.h" #include "MantidAPI/IMDHistoWorkspace.h" #include "MantidVatesAPI/MDLoadingView.h" #include "MantidVatesAPI/MetaDataExtractorUtils.h" @@ -9,160 +10,163 @@ #include <qwt_double_interval.h> #include <vtkUnstructuredGrid.h> -namespace Mantid -{ - namespace VATES - { - - /* - Constructor - @param view : MVP view - @param repository : Object for accessing the workspaces - @param wsName : Name of the workspace to use. - @throw invalid_argument if the workspace name is empty - @throw invalid_argument if the repository is null - @throw invalid_arument if view is null - */ - MDHWInMemoryLoadingPresenter::MDHWInMemoryLoadingPresenter(MDLoadingView* view, WorkspaceProvider* repository, std::string wsName) : MDHWLoadingPresenter(view), - m_repository(repository), m_wsName(wsName), m_wsTypeName(""), m_specialCoords(-1) - { - if(m_wsName.empty()) - { - throw std::invalid_argument("The workspace name is empty."); - } - if(NULL == repository) - { - throw std::invalid_argument("The repository is NULL"); - } - if(NULL == m_view) - { - throw std::invalid_argument("View is NULL."); - } - } - - /* - Indicates whether this presenter is capable of handling the type of file that is attempted to be loaded. - @return false if the file cannot be read. - */ - bool MDHWInMemoryLoadingPresenter::canReadFile() const - { - bool bCanReadIt = true; - if(!m_repository->canProvideWorkspace(m_wsName)) - { - //The workspace does not exist. - bCanReadIt = false; - } - else if(NULL == boost::dynamic_pointer_cast<Mantid::API::IMDHistoWorkspace>(m_repository->fetchWorkspace(m_wsName)).get()) - { - //The workspace can be found, but is not an IMDHistoWorkspace. - bCanReadIt = false; - } - else - { - //The workspace is present, and is of the correct type. - bCanReadIt = true; - } - return bCanReadIt; - } - - /* - Executes the underlying algorithm to create the MVP model. - @param factory : visualisation factory to use. - @param : Handler for GUI updates while algorithm progresses. - @param drawingProgressUpdate : Handler for GUI updates while vtkDataSetFactory::create occurs. - */ - vtkDataSet* MDHWInMemoryLoadingPresenter::execute(vtkDataSetFactory* factory, ProgressAction&, ProgressAction& drawingProgressUpdate) - { - using namespace Mantid::API; - using namespace Mantid::Geometry; - - Workspace_sptr ws = m_repository->fetchWorkspace(m_wsName); - IMDHistoWorkspace_sptr histoWs = boost::dynamic_pointer_cast<Mantid::API::IMDHistoWorkspace>(ws); - - //factory->setRecursionDepth(this->m_view->getRecursionDepth()); - vtkDataSet* visualDataSet = factory->oneStepCreate(histoWs, drawingProgressUpdate);//HACK: progressUpdate should be argument for drawing! - - /*extractMetaData needs to be re-run here because the first execution of this from ::executeLoadMetadata will not have ensured that all dimensions - have proper range extents set. - */ - - // Update the meta data min and max values with the values of the visual data set. This is necessary since we want the full data range of the visual - // data set and not of the actual underlying data set. - double* range = visualDataSet->GetScalarRange(); - if (range) - { - this->m_metadataJsonManager->setMinValue(range[0]); - this->m_metadataJsonManager->setMaxValue(range[1]); - } - - this->extractMetadata(histoWs); - - this->appendMetadata(visualDataSet, histoWs->getName()); - return visualDataSet; - } - - /** - Executes any meta-data loading required. - */ - void MDHWInMemoryLoadingPresenter::executeLoadMetadata() - { - using namespace Mantid::API; - - Workspace_sptr ws = m_repository->fetchWorkspace(m_wsName); - IMDHistoWorkspace_sptr histoWs = boost::dynamic_pointer_cast<Mantid::API::IMDHistoWorkspace>(ws); - m_wsTypeName = histoWs->id(); - m_specialCoords = histoWs->getSpecialCoordinateSystem(); - - // Set the minimum and maximum of the workspace data. - QwtDoubleInterval minMaxContainer = m_metaDataExtractor->getMinAndMax(histoWs); - m_metadataJsonManager->setMinValue(minMaxContainer.minValue()); - m_metadataJsonManager->setMaxValue(minMaxContainer.maxValue()); - - // Set the instrument which is associated with the workspace. - m_metadataJsonManager->setInstrument(m_metaDataExtractor->extractInstrument(histoWs)); - - // Set the special coordinates - m_metadataJsonManager->setSpecialCoordinates(m_specialCoords); - - //Call base-class extraction method. - this->extractMetadata(histoWs); - } - - ///Destructor - MDHWInMemoryLoadingPresenter::~MDHWInMemoryLoadingPresenter() - { - delete m_view; - } - - /* - * Getter for the workspace type name. - * @return Workspace Type Name - */ - std::string MDHWInMemoryLoadingPresenter::getWorkspaceTypeName() - { - return m_wsTypeName; - } - - /** - * Getter for the special coordinates. - * @return the special coordinates value - */ - int MDHWInMemoryLoadingPresenter::getSpecialCoordinates() - { - return m_specialCoords; - } - - std::vector<int> MDHWInMemoryLoadingPresenter::getExtents() - { - using namespace Mantid::API; - Workspace_sptr ws = m_repository->fetchWorkspace(m_wsName); - IMDHistoWorkspace_sptr histoWs = boost::dynamic_pointer_cast<Mantid::API::IMDHistoWorkspace>(ws); - std::vector<int> extents(6, 0); - extents[1] = static_cast<int>(histoWs->getXDimension()->getNBins()); - extents[3] = static_cast<int>(histoWs->getYDimension()->getNBins()); - extents[5] = static_cast<int>(histoWs->getZDimension()->getNBins()); - return extents; - } - +namespace Mantid { +namespace VATES { + +/* +Constructor +@param view : MVP view +@param repository : Object for accessing the workspaces +@param wsName : Name of the workspace to use. +@throw invalid_argument if the workspace name is empty +@throw invalid_argument if the repository is null +@throw invalid_arument if view is null +*/ +MDHWInMemoryLoadingPresenter::MDHWInMemoryLoadingPresenter( + MDLoadingView *view, WorkspaceProvider *repository, std::string wsName) + : MDHWLoadingPresenter(view), m_repository(repository), m_wsName(wsName), + m_wsTypeName(""), m_specialCoords(-1) { + if (m_wsName.empty()) { + throw std::invalid_argument("The workspace name is empty."); } + if (NULL == repository) { + throw std::invalid_argument("The repository is NULL"); + } + if (NULL == m_view) { + throw std::invalid_argument("View is NULL."); + } +} + +/* +Indicates whether this presenter is capable of handling the type of file that is +attempted to be loaded. +@return false if the file cannot be read. +*/ +bool MDHWInMemoryLoadingPresenter::canReadFile() const { + bool bCanReadIt = true; + if (!m_repository->canProvideWorkspace(m_wsName)) { + // The workspace does not exist. + bCanReadIt = false; + } else if (NULL == + boost::dynamic_pointer_cast<Mantid::API::IMDHistoWorkspace>( + m_repository->fetchWorkspace(m_wsName)).get()) { + // The workspace can be found, but is not an IMDHistoWorkspace. + bCanReadIt = false; + } else { + // The workspace is present, and is of the correct type. + bCanReadIt = true; + } + return bCanReadIt; +} + + +/* +Executes the underlying algorithm to create the MVP model. +@param factory : visualisation factory to use. +@param : Handler for GUI updates while algorithm progresses. +@param drawingProgressUpdate : Handler for GUI updates while +vtkDataSetFactory::create occurs. +*/ +vtkDataSet * +MDHWInMemoryLoadingPresenter::execute(vtkDataSetFactory *factory, + ProgressAction &, + ProgressAction &drawingProgressUpdate) { + using namespace Mantid::API; + using namespace Mantid::Geometry; + + Workspace_sptr ws = m_repository->fetchWorkspace(m_wsName); + IMDHistoWorkspace_sptr histoWs = + boost::dynamic_pointer_cast<Mantid::API::IMDHistoWorkspace>(ws); + + MDHWLoadingPresenter::transposeWs(histoWs, m_cachedVisualHistoWs); + + // factory->setRecursionDepth(this->m_view->getRecursionDepth()); + vtkDataSet *visualDataSet = factory->oneStepCreate( + m_cachedVisualHistoWs, drawingProgressUpdate); // HACK: progressUpdate should be + // argument for drawing! + + /*extractMetaData needs to be re-run here because the first execution of this + from ::executeLoadMetadata will not have ensured that all dimensions + have proper range extents set. + */ + + // Update the meta data min and max values with the values of the visual data + // set. This is necessary since we want the full data range of the visual + // data set and not of the actual underlying data set. + double *range = visualDataSet->GetScalarRange(); + if (range) { + this->m_metadataJsonManager->setMinValue(range[0]); + this->m_metadataJsonManager->setMaxValue(range[1]); + } + + this->extractMetadata(m_cachedVisualHistoWs); + + // Transposed workpace is temporary, outside the ADS, and does not have a name. so get it from pre-transposed. + this->appendMetadata(visualDataSet, histoWs->getName()); + return visualDataSet; +} + +/** + Executes any meta-data loading required. +*/ +void MDHWInMemoryLoadingPresenter::executeLoadMetadata() { + using namespace Mantid::API; + + Workspace_sptr ws = m_repository->fetchWorkspace(m_wsName); + IMDHistoWorkspace_sptr histoWs = + boost::dynamic_pointer_cast<Mantid::API::IMDHistoWorkspace>(ws); + m_wsTypeName = histoWs->id(); + m_specialCoords = histoWs->getSpecialCoordinateSystem(); + + MDHWLoadingPresenter::transposeWs(histoWs, m_cachedVisualHistoWs); + + // Set the minimum and maximum of the workspace data. + QwtDoubleInterval minMaxContainer = + m_metaDataExtractor->getMinAndMax(histoWs); + m_metadataJsonManager->setMinValue(minMaxContainer.minValue()); + m_metadataJsonManager->setMaxValue(minMaxContainer.maxValue()); + + // Set the instrument which is associated with the workspace. + m_metadataJsonManager->setInstrument( + m_metaDataExtractor->extractInstrument(m_cachedVisualHistoWs)); + + // Set the special coordinates + m_metadataJsonManager->setSpecialCoordinates(m_specialCoords); + + // Call base-class extraction method. + this->extractMetadata(m_cachedVisualHistoWs); +} + +/// Destructor +MDHWInMemoryLoadingPresenter::~MDHWInMemoryLoadingPresenter() { delete m_view; } + +/* + * Getter for the workspace type name. + * @return Workspace Type Name + */ +std::string MDHWInMemoryLoadingPresenter::getWorkspaceTypeName() { + return m_wsTypeName; +} + +/** + * Getter for the special coordinates. + * @return the special coordinates value + */ +int MDHWInMemoryLoadingPresenter::getSpecialCoordinates() { + return m_specialCoords; +} + +std::vector<int> MDHWInMemoryLoadingPresenter::getExtents() { + using namespace Mantid::API; + Workspace_sptr ws = m_repository->fetchWorkspace(m_wsName); + IMDHistoWorkspace_sptr histoWs = + boost::dynamic_pointer_cast<Mantid::API::IMDHistoWorkspace>(ws); + MDHWLoadingPresenter::transposeWs(histoWs, m_cachedVisualHistoWs); + std::vector<int> extents(6, 0); + extents[1] = static_cast<int>(m_cachedVisualHistoWs->getXDimension()->getNBins()); + extents[3] = static_cast<int>(m_cachedVisualHistoWs->getYDimension()->getNBins()); + extents[5] = static_cast<int>(m_cachedVisualHistoWs->getZDimension()->getNBins()); + return extents; +} +} } diff --git a/Code/Mantid/Vates/VatesAPI/src/MDHWLoadingPresenter.cpp b/Code/Mantid/Vates/VatesAPI/src/MDHWLoadingPresenter.cpp index 319edd9f331cb6744b9b0288182b0d5613ed4703..94604ad1e3757716284142eb606af3c24d39dea9 100644 --- a/Code/Mantid/Vates/VatesAPI/src/MDHWLoadingPresenter.cpp +++ b/Code/Mantid/Vates/VatesAPI/src/MDHWLoadingPresenter.cpp @@ -1,6 +1,8 @@ #include "MantidVatesAPI/MDHWLoadingPresenter.h" #include "MantidVatesAPI/MDLoadingView.h" +#include "MantidAPI/AlgorithmManager.h" #include "MantidAPI/FrameworkManager.h" +#include "MantidAPI/IAlgorithm.h" #include "MantidAPI/IMDHistoWorkspace.h" #include "MantidGeometry/MDGeometry/MDHistoDimension.h" @@ -26,263 +28,300 @@ namespace { Mantid::Kernel::Logger g_log("MDHWLoadingPresenter"); } -namespace Mantid -{ - namespace VATES - { - /// Constructor - MDHWLoadingPresenter::MDHWLoadingPresenter(MDLoadingView* view) : - m_view(view), - m_isSetup(false), - m_time(-1), - m_loadInMemory(false), - m_firstLoad(true), - m_metadataJsonManager(new MetadataJsonManager()), - m_metaDataExtractor(new MetaDataExtractorUtils()), - m_vatesConfigurations(new VatesConfigurations()) - { - Mantid::API::FrameworkManager::Instance(); - } +namespace Mantid { +namespace VATES { - /// Destructor - MDHWLoadingPresenter::~MDHWLoadingPresenter() - { - } +/** + * @brief MDHWInMemoryLoadingPresenter::transposeWs + * + * vtkDataSets are usually provided in 3D, trying to create these where one of + *those dimensions + * might be integrated out leads to empty datasets. To avoid this we reorder the + *dimensions in our workspace + * prior to visualisation by transposing if if needed. + * + * @param inHistoWs : An input workspace that may integrated dimensions + *anywhere. + * @param outCachedHistoWs : Cached histo workspace. To write to if needed. + * @return A workspace that can be directly rendered from. Integrated dimensions + *are always last. + */ +void MDHWLoadingPresenter::transposeWs(Mantid::API::IMDHistoWorkspace_sptr &inHistoWs, + Mantid::API::IMDHistoWorkspace_sptr &outCachedHistoWs) { + using namespace Mantid::API; - /* - Extract the geometry and function information - @param histoWs : histogram workspace to get the information from. - */ - void MDHWLoadingPresenter::extractMetadata(Mantid::API::IMDHistoWorkspace_sptr histoWs) - { - using namespace Mantid::Geometry; - MDGeometryBuilderXML<NoDimensionPolicy> refresh; - xmlBuilder= refresh; //Reassign. - std::vector<IMDDimension_sptr> dimensions; - size_t nDimensions = histoWs->getNumDims(); - for (size_t d=0; d<nDimensions; d++) - { - IMDDimension_const_sptr inDim = histoWs->getDimension(d); - coord_t min = inDim->getMinimum(); - coord_t max = inDim->getMaximum(); - if (min > max) - { - min = 0.0; - max = 1.0; - } - //std::cout << "dim " << d << min << " to " << max << std::endl; - axisLabels.push_back(makeAxisTitle(inDim)); - MDHistoDimension_sptr dim(new MDHistoDimension(inDim->getName(), inDim->getName(), inDim->getUnits(), min, max, inDim->getNBins())); - dimensions.push_back(dim); + if (!outCachedHistoWs) { + /* + Construct dimension indexes list for transpose. We do this by forcing + integrated + dimensions to be the last in the list. All other orderings are kept. + */ + std::vector<int> integratedDims; + std::vector<int> nonIntegratedDims; + for (int i = 0; i < int(inHistoWs->getNumDims()); ++i) { + auto dim = inHistoWs->getDimension(i); + if (dim->getIsIntegrated()) { + integratedDims.push_back(i); + } else { + nonIntegratedDims.push_back(i); } + } + std::vector<int> orderedDims; + orderedDims = nonIntegratedDims; + orderedDims.insert(orderedDims.end(), integratedDims.begin(), + integratedDims.end()); - //Configuring the geometry xml builder allows the object panel associated with this reader to later - //determine how to display all geometry related properties. - if(nDimensions > 0) - { - xmlBuilder.addXDimension( dimensions[0] ); - } - if(nDimensions > 1) - { - xmlBuilder.addYDimension( dimensions[1] ); - } - if(nDimensions > 2) - { - xmlBuilder.addZDimension( dimensions[2] ); - } - if(nDimensions > 3) - { - tDimension = dimensions[3]; - xmlBuilder.addTDimension(tDimension); - } - m_isSetup = true; + /* + If there has been any reordering above, then the dimension indexes will + no longer be sorted. We use that to determine if we can avoid transposing + the workspace. + */ + if (!std::is_sorted(orderedDims.begin(), orderedDims.end())) { + IAlgorithm_sptr alg = AlgorithmManager::Instance().create("TransposeMD"); + alg->setChild(true); + alg->initialize(); + alg->setProperty("InputWorkspace", inHistoWs); + alg->setPropertyValue("OutputWorkspace", "dummy"); + alg->setProperty("Axes", orderedDims); + alg->execute(); + IMDHistoWorkspace_sptr visualHistoWs = + alg->getProperty("OutputWorkspace"); + outCachedHistoWs = visualHistoWs; + } else { + // No need to transpose anything. + outCachedHistoWs = inHistoWs; } + } +} - /** - Method determines whether loading/re-loading is necessary. - */ - bool MDHWLoadingPresenter::shouldLoad() - { - double viewTime = m_view->getTime(); - bool viewLoadInMemory = m_view->getLoadInMemory(); +/// Constructor +MDHWLoadingPresenter::MDHWLoadingPresenter(MDLoadingView *view) + : m_view(view), m_isSetup(false), m_time(-1), m_loadInMemory(false), + m_firstLoad(true), m_metadataJsonManager(new MetadataJsonManager()), + m_metaDataExtractor(new MetaDataExtractorUtils()), + m_vatesConfigurations(new VatesConfigurations()) { + Mantid::API::FrameworkManager::Instance(); +} - bool bExecute = false; - if(m_time != viewTime) - { - bExecute = false; //Time has changed. This DOES NOT require reloading. - } - if(m_loadInMemory != viewLoadInMemory) - { - bExecute = true; //Must reload with memory/file option. - } - if(m_firstLoad) - { - bExecute = true; //First time round. should execute underlying algorithm. - } +/// Destructor +MDHWLoadingPresenter::~MDHWLoadingPresenter() {} - // Save state. - m_time = viewTime; - m_loadInMemory = viewLoadInMemory; - m_firstLoad = false; - //Return decision. - return bExecute; - } - - /** - Determines wheter the file can be loaded based on it's extension. - @param filename containing the extension - @param expectedExtension expected extension for the file to have - @return TRUE, only if the extension is approved. - */ - bool MDHWLoadingPresenter::canLoadFileBasedOnExtension(const std::string& filename, const std::string& expectedExtension) const - { - // Quick check based on extension. - const size_t startExtension = filename.find_last_of('.'); - const size_t endExtension = filename.length(); - std::string extension = filename.substr(startExtension, endExtension - startExtension); - boost::algorithm::to_lower(extension); - boost::algorithm::trim(extension); - return extension == expectedExtension; +/* +Extract the geometry and function information +@param histoWs : histogram workspace to get the information from. +*/ +void MDHWLoadingPresenter::extractMetadata( + Mantid::API::IMDHistoWorkspace_sptr histoWs) { + using namespace Mantid::Geometry; + MDGeometryBuilderXML<NoDimensionPolicy> refresh; + xmlBuilder = refresh; // Reassign. + std::vector<IMDDimension_sptr> dimensions; + size_t nDimensions = histoWs->getNumDims(); + for (size_t d = 0; d < nDimensions; d++) { + IMDDimension_const_sptr inDim = histoWs->getDimension(d); + coord_t min = inDim->getMinimum(); + coord_t max = inDim->getMaximum(); + if (min > max) { + min = 0.0; + max = 1.0; } + // std::cout << "dim " << d << min << " to " << max << std::endl; + axisLabels.push_back(makeAxisTitle(inDim)); + MDHistoDimension_sptr dim( + new MDHistoDimension(inDim->getName(), inDim->getName(), + inDim->getUnits(), min, max, inDim->getNBins())); + dimensions.push_back(dim); + } - /* - Append the geometry and function information onto the outgoing vtkDataSet. - @param visualDataSet : outgoing dataset on which to append metadata. - @param wsName : name of the workspace. - */ - void MDHWLoadingPresenter::appendMetadata(vtkDataSet* visualDataSet, const std::string& wsName) - { - using namespace Mantid::API; + // Configuring the geometry xml builder allows the object panel associated + // with this reader to later + // determine how to display all geometry related properties. + if (nDimensions > 0) { + xmlBuilder.addXDimension(dimensions[0]); + } + if (nDimensions > 1) { + xmlBuilder.addYDimension(dimensions[1]); + } + if (nDimensions > 2) { + xmlBuilder.addZDimension(dimensions[2]); + } + if (nDimensions > 3) { + tDimension = dimensions[3]; + xmlBuilder.addTDimension(tDimension); + } + m_isSetup = true; +} - vtkFieldData* outputFD = vtkFieldData::New(); - - //Serialize metadata - VatesKnowledgeSerializer serializer; - serializer.setWorkspaceName(wsName); - serializer.setGeometryXML(xmlBuilder.create()); - serializer.setImplicitFunction( Mantid::Geometry::MDImplicitFunction_sptr(new Mantid::Geometry::NullImplicitFunction())); - std::string xmlString = serializer.createXMLString(); - - // Serialize Json metadata - std::string jsonString = m_metadataJsonManager->getSerializedJson(); +/** +Method determines whether loading/re-loading is necessary. +*/ +bool MDHWLoadingPresenter::shouldLoad() { + double viewTime = m_view->getTime(); + bool viewLoadInMemory = m_view->getLoadInMemory(); - //Add metadata to dataset. - MetadataToFieldData convert; - convert(outputFD, xmlString, XMLDefinitions::metaDataId().c_str()); - convert(outputFD, jsonString, m_vatesConfigurations->getMetadataIdJson().c_str()); - visualDataSet->SetFieldData(outputFD); - outputFD->Delete(); - } + bool bExecute = false; + if (m_time != viewTime) { + bExecute = false; // Time has changed. This DOES NOT require reloading. + } + if (m_loadInMemory != viewLoadInMemory) { + bExecute = true; // Must reload with memory/file option. + } + if (m_firstLoad) { + bExecute = true; // First time round. should execute underlying algorithm. + } - /** - * Change the data based on non-orthogonal axis information - * @param visualDataSet : The VTK dataset to modify - */ - void MDHWLoadingPresenter::makeNonOrthogonal(vtkDataSet *visualDataSet) - { - std::string wsName = vtkDataSetToWsName::exec(visualDataSet); - vtkDataSetToNonOrthogonalDataSet converter(visualDataSet, wsName); - converter.execute(); - } + // Save state. + m_time = viewTime; + m_loadInMemory = viewLoadInMemory; + m_firstLoad = false; + // Return decision. + return bExecute; +} - /** - * Set the axis labels from the current dimensions - * @param visualDataSet: The VTK dataset to update - */ - void MDHWLoadingPresenter::setAxisLabels(vtkDataSet *visualDataSet) - { - if (!vtkPVChangeOfBasisHelper::AddBasisNames( - visualDataSet, axisLabels[0].c_str(), axisLabels[1].c_str(), - axisLabels[2].c_str())) { - g_log.warning("The basis names could not be added to the field data of " - "the data set.\n"); - } - } +/** +Determines wheter the file can be loaded based on it's extension. +@param filename containing the extension +@param expectedExtension expected extension for the file to have +@return TRUE, only if the extension is approved. +*/ +bool MDHWLoadingPresenter::canLoadFileBasedOnExtension( + const std::string &filename, const std::string &expectedExtension) const { + // Quick check based on extension. + const size_t startExtension = filename.find_last_of('.'); + const size_t endExtension = filename.length(); + std::string extension = + filename.substr(startExtension, endExtension - startExtension); + boost::algorithm::to_lower(extension); + boost::algorithm::trim(extension); + return extension == expectedExtension; +} - /** - Gets the geometry in a string format. - @return geometry string ref. - @throw runtime_error if execute has not been run first. - */ - const std::string& MDHWLoadingPresenter::getGeometryXML() const - { - if(!m_isSetup) - { - throw std::runtime_error("Have not yet run extractMetaData!"); - } - return xmlBuilder.create(); - } +/* +Append the geometry and function information onto the outgoing vtkDataSet. +@param visualDataSet : outgoing dataset on which to append metadata. +@param wsName : name of the workspace. +*/ +void MDHWLoadingPresenter::appendMetadata(vtkDataSet *visualDataSet, + const std::string &wsName) { + using namespace Mantid::API; - /** - @return boolean indicating whether the T dimension is available. - @throw runtime_error if execute has not been run first. - */ - bool MDHWLoadingPresenter::hasTDimensionAvailable() const - { - if(!m_isSetup) - { - throw std::runtime_error("Have not yet run ::extractMetaData!"); - } - return xmlBuilder.hasTDimension() && !xmlBuilder.hasIntegratedTDimension(); - } + vtkFieldData *outputFD = vtkFieldData::New(); - /* - @return timestep values. - @throw runtime_error if execute has not been run first. - */ - std::vector<double> MDHWLoadingPresenter::getTimeStepValues() const - { - if(!m_isSetup) - { - throw std::runtime_error("Have not yet run ::extractMetaData!"); - } - std::vector<double> result; - for(size_t i = 0; i < tDimension->getNBins(); i++) - { - result.push_back(tDimension->getX(i)); - } - return result; - } + // Serialize metadata + VatesKnowledgeSerializer serializer; + serializer.setWorkspaceName(wsName); + serializer.setGeometryXML(xmlBuilder.create()); + serializer.setImplicitFunction(Mantid::Geometry::MDImplicitFunction_sptr( + new Mantid::Geometry::NullImplicitFunction())); + std::string xmlString = serializer.createXMLString(); - /** - * Create a label for the "time" coordinate - * @return the "time" coordinate label - * @throw runtime_error if execute has not been run first. - */ - std::string MDHWLoadingPresenter::getTimeStepLabel() const - { - if (!m_isSetup) - { - throw std::runtime_error("Have not yet run ::extractMetaData!"); - } - return tDimension->getName() + " (" + tDimension->getUnits().ascii() + ")"; - } + // Serialize Json metadata + std::string jsonString = m_metadataJsonManager->getSerializedJson(); - /** - * Getter for the instrument. - * @returns The name of the instrument which is associated with the workspace. - */ - const std::string& MDHWLoadingPresenter::getInstrument() - { - return m_metadataJsonManager->getInstrument(); - } + // Add metadata to dataset. + MetadataToFieldData convert; + convert(outputFD, xmlString, XMLDefinitions::metaDataId().c_str()); + convert(outputFD, jsonString, + m_vatesConfigurations->getMetadataIdJson().c_str()); + visualDataSet->SetFieldData(outputFD); + outputFD->Delete(); +} - /** - * Getter for the minimum value; - * @return The minimum value of the data set. - */ - double MDHWLoadingPresenter::getMinValue() - { - return m_metadataJsonManager->getMinValue(); - } +/** + * Change the data based on non-orthogonal axis information + * @param visualDataSet : The VTK dataset to modify + */ +void MDHWLoadingPresenter::makeNonOrthogonal(vtkDataSet *visualDataSet) { + std::string wsName = vtkDataSetToWsName::exec(visualDataSet); + vtkDataSetToNonOrthogonalDataSet converter(visualDataSet, wsName); + converter.execute(); +} - /** - * Getter for the maximum value; - * @return The maximum value of the data set. - */ - double MDHWLoadingPresenter::getMaxValue() - { - return m_metadataJsonManager->getMaxValue(); - } +/** + * Set the axis labels from the current dimensions + * @param visualDataSet: The VTK dataset to update + */ +void MDHWLoadingPresenter::setAxisLabels(vtkDataSet *visualDataSet) { + if (!vtkPVChangeOfBasisHelper::AddBasisNames( + visualDataSet, axisLabels[0].c_str(), axisLabels[1].c_str(), + axisLabels[2].c_str())) { + g_log.warning("The basis names could not be added to the field data of " + "the data set.\n"); + } +} + +/** +Gets the geometry in a string format. +@return geometry string ref. +@throw runtime_error if execute has not been run first. +*/ +const std::string &MDHWLoadingPresenter::getGeometryXML() const { + if (!m_isSetup) { + throw std::runtime_error("Have not yet run extractMetaData!"); } + return xmlBuilder.create(); +} + +/** +@return boolean indicating whether the T dimension is available. +@throw runtime_error if execute has not been run first. +*/ +bool MDHWLoadingPresenter::hasTDimensionAvailable() const { + if (!m_isSetup) { + throw std::runtime_error("Have not yet run ::extractMetaData!"); + } + return xmlBuilder.hasTDimension() && !xmlBuilder.hasIntegratedTDimension(); +} + +/* +@return timestep values. +@throw runtime_error if execute has not been run first. +*/ +std::vector<double> MDHWLoadingPresenter::getTimeStepValues() const { + if (!m_isSetup) { + throw std::runtime_error("Have not yet run ::extractMetaData!"); + } + std::vector<double> result; + for (size_t i = 0; i < tDimension->getNBins(); i++) { + result.push_back(tDimension->getX(i)); + } + return result; +} + +/** + * Create a label for the "time" coordinate + * @return the "time" coordinate label + * @throw runtime_error if execute has not been run first. + */ +std::string MDHWLoadingPresenter::getTimeStepLabel() const { + if (!m_isSetup) { + throw std::runtime_error("Have not yet run ::extractMetaData!"); + } + return tDimension->getName() + " (" + tDimension->getUnits().ascii() + ")"; +} + +/** + * Getter for the instrument. + * @returns The name of the instrument which is associated with the workspace. + */ +const std::string &MDHWLoadingPresenter::getInstrument() { + return m_metadataJsonManager->getInstrument(); +} + +/** + * Getter for the minimum value; + * @return The minimum value of the data set. + */ +double MDHWLoadingPresenter::getMinValue() { + return m_metadataJsonManager->getMinValue(); +} + +/** + * Getter for the maximum value; + * @return The maximum value of the data set. + */ +double MDHWLoadingPresenter::getMaxValue() { + return m_metadataJsonManager->getMaxValue(); +} +} } diff --git a/Code/Mantid/Vates/VatesAPI/src/MDHWNexusLoadingPresenter.cpp b/Code/Mantid/Vates/VatesAPI/src/MDHWNexusLoadingPresenter.cpp index 2081e450c33edbe27e0fedbda37656685879f64f..eec4a5a3b109997953895099faaf9fbbb78300cf 100644 --- a/Code/Mantid/Vates/VatesAPI/src/MDHWNexusLoadingPresenter.cpp +++ b/Code/Mantid/Vates/VatesAPI/src/MDHWNexusLoadingPresenter.cpp @@ -158,7 +158,11 @@ void MDHWNexusLoadingPresenter::loadWorkspace() alg->setProperty("FileBackEnd", !this->m_view->getLoadInMemory()); //Load from file by default. alg->execute(); Workspace_sptr result = AnalysisDataService::Instance().retrieve("MD_HISTO_WS_ID"); - m_histoWs = boost::dynamic_pointer_cast<Mantid::API::IMDHistoWorkspace>(result); + auto preTranspose = boost::dynamic_pointer_cast<Mantid::API::IMDHistoWorkspace>(result); + // Perform any necessary transpose. + MDHWLoadingPresenter::transposeWs(preTranspose, m_histoWs); + + } void MDHWNexusLoadingPresenter::loadWorkspace( ProgressAction& loadingProgressUpdate) diff --git a/Code/Mantid/Vates/VatesAPI/src/SynchronisingGeometryPresenter.cpp b/Code/Mantid/Vates/VatesAPI/src/SynchronisingGeometryPresenter.cpp deleted file mode 100644 index cbc920dca153826f5371007dc4ed4cd5a69a989d..0000000000000000000000000000000000000000 --- a/Code/Mantid/Vates/VatesAPI/src/SynchronisingGeometryPresenter.cpp +++ /dev/null @@ -1,498 +0,0 @@ -#include "MantidGeometry/MDGeometry/MDGeometryXMLBuilder.h" -#include "MantidVatesAPI/SynchronisingGeometryPresenter.h" -#include "MantidVatesAPI/DimensionPresenter.h" -#include "MantidVatesAPI/DimensionView.h" -#include "MantidVatesAPI/GeometryView.h" -#include <algorithm> - - -using Mantid::Geometry::IMDDimension_sptr; -using Mantid::Geometry::VecIMDDimension_sptr; -typedef Mantid::VATES::GeometryPresenter::MappingType MappingType; - -namespace Mantid -{ - namespace VATES - { - - /// Comparitor to find integrated dimensions. - struct FindIntegrated : public std::unary_function <IMDDimension_sptr, bool> - { - bool operator ()(const IMDDimension_sptr obj) const - { - return obj->getIsIntegrated(); - } - }; - - /// Comparitor to find DimensionPresenter shared pointers via a dimension id. - struct FindId : public std::unary_function <DimPresenter_sptr, bool> - { - const std::string m_id; - FindId(const std::string &id) : m_id(id){ } - - bool operator ()(const DimPresenter_sptr obj) const - { - return m_id == obj->getModel()->getDimensionId(); - } - FindId& operator=(const FindId&); - }; - - /// Comparitor to find IMDDimension shared pointers via a dimension id. - struct FindModelId : public std::unary_function <IMDDimension_sptr, bool> - { - const std::string m_id; - FindModelId(const std::string &id) : m_id(id){ } - - bool operator ()(const IMDDimension_sptr obj) const - { - return m_id == obj->getDimensionId(); - } - FindModelId& operator=(const FindModelId&); - }; - - /** - Constructor - */ - SynchronisingGeometryPresenter::SynchronisingGeometryPresenter(Mantid::Geometry::MDGeometryXMLParser& source) : - X_AXIS("X-AXIS"), - Y_AXIS("Y-AXIS"), - Z_AXIS("Z-AXIS"), - T_AXIS("T-AXIS"), - m_dimensions(source.getAllDimensions()), - m_source(source), - m_view(NULL), - m_binDisplayMode(Simple) - { - - } - - /** - Destructor - */ - SynchronisingGeometryPresenter::~SynchronisingGeometryPresenter() - { - } - - void SynchronisingGeometryPresenter::swap(const GeometryPresenter::MappingType::key_type& keyA, const GeometryPresenter::MappingType::key_type& keyB) - { - DimPresenter_sptr temp = m_mapping[keyA]; - - //Swap items in mapping list. - m_mapping[keyA] = m_mapping[keyB]; - m_mapping[keyB] = temp; - - //Set mapping name of presenter and then force view to update. - if(NULL != m_mapping[keyA]) - { - m_mapping[keyA]->setMapping(keyA); - m_mapping[keyA]->acceptModelWeakly(m_mapping[keyA]->getModel()); - } - //Set mapping name of presenter and then force view to update. - if(NULL != m_mapping[keyB]) - { - m_mapping[keyB]->setMapping(keyB); - m_mapping[keyB]->acceptModelWeakly(m_mapping[keyB]->getModel()); - } - } - - /** - Handles dimension realignment. When a dimension presenter is handling a realignment, its is necessary for this to be synchronsied with other non-integrated dimensions. - @param pDimensionPresenter : dimension presenter on which realignement has been requested. - */ - void SynchronisingGeometryPresenter::dimensionRealigned(DimensionPresenter* pDimensionPresenter) - { - swap(pDimensionPresenter->getMapping(), pDimensionPresenter->getVisDimensionName()); - } - - /** - Ensure that for non-integrated dimensions, mappings are always occupied in the priority x before y before z before t. - */ - void SynchronisingGeometryPresenter::shuffleMappedPresenters() - { - DimPresenter_sptr temp; - if(hasYDim() && !hasXDim()) - { - swap(X_AXIS, Y_AXIS); - eraseMappedPresenter(m_mapping[Y_AXIS]); - } - if(hasZDim() && !hasYDim()) - { - swap(Y_AXIS, Z_AXIS); - eraseMappedPresenter(m_mapping[Z_AXIS]); - } - if(hasTDim() && !hasZDim()) - { - swap(T_AXIS, Z_AXIS); - eraseMappedPresenter(m_mapping[T_AXIS]); - } - } - - /** - Ensure that for the collaped mapeed dimension, it's mapped placeholder is erased (marked as empty). - @param expiredMappedDimension : mapped dimension presenter which has been collapsed, and may currently occupy a x, y, z, t mapping. - */ - void SynchronisingGeometryPresenter::eraseMappedPresenter(DimPresenter_sptr expiredMappedDimension) - { - if(NULL != expiredMappedDimension) - { - m_mapping.erase(expiredMappedDimension->getMapping()); - } - } - - /** - With the priority mapping of x before y, y before z, and z before t. Ensure that a candidate mapped dimension presenter is set to occupy a vacent mapping. - @param candidateMappedDimension : Dimension presenter to which a mapping is requested. - */ - void SynchronisingGeometryPresenter::insertMappedPresenter(DimPresenter_sptr candidateMappedDimension) - { - /* - Check to see whether there is already a mapping for this presenter. If there is, don't create another one! - */ - bool bAlreadyMapped = false; - for (MappingType::iterator it = m_mapping.begin(); it != m_mapping.end(); ++it) - { - if (it->second == candidateMappedDimension) - { - bAlreadyMapped = true; - break; - } - } - if(!bAlreadyMapped) - { - if(!this->hasXDim()) - { - m_mapping.insert(std::make_pair(X_AXIS, candidateMappedDimension)); - candidateMappedDimension->setMapping(X_AXIS); - } - else if(!this->hasYDim()) - { - m_mapping.insert(std::make_pair(Y_AXIS, candidateMappedDimension)); - candidateMappedDimension->setMapping(Y_AXIS); - } - else if(!hasZDim()) - { - m_mapping.insert(std::make_pair(Z_AXIS, candidateMappedDimension)); - candidateMappedDimension->setMapping(Z_AXIS); - } - else if(!hasTDim()) - { - m_mapping.insert(std::make_pair(T_AXIS, candidateMappedDimension)); - candidateMappedDimension->setMapping(T_AXIS); - } - } - } - - /** - Handles the change of a managed dimension presenter to be expanded (from collapsed). - @param pDimensionPresenter : dimension which is now expanded. - */ - void SynchronisingGeometryPresenter::dimensionExpanded(DimensionPresenter* pDimensionPresenter) - { - //Replace the old dimension with the new/modified one. - std::replace_if(m_dimensions.begin(), m_dimensions.end(), FindModelId(pDimensionPresenter->getAppliedModel()->getDimensionId()), pDimensionPresenter->getAppliedModel()); - //Insert an axis-mapping for this expanded dimension. - VecDimPresenter_sptr::iterator location = std::find_if(m_dimPresenters.begin(), m_dimPresenters.end(), FindId(pDimensionPresenter->getAppliedModel()->getDimensionId())); - if (location != m_dimPresenters.end()) - { - insertMappedPresenter((*location)); - } - shuffleMappedPresenters(); - - } - - /** - Handles the change of a managed dimension presenter to be collapsed (from expanded). - @param pDimensionPresenter : dimension which is now collapsed. - */ - void SynchronisingGeometryPresenter::dimensionCollapsed(DimensionPresenter* pDimensionPresenter) - { - //Effectively end the transaction if it will result in zero non-integrated dimensions - if(1 == getNonIntegratedDimensions().size()) - { - throw std::invalid_argument("Cannot have all dimensions integrated!"); - } - //Replace the old dimension with the new/modified one. - std::replace_if(m_dimensions.begin(), m_dimensions.end(), FindModelId(pDimensionPresenter->getAppliedModel()->getDimensionId()), pDimensionPresenter->getAppliedModel()); - //DONOT ERRASE THE MAPPING. - shuffleMappedPresenters(); - - } - - /** - Handles dimension resize request. Can either be collapsed or expanded. This is worked out internally. - @param pDimensionPresenter : dimension which is now collapsed/expanded. - */ - void SynchronisingGeometryPresenter::dimensionResized(DimensionPresenter* pDimensionPresenter) - { - bool nowIntegrated = pDimensionPresenter->getAppliedModel()->getNBins() == 1; - if(nowIntegrated) - { - dimensionCollapsed(pDimensionPresenter); - } - else - { - dimensionExpanded(pDimensionPresenter); - } - - //For non integrated dimension presenter. Lists of possible non-interated dimensions to switch to must be updated. - for(unsigned int i = 0; i < m_dimPresenters.size(); i++) - { - m_dimPresenters[i]->updateIfNotIntegrated(); - } - pDimensionPresenter->acceptAppliedModel(); - } - - /** - Getter for non-integrated dimensions. - @return collection of non-integrated dimensions. - */ - Mantid::Geometry::VecIMDDimension_sptr SynchronisingGeometryPresenter::getNonIntegratedDimensions() const - { - VecIMDDimension_sptr matches; - VecIMDDimension_sptr::iterator i = m_dimensions.begin(); - FindIntegrated findIntegrated; - std::unary_negate<FindIntegrated> findNotIntegrated(findIntegrated); - while(true) - { - i = std::find_if(i, m_dimensions.end(), findNotIntegrated); - if (i == m_dimensions.end()) - break; - matches.push_back(*i); - ++i; - } - return matches; - } - - /** - Getter for integrated dimensions. - @return collection of non-integrated dimensions. - */ - Mantid::Geometry::VecIMDDimension_sptr SynchronisingGeometryPresenter::getIntegratedDimensions() const - { - VecIMDDimension_sptr matches; - VecIMDDimension_sptr::iterator i = m_dimensions.begin(); - FindIntegrated findIntegrated; - while(true) - { - i = std::find_if(i, m_dimensions.end(), findIntegrated); - if (i == m_dimensions.end()) - break; - matches.push_back(*i); - ++i; - } - return matches; - } - - /** - Getter for the geometry xml. - @return GeometryXML in string format. - */ - std::string SynchronisingGeometryPresenter::getGeometryXML() const - { - //Get the selected alignment for the xdimension. - using namespace Mantid::Geometry; - MDGeometryBuilderXML<NoDimensionPolicy> xmlBuilder; - - VecIMDDimension_sptr vecIntegrated = getIntegratedDimensions(); - VecDimPresenter_sptr::const_iterator its = m_dimPresenters.begin(); - for(;its != m_dimPresenters.end(); ++its) - { - if((*its)->getAppliedModel()->getIsIntegrated()) - { - xmlBuilder.addOrdinaryDimension((*its)->getAppliedModel()); - } - } - - if(hasXDim()) - { - xmlBuilder.addXDimension(m_mapping.at(X_AXIS)->getAppliedModel()); - } - if(hasYDim()) - { - xmlBuilder.addYDimension(m_mapping.at(Y_AXIS)->getAppliedModel()); - } - if(hasZDim()) - { - xmlBuilder.addZDimension(m_mapping.at(Z_AXIS)->getAppliedModel()); - } - if(hasTDim()) - { - xmlBuilder.addTDimension(m_mapping.at(T_AXIS)->getAppliedModel()); - } - return xmlBuilder.create().c_str(); - } - - /** - SynchronisingGeometryPresenter are constructed without first knowing the view they manage. They must be dispatched with the - view instance they both belong to (GeometryViews own GeometryPresenters) and can direct (GeometryPresenters direct GeometryViews MVP). - - i) Uses factory provided by GeometryView to generate DimensionViews. - ii) Creates a DimensionPresenter for each of those views and binds the pair together. (although DimensionPresenters are owned by this and DimensionViews are owned by GeometryViews) - iv) Replicates the mappings on the original source input. These are read/writable at a later point. - - @param view : the GeoemtryView to direct. - */ - void SynchronisingGeometryPresenter::acceptView(GeometryView* view) - { - m_view = view; - m_binDisplayMode = m_view->getBinDisplayMode(); - const DimensionViewFactory& factory = m_view->getDimensionViewFactory(); - Mantid::Geometry::VecIMDDimension_sptr vecAllDimensions = m_source.getAllDimensions(); - - for(size_t i =0; i < vecAllDimensions.size(); i++) - { - DimensionView* dimView = factory.create(); - DimPresenter_sptr dimPresenter(new DimensionPresenter(dimView, this)); - - Mantid::Geometry::IMDDimension_sptr model = vecAllDimensions[i]; - - if(m_source.isXDimension(model)) - { - dimPresenter->setMapping(X_AXIS); - m_mapping.insert(std::make_pair(X_AXIS, dimPresenter)); - } - else if(m_source.isYDimension(model)) - { - dimPresenter->setMapping(Y_AXIS); - m_mapping.insert(std::make_pair(Y_AXIS, dimPresenter)); - } - else if(m_source.isZDimension(model)) - { - dimPresenter->setMapping(Z_AXIS); - m_mapping.insert(std::make_pair(Z_AXIS, dimPresenter)); - } - else if(m_source.isTDimension(model)) - { - dimPresenter->setMapping(T_AXIS); - m_mapping.insert(std::make_pair(T_AXIS, dimPresenter)); - } - - // Dimension View must have reference to Dimension Presenter. - dimView->accept(dimPresenter.get()); - // Geometry View owns the Dimension View. - m_view->addDimensionView(dimView); - // Presenters are mainatined internally. - m_dimPresenters.push_back(dimPresenter); - } - for(size_t i = 0; i < m_dimPresenters.size(); i++) - { - //Now that all presenters have views, models can be provided to complete the M-V-P chain. - m_dimPresenters[i]->acceptModelStrongly(m_source.getAllDimensions()[i]); - } - } - - /** - Determine whether x dimension mapping is available. - @return true if target mapping is available. - */ - bool SynchronisingGeometryPresenter::hasXDim() const - { - return m_mapping.find(X_AXIS) != m_mapping.end() && NULL != m_mapping.find(X_AXIS)->second; - } - - /** - Determine whether y dimension mapping is available. - @return true if target mapping is available. - */ - bool SynchronisingGeometryPresenter::hasYDim() const - { - return m_mapping.find(Y_AXIS) != m_mapping.end() && NULL != m_mapping.find(Y_AXIS)->second; - } - - /** - Determine whether z dimension mapping is available. - @return true if target mapping is available. - */ - bool SynchronisingGeometryPresenter::hasZDim() const - { - return m_mapping.find(Z_AXIS) != m_mapping.end() && NULL != m_mapping.find(Z_AXIS)->second; - } - - /** - Determine whether t dimension mapping is available. - @return true if target mapping is available. - */ - bool SynchronisingGeometryPresenter::hasTDim() const - { - return m_mapping.find(T_AXIS) != m_mapping.end() && NULL != m_mapping.find(T_AXIS)->second; - } - - /** - Pass though method indicating to the view that modifications have occured. - */ - void SynchronisingGeometryPresenter::setModified() - { - m_view->raiseModified(); - } - - /** - Setter to indicate changes to the display mode. - */ - void SynchronisingGeometryPresenter::setDimensionModeChanged() - { - //Get the actual requested display mode. - BinDisplay temp = m_view->getBinDisplayMode(); - if(temp != m_binDisplayMode) - { - m_binDisplayMode = temp; - VecDimPresenter_sptr::iterator it = m_dimPresenters.begin(); - while(it != m_dimPresenters.end()) - { - //Delegate the work of applying the changes to each DimensionPresenter. - (*it)->setViewMode(m_binDisplayMode); - ++it; - } - } - } - - /** - Determine if dimension presenter is mapped to x axis. - @param dimensionPresenter : The dimension presenter to which the comparison should be made. - @return true if dimesion presenter matches exising mapping. - */ - bool SynchronisingGeometryPresenter::isXDimensionPresenter(DimPresenter_sptr dimensionPresenter) const - { - return dimensionPresenter == m_mapping.at(X_AXIS); - } - - /** - Determine if dimension presenter is mapped to y axis. - @param dimensionPresenter : The dimension presenter to which the comparison should be made. - @return true if dimesion presenter matches exising mapping. - */ - bool SynchronisingGeometryPresenter::isYDimensionPresenter(DimPresenter_sptr dimensionPresenter) const - { - return dimensionPresenter == m_mapping.at(Y_AXIS); - } - - /** - Determine if dimension presenter is mapped to z axis. - @param dimensionPresenter : The dimension presenter to which the comparison should be made. - @return true if dimesion presenter matches exising mapping. - */ - bool SynchronisingGeometryPresenter::isZDimensionPresenter(DimPresenter_sptr dimensionPresenter) const - { - return dimensionPresenter == m_mapping.at(Z_AXIS); - } - - /** - Determine if dimension presenter is mapped to t axis. - @param dimensionPresenter : The dimension presenter to which the comparison should be made. - @return true if dimesion presenter matches exising mapping. - */ - bool SynchronisingGeometryPresenter::isTDimensionPresenter(DimPresenter_sptr dimensionPresenter) const - { - return dimensionPresenter == m_mapping.at(T_AXIS); - } - - /** - Get mappings of vis diension names to dimension presenters. - @return mapping. - */ - MappingType SynchronisingGeometryPresenter::getMappings() const - { - return m_mapping; - } - - } -} diff --git a/Code/Mantid/Vates/VatesAPI/test/DimensionPresenterTest.h b/Code/Mantid/Vates/VatesAPI/test/DimensionPresenterTest.h deleted file mode 100644 index 3285bebef6dc854b6ac065a48cee367aa6ef5f5d..0000000000000000000000000000000000000000 --- a/Code/Mantid/Vates/VatesAPI/test/DimensionPresenterTest.h +++ /dev/null @@ -1,297 +0,0 @@ -#ifndef DIMENSION_PRESENTER_TEST_H_ -#define DIMENSION_PRESENTER_TEST_H_ - -#include <cxxtest/TestSuite.h> -#include "MantidVatesAPI/DimensionPresenter.h" -#include "MantidVatesAPI/GeometryPresenter.h" -#include "MantidVatesAPI/DimensionView.h" -#include "MantidGeometry/MDGeometry/MDTypes.h" -#include "MantidKernel/UnitLabel.h" -#include "gtest/gtest.h" -#include "gmock/gmock.h" - -using namespace Mantid; -using namespace Mantid::VATES; -using namespace Mantid::Geometry; -using namespace testing; - -class DimensionPresenterTest : public CxxTest::TestSuite { -private: - class MockDimensionView : public DimensionView { - public: - MOCK_METHOD0(configureStrongly, void()); - MOCK_METHOD0(configureWeakly, void()); - MOCK_METHOD1(showAsNotIntegrated, void(VecIMDDimension_sptr)); - MOCK_METHOD0(showAsIntegrated, void()); - MOCK_METHOD1(accept, void(DimensionPresenter *)); - MOCK_CONST_METHOD0(getMinimum, float()); - MOCK_CONST_METHOD0(getMaximum, float()); - MOCK_CONST_METHOD0(getNBins, unsigned int()); - MOCK_CONST_METHOD0(getSelectedIndex, unsigned int()); - MOCK_CONST_METHOD0(getIsIntegrated, bool()); - MOCK_CONST_METHOD0(getVisDimensionName, std::string()); - MOCK_CONST_METHOD1(displayError, void(std::string)); - MOCK_METHOD1(setViewMode, void(Mantid::VATES::BinDisplay)); - ~MockDimensionView(){}; - }; - - class MockGeometryPresenter : public GeometryPresenter { - public: - MOCK_METHOD1(dimensionRealigned, void(DimensionPresenter *)); - MOCK_METHOD1(dimensionResized, void(DimensionPresenter *)); - MOCK_CONST_METHOD0(getNonIntegratedDimensions, VecIMDDimension_sptr()); - MOCK_CONST_METHOD0(getGeometryXML, std::string()); - MOCK_METHOD1(acceptView, void(GeometryView *)); - MOCK_METHOD0(setModified, void()); - MOCK_METHOD0(setDimensionModeChanged, void()); - MOCK_CONST_METHOD0(getMappings, GeometryPresenter::MappingType()); - ~MockGeometryPresenter() {} - }; - - /// Mock IMDDimension allows tests to specify exact expected behavior of - /// dependency. - class MockIMDDimension : public IMDDimension { - public: - MOCK_CONST_METHOD0(getName, std::string()); - MOCK_CONST_METHOD0(getUnits, const Mantid::Kernel::UnitLabel()); - MOCK_CONST_METHOD0(getMDFrame, const Mantid::Geometry::MDFrame &()); - MOCK_CONST_METHOD0(getMDUnits, const Mantid::Kernel::MDUnit &()); - MOCK_CONST_METHOD0(getDimensionId, std::string()); - MOCK_CONST_METHOD0(getMaximum, coord_t()); - MOCK_CONST_METHOD0(getMinimum, coord_t()); - MOCK_CONST_METHOD0(getNBins, size_t()); - MOCK_CONST_METHOD0(toXMLString, std::string()); - MOCK_CONST_METHOD0(getIsIntegrated, bool()); - MOCK_CONST_METHOD1(getX, coord_t(size_t ind)); - MOCK_METHOD3(setRange, void(size_t, coord_t, coord_t)); - }; - -public: - void testSetMapping() { - IMDDimension_sptr model(new MockIMDDimension()); - MockDimensionView view; - MockGeometryPresenter gPresenter; - DimensionPresenter presenter(&view, &gPresenter); - - TSM_ASSERT("Should have no mapping", presenter.getMapping().empty()); - - presenter.setMapping("Z-AXIS"); - TSM_ASSERT_EQUALS("Should now have mapping set", "Z-AXIS", - presenter.getMapping()); - } - - void testWithoutProperConstructionThrows() { - IMDDimension_sptr model(new MockIMDDimension()); - MockDimensionView view; - MockGeometryPresenter gPresenter; - DimensionPresenter presenter(&view, &gPresenter); - - TSM_ASSERT_THROWS("::acceptModel not called first, so should have thrown", - presenter.updateModel(), std::runtime_error); - } - - void testAcceptModelStrongly() { - MockIMDDimension *pMockDimension = new MockIMDDimension(); - EXPECT_CALL(*pMockDimension, getDimensionId()) - .Times(2) - .WillRepeatedly(Return("1")); - EXPECT_CALL(*pMockDimension, getIsIntegrated()).Times(1); - IMDDimension_sptr model(pMockDimension); - - MockDimensionView view; - EXPECT_CALL(view, configureStrongly()).Times(1); - EXPECT_CALL(view, showAsNotIntegrated(_)).Times(1); - - MockGeometryPresenter gPresenter; - EXPECT_CALL(gPresenter, getNonIntegratedDimensions()) - .Times(1) - .WillOnce(Return(VecIMDDimension_sptr())); - - DimensionPresenter presenter(&view, &gPresenter); - presenter.acceptModelStrongly(model); - - TSM_ASSERT_EQUALS("Applied model should be the same as the one provided", - model->getDimensionId(), - presenter.getModel()->getDimensionId()); - TS_ASSERT(Mock::VerifyAndClearExpectations(pMockDimension)); - TS_ASSERT(Mock::VerifyAndClearExpectations(&view)); - TS_ASSERT(Mock::VerifyAndClearExpectations(&gPresenter)); - } - - void testAcceptModelWeakly() { - MockIMDDimension *pMockDimension = new MockIMDDimension(); - EXPECT_CALL(*pMockDimension, getDimensionId()) - .Times(2) - .WillRepeatedly(Return("1")); - EXPECT_CALL(*pMockDimension, getIsIntegrated()).Times(1); - IMDDimension_sptr model(pMockDimension); - - MockDimensionView view; - EXPECT_CALL(view, configureWeakly()).Times(1); - EXPECT_CALL(view, showAsNotIntegrated(_)).Times(1); - - MockGeometryPresenter gPresenter; - EXPECT_CALL(gPresenter, getNonIntegratedDimensions()) - .Times(1) - .WillOnce(Return(VecIMDDimension_sptr())); - - DimensionPresenter presenter(&view, &gPresenter); - presenter.acceptModelWeakly(model); - - TSM_ASSERT_EQUALS("Applied model should be the same as the one provided", - model->getDimensionId(), - presenter.getModel()->getDimensionId()); - TS_ASSERT(Mock::VerifyAndClearExpectations(pMockDimension)); - TS_ASSERT(Mock::VerifyAndClearExpectations(&view)); - TS_ASSERT(Mock::VerifyAndClearExpectations(&gPresenter)); - } - - void testDriveViewToBeIntegrated() { - MockDimensionView view; - EXPECT_CALL(view, configureStrongly()).Times(1); - EXPECT_CALL(view, showAsIntegrated()).Times(2); - EXPECT_CALL(view, showAsNotIntegrated(_)) - .Times(0); // Explicitly should never use this. - EXPECT_CALL(view, getIsIntegrated()).WillOnce(Return(true)); - EXPECT_CALL(view, getVisDimensionName()).Times(1); - - MockIMDDimension *pMockDimension = new MockIMDDimension(); - EXPECT_CALL(*pMockDimension, getIsIntegrated()) - .Times(1) - .WillRepeatedly(Return(true)); // Model says it's integrated - Mantid::Geometry::IMDDimension_sptr model(pMockDimension); - - MockGeometryPresenter gPresenter; - EXPECT_CALL(gPresenter, setModified()).Times(1); - - DimensionPresenter presenter(&view, &gPresenter); - presenter.acceptModelStrongly(model); - TSM_ASSERT_THROWS_NOTHING("A model exists on the presenter, updating " - "should it should operate without exception.", - presenter.updateModel()); - - TS_ASSERT(Mock::VerifyAndClearExpectations(pMockDimension)); - TS_ASSERT(Mock::VerifyAndClearExpectations(&view)); - TS_ASSERT(Mock::VerifyAndClearExpectations(&gPresenter)); - } - - void testDriveViewToBeNotIntegrated() { - MockDimensionView view; - EXPECT_CALL(view, configureStrongly()).Times(1); - EXPECT_CALL(view, showAsNotIntegrated(_)).Times(2); - EXPECT_CALL(view, showAsIntegrated()) - .Times(0); // Explicitly should never use this - EXPECT_CALL(view, getIsIntegrated()) - .Times(AnyNumber()) - .WillRepeatedly(Return(false)); // View is not integrated. - EXPECT_CALL(view, getVisDimensionName()).Times(1); - - MockIMDDimension *pMockDimension = new MockIMDDimension(); - EXPECT_CALL(*pMockDimension, getIsIntegrated()) - .Times(AnyNumber()) - .WillRepeatedly(Return(false)); - Mantid::Geometry::IMDDimension_sptr model(pMockDimension); - - MockGeometryPresenter gPresenter; - EXPECT_CALL(gPresenter, getNonIntegratedDimensions()) - .Times(2) - .WillRepeatedly(Return(VecIMDDimension_sptr())); // Will ask the - // GeometryPresenter - // for non-integrated - // dimensions - EXPECT_CALL(gPresenter, setModified()).Times(1); - DimensionPresenter presenter(&view, &gPresenter); - presenter.acceptModelStrongly(model); - - TSM_ASSERT_THROWS_NOTHING("A model exists on the presenter, updating " - "should it should operate without exception.", - presenter.updateModel()); - TS_ASSERT(Mock::VerifyAndClearExpectations(pMockDimension)); - TS_ASSERT(Mock::VerifyAndClearExpectations(&view)); - TS_ASSERT(Mock::VerifyAndClearExpectations(&gPresenter)); - } - - void testGetAppliedModelWhenViewIntegrated() { - MockDimensionView view; - EXPECT_CALL(view, configureStrongly()).Times(1); - EXPECT_CALL(view, showAsIntegrated()).Times(1); - EXPECT_CALL(view, getIsIntegrated()) - .Times(1) - .WillRepeatedly(Return(true)); // view says it's integrated - EXPECT_CALL(view, getMinimum()).Times(1).WillOnce(Return(0.0f)); - EXPECT_CALL(view, getMaximum()).Times(1).WillOnce(Return(2.0f)); - EXPECT_CALL(view, getNBins()).Times(0); // Should never need number of bins - // because view says it's - // integrated. - - MockIMDDimension *pMockDimension = new MockIMDDimension(); - EXPECT_CALL(*pMockDimension, getIsIntegrated()) - .Times(1) - .WillRepeatedly(Return(true)); // Model says it's integrated - EXPECT_CALL(*pMockDimension, toXMLString()) - .WillOnce( - Return("<Dimension " - "ID=\"en\"><Name>Energy</Name><UpperBounds>150</" - "UpperBounds><LowerBounds>0</LowerBounds><NumberOfBins>1</" - "NumberOfBins></Dimension>")); - Mantid::Geometry::IMDDimension_sptr model(pMockDimension); - - MockGeometryPresenter gPresenter; - - DimensionPresenter presenter(&view, &gPresenter); - presenter.acceptModelStrongly(model); - Mantid::Geometry::IMDDimension_sptr product = presenter.getAppliedModel(); - - TSM_ASSERT_EQUALS("Wrong number of bins for an integrated dimension", 1, - product->getNBins()); - TSM_ASSERT_EQUALS("Range max not set properly", 2, product->getMaximum()); - TSM_ASSERT_EQUALS("Range min not set properly", 0, product->getMinimum()); - - TS_ASSERT(Mock::VerifyAndClearExpectations(pMockDimension)); - TS_ASSERT(Mock::VerifyAndClearExpectations(&view)); - TS_ASSERT(Mock::VerifyAndClearExpectations(&gPresenter)); - } - - void testHandleArgumentErrors() { - MockDimensionView view; - EXPECT_CALL(view, configureStrongly()).Times(AnyNumber()); - EXPECT_CALL(view, showAsIntegrated()).Times(AnyNumber()); - EXPECT_CALL(view, getIsIntegrated()) - .Times(AtLeast(1)) - .WillRepeatedly(Return(false)); // view says it's integrated - EXPECT_CALL(view, getMinimum()) - .Times(AnyNumber()) - .WillRepeatedly( - Return(10.0f)); // Ooops, min > max, this should be handled! - EXPECT_CALL(view, getMaximum()) - .Times(AnyNumber()) - .WillRepeatedly(Return(2.0f)); - EXPECT_CALL(view, getNBins()).Times(AnyNumber()); - EXPECT_CALL(view, displayError(_)).Times(1); - - MockIMDDimension *pMockDimension = new MockIMDDimension(); - EXPECT_CALL(*pMockDimension, getIsIntegrated()) - .Times(AnyNumber()) - .WillRepeatedly(Return(true)); // Model says it's integrated - EXPECT_CALL(*pMockDimension, toXMLString()) - .Times(AnyNumber()) - .WillRepeatedly( - Return("<Dimension " - "ID=\"en\"><Name>Energy</Name><UpperBounds>150</" - "UpperBounds><LowerBounds>0</LowerBounds><NumberOfBins>1</" - "NumberOfBins></Dimension>")); - Mantid::Geometry::IMDDimension_sptr model(pMockDimension); - - MockGeometryPresenter gPresenter; - - DimensionPresenter presenter(&view, &gPresenter); - presenter.acceptModelStrongly(model); - presenter.getAppliedModel(); - - TS_ASSERT(Mock::VerifyAndClearExpectations(pMockDimension)); - TS_ASSERT(Mock::VerifyAndClearExpectations(&view)); - TS_ASSERT(Mock::VerifyAndClearExpectations(&gPresenter)); - } -}; - -#endif diff --git a/Code/Mantid/Vates/VatesAPI/test/MDHWInMemoryLoadingPresenterTest.h b/Code/Mantid/Vates/VatesAPI/test/MDHWInMemoryLoadingPresenterTest.h index 1b61f8ac85a78c4236b9fe55d6c836bbcd4ed39f..461b007f8f7cea3fd0dc2864d2fd8050eb1b474a 100644 --- a/Code/Mantid/Vates/VatesAPI/test/MDHWInMemoryLoadingPresenterTest.h +++ b/Code/Mantid/Vates/VatesAPI/test/MDHWInMemoryLoadingPresenterTest.h @@ -32,7 +32,7 @@ private: }; // Helper method. Generates and returns a valid IMDHistoWorkspace - static Mantid::API::Workspace_sptr getGoodWorkspace() + Mantid::API::Workspace_sptr getGoodWorkspace() { Mantid::DataObjects::MDHistoWorkspace_sptr ws = makeFakeMDHistoWorkspace(1.0, 4, 5, 1.0, 0.1,"MD_HISTO_WS"); return ws; diff --git a/Code/Mantid/Vates/VatesAPI/test/MDHWLoadingPresenterTest.h b/Code/Mantid/Vates/VatesAPI/test/MDHWLoadingPresenterTest.h index 6a23deae546d4515c42c3948626d5537ae6c7dbf..693e1e895c9c6592d3812eaa69269101655ff36c 100644 --- a/Code/Mantid/Vates/VatesAPI/test/MDHWLoadingPresenterTest.h +++ b/Code/Mantid/Vates/VatesAPI/test/MDHWLoadingPresenterTest.h @@ -9,11 +9,13 @@ #include "MantidVatesAPI/MDHWLoadingPresenter.h" #include "MantidVatesAPI/MDLoadingView.h" +#include "MantidDataObjects/MDHistoWorkspace.h" #include "MockObjects.h" using namespace testing; using namespace Mantid::VATES; +using namespace Mantid::API; //===================================================================================== // Functional tests @@ -72,7 +74,7 @@ void testShouldLoadFirstTimeRound() MockMDLoadingView view; EXPECT_CALL(view, getRecursionDepth()).Times(0); EXPECT_CALL(view, getLoadInMemory()).Times(2); - EXPECT_CALL(view, getTime()).Times(2); + EXPECT_CALL(view, getTime()).Times(2).WillRepeatedly(Return(0)); EXPECT_CALL(view, updateAlgorithmProgress(_,_)).Times(0); ConcreteMDHWLoadingPresenter presenter(&view); @@ -106,7 +108,7 @@ void testLoadInMemoryChanged() EXPECT_CALL(view, getLoadInMemory()).Times(2) .WillOnce(Return(true)) .WillOnce(Return(false)); // Load in memory changed - EXPECT_CALL(view, getTime()).Times(2); + EXPECT_CALL(view, getTime()).Times(2).WillRepeatedly(Return(0)); EXPECT_CALL(view, updateAlgorithmProgress(_,_)).Times(0); ConcreteMDHWLoadingPresenter presenter(&view); @@ -119,7 +121,7 @@ void testLoadInMemoryChanged() void testhasTDimensionWhenIntegrated() { //Setup view - MockMDLoadingView* view = new MockMDLoadingView; + auto * view = new NiceMock<MockMDLoadingView>(); ConcreteMDHWLoadingPresenter presenter(view); @@ -128,12 +130,13 @@ void testhasTDimensionWhenIntegrated() presenter.extractMetadata(boost::dynamic_pointer_cast<Mantid::API::IMDHistoWorkspace>(ws)); TSM_ASSERT("This is a 4D workspace with an integrated T dimension", !presenter.hasTDimensionAvailable()); + delete view; } void testHasTDimensionWhenNotIntegrated() { //Setup view - MockMDLoadingView* view = new MockMDLoadingView; + auto * view = new NiceMock<MockMDLoadingView>(); ConcreteMDHWLoadingPresenter presenter(view); @@ -142,12 +145,13 @@ void testHasTDimensionWhenNotIntegrated() presenter.extractMetadata(boost::dynamic_pointer_cast<Mantid::API::IMDHistoWorkspace>(ws)); TSM_ASSERT("This is a 4D workspace with an integrated T dimension", presenter.hasTDimensionAvailable()); + delete view; } void testHasTimeLabelWithTDimension() { //Setup view - MockMDLoadingView* view = new MockMDLoadingView; + auto * view = new NiceMock<MockMDLoadingView>(); ConcreteMDHWLoadingPresenter presenter(view); @@ -156,12 +160,13 @@ void testHasTimeLabelWithTDimension() presenter.extractMetadata(boost::dynamic_pointer_cast<Mantid::API::IMDHistoWorkspace>(ws)); TSM_ASSERT_EQUALS("This is a 4D workspace with a T dimension", "D (A)", presenter.getTimeStepLabel()); + delete view; } void testCanSetAxisLabelsFrom3DData() { //Setup view - MockMDLoadingView* view = new MockMDLoadingView; + auto * view = new NiceMock<MockMDLoadingView>(); ConcreteMDHWLoadingPresenter presenter(view); @@ -176,12 +181,13 @@ void testCanSetAxisLabelsFrom3DData() getStringFieldDataValue(ds, "AxisTitleForY"), "B (A)"); TSM_ASSERT_EQUALS("Z Label should match exactly", getStringFieldDataValue(ds, "AxisTitleForZ"), "C (A)"); + delete view; } void testCanSetAxisLabelsFrom4DData() { //Setup view - MockMDLoadingView* view = new MockMDLoadingView; + auto * view = new NiceMock<MockMDLoadingView>(); ConcreteMDHWLoadingPresenter presenter(view); @@ -196,6 +202,78 @@ void testCanSetAxisLabelsFrom4DData() getStringFieldDataValue(ds, "AxisTitleForY"), "B (A)"); TSM_ASSERT_EQUALS("Z Label should match exactly", getStringFieldDataValue(ds, "AxisTitleForZ"), "C (A)"); + + delete view; +} + +Mantid::API::IMDHistoWorkspace_sptr makeHistoWorkspace(const std::vector<int> &shape){ + + IAlgorithm* create = FrameworkManager::Instance().createAlgorithm("CreateMDHistoWorkspace"); + create->setChild(true); + create->initialize(); + + const std::string allNames[5] = {"A", "B", "C", "D", "E"}; + const std::string allUnits[5] = {"AU", "BU", "CU", "DU", "EU"}; + + std::vector<std::string> names; + std::vector<std::string> units; + size_t flatSize = 1; + std::vector<double> extents; + for(size_t i = 0; i < shape.size(); ++i){ + flatSize *= shape[i]; + names.push_back(allNames[i]); + units.push_back(allUnits[i]); + extents.push_back(-10); + extents.push_back(10); + } + + create->setProperty("SignalInput", std::vector<double>(flatSize, 1)); + create->setProperty("ErrorInput", std::vector<double>(flatSize, 1)); + + create->setProperty("Dimensionality", int(shape.size())); + create->setProperty("Extents",extents); + create->setProperty("NumberOfBins", shape); + create->setProperty("Names", names); + create->setProperty("Units", units); + create->setPropertyValue("OutputWorkspace", "dummy"); + create->execute(); + IMDHistoWorkspace_sptr outWs = create->getProperty("OutputWorkspace"); + return outWs; +} + +void test_transpose_not_needed(){ + + //return outWs; + int shape[4] = {10, 10, 1}; // Well behaved input workspace. Integrated dim at end. + std::vector<int> shapeVec(shape, shape+3); + auto inWs = makeHistoWorkspace(shapeVec); + + IMDHistoWorkspace_sptr targetWs; + MDHWLoadingPresenter::transposeWs(inWs, targetWs); + + TS_ASSERT_EQUALS(targetWs->getNumDims(), inWs->getNumDims()); + TS_ASSERT_EQUALS(targetWs->getNPoints(), inWs->getNPoints()) + TS_ASSERT_EQUALS(targetWs->getDimension(0)->getName(), inWs->getDimension(0)->getName()); + TS_ASSERT_EQUALS(targetWs->getDimension(1)->getName(), inWs->getDimension(1)->getName()); + TS_ASSERT_EQUALS(targetWs->getDimension(2)->getName(), inWs->getDimension(2)->getName()); +} + +void test_transpose_rules_applied(){ + + //return outWs; + int shape[4] = {10, 10, 1, 10}; // Inproper input workspace. Needs transpose! + std::vector<int> shapeVec(shape, shape+4); + auto inWs = makeHistoWorkspace(shapeVec); + + IMDHistoWorkspace_sptr targetWs; + MDHWLoadingPresenter::transposeWs(inWs, targetWs); + + TS_ASSERT_EQUALS(targetWs->getNumDims(), inWs->getNumDims()); + TS_ASSERT_EQUALS(targetWs->getNPoints(), inWs->getNPoints()) + TS_ASSERT_EQUALS(targetWs->getDimension(0)->getName(), inWs->getDimension(0)->getName()); + TS_ASSERT_EQUALS(targetWs->getDimension(1)->getName(), inWs->getDimension(1)->getName()); + TSM_ASSERT_EQUALS("Integrated dims should be shifted to end", targetWs->getDimension(2)->getName(), inWs->getDimension(3)->getName()); + TSM_ASSERT_EQUALS("Integrated dims on the end", targetWs->getDimension(3)->getName(), inWs->getDimension(2)->getName()); } }; diff --git a/Code/Mantid/Vates/VatesAPI/test/MDHWNexusLoadingPresenterTest.h b/Code/Mantid/Vates/VatesAPI/test/MDHWNexusLoadingPresenterTest.h index 83063f3b3a4a2b9d49743ea8e1b165f6f9cd606f..9eee4ef3773eefba6511e80788d6d37785349822 100644 --- a/Code/Mantid/Vates/VatesAPI/test/MDHWNexusLoadingPresenterTest.h +++ b/Code/Mantid/Vates/VatesAPI/test/MDHWNexusLoadingPresenterTest.h @@ -65,6 +65,7 @@ void testExecution() { //Setup view MockMDLoadingView* view = new MockMDLoadingView; + EXPECT_CALL(*view, getTime()).WillRepeatedly(Return(0)); EXPECT_CALL(*view, getRecursionDepth()).Times(AtLeast(0)); EXPECT_CALL(*view, getLoadInMemory()).Times(AtLeast(1)).WillRepeatedly(testing::Return(true)); EXPECT_CALL(*view, updateAlgorithmProgress(_,_)).Times(AnyNumber()); @@ -125,6 +126,7 @@ void testTimeLabel() { // Setup view MockMDLoadingView* view = new MockMDLoadingView; + EXPECT_CALL(*view, getTime()).WillRepeatedly(Return(0)); EXPECT_CALL(*view, getRecursionDepth()).Times(AtLeast(0)); EXPECT_CALL(*view, getLoadInMemory()).Times(AtLeast(1)).WillRepeatedly(testing::Return(true)); EXPECT_CALL(*view, updateAlgorithmProgress(_,_)).Times(AnyNumber()); @@ -155,6 +157,7 @@ void testAxisLabels() { //Setup view MockMDLoadingView* view = new MockMDLoadingView; + EXPECT_CALL(*view, getTime()).WillRepeatedly(Return(0)); EXPECT_CALL(*view, getRecursionDepth()).Times(AtLeast(0)); EXPECT_CALL(*view, getLoadInMemory()).Times(AtLeast(1)).WillRepeatedly(testing::Return(true)); EXPECT_CALL(*view, updateAlgorithmProgress(_,_)).Times(AnyNumber()); diff --git a/Code/Mantid/Vates/VatesAPI/test/MockObjects.h b/Code/Mantid/Vates/VatesAPI/test/MockObjects.h index 6527be6e5f508d76bff3e839cefbf3873f2bfba2..ee3ae349b2ab3dc98f518fcf78047b3b4fd1ecc9 100644 --- a/Code/Mantid/Vates/VatesAPI/test/MockObjects.h +++ b/Code/Mantid/Vates/VatesAPI/test/MockObjects.h @@ -425,17 +425,18 @@ Create a field data entry containing (as contents) the argument text. Mantid::API::Workspace_sptr createSimple3DWorkspace() { using namespace Mantid::API; - AnalysisDataService::Instance().remove("3D_Workspace"); - IAlgorithm* create = FrameworkManager::Instance().createAlgorithm("CreateMDWorkspace"); + IAlgorithm* create = FrameworkManager::Instance().createAlgorithm("CreateMDWorkspace"); + create->setChild(true); create->initialize(); create->setProperty("Dimensions", 4); create->setPropertyValue("Extents","0,5,0,5,0,5,0,5"); create->setPropertyValue("Names","A,B,C,D"); create->setPropertyValue("Units","A,A,A,A"); - create->setPropertyValue("OutputWorkspace", "3D_Workspace"); + create->setPropertyValue("OutputWorkspace", "dummy"); create->execute(); - return AnalysisDataService::Instance().retrieve("3D_Workspace"); + Workspace_sptr outWs = create->getProperty("OutputWorkspace"); + return outWs; } Mantid::API::Workspace_sptr get3DWorkspace(bool integratedTDimension, bool sliceMD) @@ -445,7 +446,6 @@ Create a field data entry containing (as contents) the argument text. Mantid::API::Workspace_sptr inputWs = createSimple3DWorkspace(); - AnalysisDataService::Instance().remove("binned"); std::string binningAlgName; if(sliceMD) { @@ -456,6 +456,7 @@ Create a field data entry containing (as contents) the argument text. binningAlgName = "BinMD"; } IAlgorithm_sptr binningAlg = AlgorithmManager::Instance().createUnmanaged(binningAlgName); + binningAlg->setChild(true); binningAlg->initialize(); binningAlg->setProperty("InputWorkspace", inputWs); binningAlg->setPropertyValue("AlignedDim0","A,0,5,2"); @@ -470,10 +471,10 @@ Create a field data entry containing (as contents) the argument text. { binningAlg->setPropertyValue("AlignedDim3","D,0,5,2"); } - binningAlg->setPropertyValue("OutputWorkspace", "binned"); + binningAlg->setPropertyValue("OutputWorkspace", "dummy"); binningAlg->execute(); - - return AnalysisDataService::Instance().retrieve("binned"); + Workspace_sptr outWs = binningAlg->getProperty("OutputWorkspace"); + return outWs; } /** diff --git a/Code/Mantid/Vates/VatesAPI/test/SynchronisingGeometryPresenterTest.h b/Code/Mantid/Vates/VatesAPI/test/SynchronisingGeometryPresenterTest.h deleted file mode 100644 index 407be0a2676f098dcb76c6c53fc7035e3e60bfe7..0000000000000000000000000000000000000000 --- a/Code/Mantid/Vates/VatesAPI/test/SynchronisingGeometryPresenterTest.h +++ /dev/null @@ -1,345 +0,0 @@ -#ifndef SYNCHRONISING_GEOMETRY_PRESENTER_TEST_H_ -#define SYNCHRONISING_GEOMETRY_PRESENTER_TEST_H_ - -#include <cxxtest/TestSuite.h> -#include "MantidVatesAPI/SynchronisingGeometryPresenter.h" -#include "MantidVatesAPI/GeometryView.h" -#include "MantidVatesAPI/DimensionView.h" -#include "MantidGeometry/MDGeometry/MDGeometryXMLParser.h" -#include "MantidVatesAPI/DimensionPresenter.h" - -#include "gtest/gtest.h" -#include "gmock/gmock.h" - -using namespace testing; -using namespace Mantid::VATES; -using namespace Mantid::Geometry; - -class SynchronisingGeometryPresenterTest: public CxxTest::TestSuite -{ - - -private: - -static std::string constructXML(std::string nbinsA, std::string nbinsB, std::string nbinsC, std::string nbinsD, std::string nbinsE) -{ - return std::string("<?xml version=\"1.0\" encoding=\"utf-8\"?>") + - "<DimensionSet>" + - "<Dimension ID=\"en\">" + - "<Name>Energy</Name>" + - "<UpperBounds>150</UpperBounds>" + - "<LowerBounds>0</LowerBounds>" + - "<NumberOfBins>" + nbinsA + "</NumberOfBins>" + - "</Dimension>" + - "<Dimension ID=\"qx\">" + - "<Name>Qx</Name>" + - "<UpperBounds>5</UpperBounds>" + - "<LowerBounds>-1.5</LowerBounds>" + - "<NumberOfBins>" + nbinsB + "</NumberOfBins>" + - "</Dimension>" + - "<Dimension ID=\"qy\">" + - "<Name>Qy</Name>" + - "<UpperBounds>6.6</UpperBounds>" + - "<LowerBounds>-6.6</LowerBounds>" + - "<NumberOfBins>" + nbinsC + "</NumberOfBins>" + - "</Dimension>" + - "<Dimension ID=\"qz\">" + - "<Name>Qz</Name>" + - "<UpperBounds>6.6</UpperBounds>" + - "<LowerBounds>-6.6</LowerBounds>" + - "<NumberOfBins>" + nbinsD + "</NumberOfBins>" + - "</Dimension>" + - "<Dimension ID=\"other\">" + - "<Name>Other</Name>" + - "<UpperBounds>6.6</UpperBounds>" + - "<LowerBounds>-6.6</LowerBounds>" + - "<NumberOfBins>" + nbinsE + "</NumberOfBins>" + - "</Dimension>" + - "<XDimension>" + - "<RefDimensionId>qx</RefDimensionId>" + - "</XDimension>" + - "<YDimension>" + - "<RefDimensionId>qy</RefDimensionId>" + - "</YDimension>" + - "<ZDimension>" + - "<RefDimensionId>qz</RefDimensionId>" + - "</ZDimension>" + - "<TDimension>" + - "<RefDimensionId>en</RefDimensionId>" + - "</TDimension>" + - "</DimensionSet>"; - } - - static std::string constructXML() - { - return constructXML("1", "5", "5", "5", "3"); - } - - class MockGeometryView : public GeometryView - { - public: - MOCK_METHOD1(addDimensionView, void(DimensionView*)); - MOCK_CONST_METHOD0(getGeometryXMLString, std::string()); - MOCK_METHOD0(getDimensionViewFactory, const DimensionViewFactory&()); - MOCK_METHOD0(raiseModified, void()); - MOCK_METHOD0(raiseNoClipping, void()); - MOCK_CONST_METHOD0(getBinDisplayMode, BinDisplay()); - ~MockGeometryView(){} - }; - - class MockDimensionViewFactory : public DimensionViewFactory - { - public: - MOCK_CONST_METHOD0( create, DimensionView*()); - ~MockDimensionViewFactory(){} - }; - - class MockDimensionView : public DimensionView - { - public: - MOCK_METHOD0(configureStrongly, void()); - MOCK_METHOD0(configureWeakly, void()); - MOCK_METHOD1(showAsNotIntegrated, void(VecIMDDimension_sptr)); - MOCK_METHOD0(showAsIntegrated, void()); - MOCK_METHOD1(accept, void(DimensionPresenter*)); - MOCK_CONST_METHOD0(getVisDimensionName, std::string()); - MOCK_CONST_METHOD0(getMinimum, float()); - MOCK_CONST_METHOD0(getMaximum, float()); - MOCK_CONST_METHOD0(getNBins, unsigned int()); - MOCK_CONST_METHOD0(getSelectedIndex, unsigned int()); - MOCK_CONST_METHOD0(getIsIntegrated, bool()); - MOCK_CONST_METHOD1(displayError, void(std::string)); - MOCK_METHOD1(setViewMode, void(Mantid::VATES::BinDisplay)); - ~MockDimensionView(){}; - }; - - class ExposedSynchronisingGeometryPresenter : public Mantid::VATES::SynchronisingGeometryPresenter - { - public: - ExposedSynchronisingGeometryPresenter(Mantid::Geometry::MDGeometryXMLParser& source) : Mantid::VATES::SynchronisingGeometryPresenter(source) {} - Mantid::VATES::DimPresenter_sptr getDimensionPresenter(unsigned int index) - { - return m_dimPresenters[index]; - } - - void dimensionCollapsed(DimensionPresenter* pDimensionPresenter) - { - return Mantid::VATES::SynchronisingGeometryPresenter::dimensionCollapsed(pDimensionPresenter); - } - }; - -public: - - void testConstruct() - { - MDGeometryXMLParser parser(constructXML()); - parser.execute(); - SynchronisingGeometryPresenter* pPresenter = NULL; - TS_ASSERT_THROWS_NOTHING(pPresenter = new SynchronisingGeometryPresenter(parser)); - delete pPresenter; - } - - void testAcceptView() - { - MockDimensionView dView; - EXPECT_CALL(dView, accept(_)).Times(5); - EXPECT_CALL(dView, configureStrongly()).Times(5); - EXPECT_CALL(dView, showAsNotIntegrated(_)).Times(4); - EXPECT_CALL(dView, showAsIntegrated()).Times(1); - - MockDimensionViewFactory factory; - EXPECT_CALL(factory, create()).Times(5).WillRepeatedly(Return(&dView)); - - MockGeometryView gView; - EXPECT_CALL(gView, getDimensionViewFactory()).WillOnce(ReturnRef(factory)); - EXPECT_CALL(gView, addDimensionView(_)).Times(5); - EXPECT_CALL(gView, getBinDisplayMode()).Times(1).WillOnce(Return(Simple)); - - MDGeometryXMLParser parser(constructXML()); - parser.execute(); - - SynchronisingGeometryPresenter presenter(parser); - presenter.acceptView(&gView); - GeometryPresenter::MappingType axisMappings = presenter.getMappings(); - - TSM_ASSERT_EQUALS("Wrong number of axis-mappings", 4, axisMappings.size()); - TSM_ASSERT("Doesn't contain x-axis mapping", axisMappings.find(presenter.X_AXIS) != axisMappings.end()); - TSM_ASSERT("Doesn't contain y-axis mapping", axisMappings.find(presenter.Y_AXIS) != axisMappings.end()); - TSM_ASSERT("Doesn't contain z-axis mapping", axisMappings.find(presenter.Z_AXIS) != axisMappings.end()); - TSM_ASSERT("Doesn't contain t-axis mapping", axisMappings.find(presenter.T_AXIS) != axisMappings.end()); - - TS_ASSERT(Mock::VerifyAndClearExpectations(&gView)); - TS_ASSERT(Mock::VerifyAndClearExpectations(&dView)); - TS_ASSERT(Mock::VerifyAndClearExpectations(&factory)); - - } - - void testDimensionPartitioning() - { - MDGeometryXMLParser parser(constructXML()); - parser.execute(); - SynchronisingGeometryPresenter presenter(parser); - - VecIMDDimension_sptr nonIntegratedDimensions = presenter.getNonIntegratedDimensions(); - VecIMDDimension_sptr integratedDimensions = presenter.getIntegratedDimensions(); - - TSM_ASSERT_EQUALS("Sum of partitions doesn't compute to total", 5, nonIntegratedDimensions.size() + integratedDimensions.size()); - TSM_ASSERT_EQUALS("Wrong number of non-integrated dimensions", 4, nonIntegratedDimensions.size()); - TSM_ASSERT_EQUALS("Wrong number of integrated dimensions", 1, integratedDimensions.size()); - TSM_ASSERT_EQUALS("Wrong integrated dimension", "en", integratedDimensions[0]->getDimensionId()); - } - - void testCollapsingThrows() - { - //In this test schenario there is a only one non-integrated dimension. - MDGeometryXMLParser parser(constructXML("2", "1", "1", "1", "1")); - parser.execute(); - ExposedSynchronisingGeometryPresenter geometryPresenter(parser); - - MockDimensionView dView; - DimensionPresenter dimensionPresenter(&dView, &geometryPresenter); - - //Should not be able to make a collapse request to the geometry presenter, when there is only one non-collapsed dimension. - TSM_ASSERT_THROWS("Should not be able to collapse the only-exising non-collapsed dimension.", geometryPresenter.dimensionCollapsed(&dimensionPresenter), std::invalid_argument); - } - - void testGetGeometryXML() - { - NiceMock<MockDimensionView> dView; - - NiceMock<MockDimensionViewFactory> factory; - EXPECT_CALL(factory, create()).WillRepeatedly(Return(&dView)); - - NiceMock<MockGeometryView> gView; - EXPECT_CALL(gView, getDimensionViewFactory()).WillRepeatedly(ReturnRef(factory)); - EXPECT_CALL(gView, getBinDisplayMode()).Times(1).WillOnce(Return(Simple)); - - MDGeometryXMLParser parser(constructXML()); - parser.execute(); - - SynchronisingGeometryPresenter presenter(parser); - presenter.acceptView(&gView); - - TSM_ASSERT("Geometry XML has not been constructed", !presenter.getGeometryXML().empty()); - TS_ASSERT(Mock::VerifyAndClearExpectations(&gView)); - TS_ASSERT(Mock::VerifyAndClearExpectations(&dView)); - TS_ASSERT(Mock::VerifyAndClearExpectations(&factory)); - } - - void testDimensionRealign() - { - NiceMock<MockDimensionView> dView; - EXPECT_CALL(dView, getVisDimensionName()).WillRepeatedly(Return("T-AXIS")); - - NiceMock<MockDimensionViewFactory> factory; - EXPECT_CALL(factory, create()).WillRepeatedly(Return(&dView)); - - NiceMock<MockGeometryView> gView; - EXPECT_CALL(gView, getDimensionViewFactory()).WillRepeatedly(ReturnRef(factory)); - EXPECT_CALL(gView, getBinDisplayMode()).Times(1).WillOnce(Return(Simple)); - - MDGeometryXMLParser parser(constructXML()); - parser.execute(); - - ExposedSynchronisingGeometryPresenter presenter(parser); - presenter.acceptView(&gView); - - //find out what presenter X_DIMENSION maps to. - DimPresenter_sptr presenterA = presenter.getMappings().at(presenter.X_AXIS); - DimPresenter_sptr presenterB = presenter.getMappings().at(presenter.T_AXIS); - - TSM_ASSERT_EQUALS("Swapping has not occured as expected.", presenter.X_AXIS, presenterA->getMapping()); - TSM_ASSERT_EQUALS("Swapping has not occured as expected.", presenter.T_AXIS, presenterB->getMapping()); - - presenter.dimensionRealigned(presenterA.get()); //Now swap these two dimensions - - TSM_ASSERT_EQUALS("Swapping has not occured as expected.", presenter.T_AXIS, presenterA->getMapping()); - TSM_ASSERT_EQUALS("Swapping has not occured as expected.", presenter.X_AXIS, presenterB->getMapping()); - - TS_ASSERT(Mock::VerifyAndClearExpectations(&gView)); - TS_ASSERT(Mock::VerifyAndClearExpectations(&dView)); - TS_ASSERT(Mock::VerifyAndClearExpectations(&factory)); - } - - void testNoDimensionModeChanged() - { - NiceMock<MockDimensionView> dView; - EXPECT_CALL(dView, setViewMode(_)).Times(0); // Call 0 times since nothing has changed. - - NiceMock<MockDimensionViewFactory> factory; - EXPECT_CALL(factory, create()).WillRepeatedly(Return(&dView)); - - NiceMock<MockGeometryView> gView; - EXPECT_CALL(gView, getDimensionViewFactory()).WillRepeatedly(ReturnRef(factory)); - EXPECT_CALL(gView, getBinDisplayMode()).Times(2).WillRepeatedly(Return(Simple)); //Will return (SIMPLE) the same Mode as the original, so nothing should happen. - - MDGeometryXMLParser parser(constructXML()); - parser.execute(); - - SynchronisingGeometryPresenter presenter(parser); //Default initalizer sets the mode to SIMPLE - presenter.acceptView(&gView); - - //Some external indication that the mode has changed. - presenter.setDimensionModeChanged(); - - TS_ASSERT(Mock::VerifyAndClearExpectations(&gView)); - TS_ASSERT(Mock::VerifyAndClearExpectations(&dView)); - TS_ASSERT(Mock::VerifyAndClearExpectations(&factory)); - } - - void testDimensionModeChangedOnce() - { - NiceMock<MockDimensionView> dView; - EXPECT_CALL(dView, setViewMode(_)).Times(5); // Call 5 times since 5 dimensions are in the xml. - - NiceMock<MockDimensionViewFactory> factory; - EXPECT_CALL(factory, create()).WillRepeatedly(Return(&dView)); - - NiceMock<MockGeometryView> gView; - EXPECT_CALL(gView, getDimensionViewFactory()).WillRepeatedly(ReturnRef(factory)); - EXPECT_CALL(gView, getBinDisplayMode()).Times(2).WillOnce(Return(Simple)).WillOnce(Return(LowHighStep)); //Will return (LowHighStep) a different Mode to the original. - - MDGeometryXMLParser parser(constructXML()); - parser.execute(); - - SynchronisingGeometryPresenter presenter(parser); //Default initalizer sets the mode to SIMPLE - presenter.acceptView(&gView); - - //Some external indication that the mode has changed. - presenter.setDimensionModeChanged(); - - TS_ASSERT(Mock::VerifyAndClearExpectations(&gView)); - TS_ASSERT(Mock::VerifyAndClearExpectations(&dView)); - TS_ASSERT(Mock::VerifyAndClearExpectations(&factory)); - } - - void testDimensionModeChangedDuplicated() - { - NiceMock<MockDimensionView> dView; - EXPECT_CALL(dView, setViewMode(_)).Times(5); // Call 5 times since 5 dimensions are in the xml. - - NiceMock<MockDimensionViewFactory> factory; - EXPECT_CALL(factory, create()).WillRepeatedly(Return(&dView)); - - NiceMock<MockGeometryView> gView; - EXPECT_CALL(gView, getDimensionViewFactory()).WillRepeatedly(ReturnRef(factory)); - EXPECT_CALL(gView, getBinDisplayMode()).Times(3).WillOnce(Return(Simple)).WillRepeatedly(Return(LowHighStep)); //Will return (LowHighStep) a different Mode to the original. - - MDGeometryXMLParser parser(constructXML()); - parser.execute(); - - SynchronisingGeometryPresenter presenter(parser); //Default initalizer sets the mode to SIMPLE - presenter.acceptView(&gView); - - //Some external indication that the mode has changed. - presenter.setDimensionModeChanged(); - presenter.setDimensionModeChanged(); //Calling it again should do nothing because the last result should be cached. - - TS_ASSERT(Mock::VerifyAndClearExpectations(&gView)); - TS_ASSERT(Mock::VerifyAndClearExpectations(&dView)); - TS_ASSERT(Mock::VerifyAndClearExpectations(&factory)); - } - -}; - -#endif diff --git a/Code/Mantid/docs/source/algorithms/Transpose-v1.rst b/Code/Mantid/docs/source/algorithms/Transpose-v1.rst index 44218c1a7f57dd3aa20e13f235c0b86345c01318..15f8b725124bbb7d484339cbcc6395b8a5f95a2f 100644 --- a/Code/Mantid/docs/source/algorithms/Transpose-v1.rst +++ b/Code/Mantid/docs/source/algorithms/Transpose-v1.rst @@ -10,7 +10,7 @@ Description ----------- This algorithm transposes a workspace, so that an N1 x N2 workspace -becomes N2 x N1. +becomes N2 x N1. The X-vector values for the new workspace are taken from the axis values of the old workspace, which is generaly the spectra number but can be @@ -22,6 +22,8 @@ other values, if say the workspace has gone through The new axis values are taken from the previous X-vector values for the first specrum in the workspace. For this reason, use with ragged workspaces is undefined. + +For transposing multidimensional workspaces use :ref:`TransposeMD <algm-TransposeMD>`. Usage ----- diff --git a/Code/Mantid/docs/source/algorithms/Transpose3D-v1.rst b/Code/Mantid/docs/source/algorithms/Transpose3D-v1.rst index 0b31bfbfb5031a31614aab5f4d292048a9133292..ddb63add8e176353a946bc29be50902aaf202b18 100644 --- a/Code/Mantid/docs/source/algorithms/Transpose3D-v1.rst +++ b/Code/Mantid/docs/source/algorithms/Transpose3D-v1.rst @@ -8,7 +8,7 @@ .. warning:: - This algorithm is currently under review and may change or disappear in a future release of Mantid. + For transposing multidimensional workspaces now use :ref:`TransposeMD <algm-TransposeMD>`. This algorithm is currently under review and may change or disappear in a future release of Mantid. diff --git a/Code/Mantid/docs/source/algorithms/TransposeMD-v1.rst b/Code/Mantid/docs/source/algorithms/TransposeMD-v1.rst new file mode 100644 index 0000000000000000000000000000000000000000..501eb76c91300c3eae70e527c57be523e94e64f6 --- /dev/null +++ b/Code/Mantid/docs/source/algorithms/TransposeMD-v1.rst @@ -0,0 +1,51 @@ + +.. algorithm:: + +.. summary:: + +.. alias:: + +.. properties:: + +Description +----------- + +Performs an axis-aligned traspose of a :ref:`MDHistoWorkspace <MDHistoWorkspace>`. Default *Axes* setting gives not transpose. It is possible to remove dimensions from the input workspace by omitting those dimension indexes from the *Axes* property. *Axes* are zero-based indexes. + +Usage +----- + +**Example - TransposeMD** + +.. testcode:: TransposeMDExample + + def print_dims(ws): + for i in range(ws.getNumDims()): + print 'Dimension %i is %s' % (i, ws.getDimension(i).getName()) + + mdws = CreateMDWorkspace(Dimensions=3, Extents='-10,10,-10,10,-10,10', Names='A,B,C', Units='U,U,U') + FakeMDEventData(InputWorkspace=mdws, PeakParams='500000,0,0,0,3') + binned = BinMD(InputWorkspace=mdws, AlignedDim0='A,0,10,100', AlignedDim1='B,-10,10,100', AlignedDim2='C,-10,10,1') + print 'Dimensions before', binned.getNumDims() + print_dims(binned) + # Transpose the workspace + transposed = TransposeMD(binned, Axes=[1,0]) + print 'Dimensions after', transposed.getNumDims() + print_dims(transposed) + +Output: + +.. testoutput:: TransposeMDExample + + Dimensions before 3 + Dimension 0 is A + Dimension 1 is B + Dimension 2 is C + Dimensions after 2 + Dimension 0 is B + Dimension 1 is A + +.. categories:: + +.. sourcelink:: +