]> SALOME platform Git repositories - modules/visu.git/commitdiff
Salome HOME
1. Now SelectionEvent wil pass to PreHighlight/Highlight functionality by pointer...
authorapo <apo@opencascade.com>
Tue, 20 Sep 2005 09:31:35 +0000 (09:31 +0000)
committerapo <apo@opencascade.com>
Tue, 20 Sep 2005 09:31:35 +0000 (09:31 +0000)
2. To fix regression with PreHighlight/Highlight functionality

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

index c0c85f0c2eb194f28cd93957a403ec600da9750f..cb8a21cae80cfab5c86013c9a6463b791d91c8f2 100644 (file)
@@ -44,6 +44,7 @@
 #include <vtkRenderer.h>
 #include <vtkCellPicker.h>
 #include <vtkCell.h>
+#include <vtkPointPicker.h>
 #include <vtkPoints.h>
 #include <vtkInteractorStyle.h>
 #include <vtkDataSet.h>
@@ -471,71 +472,49 @@ VISU_Actor
   return myPipeLine->GetElemCell(theObjID);
 }
 
-//==================================================================
-// function: PreHighlight
-// purpose :
-//==================================================================
-bool VISU_Actor::PreHighlight( SVTK_Selector* theSelector,
-                              vtkInteractorStyle *theIS,
-                              SVTK_SelectionEvent theSelectionEvent,
-                              bool theIsHighlight )
+
+//----------------------------------------------------------------------------
+bool
+VISU_Actor
+::PreHighlight(SVTK_Selector* theSelector, 
+              vtkInteractorStyle* theInteractorStyle, 
+              SVTK_SelectionEvent* theSelectionEvent,
+              bool theIsHighlight)
 {
-  bool bRet, anIsChanged;
-  float x, y, z; 
-  vtkIdType aVtkId;
-  
-  bRet=Superclass::PreHighlight(theSelector,
-                               theIS,
-                               theSelectionEvent,
-                               theIsHighlight);
+  bool aRet = Superclass::PreHighlight(theSelector,
+                                      theInteractorStyle,
+                                      theSelectionEvent,
+                                      theIsHighlight);
   //
   myAnnotationActor->SetVisibility(0);
-  //
-  anIsChanged = false;
-  x = theSelectionEvent.myX;
-  y = theSelectionEvent.myY;
-  z = 0.0;
-  vtkRenderer *aRenderer=theIS->GetCurrentRenderer();
-  //
-  if(theIsHighlight) {
+  bool anIsChanged = false;
+  if(theIsHighlight){
     switch(mySelectionMode){
     case CellSelection:{ 
-      myCellPicker->Pick(x, y, z, aRenderer);
-      //if(myCellPicker->GetActor() != this){
-      //       return false;
-      //}
-      aVtkId = myCellPicker->GetCellId();
-      if (aVtkId >= 0  && 
-         theSelector->IsValid( this, aVtkId, true ) &&
-         hasIO() ) {
-       vtkIdType anObjId = GetElemObjId( aVtkId );
-       vtkCell*  pCell=GetElemCell(anObjId);
-       if (pCell){
-         int aNbPnts, i, j;
-         float *aCoord, *aCoordX;
-         //
-         aNbPnts=pCell->GetNumberOfPoints();
-         if (aNbPnts){
-           aCoord=new float[3];
-           for (j=0; j<3; ++j) {
-             aCoord[j]=0.;
+      vtkRenderer* aRenderer = theInteractorStyle->GetCurrentRenderer();
+      myCellPicker->Pick(theSelectionEvent->myX, 
+                        theSelectionEvent->myY, 
+                        0.0, 
+                        aRenderer);
+
+      if(myCellPicker->GetActor() != this)
+       return false;
+      
+      vtkIdType aVTKId = myCellPicker->GetCellId();
+      if(aVTKId >= 0  && theSelector->IsValid(this,aVTKId,true) && hasIO()){
+       vtkIdType anObjId = GetElemObjId(aVTKId);
+       if(vtkCell* aCell = GetElemCell(anObjId)){
+         vtkPoints* aPts = aCell->GetPoints();
+         if(int aNbPts = aCell->GetNumberOfPoints()){
+           float aCoord[3] = {0.0, 0.0, 0.0};
+           for(int i = 0; i < aNbPts; i++){
+             float *aPntCoord = aPts->GetPoint(i); 
+             aCoord[0] += aPntCoord[0];
+             aCoord[1] += aPntCoord[1];
+             aCoord[2] += aPntCoord[2];
            }
-           //
-           vtkPoints * pPnts=pCell->GetPoints();
-           for (i=0; i<aNbPnts; ++i){
-             aCoordX=pPnts->GetPoint(i); 
-             for (j=0; j<3; ++j) {
-               aCoord[j]+=aCoordX[j];
-             }
-           }
-           for (j=0; j<3; ++j) {
-             aCoord[j]/=aNbPnts;
-           }
-           //printf(" aVtkId=%d, x=%f, y=%f, {%f, %f, %f}\n", 
-           //   aVtkId, x, y, aCoord[0], aCoord[1], aCoord[2]);
-           // 
            // Display coordinates
-           float aWorldCoord[4] = {aCoord[0], aCoord[1], aCoord[2], 1.0};
+           float aWorldCoord[4] = {aCoord[0]/aNbPts, aCoord[1]/aNbPts, aCoord[2]/aNbPts, 1.0};
            aRenderer->SetWorldPoint(aWorldCoord);
            aRenderer->WorldToDisplay();
            float aSelectionPoint[3];
@@ -544,25 +523,59 @@ bool VISU_Actor::PreHighlight( SVTK_Selector* theSelector,
            //
            // To prepare the annotation text
            std::ostringstream aStr;
-           aStr<<"Global ID: "<< anObjId;
+           aStr<<"Cell ID: "<< anObjId;
            std::string aString = aStr.str();
            myAnnotationMapper->SetInput(aString.c_str());
            
            myAnnotationActor->SetVisibility(1);
          
-           delete aCoord;
            return true;
          }
        }
       }
+      break;
     }
+    case NodeSelection:{ 
+      vtkRenderer* aRenderer = theInteractorStyle->GetCurrentRenderer();
+      myPointPicker->Pick(theSelectionEvent->myX, 
+                         theSelectionEvent->myY, 
+                         0.0, 
+                         aRenderer);
+      
+      if(myPointPicker->GetActor() != this)
+       return false;
+
+      vtkIdType aVtkId = myPointPicker->GetPointId();
+      if(aVtkId >= 0  && theSelector->IsValid(this,aVtkId,true) && hasIO()){
+       vtkIdType anObjId = GetNodeObjId( aVtkId );
+       if(float* aCoord = GetNodeCoord(anObjId)){
+           // Display coordinates
+           float aWorldCoord[4] = {aCoord[0], aCoord[1], aCoord[2], 1.0};
+           aRenderer->SetWorldPoint(aWorldCoord);
+           aRenderer->WorldToDisplay();
+           float aSelectionPoint[3];
+           aRenderer->GetDisplayPoint(aSelectionPoint);
+           myAnnotationActor->SetPosition(aSelectionPoint);
+           //
+           // To prepare the annotation text
+           std::ostringstream aStr;
+           aStr<<"Node ID: "<< anObjId;
+           std::string aString = aStr.str();
+           myAnnotationMapper->SetInput(aString.c_str());
+           
+           myAnnotationActor->SetVisibility(1);
+         
+           return true;
+         }
+       }
       break;
-    case NodeSelection: 
+    }
     case EdgeOfCellSelection:
+      break;
     default:
       break;
     }
   }
-  return bRet;
+
+  return aRet;
 }
index 0d1a5df10e62f7e38a86859759248caefe653040..f99aad3763fe08e0185b6cc99428c278be290697 100644 (file)
@@ -172,10 +172,10 @@ class VTKOCC_EXPORT VISU_Actor : public SALOME_Actor
   //----------------------------------------------------------------------------
   virtual
   bool
-  PreHighlight( SVTK_Selector*
-               vtkInteractorStyle*,
-               SVTK_SelectionEvent, 
-               bool );
+  PreHighlight(SVTK_Selector* theSelector
+              vtkInteractorStyle* theInteractorStyle, 
+              SVTK_SelectionEvent* theSelectionEvent,
+              bool theIsHighlight);
 
   virtual
   void 
index 100fd47ec4f82866ef8b4feb131478503b1f7d63..be0d5a90aa57d444866f7b856cc3954c30257a0c 100644 (file)
 
 #include <vtkUnstructuredGrid.h>
 #include <vtkDataSetMapper.h>
-#include <vtkCell.h>
-#include <vtkCellArray.h>
 #include <vtkRenderWindow.h>
+#include <vtkCellArray.h>
+#include <vtkCell.h>
+#include <vtkMath.h>
 
 #include "VISU_Convertor_impl.hxx"
 //
@@ -366,32 +367,25 @@ VISU_GaussPtsAct
 //----------------------------------------------------------------
 bool
 VISU_GaussPtsAct
-::PreHighlight( SVTK_Selector* theSelector,
-               vtkInteractorStyle *theIS,
-               SVTK_SelectionEvent theSelectionEvent,
-               bool theIsHighlight )
+::PreHighlight(SVTK_Selector* theSelector, 
+              vtkInteractorStyle* theInteractorStyle, 
+              SVTK_SelectionEvent* theSelectionEvent,
+              bool theIsHighlight)
 {
-  vtkRenderer *aRenderer=theIS->GetCurrentRenderer();
-  //
   myTextActor->SetVisibility(false);
   mySphereActor->SetVisibility(false);
-  myCursorPyramid->SetVisibility(0);
-  
+  myCursorPyramid->SetVisibility(0);  
 
-  if(theSelectionEvent.mySelectionMode == ActorSelection || !theIsHighlight) {
-    return Superclass::PreHighlight(theSelector,theIS,theSelectionEvent,theIsHighlight);
-  }
-  myPreHighlightActor->SetVisibility( false );
+  if(theSelectionEvent->mySelectionMode == ActorSelection || !theIsHighlight)
+    return Superclass::PreHighlight(theSelector,theInteractorStyle,theSelectionEvent,theIsHighlight);
+
+  myPreHighlightActor->SetVisibility(false);
     
-  bool anIsSelectionModeChanged = (theSelectionEvent.mySelectionMode != mySelectionMode);
+  bool anIsSelectionModeChanged = (theSelectionEvent->mySelectionMode != mySelectionMode);
   if(!anIsSelectionModeChanged && mySelectionMode == ActorSelection)
     return false;
 
-  mySelectionMode = theSelectionEvent.mySelectionMode;
-
-  float x = theSelectionEvent.myX;
-  float y = theSelectionEvent.myY;
-  float z = 0.0;
+  mySelectionMode = theSelectionEvent->mySelectionMode;
 
   bool anIsChanged = false;
   if(theIsHighlight){
@@ -399,16 +393,16 @@ VISU_GaussPtsAct
     case NodeSelection: 
     case CellSelection:
     {
-      myPointPicker->Pick( x, y, z, aRenderer );
+      myPointPicker->Pick(theSelectionEvent->myX, 
+                         theSelectionEvent->myY, 
+                         0.0, 
+                         theInteractorStyle->GetCurrentRenderer());
 
-      if(myPointPicker->GetActor() != this) {
+      if(myPointPicker->GetActor() != this)
        return false;
-      }
       
       vtkIdType aVtkId = myPointPicker->GetPointId();
-      if( aVtkId >= 0 && theSelector->IsValid( this, aVtkId, true ) && hasIO() ){
-       //float* aSelectionPoint = myPointPicker->GetSelectionPoint();
-       vtkIdType aVtkId = myPointPicker->GetPointId();
+      if(aVtkId >= 0 && theSelector->IsValid(this,aVtkId,true) && hasIO()){
        vtkIdType anObjId = GetNodeObjId( aVtkId );
        if(myLastObjPointID != anObjId){
          float* aNodeCoord = GetNodeCoord(anObjId);
@@ -476,98 +470,78 @@ VISU_GaussPtsAct
 
   return anIsChanged;
 }
-#include<vtkMath.h>
+
 
 //==================================================================
 // function : Highlight
 // purpose  :
 //==================================================================
-bool VISU_GaussPtsAct::Highlight( SVTK_Selector *theSelector,
-                                 vtkInteractorStyle *theIS,
-                                 SVTK_SelectionEvent theSelectionEvent,
-                                 bool theIsHighlight )
+bool VISU_GaussPtsAct::Highlight(SVTK_Selector* theSelector, 
+                                vtkInteractorStyle* theInteractorStyle, 
+                                SVTK_SelectionEvent* theSelectionEvent,
+                                bool theIsHighlight)
 { 
-  int aTextVisibility, aSphereVisibility, aSphereVisibilitySelected, aSelectionMode;
-  //
-  aTextVisibility=myTextActor->GetVisibility();
-  aSphereVisibility=mySphereActor->GetVisibility();
-  aSphereVisibilitySelected= mySphereActorSelected->GetVisibility();
+  int aTextVisibility = myTextActor->GetVisibility();
+  int aSphereVisibility = mySphereActor->GetVisibility();
+  int aSphereVisibilitySelected = mySphereActorSelected->GetVisibility();
   //
   myTextActor->SetVisibility(0);
   mySphereActor->SetVisibility(0);
   mySphereActorSelected->SetVisibility(0);
   myCellActor->SetVisibility(0);
   //
-  vtkRenderer *aRenderer=theIS->GetCurrentRenderer();
-  vtkRenderWindowInteractor* aRWI=theIS->GetInteractor();
+  vtkRenderer *aRenderer = theInteractorStyle->GetCurrentRenderer();
+  vtkRenderWindowInteractor* anIteractor = theInteractorStyle->GetInteractor();
   //
-  aSelectionMode = theSelectionEvent.mySelectionMode;
+  Selection_Mode aSelectionMode = theSelectionEvent->mySelectionMode;
   mySelectionMode = aSelectionMode;
   //
   if(aSelectionMode==ActorSelection ){ //|| !theIsHighlight) {
     myTextActor->SetVisibility(aTextVisibility);
     mySphereActor->SetVisibility(aSphereVisibility);
     mySphereActorSelected->SetVisibility(aSphereVisibilitySelected);
-    return Superclass::Highlight(theSelector,theIS,theSelectionEvent,theIsHighlight);
+    return Superclass::Highlight(theSelector,theInteractorStyle,theSelectionEvent,theIsHighlight);
   }
   //
-  bool isShift, isRectangle, bRet, bHasIO;
-  float x1, y1, z1, x2, y2, z2;
-  //
-  x1 = theSelectionEvent.myX;
-  y1 = theSelectionEvent.myY;
-  z1 = 0.0;
-  x2 = theSelectionEvent.myLastX;
-  y2 = theSelectionEvent.myLastY;
-  z2 = 0.0;
-  
-  isShift = theSelectionEvent.myIsShift;
-  isRectangle = theSelectionEvent.myIsRectangle;
-  
-  bHasIO=hasIO();
-  bRet=false;
-  if( !isRectangle )  {
-    myPointPicker->Pick( x1, y1, z1, aRenderer );
+  bool bRet = false;
+  if(!theSelectionEvent->myIsRectangle){
+
+    myPointPicker->Pick(theSelectionEvent->myX, 
+                       theSelectionEvent->myY,
+                       0.0, 
+                       aRenderer);
+
     if(myPointPicker->GetActor() != this) {
-      
       myTextActor->SetVisibility(aTextVisibility);
       mySphereActor->SetVisibility(aSphereVisibility);
       return bRet;
     }
     //
     vtkIdType aVtkId = myPointPicker->GetPointId();
-    if( aVtkId >= 0  && theSelector->IsValid( this, aVtkId, true ) && bHasIO)  {
+    if( aVtkId >= 0  && theSelector->IsValid( this, aVtkId, true ) && hasIO())  {
       vtkIdType anObjId = GetNodeObjId( aVtkId );
-      //
-      //double aCoeff=0.667;
-      //vtkCamera *aCamera = aRenderer->GetActiveCamera();
-      //double aScale = aCamera->GetParallelScale();
-      //aCamera->SetParallelScale(aScale*aCoeff);
-      //
-      if( anObjId >= 0 ) {
+      if(anObjId >= 0){
        bRet=!bRet;
        //
        // Update the Selector
-       if( theSelector->IsSelected( myIO ) ) {
-         theSelector->AddOrRemoveIndex( myIO, anObjId, isShift );
-       }
-       else {
-         if( !isShift ) {
+       if(theSelector->IsSelected(myIO))
+         theSelector->AddOrRemoveIndex(myIO,anObjId,theSelectionEvent->myIsShift);
+       else{
+         if(!theSelectionEvent->myIsShift)
            theSelector->ClearIObjects();
-         }
-         theSelector->AddOrRemoveIndex( myIO, anObjId, isShift );
-         theSelector->AddIObject( this );
+         theSelector->AddOrRemoveIndex(myIO,anObjId,theSelectionEvent->myIsShift);
+         theSelector->AddIObject(this);
        }
        //
        float *aNodeCoord, aRadius, aDollyWas;
        //
        aNodeCoord = GetNodeCoord(anObjId);
        //
-       aDollyWas=aRWI->GetDolly();
-       aRWI->SetDolly(0.);
-       aRWI->FlyTo (aRenderer, aNodeCoord);
+       aDollyWas = anIteractor->GetDolly();
+       anIteractor->SetDolly(0.0);
+       anIteractor->FlyTo(aRenderer,aNodeCoord);
        aRenderer->ResetCameraClippingRange();
-       aRWI->SetDolly(aDollyWas);
+       anIteractor->SetDolly(aDollyWas);
        //
        // To calculate display (2D) position of the annotation
        float aWorldCoord[4] = {aNodeCoord[0], aNodeCoord[1], aNodeCoord[2], 1.};
@@ -593,7 +567,7 @@ bool VISU_GaussPtsAct::Highlight( SVTK_Selector *theSelector,
        //
        myTextActor->SetVisibility(1);
        //
-       if (aSelectionMode==CellSelection) {
+       if(aSelectionMode == CellSelection){
          // Hilighting an element from the parent Mesh
          int k, aNbPoints, aIDs[20];
          float *pX;
@@ -644,10 +618,13 @@ bool VISU_GaussPtsAct::Highlight( SVTK_Selector *theSelector,
   //
   else {
     if( vtkDataSet* aDataSet = GetInput() ) {
-      int i, aNbPnts;
-      //
-      aNbPnts=aDataSet->GetNumberOfPoints();
-      for(i = 0; i<aNbPnts && !bRet; i++){
+      float x1 = theSelectionEvent->myX;
+      float y1 = theSelectionEvent->myY;
+      float x2 = theSelectionEvent->myLastX;
+      float y2 = theSelectionEvent->myLastY;
+  
+      int aNbPnts=aDataSet->GetNumberOfPoints();
+      for(int i = 0; i < aNbPnts && !bRet; i++){
        float aPoint[3];
        aDataSet->GetPoint( i, aPoint );
        
@@ -677,20 +654,20 @@ bool VISU_GaussPtsAct::Highlight( SVTK_Selector *theSelector,
                    bRet=!bRet; // true
                    //
                    if( theSelector->IsSelected( myIO ) ) {
-                     theSelector->AddOrRemoveIndex( myIO, anObjId, isShift );
+                     theSelector->AddOrRemoveIndex(myIO,anObjId,theSelectionEvent->myIsShift);
                    }
                    else {
-                     if( !isShift ) {
+                     if(!theSelectionEvent->myIsShift)
                        theSelector->ClearIObjects();
-                     }
-                     theSelector->AddOrRemoveIndex( myIO, anObjId, isShift );
+
+                     theSelector->AddOrRemoveIndex(myIO,anObjId,theSelectionEvent->myIsShift);
                      theSelector->AddIObject( this );
                      bIsAdded=!bIsAdded;
                    }
                    //
                    if (bIsAdded){
                      float* aNodeCoord = GetNodeCoord(anObjId);
-                     aRWI->FlyTo (aRenderer, aNodeCoord); 
+                     anIteractor->FlyTo (aRenderer, aNodeCoord); 
                      aRenderer->ResetCameraClippingRange();
                      // To calculate display (2D) position of the annotation
                      float aWorldCoord[4] = {aNodeCoord[0], aNodeCoord[1], aNodeCoord[2], 1.0};
index 12ba41b11d4ac0427023dde05e0609dea967564d..37c1d347798ab0143901935c3fdeababf24df0f8 100644 (file)
@@ -75,16 +75,16 @@ class VTKOCC_EXPORT VISU_GaussPtsAct : public VISU_ScalarMapAct
 
   virtual
   bool
-  PreHighlight( SVTK_Selector* theSelector,
-               vtkInteractorStyle*,
-               SVTK_SelectionEvent theSelectionEvent,
-               bool theIsHighlight );
+  PreHighlight(SVTK_Selector* theSelector, 
+              vtkInteractorStyle* theInteractorStyle, 
+              SVTK_SelectionEvent* theSelectionEvent,
+              bool theIsHighlight);
   virtual
   bool
-  Highlight( SVTK_Selector* theSelector,
-            vtkInteractorStyle*,
-            SVTK_SelectionEvent theSelectionEvent,
-            bool theIsHighlight );
+  Highlight(SVTK_Selector* theSelector, 
+           vtkInteractorStyle* theInteractorStyle, 
+           SVTK_SelectionEvent* theSelectionEvent,
+           bool theIsHighlight);
 
  protected:
   VISU_GaussPtsAct();