]> OCCT Git - occt-copy.git/commitdiff
0031549: Draw Harness, ViewerTest - add interactive polygon definition mode to vselec... CR31549
authormkrylova <mkrylova@opencascade.com>
Tue, 16 Jun 2020 12:16:34 +0000 (15:16 +0300)
committermkrylova <mkrylova@opencascade.com>
Tue, 16 Jun 2020 12:16:34 +0000 (15:16 +0300)
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
src/AIS/AIS_ViewController.cxx
src/AIS/AIS_ViewController.hxx
src/ViewerTest/ViewerTest_EventManager.cxx
src/ViewerTest/ViewerTest_EventManager.hxx
src/ViewerTest/ViewerTest_ViewerCommands.cxx

index 22c9086693b55f63644d35acdc446c469e93e02f..0d46aa626f8bf3b36a8a39fe5b84866491140010 100644 (file)
@@ -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
index c377d82e916d0700653761a98028de6772caf866..1447e34f208a78a382409ddcd6f686fb7d5b8ad1 100644 (file)
@@ -149,6 +149,15 @@ AIS_ViewController::~AIS_ViewController()
   //
 }
 
+// =======================================================================
+// function : ActivatePolygonalSelection
+// purpose  :
+// =======================================================================
+void AIS_ViewController::ActivatePolygonalSelection()
+{
+  myMouseActiveGesture = AIS_MouseGesture_SelectPolygonal;
+}
+
 // =======================================================================
 // function : ResetViewInput
 // purpose  :
index 119fa8ca76df3f19aa379fe2b4b1adea4a55072f..b02c38c053371ac9353399fb940b9d2b4f625ebb 100644 (file)
@@ -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:
 
index 4dffd897683343561044b353d8524a6ba15425f4..821f439710b41298ed726f305b2eab3a52a78dd6 100644 (file)
@@ -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();
+      }
     }
   }
 
index 6d2fed7caf120ae4b6856a790c92fd00290c1d5d..3686128c1ca0df90bd65f34d8e7765caba73fe38 100644 (file)
@@ -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
index 6e924399a78f50afd3e1616b6d9673c5fdf0e2b6..9957db0811b4894da9aa0120df21a2055a82b265 100644 (file)
@@ -7615,7 +7615,7 @@ static Standard_Integer VSelect (Draw_Interpretor& ,
   }
 
   NCollection_Sequence<Graphic3d_Vec2i> 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)