Salome HOME
Issue #705 Color of part change color of body
authornds <natalia.donis@opencascade.com>
Mon, 6 Jul 2015 12:21:36 +0000 (15:21 +0300)
committernds <natalia.donis@opencascade.com>
Mon, 6 Jul 2015 12:21:36 +0000 (15:21 +0300)
src/Model/Model_ResultPart.cpp
src/Model/Model_ResultPart.h
src/XGUI/XGUI_Workshop.cpp

index a376cc88f1af8f486ef95d7013ed7478e158792f..87552e36225d42503329285da811d413344b4977 100644 (file)
@@ -10,6 +10,7 @@
 #include <ModelAPI_Session.h>
 #include <ModelAPI_Feature.h>
 #include <ModelAPI_ResultBody.h>
+#include <ModelAPI_AttributeIntArray.h>
 #include <Model_Document.h>
 
 #include <TNaming_Tool.hxx>
 #include <TopoDS_Compound.hxx>
 #include <BRep_Builder.hxx>
 
+void Model_ResultPart::initAttributes()
+{
+  // append the color attribute. It is empty, the attribute will be filled by a request
+  DataPtr aData = data();
+  aData->addAttribute(COLOR_ID(), ModelAPI_AttributeIntArray::typeId());
+}
+
 std::shared_ptr<ModelAPI_Document> Model_ResultPart::partDoc()
 {
   return data()->document("PartDocument")->value();
index 11f813388a82a59c3ff375be1a80dc105b936888..06c6efdad373c38337b19766a1576804edbfd3fa 100644 (file)
@@ -22,6 +22,8 @@ class Model_ResultPart : public ModelAPI_ResultPart
 {
   TopoDS_Shape myShape; ///< shape of this part created from bodies (updated only of Part deactivation)
  public:
+  /// Request for initialization of data model of the result: adding all attributes
+  virtual void initAttributes();
   /// Returns the part-document of this result
   MODEL_EXPORT virtual std::shared_ptr<ModelAPI_Document> partDoc();
   /// Part has no stored feature: this method returns NULL
index 25d0551e65bc29cdc22686ec4f5a2a21b5f3440b..8bbf783e39c08ed9978adba884b1a71347e0eb1d 100644 (file)
@@ -1240,38 +1240,18 @@ void XGUI_Workshop::changeColor(const QObjectPtrList& theObjects)
   // The objects are iterated until a first valid color is found 
   std::vector<int> aColor;
   foreach(ObjectPtr anObject, theObjects) {
-    if (anObject->groupName() == ModelAPI_ResultPart::group()) {
-      ResultPartPtr aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(anObject);
-      DocumentPtr aPartDoc = aPart->partDoc();
-      // the document should be checked on null, because in opened document if the part
-      // has not been activated yet, the part document is empty
-      if (!aPartDoc.get()) {
-        emit errorOccurred(QString::fromLatin1("Color can not be changed on a part with an empty document"));
-      }
-      else {
-        if (aPartDoc->size(ModelAPI_ResultBody::group()) > 0) {
-          ObjectPtr aObject = aPartDoc->object(ModelAPI_ResultBody::group(), 0);
-          ResultBodyPtr aBody = std::dynamic_pointer_cast<ModelAPI_ResultBody>(aObject);
-          if (aBody.get()) {
-            XGUI_CustomPrs::getResultColor(aBody, aColor);
-          }
-        }
-      }
-    }
+    ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObject);
+    if (aResult.get())
+      XGUI_CustomPrs::getResultColor(aResult, aColor);
     else {
-      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]);
-        }
+      // 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())
@@ -1302,24 +1282,8 @@ void XGUI_Workshop::changeColor(const QObjectPtrList& theObjects)
   foreach(ObjectPtr anObj, theObjects) {
     ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObj);
     if (aResult.get() != NULL) {
-      if (aResult->groupName() == ModelAPI_ResultPart::group()) {
-        ResultPartPtr aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aResult);
-        DocumentPtr aPartDoc = aPart->partDoc();
-        // the document should be checked on null, because in opened document if the part
-        // has not been activated yet, the part document is empty
-        if (aPartDoc.get()) {
-          for (int i = 0; i < aPartDoc->size(ModelAPI_ResultBody::group()); i++) {
-            ObjectPtr aObject = aPartDoc->object(ModelAPI_ResultBody::group(), i);
-            ResultBodyPtr aBody = std::dynamic_pointer_cast<ModelAPI_ResultBody>(aObject);
-            std::vector<int> aColorResult = aDlg->getColor();
-            setColor(aBody, aColorResult);
-          }
-        }
-      }
-      else {
-        std::vector<int> aColorResult = aDlg->getColor();
-        setColor(aResult, aColorResult);
-      }
+      std::vector<int> aColorResult = aDlg->getColor();
+      setColor(aResult, aColorResult);
     }
   }
   if (!aWasOperation)