Salome HOME
Issue #578 color for hidden object: the color from AIS object should not be used...
authornds <natalia.donis@opencascade.com>
Fri, 29 May 2015 09:23:39 +0000 (12:23 +0300)
committernds <natalia.donis@opencascade.com>
Fri, 29 May 2015 11:33:14 +0000 (14:33 +0300)
src/XGUI/XGUI_CustomPrs.cpp
src/XGUI/XGUI_CustomPrs.h
src/XGUI/XGUI_Workshop.cpp

index 171baa8465bb73e8b61291b7743a9eb0a7558db5..10125e574301d1c8d8cb228a97bb071bd20721f2 100644 (file)
@@ -30,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
@@ -49,14 +49,19 @@ 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()) {
index 97bc89133bdf4efd3f53b0373ce4fc874c7bad10..a1e636a5c15368e2a37ad91280baef85ed43134c 100644 (file)
@@ -24,6 +24,8 @@ public:
   /// Modifies the given presentation in the custom way.
   virtual bool customisePresentation(ResultPtr theResult, AISObjectPtr thePrs,
                                      std::shared_ptr<GeomAPI_ICustomPrs> theCustomPrs);
+
+  static void getResultColor(ResultPtr theResult, std::vector<int>& theColor);
 };
 
 #endif
index 40d623a8b6898da6ceb13acaba3dff8d8dc42839..e56e696f5d2b79aef5f5c3937986be1bc3716b9d 100644 (file)
@@ -18,6 +18,7 @@
 #include "XGUI_ModuleConnector.h"
 #include <XGUI_QtEvents.h>
 #include <XGUI_HistoryMenu.h>
+#include <XGUI_CustomPrs.h>
 
 #include <AppElements_Workbench.h>
 #include <AppElements_Viewer.h>
@@ -1511,20 +1512,25 @@ void XGUI_Workshop::changeColor(const QObjectPtrList& theObjects)
           ObjectPtr aObject = aPartDoc->object(ModelAPI_ResultBody::group(), 0);
           ResultBodyPtr aBody = std::dynamic_pointer_cast<ModelAPI_ResultBody>(aObject);
           if (aBody.get()) {
-            std::string aSection, aName, aDefault;
-            aBody->colorConfigInfo(aSection, aName, aDefault);
-            if (!aSection.empty() && !aName.empty()) {
-              aColor = Config_PropManager::color(aSection, aName, aDefault);
-            }
+            XGUI_CustomPrs::getResultColor(aBody, aColor);
           }
         }
       }
     }
     else {
-      AISObjectPtr anAISObj = myDisplayer->getAISObject(anObject);
-      if (anAISObj.get()) {
-        aColor.resize(3);
-        anAISObj->getColor(aColor[0], aColor[1], aColor[2]);
+      ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObject);
+      if (aResult.get())
+        XGUI_CustomPrs::getResultColor(aResult, aColor);
+      else {
+        // TODO: remove the obtaining a color from the AIS object
+        // this does not happen never because:
+        // 1. The color can be changed only on results
+        // 2. The result can be not visualized in the viewer(e.g. Origin Construction)
+        AISObjectPtr anAISObj = myDisplayer->getAISObject(anObject);
+        if (anAISObj.get()) {
+          aColor.resize(3);
+          anAISObj->getColor(aColor[0], aColor[1], aColor[2]);
+        }
       }
     }
     if (!aColor.empty())