]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Issue #152: Filtering of selection by active document
authorvsv <vitaly.smetannikov@opencascade.com>
Tue, 7 Oct 2014 14:17:53 +0000 (18:17 +0400)
committervsv <vitaly.smetannikov@opencascade.com>
Tue, 7 Oct 2014 14:17:53 +0000 (18:17 +0400)
src/ModuleBase/ModuleBase_WidgetShapeSelector.cpp
src/PartSet/PartSet_Module.cpp
src/PartSet/PartSet_Module.h
src/XGUI/CMakeLists.txt
src/XGUI/XGUI_Displayer.h
src/XGUI/XGUI_ViewerFilters.cpp [new file with mode: 0644]
src/XGUI/XGUI_ViewerFilters.h [new file with mode: 0644]

index da84fe6cac3bd27bcfe422f622a814e378c1fd69..3fb534b36482d1effb4df9ee153ffc0c085e1218 100644 (file)
@@ -14,6 +14,7 @@
 #include <ModelAPI_Tools.h>
 
 #include <ModelAPI_Data.h>
+#include <ModelAPI_Document.h>
 #include <ModelAPI_Object.h>
 #include <ModelAPI_Result.h>
 #include <ModelAPI_AttributeReference.h>
@@ -186,6 +187,13 @@ bool ModuleBase_WidgetShapeSelector::isAccepted(const ObjectPtr theResult) const
         return false;
     }
   }
+  // Check that object belongs to active document or PartSet
+  DocumentPtr aDoc = aResult->document();
+  SessionPtr aMgr = ModelAPI_Session::get();
+  if (!(aDoc == aMgr->activeDocument()) || (aDoc == aMgr->moduleDocument()))
+    return false;
+
+  // Check that the shape of necessary type
   boost::shared_ptr<GeomAPI_Shape> aShapePtr = ModelAPI_Tools::shape(aResult);
   if (!aShapePtr)
     return false;
index 8b45d5e47a7d7a98075fffcd5a556876f817d5ea..0232196f9d608f3d439ff197151e2185fecdcf54 100644 (file)
@@ -79,7 +79,8 @@ PartSet_Module::PartSet_Module(ModuleBase_IWorkshop* theWshop)
   connect(myWorkshop, SIGNAL(operationStopped(ModuleBase_Operation*)), this,
           SLOT(onOperationStopped(ModuleBase_Operation*)));
 
-  XGUI_ContextMenuMgr* aContextMenuMgr = xWorkshop()->contextMenuMgr();
+  XGUI_Workshop* aXWshop = xWorkshop();
+  XGUI_ContextMenuMgr* aContextMenuMgr = aXWshop->contextMenuMgr();
   connect(aContextMenuMgr, SIGNAL(actionTriggered(const QString&, bool)), this,
           SLOT(onContextMenuCommand(const QString&, bool)));
 
@@ -93,6 +94,8 @@ PartSet_Module::PartSet_Module(ModuleBase_IWorkshop* theWshop)
           SLOT(onKeyRelease(QKeyEvent*)));
   connect(myWorkshop->viewer(), SIGNAL(mouseDoubleClick(QMouseEvent*)), this,
           SLOT(onMouseDoubleClick(QMouseEvent*)));
+
+  myDocumentShapeFilter = new XGUI_ShapeDocumentFilter(aXWshop->displayer());
 }
 
 PartSet_Module::~PartSet_Module()
@@ -130,11 +133,6 @@ std::string PartSet_Module::featureFile(const std::string& theFeatureId)
  */
 void PartSet_Module::onFeatureTriggered()
 {
-  //PartSet_TestOCC::local_selection_change_shape(myWorkshop->viewer()->AISContext(),
-  //                                   myWorkshop->viewer()->activeView());
-
-  //PartSet_TestOCC::local_selection_erase(myWorkshop->viewer()->AISContext(),
-  //                                       myWorkshop->viewer()->activeView());
   QAction* aCmd = dynamic_cast<QAction*>(sender());
   //Do nothing on uncheck
   if (aCmd->isCheckable() && !aCmd->isChecked())
@@ -142,19 +140,6 @@ void PartSet_Module::onFeatureTriggered()
   launchOperation(aCmd->data().toString());
 }
 
-//void PartSet_Module::launchOperation(const QString& theCmdId)
-//{
-//  ModuleBase_Operation* anOperation = createOperation(theCmdId.toStdString());
-//  //PartSet_OperationSketchBase* aPreviewOp = dynamic_cast<PartSet_OperationSketchBase*>(anOperation);
-//  //if (aPreviewOp) {
-//    XGUI_Selection* aSelection = myWorkshop->selector()->selection();
-//    // Initialise operation with preliminary selection
-//    std::list<ModuleBase_ViewerPrs> aSelected = aSelection->getSelected();
-//    std::list<ModuleBase_ViewerPrs> aHighlighted = aSelection->getHighlighted();
-//    anOperation->initSelection(aSelected, aHighlighted);
-//  //}
-//  sendOperation(anOperation);
-//}
 
 void PartSet_Module::onOperationStarted(ModuleBase_Operation* theOperation)
 {
@@ -168,6 +153,9 @@ void PartSet_Module::onOperationStarted(ModuleBase_Operation* theOperation)
     XGUI_Displayer* aDisplayer = aXWshp->displayer();
     aDisplayer->openLocalContext();
     aDisplayer->deactivateObjectsOutOfContext();
+  } else {
+    Handle(AIS_InteractiveContext) aAIS = xWorkshop()->viewer()->AISContext();
+    aAIS->AddFilter(myDocumentShapeFilter);
   }
 }
 
@@ -179,8 +167,6 @@ void PartSet_Module::onOperationStopped(ModuleBase_Operation* theOperation)
   PartSet_OperationSketchBase* aPreviewOp = dynamic_cast<PartSet_OperationSketchBase*>(theOperation);
   if (aPreviewOp) {
     XGUI_PropertyPanel* aPropPanel = aXWshp->propertyPanel();
-    //disconnect(aPropPanel, SIGNAL(storedPoint2D(ObjectPtr, const std::string&)),
-    //           this, SLOT(onStorePoint2D(ObjectPtr, const std::string&)));
   } else {
     // Activate results of current feature for selection
     FeaturePtr aFeature = theOperation->feature();
@@ -190,6 +176,9 @@ void PartSet_Module::onOperationStopped(ModuleBase_Operation* theOperation)
     for (aIt = aResults.cbegin(); aIt != aResults.cend(); ++aIt) {
       aDisplayer->activate(*aIt);
     }
+
+    Handle(AIS_InteractiveContext) aAIS = xWorkshop()->viewer()->AISContext();
+    aAIS->RemoveFilter(myDocumentShapeFilter);
   }
 }
 
index d0698530717639ee7386beb0b993802fa3cd6525..0c39e68f814f91d7d946742f634daca3fd106c78 100644 (file)
@@ -6,6 +6,7 @@
 #include <ModuleBase_IModule.h>
 #include <ModuleBase_Definitions.h>
 #include <XGUI_Command.h>
+#include <XGUI_ViewerFilters.h>
 #include <ModelAPI_Feature.h>
 
 #include <QMap>
@@ -144,6 +145,9 @@ Q_OBJECT
   PartSet_Listener* myListener;
 
   std::map<std::string, std::string> myFeaturesInFiles;
+
+  /// A filter which provides selection within a current document or whole PartSet
+  Handle(XGUI_ShapeDocumentFilter) myDocumentShapeFilter;
 };
 
 #endif
index 0a07539a44b075b2805d7a9701310ff92948d9a2..ace172c50ba2bf627bdc74de745c5b0437eab4fa 100644 (file)
@@ -33,6 +33,7 @@ SET(PROJECT_HEADERS
        XGUI_Preferences.h
        XGUI_IPrefMgr.h
        XGUI_QtEvents.h
+       XGUI_ViewerFilters.h
 )
 
 SET(PROJECT_AUTOMOC 
@@ -66,6 +67,7 @@ SET(PROJECT_SOURCES
        XGUI_Selection.cpp
        XGUI_Preferences.cpp
        XGUI_QtEvents.cpp
+       XGUI_ViewerFilters.cpp
 )
 
 SET(PROJECT_RESOURCES 
index 9552fd6d365460379d36709319878e0b83dd3716..25b1cdfa204cbb892a4edafc5699c03ac7533ba5 100644 (file)
@@ -45,10 +45,6 @@ class XGUI_EXPORT XGUI_Displayer
   /// Destructor
   virtual ~XGUI_Displayer();
 
-  /// Set AIS_InteractiveContext object in case if it was changed
-  /// or can not be initialized in constructor
-  void setAISContext(const Handle(AIS_InteractiveContext)& theAIS);
-
   /// Returns the feature visibility state.
   /// \param theFeature a feature instance
   bool isVisible(ObjectPtr theObject) const;
diff --git a/src/XGUI/XGUI_ViewerFilters.cpp b/src/XGUI/XGUI_ViewerFilters.cpp
new file mode 100644 (file)
index 0000000..c99c5bb
--- /dev/null
@@ -0,0 +1,34 @@
+// File:        XGUI_ViewerFilters.cpp
+// Created:     07 Okt 2014
+// Author:      Vitaly SMETANNIKOV
+
+
+#include "XGUI_ViewerFilters.h"
+#include "XGUI_Displayer.h"
+
+#include <ModelAPI_Session.h>
+#include <ModelAPI_Document.h>
+
+#include <AIS_InteractiveObject.hxx>
+
+IMPLEMENT_STANDARD_HANDLE(XGUI_ShapeDocumentFilter, SelectMgr_Filter);
+IMPLEMENT_STANDARD_RTTIEXT(XGUI_ShapeDocumentFilter, SelectMgr_Filter);
+
+
+//TODO (VSV): Check bug in OCCT: Filter result is ignored
+Standard_Boolean XGUI_ShapeDocumentFilter::IsOk(const Handle(SelectMgr_EntityOwner)& theOwner) const
+{
+  if (theOwner->HasSelectable()) {
+    Handle(AIS_InteractiveObject) aAisObj = 
+      Handle(AIS_InteractiveObject)::DownCast(theOwner->Selectable());
+    if (!aAisObj.IsNull()) {
+      ObjectPtr aObj = myDisplayer->getObject(aAisObj);
+      if (aObj) {
+        DocumentPtr aDoc = aObj->document();
+        SessionPtr aMgr = ModelAPI_Session::get();
+        return (aDoc == aMgr->activeDocument()) || (aDoc == aMgr->moduleDocument());
+      }
+    }
+  }
+  return Standard_False;
+}
\ No newline at end of file
diff --git a/src/XGUI/XGUI_ViewerFilters.h b/src/XGUI/XGUI_ViewerFilters.h
new file mode 100644 (file)
index 0000000..f30f400
--- /dev/null
@@ -0,0 +1,31 @@
+// File:        XGUI_ViewerFilters.h
+// Created:     07 Okt 2014
+// Author:      Vitaly SMETANNIKOV
+
+
+#ifndef XGUI_ViewerFilters_H
+#define XGUI_ViewerFilters_H
+
+#include <SelectMgr_Filter.hxx>
+#include <SelectMgr_EntityOwner.hxx>
+
+
+class XGUI_Displayer;
+
+DEFINE_STANDARD_HANDLE(XGUI_ShapeDocumentFilter, SelectMgr_Filter);
+
+class XGUI_ShapeDocumentFilter: public SelectMgr_Filter
+{
+public:
+  Standard_EXPORT XGUI_ShapeDocumentFilter(XGUI_Displayer* myDisp): SelectMgr_Filter(),
+    myDisplayer(myDisp) {}
+
+  Standard_EXPORT virtual Standard_Boolean IsOk(const Handle(SelectMgr_EntityOwner)& theOwner) const;
+
+  DEFINE_STANDARD_RTTI(XGUI_ShapeDocumentFilter)
+
+private:
+  XGUI_Displayer* myDisplayer;
+};
+
+#endif
\ No newline at end of file