From: vsv Date: Tue, 7 Oct 2014 14:17:53 +0000 (+0400) Subject: Issue #152: Filtering of selection by active document X-Git-Tag: V_0.5~111 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=6ff1eb27b19a3f97d844994727d184576d4ab32e;p=modules%2Fshaper.git Issue #152: Filtering of selection by active document --- diff --git a/src/ModuleBase/ModuleBase_WidgetShapeSelector.cpp b/src/ModuleBase/ModuleBase_WidgetShapeSelector.cpp index da84fe6ca..3fb534b36 100644 --- a/src/ModuleBase/ModuleBase_WidgetShapeSelector.cpp +++ b/src/ModuleBase/ModuleBase_WidgetShapeSelector.cpp @@ -14,6 +14,7 @@ #include #include +#include #include #include #include @@ -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 aShapePtr = ModelAPI_Tools::shape(aResult); if (!aShapePtr) return false; diff --git a/src/PartSet/PartSet_Module.cpp b/src/PartSet/PartSet_Module.cpp index 8b45d5e47..0232196f9 100644 --- a/src/PartSet/PartSet_Module.cpp +++ b/src/PartSet/PartSet_Module.cpp @@ -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(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(anOperation); -// //if (aPreviewOp) { -// XGUI_Selection* aSelection = myWorkshop->selector()->selection(); -// // Initialise operation with preliminary selection -// std::list aSelected = aSelection->getSelected(); -// std::list 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(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); } } diff --git a/src/PartSet/PartSet_Module.h b/src/PartSet/PartSet_Module.h index d06985307..0c39e68f8 100644 --- a/src/PartSet/PartSet_Module.h +++ b/src/PartSet/PartSet_Module.h @@ -6,6 +6,7 @@ #include #include #include +#include #include #include @@ -144,6 +145,9 @@ Q_OBJECT PartSet_Listener* myListener; std::map myFeaturesInFiles; + + /// A filter which provides selection within a current document or whole PartSet + Handle(XGUI_ShapeDocumentFilter) myDocumentShapeFilter; }; #endif diff --git a/src/XGUI/CMakeLists.txt b/src/XGUI/CMakeLists.txt index 0a07539a4..ace172c50 100644 --- a/src/XGUI/CMakeLists.txt +++ b/src/XGUI/CMakeLists.txt @@ -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 diff --git a/src/XGUI/XGUI_Displayer.h b/src/XGUI/XGUI_Displayer.h index 9552fd6d3..25b1cdfa2 100644 --- a/src/XGUI/XGUI_Displayer.h +++ b/src/XGUI/XGUI_Displayer.h @@ -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 index 000000000..c99c5bbfc --- /dev/null +++ b/src/XGUI/XGUI_ViewerFilters.cpp @@ -0,0 +1,34 @@ +// File: XGUI_ViewerFilters.cpp +// Created: 07 Okt 2014 +// Author: Vitaly SMETANNIKOV + + +#include "XGUI_ViewerFilters.h" +#include "XGUI_Displayer.h" + +#include +#include + +#include + +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 index 000000000..f30f400ae --- /dev/null +++ b/src/XGUI/XGUI_ViewerFilters.h @@ -0,0 +1,31 @@ +// File: XGUI_ViewerFilters.h +// Created: 07 Okt 2014 +// Author: Vitaly SMETANNIKOV + + +#ifndef XGUI_ViewerFilters_H +#define XGUI_ViewerFilters_H + +#include +#include + + +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