Skip to content

Commit

Permalink
Refs #4316 fixed issue with setShownDim
Browse files Browse the repository at this point in the history
And added a test that runs within MantidPlot
  • Loading branch information
Janik Zikovsky committed Dec 13, 2011
1 parent d355ab5 commit 8de4940
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 41 deletions.
8 changes: 4 additions & 4 deletions Code/Mantid/MantidQt/SliceViewer/src/DimensionSliceWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ void DimensionSliceWidget::btnXYChanged()
{
if (m_insideSetShownDim)
return;
int oldDim = m_shownDim;
if (ui.btnX->isChecked() && ui.btnY->isChecked() )
{
// Toggle when both are checked
Expand All @@ -84,6 +85,9 @@ void DimensionSliceWidget::btnXYChanged()
this->setShownDim(1);
else
this->setShownDim(-1);

// Emit that the user changed the shown dimension
emit changedShownDim(m_dimIndex, m_shownDim, oldDim);
}


Expand All @@ -96,7 +100,6 @@ void DimensionSliceWidget::btnXYChanged()
void DimensionSliceWidget::setShownDim(int dim)
{
m_insideSetShownDim = true;
int oldDim = m_shownDim;
m_shownDim = dim;
ui.btnX->setChecked( m_shownDim == 0 );
ui.btnY->setChecked( m_shownDim == 1 );
Expand Down Expand Up @@ -130,9 +133,6 @@ void DimensionSliceWidget::setShownDim(int dim)

this->update();
m_insideSetShownDim = false;

// Emit that the user changed the shown dimension
emit changedShownDim(m_dimIndex, m_shownDim, oldDim);
}

//-------------------------------------------------------------------------------------------------
Expand Down
9 changes: 8 additions & 1 deletion Code/Mantid/MantidQt/SliceViewer/src/QwtRasterDataMD.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ QwtRasterDataMD::QwtRasterDataMD()
m_minVal = DBL_MAX;
m_maxVal = -DBL_MAX;
m_range = QwtDoubleInterval(0.0, 1.0);
m_nd = 0;
m_dimX = 0;
m_dimY = 0;
nan = std::numeric_limits<double>::quiet_NaN();
}

Expand Down Expand Up @@ -127,6 +130,8 @@ QSize QwtRasterDataMD::rasterHint(const QwtDoubleRect &area) const
*/
void QwtRasterDataMD::setWorkspace(Mantid::API::IMDWorkspace_sptr ws)
{
if (!ws)
throw std::runtime_error("QwtRasterDataMD::setWorkspace(): NULL workspace passed.");
m_ws = ws;
m_nd = m_ws->getNumDims();
m_dimX = 0;
Expand All @@ -144,10 +149,12 @@ void QwtRasterDataMD::setWorkspace(Mantid::API::IMDWorkspace_sptr ws)
*/
void QwtRasterDataMD::setSliceParams(size_t dimX, size_t dimY, std::vector<Mantid::coord_t> & slicePoint)
{
if (slicePoint.size() != m_nd)
throw std::runtime_error("QwtRasterDataMD::setSliceParams(): inconsistent vector/number of dimensions size.");
m_dimX = dimX;
m_dimY = dimY;
delete [] m_slicePoint;
m_slicePoint = new coord_t[m_nd];
m_slicePoint = new coord_t[slicePoint.size()];
for (size_t d=0; d<m_nd; d++)
m_slicePoint[d] = slicePoint[d];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,59 +3,54 @@
import os
import unittest
import time

# Import the Mantid framework
sys.path.append( os.getcwd() )
import MantidFramework
from MantidFramework import mtd
from mantidsimple import *
from PyQt4 import Qt
from PyQt4 import QtTest
from PyQt4.QtTest import QTest
import libmantidqtpython

# Create a test data set
CreateMDWorkspace(Dimensions='3',Extents='0,10,0,10,0,10',Names='x,y,z',
Units='m,m,m',SplitInto='5',MaxRecursionDepth='20',OutputWorkspace='mdw')
FakeMDEventData("mdw", UniformParams="1e6")
Units='m,m,m',SplitInto='5',SplitThreshold=100, MaxRecursionDepth='20',OutputWorkspace='mdw')
FakeMDEventData("mdw", UniformParams="1e4")
FakeMDEventData("mdw", PeakParams="1e3, 1, 2, 3, 1.0")
BinMD("mdw", "uniform", AxisAligned=1, AlignedDimX="x,0,10,30", AlignedDimY="y,0,10,30", AlignedDimZ="z,0,10,30", IterateEvents="1", Parallel="0")

w = mtd['uniform']
print "CREATED!", w


from PyQt4 import Qt
import libmantidqtpython


class SliceViewerPythonInterfaceTest(unittest.TestCase):
"""Test for accessing SliceViewer widgets from MantidPlot
python interpreter"""

def setUp(self):
self.app = Qt.QApplication(sys.argv)
""" Set up and create a SliceViewer widget """
global libmantidqtpython
self.sv = libmantidqtpython.MantidQt.SliceViewer.SliceViewer()
pass

def tearDown(self):
""" Close the created widget """
self.sv.close()

def test_creating(self):
print "test_creating"
import time
def test_setWorkspace(self):
print "test_setWorkspace"
sv = self.sv
#sv.setWorkspace('mdw')
sv.setWorkspace('uniform')
sv.show()
print sv
#sv.close()
global QTest
#QTest.mouseClick(sv)

def test_creating2(self):
print "test_creating2"
def test_other(self):
print "test_other"
sv = self.sv
sv.setWorkspace('mdw')
sv.show()


if __name__=="__main__":
unittest.main()

## ----- Create and run the unit test ----------------------
#sys.path.append("/home/8oz/Code/Mantid/Code/Mantid/TestingTools/unittest-xml-reporting/src")
#import xmlrunner
#suite = unittest.makeSuite(SliceViewerPythonInterfaceTest)
#runner = xmlrunner.XMLTestRunner(output='Testing')
#runner.run(suite)
#print "Done!"
# ----- Create and run the unit test ----------------------
sys.path.append("/home/8oz/Code/Mantid/Code/Mantid/TestingTools/unittest-xml-reporting/src")
import xmlrunner
suite = unittest.makeSuite(SliceViewerPythonInterfaceTest)
runner = xmlrunner.XMLTestRunner(output='Testing')
runner.run(suite)
print "Done!"

#
## Run the app.
#a.exec_()

0 comments on commit 8de4940

Please sign in to comment.