Skip to content

Commit

Permalink
Refs #4316 More tests of SliceViewer python interface
Browse files Browse the repository at this point in the history
  • Loading branch information
Janik Zikovsky committed Dec 13, 2011
1 parent 51528ba commit daf13ce
Show file tree
Hide file tree
Showing 7 changed files with 105 additions and 25 deletions.
1 change: 1 addition & 0 deletions Code/Mantid/MantidQt/API/test/MantidColorMapTest.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ class MantidColorMapTest : public CxxTest::TestSuite
MantidColorMap map;
QwtDoubleInterval range(1.0, 10000.0);
map.changeScaleType( GraphOptions::Log10 );
TS_ASSERT_EQUALS(1,2);
TS_ASSERT_DELTA( map.normalize(range, 1000.), 0.75, 1e-5);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,12 @@ class EXPORT_OPT_MANTIDQT_SLICEVIEWER DimensionSliceWidget : public QWidget
void setDimension(int index, Mantid::Geometry::IMDDimension_const_sptr dim);
void setMinMax(double min, double max);
void setShownDim(int dim);
void setSlicePoint(double value);

double getSlicePoint() const
{ return m_slicePoint; }


/// @return the shown dimension, 0=X, 1=Y, -1=None
int getShownDim() const
{ return m_shownDim; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,13 @@ class EXPORT_OPT_MANTIDQT_SLICEVIEWER SliceViewer : public QWidget
void loadColorMap(QString filename = QString() );
LineOverlay * getLineOverlay() { return m_lineOverlay; }
Mantid::Kernel::VMD getSlicePoint() const { return m_slicePoint; }
size_t getDimX() const { return m_dimX; }
size_t getDimY() const { return m_dimY; }
int getDimX() const { return int(m_dimX); }
int getDimY() const { return int(m_dimY); }

/// Methods for Python bindings
void setDimX(int index);
void setDimY(int index);
void setXYDim(int indexX, int indexY);
void setSlicePoint(int dim, double value);
double getSlicePoint(int dim) const;

signals:
/// Signal emitted when the X/Y index of the shown dimensions is changed
Expand Down
12 changes: 12 additions & 0 deletions Code/Mantid/MantidQt/SliceViewer/src/DimensionSliceWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,18 @@ void DimensionSliceWidget::setShownDim(int dim)
m_insideSetShownDim = false;
}


//-------------------------------------------------------------------------------------------------
/** Sets the slice point value.
*
* @param value :: where to slice
*/
void DimensionSliceWidget::setSlicePoint(double value)
{
// This will trigger the required events
ui.horizontalSlider->setValue(value);
}

//-------------------------------------------------------------------------------------------------
/** Sets the min/max to show on the widget
*
Expand Down
69 changes: 54 additions & 15 deletions Code/Mantid/MantidQt/SliceViewer/src/SliceViewer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -898,7 +898,7 @@ void SliceViewer::changedShownDim(int index, int dim, int oldDim)
}
}
}
// Show the new slice. This finds m_dimX and Y
// Show the new slice. This finds m_dimX and m_dimY
this->updateDisplay();
// Send out a signal
emit changedShownDim(m_dimX, m_dimY);
Expand All @@ -909,26 +909,65 @@ void SliceViewer::changedShownDim(int index, int dim, int oldDim)
//========================================== PYTHON METHODS =======================================
//=================================================================================================

/** Set the index of the dimension that will be shown as the X axis
* of the plot.
* @param index :: index of the dimension, from 0 to NDims-1.
//------------------------------------------------------------------------------------
/** Set the index of the dimensions that will be shown as
* the X and Y axis of the plot.
*
* To be called from Python, primarily
*
* @param indexX :: index of the X dimension, from 0 to NDims-1.
* @param indexX :: index of the Y dimension, from 0 to NDims-1.
*/
void SliceViewer::setDimX(int index)
void SliceViewer::setXYDim(int indexX, int indexY)
{
if (index >= int(m_dimWidgets.size()) || index < 0)
throw std::invalid_argument("There is no dimension # " + Strings::toString(index) + " in the workspace.");
m_dimWidgets[index]->setShownDim(0);
if (indexX >= int(m_dimWidgets.size()) || indexX < 0)
throw std::invalid_argument("There is no dimension # " + Strings::toString(indexX) + " in the workspace.");
if (indexY >= int(m_dimWidgets.size()) || indexY < 0)
throw std::invalid_argument("There is no dimension # " + Strings::toString(indexY) + " in the workspace.");
if (indexX == indexY)
throw std::invalid_argument("X dimension must be different than the Y dimension index.");

// Set the X and Y widgets
m_dimWidgets[indexX]->setShownDim(0);
m_dimWidgets[indexY]->setShownDim(1);

// Set all other dimensions as slice points
for (int d=0; d < int(m_dimWidgets.size()); d++)
if (d != indexX && d != indexY)
m_dimWidgets[d]->setShownDim(-1);

// Show the new slice. This finds m_dimX and m_dimY
this->updateDisplay();
emit changedShownDim(m_dimX, m_dimY);
}

/** Set the index of the dimension that will be shown as the Y axis
* of the plot.
* @param index :: index of the dimension, from 0 to NDims-1.

//------------------------------------------------------------------------------------
/** Sets the slice point in the given dimension:
* that is, what is the position of the plane in that dimension
*
* @param dim :: index of the dimension to change
* @param value :: value of the slice point, in the units of the given dimension.
* This should be within the range of min/max for that dimension.
*/
void SliceViewer::setSlicePoint(int dim, double value)
{
if (dim >= int(m_dimWidgets.size()) || dim < 0)
throw std::invalid_argument("There is no dimension # " + Strings::toString(dim) + " in the workspace.");
m_dimWidgets[dim]->setSlicePoint(value);
}

//------------------------------------------------------------------------------------
/** Returns the slice point in the given dimension
*
* @param dim :: index of the dimension
* @return slice point for that dimension. Value has not significance for the X or Y display dimensions.
*/
void SliceViewer::setDimY(int index)
double SliceViewer::getSlicePoint(int dim) const
{
if (index >= int(m_dimWidgets.size()) || index < 0)
throw std::invalid_argument("There is no dimension # " + Strings::toString(index) + " in the workspace.");
m_dimWidgets[index]->setShownDim(1);
if (dim >= int(m_dimWidgets.size()) || dim < 0)
throw std::invalid_argument("There is no dimension # " + Strings::toString(dim) + " in the workspace.");
return m_slicePoint[dim];
}

} //namespace
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,36 @@ def setUp(self):
def tearDown(self):
""" Close the created widget """
self.sv.close()
def test_setWorkspace(self):
sv = self.sv
sv.setWorkspace('uniform')
sv.show()
#sv.show()

def test_set_MDEventWorkspace(self):
def test_setWorkspace_MDEventWorkspace(self):
sv = self.sv
sv.setWorkspace('mdw')
sv.show()
#sv.show()

def test_setXYDim(self):
sv = self.sv
sv.setWorkspace('uniform')
sv.setXYDim(0,2)
self.assertEqual( sv.getDimX(), 0, "X dimension was set")
self.assertEqual( sv.getDimY(), 2, "Y dimension was set")
#sv.show()
#app.exec_()

def test_setSlicePoint(self):
sv = self.sv
sv.setWorkspace('uniform')
sv.setSlicePoint(2, 7.6)
# Set the slice point and got back the value?
self.assertAlmostEqual( sv.getSlicePoint(2), 7.6, 2)

# sv.show()
# app.exec_()




9 changes: 7 additions & 2 deletions Code/Mantid/MantidQt/mantidqt.sip
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,13 @@ public:
void zoomBy(double factor);
void setWorkspace(const QString & wsName);
void showControls(bool visible);
void setDimX(int index);
void setDimY(int index);

void setXYDim(int indexX, int indexY);
int getDimX() const;
int getDimY() const;

void setSlicePoint(int dim, double value);
double getSlicePoint(int dim) const;

};

Expand Down

0 comments on commit daf13ce

Please sign in to comment.