Salome HOME
1. Manage color of construction point using preferences dialog box. csgroup_IS2
authorvsv <vsv@opencascade.com>
Mon, 22 Mar 2021 13:59:34 +0000 (16:59 +0300)
committervsv <vsv@opencascade.com>
Mon, 22 Mar 2021 13:59:34 +0000 (16:59 +0300)
2. Get rid compilation link from ModuleBase to BuildPlugin. Provide the same filtering functionality using corresponded validators.

18 files changed:
src/BuildPlugin/BuildPlugin_Validators.cpp
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/GeomAPI/GeomAPI_ICustomPrs.h
src/Model/Model_ResultConstruction.cpp
src/ModelAPI/ModelAPI_ResultConstruction.cpp
src/ModelAPI/ModelAPI_ResultConstruction.h
src/ModuleBase/CMakeLists.txt
src/ModuleBase/ModuleBase_WidgetValidated.cpp
src/PartSet/PartSet_Module.cpp
src/PartSet/PartSet_Tools.cpp
src/SketchPlugin/SketchPlugin_ConstraintBase.h
src/XGUI/XGUI_Workshop.cpp

index ac454e620fd03348cf9162e682171fb8320e2fda..29bc897b75f56adda3b522d5f18c4b728877822f 100644 (file)
@@ -123,6 +123,35 @@ bool BuildPlugin_ValidatorBaseForWire::isValid(const std::shared_ptr<ModelAPI_Fe
     return false;
   }
 
+  /// remove objects of sub-type if ojects of correct type is in List,  in some cases :
+  /// Wire builder: wires and edges selected
+  std::set<GeomAPI_Shape::ShapeType> shapeTypes;
+  for (int anIndex = 0; anIndex < aSelectionList->size(); ++anIndex) {
+    AttributeSelectionPtr aSelection = aSelectionList->value(anIndex);
+    GeomShapePtr aShape = aSelection->value();
+    if (aShape.get())
+      shapeTypes.insert(aShape->shapeType());
+  }
+
+  std::set<int> aRemove;
+  if (shapeTypes.find(GeomAPI_Shape::WIRE) != shapeTypes.end())
+  {
+    for (int anIndex = 0; anIndex < aSelectionList->size(); ++anIndex) {
+      AttributeSelectionPtr aSelection = aSelectionList->value(anIndex);
+      GeomShapePtr aShape = aSelection->value();
+      if (aShape.get()) {
+        auto aType = aShape->shapeType();
+        if (aType == GeomAPI_Shape::EDGE)
+          aRemove.insert(anIndex);
+      }
+      else
+        aRemove.insert(anIndex);
+    }
+  }
+
+  if (aRemove.size() > 0)
+    aSelectionList->remove(aRemove);
+
   GeomAPI_Shape::ShapeType aShapeType = GeomAPI_Shape::shapeTypeByStr(theArguments.back());
 
   // Collect base shapes.
@@ -194,6 +223,35 @@ bool BuildPlugin_ValidatorBaseForFace::isValid(const std::shared_ptr<ModelAPI_Fe
     return false;
   }
 
+  /// remove objects of sub-type if ojects of correct type is in List,  in some cases :
+  /// - Face builder: edges, faces and wires selected
+  ///                 --> remove edges and wires
+  std::set<GeomAPI_Shape::ShapeType> shapeTypes;
+  for (int anIndex = 0; anIndex < aSelectionList->size(); ++anIndex) {
+    AttributeSelectionPtr aSelection = aSelectionList->value(anIndex);
+    GeomShapePtr aShape = aSelection->value();
+    if (aShape.get())
+      shapeTypes.insert(aShape->shapeType());
+  }
+
+  std::set<int> aRemove;
+  if (shapeTypes.find(GeomAPI_Shape::FACE) != shapeTypes.end())
+  {
+    for (int anIndex = 0; anIndex < aSelectionList->size(); ++anIndex) {
+      AttributeSelectionPtr aSelection = aSelectionList->value(anIndex);
+      GeomShapePtr aShape = aSelection->value();
+      if (aShape.get()) {
+        auto aType = aShape->shapeType();
+        if (aType == GeomAPI_Shape::WIRE || aType == GeomAPI_Shape::EDGE)
+          aRemove.insert(anIndex);
+      }
+      else
+        aRemove.insert(anIndex);
+    }
+  }
+  if (aRemove.size() > 0)
+    aSelectionList->remove(aRemove);
+
   bool hasEdgesOrWires = false;
   bool hasFaces = false;
 
@@ -290,6 +348,39 @@ bool BuildPlugin_ValidatorBaseForSolids::isValid(
     return false;
   }
 
+  /// remove objects of sub-type if ojects of correct type is in List,  in some cases :
+  /// Solid builder: faces and shapes shells or solids seleted
+  ///                --> remove faces
+
+  std::set<GeomAPI_Shape::ShapeType> shapeTypes;
+  for (int anIndex = 0; anIndex < aSelectionList->size(); ++anIndex) {
+    AttributeSelectionPtr aSelection = aSelectionList->value(anIndex);
+    GeomShapePtr aShape = aSelection->value();
+    if (aShape.get())
+      shapeTypes.insert(aShape->shapeType());
+  }
+
+  std::set<int> aRemove;
+  if (shapeTypes.find(GeomAPI_Shape::SHAPE) != shapeTypes.end() ||
+      shapeTypes.find(GeomAPI_Shape::SOLID) != shapeTypes.end() ||
+      shapeTypes.find(GeomAPI_Shape::SHELL) != shapeTypes.end())
+  {
+    for (int anIndex = 0; anIndex < aSelectionList->size(); ++anIndex) {
+      AttributeSelectionPtr aSelection = aSelectionList->value(anIndex);
+      GeomShapePtr aShape = aSelection->value();
+      if (aShape.get()) {
+        auto aType = aShape->shapeType();
+        if (aType == GeomAPI_Shape::FACE)
+          aRemove.insert(anIndex);
+      }
+      else
+        aRemove.insert(anIndex);
+    }
+  }
+
+  if (aRemove.size() > 0)
+    aSelectionList->remove(aRemove);
+
   // Collect base shapes.
   ListOfShape anOriginalShapes;
   for (int anIndex = 0; anIndex < aSelectionList->size(); ++anIndex) {
index 697a0b441cc990d8bc3ac934423d4a5162df0dd9..3d14eda0694c29a8316f13d01257d06199580cd0 100644 (file)
@@ -390,11 +390,9 @@ void ConstructionPlugin_Axis::execute()
   }
 }
 
-bool ConstructionPlugin_Axis::customisePresentation(ResultPtr theResult, AISObjectPtr thePrs,
-  std::shared_ptr<GeomAPI_ICustomPrs> theDefaultPrs)
+bool ConstructionPlugin_Axis::customisePresentation(ResultPtr theResult, AISObjectPtr thePrs)
 {
-  bool isCustomized = theDefaultPrs.get() != NULL &&
-                      theDefaultPrs->customisePresentation(theResult, thePrs, theDefaultPrs);
+  bool isCustomized = false;
 
   isCustomized = thePrs->setLineStyle(3) || isCustomized;
   isCustomized = thePrs->setWidth(2) || isCustomized;
index 43e1d483b353a979b00654ba1f46aec6bd6009b1..115abead134473db4a65e5929bf9dcdab7473b6b 100644 (file)
@@ -250,8 +250,7 @@ class ConstructionPlugin_Axis : public ModelAPI_Feature, public GeomAPI_ICustomP
   ConstructionPlugin_Axis();
 
   /// Customize presentation of the feature
-  virtual bool customisePresentation(ResultPtr theResult, AISObjectPtr thePrs,
-                                     std::shared_ptr<GeomAPI_ICustomPrs> theDefaultPrs);
+  virtual bool customisePresentation(ResultPtr theResult, AISObjectPtr thePrs);
 
  protected:
   /// Creates a new axis by two defined points
index 0b81fca6534558d859a3d8dd83528334c92131f5..5be399aa5485d394df70d2c475875a8ef43a2dfa 100644 (file)
@@ -142,8 +142,7 @@ void ConstructionPlugin_Plane::execute()
 }
 
 //==================================================================================================
-bool ConstructionPlugin_Plane::customisePresentation(ResultPtr theResult, AISObjectPtr thePrs,
-                                                std::shared_ptr<GeomAPI_ICustomPrs> theDefaultPrs)
+bool ConstructionPlugin_Plane::customisePresentation(ResultPtr theResult, AISObjectPtr thePrs)
 {
   std::vector<int> aColor;
   // get color from the attribute of the result
@@ -157,7 +156,7 @@ bool ConstructionPlugin_Plane::customisePresentation(ResultPtr theResult, AISObj
     }
   }
   if (aColor.empty())
-    aColor = Config_PropManager::color("Visualization", "construction_plane_color");
+    aColor = Config_PropManager::color("Visualization", COLOR_NAME());
 
   bool isCustomized = false;
   if (aColor.size() == 3)
index 95fe72d868c56f3733ab0149c65bcfe6cf7e5aa7..9b2a3ba4eb75721587329293f405beca0ba773a3 100644 (file)
@@ -46,6 +46,13 @@ public:
     return CONSTRUCTION_PLANE_COLOR;
   }
 
+  /// Default color property name.
+  inline static const std::string& COLOR_NAME()
+  {
+    static const std::string PLANE_COLOR_NAME("construction_plane_color");
+    return PLANE_COLOR_NAME;
+  }
+
   /// Plane kind.
   inline static const std::string& ID()
   {
@@ -255,8 +262,7 @@ public:
   ConstructionPlugin_Plane();
 
   /// Customize presentation of the feature
-  virtual bool customisePresentation(ResultPtr theResult, AISObjectPtr thePrs,
-                                     std::shared_ptr<GeomAPI_ICustomPrs> theDefaultPrs);
+  virtual bool customisePresentation(ResultPtr theResult, AISObjectPtr thePrs);
 
 protected:
   /// Creates a new plane by general equation.
index 69e900fdc50dbc1a1ad715ed14da817521634c8b..0beb5187230f5f14f6ce36d79bda01f8fa4ce884 100644 (file)
@@ -75,9 +75,11 @@ ConstructionPlugin_Plugin::ConstructionPlugin_Plugin()
   ModelAPI_Session::get()->registerPlugin(this);
 
   // register construction properties
-  Config_PropManager::registerProp("Visualization", "construction_plane_color",
-                                   "Construction plane color",
-                                   Config_Prop::Color, ConstructionPlugin_Plane::DEFAULT_COLOR());
+  Config_PropManager::registerProp("Visualization", ConstructionPlugin_Plane::COLOR_NAME(),
+    "Construction plane color", Config_Prop::Color, ConstructionPlugin_Plane::DEFAULT_COLOR());
+
+  Config_PropManager::registerProp("Visualization", ConstructionPlugin_Point::COLOR_NAME(),
+    "Construction point color", Config_Prop::Color, ConstructionPlugin_Point::DEFAULT_COLOR());
 }
 
 FeaturePtr ConstructionPlugin_Plugin::createFeature(std::string theFeatureID)
index 91392151bcb07e5892d6be38d86143a48fba0ac2..087cfd91deaf5d37e9da75790cef97f5e628747d 100644 (file)
@@ -21,6 +21,7 @@
 
 #include <ModelAPI_AttributeBoolean.h>
 #include <ModelAPI_AttributeDouble.h>
+#include <ModelAPI_AttributeIntArray.h>
 #include <ModelAPI_AttributeSelection.h>
 #include <ModelAPI_AttributeString.h>
 #include <ModelAPI_ResultConstruction.h>
@@ -37,6 +38,8 @@
 #include <GeomAPI_Pln.h>
 #include <GeomAPI_ShapeIterator.h>
 
+#include <Config_PropManager.h>
+
 //==================================================================================================
 ConstructionPlugin_Point::ConstructionPlugin_Point()
 {
@@ -145,19 +148,30 @@ void ConstructionPlugin_Point::execute()
   std::shared_ptr<ModelAPI_ResultConstruction> aConstr = document()->createConstruction(data());
   aConstr->setInfinite(true);
   aConstr->setShape(aShape);
-  /// set point color
-  aConstr->setColor(ModelAPI_ResultConstruction::ModelApi_PointColor::DEFAULT_COLOR(),
-                    ModelAPI_ResultConstruction::ModelApi_PointColor::COLOR_CONFIG_NAME());
   setResult(aConstr);
 }
 
 //==================================================================================================
 bool ConstructionPlugin_Point::customisePresentation(ResultPtr theResult,
-                                                     AISObjectPtr thePrs,
-                                                std::shared_ptr<GeomAPI_ICustomPrs> theDefaultPrs)
+                                                     AISObjectPtr thePrs)
 {
-  bool isCustomized = theDefaultPrs.get() != NULL &&
-                      theDefaultPrs->customisePresentation(theResult, thePrs, theDefaultPrs);
+  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", COLOR_NAME());
+
+  bool isCustomized = false;
+  if (aColor.size() == 3)
+    isCustomized = thePrs->setColor(aColor[0], aColor[1], aColor[2]);
   //thePrs->setPointMarker(1, 1.); // Set point as a '+' symbol
   return isCustomized;
 }
index ffbae672325550eab0a4a1b1d881edcb28f8cd85..8470e048b469d07076cee5904efe0c8714bd9a37 100644 (file)
@@ -39,6 +39,21 @@ public:
   /// Returns the kind of a feature.
   CONSTRUCTIONPLUGIN_EXPORT virtual const std::string& getKind();
 
+  /// Default color for a point.
+  inline static const std::string& DEFAULT_COLOR()
+  {
+    static const std::string POINT_COLOR("85,85,0");
+    return POINT_COLOR;
+  }
+
+  /// Default color property name.
+  inline static const std::string& COLOR_NAME()
+  {
+    static const std::string POINT_COLOR_NAME("construction_point_color");
+    return POINT_COLOR_NAME;
+  }
+
+
   /// Point kind.
   inline static const std::string& ID()
   {
@@ -328,8 +343,7 @@ public:
   ConstructionPlugin_Point();
 
   /// Customize presentation of the feature
-  virtual bool customisePresentation(ResultPtr theResult, AISObjectPtr thePrs,
-                                     std::shared_ptr<GeomAPI_ICustomPrs> theDefaultPrs);
+  virtual bool customisePresentation(ResultPtr theResult, AISObjectPtr thePrs);
 
 private:
   std::shared_ptr<GeomAPI_Vertex> createByXYZ();
index 6908ca948f644bd92cf3a7d9e033b74b729535e7..90d0af06193c9f40331f5ab18e2897cf7aac1ac5 100644 (file)
@@ -40,8 +40,7 @@ public:
 
   /// Modifies the given presentation in the custom way.
   virtual bool customisePresentation(std::shared_ptr<ModelAPI_Result> theResult,
-                                     AISObjectPtr thePrs,
-                                     std::shared_ptr<GeomAPI_ICustomPrs> theDefaultPrs) = 0;
+                                     AISObjectPtr thePrs) = 0;
 };
 
 typedef std::shared_ptr<GeomAPI_ICustomPrs> GeomCustomPrsPtr;
index ff2689cb321ca21a3724798afb12092f8c591f61..d782dbab34f37f82b59092514f867fe8dbfd846b 100644 (file)
@@ -100,8 +100,8 @@ void Model_ResultConstruction::colorConfigInfo(std::string& theSection, std::str
                                        std::string& theDefault)
 {
   theSection = "Visualization";
-  theName =  getColorConfigName();
-  theDefault = getColor();
+  theName = RESULT_COLOR_NAME();
+  theDefault = DEFAULT_COLOR();
 }
 
 void Model_ResultConstruction::setShape(std::shared_ptr<GeomAPI_Shape> theShape)
index 773e71db368ea9fdc17e93a5ce87ec88e4cf4e28..7ae3f66a903f6bbd37a1e6e7fcf408b9dd199713 100644 (file)
@@ -24,7 +24,3 @@ std::string ModelAPI_ResultConstruction::groupName()
 {
   return group();
 }
-
-ModelAPI_ResultConstruction::ModelAPI_ResultConstruction(){
-  setColor(DEFAULT_COLOR(), DEFAULT_COLOR_CONFIG_NAME());
-}
index 9f43462469d891c99d4bce7c90dac69c759d902d..98b22921cd34613e094b52916ff09ac3fbdcd4e6 100644 (file)
  * Provides a shape that may be displayed in the viewer.
  * Intermediate, light result that in many cases produces a result on the fly.
  */
-MODELAPI_EXPORT class ModelAPI_ResultConstruction : public ModelAPI_Result
+class ModelAPI_ResultConstruction : public ModelAPI_Result
 {
  public:
-  MODELAPI_EXPORT ModelAPI_ResultConstruction();
-
   /// Returns the group identifier of this result
   MODELAPI_EXPORT virtual std::string groupName();
 
@@ -55,6 +53,13 @@ MODELAPI_EXPORT class ModelAPI_ResultConstruction : public ModelAPI_Result
     return RESULT_CONSTRUCTION_COLOR;
   }
 
+  /// default color for a result construction
+  inline static const std::string& RESULT_COLOR_NAME()
+  {
+    static const std::string COLOR_NAME("result_construction_color");
+    return COLOR_NAME;
+  }
+
   /// default deflection for a result construction
   inline static const std::string DEFAULT_DEFLECTION()
   {
@@ -83,56 +88,6 @@ MODELAPI_EXPORT class ModelAPI_ResultConstruction : public ModelAPI_Result
   virtual bool isInfinite() = 0;
   /// Sets the flag that it is infinite
   virtual void setInfinite(const bool theInfinite) = 0;
-
-  /*************************************************************************/
-  /// Changes for custom point color
-
-  inline static const std::string& DEFAULT_COLOR_CONFIG_NAME()
-  {
-    static const std::string RESULT_CONSTRUCTION_COLOR_CONFIG_NAME("result_construction_color");
-    return RESULT_CONSTRUCTION_COLOR_CONFIG_NAME;
-  }
-
-  inline void setColor(const std::string myColor, const std::string & myColorConfigName)
-  {
-    color = myColor;
-    colorConfigName = myColorConfigName;
-  }
-
-  inline const std::string & getColor() const
-  {
-    return color;
-  }
-
-  inline const std::string & getColorConfigName() const
-  {
-    return  colorConfigName;
-  }
-
-private:
-  std::string color;
-  std::string colorConfigName;
-
-public:
-
-  /// Specific properties for point
-  class ModelApi_PointColor
-  {
-  public:
-    /// default color for a point construction
-    inline static const std::string& DEFAULT_COLOR()
-    {
-      static const std::string POINT_CONSTRUCTION_COLOR("85,85,0");
-      return POINT_CONSTRUCTION_COLOR;
-    }
-
-    inline static const std::string COLOR_CONFIG_NAME()
-    {
-      static const std::string POINT_CONFIG_COLOR_NAME("result_point_color");
-      return POINT_CONFIG_COLOR_NAME;
-    }
-  };
-  /*************************************************************************/
 };
 
 //! Pointer on feature object
index f64dfeed72b76622f9163a5b62a7181f8915e508..43b268aab2e772f9b64fb51f225255eb43f1b1e6 100644 (file)
@@ -280,7 +280,6 @@ INCLUDE_DIRECTORIES(
     ${PROJECT_SOURCE_DIR}/src/GeomAPI
     ${PROJECT_SOURCE_DIR}/src/GeomAlgoAPI
     ${PROJECT_SOURCE_DIR}/src/Locale
-    ${PROJECT_SOURCE_DIR}/src/BuildPlugin
     ${SUIT_INCLUDE}
 )
 
index 90436988e58050bbab83df44a1cf544551a9238e..feb6a380a24c291d93119642122fd36d5be7e409 100644 (file)
 #include <ModelAPI_Tools.h>
 #include <ModelAPI_AttributeSelection.h>
 
-#include <BuildPlugin_Face.h>
-#include <BuildPlugin_Wire.h>
-#include <BuildPlugin_Solid.h>
-
 #include <SelectMgr_ListIteratorOfListOfFilter.hxx>
 #include <SelectMgr_EntityOwner.hxx>
 #include <StdSelect_BRepOwner.hxx>
@@ -484,61 +480,6 @@ QList<ModuleBase_ViewerPrsPtr> ModuleBase_WidgetValidated::getFilteredSelected()
 
   filterCompSolids(aSelected);
 
-  if (myFeatureId == BuildPlugin_Face::ID() || myFeatureId == BuildPlugin_Wire::ID() ||
-      myFeatureId == BuildPlugin_Solid::ID())
-  {
-    /// remove objects of sub-type if ojects of correct type is in List,  in some cases :
-    /// - Face builder: edges, faces and wires selected
-    ///                 --> remove edges and wires
-    /// Wire builder: wires and edges selected
-    ///               --> remove egdes
-    /// Solid builder: faces and shapes shells or solids seleted
-    ///                --> remove faces
-
-    std::set<GeomAPI_Shape::ShapeType> shapeTypes;
-    for (auto aSelection: aSelected){
-      auto aShape = aSelection->shape();
-      if (aShape)
-        shapeTypes.insert(aShape->shapeType());
-    }
-
-    std::vector<ModuleBase_ViewerPrsPtr> aRemove;
-
-    if (myFeatureId == BuildPlugin_Face::ID() && shapeTypes.find(GeomAPI_Shape::FACE)
-        != shapeTypes.end())
-    {
-      for(auto aSelection: aSelected){
-        auto aType = aSelection->shape()->shapeType();
-        if (aType == GeomAPI_Shape::WIRE || aType == GeomAPI_Shape::EDGE)
-          aRemove.push_back(aSelection);
-      }
-    }
-    else if (myFeatureId == BuildPlugin_Wire::ID() && shapeTypes.find(GeomAPI_Shape::WIRE)
-             != shapeTypes.end())
-    {
-      for(auto aSelection: aSelected){
-        auto aType = aSelection->shape()->shapeType();
-        if (aType == GeomAPI_Shape::EDGE)
-          aRemove.push_back(aSelection);
-      }
-    }
-    else if (myFeatureId == BuildPlugin_Solid::ID() &&
-             (shapeTypes.find(GeomAPI_Shape::SHAPE) != shapeTypes.end() ||
-              shapeTypes.find(GeomAPI_Shape::SOLID) != shapeTypes.end() ||
-              shapeTypes.find(GeomAPI_Shape::SHELL) != shapeTypes.end()) )
-    {
-      for(auto aSelection: aSelected){
-        auto aType = aSelection->shape()->shapeType();
-        if( aType == GeomAPI_Shape::FACE)
-          aRemove.push_back(aSelection);
-      }
-    }
-
-    for(auto aSelection: aRemove){
-      aSelected.removeOne(aSelection);
-    }
-  }
-
   return aSelected;
 }
 
index 5135f716126abfcfa198a3f1eac9c7e42334611b..22017e06ed7925128712f3bde7d3d9814df1faa9 100644 (file)
@@ -196,26 +196,14 @@ PartSet_Module::PartSet_Module(ModuleBase_IWorkshop* theWshop)
 
   setDefaultConstraintShown();
 
-  //Config_PropManager::registerProp("Visualization", "object_default_color", "Object color",
-  //                                 Config_Prop::Color, "225,225,225");
-
   Config_PropManager::registerProp("Visualization", "result_body_color", "Result color",
     Config_Prop::Color, ModelAPI_ResultBody::DEFAULT_COLOR());
 
   Config_PropManager::registerProp("Visualization", "result_group_color", "Group color",
     Config_Prop::Color, ModelAPI_ResultGroup::DEFAULT_COLOR());
 
-  Config_PropManager::registerProp("Visualization",
-                                   ModelAPI_ResultConstruction::DEFAULT_COLOR_CONFIG_NAME(),
-                                   "Construction color",  Config_Prop::Color,
-                                   ModelAPI_ResultConstruction::DEFAULT_COLOR());
-
-  Config_PropManager::registerProp(
-        "Visualization",
-        ModelAPI_ResultConstruction::ModelApi_PointColor::COLOR_CONFIG_NAME(),
-        "Construction point color", Config_Prop::Color,
-        ModelAPI_ResultConstruction::ModelApi_PointColor::DEFAULT_COLOR());
-
+  Config_PropManager::registerProp("Visualization", ModelAPI_ResultConstruction::RESULT_COLOR_NAME(),
+    "Construction color", Config_Prop::Color, ModelAPI_ResultConstruction::DEFAULT_COLOR());
 
   Config_PropManager::registerProp("Visualization", "result_part_color", "Part color",
     Config_Prop::Color, ModelAPI_ResultPart::DEFAULT_COLOR());
@@ -1395,14 +1383,6 @@ AISObjectPtr PartSet_Module::createPresentation(const ObjectPtr& theObject)
   return anAIS;
 }
 
-//******************************************************
-void getResultColor(const ResultPtr& theResult, std::vector<int>& theColor)
-{
-  ModelAPI_Tools::getColor(theResult, theColor);
-  if (theColor.empty())
-    PartSet_Tools::getDefaultColor(theResult, false, theColor);
-}
-
 //******************************************************
 double getResultDeflection(const ResultPtr& theResult)
 {
@@ -1467,33 +1447,45 @@ void PartSet_Module::customizePresentation(const ObjectPtr& theObject,
   }
   else {
     ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
+    FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
     if (aResult.get()) {
       std::vector<int> aColor;
-      getResultColor(aResult, aColor);
-
-      SessionPtr aMgr = ModelAPI_Session::get();
-      if (aMgr->activeDocument() != aResult->document()) {
+      bool isSameDoc = (ModelAPI_Session::get()->activeDocument() == aResult->document());
+      // Get user defined color for the object
+      ModelAPI_Tools::getColor(aResult, aColor);
+      if (isSameDoc) {
+        bool isCustomized = false;
+        if (aColor.empty() && aFeature.get()) {
+          GeomCustomPrsPtr aCustPrs = std::dynamic_pointer_cast<GeomAPI_ICustomPrs>(aFeature);
+          if (aCustPrs.get()) {
+            isCustomized = aCustPrs->customisePresentation(aResult, thePrs);
+          }
+        }
+        if (!isCustomized) {
+          if (aColor.empty()) {
+            PartSet_Tools::getDefaultColor(aResult, false, aColor);
+          }
+          thePrs->setColor(aColor[0], aColor[1], aColor[2]);
+        }
+      }
+      else {
+        if (aColor.empty()) {
+          PartSet_Tools::getDefaultColor(aResult, false, aColor);
+        }
         QColor aQColor(aColor[0], aColor[1], aColor[2]);
         QColor aNewColor =
           QColor::fromHsvF(aQColor.hueF(), aQColor.saturationF() / 3., aQColor.valueF());
-        aColor[0] = aNewColor.red();
-        aColor[1] = aNewColor.green();
-        aColor[2] = aNewColor.blue();
+        thePrs->setColor(aNewColor.red(), aNewColor.green(), aNewColor.blue());
       }
-      thePrs->setColor(aColor[0], aColor[1], aColor[2]);
-
       thePrs->setDeflection(getResultDeflection(aResult));
-
       thePrs->setTransparency(getResultTransparency(aResult));
 
       /// set texture  parameters
-      if(aResult->hasTextureFile()){
+      if(aResult->hasTextureFile()) {
         setTexture(aResult->getTextureFile(), thePrs);
       }
     }
-    FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
-    if (aFeature.get()) {
-      if (aFeature->getKind() == SketchPlugin_Sketch::ID())
+    if (aFeature.get() && (aFeature->getKind() == SketchPlugin_Sketch::ID())) {
         thePrs->setWidth(2);
     }
   }
index 169ea993dd0f519ebb6e2172b9cb0134765eccc1..fb0750e9dfea1b4453889725238426f56bf2c05d 100644 (file)
@@ -859,12 +859,10 @@ void PartSet_Tools::getDefaultColor(ObjectPtr theObject, const bool isEmptyColor
 {
   theColor.clear();
   // get default color from the preferences manager for the given result
-  if (theColor.empty()) {
-    std::string aSection, aName, aDefault;
-    theObject->colorConfigInfo(aSection, aName, aDefault);
-    if (!aSection.empty() && !aName.empty()) {
-      theColor = Config_PropManager::color(aSection, aName);
-    }
+  std::string aSection, aName, aDefault;
+  theObject->colorConfigInfo(aSection, aName, aDefault);
+  if (!aSection.empty() && !aName.empty()) {
+    theColor = Config_PropManager::color(aSection, aName);
   }
   if (!isEmptyColorValid && theColor.empty()) {
     // all AIS objects, where the color is not set, are in black.
index ea015c6df5232d7dfcad5a0177dcd690529dcf7e..fcfedc192ba827017ea8fd5d46a9fbf7d01fe14a 100644 (file)
  *         Some feature's methods implemented here as dummy to
  *         Base class for all constraints.
  */
-class SketchPlugin_ConstraintBase : public SketchPlugin_Constraint, public GeomAPI_IPresentable,
-                                    public GeomAPI_ICustomPrs
+class SketchPlugin_ConstraintBase : public SketchPlugin_Constraint, public GeomAPI_IPresentable
 {
- public:
-  /// Customize presentation of the feature
-  virtual bool customisePresentation(ResultPtr theResult, AISObjectPtr thePrs,
-                                     std::shared_ptr<GeomAPI_ICustomPrs> theDefaultPrs)
-  {
-    return theDefaultPrs->customisePresentation(theResult, thePrs, theDefaultPrs);
-  }
-
  protected:
   /// \brief Use plugin manager for features creation
   SketchPlugin_ConstraintBase()
index b78a019bccde374fcd12c43ef7c647f5f00449fa..f2cf058bd2cbe7fb21f27e46b737f62182986de2 100644 (file)
@@ -2459,22 +2459,17 @@ void XGUI_Workshop::changeColor(const QObjectPtrList& theObjects)
     ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObject);
     if (aResult.get()) {
       ModelAPI_Tools::getColor(aResult, aColor);
-      if (aColor.empty())
+      if (aColor.empty()) {
+        AISObjectPtr anAISObj = myDisplayer->getAISObject(anObject);
+        if (anAISObj.get()) {
+          aColor.resize(3);
+          anAISObj->getColor(aColor[0], aColor[1], aColor[2]);
+        }
+      }
+      if (aColor.empty()) {
         getDefaultColor(aResult, false, 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]);
       }
     }
-    if (!aColor.empty())
-      break;
   }
   if (aColor.size() != 3)
     return;