]> SALOME platform Git repositories - modules/gui.git/commitdiff
Salome HOME
1. Now SelectionEvent wil pass to PreHighlight/Highlight functionality by pointer...
authorapo <apo@opencascade.com>
Tue, 20 Sep 2005 09:31:04 +0000 (09:31 +0000)
committerapo <apo@opencascade.com>
Tue, 20 Sep 2005 09:31:04 +0000 (09:31 +0000)
2. To fix regression with PreHighlight/Highlight functionality

src/SVTK/SALOME_Actor.cxx
src/SVTK/SALOME_Actor.h
src/SVTK/SVTK_InteractorStyle.cxx
src/SVTK/SVTK_InteractorStyle.h

index 67f033ed1f704bd00e27a7b4a2d13fff78a37ce2..836065fc8042891d349030cd645a63dbf15e0a8d 100644 (file)
@@ -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 )
   {
index b5f3443a556aae237491ebe98698f17c4b6b3a3c..bfe943b62182b249ddcab6e6607c5f795837346a 100644 (file)
@@ -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
index 4f7762d01ee8ada2e504dee6a5f5008d679fe4d0..761cfd3dd034c4dd02d3abd88b603f12942d12e5 100644 (file)
@@ -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() - "<<this);
 
   this->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<SALOME_Actor>(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) {
index 6f98dd48ca5452064881bbfe49941dad064a1a50..8355df58e72bb4a4f37b675d48716ffbe2ea3bdb 100644 (file)
@@ -33,6 +33,8 @@
 
 #include "SVTK_SelectionEvent.h"
 
+#include <boost/shared_ptr.hpp>
+
 #include <vtkInteractorStyle.h>
 #include <vtkSmartPointer.h>
 
@@ -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<SVTK_SelectionEvent> 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<SVTK_GenericRenderWindowInteractor> myInteractor;
 
+  PSelectionEvent mySelectionEvent;
+
   vtkSmartPointer<vtkPicker> myPicker;
   vtkSmartPointer<VTKViewer_RectPicker> myRectPicker;
 };