Salome HOME
Merge branch 'csgroup_IS2'
[modules/shaper.git] / src / XGUI / XGUI_FacesPanel.cpp
index e623a7e9098b3b67b19b11989838f67f036fa694..e3a649bc65470ad39d872ad2dff353ac463baa34 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2014-2019  CEA/DEN, EDF R&D
+// Copyright (C) 2014-2021  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
 #include <ModelAPI_Events.h>
 #include <ModelAPI_AttributeSelectionList.h>
 
+#include <ModuleBase_Operation.h>
+#include <ModuleBase_OperationFeature.h>
+#include <XGUI_OperationMgr.h>
+
 #include <QAction>
 #include <QCheckBox>
 #include <QFocusEvent>
@@ -88,12 +92,12 @@ void updateHiddenShapes(Handle(ModuleBase_ResultPrs) thePrs, const TopoDS_ListOf
 
 //********************************************************************
 XGUI_FacesPanel::XGUI_FacesPanel(QWidget* theParent, XGUI_Workshop* theWorkshop)
-  : QDockWidget(theParent), myIsActive(false), myWorkshop(theWorkshop)
+  : QDockWidget(theParent), myWorkshop(theWorkshop), myIsActive(false)
 {
   setWindowTitle(tr("Hide Faces"));
   setObjectName("Hide Faces");
 
-  QAction* aViewAct = toggleViewAction();
+  MAYBE_UNUSED QAction* aViewAct = toggleViewAction();
   setStyleSheet("::title { position: relative; padding-left: 5px; text-align: left center }");
 
   QWidget* aContent = new QWidget(this);
@@ -207,8 +211,10 @@ void XGUI_FacesPanel::setActivePanel(const bool theIsActive)
     // the selection is cleared by activating selection control
     myWorkshop->selector()->clearSelection();
   }
-  else
+  else{
     emit deactivated();
+    myUndoList.clear();
+  }
 }
 
 //********************************************************************
@@ -379,7 +385,7 @@ void XGUI_FacesPanel::processSelection()
     }
 
     QString aItemName = aResGroup.get()?
-      aResGroup->data()->name().c_str() : XGUI_Tools::generateName(aPrs);
+      QString::fromStdWString(aResGroup->data()->name()) : XGUI_Tools::generateName(aPrs);
     if (myListView->hasItem(aItemName))
       continue;
 
@@ -397,14 +403,14 @@ void XGUI_FacesPanel::processSelection()
     // It can happen in case of groups selection
     QMap<int, ModuleBase_ViewerPrsPtr>::const_iterator aIt;
     for (aIt = myItems.cbegin(); aIt != myItems.cend(); aIt++) {
-      ModuleBase_ViewerPrsPtr aPrs = aIt.value();
-      ObjectPtr aObject = aPrs->object();
-      ResultGroupPtr aResGroup = std::dynamic_pointer_cast<ModelAPI_ResultGroup>(aObject);
-      if (aResGroup.get())
+      ModuleBase_ViewerPrsPtr aCurPrs = aIt.value();
+      ObjectPtr aObject = aCurPrs->object();
+      ResultGroupPtr aCurResGroup = std::dynamic_pointer_cast<ModelAPI_ResultGroup>(aObject);
+      if (aCurResGroup.get())
         continue;
       if (anObjectToShapes.find(aObject) != anObjectToShapes.end()) {
         TopoDS_ListOfShape aShapes = anObjectToShapes[aObject];
-        GeomShapePtr aShapePtr = aPrs->shape();
+        GeomShapePtr aShapePtr = aCurPrs->shape();
         if (aShapes.Contains(aShapePtr->impl<TopoDS_Shape>())) {
           aToRemove.insert(aIt.key());
         }
@@ -413,6 +419,8 @@ void XGUI_FacesPanel::processSelection()
 
     myItems.insert(myLastItemIndex, aPrs);
     myListView->addItem(aItemName, myLastItemIndex);
+    // add in undo list
+    myUndoList.push_back(myLastItemIndex);
     myLastItemIndex++;
     isModified = true;
   }
@@ -462,14 +470,13 @@ void XGUI_FacesPanel::processSelection()
 bool XGUI_FacesPanel::processDelete()
 {
   //appendFirstSelectionInHistory();
-  QModelIndexList anIndices = myListView->getControl()->selectionModel()->selectedIndexes();
+  //QModelIndexList anIndices = myListView->getControl()->selectionModel()->selectedIndexes();
 
   std::set<int> aSelectedIds;
   myListView->getSelectedIndices(aSelectedIds);
   if (aSelectedIds.empty())
     return false;
 
-  bool isModified = false;
   std::set<ModuleBase_ViewerPrsPtr> aRestored;
   std::set<int>::const_iterator anIt;
   for (anIt = aSelectedIds.begin(); anIt != aSelectedIds.end(); anIt++) {
@@ -477,7 +484,6 @@ bool XGUI_FacesPanel::processDelete()
     if (aRestored.find(aPrs) == aRestored.end()) {
       aRestored.insert(aPrs);
       myItems.remove(*anIt);
-      isModified = true;
     }
   }
   std::map<ObjectPtr, TopoDS_ListOfShape> anObjectToShapes;
@@ -606,6 +612,18 @@ void XGUI_FacesPanel::onClosed()
   reset(true);
 }
 
+//********************************************************************
+
+void XGUI_FacesPanel::processUndo()
+{
+ if(!myUndoList.size())
+   return;
+
+ myListView->selectIndices({myUndoList.back()});
+ processDelete();
+ myUndoList.pop_back();
+}
+
 //********************************************************************
 void XGUI_FacesPanel::flushRedisplay() const
 {
@@ -649,14 +667,14 @@ void XGUI_FacesPanel::onObjectDisplay(ObjectPtr theObject, AISObjectPtr theAIS)
           // corresponded faces have been restored
           for (aSIt = aObjectToShapes.begin(); aSIt != aObjectToShapes.end(); aSIt++) {
             TopoDS_ListOfShape aShapes = aSIt->second;
-            Handle(ModuleBase_ResultPrs) aPrs = aObjectToPrs[aSIt->first];
-            TopoDS_ListOfShape aAlreadyHidden = aPrs->hiddenSubShapes();
+            Handle(ModuleBase_ResultPrs) aResPrs = aObjectToPrs[aSIt->first];
+            TopoDS_ListOfShape aAlreadyHidden = aResPrs->hiddenSubShapes();
             TopoDS_ListOfShape::Iterator aShPIt(aShapes);
             for (; aShPIt.More(); aShPIt.Next()) {
               if (aAlreadyHidden.Contains(aShPIt.Value()))
                 aAlreadyHidden.Remove(aShPIt.Value());
             }
-            aPrs->setSubShapeHidden(aAlreadyHidden);
+            aResPrs->setSubShapeHidden(aAlreadyHidden);
             aObjects.insert(aSIt->first);
           }
           aIdsToRem.insert(aIt.key());
@@ -667,7 +685,6 @@ void XGUI_FacesPanel::onObjectDisplay(ObjectPtr theObject, AISObjectPtr theAIS)
           if (aPIt != aObjectToPrs.end()) {
             ObjectPtr aObj = aPIt->first;
             if (aObj == theObject) {
-              Handle(ModuleBase_ResultPrs) aPrs = aPIt->second;
               TopoDS_ListOfShape aShapes = aObjectToShapes[aObj];
               aHideShapes.Append(aShapes);
               aObjects.insert(aObj);