]> SALOME platform Git repositories - modules/gui.git/commitdiff
Salome HOME
To introduce caching for prehighlight functionality
authorapo <apo@opencascade.com>
Thu, 18 Aug 2005 07:55:05 +0000 (07:55 +0000)
committerapo <apo@opencascade.com>
Thu, 18 Aug 2005 07:55:05 +0000 (07:55 +0000)
src/SVTK/SALOME_Actor.cxx
src/SVTK/SALOME_Actor.h
src/SVTK/SVTK_InteractorStyle.cxx
src/SVTK/SVTK_SelectionEvent.h

index 757f6e2afca81e85cbafd82dc4e6afbfc97c8a35..48f15a725af85e6cc28bb2a3a99257015be90143 100644 (file)
@@ -80,6 +80,7 @@ vtkStandardNewMacro(SALOME_Actor);
 SALOME_Actor
 ::SALOME_Actor()
 {
+  mySelectionMode = ActorSelection;
   myIsHighlighted = myIsPreselected = false;
 
   myRepresentation = 1;
@@ -462,7 +463,7 @@ SALOME_Actor::setDisplayMode(int theMode)
 //----------------------------------------------------------------
 void
 SALOME_Actor
-::highlight( bool theHighlight, Selection_Mode theMode )
+::highlight( bool theHighlight, int theSelectionMode )
 {
   myIsHighlighted = theHighlight; 
 
@@ -472,7 +473,7 @@ SALOME_Actor
   myOutline->SetBounds( GetBounds() );
   myOutlineActor->SetVisibility( theHighlight );
 
-  myHighlightActor->SetVisibility( theHighlight && theMode != ActorSelection );
+  myHighlightActor->SetVisibility( theHighlight && theSelectionMode != ActorSelection );
 }
 
 //----------------------------------------------------------------
@@ -484,6 +485,7 @@ SALOME_Actor
 
   myOutlineActor->SetVisibility( theVisibility && isHighlighted() );
   myHighlightActor->SetVisibility( theVisibility && isHighlighted() );
+  myPreHighlightActor->SetVisibility( theVisibility && myIsPreselected );
 }
 
 
@@ -521,90 +523,117 @@ SALOME_Actor
                SVTK_SelectionEvent theSelectionEvent,
                bool theIsHighlight )
 {
-  Selection_Mode aSelectionMode = theSelectionEvent.SelectionMode;
-  float x = theSelectionEvent.X;
-  float y = theSelectionEvent.Y;
+  myPreHighlightActor->SetVisibility( false );
+    
+  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;
 
+
+  bool anIsChanged = false;
   if( !theIsHighlight )
   {
-    myPreHighlightActor->SetVisibility( false );
-
     vtkActorCollection* theActors = theRenderer->GetActors();
     theActors->InitTraversal();
     while( vtkActor *ac = theActors->GetNextActor() )
       if( SALOME_Actor* anActor = SALOME_Actor::SafeDownCast( ac ) )
-       anActor->SetPreSelected( false );
+       if( anActor->hasIO() && myIO->isSame( anActor->getIO() ) )
+         anActor->SetPreSelected( false );
 
-    return false;
-  }
-
-  if( aSelectionMode == NodeSelection )
-  {
-    myPointPicker->Pick( x, y, z, theRenderer );
-
-    int aVtkId = myPointPicker->GetPointId();
-    if( aVtkId >= 0 && theValidator->IsValid( this, aVtkId, true ) && hasIO() )
+    myIsPreselected = theIsHighlight;
+    anIsChanged = true;
+  }else{
+    switch(mySelectionMode){
+    case NodeSelection: 
     {
-      int anObjId = GetNodeObjId( aVtkId );
-      TColStd_IndexedMapOfInteger aMapIndex;
-      aMapIndex.Add( anObjId );
-
-      myPreHighlightActor->GetProperty()->SetRepresentationToPoints();
-      myPreHighlightActor->SetVisibility( true );
-      myPreHighlightActor->MapPoints( this, aMapIndex );
+      myPointPicker->Pick( x, y, z, theRenderer );
+      
+      int aVtkId = myPointPicker->GetPointId();
+      if( aVtkId >= 0 && theValidator->IsValid( this, aVtkId, true ) && hasIO() )
+      {
+       int anObjId = GetNodeObjId( aVtkId );
+       TColStd_IndexedMapOfInteger aMapIndex;
+       aMapIndex.Add( anObjId );
+       
+       myPreHighlightActor->GetProperty()->SetRepresentationToPoints();
+       myPreHighlightActor->SetVisibility( true );
+       myPreHighlightActor->MapPoints( this, aMapIndex );
+
+       myIsPreselected = theIsHighlight;
+       anIsChanged = true;
+      }
+      break;
     }
-  }
-  else if( aSelectionMode == CellSelection )
-  {
-    myCellPicker->Pick( x, y, z, theRenderer );
-
-    int aVtkId = myCellPicker->GetCellId();
-    if ( aVtkId >= 0 && theValidator->IsValid( this, aVtkId ) && hasIO() )
+    case CellSelection:
     {
-      int anObjId = GetElemObjId (aVtkId );
-      TColStd_IndexedMapOfInteger aMapIndex;
-      aMapIndex.Add( anObjId );
+      myCellPicker->Pick( x, y, z, theRenderer );
+      
+      int aVtkId = myCellPicker->GetCellId();
+      if ( aVtkId >= 0 && theValidator->IsValid( this, aVtkId ) && hasIO() )
+      {
+       int anObjId = GetElemObjId (aVtkId );
+       TColStd_IndexedMapOfInteger aMapIndex;
+       aMapIndex.Add( anObjId );
 
-      myPreHighlightActor->GetProperty()->SetRepresentationToSurface();
-      myPreHighlightActor->SetVisibility( true );
-      myPreHighlightActor->MapCells( this, aMapIndex );
-    }
-  }
-  else if( aSelectionMode == EdgeOfCellSelection )
-  {
-    myCellPicker->Pick( x, y, z, theRenderer );
+       myPreHighlightActor->GetProperty()->SetRepresentationToSurface();
+       myPreHighlightActor->SetVisibility( true );
+       myPreHighlightActor->MapCells( this, aMapIndex );
 
-    int aVtkId = myCellPicker->GetCellId();
-    if ( aVtkId >= 0 && theValidator->IsValid( this, aVtkId ) && hasIO() )
+       myIsPreselected = theIsHighlight;
+       anIsChanged = true;
+      }
+      break;
+    }
+    case EdgeOfCellSelection:
     {
-      int anObjId = GetElemObjId( aVtkId );
-      int anEdgeId = GetEdgeId( myCellPicker, anObjId );
-      TColStd_IndexedMapOfInteger aMapIndex;
-      aMapIndex.Add( anObjId );
-      aMapIndex.Add( anEdgeId );
-
-      myPreHighlightActor->GetProperty()->SetRepresentationToWireframe();
-      myPreHighlightActor->SetVisibility( true );
-      myPreHighlightActor->MapEdge( this, aMapIndex );
+      myCellPicker->Pick( x, y, z, theRenderer );
+      
+      int aVtkId = myCellPicker->GetCellId();
+      if ( aVtkId >= 0 && theValidator->IsValid( this, aVtkId ) && hasIO() )
+      {
+       int anObjId = GetElemObjId( aVtkId );
+       int anEdgeId = GetEdgeId( myCellPicker, anObjId );
+       TColStd_IndexedMapOfInteger aMapIndex;
+       aMapIndex.Add( anObjId );
+       aMapIndex.Add( anEdgeId );
+       
+       myPreHighlightActor->GetProperty()->SetRepresentationToWireframe();
+       myPreHighlightActor->SetVisibility( true );
+       myPreHighlightActor->MapEdge( this, aMapIndex );
+
+       myIsPreselected = theIsHighlight;
+       anIsChanged = true;
+      }
+      break;
     }
-  }
-  else
-  {
-    if( hasIO() && !theSelector->IsSelected( myIO ) )
+    default:
     {
-      vtkActorCollection* theActors = theRenderer->GetActors();
-      theActors->InitTraversal();
-      while( vtkActor *ac = theActors->GetNextActor() )
+      myPreHighlightActor->SetVisibility( true );
+
+      if( hasIO() && !theSelector->IsSelected( myIO ) )
       {
-       if( SALOME_Actor* anActor = SALOME_Actor::SafeDownCast( ac ) )
-         if( anActor->hasIO() && myIO->isSame( anActor->getIO() ) )
-           anActor->SetPreSelected( true );
+       vtkActorCollection* theActors = theRenderer->GetActors();
+       theActors->InitTraversal();
+       while( vtkActor *ac = theActors->GetNextActor() )
+        {
+         if( SALOME_Actor* anActor = SALOME_Actor::SafeDownCast( ac ) )
+           if( anActor->hasIO() && myIO->isSame( anActor->getIO() ) )
+             anActor->SetPreSelected( true );
+       }
       }
+      myIsPreselected = theIsHighlight;
+      anIsChanged = true;
+    }
     }
   }
 
-  return true;
+  return anIsChanged;
 }
 
 
@@ -617,15 +646,15 @@ SALOME_Actor
             SVTK_SelectionEvent theSelectionEvent,
             bool theIsHighlight )
 {
-  Selection_Mode aSelectionMode = theSelectionEvent.SelectionMode;
-  float x1 = theSelectionEvent.X;
-  float y1 = theSelectionEvent.Y;
+  int aSelectionMode = theSelectionEvent.mySelectionMode;
+  float x1 = theSelectionEvent.myX;
+  float y1 = theSelectionEvent.myY;
   float z1 = 0.0;
-  float x2 = theSelectionEvent.LastX;
-  float y2 = theSelectionEvent.LastY;
+  float x2 = theSelectionEvent.myLastX;
+  float y2 = theSelectionEvent.myLastY;
   float z2 = 0.0;
-  bool isShift = theSelectionEvent.IsShift;
-  bool isRectangle = theSelectionEvent.IsRectangle;
+  bool isShift = theSelectionEvent.myIsShift;
+  bool isRectangle = theSelectionEvent.myIsRectangle;
 
   if( !isRectangle )
   {
index 06be74f5f64c7f5b68b0bc3c3c036b16f3ba093b..67e2db19344fc1adefa1f18e29d063bf2ab74420 100644 (file)
@@ -131,7 +131,7 @@ class SVTK_EXPORT SALOME_Actor : public VTKViewer_Actor
 
   virtual
   void
-  highlight( bool, Selection_Mode );
+  highlight( bool theHighlight, int theSelectionMode );
 
   virtual
   void
@@ -397,9 +397,10 @@ class SVTK_EXPORT SALOME_Actor : public VTKViewer_Actor
 
   vtkProperty *PreviewProperty;
   bool myIsPreselected;
+  bool myIsHighlighted;
+  int mySelectionMode;
 
   float myOpacity;
-  bool myIsHighlighted;
   int myDisplayMode;
   bool myIsInfinite;
 
@@ -417,9 +418,6 @@ class SVTK_EXPORT SALOME_Actor : public VTKViewer_Actor
   SALOME_Actor();
   ~SALOME_Actor();
 
-  // From VISU
- public:
-
  protected:
   int GetEdgeId( vtkPicker*, int );
 
index b2876bc34a7abfedab212b1d882d470b767f881c..720aace60d4d9165d95661e66de1606b122f4653 100644 (file)
@@ -150,10 +150,10 @@ SVTK_InteractorStyle
   Interactor->GetEventPosition( x, y );
   Interactor->GetSize( w, h );
 
-  aSelectionEvent.X = x;
-  aSelectionEvent.Y = h - y - 1;
-  aSelectionEvent.IsCtrl = Interactor->GetControlKey();
-  aSelectionEvent.IsShift = Interactor->GetShiftKey();
+  aSelectionEvent.myX = x;
+  aSelectionEvent.myY = h - y - 1;
+  aSelectionEvent.myIsCtrl = Interactor->GetControlKey();
+  aSelectionEvent.myIsShift = Interactor->GetShiftKey();
 
   return aSelectionEvent;
 }
@@ -952,8 +952,8 @@ SVTK_InteractorStyle
           myPicker->Pick(x, y, 0.0, this->CurrentRenderer);
          if(SALOME_Actor* aSActor = SALOME_Actor::SafeDownCast(myPicker->GetActor())){
            SVTK_SelectionEvent aSelectionEvent = GetSelectionEvent();
-           aSelectionEvent.SelectionMode = aSelectionMode;
-           aSelectionEvent.IsRectangle = false;
+           aSelectionEvent.mySelectionMode = aSelectionMode;
+           aSelectionEvent.myIsRectangle = false;
            aSActor->Highlight( this, GetSelector(), this->CurrentRenderer, aSelectionEvent, true );
          }else{
            GetSelector()->ClearIObjects();
@@ -984,10 +984,10 @@ SVTK_InteractorStyle
          myRectPicker->Pick(x1, y1, 0.0, x2, y2, 0.0, this->CurrentRenderer);
 
          SVTK_SelectionEvent aSelectionEvent = GetSelectionEvent();
-         aSelectionEvent.SelectionMode = aSelectionMode;
-         aSelectionEvent.IsRectangle = true;
-         aSelectionEvent.LastX = x1;
-         aSelectionEvent.LastY = y1;
+         aSelectionEvent.mySelectionMode = aSelectionMode;
+         aSelectionEvent.myIsRectangle = true;
+         aSelectionEvent.myLastX = x1;
+         aSelectionEvent.myLastY = y1;
          
          vtkActorCollection* aListActors = myRectPicker->GetActors();
          aListActors->InitTraversal();
@@ -1104,20 +1104,24 @@ SVTK_InteractorStyle
   Interactor->StartPickCallback();
 
   SVTK_SelectionEvent aSelectionEvent = GetSelectionEvent();
-  aSelectionEvent.SelectionMode = myViewWindow->SelectionMode();
-  aSelectionEvent.X = x;
-  aSelectionEvent.Y = y;
+  aSelectionEvent.mySelectionMode = myViewWindow->SelectionMode();
+  aSelectionEvent.myX = x;
+  aSelectionEvent.myY = y;
 
-  if(SALOME_Actor* aSActor = SALOME_Actor::SafeDownCast(myPicker->GetActor()))
-    aSActor->PreHighlight( this, GetSelector(), this->CurrentRenderer, aSelectionEvent, false );
+  bool anIsChanged = false;
+  SALOME_Actor* aLastActor = SALOME_Actor::SafeDownCast(myPicker->GetActor());
 
   myPicker->Pick(x, y, 0.0, this->CurrentRenderer);
-  if(SALOME_Actor* aSActor = SALOME_Actor::SafeDownCast(myPicker->GetActor()))
-    aSActor->PreHighlight( this, GetSelector(), this->CurrentRenderer, aSelectionEvent, true );
+  if(SALOME_Actor* anActor = SALOME_Actor::SafeDownCast(myPicker->GetActor())){
+    anIsChanged |= anActor->PreHighlight( this, GetSelector(), this->CurrentRenderer, aSelectionEvent, true );
+    if(aLastActor && aLastActor != anActor)
+      aLastActor->PreHighlight( this, GetSelector(), this->CurrentRenderer, aSelectionEvent, false );
+  }
   
   Interactor->EndPickCallback();
-  //Interactor->Render();
-  myGUIWindow->update();
+
+  if(anIsChanged)
+    Interactor->Render();
   
   this->LastPos[0] = x;
   this->LastPos[1] = y;
index 0f9ece3e4bbb8c66cc75524a6547249a7f3f0c67..6a349d06243a676f83bb29c7bd78fdcf4dd6a315 100644 (file)
 
 struct SVTK_SelectionEvent
 {
-  Selection_Mode SelectionMode;
-  int            X;
-  int            Y;
-  int            LastX;
-  int            LastY;
-  bool           IsRectangle;
-  bool           IsCtrl;
-  bool           IsShift;
-  int            KeyCode;
-  int            RepeatCount;
+  int mySelectionMode;
+  int myX;
+  int myY;
+  int myLastX;
+  int myLastY;
+  bool myIsRectangle;
+  bool myIsCtrl;
+  bool myIsShift;
+  int myKeyCode;
+  int myRepeatCount;
 };
 
 #endif