]> SALOME platform Git repositories - modules/shaper.git/blobdiff - src/XGUI/XGUI_Displayer.cpp
Salome HOME
Restore selection in the viewer by multi selector widget activation.
[modules/shaper.git] / src / XGUI / XGUI_Displayer.cpp
index c30e93d56f11d84742e596fcf9566716b6674fa2..430556d295d9c5e2e8bc5d8e79750747343a9bde 100644 (file)
@@ -47,6 +47,7 @@ const int MOUSE_SENSITIVITY_IN_PIXEL = 10;  ///< defines the local context mouse
 //#define DEBUG_ACTIVATE
 //#define DEBUG_FEATURE_REDISPLAY
 //#define DEBUG_SELECTION_FILTERS
+//#define DEBUG_USE_CLEAR_OUTDATED_SELECTION
 
 // Workaround for bug #25637
 void displayedObjects(const Handle(AIS_InteractiveContext)& theAIS, AIS_ListOfInteractive& theList)
@@ -240,10 +241,8 @@ void XGUI_Displayer::redisplay(ObjectPtr theObject, bool isUpdateViewer)
       if (!aShapePrs.IsNull()) {
         std::shared_ptr<GeomAPI_Shape> aShapePtr = ModelAPI_Tools::shape(aResult);
         if (aShapePtr.get()) {
-          const TopoDS_Shape& aShape = aShapePrs->Shape();
-          std::shared_ptr<GeomAPI_Shape> anAISShapePtr(new GeomAPI_Shape());
-          anAISShapePtr->setImpl(new TopoDS_Shape(aShape));
-          isEqualShapes = aShapePtr->isEqual(anAISShapePtr);
+          const TopoDS_Shape& aOldShape = aShapePrs->Shape();
+          isEqualShapes = aOldShape.IsEqual(aShapePtr->impl<TopoDS_Shape>());
         }
       }
     }
@@ -274,6 +273,10 @@ void XGUI_Displayer::deactivate(ObjectPtr theObject)
     AISObjectPtr anObj = myResult2AISObjectMap[theObject];
     Handle(AIS_InteractiveObject) anAIS = anObj->impl<Handle(AIS_InteractiveObject)>();
     aContext->Deactivate(anAIS);
+#ifdef DEBUG_USE_CLEAR_OUTDATED_SELECTION
+    aContext->LocalContext()->ClearOutdatedSelection(anAIS, true);
+    updateViewer();
+#endif
   }
 }
 
@@ -390,6 +393,10 @@ void XGUI_Displayer::deactivateObjects()
   for(aLIt.Initialize(aPrsList); aLIt.More(); aLIt.Next()){
     anAISIO = aLIt.Value();
     aContext->Deactivate(anAISIO);
+#ifdef DEBUG_USE_CLEAR_OUTDATED_SELECTION
+    aContext->LocalContext()->ClearOutdatedSelection(anAISIO, true);
+    updateViewer();
+#endif
   }
 }
 
@@ -421,8 +428,13 @@ void XGUI_Displayer::setSelected(const QObjectPtrList& theResults, const bool is
       if (isVisible(aResult)) {
         AISObjectPtr anObj = myResult2AISObjectMap[aResult];
         Handle(AIS_InteractiveObject) anAIS = anObj->impl<Handle(AIS_InteractiveObject)>();
-        if (!anAIS.IsNull())
-          aContext->SetSelected(anAIS, false);
+        if (!anAIS.IsNull()) {
+          // The methods are replaced in order to provide multi-selection, e.g. restore selection
+          // by activating multi selector widget. It also gives an advantage that the multi
+          // selection in OB gives multi-selection in the viewer
+          //aContext->SetSelected(anAIS, false);
+          aContext->AddOrRemoveSelected(anAIS, false);
+        }
       }
     }
   } else {
@@ -590,7 +602,7 @@ bool XGUI_Displayer::enableUpdateViewer(const bool isEnabled)
   return aWasEnabled;
 }
 
-void XGUI_Displayer::updateViewer()
+void XGUI_Displayer::updateViewer() const
 {
   Handle(AIS_InteractiveContext) aContext = AISContext();
   if (!aContext.IsNull() && myEnableUpdateViewer)
@@ -672,6 +684,8 @@ void XGUI_Displayer::setDisplayMode(ObjectPtr theObject, DisplayMode theMode, bo
     closeLocalContexts(false);
   }
   aContext->SetDisplayMode(aAISIO, theMode, false);
+  // Redisplay in order to update new mode because it could be not computed before
+  aContext->Redisplay(aAISIO, false);
   if (aCanBeShaded) {
     openLocalContext();
     activateObjects(myActiveSelectionModes);
@@ -788,6 +802,7 @@ void XGUI_Displayer::activate(const Handle(AIS_InteractiveObject)& theIO,
   aContext->ActivatedModes(theIO, aTColModes);
   TColStd_ListIteratorOfListOfInteger itr( aTColModes );
   QIntList aModesActivatedForIO;
+  //bool isDeactivated = false;
   for (; itr.More(); itr.Next() ) {
     Standard_Integer aMode = itr.Value();
     if (!theModes.contains(aMode)) {
@@ -795,6 +810,7 @@ void XGUI_Displayer::activate(const Handle(AIS_InteractiveObject)& theIO,
       qDebug(QString("deactivate: %1").arg(aMode).toStdString().c_str());
 #endif
       aContext->Deactivate(theIO, aMode);
+      //isDeactivated = true;
     }
     else {
       aModesActivatedForIO.append(aMode);
@@ -803,6 +819,12 @@ void XGUI_Displayer::activate(const Handle(AIS_InteractiveObject)& theIO,
 #endif
     }
   }
+#ifdef DEBUG_USE_CLEAR_OUTDATED_SELECTION
+  if (isDeactivated) {
+    aContext->LocalContext()->ClearOutdatedSelection(theIO, true);
+    updateViewer();
+  }
+#endif
   // loading the interactive object allowing the decomposition
   if (aTColModes.IsEmpty())
     aContext->Load(theIO, -1, true);