From 1e756cb9798b506d9f9cf6419e49a752764ce291 Mon Sep 17 00:00:00 2001 From: kgv Date: Tue, 26 Feb 2019 08:17:19 +0300 Subject: [PATCH] 0030520: VIS - IVtkTools_ShapePicker::GetPickPosition() returns incorrect point vmoveto and ivtkmoveto commands now print topmost picked 3D point. --- src/IVtkDraw/IVtkDraw.cxx | 4 ++++ src/IVtkDraw/IVtkDraw_Interactor.hxx | 1 + src/IVtkOCC/IVtkOCC_ShapePickerAlgo.cxx | 8 ++++++++ src/IVtkOCC/IVtkOCC_ShapePickerAlgo.hxx | 4 ++++ src/IVtkTools/IVtkTools_ShapePicker.cxx | 4 ++++ src/ViewerTest/ViewerTest_ViewerCommands.cxx | 13 ++++++++++++- 6 files changed, 33 insertions(+), 1 deletion(-) diff --git a/src/IVtkDraw/IVtkDraw.cxx b/src/IVtkDraw/IVtkDraw.cxx index 18ccdb92d8..9c517db488 100644 --- a/src/IVtkDraw/IVtkDraw.cxx +++ b/src/IVtkDraw/IVtkDraw.cxx @@ -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; } diff --git a/src/IVtkDraw/IVtkDraw_Interactor.hxx b/src/IVtkDraw/IVtkDraw_Interactor.hxx index 9a1977c833..2bfe759781 100644 --- a/src/IVtkDraw/IVtkDraw_Interactor.hxx +++ b/src/IVtkDraw/IVtkDraw_Interactor.hxx @@ -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); diff --git a/src/IVtkOCC/IVtkOCC_ShapePickerAlgo.cxx b/src/IVtkOCC/IVtkOCC_ShapePickerAlgo.cxx index dca1ebf01f..520fdbc77c 100644 --- a/src/IVtkOCC/IVtkOCC_ShapePickerAlgo.cxx +++ b/src/IVtkOCC/IVtkOCC_ShapePickerAlgo.cxx @@ -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(); diff --git a/src/IVtkOCC/IVtkOCC_ShapePickerAlgo.hxx b/src/IVtkOCC/IVtkOCC_ShapePickerAlgo.hxx index fb452a4cc0..b0865c698e 100644 --- a/src/IVtkOCC/IVtkOCC_ShapePickerAlgo.hxx +++ b/src/IVtkOCC/IVtkOCC_ShapePickerAlgo.hxx @@ -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; }; diff --git a/src/IVtkTools/IVtkTools_ShapePicker.cxx b/src/IVtkTools/IVtkTools_ShapePicker.cxx index b94c364282..5d272f50d0 100644 --- a/src/IVtkTools/IVtkTools_ShapePicker.cxx +++ b/src/IVtkTools/IVtkTools_ShapePicker.cxx @@ -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(); } //============================================================================ diff --git a/src/ViewerTest/ViewerTest_ViewerCommands.cxx b/src/ViewerTest/ViewerTest_ViewerCommands.cxx index 7d04971c7c..0992d83ff6 100644 --- a/src/ViewerTest/ViewerTest_ViewerCommands.cxx +++ b/src/ViewerTest/ViewerTest_ViewerCommands.cxx @@ -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; }