Salome HOME
refs #430: incorrect coordinates in dump polyline
[modules/hydro.git] / src / HYDROGUI / HYDROGUI_VTKPrsDisplayer.cxx
index 2b3e55f58810093e80c2ec9b07ecafa4bd60cd11..b096a067269bf316943b42c05495e80ab8ce7197 100644 (file)
@@ -26,6 +26,7 @@
 #include "HYDROGUI_Module.h"
 #include "HYDROGUI_VTKPrs.h"
 #include "HYDROGUI_VTKPrsBathymetryDriver.h"
+#include "HYDROGUI_VTKPrsShapeDriver.h"
 #include "HYDROGUI_Tool.h"
 
 #include "HYDROData_Tool.h"
@@ -59,7 +60,7 @@
 #define SATURATION_END   1.0
 
 HYDROGUI_VTKPrsDisplayer::HYDROGUI_VTKPrsDisplayer( HYDROGUI_Module* theModule )
-: HYDROGUI_AbstractDisplayer( theModule ), myDriver( NULL )
+: HYDROGUI_AbstractDisplayer( theModule ), myDriver( NULL ), myShapeDriver( NULL )
 {
 }
 
@@ -96,10 +97,11 @@ void HYDROGUI_VTKPrsDisplayer::EraseAll( const int theViewerId )
   {
     aViewer->EraseAll( 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 )
@@ -119,7 +121,10 @@ void HYDROGUI_VTKPrsDisplayer::DeleteScalarBar( const int theViewerId )
           }
         }
       }
-      myScalarBars.remove( (size_t)aViewer );
+      if ( theIsDelete )
+      {
+        myScalarBars.remove( (size_t)aViewer );
+      }
     }
   }
 }
@@ -182,6 +187,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++ )
     {
@@ -194,6 +200,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 )
@@ -207,28 +219,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 ) )
-            {
-              aGlobalRange[0] = aRange[0];
-              anIsUpdate = true;
-            }
-            if ( aRange[1] > aGlobalRange[1] || ValuesEquals( aGlobalRange[1], anInvalidZ ) )
+            if ( aPrs->needScalarBar() )
             {
-              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
@@ -242,7 +257,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 );
@@ -256,7 +271,7 @@ void HYDROGUI_VTKPrsDisplayer::Display( const HYDROData_SequenceOfObjects& theOb
       } 
       else if ( isChanged )
       {
-        aView->Repaint();
+        aView->Repaint( true );
       }
     }
   }
@@ -264,12 +279,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() )
@@ -279,17 +296,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 );
+    }
   }
 }
 
@@ -305,6 +352,14 @@ HYDROGUI_VTKPrsDriver* HYDROGUI_VTKPrsDisplayer::getDriver( const int theViewId,
     }
     aDriver = myDriver;
   }
+  else
+  {
+    if ( !myShapeDriver )
+    {
+      myShapeDriver = new HYDROGUI_VTKPrsShapeDriver( myScalarBars[ theViewId ] );
+    }
+    aDriver = myShapeDriver;
+  }
 
   return aDriver;
 }