From ce229d749bed2ab271e556dd712474667cfc9bf5 Mon Sep 17 00:00:00 2001 From: apo Date: Mon, 14 Nov 2005 13:11:46 +0000 Subject: [PATCH] 1. To implement caching of highlight / prehighlight functionality 2. To move "change camera zoom on picking" functionality from VVTK_InteractorStyle to VISU_GaussPtsAct --- src/OBJECT/VISU_GaussPtsAct.cxx | 115 ++++++++++++++++++++++++-------- 1 file changed, 89 insertions(+), 26 deletions(-) diff --git a/src/OBJECT/VISU_GaussPtsAct.cxx b/src/OBJECT/VISU_GaussPtsAct.cxx index b17b622c..14b6921e 100644 --- a/src/OBJECT/VISU_GaussPtsAct.cxx +++ b/src/OBJECT/VISU_GaussPtsAct.cxx @@ -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; } -- 2.39.2