Salome HOME
Update viewer on delete an item
[modules/shaper.git] / src / XGUI / XGUI_Displayer.cpp
index 3ff7886e03f42dd300e4f0e33aca68a17707ba35..ccad93e0e2325f4d0a776c4c8a9044ebb5b3af85 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2014-2017  CEA/DEN, EDF R&D
+// Copyright (C) 2014-2019  CEA/DEN, EDF R&D
 //
 // This library is free software; you can redistribute it and/or
 // modify it under the terms of the GNU Lesser General Public
 //
 // You should have received a copy of the GNU Lesser General Public
 // License along with this library; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
 //
-// See http://www.salome-platform.org/ or
-// email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
 //
 
 #include "XGUI_Displayer.h"
@@ -38,6 +37,7 @@
 #include <ModelAPI_Tools.h>
 #include <ModelAPI_AttributeIntArray.h>
 #include <ModelAPI_ResultBody.h>
+#include <ModelAPI_ResultConstruction.h>
 
 #include <ModuleBase_BRepOwner.h>
 #include <ModuleBase_IModule.h>
@@ -86,6 +86,7 @@
 
 #include <Events_Loop.h>
 #include <ModelAPI_Events.h>
+#include <Config_PropManager.h>
 
 #include <set>
 
@@ -96,8 +97,6 @@ const int MOUSE_SENSITIVITY_IN_PIXEL = 10;
 //#define DEBUG_FEATURE_REDISPLAY
 //#define DEBUG_SELECTION_FILTERS
 
-//#define DEBUG_COMPOSILID_DISPLAY
-
 //#define DEBUG_OCCT_SHAPE_SELECTION
 
 #define CLEAR_OUTDATED_SELECTION_BEFORE_REDISPLAY
@@ -145,20 +144,6 @@ bool XGUI_Displayer::display(ObjectPtr theObject, bool theUpdateViewer)
 {
   bool aDisplayed = false;
   if (isVisible(theObject)) {
-#ifdef DEBUG_COMPOSILID_DISPLAY
-    ResultCompSolidPtr aCompsolidResult =
-      std::dynamic_pointer_cast<ModelAPI_ResultCompSolid>(theObject);
-    if (aCompsolidResult.get()) {
-      for(int i = 0; i < aCompsolidResult->numberOfSubs(); i++) {
-        ResultPtr aSubResult = aCompsolidResult->subResult(i);
-        if (aSubResult.get())
-          redisplay(aSubResult, false);
-      }
-      if (theUpdateViewer)
-        updateViewer();
-    }
-    else
-#endif
     aDisplayed = redisplay(theObject, theUpdateViewer);
   } else {
     AISObjectPtr anAIS;
@@ -171,55 +156,24 @@ bool XGUI_Displayer::display(ObjectPtr theObject, bool theUpdateViewer)
         aScreen->setViewScale(getViewScale());
       }
       anAIS = aPrs->getAISObject(anAIS);
-      //if (anAIS.get()) {
-        // correct deviation coefficient for
-        /*Handle(AIS_InteractiveObject) anAISPrs = anAIS->impl<Handle(AIS_InteractiveObject)>();
-        if (!anAISPrs.IsNull()) {
-          Handle(AIS_Shape) aShapePrs = Handle(AIS_Shape)::DownCast(anAISPrs);
-          if (!aShapePrs.IsNull()) {
-            TopoDS_Shape aShape = aShapePrs->Shape();
-            if (!aShape.IsNull())
-              //ModuleBase_Tools::setDefaultDeviationCoefficient(aShape, anAISPrs->Attributes());
-          }
-        }*/
-      //}
     } else {
-      ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
-      if (aResult.get() != NULL) {
-#ifdef DEBUG_COMPOSILID_DISPLAY
-        ResultCompSolidPtr aCompsolidResult =
-          std::dynamic_pointer_cast<ModelAPI_ResultCompSolid>(theObject);
-        if (aCompsolidResult.get()) {
-          for(int i = 0; i < aCompsolidResult->numberOfSubs(); i++) {
-            ResultPtr aSubResult = aCompsolidResult->subResult(i);
-            if (aSubResult.get())
-              display(aSubResult, false);
-          }
-          if (theUpdateViewer)
-            updateViewer();
-        }
-        else {
-#endif
-        std::shared_ptr<GeomAPI_Shape> aShapePtr = ModelAPI_Tools::shape(aResult);
-        if (aShapePtr.get() != NULL) {
-          anAIS = AISObjectPtr(new GeomAPI_AISObject());
-          Handle(AIS_InteractiveObject) anAISPrs =
-            myWorkshop->module()->createPresentation(aResult);
-          if (anAISPrs.IsNull())
-            anAISPrs = new ModuleBase_ResultPrs(aResult);
-          else {
-            Handle(AIS_Shape) aShapePrs = Handle(AIS_Shape)::DownCast(anAISPrs);
-            if (!aShapePrs.IsNull())
-              ModuleBase_Tools::setPointBallHighlighting((AIS_Shape*) aShapePrs.get());
+      Handle(AIS_InteractiveObject) anAISPrs =
+        myWorkshop->module()->createPresentation(theObject);
+      if (anAISPrs.IsNull()) {
+        ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
+        if (aResult.get() != NULL) {
+          std::shared_ptr<GeomAPI_Shape> aShapePtr = ModelAPI_Tools::shape(aResult);
+          if (aShapePtr.get() != NULL) {
+             anAISPrs = new ModuleBase_ResultPrs(aResult);
           }
-          anAIS->setImpl(new Handle(AIS_InteractiveObject)(anAISPrs));
-          //anAIS->createShape(aShapePtr);
-          isShading = true;
         }
-#ifdef DEBUG_COMPOSILID_DISPLAY
-        } // close else
-#endif
       }
+      Handle(AIS_Shape) aShapePrs = Handle(AIS_Shape)::DownCast(anAISPrs);
+      if (!aShapePrs.IsNull())
+        ModuleBase_Tools::setPointBallHighlighting((AIS_Shape*)aShapePrs.get());
+      anAIS = AISObjectPtr(new GeomAPI_AISObject());
+      anAIS->setImpl(new Handle(AIS_InteractiveObject)(anAISPrs));
+      isShading = true;
     }
     if (anAIS)
       aDisplayed = display(theObject, anAIS, isShading, theUpdateViewer);
@@ -227,6 +181,7 @@ bool XGUI_Displayer::display(ObjectPtr theObject, bool theUpdateViewer)
   return aDisplayed;
 }
 
+
 //**************************************************************
 bool canBeShaded(Handle(AIS_InteractiveObject) theAIS, ModuleBase_IModule* theModule)
 {
@@ -342,6 +297,7 @@ bool XGUI_Displayer::redisplay(ObjectPtr theObject, bool theUpdateViewer)
       return aRedisplayed;
     }
     if (aAIS_Obj != aAISObj) {
+      erase(theObject, theUpdateViewer);
       appendResultObject(theObject, aAIS_Obj);
     }
     aAISIO = aAIS_Obj->impl<Handle(AIS_InteractiveObject)>();
@@ -385,7 +341,10 @@ bool XGUI_Displayer::redisplay(ObjectPtr theObject, bool theUpdateViewer)
 #ifdef CLEAR_OUTDATED_SELECTION_BEFORE_REDISPLAY
       myWorkshop->selector()->deselectPresentation(aAISIO);
 #endif
-      aContext->Redisplay(aAISIO, false);
+      if (aContext->IsDisplayed(aAISIO))
+        aContext->Redisplay(aAISIO, false);
+      else
+        aContext->Display(aAISIO, false);
 
       #ifdef TINSPECTOR
       if (getCallBack()) getCallBack()->Redisplay(aAISIO);
@@ -411,11 +370,16 @@ void XGUI_Displayer::redisplayObjects()
   // redisplay objects visualized in the viewer
   static Events_ID EVENT_DISP = Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY);
   static const ModelAPI_EventCreator* aECreator = ModelAPI_EventCreator::get();
-  QObjectPtrList aDisplayed = myWorkshop->displayer()->displayedObjects();
+  QObjectPtrList aDisplayed = displayedObjects();
   QObjectPtrList::const_iterator anIt = aDisplayed.begin(), aLast = aDisplayed.end();
   for (; anIt != aLast; anIt++) {
     aECreator->sendUpdated(*anIt, EVENT_DISP);
   }
+  XGUI_ViewerProxy* aViewer = myWorkshop->viewer();
+  if (aViewer->isColorScaleVisible()) {
+    aViewer->setupColorScale();
+    aViewer->setColorScaleShown(true);
+  }
   Events_Loop::loop()->flush(EVENT_DISP);
 }
 
@@ -450,8 +414,9 @@ bool XGUI_Displayer::isVisible(XGUI_Displayer* theDisplayer, const ObjectPtr& th
     if (!aVisible && aResult.get() && aResult->groupName() == ModelAPI_ResultBody::group()) {
       ResultBodyPtr aCompsolidResult = std::dynamic_pointer_cast<ModelAPI_ResultBody>(aResult);
       if (aCompsolidResult.get() != NULL) { // change colors for all sub-solids
-        bool anAllSubsVisible = aCompsolidResult->numberOfSubs() > 0;
-        for(int i = 0; i < aCompsolidResult->numberOfSubs() && anAllSubsVisible; i++) {
+        int aNumberOfSubs = aCompsolidResult->numberOfSubs();
+        bool anAllSubsVisible = aNumberOfSubs > 0;
+        for(int i = 0; i < aNumberOfSubs && anAllSubsVisible; i++) {
           anAllSubsVisible = theDisplayer->isVisible(aCompsolidResult->subResult(i));
         }
         aVisible = anAllSubsVisible;
@@ -653,12 +618,6 @@ bool XGUI_Displayer::enableUpdateViewer(const bool isEnabled)
   return aWasEnabled;
 }
 
-//**************************************************************
-bool XGUI_Displayer::isUpdateEnabled() const
-{
-  return myViewerBlockedRecursiveCount == 0;
-}
-
 //**************************************************************
 void XGUI_Displayer::updateViewer() const
 {
@@ -688,7 +647,18 @@ Handle(AIS_InteractiveContext) XGUI_Displayer::AISContext() const
       selectionActivate()->deactivateTrihedron(true);
     aContext->DefaultDrawer()->VIsoAspect()->SetNumber(0);
     aContext->DefaultDrawer()->UIsoAspect()->SetNumber(0);
+
     ModuleBase_IViewer::DefaultHighlightDrawer = aContext->HighlightStyle();
+    // Commented out according to discussion in bug #2825
+    //Handle(Prs3d_Drawer) aSelStyle = aContext->SelectionStyle();
+    //double aDeflection =
+    //  QString(ModelAPI_ResultConstruction::DEFAULT_DEFLECTION().c_str()).toDouble();
+    //try {
+    //  aDeflection = Config_PropManager::real("Visualization", "construction_deflection");
+    //} catch (...) {}
+
+    //ModuleBase_IViewer::DefaultHighlightDrawer->SetDeviationCoefficient(aDeflection);
+    //aSelStyle->SetDeviationCoefficient(aDeflection);
   }
   return aContext;
 }
@@ -1085,8 +1055,6 @@ void XGUI_Displayer::displayTrihedron(bool theToDisplay) const
     if (getCallBack()) getCallBack()->Remove(aTrihedron);
     #endif
   }
-
-  updateViewer();
 }
 
 //**************************************************************
@@ -1107,12 +1075,12 @@ void XGUI_Displayer::AddOrRemoveSelectedShapes(Handle(AIS_InteractiveContext) th
   /// If count of calls setSelectec is even, the object stays in the previous state
   /// (selected, deselected)
   /// OCCT: to write about the problem that active owners method returns one owner several times
-  QList<long> aSelectedIds; // Remember of selected address in order to avoid duplicates
+  QList<size_t> aSelectedIds; // Remember of selected address in order to avoid duplicates
   for (; anOwnersIt.More(); anOwnersIt.Next()) {
     anOwner = Handle(SelectMgr_EntityOwner)::DownCast (anOwnersIt.Value());
-    if (aSelectedIds.contains((long)anOwner.get()))
+    if (aSelectedIds.contains((size_t)anOwner.get()))
       continue;
-    aSelectedIds.append((long)anOwner.get());
+    aSelectedIds.append((size_t)anOwner.get());
 
     Handle(StdSelect_BRepOwner) BROwnr = Handle(StdSelect_BRepOwner)::DownCast(anOwner);
     if (!BROwnr.IsNull() && BROwnr->HasShape()) {
@@ -1126,17 +1094,21 @@ void XGUI_Displayer::AddOrRemoveSelectedShapes(Handle(AIS_InteractiveContext) th
                                              ::Iterator aShapeIt(theShapesToBeSelected);
       for (; aShapeIt.More(); aShapeIt.Next()) {
         const TopoDS_Shape& aParameterShape = aShapeIt.Key();
-        // isSame should be used here as it does not check orientation of shapes
-        // despite on isEqual of shapes or IsBound for shape in QMap. Orientation is
-        // different for Edges shapes in model shape and owner even if this is the same shape
-        if (aParameterShape.IsSame(aShape)) {
+        // In case of compound we cannot rely on simple comparison method.
+        // If the compound is generated by Group feature then this compound is alwais new.
+        // So, we have to compare content of these compounds
+
+          // isSame should be used here as it does not check orientation of shapes
+          // despite on isEqual of shapes or IsBound for shape in QMap. Orientation is
+          // different for Edges shapes in model shape and owner even if this is the same shape
+        if (ModuleBase_Tools::isSameShape(aParameterShape, aShape)) {
           Handle(AIS_InteractiveObject) anOwnerPresentation =
-                            Handle(AIS_InteractiveObject)::DownCast(anOwner->Selectable());
+            Handle(AIS_InteractiveObject)::DownCast(anOwner->Selectable());
           NCollection_Map<Handle(AIS_InteractiveObject)> aPresentations =
-                                      theShapesToBeSelected.Find(aParameterShape);
+            theShapesToBeSelected.Find(aParameterShape);
           if (aPresentations.Contains(anOwnerPresentation)) {
             theContext->AddOrRemoveSelected(anOwner, Standard_False);
-            anOwner->SetSelected (Standard_True);
+            anOwner->SetSelected(Standard_True);
             // collect selected presentations to do not select them if compsolid is selected
             if (!aSelectedPresentations.Contains(anOwnerPresentation))
               aSelectedPresentations.Add(anOwnerPresentation);