]> OCCT Git - occt-copy.git/commitdiff
0031221: Visualization - selection filter in context
authornds <nds@opencascade.com>
Sun, 8 Dec 2019 15:57:34 +0000 (18:57 +0300)
committernds <nds@opencascade.com>
Sun, 8 Dec 2019 16:00:03 +0000 (19:00 +0300)
(cherry picked from commit 7573337633895bca6f7417851398539140dac4d2)

src/AIS/AIS_InteractiveContext.cxx
src/AIS/AIS_InteractiveContext.hxx
src/AIS/AIS_InteractiveContext_1.cxx
src/AIS/AIS_InteractiveContext_2.cxx
src/AIS/AIS_InteractiveContext_3.cxx
src/SelectMgr/FILES
src/SelectMgr/SelectMgr_DisabledObjectsFilter.cxx [new file with mode: 0644]
src/SelectMgr/SelectMgr_DisabledObjectsFilter.hxx [new file with mode: 0644]
src/SelectMgr/SelectMgr_OrFilter.cxx
src/SelectMgr/SelectMgr_OrFilter.hxx

index aa7ea03bf08d5decf8a991f1d6a7d3e00b0e09c0..d3788f6e640f519d3479541e5363731a9d1e29bb 100644 (file)
@@ -39,6 +39,8 @@
 #include <Prs3d_ShadingAspect.hxx>
 #include <PrsMgr_PresentableObject.hxx>
 #include <Quantity_Color.hxx>
+#include <SelectMgr_AndFilter.hxx>
+#include <SelectMgr_DisabledObjectsFilter.hxx>
 #include <SelectMgr_EntityOwner.hxx>
 #include <SelectMgr_Filter.hxx>
 #include <SelectMgr_OrFilter.hxx>
@@ -108,7 +110,7 @@ myMainVwr(MainViewer),
 myMainSel(new StdSelect_ViewerSelector3d()),
 myToHilightSelected(Standard_True),
 mySelection(new AIS_Selection()),
-myFilters(new SelectMgr_OrFilter()),
+myFilters(new SelectMgr_AndFilter()),
 myDefaultDrawer(new Prs3d_Drawer()),
 myCurDetected(0),
 myCurHighlighted(0),
@@ -116,6 +118,8 @@ myPickingStrategy (SelectMgr_PickingStrategy_FirstAcceptable),
 myAutoHilight(Standard_True),
 myIsAutoActivateSelMode(Standard_True)
 {
+  myFilters->Add (new SelectMgr_DisabledObjectsFilter());
+
   mgrSelector = new SelectMgr_SelectionManager (myMainSel);
 
   myStyles[Prs3d_TypeOfHighlight_None]          = myDefaultDrawer;
index 373ebf3453cb9235421be5fe1ce0925a0b0250e8..d45772c49778f3ee8b7144395f91240cc96a8963 100644 (file)
@@ -47,7 +47,7 @@
 
 class SelectMgr_SelectionManager;
 class V3d_Viewer;
-class SelectMgr_OrFilter;
+class SelectMgr_AndFilter;
 class V3d_View;
 class TopLoc_Location;
 class TCollection_ExtendedString;
@@ -767,13 +767,20 @@ public: //! @name management of active Selection Modes
 
 public: //! @name Selection Filters management
 
+  //! Allows you to set the filter.
+  Standard_EXPORT void SetFilter (const Handle(SelectMgr_Filter)& theFilter);
+
+  //! Returns the filter. Use with global is in false to get the filter, that is set with SetFilter.
+  //! If global filter is true, it returns whole filter used in the context (with an internal default filter)
+  Standard_EXPORT Handle(SelectMgr_Filter) Filter (const Standard_Boolean isGlobalFilter = Standard_False) const;
+
   //! Returns the list of filters active in a local context.
-  Standard_EXPORT const SelectMgr_ListOfFilter& Filters() const;
+  Standard_EXPORT SelectMgr_ListOfFilter Filters() const;
 
-  //! Allows you to add the filter.
+  //! Allows you to add the filter. Default filter here is Or filter.
   Standard_EXPORT void AddFilter (const Handle(SelectMgr_Filter)& theFilter);
 
-  //! Removes a filter from context.
+  //! Removes a filter from context. Default filter here is Or filter
   Standard_EXPORT void RemoveFilter (const Handle(SelectMgr_Filter)& theFilter);
 
   //! Remove all filters from context.
@@ -1437,7 +1444,7 @@ protected: //! @name internal fields
   Handle(SelectMgr_EntityOwner) myLastPicked;
   Standard_Boolean myToHilightSelected;
   Handle(AIS_Selection) mySelection;
-  Handle(SelectMgr_OrFilter) myFilters;
+  Handle(SelectMgr_AndFilter) myFilters;
   Handle(Prs3d_Drawer) myDefaultDrawer;
   Handle(Prs3d_Drawer) myStyles[Prs3d_TypeOfHighlight_NB];
   TColStd_SequenceOfInteger myDetectedSeq;
index bb1e938bfe148d978b38fa6f784154a41f76956b..6252c69fd5a2b7305119749af115c5a83fbde803 100644 (file)
@@ -31,6 +31,8 @@
 #include <Prs3d_Presentation.hxx>
 #include <Quantity_Color.hxx>
 #include <Select3D_SensitiveEntity.hxx>
+#include <SelectMgr_AndFilter.hxx>
+#include <SelectMgr_DisabledObjectsFilter.hxx>
 #include <SelectMgr_EntityOwner.hxx>
 #include <SelectMgr_Filter.hxx>
 #include <SelectMgr_OrFilter.hxx>
@@ -336,7 +338,8 @@ AIS_StatusOfDetection AIS_InteractiveContext::MoveTo (const Standard_Integer  th
   AIS_StatusOfDetection aStatus        = AIS_SOD_Nothing;
   Standard_Boolean      toUpdateViewer = Standard_False;
 
-  myFilters->SetDisabledObjects (theView->View()->HiddenObjects());
+  Handle(SelectMgr_DisabledObjectsFilter) anObjectsFilter = Handle(SelectMgr_DisabledObjectsFilter)::DownCast (myFilters->StoredFilters().First());
+  anObjectsFilter->SetDisabledObjects (theView->View()->HiddenObjects());
   myMainSel->Pick (theXPix, theYPix, theView);
 
   // filling of myAISDetectedSeq sequence storing information about detected AIS objects
index 9ce6fa886fc6bbbc90d1ead31e8b6853e17a6524..e32f7fc5ec1213806f5c98ef7f9fcfd2713663d4 100644 (file)
@@ -30,6 +30,7 @@
 #include <SelectMgr_EntityOwner.hxx>
 #include <SelectMgr_Filter.hxx>
 #include <SelectMgr_OrFilter.hxx>
+#include <SelectMgr_AndFilter.hxx>
 #include <SelectMgr_SelectionManager.hxx>
 #include <Standard_Transient.hxx>
 #include <StdSelect_ViewerSelector3d.hxx>
@@ -264,22 +265,74 @@ void AIS_InteractiveContext::SubIntensityOff (const Handle(AIS_InteractiveObject
   }
 }
 
+//=======================================================================
+//function : SetFilter
+//purpose  : 
+//=======================================================================
+void AIS_InteractiveContext::SetFilter (const Handle(SelectMgr_Filter)& theFilter)
+{
+  Handle(SelectMgr_Filter) aDefFilter = myFilters->StoredFilters().First();
+  if (myFilters->StoredFilters().Size() < 2)
+  {
+    myFilters->Clear();
+    myFilters->Add (aDefFilter);
+  }
+
+  myFilters->Add (theFilter);
+}
+
+//=======================================================================
+//function : Filter
+//purpose  : 
+//=======================================================================
+Handle(SelectMgr_Filter) AIS_InteractiveContext::Filter (const Standard_Boolean isGlobalFilter) const
+{
+  if (isGlobalFilter)
+    return myFilters;
+
+  if (myFilters->StoredFilters().Size() < 2)
+    return NULL;
+
+  SelectMgr_ListIteratorOfListOfFilter anIterator (myFilters->StoredFilters());
+  anIterator.Next();
+  return anIterator.Value();
+}
+
 //=======================================================================
 //function : AddFilter
 //purpose  : 
 //=======================================================================
-void AIS_InteractiveContext::AddFilter(const Handle(SelectMgr_Filter)& aFilter)
+void AIS_InteractiveContext::AddFilter(const Handle(SelectMgr_Filter)& theFilter)
 {
-  myFilters->Add(aFilter);
+  Handle(SelectMgr_Filter) aFilter = Filter();
+  if (aFilter.IsNull())
+    SetFilter (new SelectMgr_OrFilter());
+
+  Handle (SelectMgr_CompositionFilter) aCompositeFilter = Handle(SelectMgr_CompositionFilter)::DownCast (aFilter);
+  if (aCompositeFilter.IsNull())
+    return;
+
+  if (aCompositeFilter->IsIn (theFilter))
+    return;
+
+  aCompositeFilter->Add (theFilter);
 }
 
 //=======================================================================
 //function : RemoveFilter
 //purpose  : 
 //=======================================================================
-void AIS_InteractiveContext::RemoveFilter(const Handle(SelectMgr_Filter)& aFilter)
+void AIS_InteractiveContext::RemoveFilter(const Handle(SelectMgr_Filter)& theFilter)
 {
-  myFilters->Remove(aFilter);
+  Handle(SelectMgr_Filter) aFilter = Filter();
+  if (aFilter.IsNull())
+    return;
+
+  Handle (SelectMgr_CompositionFilter) aCompositeFilter = Handle(SelectMgr_CompositionFilter)::DownCast (aFilter);
+  if (aCompositeFilter.IsNull())
+    return;
+
+  aCompositeFilter->Remove (theFilter);
 }
 
 //=======================================================================
@@ -289,16 +342,24 @@ void AIS_InteractiveContext::RemoveFilter(const Handle(SelectMgr_Filter)& aFilte
 
 void AIS_InteractiveContext::RemoveFilters()
 {
-  myFilters->Clear();
+  SetFilter (NULL);
 }
 
 //=======================================================================
 //function : Filters
 //purpose  : 
 //=======================================================================
-const SelectMgr_ListOfFilter& AIS_InteractiveContext::Filters() const 
+SelectMgr_ListOfFilter AIS_InteractiveContext::Filters() const 
 {
-  return myFilters->StoredFilters();
+  Handle(SelectMgr_Filter) aFilter = Filter();
+  if (aFilter.IsNull())
+    return SelectMgr_ListOfFilter();
+
+  Handle (SelectMgr_CompositionFilter) aCompositeFilter = Handle(SelectMgr_CompositionFilter)::DownCast (aFilter);
+  if (aCompositeFilter.IsNull())
+    return SelectMgr_ListOfFilter();
+
+  return aCompositeFilter->StoredFilters();
 }
 
 //=======================================================================
index 6f7840e5fd9c405456ba27ccc65f37039327fa72..91357cdf2878bcb815e2b667b4acc11fc25e948d 100644 (file)
@@ -23,7 +23,7 @@
 #include <Quantity_Color.hxx>
 #include <SelectMgr_EntityOwner.hxx>
 #include <SelectMgr_Filter.hxx>
-#include <SelectMgr_OrFilter.hxx>
+#include <SelectMgr_AndFilter.hxx>
 #include <SelectMgr_SelectionManager.hxx>
 #include <Standard_Transient.hxx>
 #include <TCollection_AsciiString.hxx>
index 4b9152d7dad5eaece7fb4dc795ea2686615f42f5..e921808bcd72c643574e782c0d15e5ce16a48ce5 100755 (executable)
@@ -7,6 +7,8 @@ SelectMgr_BaseFrustum.hxx
 SelectMgr_CompositionFilter.cxx
 SelectMgr_CompositionFilter.hxx
 SelectMgr_CompositionFilter.lxx
+SelectMgr_DisabledObjectsFilter.cxx
+SelectMgr_DisabledObjectsFilter.hxx
 SelectMgr_EntityOwner.cxx
 SelectMgr_EntityOwner.hxx
 SelectMgr_Filter.cxx
diff --git a/src/SelectMgr/SelectMgr_DisabledObjectsFilter.cxx b/src/SelectMgr/SelectMgr_DisabledObjectsFilter.cxx
new file mode 100644 (file)
index 0000000..71fd54f
--- /dev/null
@@ -0,0 +1,53 @@
+// This file is part of Open CASCADE Technology software library.
+//
+// This library is free software; you can redistribute it and/or modify it under
+// the terms of the GNU Lesser General Public License version 2.1 as published
+// by the Free Software Foundation, with special exception defined in the file
+// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
+// distribution for complete text of the license and disclaimer of any warranty.
+//
+// Alternatively, this file may be used under the terms of Open CASCADE
+// commercial license or contractual agreement.
+
+
+#include <SelectMgr_EntityOwner.hxx>
+#include <SelectMgr_Filter.hxx>
+#include <SelectMgr_ListIteratorOfListOfFilter.hxx>
+#include <SelectMgr_DisabledObjectsFilter.hxx>
+#include <SelectMgr_SelectableObject.hxx>
+#include <Standard_Type.hxx>
+
+IMPLEMENT_STANDARD_RTTIEXT(SelectMgr_DisabledObjectsFilter, SelectMgr_Filter)
+
+//=============================================================================
+//function : SelectMgr_DisabledObjectsFilter
+//purpose  :
+//=============================================================================
+SelectMgr_DisabledObjectsFilter::SelectMgr_DisabledObjectsFilter()
+{
+}
+
+//=============================================================================
+//function : SetDisabledObjects
+//purpose  :
+//=============================================================================
+void SelectMgr_DisabledObjectsFilter::SetDisabledObjects (const Handle(Graphic3d_NMapOfTransient)& theObjects)
+{
+  myDisabledObjects = theObjects;
+}
+
+//=============================================================================
+//function : IsOk
+//purpose  :
+//=============================================================================
+Standard_Boolean SelectMgr_DisabledObjectsFilter::IsOk (const Handle(SelectMgr_EntityOwner)& theObj) const
+{
+  const SelectMgr_SelectableObject* aSelectable = theObj->Selectable().operator->();
+  if (!myDisabledObjects.IsNull()
+    && myDisabledObjects->Contains (aSelectable))
+  {
+    return Standard_False;
+  }
+
+  return Standard_True;
+}
diff --git a/src/SelectMgr/SelectMgr_DisabledObjectsFilter.hxx b/src/SelectMgr/SelectMgr_DisabledObjectsFilter.hxx
new file mode 100644 (file)
index 0000000..cec6604
--- /dev/null
@@ -0,0 +1,59 @@
+//
+// This file is part of Open CASCADE Technology software library.
+//
+// This library is free software; you can redistribute it and/or modify it under
+// the terms of the GNU Lesser General Public License version 2.1 as published
+// by the Free Software Foundation, with special exception defined in the file
+// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
+// distribution for complete text of the license and disclaimer of any warranty.
+//
+// Alternatively, this file may be used under the terms of Open CASCADE
+// commercial license or contractual agreement.
+
+#ifndef _SelectMgr_DisabledObjectsFilter_HeaderFile
+#define _SelectMgr_DisabledObjectsFilter_HeaderFile
+
+#include <Standard.hxx>
+#include <Standard_Type.hxx>
+
+#include <Graphic3d_NMapOfTransient.hxx>
+#include <Standard_Boolean.hxx>
+
+class SelectMgr_EntityOwner;
+
+
+class SelectMgr_DisabledObjectsFilter;
+DEFINE_STANDARD_HANDLE(SelectMgr_DisabledObjectsFilter, SelectMgr_Filter)
+
+//! A framework to define an or selection filter.
+//! This selects one or another type of sensitive entity.
+class SelectMgr_DisabledObjectsFilter : public SelectMgr_Filter
+{
+
+public:
+
+  //! Constructs an empty or selection filter.
+  Standard_EXPORT SelectMgr_DisabledObjectsFilter();
+  
+  Standard_EXPORT Standard_Boolean IsOk (const Handle(SelectMgr_EntityOwner)& anobj) const Standard_OVERRIDE;
+
+  //! Disable selection of specified objects.
+  Standard_EXPORT void SetDisabledObjects (const Handle(Graphic3d_NMapOfTransient)& theObjects);
+
+
+  DEFINE_STANDARD_RTTIEXT(SelectMgr_DisabledObjectsFilter, SelectMgr_Filter)
+
+private:
+
+  Handle(Graphic3d_NMapOfTransient) myDisabledObjects;
+
+
+};
+
+
+
+
+
+
+
+#endif // _SelectMgr_DisabledObjectsFilter_HeaderFile
index fe84f35b7f27209ec2562d317655bf61f119dcc5..cedfb54a993c4cdc4894059eefc564fb62a196dc 100644 (file)
@@ -15,9 +15,7 @@
 
 #include <SelectMgr_EntityOwner.hxx>
 #include <SelectMgr_Filter.hxx>
-#include <SelectMgr_ListIteratorOfListOfFilter.hxx>
 #include <SelectMgr_OrFilter.hxx>
-#include <SelectMgr_SelectableObject.hxx>
 #include <Standard_Type.hxx>
 
 IMPLEMENT_STANDARD_RTTIEXT(SelectMgr_OrFilter,SelectMgr_CompositionFilter)
@@ -30,28 +28,13 @@ SelectMgr_OrFilter::SelectMgr_OrFilter()
 {
 }
 
-//=============================================================================
-//function : SetDisabledObjects
-//purpose  :
-//=============================================================================
-void SelectMgr_OrFilter::SetDisabledObjects (const Handle(Graphic3d_NMapOfTransient)& theObjects)
-{
-  myDisabledObjects = theObjects;
-}
-
 //=============================================================================
 //function : IsOk
 //purpose  :
 //=============================================================================
 Standard_Boolean SelectMgr_OrFilter::IsOk (const Handle(SelectMgr_EntityOwner)& theObj) const
 {
-  const SelectMgr_SelectableObject* aSelectable = theObj->Selectable().operator->();
-  if (!myDisabledObjects.IsNull()
-    && myDisabledObjects->Contains (aSelectable))
-  {
-    return Standard_False;
-  }
-  else if (myFilters.IsEmpty())
+  if (myFilters.IsEmpty())
   {
     return Standard_True;
   }
index f4625740d37cf1cf5912aea2c3932977e40d8d64..192b7e0c9cf1f5219310e46bc705eb17bbb98f71 100644 (file)
@@ -20,7 +20,6 @@
 #include <Standard.hxx>
 #include <Standard_Type.hxx>
 
-#include <Graphic3d_NMapOfTransient.hxx>
 #include <SelectMgr_CompositionFilter.hxx>
 #include <Standard_Boolean.hxx>
 class SelectMgr_EntityOwner;
@@ -41,26 +40,11 @@ public:
   Standard_EXPORT SelectMgr_OrFilter();
   
   Standard_EXPORT Standard_Boolean IsOk (const Handle(SelectMgr_EntityOwner)& anobj) const Standard_OVERRIDE;
-  
-  //! Disable selection of specified objects.
-  Standard_EXPORT void SetDisabledObjects (const Handle(Graphic3d_NMapOfTransient)& theObjects);
-
-
-
 
   DEFINE_STANDARD_RTTIEXT(SelectMgr_OrFilter,SelectMgr_CompositionFilter)
 
 protected:
 
-
-
-
-private:
-
-
-  Handle(Graphic3d_NMapOfTransient) myDisabledObjects;
-
-
 };