Salome HOME
refs #416: to store the open state of object browser items in the binary array
[modules/gui.git] / src / SVTK / SVTK_InteractorStyle.cxx
index 7f7f5e6e79a003291d21295ab64f82ddbf90decb..6bb80535913743fbe32a5d9afe83ccdcd3e9e839 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2007-2013  CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2007-2014  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>
@@ -160,6 +161,15 @@ SVTK_Selector* SVTK_InteractorStyle::GetSelector()
   return myInteractor->GetSelector();
 }
 
+/*!
+  Realeaze actors
+*/
+void SVTK_InteractorStyle::FreeActors()
+{
+  myLastHighlitedActor = NULL;
+  myLastPreHighlitedActor = NULL;
+}
+
 /*!
   Generate special SVTK_SelectionEvent
 */
@@ -526,22 +536,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;
+               int 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 )
+              {
+                int 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();
+              int 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;
@@ -563,6 +612,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)
@@ -1289,6 +1339,9 @@ void SVTK_InteractorStyle::onOperation(QPoint mousePos)
 */
 void SVTK_InteractorStyle::onCursorMove(QPoint mousePos) 
 {
+  if ( !GetSelector()->IsPreSelectionEnabled() ) 
+    return;
+
   // processing highlighting
   SVTK_SelectionEvent* aSelectionEvent = GetSelectionEventFlipY();
   this->FindPokedRenderer(aSelectionEvent->myX,aSelectionEvent->myY);
@@ -1298,8 +1351,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 );