From 163e58793e90b5bc6abf6d726623273549defe25 Mon Sep 17 00:00:00 2001 From: mkrylova Date: Tue, 16 Jun 2020 15:16:34 +0300 Subject: [PATCH] 0031549: Draw Harness, ViewerTest - add interactive polygon definition mode to vselect command Has been added an option to interactive polygonal selection by - addition new option "-polygonal" to vselect command - addition activation polygonal selection mode in ViewerTest_ViewerCommands - addition new AIS_MouseGesture - addition new function in AIS_ViewController to set new AIS_MouseGesture - addition Boolean variable in ViewerTest_EventManager to enable/disable polygonal selection - editing functions in ViewerTest_EventManager for manipulation with selection --- src/AIS/AIS_MouseGesture.hxx | 2 + src/AIS/AIS_ViewController.cxx | 9 +++ src/AIS/AIS_ViewController.hxx | 2 + src/ViewerTest/ViewerTest_EventManager.cxx | 61 ++++++++++++++++---- src/ViewerTest/ViewerTest_EventManager.hxx | 4 +- src/ViewerTest/ViewerTest_ViewerCommands.cxx | 11 +++- 6 files changed, 77 insertions(+), 12 deletions(-) diff --git a/src/AIS/AIS_MouseGesture.hxx b/src/AIS/AIS_MouseGesture.hxx index 22c9086693..0d46aa626f 100644 --- a/src/AIS/AIS_MouseGesture.hxx +++ b/src/AIS/AIS_MouseGesture.hxx @@ -25,6 +25,8 @@ enum AIS_MouseGesture //! press button to start, move mouse to define rectangle, release to finish AIS_MouseGesture_SelectLasso, //!< polygonal selection; //! press button to start, move mouse to define polygonal path, release to finish + AIS_MouseGesture_SelectPolygonal, //!< polygonal selection; + //! press buttons to define the vertices of the polygon, click on the first vertex or Esc to finish // AIS_MouseGesture_Zoom, //!< view zoom gesture; //! move mouse left to zoom-out, and to the right to zoom-in diff --git a/src/AIS/AIS_ViewController.cxx b/src/AIS/AIS_ViewController.cxx index c377d82e91..1447e34f20 100644 --- a/src/AIS/AIS_ViewController.cxx +++ b/src/AIS/AIS_ViewController.cxx @@ -149,6 +149,15 @@ AIS_ViewController::~AIS_ViewController() // } +// ======================================================================= +// function : ActivatePolygonalSelection +// purpose : +// ======================================================================= +void AIS_ViewController::ActivatePolygonalSelection() +{ + myMouseActiveGesture = AIS_MouseGesture_SelectPolygonal; +} + // ======================================================================= // function : ResetViewInput // purpose : diff --git a/src/AIS/AIS_ViewController.hxx b/src/AIS/AIS_ViewController.hxx index 119fa8ca76..b02c38c053 100644 --- a/src/AIS/AIS_ViewController.hxx +++ b/src/AIS/AIS_ViewController.hxx @@ -598,6 +598,8 @@ public: const Handle(V3d_View)& theView, const gp_Trsf& thePose, const Standard_Boolean theToHighlight); + //! Activate polygonal selection mode. + Standard_EXPORT void ActivatePolygonalSelection(); protected: diff --git a/src/ViewerTest/ViewerTest_EventManager.cxx b/src/ViewerTest/ViewerTest_EventManager.cxx index 4dffd89768..821f439710 100644 --- a/src/ViewerTest/ViewerTest_EventManager.cxx +++ b/src/ViewerTest/ViewerTest_EventManager.cxx @@ -45,7 +45,8 @@ ViewerTest_EventManager::ViewerTest_EventManager (const Handle(V3d_View)& const Handle(AIS_InteractiveContext)& theCtx) : myCtx (theCtx), myView (theView), - myToPickPnt (Standard_False) + myToPickPnt (Standard_False), + myToSelectPolygon (Standard_False) { myViewAnimation = GlobalViewAnimation(); } @@ -64,30 +65,63 @@ ViewerTest_EventManager::~ViewerTest_EventManager() } } +//======================================================================= +//function : PolygonalSelection +//purpose : +//======================================================================= +void ViewerTest_EventManager::SelectPolygon() +{ + ActivatePolygonalSelection(); + myToSelectPolygon = Standard_True; +} + + //======================================================================= //function : UpdateMouseButtons //purpose : //======================================================================= -bool ViewerTest_EventManager::UpdateMouseButtons (const Graphic3d_Vec2i& thePoint, - Aspect_VKeyMouse theButtons, - Aspect_VKeyFlags theModifiers, - bool theIsEmulated) +bool ViewerTest_EventManager::UpdateMouseButtons(const Graphic3d_Vec2i& thePoint, + Aspect_VKeyMouse theButtons, + Aspect_VKeyFlags theModifiers, + bool theIsEmulated) { - SetAllowRotation (!ViewerTest_V3dView::IsCurrentViewIn2DMode()); + SetAllowRotation(!ViewerTest_V3dView::IsCurrentViewIn2DMode()); if (theButtons == Aspect_VKeyMouse_LeftButton) { if (myToPickPnt && (theModifiers & Aspect_VKeyFlags_CTRL) != 0) { Graphic3d_Vec3d anXYZ; - myView->Convert (thePoint.x(), thePoint.y(), anXYZ.x(), anXYZ.y(), anXYZ.z()); - Draw::Set (myPickPntArgVec[0].ToCString(), anXYZ.x()); - Draw::Set (myPickPntArgVec[1].ToCString(), anXYZ.y()); - Draw::Set (myPickPntArgVec[2].ToCString(), anXYZ.z()); + myView->Convert(thePoint.x(), thePoint.y(), anXYZ.x(), anXYZ.y(), anXYZ.z()); + Draw::Set(myPickPntArgVec[0].ToCString(), anXYZ.x()); + Draw::Set(myPickPntArgVec[1].ToCString(), anXYZ.y()); + Draw::Set(myPickPntArgVec[2].ToCString(), anXYZ.z()); myToPickPnt = false; } } + if (myToSelectPolygon) + { + if ((theButtons & Aspect_VKeyMouse_LeftButton) == Aspect_VKeyMouse_LeftButton) + { + if (!myUI.Selection.Points.IsEmpty()) + { + if (myUI.Selection.Points.First() == thePoint) + { + myUI.Selection.ToApplyTool = true; + myToSelectPolygon = Standard_False; + } + } + UpdatePolySelection(thePoint, true); + FlushViewEvents(myCtx, myView, true); + return true; + } + else if (((theButtons & Aspect_VKeyMouse_RightButton) == Aspect_VKeyMouse_RightButton) + && (!myUI.Selection.Points.IsEmpty())) + { + myUI.Selection.Points.Remove(myUI.Selection.Points.Size()); + } + } return AIS_ViewController::UpdateMouseButtons (thePoint, theButtons, theModifiers, theIsEmulated); } @@ -338,6 +372,13 @@ void ViewerTest_EventManager::ProcessKeyPress (Aspect_VKey theKey) { Draw_Interprete (ViewerTest_EventManager::ToExitOnCloseView() ? "exit" : "vclose"); } + if (myToSelectPolygon) + { + myToSelectPolygon = false; + myUI.Selection.Points.Clear(); + myView->Redraw(); + myView->Invalidate(); + } } } diff --git a/src/ViewerTest/ViewerTest_EventManager.hxx b/src/ViewerTest/ViewerTest_EventManager.hxx index 6d2fed7caf..3686128c1c 100644 --- a/src/ViewerTest/ViewerTest_EventManager.hxx +++ b/src/ViewerTest/ViewerTest_EventManager.hxx @@ -94,6 +94,8 @@ public: //! Handle KeyPress event. Standard_EXPORT void ProcessKeyPress (Aspect_VKey theKey); + Standard_EXPORT void SelectPolygon (); + private: Handle(AIS_InteractiveContext) myCtx; @@ -101,7 +103,7 @@ private: TCollection_AsciiString myPickPntArgVec[3]; Standard_Boolean myToPickPnt; - + Standard_Boolean myToSelectPolygon; }; #endif // _ViewerTest_EventManager_HeaderFile diff --git a/src/ViewerTest/ViewerTest_ViewerCommands.cxx b/src/ViewerTest/ViewerTest_ViewerCommands.cxx index 6e924399a7..9957db0811 100644 --- a/src/ViewerTest/ViewerTest_ViewerCommands.cxx +++ b/src/ViewerTest/ViewerTest_ViewerCommands.cxx @@ -7615,7 +7615,7 @@ static Standard_Integer VSelect (Draw_Interpretor& , } NCollection_Sequence aPnts; - bool isShiftSelection = false, toAllowOverlap = false; + bool isShiftSelection = false, toAllowOverlap = false, toSelectPolygon = false; for (Standard_Integer anArgIter = 1; anArgIter < theNbArgs; ++anArgIter) { TCollection_AsciiString anArg (theArgVec[anArgIter]); @@ -7629,6 +7629,11 @@ static Standard_Integer VSelect (Draw_Interpretor& , ++anArgIter; } } + else if (anArg == "-polygonal") + { + std::cout << "Polygonal Selection is activated" << std::endl; + toSelectPolygon = true; + } else if (anArgIter + 1 < theNbArgs && anArg.IsIntegerValue() && TCollection_AsciiString (theArgVec[anArgIter + 1]).IsIntegerValue()) @@ -7654,6 +7659,10 @@ static Standard_Integer VSelect (Draw_Interpretor& , } Handle(ViewerTest_EventManager) aCurrentEventManager = ViewerTest::CurrentEventManager(); + if (toSelectPolygon) + { + aCurrentEventManager->SelectPolygon(); + } if (aPnts.IsEmpty()) { if (isShiftSelection) -- 2.39.5