]> SALOME platform Git repositories - modules/gui.git/commitdiff
Salome HOME
To use pure VTK way for slection event invocation
authorapo <apo@opencascade.com>
Fri, 19 Aug 2005 05:52:11 +0000 (05:52 +0000)
committerapo <apo@opencascade.com>
Fri, 19 Aug 2005 05:52:11 +0000 (05:52 +0000)
src/SVTK/SVTK_InteractorStyle.cxx
src/SVTK/SVTK_InteractorStyle.h
src/SVTK/SVTK_Selector.cxx
src/SVTK/SVTK_Selector.h
src/SVTK/SVTK_SelectorDef.h
src/SVTK/SVTK_View.cxx
src/SVTK/SVTK_View.h
src/SVTK/SVTK_ViewWindow.cxx
src/SVTK/SVTK_ViewWindow.h

index 52a26e8c0f1d322a9cd6b9a1b1fdbc7ffa539997..0817bb6d7992145b805f9e88b1cb1108c6d668a1 100644 (file)
@@ -128,7 +128,7 @@ SVTK_Selector*
 SVTK_InteractorStyle
 ::GetSelector() 
 {
-  return myViewWindow->GetSelector();
+  return mySelector.GetPointer();
 }
 
 //----------------------------------------------------------------------------
@@ -154,6 +154,7 @@ SVTK_InteractorStyle
   aSelectionEvent.myY = h - y - 1;
   aSelectionEvent.myIsCtrl = Interactor->GetControlKey();
   aSelectionEvent.myIsShift = Interactor->GetShiftKey();
+  aSelectionEvent.mySelectionMode = GetSelector()->SelectionMode();
 
   return aSelectionEvent;
 }
@@ -166,6 +167,14 @@ SVTK_InteractorStyle
   myViewWindow = theViewWindow;
 }
 
+//----------------------------------------------------------------------------
+void
+SVTK_InteractorStyle
+::SetSelector( SVTK_Selector* theSelector ) 
+{ 
+  mySelector = theSelector; 
+}
+
 //----------------------------------------------------------------------------
 void
 SVTK_InteractorStyle
@@ -200,7 +209,7 @@ SVTK_InteractorStyle
   cam->Elevation(ryf);
   cam->OrthogonalizeViewUp();
   ::ResetCameraClippingRange(this->CurrentRenderer); 
-  this->Interactor->CreateTimer(VTKI_TIMER_FIRST);
+  this->Render();
 }
 
 //----------------------------------------------------------------------------
@@ -209,7 +218,7 @@ SVTK_InteractorStyle
 ::PanXY(int x, int y, int oldX, int oldY)
 {
   TranslateView(x, y, oldX, oldY);   
-  this->Interactor->CreateTimer(VTKI_TIMER_FIRST);
+  this->Render();
 }
 
 
@@ -233,7 +242,7 @@ SVTK_InteractorStyle
     ::ResetCameraClippingRange(this->CurrentRenderer);
   }
 
-  this->Interactor->CreateTimer(VTKI_TIMER_FIRST);
+  this->Render();
 }
 
 //----------------------------------------------------------------------------
@@ -260,7 +269,7 @@ SVTK_InteractorStyle
   cam->Roll(newAngle - oldAngle);
   cam->OrthogonalizeViewUp();
       
-  this->Interactor->CreateTimer(VTKI_TIMER_FIRST);
+  this->Render();
 }
 
 
@@ -736,7 +745,7 @@ SVTK_InteractorStyle
 
   if (myViewWindow) myViewWindow->onFitAll();
 
-  this->Interactor->CreateTimer(VTKI_TIMER_FIRST);
+  this->Render();
   
   qApp->installEventFilter(this);
 }
@@ -774,7 +783,7 @@ SVTK_InteractorStyle
     ::ResetCameraClippingRange(this->CurrentRenderer);
   }
   
-  this->Interactor->CreateTimer(VTKI_TIMER_FIRST);
+  this->Render();
 }
 
 
@@ -893,7 +902,7 @@ SVTK_InteractorStyle
   // VSV: LOD actor activisation
   //  rwi->GetRenderWindow()->SetDesiredUpdateRate(rwi->GetStillUpdateRate());
 
-  Selection_Mode aSelectionMode = myViewWindow->SelectionMode();
+  Selection_Mode aSelectionMode = GetSelector()->SelectionMode();
 
   switch (State) {
     case VTK_INTERACTOR_STYLE_CAMERA_SELECT:
@@ -940,6 +949,7 @@ SVTK_InteractorStyle
         } else {
           //processing rectangle selection
          Interactor->StartPickCallback();
+         GetSelector()->StartPickCallback();
 
          if (!myShiftState) {
            this->PropPicked = 0;
@@ -977,7 +987,7 @@ SVTK_InteractorStyle
          }
        }
        Interactor->EndPickCallback();
-       myViewWindow->onSelectionChanged();
+       GetSelector()->EndPickCallback();
       } 
     } 
     break;
@@ -997,7 +1007,7 @@ SVTK_InteractorStyle
     break;
   }
 
-  this->Interactor->CreateTimer(VTKI_TIMER_FIRST);
+  this->Render();
 }
 
 
@@ -1071,9 +1081,9 @@ SVTK_InteractorStyle
 
   this->FindPokedRenderer(x,y);
   Interactor->StartPickCallback();
+  GetSelector()->StartPickCallback();
 
   SVTK_SelectionEvent aSelectionEvent = GetSelectionEvent();
-  aSelectionEvent.mySelectionMode = myViewWindow->SelectionMode();
   aSelectionEvent.myX = x;
   aSelectionEvent.myY = y;
 
@@ -1088,9 +1098,10 @@ SVTK_InteractorStyle
   }
   
   Interactor->EndPickCallback();
+  GetSelector()->EndPickCallback();
 
   if(anIsChanged)
-    this->Interactor->CreateTimer(VTKI_TIMER_FIRST);
+    this->Render();
 }
 
 // called on finsh GlobalPan operation 
@@ -1115,7 +1126,7 @@ SVTK_InteractorStyle
   cam->SetParallelScale(myScale);
   ::ResetCameraClippingRange(this->CurrentRenderer);
 
-  this->Interactor->CreateTimer(VTKI_TIMER_FIRST);
+  this->Render();
 }
 
 
@@ -1253,6 +1264,14 @@ SVTK_InteractorStyle
   this->Interactor->Render();
 }
 
+//----------------------------------------------------------------------------
+void
+SVTK_InteractorStyle
+::Render() 
+{
+  this->Interactor->CreateTimer(VTKI_TIMER_FIRST);
+}
+
 //----------------------------------------------------------------------------
 void
 SVTK_InteractorStyle
@@ -1357,4 +1376,3 @@ SVTK_InteractorStyle
     }
   }
 }
-
index 8c3b00d052256a50b9db981e1a8ab959d2c057ba..9084db8d67a36ffb74c10c37b2db3e26cfa8ad2e 100644 (file)
@@ -81,6 +81,10 @@ class SVTK_EXPORT SVTK_InteractorStyle :
   vtkTypeMacro(SVTK_InteractorStyle, vtkInteractorStyle);
 
   void setViewWindow(SVTK_ViewWindow* theViewWindow);
+
+  void SetSelector( SVTK_Selector* theSelector );
+  SVTK_Selector* GetSelector();
+
   void SetRenderWidget(QWidget* theRenderWidget);
 
   virtual int GetState();
@@ -90,6 +94,8 @@ class SVTK_EXPORT SVTK_InteractorStyle :
   // redefined in order to add an observer (callback) for custorm event (space mouse event)
   virtual void SetInteractor( vtkRenderWindowInteractor* );
 
+  virtual void Render();
+
   // redefined in order to cach rendering
   virtual void OnTimer();
 
@@ -143,8 +149,6 @@ class SVTK_EXPORT SVTK_InteractorStyle :
   SVTK_InteractorStyle(const SVTK_InteractorStyle&) {};
   void operator=(const SVTK_InteractorStyle&) {};
 
-  SVTK_Selector* GetSelector();
-
   void RotateXY(int dx, int dy);
   void PanXY(int x, int y, int oldX, int oldY);
   void DollyXY(int dx, int dy);
@@ -202,6 +206,7 @@ class SVTK_EXPORT SVTK_InteractorStyle :
   bool                      myShiftState;
   int                       ForcedState;
   
+  vtkSmartPointer<SVTK_Selector> mySelector;
   SVTK_ViewWindow*          myViewWindow;
   QWidget*                  myRenderWidget;
 
index 96690603ea100e6a8a34cfb2c37dca85171d9967..5ee296214a82a1484707ee0b3bb7844b0bd13296 100644 (file)
 #include <TColStd_MapIteratorOfMapOfInteger.hxx>
 #include <TColStd_IndexedMapOfInteger.hxx>
 
-
 #include "SALOME_Actor.h"
 #include "SVTK_ViewModel.h"
 #include "SVTK_ViewWindow.h"
 
 #include "SVTK_SelectorDef.h"
+
 #include "utilities.h"
 
+#include <vtkCallbackCommand.h>
+
+SVTK_Selector* 
+SVTK_Selector
+::New()
+{
+  return new SVTK_SelectorDef();
+}
+
+//----------------------------------------------------------------------------
 SVTK_SelectorDef
 ::SVTK_SelectorDef()
 {
+  mySelectionMode = ActorSelection;
 }
 
 SVTK_SelectorDef
@@ -48,6 +59,23 @@ SVTK_SelectorDef
 {
 }
 
+//----------------------------------------------------------------------------
+void 
+SVTK_SelectorDef
+::StartPickCallback()
+{
+  this->InvokeEvent(vtkCommand::StartPickEvent,NULL);
+}
+
+//----------------------------------------------------------------------------
+void 
+SVTK_SelectorDef
+::EndPickCallback()
+{
+  this->InvokeEvent(vtkCommand::EndPickEvent,NULL);
+}
+
+//----------------------------------------------------------------------------
 void 
 SVTK_SelectorDef
 ::SetSelectionMode(Selection_Mode theMode)
index 26150b4f4df3d5c9a9e1da6b0b32e8ee4629b52f..cec7d3120845e908a614ac78384946eca081609a 100644 (file)
@@ -29,6 +29,8 @@
 #ifndef SVTK_SELECTOR_H
 #define SVTK_SELECTOR_H
 
+#include <vtkObject.h>
+
 #include <TColStd_MapOfInteger.hxx>
 #include <TColStd_IndexedMapOfInteger.hxx>
 
 
 class SALOME_Actor;
 
-class SVTK_Selector
+class SVTK_Selector: public vtkObject
 {
 public:
-  virtual ~SVTK_Selector() {};
+  static SVTK_Selector* New();
+  
+  vtkTypeMacro(SVTK_Selector,vtkObject);
 
   virtual
   void 
@@ -125,6 +129,14 @@ public:
   virtual
   void 
   ClearIndex() = 0;
+
+  virtual
+  void 
+  StartPickCallback() = 0;
+
+  virtual
+  void 
+  EndPickCallback() = 0;
 };
 
 
index 47f593e9a3b438ee3bd533b4affe93f653d34846..5cff4c62cfcb17c4e6cedb72f2c35abb99ba81b3 100644 (file)
@@ -133,6 +133,14 @@ public:
   void 
   ClearIndex();
 
+  virtual
+  void 
+  StartPickCallback();
+
+  virtual
+  void 
+  EndPickCallback();
+
 private:
   Selection_Mode mySelectionMode;
 
index 40ee784716453cb7fb06e689e132cebb33f4ea89..f4658a99b3be3840b75b0b1064e82d42d98399d5 100644 (file)
@@ -2,6 +2,7 @@
 
 #include <qapplication.h>
 
+#include <vtkCallbackCommand.h>
 #include <vtkTextProperty.h>
 #include <vtkActorCollection.h>
 #include <vtkRenderer.h>
@@ -38,6 +39,16 @@ SVTK_View
 ::SVTK_View( QWidget* parent, const char* name ) :
   SVTK_RenderWindowInteractor( parent, name )
 {
+  mySelector = SVTK_Selector::New();
+  mySelector->Delete();
+
+  myEventCallbackCommand = vtkCallbackCommand::New();
+  myEventCallbackCommand->Delete();
+
+  myEventCallbackCommand->SetClientData(this); 
+  myPriority = 0.0;
+
+  myEventCallbackCommand->SetCallback(SVTK_View::ProcessEvents);
 }
 
 //----------------------------------------------------------------------------
@@ -47,6 +58,13 @@ SVTK_View
 }
 
 //----------------------------------------------------------------------------
+SVTK_InteractorStyle* 
+SVTK_View
+::GetInteractorStyle() 
+{ 
+  return myInteractorStyle; 
+}
+
 void
 SVTK_View
 ::SetInteractorStyle( SVTK_InteractorStyle* theStyle )
@@ -55,6 +73,46 @@ SVTK_View
   getInteractor()->SetInteractorStyle( theStyle ); 
 }
 
+//----------------------------------------------------------------------------
+SVTK_Selector* 
+SVTK_View
+::GetSelector() 
+{ 
+  return mySelector.GetPointer(); 
+}
+
+void
+SVTK_View
+::SetSelector( SVTK_Selector* theSelector )
+{ 
+  if(mySelector.GetPointer())
+    mySelector->RemoveObserver(myEventCallbackCommand.GetPointer());
+
+  mySelector = theSelector; 
+
+  if(mySelector.GetPointer())
+    mySelector->AddObserver(vtkCommand::EndPickEvent, 
+                           myEventCallbackCommand.GetPointer(), 
+                           myPriority);
+}
+
+//----------------------------------------------------------------------------
+void 
+SVTK_View
+::ProcessEvents(vtkObject* vtkNotUsed(theObject), 
+               unsigned long theEvent,
+               void* theClientData, 
+               void* vtkNotUsed(theCallData))
+{
+  SVTK_View* self = reinterpret_cast<SVTK_View*>(theClientData);
+
+  switch(theEvent){
+  case vtkCommand::EndPickEvent:
+    self->onEmitSelectionChanged();
+    break;
+  }
+}
+
 //----------------------------------------------------------------------------
 void
 SVTK_View
@@ -121,7 +179,13 @@ SVTK_View
   for(; anIter.More(); anIter.Next()){
     highlight(anIter.Value(),true,!anIter.More());
   }
+}
 
+//----------------------------------------------------------------
+void
+SVTK_View
+::onEmitSelectionChanged()
+{
   emit selectionChanged();
 }
 
@@ -131,8 +195,6 @@ SVTK_View
 ::SetSelectionMode(Selection_Mode theMode)
 {
   mySelector->SetSelectionMode(theMode);
-
-  //myRWInteractor->SetSelectionMode(theMode);
 }
 
 //----------------------------------------------------------------
index 5dbb76ef9046f6ad79f0dbff05d048b961c1c4b0..276793b620f9d3750ce68111c317fbacf84e1251 100644 (file)
@@ -11,6 +11,9 @@
 
 #include "SALOME_InteractiveObject.hxx"
 
+#include <vtkSmartPointer.h>
+
+class vtkCallbackCommand;
 class VTKViewer_Actor;
 
 class SVTK_Viewer;
@@ -21,18 +24,26 @@ class SVTK_InteractorStyle;
 
 class SVTK_EXPORT SVTK_View : public SVTK_RenderWindowInteractor
 {
-  Q_OBJECT
+  Q_OBJECT;
 
 public:
   SVTK_View( QWidget*, const char* );
   virtual ~SVTK_View();
   
-  SVTK_Selector* GetSelector() { return mySelector; }
-  void SetSelector( SVTK_Selector* theSelector ) { mySelector = theSelector; }
-
-  SVTK_InteractorStyle* GetInteractorStyle() { return myInteractorStyle; }
+  SVTK_InteractorStyle* GetInteractorStyle();
   void SetInteractorStyle( SVTK_InteractorStyle* );
 
+  SVTK_Selector* GetSelector();
+  void SetSelector( SVTK_Selector* theSelector );
+
+  // Main process VTK event method
+  static
+  void
+  ProcessEvents(vtkObject* theObject, 
+               unsigned long theEvent,
+               void* theClientData, 
+               void* theCallData);
+
   Selection_Mode SelectionMode() const;
   void SetSelectionMode( Selection_Mode );
 
@@ -70,6 +81,7 @@ public:
 
 public slots:
   void onSelectionChanged();
+  void onEmitSelectionChanged();
 
 signals:
   void selectionChanged();
@@ -108,13 +120,16 @@ private:
 
 private:  
   SVTK_Viewer* myModel;
-  SVTK_Selector* mySelector;
 
+  // Used to process VTK events
+  vtkSmartPointer<vtkCallbackCommand> myEventCallbackCommand;
+  // Priority at which events are processed
+  float myPriority;
+
+  vtkSmartPointer<SVTK_Selector> mySelector;
   SVTK_InteractorStyle* myInteractorStyle;
 
   double myCurScale;
-
-  friend class SVTK_RenderWindowInteractor;
 };
 
 #ifdef WIN32
index bdbe7b1fee2e0316d0b354d171c82d540609e5ae..907010801d5ffa120d61e39f719568118db8a259 100755 (executable)
@@ -32,7 +32,7 @@
 
 #include "SALOME_ListIteratorOfListIO.hxx"
 
-#include "SVTK_SelectorDef.h"
+#include "SVTK_Selector.h"
 
 #include "VTKViewer_Algorithm.h"
 #include "SVTK_Functor.h"
@@ -43,9 +43,6 @@ SVTK_ViewWindow
                   SVTK_ViewModelBase* theModel)
   : SUIT_ViewWindow( theDesktop )
 {
-  mySelector = new SVTK_SelectorDef();
-  connect(this,SIGNAL(selectionChanged()),theModel,SLOT(onSelectionChanged()));
-
   QWidget* aCentralWidget = new QWidget( this );
   setCentralWidget( aCentralWidget );
   QBoxLayout* aLayout = new QVBoxLayout( aCentralWidget );
@@ -59,14 +56,17 @@ SVTK_ViewWindow
   bottomView->getInteractor()->SetInteractorStyle( myInteractorStyle ); 
   bottomView->Initialize();
   */
+
   myInteractorStyle = SVTK_InteractorStyle::New();
   myInteractorStyle->SetRenderWidget( myView );
   myInteractorStyle->setViewWindow( this );
+  myInteractorStyle->SetSelector( myView->GetSelector() );
 
   myView->SetInteractorStyle( myInteractorStyle );
-  myView->SetSelector( mySelector );
   myView->Initialize();
 
+  connect(myView,SIGNAL(selectionChanged()),theModel,SLOT(onSelectionChanged()));
+
   //merge with V2_2_0_VISU_improvements:myInteractorStyle->setTriedron( myTrihedron );
   myInteractorStyle->FindPokedRenderer( 0, 0 );
 
@@ -103,6 +103,13 @@ SVTK_ViewWindow
   return myView->getRenderer();
 }
 
+//----------------------------------------------------------------------------
+SVTK_Selector* 
+SVTK_ViewWindow
+::GetSelector() { 
+  return myView->GetSelector(); 
+}
+
 //----------------------------------------------------------------------------
 void
 SVTK_ViewWindow
@@ -172,8 +179,6 @@ void
 SVTK_ViewWindow
 ::onSelectionChanged()
 {
-  //cout << "SVTK_ViewWindow::onSelectionChanged" << endl;
-  myView->onSelectionChanged();
   emit selectionChanged();
 }
 
index 461a34e433fcad8fe45b3b16bd9fb0f319b6b8d1..ff2ebada8ae82ec4a0b461b9f47c0ee8dbb1a40b 100755 (executable)
@@ -13,6 +13,8 @@
 
 #include "SALOME_InteractiveObject.hxx"
 
+#include <vtkSmartPointer.h>
+
 class SUIT_Desktop;
 
 class VTKViewer_Actor;
@@ -40,7 +42,7 @@ public:
   QColor backgroundColor() const;
 
   vtkRenderer* getRenderer();
-  SVTK_Selector* GetSelector() {return mySelector;}
+  SVTK_Selector* GetSelector();
 
   SVTK_View* getView() { return myView; }
   SVTK_View* getRenderWindow() { return myView; }
@@ -130,9 +132,6 @@ public slots:
   void onRotateUp();
   void onRotateDown();
 
-protected:
-  QImage dumpView();
-
 protected slots:
   void onKeyPressed(QKeyEvent* event);
   void onKeyReleased(QKeyEvent* event);
@@ -141,21 +140,11 @@ protected slots:
   void onMouseReleased(QMouseEvent* event);
   void onMouseMoving(QMouseEvent* event);
 
-private:
-  void InitialSetup();
-  //void InsertActor( VTKViewer_Actor* theActor,
-  //                  bool theMoveInternalActors = false );
-  //void MoveActor( VTKViewer_Actor* theActor );
-
-private:  
-  SVTK_Selector* mySelector;
+protected:
+  QImage dumpView();
 
   SVTK_View* myView;
   SVTK_InteractorStyle* myInteractorStyle;
-
-  double myCurScale;
-
-  friend class SVTK_RenderWindowInteractor;
 };
 
 #ifdef WIN32