Salome HOME
Issue #2975: Do not select groups in all operations except operations on groups
[modules/shaper.git] / src / PartSet / PartSet_Filters.cpp
index e99265ee13683fc8c319e8539522812247b248f1..88ba16c9ad36518e8722fbb5326eea378693d354 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 "PartSet_Filters.h"
@@ -27,6 +26,7 @@
 #include <ModelAPI_Feature.h>
 #include <ModelAPI_ResultPart.h>
 #include <ModelAPI_ResultGroup.h>
+#include <ModelAPI_ResultField.h>
 #include <ModelAPI_Session.h>
 
 #include <AIS_InteractiveObject.hxx>
 
 IMPLEMENT_STANDARD_RTTIEXT(PartSet_GlobalFilter, ModuleBase_ShapeDocumentFilter);
 
+PartSet_GlobalFilter::PartSet_GlobalFilter(ModuleBase_IWorkshop* theWorkshop)
+  : ModuleBase_ShapeDocumentFilter(theWorkshop)
+{
+  addNonSelectableType(ModelAPI_ResultField::group().c_str());
+  addNonSelectableType(ModelAPI_ResultGroup::group().c_str());
+}
+
+
 Standard_Boolean PartSet_GlobalFilter::IsOk(const Handle(SelectMgr_EntityOwner)& theOwner) const
 {
   bool aValid = true;
@@ -59,10 +67,11 @@ Standard_Boolean PartSet_GlobalFilter::IsOk(const Handle(SelectMgr_EntityOwner)&
         // result of parts belongs to PartSet document and can be selected only when PartSet
         //  is active in order to do not select the result of the active part.
         if (aResult.get()) {
-          if (aResult->groupName() == ModelAPI_ResultPart::group()) {
+          std::string aResultGroupName = aResult->groupName();
+          if (aResultGroupName == ModelAPI_ResultPart::group()) {
             SessionPtr aMgr = ModelAPI_Session::get();
             aValid = aMgr->activeDocument() == aMgr->moduleDocument();
-          } else if (aResult->groupName() == ModelAPI_ResultGroup::group()) {
+          } else if (myNonSelectableTypes.contains(aResultGroupName.c_str())) {
             aValid = Standard_False;
           } else
             aValid = Standard_True;
@@ -71,7 +80,7 @@ Standard_Boolean PartSet_GlobalFilter::IsOk(const Handle(SelectMgr_EntityOwner)&
           // only and there can not be Group feature
           FeaturePtr aFeature = ModelAPI_Feature::feature(aObj);
           if (aFeature) {
-            aValid = aFeature->getKind() != "Group";
+            aValid = !myNonSelectableTypes.contains(aFeature->getKind().c_str());
           } else
             aValid = Standard_True;
         }
@@ -93,7 +102,8 @@ void PartSet_ResultGroupNameFilter::setGroupNames(const std::set<std::string>& t
   myGroupNames = theGroupNames;
 }
 
-Standard_Boolean PartSet_ResultGroupNameFilter::IsOk(const Handle(SelectMgr_EntityOwner)& theOwner) const
+Standard_Boolean PartSet_ResultGroupNameFilter::IsOk(
+  const Handle(SelectMgr_EntityOwner)& theOwner) const
 {
   std::shared_ptr<GeomAPI_AISObject> aAISObj = AISObjectPtr(new GeomAPI_AISObject());
   if (theOwner->HasSelectable()) {