Salome HOME
Fix for the issue #2753 : error when dump/load script
[modules/shaper.git] / src / PartSet / PartSet_Filters.cpp
index afe4fbbda47d0090db276282818800f086cda5f5..ffc6b27464209f07742db25652521ea87c727717 100644 (file)
@@ -27,6 +27,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>
@@ -59,10 +60,12 @@ 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 (aResultGroupName == ModelAPI_ResultGroup::group() ||
+                     aResultGroupName == ModelAPI_ResultField::group()) {
             aValid = Standard_False;
           } else
             aValid = Standard_True;
@@ -86,6 +89,42 @@ Standard_Boolean PartSet_GlobalFilter::IsOk(const Handle(SelectMgr_EntityOwner)&
   return aValid;
 }
 
+IMPLEMENT_STANDARD_RTTIEXT(PartSet_ResultGroupNameFilter, SelectMgr_Filter);
+
+void PartSet_ResultGroupNameFilter::setGroupNames(const std::set<std::string>& theGroupNames)
+{
+  myGroupNames = theGroupNames;
+}
+
+Standard_Boolean PartSet_ResultGroupNameFilter::IsOk(
+  const Handle(SelectMgr_EntityOwner)& theOwner) const
+{
+  std::shared_ptr<GeomAPI_AISObject> aAISObj = AISObjectPtr(new GeomAPI_AISObject());
+  if (theOwner->HasSelectable()) {
+    Handle(AIS_InteractiveObject) aAisObj =
+      Handle(AIS_InteractiveObject)::DownCast(theOwner->Selectable());
+    if (!aAisObj.IsNull()) {
+      aAISObj->setImpl(new Handle(AIS_InteractiveObject)(aAisObj));
+    }
+  }
+  ObjectPtr anObject = myWorkshop->findPresentedObject(aAISObj);
+  if (!anObject.get())
+    return true;
+
+  ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObject);
+  // 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())
+    return true;
+
+  std::string aGroupName = aResult->groupName();// == ModelAPI_ResultPart::group()) {
+  if (myGroupNames.find(aGroupName) != myGroupNames.end())
+    return false; // the object of the filtered type is found
+
+  return true;
+}
+
+
 IMPLEMENT_STANDARD_RTTIEXT(PartSet_CirclePointFilter, SelectMgr_Filter);
 
 Standard_Boolean