Salome HOME
portage V8_5_0
[modules/hydro.git] / src / HYDROGUI / HYDROGUI_VTKPrsDisplayer.cxx
index 8b373317e81242cbaae2fafeddba21582cf7f389..20901f2b6c9dd78e10be7a8656b53d06bcc743b5 100644 (file)
@@ -1,12 +1,8 @@
-// Copyright (C) 2007-2013  CEA/DEN, EDF R&D, OPEN CASCADE
-//
-// Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
-// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
-//
+// Copyright (C) 2014-2015  EDF-R&D
 // This library is free software; you can redistribute it and/or
 // modify it under the terms of the GNU Lesser General Public
 // License as published by the Free Software Foundation; either
-// version 2.1 of the License.
+// version 2.1 of the License, or (at your option) any later version.
 //
 // This library is distributed in the hope that it will be useful,
 // but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -33,7 +29,7 @@
 #include <SVTK_ViewModel.h>
 #include <SVTK_ViewWindow.h>
 #include <SALOME_ListIO.hxx>
-#include <SALOME_ListIteratorOfListIO.hxx>
+//#include <SALOME_ListIteratorOfListIO.hxx>
 #include <SALOME_InteractiveObject.hxx>
 #include <SUIT_ViewManager.h>
 #include <SUIT_Accel.h>
@@ -90,17 +86,55 @@ void HYDROGUI_VTKPrsDisplayer::SetToUpdate( const HYDROData_SequenceOfObjects& t
   }
 }
 
+void HYDROGUI_VTKPrsDisplayer::DisplayAll( const int theViewerId,
+                                           const bool theIsForced,
+                                           const bool theDoFitAll )
+{
+  HYDROGUI_AbstractDisplayer::DisplayAll( theViewerId, theIsForced, theDoFitAll );
+
+  bool isEraseScalarBar = true;
+
+  SVTK_Viewer* aViewer = module()->getVTKViewer( theViewerId );
+  if( aViewer )
+  {
+    SALOME_ListIO aListIO;
+    aViewer->GetVisible( aListIO );
+    
+    HYDROGUI_VTKPrs* aPrs;
+    SALOME_ListIteratorOfListIO anIter( aListIO );
+    for( ; anIter.More(); anIter.Next() )
+    {
+      Handle(SALOME_InteractiveObject) aPrsObj = anIter.Value();
+      if ( !aPrsObj.IsNull() )
+      {
+        Handle(HYDROData_Entity) anObj = 
+          module()->getDataModel()->objectByEntry( aPrsObj->getEntry() );
+        aPrs = module()->getObjectVTKPrs( (size_t)aViewer, anObj );
+        if( aPrs->needScalarBar() )
+        {
+          isEraseScalarBar = false;
+          break;
+        }
+      }
+    }
+  }
+
+  if( isEraseScalarBar )
+    EraseScalarBar( theViewerId );
+}
+
 void HYDROGUI_VTKPrsDisplayer::EraseAll( const int theViewerId )
 {
   SVTK_Viewer* aViewer = module()->getVTKViewer( theViewerId );
   if( aViewer )
   {
-    aViewer->EraseAll( true );
+    aViewer->EraseAll( 0, true );
     module()->removeViewVTKPrs( (size_t)aViewer );
+    EraseScalarBar( theViewerId );
   }
 }
 
-void HYDROGUI_VTKPrsDisplayer::DeleteScalarBar( const int theViewerId )
+void HYDROGUI_VTKPrsDisplayer::EraseScalarBar( const int theViewerId, const bool theIsDelete )
 {
   SVTK_Viewer* aViewer = module()->getVTKViewer( theViewerId );
   if( aViewer )
@@ -120,7 +154,10 @@ void HYDROGUI_VTKPrsDisplayer::DeleteScalarBar( const int theViewerId )
           }
         }
       }
-      myScalarBars.remove( (size_t)aViewer );
+      if ( theIsDelete )
+      {
+        myScalarBars.remove( (size_t)aViewer );
+      }
     }
   }
 }
@@ -183,6 +220,7 @@ void HYDROGUI_VTKPrsDisplayer::Display( const HYDROData_SequenceOfObjects& theOb
 
     int anInvalidZ = HYDROGUI_VTKPrs::InvalidZValue();
     bool isChanged = false;
+    bool isScalarBarNeeded = false;
     HYDROGUI_VTKPrs* aPrs;
     for ( int i = 1, n = theObjs.Length(); i <= n; i++ )
     {
@@ -195,6 +233,12 @@ void HYDROGUI_VTKPrsDisplayer::Display( const HYDROData_SequenceOfObjects& theOb
         bool anIsInserted = ( aPrs != 0 );
         if( anIsVisible && ( !aPrs || aPrs->getIsToUpdate() || theIsForced ) )
         {
+          // Erase the presentation in the view because of the problem with GEOM_Actor upadting on second SetShape.
+          if ( aPrs )
+          {
+            aViewer->Erase( aPrs, true );
+          }
+          // Update the presentation
           if( HYDROGUI_VTKPrsDriver* aDriver = getDriver( (size_t)aViewer, anObj ) )
           {
             if( aDriver->Update( anObj, aPrs ) && aPrs && !anIsInserted )
@@ -208,28 +252,31 @@ void HYDROGUI_VTKPrsDisplayer::Display( const HYDROData_SequenceOfObjects& theOb
         {
           if ( anIsVisible )
           {
-
-            // Extend the global Z range if necessary
-            double* aGlobalRange = GetZRange( (size_t)aViewer );
-            double* aRange = aPrs->getInternalZRange();
-            bool anIsUpdate = false;
-            if ( aRange[0] < aGlobalRange[0] || ValuesEquals( aGlobalRange[0], anInvalidZ ) )
+            if ( aPrs->needScalarBar() )
             {
-              aGlobalRange[0] = aRange[0];
-              anIsUpdate = true;
-            }
-            if ( aRange[1] > aGlobalRange[1] || ValuesEquals( aGlobalRange[1], anInvalidZ ) )
-            {
-              aGlobalRange[1] = aRange[1];
-              anIsUpdate = true;
-            }
-
-            if ( anIsUpdate )
-            {
-              module()->updateVTKZRange( (size_t)aViewer, aGlobalRange );
+              // Extend the global Z range if necessary
+              double* aGlobalRange = GetZRange( (size_t)aViewer );
+              double* aRange = aPrs->getInternalZRange();
+              bool anIsUpdate = false;
+              if ( aRange[0] < aGlobalRange[0] || ValuesEquals( aGlobalRange[0], anInvalidZ ) )
+              {
+                aGlobalRange[0] = aRange[0];
+                anIsUpdate = true;
+              }
+              if ( aRange[1] > aGlobalRange[1] || ValuesEquals( aGlobalRange[1], anInvalidZ ) )
+              {
+                aGlobalRange[1] = aRange[1];
+                anIsUpdate = true;
+              }
+
+              if ( anIsUpdate )
+              {
+                module()->updateVTKZRange( (size_t)aViewer, aGlobalRange );
+              }
             }
 
             aViewer->Display( aPrs );
+            isScalarBarNeeded = isScalarBarNeeded || aPrs->needScalarBar();
 
           }
           else
@@ -243,7 +290,7 @@ void HYDROGUI_VTKPrsDisplayer::Display( const HYDROData_SequenceOfObjects& theOb
 
     if ( aView ) 
     {
-      if ( isChanged && aScalarBar )
+      if ( isChanged && isScalarBarNeeded && aScalarBar )
       {
         // Show colors legend bar
           aView->getRenderer()->AddActor2D( aScalarBar );
@@ -257,7 +304,7 @@ void HYDROGUI_VTKPrsDisplayer::Display( const HYDROData_SequenceOfObjects& theOb
       } 
       else if ( isChanged )
       {
-        aView->Repaint();
+        aView->Repaint( true );
       }
     }
   }
@@ -265,12 +312,14 @@ void HYDROGUI_VTKPrsDisplayer::Display( const HYDROData_SequenceOfObjects& theOb
 
 void HYDROGUI_VTKPrsDisplayer::purgeObjects( const int theViewerId )
 {
+  bool doEraseScalarBar = false;
+
   SVTK_Viewer* aViewer = module()->getVTKViewer( theViewerId );
   if( aViewer )
   {
     SALOME_ListIO aListIO;
     aViewer->GetVisible( aListIO );
-
+    
     HYDROGUI_VTKPrs* aPrs;
     SALOME_ListIteratorOfListIO anIter( aListIO );
     for( ; anIter.More(); anIter.Next() )
@@ -280,17 +329,47 @@ void HYDROGUI_VTKPrsDisplayer::purgeObjects( const int theViewerId )
       {
         Handle(HYDROData_Entity) anOwnerObj = 
           module()->getDataModel()->objectByEntry( aPrsObj->getEntry() );
-        if ( !anOwnerObj.IsNull() && anOwnerObj->IsRemoved() )
+        if ( anOwnerObj.IsNull() )
+        {
+          // We found an unknown IO presented in the viewer. 
+          // Remove such an orphan presentation from all the views of the viewer.
+          SUIT_ViewManager* aViewMgr = dynamic_cast<SUIT_ViewManager*>( aViewer->getViewManager() );
+          if ( aViewMgr && aViewMgr->getViewsCount() > 0 )
+          {
+            QVector<SUIT_ViewWindow*> aViews = aViewMgr->getViews();
+            foreach ( SUIT_ViewWindow* aView, aViews )
+            {
+              SVTK_ViewWindow* aVTKView = dynamic_cast<SVTK_ViewWindow*>( aView );
+              if ( aVTKView )
+              {
+                aVTKView->Erase( aPrsObj, false );
+              }
+            }
+          }
+          // Remove the object presentation from the module's cache
+          module()->removeObjectVTKPrs( (size_t)aViewer, aPrsObj->getEntry() );
+          doEraseScalarBar = true;
+        }
+        else if ( anOwnerObj->IsRemoved() )
         {
           aPrs = module()->getObjectVTKPrs( (size_t)aViewer, anOwnerObj );
           if ( aPrs )
           {
             aViewer->Erase( aPrs );
           }
+          else
+          {
+          }
           module()->removeObjectVTKPrs( (size_t)aViewer, anOwnerObj );
+          doEraseScalarBar = true;
         }
       }
     }
+
+    if ( doEraseScalarBar )
+    {
+      EraseScalarBar( theViewerId );
+    }
   }
 }
 
@@ -352,6 +431,10 @@ void HYDROGUI_VTKPrsDisplayer::createScalarBar( const int theViewId )
     aScalarBar->SetNumberOfLabels( NB_COLORS * 0.75 );
     aScalarBar->SetWidth( aScalarBar->GetWidth() / 1.5 );
     aScalarBar->SetTextureGridWidth( aScalarBar->GetTextureGridWidth() * 4. );
+    aScalarBar->SetTitle( "  " );
+    // The call of SetTitle() with dummy string is a workaround necessary
+    // to avoid the problem with uninitialized variables in VTK scalar bar actor
+    // which leads to incorrect (very big) size of the VTK scalar bar presentation
     aTable->Delete();
     myScalarBars.insert( theViewId, aScalarBar );
   }