diff --git a/Vates/VatesSimpleGui/ViewWidgets/CMakeLists.txt b/Vates/VatesSimpleGui/ViewWidgets/CMakeLists.txt index a55ce3e0652e87a18e42ee25c601d86f8514de47..8fb1f90b4ed54ca69a1117f3033875be63492cc0 100644 --- a/Vates/VatesSimpleGui/ViewWidgets/CMakeLists.txt +++ b/Vates/VatesSimpleGui/ViewWidgets/CMakeLists.txt @@ -154,6 +154,7 @@ ${PYTHON_LIBRARIES} MantidWidgets ${POCO_LIBRARIES} ${Boost_LIBRARIES} +${JSONCPP_LIBRARIES} ) if (OSX_VERSION VERSION_GREATER 10.8) @@ -181,7 +182,8 @@ if( CXXTEST_FOUND AND GMOCK_FOUND AND GTEST_FOUND ) ${POCO_LIBRARIES} ${Boost_LIBRARIES} ${GMOCK_LIBRARIES} - ${GTEST_LIBRARIES}) + ${GTEST_LIBRARIES} + ${JSONCPP_LIBRARIES}) add_dependencies( AllTests VatesSimpleGuiViewWidgetsTest ) # Add to the 'UnitTests' group in VS diff --git a/Vates/VatesSimpleGui/ViewWidgets/inc/MantidVatesSimpleGuiViewWidgets/ColorSelectionWidget.h b/Vates/VatesSimpleGui/ViewWidgets/inc/MantidVatesSimpleGuiViewWidgets/ColorSelectionWidget.h index c0675ec3ce89a2159824afdd49267c7213ae8896..2192beaa29fe1802183ebfb0ed4ae4d3a09a0647 100644 --- a/Vates/VatesSimpleGui/ViewWidgets/inc/MantidVatesSimpleGuiViewWidgets/ColorSelectionWidget.h +++ b/Vates/VatesSimpleGui/ViewWidgets/inc/MantidVatesSimpleGuiViewWidgets/ColorSelectionWidget.h @@ -6,13 +6,12 @@ #include "MantidVatesSimpleGuiViewWidgets/WidgetDllOption.h" #include "MantidVatesAPI/ColorScaleGuard.h" #include "MantidQtAPI/MdConstants.h" +#include "MantidQtAPI/MdSettings.h" #include "boost/scoped_ptr.hpp" #include <QWidget> +#include "vtkNew.h" +#include "vtkSMTransferFunctionPresets.h" -class pqColorMapModel; -class pqColorPresetManager; -class pqColorPresetModel; -class vtkPVXMLParser; class QDoubleValidator; namespace Mantid @@ -103,7 +102,7 @@ signals: * Signal to pass on information about a change to the color map. * @param model the color map to send */ - void colorMapChanged(const pqColorMapModel *model); + void colorMapChanged(const Json::Value &model); /** * Signal to pass on information that the color scale has changed. * @@ -129,10 +128,9 @@ protected slots: private: /// Add color maps from XML files. - void addColorMapsFromFile(std::string fileName, vtkPVXMLParser *parser, - pqColorPresetModel *model); + // void addColorMapsFromFile(std::string fileName, const char *model); /// Add color maps from XML fragments. - void addColorMapsFromXML(vtkPVXMLParser *parser, pqColorPresetModel *model); + // void addColorMapsFromXML(const char *model); /// Set up various color maps. void loadBuiltinColorPresets(); /// Set status of the color selection editor widgets. @@ -150,8 +148,10 @@ private: double m_maxHistoric; MantidQt::API::MdConstants m_mdConstants; + vtkNew<vtkSMTransferFunctionPresets> + m_presets; ///< Dialog for choosing color presets + MantidQt::API::MdSettings m_mdSettings; - // pqColorPresetManager *m_presets; ///< Dialog for choosing color presets Ui::ColorSelectionWidgetClass m_ui; ///< The mode control widget's UI form bool m_ignoreColorChangeCallbacks; ///< Effectively blocks/disables callbacks diff --git a/Vates/VatesSimpleGui/ViewWidgets/inc/MantidVatesSimpleGuiViewWidgets/ColorUpdater.h b/Vates/VatesSimpleGui/ViewWidgets/inc/MantidVatesSimpleGuiViewWidgets/ColorUpdater.h index 02e973bcc5ca13374adc2be7a11511af709849c2..c5411795758c72b9d23c7877702f7498164ce4af 100644 --- a/Vates/VatesSimpleGui/ViewWidgets/inc/MantidVatesSimpleGuiViewWidgets/ColorUpdater.h +++ b/Vates/VatesSimpleGui/ViewWidgets/inc/MantidVatesSimpleGuiViewWidgets/ColorUpdater.h @@ -11,6 +11,10 @@ class pqPipelineRepresentation; class vtkObject; +namespace Json { +class Value; +} + namespace Mantid { namespace Vates @@ -65,7 +69,7 @@ public: * @param repr the representation to change the color map on * @param model the color map to use */ - void colorMapChange(pqPipelineRepresentation *repr, const char *model); + void colorMapChange(pqPipelineRepresentation *repr, const Json::Value &model); /** * Set the data color scale range to the requested bounds. * @param min the minimum bound for the color scale diff --git a/Vates/VatesSimpleGui/ViewWidgets/inc/MantidVatesSimpleGuiViewWidgets/ViewBase.h b/Vates/VatesSimpleGui/ViewWidgets/inc/MantidVatesSimpleGuiViewWidgets/ViewBase.h index 36e83e68d475dcbb8de6ad394bc0b0f5ed57f513..6194b07018948164b0788d78271febabb1d242ff 100644 --- a/Vates/VatesSimpleGui/ViewWidgets/inc/MantidVatesSimpleGuiViewWidgets/ViewBase.h +++ b/Vates/VatesSimpleGui/ViewWidgets/inc/MantidVatesSimpleGuiViewWidgets/ViewBase.h @@ -151,7 +151,7 @@ public slots: /// Set the color scale back to the original bounds. void onAutoScale(ColorSelectionWidget* colorSelectionWidget); /// Set the requested color map on the data. - void onColorMapChange(const char *model); + void onColorMapChange(const Json::Value &model); /// Set the data color scale range to the requested bounds. void onColorScaleChange(double min, double max); /// Set the view to use a LOD threshold. diff --git a/Vates/VatesSimpleGui/ViewWidgets/src/ColorSelectionWidget.cpp b/Vates/VatesSimpleGui/ViewWidgets/src/ColorSelectionWidget.cpp index 8a0dbef565fc01361e2373d2ead5811db90a2f2d..5f30434f7db987c0ec2f71012926519c35640f13 100644 --- a/Vates/VatesSimpleGui/ViewWidgets/src/ColorSelectionWidget.cpp +++ b/Vates/VatesSimpleGui/ViewWidgets/src/ColorSelectionWidget.cpp @@ -6,20 +6,13 @@ #include "MantidQtAPI/MdConstants.h" #include "MantidVatesAPI/ColorScaleGuard.h" -// Have to deal with ParaView warnings and Intel compiler the hard way. -#if defined(__INTEL_COMPILER) - #pragma warning disable 1170 -#endif - +#include "vtk_jsoncpp.h" #include "pqPresetDialog.h" +#include "vtkSMTransferFunctionPresets.h" #include <vtkPVXMLElement.h> #include <vtkPVXMLParser.h> -#if defined(__INTEL_COMPILER) - #pragma warning enable 1170 -#endif - #include <QDir> #include <QDoubleValidator> #include <QFile> @@ -45,9 +38,6 @@ ColorSelectionWidget::ColorSelectionWidget(QWidget *parent): QWidget(parent), this->m_ui.autoColorScaleCheckBox->setChecked(true); this->setEditorStatus(false); - // this->m_presets = new pqColorPresetManager(this); - // this->m_presets->restoreSettings(); - this->loadBuiltinColorPresets(); m_minValidator = new QDoubleValidator(this); @@ -95,28 +85,14 @@ void ColorSelectionWidget::setEditorStatus(bool status) */ void ColorSelectionWidget::loadBuiltinColorPresets() { - // pqColorPresetModel *presetModel = this->m_presets->getModel(); - - // Associate the colormap value with the index a continuous index - - // create xml parser - vtkPVXMLParser *xmlParser = vtkPVXMLParser::New(); - - // 1. Get builtinw color maps (Reading fragment requires: InitializeParser, ParseChunk, CleanupParser) - // const char *xml = pqComponentsGetColorMapsXML(); - // xmlParser->InitializeParser(); - // xmlParser->ParseChunk(xml, static_cast<unsigned>(strlen(xml))); - // xmlParser->CleanupParser(); - // this->addColorMapsFromXML(xmlParser, presetModel); - - // 2. Add color maps from Slice Viewer, IDL and Matplotlib - // this->addColorMapsFromFile("All_slice_viewer_cmaps_for_vsi.xml", xmlParser, - // presetModel); - // this->addColorMapsFromFile("All_idl_cmaps.xml", xmlParser, presetModel); - // this->addColorMapsFromFile("All_mpl_cmaps.xml", xmlParser, presetModel); - - // cleanup parser - xmlParser->Delete(); + const std::string filenames[3] = {"All_slice_viewer_cmaps_for_vsi.json", + "All_idl_cmaps.json", "All_mpl_cmaps.json"}; + const std::string colorMapDirectory = + Kernel::ConfigService::Instance().getString("colormaps.directory"); + for (const auto &baseName : filenames) { + std::string colorMap = colorMapDirectory + baseName; + this->m_presets->ImportPresets(colorMap.c_str()); + } } /** @@ -125,15 +101,37 @@ void ColorSelectionWidget::loadBuiltinColorPresets() */ void ColorSelectionWidget::loadColorMap(bool viewSwitched) { - int defaultColorMapIndex = this->colorMapManager->getDefaultColorMapIndex(viewSwitched); - - // const pqColorMapModel *colorMap = - // this->m_presets->getModel()->getColorMap(defaultColorMapIndex); - - // if (colorMap) - //{ - // emit this->colorMapChanged(colorMap); - //} + /*int defaultColorMapIndex = + this->colorMapManager->getDefaultColorMapIndex(viewSwitched); + + const pqColorMapModel *colorMap = + this->m_presets->getModel()->getColorMap(defaultColorMapIndex); + */ + QString defaultColorMap; + + // If the view has switched or the VSI is loaded use the last color map + // index + if (viewSwitched) { + defaultColorMap = m_mdSettings.getLastSessionColorMap(); + } else { + // Check if the user wants a general MD color map + if (m_mdSettings.getUsageGeneralMdColorMap()) { + // The name is sufficient for the VSI to find the color map + defaultColorMap = m_mdSettings.getGeneralMdColorMapName(); + } else { + // Check if the user wants to use the last session + if (m_mdSettings.getUsageLastSession()) { + defaultColorMap = m_mdSettings.getLastSessionColorMap(); + } else { + defaultColorMap = m_mdSettings.getUserSettingColorMap(); + } + } + } + const Json::Value &colorMap = m_presets->GetFirstPresetWithName( + defaultColorMap.toStdString().c_str()); + if (!colorMap.empty()) { + emit this->colorMapChanged(colorMap); + } } /** @@ -143,23 +141,23 @@ void ColorSelectionWidget::loadBuiltinColorPresets() * @param parser : The XML parser with the color maps. * @param model : The color preset model to add the maps too. */ -void ColorSelectionWidget::addColorMapsFromFile(std::string fileName, - vtkPVXMLParser *parser, - pqColorPresetModel *model) -{ - std::string colorMapDir = Kernel::ConfigService::Instance().getString("colormaps.directory"); - if (!colorMapDir.empty()) + /*void ColorSelectionWidget::addColorMapsFromFile(std::string fileName, + const char *model) { - QFileInfo cmaps(QDir(QString::fromStdString(colorMapDir)), - QString::fromStdString(fileName)); - if (cmaps.exists()) + std::string colorMapDir = + Kernel::ConfigService::Instance().getString("colormaps.directory"); + if (!colorMapDir.empty()) { - parser->SetFileName(cmaps.absoluteFilePath().toStdString().c_str()); - parser->Parse(); - this->addColorMapsFromXML(parser, model); + QFileInfo cmaps(QDir(QString::fromStdString(colorMapDir)), + QString::fromStdString(fileName)); + if (cmaps.exists()) + { + parser->SetFileName(cmaps.absoluteFilePath().toStdString().c_str()); + parser->Parse(); + this->addColorMapsFromXML(parser, model); + } } - } -} + }*/ /** * This function takes a XML parser and loads and adds color maps to the color @@ -167,35 +165,34 @@ void ColorSelectionWidget::addColorMapsFromFile(std::string fileName, * @param parser : The XML parser with the color maps. * @param model : The color preset model to add the maps too. */ -void ColorSelectionWidget::addColorMapsFromXML(vtkPVXMLParser *parser, - pqColorPresetModel *model) -{ - // parse each color map element - vtkPVXMLElement *root = parser->GetRootElement(); - for(unsigned int i = 0; i < root->GetNumberOfNestedElements(); i++) + /*void ColorSelectionWidget::addColorMapsFromXML(const char *model) { - vtkPVXMLElement *colorMapElement = root->GetNestedElement(i); - if(std::string("ColorMap") != colorMapElement->GetName()) + // parse each color map element + vtkPVXMLElement *root = parser->GetRootElement(); + for(unsigned int i = 0; i < root->GetNumberOfNestedElements(); i++) { - continue; + vtkPVXMLElement *colorMapElement = root->GetNestedElement(i); + if(std::string("ColorMap") != colorMapElement->GetName()) + { + continue; + } + + // load color map from its XML + pqColorMapModel colorMap = + pqColorPresetManager::createColorMapFromXML(colorMapElement); + QString name = colorMapElement->GetAttribute("name"); + + // Only add the color map if the name does not exist yet + if (!this->colorMapManager->isRecordedColorMap(name.toStdString())) + { + // add color map to the model + model->addBuiltinColorMap(colorMap, name); + + // add color map to the color map manager + this->colorMapManager->readInColorMap(name.toStdString()); + } } - - // load color map from its XML - // pqColorMapModel colorMap = - // pqColorPresetManager::createColorMapFromXML(colorMapElement); - // QString name = colorMapElement->GetAttribute("name"); - - // Only add the color map if the name does not exist yet - // if (!this->colorMapManager->isRecordedColorMap(name.toStdString())) - //{ - // add color map to the model - // model->addBuiltinColorMap(colorMap, name); - - // add color map to the color map manager - // this->colorMapManager->readInColorMap(name.toStdString()); - //} - } -} + }*/ /** * Changes the status of the autoScaling checkbox. This is in @@ -274,7 +271,7 @@ void ColorSelectionWidget::loadPreset() Mantid::VATES::ColorScaleLockGuard guard(m_colorScaleLock); // this->m_presets->setUsingCloseButton(false); // if (this->m_presets->exec() == QDialog::Accepted) - //{ + // { // Get the color map from the selection. // QItemSelectionModel *selection = this->m_presets->getSelectionModel(); // QModelIndex index = selection->currentIndex(); @@ -282,10 +279,10 @@ void ColorSelectionWidget::loadPreset() // this->m_presets->getModel()->getColorMap(index.row()); // if (colorMap) - //{ - // Persist the color map change - // this->colorMapManager->setNewActiveColorMap(index.row()); - // emit this->colorMapChanged(colorMap); + // { + // Persist the color map change + // this->colorMapManager->setNewActiveColorMap(index.row()); + // emit this->colorMapChanged(colorMap); //} //} } diff --git a/Vates/VatesSimpleGui/ViewWidgets/src/ColorUpdater.cpp b/Vates/VatesSimpleGui/ViewWidgets/src/ColorUpdater.cpp index 5b8597bafdb4351fd05b8807bb23582f0aa86af1..80c0c2a623061971257f195908a2c3682616ffe9 100644 --- a/Vates/VatesSimpleGui/ViewWidgets/src/ColorUpdater.cpp +++ b/Vates/VatesSimpleGui/ViewWidgets/src/ColorUpdater.cpp @@ -81,7 +81,7 @@ VsiColorScale ColorUpdater::autoScale() } void ColorUpdater::colorMapChange(pqPipelineRepresentation *repr, - const char *model) { + const Json::Value &model) { pqScalarsToColors *lut = repr->getLookupTable(); if (NULL == lut) { @@ -90,7 +90,7 @@ void ColorUpdater::colorMapChange(pqPipelineRepresentation *repr, } // Need the scalar bounds to calculate the color point settings - QPair<double, double> bounds = lut->getScalarRange(); + // QPair<double, double> bounds = lut->getScalarRange(); vtkSMProxy *lutProxy = lut->getProxy(); @@ -98,15 +98,15 @@ void ColorUpdater::colorMapChange(pqPipelineRepresentation *repr, pqSMAdaptor::setElementProperty(lutProxy->GetProperty("ColorSpace"), QVariant()); // Set the NaN color - QList<QVariant> values; - QColor nanColor; + // QList<QVariant> values; + // QColor nanColor; // model->getNanColor(nanColor); - values << nanColor.redF() << nanColor.greenF() << nanColor.blueF(); - pqSMAdaptor::setMultipleElementProperty(lutProxy->GetProperty("NanColor"), - values); + // values << nanColor.redF() << nanColor.greenF() << nanColor.blueF(); + // pqSMAdaptor::setMultipleElementProperty(lutProxy->GetProperty("NanColor"), + // values); // Set the RGB points - QList<QVariant> rgbPoints; + // QList<QVariant> rgbPoints; /*for(int i = 0; i < model->getNumberOfPoints(); i++) { QColor rgbPoint; @@ -116,8 +116,9 @@ void ColorUpdater::colorMapChange(pqPipelineRepresentation *repr, rgbPoints << fraction.getDoubleValue() * bounds.second << rgbPoint.redF() << rgbPoint.greenF() << rgbPoint.blueF(); }*/ - pqSMAdaptor::setMultipleElementProperty(lutProxy->GetProperty("RGBPoints"), - rgbPoints); + // pqSMAdaptor::setMultipleElementProperty(lutProxy->GetProperty("RGBPoints"), + // rgbPoints); + vtkSMTransferFunctionProxy::ApplyPreset(lutProxy, model); lutProxy->UpdateVTKObjects(); } diff --git a/Vates/VatesSimpleGui/ViewWidgets/src/MdViewerWidget.cpp b/Vates/VatesSimpleGui/ViewWidgets/src/MdViewerWidget.cpp index dbf6fd817431f0591b7576ca4777a10e31aa9b97..a123ecb9f7cea8860b638e0da896fe967bee99a8 100644 --- a/Vates/VatesSimpleGui/ViewWidgets/src/MdViewerWidget.cpp +++ b/Vates/VatesSimpleGui/ViewWidgets/src/MdViewerWidget.cpp @@ -1334,9 +1334,9 @@ void MdViewerWidget::connectColorSelectionWidget() { // Set the color selection widget signal -> view slot connection QObject::connect(this->ui.colorSelectionWidget, - SIGNAL(colorMapChanged(const pqColorMapModel *)), + SIGNAL(colorMapChanged(const Json::Value &)), this->currentView, - SLOT(onColorMapChange(const pqColorMapModel *))); + SLOT(onColorMapChange(const Json::Value &))); QObject::connect(this->ui.colorSelectionWidget, SIGNAL(colorScaleChanged(double, double)), this->currentView, diff --git a/Vates/VatesSimpleGui/ViewWidgets/src/ViewBase.cpp b/Vates/VatesSimpleGui/ViewWidgets/src/ViewBase.cpp index d6f0f605ec92eea7c141cc4c5ba9b448f022a256..792c887cd3cf327e60de63bc7d3e597ad14e81e0 100644 --- a/Vates/VatesSimpleGui/ViewWidgets/src/ViewBase.cpp +++ b/Vates/VatesSimpleGui/ViewWidgets/src/ViewBase.cpp @@ -260,7 +260,7 @@ void ViewBase::releasePyGIL() { * This function sets the requested color map on the data. * @param model the color map to use */ -void ViewBase::onColorMapChange(const char *model) { +void ViewBase::onColorMapChange(const Json::Value &model) { pqPipelineRepresentation *rep = this->getRep(); if (NULL == rep) {