]> SALOME platform Git repositories - modules/visu.git/commitdiff
Salome HOME
add Highlight() method to the class VISU_GaussPoint
authorpkv <pkv@opencascade.com>
Wed, 7 Sep 2005 06:09:15 +0000 (06:09 +0000)
committerpkv <pkv@opencascade.com>
Wed, 7 Sep 2005 06:09:15 +0000 (06:09 +0000)
src/OBJECT/VISU_GaussPtsAct.cxx
src/OBJECT/VISU_GaussPtsAct.h

index 9c1cf3c8b4d4659d9514e74091c7d8de92517996..d5b095d1a8a91ba78e66592121a2d1d4fb7e6190 100644 (file)
@@ -46,6 +46,8 @@
 
 #include <vtkObjectFactory.h>
 #include <vtkInteractorStyle.h>
+#include <vtkRenderWindowInteractor.h>
+#include <vtkCamera.h>
 
 #include <sstream>
 
@@ -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; i<aNbPnts && !bRet; i++){
+       float aPoint[3];
+       aDataSet->GetPoint( 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: "<<anObjId;
+                       
+                       VISU::TGaussPointID aGaussPointID = myGaussPointsPL->GetObjID(anObjId);
+                       VISU::TCellID aCellID = aGaussPointID.first;
+                       VISU::TLocalPntID aLocalPntID = aGaussPointID.second;
+                       aStr<<"\nParentCellID: "<<aCellID;
+                       aStr<<"\nLocalPntID: "<<aLocalPntID;
+                       
+                       vtkDataSet* aDataSet = GetInput();
+                       vtkCellData* aCellData = aDataSet->GetCellData();
+                       if(vtkDataArray *aScalarArray = aCellData->GetScalars()){
+                         float aVal = aScalarArray->GetTuple1(aVtkId);
+                         aStr<<"\nScalar: "<<aVal;
+                         
+                         mySphereSource->SetCenter(aNodeCoord);
+                         float aRadius = myGaussPointsPL->GetPointSize(anObjId,aScalarArray);
+                         mySphereSource->SetRadius(aRadius);
+                       }
+                       
+                       if(vtkDataArray *aVectorArray = aCellData->GetVectors()){
+                         float* aVal = aVectorArray->GetTuple3(aVtkId);
+                         aStr<<"\nVector: {"<<aVal[0]<<"; "<<aVal[1]<<"; "<<aVal[2]<<"}";
+                       }
+                       
+                       std::string aString = aStr.str();
+                       myTextMapper->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;
+}
index a2c3e299778a24ba7106697d9b2124e838f1acf6..7c6e81e88790ab3a4837d1b84ab22bac5b86d603 100644 (file)
@@ -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();