Salome HOME
"2.11 Constraint with a point from the intersection between an outer edge and plane...
[modules/shaper.git] / src / PartSet / PartSet_Filters.cpp
index 04ea88b37db50784de00c1ba3a6a0c17bbc3dd59..31f1872c778acce3053fce118629971a8dbbdcb2 100644 (file)
@@ -1,3 +1,5 @@
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
 // File:        PartSet_Filters.cpp
 // Created:     08 Nov 2014
 // Author:      Vitaly SMETANNIKOV
@@ -5,8 +7,11 @@
 #include "PartSet_Filters.h"
 
 #include <ModuleBase_IWorkshop.h>
+#include "ModuleBase_IModule.h"
 
 #include <ModelAPI_Feature.h>
+#include <ModelAPI_ResultPart.h>
+#include <ModelAPI_Session.h>
 #include <FeaturesPlugin_Group.h>
 
 #include <AIS_InteractiveObject.hxx>
@@ -18,25 +23,44 @@ IMPLEMENT_STANDARD_RTTIEXT(PartSet_GlobalFilter, ModuleBase_ShapeDocumentFilter)
 
 Standard_Boolean PartSet_GlobalFilter::IsOk(const Handle(SelectMgr_EntityOwner)& theOwner) const
 {
-  if (ModuleBase_ShapeDocumentFilter::IsOk(theOwner)) {
-    if (theOwner->HasSelectable()) {
-      Handle(AIS_InteractiveObject) aAisObj = 
-        Handle(AIS_InteractiveObject)::DownCast(theOwner->Selectable());
-      if (!aAisObj.IsNull()) {
-        std::shared_ptr<GeomAPI_AISObject> aAISObj = AISObjectPtr(new GeomAPI_AISObject());
-        aAISObj->setImpl(new Handle(AIS_InteractiveObject)(aAisObj));
-        ObjectPtr aObj = myWorkshop->findPresentedObject(aAISObj);
-        if (aObj) {
+  bool aValid = true;
+  ModuleBase_Operation* anOperation = myWorkshop->module()->currentOperation();
+  // the shapes from different documents should be provided if there is no started operation
+  // in order to show/hide results
+  if (anOperation) {
+    aValid = false;
+    if (ModuleBase_ShapeDocumentFilter::IsOk(theOwner)) {
+      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 aObj = myWorkshop->findPresentedObject(aAISObj);
+      if (aObj) {
+        ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(aObj);
+        // 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() && aResult->groupName() == ModelAPI_ResultPart::group()) {
+          SessionPtr aMgr = ModelAPI_Session::get();
+          aValid = aMgr->activeDocument() == aMgr->moduleDocument();
+        }
+        else {
           FeaturePtr aFeature = ModelAPI_Feature::feature(aObj);
           if (aFeature) {
-            return aFeature->getKind() != FeaturesPlugin_Group::ID();
+            aValid = aFeature->getKind() != FeaturesPlugin_Group::ID();
           } else 
-            return Standard_True;
-        } else
-          // This is not object controlled by the filter
-          return Standard_True;
-      }
+            aValid = Standard_True;
+        }
+      } else
+        // This is not object controlled by the filter
+        aValid = Standard_True;
     }
   }
-  return Standard_False;
+#ifdef DEBUG_FILTERS
+  qDebug(QString("PartSet_GlobalFilter::IsOk = %1").arg(aValid).toStdString().c_str());
+#endif
+  return aValid;
 }