Salome HOME
Implementation of color as integer array attribute
[modules/shaper.git] / src / XGUI / XGUI_Workshop.cpp
index 70b6c615654dee1e67bea0d7c5dc1f746c546d46..a1a8727548a718536b40b6bd905349039ef206ea 100644 (file)
@@ -1407,24 +1407,23 @@ bool XGUI_Workshop::canChangeColor() const
 #include <QDialog>
 #include <QHBoxLayout>
 #include <QtxColorButton.h>
-#include <ModelAPI_AttributeColor.h>
+#include <ModelAPI_AttributeIntArray.h>
 void XGUI_Workshop::changeColor(const QObjectPtrList& theObjects)
 {
   // 1. find the initial value of the color
-  AttributeColorPtr aColorAttr;
+  AttributeIntArrayPtr aColorAttr;
   foreach(ObjectPtr anObj, theObjects) {
     ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObj);
     if (aResult.get() != NULL) {
-      AttributePtr anAttr = aResult->data()->attribute(ModelAPI_Result::COLOR_ID());
-      if (anAttr.get() != NULL)
-        aColorAttr = std::dynamic_pointer_cast<ModelAPI_AttributeColor>(anAttr);
+      aColorAttr = aResult->data()->intArray(ModelAPI_Result::COLOR_ID());
     }
   }
   // there is no object with the color attribute
-  if (aColorAttr.get() == NULL)
+  if (aColorAttr.get() == NULL || aColorAttr->size() == 0)
     return;
-  int aRed, aGreen, aBlue;
-  aColorAttr->values(aRed, aGreen, aBlue);
+  int aRed = aColorAttr->value(0);
+  int aGreen = aColorAttr->value(1);
+  int aBlue = aColorAttr->value(2);
 
   // 2. show the dialog to change the value
   QDialog aDlg;
@@ -1457,11 +1456,14 @@ void XGUI_Workshop::changeColor(const QObjectPtrList& theObjects)
   foreach(ObjectPtr anObj, theObjects) {
     ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObj);
     if (aResult.get() != NULL) {
-      AttributePtr anAttr = aResult->data()->attribute(ModelAPI_Result::COLOR_ID());
-      if (anAttr.get() != NULL) {
-        aColorAttr = std::dynamic_pointer_cast<ModelAPI_AttributeColor>(anAttr);
-        if (aColorAttr.get() != NULL)
-          aColorAttr->setValues(aRedResult, aGreenResult, aBlueResult);
+      aColorAttr = aResult->data()->intArray(ModelAPI_Result::COLOR_ID());
+      if (aColorAttr.get() != NULL) {
+        if (!aColorAttr->size()) {
+          aColorAttr->setSize(3);
+        }
+        aColorAttr->setValue(0, aRedResult);
+        aColorAttr->setValue(1, aGreenResult);
+        aColorAttr->setValue(2, aBlueResult);
       }
     }
   }