Salome HOME
Merge branch 'python_parametric_api' of https://git.salome-platform.org/git/modules...
[modules/shaper.git] / src / XGUI / XGUI_CustomPrs.cpp
index c074a841e4ab3af76f0b33dee705234510d38f74..10125e574301d1c8d8cb228a97bb071bd20721f2 100644 (file)
@@ -7,11 +7,13 @@
 #include <XGUI_CustomPrs.h>
 
 #include <ModelAPI_AttributeIntArray.h>
+#include <ModelAPI_Session.h>
 #include <Config_PropManager.h>
 
 #include <Events_Error.h>
 
 #include <vector>
+#include <QColor>
 
 
 void getColor(ResultPtr theResult, std::vector<int>& theColor)
@@ -28,7 +30,7 @@ void getColor(ResultPtr theResult, std::vector<int>& theColor)
   }
 }
 
-void getDefaultColor(ResultPtr theResult, AISObjectPtr thePrs, std::vector<int>& theColor)
+void getDefaultColor(ResultPtr theResult, std::vector<int>& theColor)
 {
   theColor.clear();
   // get default color from the preferences manager for the given result
@@ -47,14 +49,27 @@ void getDefaultColor(ResultPtr theResult, AISObjectPtr thePrs, std::vector<int>&
   }
 }
 
+void XGUI_CustomPrs::getResultColor(ResultPtr theResult, std::vector<int>& theColor)
+{
+  getColor(theResult, theColor);
+  if (theColor.empty())
+    getDefaultColor(theResult, theColor);
+}
+
 bool XGUI_CustomPrs::customisePresentation(ResultPtr theResult, AISObjectPtr thePrs,
                                            std::shared_ptr<GeomAPI_ICustomPrs> theCustomPrs)
 {
   std::vector<int> aColor;
 
-  getColor(theResult, aColor);
-  if (aColor.empty())
-    getDefaultColor(theResult, thePrs, aColor);
+  getResultColor(theResult, aColor);
 
+  SessionPtr aMgr = ModelAPI_Session::get();
+  if (aMgr->activeDocument() != theResult->document()) {
+    QColor aQColor(aColor[0], aColor[1], aColor[2]);
+    QColor aNewColor = QColor::fromHsvF(aQColor.hueF(), aQColor.saturationF()/3., aQColor.valueF());
+    aColor[0] = aNewColor.red();
+    aColor[1] = aNewColor.green();
+    aColor[2] = aNewColor.blue();
+  }
   return !aColor.empty() && thePrs->setColor(aColor[0], aColor[1], aColor[2]);
 }