From: pkv Date: Wed, 7 Sep 2005 06:09:15 +0000 (+0000) Subject: add Highlight() method to the class VISU_GaussPoint X-Git-Tag: BR-D5-38-2003_D2005-12-09~21 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=2ed813d91309a3617a4e3e7cc48c52876bef32ce;p=modules%2Fvisu.git add Highlight() method to the class VISU_GaussPoint --- diff --git a/src/OBJECT/VISU_GaussPtsAct.cxx b/src/OBJECT/VISU_GaussPtsAct.cxx index 9c1cf3c8..d5b095d1 100644 --- a/src/OBJECT/VISU_GaussPtsAct.cxx +++ b/src/OBJECT/VISU_GaussPtsAct.cxx @@ -46,6 +46,8 @@ #include #include +#include +#include #include @@ -71,6 +73,7 @@ VISU_GaussPtsAct myTextActor->SetMapper(myTextMapper.GetPointer()); //myTextActor->SetAlignmentPoint(3); myTextActor->SetVisibility(false); + myTextActor->SetPickable(false); mySphereSource->Delete(); mySphereMapper->Delete(); @@ -79,6 +82,7 @@ VISU_GaussPtsAct mySphereMapper->SetInput(mySphereSource->GetOutput()); mySphereActor->SetMapper(mySphereMapper.GetPointer()); mySphereActor->SetVisibility(false); + mySphereActor->SetPickable(false); } VISU_GaussPtsAct @@ -123,7 +127,6 @@ VISU_GaussPtsAct // myTextActor->SetVisibility(false); mySphereActor->SetVisibility(false); - if(theSelectionEvent.mySelectionMode == ActorSelection || !theIsHighlight) { return Superclass::PreHighlight(theSelector,theIS,theSelectionEvent,theIsHighlight); } @@ -147,8 +150,9 @@ VISU_GaussPtsAct { myPointPicker->Pick( x, y, z, aRenderer ); - if(myPointPicker->GetActor() != this) + if(myPointPicker->GetActor() != this) { return false; + } vtkIdType aVtkId = myPointPicker->GetPointId(); if( aVtkId >= 0 && theSelector->IsValid( this, aVtkId, true ) && hasIO() ){ @@ -215,3 +219,197 @@ VISU_GaussPtsAct return anIsChanged; } + +//---------------------------------------------------------------- +bool +VISU_GaussPtsAct::Highlight( SVTK_Selector *theSelector, + vtkInteractorStyle *theIS, + SVTK_SelectionEvent theSelectionEvent, + bool theIsHighlight ) +{ + int aTextVisibility, aSphereVisibility; + // + aTextVisibility=myTextActor->GetVisibility(); + aSphereVisibility=mySphereActor->GetVisibility(); + // + myTextActor->SetVisibility(0); + mySphereActor->SetVisibility(0); + // + vtkRenderer *aRenderer=theIS->GetCurrentRenderer(); + vtkRenderWindowInteractor* aRWI=theIS->GetInteractor(); + // + int aSelectionMode = theSelectionEvent.mySelectionMode; + mySelectionMode = aSelectionMode; + // + if(aSelectionMode==ActorSelection ){ //|| !theIsHighlight) { + myTextActor->SetVisibility(aTextVisibility); + mySphereActor->SetVisibility(aSphereVisibility); + return Superclass::Highlight(theSelector,theIS,theSelectionEvent,theIsHighlight); + } + // + float x1 = theSelectionEvent.myX; + float y1 = theSelectionEvent.myY; + float z1 = 0.0; + float x2 = theSelectionEvent.myLastX; + float y2 = theSelectionEvent.myLastY; + float z2 = 0.0; + bool isShift = theSelectionEvent.myIsShift; + bool isRectangle = theSelectionEvent.myIsRectangle; + bool bRet=false; + // + if( !isRectangle ) { + myPointPicker->Pick( x1, y1, z1, 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 ) && hasIO()) { + vtkIdType anObjId = GetNodeObjId( aVtkId ); + // + //double aCoeff=0.667; + //vtkCamera *aCamera = aRenderer->GetActiveCamera(); + //double aScale = aCamera->GetParallelScale(); + //aCamera->SetParallelScale(aScale*aCoeff); + // + if( anObjId >= 0 ) { + bRet=!bRet; + if( theSelector->IsSelected( myIO ) ) { + theSelector->AddOrRemoveIndex( myIO, anObjId, isShift ); + } + else { + if( !isShift ) { + theSelector->ClearIObjects(); + } + theSelector->AddOrRemoveIndex( myIO, anObjId, isShift ); + theSelector->AddIObject( this ); + } + float* aNodeCoord = GetNodeCoord(anObjId); + aRWI->FlyTo (aRenderer, aNodeCoord); + aRenderer->ResetCameraClippingRange(); + // + // To calculate display (2D) position of the annotation + float aWorldCoord[4] = {aNodeCoord[0], aNodeCoord[1], aNodeCoord[2], 1.0}; + aRenderer->SetWorldPoint(aWorldCoord); + aRenderer->WorldToDisplay(); + float aSelectionPoint[3]; + aRenderer->GetDisplayPoint(aSelectionPoint); + myTextActor->SetPosition(aSelectionPoint); + // + float aColor[3]={1.,1.,1.}; + mySphereActor->GetProperty()->SetColor(aColor); + } + } + }// if( !isRectangle ) + else { + if( vtkDataSet* aDataSet = GetInput() ) { + int i, aNbPnts; + // + aNbPnts=aDataSet->GetNumberOfPoints(); + for(i = 0; iGetPoint( i, aPoint ); + + float aPnt[3]; + aRenderer->SetWorldPoint( aPoint[0], aPoint[1], aPoint[2], 1.0 ); + aRenderer->WorldToDisplay(); + aRenderer->GetDisplayPoint( aPnt ); + + if( aPnt[0] > x2 && aPnt[0] < x1 && aPnt[1] > y1 && aPnt[1] < y2 ) { + float aDisp[3]; + aRenderer->SetWorldPoint( aPoint[0], aPoint[1], aPoint[2], 1.0 ); + aRenderer->WorldToDisplay(); + aRenderer->GetDisplayPoint( aDisp ); + + if( myPointPicker->Pick( aDisp[0], aDisp[1], 0.0, aRenderer ) ) { + if( vtkActorCollection* anActorCollection = myPointPicker->GetActors() ) { + if( anActorCollection->IsItemPresent( this ) ) { + float aPickedPoint[3]; + myPointPicker->GetMapperPosition( aPickedPoint ); + vtkIdType aVtkId = aDataSet->FindPoint( aPickedPoint ); + if( aVtkId >= 0 && theSelector->IsValid( this, aVtkId, true ) ) { + vtkIdType anObjId = GetNodeObjId( aVtkId ); + + if( anObjId >= 0 ) { + // + bool bIsAdded=false; + bRet=!bRet; // true + // + if( theSelector->IsSelected( myIO ) ) { + theSelector->AddOrRemoveIndex( myIO, anObjId, isShift ); + } + else { + if( !isShift ) { + theSelector->ClearIObjects(); + } + theSelector->AddOrRemoveIndex( myIO, anObjId, isShift ); + theSelector->AddIObject( this ); + bIsAdded=!bIsAdded; + } + // + if (bIsAdded){ + float* aNodeCoord = GetNodeCoord(anObjId); + aRWI->FlyTo (aRenderer, aNodeCoord); + aRenderer->ResetCameraClippingRange(); + // To calculate display (2D) position of the annotation + float aWorldCoord[4] = {aNodeCoord[0], aNodeCoord[1], aNodeCoord[2], 1.0}; + aRenderer->SetWorldPoint(aWorldCoord); + aRenderer->WorldToDisplay(); + float aSelectionPoint[3]; + aRenderer->GetDisplayPoint(aSelectionPoint); + myTextActor->SetPosition(aSelectionPoint); + // + // annotation text + { + std::ostringstream aStr; + aStr<<"Global ID: "<GetObjID(anObjId); + VISU::TCellID aCellID = aGaussPointID.first; + VISU::TLocalPntID aLocalPntID = aGaussPointID.second; + aStr<<"\nParentCellID: "<GetCellData(); + if(vtkDataArray *aScalarArray = aCellData->GetScalars()){ + float aVal = aScalarArray->GetTuple1(aVtkId); + aStr<<"\nScalar: "<SetCenter(aNodeCoord); + float aRadius = myGaussPointsPL->GetPointSize(anObjId,aScalarArray); + mySphereSource->SetRadius(aRadius); + } + + if(vtkDataArray *aVectorArray = aCellData->GetVectors()){ + float* aVal = aVectorArray->GetTuple3(aVtkId); + aStr<<"\nVector: {"<SetInput(aString.c_str()); + }// annotation text + // + float aColor[3]={1.,1.,1.}; + mySphereActor->GetProperty()->SetColor(aColor); + // shoe sphere + myTextActor->SetVisibility(1); + mySphereActor->SetVisibility(1); + return bRet; + }// if (bIsAdded){ + }// if( anObjId >= 0 ) + } + } + } + } + } + } + } + }//else ... if(!isRectangle ) + myTextActor->SetVisibility(aTextVisibility); + mySphereActor->SetVisibility(aSphereVisibility); + return bRet; +} diff --git a/src/OBJECT/VISU_GaussPtsAct.h b/src/OBJECT/VISU_GaussPtsAct.h index a2c3e299..7c6e81e8 100644 --- a/src/OBJECT/VISU_GaussPtsAct.h +++ b/src/OBJECT/VISU_GaussPtsAct.h @@ -68,7 +68,13 @@ class VTKOCC_EXPORT VISU_GaussPtsAct : public VISU_ScalarMapAct vtkInteractorStyle*, SVTK_SelectionEvent theSelectionEvent, bool theIsHighlight ); - + virtual + bool + Highlight( SVTK_Selector* theSelector, + vtkInteractorStyle*, + SVTK_SelectionEvent theSelectionEvent, + bool theIsHighlight ); + protected: VISU_GaussPtsAct(); virtual ~VISU_GaussPtsAct();