]> SALOME platform Git repositories - modules/gui.git/commitdiff
Salome HOME
0020735: EDF 1308 VISU: Gauss point picking not possible when a mesh representation...
authorouv <ouv@opencascade.com>
Wed, 3 Mar 2010 12:31:26 +0000 (12:31 +0000)
committerouv <ouv@opencascade.com>
Wed, 3 Mar 2010 12:31:26 +0000 (12:31 +0000)
src/SVTK/SALOME_Actor.cxx
src/SVTK/SALOME_Actor.h
src/SVTK/SVTK_InteractorStyle.cxx
src/SVTK/SVTK_Selector.cxx
src/SVTK/SVTK_Selector.h
src/SVTK/SVTK_SelectorDef.h
src/VTKViewer/VTKViewer_Actor.cxx
src/VTKViewer/VTKViewer_Actor.h

index b85f7c26f27be5214d88839eee425c7ce486b045..3d74ab9bc2c395ded650d1479f198e04e278db8b 100644 (file)
@@ -122,29 +122,27 @@ namespace
     };
     return false;
   }
+}
 
-  class TPickLimiter
+namespace SVTK
+{
+  /*!
+    Make picker work with this actor only
+  */
+  TPickLimiter::TPickLimiter(vtkAbstractPicker* picker, SALOME_Actor* actor):myPicker(picker)
   {
-    vtkAbstractPicker* myPicker;
-  public:
-    /*!
-      Make picker work with this actor only
-    */
-    TPickLimiter(vtkAbstractPicker* picker, SALOME_Actor* actor):myPicker(picker)
-    {
-      myPicker->InitializePickList();
-      myPicker->AddPickList( actor );
-      myPicker->SetPickFromList( true );
-    }
-    /*!
-      Unlimit picking
-    */
-    ~TPickLimiter()
-    {
-      myPicker->SetPickFromList( false );
-      myPicker->InitializePickList();
-    }
-  };
+    myPicker->InitializePickList();
+    myPicker->AddPickList( actor );
+    myPicker->SetPickFromList( true );
+  }
+  /*!
+    Unlimit picking
+  */
+  TPickLimiter::~TPickLimiter()
+  {
+    myPicker->SetPickFromList( false );
+    myPicker->InitializePickList();
+  }
 }
 
 
@@ -506,7 +504,7 @@ SALOME_Actor
     switch(aSelectionMode) {
     case NodeSelection: 
     {
-      TPickLimiter( myPointPicker, this );
+      SVTK::TPickLimiter aPickLimiter( myPointPicker, this );
       myPointPicker->Pick( x, y, z, aRenderer );
       
       int aVtkId = myPointPicker->GetPointId();
@@ -534,7 +532,7 @@ SALOME_Actor
     case FaceSelection:
     case VolumeSelection: 
     {
-      TPickLimiter( myCellPicker, this );
+      SVTK::TPickLimiter aPickLimiter( myCellPicker, this );
       myCellPicker->Pick( x, y, z, aRenderer );
       
       int aVtkId = myCellPicker->GetCellId();
@@ -561,7 +559,7 @@ SALOME_Actor
     }
     case EdgeOfCellSelection:
     {
-      TPickLimiter( myCellPicker, this );
+      SVTK::TPickLimiter aPickLimiter( myCellPicker, this );
       myCellPicker->Pick( x, y, z, aRenderer );
       
       int aVtkId = myCellPicker->GetCellId();
@@ -649,7 +647,7 @@ SALOME_Actor
   if( !theSelectionEvent->myIsRectangle ) {
     switch(aSelectionMode){
     case NodeSelection: {
-      TPickLimiter( myPointPicker, this );
+      SVTK::TPickLimiter aPickLimiter( myPointPicker, this );
       myPointPicker->Pick( x, y, z, aRenderer );
 
       int aVtkId = myPointPicker->GetPointId();
@@ -667,7 +665,7 @@ SALOME_Actor
     case FaceSelection:
     case VolumeSelection: 
     {
-      TPickLimiter( myCellPicker, this );
+      SVTK::TPickLimiter aPickLimiter( myCellPicker, this );
       myCellPicker->Pick( x, y, z, aRenderer );
     
       int aVtkId = myCellPicker->GetCellId();
@@ -684,7 +682,7 @@ SALOME_Actor
     }
     case EdgeOfCellSelection: 
     {
-      TPickLimiter( myCellPicker, this );
+      SVTK::TPickLimiter aPickLimiter( myCellPicker, this );
       myCellPicker->Pick( x, y, z, aRenderer );
     
       int aVtkId = myCellPicker->GetCellId();
@@ -728,7 +726,7 @@ SALOME_Actor
     switch(aSelectionMode){
     case NodeSelection: {
 
-      TPickLimiter( myPointRectPicker, this );
+      SVTK::TPickLimiter aPickLimiter( myPointRectPicker, this );
       myPointRectPicker->Pick( x1, y1, z1, x2, y2, z2, aRenderer );
 
       const SVTK_RectPicker::TVectorIdsMap& aVectorIdsMap = myPointRectPicker->GetPointIdsMap();
@@ -787,7 +785,7 @@ SALOME_Actor
     case FaceSelection:
     case VolumeSelection: 
     {
-      TPickLimiter( myCellRectPicker, this );
+      SVTK::TPickLimiter aPickLimiter( myCellRectPicker, this );
       myCellRectPicker->Pick( x1, y1, z1, x2, y2, z2, aRenderer );
 
       const SVTK_RectPicker::TVectorIdsMap& aVectorIdsMap = myCellRectPicker->GetCellIdsMap();
index a9081a208563f4a64bf6fc0716d00c5cbe7c040e..3e9089723e7b7cedd267bd114b39d1df9dfb8435 100644 (file)
@@ -43,6 +43,7 @@ class Handle(SALOME_InteractiveObject);
 
 #include <vtkSmartPointer.h>
 
+class vtkAbstractPicker;
 class vtkPointPicker;
 class vtkCellPicker;
 class vtkOutlineSource;
@@ -271,6 +272,17 @@ class SVTK_EXPORT SALOME_Actor : public VTKViewer_Actor
   vtkSmartPointer<VTKViewer_FramedTextActor> myNameActor;
 };
 
+namespace SVTK
+{
+  class TPickLimiter
+  {
+    vtkAbstractPicker* myPicker;
+  public:
+    TPickLimiter(vtkAbstractPicker*, SALOME_Actor*);
+    ~TPickLimiter();
+  };
+}
+
 #ifdef WIN32
 #pragma warning ( default:4251 )
 #endif
index 050386f959438474af3e288b17ec55366d1af728..4336965e0186d7646279ef0ea7eba3ed7e1bd765 100644 (file)
@@ -455,48 +455,48 @@ void SVTK_InteractorStyle::OnLeftButtonDown(int ctrl, int shift,
     {
       SVTK_SelectionEvent* aSelectionEvent = GetSelectionEventFlipY();
 
-      SALOME_Actor* anActor = GetSelector()->Pick(aSelectionEvent, GetCurrentRenderer());
+      bool isPicked = false;
+      vtkActorCollection* anActorCollection = GetSelector()->Pick(aSelectionEvent, GetCurrentRenderer());
       
-      if ( anActor )
+      if( anActorCollection )
       {
-        myPointPicker->Pick( aSelectionEvent->myX,
-                             aSelectionEvent->myY, 
-                             0.0, 
-                             GetCurrentRenderer() );
-        int aVtkId = myPointPicker->GetPointId();
-        if ( aVtkId >= 0 )
+        anActorCollection->InitTraversal();
+        while( vtkActor* aVTKActor = anActorCollection->GetNextActor() )
         {
-          int anObjId = anActor->GetNodeObjId( aVtkId );
-          vtkFloatingPointType* aCoords = anActor->GetNodeCoord(anObjId);
-          
-          if (myCurrRotationPointType == SVTK::StartPointSelection) {
-            myCurrRotationPointType = SVTK::SetRotateSelected;
-          
-            // invoke event for update coordinates in SVTK_SetRotationPointDlg
-            InvokeEvent(SVTK::RotationPointChanged,(void*)aCoords);
-          }
-          else if (myCurrFocalPointType == SVTK::StartFocalPointSelection) {
-            myCurrFocalPointType = SVTK::SetFocalPointSelected;
-          
-            // invoke event for update coordinates in SVTK_ViewParameterDlg
-            InvokeEvent(SVTK::FocalPointChanged,(void*)aCoords);
-          }
-        }
-        else
-        {
-          if (myCurrRotationPointType == SVTK::StartPointSelection) {
-            // invoke event with no data (for SVTK_SetRotationPointDlg)
-            InvokeEvent(SVTK::RotationPointChanged,0);
-            myCurrRotationPointType = myPrevRotationPointType;
-          }
-          else if (myCurrFocalPointType == SVTK::StartFocalPointSelection) {
-            // invoke event with no data (for SVTK_ViewParameterDlg)
-            InvokeEvent(SVTK::FocalPointChanged,0);
-            myCurrFocalPointType = myPrevFocalPointType;
+          if( SALOME_Actor* anActor = SALOME_Actor::SafeDownCast( aVTKActor ) )
+          {
+            SVTK::TPickLimiter aPickLimiter( myPointPicker, anActor );
+            myPointPicker->Pick( aSelectionEvent->myX,
+                                 aSelectionEvent->myY, 
+                                 0.0, 
+                                 GetCurrentRenderer() );
+            int aVtkId = myPointPicker->GetPointId();
+            if ( aVtkId >= 0 )
+            {
+              int anObjId = anActor->GetNodeObjId( aVtkId );
+              vtkFloatingPointType* aCoords = anActor->GetNodeCoord(anObjId);
+              
+              if (myCurrRotationPointType == SVTK::StartPointSelection) {
+                myCurrRotationPointType = SVTK::SetRotateSelected;
+                
+                // invoke event for update coordinates in SVTK_SetRotationPointDlg
+                InvokeEvent(SVTK::RotationPointChanged,(void*)aCoords);
+              }
+              else if (myCurrFocalPointType == SVTK::StartFocalPointSelection) {
+                myCurrFocalPointType = SVTK::SetFocalPointSelected;
+                
+                // invoke event for update coordinates in SVTK_ViewParameterDlg
+                InvokeEvent(SVTK::FocalPointChanged,(void*)aCoords);
+              }
+
+              isPicked = true;
+              break;
+            }
           }
         }
       }
-      else
+
+      if( !isPicked )
       {
         if (myCurrRotationPointType == SVTK::StartPointSelection) {
           // invoke event with no data (for SVTK_SetRotationPointDlg)
@@ -1035,23 +1035,37 @@ void SVTK_InteractorStyle::onFinishOperation()
             this->FindPokedRenderer(aSelectionEvent->myX, aSelectionEvent->myY);
             Interactor->StartPickCallback();
             
-            SALOME_Actor* anActor = GetSelector()->Pick(aSelectionEvent, GetCurrentRenderer());
+            SALOME_Actor* aHighlightedActor = NULL;
+            vtkActorCollection* anActorCollection = GetSelector()->Pick(aSelectionEvent, GetCurrentRenderer());
 
             aSelectionEvent->myIsRectangle = false;
 
             if(!myShiftState)
               GetSelector()->ClearIObjects();
 
-            if(anActor)
+            if( anActorCollection )
+            {
+              anActorCollection->InitTraversal();
+              while( vtkActor* aVTKActor = anActorCollection->GetNextActor() )
               {
-                anActor->Highlight( this, aSelectionEvent, true );
-              }
-            else
-              {
-                if(myLastHighlitedActor.GetPointer() && myLastHighlitedActor.GetPointer() != anActor)
-                  myLastHighlitedActor->Highlight( this, aSelectionEvent, false );
+                if( SALOME_Actor* anActor = SALOME_Actor::SafeDownCast( aVTKActor ) )
+                {
+                  if( anActor->Highlight( this, aSelectionEvent, true ) &&
+                      anActor->isHighlighted() )
+                  {
+                    aHighlightedActor = anActor;
+                    break;
+                  }
+                }
               }
-            myLastHighlitedActor = anActor;
+            }
+
+            if( !aHighlightedActor )
+            {
+              if(myLastHighlitedActor.GetPointer() && myLastHighlitedActor.GetPointer() != aHighlightedActor)
+                myLastHighlitedActor->Highlight( this, aSelectionEvent, false );
+            }
+            myLastHighlitedActor = aHighlightedActor;
           } 
         else 
           {
@@ -1166,40 +1180,63 @@ void SVTK_InteractorStyle::onCursorMove(QPoint mousePos)
 
   bool anIsChanged = false;
 
-  SALOME_Actor *anActor = GetSelector()->Pick(aSelectionEvent, GetCurrentRenderer());
+  SALOME_Actor* aPreHighlightedActor = NULL;
+  vtkActorCollection* anActorCollection = GetSelector()->Pick(aSelectionEvent, GetCurrentRenderer());
 
   if ( myCurrRotationPointType == SVTK::StartPointSelection ||
        myCurrFocalPointType == SVTK::StartFocalPointSelection )
   {
     myHighlightSelectionPointActor->SetVisibility( false );
 
-    if ( anActor )
+    if( anActorCollection )
     {
-      myPointPicker->Pick( aSelectionEvent->myX, aSelectionEvent->myY, 0.0, GetCurrentRenderer() );
-      int aVtkId = myPointPicker->GetPointId();
-      if ( aVtkId >= 0 ) {
-        int anObjId = anActor->GetNodeObjId( aVtkId );
-
-        TColStd_IndexedMapOfInteger aMapIndex;
-        aMapIndex.Add( anObjId );
-        myHighlightSelectionPointActor->MapPoints( anActor, aMapIndex );
-
-        myHighlightSelectionPointActor->SetVisibility( true );
-        anIsChanged = true;
+      anActorCollection->InitTraversal();
+      while( vtkActor* aVTKActor = anActorCollection->GetNextActor() )
+      {
+        if( SALOME_Actor* anActor = SALOME_Actor::SafeDownCast( aVTKActor ) )
+        {
+          SVTK::TPickLimiter aPickLimiter( myPointPicker, anActor );
+          myPointPicker->Pick( aSelectionEvent->myX, aSelectionEvent->myY, 0.0, GetCurrentRenderer() );
+          int aVtkId = myPointPicker->GetPointId();
+          if ( aVtkId >= 0 ) {
+            int anObjId = anActor->GetNodeObjId( aVtkId );
+
+            TColStd_IndexedMapOfInteger aMapIndex;
+            aMapIndex.Add( anObjId );
+            myHighlightSelectionPointActor->MapPoints( anActor, aMapIndex );
+
+            myHighlightSelectionPointActor->SetVisibility( true );
+            anIsChanged = true;
+            break;
+          }
+        }
       }
     }
   }
   else {
-    if (anActor){
-      anIsChanged |= anActor->PreHighlight( this, aSelectionEvent, true );
+    if( anActorCollection )
+    {
+      anActorCollection->InitTraversal();
+      while( vtkActor* aVTKActor = anActorCollection->GetNextActor() )
+      {
+        if( SALOME_Actor* anActor = SALOME_Actor::SafeDownCast( aVTKActor ) )
+        {
+          anIsChanged = anActor->PreHighlight( this, aSelectionEvent, true );
+          if( anActor->isPreselected() )
+          {
+            aPreHighlightedActor = anActor;
+            break;
+          }
+        }
+      }
     }
 
-    if(myLastPreHighlitedActor.GetPointer() && myLastPreHighlitedActor.GetPointer() != anActor)
+    if(myLastPreHighlitedActor.GetPointer() && myLastPreHighlitedActor.GetPointer() != aPreHighlightedActor)
       anIsChanged |= myLastPreHighlitedActor->PreHighlight( this, aSelectionEvent, false );   
 
   }
   
-  myLastPreHighlitedActor = anActor;
+  myLastPreHighlitedActor = aPreHighlightedActor;
 
   if(anIsChanged)
     this->Render();
index bbb58454083537a9da1dfb4c88af25e897591b45..bc9e284ecf95a2f2c9508d32e575e4c00af8bbe7 100644 (file)
 #include <vtkCellPicker.h>
 
 
-/*!
-  Find first SALOME_Actor from the end of actors collection
-*/
-inline
-SALOME_Actor* 
-GetLastSALOMEActor(vtkActorCollection* theCollection)
-{
-  if (theCollection) {
-    for (int i = theCollection->GetNumberOfItems() - 1; i >= 0; i--) {
-      if (SALOME_Actor* anActor = dynamic_cast<SALOME_Actor*>(theCollection->GetItemAsObject(i)))
-        if (anActor->hasIO())
-          return anActor;
-    }
-  }
-  return NULL;
-}
-
-
 /*!
   \return new SVTK_Selector
 */
@@ -544,7 +526,7 @@ SVTK_SelectorDef
   return Handle(VTKViewer_Filter)();
 }
 
-SALOME_Actor*
+vtkActorCollection*
 SVTK_SelectorDef
 ::Pick(const SVTK_SelectionEvent* theEvent, vtkRenderer* theRenderer) const
 {
@@ -553,7 +535,6 @@ SVTK_SelectorDef
   if ( aResourceMgr )
     anAdvancedSelectionAlgorithm = aResourceMgr->booleanValue( "VTKViewer", "use_advanced_selection_algorithm", true );
 
-  SALOME_Actor* anActor = NULL;
   vtkActorCollection* aListActors = NULL;
   if ( anAdvancedSelectionAlgorithm ) {
     myCellPicker->Pick(theEvent->myX,
@@ -562,19 +543,17 @@ SVTK_SelectorDef
                        theRenderer);
   
     aListActors = myCellPicker->GetActors();
-    anActor = GetLastSALOMEActor(aListActors);
   }
 
-  if ( !anActor ) {
+  if ( !aListActors || !aListActors->GetNumberOfItems() ) {
     myPicker->Pick(theEvent->myX,
                    theEvent->myY, 
                    0.0,
                    theRenderer);
     aListActors = myPicker->GetActors();
-    anActor = GetLastSALOMEActor(aListActors);
   }
   
-  return anActor;
+  return aListActors;
 }
 
 void
index 9ffd5ee7753509e1b74fd45c5460c3f9c7bd035c..b1254a24267d9c0b25b0bb1f414aced0dae45350 100644 (file)
@@ -41,6 +41,7 @@ class Handle(VTKViewer_Filter);
 
 class SALOME_Actor;
 class SVTK_SelectionEvent;
+class vtkActorCollection;
 class vtkRenderer;
 class Handle(SALOME_InteractiveObject);
 
@@ -210,7 +211,7 @@ public:
 
   //----------------------------------------------------------------------------
   virtual
-  SALOME_Actor*
+  vtkActorCollection*
   Pick(const SVTK_SelectionEvent* theEvent, vtkRenderer* theRenderer) const = 0;
 
   virtual
index bed2189f0f36f2a1ca85db6c4c18d765ec0d8c1c..f80598904d943e33c8884c5f34efaf04385f062f 100644 (file)
@@ -170,7 +170,7 @@ public:
 
   //----------------------------------------------------------------------------
   virtual
-  SALOME_Actor*
+  vtkActorCollection*
   Pick(const SVTK_SelectionEvent* theEvent, vtkRenderer* theRenderer) const;
 
   virtual
index 5118c43902a556cd93c2b127e84c06a26ef0c30e..84e3fda14e859ee710e391fd440d0fb905944fb1 100755 (executable)
@@ -653,6 +653,16 @@ VTKViewer_Actor
   return myIsHighlighted; 
 }
 
+/*!
+  \return true if the VTKViewer_Actor is already preselected
+*/
+bool
+VTKViewer_Actor
+::isPreselected() 
+{ 
+  return myIsPreselected; 
+}
+
 /*!
   Set preselection mode
 */
index d41760d9f26a5af8b762beeb6034a6344feba031..dd285100317e652008f144d694a3b6ee9cac87ac 100755 (executable)
@@ -287,6 +287,11 @@ class VTKVIEWER_EXPORT VTKViewer_Actor : public vtkLODActor
   bool
   isHighlighted();
 
+  //! Ask, if the VTKViewer_Actor is already preselected
+  virtual
+  bool
+  isPreselected();
+
   //! Set preselection mode
   virtual
   void