Salome HOME
Issue #2029 Change the color of the Sketch when fully constrained
authornds <nds@opencascade.com>
Thu, 30 Mar 2017 06:02:34 +0000 (09:02 +0300)
committernds <nds@opencascade.com>
Thu, 30 Mar 2017 06:02:53 +0000 (09:02 +0300)
src/ModuleBase/ModuleBase_IModule.h
src/PartSet/PartSet_Module.cpp
src/PartSet/PartSet_Module.h
src/PartSet/PartSet_OverconstraintListener.cpp
src/PartSet/PartSet_OverconstraintListener.h
src/XGUI/XGUI_Displayer.cpp

index b57291d2615e31deba45cffd279967de61f1cf77..f72ad02fd16dd3045131755395562651570ea0e3 100755 (executable)
@@ -229,6 +229,11 @@ class MODULEBASE_EXPORT ModuleBase_IModule : public QObject
                                      AISObjectPtr thePrs,
                                      GeomCustomPrsPtr theCustomPrs) { return false; };
 
+  /// Modifies the given presentation in the custom way after usual customize is performed.
+  virtual bool afterCustomisePresentation(std::shared_ptr<ModelAPI_Result> theResult,
+                                     AISObjectPtr thePrs,
+                                     GeomCustomPrsPtr theCustomPrs) { return false; };
+
   /// Update the object presentable properties such as color, lines width and other
   /// 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
index 13980163387fb97fff304c441ef890e4ab50e620..2d4bc1579a29fd48ae1e8e6b15029bb386f4cdbe 100755 (executable)
@@ -1015,10 +1015,10 @@ bool PartSet_Module::customisePresentation(ResultPtr theResult, AISObjectPtr the
     return aCustomized;
 
   std::vector<int> aColor;
-  bool aCustomColor = myOverconstraintListener->hasCustomColor(anObject, aColor);
+  //bool aCustomColor = myOverconstraintListener->hasCustomColor(anObject, aColor);
 
   if (!theResult.get()) {
-    // customize sketch symbol presentation
+    /*// customize sketch symbol presentation
     if (thePrs.get()) {
       Handle(AIS_InteractiveObject) anAISIO = thePrs->impl<Handle(AIS_InteractiveObject)>();
       if (!anAISIO.IsNull()) {
@@ -1036,19 +1036,76 @@ bool PartSet_Module::customisePresentation(ResultPtr theResult, AISObjectPtr the
           }
         }
       }
+    }*/
+    // customize sketch dimension constraint presentation
+    //if (!aCustomized) {
+    //  if (!aCustomColor)
+    XGUI_CustomPrs::getDefaultColor(anObject, true, aColor);
+    if (!aColor.empty()) {
+      aCustomized = thePrs->setColor(aColor[0], aColor[1], aColor[2]);
+    //  }
     }
+  }
+  // customize dimentional constrains
+  sketchMgr()->customizePresentation(anObject);
+
+  return aCustomized;
+}
+
+bool PartSet_Module::afterCustomisePresentation(std::shared_ptr<ModelAPI_Result> theResult,
+                                                AISObjectPtr thePrs,
+                                                GeomCustomPrsPtr theCustomPrs)
+{
+  bool aCustomized = false;
+
+  XGUI_Workshop* aWorkshop = getWorkshop();
+  XGUI_Displayer* aDisplayer = aWorkshop->displayer();
+  ObjectPtr anObject = aDisplayer->getObject(thePrs);
+  if (!anObject)
+    return aCustomized;
+
+  std::vector<int> aColor;
+  bool aCustomColorChanged = myOverconstraintListener->isNeedUpdateCustomColor();
+  if (aCustomColorChanged) {
+    bool aUseCustomColor = true;
+    // do not use fully constrained color if create operation is started
+    /*if (aWorkshop->operationMgr()->hasOperation()) {
+      ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
+                                           (aWorkshop->operationMgr()->currentOperation());
+      if (aFOperation && !aFOperation->isEditOperation())
+        aUseCustomColor = false;
+    }*/
+    if (aUseCustomColor)
+      myOverconstraintListener->getCustomColor(anObject, aColor);
+    //if (!theResult.get()) {
+    // customize sketch symbol presentation
+    //if (thePrs.get()) {
+      Handle(AIS_InteractiveObject) anAISIO = thePrs->impl<Handle(AIS_InteractiveObject)>();
+      if (!anAISIO.IsNull()) {
+        if (!Handle(SketcherPrs_SymbolPrs)::DownCast(anAISIO).IsNull()) {
+          Handle(SketcherPrs_SymbolPrs) aPrs = Handle(SketcherPrs_SymbolPrs)::DownCast(anAISIO);
+          if (!aPrs.IsNull()) {
+            aPrs->SetCustomColor(aColor);
+            aCustomized = true;
+          }
+        } else if (!Handle(SketcherPrs_Coincident)::DownCast(anAISIO).IsNull()) {
+          Handle(SketcherPrs_Coincident) aPrs = Handle(SketcherPrs_Coincident)::DownCast(anAISIO);
+          if (!aPrs.IsNull()) {
+            aPrs->SetCustomColor(aColor);
+            aCustomized = true;
+          }
+        }
+      }
+    //}
     // customize sketch dimension constraint presentation
     if (!aCustomized) {
-      if (!aCustomColor)
-        XGUI_CustomPrs::getDefaultColor(anObject, true, aColor);
-      if (!aColor.empty()) {
+      //if (!aCustomColor)
+      //  XGUI_CustomPrs::getDefaultColor(anObject, true, aColor);
+      if (!aColor.empty()) { // otherwise presentation has the default color
         aCustomized = thePrs->setColor(aColor[0], aColor[1], aColor[2]);
       }
     }
   }
-  // customize dimentional constrains
-  sketchMgr()->customizePresentation(anObject);
-
   return aCustomized;
 }
 
index 3c7316458e02a0cfc32b22ab124bbd53574f3fa4..2795d2965721b88786a05d76003b061389f192b0 100755 (executable)
@@ -252,6 +252,11 @@ public:
                                      AISObjectPtr thePrs,
                                      std::shared_ptr<GeomAPI_ICustomPrs> theCustomPrs);
 
+  /// Modifies the given presentation in the custom way after usual customize is performed.
+  virtual bool afterCustomisePresentation(std::shared_ptr<ModelAPI_Result> theResult,
+                                          AISObjectPtr thePrs,
+                                          GeomCustomPrsPtr theCustomPrs);
+
   /// Update the object presentable properties such as color, lines width and other
   /// 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
index 40ec725ce0d601393503e8465b63552ff15ec6ab..8dd5af2eb002627505ae916c9f95725784f4390f 100755 (executable)
@@ -29,7 +29,7 @@
 //#define DEBUG_FEATURE_OVERCONSTRAINT_LISTENER
 
 PartSet_OverconstraintListener::PartSet_OverconstraintListener(ModuleBase_IWorkshop* theWorkshop)
-: myWorkshop(theWorkshop), myIsFullyConstrained(false)
+: myWorkshop(theWorkshop), myIsFullyConstrained(false), myIsNeedUpdateCustomColor(false)
 {
   Events_Loop* aLoop = Events_Loop::loop();
   aLoop->registerListener(this, Events_Loop::eventByName(EVENT_SOLVER_FAILED));
@@ -39,7 +39,7 @@ PartSet_OverconstraintListener::PartSet_OverconstraintListener(ModuleBase_IWorks
   aLoop->registerListener(this, Events_Loop::eventByName(EVENT_SKETCH_FULLY_CONSTRAINED));
 }
 
-bool PartSet_OverconstraintListener::hasCustomColor(const ObjectPtr& theObject,
+void PartSet_OverconstraintListener::getCustomColor(const ObjectPtr& theObject,
                                                     std::vector<int>& theColor)
 {
   if (myConflictingObjects.find(theObject) != myConflictingObjects.end()) {
@@ -48,7 +48,6 @@ bool PartSet_OverconstraintListener::hasCustomColor(const ObjectPtr& theObject,
     theColor.push_back(aColor.Red()*255.);
     theColor.push_back(aColor.Green()*255.);
     theColor.push_back(aColor.Blue()*255.);
-    return true;
   }
   if (myIsFullyConstrained) {
     FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
@@ -59,14 +58,12 @@ bool PartSet_OverconstraintListener::hasCustomColor(const ObjectPtr& theObject,
       if (ModelAPI_Tools::compositeOwner(aFeature) == aCompositeFeature) {
         Quantity_Color aColor = ModuleBase_Tools::color("Visualization",
                                                         "sketch_fully_constrained_color");
-        theColor.push_back(aColor.Red()*255.);
+        theColor.push_back(aColor.Red()*0.);
         theColor.push_back(aColor.Green()*255.);
-        theColor.push_back(aColor.Blue()*255.);
-        return true;
+        theColor.push_back(aColor.Blue()*0.);
       }
     }
   }
-  return false;
 }
 
 void PartSet_OverconstraintListener::processEvent(
@@ -114,6 +111,7 @@ void PartSet_OverconstraintListener::processEvent(
     myIsFullyConstrained = anEventID == Events_Loop::eventByName(EVENT_SKETCH_FULLY_CONSTRAINED);
 
     if (aPrevFullyConstrained != myIsFullyConstrained) {
+      myIsNeedUpdateCustomColor = true;
       std::set<ObjectPtr> aModifiedObjects;
       PartSet_Module* aModule = dynamic_cast<PartSet_Module*>(myWorkshop->module());
       CompositeFeaturePtr aSketch = aModule->sketchMgr()->activeSketch();
@@ -127,6 +125,7 @@ void PartSet_OverconstraintListener::processEvent(
         }
       }
       redisplayObjects(aModifiedObjects);
+      myIsNeedUpdateCustomColor = false;
     }
   }
 
index 4eaf5c8059c48d7ae1ea839f7cb098468a58e9a1..4051c0c9558c175f5f4e7abbc6bf8a257c62fbc7 100755 (executable)
@@ -42,7 +42,11 @@ public:
   /// \param theObject an object to be checked
   /// \param theColor the output container to be filled in [red, green, blue] values
   /// \return boolean result
-  bool hasCustomColor(const ObjectPtr& theObject, std::vector<int>& theColor);
+  void getCustomColor(const ObjectPtr& theObject, std::vector<int>& theColor);
+
+  /// Returns true if custom color of presentations is changed and it should be redisplayed
+  /// \return boolean value
+  bool isNeedUpdateCustomColor() const { return true;/*myIsNeedUpdateCustomColor;*/ }
 
   /// Redefinition of Events_Listener method
   virtual void processEvent(const std::shared_ptr<Events_Message>& theMessage);
@@ -77,6 +81,7 @@ private:
   std::set<ObjectPtr> myConflictingObjects;
   ModuleBase_IWorkshop* myWorkshop;
   bool myIsFullyConstrained; /// state if Solver is fully constrained, DOF = 0
+  bool myIsNeedUpdateCustomColor;
 };
 
 #endif
index 3970d8b32b2a6758e6e19fb8d6dd463ce2ec40a8..5d879f42a6b10016649f1fd243d9358f20d33038 100644 (file)
@@ -1351,6 +1351,7 @@ bool XGUI_Displayer::activate(const Handle(AIS_InteractiveObject)& theIO,
   return isActivationChanged;
 }
 
+//#define DEBUG_FULLY_CONSTRAINED
 bool XGUI_Displayer::customizeObject(ObjectPtr theObject)
 {
   AISObjectPtr anAISObj = getAISObject(theObject);
@@ -1373,6 +1374,9 @@ bool XGUI_Displayer::customizeObject(ObjectPtr theObject)
   }
   bool isCustomized = aCustomPrs.get() &&
                       aCustomPrs->customisePresentation(aResult, anAISObj, myCustomPrs);
+#ifdef DEBUG_FULLY_CONSTRAINED
+  isCustomized = myWorkshop->module()->afterCustomisePresentation(aResult, anAISObj, myCustomPrs) || isCustomized;
+#endif
   return isCustomized;
 }