From 380fd93f1e69e311143fe1158ef150b362bd14b4 Mon Sep 17 00:00:00 2001 From: apo Date: Tue, 20 Sep 2005 09:31:35 +0000 Subject: [PATCH] 1. Now SelectionEvent wil pass to PreHighlight/Highlight functionality by pointer, not by value. 2. To fix regression with PreHighlight/Highlight functionality --- src/OBJECT/VISU_Actor.cxx | 139 ++++++++++++++++------------- src/OBJECT/VISU_Actor.h | 8 +- src/OBJECT/VISU_GaussPtsAct.cxx | 153 ++++++++++++++------------------ src/OBJECT/VISU_GaussPtsAct.h | 16 ++-- 4 files changed, 153 insertions(+), 163 deletions(-) diff --git a/src/OBJECT/VISU_Actor.cxx b/src/OBJECT/VISU_Actor.cxx index c0c85f0c..cb8a21ca 100644 --- a/src/OBJECT/VISU_Actor.cxx +++ b/src/OBJECT/VISU_Actor.cxx @@ -44,6 +44,7 @@ #include #include #include +#include #include #include #include @@ -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; iGetPoint(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; } diff --git a/src/OBJECT/VISU_Actor.h b/src/OBJECT/VISU_Actor.h index 0d1a5df1..f99aad37 100644 --- a/src/OBJECT/VISU_Actor.h +++ b/src/OBJECT/VISU_Actor.h @@ -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 diff --git a/src/OBJECT/VISU_GaussPtsAct.cxx b/src/OBJECT/VISU_GaussPtsAct.cxx index 100fd47e..be0d5a90 100644 --- a/src/OBJECT/VISU_GaussPtsAct.cxx +++ b/src/OBJECT/VISU_GaussPtsAct.cxx @@ -57,9 +57,10 @@ #include #include -#include -#include #include +#include +#include +#include #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 + //================================================================== // 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; imyX; + 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}; diff --git a/src/OBJECT/VISU_GaussPtsAct.h b/src/OBJECT/VISU_GaussPtsAct.h index 12ba41b1..37c1d347 100644 --- a/src/OBJECT/VISU_GaussPtsAct.h +++ b/src/OBJECT/VISU_GaussPtsAct.h @@ -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(); -- 2.39.2