]> SALOME platform Git repositories - modules/visu.git/commitdiff
Salome HOME
provides pass vtkInteractorStyle objrct to the methods Highlight(),Prehighlight(...
authorpkv <pkv@opencascade.com>
Tue, 6 Sep 2005 06:09:29 +0000 (06:09 +0000)
committerpkv <pkv@opencascade.com>
Tue, 6 Sep 2005 06:09:29 +0000 (06:09 +0000)
src/OBJECT/VISU_Actor.cxx
src/OBJECT/VISU_Actor.h
src/OBJECT/VISU_GaussPtsAct.cxx
src/OBJECT/VISU_GaussPtsAct.h

index 2814e57cd0fdc6c282eb167824a3c0288a3ac88f..1b959f19fed313b7e3e85c3561e9f502a92356ac 100644 (file)
 #include "VTKViewer_PassThroughFilter.h"
  
 #include <stdexcept>
+#include <sstream>
 
 // VTK Includes
 #include <vtkProperty.h>
-
+#include <vtkSmartPointer.h>
+#include <vtkTextMapper.h>
+#include <vtkTextActor.h>
+#include <vtkProperty2D.h>
+#include <vtkRenderer.h>
+#include <vtkCellPicker.h>
+#include <vtkCell.h>
+#include <vtkPoints.h>
+#include <vtkInteractorStyle.h>
 #include <vtkDataSet.h>
 #include <vtkPolyData.h>
 #include <vtkUnstructuredGrid.h>
@@ -72,7 +81,9 @@ VISU_Actor::VISU_Actor():
   myMapper(vtkDataSetMapper::New()),
   myIsShrunk(false),
   myIsShrinkable(false),
-  myShrinkFilter(VTKViewer_ShrinkFilter::New())
+  myShrinkFilter(VTKViewer_ShrinkFilter::New()),
+  myAnnotationMapper(vtkTextMapper::New()),
+  myAnnotationActor(vtkTextActor::New())
 {
   SetDebug(MYVTKDEBUG);
 
@@ -80,6 +91,11 @@ VISU_Actor::VISU_Actor():
 
   myShrinkFilter->SetStoreMapping(true);
   SetShrinkFactor();  
+
+  myAnnotationMapper->Delete();
+  myAnnotationActor->Delete();
+  myAnnotationActor->SetMapper(myAnnotationMapper.GetPointer());
+  myAnnotationActor.GetPointer()->SetVisibility(0);
 }
 
 VISU_Actor::~VISU_Actor(){
@@ -299,3 +315,119 @@ VISU_Actor
 
   return myPipeLine->GetElemCell(theObjID);
 }
+
+//==================================================================
+// function: PreHighlight
+// purpose :
+//==================================================================
+bool VISU_Actor::PreHighlight( SVTK_Selector* theSelector,
+                              vtkInteractorStyle *theIS,
+                              SVTK_SelectionEvent theSelectionEvent,
+                              bool theIsHighlight )
+{
+  bool bRet, anIsChanged;
+  float x, y, z; 
+  vtkIdType aVtkId;
+  
+  bRet=Superclass::PreHighlight(theSelector,
+                               theIS,
+                               theSelectionEvent,
+                               theIsHighlight);
+  //
+  myAnnotationActor->SetVisibility(0);
+  //
+  anIsChanged = false;
+  x = theSelectionEvent.myX;
+  y = theSelectionEvent.myY;
+  z = 0.0;
+  vtkRenderer *aRenderer=theIS->GetCurrentRenderer();
+  //
+  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.;
+           }
+           //
+           vtkPoints * pPnts=pCell->GetPoints();
+           for (i=0; i<aNbPnts; ++i){
+             aCoordX=pPnts->GetPoint(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};
+           aRenderer->SetWorldPoint(aWorldCoord);
+           aRenderer->WorldToDisplay();
+           float aSelectionPoint[3];
+           aRenderer->GetDisplayPoint(aSelectionPoint);
+           myAnnotationActor->SetPosition(aSelectionPoint);
+           //
+           // To prepare the annotation text
+           std::ostringstream aStr;
+           aStr<<"Global ID: "<< anObjId;
+           std::string aString = aStr.str();
+           myAnnotationMapper->SetInput(aString.c_str());
+           
+           myAnnotationActor->SetVisibility(1);
+         
+           delete aCoord;
+           return true;
+         }
+       }
+      }
+    }
+      break;
+    case NodeSelection: 
+    case EdgeOfCellSelection:
+    default:
+      break;
+    }
+  }
+  return bRet;
+}
+//==================================================================
+// function: AddToRender
+// purpose :
+//==================================================================
+void VISU_Actor::AddToRender(vtkRenderer* theRenderer)
+{
+  
+  Superclass::AddToRender(theRenderer);
+  theRenderer->AddActor(myAnnotationActor.GetPointer());
+}
+//==================================================================
+// function: RemoveFromRender
+// purpose :
+//==================================================================
+void VISU_Actor::RemoveFromRender(vtkRenderer* theRenderer)
+{
+  theRenderer->RemoveActor(myAnnotationActor.GetPointer());
+  Superclass::RemoveFromRender(theRenderer); 
+  
+}
index 478a6c0713a729f4e5156973ce24e613e2d616da..13c736f296bce8866dc861860210cb239ce41bb8 100644 (file)
 #include "SALOME_Actor.h"
 
 #include <string>
+#include <vtkSmartPointer.h>
 
 class vtkProp;
 class vtkProperty;
 class vtkDataSetMapper;
-
+class vtkTextMapper;
+class vtkTextActor;
+class vtkInteractorStyle;
 class VTKViewer_ShrinkFilter;
 class VISU_PipeLine;
 
@@ -89,6 +92,15 @@ class VTKOCC_EXPORT VISU_Actor : public SALOME_Actor
   virtual void SetLineWidth(float theLineWidth);
   virtual float GetLineWidth();
  
+  virtual void AddToRender( vtkRenderer* ); 
+
+  virtual void RemoveFromRender( vtkRenderer* );
+
+  virtual bool PreHighlight( SVTK_Selector*, 
+                            vtkInteractorStyle*,
+                            SVTK_SelectionEvent, 
+                            bool );
+
   virtual
   void 
   SetVTKMapping(bool theIsVTKMapping); 
@@ -140,6 +152,8 @@ class VTKOCC_EXPORT VISU_Actor : public SALOME_Actor
   VTKViewer_ShrinkFilter* myShrinkFilter;
   bool myIsShrinkable;
   bool myIsShrunk;
+  vtkSmartPointer<vtkTextMapper> myAnnotationMapper;
+  vtkSmartPointer<vtkTextActor>  myAnnotationActor;
 };
 
 #endif //VISU_ACTOR_H
index 9788ee9b4cc347af7b53a814b10ef628d1a6a257..9c1cf3c8b4d4659d9514e74091c7d8de92517996 100644 (file)
@@ -45,6 +45,7 @@
 #include <vtkActor.h>
 
 #include <vtkObjectFactory.h>
+#include <vtkInteractorStyle.h>
 
 #include <sstream>
 
@@ -114,16 +115,18 @@ VISU_GaussPtsAct
 bool
 VISU_GaussPtsAct
 ::PreHighlight( SVTK_Selector* theSelector,
-               vtkRenderer* theRenderer,
+               vtkInteractorStyle *theIS,
                SVTK_SelectionEvent theSelectionEvent,
                bool theIsHighlight )
 {
+  vtkRenderer *aRenderer=theIS->GetCurrentRenderer();
+  //
   myTextActor->SetVisibility(false);
   mySphereActor->SetVisibility(false);
 
-  if(theSelectionEvent.mySelectionMode == ActorSelection || !theIsHighlight)
-    return Superclass::PreHighlight(theSelector,theRenderer,theSelectionEvent,theIsHighlight);
-
+  if(theSelectionEvent.mySelectionMode == ActorSelection || !theIsHighlight) {
+    return Superclass::PreHighlight(theSelector,theIS,theSelectionEvent,theIsHighlight);
+  }
   myPreHighlightActor->SetVisibility( false );
     
   bool anIsSelectionModeChanged = (theSelectionEvent.mySelectionMode != mySelectionMode);
@@ -142,7 +145,7 @@ VISU_GaussPtsAct
     case NodeSelection: 
     case CellSelection:
     {
-      myPointPicker->Pick( x, y, z, theRenderer );
+      myPointPicker->Pick( x, y, z, aRenderer );
 
       if(myPointPicker->GetActor() != this)
        return false;
@@ -157,10 +160,10 @@ VISU_GaussPtsAct
 
          // To calculate display (2D) position of the annotation
          float aWorldCoord[4] = {aNodeCoord[0], aNodeCoord[1], aNodeCoord[2], 1.0};
-         theRenderer->SetWorldPoint(aWorldCoord);
-         theRenderer->WorldToDisplay();
+         aRenderer->SetWorldPoint(aWorldCoord);
+         aRenderer->WorldToDisplay();
          float aSelectionPoint[3];
-         theRenderer->GetDisplayPoint(aSelectionPoint);
+         aRenderer->GetDisplayPoint(aSelectionPoint);
          myTextActor->SetPosition(aSelectionPoint);
          
          // To prepare the annotation text
index ae766a5473b7abf32a013a45a85fff9210a85fdb..a2c3e299778a24ba7106697d9b2124e838f1acf6 100644 (file)
@@ -39,6 +39,7 @@ class vtkTextActor;
 class vtkSphereSource;
 class vtkPolyDataMapper;
 class vtkActor;
+class vtkInteractorStyle;
 
 class VTKOCC_EXPORT VISU_GaussPtsAct : public VISU_ScalarMapAct
 {
@@ -64,7 +65,7 @@ class VTKOCC_EXPORT VISU_GaussPtsAct : public VISU_ScalarMapAct
   virtual
   bool
   PreHighlight( SVTK_Selector* theSelector,
-               vtkRenderer* theRenderer,
+               vtkInteractorStyle*,
                SVTK_SelectionEvent theSelectionEvent,
                bool theIsHighlight );