Salome HOME
updated copyright message
[modules/gui.git] / src / SVTK / SVTK_InteractorStyle.cxx
index 7e99f5b7070ed50792533340b3d753c4bd75ec37..c990139da823ff3cab97a7a02c237eaa251f93fa 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2007-2013  CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2007-2023  CEA/DEN, EDF R&D, OPEN CASCADE
 //
 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
@@ -6,7 +6,7 @@
 // This library is free software; you can redistribute it and/or
 // modify it under the terms of the GNU Lesser General Public
 // License as published by the Free Software Foundation; either
-// version 2.1 of the License.
+// version 2.1 of the License, or (at your option) any later version.
 //
 // This library is distributed in the hope that it will be useful,
 // but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -48,6 +48,7 @@
 #include <vtkCamera.h>
 #include <vtkRenderer.h>
 #include <vtkPointPicker.h>
+#include <vtkCellPicker.h>
 #include <vtkRenderWindow.h>
 #include <vtkRenderWindowInteractor.h>
 #include <vtkCallbackCommand.h>
 #include <vtkPerspectiveTransform.h> 
 #include <vtkMatrix4x4.h>
 
+#include <QtxRubberBand.h>
+
 #include <QPixmap>
 #include <QWidget>
-#include <QRubberBand>
+#include <QPolygon>
 
 #include <algorithm>
 #include <iostream>
@@ -75,22 +78,25 @@ namespace
 }
 
 
-vtkStandardNewMacro(SVTK_InteractorStyle);
+vtkStandardNewMacro(SVTK_InteractorStyle)
 
 
 /*!
   Constructor
 */
 SVTK_InteractorStyle::SVTK_InteractorStyle():
-  mySelectionEvent(new SVTK_SelectionEvent()),
-  myPointPicker(vtkPointPicker::New()),
   myLastHighlitedActor(NULL),
   myLastPreHighlitedActor(NULL),
   myControllerIncrement(SVTK_ControllerIncrement::New()),
   myControllerOnKeyDown(SVTK_ControllerOnKeyDown::New()),
+  mySelectionEvent(new SVTK_SelectionEvent()),
   myHighlightSelectionPointActor(SVTK_Actor::New()),
+  myPointPicker(vtkPointPicker::New()),
   myRectBand(0),
-  myIsAdvancedZoomingEnabled(false)
+  myPolygonBand(0),
+  myPoligonState(Disable),
+  myIsAdvancedZoomingEnabled(false),
+  myInteractivePoint{0.0, 0.0, 0.0}
 {
   myPointPicker->Delete();
 
@@ -138,6 +144,7 @@ SVTK_InteractorStyle::SVTK_InteractorStyle():
 SVTK_InteractorStyle::~SVTK_InteractorStyle() 
 {
   endDrawRect();
+  endDrawPolygon();
 }
 
 /*!
@@ -156,6 +163,15 @@ SVTK_Selector* SVTK_InteractorStyle::GetSelector()
   return myInteractor->GetSelector();
 }
 
+/*!
+  Realeaze actors
+*/
+void SVTK_InteractorStyle::FreeActors()
+{
+  myLastHighlitedActor = NULL;
+  myLastPreHighlitedActor = NULL;
+}
+
 /*!
   Generate special SVTK_SelectionEvent
 */
@@ -451,6 +467,17 @@ void SVTK_InteractorStyle::OnMouseWheelBackward()
   myOtherPoint = QPoint(x, y);
 }
 
+/*!
+  To handle mouse double click event
+*/
+void SVTK_InteractorStyle::OnMouseButtonDoubleClick()
+{
+  if( myPoligonState == InProcess ) {
+    onFinishOperation();
+    myPoligonState = Finished;
+  }
+}
+
 /*!
   To handle mouse move event
 */
@@ -458,6 +485,12 @@ void SVTK_InteractorStyle::OnMouseMove(int vtkNotUsed(ctrl),
                                        int shift,
                                        int x, int y) 
 {
+  if ( myPoligonState == Start ) {
+    // if right button was pressed and mouse is moved
+    // we can to draw a polygon for polygonal selection
+    myPoligonState = InProcess;
+    startOperation( VTK_INTERACTOR_STYLE_CAMERA_SELECT );
+  }
   myShiftState = shift;
   if (State != VTK_INTERACTOR_STYLE_CAMERA_NONE)
     onOperation(QPoint(x, y));
@@ -475,6 +508,9 @@ void SVTK_InteractorStyle::OnLeftButtonDown(int ctrl, int shift,
   if(GetCurrentRenderer() == NULL)
     return;
 
+  if ( myPoligonState != Disable )
+    return;
+
   myShiftState = shift;
   // finishing current viewer operation
   if (State != VTK_INTERACTOR_STYLE_CAMERA_NONE) {
@@ -502,22 +538,61 @@ void SVTK_InteractorStyle::OnLeftButtonDown(int ctrl, int shift,
         {
           if( SALOME_Actor* anActor = SALOME_Actor::SafeDownCast( aVTKActor ) )
           {
-            SVTK::TPickLimiter aPickLimiter( myPointPicker, anActor );
-            myPointPicker->Pick( aSelectionEvent->myX,
-                                 aSelectionEvent->myY, 
-                                 0.0, 
+               Selection_Mode aSelectionMode = GetSelector()->SelectionMode();
+               double* aCoords = NULL;
+               vtkIdType aVtkId;
+               bool isTrueType = false;
+               
+               if( myCurrFocalPointType == SVTK::StartFocalPointSelection ||
+                       ( myCurrRotationPointType == SVTK::StartPointSelection && aSelectionMode == NodeSelection ) )
+               {
+              SVTK::TPickLimiter aPickLimiter( myPointPicker, anActor );
+              myPointPicker->Pick( aSelectionEvent->myX,
+                                   aSelectionEvent->myY,
+                                   0.0,
+                                   GetCurrentRenderer() );
+              aVtkId = myPointPicker->GetPointId();
+              if ( aVtkId >= 0 )
+              {
+                vtkIdType anObjId = anActor->GetNodeObjId( aVtkId );
+                aCoords = anActor->GetNodeCoord(anObjId);
+                isTrueType = true;
+              }
+               }
+
+               if( aSelectionMode == EdgeSelection || aSelectionMode == FaceSelection ||  aSelectionMode == VolumeSelection )
+               {
+              vtkSmartPointer<vtkCellPicker> aCellPicker = vtkCellPicker::New();
+              aCellPicker->SetTolerance( 0.005 );
+              SVTK::TPickLimiter aPickLimiter( aCellPicker, anActor );
+              aCellPicker->Pick( aSelectionEvent->myX,
+                                 aSelectionEvent->myY,
+                                 0.0,
                                  GetCurrentRenderer() );
-            int aVtkId = myPointPicker->GetPointId();
-            if ( aVtkId >= 0 )
-            {
-              int anObjId = anActor->GetNodeObjId( aVtkId );
-              double* aCoords = anActor->GetNodeCoord(anObjId);
-              
+              aVtkId = aCellPicker->GetCellId();
+              vtkIdType aCellId = anActor->GetElemObjId( aVtkId );
+
+              if( aSelectionMode == EdgeSelection )
+               isTrueType = anActor->GetObjDimension( aCellId ) == 1;
+              else if( aSelectionMode == FaceSelection )
+               isTrueType = anActor->GetObjDimension( aCellId ) == 2;
+              else if( aSelectionMode == VolumeSelection )
+               isTrueType = anActor->GetObjDimension( aCellId ) == 3;
+
+              if ( aVtkId >= 0 && isTrueType )
+                aCoords = anActor->GetGravityCenter( aCellId );
+               }
+
+               if( aVtkId >= 0 )
+               {
               if (myCurrRotationPointType == SVTK::StartPointSelection) {
                 myCurrRotationPointType = SVTK::SetRotateSelected;
-                
                 // invoke event for update coordinates in SVTK_SetRotationPointDlg
-                InvokeEvent(SVTK::RotationPointChanged,(void*)aCoords);
+                if( isTrueType )
+                  InvokeEvent(SVTK::RotationPointChanged,(void*)aCoords);
+                else
+                  InvokeEvent(SVTK::RotationPointChanged);
+                GetSelector()->SetSelectionMode(ActorSelection);
               }
               else if (myCurrFocalPointType == SVTK::StartFocalPointSelection) {
                 myCurrFocalPointType = SVTK::SetFocalPointSelected;
@@ -539,6 +614,7 @@ void SVTK_InteractorStyle::OnLeftButtonDown(int ctrl, int shift,
           // invoke event with no data (for SVTK_SetRotationPointDlg)
           InvokeEvent(SVTK::RotationPointChanged,0);
           myCurrRotationPointType = myPrevRotationPointType;
+          GetSelector()->SetSelectionMode(ActorSelection);
         }
         else if (myCurrFocalPointType == SVTK::StartFocalPointSelection) {
           // invoke event with no data (for SVTK_ViewParameterDlg)
@@ -565,14 +641,31 @@ void SVTK_InteractorStyle::OnLeftButtonDown(int ctrl, int shift,
 */
 void SVTK_InteractorStyle::OnLeftButtonUp(int vtkNotUsed(ctrl),
                                           int shift, 
-                                          int vtkNotUsed(x),
-                                          int vtkNotUsed(y))
+                                          int x,
+                                          int y)
 {
   myShiftState = shift;
+  if( myPoligonState == InProcess ) { // add a new point of polygon
+    myPolygonPoints.append( QPoint( x, y ) );
+    this->Interactor->GetEventPosition( mySelectionEvent->myX, mySelectionEvent->myY );
+    mySelectionEvent->myPolygonPoints.append( QPoint( mySelectionEvent->myX, mySelectionEvent->myY ) );
+    return;
+  }
+  else if ( myPoligonState == Closed ) { // close polygon and apply a selection
+    onFinishOperation();
+    myPoligonState = Finished;
+    return;
+  }
+  else if( myPoligonState == Finished || myPoligonState == NotValid )
+    return;
   // finishing current viewer operation
   if (State != VTK_INTERACTOR_STYLE_CAMERA_NONE) {
     onFinishOperation();
+    int lastOperation = State;
     startOperation(VTK_INTERACTOR_STYLE_CAMERA_NONE);
+    if (lastOperation == VTK_INTERACTOR_STYLE_CAMERA_INTERACTIVE_SELECTION) {
+      InvokeEvent(SVTK::InteractiveSelectionFinished, nullptr);
+    }
   }
 }
 
@@ -587,6 +680,9 @@ void SVTK_InteractorStyle::OnMiddleButtonDown(int ctrl,
   if(GetCurrentRenderer() == NULL)
     return;
 
+  if ( myPoligonState != Disable )
+    return;
+
   myShiftState = shift;
   // finishing current viewer operation
   if (State != VTK_INTERACTOR_STYLE_CAMERA_NONE) {
@@ -594,7 +690,8 @@ void SVTK_InteractorStyle::OnMiddleButtonDown(int ctrl,
     startOperation(VTK_INTERACTOR_STYLE_CAMERA_NONE);
   }
   myOtherPoint = myPoint = QPoint(x, y);
-  if (ForcedState != VTK_INTERACTOR_STYLE_CAMERA_NONE) {
+  if (ForcedState != VTK_INTERACTOR_STYLE_CAMERA_NONE &&
+      ForcedState != VTK_INTERACTOR_STYLE_CAMERA_INTERACTIVE_SELECTION) {
     startOperation(ForcedState);
   }
   else {
@@ -612,6 +709,13 @@ void SVTK_InteractorStyle::OnMiddleButtonUp(int vtkNotUsed(ctrl),
                                             int vtkNotUsed(x),
                                             int vtkNotUsed(y))
 {
+  if( myPoligonState == InProcess ) { // delete a point of polygon
+    if ( myPolygonPoints.size() > 2 ) {
+      myPolygonPoints.remove( myPolygonPoints.size() - 1 );
+      mySelectionEvent->myPolygonPoints.remove( mySelectionEvent->myPolygonPoints.size() - 1 );
+    }
+    return;
+  }
   myShiftState = shift;
   // finishing current viewer operation
   if (State != VTK_INTERACTOR_STYLE_CAMERA_NONE) {
@@ -633,13 +737,20 @@ void SVTK_InteractorStyle::OnRightButtonDown(int ctrl,
     return;
 
   myShiftState = shift;
+
+  if ( !ctrl ) {
+    myPoligonState = Start;
+    this->Interactor->GetEventPosition(mySelectionEvent->myX, mySelectionEvent->myY);
+    mySelectionEvent->myPolygonPoints.append( QPoint( mySelectionEvent->myX, mySelectionEvent->myY) );
+  }
   // finishing current viewer operation
   if (State != VTK_INTERACTOR_STYLE_CAMERA_NONE) {
     onFinishOperation();
     startOperation(VTK_INTERACTOR_STYLE_CAMERA_NONE);
   }
   myOtherPoint = myPoint = QPoint(x, y);
-  if (ForcedState != VTK_INTERACTOR_STYLE_CAMERA_NONE) {
+  if (ForcedState != VTK_INTERACTOR_STYLE_CAMERA_NONE && 
+      ForcedState != VTK_INTERACTOR_STYLE_CAMERA_INTERACTIVE_SELECTION) {
     startOperation(ForcedState);
   }
   else {
@@ -656,6 +767,18 @@ void SVTK_InteractorStyle::OnRightButtonUp(int vtkNotUsed(ctrl),
                                            int vtkNotUsed(x),
                                            int vtkNotUsed(y))
 {
+  if( myPoligonState == Start ) { // if right button was pressed but mouse is not moved
+    myPoligonState = Disable;
+    mySelectionEvent->myPolygonPoints.clear();
+  }
+
+  if( myPoligonState != Disable ) {
+    endDrawPolygon();
+    myPoligonState = Finished;
+    startOperation(VTK_INTERACTOR_STYLE_CAMERA_NONE);
+    return;
+  }
+
   myShiftState = shift;
   // finishing current viewer operation
   if (State != VTK_INTERACTOR_STYLE_CAMERA_NONE) {
@@ -801,6 +924,20 @@ void SVTK_InteractorStyle::startRotate()
   ForcedState = VTK_INTERACTOR_STYLE_CAMERA_ROTATE;
 }
 
+/*!
+  Starts Interactive Selection operation
+*/
+void SVTK_InteractorStyle::startInteractiveSelection()
+{
+       if (State != VTK_INTERACTOR_STYLE_CAMERA_NONE)
+       {
+               onFinishOperation();
+               startOperation(VTK_INTERACTOR_STYLE_CAMERA_NONE);
+       }
+       ForcedState = VTK_INTERACTOR_STYLE_CAMERA_INTERACTIVE_SELECTION;
+}
+
+
 /*!
   Set rotation point selected by user
 */
@@ -942,6 +1079,7 @@ void SVTK_InteractorStyle::startOperation(int operation)
   case VTK_INTERACTOR_STYLE_CAMERA_SPIN:
   case VTK_INTERACTOR_STYLE_CAMERA_FIT:
   case VTK_INTERACTOR_STYLE_CAMERA_SELECT:
+  case VTK_INTERACTOR_STYLE_CAMERA_INTERACTIVE_SELECTION:
     if (State != VTK_INTERACTOR_STYLE_CAMERA_NONE)
       startOperation(VTK_INTERACTOR_STYLE_CAMERA_NONE);
     State = operation;
@@ -1020,7 +1158,15 @@ void SVTK_InteractorStyle::onStartOperation()
     case VTK_INTERACTOR_STYLE_CAMERA_SELECT:
     case VTK_INTERACTOR_STYLE_CAMERA_FIT:
     {
-      drawRect();
+      if ( myPoligonState == InProcess )
+        drawPolygon();
+      else
+        drawRect();
+      break;
+    }
+    case VTK_INTERACTOR_STYLE_CAMERA_INTERACTIVE_SELECTION:
+    {
+      InteractiveSelection();
       break;
     }
     case VTK_INTERACTOR_STYLE_CAMERA_ZOOM:
@@ -1067,78 +1213,91 @@ void SVTK_InteractorStyle::onFinishOperation()
       }
       else {
         if (myPoint == myOtherPoint)
-          {
-            // process point selection
-            this->FindPokedRenderer(aSelectionEvent->myX, aSelectionEvent->myY);
-            Interactor->StartPickCallback();
+        {
+          // process point selection
+          this->FindPokedRenderer(aSelectionEvent->myX, aSelectionEvent->myY);
+          Interactor->StartPickCallback();
             
-            SALOME_Actor* aHighlightedActor = NULL;
-            vtkActorCollection* anActorCollection = GetSelector()->Pick(aSelectionEvent, GetCurrentRenderer());
-
-            aSelectionEvent->myIsRectangle = false;
+          SALOME_Actor* aHighlightedActor = NULL;
+          vtkActorCollection* anActorCollection = GetSelector()->Pick(aSelectionEvent, GetCurrentRenderer());
 
-            if(!myShiftState)
-              GetSelector()->ClearIObjects();
+          aSelectionEvent->myIsRectangle = false;
+          aSelectionEvent->myIsPolygon = false;
+          if(!myShiftState)
+            GetSelector()->ClearIObjects();
 
-            if( anActorCollection )
+          if( anActorCollection )
+          {
+           if( !myShiftState && 
+               anActorCollection->GetNumberOfItems () > 1 && 
+               myLastHighlitedActor.GetPointer() ) {
+             anActorCollection->RemoveItem ( myLastHighlitedActor.GetPointer() );
+           }
+            anActorCollection->InitTraversal();
+            while( vtkActor* aVTKActor = anActorCollection->GetNextActor() )
             {
-              anActorCollection->InitTraversal();
-              while( vtkActor* aVTKActor = anActorCollection->GetNextActor() )
+              if( SALOME_Actor* anActor = SALOME_Actor::SafeDownCast( aVTKActor ) )
               {
-                if( SALOME_Actor* anActor = SALOME_Actor::SafeDownCast( aVTKActor ) )
+                if( anActor->Highlight( this, aSelectionEvent, true ) )
                 {
-                  if( anActor->Highlight( this, aSelectionEvent, true ) )
-                  {
-                    aHighlightedActor = anActor;
-                    break;
-                  }
+                  aHighlightedActor = anActor;
+                  break;
                 }
               }
             }
+          }
 
-            if( !aHighlightedActor )
-            {
-              if(myLastHighlitedActor.GetPointer() && myLastHighlitedActor.GetPointer() != aHighlightedActor)
-                myLastHighlitedActor->Highlight( this, aSelectionEvent, false );
-            }
-            myLastHighlitedActor = aHighlightedActor;
-          } 
-        else 
+          if( !aHighlightedActor )
           {
-            //processing rectangle selection
-            Interactor->StartPickCallback();
-            GetSelector()->StartPickCallback();
+            if(myLastHighlitedActor.GetPointer() && myLastHighlitedActor.GetPointer() != aHighlightedActor)
+              myLastHighlitedActor->Highlight( this, aSelectionEvent, false );
+          }
+          myLastHighlitedActor = aHighlightedActor;
+        }
+        else
+        {
+          if ( myPoligonState == InProcess || myPoligonState == Closed )
+            aSelectionEvent->myIsPolygon = true;
+          else
             aSelectionEvent->myIsRectangle = true;
 
-            if(!myShiftState)
-              GetSelector()->ClearIObjects();
+          //processing polygonal selection
+          Interactor->StartPickCallback();
+          GetSelector()->StartPickCallback();
+
+          if(!myShiftState)
+            GetSelector()->ClearIObjects();
 
-            VTK::ActorCollectionCopy aCopy(GetCurrentRenderer()->GetActors());
-            vtkActorCollection* aListActors = aCopy.GetActors();
-            aListActors->InitTraversal();
-            while(vtkActor* aActor = aListActors->GetNextActor())
+          VTK::ActorCollectionCopy aCopy(GetCurrentRenderer()->GetActors());
+          vtkActorCollection* aListActors = aCopy.GetActors();
+          aListActors->InitTraversal();
+          while(vtkActor* aActor = aListActors->GetNextActor())
+          {
+            if(aActor->GetVisibility())
+            {
+              if(SALOME_Actor* aSActor = SALOME_Actor::SafeDownCast(aActor))
               {
-                if(aActor->GetVisibility())
-                  {
-                    if(SALOME_Actor* aSActor = SALOME_Actor::SafeDownCast(aActor))
-                      {
-                        if(aSActor->hasIO())
-                          aSActor->Highlight( this, aSelectionEvent, true );
-                      }
-                  }
+                if(aSActor->hasIO())
+                  aSActor->Highlight( this, aSelectionEvent, true );
               }
+            }
           }
+        }
+        aSelectionEvent->myIsRectangle = false;
+        aSelectionEvent->myIsPolygon = false;
+        aSelectionEvent->myPolygonPoints.clear();
+        endDrawPolygon();
         Interactor->EndPickCallback();
         GetSelector()->EndPickCallback();
       } 
-    } 
-    break;
-  case VTK_INTERACTOR_STYLE_CAMERA_ZOOM:
-  case VTK_INTERACTOR_STYLE_CAMERA_PAN:
-  case VTK_INTERACTOR_STYLE_CAMERA_ROTATE:
-  case VTK_INTERACTOR_STYLE_CAMERA_SPIN:
-    break;
-  case VTK_INTERACTOR_STYLE_CAMERA_GLOBAL_PAN: 
+      break;
+    }
+    case VTK_INTERACTOR_STYLE_CAMERA_ZOOM:
+    case VTK_INTERACTOR_STYLE_CAMERA_PAN:
+    case VTK_INTERACTOR_STYLE_CAMERA_ROTATE:
+    case VTK_INTERACTOR_STYLE_CAMERA_SPIN:
+      break;
+    case VTK_INTERACTOR_STYLE_CAMERA_GLOBAL_PAN:
     {
       int w, h, x, y;
       Interactor->GetSize(w, h);
@@ -1194,13 +1353,18 @@ void SVTK_InteractorStyle::onOperation(QPoint mousePos)
     {
       if (!myCursorState)
         setCursor(VTK_INTERACTOR_STYLE_CAMERA_SELECT);
-    }
+    } // fall through!
   case VTK_INTERACTOR_STYLE_CAMERA_FIT:
     {
       myOtherPoint = mousePos;
-      drawRect();
+      if ( myPoligonState == InProcess || myPoligonState == Closed || myPoligonState == NotValid )
+        drawPolygon();
+      else if ( myPoligonState != Finished )
+        drawRect();
       break;
     }
+  case VTK_INTERACTOR_STYLE_CAMERA_INTERACTIVE_SELECTION:
+         this->InteractiveSelection();
   }
 }
 
@@ -1208,8 +1372,11 @@ void SVTK_InteractorStyle::onOperation(QPoint mousePos)
   Called when user moves mouse inside viewer window and there is no active viewer operation 
   (!put necessary processing here!)
 */
-void SVTK_InteractorStyle::onCursorMove(QPoint mousePos
+void SVTK_InteractorStyle::onCursorMove(QPoint /*mousePos*/
 {
+  if ( !GetSelector()->IsPreSelectionEnabled() ) 
+    return;
+
   // processing highlighting
   SVTK_SelectionEvent* aSelectionEvent = GetSelectionEventFlipY();
   this->FindPokedRenderer(aSelectionEvent->myX,aSelectionEvent->myY);
@@ -1219,8 +1386,7 @@ void SVTK_InteractorStyle::onCursorMove(QPoint mousePos)
   SALOME_Actor* aPreHighlightedActor = NULL;
   vtkActorCollection* anActorCollection = GetSelector()->Pick(aSelectionEvent, GetCurrentRenderer());
 
-  if ( myCurrRotationPointType == SVTK::StartPointSelection ||
-       myCurrFocalPointType == SVTK::StartFocalPointSelection )
+  if ( myCurrFocalPointType == SVTK::StartFocalPointSelection )
   {
     myHighlightSelectionPointActor->SetVisibility( false );
 
@@ -1233,11 +1399,11 @@ void SVTK_InteractorStyle::onCursorMove(QPoint mousePos)
         {
           SVTK::TPickLimiter aPickLimiter( myPointPicker, anActor );
           myPointPicker->Pick( aSelectionEvent->myX, aSelectionEvent->myY, 0.0, GetCurrentRenderer() );
-          int aVtkId = myPointPicker->GetPointId();
+          vtkIdType aVtkId = myPointPicker->GetPointId();
           if ( aVtkId >= 0 ) {
-            int anObjId = anActor->GetNodeObjId( aVtkId );
+            vtkIdType anObjId = anActor->GetNodeObjId( aVtkId );
 
-            TColStd_IndexedMapOfInteger aMapIndex;
+            SVTK_TIndexedMapOfVtkId aMapIndex;
             aMapIndex.Add( anObjId );
             myHighlightSelectionPointActor->MapPoints( anActor, aMapIndex );
 
@@ -1355,6 +1521,23 @@ void SVTK_InteractorStyle::IncrementalRotate( const int incrX, const int incrY )
   this->RotateXY( incrX, -incrY );
 }
 
+void SVTK_InteractorStyle::InteractiveSelection() 
+{
+  if (vtkCamera *cam = GetCurrentRenderer()->GetActiveCamera()) {
+    int posX, posY;
+    this->Interactor->GetEventPosition(posX, posY);
+    double viewFocus[3], z;
+    double* focalPointWorld = cam->GetFocalPoint();
+         this->ComputeWorldToDisplay(focalPointWorld[0], focalPointWorld[1],
+                 focalPointWorld[2], viewFocus);
+         z = viewFocus[2];
+
+         this->ComputeDisplayToWorld(double(posX), double(posY),
+               z, this->myInteractivePoint);
+         InvokeEvent(SVTK::InteractiveSelectionChanged, (void*)this->myInteractivePoint);
+  }
+}
+
 /*!
   Redefined in order to add an observer (callback) for custorm event (space mouse event)
 */
@@ -1401,6 +1584,8 @@ void SVTK_InteractorStyle::SetInteractor( vtkRenderWindowInteractor* theInteract
     theInteractor->AddObserver( SVTK::SetFocalPointGravity, EventCallbackCommand, Priority );
     theInteractor->AddObserver( SVTK::StartFocalPointSelection, EventCallbackCommand, Priority );
     theInteractor->AddObserver( SVTK::SetFocalPointSelected, EventCallbackCommand, Priority );
+         theInteractor->AddObserver( SVTK::StartInteractiveSelection, EventCallbackCommand, Priority);
+    theInteractor->AddObserver( SVTK::StopCurrentOperation, EventCallbackCommand, Priority);
   }
 }
 
@@ -1414,6 +1599,9 @@ void SVTK_InteractorStyle::OnTimer()
   // check if bounding box was changed
   if ( GetCurrentRenderer() )
   {
+#ifdef VGL_WORKAROUND
+    GetCurrentRenderer()->Render();
+#endif
     double aCurrBBCenter[3];
     if ( ComputeBBCenter(GetCurrentRenderer(),aCurrBBCenter) )
     {
@@ -1480,17 +1668,17 @@ void SVTK_InteractorStyle::DominantCombinedSwitch()
 */
 void SVTK_InteractorStyle::drawRect()
 {
-  if ( !myRectBand ) {
-    myRectBand = new QRubberBand( QRubberBand::Rectangle, GetRenderWidget() );
-    QPalette palette;
-    palette.setColor(myRectBand->foregroundRole(), Qt::white);
-    myRectBand->setPalette(palette);
-  }
-  myRectBand->hide();
+  if ( !myRectBand )
+    myRectBand = new QtxRectRubberBand( GetRenderWidget() );
 
+  myRectBand->setUpdatesEnabled ( false );
   QRect aRect = SUIT_Tools::makeRect(myPoint.x(), myPoint.y(), myOtherPoint.x(), myOtherPoint.y());
-  myRectBand->setGeometry( aRect );
-  myRectBand->setVisible( aRect.isValid() );
+  myRectBand->initGeometry( aRect );
+
+  if ( !myRectBand->isVisible() )
+    myRectBand->show();
+
+  myRectBand->setUpdatesEnabled ( true );
 }
 
 /*!
@@ -1498,10 +1686,150 @@ void SVTK_InteractorStyle::drawRect()
 */
 void SVTK_InteractorStyle::endDrawRect()
 {
-  if ( myRectBand ) myRectBand->hide();
+  if ( myRectBand ) {
+    myRectBand->clearGeometry();
+    myRectBand->hide();
+  }
+}
+
+bool isIntersect( const QPoint& theStart1, const QPoint& theEnd1,
+                  const QPoint& theStart2, const QPoint& theEnd2 )
+{
+  if ( ( theStart1 == theStart2 && theEnd1 == theEnd2 ) ||
+       ( theStart1 == theEnd2 && theEnd1 == theStart2 ) )
+    return true;
+
+  if ( theStart1 == theStart2 || theStart2 == theEnd1 ||
+      theStart1 == theEnd2 || theEnd1 == theEnd2 )
+    return false;
+
+  double x11 = theStart1.x() * 1.0;
+  double x12 = theEnd1.x() * 1.0;
+  double y11 = theStart1.y() * 1.0;
+  double y12 = theEnd1.y() * 1.0;
+
+  double x21 = theStart2.x() * 1.0;
+  double x22 = theEnd2.x() * 1.0;
+  double y21 = theStart2.y() * 1.0;
+  double y22 = theEnd2.y() * 1.0;
+
+  double k1 = x12 == x11 ? 0 : ( y12 - y11 ) / ( x12 - x11 );
+  double k2 = x22 == x21 ? 0 : ( y22 - y21 ) / ( x22 - x21 );
+
+  double b1 = y11 - k1 * x11;
+  double b2 = y21 - k2 * x21;
+
+  if ( k1 == k2 )
+  {
+    if ( b1 != b2 )
+      return false;
+    else
+      return !( ( qMax( x11, x12 ) <= qMin( x21, x22 ) ||
+                  qMin( x11, x12 ) >= qMax( x21, x22 ) ) &&
+                ( qMax( y11, y12 ) <= qMin( y21, y22 ) ||
+                  qMin( y11, y12 ) >= qMax( y21, y22 ) ) );
+  }
+  else
+  {
+    double x0 = ( b2 - b1 ) / ( k1 - k2 );
+    double y0 = ( k1 * b2 - k2 * b1 ) / ( k1 - k2 );
+
+    if ( qMin( x11, x12 ) < x0 && x0 < qMax( x11, x12 ) &&
+         qMin( y11, y12 ) < y0 && y0 < qMax( y11, y12 ) &&
+         qMin( x21, x22 ) < x0 && x0 < qMax( x21, x22 ) &&
+         qMin( y21, y22 ) < y0 && y0 < qMax( y21, y22 ) )
+      return true;
+  }
+  return false;
+}
+
+bool isValid( const QPolygon* thePoints, const QPoint& theCurrent )
+{
+  if ( !thePoints->count() )
+    return true;
 
-  delete myRectBand;
-  myRectBand = 0;
+  if ( thePoints->count() == 1 && thePoints->point( 0 ) == theCurrent )
+    return false;
+
+  const QPoint& aLast = thePoints->point( thePoints->count() - 1 );
+
+  if ( aLast == theCurrent )
+    return true;
+
+  bool res = true;
+  for ( int i = 0; i < thePoints->count() - 1 && res; i++ )
+  {
+    const QPoint& aStart = thePoints->point( i );
+    const QPoint& anEnd  = thePoints->point( i + 1 );
+    res = !isIntersect( aStart, anEnd, theCurrent, aLast );
+  }
+  return res;
+}
+
+/*!
+  Draws polygon
+*/
+void SVTK_InteractorStyle::drawPolygon()
+{
+  QSize aToler( 5, 5 );
+  if ( !myPolygonBand ) {
+    myPolygonBand = new QtxPolyRubberBand( GetRenderWidget() );
+    QPalette palette;
+    palette.setColor( myPolygonBand->foregroundRole(), Qt::white );
+    myPolygonBand->setPalette( palette );
+    myPolygonPoints.append( QPoint( myPoint.x(), myPoint.y() ) );
+  }
+  myPolygonBand->hide();
+
+  bool closed = false;
+  bool valid = GetRenderWidget()->rect().contains( QPoint( myOtherPoint.x(), myOtherPoint.y() ) );
+  if ( !myPolygonPoints.at(0).isNull() )
+  {
+    QRect aRect( myPolygonPoints.at(0).x() - aToler.width(), myPolygonPoints.at(0).y() - aToler.height(),
+                 2 * aToler.width(), 2 * aToler.height() );
+    closed = aRect.contains( QPoint( myOtherPoint.x(), myOtherPoint.y() ) );
+  }
+
+  QPolygon* points = new QPolygon( myPolygonPoints );
+  valid = valid && isValid( points, QPoint( myOtherPoint.x(), myOtherPoint.y() ) );
+  myPoligonState = valid ? InProcess : NotValid;
+  delete points;
+  if ( closed && !valid )
+    closed = false;
+
+  if ( closed && myPolygonPoints.size() > 2 ) {
+    GetRenderWidget()->setCursor( Qt::CrossCursor );
+    myPoligonState = Closed;
+  }
+  else if ( valid )
+    GetRenderWidget()->setCursor( Qt::PointingHandCursor );
+  else
+    GetRenderWidget()->setCursor( Qt::ForbiddenCursor );
+
+  myPolygonPoints.append( QPoint( myOtherPoint.x(), myOtherPoint.y() ) );
+
+  QPolygon aPolygon( myPolygonPoints );
+  myPolygonBand->initGeometry( aPolygon );
+  myPolygonBand->setVisible( true );
+
+  if ( myPolygonPoints.size() > 1 ) {
+    myPolygonPoints.remove( myPolygonPoints.size() - 1 );
+  }
+}
+
+/*!
+  \brief Delete rubber band on the end on the dragging operation.
+*/
+void SVTK_InteractorStyle::endDrawPolygon()
+{
+  if ( myPolygonBand ) myPolygonBand->hide();
+
+  // RNV fix for : #19204 [CEA][Windows] VTK Viewer - Access violation while right clicking
+  //delete myPolygonBand;
+  myPolygonBand->deleteLater();
+  myPolygonBand = 0;
+
+  myPolygonPoints.clear();
 }
 
 /*!
@@ -1643,7 +1971,9 @@ void SVTK_InteractorStyle::ProcessEvents( vtkObject* object,
       case SVTK::StartFocalPointSelection:
         self->startFocalPointSelection();
         return;
-
+      case SVTK::StartInteractiveSelection:
+        self->startInteractiveSelection();
+        return;
       case SVTK::SetFocalPointSelected:
         if ( self->myCurrFocalPointType == SVTK::StartFocalPointSelection )
         {
@@ -1655,6 +1985,9 @@ void SVTK_InteractorStyle::ProcessEvents( vtkObject* object,
         self->myPrevFocalPointType = self->myCurrFocalPointType;
         self->myCurrFocalPointType = SVTK::SetFocalPointSelected;
         return;
+      case SVTK::StopCurrentOperation:
+        self->onFinishOperation();
+        self->startOperation(VTK_INTERACTOR_STYLE_CAMERA_NONE);
       }
     }
   }
@@ -1749,7 +2082,7 @@ SVTK_ControllerIncrement* SVTK_InteractorStyle::ControllerIncrement()
   return myControllerIncrement.GetPointer();
 }
 
-vtkStandardNewMacro(SVTK_ControllerIncrement);
+vtkStandardNewMacro(SVTK_ControllerIncrement)
 SVTK_ControllerIncrement::SVTK_ControllerIncrement()
 {
   myIncrement=10;
@@ -1778,7 +2111,7 @@ int SVTK_ControllerIncrement::Decrease()
   return myIncrement;
 }
 
-vtkStandardNewMacro(SVTK_GeomControllerIncrement);
+vtkStandardNewMacro(SVTK_GeomControllerIncrement)
 SVTK_GeomControllerIncrement::SVTK_GeomControllerIncrement()
 {
 }
@@ -1799,7 +2132,7 @@ int SVTK_GeomControllerIncrement::Decrease()
   return myIncrement;
 }
 
-vtkStandardNewMacro(SVTK_ControllerOnKeyDown);
+vtkStandardNewMacro(SVTK_ControllerOnKeyDown)
 
 /*!
   Constructor
@@ -1815,7 +2148,7 @@ SVTK_ControllerOnKeyDown::~SVTK_ControllerOnKeyDown()
 {
 }
 
-bool SVTK_ControllerOnKeyDown::OnKeyDown(vtkInteractorStyle* theIS)
+bool SVTK_ControllerOnKeyDown::OnKeyDown(vtkInteractorStyle* /*theIS*/)
 {
   return true;
 }