Salome HOME
Adjust unit tests
[modules/shaper.git] / src / XGUI / XGUI_FacesPanel.cpp
index f8dde4f9a0661bd87e4d621f718d2ed7dab80458..a815c49ec9632cfb4e820515c131ceaa8ed1d9f6 100644 (file)
@@ -26,6 +26,7 @@
 
 #include <ModelAPI_Events.h>
 
+#include <ModuleBase_IModule.h>
 #include <ModuleBase_ISelection.h>
 #include "ModuleBase_IWorkshop.h"
 #include "ModuleBase_ListView.h"
@@ -33,6 +34,8 @@
 #include "ModuleBase_Tools.h"
 #include "ModuleBase_ViewerPrs.h"
 
+#include "XGUI_SelectionMgr.h"
+#include "XGUI_SelectionFilterType.h"
 #include "XGUI_Tools.h"
 #include "XGUI_Workshop.h"
 
@@ -93,12 +96,29 @@ void XGUI_FacesPanel::reset(const bool isToFlushRedisplay)
   myLastItemIndex = 0; // it should be after redisplay as flag used in customize
 }
 
+//********************************************************************
+bool XGUI_FacesPanel::isEmpty() const
+{
+  return myItems.size() == 0;
+}
+
 //********************************************************************
 void XGUI_FacesPanel::selectionModes(QIntList& theModes)
 {
   theModes.append(TopAbs_FACE);
 }
 
+//********************************************************************
+void XGUI_FacesPanel::selectionFilters(SelectMgr_ListOfFilter& theSelectionFilters)
+{
+  ModuleBase_IModule* aModule = myWorkshop->module();
+  QIntList aModuleSelectionFilters = myWorkshop->module()->selectionFilters();
+
+  theSelectionFilters.Append(aModule->selectionFilter(SF_GlobalFilter));
+  theSelectionFilters.Append(aModule->selectionFilter(SF_FilterInfinite));
+  theSelectionFilters.Append(aModule->selectionFilter(SF_ResultGroupNameFilter));
+}
+
 //********************************************************************
 bool XGUI_FacesPanel::eventFilter(QObject* theObject, QEvent *theEvent)
 {
@@ -121,8 +141,13 @@ void XGUI_FacesPanel::setActivePanel(const bool theIsActive)
   ModuleBase_Tools::setShadowEffect(myListView->getControl(), theIsActive);
   myIsActive = theIsActive;
 
-  if (myIsActive)
+  if (myIsActive) {
     emit activated();
+    // selection should be cleared after emit of signal to do not process selection change
+    // event by the previous selector
+    // the selection is cleared by activating selection control
+    XGUI_Tools::workshop(myWorkshop)->selector()->clearSelection();
+  }
   else
     emit deactivated();
 }
@@ -191,6 +216,9 @@ void XGUI_FacesPanel::processSelection()
                                                        ModuleBase_ISelection::Viewer);
   bool isModified = false;
   static Events_ID aDispEvent = Events_Loop::loop()->eventByName(EVENT_OBJECT_TO_REDISPLAY);
+
+  std::map<ObjectPtr, NCollection_List<TopoDS_Shape> > anObjectToShapes;
+  std::map<ObjectPtr, Handle(ModuleBase_ResultPrs) > anObjectToPrs;
   for (int i = 0; i < aSelected.size(); i++) {
     ModuleBase_ViewerPrsPtr aPrs = aSelected[i];
     ObjectPtr anObject = aPrs->object();
@@ -209,8 +237,23 @@ void XGUI_FacesPanel::processSelection()
     myLastItemIndex++;
     isModified = true;
 
-    if (aResultPrs->hasSubShapeVisible(ModuleBase_Tools::getSelectedShape(aPrs)) ||
-        useTransparency()) // redisplay
+    if (anObjectToShapes.find(anObject) != anObjectToShapes.end())
+      anObjectToShapes.at(anObject).Append(ModuleBase_Tools::getSelectedShape(aPrs));
+    else {
+      NCollection_List<TopoDS_Shape> aListOfShapes;
+      aListOfShapes.Append(ModuleBase_Tools::getSelectedShape(aPrs));
+      anObjectToShapes[anObject] = aListOfShapes;
+      anObjectToPrs[anObject] = aResultPrs;
+    }
+  }
+  for (std::map<ObjectPtr, NCollection_List<TopoDS_Shape> >::const_iterator
+    anIt = anObjectToShapes.begin(); anIt != anObjectToShapes.end(); anIt++) {
+    ObjectPtr anObject = anIt->first;
+    if (!anObject.get() || anObjectToPrs.find(anObject) == anObjectToPrs.end())
+      continue;
+    Handle(ModuleBase_ResultPrs) aResultPrs = anObjectToPrs.at(anObject);
+
+    if (aResultPrs->hasSubShapeVisible(anIt->second) || useTransparency()) // redisplay
       ModelAPI_EventCreator::get()->sendUpdated(anObject, aDispEvent);
     else { // erase object because it is entirely hidden
       anObject->setDisplayed(false);
@@ -322,6 +365,9 @@ bool XGUI_FacesPanel::hideEmptyObjects()
 {
   bool isModified = false;
   static Events_ID aDispEvent = Events_Loop::loop()->eventByName(EVENT_OBJECT_TO_REDISPLAY);
+  std::map<ObjectPtr, NCollection_List<TopoDS_Shape> > anObjectToShapes;
+  std::map<ObjectPtr, Handle(ModuleBase_ResultPrs) > anObjectToPrs;
+
   for (QMap<int, ModuleBase_ViewerPrsPtr>::const_iterator anIt = myItems.begin();
        anIt != myItems.end(); anIt++) {
     ModuleBase_ViewerPrsPtr aPrs = anIt.value();
@@ -334,7 +380,23 @@ bool XGUI_FacesPanel::hideEmptyObjects()
     if (aResultPrs.IsNull())
       continue;
 
-    if (!aResultPrs->hasSubShapeVisible(ModuleBase_Tools::getSelectedShape(aPrs))) {
+    if (anObjectToShapes.find(anObject) != anObjectToShapes.end())
+      anObjectToShapes.at(anObject).Append(ModuleBase_Tools::getSelectedShape(aPrs));
+    else {
+      NCollection_List<TopoDS_Shape> aListOfShapes;
+      aListOfShapes.Append(ModuleBase_Tools::getSelectedShape(aPrs));
+      anObjectToShapes[anObject] = aListOfShapes;
+      anObjectToPrs[anObject] = aResultPrs;
+    }
+  }
+  for (std::map<ObjectPtr, NCollection_List<TopoDS_Shape> >::const_iterator
+    anIt = anObjectToShapes.begin(); anIt != anObjectToShapes.end(); anIt++) {
+    ObjectPtr anObject = anIt->first;
+    if (!anObject.get() || anObjectToPrs.find(anObject) == anObjectToPrs.end())
+      continue;
+    Handle(ModuleBase_ResultPrs) aResultPrs = anObjectToPrs.at(anObject);
+
+    if (!aResultPrs->hasSubShapeVisible(anIt->second)) {
       // erase object because it is entirely hidden
       anObject->setDisplayed(false);
       myHiddenObjects.insert(anObject);