Salome HOME
Change color for construction/body/group.
authornds <natalia.donis@opencascade.com>
Wed, 11 Mar 2015 14:42:26 +0000 (17:42 +0300)
committernds <natalia.donis@opencascade.com>
Wed, 11 Mar 2015 14:42:26 +0000 (17:42 +0300)
The default custom presentation to customize the AIS object color if there is no a customizer realized with the feature of the object.

29 files changed:
src/ConstructionPlugin/ConstructionPlugin_Axis.cpp
src/ConstructionPlugin/ConstructionPlugin_Axis.h
src/ConstructionPlugin/ConstructionPlugin_Plane.cpp
src/ConstructionPlugin/ConstructionPlugin_Plane.h
src/ConstructionPlugin/ConstructionPlugin_Plugin.cpp
src/ConstructionPlugin/ConstructionPlugin_Point.cpp
src/ConstructionPlugin/ConstructionPlugin_Point.h
src/ExchangePlugin/ExchangePlugin_ImportFeature.cpp
src/ExchangePlugin/ExchangePlugin_ImportFeature.h
src/ExchangePlugin/ExchangePlugin_Plugin.cpp
src/GeomAPI/GeomAPI_AISObject.cpp
src/GeomAPI/GeomAPI_AISObject.h
src/GeomAPI/GeomAPI_ICustomPrs.h
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/ModelAPI/ModelAPI_Result.h
src/ModuleBase/ModuleBase_Preferences.cpp
src/SketchPlugin/SketchPlugin_SketchEntity.cpp
src/SketchPlugin/SketchPlugin_SketchEntity.h
src/XGUI/CMakeLists.txt
src/XGUI/XGUI_CustomPrs.cpp [new file with mode: 0644]
src/XGUI/XGUI_CustomPrs.h [new file with mode: 0644]
src/XGUI/XGUI_Displayer.cpp
src/XGUI/XGUI_Displayer.h
src/XGUI/XGUI_Workshop.cpp

index 258ed85e94e9404945072a0ce17ab5d145127d76..7678b51a4d222bdc62d35860900183c6f9eb5f35 100644 (file)
@@ -55,11 +55,13 @@ void ConstructionPlugin_Axis::execute()
   }
 }
 
-void ConstructionPlugin_Axis::customisePresentation(AISObjectPtr thePrs)
+bool ConstructionPlugin_Axis::customisePresentation(ResultPtr theResult, AISObjectPtr thePrs,
+                                                    std::shared_ptr<GeomAPI_ICustomPrs> theDefaultPrs)
 {
-  std::vector<int> aRGB = Config_PropManager::color("Visualization", "construction_axis_color",
-                                                    ConstructionPlugin_Axis::DEFAULT_COLOR());
-  thePrs->setColor(aRGB[0], aRGB[1], aRGB[2]);
-  thePrs->setLineStyle(3);
-  thePrs->redisplay();
+  bool isCustomized = theDefaultPrs.get() != NULL &&
+                      theDefaultPrs->customisePresentation(theResult, thePrs, theDefaultPrs);
+
+  isCustomized = thePrs->setLineStyle(3);
+
+  return isCustomized;
 }
index 473d3e3524e18f86435d88e3e9df969656fb4a29..b92e0842c4ed9b595adc017156c5f10a1e458dfd 100644 (file)
@@ -9,6 +9,7 @@
 
 #include "ConstructionPlugin.h"
 #include <ModelAPI_Feature.h>
+#include <ModelAPI_Result.h>
 #include <GeomAPI_ICustomPrs.h>
 
 /**\class ConstructionPlugin_Axis
@@ -56,12 +57,6 @@ class ConstructionPlugin_Axis : public ModelAPI_Feature, public GeomAPI_ICustomP
     static const std::string CYLINDRICAL_FACE_ATTR("cylindricalFace");
     return CYLINDRICAL_FACE_ATTR;
   }
-  /// default color for an axis
-  inline static const std::string& DEFAULT_COLOR()
-  {
-    static const std::string CONSTRUCTION_AXIS_COLOR("#000000");
-    return CONSTRUCTION_AXIS_COLOR;
-  }
 
   inline static const double MINIMAL_LENGTH() { return 1.e-5; }
 
@@ -78,7 +73,8 @@ class ConstructionPlugin_Axis : public ModelAPI_Feature, public GeomAPI_ICustomP
   ConstructionPlugin_Axis();
 
   /// Customize presentation of the feature
-  virtual void customisePresentation(AISObjectPtr thePrs);
+  virtual bool customisePresentation(ResultPtr theResult, AISObjectPtr thePrs,
+                                     std::shared_ptr<GeomAPI_ICustomPrs> theDefaultPrs);
 };
 
 
index d0ecc4d7ee88012e5f239c892402f118851862a1..501d9664e7762c01e75548bf4a8c275445a181b7 100644 (file)
@@ -11,6 +11,7 @@
 #include <ModelAPI_AttributeSelection.h>
 #include <ModelAPI_AttributeDouble.h>
 #include <ModelAPI_ResultConstruction.h>
+#include <ModelAPI_AttributeIntArray.h>
 #include <GeomAlgoAPI_FaceBuilder.h>
 
 #include <GeomAPI_Pnt2d.h>
@@ -73,10 +74,28 @@ void ConstructionPlugin_Plane::execute()
   }
 }
 
-void ConstructionPlugin_Plane::customisePresentation(AISObjectPtr thePrs)
+bool ConstructionPlugin_Plane::customisePresentation(ResultPtr theResult, AISObjectPtr thePrs,
+                                                     std::shared_ptr<GeomAPI_ICustomPrs> theDefaultPrs)
 {
-  std::vector<int> aRGB = Config_PropManager::color("Visualization", "construction_plane_color",
-                                                    ConstructionPlugin_Plane::DEFAULT_COLOR());
-  thePrs->setColor(aRGB[0], aRGB[1], aRGB[2]);
-  thePrs->setTransparensy(0.6);
+  std::vector<int> aColor;
+  // get color from the attribute of the result
+  if (theResult.get() != NULL && theResult->data()->attribute(ModelAPI_Result::COLOR_ID()).get() != NULL) {
+    AttributeIntArrayPtr aColorAttr = theResult->data()->intArray(ModelAPI_Result::COLOR_ID());
+    if (aColorAttr.get() && aColorAttr->size()) {
+      aColor.push_back(aColorAttr->value(0));
+      aColor.push_back(aColorAttr->value(1));
+      aColor.push_back(aColorAttr->value(2));
+    }
+  }
+  if (aColor.empty())
+    aColor = Config_PropManager::color("Visualization", "construction_plane_color",
+                                       ConstructionPlugin_Plane::DEFAULT_COLOR());
+
+  bool isCustomized = false;
+  if (aColor.size() == 3)
+    isCustomized = thePrs->setColor(aColor[0], aColor[1], aColor[2]);
+
+  isCustomized = thePrs->setTransparensy(0.6) || isCustomized;
+
+  return isCustomized;
 }
index f57ff1eb10099565f71d87486d4da7465c0ccb85..2ff71979a32780c69cfdeda3ebb3848488322955 100644 (file)
@@ -9,6 +9,7 @@
 
 #include "ConstructionPlugin.h"
 #include <ModelAPI_Feature.h>
+#include <ModelAPI_Result.h>
 #include <GeomAPI_ICustomPrs.h>
 
 
@@ -91,7 +92,8 @@ class ConstructionPlugin_Plane : public ModelAPI_Feature, public GeomAPI_ICustom
   ConstructionPlugin_Plane();
 
   /// Customize presentation of the feature
-  virtual void customisePresentation(AISObjectPtr thePrs);
+  virtual bool customisePresentation(ResultPtr theResult, AISObjectPtr thePrs,
+                                     std::shared_ptr<GeomAPI_ICustomPrs> theDefaultPrs);
 };
 
 #endif
index 4731cc4c8c766fea1a5e00d6398838618711dd49..c60c022b4311028afd31a9c801159ed0d1158822 100644 (file)
@@ -21,10 +21,6 @@ ConstructionPlugin_Plugin::ConstructionPlugin_Plugin()
   ModelAPI_Session::get()->registerPlugin(this);
 
   // register construction properties
-  Config_PropManager::registerProp("Visualization", "construction_point_color", "Construction point color",
-                                   Config_Prop::Color, ConstructionPlugin_Point::DEFAULT_COLOR());
-  Config_PropManager::registerProp("Visualization", "construction_axis_color", "Construction axis color",
-                                   Config_Prop::Color, ConstructionPlugin_Axis::DEFAULT_COLOR());
   Config_PropManager::registerProp("Visualization", "construction_plane_color", "Construction plane color",
                                    Config_Prop::Color, ConstructionPlugin_Plane::DEFAULT_COLOR());
 }
index 231e54fb2cddaa70bbcfbeb0b7d9f0adfe269791..671a38cd7a1daf72a4d802470e5f3e60d2f02bdd 100644 (file)
@@ -45,11 +45,3 @@ void ConstructionPlugin_Point::execute()
   aConstr->setShape(GeomAlgoAPI_PointBuilder::point(aPnt));
   setResult(aConstr);
 }
-
-void ConstructionPlugin_Point::customisePresentation(AISObjectPtr thePrs)
-{
-  std::vector<int> aRGB = Config_PropManager::color("Visualization", "construction_point_color",
-                                                    ConstructionPlugin_Point::DEFAULT_COLOR());
-  thePrs->setColor(aRGB[0], aRGB[1], aRGB[2]);
-  thePrs->redisplay();
-}
index f4bf39a1186fdc61b3ee35e42f3665a8b7a609fa..84cb35cb35085d1b7461b84cf3da54ca5ea7f07f 100644 (file)
@@ -9,13 +9,13 @@
 
 #include "ConstructionPlugin.h"
 #include <ModelAPI_Feature.h>
-#include <GeomAPI_ICustomPrs.h>
+#include <ModelAPI_Result.h>
 
 /**\class ConstructionPlugin_Point
  * \ingroup Plugins
  * \brief Feature for creation of the new part in PartSet.
  */
-class ConstructionPlugin_Point : public ModelAPI_Feature, public GeomAPI_ICustomPrs
+class ConstructionPlugin_Point : public ModelAPI_Feature
 {
  public:
   /// Returns the kind of a feature
@@ -27,13 +27,6 @@ class ConstructionPlugin_Point : public ModelAPI_Feature, public GeomAPI_ICustom
     return CONSTRUCTION_POINT_KIND;
   }
 
-  /// default color for a point
-  inline static const std::string& DEFAULT_COLOR()
-  {
-    static const std::string CONSTRUCTION_POINT_COLOR("#ffff00");
-    return CONSTRUCTION_POINT_COLOR;
-  }
-
   /// attribute name for X coordinate
   inline static const std::string& X()
   {
@@ -64,10 +57,6 @@ class ConstructionPlugin_Point : public ModelAPI_Feature, public GeomAPI_ICustom
 
   /// Use plugin manager for features creation
   ConstructionPlugin_Point();
-
-  /// Modifies the given presentation in the custom way.
-  virtual void customisePresentation(AISObjectPtr thePrs);
-
 };
 
 #endif
index 11d45e7854aa0fecba09c74b3645e17e67816963..7fe93e09022b7b962ade8ce358258507c844bab7 100644 (file)
@@ -70,14 +70,6 @@ void ExchangePlugin_ImportFeature::execute()
   importFile(aFilePath);
 }
 
-void ExchangePlugin_ImportFeature::customisePresentation(AISObjectPtr thePrs)
-{
-  std::vector<int> aRGB = Config_PropManager::color("Visualization", "import_feature_color",
-                                                    IMPORTED_FEATURE_COLOR);
-  thePrs->setColor(aRGB[0], aRGB[1], aRGB[2]);
-  thePrs->redisplay();
-}
-
 bool ExchangePlugin_ImportFeature::importFile(const std::string& theFileName)
 {
   // retrieve the file and plugin library names
index 54ed715213ce7c2ea7c4800e7a95e8a3afed1904..673a6d9509955ac69ccd9298798b1ea936a7f8a7 100644 (file)
@@ -5,20 +5,17 @@
 
 #include <ExchangePlugin.h>
 #include <ModelAPI_Feature.h>
-
-#include <GeomAPI_ICustomPrs.h>
+#include <ModelAPI_Result.h>
 
 #include <map>
 
-#define IMPORTED_FEATURE_COLOR "#E0A01B"
-
   /**\class ExchangePlugin_ImportFeature
  * \ingroup Plugins
  * \brief Feature for import shapes from the external files in CAD formats.
  *
  * The set of supported formats is defined in the configuration file.
  */
-class ExchangePlugin_ImportFeature : public ModelAPI_Feature, public GeomAPI_ICustomPrs
+class ExchangePlugin_ImportFeature : public ModelAPI_Feature
 {
  public:
   /// Extrusion kind
@@ -52,9 +49,6 @@ class ExchangePlugin_ImportFeature : public ModelAPI_Feature, public GeomAPI_ICu
     return true;
   }
 
-  /// Modifies the given presentation in the custom way.
-  virtual void customisePresentation(AISObjectPtr thePrs);
-
  protected:
   /// POerforms the import of the file
   EXCHANGEPLUGIN_EXPORT bool importFile(const std::string& theFileName);
index e2b1ee20f7f69c890a3d86d1e05f007ae3fa6f6a..58b214b47c96522dcfcf5df123e5f27b7e1251fe 100644 (file)
@@ -30,12 +30,8 @@ ExchangePlugin_Plugin::ExchangePlugin_Plugin()
                               new ExchangePlugin_ImportFormatValidator);
 
   // register construction properties
-  Config_PropManager::registerProp("Visualization", "import_feature_color", "Imported feature color",
-                                   Config_Prop::Color, IMPORTED_FEATURE_COLOR);
-
-  // register random result color properties
-  Config_PropManager::registerProp("Visualization", "random_result_color", "Use random color for results",
-                                   Config_Prop::Bool, "true");
+  //Config_PropManager::registerProp("Visualization", "import_feature_color", "Imported feature color",
+  //                                 Config_Prop::Color, ExchangePlugin_ImportFeature::DEFAULT_COLOR());
 }
 
 FeaturePtr ExchangePlugin_Plugin::createFeature(string theFeatureID)
index 5e0c21b44ae344824eff4008ce15cf299a561dab..fb90ceccb6d06672058670f36bc40dc4b5d9a287 100644 (file)
@@ -29,6 +29,8 @@
 #include <AIS_FixRelation.hxx>
 #include <Prs3d_PointAspect.hxx>
 
+#include <Graphic3d_AspectLine3d.hxx>
+
 const double tolerance = 1e-7;
 
 const int CONSTRAINT_TEXT_HEIGHT = 28;  /// the text height of the constraint
@@ -253,16 +255,6 @@ void GeomAPI_AISObject::createFixed(std::shared_ptr<GeomAPI_Shape> theShape,
   }
 }
 
-void GeomAPI_AISObject::redisplay()
-{
-  Handle(AIS_InteractiveObject) anAIS = impl<Handle(AIS_InteractiveObject)>();
-  if (!anAIS.IsNull()) {
-    Handle(AIS_InteractiveContext) aContext = anAIS->GetContext();
-    aContext->Redisplay(anAIS, false);
-  }
-}
-
-
 void GeomAPI_AISObject::setColor(const int& theColor)
 {
   Handle(AIS_InteractiveObject) anAIS = impl<Handle(AIS_InteractiveObject)>();
@@ -278,21 +270,30 @@ void GeomAPI_AISObject::setColor(const int& theColor)
   aContext->SetColor(anAIS, aColor, false);
 }
 
-void GeomAPI_AISObject::setWidth(const double& theWidth)
+bool GeomAPI_AISObject::setWidth(const double& theWidth)
 {
+  bool isChanged = false;
   Handle(AIS_InteractiveObject) anAIS = impl<Handle(AIS_InteractiveObject)>();
-  if (anAIS.IsNull())
-    return;
-  anAIS->SetWidth(theWidth);
-  anAIS->Redisplay();
+  if (!anAIS.IsNull()) {
+    isChanged = anAIS->Width() != theWidth;
+    if (isChanged)
+      anAIS->SetWidth(theWidth);
+  }
+  return isChanged;
 }
 
-void GeomAPI_AISObject::setColor(int theR, int theG, int theB)
+bool GeomAPI_AISObject::setColor(int theR, int theG, int theB)
 {
   Handle(AIS_InteractiveObject) anAIS = impl<Handle(AIS_InteractiveObject)>();
   if (anAIS.IsNull())
-    return;
+    return false;
   Quantity_Color aColor(theR / 255., theG / 255., theB / 255., Quantity_TOC_RGB);
+  Quantity_Color aCurrentColor;
+  anAIS->Color(aCurrentColor);
+  // do not set the same color to the presentation
+  if (aColor.IsEqual(aCurrentColor))
+    return false;
+
   anAIS->SetColor(aColor);
   Handle(AIS_Dimension) aDimAIS = Handle(AIS_Dimension)::DownCast(anAIS);
   if (!aDimAIS.IsNull()) {
@@ -300,6 +301,19 @@ void GeomAPI_AISObject::setColor(int theR, int theG, int theB)
   }
   Handle(AIS_InteractiveContext) aContext = anAIS->GetContext();
   aContext->SetColor(anAIS, aColor, false);
+  return true;
+}
+
+void GeomAPI_AISObject::getColor(int& theR, int& theG, int& theB)
+{
+  Handle(AIS_InteractiveObject) anAIS = impl<Handle(AIS_InteractiveObject)>();
+  if (anAIS.IsNull())
+    return;
+
+  Quantity_Color aColor = anAIS->Color();
+  theR = aColor.Red()*255.;
+  theG = aColor.Green()*255.;
+  theB = aColor.Blue()*255.;
 }
 
 bool GeomAPI_AISObject::empty() const
@@ -340,26 +354,46 @@ void GeomAPI_AISObject::setPointMarker(int theType, double theScale)
   }
 }
 
-
-void GeomAPI_AISObject::setLineStyle(int theStyle)
+bool GeomAPI_AISObject::setLineStyle(int theStyle)
 {
+  bool isChanged = false;
   Handle(AIS_InteractiveObject) anAIS = impl<Handle(AIS_InteractiveObject)>();
   if (!anAIS.IsNull()) {
     Handle(AIS_Drawer) aDrawer = anAIS->Attributes();
-    if (aDrawer->HasLineAspect())
-      aDrawer->LineAspect()->SetTypeOfLine((Aspect_TypeOfLine)theStyle);
-    if (aDrawer->HasWireAspect())
-      aDrawer->WireAspect()->SetTypeOfLine((Aspect_TypeOfLine)theStyle);
+    Handle(Prs3d_LineAspect) aLineAspect;
+
+    Aspect_TypeOfLine aType = (Aspect_TypeOfLine)theStyle;
+    if (aDrawer->HasLineAspect()) {
+      aLineAspect = aDrawer->LineAspect();
+    }
+    if (aDrawer->HasWireAspect()) {
+      aLineAspect = aDrawer->WireAspect();
+    }
+    Quantity_Color aCurrentColor;
+    Aspect_TypeOfLine aCurrentType;
+    Standard_Real aCurrentWidth;
+    aLineAspect->Aspect()->Values(aCurrentColor, aCurrentType, aCurrentWidth);
+    isChanged = aType != aCurrentType;
+    if (isChanged) {
+      aLineAspect->SetTypeOfLine(aType);
+    }
   }
+  return isChanged;
 }
 
 
-void GeomAPI_AISObject::setTransparensy(double theVal)
+bool GeomAPI_AISObject::setTransparensy(double theVal)
 {
+  bool isChanged = false;
   Handle(AIS_InteractiveObject) anAIS = impl<Handle(AIS_InteractiveObject)>();
   if (!anAIS.IsNull()) {
     Handle(AIS_InteractiveContext) aContext = anAIS->GetContext();
-    if (!aContext.IsNull())
-      aContext->SetTransparency(anAIS, theVal, false);
+    if (!aContext.IsNull()) {
+      double aCurrentValue = anAIS->Transparency();
+      isChanged = aCurrentValue != theVal;
+      if (isChanged)
+        aContext->SetTransparency(anAIS, theVal, false);
+    }
   }
+ return isChanged;
 }
index c916320c093b70c4bfd9306df2fbee7c064ea3aa..ad879d1dbc790d70d9735194bcb57bf6449f01ef 100644 (file)
@@ -78,24 +78,28 @@ class GEOMAPI_EXPORT GeomAPI_AISObject : public GeomAPI_Interface
   void createFixed(std::shared_ptr<GeomAPI_Shape> theShape,
                    std::shared_ptr<GeomAPI_Pln> thePlane);
 
-  /** \brief Redisplays the current AIS object in the context
-   */
-  void redisplay();
-
   /** \brief Assigns the color for the shape
    *  \param[in] theColor index of the color
    */
   void setColor(const int& theColor);
 
   /** \brief Assigns the color for the shape
+   *  \param[in] theR value of the red component
+   *  \param[in] theG value of the green component
+   *  \param[in] theB value of the blue component
+   *  \returns true if the presentation color is changed
+   */
+  bool setColor(int theR, int theG, int theB);
+
+  /** \brief Returns the color for the shape
    *  \param[in] theR value of the red component
    *  \param[in] theG value of the green component
    *  \param[in] theB value of the blue component
    */
-  void setColor(int theR, int theG, int theB);
+  void getColor(int& theR, int& theG, int& theB);
 
   /// \brief Assigns the width of the lines of shape
-  void setWidth(const double& theWidth);
+  bool setWidth(const double& theWidth);
 
   /// \brief Checks if the object is empty
   bool empty() const;
@@ -110,10 +114,12 @@ class GEOMAPI_EXPORT GeomAPI_AISObject : public GeomAPI_Interface
 
   /// Set line type of edges
   /// Has to be defined according to Aspect_TypeOfLine
-  void setLineStyle(int theStyle);
+  /// \returns true if the object value differs from the current
+  bool setLineStyle(int theStyle);
 
   /// Set transparency of the presentation (theVal = 0 ... 1)
-  void setTransparensy(double theVal);
+  /// \returns true if the object value differs from the current
+  bool setTransparensy(double theVal);
 };
 
 //! Pointer on attribute object
index 72c362d657e7e46787e30f3852cc878781de4e70..de9c6d299f5dbb359aee66febcb07473c2003c73 100644 (file)
@@ -9,18 +9,23 @@
 
 #include "GeomAPI.h"
 #include "GeomAPI_AISObject.h"
+#include "GeomAPI_AISObject.h"
 
+#include <vector>
 /**
 * Interface of a class which can provide specific customization of
 * object presentation
 */ 
+class ModelAPI_Result;
+
 class GeomAPI_ICustomPrs
 {
 public:
   GEOMAPI_EXPORT virtual ~GeomAPI_ICustomPrs();
 
   /// Modifies the given presentation in the custom way.
-  virtual void customisePresentation(AISObjectPtr thePrs) = 0;
+  virtual bool customisePresentation(std::shared_ptr<ModelAPI_Result> theResult, AISObjectPtr thePrs,
+                                     std::shared_ptr<GeomAPI_ICustomPrs> theDefaultPrs) = 0;
 };
 
 typedef std::shared_ptr<GeomAPI_ICustomPrs> GeomCustomPrsPtr;
index 784eff153c53703fa6c1e4cb4cbca58b5e721d51..2bdea7f5f30bdf54fbd2db814dccdc2b16615f1e 100644 (file)
@@ -44,16 +44,17 @@ Model_ResultBody::Model_ResultBody()
 
 void Model_ResultBody::initAttributes()
 {
-  // append the color attribute
+  // append the color attribute. It is empty, the attribute will be filled by a request
   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_body_color", DEFAULT_COLOR());
-  aColorAttr->setSize(3);
-  aColorAttr->setValue(0, aRGB[0]);
-  aColorAttr->setValue(1, aRGB[1]);
-  aColorAttr->setValue(2, aRGB[2]);
+}
+
+void Model_ResultBody::colorConfigInfo(std::string& theSection, std::string& theName,
+                                       std::string& theDefault)
+{
+  theSection = "Visualization";
+  theName = "result_body_color";
+  theDefault = DEFAULT_COLOR();
 }
 
 void Model_ResultBody::store(const std::shared_ptr<GeomAPI_Shape>& theShape)
index e7fdcb5ca5ab53b310ef4a88ef7158655c9cbd12..a5ffd83027b04bba1e2ca48a2fac7b6f6df0b951 100644 (file)
@@ -39,6 +39,10 @@ public:
   /// Request for initialization of data model of the result: adding all attributes
   virtual void initAttributes();
 
+  // Retuns the parameters of color definition in the resources config manager
+  MODEL_EXPORT virtual void colorConfigInfo(std::string& theSection, std::string& theName,
+                                            std::string& theDefault);
+
   /// Stores the shape (called by the execution method).
   MODEL_EXPORT virtual void store(const std::shared_ptr<GeomAPI_Shape>& theShape);
 
index 97f2b4fcd3808b381aad63b2d71c63cb8b06531c..a0f3b9306ed2281a13ef5fe3c7c96d4596f6b44f 100644 (file)
 
 void Model_ResultConstruction::initAttributes()
 {
-  // append the color attribute
+  // append the color attribute. It is empty, the attribute will be filled by a request
   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::colorConfigInfo(std::string& theSection, std::string& theName,
+                                       std::string& theDefault)
+{
+  theSection = "Visualization";
+  theName = "result_construction_color";
+  theDefault = DEFAULT_COLOR();
 }
 
 void Model_ResultConstruction::setShape(std::shared_ptr<GeomAPI_Shape> theShape)
index 2fb81219d9b9989271a16aa03e03c3a78b6157d0..8292e09bc12b12f9d8492199dac11d759b57e142 100644 (file)
@@ -33,6 +33,10 @@ class Model_ResultConstruction : public ModelAPI_ResultConstruction
   /// Request for initialization of data model of the result: adding all attributes
   virtual void initAttributes();
 
+  // Retuns the parameters of color definition in the resources config manager
+  MODEL_EXPORT virtual void colorConfigInfo(std::string& theSection, std::string& theName,
+                                            std::string& theDefault);
+
   /// By default object is displayed in the object browser.
   MODEL_EXPORT virtual bool isInHistory()
   {
index a0a5922cd056249e7e3fbec64597e0d29d63dd08..dd4ee732b7091f9823036048d326bef3f3d6f1af 100644 (file)
@@ -20,16 +20,17 @@ Model_ResultGroup::Model_ResultGroup(std::shared_ptr<ModelAPI_Data> theOwnerData
 
 void Model_ResultGroup::initAttributes()
 {
-  // append the color attribute
+  // append the color attribute. It is empty, the attribute will be filled by a request
   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]);
+}
+
+void Model_ResultGroup::colorConfigInfo(std::string& theSection, std::string& theName,
+                                       std::string& theDefault)
+{
+  theSection = "Visualization";
+  theName = "result_group_color";
+  theDefault = DEFAULT_COLOR();
 }
 
 std::shared_ptr<GeomAPI_Shape> Model_ResultGroup::shape()
index 33c0e17a74ba47245741359e4e8c9d50653826c7..7bfa796942d8053b4f72f03188bf3a114222444a 100644 (file)
@@ -29,6 +29,10 @@ public:
   /// Request for initialization of data model of the result: adding all attributes
   virtual void initAttributes();
 
+  // Retuns the parameters of color definition in the resources config manager
+  MODEL_EXPORT virtual void colorConfigInfo(std::string& theSection, std::string& theName,
+                                            std::string& theDefault);
+
   /// Returns the compound of selected entities
   MODEL_EXPORT virtual std::shared_ptr<GeomAPI_Shape> shape();
 
index 776a2839153c4d64efb681044983402b4f8ba551..c02abf60828854ffb8dac14a4c808e9129173efd 100644 (file)
@@ -42,6 +42,9 @@ class ModelAPI_Result : public ModelAPI_Object
     myIsConcealed = theValue;
   }
 
+  // Retuns the parameters of color definition in the resources config manager
+  virtual void colorConfigInfo(std::string& theSection, std::string& theName, std::string& theDefault) {}
+
   /// Request for initialization of data model of the result: adding all attributes
   virtual void initAttributes() {};
 
index 4d4d1c78dbd20097353ddb1738fcb9a81142768e..f97a9ed7f4cbabe15350fc9165530511dd40a6f8 100644 (file)
@@ -261,6 +261,9 @@ void ModuleBase_PreferencesDlg::createViewerPage(int thePageId)
   myPreferences->setItemProperty("custom_enabled", false, bgId);
   myPreferences->setItemProperty("image_formats", aImgFiles, bgId);
 
+  //Config_PropManager::registerProp("Visualization", "object_default_color", "Object color",
+  //                                 Config_Prop::Color, "#ffffff");
+
   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",
index 1e7c4de3b5e2a999f2714426e2bc4feac8373118..0737eb899b8f4c756a443b3d154ee0a4fa002476 100644 (file)
@@ -4,6 +4,7 @@
 
 #include <ModelAPI_Session.h>
 #include <ModelAPI_Validator.h>
+#include <ModelAPI_AttributeIntArray.h>
 
 SketchPlugin_SketchEntity::SketchPlugin_SketchEntity()
 : SketchPlugin_Feature()
index c0c0925638556abf9425de6208d45c1d184f8553..11bc85e620fe2ddf2bdbc75f48720f82e8599829 100644 (file)
@@ -60,48 +60,52 @@ class SketchPlugin_SketchEntity : public SketchPlugin_Feature, public GeomAPI_IC
   }
 
   /// Customize presentation of the feature
-  virtual void customisePresentation(AISObjectPtr thePrs)
+  virtual bool customisePresentation(ResultPtr theResult, AISObjectPtr thePrs,
+                                     std::shared_ptr<GeomAPI_ICustomPrs> theDefaultPrs)
   {
-    std::vector<int> aRGB;
-  
+    bool isCustomized = false;
     int aShapeType = thePrs->getShapeType();
     if (aShapeType != 6/*an edge*/ && aShapeType != 7/*a vertex*/)
-      return;
+      return false;
 
+    std::vector<int> aColor;
     std::shared_ptr<ModelAPI_AttributeBoolean> aConstructionAttr =
-                                   data()->boolean(SketchPlugin_SketchEntity::CONSTRUCTION_ID());
+                                    data()->boolean(SketchPlugin_SketchEntity::CONSTRUCTION_ID());
     bool isConstruction = aConstructionAttr.get() != NULL && aConstructionAttr->value();
     if (aShapeType == 6) { // if this is an edge
       if (isConstruction) {
-        thePrs->setWidth(1);
-        thePrs->setLineStyle(3);
-        aRGB = Config_PropManager::color("Visualization", "sketch_construction_color",
-                                         SKETCH_CONSTRUCTION_COLOR);
+        isCustomized = thePrs->setWidth(1) || isCustomized;
+        isCustomized = thePrs->setLineStyle(3) || isCustomized;
+
+        aColor = Config_PropManager::color("Visualization", "sketch_construction_color",
+                                          SKETCH_CONSTRUCTION_COLOR);
       }
       else {
-        thePrs->setWidth(3);
-        thePrs->setLineStyle(0);
+        isCustomized = thePrs->setWidth(3) || isCustomized;
+        isCustomized = thePrs->setLineStyle(0) || isCustomized;
+
         if (isExternal()) {
           // Set color from preferences
-          aRGB = Config_PropManager::color("Visualization", "sketch_external_color",
-                                           SKETCH_EXTERNAL_EDGE_COLOR);
+          aColor = Config_PropManager::color("Visualization", "sketch_external_color",
+                                            SKETCH_EXTERNAL_EDGE_COLOR);
         }
         else {
           // Set color from preferences
-          aRGB = Config_PropManager::color("Visualization", "sketch_edge_color",
-                                           SKETCH_EDGE_COLOR);
+          aColor = Config_PropManager::color("Visualization", "sketch_edge_color",
+                                             SKETCH_EDGE_COLOR);
         }
       }
     }
     else if (aShapeType == 7) { // otherwise this is a vertex
       //  thePrs->setPointMarker(6, 2.);
-      // Set color from preferences
-      aRGB = Config_PropManager::color("Visualization", "sketch_point_color",
-                                       SKETCH_POINT_COLOR);
+      aColor = Config_PropManager::color("Visualization", "sketch_point_color",
+                                        SKETCH_POINT_COLOR);
     }
 
-    if (!aRGB.empty())
-      thePrs->setColor(aRGB[0], aRGB[1], aRGB[2]);
+    if (!aColor.empty()) {
+      isCustomized = thePrs->setColor(aColor[0], aColor[1], aColor[2]) || isCustomized;
+    }
+    return isCustomized;
   }
 
 protected:
index c7a27c7161cfdc275dc1f0be70c5ca5f2282d253..bd843caa93b19576aab7c2eca61099108cc77a7c 100644 (file)
@@ -7,6 +7,7 @@ SET(PROJECT_HEADERS
        XGUI.h
        XGUI_ActionsMgr.h
        XGUI_ContextMenuMgr.h
+       XGUI_CustomPrs.h
        XGUI_DataTreeModel.h
        XGUI_Displayer.h
        XGUI_DocumentDataModel.h
@@ -33,6 +34,7 @@ SET(PROJECT_AUTOMOC
 SET(PROJECT_SOURCES
        XGUI_ActionsMgr.cpp
        XGUI_ContextMenuMgr.cpp
+       XGUI_CustomPrs.cpp
        XGUI_Displayer.cpp
        XGUI_DocumentDataModel.cpp
        XGUI_ErrorDialog.cpp
diff --git a/src/XGUI/XGUI_CustomPrs.cpp b/src/XGUI/XGUI_CustomPrs.cpp
new file mode 100644 (file)
index 0000000..8584bc5
--- /dev/null
@@ -0,0 +1,55 @@
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
+// File:        XGUI_CustomPrs.cpp
+// Created:     10 Mar 2015
+// Author:      Natalia ERMOLAEVA
+
+#include <XGUI_CustomPrs.h>
+
+#include <ModelAPI_AttributeIntArray.h>
+#include <Config_PropManager.h>
+
+#include <vector>
+
+
+void getColor(ResultPtr theResult, std::vector<int>& theColor)
+{
+  theColor.clear();
+  // get color from the attribute of the result
+  if (theResult.get() != NULL && theResult->data()->attribute(ModelAPI_Result::COLOR_ID()).get() != NULL) {
+    AttributeIntArrayPtr aColorAttr = theResult->data()->intArray(ModelAPI_Result::COLOR_ID());
+    if (aColorAttr.get() && aColorAttr->size()) {
+      theColor.push_back(aColorAttr->value(0));
+      theColor.push_back(aColorAttr->value(1));
+      theColor.push_back(aColorAttr->value(2));
+    }
+  }
+}
+
+void getDefaultColor(ResultPtr theResult, AISObjectPtr thePrs, std::vector<int>& theColor)
+{
+  theColor.clear();
+  // get default color from the preferences manager for the given result
+  if (theColor.empty()) {
+    std::string aSection, aName, aDefault;
+    theResult->colorConfigInfo(aSection, aName, aDefault);
+    if (!aSection.empty() && !aName.empty()) {
+      theColor = Config_PropManager::color(aSection, aName, aDefault);
+    }
+  }
+  if (theColor.empty()) // all AIS objects, where the color is not set, a white.
+    // The color should be defined in XML or set in the attribute
+    theColor = Config_PropManager::color("Visualization", "object_default_color", "#ffffff");
+}
+
+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);
+
+  return !aColor.empty() && thePrs->setColor(aColor[0], aColor[1], aColor[2]);
+}
diff --git a/src/XGUI/XGUI_CustomPrs.h b/src/XGUI/XGUI_CustomPrs.h
new file mode 100644 (file)
index 0000000..97bc891
--- /dev/null
@@ -0,0 +1,29 @@
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
+// File:        XGUI_CustomPrs.hxx
+// Created:     10 Mar 2015
+// Author:      Natalia ERMOLAEVA
+
+#ifndef XGUI_CustomPrs_H
+#define XGUI_CustomPrs_H
+
+#include "XGUI.h"
+#include <GeomAPI_ICustomPrs.h>
+#include <GeomAPI_AISObject.h>
+#include <ModelAPI_Result.h>
+
+/**
+* Interface of a class which can provide specific customization of
+* object presentation
+*/ 
+class XGUI_CustomPrs : public GeomAPI_ICustomPrs
+{
+public:
+  XGUI_EXPORT virtual ~XGUI_CustomPrs() {};
+
+  /// Modifies the given presentation in the custom way.
+  virtual bool customisePresentation(ResultPtr theResult, AISObjectPtr thePrs,
+                                     std::shared_ptr<GeomAPI_ICustomPrs> theCustomPrs);
+};
+
+#endif
index 9d6884b929cf0ce4749daeb8a52ad28ffaf22674..1acdc22eafcc5a97440dfde8ae33ba561e3e7e73 100644 (file)
@@ -9,6 +9,7 @@
 #include "XGUI_ViewerProxy.h"
 #include "XGUI_SelectionMgr.h"
 #include "XGUI_Selection.h"
+#include "XGUI_CustomPrs.h"
 
 #include <AppElements_Viewer.h>
 
@@ -72,6 +73,7 @@ XGUI_Displayer::XGUI_Displayer(XGUI_Workshop* theWorkshop)
   : myWorkshop(theWorkshop)
 {
   enableUpdateViewer(true);
+  myCustomPrs = std::shared_ptr<GeomAPI_ICustomPrs>(new XGUI_CustomPrs());
 }
 
 XGUI_Displayer::~XGUI_Displayer()
@@ -159,7 +161,10 @@ void XGUI_Displayer::display(ObjectPtr theObject, AISObjectPtr theAIS,
 
     aContext->SetDisplayMode(anAISIO, isShading? Shading : Wireframe, false);
 
-    customizeObject(theObject);
+    bool isCustomized = customizeObject(theObject);
+    if (isCustomized)
+      aContext->Redisplay(anAISIO, false);
+
     if (aCanBeShaded) {
       openLocalContext();
       activateObjects(myActiveSelectionModes);
@@ -223,6 +228,7 @@ void XGUI_Displayer::redisplay(ObjectPtr theObject, bool isUpdateViewer)
     // before and after the values modification.
     // Moreother, this check avoids customize and redisplay presentation if the presentable
     // parameter is changed.
+    bool isEqualShapes = false;
     ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
     if (aResult.get() != NULL) {
       Handle(AIS_Shape) aShapePrs = Handle(AIS_Shape)::DownCast(aAISIO);
@@ -233,17 +239,17 @@ void XGUI_Displayer::redisplay(ObjectPtr theObject, bool isUpdateViewer)
           std::shared_ptr<GeomAPI_Shape> anAISShapePtr(new GeomAPI_Shape());
           anAISShapePtr->setImpl(new TopoDS_Shape(aShape));
 
-          if (aShapePtr->isEqual(anAISShapePtr))
-            return;
+          isEqualShapes = aShapePtr->isEqual(anAISShapePtr);
         }
       }
     }
     // Customization of presentation
-    customizeObject(theObject);
-
-    aContext->Redisplay(aAISIO, false);
-    if (isUpdateViewer)
-      updateViewer();
+    bool isCustomized = customizeObject(theObject);
+    if (!isEqualShapes || isCustomized) {
+      aContext->Redisplay(aAISIO, false);
+      if (isUpdateViewer)
+        updateViewer();
+    }
   }
 }
 
@@ -758,25 +764,24 @@ void XGUI_Displayer::activate(const Handle(AIS_InteractiveObject)& theIO,
   }
 }
 
-void XGUI_Displayer::customizeObject(ObjectPtr theObject)
+bool XGUI_Displayer::customizeObject(ObjectPtr theObject)
 {
+  // we need not customize presentable objects
+  GeomPresentablePtr aPrs = std::dynamic_pointer_cast<GeomAPI_IPresentable>(theObject);
+  if (aPrs.get() != NULL)
+    return false;
+
   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);
-    }
-  }
+
   // Customization of presentation
+  GeomCustomPrsPtr aCustomPrs = myCustomPrs;
   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);
+      aCustomPrs = aCustPrs;
   }
+  return aCustomPrs->customisePresentation(aResult, anAISObj, myCustomPrs);
 }
index e5ea6fd05d7995b7bf8d080aad56af2cc1512add..da11c4d8ef6f65ba1ca039fe7f9c208d41c92a43 100644 (file)
@@ -20,6 +20,8 @@
 #include <ModuleBase_Definitions.h>
 #include <ModuleBase_ViewerPrs.h>
 
+#include <GeomAPI_ICustomPrs.h>
+
 #include <SelectMgr_AndFilter.hxx>
 
 #include <QString>
@@ -218,8 +220,9 @@ class XGUI_EXPORT XGUI_Displayer
    * If the object is result with the color attribute value set, it is used,
    * otherwise the customize is applyed to the object's feature if it is a custom prs
    * \param theObject an object instance
+   * \return the true state if there is changes and the presentation is customized
    */
-  void customizeObject(ObjectPtr theObject);
+  bool customizeObject(ObjectPtr theObject);
 
  protected:
    /// Reference to workshop
@@ -228,6 +231,9 @@ class XGUI_EXPORT XGUI_Displayer
   /// A container for selection filters
   Handle(SelectMgr_AndFilter) myAndFilter;
 
+  /// A default custom presentation, which is used if the displayed feature is not a custom presentation
+  GeomCustomPrsPtr myCustomPrs;
+
   /// Definition of a type of map which defines correspondance between objects and presentations
   typedef QMap<ObjectPtr, AISObjectPtr> ResultToAISMap;
 
index 45f12d0d571c8b32b0b65b9b20ab790d4bd4c0f7..dc54367498b68b55918a8c871eed80dad398fe47 100644 (file)
@@ -1411,20 +1411,17 @@ bool XGUI_Workshop::canChangeColor() const
 //**************************************************************
 void XGUI_Workshop::changeColor(const QObjectPtrList& theObjects)
 {
-  // 1. find the initial value of the color
-  AttributeIntArrayPtr aColorAttr;
-  foreach(ObjectPtr anObj, theObjects) {
-    ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObj);
-    if (aResult.get() != NULL) {
-      aColorAttr = aResult->data()->intArray(ModelAPI_Result::COLOR_ID());
-    }
+  std::vector<int> aColor;
+  foreach(ObjectPtr anObject, theObjects) {
+
+    AISObjectPtr anAISObj = myDisplayer->getAISObject(anObject);
+    aColor.resize(3);
+    anAISObj->getColor(aColor[0], aColor[1], aColor[2]);
+    if (!aColor.empty())
+      break;
   }
-  // there is no object with the color attribute
-  if (aColorAttr.get() == NULL || aColorAttr->size() == 0)
+  if (aColor.size() != 3)
     return;
-  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 = new QDialog();
@@ -1434,7 +1431,7 @@ void XGUI_Workshop::changeColor(const QObjectPtrList& theObjects)
   aColorBtn->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
 
   aLay->addWidget(aColorBtn);
-  aColorBtn->setColor(QColor(aRed, aGreen, aBlue));
+  aColorBtn->setColor(QColor(aColor[0], aColor[1], aColor[2]));
 
   QDialogButtonBox* aButtons = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel,
                                                     Qt::Horizontal, aDlg);
@@ -1452,7 +1449,7 @@ void XGUI_Workshop::changeColor(const QObjectPtrList& theObjects)
       aGreenResult = aColorResult.green(),
       aBlueResult = aColorResult.blue();
 
-  if (aRedResult == aRed && aGreenResult == aGreen && aBlueResult == aBlue)
+  if (aRedResult == aColor[0] && aGreenResult == aColor[1] && aBlueResult == aColor[2])
     return;
 
   // 3. abort the previous operation and start a new one
@@ -1465,6 +1462,7 @@ void XGUI_Workshop::changeColor(const QObjectPtrList& theObjects)
 
   // 4. set the value to all results
   static Events_ID EVENT_DISP = Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY);
+  AttributeIntArrayPtr aColorAttr;
   foreach(ObjectPtr anObj, theObjects) {
     ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObj);
     if (aResult.get() != NULL) {