0029724: Visualization - add AIS_InteractiveContext::ClearDetected() undoing MoveTo...
authorkgv <kgv@opencascade.com>
Wed, 25 Apr 2018 08:38:11 +0000 (11:38 +0300)
committerabv <abv@opencascade.com>
Thu, 24 May 2018 12:36:20 +0000 (15:36 +0300)
Introduced new method AIS_InteractiveContext::ClearDetected() allowing
to reset the list of detected objects and clear dynamically highlighted
entity under mouse cursor after previous AIS_InteractiveContext::MoveTo().

vmoveto command has been extended with new argument -reset.

src/AIS/AIS_InteractiveContext.cxx
src/AIS/AIS_InteractiveContext.hxx
src/SelectMgr/SelectMgr_ViewerSelector.cxx
src/SelectMgr/SelectMgr_ViewerSelector.hxx
src/ViewerTest/ViewerTest_ViewerCommands.cxx
tests/v3d/materials/bug27818_1

index 9f3f8b5..4e74d54 100644 (file)
@@ -2491,6 +2491,33 @@ void AIS_InteractiveContext::ClearGlobalPrs (const Handle(AIS_InteractiveObject)
   }
 }
 
   }
 }
 
+//=======================================================================
+//function : ClearDetected
+//purpose  :
+//=======================================================================
+Standard_Boolean AIS_InteractiveContext::ClearDetected (Standard_Boolean theToRedrawImmediate)
+{
+  myCurDetected = 0;
+  myCurHighlighted = 0;
+  myDetectedSeq.Clear();
+  myLastPicked  = myLastinMain;
+  myWasLastMain = Standard_True;
+  Standard_Boolean toUpdate = Standard_False;
+  if (!myLastPicked.IsNull() && myLastPicked->HasSelectable())
+  {
+    toUpdate = Standard_True;
+    clearDynamicHighlight();
+  }
+  myLastinMain.Nullify();
+  myLastPicked.Nullify();
+  myMainSel->ClearPicked();
+  if (toUpdate && theToRedrawImmediate)
+  {
+    myMainVwr->RedrawImmediate();
+  }
+  return toUpdate;
+}
+
 //=======================================================================
 //function : DrawHiddenLine
 //purpose  :
 //=======================================================================
 //function : DrawHiddenLine
 //purpose  :
index 2893ab0..7349692 100644 (file)
@@ -347,6 +347,11 @@ public: //! @name mouse picking logic (detection and dynamic highlighting of ent
                                                 const Handle(V3d_View)& theView,
                                                 const Standard_Boolean  theToRedrawOnUpdate);
 
                                                 const Handle(V3d_View)& theView,
                                                 const Standard_Boolean  theToRedrawOnUpdate);
 
+  //! Clears the list of entities detected by MoveTo() and resets dynamic highlighting.
+  //! @param theToRedrawImmediate if TRUE, the main Viewer will be redrawn on update
+  //! @return TRUE if viewer needs to be updated (e.g. there were actually dynamically highlighted entities)
+  Standard_EXPORT Standard_Boolean ClearDetected (Standard_Boolean theToRedrawImmediate = Standard_False);
+
   //! Returns true if there is a mouse-detected entity in context.
   //! @sa DetectedOwner()/HasNextDetected()/HilightPreviousDetected()/HilightNextDetected().
   Standard_EXPORT Standard_Boolean HasDetected() const;
   //! Returns true if there is a mouse-detected entity in context.
   //! @sa DetectedOwner()/HasNextDetected()/HilightPreviousDetected()/HilightNextDetected().
   Standard_EXPORT Standard_Boolean HasDetected() const;
index 8709197..a555ab7 100644 (file)
@@ -623,6 +623,15 @@ void SelectMgr_ViewerSelector::TraverseSensitives()
   SortResult();
 }
 
   SortResult();
 }
 
+//==================================================
+// Function: ClearPicked
+// Purpose :
+//==================================================
+void SelectMgr_ViewerSelector::ClearPicked()
+{
+  mystored.Clear();
+}
+
 //==================================================
 // Function: Picked
 // Purpose :
 //==================================================
 // Function: Picked
 // Purpose :
index 4cbe359..275e2e9 100644 (file)
@@ -112,6 +112,9 @@ public:
   //! Returns the number of detected owners.
   Standard_Integer NbPicked() const { return mystored.Extent(); }
 
   //! Returns the number of detected owners.
   Standard_Integer NbPicked() const { return mystored.Extent(); }
 
+  //! Clears picking results.
+  Standard_EXPORT void ClearPicked();
+
   //! Returns the entity Owner for the object picked at specified position.
   //! @param theRank rank of detected object within range 1...NbPicked()
   Standard_EXPORT Handle(SelectMgr_EntityOwner) Picked (const Standard_Integer theRank) const;
   //! Returns the entity Owner for the object picked at specified position.
   //! @param theRank rank of detected object within range 1...NbPicked()
   Standard_EXPORT Handle(SelectMgr_EntityOwner) Picked (const Standard_Integer theRank) const;
index 89f0774..d1c8f2e 100644 (file)
@@ -26,6 +26,7 @@
 #include <AIS_InteractiveObject.hxx>
 #include <AIS_ListOfInteractive.hxx>
 #include <AIS_ListIteratorOfListOfInteractive.hxx>
 #include <AIS_InteractiveObject.hxx>
 #include <AIS_ListOfInteractive.hxx>
 #include <AIS_ListIteratorOfListOfInteractive.hxx>
+#include <Aspect_Grid.hxx>
 #include <DBRep.hxx>
 #include <Draw_ProgressIndicator.hxx>
 #include <Graphic3d_ArrayOfPolylines.hxx>
 #include <DBRep.hxx>
 #include <Draw_ProgressIndicator.hxx>
 #include <Graphic3d_ArrayOfPolylines.hxx>
@@ -6667,23 +6668,69 @@ static Standard_Integer VSelect (Draw_Interpretor& di,
 //function : VMoveTo
 //purpose  : Emulates cursor movement to defined pixel position
 //=======================================================================
 //function : VMoveTo
 //purpose  : Emulates cursor movement to defined pixel position
 //=======================================================================
-static Standard_Integer VMoveTo (Draw_Interpretor& di,
-                                Standard_Integer argc,
-                                const char ** argv)
+static Standard_Integer VMoveTo (Draw_Interpretor& ,
+                                Standard_Integer theNbArgs,
+                                const char**     theArgVec)
 {
 {
-  if(argc != 3)
+  const Handle(AIS_InteractiveContext)& aContext = ViewerTest::GetAISContext();
+  const Handle(V3d_View)&               aView    = ViewerTest::CurrentView();
+  if (aContext.IsNull())
   {
   {
-    di << "Usage : " << argv[0] << " x y\n";
+    std::cout << "Error: no active View\n";
     return 1;
   }
 
     return 1;
   }
 
-  Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
-  if(aContext.IsNull())
+  Graphic3d_Vec2i aMousePos (IntegerLast(), IntegerLast());
+  for (Standard_Integer anArgIter = 1; anArgIter < theNbArgs; ++anArgIter)
   {
   {
-    di << "use 'vinit' command before " << argv[0] << "\n";
+    TCollection_AsciiString anArgStr (theArgVec[anArgIter]);
+    anArgStr.LowerCase();
+    if (anArgStr == "-reset"
+     || anArgStr == "-clear")
+    {
+      if (anArgIter + 1 < theNbArgs)
+      {
+        std::cout << "Syntax error at '" << theArgVec[anArgIter + 1] << "'\n";
+        return 1;
+      }
+
+      const Standard_Boolean toEchoGrid = aContext->CurrentViewer()->Grid()->IsActive()
+                                       && aContext->CurrentViewer()->GridEcho();
+      if (toEchoGrid)
+      {
+        aContext->CurrentViewer()->HideGridEcho (aView);
+      }
+      if (aContext->ClearDetected() || toEchoGrid)
+      {
+        aContext->CurrentViewer()->RedrawImmediate();
+      }
+      return 0;
+    }
+    else if (aMousePos.x() == IntegerLast()
+          && anArgStr.IsIntegerValue())
+    {
+      aMousePos.x() = anArgStr.IntegerValue();
+    }
+    else if (aMousePos.y() == IntegerLast()
+          && anArgStr.IsIntegerValue())
+    {
+      aMousePos.y() = anArgStr.IntegerValue();
+    }
+    else
+    {
+      std::cout << "Syntax error at '" << theArgVec[anArgIter] << "'\n";
+      return 1;
+    }
+  }
+
+  if (aMousePos.x() == IntegerLast()
+   || aMousePos.y() == IntegerLast())
+  {
+    std::cout << "Syntax error: wrong number of arguments\n";
     return 1;
   }
     return 1;
   }
-  ViewerTest::CurrentEventManager()->MoveTo(atoi(argv[1]),atoi(argv[2]));
+
+  ViewerTest::CurrentEventManager()->MoveTo (aMousePos.x(), aMousePos.y());
   return 0;
 }
 
   return 0;
 }
 
@@ -12161,8 +12208,9 @@ void ViewerTest::ViewerCommands(Draw_Interpretor& theCommands)
     "- 5) any of these selections with shift button pressed",
     __FILE__, VSelect, group);
   theCommands.Add ("vmoveto",
     "- 5) any of these selections with shift button pressed",
     __FILE__, VSelect, group);
   theCommands.Add ("vmoveto",
-    "vmoveto x y"
-    "- emulates cursor movement to pixel postion (x,y)",
+    "vmoveto [x y] [-reset]"
+    "\n\t\t: Emulates cursor movement to pixel position (x,y)."
+    "\n\t\t:   -reset resets current highlighting",
     __FILE__, VMoveTo, group);
   theCommands.Add ("vviewparams",
               "vviewparams [-args] [-scale [s]]"
     __FILE__, VMoveTo, group);
   theCommands.Add ("vviewparams",
               "vviewparams [-args] [-scale [s]]"
index 8cfb491..3311235 100644 (file)
@@ -1,44 +1,30 @@
 puts "============"
 puts "============"
-puts "OCC27818_1"
+puts "0027818: Visualization - provide an interface to define highlight presentation properties"
+puts "Test change of highlight properties for whole interactive context"
 puts "============"
 puts ""
 puts "============"
 puts ""
-####################################################################################
-# Visualization - provide an interface to define highlight presentation properties:
-# test change of highlight properties for whole interactive context
-####################################################################################
-
 
 pload VISUALIZATION MODELING
 
 box b 10 20 30
 pcone p 15 0 40
 
 
 pload VISUALIZATION MODELING
 
 box b 10 20 30
 pcone p 15 0 40
 
-vinit
 vclear
 vclear
-
-vdisplay b -dispMode 1
-vdisplay p -dispMode 1
+vinit View1
+vdisplay b -dispMode 1 b p
 vsetcolor b RED
 vsetcolor b RED
-vsetcolor p GREEN
+vsetcolor p GRAY
+
+vviewparams -scale 17.8 -proj 0.892687 -0.331602 0.305206 -up -0.162521 0.394789 0.904284 -at 1.99 2.4 20.9
+vselprops dynHighlight -transp 0.3 -color PALEGREEN2 -dispMode 1
 
 
-vviewparams -scale 17.8 -proj 0.9 -0.3 0.3
-vviewparams -up -0.2 0.4 0.9 -at 1.99 2.4 20.9
-vviewparams -eye 56.1 -17.7 39.4
+vmoveto 285 212
+if { [vreadpixel 285 212 name rgb] != "DARKKHAKI" }     { puts "Error: highlighting of a box is not transparent!" }
 
 
-vselprops dynHighlight -transp 0.1 -color PALEGREEN2 -dispMode 1
+vmoveto -reset
+if { [vreadpixel 285 212 name rgb] != "RED" }           { puts "Error: highlighting of a box is not reset!" }
 
 vmoveto 167 263
 
 vmoveto 167 263
-set aPixelColor [vreadpixel 167 263 name rgba]
-set aTransp [lindex [split $aPixelColor { }] 1]
-if { $aTransp == 1 } {
-  puts "Error: highlighting of a cone is not transparent!"
-}
-
-vmoveto 285 212
-set aPixelColor [vreadpixel 285 212 name rgba]
-set aTransp [lindex [split $aPixelColor { }] 1]
-if { $aTransp == 1 } {
-  puts "Error: highlighting of a box is not transparent!"
-}
+if { [vreadpixel 167 263 name rgb] != "DARKSEAGREEN2" } { puts "Error: highlighting of a cone is not transparent!" }
 
 vdump $imagedir/${casename}.png
 
 vdump $imagedir/${casename}.png