]> SALOME platform Git repositories - modules/shaper.git/blobdiff - src/XGUI/XGUI_Displayer.cpp
Salome HOME
Implementation of color as integer array attribute
[modules/shaper.git] / src / XGUI / XGUI_Displayer.cpp
index 401d1d3cafeb4997285ac69078ff9fbc24e625bc..0db30a1453b772c1efbbd1ac8371d15ed615b0d0 100644 (file)
@@ -16,6 +16,7 @@
 #include <ModelAPI_Data.h>
 #include <ModelAPI_Object.h>
 #include <ModelAPI_Tools.h>
+#include <ModelAPI_AttributeIntArray.h>
 
 #include <ModuleBase_ResultPrs.h>
 
@@ -157,13 +158,8 @@ void XGUI_Displayer::display(ObjectPtr theObject, AISObjectPtr theAIS,
     aContext->Display(anAISIO, false);
 
     aContext->SetDisplayMode(anAISIO, isShading? Shading : Wireframe, false);
-    // Customization of presentation
-    FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
-    if (aFeature.get() != NULL) {
-      GeomCustomPrsPtr aCustPrs = std::dynamic_pointer_cast<GeomAPI_ICustomPrs>(aFeature);
-      if (aCustPrs.get() != NULL)
-        aCustPrs->customisePresentation(theAIS);
-    }
+
+    customizeObject(theObject);
     if (aCanBeShaded) {
       openLocalContext();
       activateObjects(myActiveSelectionModes);
@@ -222,7 +218,11 @@ void XGUI_Displayer::redisplay(ObjectPtr theObject, bool isUpdateViewer)
     // Check that the visualized shape is the same and the redisplay is not necessary
     // Redisplay of AIS object leads to this object selection compute and the selection 
     // in the browser is lost
-    // become
+
+    // this check is not necessary anymore because the selection store/restore is realized
+    // before and after the values modification.
+    // Moreother, this check avoids customize and redisplay presentation if the presentable
+    // parameter is changed.
     ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
     if (aResult.get() != NULL) {
       Handle(AIS_Shape) aShapePrs = Handle(AIS_Shape)::DownCast(aAISIO);
@@ -238,6 +238,9 @@ void XGUI_Displayer::redisplay(ObjectPtr theObject, bool isUpdateViewer)
         }
       }
     }
+    // Customization of presentation
+    customizeObject(theObject);
+
     aContext->Redisplay(aAISIO, false);
     if (isUpdateViewer)
       updateViewer();
@@ -754,3 +757,28 @@ void XGUI_Displayer::activate(const Handle(AIS_InteractiveObject)& theIO,
     }
   }
 }
+
+void XGUI_Displayer::customizeObject(ObjectPtr theObject)
+{
+  AISObjectPtr anAISObj = getAISObject(theObject);
+  // correct the result's color it it has the attribute
+  ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
+  if (aResult.get() != NULL && aResult->data()->attribute(ModelAPI_Result::COLOR_ID()).get() != NULL) {
+    AttributeIntArrayPtr aColorAttr = aResult->data()->intArray(ModelAPI_Result::COLOR_ID());
+    if (aColorAttr.get() && aColorAttr->size()) {
+      int aRed = aColorAttr->value(0);
+      int aGreen = aColorAttr->value(1);
+      int aBlue = aColorAttr->value(2);
+      anAISObj->setColor(aRed, aGreen, aBlue);
+    }
+  }
+  else {
+    // Customization of presentation
+    FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
+    if (aFeature.get() != NULL) {
+      GeomCustomPrsPtr aCustPrs = std::dynamic_pointer_cast<GeomAPI_ICustomPrs>(aFeature);
+      if (aCustPrs.get() != NULL)
+        aCustPrs->customisePresentation(anAISObj);
+    }
+  }
+}