]> SALOME platform Git repositories - modules/visu.git/commitdiff
Salome HOME
1. To implement caching of highlight / prehighlight functionality
authorapo <apo@opencascade.com>
Mon, 14 Nov 2005 13:11:46 +0000 (13:11 +0000)
committerapo <apo@opencascade.com>
Mon, 14 Nov 2005 13:11:46 +0000 (13:11 +0000)
2. To move "change camera zoom on picking" functionality from VVTK_InteractorStyle to VISU_GaussPtsAct

src/OBJECT/VISU_GaussPtsAct.cxx

index b17b622caba41f31c24b90dc74326a8bfdecc68a..14b6921ef7229f877f65647c0ad9ebfd5f280171 100644 (file)
@@ -490,19 +490,19 @@ bool VISU_GaussPtsAct::PreHighlight(vtkInteractorStyle* theInteractorStyle,
     return false;
   }
 
-  if(theSelectionEvent->mySelectionMode == ActorSelection || !theIsHighlight)
+  if(!theIsHighlight)
+    myLastObjPointID = -1;
+
+  Selection_Mode aSelectionMode = theSelectionEvent->mySelectionMode;
+
+  if(aSelectionMode == ActorSelection || !theIsHighlight)
     return Superclass::PreHighlight(theInteractorStyle,
                                    theSelectionEvent,
                                    theIsHighlight);
-
-
-  bool anIsSelectionModeChanged = (theSelectionEvent->mySelectionMode != mySelectionMode);
-  if(!anIsSelectionModeChanged && mySelectionMode == ActorSelection)
-    return false;
-
-  mySelectionMode = theSelectionEvent->mySelectionMode;
-
-  bool anIsChanged = false;
+  
+  bool anIsChanged = (mySelectionMode != aSelectionMode);
+  bool anIsPreselected = myIsPreselected;
+  
   if(theIsHighlight){
     switch(mySelectionMode){
     case NodeSelection: 
@@ -520,39 +520,83 @@ bool VISU_GaussPtsAct::PreHighlight(vtkInteractorStyle* theInteractorStyle,
       
       if(aVtkId >= 0 && mySelector->IsValid(this,aVtkId,true) && hasIO()){
        vtkIdType anObjId = GetNodeObjId( aVtkId );
-       if(myLastObjPointID != anObjId){
-         float* aNodeCoord = GetNodeCoord(anObjId);
-         vtkDataSet* aDataSet = GetInput();
-         vtkCellData* aCellData = aDataSet->GetCellData();
-         if(vtkDataArray *aScalarArray = aCellData->GetScalars()){
-           float aRadius = myGaussPointsPL->GetPointSize(aVtkId,aScalarArray);
-           float aPyramidHeight = myPickingSettings->GetPyramidHeight();
-           aPyramidHeight = aPyramidHeight*myGaussPointsPL->GetMaxPointSize();
-           myCursorPyramid->Init(aPyramidHeight,
-                                 aRadius,
-                                 aNodeCoord,
-                                 myPreHighlightActor->GetProperty()->GetColor()); 
+       myIsPreselected = (anObjId >= 0);
+       if(myIsPreselected){
+         anIsChanged = (myLastObjPointID != anObjId);
+         if(anIsChanged){
+           float* aNodeCoord = GetNodeCoord(anObjId);
+           vtkDataSet* aDataSet = GetInput();
+           vtkCellData* aCellData = aDataSet->GetCellData();
+           if(vtkDataArray *aScalarArray = aCellData->GetScalars()){
+             float aRadius = myGaussPointsPL->GetPointSize(aVtkId,aScalarArray);
+             float aPyramidHeight = myPickingSettings->GetPyramidHeight();
+             aPyramidHeight = aPyramidHeight*myGaussPointsPL->GetMaxPointSize();
+             myCursorPyramid->Init(aPyramidHeight,
+                                   aRadius,
+                                   aNodeCoord,
+                                   myPreHighlightActor->GetProperty()->GetColor()); 
+           }
+           myLastObjPointID = anObjId;
          }
-         myLastObjPointID = anObjId;
+         myCursorPyramid->SetVisibility(true);
        }
-       myCursorPyramid->SetVisibility(true);
-       myIsPreselected = theIsHighlight;
-       anIsChanged = true;
       }
     }
     break;
     }
   }
 
+  mySelectionMode = aSelectionMode;
+  anIsChanged |= (anIsPreselected != myIsPreselected);
+
   return anIsChanged;
 }
 
 
 //----------------------------------------------------------------------------
+inline
+void
+ChangeZoom(VISU_PickingSettings *thePickingSettings,
+          vtkInteractorStyle* theInteractorStyle,
+          int theInitialHasIndex,
+          SVTK_Selector* theSelector,
+          const Handle(SALOME_InteractiveObject)& theIO)
+{
+  int aCurrentHasIndex = theSelector->HasIndex(theIO);
+
+  if(theInitialHasIndex + aCurrentHasIndex == 1){
+    vtkRenderer *aRenderer = theInteractorStyle->GetCurrentRenderer();
+    vtkCamera *aCamera = aRenderer->GetActiveCamera();
+    float aZoomFactor = thePickingSettings->GetZoomFactor();
+    double aScale = aCamera->GetParallelScale();
+    if (!theInitialHasIndex && aCurrentHasIndex) {
+      aCamera->SetParallelScale(aScale/aZoomFactor);
+    }
+    else {
+      aCamera->SetParallelScale(aScale*aZoomFactor);
+    }
+  }
+  
+}
+
 bool VISU_GaussPtsAct::Highlight(vtkInteractorStyle* theInteractorStyle, 
                                 SVTK_SelectionEvent* theSelectionEvent,
                                 bool theIsHighlight)
 { 
+  Handle(SALOME_InteractiveObject) anIO = getIO();
+  int anInitialHasIndex = mySelector->HasIndex(anIO);
+  if(!theIsHighlight){
+    mySelector->RemoveIObject(anIO);
+
+    ChangeZoom(myPickingSettings,
+              theInteractorStyle,
+              anInitialHasIndex,
+              mySelector.GetPointer(),
+              anIO);
+
+    return true;
+  }
+  
   if (!myBarVisibility) {
     return false;
   }
@@ -575,6 +619,13 @@ bool VISU_GaussPtsAct::Highlight(vtkInteractorStyle* theInteractorStyle,
 
     if(myPointPicker->GetActor() != this) {
       mySelector->ClearIObjects();
+
+      ChangeZoom(myPickingSettings,
+                theInteractorStyle,
+                anInitialHasIndex,
+                mySelector.GetPointer(),
+                anIO);
+
       return true;
     }
 
@@ -609,11 +660,23 @@ bool VISU_GaussPtsAct::Highlight(vtkInteractorStyle* theInteractorStyle,
        
        mySelectionMode = aSelectionMode;
 
+       ChangeZoom(myPickingSettings,
+                  theInteractorStyle,
+                  anInitialHasIndex,
+                  mySelector.GetPointer(),
+                  anIO);
+
        return true;
        //
       }// if( anObjId >= 0 ) {
     }//if( aVtkId >= 0  && mySelector->IsValid( this, aVtkId, true ) && hasIO()) 
   }//if(!theSelectionEvent->myIsRectangle){
+
+  ChangeZoom(myPickingSettings,
+            theInteractorStyle,
+            anInitialHasIndex,
+            mySelector.GetPointer(),
+            anIO);
   
   return false;
 }