Salome HOME
Bos #24043: EDF 23094 - problem with dump. Fix for nested compounds.
[modules/shaper.git] / src / ModuleBase / ModuleBase_WidgetSelectionFilter.cpp
index 3e3d407d3a1f903f381fa8a7f6e530513ca0478e..741298f5a530da15a11a7bdb076995bbd8479e49 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2014-2020  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
@@ -360,7 +360,6 @@ void ModuleBase_WidgetSelectionFilter::onAddFilter(int theIndex)
   std::string aText = myFiltersCombo->itemText(theIndex).toStdString();
 
   std::list<FilterPtr>::iterator aIt;
-  int i;
   std::string aFilter;
   std::map<std::string, FilterPtr>::const_iterator aFound = myFilters.find(aText);
   if (aFound == myFilters.end()) {
@@ -477,7 +476,25 @@ void ModuleBase_WidgetSelectionFilter::onSelect()
       bool isValid = aSession->filters()->isValid(myFeature, aBody, aSubShape);
       if (isValid) {
         aBuilder.Add(aComp, aTShape);
-        ModuleBase_ViewerPrsPtr aValue(new ModuleBase_ViewerPrs(aObj, aSubShape));
+        // bos #24043: Naming on a compsolid works wrong.
+        // Find a simple sub-result for the ViewerPrs context:
+        ResultBodyPtr aContext = aBody;
+        bool isComposite = aContext->numberOfSubs() > 0;
+        while (isComposite) {
+          isComposite = false;
+          int nbSubs = aContext->numberOfSubs();
+          for (int aSubIndex = 0; aSubIndex < nbSubs; aSubIndex++) {
+            ResultBodyPtr aSubResult = aContext->subResult(aSubIndex);
+            GeomShapePtr aSubResultShape = aSubResult->shape();
+            if (aSubResultShape->isSubShape(aSubShape)) {
+              aContext = aSubResult;
+              isComposite = aContext->numberOfSubs() > 0;
+              break;
+            }
+          }
+        }
+        ModuleBase_ViewerPrsPtr aValue(new ModuleBase_ViewerPrs(aContext, aSubShape));
+        //ModuleBase_ViewerPrsPtr aValue(new ModuleBase_ViewerPrs(aObj, aSubShape));
         myValues.append(aValue);
       }
     }
@@ -521,33 +538,40 @@ void ModuleBase_WidgetSelectionFilter::updatePreview(const TopoDS_Shape& theShap
 
 void ModuleBase_WidgetSelectionFilter::onShowOnly(bool theShow)
 {
-  if (myPreview.IsNull())
-    return;
   Handle(AIS_InteractiveContext) aCtx = myWorkshop->viewer()->AISContext();
-
   if (theShow) {
     AIS_ListOfInteractive aList;
     aCtx->DisplayedObjects(AIS_KOI_Shape, -1, aList);
-    aList.Remove(myPreview);
+    if (!myPreview.IsNull())
+      aList.Remove(myPreview);
     if (aList.Size() > 0)
       myListIO = aList;
   }
   AIS_ListOfInteractive::const_iterator aIt;
   Handle(AIS_Shape) aShapeIO;
+  bool isModified = false;
   for (aIt = myListIO.cbegin(); aIt != myListIO.cend(); aIt++) {
     aShapeIO = Handle(AIS_Shape)::DownCast(*aIt);
     if (!aShapeIO.IsNull()) {
-      if (theShow)
-        aCtx->Erase(aShapeIO, false);
+      if (theShow) {
+        if (aCtx->IsDisplayed(aShapeIO)) {
+          aCtx->Erase(aShapeIO, false);
+          isModified = true;
+        }
+      }
       else {
-        aCtx->Display(aShapeIO, false);
-        std::shared_ptr<GeomAPI_AISObject> anAISObj = AISObjectPtr(new GeomAPI_AISObject());
-        anAISObj->setImpl(new Handle(AIS_InteractiveObject)(aShapeIO));
-        myWorkshop->applyCurrentSelectionModes(anAISObj);
+        if (!aCtx->IsDisplayed(aShapeIO)) {
+          aCtx->Display(aShapeIO, false);
+          std::shared_ptr<GeomAPI_AISObject> anAISObj = AISObjectPtr(new GeomAPI_AISObject());
+          anAISObj->setImpl(new Handle(AIS_InteractiveObject)(aShapeIO));
+          myWorkshop->applyCurrentSelectionModes(anAISObj);
+          isModified = true;
+        }
       }
     }
   }
-  myWorkshop->viewer()->update();
+  if (isModified)
+    myWorkshop->viewer()->update();
 }
 
 void ModuleBase_WidgetSelectionFilter::updateSelectBtn()
@@ -560,11 +584,16 @@ void ModuleBase_WidgetSelectionFilter::updateNumberSelected()
 {
   int aNb = myValues.size();
   myNbLbl->setText(QString::number(aNb));
-  if (aNb == 0)
+  if (aNb == 0) {
     myFeature->setError(translate("Selection is empty").toStdString(), false, false);
+    myShowBtn->setChecked(false);
+    onShowOnly(false);
+    myShowBtn->setEnabled(false);
+  }
   else {
     myFeature->setError("", false, false);
     myFeature->data()->execState(ModelAPI_StateDone);
+    myShowBtn->setEnabled(true);
   }
 }