0030520: VIS - IVtkTools_ShapePicker::GetPickPosition() returns incorrect point
authorkgv <kgv@opencascade.com>
Tue, 26 Feb 2019 05:17:19 +0000 (08:17 +0300)
committerapn <apn@opencascade.com>
Wed, 27 Feb 2019 16:51:02 +0000 (19:51 +0300)
vmoveto and ivtkmoveto commands now print topmost picked 3D point.

src/IVtkDraw/IVtkDraw.cxx
src/IVtkDraw/IVtkDraw_Interactor.hxx
src/IVtkOCC/IVtkOCC_ShapePickerAlgo.cxx
src/IVtkOCC/IVtkOCC_ShapePickerAlgo.hxx
src/IVtkTools/IVtkTools_ShapePicker.cxx
src/ViewerTest/ViewerTest_ViewerCommands.cxx

index 18ccdb9..9c517db 100644 (file)
@@ -899,6 +899,10 @@ static Standard_Integer VtkMoveTo(Draw_Interpretor& theDI,
 
   Standard_Integer anY = GetInteractor()->GetRenderWindow()->GetSize()[1] - atoi (theArgs[2]) - 1;
   GetInteractor()->MoveTo (atoi (theArgs[1]), anY);
+
+  gp_XYZ aPickPnt;
+  GetInteractor()->Selector()->GetPickPosition (aPickPnt.ChangeData());
+  theDI << aPickPnt.X() << " " << aPickPnt.Y() << " " << aPickPnt.Z();
   return 0;
 }
 
index 9a1977c..2bfe759 100644 (file)
@@ -58,6 +58,7 @@ public:
   virtual void Enable();
   virtual void Start() { }
 
+  const PSelector& Selector() const { return mySelector; }
   void SetShapePicker (const PSelector& theSelector);
   void SetPipelines (const Handle(ShapePipelineMap)& thePipelines);
   void SetOCCWindow (const Handle(Aspect_Window)& theWindow);
index dca1ebf..520fdbc 100644 (file)
@@ -269,6 +269,7 @@ void IVtkOCC_ShapePickerAlgo::SubShapesPicked (const IVtk_IdType theId, IVtk_Sha
 //================================================================
 void IVtkOCC_ShapePickerAlgo::clearPicked()
 {
+  myTopPickedPoint.SetCoord (RealLast(), RealLast(), RealLast());
   myShapesPicked.Clear();
   mySubShapesPicked.Clear();
 }
@@ -289,9 +290,11 @@ int IVtkOCC_ShapePickerAlgo::NbPicked()
 bool IVtkOCC_ShapePickerAlgo::processPicked()
 {
   Standard_Integer aNbPicked =  myViewerSelector->NbPicked();
+
   Handle(StdSelect_BRepOwner) anEntityOwner;
   Handle(Message_Messenger) anOutput = Message::DefaultMessenger();
 
+  bool isTop = true;
   for (Standard_Integer aDetectIt = 1; aDetectIt <= aNbPicked; aDetectIt++)
   {
     // ViewerSelector detects sensitive entities under the mouse
@@ -320,6 +323,11 @@ bool IVtkOCC_ShapePickerAlgo::processPicked()
 
       IVtk_IdType aTopLevelId = aSelShape->GetId();
       myShapesPicked.Append (aTopLevelId);
+      if (isTop)
+      {
+        isTop = false;
+        myTopPickedPoint = myViewerSelector->PickedPoint (aDetectIt);
+      }
 
       // Now try to guess if it's the top-level shape itself or just a sub-shape picked
       TopoDS_Shape aTopLevelShape = aSelShape->GetShape();
index fb452a4..b0865c6 100644 (file)
@@ -100,6 +100,9 @@ public: //! @name Obtain picking results
   //! @param [in] theShape the selectable shape
   Standard_EXPORT virtual void RemoveSelectableObject(const IVtk_IShape::Handle& theShape);
 
+  //! Return topmost picked 3D point or (Inf, Inf, Inf) if undefined.
+  const gp_Pnt& TopPickedPoint() const { return myTopPickedPoint; }
+
 public:
 
   DEFINE_STANDARD_RTTIEXT(IVtkOCC_ShapePickerAlgo,IVtk_IShapePickerAlgo)
@@ -121,6 +124,7 @@ private:
   IVtk_IView::Handle             myView;
   IVtk_ShapeIdList               myShapesPicked;
   IVtk_SubShapeMap               mySubShapesPicked;
+  gp_Pnt                         myTopPickedPoint;
   Handle(IVtkOCC_ViewerSelector) myViewerSelector;
 };
 
index b94c364..5d272f5 100644 (file)
@@ -193,6 +193,10 @@ void IVtkTools_ShapePicker::doPickImpl (double* thePos,
   {
     myOccPickerAlgo->Pick (thePos[0], thePos[1]);
   }
+
+  PickPosition[0] = myOccPickerAlgo->TopPickedPoint().X();
+  PickPosition[1] = myOccPickerAlgo->TopPickedPoint().Y();
+  PickPosition[2] = myOccPickerAlgo->TopPickedPoint().Z();
 }
 
 //============================================================================
index 7d04971..0992d83 100644 (file)
@@ -6704,7 +6704,7 @@ static Standard_Integer VSelect (Draw_Interpretor& di,
 //function : VMoveTo
 //purpose  : Emulates cursor movement to defined pixel position
 //=======================================================================
-static Standard_Integer VMoveTo (Draw_Interpretor& ,
+static Standard_Integer VMoveTo (Draw_Interpretor& theDI,
                                 Standard_Integer theNbArgs,
                                 const char**     theArgVec)
 {
@@ -6767,6 +6767,17 @@ static Standard_Integer VMoveTo (Draw_Interpretor& ,
   }
 
   ViewerTest::CurrentEventManager()->MoveTo (aMousePos.x(), aMousePos.y());
+  gp_Pnt aTopPnt (RealLast(), RealLast(), RealLast());
+  const Handle(SelectMgr_EntityOwner)& aDetOwner = aContext->DetectedOwner();
+  for (Standard_Integer aDetIter = 1; aDetIter <= aContext->MainSelector()->NbPicked(); ++aDetIter)
+  {
+    if (aContext->MainSelector()->Picked (aDetIter) == aDetOwner)
+    {
+      aTopPnt = aContext->MainSelector()->PickedPoint (aDetIter);
+      break;
+    }
+  }
+  theDI << aTopPnt.X() << " " << aTopPnt.Y() << " " << aTopPnt.Z();
   return 0;
 }