Skip to content

Commit

Permalink
Harmonize creation of plot axis titles for MD & nonMD sources.
Browse files Browse the repository at this point in the history
Refs #9252
  • Loading branch information
martyngigg committed Apr 9, 2014
1 parent de1cc4b commit a8c8305
Show file tree
Hide file tree
Showing 24 changed files with 79 additions and 41 deletions.
19 changes: 15 additions & 4 deletions Code/Mantid/Framework/API/src/MatrixWorkspace.cpp
Expand Up @@ -1211,10 +1211,15 @@ namespace Mantid
{
}
/// the name of the dimennlsion as can be displayed along the axis
virtual std::string getName() const {return m_axis.unit()->caption();}
virtual std::string getName() const
{
const auto & unit = m_axis.unit();
if (unit && unit->unitID() != "Empty" ) return unit->caption();
else return m_axis.title();
}

/// @return the units of the dimension as a string
virtual std::string getUnits() const {return m_axis.unit()->label();}
virtual const Kernel::UnitLabel getUnits() const { return m_axis.unit()->label(); }

/// short name which identify the dimension among other dimension. A dimension can be usually find by its ID and various
/// various method exist to manipulate set of dimensions by their names.
Expand Down Expand Up @@ -1267,10 +1272,16 @@ namespace Mantid
virtual ~MWXDimension(){};

/// the name of the dimennlsion as can be displayed along the axis
virtual std::string getName() const {return m_ws->getAxis(0)->unit()->caption();}
virtual std::string getName() const
{
const auto *axis = m_ws->getAxis(0);
const auto & unit = axis->unit();
if (unit && unit->unitID() != "Empty" ) return unit->caption();
else return axis->title();
}

/// @return the units of the dimension as a string
virtual std::string getUnits() const {return m_ws->getAxis(0)->unit()->label();}
virtual const Kernel::UnitLabel getUnits() const {return m_ws->getAxis(0)->unit()->label();}

/// short name which identify the dimension among other dimension. A dimension can be usually find by its ID and various
/// various method exist to manipulate set of dimensions by their names.
Expand Down
Expand Up @@ -10,6 +10,14 @@

namespace Mantid
{
namespace Kernel
{
//---------------------------------------------------------------------------
// Forward declarations
//---------------------------------------------------------------------------
class UnitLabel;
}

namespace Geometry
{
/** The class discribes one dimension of multidimensional dataset representing an ortogonal dimension and linear axis.
Expand Down Expand Up @@ -50,7 +58,7 @@ namespace Mantid
virtual std::string getName() const = 0;

/// @return the units of the dimension as a string
virtual std::string getUnits() const = 0;
virtual const Kernel::UnitLabel getUnits() const = 0;

/// short name which identify the dimension among other dimensin. A dimension can be usually find by its ID and various
/// various method exist to manipulate set of dimensions by their names.
Expand Down
Expand Up @@ -4,6 +4,7 @@
#include "MantidGeometry/DllConfig.h"
#include "MantidKernel/Exception.h"
#include "MantidGeometry/MDGeometry/IMDDimension.h"
#include "MantidKernel/UnitLabel.h"
#include "MantidKernel/VMD.h"

namespace Mantid
Expand All @@ -26,12 +27,12 @@ namespace Geometry
/** Constructor for simple MDHistoDimension
* @param name :: full name of the axis
* @param ID :: identifier string
* @param units :: string giving the units of this dimension
* @param units :: A plain-text string giving the units of this dimension
* @param min :: minimum extent
* @param max :: maximum extent
* @param numBins :: number of bins (evenly spaced)
*/
MDHistoDimension(std::string name, std::string ID, std::string units, coord_t min, coord_t max, size_t numBins)
MDHistoDimension(std::string name, std::string ID, const Kernel::UnitLabel & units, coord_t min, coord_t max, size_t numBins)
: m_name(name), m_dimensionId(ID), m_units(units),
m_min(min), m_max(max), m_numBins(numBins),
m_binWidth((max-min)/static_cast<coord_t>(numBins))
Expand Down Expand Up @@ -65,7 +66,7 @@ namespace Geometry
}

/// Return the units of the dimension as a string
virtual std::string getUnits() const
virtual const Kernel::UnitLabel getUnits() const
{
return m_units;
}
Expand Down Expand Up @@ -137,7 +138,7 @@ namespace Geometry
std::string m_dimensionId;

/// Dimension units
std::string m_units;
Kernel::UnitLabel m_units;

/// Extent of dimension
coord_t m_min;
Expand Down
7 changes: 4 additions & 3 deletions Code/Mantid/Framework/Geometry/test/IMDDimensionFactoryTest.h
Expand Up @@ -3,6 +3,7 @@

#include <cxxtest/TestSuite.h>
#include "MantidGeometry/MDGeometry/IMDDimensionFactory.h"
#include "MantidKernel/UnitLabel.h"
#include <Poco/DOM/DOMParser.h>
#include <Poco/DOM/Document.h>
#include <Poco/XML/XMLException.h>
Expand Down Expand Up @@ -54,7 +55,7 @@ class IMDDimensionFactoryTest: public CxxTest::TestSuite
void testCorrectGeneration()
{
IMDDimension_const_sptr dimension = createDimension(constructDimensionWithUnitsXMLString());
TS_ASSERT_EQUALS("Cubits", dimension->getUnits());
TS_ASSERT_EQUALS("Cubits", dimension->getUnits().ascii());
TS_ASSERT_EQUALS("Qz", dimension->getName());
TS_ASSERT_EQUALS("qz", dimension->getDimensionId());
TS_ASSERT_EQUALS(-3, dimension->getMinimum());
Expand All @@ -65,7 +66,7 @@ class IMDDimensionFactoryTest: public CxxTest::TestSuite
void testCorrectGenerationWithoutUnits()
{
IMDDimension_const_sptr dimension = createDimension(constructDimensionWithoutUnitsXMLString());
TS_ASSERT_EQUALS("None", dimension->getUnits());
TS_ASSERT_EQUALS("None", dimension->getUnits().ascii());
TS_ASSERT_EQUALS("Qz", dimension->getName());
TS_ASSERT_EQUALS("qz", dimension->getDimensionId());
TS_ASSERT_EQUALS(-3, dimension->getMinimum());
Expand All @@ -87,7 +88,7 @@ class IMDDimensionFactoryTest: public CxxTest::TestSuite
void testOverrideMethod()
{
IMDDimension_const_sptr dimension = createDimension(constructDimensionWithUnitsXMLString(),10,-9.0,8.5);
TS_ASSERT_EQUALS("Cubits", dimension->getUnits());
TS_ASSERT_EQUALS("Cubits", dimension->getUnits().ascii());
TS_ASSERT_EQUALS("Qz", dimension->getName());
TS_ASSERT_EQUALS("qz", dimension->getDimensionId());
TS_ASSERT_EQUALS(-9.0, dimension->getMinimum());
Expand Down
Expand Up @@ -8,6 +8,8 @@
#include "MantidGeometry/MDGeometry/MDGeometryXMLBuilder.h"
#include "MantidGeometry/MDGeometry/IMDDimension.h"

#include "MantidKernel/UnitLabel.h"

#include <boost/functional/hash.hpp>
#include <boost/algorithm/string.hpp>
#include <boost/format.hpp>
Expand Down Expand Up @@ -36,7 +38,7 @@ class MDGeometryXMLBuilderTest : public CxxTest::TestSuite
MOCK_CONST_METHOD0(getName,
std::string());
MOCK_CONST_METHOD0(getUnits,
std::string());
const Mantid::Kernel::UnitLabel());
MOCK_CONST_METHOD0(getDimensionId,
std::string());
MOCK_CONST_METHOD0(getMaximum,
Expand Down
Expand Up @@ -26,7 +26,7 @@ class MDHistoDimensionBuilderTest : public CxxTest::TestSuite

TS_ASSERT_EQUALS("testDimName", product->getName());
TS_ASSERT_EQUALS("testDimId", product->getDimensionId());
TS_ASSERT_EQUALS("A^-1", product->getUnits());
TS_ASSERT_EQUALS("A^-1", product->getUnits().ascii());
TS_ASSERT_EQUALS(0, product->getMinimum());
TS_ASSERT_EQUALS(2, product->getMaximum());
TS_ASSERT_EQUALS(1, product->getNBins());
Expand All @@ -47,7 +47,7 @@ class MDHistoDimensionBuilderTest : public CxxTest::TestSuite
TS_ASSERT_THROWS_NOTHING(product = builder.create());
TS_ASSERT_EQUALS("testDimName", product->getName());
TS_ASSERT_EQUALS("testDimId", product->getDimensionId());
TS_ASSERT_EQUALS("A^-1", product->getUnits());
TS_ASSERT_EQUALS("A^-1", product->getUnits().ascii());
TS_ASSERT_EQUALS(0, product->getMinimum());
TS_ASSERT_EQUALS(2, product->getMaximum());
TS_ASSERT_EQUALS(1, product->getNBins());
Expand Down Expand Up @@ -211,4 +211,4 @@ class MDHistoDimensionBuilderTest : public CxxTest::TestSuite

};

#endif
#endif
7 changes: 7 additions & 0 deletions Code/Mantid/Framework/Kernel/src/Strings.cpp
@@ -1,5 +1,6 @@
#include "MantidKernel/Strings.h"
#include "MantidKernel/Exception.h"
#include "MantidKernel/UnitLabel.h"

#include <Poco/StringTokenizer.h>
#include <Poco/Path.h>
Expand Down Expand Up @@ -777,6 +778,12 @@ namespace Mantid
return toString(std::vector<T>(value.begin(), value.end()));
}

template<>
std::string toString(const UnitLabel &value)
{
return value;
}

//------------------------------------------------------------------------------------------------
/**
* Write out the three vectors into a file of type dc 9
Expand Down
Expand Up @@ -111,7 +111,7 @@ class CreateMDHistoWorkspaceTest : public CxxTest::TestSuite

TS_ASSERT_EQUALS("A", dim1->getName());
TS_ASSERT_EQUALS("A", dim1->getDimensionId());
TS_ASSERT_EQUALS("U", dim1->getUnits());
TS_ASSERT_EQUALS("U", dim1->getUnits().ascii());
TS_ASSERT_EQUALS(1, dim1->getMaximum());
TS_ASSERT_EQUALS(-1, dim1->getMinimum());
TS_ASSERT_EQUALS(5, dim1->getNBins());
Expand Down Expand Up @@ -177,4 +177,4 @@ class CreateMDHistoWorkspaceTest : public CxxTest::TestSuite
};


#endif /* MANTID_MDEVENTS_CREATEMDHISTOWORKSPACETEST_H_ */
#endif /* MANTID_MDEVENTS_CREATEMDHISTOWORKSPACETEST_H_ */
8 changes: 4 additions & 4 deletions Code/Mantid/Framework/MDAlgorithms/test/LoadSQWTest.h
Expand Up @@ -142,10 +142,10 @@ class LoadSQWTest : public CxxTest::TestSuite
TS_ASSERT_EQUALS("en", d->getDimensionId());

//Check Units
TS_ASSERT_EQUALS("A^-1", a->getUnits());
TS_ASSERT_EQUALS("A^-1", b->getUnits());
TS_ASSERT_EQUALS("A^-1", c->getUnits());
TS_ASSERT_EQUALS("mEv", d->getUnits());
TS_ASSERT_EQUALS("A^-1", a->getUnits().ascii());
TS_ASSERT_EQUALS("A^-1", b->getUnits().ascii());
TS_ASSERT_EQUALS("A^-1", c->getUnits().ascii());
TS_ASSERT_EQUALS("mEv", d->getUnits().ascii());

//Check Nbins
TS_ASSERT_EQUALS(3, a->getNBins());
Expand Down
2 changes: 1 addition & 1 deletion Code/Mantid/Framework/MDEvents/src/QueryMDWorkspace.cpp
Expand Up @@ -231,7 +231,7 @@ namespace MDEvents
for(size_t index = 0; index < ndims; ++index)
{
Mantid::Geometry::IMDDimension_const_sptr dim = input->getDimension(index);
std::string dimInUnit = dim->getName()+"/"+dim->getUnits();
std::string dimInUnit = dim->getName()+"/"+dim->getUnits().ascii();
output->addColumn("double",dimInUnit);
//Magic numbers required to configure the X axis.
output->getColumn(dimInUnit)->setPlotType(1);
Expand Down
Expand Up @@ -251,13 +251,13 @@ void do_check_throws_invalid_alg_upon_execution(const MDFileObject& infile)

TS_ASSERT_EQUALS("a", dim1->getName());
TS_ASSERT_EQUALS("A", dim1->getDimensionId());
TS_ASSERT_EQUALS("U", dim1->getUnits());
TS_ASSERT_EQUALS("U", dim1->getUnits().ascii());
TS_ASSERT_EQUALS(-1, dim1->getMinimum());
TS_ASSERT_EQUALS(2, dim1->getMaximum());

TS_ASSERT_EQUALS("b", dim2->getName());
TS_ASSERT_EQUALS("B", dim2->getDimensionId());
TS_ASSERT_EQUALS("U", dim2->getUnits());
TS_ASSERT_EQUALS("U", dim2->getUnits().ascii());
TS_ASSERT_EQUALS(-2, dim2->getMinimum());
TS_ASSERT_EQUALS(3, dim2->getMaximum());
}
Expand Down
Expand Up @@ -231,14 +231,14 @@ class ImportMDHistoWorkspaceTest : public CxxTest::TestSuite

TS_ASSERT_EQUALS("A", dim1->getName());
TS_ASSERT_EQUALS("A", dim1->getDimensionId());
TS_ASSERT_EQUALS("U1", dim1->getUnits());
TS_ASSERT_EQUALS("U1", dim1->getUnits().ascii());
TS_ASSERT_EQUALS(1, dim1->getMaximum());
TS_ASSERT_EQUALS(-1, dim1->getMinimum());
TS_ASSERT_EQUALS(2, dim1->getNBins());

TS_ASSERT_EQUALS("B", dim2->getName());
TS_ASSERT_EQUALS("B", dim2->getDimensionId());
TS_ASSERT_EQUALS("U2", dim2->getUnits());
TS_ASSERT_EQUALS("U2", dim2->getUnits().ascii());
TS_ASSERT_EQUALS(1, dim2->getMaximum());
TS_ASSERT_EQUALS(-1, dim2->getMinimum());
TS_ASSERT_EQUALS(2, dim2->getNBins());
Expand Down Expand Up @@ -289,4 +289,4 @@ class ImportMDHistoWorkspaceTest : public CxxTest::TestSuite
};


#endif /* MANTID_MDEVENTS_IMPORTMDHISTOWORKSPACETEST_H_ */
#endif /* MANTID_MDEVENTS_IMPORTMDHISTOWORKSPACETEST_H_ */
@@ -1,4 +1,5 @@
#include "MantidGeometry/MDGeometry/IMDDimension.h"
#include "MantidKernel/UnitLabel.h"

#include <boost/python/class.hpp>
#include <boost/python/register_ptr_to_python.hpp>
Expand Down
2 changes: 1 addition & 1 deletion Code/Mantid/MantidQt/API/src/MantidQwtIMDWorkspaceData.cpp
Expand Up @@ -453,7 +453,7 @@ QString MantidQwtIMDWorkspaceData::getXAxisLabel() const
{
// One of the dimensions of the original
IMDDimension_const_sptr dim = m_originalWorkspace.lock()->getDimension(m_currentPlotAxis);
xLabel = QString::fromStdString(dim->getName() + " (" + dim->getUnits() + ")");
xLabel = QString::fromStdString(dim->getName()) + " (" + QString::fromStdWString(dim->getUnits().utf8()) + ")";
}
else
{
Expand Down
Expand Up @@ -177,7 +177,7 @@ public slots:

void updateDisplay(bool resetAxes = false);
void updateDimensionSliceWidgets();
void resetAxis(int axis, Mantid::Geometry::IMDDimension_const_sptr dim);
void resetAxis(int axis, const Mantid::Geometry::IMDDimension_const_sptr & dim);
QwtDoubleInterval getRange(Mantid::API::IMDIterator * it);
QwtDoubleInterval getRange(std::vector<Mantid::API::IMDIterator *> iterators);

Expand Down
@@ -1,4 +1,5 @@
#include "MantidQtSliceViewer/DimensionSliceWidget.h"
#include "MantidKernel/UnitLabel.h"
#include <iosfwd>
#include <iostream>
#include <iomanip>
Expand Down Expand Up @@ -175,7 +176,7 @@ void DimensionSliceWidget::setMinMax(double min, double max)
{
if (!m_dim) return;
ui.lblName->setText(QString::fromStdString(m_dim->getName()) );
ui.lblUnits->setText(QString::fromStdString(m_dim->getUnits()) );
ui.lblUnits->setText(QString::fromStdWString(m_dim->getUnits().utf8()) );

ui.horizontalSlider->setRange(min, max, m_dim->getBinWidth());

Expand Down
7 changes: 4 additions & 3 deletions Code/Mantid/MantidQt/SliceViewer/src/SliceViewer.cpp
Expand Up @@ -74,6 +74,7 @@
#include "MantidAPI/AlgorithmManager.h"
#include "MantidQtAPI/AlgorithmRunner.h"
#include "MantidQtAPI/FileDialogHandler.h"
#include "MantidQtAPI/PlotAxis.h"


using namespace Mantid;
Expand Down Expand Up @@ -1192,10 +1193,10 @@ void SliceViewer::setXYCenter(double x, double y)
* @param axis :: int for X or Y
* @param dim :: dimension to show
*/
void SliceViewer::resetAxis(int axis, Mantid::Geometry::IMDDimension_const_sptr dim)
void SliceViewer::resetAxis(int axis, const IMDDimension_const_sptr &dim)
{
m_plot->setAxisScale( axis, dim->getMinimum(), dim->getMaximum());
m_plot->setAxisTitle( axis, QString::fromStdString(dim->getName() + " (" + dim->getUnits() + ")") );
m_plot->setAxisTitle( axis, API::PlotAxis(*dim).title());
}

//------------------------------------------------------------------------------------
Expand Down Expand Up @@ -2073,7 +2074,7 @@ void SliceViewer::rebinParamsChanged()
// Set the BasisVector property...
VMD basis(m_ws->getNumDims());
basis[d] = 1.0;
std::string prop = dim->getName() +"," + dim->getUnits() + ","
std::string prop = dim->getName() +"," + dim->getUnits().ascii() + ","
+ basis.toString(",");
alg->setPropertyValue("BasisVector" + Strings::toString(d), prop);
}
Expand Down
5 changes: 3 additions & 2 deletions Code/Mantid/MantidQt/SliceViewer/src/XYLimitsDialog.cpp
@@ -1,4 +1,5 @@
#include "../inc/MantidQtSliceViewer/XYLimitsDialog.h"
#include "MantidKernel/UnitLabel.h"
#include <QIntValidator>

XYLimitsDialog::XYLimitsDialog(QWidget *parent)
Expand Down Expand Up @@ -26,15 +27,15 @@ XYLimitsDialog::~XYLimitsDialog()
void XYLimitsDialog::setXDim(Mantid::Geometry::IMDDimension_const_sptr dim)
{
ui.lblXName->setText( QString::fromStdString(dim->getName()) );
ui.lblXUnits->setText( QString::fromStdString(dim->getUnits()) );
ui.lblXUnits->setText( QString::fromStdWString(dim->getUnits().utf8()) );
}

/** Set the labels for the Y dimensions
* @param dim : IMDDimension */
void XYLimitsDialog::setYDim(Mantid::Geometry::IMDDimension_const_sptr dim)
{
ui.lblYName->setText( QString::fromStdString(dim->getName()) );
ui.lblYUnits->setText( QString::fromStdString(dim->getUnits()) );
ui.lblYUnits->setText( QString::fromStdWString(dim->getUnits().utf8()) );
}

//------------------------------------------------------------------------------------------
Expand Down
3 changes: 2 additions & 1 deletion Code/Mantid/MantidQt/SliceViewer/test/MockObjects.h
Expand Up @@ -11,6 +11,7 @@
#include "MantidQtSliceViewer/ZoomablePeaksView.h"
#include "MantidQtSliceViewer/UpdateableOnDemand.h"
#include "MantidAPI/IPeak.h"
#include "MantidKernel/UnitLabel.h"
#include <boost/regex.hpp>
#include <gmock/gmock.h>
#include <QColor>
Expand Down Expand Up @@ -268,7 +269,7 @@ class MockPeakTransformFactory : public PeakTransformFactory
MOCK_CONST_METHOD0(getName,
std::string());
MOCK_CONST_METHOD0(getUnits,
std::string());
const Mantid::Kernel::UnitLabel());
MOCK_CONST_METHOD0(getDimensionId,
std::string());
MOCK_CONST_METHOD0(getMaximum,
Expand Down
1 change: 1 addition & 0 deletions Code/Mantid/Vates/VatesAPI/src/Common.cpp
@@ -1,5 +1,6 @@
#include "MantidVatesAPI/Common.h"
#include "MantidGeometry/MDGeometry/IMDDimension.h"
#include "MantidKernel/UnitLabel.h"

#include <vtkNew.h>
#include <vtkFieldData.h>
Expand Down

0 comments on commit a8c8305

Please sign in to comment.