From: apo Date: Tue, 20 Sep 2005 09:31:04 +0000 (+0000) Subject: 1. Now SelectionEvent wil pass to PreHighlight/Highlight functionality by pointer... X-Git-Tag: BR-D5-38-2003_D2005-12-10~39 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=44593a69830b3f44f2b26b7580f112e1e60c822c;p=modules%2Fgui.git 1. Now SelectionEvent wil pass to PreHighlight/Highlight functionality by pointer, not by value. 2. To fix regression with PreHighlight/Highlight functionality --- diff --git a/src/SVTK/SALOME_Actor.cxx b/src/SVTK/SALOME_Actor.cxx index 67f033ed1..836065fc8 100644 --- a/src/SVTK/SALOME_Actor.cxx +++ b/src/SVTK/SALOME_Actor.cxx @@ -733,21 +733,21 @@ bool SALOME_Actor ::PreHighlight(SVTK_Selector* theSelector, vtkInteractorStyle *theInteractorStyle, - const SVTK_SelectionEvent& theSelectionEvent, + SVTK_SelectionEvent* theSelectionEvent, bool theIsHighlight) { vtkRenderer *aRenderer = theInteractorStyle->GetCurrentRenderer(); // myPreHighlightActor->SetVisibility( false ); - bool anIsSelectionModeChanged = (theSelectionEvent.mySelectionMode != mySelectionMode); + bool anIsSelectionModeChanged = (theSelectionEvent->mySelectionMode != mySelectionMode); if(!anIsSelectionModeChanged && mySelectionMode == ActorSelection) return false; - mySelectionMode = theSelectionEvent.mySelectionMode; + mySelectionMode = theSelectionEvent->mySelectionMode; - float x = theSelectionEvent.myX; - float y = theSelectionEvent.myY; + float x = theSelectionEvent->myX; + float y = theSelectionEvent->myY; float z = 0.0; @@ -857,20 +857,20 @@ bool SALOME_Actor ::Highlight(SVTK_Selector* theSelector, vtkInteractorStyle *theInteractorStyle, - const SVTK_SelectionEvent& theSelectionEvent, + SVTK_SelectionEvent* theSelectionEvent, bool theIsHighlight) { vtkRenderer *aRenderer = theInteractorStyle->GetCurrentRenderer(); // - int aSelectionMode = theSelectionEvent.mySelectionMode; - float x1 = theSelectionEvent.myX; - float y1 = theSelectionEvent.myY; + int aSelectionMode = theSelectionEvent->mySelectionMode; + float x1 = theSelectionEvent->myX; + float y1 = theSelectionEvent->myY; float z1 = 0.0; - float x2 = theSelectionEvent.myLastX; - float y2 = theSelectionEvent.myLastY; + float x2 = theSelectionEvent->myLastX; + float y2 = theSelectionEvent->myLastY; float z2 = 0.0; - bool isShift = theSelectionEvent.myIsShift; - bool isRectangle = theSelectionEvent.myIsRectangle; + bool isShift = theSelectionEvent->myIsShift; + bool isRectangle = theSelectionEvent->myIsRectangle; if( !isRectangle ) { diff --git a/src/SVTK/SALOME_Actor.h b/src/SVTK/SALOME_Actor.h index b5f3443a5..bfe943b62 100644 --- a/src/SVTK/SALOME_Actor.h +++ b/src/SVTK/SALOME_Actor.h @@ -303,14 +303,14 @@ class SVTK_EXPORT SALOME_Actor : public VTKViewer_Actor bool PreHighlight(SVTK_Selector* theSelector, vtkInteractorStyle* theInteractorStyle, - const SVTK_SelectionEvent& theSelectionEvent, + SVTK_SelectionEvent* theSelectionEvent, bool theIsHighlight); virtual bool Highlight(SVTK_Selector* theSelector, vtkInteractorStyle* theInteractorStyle, - const SVTK_SelectionEvent& theSelectionEvent, + SVTK_SelectionEvent* theSelectionEvent, bool theIsHighlight); virtual diff --git a/src/SVTK/SVTK_InteractorStyle.cxx b/src/SVTK/SVTK_InteractorStyle.cxx index 4f7762d01..761cfd3dd 100644 --- a/src/SVTK/SVTK_InteractorStyle.cxx +++ b/src/SVTK/SVTK_InteractorStyle.cxx @@ -95,25 +95,26 @@ vtkStandardNewMacro(SVTK_InteractorStyle); //---------------------------------------------------------------------------- SVTK_InteractorStyle -::SVTK_InteractorStyle() +::SVTK_InteractorStyle(): + mySelectionEvent(new SVTK_SelectionEvent()), + myRectPicker(VTKViewer_RectPicker::New()), + myPicker(vtkPicker::New()) { + myRectPicker->Delete(); + myPicker->Delete(); + if(MYDEBUG) INFOS("SVTK_InteractorStyle() - "<MotionFactor = 10.0; this->State = VTK_INTERACTOR_STYLE_CAMERA_NONE; this->RadianToDegree = 180.0 / vtkMath::Pi(); this->ForcedState = VTK_INTERACTOR_STYLE_CAMERA_NONE; + loadCursors(); // set custom event handling function (to handle 3d space mouse events) EventCallbackCommand->SetCallback( SVTK_InteractorStyle::ProcessEvents ); - myPicker = vtkPicker::New(); - myPicker->Delete(); - - myRectPicker = VTKViewer_RectPicker::New(); - myRectPicker->Delete(); - // set default values of properties. user may edit them in preferences. mySpeedIncrement = 10; mySpaceMouseBtns[0] = 1; @@ -154,41 +155,41 @@ SVTK_InteractorStyle } //---------------------------------------------------------------------------- -SVTK_SelectionEvent +SVTK_SelectionEvent* SVTK_InteractorStyle ::GetSelectionEvent() { - SVTK_SelectionEvent aSelectionEvent; + mySelectionEvent->mySelectionMode = GetSelector()->SelectionMode(); - int x, y; - GetEventPosition( this->Interactor, x, y ); + mySelectionEvent->myIsCtrl = Interactor->GetControlKey(); + mySelectionEvent->myIsShift = Interactor->GetShiftKey(); + + mySelectionEvent->myLastX = mySelectionEvent->myX; + mySelectionEvent->myLastY = mySelectionEvent->myY; - aSelectionEvent.myX = x; - aSelectionEvent.myY = y; - aSelectionEvent.myIsCtrl = Interactor->GetControlKey(); - aSelectionEvent.myIsShift = Interactor->GetShiftKey(); - aSelectionEvent.mySelectionMode = GetSelector()->SelectionMode(); + GetEventPosition( this->Interactor, mySelectionEvent->myX, mySelectionEvent->myY ); - return aSelectionEvent; + return mySelectionEvent.get(); } + //---------------------------------------------------------------------------- -SVTK_SelectionEvent +SVTK_SelectionEvent* SVTK_InteractorStyle ::GetSelectionEventFlipY() { - SVTK_SelectionEvent aSelectionEvent; - int x, y; + mySelectionEvent->mySelectionMode = GetSelector()->SelectionMode(); + + mySelectionEvent->myIsCtrl = Interactor->GetControlKey(); + mySelectionEvent->myIsShift = Interactor->GetShiftKey(); - //GetEventPosition( this->Interactor, x, y ); - Interactor->GetEventPosition(x, y); - aSelectionEvent.myX = x; - aSelectionEvent.myY = y; - aSelectionEvent.myIsCtrl = Interactor->GetControlKey(); - aSelectionEvent.myIsShift = Interactor->GetShiftKey(); - aSelectionEvent.mySelectionMode = GetSelector()->SelectionMode(); + mySelectionEvent->myLastX = mySelectionEvent->myX; + mySelectionEvent->myLastY = mySelectionEvent->myY; - return aSelectionEvent; + this->Interactor->GetEventPosition(mySelectionEvent->myX, mySelectionEvent->myY); + + return mySelectionEvent.get(); } + //---------------------------------------------------------------------------- void SVTK_InteractorStyle @@ -874,27 +875,27 @@ SVTK_InteractorStyle // VSV: LOD actor activisation // rwi->GetRenderWindow()->SetDesiredUpdateRate(rwi->GetStillUpdateRate()); - Selection_Mode aSelectionMode = GetSelector()->SelectionMode(); + SVTK_SelectionEvent* aSelectionEvent = GetSelectionEventFlipY(); switch (State) { case VTK_INTERACTOR_STYLE_CAMERA_SELECT: case VTK_INTERACTOR_STYLE_CAMERA_FIT: { - QPainter p(GetRenderWidget()); - p.setPen(Qt::lightGray); - p.setRasterOp(Qt::XorROP); - QRect rect(myPoint, myOtherPoint); - p.drawRect(rect); - rect = rect.normalize(); + QPainter aPainter(GetRenderWidget()); + aPainter.setPen(Qt::lightGray); + aPainter.setRasterOp(Qt::XorROP); + QRect aRect(myPoint, myOtherPoint); + aPainter.drawRect(aRect); + aRect = aRect.normalize(); + if (State == VTK_INTERACTOR_STYLE_CAMERA_FIT) { // making fit rect opeation int w, h; Interactor->GetSize(w, h); - int x1, y1, x2, y2; - x1 = rect.left(); - y1 = h - rect.top() - 1; - x2 = rect.right(); - y2 = h - rect.bottom() - 1; + int x1 = aRect.left(); + int y1 = h - aRect.top() - 1; + int x2 = aRect.right(); + int y2 = h - aRect.bottom() - 1; fitRect(x1, y1, x2, y2); } else { @@ -902,19 +903,16 @@ SVTK_InteractorStyle VTK::THighlight(false)); if (myPoint == myOtherPoint) { // process point selection - int w, h, x, y; - Interactor->GetSize(w, h); - x = myPoint.x(); - y = h - myPoint.y() - 1; - - this->FindPokedRenderer(x, y); + this->FindPokedRenderer(aSelectionEvent->myX, aSelectionEvent->myY); Interactor->StartPickCallback(); - myPicker->Pick(x, y, 0.0, GetCurrentRenderer()); + myPicker->Pick(aSelectionEvent->myX, + aSelectionEvent->myY, + 0.0, + GetCurrentRenderer()); + if(SALOME_Actor* aSActor = SALOME_Actor::SafeDownCast(myPicker->GetActor())){ - SVTK_SelectionEvent aSelectionEvent = GetSelectionEventFlipY(); - aSelectionEvent.mySelectionMode = aSelectionMode; - aSelectionEvent.myIsRectangle = false; + aSelectionEvent->myIsRectangle = false; aSActor->Highlight( GetSelector(), this, aSelectionEvent, true ); } else{ @@ -925,32 +923,20 @@ SVTK_InteractorStyle //processing rectangle selection Interactor->StartPickCallback(); GetSelector()->StartPickCallback(); + aSelectionEvent->myIsRectangle = true; - if (!myShiftState) { - this->PropPicked = 0; - this->HighlightProp( NULL ); + if(!myShiftState) GetSelector()->ClearIObjects(); - } - - // Compute bounds - // vtkCamera *cam = this->CurrentRenderer->GetActiveCamera(); - QRect rect(myPoint, myOtherPoint); - rect = rect.normalize(); - int w, h; - Interactor->GetSize(w, h); - int x1, y1, x2, y2; - x1 = rect.left(); - y1 = h - rect.top() - 1; - x2 = rect.right(); - y2 = h - rect.bottom() - 1; myRectPicker->SetTolerance(0.001); - myRectPicker->Pick(x1, y1, 0.0, x2, y2, 0.0, GetCurrentRenderer()); - SVTK_SelectionEvent aSelectionEvent = GetSelectionEventFlipY(); - aSelectionEvent.mySelectionMode = aSelectionMode; - aSelectionEvent.myIsRectangle = true; - aSelectionEvent.myLastX = x1; - aSelectionEvent.myLastY = y1; + myRectPicker->Pick(aSelectionEvent->myLastX, + aSelectionEvent->myLastY, + 0.0, + aSelectionEvent->myX, + aSelectionEvent->myY, + 0.0, + GetCurrentRenderer()); + vtkActorCollection* aListActors = myRectPicker->GetActors(); aListActors->InitTraversal(); while(vtkActor* aActor = aListActors->GetNextActor()){ @@ -1048,20 +1034,17 @@ SVTK_InteractorStyle ::onCursorMove(QPoint mousePos) { // processing highlighting - int w, h, x, y; - Interactor->GetSize(w, h); - x = mousePos.x(); y = h - mousePos.y() - 1; - - this->FindPokedRenderer(x,y); - - SVTK_SelectionEvent aSelectionEvent = GetSelectionEvent(); - aSelectionEvent.myX = x; - aSelectionEvent.myY = y; + SVTK_SelectionEvent* aSelectionEvent = GetSelectionEventFlipY(); + this->FindPokedRenderer(aSelectionEvent->myX,aSelectionEvent->myY); bool anIsChanged = false; SALOME_Actor* aLastActor = SALOME_Actor::SafeDownCast(myPicker->GetActor()); - myPicker->Pick(x, y, 0.0, GetCurrentRenderer()); + myPicker->Pick(aSelectionEvent->myX, + aSelectionEvent->myY, + 0.0, + GetCurrentRenderer()); + if(SALOME_Actor* anActor = SALOME_Actor::SafeDownCast(myPicker->GetActor())){ anIsChanged |= anActor->PreHighlight( GetSelector(), this, aSelectionEvent, true ); if(aLastActor && aLastActor != anActor) { diff --git a/src/SVTK/SVTK_InteractorStyle.h b/src/SVTK/SVTK_InteractorStyle.h index 6f98dd48c..8355df58e 100644 --- a/src/SVTK/SVTK_InteractorStyle.h +++ b/src/SVTK/SVTK_InteractorStyle.h @@ -33,6 +33,8 @@ #include "SVTK_SelectionEvent.h" +#include + #include #include @@ -67,27 +69,66 @@ class SVTK_EXPORT SVTK_InteractorStyle: public vtkInteractorStyle static SVTK_InteractorStyle *New(); vtkTypeMacro(SVTK_InteractorStyle, vtkInteractorStyle); - virtual int GetState(); + virtual + int + GetState(); + + typedef boost::shared_ptr PSelectionEvent; + + virtual + SVTK_SelectionEvent* + GetSelectionEvent(); + + virtual + SVTK_SelectionEvent* + GetSelectionEventFlipY(); - SVTK_SelectionEvent GetSelectionEvent(); - SVTK_SelectionEvent GetSelectionEventFlipY(); // redefined in order to add an observer (callback) for custorm event (space mouse event) - virtual void SetInteractor( vtkRenderWindowInteractor* ); + virtual + void + SetInteractor( vtkRenderWindowInteractor* ); - virtual void Render(); + virtual + void + Render(); // redefined in order to cach rendering - virtual void OnTimer(); + virtual + void + OnTimer(); // VTK events - virtual void OnConfigure(); - virtual void OnMouseMove(); - virtual void OnLeftButtonDown(); - virtual void OnLeftButtonUp(); - virtual void OnMiddleButtonDown(); - virtual void OnMiddleButtonUp(); - virtual void OnRightButtonDown(); - virtual void OnRightButtonUp(); + virtual + void + OnConfigure(); + + virtual + void + OnMouseMove(); + + virtual + void + OnLeftButtonDown(); + + virtual + void + OnLeftButtonUp(); + + virtual + void + OnMiddleButtonDown(); + + virtual + void + OnMiddleButtonUp(); + + virtual + void + OnRightButtonDown(); + + virtual + void + OnRightButtonUp(); protected: SVTK_InteractorStyle(); @@ -179,9 +220,11 @@ class SVTK_EXPORT SVTK_InteractorStyle: public vtkInteractorStyle // [4] Increase Gauss Point Magnification // [5] Dominant Combined Switch - QWidget* myRenderWidget; + QWidget* myRenderWidget; vtkSmartPointer myInteractor; + PSelectionEvent mySelectionEvent; + vtkSmartPointer myPicker; vtkSmartPointer myRectPicker; };