Salome HOME
Issue #389 Undo/redo problem on sketch line creation
[modules/shaper.git] / src / XGUI / XGUI_SelectionMgr.cpp
index 0cdaecf9ba94fdd830f7faefff3d03f0855f22c4..8304179726f246d4106c5cef7f06256dd71a53b5 100644 (file)
@@ -18,6 +18,8 @@
 #include <ModelAPI_Result.h>
 #include <ModelAPI_Object.h>
 
+#include <SelectMgr_ListIteratorOfListOfFilter.hxx>
+
 XGUI_SelectionMgr::XGUI_SelectionMgr(XGUI_Workshop* theParent)
     : QObject(theParent),
       myWorkshop(theParent)
@@ -41,14 +43,46 @@ void XGUI_SelectionMgr::connectViewers()
 }
 
 //**************************************************************
-void XGUI_SelectionMgr::setSelectedOwners(const SelectMgr_IndexedMapOfOwner& theSelectedOwners)
+void XGUI_SelectionMgr::setSelectedOwners(const SelectMgr_IndexedMapOfOwner& theSelectedOwners,
+                                          bool isUpdateViewer)
 {
+  SelectMgr_IndexedMapOfOwner aSelectedOwners;
+  selection()->selectedOwners(aSelectedOwners);
+
   Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
   for  (Standard_Integer i = 1, n = theSelectedOwners.Extent(); i <= n; i++)  {
-    aContext->AddOrRemoveSelected(theSelectedOwners(i), false);
+    Handle(SelectMgr_EntityOwner) anOwner = theSelectedOwners(i);
+    if (aSelectedOwners.FindIndex(anOwner) > 0)
+      continue;
+
+    aContext->AddOrRemoveSelected(anOwner, isUpdateViewer);
   }
 }
 
+//**************************************************************
+void XGUI_SelectionMgr::updateSelectedOwners(bool isUpdateViewer)
+{
+  Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
+  const SelectMgr_ListOfFilter& aFilters = aContext->Filters();
+
+  SelectMgr_IndexedMapOfOwner anOwnersToDeselect;
+
+  SelectMgr_ListIteratorOfListOfFilter anIt(aFilters);
+  for (; anIt.More(); anIt.Next()) {
+    Handle(SelectMgr_Filter) aFilter = anIt.Value();
+    for (aContext->InitSelected(); aContext->MoreSelected(); aContext->NextSelected()) {
+      Handle(SelectMgr_EntityOwner) anOwner = aContext->SelectedOwner();
+      if (!aFilter->IsOk(anOwner))
+        anOwnersToDeselect.Add(aContext->SelectedOwner());
+    }
+  }
+
+  setSelectedOwners(anOwnersToDeselect, false);
+
+  if (isUpdateViewer)
+    aContext->UpdateCurrentViewer();
+}
+
 //**************************************************************
 void XGUI_SelectionMgr::onObjectBrowserSelection()
 {