Salome HOME
Issue #1437: provide update of parameters table part on editing of any parameter
[modules/shaper.git] / src / XGUI / XGUI_CustomPrs.cpp
index 171baa8465bb73e8b61291b7743a9eb0a7558db5..7948325d795e1442ceeff7b5521220b8d90e4605 100644 (file)
@@ -5,6 +5,10 @@
 // Author:      Natalia ERMOLAEVA
 
 #include <XGUI_CustomPrs.h>
+#include <XGUI_Workshop.h>
+#include <XGUI_Displayer.h>
+
+#include <ModuleBase_IModule.h>
 
 #include <ModelAPI_AttributeIntArray.h>
 #include <ModelAPI_Session.h>
@@ -30,18 +34,19 @@ void getColor(ResultPtr theResult, std::vector<int>& theColor)
   }
 }
 
-void getDefaultColor(ResultPtr theResult, AISObjectPtr thePrs, std::vector<int>& theColor)
+void XGUI_CustomPrs::getDefaultColor(ObjectPtr theObject, const bool isEmptyColorValid,
+                                     std::vector<int>& theColor)
 {
   theColor.clear();
   // get default color from the preferences manager for the given result
   if (theColor.empty()) {
     std::string aSection, aName, aDefault;
-    theResult->colorConfigInfo(aSection, aName, aDefault);
+    theObject->colorConfigInfo(aSection, aName, aDefault);
     if (!aSection.empty() && !aName.empty()) {
       theColor = Config_PropManager::color(aSection, aName, aDefault);
     }
   }
-  if (theColor.empty()) {
+  if (!isEmptyColorValid && theColor.empty()) {
     // all AIS objects, where the color is not set, are in black.
     // The color should be defined in XML or set in the attribute
     theColor = Config_PropManager::color("Visualization", "object_default_color", "#000000");
@@ -49,22 +54,41 @@ void getDefaultColor(ResultPtr theResult, AISObjectPtr thePrs, std::vector<int>&
   }
 }
 
+XGUI_CustomPrs::XGUI_CustomPrs(XGUI_Workshop* theWorkshop)
+: myWorkshop(theWorkshop)
+{
+}
+
+void XGUI_CustomPrs::getResultColor(ResultPtr theResult, std::vector<int>& theColor)
+{
+  getColor(theResult, theColor);
+  if (theColor.empty())
+    getDefaultColor(theResult, false, 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);
+  bool aCustomized = false;
+  if (theResult.get()) {
+    std::vector<int> 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();
+    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();
+    }
+    aCustomized = !aColor.empty() && thePrs->setColor(aColor[0], aColor[1], aColor[2]);
+  }
+  else {
+   if (!aCustomized) {
+      ModuleBase_IModule* aModule = myWorkshop->module();
+      aCustomized = aModule->customisePresentation(theResult, thePrs, theCustomPrs);
+    }
   }
-  return !aColor.empty() && thePrs->setColor(aColor[0], aColor[1], aColor[2]);
+  return aCustomized;
 }