Skip to content
Snippets Groups Projects
Commit 1d76022b authored by Anton Piccardo-Selg's avatar Anton Piccardo-Selg
Browse files

Refs #10656 Store bgnd and cmap settings

parent 0af140a2
No related branches found
No related tags found
No related merge requests found
......@@ -33,6 +33,11 @@ set( SOURCE_FILES
src/ViewBase.cpp
)
set( TEST_FILES
test/unitTests/BackgroundRgbProviderTest.h
test/unitTests/ColorMapManagerTest.h
)
# These are the headers to be preprocessed using
# Qt's moc preprocessor.
qt4_wrap_cpp( MOC_SOURCES
......@@ -109,6 +114,22 @@ MantidQtSliceViewer
MantidQtFactory
)
# Create test file projects
if( CXXTEST_FOUND AND GMOCK_FOUND AND GTEST_FOUND )
include_directories ( SYSTEM ${CXXTEST_INCLUDE_DIR} ${GMOCK_INCLUDE_DIR} ${GTEST_INCLUDE_DIR} )
include_directories( inc ../../../Framework/TestHelpers/inc ../../../Framework/DataHandling/inc ../../../Framework/DataObjects/inc)
set ( TESTHELPER_SRCS ../../../Framework/TestHelpers/src/ComponentCreationHelper.cpp
../../../Framework/TestHelpers/src/WorkspaceCreationHelper.cpp
../../../Framework/TestHelpers/src/MDEventsTestHelper.cpp
../../../Framework/TestHelpers/src/StartFrameworkManager.cpp )
cxxtest_add_test( VatesSimpleGuiViewWidgetsTest ${TEST_FILES} )
target_link_libraries( VatesSimpleGuiViewWidgetsTest VatesSimpleGuiViewWidgets DataHandling Kernel DataObjects ${GMOCK_LIBRARIES} ${GTEST_LIBRARIES} )
add_dependencies( AllTests VatesSimpleGuiViewWidgetsTest )
# Add to the 'UnitTests' group in VS
set_property ( TARGET VatesSimpleGuiViewWidgetsTest PROPERTY FOLDER "UnitTests" )
endif()
configure_file ( ${CMAKE_CURRENT_SOURCE_DIR}/inc/MantidVatesSimpleGuiViewWidgets/LibHelper.h.in
${CMAKE_CURRENT_SOURCE_DIR}/inc/MantidVatesSimpleGuiViewWidgets/LibHelper.h )
......
......@@ -59,8 +59,6 @@ namespace Mantid
*/
std::vector<double> getRbgFromPropertiesFile();
/**
* Extract the rgb vector from the numeric user setting
* @param background A vector with three color settings
......
......@@ -45,6 +45,12 @@ namespace Mantid
virtual ~ColorMapManager();
/**
* Get default color map
* @returns index The index of the default color map in the list of color maps.
*/
int getDefaultColorMapIndex();
/**
* Read in and store the available color maps
* @param xml The path to the colormap.
......@@ -65,9 +71,16 @@ namespace Mantid
*/
bool isRecordedColorMap(std::string colorMap);
/**
* Record the new active color map when the user selected a new one.
* @param index The index of the color map in the color map list.
*/
void setNewActiveColorMap(int index);
private:
int indexCounter;
std::map<std::string, int> colorMapInfo;
std::map<std::string, int> nameToIndex;
std::map<int, std::string> indexToName;
};
}
}
......
#include "MantidVatesSimpleGuiViewWidgets/ColorMapManager.h"
#include "MantidKernel/Logger.h"
#include "MantidKernel/ConfigService.h"
#include <QSettings>
#include <map>
#include <string>
......@@ -9,48 +10,81 @@ namespace Mantid
{
namespace SimpleGui
{
namespace
ColorMapManager::ColorMapManager() : indexCounter(0)
{
/// static logger
Mantid::Kernel::Logger g_log("ColorMapManager");
}
// Check if this is the first time a color map will be loaded
QSettings settings;
ColorMapManager::ColorMapManager() :indexCounter(0)
{
settings.beginGroup("Mantid/Vsi");
settings.setValue("intitialcolormap", "Cool to Warm");
settings.endGroup();
}
ColorMapManager::~ColorMapManager()
{
}
int ColorMapManager::getDefaultColorMapIndex()
{
// Read from QSettings
QSettings settings;
settings.beginGroup("Mantid/Vsi");
std::string defaultColorMap;
if (settings.value("firststartup", true).asBool())
{
defaultColorMap = settings.value("intitialcolormap", QString("")).toString().toStdString();
settings.setValue("firststartup", false);
}
else
{
defaultColorMap = settings.value("colormap", QString("")).toString().toStdString();
}
settings.endGroup();
// Set the default colormap
int defaultColorMapIndex = 0;
if (!defaultColorMap.empty())
{
defaultColorMapIndex = this->getColorMapIndex(defaultColorMap);
}
return defaultColorMapIndex;
}
void ColorMapManager::readInColorMap(std::string name)
{
// Add the name to the colormap map and increment the index counter
if (!name.empty())
{
this->colorMapInfo.insert(std::pair<std::string, int>(name, this->indexCounter));
this->nameToIndex.insert(std::pair<std::string, int>(name, this->indexCounter));
this->indexToName.insert(std::pair<int,std::string>(this->indexCounter, name));
this->indexCounter = this->indexCounter + 1;
}
}
int ColorMapManager::getColorMapIndex(std::string colorMap)
{
if (this->colorMapInfo.count(colorMap) == 1 )
if (this->nameToIndex.count(colorMap) == 1 )
{
return colorMapInfo[colorMap];
return nameToIndex[colorMap];
}
else
{
// requested color map was not found
g_log.warning() <<"Warning: Requested color map could not be found. Setting default color map. \n";
return 0;
}
}
bool ColorMapManager::isRecordedColorMap(std::string colorMap)
{
if (this->colorMapInfo.count(colorMap) > 0)
if (this->nameToIndex.count(colorMap) > 0)
{
return true;
}
......@@ -59,6 +93,19 @@ namespace Mantid
return false;
}
}
void ColorMapManager::setNewActiveColorMap(int index)
{
// Persist the new value of the color map in the QSettings object.
if (indexToName.count(index) > 0)
{
// Persist default color map
QSettings settings;
settings.beginGroup("Mantid/Vsi");
settings.setValue("colormap", QString::fromStdString(indexToName[index]));
settings.endGroup();
}
}
}
}
}
\ No newline at end of file
#include "MantidVatesSimpleGuiViewWidgets/ColorSelectionWidget.h"
#include "MantidKernel/ConfigService.h"
#include "MantidVatesSimpleGuiViewWidgets/ColorMapManager.h"
......@@ -104,15 +103,7 @@ void ColorSelectionWidget::loadBuiltinColorPresets()
*/
void ColorSelectionWidget::loadDefaultColorMap()
{
// Check in the Mantid.users.properties file if a default color map was specified
std::string defaultColorMap = Kernel::ConfigService::Instance().getString("vsi.colormap");
int defaultColorMapIndex = 0;
if (!defaultColorMap.empty())
{
defaultColorMapIndex = this->colorMapManager->getColorMapIndex(defaultColorMap);
}
int defaultColorMapIndex = this->colorMapManager->getDefaultColorMapIndex();
const pqColorMapModel *colorMap = this->presets->getModel()->getColorMap(defaultColorMapIndex);
......@@ -215,8 +206,11 @@ void ColorSelectionWidget::loadPreset()
QItemSelectionModel *selection = this->presets->getSelectionModel();
QModelIndex index = selection->currentIndex();
const pqColorMapModel *colorMap = this->presets->getModel()->getColorMap(index.row());
if (colorMap)
{
// Persist the color map change
this->colorMapManager->setNewActiveColorMap(index.row());
emit this->colorMapChanged(colorMap);
}
}
......
......@@ -166,7 +166,6 @@ void MdViewerWidget::internalSetup(bool pMode)
this->rotPointDialog = NULL;
this->lodThreshold = 5.0;
this->viewSwitched = false;
this->startingUp = true;
}
/**
......@@ -717,17 +716,10 @@ void MdViewerWidget::renderAndFinalSetup()
{
this->setDefaultColorForBackground();
this->currentView->render();
this->ui.colorSelectionWidget->loadDefaultColorMap();
this->currentView->setColorsForView();
this->currentView->checkView(this->initialView);
this->currentView->updateAnimationControls();
// Only load the default color map for the first time
// that a representation is created.
if (this->startingUp)
{
this->ui.colorSelectionWidget->loadDefaultColorMap();
this->startingUp = false;
}
}
/**
......@@ -741,7 +733,7 @@ void MdViewerWidget::setDefaultColorForBackground()
vtkSMDoubleVectorProperty* background = vtkSMDoubleVectorProperty::SafeDownCast(this->currentView->getView()->getViewProxy()->GetProperty("Background"));
background->SetElements3(backgroundRgb[0],backgroundRgb[1],backgroundRgb[2]);
this->currentView->getView()->resetCamera();
}
......
#ifndef BACKGROUND_RGB_PROVIDER_TEST_H_
#define BACKGROUND_RGB_PROVIDER_TEST_H_
#include "MantidVatesSimpleGuiViewWidgets/BackgroundRgbProvider.h"
#include <cxxtest/TestSuite.h>
using namespace Mantid::Vates::SimpleGui;
class BackgroundRgbProviderTest : public CxxTest::TestSuite
{
public:
// As config service is not setup, the backgroundRgbProvider should return the default value
void testGetTheDefaultValue()
{
// Arrange
BackgroundRgbProvider backgroundRgbProvider;
// Act
std::vector<double> colors = backgroundRgbProvider.getRgb();
// Assert
TSM_ASSERT("Should have three default entries for r, g and b", colors.size()==3);
TSM_ASSERT("Should have the default value of r", colors[0] == 84.0/255.0);
TSM_ASSERT("Should have the default value of g", colors[1] == 89.0/255.0);
TSM_ASSERT("Should have the default value of b", colors[2] == 109.0/255.0);
}
};
#endif
\ No newline at end of file
#ifndef BACKGROUND_RGB_PROVIDER_TEST_H_
#define BACKGROUND_RGB_PROVIDER_TEST_H_
#include "MantidVatesSimpleGuiViewWidgets/ColorMapManager.h"
#include <cxxtest/TestSuite.h>
using namespace Mantid::Vates::SimpleGui;
class ColorMapManagerTest : public CxxTest::TestSuite
{
public:
void testWriteAndReadIndexForValidElements()
{
// Arrange
ColorMapManager manager;
// Act
manager.readInColorMap("test1");
manager.readInColorMap("test2");
manager.readInColorMap("test3");
// Assert
TSM_ASSERT("Should have an index of 0 as it was entered first.", manager.getColorMapIndex("test1") == 0);
TSM_ASSERT("Should have an index of 1 as it was entered second.", manager.getColorMapIndex("test2") == 1);
TSM_ASSERT("Should have an index of 2 as it was entered third.", manager.getColorMapIndex("test3") == 2);
}
void testGetsFirstIndexForInvalidColorMapRequest()
{
// Arrange
ColorMapManager manager;
// Act
manager.readInColorMap("test1");
manager.readInColorMap("test2");
manager.readInColorMap("test3");
// Assert
TSM_ASSERT("Should have an index of 0 if the color map does not exist", manager.getColorMapIndex("wrongMap") == 0);
}
void testGetsFirstIndexForManagerWithoutRecordings()
{
// Arrange
ColorMapManager manager;
// Act
// Assert
TSM_ASSERT("Should have an index of 0 if there are no color maps recorded.", manager.getColorMapIndex("wrongMap") == 0);
}
void testDetectsValidAndInvalidEntries()
{
//Arrange
ColorMapManager manager;
// Act
manager.readInColorMap("test1");
// Assert
TSM_ASSERT("Should find a recorded color map", manager.isRecordedColorMap("test1"));
TSM_ASSERT("Should not find an unrecorded color map", !manager.isRecordedColorMap("wrongMap"));
}
};
#endif
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment