From: apo Date: Fri, 19 Aug 2005 05:52:11 +0000 (+0000) Subject: To use pure VTK way for slection event invocation X-Git-Tag: BR-D5-38-2003_D2005-12-09~37 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=192123ea457c47348c31284e2891fa6c3befe747;p=modules%2Fgui.git To use pure VTK way for slection event invocation --- diff --git a/src/SVTK/SVTK_InteractorStyle.cxx b/src/SVTK/SVTK_InteractorStyle.cxx index 52a26e8c0..0817bb6d7 100644 --- a/src/SVTK/SVTK_InteractorStyle.cxx +++ b/src/SVTK/SVTK_InteractorStyle.cxx @@ -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 } } } - diff --git a/src/SVTK/SVTK_InteractorStyle.h b/src/SVTK/SVTK_InteractorStyle.h index 8c3b00d05..9084db8d6 100644 --- a/src/SVTK/SVTK_InteractorStyle.h +++ b/src/SVTK/SVTK_InteractorStyle.h @@ -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 mySelector; SVTK_ViewWindow* myViewWindow; QWidget* myRenderWidget; diff --git a/src/SVTK/SVTK_Selector.cxx b/src/SVTK/SVTK_Selector.cxx index 96690603e..5ee296214 100644 --- a/src/SVTK/SVTK_Selector.cxx +++ b/src/SVTK/SVTK_Selector.cxx @@ -30,17 +30,28 @@ #include #include - #include "SALOME_Actor.h" #include "SVTK_ViewModel.h" #include "SVTK_ViewWindow.h" #include "SVTK_SelectorDef.h" + #include "utilities.h" +#include + +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) diff --git a/src/SVTK/SVTK_Selector.h b/src/SVTK/SVTK_Selector.h index 26150b4f4..cec7d3120 100644 --- a/src/SVTK/SVTK_Selector.h +++ b/src/SVTK/SVTK_Selector.h @@ -29,6 +29,8 @@ #ifndef SVTK_SELECTOR_H #define SVTK_SELECTOR_H +#include + #include #include @@ -37,10 +39,12 @@ 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; }; diff --git a/src/SVTK/SVTK_SelectorDef.h b/src/SVTK/SVTK_SelectorDef.h index 47f593e9a..5cff4c62c 100644 --- a/src/SVTK/SVTK_SelectorDef.h +++ b/src/SVTK/SVTK_SelectorDef.h @@ -133,6 +133,14 @@ public: void ClearIndex(); + virtual + void + StartPickCallback(); + + virtual + void + EndPickCallback(); + private: Selection_Mode mySelectionMode; diff --git a/src/SVTK/SVTK_View.cxx b/src/SVTK/SVTK_View.cxx index 40ee78471..f4658a99b 100644 --- a/src/SVTK/SVTK_View.cxx +++ b/src/SVTK/SVTK_View.cxx @@ -2,6 +2,7 @@ #include +#include #include #include #include @@ -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(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); } //---------------------------------------------------------------- diff --git a/src/SVTK/SVTK_View.h b/src/SVTK/SVTK_View.h index 5dbb76ef9..276793b62 100644 --- a/src/SVTK/SVTK_View.h +++ b/src/SVTK/SVTK_View.h @@ -11,6 +11,9 @@ #include "SALOME_InteractiveObject.hxx" +#include + +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 myEventCallbackCommand; + // Priority at which events are processed + float myPriority; + + vtkSmartPointer mySelector; SVTK_InteractorStyle* myInteractorStyle; double myCurScale; - - friend class SVTK_RenderWindowInteractor; }; #ifdef WIN32 diff --git a/src/SVTK/SVTK_ViewWindow.cxx b/src/SVTK/SVTK_ViewWindow.cxx index bdbe7b1fe..907010801 100755 --- a/src/SVTK/SVTK_ViewWindow.cxx +++ b/src/SVTK/SVTK_ViewWindow.cxx @@ -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(); } diff --git a/src/SVTK/SVTK_ViewWindow.h b/src/SVTK/SVTK_ViewWindow.h index 461a34e43..ff2ebada8 100755 --- a/src/SVTK/SVTK_ViewWindow.h +++ b/src/SVTK/SVTK_ViewWindow.h @@ -13,6 +13,8 @@ #include "SALOME_InteractiveObject.hxx" +#include + 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