Salome HOME
Issue #2948: Synchronize selection for filters controls
[modules/shaper.git] / src / ModuleBase / ModuleBase_WidgetValidated.cpp
index 16b47680e337ab0a01b3dfd3951c90d9b3228d4a..3664c25c1d9bd4900ba01180c995eec107fcf874 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2014-2017  CEA/DEN, EDF R&D
+// Copyright (C) 2014-2019  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
 //
 // You should have received a copy of the GNU Lesser General Public
 // License along with this library; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
 //
-// See http://www.salome-platform.org/ or
-// email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
 //
 
 #include <ModuleBase_WidgetValidated.h>
@@ -117,7 +116,8 @@ bool ModuleBase_WidgetValidated::isValidInFilters(const ModuleBase_ViewerPrsPtr&
       myPresentedObject = aResult;
     }
     else {
-      FeaturePtr aFeature = ModelAPI_Feature::feature(thePrs->object());
+      //FeaturePtr aFeature = ModelAPI_Feature::feature(thePrs->object());
+      FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(thePrs->object());
       if (aFeature.get()) {
         // Use feature as a reference to all its results
         myPresentedObject = aFeature;
@@ -141,7 +141,7 @@ bool ModuleBase_WidgetValidated::isValidInFilters(const ModuleBase_ViewerPrsPtr&
           }
           else
             aValid = false;
-          aSelectAttr->setValue(ObjectPtr(), GeomShapePtr(), true);
+          //aSelectAttr->setValue(ObjectPtr(), GeomShapePtr(), true);
         }
         else {
           ResultPtr aResult = aFeature->firstResult();
@@ -149,8 +149,11 @@ bool ModuleBase_WidgetValidated::isValidInFilters(const ModuleBase_ViewerPrsPtr&
             GeomShapePtr aShapePtr = ModelAPI_Tools::shape(aResult);
             if (aShapePtr.get()) {
               const TopoDS_Shape aTDShape = aShapePtr->impl<TopoDS_Shape>();
-              Handle(AIS_InteractiveObject) anIO = myWorkshop->selection()->getIO(thePrs);
-              anOwner = new StdSelect_BRepOwner(aTDShape, anIO);
+              AISObjectPtr aIOPtr = myWorkshop->findPresentation(aResult);
+              if (aIOPtr.get()) {
+                Handle(AIS_InteractiveObject) anIO = aIOPtr->impl<Handle(AIS_InteractiveObject)>();
+                anOwner = new StdSelect_BRepOwner(aTDShape, anIO);
+              }
             }
           }
           aValid = !anOwner.IsNull(); // only results with a shape can be filtered
@@ -194,6 +197,16 @@ bool ModuleBase_WidgetValidated::isValidInFilters(const ModuleBase_ViewerPrsPtr&
     anOwner.Nullify();
     myPresentedObject = ObjectPtr();
   }
+  if (!aValid) {
+    // Clear attribute if it still has selection
+    AttributePtr anAttr = attribute();
+    std::string aType = anAttr->attributeType();
+    if (aType == ModelAPI_AttributeSelection::typeId()) {
+      AttributeSelectionPtr aSelectAttr =
+        std::dynamic_pointer_cast<ModelAPI_AttributeSelection>(anAttr);
+      aSelectAttr->removeTemporaryValues();
+    }
+  }
   return aValid;
 }
 
@@ -440,12 +453,9 @@ QList<ModuleBase_ViewerPrsPtr> ModuleBase_WidgetValidated::getFilteredSelected()
 void ModuleBase_WidgetValidated::filterPresentations(QList<ModuleBase_ViewerPrsPtr>& theValues)
 {
   QList<ModuleBase_ViewerPrsPtr> aValidatedValues;
-
-  QList<ModuleBase_ViewerPrsPtr>::const_iterator anIt = theValues.begin(), aLast = theValues.end();
-  bool isDone = false;
-  for (; anIt != aLast; anIt++) {
-    if (isValidInFilters(*anIt))
-      aValidatedValues.append(*anIt);
+  foreach(ModuleBase_ViewerPrsPtr aPrs, theValues) {
+    if (isValidInFilters(aPrs))
+      aValidatedValues.append(aPrs);
   }
   if (aValidatedValues.size() != theValues.size()) {
     theValues.clear();