]> SALOME platform Git repositories - modules/visu.git/commitdiff
Salome HOME
Implementation of InteractorObserver functionality for the GaussPoints Actor class
authorapo <apo@opencascade.com>
Thu, 22 Sep 2005 05:44:51 +0000 (05:44 +0000)
committerapo <apo@opencascade.com>
Thu, 22 Sep 2005 05:44:51 +0000 (05:44 +0000)
src/OBJECT/VISU_ActorFactory.h
src/OBJECT/VISU_GaussPtsAct.cxx
src/OBJECT/VISU_GaussPtsAct.h

index a41cbfed2e4629da00c49cb5c478c861167c622e..a23cbe640b47d176eaa32d4ab1651bf237722d96 100644 (file)
@@ -48,6 +48,10 @@ namespace VISU
     void
     UpdateActor(VISU_Actor* theActor) = 0;
 
+    virtual 
+    void
+    UpdateFromActor(VISU_Actor* theActor) = 0;
+
     virtual 
     void 
     SetImplicitFunction(VISU_Actor* theActor, 
@@ -55,5 +59,4 @@ namespace VISU
   };
 }
 
-
 #endif //VISU_ACTOR_FACTORY_H
index 8489cc3bd2534af023429ac4c0914b715d918f2e..1b1ce339bf56a7893c7c26bc4d895cbf3947dab4 100644 (file)
@@ -32,6 +32,7 @@
 
 #include "SVTK_Actor.h"
 
+#include <vtkCamera.h>
 #include <vtkRenderer.h>
 #include <vtkPointPicker.h>
 #include <vtkScalarBarWidget.h>
 #include <vtkPolyData.h>
 #include <vtkActor.h>
 
+#include <vtkCommand.h>
 #include <vtkObjectFactory.h>
+#include <vtkCallbackCommand.h>
 #include <vtkInteractorStyle.h>
+#include <vtkInteractorObserver.h>
 #include <vtkRenderWindowInteractor.h>
-#include <vtkCamera.h>
 
 #include <sstream>
+#include <boost/bind.hpp>
 
 #include <vtkUnstructuredGrid.h>
 #include <vtkDataSetMapper.h>
@@ -235,6 +239,8 @@ vtkStandardNewMacro(VISU_GaussPtsAct);
 
 VISU_GaussPtsAct
 ::VISU_GaussPtsAct():
+  myInteractorObserver(vtkInteractorObserver::New()),
+  myEventCallbackCommand(vtkCallbackCommand::New()),
   myPSMapper(VISU_OpenGLPointSpriteMapper::New()),
   myGaussPointsPL(NULL),
   myTextMapper(vtkTextMapper::New()),
@@ -245,6 +251,12 @@ VISU_GaussPtsAct
   mySphereActor(vtkActor::New()),
   myCursorPyramid(VISU_CursorPyramid::New())
 {
+  myInteractorObserver->Delete();
+  myEventCallbackCommand->Delete();
+
+  myEventCallbackCommand->SetClientData(this); 
+  myEventCallbackCommand->SetCallback(VISU_GaussPtsAct::ProcessEvents);
+
   myTextMapper->Delete();
   myTextActor->Delete();
   myPSMapper->Delete();
@@ -356,6 +368,16 @@ VISU_GaussPtsAct
   Superclass::SetPipeLine(thePipeLine);
 }
 
+void
+VISU_GaussPtsAct
+::SetFactory(VISU::TActorFactory* theActorFactory)
+{ 
+  VISU_Actor::SetFactory(theActorFactory);
+  myUpdatePrs3dSignal.connect(boost::bind(&VISU::TActorFactory::UpdateFromActor,
+                                         theActorFactory,
+                                         _1));
+}
+
 VISU_GaussPointsPL*
 VISU_GaussPtsAct
 ::GetGaussPointsPL()
@@ -363,6 +385,75 @@ VISU_GaussPtsAct
   return myGaussPointsPL.GetPointer();
 }
 
+bool
+VISU_GaussPtsAct
+::ChangeMagnification()
+{
+  return myChangeMagnification;
+}
+
+
+//----------------------------------------------------------------------------
+void
+VISU_GaussPtsAct
+::SetInteractor(vtkRenderWindowInteractor* theInteractor)
+{
+  if(theInteractor == myInteractor)
+    return;
+
+  if(myInteractor)
+    myInteractor->RemoveObserver(myEventCallbackCommand.GetPointer());
+  
+  
+  if(theInteractor)
+    theInteractor->AddObserver(vtkCommand::CharEvent, 
+                              myEventCallbackCommand.GetPointer(), 
+                              0.0);
+  
+
+  Superclass::SetInteractor(theInteractor);
+
+  Modified();
+}
+
+void 
+VISU_GaussPtsAct
+::ProcessEvents(vtkObject* vtkNotUsed(theObject), 
+               unsigned long theEvent,
+               void* theClientData, 
+               void* vtkNotUsed(theCallData))
+{
+  if(vtkObject* anObject = reinterpret_cast<vtkObject*>(theClientData))
+    if(VISU_GaussPtsAct* self = dynamic_cast<VISU_GaussPtsAct*>(anObject))
+      self->OnInteractorEvent(theEvent);
+}
+
+void
+VISU_GaussPtsAct
+::OnInteractorEvent(unsigned long theEvent)
+{
+  switch(theEvent){
+  case vtkCommand::CharEvent: {
+    switch(myInteractor->GetKeyCode()) {
+    case 'm' :
+    case 'M' :
+      myChangeMagnification = true;
+      break;
+    case 'n' :
+    case 'N' :
+      myChangeMagnification = false;
+      break;
+    default:
+      return;
+    }
+    myUpdatePrs3dSignal(this);
+    return;
+  }
+    break;
+  }
+}
+
+
 //----------------------------------------------------------------
 bool
 VISU_GaussPtsAct
@@ -502,7 +593,7 @@ VISU_GaussPtsAct
   Selection_Mode aSelectionMode = theSelectionEvent->mySelectionMode;
   mySelectionMode = aSelectionMode;
   //
-  if(aSelectionMode==ActorSelection ){ //|| !theIsHighlight) {
+  if(aSelectionMode == ActorSelection ){
     myTextActor->SetVisibility(aTextVisibility);
     mySphereActor->SetVisibility(aSphereVisibility);
     mySphereActorSelected->SetVisibility(aSphereVisibilitySelected);
index 37c1d347798ab0143901935c3fdeababf24df0f8..d7f9e78e2d63266a3505141d5c6c113bc4d6aacb 100644 (file)
@@ -45,10 +45,15 @@ class vtkInteractorStyle;
 
 class VISU_CursorPyramid;
 class VISU_GPTextActor;
-//xxx 
+
 class vtkUnstructuredGrid;
 class vtkDataSetMapper;
-//xxx
+
+class vtkInteractorObserver;
+class vtkCallbackCommand;
+
+
+//----------------------------------------------------------------------------
 class VTKOCC_EXPORT VISU_GaussPtsAct : public VISU_ScalarMapAct
 {
  public:
@@ -58,13 +63,22 @@ class VTKOCC_EXPORT VISU_GaussPtsAct : public VISU_ScalarMapAct
   VISU_GaussPtsAct* 
   New();
 
+  //----------------------------------------------------------------------------
   virtual
   void
   SetPipeLine(VISU_PipeLine* thePipeLine) ;
   
+  virtual
+  void
+  SetFactory(VISU::TActorFactory* theActorFactory);
+
   VISU_GaussPointsPL*
   GetGaussPointsPL();
 
+  bool
+  ChangeMagnification();
+
+  //----------------------------------------------------------------------------
   virtual
   void
   AddToRender(vtkRenderer* theRenderer); 
@@ -73,6 +87,11 @@ class VTKOCC_EXPORT VISU_GaussPtsAct : public VISU_ScalarMapAct
   void
   RemoveFromRender(vtkRenderer* theRenderer);
 
+  virtual
+  void
+  SetInteractor(vtkRenderWindowInteractor* theInteractor);
+
+  //----------------------------------------------------------------------------
   virtual
   bool
   PreHighlight(SVTK_Selector* theSelector, 
@@ -86,6 +105,7 @@ class VTKOCC_EXPORT VISU_GaussPtsAct : public VISU_ScalarMapAct
            SVTK_SelectionEvent* theSelectionEvent,
            bool theIsHighlight);
 
+  //----------------------------------------------------------------------------
  protected:
   VISU_GaussPtsAct();
 
@@ -96,8 +116,25 @@ class VTKOCC_EXPORT VISU_GaussPtsAct : public VISU_ScalarMapAct
   void
   SetMapperInput(vtkDataSet* theDataSet);
 
-  vtkSmartPointer<VISU_OpenGLPointSpriteMapper> myPSMapper;
+  //----------------------------------------------------------------------------
+  vtkSmartPointer<vtkInteractorObserver> myInteractorObserver;
+  vtkSmartPointer<vtkCallbackCommand> myEventCallbackCommand;
 
+  // Main process VTK event method
+  static
+  void
+  ProcessEvents(vtkObject* theObject, 
+               unsigned long theEvent,
+               void* theClientData, 
+               void* theCallData);
+  void
+  OnInteractorEvent(unsigned long theEvent);
+
+  boost::signal1<void,VISU_Actor*> myUpdatePrs3dSignal;
+  bool myChangeMagnification;
+
+  //----------------------------------------------------------------------------
+  vtkSmartPointer<VISU_OpenGLPointSpriteMapper> myPSMapper;
   vtkSmartPointer<VISU_GaussPointsPL> myGaussPointsPL;
 
   vtkSmartPointer<vtkTextMapper> myTextMapper;