Skip to content

Commit

Permalink
refs #4328 #3641. Add apply action functionality.
Browse files Browse the repository at this point in the history
 Also restrict use of setGoniometer for timebeing until a good mechanism for storing/resetting the goniometer can be found.
  • Loading branch information
OwenArnold committed Jan 5, 2012
1 parent 72a1f0b commit fd31765
Show file tree
Hide file tree
Showing 9 changed files with 104 additions and 16 deletions.
6 changes: 3 additions & 3 deletions Code/Mantid/MantidQt/CustomInterfaces/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ set ( SRC_FILES
src/SANSRunWindow.cpp
src/background.cpp
src/deltaECalc.cpp
src/WorkspaceInADS.cpp
src/WorkspaceInADS.cpp
src/WorkspaceMemento.cpp
src/WorkspaceOnDisk.cpp
src/WorkspaceOnDisk.cpp
)

# Include files aren't required, but this makes them appear in Visual Studio
Expand Down Expand Up @@ -115,7 +115,7 @@ target_link_libraries ( CustomInterfaces MantidQtAPI MantidWidgets QtPropertyBro

if ( CXXTEST_FOUND )

include_directories( ../../Framework/TestHelpers/inc ../../Framework/DataObjects/inc )
include_directories( ../../Framework/TestHelpers/inc ../../Framework/DataObjects/inc ../../Framework/Crystal/inc )

if ( GMOCK_FOUND AND GTEST_FOUND )
cxxtest_add_test ( CustomInterfacesTest ${TEST_FILES} ${GMOCK_TEST_FILES} )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,21 @@ namespace MantidQt
{
}

/*
Location type associated with this type.
@return string describing location
*/
static std::string locType()
{
return "In Memory";
}

/// Destructor
virtual ~WorkspaceInADS();

//Apply actions wrapped up in this memento.
virtual void applyActions();

private:
/// Id/name of the workspace in the ADS
std::string m_wsName;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,14 +86,20 @@ namespace MantidQt
virtual ~WorkspaceMemento(){};
/// Common implementation for generating status
Status generateStatus() const;
/// Apply actions wrapped up in the memento back to the original workspace
virtual void applyActions() = 0;

protected:

// Vector of elements describing a UB matrix.
std::vector<double> m_ub;

private:

/// Extract a friendly status.
std::string interpretStatus(const Status arg) const;

// Vector of elements describing a UB matrix.
std::vector<double> m_ub;


// Goniometer matrix
Mantid::Kernel::DblMatrix m_goniometer;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,19 @@ namespace MantidQt
virtual void cleanUp();
/// Destructor
virtual ~WorkspaceOnDisk();

/*
Location type associated with this type.
@return string describing location
*/
static std::string locType()
{
return "On Disk";
}

//Apply actions wrapped up in this memento.
virtual void applyActions();

private:
/// Helper method to delete a workspace out of memory after loading.
void dumpIt(const std::string& name);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ namespace CustomInterfaces
{

//Add this class to the list of specialised dialogs in this namespace
//DECLARE_SUBWINDOW(CreateMDWorkspace); //TODO: Enable this to use it via mantid plot. Not ready for this yet!
DECLARE_SUBWINDOW(CreateMDWorkspace);

/**
Helper type to perform comparisons between WorkspaceMementos
Expand Down Expand Up @@ -308,6 +308,11 @@ void CreateMDWorkspace::setGoniometerClicked()
try
{
WorkspaceMemento_sptr memento = getFirstSelected();
if(memento->locationType() != WorkspaceInADS::locType())
{
runConfirmation("Currently, Goniometer settings may only be applied to Workspace in memory");
return;
}
Mantid::API::MatrixWorkspace_sptr ws = memento->fetchIt();
QString id = QString(memento->getId().c_str());

Expand Down
10 changes: 9 additions & 1 deletion Code/Mantid/MantidQt/CustomInterfaces/src/WorkspaceInADS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ namespace MantidQt
*/
std::string WorkspaceInADS::locationType() const
{
return "In Memory";
return locType();
}

/**
Expand Down Expand Up @@ -80,5 +80,13 @@ namespace MantidQt
WorkspaceInADS::~WorkspaceInADS()
{
}

/*
Apply actions. Load workspace and apply all actions to it.
*/
void WorkspaceInADS::applyActions()
{
//Do nothing.
}
}
}
36 changes: 27 additions & 9 deletions Code/Mantid/MantidQt/CustomInterfaces/src/WorkspaceOnDisk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ namespace MantidQt
*/
std::string WorkspaceOnDisk::locationType() const
{
return "On Disk";
return locType();
}

/**
Expand All @@ -84,15 +84,17 @@ namespace MantidQt

checkStillThere();

IAlgorithm_sptr alg = Mantid::API::AlgorithmManager::Instance().create("LoadRaw");
alg->initialize();
alg->setRethrows(true);
alg->setProperty("Filename", m_fileName);
alg->setPropertyValue("OutputWorkspace", m_adsID);
alg->execute();
if(!AnalysisDataService::Instance().doesExist(m_adsID))
{
IAlgorithm_sptr alg = Mantid::API::AlgorithmManager::Instance().create("LoadRaw");
alg->initialize();
alg->setRethrows(true);
alg->setProperty("Filename", m_fileName);
alg->setPropertyValue("OutputWorkspace", m_adsID);
alg->execute();
}
Workspace_sptr ws = AnalysisDataService::Instance().retrieve(m_adsID);

Mantid::API::Workspace_sptr ws = AnalysisDataService::Instance().retrieve(m_adsID);

Mantid::API::WorkspaceGroup_sptr gws = boost::dynamic_pointer_cast<WorkspaceGroup>(ws);
if(gws != NULL)
{
Expand Down Expand Up @@ -125,5 +127,21 @@ namespace MantidQt
dumpIt(m_adsID);
}

/*
Apply actions. Load workspace and apply all actions to it.
*/
void WorkspaceOnDisk::applyActions()
{
Mantid::API::MatrixWorkspace_sptr ws = fetchIt();

Mantid::API::IAlgorithm_sptr alg = Mantid::API::AlgorithmManager::Instance().create("SetUB");
alg->initialize();
alg->setRethrows(true);
alg->setPropertyValue("Workspace", this->m_adsID);
alg->setProperty("UB", m_ub);
alg->execute();

}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@ class ConcreteWorkspaceMemento : public WorkspaceMemento
{
throw std::runtime_error("Not implemented");
}

virtual void applyActions()
{
throw std::runtime_error("Not implemented");
}
};


Expand Down
20 changes: 20 additions & 0 deletions Code/Mantid/MantidQt/CustomInterfaces/test/WorkspaceOnDiskTest.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <cxxtest/TestSuite.h>
#include "MantidQtCustomInterfaces/WorkspaceOnDisk.h"
#include "MantidAPI/FileFinder.h"
#include "MantidGeometry/Crystal/OrientedLattice.h"

using namespace MantidQt::CustomInterfaces;

Expand Down Expand Up @@ -52,6 +53,25 @@ class WorkspaceOnDiskTest : public CxxTest::TestSuite
TS_ASSERT_EQUALS(WorkspaceMemento::NoOrientedLattice, memento.generateStatus());
}

void testApplyActions()
{
WorkspaceOnDisk memento(getSuitableFileNamePath());
memento.setUB(0,0,2,0,4,0,-8,0,0);
memento.applyActions();
std::vector<double> ub = memento.fetchIt()->sample().getOrientedLattice().getUB().get_vector();
TS_ASSERT_EQUALS(0, ub[0]);
TS_ASSERT_EQUALS(0, ub[1]);
TS_ASSERT_EQUALS(2, ub[2]);
TS_ASSERT_EQUALS(0, ub[3]);
TS_ASSERT_EQUALS(4, ub[4]);
TS_ASSERT_EQUALS(0, ub[5]);
TS_ASSERT_EQUALS(-8, ub[6]);
TS_ASSERT_EQUALS(0, ub[7]);
TS_ASSERT_EQUALS(0, ub[8]);


}

};

#endif

0 comments on commit fd31765

Please sign in to comment.