Salome HOME
Issue #2029 Change the color of the Sketch when fully constrained
[modules/shaper.git] / src / PartSet / PartSet_Module.cpp
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;
 }