From 2dbf027ec8d3fff7752367fc3b85ed7a3bc1c4ff Mon Sep 17 00:00:00 2001
From: Steven Hahn <hahnse@ornl.gov>
Date: Wed, 23 Mar 2016 13:48:41 -0400
Subject: [PATCH] Refs #15696. Move color changing code into its own class.

---
 .../VatesSimpleGui/ViewWidgets/CMakeLists.txt |   2 +
 .../MdViewerWidget.h                          |   4 +-
 .../ViewBase.h                                |  11 +-
 .../VisibleAxesColor.h                        |  54 ++++++++
 .../ViewWidgets/src/BackgroundRgbProvider.cpp |  21 ---
 .../ViewWidgets/src/ColorUpdater.cpp          |  39 ------
 .../ViewWidgets/src/MdViewerWidget.cpp        |  15 +--
 .../ViewWidgets/src/ViewBase.cpp              |  74 ++---------
 .../ViewWidgets/src/VisibleAxesColor.cpp      | 123 ++++++++++++++++++
 9 files changed, 207 insertions(+), 136 deletions(-)
 create mode 100644 Vates/VatesSimpleGui/ViewWidgets/inc/MantidVatesSimpleGuiViewWidgets/VisibleAxesColor.h
 create mode 100644 Vates/VatesSimpleGui/ViewWidgets/src/VisibleAxesColor.cpp

diff --git a/Vates/VatesSimpleGui/ViewWidgets/CMakeLists.txt b/Vates/VatesSimpleGui/ViewWidgets/CMakeLists.txt
index dd2c568c083..da5aabf73ea 100644
--- a/Vates/VatesSimpleGui/ViewWidgets/CMakeLists.txt
+++ b/Vates/VatesSimpleGui/ViewWidgets/CMakeLists.txt
@@ -18,6 +18,7 @@ set( INCLUDE_FILES
   inc/MantidVatesSimpleGuiViewWidgets/PeaksTabWidget.h
   inc/MantidVatesSimpleGuiViewWidgets/SaveScreenshotReaction.h
   inc/MantidVatesSimpleGuiViewWidgets/RebinnedSourcesManager.h
+  inc/MantidVatesSimpleGuiViewWidgets/VisibleAxesColor.h
   inc/MantidVatesSimpleGuiViewWidgets/StandardView.h
   inc/MantidVatesSimpleGuiViewWidgets/SplatterPlotView.h
   inc/MantidVatesSimpleGuiViewWidgets/ThreesliceView.h
@@ -42,6 +43,7 @@ set( SOURCE_FILES
   src/PeaksWidget.cpp
   src/SaveScreenshotReaction.cpp
   src/RebinnedSourcesManager.cpp
+  src/VisibleAxesColor.cpp
   src/StandardView.cpp
   src/SplatterPlotView.cpp
   src/ThreesliceView.cpp
diff --git a/Vates/VatesSimpleGui/ViewWidgets/inc/MantidVatesSimpleGuiViewWidgets/MdViewerWidget.h b/Vates/VatesSimpleGui/ViewWidgets/inc/MantidVatesSimpleGuiViewWidgets/MdViewerWidget.h
index 5aea7580197..7da07a35f67 100644
--- a/Vates/VatesSimpleGui/ViewWidgets/inc/MantidVatesSimpleGuiViewWidgets/MdViewerWidget.h
+++ b/Vates/VatesSimpleGui/ViewWidgets/inc/MantidVatesSimpleGuiViewWidgets/MdViewerWidget.h
@@ -92,7 +92,7 @@ public:
   void setupPluginMode() override;
 
 public slots:
-  /// Seet MantidQt::API::VatesViewerInterface
+  /// See MantidQt::API::VatesViewerInterface
   void shutdown() override;
 
 protected slots:
@@ -244,6 +244,8 @@ private:
                                         QStringList &wsNames);
   /// Set up the default color for the background of the view.
   void setColorForBackground();
+  /// Sets axes colors that are visible against the background.
+  void setVisibleAxesColors();
   /// Set the color map
   void setColorMap();
   /// Render the original workspace
diff --git a/Vates/VatesSimpleGui/ViewWidgets/inc/MantidVatesSimpleGuiViewWidgets/ViewBase.h b/Vates/VatesSimpleGui/ViewWidgets/inc/MantidVatesSimpleGuiViewWidgets/ViewBase.h
index 7e23810dbf6..761be1f80ba 100644
--- a/Vates/VatesSimpleGui/ViewWidgets/inc/MantidVatesSimpleGuiViewWidgets/ViewBase.h
+++ b/Vates/VatesSimpleGui/ViewWidgets/inc/MantidVatesSimpleGuiViewWidgets/ViewBase.h
@@ -1,14 +1,16 @@
 #ifndef VIEWBASE_H_
 #define VIEWBASE_H_
 
+#include "MantidVatesAPI/ColorScaleGuard.h"
+#include "MantidVatesSimpleGUiViewWidgets/VisibleAxesColor.h"
+#include "MantidVatesSimpleGuiQtWidgets/ModeControlWidget.h"
 #include "MantidVatesSimpleGuiViewWidgets/BackgroundRgbProvider.h"
 #include "MantidVatesSimpleGuiViewWidgets/ColorUpdater.h"
+#include "MantidVatesSimpleGuiViewWidgets/MdViewerWidget.h"
 #include "MantidVatesSimpleGuiViewWidgets/WidgetDllOption.h"
-#include "MantidVatesSimpleGuiQtWidgets/ModeControlWidget.h"
-#include "MantidVatesAPI/ColorScaleGuard.h"
+#include "vtk_jsoncpp.h"
 #include <QPointer>
 #include <QWidget>
-#include "vtk_jsoncpp.h"
 
 class pqDataRepresentation;
 class pqObjectBuilder;
@@ -123,6 +125,8 @@ public:
   virtual void setColorForBackground(bool useCurrentColorSettings);
   /// Sets the splatterplot button to the desired visibility.
   virtual void setSplatterplot(bool visibility);
+  /// Sets axes colors that contrast with the background.
+  virtual void setVisibleAxesColors(bool useCurrentColorSettings);
   /// Initializes the settings of the color scale
   virtual void initializeColorScale();
   /// Sets the standard veiw button to the desired visibility.
@@ -254,6 +258,7 @@ private:
 
   ColorUpdater colorUpdater; ///< Handle to the color updating delegator
   BackgroundRgbProvider backgroundRgbProvider; /// < Holds the manager for background color related tasks.
+  VisibleAxesColor m_visibleAxesColor;
   RebinnedSourcesManager* m_rebinnedSourcesManager;
   Json::Value m_currentColorMapModel;
 
diff --git a/Vates/VatesSimpleGui/ViewWidgets/inc/MantidVatesSimpleGuiViewWidgets/VisibleAxesColor.h b/Vates/VatesSimpleGui/ViewWidgets/inc/MantidVatesSimpleGuiViewWidgets/VisibleAxesColor.h
new file mode 100644
index 00000000000..7bc7ec44b6a
--- /dev/null
+++ b/Vates/VatesSimpleGui/ViewWidgets/inc/MantidVatesSimpleGuiViewWidgets/VisibleAxesColor.h
@@ -0,0 +1,54 @@
+#ifndef MANTID_VISIBLEAXESCOLOR_H_
+#define MANTID_VISIBLEAXESCOLOR_H_
+#include "MantidVatesSimpleGuiViewWidgets/WidgetDllOption.h"
+#include "pqRenderView.h"
+
+namespace Mantid {
+namespace Vates {
+namespace SimpleGui {
+
+/**
+ *
+
+  Copyright &copy; 2016 ISIS Rutherford Appleton Laboratory, NScD Oak Ridge
+  National Laboratory & European Spallation Source
+
+  This file is part of Mantid.
+
+  Mantid is free software; you can redistribute it and/or modify
+  it under the terms of the GNU General Public License as published by
+  the Free Software Foundation; either version 3 of the License, or
+  (at your option) any later version.
+
+  Mantid is distributed in the hope that it will be useful,
+  but WITHOUT ANY WARRANTY; without even the implied warranty of
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+  GNU General Public License for more details.
+
+  You should have received a copy of the GNU General Public License
+  along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+  File change history is stored at: <https://github.com/mantidproject/mantid>
+  Code Documentation is available at: <http://doxygen.mantidproject.org>
+*/
+
+class EXPORT_OPT_MANTIDVATES_SIMPLEGUI_VIEWWIDGETS VisibleAxesColor {
+public:
+  /**
+   * Set the Rgb values for the color of the view's orientation axes Label.
+   * @param useCurrentBackgroundColor Is this the initial loading or were the
+   * views switched?
+   * @param view The view which has its background color set.
+   */
+  void setOrientationAxesLabelColor(pqRenderView *view,
+                                    bool useCurrentBackgroundColor);
+  void setGridAxesColor(pqRenderView *view, bool /*on*/);
+  void setScalarBarColor();
+
+private:
+};
+}
+}
+}
+
+#endif // MANTID_VISIBLEAXESCOLOR_H_
diff --git a/Vates/VatesSimpleGui/ViewWidgets/src/BackgroundRgbProvider.cpp b/Vates/VatesSimpleGui/ViewWidgets/src/BackgroundRgbProvider.cpp
index 973204744e9..89d0a56b623 100644
--- a/Vates/VatesSimpleGui/ViewWidgets/src/BackgroundRgbProvider.cpp
+++ b/Vates/VatesSimpleGui/ViewWidgets/src/BackgroundRgbProvider.cpp
@@ -6,17 +6,10 @@
 #include <cmath>
 #include <vector>
 
-#include <pqActiveObjects.h>
-#include <pqDataRepresentation.h>
-#include <pqPipelineRepresentation.h>
-
 #include <pqRenderView.h>
 #include <vtkCallbackCommand.h>
 #include <vtkCommand.h>
-#include <vtkNew.h>
 #include <vtkSMDoubleVectorProperty.h>
-#include <vtkSMPropertyHelper.h>
-#include <vtkSMTransferFunctionProxy.h>
 #include <vtkSMViewProxy.h>
 #include <vtkSmartPointer.h>
 
@@ -123,20 +116,6 @@ namespace Mantid
 
         background->SetElements3(backgroundRgb[0],backgroundRgb[1],backgroundRgb[2]);
 
-        // Counting the perceptive luminance
-        // human eye favors green color...
-        double a = 1. - (0.299 * backgroundRgb[0] + 0.587 * backgroundRgb[1] +
-                         0.114 * backgroundRgb[2]);
-
-        std::array<double, 3> color;
-        if (a < 0.5)
-          color = {{0., 0., 0.}};
-        else
-          color = {{1., 1., 1.}};
-
-        vtkSMPropertyHelper(view->getProxy(), "OrientationAxesLabelColor")
-            .Set(color.data(), 3);
-
         view->resetCamera();
       }
 
diff --git a/Vates/VatesSimpleGui/ViewWidgets/src/ColorUpdater.cpp b/Vates/VatesSimpleGui/ViewWidgets/src/ColorUpdater.cpp
index d6278dae40f..9398b282d10 100644
--- a/Vates/VatesSimpleGui/ViewWidgets/src/ColorUpdater.cpp
+++ b/Vates/VatesSimpleGui/ViewWidgets/src/ColorUpdater.cpp
@@ -22,7 +22,6 @@
 #include <vtkCallbackCommand.h>
 #include <vtkSMDoubleVectorProperty.h>
 #include <vtkSMIntVectorProperty.h>
-#include <vtkSMPropertyHelper.h>
 #include <vtkSMProxy.h>
 #include <vtkSMTransferFunctionProxy.h>
 
@@ -85,16 +84,6 @@ void ColorUpdater::colorMapChange(pqPipelineRepresentation *repr,
   vtkSMTransferFunctionProxy::ApplyPreset(lutProxy, model, true);
 }
 
-void SafeSetScalarBarColor(vtkSMProxy *gridAxis, const char *pname,
-                           double *value) {
-  vtkSMProperty *prop = gridAxis->GetProperty(pname);
-  Q_ASSERT(prop);
-  vtkSMPropertyHelper helper(prop);
-  if (value) {
-    helper.Set(value, 3);
-  }
-}
-
 /**
  * React to a change of the color scale settings.
  * @param min The lower end of the color scale.
@@ -112,43 +101,15 @@ void ColorUpdater::colorScaleChange(double min, double max)
     pqServerManagerModel *smModel = pqApplicationCore::instance()->getServerManagerModel();
     const QList<pqPipelineSource *> sources =
         smModel->findItems<pqPipelineSource *>(server);
-
     // For all sources
     foreach (pqPipelineSource *source, sources) {
       const QList<pqView *> views = source->getViews();
       // For all views
       foreach (pqView *view, views) {
-        std::vector<double> backgroundRgb;
-        if (view) {
-          vtkSMProperty *prop = view->getProxy()->GetProperty("Background");
-          vtkSMPropertyHelper helper(prop);
-          backgroundRgb = helper.GetDoubleArray();
-        }
         QList<pqDataRepresentation*> reps =  source->getRepresentations(view);
 
         // For all representations
         foreach (pqDataRepresentation *rep, reps) {
-          if (backgroundRgb.size() == 3) {
-            double a =
-                1. - (0.299 * backgroundRgb[0] + 0.587 * backgroundRgb[1] +
-                      0.114 * backgroundRgb[2]);
-
-            std::array<double, 3> color;
-            if (a < 0.5)
-              color = {{0., 0., 0.}};
-            else
-              color = {{1., 1., 1.}};
-
-            vtkSMProxy *ScalarBarProxy =
-                vtkSMTransferFunctionProxy::FindScalarBarRepresentation(
-                    rep->getLookupTableProxy(), view->getProxy());
-            if (ScalarBarProxy) {
-              SafeSetScalarBarColor(ScalarBarProxy, "TitleColor", color.data());
-              ScalarBarProxy->UpdateProperty("TitleColor");
-              SafeSetScalarBarColor(ScalarBarProxy, "LabelColor", color.data());
-              ScalarBarProxy->UpdateProperty("LabelColor");
-            }
-          }
           this->updateLookupTable(rep);
         }
       }
diff --git a/Vates/VatesSimpleGui/ViewWidgets/src/MdViewerWidget.cpp b/Vates/VatesSimpleGui/ViewWidgets/src/MdViewerWidget.cpp
index 1f088ccf4ee..442d538e1b9 100644
--- a/Vates/VatesSimpleGui/ViewWidgets/src/MdViewerWidget.cpp
+++ b/Vates/VatesSimpleGui/ViewWidgets/src/MdViewerWidget.cpp
@@ -930,16 +930,6 @@ void MdViewerWidget::renderAndFinalSetup() {
   this->currentView->setColorsForView(this->ui.colorSelectionWidget);
   this->currentView->checkView(this->initialView);
   this->currentView->updateAnimationControls();
-  pqPipelineSource *source = this->currentView->origSrc;
-  // suppress unused variable;
-  (void)source;
-  pqPipelineRepresentation *repr = this->currentView->origRep;
-  // suppress unused variable;
-  (void)repr;
-  // this->ui.proxiesPanel->clear();
-  // this->ui.proxiesPanel->addProxy(source->getProxy(),"datasource",QStringList(),true);
-  // this->ui.proxiesPanel->addProxy(repr->getProxy(),"display",QStringList("CubeAxesVisibility"),true);
-  // this->ui.proxiesPanel->updateLayout();
   this->setDestroyedListener();
   this->currentView->setVisibilityListener();
   this->currentView->onAutoScale(this->ui.colorSelectionWidget);
@@ -952,6 +942,10 @@ void MdViewerWidget::setColorForBackground() {
   this->currentView->setColorForBackground(this->useCurrentColorSettings);
 }
 
+void MdViewerWidget::setVisibleAxesColors() {
+  this->currentView->setVisibleAxesColors(this->useCurrentColorSettings);
+}
+
 /**
  * This function is used during the post-apply process of particular pipeline
  * filters to check for updates to anything that relies on information from the
@@ -1029,6 +1023,7 @@ void MdViewerWidget::switchViews(ModeControlWidget::Views v) {
   // ViewBase and the specialized VSI view classes (trac ticket #11739).
   restoreViewState(this->currentView, v);
   this->currentView->setColorsForView(this->ui.colorSelectionWidget);
+  this->currentView->setVisibleAxesColors(this->useCurrentColorSettings);
 
   this->currentView->checkViewOnSwitch();
   this->updateAppState();
diff --git a/Vates/VatesSimpleGui/ViewWidgets/src/ViewBase.cpp b/Vates/VatesSimpleGui/ViewWidgets/src/ViewBase.cpp
index 5ef4dbf3457..6d9df46c295 100644
--- a/Vates/VatesSimpleGui/ViewWidgets/src/ViewBase.cpp
+++ b/Vates/VatesSimpleGui/ViewWidgets/src/ViewBase.cpp
@@ -9,9 +9,6 @@
 #include "MantidAPI/IMDEventWorkspace.h"
 #include "MantidVatesAPI/BoxInfo.h"
 #include "MantidKernel/WarningSuppressions.h"
-#if defined(__INTEL_COMPILER)
-  #pragma warning disable 1170
-#endif
 
 #include <QVTKWidget.h>
 #include <pqActiveObjects.h>
@@ -39,14 +36,9 @@
 #include <vtkSMProxy.h>
 #include <vtkSMRenderViewProxy.h>
 #include <vtkSMSourceProxy.h>
-#include <vtkSMTransferFunctionProxy.h>
 
 #include <pqMultiSliceAxisWidget.h>
 
-#if defined(__INTEL_COMPILER)
-  #pragma warning enable 1170
-#endif
-
 #include <QHBoxLayout>
 #include <QPointer>
 #include <QThread>
@@ -797,6 +789,18 @@ void ViewBase::setColorForBackground(bool useCurrentColorSettings)
   backgroundRgbProvider.observe(this->getView());
 }
 
+/**
+ * This function sets the default colors for the background and connects a
+ * tracker for changes of the background color by the user.
+ * @param useCurrentColorSettings If the view was switched or created.
+ */
+void ViewBase::setVisibleAxesColors(bool useCurrentColorSettings) {
+  m_visibleAxesColor.setOrientationAxesLabelColor(this->getView(),
+                                                  useCurrentColorSettings);
+  m_visibleAxesColor.setGridAxesColor(this->getView(), true);
+  m_visibleAxesColor.setScalarBarColor();
+  // m_visibleAxesColor.observe(this->getView());
+}
 
 /**
  * Set color scale lock
@@ -935,32 +939,6 @@ void ViewBase::removeVisibilityListener() {
   }
 }
 
-void SafeSetAxisTitle(vtkSMProxy *gridAxis, const char *pname,
-                      const char *value) {
-  vtkSMProperty *prop = gridAxis->GetProperty(pname);
-  Q_ASSERT(prop);
-
-  vtkSMPropertyHelper helper(prop);
-  QString key = QString("MTSBAutoTitle.%1").arg(pname);
-  if (value) {
-    helper.Set(value);
-    gridAxis->SetAnnotation(key.toLatin1().data(), value);
-  } else {
-    prop->ResetToDefault();
-    gridAxis->RemoveAnnotation(key.toLatin1().data());
-  }
-}
-
-void SafeSetAxisTitleProperty(vtkSMProxy *gridAxis, const char *pname,
-                              double *value) {
-  vtkSMProperty *prop = gridAxis->GetProperty(pname);
-  Q_ASSERT(prop);
-  vtkSMPropertyHelper helper(prop);
-  if (value) {
-    helper.Set(value, 3);
-  }
-}
-
 /**
  * Sets the axes grid if the user has this enabled
  */
@@ -970,34 +948,6 @@ void ViewBase::setAxesGrid(bool on) {
       vtkSMProxy *gridAxes3DActor = vtkSMPropertyHelper(renderView->getProxy(), "AxesGrid", true).GetAsProxy();
       vtkSMPropertyHelper(gridAxes3DActor, "Visibility").Set(1);
       gridAxes3DActor->UpdateProperty("Visibility");
-
-      vtkSMProperty *prop = renderView->getProxy()->GetProperty("Background");
-      vtkSMPropertyHelper helper(prop);
-      std::vector<double> backgroundRgb = helper.GetDoubleArray();
-
-      double a = 1. - (0.299 * backgroundRgb[0] + 0.587 * backgroundRgb[1] +
-                       0.114 * backgroundRgb[2]);
-
-      std::array<double, 3> color;
-      if (a < 0.5)
-        color = {{0., 0., 0.}};
-      else
-        color = {{1., 1., 1.}};
-
-      SafeSetAxisTitleProperty(gridAxes3DActor, "XTitleColor", color.data());
-      gridAxes3DActor->UpdateProperty("XTitleColor");
-      SafeSetAxisTitleProperty(gridAxes3DActor, "YTitleColor", color.data());
-      gridAxes3DActor->UpdateProperty("YTitleColor");
-      SafeSetAxisTitleProperty(gridAxes3DActor, "ZTitleColor", color.data());
-      gridAxes3DActor->UpdateProperty("ZTitleColor");
-      SafeSetAxisTitleProperty(gridAxes3DActor, "XLabelColor", color.data());
-      gridAxes3DActor->UpdateProperty("XLabelColor");
-      SafeSetAxisTitleProperty(gridAxes3DActor, "YLabelColor", color.data());
-      gridAxes3DActor->UpdateProperty("YLabelColor");
-      SafeSetAxisTitleProperty(gridAxes3DActor, "ZLabelColor", color.data());
-      gridAxes3DActor->UpdateProperty("ZLabelColor");
-      SafeSetAxisTitleProperty(gridAxes3DActor, "GridColor", color.data());
-      gridAxes3DActor->UpdateProperty("GridColor");
     }
   }
 }
diff --git a/Vates/VatesSimpleGui/ViewWidgets/src/VisibleAxesColor.cpp b/Vates/VatesSimpleGui/ViewWidgets/src/VisibleAxesColor.cpp
new file mode 100644
index 00000000000..ffb7a011161
--- /dev/null
+++ b/Vates/VatesSimpleGui/ViewWidgets/src/VisibleAxesColor.cpp
@@ -0,0 +1,123 @@
+
+//#include "MantidKernel/Logger.h"
+
+#include "MantidVatesSimpleGuiViewWidgets/VisibleAxesColor.h"
+
+#include <array>
+#include <vector>
+
+#include "pqActiveObjects.h"
+#include "pqApplicationCore.h"
+#include "pqServerManagerModel.h"
+#include "vtkSMPropertyHelper.h"
+#include "vtkSMTransferFunctionProxy.h"
+
+namespace Mantid {
+// static logger
+// Kernel::Logger g_log("VisibleAxesColor");
+
+namespace Vates {
+namespace SimpleGui {
+
+namespace {
+
+std::array<double, 3> GetContrastingColor(const std::vector<double> &color) {
+  double criteria =
+      1. - (0.299 * color[0] + 0.587 * color[1] + 0.114 * color[2]);
+
+  if (criteria < 0.5)
+    return {{0., 0., 0.}};
+  else
+    return {{1., 1., 1.}};
+}
+
+void SafeSetProperty(vtkSMProxy *gridAxis, const char *pname,
+                     const std::array<double, 3> &value) {
+  if (gridAxis) {
+    vtkSMProperty *prop = gridAxis->GetProperty(pname);
+    if (prop) {
+      vtkSMPropertyHelper helper(prop);
+      helper.Set(value.data(), 3);
+    }
+  }
+}
+}
+
+void VisibleAxesColor::setOrientationAxesLabelColor(
+    pqRenderView *view, bool /*useCurrentBackgroundColor*/) {
+  vtkSMProperty *prop = view->getProxy()->GetProperty("Background");
+  vtkSMPropertyHelper helper(prop);
+  auto backgroundColor = helper.GetDoubleArray();
+  auto color = GetContrastingColor(backgroundColor);
+  vtkSMPropertyHelper(view->getProxy(), "OrientationAxesLabelColor")
+      .Set(color.data(), 3);
+}
+
+void VisibleAxesColor::setGridAxesColor(pqRenderView *view, bool /*on*/) {
+  vtkSMProperty *prop = view->getProxy()->GetProperty("Background");
+  vtkSMPropertyHelper helper(prop);
+  auto backgroundColor = helper.GetDoubleArray();
+  auto color = GetContrastingColor(backgroundColor);
+  vtkSMProxy *gridAxes3DActor =
+      vtkSMPropertyHelper(view->getProxy(), "AxesGrid", true).GetAsProxy();
+
+  SafeSetProperty(gridAxes3DActor, "XTitleColor", color);
+  gridAxes3DActor->UpdateProperty("XTitleColor");
+  SafeSetProperty(gridAxes3DActor, "YTitleColor", color);
+  gridAxes3DActor->UpdateProperty("YTitleColor");
+  SafeSetProperty(gridAxes3DActor, "ZTitleColor", color);
+  gridAxes3DActor->UpdateProperty("ZTitleColor");
+  SafeSetProperty(gridAxes3DActor, "XLabelColor", color);
+  gridAxes3DActor->UpdateProperty("XLabelColor");
+  SafeSetProperty(gridAxes3DActor, "YLabelColor", color);
+  gridAxes3DActor->UpdateProperty("YLabelColor");
+  SafeSetProperty(gridAxes3DActor, "ZLabelColor", color);
+  gridAxes3DActor->UpdateProperty("ZLabelColor");
+  SafeSetProperty(gridAxes3DActor, "GridColor", color);
+  gridAxes3DActor->UpdateProperty("GridColor");
+}
+
+void VisibleAxesColor::setScalarBarColor() {
+  // Update for all sources and all reps
+  pqServer *server = pqActiveObjects::instance().activeServer();
+  pqServerManagerModel *smModel =
+      pqApplicationCore::instance()->getServerManagerModel();
+  const QList<pqPipelineSource *> sources =
+      smModel->findItems<pqPipelineSource *>(server);
+
+  // For all sources
+  foreach (pqPipelineSource *source, sources) {
+    const QList<pqView *> views = source->getViews();
+    // For all views
+    foreach (pqView *view, views) {
+      std::vector<double> backgroundRgb;
+      if (view) {
+        vtkSMProperty *prop = view->getProxy()->GetProperty("Background");
+        vtkSMPropertyHelper helper(prop);
+        backgroundRgb = helper.GetDoubleArray();
+      }
+      QList<pqDataRepresentation *> reps = source->getRepresentations(view);
+
+      // For all representations
+      foreach (pqDataRepresentation *rep, reps) {
+        if (backgroundRgb.size() == 3) {
+          auto color = GetContrastingColor(backgroundRgb);
+          vtkSMProxy *ScalarBarProxy =
+              vtkSMTransferFunctionProxy::FindScalarBarRepresentation(
+                  rep->getLookupTableProxy(), view->getProxy());
+
+          if (ScalarBarProxy) {
+            SafeSetProperty(ScalarBarProxy, "TitleColor", color);
+            ScalarBarProxy->UpdateProperty("TitleColor");
+            SafeSetProperty(ScalarBarProxy, "LabelColor", color);
+            ScalarBarProxy->UpdateProperty("LabelColor");
+          }
+        }
+      }
+    }
+  }
+}
+
+} // SimpleGui
+} // Vates
+} // Mantid
-- 
GitLab