Salome HOME
Change color for construction/body/group.
authornds <natalia.donis@opencascade.com>
Tue, 10 Mar 2015 13:30:47 +0000 (16:30 +0300)
committernds <natalia.donis@opencascade.com>
Tue, 10 Mar 2015 13:30:47 +0000 (16:30 +0300)
src/Model/Model_ResultBody.cpp
src/Model/Model_ResultBody.h
src/Model/Model_ResultConstruction.cpp
src/Model/Model_ResultConstruction.h
src/Model/Model_ResultGroup.cpp
src/Model/Model_ResultGroup.h
src/ModuleBase/ModuleBase_Preferences.cpp
src/XGUI/XGUI_Displayer.cpp
src/XGUI/XGUI_Workshop.cpp

index 7b7e3c3be3a8eab1722a97f0a049137e33274161..784eff153c53703fa6c1e4cb4cbca58b5e721d51 100644 (file)
@@ -37,8 +37,6 @@
 //#include <TDF_Tool.hxx>
 //#define DEB_IMPORT 1
 
-#define RESULT_BODY_COLOR "#E0A01B"
-
 Model_ResultBody::Model_ResultBody()
 {
   setIsConcealed(false);
@@ -51,7 +49,7 @@ void Model_ResultBody::initAttributes()
   aData->addAttribute(COLOR_ID(), ModelAPI_AttributeIntArray::type());
   AttributeIntArrayPtr aColorAttr = aData->intArray(COLOR_ID());
   std::vector<int> aRGB;
-  aRGB = Config_PropManager::color("Visualization", "result_body_color", RESULT_BODY_COLOR);
+  aRGB = Config_PropManager::color("Visualization", "result_body_color", DEFAULT_COLOR());
   aColorAttr->setSize(3);
   aColorAttr->setValue(0, aRGB[0]);
   aColorAttr->setValue(1, aRGB[1]);
index 5b849c620b50b64b8fa1b3bad68c0eb68052d0a6..e7fdcb5ca5ab53b310ef4a88ef7158655c9cbd12 100644 (file)
@@ -29,6 +29,13 @@ class Model_ResultBody : public ModelAPI_ResultBody
   /// label; index in vector corresponds to the label tag
   std::vector<TNaming_Builder*> myBuilders;
 public:
+  /// default color for a result body
+  inline static const std::string& DEFAULT_COLOR()
+  {
+    static const std::string RESULT_BODY_COLOR("#E0A01B");
+    return RESULT_BODY_COLOR;
+  }
+
   /// Request for initialization of data model of the result: adding all attributes
   virtual void initAttributes();
 
index aaade70ff23d3364b2fb930b5c1bc61081d5eac2..97f2b4fcd3808b381aad63b2d71c63cb8b06531c 100644 (file)
@@ -6,6 +6,23 @@
 
 #include <Model_ResultConstruction.h>
 
+#include <ModelAPI_AttributeIntArray.h>
+#include <Config_PropManager.h>
+
+void Model_ResultConstruction::initAttributes()
+{
+  // append the color attribute
+  DataPtr aData = data();
+  aData->addAttribute(COLOR_ID(), ModelAPI_AttributeIntArray::type());
+  AttributeIntArrayPtr aColorAttr = aData->intArray(COLOR_ID());
+  std::vector<int> aRGB;
+  aRGB = Config_PropManager::color("Visualization", "result_construction_color", DEFAULT_COLOR());
+  aColorAttr->setSize(3);
+  aColorAttr->setValue(0, aRGB[0]);
+  aColorAttr->setValue(1, aRGB[1]);
+  aColorAttr->setValue(2, aRGB[2]);
+}
+
 void Model_ResultConstruction::setShape(std::shared_ptr<GeomAPI_Shape> theShape)
 {
   myShape = theShape;
index a66aeeb5a73eccebf1883dca7f04715774d5174b..2fb81219d9b9989271a16aa03e03c3a78b6157d0 100644 (file)
@@ -23,6 +23,16 @@ class Model_ResultConstruction : public ModelAPI_ResultConstruction
   std::shared_ptr<GeomAPI_Shape> myShape;  ///< shape of this result created "on the fly"
   bool myIsInHistory;
  public:
+  /// default color for a result construction
+  inline static const std::string& DEFAULT_COLOR()
+  {
+    static const std::string RESULT_CONSTRUCTION_COLOR("#000000");
+    return RESULT_CONSTRUCTION_COLOR;
+  }
+
+  /// Request for initialization of data model of the result: adding all attributes
+  virtual void initAttributes();
+
   /// By default object is displayed in the object browser.
   MODEL_EXPORT virtual bool isInHistory()
   {
index ebcdb9b437ff4915e0bfe66b11856f4efb0b16f3..a0a5922cd056249e7e3fbec64597e0d29d63dd08 100644 (file)
@@ -6,14 +6,32 @@
 
 #include <Model_ResultGroup.h>
 #include <ModelAPI_AttributeSelectionList.h>
+#include <ModelAPI_AttributeIntArray.h>
+
 #include <GeomAlgoAPI_CompoundBuilder.h>
 
+#include <Config_PropManager.h>
+
 Model_ResultGroup::Model_ResultGroup(std::shared_ptr<ModelAPI_Data> theOwnerData)
 {
   setIsConcealed(false);
   myOwnerData = theOwnerData;
 }
 
+void Model_ResultGroup::initAttributes()
+{
+  // append the color attribute
+  DataPtr aData = data();
+  aData->addAttribute(COLOR_ID(), ModelAPI_AttributeIntArray::type());
+  AttributeIntArrayPtr aColorAttr = aData->intArray(COLOR_ID());
+  std::vector<int> aRGB;
+  aRGB = Config_PropManager::color("Visualization", "result_group_color", DEFAULT_COLOR());
+  aColorAttr->setSize(3);
+  aColorAttr->setValue(0, aRGB[0]);
+  aColorAttr->setValue(1, aRGB[1]);
+  aColorAttr->setValue(2, aRGB[2]);
+}
+
 std::shared_ptr<GeomAPI_Shape> Model_ResultGroup::shape()
 {
   std::shared_ptr<GeomAPI_Shape> aResult;
index 33b4351c9ac3e59bd7527528d6b8d5a0d6490272..33c0e17a74ba47245741359e4e8c9d50653826c7 100644 (file)
@@ -20,6 +20,15 @@ class Model_ResultGroup : public ModelAPI_ResultGroup
 {
   std::shared_ptr<ModelAPI_Data> myOwnerData;  ///< data of owner of this result
 public:
+  /// default color for a result body
+  inline static const std::string& DEFAULT_COLOR()
+  {
+    static const std::string RESULT_GROUP_COLOR("#E0A01B");
+    return RESULT_GROUP_COLOR;
+  }
+  /// Request for initialization of data model of the result: adding all attributes
+  virtual void initAttributes();
+
   /// Returns the compound of selected entities
   MODEL_EXPORT virtual std::shared_ptr<GeomAPI_Shape> shape();
 
index 616e659e06c6a9c69bc0fbdb8ff39ea3470c54b0..4d4d1c78dbd20097353ddb1738fcb9a81142768e 100644 (file)
@@ -7,6 +7,10 @@
 #include "ModuleBase_Preferences.h"
 //#include "ModuleBase_Constants.h"
 
+#include <Model_ResultBody.h>
+#include <Model_ResultGroup.h>
+#include <Model_ResultConstruction.h>
+
 #include <Config_PropManager.h>
 
 #include <SUIT_ResourceMgr.h>
@@ -256,6 +260,13 @@ void ModuleBase_PreferencesDlg::createViewerPage(int thePageId)
   myPreferences->setItemProperty("texture_stretch_enabled", true, bgId);
   myPreferences->setItemProperty("custom_enabled", false, bgId);
   myPreferences->setItemProperty("image_formats", aImgFiles, bgId);
+
+  Config_PropManager::registerProp("Visualization", "result_body_color", "Body color",
+                                   Config_Prop::Color, Model_ResultBody::DEFAULT_COLOR());
+  Config_PropManager::registerProp("Visualization", "result_group_color", "Group color",
+                                   Config_Prop::Color, Model_ResultGroup::DEFAULT_COLOR());
+  Config_PropManager::registerProp("Visualization", "result_construction_color", "Construction color",
+                                   Config_Prop::Color, Model_ResultConstruction::DEFAULT_COLOR());
 }
 
 void ModuleBase_PreferencesDlg::createMenuPage(int thePageId)
index 0db30a1453b772c1efbbd1ac8371d15ed615b0d0..9d6884b929cf0ce4749daeb8a52ad28ffaf22674 100644 (file)
@@ -772,13 +772,11 @@ void XGUI_Displayer::customizeObject(ObjectPtr theObject)
       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);
-    }
+  // 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);
   }
 }
index dacaa1512da880587ec7efdc42d68434920aad24..45f12d0d571c8b32b0b65b9b20ab790d4bd4c0f7 100644 (file)
@@ -39,6 +39,7 @@
 #include <ModelAPI_ResultGroup.h>
 #include <ModelAPI_ResultConstruction.h>
 #include <ModelAPI_ResultBody.h>
+#include <ModelAPI_AttributeIntArray.h>
 
 //#include <PartSetPlugin_Part.h>
 
 #include <QMenu>
 #include <QToolButton>
 #include <QAction>
+#include <QDialog>
+#include <QDialogButtonBox>
+#include <QHBoxLayout>
+#include <QtxColorButton.h>
 
 #ifdef _DEBUG
 #include <QDebug>
@@ -1404,11 +1409,6 @@ bool XGUI_Workshop::canChangeColor() const
 }
 
 //**************************************************************
-#include <QDialog>
-#include <QDialogButtonBox>
-#include <QHBoxLayout>
-#include <QtxColorButton.h>
-#include <ModelAPI_AttributeIntArray.h>
 void XGUI_Workshop::changeColor(const QObjectPtrList& theObjects)
 {
   // 1. find the initial value of the color
@@ -1456,11 +1456,12 @@ void XGUI_Workshop::changeColor(const QObjectPtrList& theObjects)
     return;
 
   // 3. abort the previous operation and start a new one
-  if(!isActiveOperationAborted())
-    return;
   SessionPtr aMgr = ModelAPI_Session::get();
-  QString aDescription = contextMenuMgr()->action("DELETE_CMD")->text();
-  aMgr->startOperation(aDescription.toStdString());
+  bool aWasOperation = aMgr->isOperation(); // keep this value
+  if (!aWasOperation) {
+    QString aDescription = contextMenuMgr()->action("DELETE_CMD")->text();
+    aMgr->startOperation(aDescription.toStdString());
+  }
 
   // 4. set the value to all results
   static Events_ID EVENT_DISP = Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY);
@@ -1479,7 +1480,8 @@ void XGUI_Workshop::changeColor(const QObjectPtrList& theObjects)
       }
     }
   }
-  aMgr->finishOperation();
+  if (!aWasOperation)
+    aMgr->finishOperation();
   updateCommandStatus();
 }