]> SALOME platform Git repositories - modules/gui.git/commitdiff
Salome HOME
To implement caching of highlight / prehighlight functionality
authorapo <apo@opencascade.com>
Mon, 14 Nov 2005 12:43:08 +0000 (12:43 +0000)
committerapo <apo@opencascade.com>
Mon, 14 Nov 2005 12:43:08 +0000 (12:43 +0000)
src/SVTK/SALOME_Actor.cxx
src/SVTK/SVTK_Actor.cxx
src/SVTK/SVTK_Actor.h
src/SVTK/SVTK_InteractorStyle.cxx
src/SVTK/SVTK_InteractorStyle.h

index 646344064df306906098d776623af2bb73ed0c1d..c7b744bc574d12e6dc7e5be2dc4649a9ae0a3581 100644 (file)
@@ -89,7 +89,7 @@ namespace
            vtkPicker* thePicker, 
            int theObjId)
   {
-    int anEdgeId = -1;
+    int anEdgeId = 0;
     if (vtkCell* aPickedCell = theActor->GetElemCell(theObjId)) {
       float aPickPosition[3];
       thePicker->GetPickPosition(aPickPosition);
@@ -100,7 +100,7 @@ namespace
          aLine->EvaluatePosition(aPickPosition,closestPoint,subId,pcoords,aDist,weights);
          if (aDist < aMinDist) {
            aMinDist = aDist;
-           anEdgeId = i;
+           anEdgeId = -1 - i;
          }
        }
       }
@@ -802,7 +802,8 @@ SALOME_Actor
   vtkRenderer *aRenderer = theInteractorStyle->GetCurrentRenderer();
   //
   myPreHighlightActor->SetVisibility( false );
-    
+  bool anIsPreselected = myIsPreselected;
+  
   Selection_Mode aSelectionMode = theSelectionEvent->mySelectionMode;
   bool anIsChanged = (mySelectionMode != aSelectionMode);
 
@@ -819,7 +820,6 @@ SALOME_Actor
        if( anActor->hasIO() && myIO->isSame( anActor->getIO() ) )
          anActor->SetPreSelected( false );
 
-    anIsChanged = true;
   }else{
     switch(aSelectionMode){
     case NodeSelection: 
@@ -829,16 +829,19 @@ SALOME_Actor
       int aVtkId = myPointPicker->GetPointId();
       if( aVtkId >= 0 && mySelector->IsValid( this, aVtkId, true ) ) {
        int anObjId = GetNodeObjId( aVtkId );
-       if ( anObjId >= 0 ) {
-         TColStd_IndexedMapOfInteger aMapIndex;
-         aMapIndex.Add( anObjId );
-       
-         myPreHighlightActor->GetProperty()->SetRepresentationToPoints();
-         myPreHighlightActor->SetVisibility( true );
-         myPreHighlightActor->MapPoints( this, aMapIndex );
-
-         myIsPreselected = theIsHighlight;
-         anIsChanged = true;
+       myIsPreselected = (anObjId >= 0);
+       if(myIsPreselected){
+         const TColStd_IndexedMapOfInteger& aMapIndex = myPreHighlightActor->GetMapIndex();
+         int anExtent = aMapIndex.Extent();
+         anIsChanged |= (anExtent == 0 || anExtent > 0 && anObjId != aMapIndex(1));
+         if(anIsChanged){
+           TColStd_IndexedMapOfInteger aMapIndex;
+           aMapIndex.Add( anObjId );
+           
+           myPreHighlightActor->GetProperty()->SetRepresentationToPoints();
+           myPreHighlightActor->SetVisibility( true );
+           myPreHighlightActor->MapPoints( this, aMapIndex );
+         }
        }
       }
       break;
@@ -854,16 +857,19 @@ SALOME_Actor
       if ( aVtkId >= 0 && mySelector->IsValid( this, aVtkId ) && hasIO() ) {
        int anObjId = GetElemObjId (aVtkId );
        if ( anObjId >= 0 ) {
-         if ( CheckDimensionId(aSelectionMode,this,anObjId) ) {
-           TColStd_IndexedMapOfInteger aMapIndex;
-           aMapIndex.Add( anObjId );
-           
-           myPreHighlightActor->GetProperty()->SetRepresentationToSurface();
-           myPreHighlightActor->SetVisibility( true );
-           myPreHighlightActor->MapCells( this, aMapIndex );
-           
-           myIsPreselected = theIsHighlight;
-           anIsChanged = true;
+         myIsPreselected = CheckDimensionId(aSelectionMode,this,anObjId);
+         if(myIsPreselected){
+           const TColStd_IndexedMapOfInteger& aMapIndex = myPreHighlightActor->GetMapIndex();
+           int anExtent = aMapIndex.Extent();
+           anIsChanged |= (anExtent == 0 || anExtent > 0 && anObjId != aMapIndex(1));
+           if(anIsChanged){
+             TColStd_IndexedMapOfInteger aMapIndex;
+             aMapIndex.Add( anObjId );
+             
+             myPreHighlightActor->GetProperty()->SetRepresentationToSurface();
+             myPreHighlightActor->SetVisibility( true );
+             myPreHighlightActor->MapCells( this, aMapIndex );
+           }
          }
        }
       }
@@ -878,16 +884,22 @@ SALOME_Actor
        int anObjId = GetElemObjId( aVtkId );
        if ( anObjId >= 0 ) {
          int anEdgeId = GetEdgeId(this,myCellPicker.GetPointer(),anObjId);
-         TColStd_IndexedMapOfInteger aMapIndex;
-         aMapIndex.Add( anObjId );
-         aMapIndex.Add( anEdgeId );
+         myIsPreselected = anEdgeId < 0;
+         if(myIsPreselected){
+           const TColStd_IndexedMapOfInteger& aMapIndex = myPreHighlightActor->GetMapIndex();
+           int anExtent = aMapIndex.Extent();
+           anIsChanged |= (anExtent != 2);
+           anIsChanged |= (anExtent == 0 && (anObjId != aMapIndex(1) || anEdgeId != aMapIndex(2)));
+           if(anIsChanged){
+             TColStd_IndexedMapOfInteger aMapIndex;
+             aMapIndex.Add( anObjId );
+             aMapIndex.Add( anEdgeId );
        
-         myPreHighlightActor->GetProperty()->SetRepresentationToWireframe();
-         myPreHighlightActor->SetVisibility( true );
-         myPreHighlightActor->MapEdge( this, aMapIndex );
-
-         myIsPreselected = theIsHighlight;
-         anIsChanged = true;
+             myPreHighlightActor->GetProperty()->SetRepresentationToWireframe();
+             myPreHighlightActor->SetVisibility( true );
+             myPreHighlightActor->MapEdge( this, aMapIndex );
+           }
+         }
        }
       }
       break;
@@ -906,7 +918,6 @@ SALOME_Actor
                anActor->SetPreSelected( true );
        }
       }
-      anIsChanged = true;
     }
     default:
       break;
@@ -914,6 +925,7 @@ SALOME_Actor
   }
 
   mySelectionMode = aSelectionMode;
+  anIsChanged |= (anIsPreselected != myIsPreselected);
 
   return anIsChanged;
 }
index 16faf1791459d9e6dd68af2bd6063196ee965af2..b633626b2426d034ad5813a116174b0862934503 100644 (file)
@@ -42,7 +42,10 @@ static int MYDEBUG = 0;
 #endif
 
 
-static void CopyPoints(vtkUnstructuredGrid* theGrid, vtkDataSet *theSourceDataSet){
+static 
+void
+CopyPoints(vtkUnstructuredGrid* theGrid, vtkDataSet *theSourceDataSet)
+{
   vtkPoints *aPoints = vtkPoints::New();
   vtkIdType iEnd = theSourceDataSet->GetNumberOfPoints();
   aPoints->SetNumberOfPoints(iEnd);
@@ -57,7 +60,8 @@ static void CopyPoints(vtkUnstructuredGrid* theGrid, vtkDataSet *theSourceDataSe
 
 vtkStandardNewMacro(SVTK_Actor);
 
-SVTK_Actor::SVTK_Actor()
+SVTK_Actor
+::SVTK_Actor()
 {
   if(MYDEBUG) INFOS("SVTK_Actor - "<<this);
 
@@ -81,12 +85,17 @@ SVTK_Actor::SVTK_Actor()
   SetResolveCoincidentTopology(false);
 }
 
-void SVTK_Actor::SetShrinkFactor(float theValue){
+void
+SVTK_Actor
+::SetShrinkFactor(float theValue)
+{
   myShrinkFilter->SetShrinkFactor(theValue);
   Modified();
 }
 
-void SVTK_Actor::SetShrink()
+void
+SVTK_Actor
+::SetShrink()
 {
   if ( !myIsShrinkable ) return;
   if ( vtkDataSet* aDataSet = myPassFilter[0]->GetOutput() )
@@ -97,7 +106,9 @@ void SVTK_Actor::SetShrink()
   }
 }
 
-void SVTK_Actor::UnShrink()
+void
+SVTK_Actor
+::UnShrink()
 {
   if ( !myIsShrunk ) return;
   if ( vtkDataSet* aDataSet = myPassFilter[0]->GetOutput() )
@@ -111,7 +122,8 @@ void SVTK_Actor::UnShrink()
 
 
 //----------------------------------------------------------------------------
-SVTK_Actor::~SVTK_Actor()
+SVTK_Actor
+::~SVTK_Actor()
 {
   if(MYDEBUG) INFOS("~SVTK_Actor()");
 
@@ -126,8 +138,19 @@ SVTK_Actor::~SVTK_Actor()
 
 
 //----------------------------------------------------------------------------
-void SVTK_Actor::MapCells(SALOME_Actor* theMapActor,
-                              const TColStd_IndexedMapOfInteger& theMapIndex)
+const TColStd_IndexedMapOfInteger&
+SVTK_Actor
+::GetMapIndex() const
+{
+  return myMapIndex;
+}
+
+
+//----------------------------------------------------------------------------
+void
+SVTK_Actor
+::MapCells(SALOME_Actor* theMapActor,
+          const TColStd_IndexedMapOfInteger& theMapIndex)
 {
   myUnstructuredGrid->Reset();
 
@@ -139,10 +162,6 @@ void SVTK_Actor::MapCells(SALOME_Actor* theMapActor,
     int aPartId = theMapIndex( ind );
     vtkCell* aCell = theMapActor->GetElemCell(aPartId);
     myUnstructuredGrid->InsertNextCell(aCell->GetCellType(),aCell->GetPointIds());
-    //for (int i = 0, iEnd = aCell->GetNumberOfEdges(); i < iEnd; i++){
-    //  vtkCell* anEdgeCell = aCell->GetEdge(i);
-    //  myUnstructuredGrid->InsertNextCell(VTK_LINE,anEdgeCell->GetPointIds());
-    //}
   }
 
   UnShrink();
@@ -150,12 +169,16 @@ void SVTK_Actor::MapCells(SALOME_Actor* theMapActor,
     SetShrinkFactor(theMapActor->GetShrinkFactor());
     SetShrink();
   }
+
+  myMapIndex = theMapIndex;
 }
 
 
 //----------------------------------------------------------------------------
-void SVTK_Actor::MapPoints(SALOME_Actor* theMapActor,
-                               const TColStd_IndexedMapOfInteger& theMapIndex)
+void 
+SVTK_Actor
+::MapPoints(SALOME_Actor* theMapActor,
+           const TColStd_IndexedMapOfInteger& theMapIndex)
 {
   myUnstructuredGrid->Reset();
   if(int aNbOfParts = theMapIndex.Extent()){
@@ -172,12 +195,16 @@ void SVTK_Actor::MapPoints(SALOME_Actor* theMapActor,
   }
 
   UnShrink();
+
+  myMapIndex = theMapIndex;
 }
 
 
 //----------------------------------------------------------------------------
-void SVTK_Actor::MapEdge(SALOME_Actor* theMapActor,
-                             const TColStd_IndexedMapOfInteger& theMapIndex)
+void
+SVTK_Actor
+::MapEdge(SALOME_Actor* theMapActor,
+         const TColStd_IndexedMapOfInteger& theMapIndex)
 {
   myUnstructuredGrid->Reset();
 
@@ -227,6 +254,8 @@ void SVTK_Actor::MapEdge(SALOME_Actor* theMapActor,
     SetShrinkFactor(theMapActor->GetShrinkFactor());
     SetShrink();
   }
+
+  myMapIndex = theMapIndex;
 }
 
 //----------------------------------------------------------------------------
index 74a883a1aeaf206b1c4850732d65d5bc5aa30507..d43ca24d699b0826ad26babd5f582bfb1934442e 100644 (file)
@@ -56,10 +56,14 @@ public:
   void MapEdge(SALOME_Actor* theMapActor, 
               const TColStd_IndexedMapOfInteger& theMapIndex);
 
+  const TColStd_IndexedMapOfInteger&
+  GetMapIndex() const;
+
  protected:
+  TColStd_IndexedMapOfInteger myMapIndex;
+
   vtkUnstructuredGrid* myUnstructuredGrid;
   vtkDataSetMapper* myMapper;
-
   vtkRenderer* myRenderer;
 
   vtkShrinkFilter* myShrinkFilter;
index b2e4b60e0af70493731b07b6527ad4b0788617dd..2f8100b5724d1fd7b87c3f0d85d6569234b3e3dd 100644 (file)
@@ -72,10 +72,6 @@ static int MYDEBUG = 0;
 static int MYDEBUG = 0;
 #endif
 
-static 
-  bool GetFirstSALOMEActor(vtkPicker *pPicker, 
-                          SALOME_Actor*& pSA);
-
 namespace
 {
   inline 
@@ -87,7 +83,29 @@ namespace
     theInteractor->GetEventPosition(theX,theY);
     theY = theInteractor->GetSize()[1] - theY - 1;
   }
-}  
+
+  //==================================================================
+  // function : GetFirstSALOMEActor
+  // purpose  :
+  //==================================================================
+  struct THaveIO
+  {
+    bool
+    operator()(SALOME_Actor* theActor)
+    {
+      return theActor->hasIO();
+    }
+  };
+
+  inline
+  SALOME_Actor* 
+  GetFirstSALOMEActor(vtkPicker *thePicker)
+  {
+    return VTK::Find<SALOME_Actor>(thePicker->GetActors(),THaveIO());
+  }
+}
+
+
 //----------------------------------------------------------------------------
 vtkStandardNewMacro(SVTK_InteractorStyle);
 //----------------------------------------------------------------------------
@@ -95,7 +113,9 @@ vtkStandardNewMacro(SVTK_InteractorStyle);
 SVTK_InteractorStyle
 ::SVTK_InteractorStyle():
   mySelectionEvent(new SVTK_SelectionEvent()),
-  myPicker(vtkPicker::New())
+  myPicker(vtkPicker::New()),
+  myLastHighlitedActor(NULL),
+  myLastPreHighlitedActor(NULL)
 {
   myPicker->Delete();
 
@@ -895,20 +915,17 @@ SVTK_InteractorStyle
                         0.0, 
                         GetCurrentRenderer());
          //
-         SALOME_Actor* aSActor=NULL;
-         //
-         GetFirstSALOMEActor(myPicker.GetPointer(), aSActor);
-         if (aSActor){
-           //if(SALOME_Actor* aSActor = SALOME_Actor::SafeDownCast(myPicker->GetActor())){
-           if(aSActor->hasIO()){
-             aSelectionEvent->myIsRectangle = false;
-             aSActor->Highlight( this, aSelectionEvent, true );
-           }
-         }
-         else{
+         SALOME_Actor* anActor = GetFirstSALOMEActor(myPicker.GetPointer());
+         aSelectionEvent->myIsRectangle = false;
+         if(anActor){
+           anActor->Highlight( this, aSelectionEvent, true );
+         }else{
+           if(myLastHighlitedActor && myLastHighlitedActor != anActor)
+             myLastHighlitedActor->Highlight( this, aSelectionEvent, false );
            GetSelector()->ClearIObjects();
          }
-        } 
+         myLastHighlitedActor = anActor;
+       } 
        else {
           //processing rectangle selection
          Interactor->StartPickCallback();
@@ -1021,24 +1038,22 @@ SVTK_InteractorStyle
   this->FindPokedRenderer(aSelectionEvent->myX,aSelectionEvent->myY);
 
   bool anIsChanged = false;
-  SALOME_Actor *aLastActor=NULL;
-  //
-  GetFirstSALOMEActor(myPicker.GetPointer(), aLastActor);
-  if (aLastActor){
-    anIsChanged |= aLastActor->PreHighlight( this, aSelectionEvent, false );
-  }
+
   myPicker->Pick(aSelectionEvent->myX, 
                 aSelectionEvent->myY, 
                 0.0, 
                 GetCurrentRenderer());
   
-  SALOME_Actor *anActor=NULL;
-  //
-  GetFirstSALOMEActor(myPicker.GetPointer(), anActor);
+  SALOME_Actor *anActor = GetFirstSALOMEActor(myPicker.GetPointer());
   if (anActor){
     anIsChanged |= anActor->PreHighlight( this, aSelectionEvent, true );
   }
-  
+
+  if(myLastPreHighlitedActor && myLastPreHighlitedActor != anActor)
+    anIsChanged |= myLastPreHighlitedActor->PreHighlight( this, aSelectionEvent, false );   
+
+  myLastPreHighlitedActor = anActor;
+
   if(anIsChanged)
     this->Render();
 }
@@ -1317,31 +1332,3 @@ SVTK_InteractorStyle
 void SVTK_InteractorStyle::OnChar()
 {
 }
-//==================================================================
-// function : GetFirstSALOMEActor
-// purpose  :
-//==================================================================
-bool GetFirstSALOMEActor(vtkPicker *pPicker, 
-                        SALOME_Actor*& pSA)
-{
-  bool bRet=false;
-  pSA=NULL;
-  vtkActor *pA;
-  //
-  vtkActorCollection *pActors=pPicker->GetActors();
-  //
-  pActors->InitTraversal(); 
-  while(1) {
-    pA=pActors->GetNextActor();
-    if (!pA) {
-      break;
-    }
-    //
-    pSA=SALOME_Actor::SafeDownCast(pA);
-    if (pSA){
-      bRet=!bRet;
-      break;
-    }
-  }
-  return bRet;
-}
index 5667a42cb595c76a295195516885c0f7976423e2..a97480dde29b02a001be861faf9046cc5aff7281 100644 (file)
@@ -46,6 +46,8 @@
 class vtkCell;
 class vtkPicker;
 
+class SALOME_Actor;
+
 class SVTK_Selector;
 class SVTK_GenericRenderWindowInteractor;
 
@@ -225,6 +227,9 @@ class SVTK_EXPORT SVTK_InteractorStyle: public vtkInteractorStyle
   bool                      myShiftState;
   int                       ForcedState;
 
+  SALOME_Actor*             myLastHighlitedActor;
+  SALOME_Actor*             myLastPreHighlitedActor;
+
   //! "Increment" for pan/rotate/zoom operations
   int                       mySpeedIncrement;