Salome HOME
Fix for the bug #130: bathymetry sign is wrong
[modules/hydro.git] / src / HYDROGUI / HYDROGUI_VTKPrsDisplayer.cxx
index c22b85aa109063e89126a51f7466bf6ee356ad8c..909012353d23fffc6ad6de8103e0a11e6de9a561 100644 (file)
 //#define SATURATION_START 1.0 
 //#define SATURATION_END   0.4
 
-#define HUE_START 0.
-#define HUE_END   0.0
+#define HUE_START 0.0
+#define HUE_END   0.
 #define SATURATION_START 1.0 
 #define SATURATION_END   1.0
 
 HYDROGUI_VTKPrsDisplayer::HYDROGUI_VTKPrsDisplayer( HYDROGUI_Module* theModule )
 : HYDROGUI_AbstractDisplayer( theModule ), myDriver( NULL )
 {
-  // The invalid value is used to identify the case when the table range is not initialized yet.
-  double anInvalidValue = HYDROGUI_VTKPrs::InvalidZValue();
-  vtkLookupTable* aTable = vtkLookupTable::New();
-  aTable->SetHueRange( HUE_START, HUE_END );
-  aTable->SetSaturationRange( SATURATION_START, SATURATION_END );
-  aTable->SetTableRange( anInvalidValue, anInvalidValue );
-  aTable->SetValueRange( 1.0, 1.0 );
-  aTable->SetAlphaRange( 1.0, 1.0 );
-  aTable->SetNumberOfColors( NB_COLORS );
-  myScalarBar->SetLookupTable( aTable );
 }
 
 HYDROGUI_VTKPrsDisplayer::~HYDROGUI_VTKPrsDisplayer()
@@ -108,6 +98,27 @@ void HYDROGUI_VTKPrsDisplayer::EraseAll( const int theViewerId )
   }
 }
 
+void HYDROGUI_VTKPrsDisplayer::DeleteScalarBar( const int theViewerId )
+{
+  SVTK_Viewer* aViewer = module()->getVTKViewer( theViewerId );
+  if( aViewer )
+  {
+    SVTK_ViewWindow* aView = dynamic_cast<SVTK_ViewWindow*>(
+      aViewer->getViewManager()->getActiveView() );
+    if ( aView )
+    {
+      if ( myScalarBars.contains( (size_t)aViewer ) )
+      {
+        vtkScalarBarActor* aScalarBar = myScalarBars[ (size_t)aViewer ];
+        if ( aView->getRenderer()->HasViewProp( aScalarBar ) )
+        {
+          aView->getRenderer()->RemoveActor2D( aScalarBar );
+        }
+      }
+    }
+  }
+}
+
 void HYDROGUI_VTKPrsDisplayer::Erase( const HYDROData_SequenceOfObjects& theObjs,
                                 const int theViewerId )
 {
@@ -142,20 +153,27 @@ void HYDROGUI_VTKPrsDisplayer::Display( const HYDROData_SequenceOfObjects& theOb
   SVTK_Viewer* aViewer = module()->getVTKViewer( theViewerId );
   if( aViewer )
   {
-    // Invalidate global Z range
-    double anInvalidRange[2] = { HYDROGUI_VTKPrs::InvalidZValue(), HYDROGUI_VTKPrs::InvalidZValue() };
-    SetZRange( anInvalidRange );
     // Hide colors legend bar
     SVTK_ViewWindow* aView = dynamic_cast<SVTK_ViewWindow*>(
       aViewer->getViewManager()->getActiveView() );
+    vtkScalarBarActor* aScalarBar = 0;
     if ( aView )
     {
-      if ( aView->getRenderer()->HasViewProp( myScalarBar.GetPointer() ) )
+      if ( !myScalarBars.contains( (size_t)aViewer ) )
       {
-        aView->getRenderer()->RemoveActor2D( myScalarBar.GetPointer() );
+        createScalarBar( (size_t)aViewer );
+      }
+      aScalarBar = myScalarBars[ (size_t)aViewer ];
+
+      if ( aView->getRenderer()->HasViewProp( aScalarBar ) )
+      {
+        aView->getRenderer()->RemoveActor2D( aScalarBar );
       }
     }
 
+    // Invalidate global Z range
+    double anInvalidRange[2] = { HYDROGUI_VTKPrs::InvalidZValue(), HYDROGUI_VTKPrs::InvalidZValue() };
+    SetZRange( (size_t)aViewer, anInvalidRange );
 
     int anInvalidZ = HYDROGUI_VTKPrs::InvalidZValue();
     bool isChanged = false;
@@ -171,7 +189,7 @@ void HYDROGUI_VTKPrsDisplayer::Display( const HYDROData_SequenceOfObjects& theOb
         bool anIsInserted = ( aPrs != 0 );
         if( anIsVisible && ( !aPrs || aPrs->getIsToUpdate() || theIsForced ) )
         {
-          if( HYDROGUI_VTKPrsDriver* aDriver = getDriver( anObj ) )
+          if( HYDROGUI_VTKPrsDriver* aDriver = getDriver( (size_t)aViewer, anObj ) )
           {
             if( aDriver->Update( anObj, aPrs ) && aPrs && !anIsInserted )
             {
@@ -186,7 +204,7 @@ void HYDROGUI_VTKPrsDisplayer::Display( const HYDROData_SequenceOfObjects& theOb
           {
 
             // Extend the global Z range if necessary
-            double* aGlobalRange = GetZRange();
+            double* aGlobalRange = GetZRange( (size_t)aViewer );
             double* aRange = aPrs->getInternalZRange();
             bool anIsUpdate = false;
             if ( aRange[0] < aGlobalRange[0] || ValuesEquals( aGlobalRange[0], anInvalidZ ) )
@@ -202,7 +220,7 @@ void HYDROGUI_VTKPrsDisplayer::Display( const HYDROData_SequenceOfObjects& theOb
 
             if ( anIsUpdate )
             {
-              module()->updateVTKZRange( aGlobalRange );
+              module()->updateVTKZRange( (size_t)aViewer, aGlobalRange );
             }
 
             aViewer->Display( aPrs );
@@ -217,23 +235,24 @@ void HYDROGUI_VTKPrsDisplayer::Display( const HYDROData_SequenceOfObjects& theOb
       }
     }
 
-    if ( isChanged )
+    if ( aView ) 
     {
-      // Show colors legend bar
-      if ( aView )
+      if ( isChanged && aScalarBar )
       {
-        aView->getRenderer()->AddActor2D( myScalarBar.GetPointer() );
+        // Show colors legend bar
+          aView->getRenderer()->AddActor2D( aScalarBar );
       }
-    }
 
-    if ( theDoFitAll )
-    {
-      // Repaint is done inside OnFitAll()
-      aViewer->getViewManager()->getActiveView()->onAccelAction( SUIT_Accel::ZoomFit );
-    } 
-    else if ( isChanged )
-    {
-      aViewer->Repaint();
+      // Refresh the view
+      if ( theDoFitAll )
+      {
+        // Repaint is done inside OnFitAll()
+        aView->onAccelAction( SUIT_Accel::ZoomFit );
+      } 
+      else if ( isChanged )
+      {
+        aView->Repaint();
+      }
     }
   }
 }
@@ -269,7 +288,7 @@ void HYDROGUI_VTKPrsDisplayer::purgeObjects( const int theViewerId )
   }
 }
 
-HYDROGUI_VTKPrsDriver* HYDROGUI_VTKPrsDisplayer::getDriver( const Handle(HYDROData_Entity)& theObj )
+HYDROGUI_VTKPrsDriver* HYDROGUI_VTKPrsDisplayer::getDriver( const int theViewId, const Handle(HYDROData_Entity)& theObj )
 {
   HYDROGUI_VTKPrsDriver* aDriver = NULL;
   ObjectKind aKind = theObj->GetKind();
@@ -277,7 +296,7 @@ HYDROGUI_VTKPrsDriver* HYDROGUI_VTKPrsDisplayer::getDriver( const Handle(HYDRODa
   {
     if ( !myDriver )
     {
-      myDriver = new HYDROGUI_VTKPrsBathymetryDriver( myScalarBar.GetPointer() );
+      myDriver = new HYDROGUI_VTKPrsBathymetryDriver( myScalarBars[ theViewId ] );
     }
     aDriver = myDriver;
   }
@@ -290,12 +309,33 @@ QString HYDROGUI_VTKPrsDisplayer::GetType() const
   return SVTK_Viewer::Type();
 }
 
-void HYDROGUI_VTKPrsDisplayer::SetZRange( double theRange[] )
+void HYDROGUI_VTKPrsDisplayer::SetZRange( const int theViewId, double theRange[] )
+{
+  myScalarBars[ theViewId ]->GetLookupTable()->SetRange( theRange );
+}
+
+double* HYDROGUI_VTKPrsDisplayer::GetZRange( const int theViewId ) const
 {
-  myScalarBar->GetLookupTable()->SetRange( theRange );
+  return myScalarBars[ theViewId ]->GetLookupTable()->GetRange();
 }
 
-double* HYDROGUI_VTKPrsDisplayer::GetZRange() const
+void HYDROGUI_VTKPrsDisplayer::createScalarBar( const int theViewId )
 {
-  return myScalarBar->GetLookupTable()->GetRange();
-}
\ No newline at end of file
+  if ( !myScalarBars.contains( theViewId ) )
+  {
+    // The invalid value is used to identify the case when the table range is not initialized yet.
+    double anInvalidValue = HYDROGUI_VTKPrs::InvalidZValue();
+    vtkLookupTable* aTable = vtkLookupTable::New();
+    aTable->SetHueRange( HUE_START, HUE_END );
+    aTable->SetSaturationRange( SATURATION_START, SATURATION_END );
+    aTable->SetTableRange( anInvalidValue, anInvalidValue );
+    aTable->SetValueRange( 1.0, 1.0 );
+    aTable->SetAlphaRange( 1.0, 1.0 );
+    aTable->SetNumberOfColors( NB_COLORS );
+    aTable->Build();
+    vtkSmartPointer<vtkScalarBarActor> aScalarBar = vtkScalarBarActor::New();
+    aScalarBar->SetLookupTable( aTable );
+    aTable->Delete();
+    myScalarBars.insert( theViewId, aScalarBar );
+  }
+}