]> OCCT Git - occt.git/commitdiff
0028365: Visualization, AIS_InteractiveContext - apply selection filter in AddOrRemov...
authornds <nds@opencascade.com>
Thu, 26 Jan 2017 14:16:09 +0000 (17:16 +0300)
committerapn <apn@opencascade.com>
Thu, 2 Feb 2017 13:03:48 +0000 (16:03 +0300)
src/AIS/AIS_InteractiveContext_1.cxx
src/ViewerTest/ViewerTest.cxx
tests/bugs/vis/bug28365 [new file with mode: 0644]

index 8cfcb6e1d187836677a1168e8beb56d51f83111b..0c181b46b5cee49bdbfe630354256ae213f16621 100644 (file)
@@ -1183,6 +1183,9 @@ void AIS_InteractiveContext::AddOrRemoveSelected (const Handle(SelectMgr_EntityO
   if (theOwner.IsNull() || !theOwner->HasSelectable())
     return;
 
+  if (!myFilters->IsOk(theOwner) && !theOwner->IsSelected())
+    return;
+
   AIS_SelectStatus aSelStat = mySelection->Select (theOwner);
   theOwner->SetSelected (aSelStat == AIS_SS_Added);
   const Handle(AIS_InteractiveObject) anObj =
index bdb5c6fe27080baf8c4a92e17ec22e10445403bb..58ec6a6c94d9113f5a7993c166be20f9a74ac371 100644 (file)
@@ -4947,6 +4947,62 @@ static int VPickShape( Draw_Interpretor& di, Standard_Integer argc, const char**
   return 0;
 }
 
+//=======================================================================
+//function : VSetFilter
+//purpose  :
+//=======================================================================
+static int VSetFilter(Draw_Interpretor& theDi, Standard_Integer theArgc,
+                      const char** theArgv)
+{
+  if (theArgc != 2)
+  {
+    theDi << theArgv[0] << " error : wrong number of parameters.\n";
+    return 1;
+  }
+
+  Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
+  if (aContext.IsNull())
+  {
+    std::cout << "Error: AIS context is not available.\n";
+    return 1;
+  }
+
+  TCollection_AsciiString anArg(theArgv[1]);
+  if (anArg.IsEqual("-clear")) {
+    aContext->RemoveFilters();
+  }
+  else {
+    TCollection_AsciiString aPName, aPValue;
+    if (!ViewerTest::SplitParameter (anArg, aPName, aPValue)) {
+      std::cout << "Error: wrong command attribute name" << std::endl;
+      return 1;
+    }
+
+    TopAbs_ShapeEnum aType = TopAbs_COMPOUND;
+    if(aPValue.IsEqual("VERTEX")) aType = TopAbs_VERTEX;
+    else if (aPValue.IsEqual("EDGE")) aType = TopAbs_EDGE;
+    else if (aPValue.IsEqual("WIRE")) aType = TopAbs_WIRE;
+    else if (aPValue.IsEqual("FACE")) aType = TopAbs_FACE;
+    else if(aPValue.IsEqual("SHAPE")) aType = TopAbs_SHAPE;
+    else if (aPValue.IsEqual("SHELL")) aType = TopAbs_SHELL;
+    else if (aPValue.IsEqual("SOLID")) aType = TopAbs_SOLID;
+    else {
+      std::cout << "Error: wrong command attribute value" << std::endl;
+      return 1;
+    }
+
+    if(aType==TopAbs_SHAPE){
+      Handle(AIS_TypeFilter) aFilter = new AIS_TypeFilter(AIS_KOI_Shape);
+      aContext->AddFilter(aFilter);
+    }
+    else{
+      Handle(StdSelect_ShapeTypeFilter) aFilter = new StdSelect_ShapeTypeFilter(aType);
+      aContext->AddFilter(aFilter);
+    }
+  }
+  return 0;
+}
+
 //=======================================================================
 //function : VPickSelected
 //purpose  :
@@ -5839,6 +5895,13 @@ void ViewerTest::Commands(Draw_Interpretor& theCommands)
       "\n\t\t: Reads shape from BREP-format file and displays it in the viewer. ",
                  __FILE__,vr, group);
 
+  theCommands.Add("vsetfilter",
+                 "vsetfilter [-type={VERTEX|EDGE|WIRE|FACE|SHAPE|SHELL|SOLID}] [-clear]"
+    "\nSets selection shape type filter in context or remove all filters."
+    "\n    : Option -type set type of selection filter. Filters are applyed with Or combination."
+    "\n    : Option -clear remove all filters in context",
+                 __FILE__,VSetFilter,group);
+
   theCommands.Add("vpickselected", "vpickselected [name]: extract selected shape.",
     __FILE__, VPickSelected, group);
 
diff --git a/tests/bugs/vis/bug28365 b/tests/bugs/vis/bug28365
new file mode 100644 (file)
index 0000000..b9cc399
--- /dev/null
@@ -0,0 +1,21 @@
+puts "==========="
+puts "OCC28365"
+puts "==========="
+puts ""
+##########################################################################
+# Visualization, AIS_InteractiveContext - apply selection filter in
+# AddOrRemoveSelected at Neutral point
+##########################################################################
+
+pload ALL
+vinit
+box b 10 10 10
+vdisplay b
+vfit
+vsetfilter -type=VERTEX
+vchangeselected b
+
+set NbSelected1 [vnbselected]
+if { ${NbSelected1} != 0 } {
+  puts "Error : Vertex filter was not applyed"
+}