From: nds Date: Tue, 2 Dec 2014 14:49:02 +0000 (+0300) Subject: This is an improvement to use one AND filter in the viewer context. It serves to... X-Git-Tag: V_0.6.0^2~35^2~5 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=c11c3bbeb38d103a882fc24c0f2cb933b20d4053;p=modules%2Fshaper.git This is an improvement to use one AND filter in the viewer context. It serves to combine the document and the plane filters inside. --- diff --git a/src/ModuleBase/ModuleBase_ViewerFilters.cpp b/src/ModuleBase/ModuleBase_ViewerFilters.cpp index e7309ca07..94625a480 100644 --- a/src/ModuleBase/ModuleBase_ViewerFilters.cpp +++ b/src/ModuleBase/ModuleBase_ViewerFilters.cpp @@ -39,6 +39,10 @@ Standard_Boolean ModuleBase_ShapeDocumentFilter::IsOk(const Handle(SelectMgr_Ent SessionPtr aMgr = ModelAPI_Session::get(); return (aDoc == aMgr->activeDocument() || aDoc == aMgr->moduleDocument()); } + else { + // This is not object controlled by the filter + return Standard_True; + } } } return Standard_False; @@ -74,6 +78,10 @@ Standard_Boolean ModuleBase_ShapeInPlaneFilter::IsOk(const Handle(SelectMgr_Enti bool aD3 = myPlane.Distance(aLastPnt) < Precision::Confusion(); return aD1 && aD2 && aD3; } + default: + // This is not object controlled by the filter + return Standard_True; + break; } } else { // This is not object controlled by the filter diff --git a/src/PartSet/PartSet_Module.cpp b/src/PartSet/PartSet_Module.cpp index 93f886f13..e5b587fe6 100644 --- a/src/PartSet/PartSet_Module.cpp +++ b/src/PartSet/PartSet_Module.cpp @@ -94,6 +94,10 @@ PartSet_Module::PartSet_Module(ModuleBase_IWorkshop* theWshop) PartSet_Module::~PartSet_Module() { + if (!myDocumentShapeFilter.IsNull()) + myDocumentShapeFilter.Nullify(); + if (!myPlaneFilter.IsNull()) + myPlaneFilter.Nullify(); } void PartSet_Module::registerValidators() @@ -175,6 +179,9 @@ void PartSet_Module::onOperationStarted(ModuleBase_Operation* theOperation) myPlaneFilter->setPlane(aPln->impl()); } } + if (myDocumentShapeFilter.IsNull()) + myDocumentShapeFilter = new ModuleBase_ShapeDocumentFilter(myWorkshop); + myWorkshop->viewer()->addSelectionFilter(myDocumentShapeFilter); } void PartSet_Module::onOperationStopped(ModuleBase_Operation* theOperation) @@ -209,6 +216,7 @@ void PartSet_Module::onOperationStopped(ModuleBase_Operation* theOperation) myCurrentSketch = CompositeFeaturePtr(); myWorkshop->viewer()->removeSelectionFilter(myPlaneFilter); } + myWorkshop->viewer()->removeSelectionFilter(myDocumentShapeFilter); } void PartSet_Module::onPlaneSelected(const std::shared_ptr& thePln) diff --git a/src/PartSet/PartSet_Module.h b/src/PartSet/PartSet_Module.h index eb8fb5821..085876eb2 100644 --- a/src/PartSet/PartSet_Module.h +++ b/src/PartSet/PartSet_Module.h @@ -110,6 +110,8 @@ protected slots: QList myEditingAttr; Handle(ModuleBase_ShapeInPlaneFilter) myPlaneFilter; + /// A filter which provides selection within a current document or whole PartSet + Handle(ModuleBase_ShapeDocumentFilter) myDocumentShapeFilter; }; #endif diff --git a/src/PartSet/PartSet_WidgetSketchLabel.cpp b/src/PartSet/PartSet_WidgetSketchLabel.cpp index 37cd83445..3f7b53b25 100644 --- a/src/PartSet/PartSet_WidgetSketchLabel.cpp +++ b/src/PartSet/PartSet_WidgetSketchLabel.cpp @@ -133,13 +133,13 @@ void PartSet_WidgetSketchLabel::activate() XGUI_Displayer* aDisp = myWorkshop->displayer(); aDisp->openLocalContext(); - aDisp->activateObjectsOutOfContext(QIntList()); + aDisp->activateObjects(QIntList()); if (myPlaneFilter.IsNull()) myPlaneFilter = new StdSelect_FaceFilter(StdSelect_Plane); aDisp->addSelectionFilter(myPlaneFilter); QIntList aModes; aModes << TopAbs_FACE; - aDisp->setSelectionModes(aModes); + aDisp->activateObjects(aModes); myLabel->setText(myText); myLabel->setToolTip(myTooltip); @@ -265,7 +265,7 @@ void PartSet_WidgetSketchLabel::setSketchingMode() XGUI_Displayer* aDisp = myWorkshop->displayer(); QIntList aModes; // Clear standard selection modes if they are defined - aDisp->setSelectionModes(aModes); + aDisp->activateObjects(aModes); aDisp->openLocalContext(); // Set filter @@ -283,5 +283,5 @@ void PartSet_WidgetSketchLabel::setSketchingMode() aModes.append(AIS_Shape::SelectionMode((TopAbs_ShapeEnum) TopAbs_VERTEX)); aModes.append(AIS_Shape::SelectionMode((TopAbs_ShapeEnum) TopAbs_EDGE)); - aDisp->activateObjectsOutOfContext(aModes); + aDisp->activateObjects(aModes); } diff --git a/src/XGUI/XGUI_Displayer.cpp b/src/XGUI/XGUI_Displayer.cpp index 9ca390ecb..8347d607a 100644 --- a/src/XGUI/XGUI_Displayer.cpp +++ b/src/XGUI/XGUI_Displayer.cpp @@ -328,10 +328,12 @@ void XGUI_Displayer::openLocalContext() //for (aContext->InitCurrent(); aContext->MoreCurrent(); aContext->NextCurrent()) // aAisList.Append(aContext->Current()); + // get the filters from the global context and append them to the local context + // a list of filters in the global context is not cleared and should be cleared here SelectMgr_ListOfFilter aFilters; aFilters.Assign(aContext->Filters()); - aContext->ClearCurrents(); + //aContext->ClearCurrents(); aContext->OpenLocalContext(); aContext->NotUseDisplayedObjects(); @@ -341,6 +343,7 @@ void XGUI_Displayer::openLocalContext() SelectMgr_ListIteratorOfListOfFilter aIt(aFilters); for (;aIt.More(); aIt.Next()) { aContext->AddFilter(aIt.Value()); + //GetFilter()->Add(aIt.Value()); } // Restore selection //AIS_ListIteratorOfListOfInteractive aIt(aAisList); @@ -360,7 +363,12 @@ void XGUI_Displayer::closeLocalContexts(const bool isUpdateViewer) //for (ic->InitSelected(); ic->MoreSelected(); ic->NextSelected()) // aAisList.Append(ic->SelectedInteractive()); - ic->ClearSelected(); + // get the filters from the local context and append them to the global context + // a list of filters in the local context is cleared + SelectMgr_ListOfFilter aFilters; + aFilters.Assign(ic->Filters()); + + //ic->ClearSelected(); ic->CloseAllContexts(false); // Redisplay all object if they were displayed in localContext @@ -372,6 +380,15 @@ void XGUI_Displayer::closeLocalContexts(const bool isUpdateViewer) ic->SetDisplayMode(aAISIO, Shading, false); } } + + // Append the filters from the local selection in the global selection context + SelectMgr_ListIteratorOfListOfFilter aIt(aFilters); + for (;aIt.More(); aIt.Next()) { + Handle(SelectMgr_Filter) aFilter = aIt.Value(); + ic->AddFilter(aFilter); + //GetFilter()->Add(aIt.Value()); + } + if (isUpdateViewer) updateViewer(); myUseExternalObjects = false; @@ -424,6 +441,16 @@ Handle(AIS_InteractiveContext) XGUI_Displayer::AISContext() const return myWorkshop->viewer()->AISContext(); } +Handle(SelectMgr_AndFilter) XGUI_Displayer::GetFilter() +{ + Handle(AIS_InteractiveContext) aContext = AISContext(); + if (myAndFilter.IsNull() && !aContext.IsNull()) { + myAndFilter = new SelectMgr_AndFilter(); + aContext->AddFilter(myAndFilter); + } + return myAndFilter; +} + void XGUI_Displayer::displayAIS(AISObjectPtr theAIS, bool isUpdate) { Handle(AIS_InteractiveContext) aContext = AISContext(); @@ -453,7 +480,7 @@ void XGUI_Displayer::eraseAIS(AISObjectPtr theAIS, const bool isUpdate) } } -void XGUI_Displayer::activateObjectsOutOfContext(const QIntList& theModes) +void XGUI_Displayer::activateObjects(const QIntList& theModes) { Handle(AIS_InteractiveContext) aContext = AISContext(); // Open local context if there is no one @@ -478,9 +505,18 @@ void XGUI_Displayer::activateObjectsOutOfContext(const QIntList& theModes) } } + //Activate all displayed objects with the module modes + //AIS_ListOfInteractive aPrsList; + //aContext->DisplayedObjects(aPrsList, true); + + //AIS_ListIteratorOfListOfInteractive aLIt(aPrsList); Handle(AIS_InteractiveObject) anAISIO; - foreach (AISObjectPtr aAIS, myResult2AISObjectMap) { - anAISIO = aAIS->impl(); + for(aLIt.Initialize(aPrsList); aLIt.More(); aLIt.Next()){ + anAISIO = aLIt.Value(); + aTrihedron = Handle(AIS_Trihedron)::DownCast(anAISIO); + if (!aTrihedron.IsNull()) + continue; + aContext->Load(anAISIO, -1, true); if (theModes.size() == 0) aContext->Activate(anAISIO); @@ -493,7 +529,7 @@ void XGUI_Displayer::activateObjectsOutOfContext(const QIntList& theModes) } -void XGUI_Displayer::deactivateObjectsOutOfContext() +void XGUI_Displayer::deactivateObjects() { Handle(AIS_InteractiveContext) aContext = AISContext(); // Open local context if there is no one @@ -521,28 +557,6 @@ void XGUI_Displayer::setDisplayMode(ObjectPtr theObject, DisplayMode theMode, bo aContext->SetDisplayMode(aAISIO, theMode, toUpdate); } -void XGUI_Displayer::setSelectionModes(const QIntList& theModes) -{ - Handle(AIS_InteractiveContext) aContext = AISContext(); - if (aContext.IsNull()) - return; - if (!aContext->HasOpenedContext()) - return; - // Clear previous mode - const TColStd_ListOfInteger& aModes = aContext->ActivatedStandardModes(); - if (!aModes.IsEmpty()) { - TColStd_ListOfInteger aMModes; - aMModes.Assign(aModes); - TColStd_ListIteratorOfListOfInteger it(aMModes); - for(; it.More(); it.Next()) { - aContext->DeactivateStandardMode((TopAbs_ShapeEnum)it.Value()); - } - } - foreach(int aMode, theModes) { - aContext->ActivateStandardMode((TopAbs_ShapeEnum)aMode); - } -} - XGUI_Displayer::DisplayMode XGUI_Displayer::displayMode(ObjectPtr theObject) const { Handle(AIS_InteractiveContext) aContext = AISContext(); @@ -568,7 +582,8 @@ void XGUI_Displayer::addSelectionFilter(const Handle(SelectMgr_Filter)& theFilte if (theFilter.Access() == aIt.Value().Access()) return; } - aContext->AddFilter(theFilter); + //aContext->AddFilter(theFilter); + GetFilter()->Add(theFilter); } void XGUI_Displayer::removeSelectionFilter(const Handle(SelectMgr_Filter)& theFilter) @@ -576,7 +591,8 @@ void XGUI_Displayer::removeSelectionFilter(const Handle(SelectMgr_Filter)& theFi Handle(AIS_InteractiveContext) aContext = AISContext(); if (aContext.IsNull()) return; - aContext->RemoveFilter(theFilter); + //aContext->RemoveFilter(theFilter); + GetFilter()->Remove(theFilter); } void XGUI_Displayer::removeFilters() @@ -584,5 +600,6 @@ void XGUI_Displayer::removeFilters() Handle(AIS_InteractiveContext) aContext = AISContext(); if (aContext.IsNull()) return; - aContext->RemoveFilters(); + //aContext->RemoveFilters(); + GetFilter()->Clear(); } diff --git a/src/XGUI/XGUI_Displayer.h b/src/XGUI/XGUI_Displayer.h index f56322328..b18eb0f8d 100644 --- a/src/XGUI/XGUI_Displayer.h +++ b/src/XGUI/XGUI_Displayer.h @@ -18,6 +18,8 @@ #include #include +#include + #include #include @@ -94,13 +96,6 @@ class XGUI_EXPORT XGUI_Displayer /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly void closeLocalContexts(const bool isUpdateViewer = true); - /* - * Set modes of selections. Selection mode has to be defined by TopAbs_ShapeEnum. - * It doesn't manages a local context - * \param theModes - list of selection modes. If the list is empty then all selectoin modes will be cleared. - */ - void setSelectionModes(const QIntList& theModes); - void addSelectionFilter(const Handle(SelectMgr_Filter)& theFilter); void removeSelectionFilter(const Handle(SelectMgr_Filter)& theFilter); @@ -136,10 +131,10 @@ class XGUI_EXPORT XGUI_Displayer /// Activates in local context displayed outside of the context. /// \param theModes - modes on which it has to be activated (can be empty) - void activateObjectsOutOfContext(const QIntList& theModes); + void activateObjects(const QIntList& theModes); /// Activates in local context displayed outside of the context. - void deactivateObjectsOutOfContext(); + void deactivateObjects(); /// Sets display mode for the given object if this object is displayed void setDisplayMode(ObjectPtr theObject, DisplayMode theMode, bool toUpdate = true); @@ -155,6 +150,10 @@ class XGUI_EXPORT XGUI_Displayer /// Returns currently installed AIS_InteractiveContext Handle(AIS_InteractiveContext) AISContext() const; + /// Returns the viewer context top filter. If there is no a filter, it is created and set into + /// The context should have only this filter inside. Other filters should be add to the filter + Handle(SelectMgr_AndFilter) GetFilter(); + /// Display the feature and a shape. This shape would be associated to the given feature /// \param theFeature a feature instance /// \param theAIS AIS presentation @@ -181,6 +180,8 @@ class XGUI_EXPORT XGUI_Displayer protected: XGUI_Workshop* myWorkshop; + Handle(SelectMgr_AndFilter) myAndFilter; + typedef QMap ResultToAISMap; ResultToAISMap myResult2AISObjectMap; diff --git a/src/XGUI/XGUI_ModuleConnector.cpp b/src/XGUI/XGUI_ModuleConnector.cpp index cd13a987b..e45a52cce 100644 --- a/src/XGUI/XGUI_ModuleConnector.cpp +++ b/src/XGUI/XGUI_ModuleConnector.cpp @@ -73,7 +73,7 @@ void XGUI_ModuleConnector::activateSubShapesSelection(const QIntList& theTypes) foreach(int aType, theTypes) { aModes.append(AIS_Shape::SelectionMode((TopAbs_ShapeEnum)aType)); } - aDisp->activateObjectsOutOfContext(aModes); + aDisp->activateObjects(aModes); //TODO: We have to open Local context because at neutral point filters don't work (bug 25340) //aDisp->addSelectionFilter(myDocumentShapeFilter); }