From 337bcb720fead50907a7420a52d92e317ef9dc70 Mon Sep 17 00:00:00 2001 From: apo Date: Thu, 18 Aug 2005 07:55:05 +0000 Subject: [PATCH] To introduce caching for prehighlight functionality --- src/SVTK/SALOME_Actor.cxx | 171 +++++++++++++++++------------- src/SVTK/SALOME_Actor.h | 8 +- src/SVTK/SVTK_InteractorStyle.cxx | 42 ++++---- src/SVTK/SVTK_SelectionEvent.h | 20 ++-- 4 files changed, 136 insertions(+), 105 deletions(-) diff --git a/src/SVTK/SALOME_Actor.cxx b/src/SVTK/SALOME_Actor.cxx index 757f6e2af..48f15a725 100644 --- a/src/SVTK/SALOME_Actor.cxx +++ b/src/SVTK/SALOME_Actor.cxx @@ -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 ) { diff --git a/src/SVTK/SALOME_Actor.h b/src/SVTK/SALOME_Actor.h index 06be74f5f..67e2db193 100644 --- a/src/SVTK/SALOME_Actor.h +++ b/src/SVTK/SALOME_Actor.h @@ -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 ); diff --git a/src/SVTK/SVTK_InteractorStyle.cxx b/src/SVTK/SVTK_InteractorStyle.cxx index b2876bc34..720aace60 100644 --- a/src/SVTK/SVTK_InteractorStyle.cxx +++ b/src/SVTK/SVTK_InteractorStyle.cxx @@ -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; diff --git a/src/SVTK/SVTK_SelectionEvent.h b/src/SVTK/SVTK_SelectionEvent.h index 0f9ece3e4..6a349d062 100644 --- a/src/SVTK/SVTK_SelectionEvent.h +++ b/src/SVTK/SVTK_SelectionEvent.h @@ -33,16 +33,16 @@ 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 -- 2.39.2