]> SALOME platform Git repositories - modules/visu.git/commitdiff
Salome HOME
Fix for Bug NPAL16809
authorapo <apo@opencascade.com>
Wed, 14 Nov 2007 08:19:19 +0000 (08:19 +0000)
committerapo <apo@opencascade.com>
Wed, 14 Nov 2007 08:19:19 +0000 (08:19 +0000)
   EDF 562 VISU Gauss Picking, having an alphanumeric selection
(Context zooming and camera position modification is moved to the post highlight action)

src/OBJECT/VISU_GaussPtsAct.cxx
src/OBJECT/VISU_GaussPtsAct.h

index 1941fec31b9798f4f6e021e1e7203a07269fb537..fe142dccda729eae08c8a1b777e3b48194198c77 100644 (file)
@@ -91,6 +91,31 @@ static int MYDEBUG2 = 0;
 #endif
 
 
+namespace
+{
+  bool
+  CheckIsSameValue(vtkFloatingPointType theTarget,
+                  vtkFloatingPointType theSource)
+  {
+    static vtkFloatingPointType TOL = 10.0 / VTK_LARGE_FLOAT;
+    return fabs(theTarget - theSource)  < TOL;
+  }
+
+  bool
+  CheckIsSameVector(vtkFloatingPointType* theTarget,
+                   vtkFloatingPointType* theSource,
+                   size_t theLength)
+  {
+    for ( size_t anId = 0; anId < theLength; anId++ ) {
+      if ( !CheckIsSameValue( theTarget[ anId ], theSource[ anId ] ) )
+       return false;
+    }
+
+    return true;
+  }
+  
+}
+
 //============================================================================
 vtkStandardNewMacro(VISU_GaussPtsAct);
 
@@ -102,7 +127,7 @@ VISU_GaussPtsAct
   myDeviceActor(VISU_GaussPtsDeviceActor::New()),
   myWidgetCtrl(NULL),
   myGaussPointsPL(NULL),
-  myLastObjPointID(-1),
+  myLastPreHighlightObjID(-1),
   myTextActor(VISU_FramedTextActor::New()),
   myCursorPyramid(VISU_CursorPyramid::New()),
   myCursorPyramidSelected(VISU_CursorPyramid::New()),
@@ -651,7 +676,7 @@ VISU_GaussPtsAct
 
 
   if(!theIsHighlight)
-    myLastObjPointID = -1;
+    myLastPreHighlightObjID = -1;
 
   Selection_Mode aSelectionMode = theSelectionEvent->mySelectionMode;
 
@@ -679,7 +704,7 @@ VISU_GaussPtsAct
       vtkIdType anObjId = GetNodeObjId( aVtkId );
       myIsPreselected = (anObjId >= 0);
       if(myIsPreselected){
-       anIsChanged = (myLastObjPointID != anObjId);
+       anIsChanged = (myLastPreHighlightObjID != anObjId);
        if(anIsChanged){
          vtkFloatingPointType* aNodeCoord = GetNodeCoord(anObjId);
          vtkDataSet* aDataSet = GetInput();
@@ -702,7 +727,7 @@ VISU_GaussPtsAct
                                  aNodeCoord,
                                  aColor);
          }
-         myLastObjPointID = anObjId;
+         myLastPreHighlightObjID = anObjId;
        }
        myCursorPyramid->SetVisibility(true);
       }
@@ -720,21 +745,19 @@ VISU_GaussPtsAct
 inline
 void
 ChangeZoom(VISU_PickingSettings *thePickingSettings,
-          vtkInteractorStyle* theInteractorStyle,
-          int theInitialHasIndex,
-          int theCurrentHasIndex,
-          const Handle(SALOME_InteractiveObject)& theIO)
+          vtkRenderer *theRenderer,
+          vtkIdType theInitialHasIndex,
+          vtkIdType theCurrentHasIndex)
 {
   if(theInitialHasIndex + theCurrentHasIndex == 1){
-    vtkRenderer *aRenderer = theInteractorStyle->GetCurrentRenderer();
-    vtkCamera *aCamera = aRenderer->GetActiveCamera();
+    vtkCamera *aCamera = theRenderer->GetActiveCamera();
     vtkFloatingPointType aZoomFactor = thePickingSettings->GetZoomFactor();
     double aScale = aCamera->GetParallelScale();
-    if (!theInitialHasIndex && theCurrentHasIndex) {
-      aCamera->SetParallelScale(aScale/aZoomFactor);
+    if ( !theInitialHasIndex && theCurrentHasIndex ) {
+      aCamera->SetParallelScale( aScale / aZoomFactor );
     }
     else {
-      aCamera->SetParallelScale(aScale*aZoomFactor);
+      aCamera->SetParallelScale( aScale * aZoomFactor );
     }
   }
   
@@ -749,21 +772,11 @@ VISU_GaussPtsAct
   if ( !GetPickable() )
     return false;
 
-  int anInitialHasIndex = myIsHighlighted && mySelectionMode == GaussPointSelection;
   Handle(SALOME_InteractiveObject) anIO = getIO();
-  myIsHighlighted = false;
-
   Selection_Mode aSelectionMode = theSelectionEvent->mySelectionMode;
 
   if(!theIsHighlight && aSelectionMode == GaussPointSelection){
     mySelector->RemoveIObject(anIO);
-
-    ChangeZoom(myPickingSettings,
-              theInteractorStyle,
-              anInitialHasIndex,
-              false,
-              anIO);
-
     return true;
   }
   
@@ -786,13 +799,6 @@ VISU_GaussPtsAct
 
     if(myPointPicker->GetActor() != this) {
       mySelector->ClearIObjects();
-
-      ChangeZoom(myPickingSettings,
-                theInteractorStyle,
-                anInitialHasIndex,
-                false,
-                anIO);
-
       return true;
     }
 
@@ -800,7 +806,6 @@ VISU_GaussPtsAct
     if( aVtkId >= 0  && mySelector->IsValid( this, aVtkId, true ) && hasIO()) {
       vtkIdType anObjId = GetNodeObjId( aVtkId );
       if(anObjId >= 0){
-       myIsHighlighted = true;
        // Update the Selector
        if(mySelector->IsSelected(myIO))
          mySelector->AddOrRemoveIndex(myIO,anObjId,theSelectionEvent->myIsShift);
@@ -812,42 +817,13 @@ VISU_GaussPtsAct
          mySelector->AddIObject(this);
        }
        //
-       vtkFloatingPointType* aNodeCoord = GetNodeCoord(anObjId);
-       //
-       // FlyTo
-       vtkRenderWindowInteractor* anInteractor = theInteractorStyle->GetInteractor();
-       vtkFloatingPointType aDollyWas = anInteractor->GetDolly();
-       int aNumberOfFlyFramesWas = anInteractor->GetNumberOfFlyFrames();
-       
-       anInteractor->SetDolly(0.);
-       anInteractor->SetNumberOfFlyFrames(myPickingSettings->GetStepNumber());
-       anInteractor->FlyTo(aRenderer, aNodeCoord);
-       aRenderer->ResetCameraClippingRange();
-       anInteractor->SetDolly(aDollyWas);
-       anInteractor->SetNumberOfFlyFrames(aNumberOfFlyFramesWas);
-       
-       anInteractor->InvokeEvent(SVTK::ChangeRotationPoint, aNodeCoord);
-
        mySelectionMode = aSelectionMode;
 
-       ChangeZoom(myPickingSettings,
-                  theInteractorStyle,
-                  anInitialHasIndex,
-                  true,
-                  anIO);
-
        return true;
-       //
       }// if( anObjId >= 0 ) {
     }//if( aVtkId >= 0  && mySelector->IsValid( this, aVtkId, true ) && hasIO()) 
   }//if(!theSelectionEvent->myIsRectangle){
 
-  ChangeZoom(myPickingSettings,
-            theInteractorStyle,
-            anInitialHasIndex,
-            false,
-            anIO);
-  
   return false;
 }
 
@@ -862,34 +838,72 @@ VISU_GaussPtsAct
   if(!mySelector.GetPointer())
     return;
 
+  Selection_Mode aSelectionMode = mySelector->SelectionMode();
+
+  bool anInitialHasIndex = isHighlighted() && mySelectionMode == GaussPointSelection;
+
+  TColStd_IndexedMapOfInteger aMapIndex;
+  mySelector->GetIndex( getIO(), aMapIndex );
+  bool aCurrentHasIndex = aMapIndex.Extent() == 1;
+  bool anIsVisible = GetVisibility() && aCurrentHasIndex && theIsHighlight;
+
   myOutlineActor->SetVisibility(false);
-  myTextActor->SetVisibility(false);
-  myCursorPyramidSelected->SetVisibility(false);
   myCursorPyramid->SetVisibility(false);
-  myCellActor->SetVisibility(false);
-  GetScalarBarCtrl()->SetIsMarked(false);
-  GetScalarBarCtrl()->Update();
+
+  myTextActor->SetVisibility(anIsVisible);
+  myCellActor->SetVisibility(anIsVisible);
+  GetScalarBarCtrl()->SetIsMarked(anIsVisible);
+  myCursorPyramidSelected->SetVisibility(anIsVisible);
+
+  myIsHighlighted = aCurrentHasIndex;
+
+  // Zoom if necessary
+  ChangeZoom(myPickingSettings,
+            GetRenderer(),
+            anInitialHasIndex,
+            aCurrentHasIndex);
 
   if(!theIsHighlight)
     return;
 
-  bool anIsVisible = GetVisibility();
+  if ( aSelectionMode == ActorSelection ) {
+    Superclass::highlight(theIsHighlight);
+    return;
+  }
 
-  Selection_Mode aSelectionMode = mySelector->SelectionMode();
+  if ( aSelectionMode != GaussPointSelection )
+    return;
 
-  if(aSelectionMode == ActorSelection)
-    Superclass::highlight(theIsHighlight);
-  else if(aSelectionMode != GaussPointSelection)
+  if ( !aCurrentHasIndex || !myBarVisibility )
     return;
 
-  TColStd_IndexedMapOfInteger aMapIndex;
-  mySelector->GetIndex( getIO(), aMapIndex );
-  if(aMapIndex.Extent() != 1 || !myBarVisibility) {
+  vtkRenderer *aRenderer = GetRenderer();
+  vtkCamera* aCamera = aRenderer->GetActiveCamera();
+
+  int anObjId = aMapIndex(1);
+  vtkFloatingPointType* aNodeCoord = GetNodeCoord(anObjId);
+
+  vtkFloatingPointType aFocalPnt[3];
+  aCamera->GetFocalPoint(aFocalPnt);
+
+  if ( CheckIsSameVector( aNodeCoord, aFocalPnt, 3 ) ) 
     return;
-  }
-  //
+
+  // FlyTo
+  vtkRenderWindowInteractor* anInteractor = myInteractor;
+  vtkFloatingPointType aDollyWas = anInteractor->GetDolly();
+  int aNumberOfFlyFramesWas = anInteractor->GetNumberOfFlyFrames();
+  
+  anInteractor->SetDolly(0.0);
+  anInteractor->SetNumberOfFlyFrames(myPickingSettings->GetStepNumber());
+  anInteractor->FlyTo(aRenderer, aNodeCoord);
+  aRenderer->ResetCameraClippingRange();
+  anInteractor->SetDolly(aDollyWas);
+  anInteractor->SetNumberOfFlyFrames(aNumberOfFlyFramesWas);
+  
+  anInteractor->InvokeEvent(SVTK::ChangeRotationPoint, aNodeCoord);
+
   std::ostringstream aStr;
-  int anObjId = aMapIndex(1);
   aStr<<"Global ID: "<<anObjId;
   //
   vtkIdType aVtkId = GetNodeVTKID(anObjId);
@@ -903,7 +917,6 @@ VISU_GaussPtsAct
     if(vtkDataArray* aScalarArray = aDataSetAttributes->GetScalars()){
       vtkFloatingPointType aVal = aScalarArray->GetTuple1(aVtkId);
       //
-      GetScalarBarCtrl()->SetIsMarked(true);
       GetScalarBarCtrl()->SetMarkValue(aVal);
       GetScalarBarCtrl()->Update();
       //
index 2603a820a9d7597ce4abf9fe7bbcbb44a8972bae..09680e30945f05bdb86193fc3b847db6067516c3 100644 (file)
@@ -297,7 +297,7 @@ class VTKOCC_EXPORT VISU_GaussPtsAct : public VISU_Actor
   VISU_GaussPointsPL* myCurrentPL;
   vtkSmartPointer<VISU_GaussPointsPL> myGaussPointsPL;
 
-  vtkIdType myLastObjPointID;
+  vtkIdType myLastPreHighlightObjID;
 
   vtkSmartPointer<VISU_FramedTextActor> myTextActor;